A Learning Project for Real-Time OS Concepts, Task Scheduling, and Embedded Systems
Embedded RTOS Simulator — small, realistic RTOS kernel written in C for learning and interviews.
Implements a preemptive priority scheduler, message queues (strings), semaphores, simulated UART, shell CLI, timer & interrupt simulation, logging and diagnostics — no hardware required.
- Why this project
- Features
- Architecture & design
- Build & run
- Shell / Command Line Interface
- Example session
- Tests & Continuous Integration
- Limitations & future work
- License
This repository is built to teach the core concepts of operating systems and real-time embedded software through a hands-on, incremental approach:
- Learn how kernels schedule tasks and handle concurrency
- Understand interrupts, ISRs and how they wake tasks
- Practice writing firmware-style C (no OS abstractions)
-
Kernel fundamentals
- Task Control Block (TCB) style
Taskstructure - Task states:
READY,RUNNING,BLOCKED,SLEEPING,TERMINATED - Preemptive priority-based scheduler with round-robin tie-break
- Idle task + CPU usage monitoring
- Task Control Block (TCB) style
-
IPC & sync
- Message queue (string messages)
- Binary semaphore (mutex-like behavior)
-
Peripherals (simulated)
- UART simulation (TX/RX circular buffers)
- Timer simulation with
timer_isr()callback - Interrupt vector table (
registerInterrupt/triggerInterrupt)
-
User Interface
- CLI shell running as a task with commands:
help,list,send,pause,resume,kill,log show,log clear,set threshold,status,trigger_interrupt, etc.
- CLI shell running as a task with commands:
-
Diagnostics
- Log buffer for sensor data
statuscommand shows queue usage, tick count, task counts, CPU usage
High-level components:
- main loop:
tick()→runScheduler()→sleep/usleep(simulated) - scheduler: selects highest-priority READY task, runs it (preemptive)
- tick(): advances sleep counters, triggers shell wakeups and timer ISR
- interrupt module: simple vector table and API to register/trigger ISRs
- IPC: circular queue for string messages
- Shell: user-facing CLI to control runtime
+--------------------------------------------------+
| Shell Task |
| (User Commands: list, send, kill, pause, etc.) |
+--------------------------------------------------+
| |
v v
+---------------------+ +---------------------+
| Sensor Reader | | LED Blinker |
| (Simulated sensors) | | (Status LED toggle) |
+---------------------+ +---------------------+
| ^
v |
+---------------------+ +---------------------+
| Data Logger |<--| Message Queue |
| (Logs temperature) | | (IPC mechanism) |
+---------------------+ +---------------------+
^
|
+---------------------+
| Interrupt Handlers |
| (Timer, Button ISR) |
+---------------------+
- Linux / macOS:
gcc,make - Windows: MSYS2 with
base-devel,gcc,make
git clone https://github.com/hitesh-bhatnagar/Embedded-RTOS-Simulator-C-Learning-Project.git
cd Embedded-RTOS-Simulator-C-Learning-Project
make clean
make
./rtoshelp - Show help list - List all tasks and their state send - Send string message to queue log show - Show in-memory log log clear - Clear the log buffer pause - Pause (BLOCK) a task resume - Resume (READY) a task kill - Terminate a task trigger - Manually set a task READY trigger_interrupt - Call registered ISR (simulate button/timer) status - Print detailed system status clear - Clear terminal screen
[SHELL] >>> help
[SHELL] >>> send Hello from RTOS
[SHELL] >>> log show
[SHELL] >>> trigger_interrupt 0
[SHELL] >>> status===== RTOS Booting =====
[KERNEL] Task Created: ID=0 | Name=Sensor_Reader | Priority=1
[KERNEL] Task Created: ID=1 | Name=Logger | Priority=1
[KERNEL] Task Created: ID=2 | Name=LED_Blinker | Priority=1
[KERNEL] Task Created: ID=3 | Name=ShellTask | Priority=2
[TICK 0]
[SCHEDULER] Running task: ShellTask (Priority: 2)
[SHELL] >> list
Task[0]: Sensor_Reader | State: READY | Priority: 1
Task[1]: Logger | State: READY | Priority: 1
Task[2]: LED_Blinker | State: READY | Priority: 1
Task[3]: ShellTask | State: RUNNING | Priority: 2
This project uses GitHub Actions for automated Continuous Integration (CI).
Every time code is pushed or a pull request is opened, GitHub automatically:
- Builds the RTOS Simulator on a fresh environment
- Verifies that all files compile without errors or warnings
- Confirms that the build completes successfully on Linux
- The workflow file is located in
.github/workflows/ci.yml - It runs the build using GCC inside a Linux runner
- Any compilation failure will break the build and mark the commit as ❌
If you want to check the build on your own system:
# Build the RTOS Simulator
gcc -o rtos src/*.c -Iinclude
# Run the simulator
./rtos-
This is a simulation running on a host OS — not a real microcontroller. Timing and power states are approximated.
-
No actual context switching of CPU registers is performed (we call task functions directly).
-
No stack/heap per task simulation (can be added later).
-
Implement nested interrupts and interrupt priorities
-
Task stack usage simulation and simulated per-task memory limits
This project is licensed under the MIT License.
-
Export log to file / CSV
-
Add a small unit-test harness for modules
-
Port demo tasks to run on a microcontroller (STM32/ESP32) as follow-up project