Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Save energy, save the world

Posted by Cesar Verdes on May 4, 2010
I've noted that when the system uses co-routines it's dificult to know when send the CPU to sleep.

As I could understand, the documentation suggests to include the vCoRoutineSchedule() call into the vApplicationIdleHook() function, setting configUSE_IDLE_HOOK to 1. I reference the "Scheduling the co-routine" topic at the documentation.

The Solution #2 of the FreeRTOS Tutorial evaluates that for a fully preemptive system the power consumption can be reduced if the idle task places the processor into power save (sleep) mode.

With the present co-routine implementation I find hard to detect when all the co-rutines are blocked (delayed) in order to place the processor into a power save mode until the next tick.

In this post Richard Damon sugest this pseudo-code for the idle hook funcion:

idle hook function (will be called periodically by the idle task) 
Enter Critical Section
if(ok to go to sleep)
prepare system to go to sleep
enter sleep state
wake system up from sleep state
end critical section
end critical section
maybe go to idle state if one is available

The question is, how to know when is ok to go to sleep when co-ruoutines are used?

As a possile solution I suggest to change the return value of vCoRoutineSchedule() from void to portBASE_TYPE, and modify this function in order to return pdTRUE when there is at least one ready co-rutine, and return pdFALSE if there is not.

As the documentation declares, Co-routines are really only intended for use on very small processors that have severe RAM constraints. This kind of constraints can be common in small battery operated appliances.

Please, does anyone see the same dificulty that I do? Does anyone found a good way to solve it?

I know myself as a newbie, in case than more experienced FreeRTOS developers find my suggestion a good one, I would like to work on it and propose some code to discuss.

I'm studing FreeRTOS only for pleasure, as a hobby in my free time. I'm trying to understand line by line, function by function. That's why I could even think about situations that perhaps they are not real life ones.



RE: Save energy, save the world

Posted by Richard Damon on May 4, 2010
I don't use co-routines, but it seems to me that what could be done is use the priority feature of co-routines to do this. Set up a Priority 0 co-routine that does the sleep, and put all other co-routines at a higher priority. The Priority 0 co-routine will only get time if no task or other co-routine (unless they also are at priority 0) are able to run.

RE: Save energy, save the world

Posted by Dave on May 4, 2010
Both suggestions sound good. The first one could be added under the sourceforge feature request tracker for FreeRTOS, although maybe richard_damons suggestion makes it obsolete?

RE: Save energy, save the world

Posted by Cesar Verdes on May 5, 2010
Dear Richard, your suggestion is really nice and simple. Thanks a lot. I didn't realize.

Perhaps, something that some day may be improved is the number of CPU cicles to determine if any co-routine is in ready state.

One day I read that for a battery operated device each CPU cicle can be measure as miliseconds of authonomy.

But I think your suggestion is really good enough without any kernel modification. It's a pleasure to be studing an OS with this level of community support.

RE: Save energy, save the world

Posted by Richard Damon on May 6, 2010
The code actually uses a fairly efficient method to scan for the highest priority co-routine (or task in similar code) that is ready to run. I suspect that by making the sleep routine just the lowest priority may be a very efficient way to check for this, as it uses the existing code without special cases.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists