tm4c123g中断优先级怎么设置
答案:1 悬赏:0 手机版
解决时间 2021-02-16 03:33
- 提问者网友:半生酒醒
- 2021-02-15 17:33
tm4c123g中断优先级怎么设置
最佳答案
- 五星知识达人网友:过活
- 2021-02-15 18:15
设置中断优先级的函数,CMISIS已经写好,并嵌入到了编译器中,例如,我们用KEIL开发的话,设置中断优先级的函数位于core_cm0.h文件当中,函数如下所示:
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if(IRQn < 0) {
SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
else {
NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
}
从上面函数可以看出,该函数有两个参数,IRQn是指要设置的中断向量,priority是中断优先级,优先级可以是0 1 2 3四个数,0的优先级最大,3的优先级最小。假设你要设置GPIO1中断的优先级最高,那么就是:
NVIC_SetPriority(EINT1_IRQn, 0);
这时,有人会问,”EINT1_IRQn”
答:这个可以在LPC11xx.h文件当中找到,如下所示:
typedef enum IRQn
{
Reset_IRQn = -15,
NonMaskableInt_IRQn = -14,
HardFault_IRQn = -13,
SVCall_IRQn = -5,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
WAKEUP0_IRQn = 0,
WAKEUP1_IRQn = 1,
WAKEUP2_IRQn = 2,
WAKEUP3_IRQn = 3,
WAKEUP4_IRQn = 4,
WAKEUP5_IRQn = 5,
WAKEUP6_IRQn = 6,
WAKEUP7_IRQn = 7,
WAKEUP8_IRQn = 8,
WAKEUP9_IRQn = 9,
WAKEUP10_IRQn = 10,
WAKEUP11_IRQn = 11,
WAKEUP12_IRQn = 12,
CAN_IRQn = 13,
SSP1_IRQn = 14,
I2C_IRQn = 15,
TIMER_16_0_IRQn = 16,
TIMER_16_1_IRQn = 17,
TIMER_32_0_IRQn = 18,
TIMER_32_1_IRQn = 19,
SSP0_IRQn = 20,
UART_IRQn = 21,
Reserved0_IRQn = 22,
Reserved1_IRQn = 23,
ADC_IRQn = 24,
WDT_IRQn = 25,
BOD_IRQn = 26,
FMC_IRQn = 27,
EINT3_IRQn = 28,
EINT2_IRQn = 29,
EINT1_IRQn = 30,
EINT0_IRQn = 31,
} IRQn_Type;
__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if(IRQn < 0) {
SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
else {
NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) |
(((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); }
}
从上面函数可以看出,该函数有两个参数,IRQn是指要设置的中断向量,priority是中断优先级,优先级可以是0 1 2 3四个数,0的优先级最大,3的优先级最小。假设你要设置GPIO1中断的优先级最高,那么就是:
NVIC_SetPriority(EINT1_IRQn, 0);
这时,有人会问,”EINT1_IRQn”
答:这个可以在LPC11xx.h文件当中找到,如下所示:
typedef enum IRQn
{
Reset_IRQn = -15,
NonMaskableInt_IRQn = -14,
HardFault_IRQn = -13,
SVCall_IRQn = -5,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
WAKEUP0_IRQn = 0,
WAKEUP1_IRQn = 1,
WAKEUP2_IRQn = 2,
WAKEUP3_IRQn = 3,
WAKEUP4_IRQn = 4,
WAKEUP5_IRQn = 5,
WAKEUP6_IRQn = 6,
WAKEUP7_IRQn = 7,
WAKEUP8_IRQn = 8,
WAKEUP9_IRQn = 9,
WAKEUP10_IRQn = 10,
WAKEUP11_IRQn = 11,
WAKEUP12_IRQn = 12,
CAN_IRQn = 13,
SSP1_IRQn = 14,
I2C_IRQn = 15,
TIMER_16_0_IRQn = 16,
TIMER_16_1_IRQn = 17,
TIMER_32_0_IRQn = 18,
TIMER_32_1_IRQn = 19,
SSP0_IRQn = 20,
UART_IRQn = 21,
Reserved0_IRQn = 22,
Reserved1_IRQn = 23,
ADC_IRQn = 24,
WDT_IRQn = 25,
BOD_IRQn = 26,
FMC_IRQn = 27,
EINT3_IRQn = 28,
EINT2_IRQn = 29,
EINT1_IRQn = 30,
EINT0_IRQn = 31,
} IRQn_Type;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯