📄 ateb40x_int.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 : ATEB40x_INT.c
//* Object : Led Blinking for the AT91EB40a, use interrupt
//* - PIO IRQ in SW4 TIOB
//* - IRQ0 in SW3
//* - FIQ in SW5
//* - SWIRQ
//*
//* 1.0 10/01/02 JPP : Creation
//*----------------------------------------------------------------------------
#include "parts/r40008/lib_r40008.h"
#include "EB40008.h"
//* Waiting time between LED1 and LED2
#define WAIT_TIME MCK
//* Global variable
int count_timer0_interrupt;
int count_timer1_interrupt;
// Use the Library Handler defined in file periph/pio/pio_irq/irq_pio.s
extern void pio_asm_irq_handler(void);
extern void irq0_asm_irq_handler(void);
extern void sw_asm_irq_handler(void);
extern void asm_fiq_init_handler(void);
extern void asm_fiq_handler(void);
extern int timer_init ( void );
//*----------------------------------------------------------------------------
//* Function Name : aic_sotfware_interrupt
//* Object : Sofware interup function
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : at91_pio_write
//*----------------------------------------------------------------------------
void aic_sotfware_interrupt(void)
{
//* read the ouput state
if ( (at91_pio_read ( &PIO_DESC) & LED4 ) == LED4 )
{
at91_pio_write ( &PIO_DESC, LED4, PIO_CLEAR_OUT );
}
else
{
at91_pio_write ( &PIO_DESC, LED4, PIO_SET_OUT );
}
}
//*----------------------------------------------------------------------------
//* 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 ;
//* while SW4 is push wait
while ( ( at91_pio_read ( &PIO_DESC) & SW4_MASK ) != SW4_MASK );
}
//*----------------------------------------------------------------------------
//* 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 < WAIT_TIME/100 );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 ;
//* Init
loop_count = 0 ;
//* 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,5,AIC_SRCTYPE_INT_EDGE_TRIGGERED,pio_asm_irq_handler);
//* open external IRQ interrupt
at91_extirq_open(&IRQ0_DESC,4,AIC_SRCTYPE_INT_EDGE_TRIGGERED,irq0_asm_irq_handler);
//* open external FIQ interrupt
//init FIQ register by Software test
at91_extirq_open(&FIQ_DESC,0,AIC_SRCTYPE_INT_EDGE_TRIGGERED,asm_fiq_init_handler);
at91_irq_trig_cmd(FIQ_DESC.source_id,0);
at91_extirq_open(&FIQ_DESC,0,AIC_SRCTYPE_INT_EDGE_TRIGGERED,asm_fiq_handler);
//* Open the software interrupt on the AIC
at91_irq_open ( SWIRQ_ID, 0, AIC_SRCTYPE_INT_EDGE_TRIGGERED, sw_asm_irq_handler ) ;
//* Init timer interrupt
timer_init();
//* generate interrupt by software
at91_irq_trig_cmd(SWIRQ_ID,0);
at91_irq_trig_cmd(PIO_DESC.periph_id,0);
//* note no generate this funtion because this interrupt clear the timer interrupt
//* at91_irq_trig_cmd(IRQ0_DESC.source_id,0);
for (;;)
{
at91_pio_write ( &PIO_DESC, LED1, PIO_CLEAR_OUT );
delay () ;
at91_pio_write ( &PIO_DESC, LED2, PIO_CLEAR_OUT );
delay () ;
at91_pio_write ( &PIO_DESC, LED1, PIO_SET_OUT);
delay () ;
at91_pio_write ( &PIO_DESC, LED2, PIO_SET_OUT );
delay () ;
loop_count ++ ;
//* Set LED by software interrupt
if (loop_count == 10)
{
loop_count=0;
//* Software interrupt
at91_irq_trig_cmd(SWIRQ_ID,0);
}
}
return(TRUE);
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -