Quality RTOS & Embedded Software

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




Loading

Task or software timer?

Posted by Paul Coleman on February 27, 2012
I have a background task which is doing a bit of housekeeping and is run every 500ms. It has the lowest priority in the system and I created it in preference to using the idel task as I want to use that for something else. However, it seems a bit of a waste of resources as it needs a stackof its own, so I thought about replacing the task with a software timer but when I looked into it that too seems to need a stack? So I'm not exactly sure what I stand to gain and I'm a little confused as to why it needs a stack, after all it's just running a callback when the timer expires???
Thanks, Paul.

RE: Task or software timer?

Posted by Richard on February 27, 2012
Software timers themselves don't need any more stack than a standard C function. However, software timer callbacks run in the context of the timer task. The timer task does need a stack (just like any other task), but there is only one timer task. Therefore, if you have 1 software timer or 10 software, the amount of additional stack required is the same.

Regards.

RE: Task or software timer?

Posted by Paul Coleman on February 27, 2012
Okay, thanks for the clarification.

I noticed that even if you create a stack size of 1 the OS will set a minimum stack size of 256 and that 256 means the number of 4 byte words not bytes. So in effect the minimum stack size is 1Kb - is my understanding correct?

Thanks, Paul.

RE: Task or software timer?

Posted by Richard on February 27, 2012
“is my understanding correct”


No. I don't know where you have got that from.

The timer task stack is set by configTIMER_TASK_STACK_DEPTH and is specified in words, just like any other task. It should not be set below configMINIMAL_STACK_SIZE, and in fact even that might be too small.

Regards.

RE: Task or software timer?

Posted by Paul Coleman on February 27, 2012
But configMINIMAL_STACK_SIZE is hash defined as 256 in the config header file? And in the documentation for the function xTaskreate() it says that the stack size is the number of words not the number of bytes?

Regards, Paul.

RE: Task or software timer?

Posted by Richard on February 27, 2012
What you originally stated was:

“I noticed that even if you create a stack size of 1 the OS will set a minimum stack size of 256”


...and that is not correct. The OS will set whatever you set configTIMER_TASK_STACK_DEPTH to.

256 sounds like a large minimal stack value - which port are you using? Check the setting in the official demo for the port as it could well be smaller.

Regards.

RE: Task or software timer?

Posted by Paul Coleman on February 27, 2012
Okay thanks, will do.

Regards, Paul.

RE: Task or software timer?

Posted by Paul Coleman on February 27, 2012
Looking back it seems as though I got the stack size of 256 from one of the examples and never changed it. The demo for my port (AVR32) has a size of 128. Was I right in saying that's words not bytes though?

Is a task's stack used purely for local variables and any parameters passed into that task or does the OS use it behind the scenes? I'm just trying to get a feel for what size I should make it.

I know there are some hooks that I can implement to monitor the stack size which I'll do in the future.

Thanks, Paul.


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




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS