Introduction
Lua implements co-routine based on setjmp
/longjmp
functions. I found some problems during porting lua to these RTOS environment:
1. Zephyr RTOS: Failed
Heading
MISRA C 2012 Rule 21.4 pointed:
The standard header file <setjmp.h> shall not be used
and when I call setjmp/longjmp functions it suggests that a MPU Fault is occurred although CONFIG_MPU=n
is set in prj.conf
.
2. Mbed OS: Success
I call lua API in main()
and it contains no other thread or task in program. It was OK. But I do not test multi-thread cases.
3. FreeRTOS: Not Tested yet, but likely ok
Opensource project like NodeMCU and Lua RTOS use Lua and FreeRTOS as their basic framework. But I am not sure that they have tested in FreeRTOS multi-task situation.
I found a thread on FreeRTOS Forum about this problem. One of FreeRTOS developer said he did not know. Another people indicated may cause unexpected behaviors in ISR or task context switching due to conflict register change.
My Question
If I disabled all interrupts during
setjmp
/longjmp
usage, could I avoid unexpected behaviors in case of conflicting ofsetjmp
/longjmp
and ISR/task switching?Why do
setjmp
/longjmp
have failed in Zephyr RTOS?