0
0
FreeRTOSprogramming~30 mins

Health monitoring and heartbeat in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Health Monitoring and Heartbeat in FreeRTOS
📖 Scenario: You are building a simple health monitoring system for a FreeRTOS-based embedded device. The system needs to track the heartbeat of a task to ensure it is running properly. If the heartbeat is missed, the system should detect it and raise an alert.
🎯 Goal: Create a FreeRTOS task that sends a heartbeat signal periodically. Then, implement a monitoring task that checks the heartbeat and prints a message if the heartbeat is missed.
📋 What You'll Learn
Create a global variable heartbeat_flag to track heartbeat status
Create a task HeartbeatTask that sets heartbeat_flag to 1 every 1000 ms
Create a task MonitorTask that checks heartbeat_flag every 1500 ms
If heartbeat_flag is 0, print "Heartbeat missed!"
If heartbeat_flag is 1, print "Heartbeat received." and reset heartbeat_flag to 0
💡 Why This Matters
🌍 Real World
Heartbeat monitoring is used in embedded systems to detect if critical tasks are running properly and to trigger recovery actions if they fail.
💼 Career
Understanding task health monitoring and heartbeat mechanisms is important for embedded software developers and DevOps engineers working with real-time systems.
Progress0 / 4 steps
1
Create the heartbeat flag variable
Create a global variable called heartbeat_flag and initialize it to 0.
FreeRTOS
Need a hint?

Use volatile int heartbeat_flag = 0; to declare the flag.

2
Create the HeartbeatTask
Create a FreeRTOS task function called HeartbeatTask that sets heartbeat_flag to 1 every 1000 milliseconds using vTaskDelay.
FreeRTOS
Need a hint?

Use an infinite loop and vTaskDelay(pdMS_TO_TICKS(1000)); to wait 1 second.

3
Create the MonitorTask
Create a FreeRTOS task function called MonitorTask that checks heartbeat_flag every 1500 milliseconds. If heartbeat_flag is 0, print "Heartbeat missed!". If it is 1, print "Heartbeat received." and reset heartbeat_flag to 0.
FreeRTOS
Need a hint?

Use an infinite loop and check heartbeat_flag. Use printf to print messages.

4
Print the heartbeat status in main
In the main function, create the tasks HeartbeatTask and MonitorTask using xTaskCreate. Start the scheduler with vTaskStartScheduler(). The program should print heartbeat status messages.
FreeRTOS
Need a hint?

Use xTaskCreate to create tasks and vTaskStartScheduler() to start FreeRTOS.