I am currently developing a bare-metal application using the S32K311 microcontroller, which is based on the ARM Cortex-M7 core. In our project, we are using the Periodic Interrupt Timer (PIT) to implement a cooperative scheduler that runs tasks every 10ms, 100ms, and 300ms.
for example)
function RunApplicationTasks(): // 10ms period if timer_10ms_flag is TRUE: timer_10ms_flag = FALSE Execute10msTaskGroup() // 100ms period if timer_100ms_flag is TRUE: timer_100ms_flag = FALSE Execute100msTaskGroup() // 300ms period if timer_300ms_flag is TRUE: timer_300ms_flag = FALSE Execute300msTaskGroup()
While researching ways to reduce current consumption, I came across information about the WFI (Wait For Interrupt) instruction built into the Cortex-M7 core. Based on this, I am planning to structure my code as follows:
function RunApplicationTasks(): // if all timer flag disable if ( timer_10ms_flag is FALSE AND timer_100ms_flag is FALSE AND timer_300ms_flag is FALSE ): __asm volatile ("wfi"); // WFI // 10ms task if timer_10ms_flag is TRUE: timer_10ms_flag = FALSE Execute10msTaskGroup() // 100ms task if timer_100ms_flag is TRUE: timer_100ms_flag = FALSE Execute100msTaskGroup() // 300ms task if timer_300ms_flag is TRUE: timer_300ms_flag = FALSE Execute300msTaskGroup()
I’m posting this to ask whether this approach is safe and reliable in a bare-metal environment.