I am learning to use a RTOS, CMSIS RTOS in this case, so my question is basic. I want to know what is the best way to share information between two tasks.
What I am trying to do is basically a controller with some external communication. This system has two tasks.
Task 1. Controller task:
- It is executed at fixed intervals, each X ms, as fast as possible
- It has a setpoint
- It reads several sensors
- It calculates and sets several outputs
Task 2. Communication task:
- It’s a slave in a master/slave communication (Modbus). So, it only communicates when it receives a request from master
- It must be able to set the setpoint
- It must be able to read the value/status of sensors and outputs
How should these two tasks communicate? If I was not using an RTOS I will use private global variables, wrapped with some public get/set functions. But as far as I understand that is not the way to do it in a RTOS.
Should I use a queue where the communication task writes a request message, that the controller task will check every iteration? The problem I see with this solution is that the controller task must execute as fast as possible, so either the controller task only replies to one request each iteration making the communication task less responsive or, it responses to all the request making its execution time longer.