/*---------------------------------------------------------------------------------------------------------*/
/* GPIO Interrupt Type Constant Definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define GPIO_INT_RISING 0x00010000UL /*!< Interrupt enable by Input Rising Edge */
#define GPIO_INT_FALLING 0x00000001UL /*!< Interrupt enable by Input Falling Edge */
#define GPIO_INT_BOTH_EDGE 0x00010001UL /*!< Interrupt enable by both Rising Edge and Falling Edge */
#define GPIO_INT_HIGH 0x01010000UL /*!< Interrupt enable by Level-High */
#define GPIO_INT_LOW 0x01000001UL /*!< Interrupt enable by Level-Level */
一共5个中断类型。
void GPIO_EnableInt(GPIO_T *port, uint32_t u32Pin, uint32_t u32IntAttribs);
void GPIO_DisableInt(GPIO_T *port, uint32_t u32Pin);
两个函数用于开启或关闭,开启时候有开启的类型,就是上面五种,
我们看例子。
/* Configure P3.2 as EINT0 pin and enable interrupt by falling edge trigger */
GPIO_SetMode(P3, BIT2, GPIO_PMD_INPUT);
GPIO_EnableEINT0(P3, 2, GPIO_INT_FALLING);
NVIC_EnableIRQ(EINT0_IRQn);
/* Configure P3.3 as EINT1 pin and enable interrupt by rising and falling edge trigger */
GPIO_SetMode(P3, BIT3, GPIO_PMD_INPUT);
GPIO_EnableEINT1(P3, 3, GPIO_INT_BOTH_EDGE);
NVIC_EnableIRQ(EINT1_IRQn);
我们看到想用中断,要先配置为输入模式。
之后使能中断,然后通过NVIC中断嵌套控制器,使能中断。
为何前面写的使能中断的名称不一样的,其实内涵是一样的,
#define GPIO_EnableEINT1 GPIO_EnableInt
看到没,都是通过宏定义到了一个函数里。
那么NVIC的控制使能呢?
NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(EINT1_IRQn);
关于这两个函数,可以在
core_cm0.h找到,如下所示
/** \brief Enable External Interrupt
The function enables a device-specific interrupt in the NVIC interrupt controller.
\param [in] IRQn External interrupt number. Value cannot be negative.
*/
__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn)
{
NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F));
}
——————————————————
由此可知,这个IRQn_Type IRQn参数,其实就是个中断类型。
我们看手册可知
大家知道那个名字怎么来的了吧。
定义在文件M051Series.h
typedef enum IRQn
{
/****** Cortex-M0 Processor Exceptions Numbers ***************************************************/
NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
HardFault_IRQn = -13, /*!< 3 Cortex-M0 Hard Fault Interrupt */
SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */
PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */
SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */
/****** ARMIKMCU Swift specific Interrupt Numbers ************************************************/
BOD_IRQn = 0, /*!< Brown-Out Low Voltage Detected Interrupt */
WDT_IRQn = 1, /*!< Watch Dog Timer Interrupt */
EINT0_IRQn = 2, /*!< EINT0 Interrupt */
EINT1_IRQn = 3, /*!< EINT1 Interrupt */
GPIO_P0P1_IRQn = 4, /*!< GPIO_P0P1 Interrupt */
GPIO_P2P3P4_IRQn = 5, /*!< GPIO_P2P3P4 Interrupt */
PWMA_IRQn = 6, /*!< PWMA Interrupt */
PWMB_IRQn = 7, /*!< PWMB Interrupt */
TMR0_IRQn = 8, /*!< TIMER0 Interrupt */
TMR1_IRQn = 9, /*!< TIMER1 Interrupt */
TMR2_IRQn = 10, /*!< TIMER2 Interrupt */
TMR3_IRQn = 11, /*!< TIMER3 Interrupt */
UART0_IRQn = 12, /*!< UART0 Interrupt */
UART1_IRQn = 13, /*!< UART1 Interrupt */
SPI0_IRQn = 14, /*!< SPI0 Interrupt */
SPI1_IRQn = 15, /*!< SPI1 Interrupt */
I2C0_IRQn = 18, /*!< I2C0 Interrupt */
I2C1_IRQn = 19, /*!< I2C1 Interrupt */
ACMP01_IRQn = 25, /*!< ACMP0/1 Interrupt */
ACMP23_IRQn = 26, /*!< ACMP2/3 Interrupt */
PWRWU_IRQn = 28, /*!< Power Down Wake Up Interrupt */
ADC_IRQn = 29 /*!< ADC Interrupt */
} IRQn_Type;
|