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 2014 Threads] Setup() with delay() functionality, before creating TaskPosted by vr6073 on October 26, 2014 Hello,
I Am using freeRTOS with STM32 F2 microprocessor.
I need to execute some operations for configuring my hardware, before creating my Tasks. In this Setup operations, I need to use any kind of delay() function.
But At the beginning of the program, vTaskDelay() is not still available. What is the way for using delay functionality before create Tasks and starts scheduler, by calling vTaskStartScheduler() ?
Or stated another way:
Do I have to create a Setup() function as a Task, and then the other Tasks have to wait to start till the setup() finalizes? Is there an specific freeRTOS function to synchronize them that way?
Thanks,
Setup() with delay() functionality, before creating TaskPosted by heinbali01 on October 26, 2014 Hello,
If you want to have a blocking delay without using RTOS, you'll have to setup a timer that triggers an interrupt.
What I would do:
- Setup the clocks and a timer for RTOS
- Start your first task and from there:
- Call your Setup() and use vTaskDelay()
- Start-up the other tasks
~~~~~~
void vMainTask (void pvParameters)
{
/ While running Setup(), there are
no other tasks yet */
Setup( );
xTaskCreateStack (vMacbTASK, ...)
xTaskCreateStack (vUsbTASK, ...)
xTaskCreateStack (vLoggingTASK, ...)
for( ; ; )
{
/* Do the normal work */
}
}
~~~~~~
Regards,
Hein
Setup() with delay() functionality, before creating TaskPosted by vr6073 on October 30, 2014 Thank you, Hein,
I am testing another way to do it:
In order to be able to use vTaskDelay() in my Setup() function , I am creating all task at the same time, but Setup with higher priority. That way I am sure that it starts the first:
xTaskCreate(mySetup, "mySetup", STACK_SIZE, NULL, tskIDLE_PRIORITY+2, NULL);
xTaskCreate(Task1, "Task1", STACK_SIZE, NULL, tskIDLE_PRIORITY+1, &xTasksHandle1);
xTaskCreate(AxisControl, "Task2", STACK_SIZE, NULL, tskIDLE_PRIORITY+1, &xTasksHandle2);
In the body of Setup, I suspend all others Tasks. At the end of Setup, I resume all other tasks and delete Setup Task.
void mySetup(void * pvParameters) {
vTaskSuspend(xTasksHandle1);
vTaskSuspend(xTasksHandle2);
for (;;) {
.........................
.........................
doing things, and using
vTaskDelay() delays
.........................
.........................
// Resume the suspended tasks.
vTaskResume(xTasksHandle1);
vTaskResume(xTasksHandle2);
// Delete Setup task (ourselves).
vTaskDelete(NULL);
}
}
It is working right now...
Setup() with delay() functionality, before creating TaskPosted by markwrichardson on October 30, 2014 When I encountered a similar issue in my design, I chose to implement as Hein described. I felt this was better for the reader and eliminated the chance of a race condition. The way you describe requires internal knowledge of the OS, which high-level code should not rely on. For example, if a maintainer moved TaskCreate( mySetup ) after the other TaskCreates, then the outcome wouldn't be clear even with knowledge of the priorities.
Anyone else have preferences they use ?
Mark
Setup() with delay() functionality, before creating TaskPosted by vr6073 on October 30, 2014 I've been studying the Hein's code again, and it's really good. I had misunderstood.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|