Postby ESP_Sprite » Wed Jan 17, 2018 3:33 am
It depends on how you want to architect your application. There are a few things to take into account: 1. the cost (CPU-wise) to create and delete a task, 2. the total memory usage of your app, 3. the risk you want to take wrt 'over-booking' your RAM.
For 1, it's pretty simple. FreeRTOS lives under the assumption tasks aren't created that often and as such has no real speed optimization for these calls: it fills memory with stack canaries, happily modifies a fair lot of variables etc. This takes a while, and if you spin up a task e.g. every millisecond, you'll see a lot of time taken up by spinning up and deleting tasks.
For 2 and 3, the idea is that for an embeded application, ideally you'd want there to always be enough memory to fit all processes that can be going on at the same time to fit into all available memory. If that's the case, you can just happily spin up all tasks at boot-up and leave it at that. If you have an application that worst-case cannot fit into RAM, you can start to think about 'over-booking' your RAM: dynamically allocating and freeing memory (maybe in the form of tasks) and hoping that you won't run into the worst-case scenario because that would lead to an out-of-memory situation and if not handled well anywhere where memory is allocated, this can lead to a crash.