Quality RTOS & Embedded Software

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


can i use vTaskDelay before starting schedular

Posted by ephobb on January 16, 2016

Hi, Can i use vTaskDelay before starting schedular. I need delay to initialize the LCD and it will come under initialization of hardware. So, this should be initialize before starting schedular.

can i use vTaskDelay before starting schedular

Posted by rtel on January 16, 2016

vTaskDelay() uses the services of the scheduler, and while one task is delaying (in the Blocked state) the scheduler will select another task to execute. This can only be done after the scheduler has been started - so no - you can't call vTaskDelay() or any other function that might attempt to either enter the Blocked state or cause a context switch, until after the scheduler has been started.

It is common practice to create an initialisation task though. So main() will create an initialisation task, then start the scheduler. The initialisation task will perform the hardware and any other initialisation that is needed, and can use vTaskDelay() as the scheduler is running. Once the initialisation task has completed its responsibilities it creates all the other tasks necessary to run the application. The initialisation task can then either delete itself, or it can also start to execute application code.


can i use vTaskDelay before starting schedular

Posted by ephobb on January 16, 2016

Thanks Lot. Is it like following flow.

~~~~ void main() { xTaskCreate(Init_Periphearls,"Init",128,NULL,0,NULL); vTaskStartScheduler();

void Init_Periphearls()
                  vTaskDelete( xHandle );


Is it correct Way?

can i use vTaskDelay before starting schedular

Posted by rtel on January 16, 2016

Yes - that's the right idea. The task can delete itself by calling vTaskDelete( NULL );

can i use vTaskDelay before starting schedular

Posted by richard_damon on January 16, 2016

I personally like to initilize as much as practical (but no more) before starting the scheduler. Before starting the scheduler, you have a simpler enviorment, since you don't need to worry about inter-task interactions. Devices that require significant delays or waiting for interrupts do get initialized after the scheduler is started, at the begining of some appropriate task. I avoid a dedicate 'initilization' task, as normally I don't use any dynamic memory after startup, so the memory used by the initilization task becomes lost memory.

For many devices, there will be a task dedicated to the device, so that task is the natural for doing the initilization. For output only devices like a disply, there may not be a task dedicated for it, so the initiliztion can either be done on first access in the driver interface, or some task is give the responsibility for calling the init function to do the initlization. (You do need then some flag to make sure no tasks try to use the device before the initilization is complete).

can i use vTaskDelay before starting schedular

Posted by ephobb on January 23, 2016

Thanks Richard. I think, your idea is good. I should Initialize all the peripherial before starting task. It would better. So there will be no context switch no interrupt occurance.

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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists