📄 interrupt.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.c
//* Object : Led Blinking for the AT91EB63, use interrupt
//* - PIO IRQ in SW1 TIOB
//* - IRQ0 in SW4
//*
//* - SWIRQ
//* - getb result on USART 0
//*
//* 1.0 30/08/01 JPP : Creation
//*----------------------------------------------------------------------------
#include "parts/m63200/lib_m63200.h"
#include "targets/eb63/eb63.h"
#include "drivers/com/com.h"
#include <stdio.h>
//* Global variable
int count_timer0_interrupt;
int count_timer1_interrupt;
int count_PIO_interrupt;
int count_software_interrupt;
#define MCKI 25000000
#define BAUD_RATE 38400
char message[512];
ComDesc COM;
static const char atmel_header[]=
{
"\n\r *** ATMEL Interrupt Example for EB63 ***\n\r"
"Copyright (C) 2001 ATMEL V 1.0\n\r"
};
// 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)
{
at91_pio_write ( &PIOB_DESC, LED3|LED2|LED1, PIO_SET_OUT );
count_software_interrupt++;
}
//*----------------------------------------------------------------------------
//* 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;
int len;
//* read the ouput state
len = sprintf(message,"PIO:%d\n\r",count_PIO_interrupt);
at91_print_frame(&COM,message,len);
count_PIO_interrupt++;
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 SW3 is push wait in interrupt runtime
while ( ( at91_pio_read ( &PIOB_DESC) & SW2_MASK ) != SW2_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 < 100000);i++ ) ;
}
//*----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main function of the led blink
//* Input Parameters : none
//* Output Parameters : TRUE
//*----------------------------------------------------------------------------
int main( void )
//* Begin
{
u_short cd_baud;
u_int loop_count = 0 ;
u_int len;
//* Init
count_PIO_interrupt=0;
count_software_interrupt=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 SW3 at PIO input interupt
at91_pio_open ( &PIOB_DESC, SW2_MASK | SW3_MASK , PIO_INPUT );
//* define switch SW4 at PIO input interupt
at91_pio_open ( &PIOB_DESC, SW1_MASK, PIO_INPUT_IRQ_BIT );
//* open terminal for console
COM.usart=&USART1_DESC;
cd_baud = at91_baud_com(MCKI, BAUD_RATE);
//* open com
at91_open_com(&COM,(COM_8_BIT|COM_PAR_NONE|COM_NBSTOP_1|COM_FLOW_CONTROL_NONE), cd_baud);
at91_print_frame(&COM,(char *)atmel_header,sizeof(atmel_header));
//* open external PIO interrupt
at91_irq_open(PIOB_DESC.periph_id,5,AIC_SRCTYPE_INT_EDGE_TRIGGERED,pio_asm_irq_handler);
//* Enable the PIO Clock
at91_clock_open (PIOB_DESC.periph_id ) ;
//* open external IRQ interrupt
//* define switch SW4 at PIO input interupt
at91_pio_close ( &PIOA_DESC, SW4_MASK);
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(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, LED7, PIO_CLEAR_OUT );
delay () ;
at91_pio_write ( &PIOB_DESC, LED8, PIO_CLEAR_OUT );
delay () ;
at91_pio_write ( &PIOB_DESC, LED7, PIO_SET_OUT );
delay () ;
at91_pio_write ( &PIOB_DESC, LED8, PIO_SET_OUT );
delay () ;
//* while SW2 is push wait in interrupt runtime
if (( at91_pio_read ( &PIOB_DESC) & SW3_MASK) != SW3_MASK )
{
len = sprintf(message,"SW 1 timer 0:%d timer 1:%d\n\r PIO:%d software:%d\n\r",
count_timer0_interrupt,count_timer1_interrupt,count_PIO_interrupt,count_software_interrupt);
at91_print_frame(&COM,message,len);
}
loop_count ++ ;
//* Set LED by software interrupt
if (loop_count == 100)
{
loop_count=0;
//* Software interrupt
at91_irq_trig_cmd(SWIRQ_ID,0);
len = sprintf(message," Software interrupt:%d\n\r",count_software_interrupt);
at91_print_frame(&COM,message,len);
}
}
return(TRUE);
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -