OS Notes
Embedded Operating Systems — characteristics, architecture, memory constraints, scheduling in embedded systems, examples (FreeRTOS, Embedded Linux), and IoT applications.
Introduction
An embedded operating system runs on specialized hardware designed for a specific purpose — unlike a general-purpose OS that runs on PCs and servers. Your washing machine, car dashboard, smartwatch, Wi-Fi router, and insulin pump all run embedded operating systems. These systems have strict constraints that general-purpose operating systems cannot meet: limited memory (kilobytes, not gigabytes), limited processing power, real-time deadlines, and requirements for continuous operation without crashes or reboots.
There are more embedded systems in the world than all PCs and servers combined. Every person in a developed country interacts with dozens of embedded systems daily, usually without realizing it.
Characteristics of Embedded OS
Resource Constraints
| Resource | Desktop/Server OS | Embedded OS |
|---|---|---|
| RAM | 8-128 GB | 2 KB - 512 MB |
| Storage | 256 GB - 10 TB | 64 KB - 32 GB |
| CPU | Multi-core GHz | Single-core MHz |
| Power | Unlimited (wall outlet) | Battery (years of life) |
| Cost per unit | $500-$5000 | $0.50-$50 |
Dedicated Functionality
An embedded OS is designed for ONE purpose. A thermostat OS does not need a web browser, a file manager, or multi-user login. This allows the OS to be stripped down to only essential components, reducing code size, memory usage, and attack surface.
Real-Time Requirements
Many embedded systems must respond to events within strict time bounds:
- Airbag deployment: < 10 milliseconds
- Engine fuel injection timing: microsecond precision
- Industrial robot arm: millisecond position updates
- Heart rate monitor: consistent sampling intervals
Reliability and Uptime
Embedded systems often cannot be rebooted or patched:
- A pacemaker must run for 10+ years without failure
- A satellite OS cannot be physically accessed for repairs
- An industrial controller cannot randomly restart during manufacturing
Embedded OS Architecture
Monolithic (Single Address Space)
The simplest architecture — application and OS code share the same address space with no memory protection. Used in very constrained systems.
Examples: FreeRTOS, bare-metal RTOS Used when: < 256 KB RAM, no MMU hardware, cost-sensitive
Microkernel (Minimal Kernel + User Services)
Kernel provides only essential services (scheduling, IPC). Device drivers and file systems run as separate processes with memory protection.
Examples: QNX, INTEGRITY, seL4 Used when: Safety-critical systems requiring fault isolation (medical, automotive, aerospace)
Embedded Linux
Full Linux kernel adapted for embedded hardware. Provides standard APIs, networking stack, and driver ecosystem.
Examples: Yocto-built Linux, OpenWrt (routers), Android (phones) Used when: System has 32+ MB RAM, needs networking, file systems, or standard application framework
Scheduling in Embedded Systems
Embedded schedulers are simpler and more deterministic than desktop schedulers:
Priority-Based Preemptive Scheduling
The most common embedded scheduling approach:
- Each task assigned a fixed priority at design time
- Highest-priority ready task always runs
- Lower-priority task preempted immediately when higher-priority task becomes ready
- No time-slicing between tasks of equal priority (strict priority)
// FreeRTOS task creation example
void vTask1(void *pvParameters) {
while (1) {
read_sensor();
process_data();
vTaskDelay(pdMS_TO_TICKS(100)); // sleep 100ms
}
}
void vTask2(void *pvParameters) {
while (1) {
check_alarm_condition();
vTaskDelay(pdMS_TO_TICKS(10)); // runs more frequently
}
}
int main(void) {
xTaskCreate(vTask1, "Sensor", 128, NULL, 1, NULL); // priority 1
xTaskCreate(vTask2, "Alarm", 128, NULL, 3, NULL); // priority 3 (higher)
vTaskStartScheduler();
}Cooperative Scheduling
Tasks voluntarily yield the CPU. Simpler than preemptive (no need for critical sections) but a misbehaving task can block the entire system.
Used in: Very simple systems, Arduino-style "super loop" patterns.
Rate Monotonic Scheduling
For periodic tasks: assign priority inversely proportional to period. Mathematically proven optimal for fixed-priority scheduling of periodic tasks.
Memory Management in Embedded Systems
No Virtual Memory
Most small embedded systems lack an MMU (Memory Management Unit). Consequences:
- No address translation — logical addresses equal physical addresses
- No memory protection — a bug in one task can corrupt another's data
- No demand paging — all code and data must fit in physical RAM
- Static allocation preferred — dynamic allocation (malloc) avoided for predictability
Memory Allocation Strategies
Why avoid malloc/free in embedded:
- Non-deterministic execution time (fragmentation → searching)
- Memory fragmentation over time can exhaust memory despite sufficient total free space
- Hard to prove worst-case memory usage for safety certification
Power Management
Battery-powered embedded systems spend most of their time sleeping to conserve power:
| Active Mode | CPU running, full power consumption |
| Idle Mode | CPU halted, peripherals active, wake on interrupt |
| Deep Sleep | Most peripherals off, wake on timer or external event |
| Power Off | Only RTC running, wake on alarm or button press |
The embedded OS manages transitions between power states:
- Put CPU to sleep whenever no task is ready
- Power down unused peripherals
- Adjust clock frequency based on workload (DVFS)
A well-designed embedded system might spend 99.9% of its time sleeping, waking for milliseconds to do its job.
Examples of Embedded Operating Systems
| OS | RAM Required | Key Feature | Used In |
|---|---|---|---|
| FreeRTOS | 4-64 KB | Minimal, widely ported | IoT, microcontrollers |
| Zephyr | 8-256 KB | Modern, Bluetooth/network stack | Wearables, IoT |
| RIOT | 1.5 KB+ | IoT-focused, POSIX-like API | Sensor networks |
| Mbed OS | 32+ KB | ARM ecosystem integration | ARM Cortex-M devices |
| QNX | 512 KB+ | Microkernel, safety-certified | Cars, medical devices |
| VxWorks | 256 KB+ | Aerospace-grade reliability | Satellites, rovers |
| Embedded Linux | 32+ MB | Full features, broad hardware support | Routers, cameras, phones |
IoT and Embedded OS
The Internet of Things (IoT) has created new demands for embedded operating systems:
- Networking: TCP/IP, MQTT, CoAP protocols on devices with 32 KB RAM
- Security: TLS encryption, secure boot, over-the-air updates
- Cloud connectivity: Device-to-cloud communication (AWS IoT, Azure IoT Hub)
- Interoperability: Standard APIs so devices from different manufacturers work together
Key Takeaways
- Embedded OS operates under severe resource constraints (KB of RAM, MHz processors)
- Priority-based preemptive scheduling is the standard approach
- No virtual memory in small systems — static allocation preferred for predictability
- Power management is critical — most time spent in low-power sleep states
- FreeRTOS dominates small microcontrollers; Embedded Linux dominates larger systems
- Safety-critical applications (medical, automotive) require certified OS like QNX or INTEGRITY
- The IoT revolution is driving embedded OS to add networking and security features
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Embedded Operating Systems - Real-time and Resource-Constrained.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, distributed, and, modern, embedded
Related Operating Systems Topics