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

Tasks and methods

Posted by jesseb9900 on October 25, 2016

Hello,

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?

Thanks!


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 ]    [ 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