Quality RTOS & Embedded Software

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




Loading

How to call another task from a task?

Posted by Victor Castro on September 25, 2009
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

RE: How to call another task from a task?

Posted by Mike Hibbett on September 25, 2009
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

RE: How to call another task from a task?

Posted by Victor Castro on September 28, 2009
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

RE: How to call another task from a task?

Posted by Mike Hibbett on September 28, 2009
I'm sorry Victor but I do not understand what you are suggesting. Could you describe it another way?

Mike

RE: How to call another task from a task?

Posted by Lukasz Sokol on September 29, 2009
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.


RE: How to call another task from a task?

Posted by Victor Castro on September 29, 2009
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

RE: How to call another task from a task?

Posted by Lukasz Sokol on September 29, 2009
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 ?)

RE: How to call another task from a task?

Posted by Lukasz Sokol on September 29, 2009
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.


[ 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