Quality RTOS & Embedded Software

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


Code inside vs. outside tasks

Posted by on November 4, 2011

I have a general question regarding tasks. Let's say that I have non-RTOS code that I would like to convert to a FreeRTOS task. The existing code performs some initialization (e.g. HW setup) only at startup and then enters the main program loop. Now if I move the code to FreeRTOS I could put all the code as is including those initialization stiff inside a task function or I could try to isolate the init stuff into my main() so that it runs before the scheduler is started. Only the main program loop would then go into the task function. Are there any benefits (e.g. resource saving) that are worth that additional program modification? Thank you in advance for the clarification.


RE: Code inside vs. outside tasks

Posted by Dave on November 4, 2011
Normally hardware would be set up before the scheduler was started. You can disable interrupts if necessary, as they will be automatically be re-enabled when the first task starts.

RE: Code inside vs. outside tasks

Posted by on November 4, 2011
Thank you very much for the help.

RE: Code inside vs. outside tasks

Posted by Richard Damon on November 4, 2011
My general rule is hardware initilzation (which tends to want to be done before interrupts are put "on the air") and the creating of communication resources (queue, semaphores, and mutes) generally want to be done before the scheduler starts. Sometimes a device needs a longer "configuration" protocol that might go into the beginning of a task, especially if it needs delays or interrupt responses.

[ 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.


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


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