FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [October 2016 Threads] Tasks and methodsPosted 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 methodsPosted 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 methodsPosted 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 methodsPosted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|