I started to learn freeRTOS few weeks ago using the windows simulator, and need your help.
In my project I use 18 tasks, 4 queues and 4 counting semaphores. I create all of the tasks, semaphores and queus in the main function (before the scheduler starts).
I know I should check if the tasks,queues and semaphore were created, so I made functions to do so.
My question is, if one of the tasks, queues or semaphores failed to be created (returnes NULL), can I use exit(error_code) to end the program?
I know that return statements should not be used, but I am not sure about exit.
If I should not use exit, please tell me what can be used instead. I can’t find answer to this anywhere.
As long as you’re using the simulator on a host OS like Linux / Windows you can use exit
But be aware that on real targets / native FreeRTOS applications there is no exit system call. Simply because there is only the FreeRTOS application and no further underlying OS.
So on a real target system, what do I have to do in case a xQueueCreate returns null in main function? Or in case I have multiple queues and semaphores and some fail?
There is no real fallback resp. it’s up to you.
Usually you have ensure that the required resources are available during development e.g. configuring the heap large enough etc.
The key things is that the real system will usually always have the same resources, so either it will always be able to allocate the objects, or never, so having the code “lockup” on failure, so you can see the problem with a debugger is a reasonable option.
Other failures, like if you detect some broken hardware, may indicate for some other sorts of failure indications, sometimes you can turn on a “Trouble” light, and some times start in a limited functionality mode. Those are all application level decisions.