Quality RTOS & Embedded Software

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


Loading

All the tasks in main.c ? FreeRTOS

Posted by ltu-pierre on November 14, 2013

Hello, I'm relatively new with FreeRTOS, and as my project is growing, I was asking myself if it was common/a good idea to split the main.c file into multiple files (for example one for each task + the main.c with the main() function) to have a clearer and more understandable structure in my project. I'm trying to do it right now, but it seems to become even more complex with all the inclusion it need everywhere... How are you used to organize your own sources in an RTOS project ?

Thank you,

Pierre


All the tasks in main.c ? FreeRTOS

Posted by richardbarry on November 14, 2013

Normally I would not implement any tasks from the file that contained the implementation of main() - although it is very common to create all the tasks from main() before the scheduler is started.

With regards to header files - if you make calls to xTaskCreate() you will need to include FreeRTOS.h then tasks.h. Just as if you wanted to use queues you would include FreeRTOS.h then queue.h. It should be possible to use any FreeRTOS API function from any file provided the header file that defines that function is included, and FreeRTOS.h is included before that. The prefix on the function's name tells you which file it is defined in (hence x'Task'Create() is in 'Tasks'.h).

Regards.


All the tasks in main.c ? FreeRTOS

Posted by richard_damon on November 15, 2013

My own organization is that the project is divided into source files, each source file being one aspect of the program (dealing with a specific device or operation). Every C file has a matching .h file defining the API for that file, functions that other files might need to call, Global data (as little as possible) to be referenced by other files, and any types/constants needed for these.

One function that every file will define is an init function that main will call to perform the needed initialization for that piece of code, creating tasks/queue/semaphores, and initializing the hardware.

The main program will then include all these headers (other files will just need to include the headers for the parts they talk to, but main talks to almost all of them for this init function), and calls the init functions. (If I am programming in C++, I don't need the calls to the init function, as I can normally create object whose constructors, called at startup time, do this needed initialization).


All the tasks in main.c ? FreeRTOS

Posted by ltu-pierre on November 15, 2013

Thanks a lot for all these information, it helps me a lot !

Regards.


[ 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