FreeRTOS for a multi-threaded application

manigrand wrote on Wednesday, January 11, 2017:

I am a beginner with embedded programming. I would like to have some details about how the various components of FreeRTOS can be used for the application described below. I would like to have the details of not just the features, but also the names of the functions/procedures in the code of FreeRTOS that can be used for the following application to achieve maximum efficiency and reliability.

There will be many COM ports running: pulling in GPS Receiver data via RS-232/422, sensor data over RS-422 and LVDS, transceiver modem over RS-232, telemetry data over RS-422, etc. Many devices and com ports must run simultaneously and not lose data (with CRC checks on each Com port running).

Basically, we are looking for an ability to run many threads – about ten simultaneously (mainly COM ports RS-232/422, USB, Ethernet, LVDS) with CRC checks and not have any data drops. This is going to be a hard real-time embedded application.

Thank you.

rtel wrote on Wednesday, January 11, 2017:

Your question is very broad, almost more of a consultancy project, and
even then would require a lot more details from yourself to give an
answer. I would recommend starting with the book that is now available
here then if
necessary come back with some more specific questions.

richard_damon wrote on Thursday, January 12, 2017:

As RTE indicated, this isn’t so much a question about what feature in FreeRTOS you will use, but a programming exercise in designing and writing the actual code to implement your application logic.

The basic layout of your program would be to have an ISR for every comm port (that is normally how serial ports work) which gather the data and send it to the appropriate task. Avoiding data loss is purely a matter making sure you have enough buffer space and that your processing tasks can take the data fast enough.

The simplest method would be for each ISR to just put the received data into a Queue, one for each serial port, and the tasks pulling the messages out of the appropriate queue. This has a high processing overhead, but for many serial devices that really use RS-232 the data rates are likely slow enough that this will work.

If the data reate really are too high for this, then the ISRs need to be a bit smarter and build up a full ‘message’ in a buffer and send notification to the task that it has a message to process. This requires each serial port ISR to understand the basic data format of the device it is receiving from.

All of this code is considered ‘Application Specific’ and not proviced by FreeRTOS, it just provides the basic ISR -> Task communication primatives, not the serial port drivers, though there may well be a sample in the code examples (which will be the queue based approach),