标题:
FreeRTOS CortexM3 M4中断优先级设置总结
[打印本页]
作者:
yuchengze
时间:
2017-6-22 16:46
标题:
FreeRTOS CortexM3 M4中断优先级设置总结
前言
本文将说明在
FreeRTOS
嵌入式操作系统中,如何设置STM32 Cortex M3和
M4
系列MCU的
中断优先级
。
总结
【1】STM32L1系列,STM32F1系列,STM32F4系列,设置NVIC时需要使用NVIC_PriorityGroup_4。
【2】抢占优先级的要比“MAX”更大,而比“LOWEST”更小。例如
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY=5
configLIBRARY_LOWEST_INTERRUPT_PRIORITY=15
那么NVIC抢占优先级设置的具体值应该比MAX=5更大(包括等于),比LOWEST=15更小(包括等于),也就是说5,6,7,8,9,10,11,12,13,14,15肯定是合法值。
【3】FreeRTOS中,数值越大优先级越高,这种优先级可以成为逻辑优先级。Cortex M3/M4中断中,数值越大优先级越低,这种优先级成为中断优先级。两者相反,所以才会出现比"MAX"更大而比“LOWEST”更小的情况。
示意代码
【FreeRTOSConfig.h】
/* Use the system definition, if there is one */
#ifdef __NVIC_PRIO_BITS
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4 /* 15 priority levels */
#endif
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 15
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
/* The lowest priority. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Priority 5, or 95 as only the top four bits are implemented. */
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See
http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html.
*/
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
【NVIC设置】
【示例A】
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = XXXX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
【示例A】
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure.NVIC_IRQChannel = XXXX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY-1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
参考博文
【FreeRTOS STM32移植笔记】
【FreeRTOS学习笔记——任务间使用队列同步数据】
【FreeRTOS学习笔记——二值型信号量】
【FreeRTOS学习笔记——互斥型信号量】
【如何在FreeRTOS下实现低功耗——MSP430F5438平台】
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0