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 ?
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).
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).
Thanks a lot for all these information, it helps me a lot !
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.