Quality RTOS & Embedded Software

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


Loading

Setup() with delay() functionality, before creating Task

Posted 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 Task

Posted 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 Task

Posted 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 Task

Posted 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 Task

Posted by vr6073 on October 30, 2014

I've been studying the Hein's code again, and it's really good. I had misunderstood.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner