ARM 中断函数定义
2018-12-19 来源:eefocus
ARM的中断函数是在startup code中定义的,在CODE区分配中断向量表时,及将中断函数定义出了
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD GPIO0_IRQHandler ; GPIO P0 Interrupt
DCD GPIO1_IRQHandler ; GPIO P1 Interrupt
DCD GPIO2_IRQHandler ; GPIO P2 Interrupt
DCD GPIO3_IRQHandler ; GPIO P3 Interrupt
DCD GPIO4_IRQHandler ; GPIO P4 Interrupt
DCD CP_IRQHandler ; Capture/PWM
DCD ADC_IRQHandler ; A/D Converter
DCD Reserved_IRQHandler ; Reserved
DCD Reserved_IRQHandler ; Reserved
DCD Reserved_IRQHandler ; Reserved
DCD Reserved_IRQHandler ; Reserved
DCD Reserved_IRQHandler ; Reserved
DCD Reserved_IRQHandler ; Reserved
DCD Reserved_IRQHandler ; Reserved
DCD Reserved_IRQHandler ; Reserved
DCD UART0_IRQHandler ; UART0
DCD UART1_IRQHandler ; UART1
DCD UART2_IRQHandler ; UART2
DCD UART3_IRQHandler ; UART3
DCD TIMER0_IRQHandler ; Timer0
DCD TIMER1_IRQHandler ; Timer1
DCD TIMER2_IRQHandler ; Timer2
DCD TIMER3_IRQHandler ; Timer3
DCD WDT_IRQHandler ; Watchdog timer
DCD I2C0_IRQHandler ; I2C0
DCD I2C1_IRQHandler ; I2C1
DCD SSP0_IRQHandler ; SSP0
DCD SSP1_IRQHandler ; SSP1
DCD TIMER01_IRQHandler ; Timer0 & Timer1
DCD TIMER23_IRQHandler ; Timer2 & Timer3
DCD Reserved_IRQHandler ; Reserved
DCD Reserved_IRQHandler ; Reserved
AREA |.text|, CODE, READONLY
不同芯片有各自的startup code,所以定义不同。
在startup code中定义的中断函数都是[weak]属性,如果编译器在别的文件中发现相同的函数名,则在链接时用别处的地址进行链接。
所以只要在工程的具体位置,按startup code中定义的名称直接完整该函数即可,不用在特别声明和与中断向量号联系起来。
Default_Handler PROC
EXPORT GPIO0_IRQHandler [WEAK]
EXPORT GPIO1_IRQHandler [WEAK]
EXPORT GPIO2_IRQHandler [WEAK]
EXPORT GPIO3_IRQHandler [WEAK]
EXPORT GPIO4_IRQHandler [WEAK]
EXPORT CP_IRQHandler [WEAK]
EXPORT ADC_IRQHandler [WEAK]
EXPORT SSP0RXINT_IRQHandler [WEAK]
EXPORT SSP0TXINT_IRQHandler [WEAK]
EXPORT SSP0RORINT_IRQHandler [WEAK]
EXPORT SSP0RTINT_IRQHandler [WEAK]
EXPORT SSP1RXINT_IRQHandler [WEAK]
EXPORT SSP1TXINT_IRQHandler [WEAK]
EXPORT SSP1RORINT_IRQHandler [WEAK]
EXPORT SSP1RTINT_IRQHandler [WEAK]
EXPORT UART0_IRQHandler [WEAK]
EXPORT UART1_IRQHandler [WEAK]
EXPORT UART2_IRQHandler [WEAK]
EXPORT UART3_IRQHandler [WEAK]
EXPORT TIMER0_IRQHandler [WEAK]
EXPORT TIMER1_IRQHandler [WEAK]
EXPORT TIMER2_IRQHandler [WEAK]
EXPORT TIMER3_IRQHandler [WEAK]
EXPORT WDT_IRQHandler [WEAK]
EXPORT I2C0_IRQHandler [WEAK]
EXPORT I2C1_IRQHandler [WEAK]
EXPORT SSP0_IRQHandler [WEAK]
EXPORT SSP1_IRQHandler [WEAK]
EXPORT TIMER01_IRQHandler [WEAK]
EXPORT TIMER23_IRQHandler [WEAK]
在具体的.c文件中
/*---------------------------------------------------------------------------------------------------------*/
/* Interrupt Handler */
/*---------------------------------------------------------------------------------------------------------*/
void I2C0_IRQHandler(void)
{
uint32_t status;
status = I2C0->STAT;
switch (status)
{
/* Arbitration loss */
case 0x38:
if (I2CHandler[0].ArbitLossCallBackFn)
I2CHandler[0].ArbitLossCallBackFn(status);
break;
/* Bus error */
case 0x00:
if (I2CHandler[0].BusErrCallBackFn)
I2CHandler[0].BusErrCallBackFn(status);
break;
default:
if (I2CHandler[0].I2CCallBackFn)
I2CHandler[0].I2CCallBackFn(status);
break;
}
}
上一篇:ARM中断向量程序实例