We run our application under the MSP430X port of FreeRTOS 8.0.0 in tickless mode. When we are idle we want to disable some peripherals (I2C, UART, timers) to save power. That's relatively easy to do by adding code to vApplicationIdleHook(). However, we also need to do the opposite - wake up the peripherals when starting to execute a task (i.e. on becoming not idle). I added the following chunk of code at the bottom of xTaskIncrementTick().
extern void vApplicationNotIdleHook();
just before the line
Obviously, I add a new hook function vApplicationNotIdleHook() that does the enabling.
Could anybody please suggest whether this is going to achieve what I want? Is there a better way to do it?
Thanks for any help,
You can copy the tickless idle implementations for other chips http://www.freertos.org/low-power-tickless-rtos.html these have pre and post sleep macros to enable disabling then reenabling peripherals as you are trying to do.
If you want to do something in the idle hook then you could do something like
//Stop context switches so the idle task continues running after sleep
//Turn off what needs turning off
//Call your sleep function
//Reenable what needs reenabling
//Allow context switching again to yield
A hook in xTaskIncrementTick() is not going to execute until the next tick time and not at all if the clock used to create the tick is one of the things that you turn off before sleeping. Better to add a hook in the traceTASKSWITCHEDIN macros, or another trace macro that runs when you leave sleep. Another options would be to somehow signal a wake event from the interrupt that causes the wake.
Thanks for replying, Dave.
It looks like there are a few problems with my implementation. The foremost of these is that I wasn't actually running in tickless mode. I didn't realise that the MSP430 port doesn't implement this internally - I need to implement portSUPPRESSTICKSAND_SLEEP() myself (which I haven't). If/when I do that, I'll come back to this.