0
0
FreeRTOSprogramming~5 mins

Real-time vs general-purpose OS in FreeRTOS

Choose your learning style9 modes available
Introduction

We use different types of operating systems to handle tasks depending on how fast and predictable the response needs to be.

When you need a system to respond immediately, like controlling a robot arm.
When running a device that plays music or videos smoothly without delays.
When building a simple computer that runs many programs but speed is not critical.
When creating a system that must guarantee actions happen within a strict time limit.
When developing a device that can handle many tasks but can tolerate some delays.
Syntax
FreeRTOS
/* No specific code syntax for this concept, but here is a simple FreeRTOS task example */
void TaskFunction(void *pvParameters) {
    for(;;) {
        // Task code here
        vTaskDelay(pdMS_TO_TICKS(100));
    }
}

FreeRTOS is a real-time operating system designed to run tasks with precise timing.

General-purpose OS like Windows or Linux focus on running many programs but may delay tasks unpredictably.

Examples
This task toggles an LED every 500 milliseconds with precise timing.
FreeRTOS
/* Real-time OS task example in FreeRTOS */
void BlinkTask(void *pvParameters) {
    for(;;) {
        ToggleLED();
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}
This program runs on a general OS like Linux or Windows without strict timing guarantees.
FreeRTOS
/* General-purpose OS example: running a program */
#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}
Sample Program

This FreeRTOS program creates a task that prints "LED ON" and "LED OFF" every 500 milliseconds, showing real-time behavior.

FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>

void BlinkTask(void *pvParameters) {
    for(;;) {
        printf("LED ON\n");
        vTaskDelay(pdMS_TO_TICKS(500));
        printf("LED OFF\n");
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}

int main(void) {
    xTaskCreate(BlinkTask, "Blink", 1000, NULL, 1, NULL);
    vTaskStartScheduler();
    for(;;) {}
    return 0;
}
OutputSuccess
Important Notes

Real-time OS guarantees tasks run on time, which is important for devices like medical machines or robots.

General-purpose OS are better for everyday computers where many programs run but exact timing is less critical.

FreeRTOS is popular for small devices needing real-time control.

Summary

Real-time OS respond quickly and predictably to events.

General-purpose OS handle many tasks but may delay some unpredictably.

Choose the OS type based on how important timing is for your project.