0
0
FreeRTOSprogramming~30 mins

Hard real-time vs soft real-time in FreeRTOS - Hands-On Comparison

Choose your learning style9 modes available
Hard real-time vs Soft real-time Task Handling in FreeRTOS
📖 Scenario: You are working on a small embedded system using FreeRTOS. Your system needs to handle two types of tasks:A hard real-time task that must run exactly every 100 milliseconds without fail.A soft real-time task that runs every 200 milliseconds but can tolerate some delays.This is like having a fire alarm that must sound immediately (hard real-time) and a temperature logger that can update less strictly (soft real-time).
🎯 Goal: Build a FreeRTOS program that creates two tasks: one hard real-time task that runs precisely every 100 ms, and one soft real-time task that runs every 200 ms but can skip some cycles if delayed.You will set up the tasks, configure their timing, implement their behavior, and print messages to show their execution.
📋 What You'll Learn
Create a hard real-time task function called HardRealTimeTask that runs every 100 ms using vTaskDelayUntil.
Create a soft real-time task function called SoftRealTimeTask that runs every 200 ms using vTaskDelay.
Create task handles and start the FreeRTOS scheduler.
Print messages inside each task to show when they run.
💡 Why This Matters
🌍 Real World
Embedded systems often need to handle tasks with strict timing (hard real-time) and others with flexible timing (soft real-time), such as controlling motors and logging data.
💼 Career
Understanding how to implement and differentiate hard and soft real-time tasks is essential for embedded software engineers working with FreeRTOS or similar real-time operating systems.
Progress0 / 4 steps
1
Setup Task Functions
Create two task functions called HardRealTimeTask and SoftRealTimeTask. Each should take a void *pvParameters argument and have an infinite loop with empty bodies for now.
FreeRTOS
Need a hint?

Define two functions with the exact names and infinite loops inside.

2
Configure Task Timing Variables
Create two variables: TickType_t xLastWakeTime initialized to 0 for the hard real-time task, and const TickType_t xSoftDelay = pdMS_TO_TICKS(200) for the soft real-time task delay.
FreeRTOS
Need a hint?

Use TickType_t type and initialize variables exactly as shown.

3
Implement Task Timing Logic
In HardRealTimeTask, use vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(100)) inside the loop to run every 100 ms. In SoftRealTimeTask, use vTaskDelay(xSoftDelay) inside the loop to run every 200 ms. Add printf statements inside each loop to print "Hard task running" and "Soft task running" respectively.
FreeRTOS
Need a hint?

Use vTaskDelayUntil for the hard task and vTaskDelay for the soft task with the exact delays and print statements.

4
Create Tasks and Start Scheduler
In main(), create two tasks using xTaskCreate: one for HardRealTimeTask with priority 2, and one for SoftRealTimeTask with priority 1. Then start the scheduler with vTaskStartScheduler(). Print "Scheduler started" before starting.
FreeRTOS
Need a hint?

Use xTaskCreate with the exact parameters and start the scheduler. The output should show the scheduler start message and task prints.