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] [May 2016 Threads] Return Statement in taskPosted by savindra on May 18, 2016 Hello ,
I want to use soemthing like this in a task:
if(true)
{
return;
}
I know it is not allowed to use such type of instruction in the task.
Is there alternate way to do this in FreeRTOS?
What i want to do is stop the task when a condition is true and start normally at next cycle.
Return Statement in taskPosted by westmorelandeng on May 18, 2016 Savindra,
You can use vTaskSuspend(NULL); inside the task and then vTaskResume(&Handle); - I think that syntax is correct. You can use semaphores too.
Take a look at some of the example code that does this.
If you return from a task your task stack goes bye-bye. Try it - it's a learning experience.
This made me laugh because I am working on a port and it had a ton of returns - I converted a lot of code to tasks - and it died - and I was certain I had found all of the returns - but I missed some and it sure as heck crashed the port - so be careful - each task has to run in its own context.
Good Luck!
John W.
Return Statement in taskPosted by rtel on May 18, 2016 Do you mean you want to restart a task? If so, there is no built in way
of doing that, but you could:
1) Implement a function as follows:
void RecreateTask( void * pvParameter1, uint32_t ulParameter2 )
{
/* Delete the original task, the handle to which is passed
in using the first parameter. */
vTaskDelete( ( TaskHandle_t ) pvParameter1 );
/* Recreate the task. */
xTaskCreate( [whatever] );
}
2) When you want to exit the task, use the xTimerPendFunctionCall()
API function to send the above implemented function to the Timer task,
where it will be executed.
xTimerPendFunctionCall( RecreateTask,
xTaskGetCurrentTaskHandle(),
0, /* not used. */
portMAX_DELAY );
/* If the timer task has a high enough priority the following code
will not execute because the timer task will have deleted this task.
If the timer task has a lower priority then suspend this task so it
allows the timer task to execute and delete this task. */
vTaskSuspend( NULL );
Regards.
Return Statement in taskPosted by westmorelandeng on May 18, 2016 I didn't see the reply before I posted - maybe I misunderstood the question. Recreating the task is a nice feature.
Return Statement in taskPosted by savindra on May 18, 2016 I was also thinking to recreate the task.
but i have one doubt :
My task is running at 10ms interval, if i recreate it will not come directly into while loop.
I mean it will do the intialisation also if i recreate the task.
Don't you think it will loose the deterministic behaviour.
void vMy_Task( void *pvParameters )
{
///intialisation code
while(1)
{
vTaskDelayUntil( &xNextWakeTime, configMODBUS_MASTER_FREQUENCY_10MS );
///do this work
}
}
Return Statement in taskPosted by rtel on May 18, 2016 I think from your reply it is clear I don't understand what it is you
want to do.
Return Statement in taskPosted by richard_damon on May 18, 2016 If you want to terminate the task to be created again fresh for another job, just have the task delete itself: vTaskDelete(0);
Normally, I don't keep deleting and creating tasks, as it is inefficient, but the task has out the outer level a while(1) loop, and at the top of that loop something that causes the task to block until it has something to do (a vTaskDelay, or wait on a semaphore/event flag, or get from a queue). If at some point in processing, I am done and want to wait for the next operation, you just use a continue statement.
If you want to use a return, just make that part of the code a function that the main loop of the task calls, then THAT function can return and the main loop goes up to wait again.
Return Statement in taskPosted by savindra on May 19, 2016 It seems to be a great idea.
Thanks Richard.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|