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




Loading

instead of the idle task as is...

Posted by Michael on March 4, 2010
I would like to have a set number of things happen when the idle task is called. I put my board to sleep when there is nothing to do (loops in idle mode right now). The problem with just sticking all the power down steps in the idle task is that this task is jumped into and out of from any point within. I need to have a set number of steps occur before putting the micro into lpm3 (MSP430).

Whats a good way fo going about this?

Oh ya, I am not just calling lpm3, but talking to external hardware to shut it down (and other stuff). So there is an important order to the shutdown task.

Thanks!

RE: instead of the idle task as is...

Posted by Richard Damon on March 5, 2010
For something like this, I would use an idle hook function, and in that function enter a critical section, and inside that section quickly check that it really is time to go to sleep (and not just that all the other tasks are just temporarily busy), if not time, quickly end the critical section, but if it is time, perform the shutdown. Depending on the condition that will be used to wake you up, you probably need to end the critical section just before actually going to sleep.

RE: instead of the idle task as is...

Posted by Michael on March 5, 2010
Hmmm, but what about when I come out of idle. I would need to do the powerup stuff.

Essentially I need to somehow have a single exit and single entry point for idle power down/power up.

When entering idle i want to power down and go into lpm3. Then if I wake up, enter a powerup phase and then exit idle.

what about something like
(psuedo code)
idle func
enter critical---
power down code
exit critical----
lpm3
enter critical---
power up code
exit critical-----
end func



or is there a better strategy?

RE: instead of the idle task as is...

Posted by Richard Damon on March 5, 2010
close, I don't know that processor, and the definition of "sleep" varies by processor and application.

pseudo code:

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
} else {
end critical section
maybe go to idle state if one is available
}
}

Note that if you need an interrupt to wake you up from the sleep state, and the critical section disables that interrupt, the prepare to go to sleep may need to end with a exit critical section or at least re enabling that interrupt.

I am assuming that the sleep being talked about here is a significant shutdown state that may take some time to recover from (restarting clocks and the like) and may disable some peripherals, so should only be entered when conditions are right for it. I have added an "Idle" routine, if the processor supports it, that saves a bit of power by stopping the processor until an interrupt occurs (if we are in the idle task, nothing else is going to be able to execute until an interrupt occurs anyway, might as well let the processor take a break). If you have other tasks at the idle priority that can use the time productively, then you can skip the idle state.

RE: instead of the idle task as is...

Posted by Michael on March 5, 2010
Thanks,

There is a lot to think about. Mostly because i need to keep a certain interrupt enabled when going to sleep, but when waking on that interrupt, service my powerup routine before i service that said interrupt.

I am using a MSP430f5438 btw.

I will post my solution when i have one.

RE: instead of the idle task as is...

Posted by Richard Damon on March 6, 2010
As I said, the prepare system to go to sleep will probably end with enabling some needed interrupts. If the interrupt processing function itself needs to fully wake up the processor, then you may need to have a flag that the enter sleep routine sets, so that the interrupt know that IT needs to do the wake up (and it can clear the flag so the code in the idle hook know enough to not do the wake up it self too.)

It may be possible to make the interrupt to just a bit of minimal processing that could be done in the native "just woke up state" and do something to wake up a task to do most of the work,

Thinking about this, part of the "preparing to go to sleep" routine will need to be disabling the scheduler, and re-enabling it AFTER you do all the wake up code, otherwise some other task might get started before you wake up everything.


[ 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