Search code examples
multithreadingreal-timeembedded-resourcertosmultitasking

Reduce resource usage of an Idle task


I find that in uC/OS-II RTOS, there is an idle task that gets executed when no other task is ready to run. If an idle task can consume resources, how can we reduce it ?


Solution

  • Usually the idle task is where the processor is put into low power (sleep) mode, if it's a low-power system and the processor has such a mode. This is usually a specific assembly instruction, for example on the ARM Cortex M3 you'd execute the "WFI" instruction. On other chips, there might be a specific register outside the core that manages power (as opposed to an instruction).

    Note that there are often conditions (requirements that must be met) before entering low power mode. Sometimes you need to have interrupts locked, sometimes unlocked, before going to sleep; check your chip's datasheet.

    Usually before entering low-power mode, you'll power down any peripherals you don't need. Again, check your chip's datasheet. Also if you're going to use an interrupt to wake back up, make sure that the peripheral isn't powered down, and that the interrupt is enabled, otherwise, you won't wake up.

    Last point: often when debugging (e.g. under control of a JTAG device), weird things happen when entering low power mode, so you want to disable "sleeping" in the idle task when debugging, and only do this when running without the debugger. Usually this is a compile-time decision (#ifdef ...)