How to call another task from a task?

Hi, I’m using 4 tasks in my project. I’d like to know, how I call another task from a task? Other rtos has a function called switchtask, which would be similar in FreeRTOS? Thank you very much, Víctor

How to call another task from a task?

Hi Victor, Can you explain what it is you are actually trying to do? You don’t ever call one task from another, but instead pass messages between them ( or use shared memory ) Each task is like it’s own independent computer. Maybe you can say what this ‘switchtask’ function is, and in what OS. That might also help explain what it is you are trying to do. Regards, Mike

How to call another task from a task?

Hi, to simplify, I have 2 tasks for example, task1 and task2… void vTask1 ( void *pvParameters )
{
portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); for ( ;; )
{
vParTestToggleLED( 0 );
vTaskDelayUntil( &xLastWakeTime, 5 ); //100 mseg
}
} void vTask2 ( void *pvParameters )
{
portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); vParTestToggleLED( 7 ); for ( ;; )
{
vParTestToggleLED( 1 );
vAnyFunction ();
vInfinityFunction ();
vTaskDelayUntil( &xLastWakeTime, 5 ); //100 mseg
}
} As I have a function that takes a ‘while’ infinity within task2, and I have to always say task2 resume, to turn on and turn off, the ‘LED 7’ for example. I would like to make a call to the start of task2 by task1, but that infinity function continued to do what it was doing. Regards, Víctor

How to call another task from a task?

I’m sorry Victor but I do not understand what you are suggesting. Could you describe it another way? Mike

How to call another task from a task?

Do you have to have the infinite loop in task2 ? Can you not make it a part of task (which is an infinite loop itself)? I.E. the way the task system works, it guarantees that a) every function within the for (,,) {} block is called, and b) that it is called in the coded order once per cycle; If you just want the operations in task2 to run ‘constantly’, take the vTaskDelayUntil out of it and set it to lower priority than Task1, so that Task1 is woken up when needed; or configure them to have the same priority, then they will be run in round-robin manner (Task1-Task2-Task1-Task2 and so on). The scheduler will freeze them as appropriate and then restart where they left off, every ‘tick’. Then if you want task1 to tell task2 something, you need to create a queue, to which task1 will be writing (e.g. 1 character long queue), and task 2 will be emptying it (reading) and acting accordingly.

How to call another task from a task?

Unfortunately I have, but I’ll take your idea. I’ll make another task and put the infinite loop. If, in the middle of the execution of task1 I want to go to task2, how would I do that? Just calling the "vTaskResume", work? Thanks, regards, Victor

How to call another task from a task?

It would help, if you described what these tasks do (you don’t have to share your code if you don’t want to, or you’re not proud of it ;) ) and what platform are you running it on (or is it in emulator ?)

How to call another task from a task?

And vTaskResume, will only do what you want if the task was suspended before – which means it won’t be scheduled to run AT ALL, until vTaskResume is called, then it will resume from the state it has been suspended on (’unfrozen’).
I think http://www.freertos.org/a00130.html, http://www.freertos.org/a00131.html should tell you something. also http://www.freertos.org/a00020.html#taskYIELD can come in useful.
The taskYIELD will cause the task to be switched immediately, into the place it was last left off, NOT from the start of it.