4

I'm learning FreeRTOS on a Cortex M0. (Simultaneously, I'm learning the Cortex as well...). I've got plenty of experience with 8bit MCUs.

I'm going through the newbie tutorials on FreeRTOS and I understand setting up basics tasks and the idle daemon.

I realize I don't really understand what the FreeRTOS is doing to manage the underlying timing mechanicals of the kernel. Which leads to one big question...

What is the ideal way to shutdown an RTOS when you want to turn your device off? Not idle the device, but put your MCU into the deepest OFF there is (whatever you want to call it).

It seems trivial, to idle between tasks, but shutting the MCU off and making sure it stays off, and the RTOS kernel doesn't trigger an interrupt or somethign else to wake the MCU back up...?

Leroy105
  • 139
  • 5
  • Have you considered simply disabling the timer interrupt that drives the FreeRTOS ticks? – semaj Jan 24 '18 at 16:55

1 Answers1

3

this is deep sleep mode / power down mode, for an 8-bit MCU this is in the datasheet of ATmega128RFA1 on page 159 ff in http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8266-MCU_Wireless-ATmega128RFA1_Datasheet.pdf ( with the wake-up sources ) in this mode all internal timers are disabled

in freeRTOS this is named Tickless Idle Mode, cf https://www.freertos.org/low-power-tickless-rtos.html

Note: If eTaskConfirmSleepModeStatus() returns eNoTasksWaitingTimeout when it is called from within portSUPPRESS_TICKS_AND_SLEEP() then the microcontroller can remain in a deep sleep state indefinitely. eTaskConfirmSleepModeStatus() will only return eNoTasksWaitingTimeout when the following conditions are true:

  1. Software timers are not being used, so the scheduler is not due to execute a timer callback function at any time in the future.

  2. All the application tasks are either in the Suspended state, or in the Blocked state with an infinite timeout (a timeout value of portMAX_DELAY), so the scheduler is not due to transition a task out of the Blocked state at any fixed time in the future.

To avoid race conditions the RTOS scheduler is suspended before portSUPPRESS_TICKS_AND_SLEEP() is called, and resumed when portSUPPRESS_TICKS_AND_SLEEP() completes. This ensures application tasks cannot execute between the microcontroller exiting its low power state and portSUPPRESS_TICKS_AND_SLEEP() completing its execution. Further, it is necessary for the portSUPPRESS_TICKS_AND_SLEEP() function to create a small critical section between the tick source being stopped and the microcontroller entering the sleep state. eTaskConfirmSleepModeStatus() should be called from this critical section.

All GCC, IAR and Keil ARM Cortex-M3 and ARM Cortex-M4 ports now provide a default portSUPPRESS_TICKS_AND_SLEEP() implementation. Important information on using the ARM Cortex-M implementation is provided on the Low Power Features For ARM Cortex-M MCUs page.

so in freeRTOS invoking tickless idle mode is equivalent to deep sleep or power down. possibly you have to manually disable internal timers on the cortex ...

had some problems powering down the ATmega128RFA1 MCU in Contiki OS ...

ralf htp
  • 9,149
  • 4
  • 22
  • 34
  • Yeah, I'm noodling this on Cortex M0. There is a SysTick interrupt, that I think clocks FreeRTOS. It depends on your port. You'd love that on Cortex there is an abstraction layer for vendor-ported FreeRTOS, so not only do you have to figure out FreeRTOS you get to learn an abstraction as well!! There is no documentation on the CMSIS-RTOS, how you turn the service off gracefully... Painful stuff going from 8-bits. This seems like such a trivial thing, but it really gets to the guts of the RTOS... – Leroy105 Jan 19 '18 at 19:24
  • this is similar in contiki. contiki uses many of the timer / counters of the MCUs. the problem is then that deep sleep is only possible if most of these timers are disabled and you have to disable them without crashing the overlying contiki os ... – ralf htp Jan 19 '18 at 19:39
  • I haven't even gotten there! I just was lying in bed last night, thinking of what I DID NOT KNOW about getting an RTOS going. This one stuck out. You never see this condition in a newbie tutorial. – Leroy105 Jan 19 '18 at 19:41
  • This some commentary from FreeRTOS on the tickless mode using the SysTick on Cortex. I have to digest this: https://www.freertos.org/low-power-ARM-cortex-rtos.html – Leroy105 Jan 19 '18 at 19:47
  • This is commentary on how this was handled in the "OLD" -- CMSIS-RTOS API: http://www.keil.com/pack/doc/CMSIS/RTOS/html/lowPower.html It probably hasn't changed much... – Leroy105 Jan 19 '18 at 19:51