Skip to main content
arnold_w
Senior II
July 16, 2019
Question

Combining high speed buses with stop mode and avoiding race conditions?

  • July 16, 2019
  • 0 replies
  • 447 views

I working with the STM32F446-microcontroller and my project is using a simple home-made task scheduler: 

while (TRUE) {
 if (0 < numQueuedTasks(TASK_LOW_LEVEL_DRIVERS)) {
 handleNextTask(TASK_LOW_LEVEL_DRIVERS);
 continue;
 }
 
 if (0 < numQueuedTasks(TASK_HIGH_LEVEL_USER_EVENTS)) {
 handleNextTask(TASK_HIGH_LEVEL_USER_EVENTS);
 continue;
 }
 
 if (0 < totalNumQueuedTasks) {
 continue;
 }
 
 
 if (isAnyTimerRunning()) {
 enterSleepMode();
 continue;
 }
 
 if (0 < totalNumQueuedTasks) {
 continue;
 }
 
 enableExtWakeupInts();
 enterStopMode()
 disableExtWakeupInts();
}

I am using several buses and communication protocols (CAN, SPI & UART) and in order to wake up when there is traffic, I enable external interrupts on the appropriate pins (CAN Rx, SPI chip select and UART Rx) before I go to sleep. However, this approach isn't working well, if I get a bus-interrupt at line 25, then I will queue a TASK_LOW_LEVEL_BUS task, but it won't be serviced because the microcontroller will soon enter stop mode. How can I solve this? I guess in my interrupt routines I could somehow read where the program counter is destined to return to and if it's greater than line 20 then it should be manipulated to line 1 instead. But it seems like a hacking solution, can anyone think of a cleaner solution?

This topic has been closed for replies.