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




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