📄 interrupt_eb42.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 : interrupt_eb42.c
//* Object : Led Blinking for the AT91EB42, use interrupt
//* - PIO IRQ on SW4 TIOB
//* - IRQ0 on SW3
//* - FIQ on SW5
//* - SWIRQ
//*
//* 1.0 10/01/02 JPP : Creation
//*----------------------------------------------------------------------------
#include "parts/m42800/lib_m42800.h"
#include "targets/eb42/eb42.h"
#include "periph/timer_counter/lib_tc.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 ( &PIOB_DESC) & LED4 ) == LED4 )
{
at91_pio_write ( &PIOB_DESC, LED4, PIO_CLEAR_OUT );
}
else
{
at91_pio_write ( &PIOB_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 ( &PIOB_DESC) & LED3 ) == LED3 )
{
at91_pio_write ( &PIOB_DESC, LED3, PIO_CLEAR_OUT );
}
else
{
at91_pio_write ( &PIOB_DESC, LED3, PIO_SET_OUT );
}
// enable the next PIO IRQ
tmp = PIOB_DESC.pio_base->PIO_ISR ;
//* while SW4 is push wait
while ( ( at91_pio_read ( &PIOB_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 ( &PIOB_DESC, LED_MASK, PIO_OUTPUT );
//* Init LED state
at91_pio_write ( &PIOB_DESC, LED_MASK, PIO_CLEAR_OUT );
//* define switch SW4 at PIO input interupt PIO_OPENDRAIN_BIT
at91_pio_open ( &PIOB_DESC, SW4_MASK, PIO_INPUT_IRQ_BIT );
//* open external PIO interrupt
at91_irq_open(PIOB_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 ( SW_ID, 0, AIC_SRCTYPE_INT_EDGE_TRIGGERED, sw_asm_irq_handler ) ;
//* Init timer interrupt
timer_init();
//* generate interrupt by software
at91_irq_trig_cmd(SW_ID,0);
at91_irq_trig_cmd(PIOB_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 ( &PIOB_DESC, LED1, PIO_CLEAR_OUT );
delay () ;
at91_pio_write ( &PIOB_DESC, LED2, PIO_CLEAR_OUT );
delay () ;
at91_pio_write ( &PIOB_DESC, LED1, PIO_SET_OUT);
delay () ;
at91_pio_write ( &PIOB_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(SW_ID,0);
}
}
return(TRUE);
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -