0
0
FreeRTOSprogramming~30 mins

Real-time vs general-purpose OS in FreeRTOS - Hands-On Comparison

Choose your learning style9 modes available
Real-time vs General-purpose OS Task Scheduling
📖 Scenario: You are working on a small embedded device that controls a home automation system. It needs to handle urgent tasks like turning off the heater immediately when the temperature is too high, and also less urgent tasks like updating the display every few seconds.This project will help you understand how a real-time operating system (RTOS) like FreeRTOS schedules tasks differently from a general-purpose OS.
🎯 Goal: You will create two tasks in FreeRTOS: one high-priority task that simulates an urgent sensor check, and one low-priority task that simulates a display update. You will see how the RTOS runs the urgent task immediately when needed, unlike a general-purpose OS that might delay it.
📋 What You'll Learn
Create two FreeRTOS tasks with different priorities
Use vTaskDelay to simulate task timing
Print messages to show which task is running
Observe task switching behavior
💡 Why This Matters
🌍 Real World
Embedded systems like home automation, robotics, and automotive use real-time OS to handle urgent tasks reliably.
💼 Career
Understanding RTOS task scheduling is essential for embedded software engineers and developers working on time-critical applications.
Progress0 / 4 steps
1
Create two FreeRTOS tasks
Write code to create two tasks named UrgentTask and DisplayTask using xTaskCreate. Use the function prototypes void UrgentTask(void *pvParameters) and void DisplayTask(void *pvParameters). Do not start the scheduler yet.
FreeRTOS
Need a hint?

Use xTaskCreate to create tasks with their function names and priorities.

2
Add task delays and print messages
Inside UrgentTask, add a printf statement to print "Urgent task running" before vTaskDelay(pdMS_TO_TICKS(1000)). Inside DisplayTask, add a printf statement to print "Display task running" before vTaskDelay(pdMS_TO_TICKS(2000)).
FreeRTOS
Need a hint?

Use printf before the delay in each task to show which task runs.

3
Start the FreeRTOS scheduler
In the main function, after creating the tasks, add the call to vTaskStartScheduler() to start the RTOS scheduler.
FreeRTOS
Need a hint?

Call vTaskStartScheduler() to begin running the tasks.

4
Observe and print the task switching output
Run the program and observe the printed output. Write a printf statement after vTaskStartScheduler() in main to print "Scheduler ended". Note that this line should never run if the scheduler works correctly. The expected output should show alternating messages from UrgentTask and DisplayTask.
FreeRTOS
Need a hint?

The scheduler runs tasks repeatedly. You should see both messages printed repeatedly. The line "Scheduler ended" should not appear unless the scheduler stops.