⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ext_irq_handler.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 C
字号:
//*----------------------------------------------------------------------------
//*      ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : ext_irq_handler.c
//* Object              : C Handler for External Interrupt.
//*
//* 1.0 11/07/01  PF    : Creation
//*----------------------------------------------------------------------------

#include    "parts/m55800/lib_m55800.h"
#include    "targets/eb55/eb55.h"

// Use the C handler must be compile in ARM mode
extern void ext_IRQ0_handler(void);

//*----------------------------------------------------------------------------
//* Function Name       : pio_c_irq_handler
//* Object              : Irq Handler called by the irq_pio.s
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : at91_pio_read, at91_pio_write
//*----------------------------------------------------------------------------
void pio_c_irq_handler ( void )
{
int tmp;
    //* read the ouput state
    if ( (at91_pio_read ( &PIO_DESC) & LED3 ) == LED3 )
    {
        at91_pio_write ( &PIO_DESC, LED3, PIO_CLEAR_OUT );
    }
    else
    {
         at91_pio_write ( &PIO_DESC, LED3, PIO_SET_OUT );
    }
    // enable the next PIO IRQ
    tmp = PIO_DESC.pio_base->PIO_ISR ;
}

//*----------------------------------------------------------------------------
//* Function Name       : delay
//* Object              : Wait
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions called    : none
//*----------------------------------------------------------------------------
void delay ( void )
{
    u_int    i ;
//* loop delay
    for ( i = 0 ;(i < 100000);i++ ) ;
}

//*----------------------------------------------------------------------------
//* Function Name       : main
//* Object              : Main function of the led blink
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
int main( void )
//* Begin
{
    u_int   loop_count = 0 ;
//* Init
    //* define led at PIO output
    at91_pio_open ( &PIO_DESC, LED_MASK, PIO_OUTPUT );

     //* Init LED state
    at91_pio_write ( &PIO_DESC, LED_MASK, PIO_CLEAR_OUT );

    //* define switch SW4 at PIO input interupt PIO_OPENDRAIN_BIT
     at91_pio_open ( &PIO_DESC, SW4_MASK, PIO_INPUT_IRQ_BIT );

    //* open external PIO interrupt
    at91_irq_open(PIO_DESC.periph_id,4,AIC_SRCTYPE_INT_EDGE_TRIGGERED,pio_asm_irq_handler);

    //* open external IRQ interrupt
    at91_extirq_open(&IRQ0_DESC,5,AIC_SRCTYPE_INT_EDGE_TRIGGERED,ext_IRQ0_handler);

    //* open external FIQ interrupt
    at91_extirq_open(&FIQ_DESC,5,AIC_SRCTYPE_INT_EDGE_TRIGGERED,ext_FIQ_handler);

    //* Open the software interrupt on the AIC
    at91_irq_open ( SWIRQ_ID, 0, AIC_SRCTYPE_INT_EDGE_TRIGGERED, aic_sotfware_interrupt ) ;


//* generate interrupt by software
    at91_irq_trig_cmd(SWIRQ_ID,0);
    at91_irq_trig_cmd(FIQ_DESC.source_id,0);
    at91_irq_trig_cmd(IRQ0_DESC.source_id,0);
    at91_irq_trig_cmd(PIO_DESC.periph_id,0);

   for (;;)
    {
        at91_pio_write ( &PIO_DESC, LED1, PIO_CLEAR_OUT );

        delay () ;

        at91_pio_write ( &PIO_DESC, LED1, PIO_SET_OUT );

        delay () ;

        loop_count ++ ;
        //* Set LED by software interrupt
        if (loop_count == 100)
        {
             loop_count=0;
             at91_irq_trig_cmd(SWIRQ_ID,0);
        }
    }
    return(TRUE);
//* End
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -