Low power mode when scheduler idle

anonymous wrote on Thursday, January 26, 2012:

I would like to be able to switch my dsPIC33F into a low power mode when there are no tasks running (or all are suspended or blocking). The idea is to use the core doze mode to reduce power to 1/4 normal operation when idle by underclocking the CPU (but peripherals and timers run on the main clock, so it still keeps time.)

The simplest way of implementing this, I thought, would be to look for a vGetNumRunningTasks function; but there doesn’t seem to be one. I’d need to access the internal RTOS data structures to get the task list, which is probably a bad idea.

Any ideas?

Thanks for a great RTOS!

rtel wrote on Thursday, January 26, 2012:

The normal way of doing this is to use the idle hook.  Assuming your application tasks run at a priority above the idle priority, the idle task will only run when no application tasks can run.  Set configUSE_IDLE_HOOK to 1 in FreeRTOSConfig.h, then define a function called vApplicationIdleHook(), and put your sleep code in that.



anonymous wrote on Thursday, January 26, 2012:

Hi Richard

That looks useful - thanks. I would need to enter and exit low power mode several times a second though (at least); is there some function (aside from any of my tasks) that would run a callback when tasks are started so I can exit the low power mode I entered in the idle hook?

richard_damon wrote on Thursday, January 26, 2012:

I tend to just execute an Idle instruction in the idle hook to stop the processor when there is nothing to be done.

If you want to actually a clock change for lower power, you could add that code before the idle, then define a handler for
traceTASK_SWITCH_IN() that checks if you are in that low power mode, and are switching to a task besides the idle task, switches back into full speed mode.