I’m working on a project with FreeRTOS including FATFs.
I’m currently with two tasks (but soon increasing to more): one that reads some values from a sensor connected to the microcontroller (EFM32LG) and sends this values to another task, which takes care of writing them to an SD Card.
To make this writing process the fastest possible, I’m writing in the SDcard every 512 bytes of data I have (sector size). The buffers containing this data must be normal arrays of bytes. The sensor puts out data with different length in bytes, at a certain frequency, and each type of data (temperature, acceleration…) has its own file (one buffer for each file).
The question I’m facing is, I want to have few buffers so I don’t occupy much memory, but also avoid a lot of copy operations in and out of queues. Which would be the best trade-off?
Should I simply pass values between tasks with a queue for each sensor output type and save them in buffers till I reach the sector size for each? Or should I use semaphores with ring buffers (but then having to copy again from this ring buffer to the normal buffer)?
The queues seem like the best option, but since I have different files/data length, I’m afraid I won’t be able to have just one task to take care of writing the files, since it can block in one queue while others are waiting…
Is it a good practice to keep a binary semaphore and just use the queues as ring buffers? This way I avoid blocking on a specific queue, since I know I’m expecting a certain amount data to be available (as we read different data, but from the same source and frequency).