How pdlsurya/sanortos works
Project Type and Purpose
• This is an embedded Real-Time Operating System (RTOS) library (sanoRTOS) written in C, targeting ARM Cortex-M and RISC-V microcontrollers.
• It provides preemptive, priority-based scheduling, synchronization primitives (mutex, semaphore, condition variable), inter-task message queues, software timers, and SMP support.
File Structure Analysis
• Top-level directories:
• /sanoRTOS – public API headers (task management, synchronization, scheduler, timer)
• source/ – core kernel implementation (scheduler, task queue, synchronization primitives)
• ports/ – Hardware Abstraction Layer (HAL) for each supported architecture (ARM/nrf52, ARM/rp2350, ARM/stm32, RISC-V/esp32c6, RISC-V/rp2350)
• Build/deployment artifacts are minimal; no complex scripts. The design enforces a clear separation between the portable kernel core (source + include) and the architecture-specific port layer.
Key Components
a. Application Layer
• User tasks defined via TASK_DEFINE, calling API functions (taskStart, mutexLock, msgQueueSend, etc.).
b. API Layer (include/sanoRTOS headers)
• Task Management, Spin‐Lock, Mutex, Semaphore, Condition Variable, Message Queue, Timer APIs.
c. Kernel Core (source/*.c)
• scheduler.c: manages ready queues and context switches
• taskQueue.c: priority‐based task ready list
• synchronization primitives (mutex.c, semaphore.c, conditionVariable.c, messageQueue.c)
• timer.c: software timer management
• mem.c: stack overflow monitoring
d. HAL / Port Layer (ports/…/port.c, port.S)
• port_init: configure CPU registers for context switching
• osSysTick_Handler, PendSV_Handler, SVC_Handler: interrupt handlers for tick, context switch, system calls
• low-level routines to save/restore CPU context
e. Hardware Layer
• Microcontroller cores (ARM Cortex-M, RISC-V), SysTick timer, memory subsystem, NVIC (interrupt controller).
Relationships and Data Flows
• Application → API calls → Kernel Core
• Kernel Core invokes Port Layer functions for context save/restore and interrupt registration
• Port Layer interacts with Hardware (SysTick interrupt, CPU registers)
• Scheduler tick (hardware interrupt) triggers osSysTick_Handler → schedulerCore → PendSV to perform context switch
• Tasks synchronize via kernel primitives, communicate via message queues
• Software timers maintained in kernel core, driven by SysTick ticks
Architectural Patterns and Principles
• Layered architecture: Application → API → Kernel Core → HAL → Hardware
• Separation of concerns: Core RTOS logic is portable; ports handle architecture specifics
• Static object definitions (macros for TASK_DEFINE, MUTEX_DEFINE) for zero dynamic allocation
• Priority-based preemptive scheduling with optional priority inheritance
• Modular synchronization primitives for extensibility