📄 irq main.c
字号:
// ----------------------------------------------------------------------------
// ATMEL Microcontroller Software Support - ROUSSET -
// ----------------------------------------------------------------------------
// DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name : main.c
// Object : main application written in C
// Creation : JPP 08-Sep-2005
// ----------------------------------------------------------------------------
// Include Standard LIB files
#include "project.h"
//* Waiting time between AT91B_LED1 and AT91B_LED2
#define WAIT_TIME AT91B_MCK
#define KEY_CLK 1<<20//board PA22
#define KEY_DATA 1<<22 //board PA24
#define PIO_INTERRUPT_LEVEL 6
#define SOFT_INTERRUPT_LEVEL 2
#define FIQ_INTERRUPT_LEVEL 7 // Always high
//* 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 FIQ_init_handler(void);
// External Function Prototype
extern void timer_init (void );
extern void Usart_init (void);
extern void AT91F_DBGU_Init (void);
extern void AT91F_DBGU_Printk(char *buffer) ;
char strprint[30] = {0};
int i_data_number = 0;
//*----------------------------------------------------------------------------
//* Function Name : key_interrupt_handle
//* Object : Software interrupt function
//* CLK
//*----------------------------------------------------------------------------
void f6_delay(int num){
int i= 0;
for ( i = 0 ;i < num;i++ ) ;
}
//*----------------------------------------------------------------------------
//* Function Name : aic_software_interrupt
//* Object : Software interrupt function
//*----------------------------------------------------------------------------
void aic_software_interrupt(void)
{
//* Read the output state
if ( (AT91F_PIO_GetInput(AT91D_BASE_PIO_LED) & AT91B_LED2 ) == AT91B_LED2 )
{
AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, AT91B_LED2 );
}
}
//*----------------------------------------------------------------------------
//* Function Name : pio_c_irq_handler
//* Object : Irq Handler calAT91B_LED by the irq_pio.s
//*----------------------------------------------------------------------------
void pio_c_irq_handler ( void )
{
int dummy;
//* Read the output state
if ( (AT91F_PIO_GetInput(AT91D_BASE_PIO_LED) & AT91B_LED1 ) == AT91B_LED1 )
{
AT91F_PIO_ClearOutput( AT91D_BASE_PIO_LED, AT91B_LED1);
} else {
AT91F_PIO_SetOutput( AT91D_BASE_PIO_LED, AT91B_LED1);
}
//* enable the next PIO IRQ
dummy =AT91D_BASE_PIO_SW->PIO_ISR;
//* suppress the compilation warning
dummy =dummy;
//* while SW3 is push wait
while ( (AT91F_PIO_GetInput(AT91D_BASE_PIO_SW) & AT91B_BP2 ) != AT91B_BP2 );
}
void key_interrupt_handle(void){
// int i_data_number = 0;
int j_parity = 0;
int i_num =0;
int over_time = 0;
unsigned char over_time_mask = 0;
int read_data = 0;
int key_data = 0;
unsigned char be_wrong = 0;
int dummy;
AT91F_DBGU_Printk("\r\n\r\nMASK:");
AT91F_DBGU_Printk("key_interrupt_handle\r\n");
// AT91F_PIO_InterruptDisable(AT91C_BASE_PIOA,KEY_CLK);
/* while(1){
//等待时钟端口为高电平
while((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & KEY_CLK)==0){
//时间控制,避免死循环
over_time++;
if(over_time>CONTROL_TIME)break;
}
//时间控制,避免死循环
if(over_time>CONTROL_TIME){over_time_mask = 1;break;}
over_time=0;
*/
//读数据端口
read_data = (AT91F_PIO_GetInput(AT91D_BASE_PIO_SW) & KEY_DATA)>>22;
i_data_number++;
sprintf(strprint,"read_data is %x.\r\n",read_data);
AT91F_DBGU_Printk(strprint);
sprintf(strprint,"i_data_number is %x.\r\n",i_data_number);
AT91F_DBGU_Printk(strprint);
//等待时钟端口为高电平
while((AT91F_PIO_GetInput(AT91D_BASE_PIO_SW) & KEY_CLK)==0){
//时间控制,避免死循环
over_time++;
if(over_time>CONTROL_TIME)break;
}
//时间控制,避免死循环
// if(over_time>CONTROL_TIME){over_time_mask = 2;break;}
// over_time=0;
// }
// f6_delay(500);
//* enable the next PIO IRQ
// dummy =AT91D_BASE_PIO_SW->PIO_ISR;
//* suppress the compilation warning
// dummy =dummy;
if(over_time>CONTROL_TIME){
sprintf(strprint,"over_time_mask is %x.\r\n",over_time_mask);
AT91F_DBGU_Printk(strprint);
}
// AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA,KEY_CLK);
AT91F_DBGU_Printk("end key_interrupt_handle\r\n");
}
//*----------------------------------------------------------------------------
//* Function Name : delay
//* Object : Wait
//*----------------------------------------------------------------------------
void delay ( void )
{
//* Set in Volatile for Optimisation
volatile unsigned int i ;
//* loop delay
for ( i = 0 ;(i < WAIT_TIME/100 );i++ ) ;
}
//*----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main interrupt function
//*----------------------------------------------------------------------------
int main( void )
//* Begin
{
unsigned int loop_count ;
AT91PS_AIC pAic;
//* Load System pAic Base address
pAic = AT91C_BASE_AIC;
//* Enable User Reset and set its minimal assertion to 960 us
AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24);
//add by suminhua 2007-5-29 for debug
AT91F_DBGU_Init();
AT91F_DBGU_Printk("START:\r\n");
loop_count = 0 ;
// First, enable the clock of the PIO for led and PIO for Switch
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91D_ID_PIO_LED ) ;
AT91F_PIO_CfgInput(AT91D_BASE_PIO_SW, KEY_DATA );
AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_IRQ0,
FIQ_INTERRUPT_LEVEL,
AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL,
key_interrupt_handle);
AT91F_AIC_EnableIt (pAic, AT91C_ID_IRQ0);
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -