Nicholas Khorasani

Computer Engineer | Software Engineer

TinyRTOS: Real-Time Operating System in C

January – April 2024

TLDR

  • Designed, programmed, and tested a custom real-time operating system (RTOS) kernel in C on an Intel DE1-SoC FPGA board with a team of four.
  • Implemented dynamic memory using first-fit allocation with a linked-list free list, block splitting/coalescing, fragmentation tracking, and leak tests.
  • Built dynamic task management with a preemptive, priority-based scheduler. Two-level design: a red-black tree stores active priorities, each pointing to a FIFO ready queue for tasks at that priority (O(1) highest-priority pick, O(log n) updates).
  • Added mailbox-based inter-process communication (IPC) with a ring buffer for typed messages and sender IDs, supporting inter-task messaging and I/O.
  • Included a Keyboard Command Dispatcher (KCD) system task to parse keyboard input and route commands to registered tasks.

Architecture

  • Data structures: Task Control Blocks (TCBs), red-black tree of active priorities, per-priority ready lists, linked-list free list, mailbox ring buffer.
  • Scheduling: preemptive priority scheduling; pick via RB-tree minimum then pop from the corresponding ready queue; supports yield and priority changes.
  • Memory: first-fit allocation, 8-byte alignment, header guards with task ID, adjacent coalescing, external fragmentation counter.
  • IPC & I/O: mailbox create/send/recv with wrap-around copy; KCD routes “%x…” commands as messages to tasks.

Code

💻 GitHub Repository

What I Learned

  1. Building low-level OS components in C is difficult, and requires careful planning.
  2. Data structure choices (RB-tree + ready queues) significantly impact program performance and predictability.
  3. Developed a much deeper understanding of how operating systems manage resources, schedule tasks, and enable arbitrary computation safely.
  4. Gained practical experience in debugging and testing on embedded hardware (Intel DE1-SoC) with constrained I/O.