Cortex-M3 异常和中断---基于NXP LPC177x/8x(6)
- UID
- 1029342
- 性别
- 男
|
Cortex-M3 异常和中断---基于NXP LPC177x/8x(6)
2.2.1 设置优先级寄存器组的C代码 1: /** 2: * @brief Set the Priority Grouping in NVIC Interrupt Controller 3: * 4: * @param PriorityGroup is priority grouping field 5: * 6: * Set the priority grouping field using the required unlock sequence. 7: * The parameter priority_grouping is assigned to the field 8: * SCB->AIRCR [10:8] PRIGROUP field. Only values from 0..7 are used. 9: * In case of a conflict between priority grouping and available 10: * priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. 11: */ 12: static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) 13: { 14: uint32_t reg_value; 15: /* only values 0..7 are used */ 16: uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); 17: 18: reg_value = SCB->AIRCR; /* read old register configuration */ 19: /* clear bits to change */ 20: reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); 21: /* Insert write key and priorty group */ 22: reg_value = (reg_value | 23: (0x5FA << SCB_AIRCR_VECTKEY_Pos) | 24: (PriorityGroupTmp << 8)); 25: SCB->AIRCR = reg_value; 26: }
其中,参数PriorityGroup为要设置的优先级分组(PRIGROUP)段的值,取值范围为0~7.由于操作AIRCR寄存器需要访问钥匙,所以要把0x05FA写入到该寄存器的bit[31:16]中,否则写入的值会被忽略。
需要注意的是,在一个设计好的产品中,如果没有十足的把握,不要修改优先级组,不然会有大恶魔纠缠你的。
最后,本文所使用的代码,全部由CMSIS-M3提供。 |
|
|
|
|
|