We use different types of operating systems to handle tasks depending on how fast and predictable the response needs to be.
Real-time vs general-purpose OS in 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.
/* Real-time OS task example in FreeRTOS */ void BlinkTask(void *pvParameters) { for(;;) { ToggleLED(); vTaskDelay(pdMS_TO_TICKS(500)); } }
/* General-purpose OS example: running a program */ #include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
This FreeRTOS program creates a task that prints "LED ON" and "LED OFF" every 500 milliseconds, showing real-time behavior.
#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; }
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.
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.