程序中调用NVIC_GetPriority以获取几个中断的优先级,结果有的中断获取值显示异常:
程序如下:
中断设置:
#define __NVIC_PRIO_BITS 2
NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(GPAB_IRQn);
NVIC_EnableIRQ(GPCDF_IRQn);
NVIC_SetPriority (EINT0_IRQn, 1);
NVIC_SetPriority (GPAB_IRQn, 2);
NVIC_SetPriority (GPCDF_IRQn, 3);
/*
typedef enum IRQn
{
...
SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */
...
EINT0_IRQn = 2, /*!< EINT0 Interrupt */
EINT1_IRQn = 3, /*!< EINT1 Interrupt */
GPAB_IRQn = 4, /*!< GPIO_PA/PB Interrupt */
GPCDF_IRQn = 5, /*!< GPIO_PC/PD/PF Interrupt */
...
}
*/
获取中断优先级:
int a = 0;
a=NVIC_GetPriority(GPAB_IRQn);
printf("AB irq=%d\r\n", a);
a = NVIC_GetPriority(GPCDF_IRQn);
printf("CDF irq=%d\r\n", a);
a = NVIC_GetPriority(EINT0_IRQn);
printf("EINT0 irq=%d\r\n", a);
a = NVIC_GetPriority(SysTick_IRQn);
printf("SysTick_IRQn irq=%d\r\n", a);
结果:
AB irq=770
CDF irq=3
EINT0 irq=1
SysTick_IRQn irq=0
可见:AB port优先级异常
仔细看了下获取接口:
__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn)
{
if(IRQn < 0) {
return((uint32_t)((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */
else {
return((uint32_t)((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */
}
这部分其实是arm cortex m3统一的接口,又看了新唐datasheet有关nvic中断优先级的设定寄存器:
可见是因为在获取的优先级中没有再对所要查询接口优先级做掩码操作所致
(770即0x0302: 低2位即表示AB port优先组,3表示的是CDF port优先级)
改为: a=NVIC_GetPriority(GPAB_IRQn) &0x03; 即可
不过最好的,掩码操作应该在接口中添加,不知道为什么arm提供的接口中没这么做,而且在网上居然没查到别人有反馈这样的问题
|