Marvee Amasi
DIIDevHeads IoT Integration Server
•Created by Enthernet Code on 5/21/2024 in #📦-middleware-and-os
Implementing Task Synchronization in RTOS for Sensor Data Processing and Display
In the above code, we are using an RTOS to create TaskA and TaskB. TaskA is responsible for receiving data from a sensor, processing it, and marking it as received. TaskB waits until TaskA marks the data as received, then it processes the received data and displays the result on an LCD screen.
To ensure synchronization between TaskA and TaskB, we are using a global flag
dataReceived
in TaskA. When TaskA receives the data, it sets the flag to 1, suspends its execution using vTaskSuspend()
, and waits for TaskB to process the data. In TaskB, we have a loop that continuously checks the dataReceived
flag. Once it becomes 1, TaskB processes the data, displays the result, clears the flag, and resumes TaskA using vTaskResume()
. We also add a small delay using vTaskDelay()
to allow TaskA some time to execute before TaskB resumes.10 replies