Quality RTOS & Embedded Software

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


Tasks and methods

Posted by jesseb9900 on October 25, 2016


In my project I have a lot of functions to calculate things in sequence (transform raw data -> interpreted data -> act on data e.t.c.). Now I want to switch to freertos tasks but I'm not sure how to properly implement it. Is it best to transform them al to separate tasks or just to create one big task? Maybe only the first as task and the rest as functions? What will happen to a (running) function during a context switch?


Tasks and methods

Posted by rtel on October 25, 2016

There is not enough information here for a proper answer, and even if there was enough information, the answer would be complex. The first question to ask yourself is - are the calculations related to each other? In other words, are they part of the same piece of related functionality? If so, and as you say they have to happen in sequence, then the simplest thing would probably be to have them done in the same task - but that is a general statement rather than a suggestion for your particular case.

As long as your functions are thread safe, or if only one task calls the functions, then the output of the calculations will be the same whether the task is preempted while the calculation is being performed or not.

Tasks and methods

Posted by jesseb9900 on October 26, 2016

Thank you. Only one task is using the functions. So I think, according to the answer, the best way to implement it is to create seperate functions to do the calculations. The thing I'm not sure about, is what will happen if the task gets preempted while waiting for a return of one of the "sub"-functions. When the task continues, will it also continue the funtion? If so, does this mean for the stack? Does this mean the state of the function get saved (taste like memory problems)?

Tasks and methods

Posted by heinbali01 on October 26, 2016

Hi Jesse,

what will happen if the task gets preempted while waiting for a return of one of the "sub"-functions

No problem. When pre-emption is allowed, you task can indeed be interrupted at any moment, unless task-switching is temporarily suppressed or when all interrupts have been dis-allowed. Before switching to a new task, the kernel will save all information: next instruction to be done (PC), current stack (SP), and all other important registers.

A new task will run for a while and after that, your "sub"-functions will become active again. It is as if it got frozen for a while and continues where it was.

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

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


FreeRTOS and other embedded software careers at AWS.

Latest News

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

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

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

Xilinx Microblaze and Zynq partner