STM32与FreeRTOS学习备忘,xSemaphoreGiveFromISR

来源:互联网 发布:java编写信息管理系统 编辑:程序博客网 时间:2024/05/29 13:45

在学习FreeRTOS的时候,使用中断释放信号量时,出现了问题。

中断函数卡在xSemaphoreGiveFromISR();函数里了,具体是卡在portASSERT_IF_INTERRUPT_PRIORITY_INVALID();里。


根据注释查看http://www.freertos.org/RTOS-Cortex-M3-M4.html,里面有两点点出关键。

1.

Most systems default to the wanted configuration, with the noticeable exception of the STM32 driver library. If you are using an STM32 with the STM32 driver library then ensure all the priority bits are assigned to be preempt priority bits by calling NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); before the RTOS is started.

意味着选中断分组时只能选preempt为4bit,sub为0bit,即preemption范围0~15,sub priority范围为0


2.

Relevance when using the RTOS

FreeRTOS functions that end in "FromISR" are interrupt safe, but even these functions cannot be called from interrupts that have a logical priority above the priority defined by configMAX_SYSCALL_INTERRUPT_PRIORITY (configMAX_SYSCALL_INTERRUPT_PRIORITY is defined in the FreeRTOSConfig.h header file). Therefore, any interrupt service routine that uses an RTOS API function must have its priority manually set to a value that is numerically equal to or greater than the configMAX_SYSCALL_INTERRUPT_PRIORITY setting. This ensures the interrupt's logical priority is equal to or less than the configMAX_SYSCALL_INTERRUPT_PRIORITY setting.

Cortex-M interrupts default to having a priority value of zero. Zero is the highest possible priority value. Therefore, never leave the priority of an interrupt that uses the interrupt safe RTOS API at its default value.

意味着不能让中断优先号分配不能小于configMAX_SYSCALL_INTERRUPT_PRIORITY!!!最好的分配方法当然是尾部15分配起,而不是从头部0开始分配。



让GPIO的中断优先号大于configMAX_SYSCALL_INTERRUPT_PRIORITY,即中断优先号不优先于(logic above)你定义的最优中断优先号就行,xSemaphoreGiveFromISR();就可以用了。

1 0
原创粉丝点击