学习KEA之中断系统

这篇 学习KEA之周期中断定时器PIT 已经使用了定时中断,本篇将归纳一下中断系统的操作。

中断向量表

KEA系列是Arm® Cortex®-M0+,最多有48个中断。

比如在SKEAZN642.h中,定义了中断向量表,数字越小的中断,表明默认的中断优先级是越高的:

typedef enum IRQn {
  /* Core interrupts */
  NonMaskableInt_IRQn          = -14,              /**< Non Maskable Interrupt */
  HardFault_IRQn               = -13,              /**< Cortex-M0 SV Hard Fault Interrupt */
  SVCall_IRQn                  = -5,               /**< Cortex-M0 SV Call Interrupt */
  PendSV_IRQn                  = -2,               /**< Cortex-M0 Pend SV Interrupt */
  SysTick_IRQn                 = -1,               /**< Cortex-M0 System Tick Interrupt */

  /* Device specific interrupts */
  Reserved16_IRQn              = 0,                /**< Reserved interrupt 16 */
  Reserved17_IRQn              = 1,                /**< Reserved interrupt 17 */
  Reserved18_IRQn              = 2,                /**< Reserved interrupt 18 */
  Reserved19_IRQn              = 3,                /**< Reserved interrupt 19 */
  Reserved20_IRQn              = 4,                /**< Reserved interrupt 20 */
  FTMRH_IRQn                   = 5,                /**< FTMRH command complete and error interrupt */
  LVD_LVW_IRQn                 = 6,                /**< Low-voltage warning */
  IRQ_IRQn                     = 7,                /**< External interrupt */
  I2C0_IRQn                    = 8,                /**< I2C0 single interrupt vector for all sources */
  Reserved25_IRQn              = 9,                /**< Reserved interrupt 25 */
  SPI0_IRQn                    = 10,               /**< SPI0 single interrupt vector for all sources */
  SPI1_IRQn                    = 11,               /**< SPI1 single interrupt vector for all sources */
  UART0_IRQn                   = 12,               /**< UART0 status and error */
  UART1_IRQn                   = 13,               /**< UART1 status and error */
  UART2_IRQn                   = 14,               /**< UART2 status and error */
  ADC0_IRQn                    = 15,               /**< ADC conversion complete interrupt */
  ACMP0_IRQn                   = 16,               /**< ACMP0 interrupt */
  FTM0_IRQn                    = 17,               /**< FTM0 single interrupt vector for all sources */
  FTM1_IRQn                    = 18,               /**< FTM1 single interrupt vector for all sources */
  FTM2_IRQn                    = 19,               /**< FTM2 single interrupt vector for all sources */
  RTC_IRQn                     = 20,               /**< RTC overflow */
  ACMP1_IRQn                   = 21,               /**< ACMP1 interrupt */
  PIT_CH0_IRQn                 = 22,               /**< PIT CH0 overflow */
  PIT_CH1_IRQn                 = 23,               /**< PIT CH1 overflow */
  KBI0_IRQn                    = 24,               /**< KBI0 interrupt */
  KBI1_IRQn                    = 25,               /**< KBI1 interrupt */
  Reserved42_IRQn              = 26,               /**< Reserved interrupt 42 */
  ICS_IRQn                     = 27,               /**< Clock loss of lock */
  WDOG_EWM_IRQn                = 28,               /**< Watchdog timeout */
  Reserved45_IRQn              = 29,               /**< Reserved interrupt 45 */
  Reserved46_IRQn              = 30,               /**< Reserved interrupt 46 */
  Reserved47_IRQn              = 31                /**< Reserved interrupt 47 */
} IRQn_Type;

中断的使用步骤

  • init_IRQs
// 这三个是在core_cm0plus.h中定义:
NVIC_ClearPendingIRQ(PIT_CH1_IRQn);  /* Clear any Pending IRQ for all PIT ch1 (#23) */
NVIC_EnableIRQ(PIT_CH1_IRQn);        /* Set Enable IRQ for PIT_CH1 */
NVIC_SetPriority(PIT_CH1_IRQn, 0);    /* Set Priority for PIT_CH1 */
  • 到相应的控制寄存器中开启中断
    学习KEA之中断系统_第1张图片
  • 中断服务程序
    • 清除相应的中断标志位 (可选)
void PIT_CH1_IRQHandler (void)
{
	PIT_TFLG1 |= PIT_TFLG_TIF_MASK; /* Clear PIT1 flag */

	/* 应用程序 */
}

从上面可以看到,中断服务程序的名称的规则是一般是这样:

  • 先在中断向量表中找到相应的中断向量PIT_CH1_IRQn
  • 然后提取前缀PIT_CH1
  • 最后和IRQHandler结合,就是中断服务程序的名称 PIT_CH1_IRQHandler。

一些中断服务程序的名称的汇总:

  • FTM2_IRQHandler
  • PIT_CH1_IRQHandler
  • KBI1_IRQHandler
  • UART2_IRQHandle
  • ADC_IRQHandler

OVER~~

你可能感兴趣的:(KEA)