SyntropicOS Documentation¶
High-Performance Bare-Metal Application Framework & Cooperative OS
SyntropicOS is a zero-overhead, production-grade C99 framework designed for deeply embedded systems. It provides stackless multitasking, non-blocking drivers, industrial fieldbuses, and display graphics for targets ranging from 8-bit microcontrollers to 32-bit Cortex-M and RISC-V targets.
Why SyntropicOS? (Design Rationale & Philosophy)¶
Deeply embedded systems present a fundamental architectural choice:
- Bare-Metal Super-Loops (
while(1)): Simple to start and zero memory overhead. However, managing timers, state machines, protocol decoders, and non-blocking I/O in a single main loop quickly results in unmaintainable code. Any blocking call halts the entire microcontroller. - Preemptive RTOS (FreeRTOS, Zephyr): Multi-tasking where every task requires an allocated stack (512 B to 4 KB RAM per task). On microcontrollers with 2 KB to 16 KB total RAM, allocating thread stacks severely constrains memory. Preemptive switches also introduce race conditions, mutex contention, context-switch overhead, and potential stack overflows.
- The SyntropicOS Approach: A cooperative OS built around stackless coroutines (protothreads
syn_pt). Tasks execute sequentially on a single system stack while syntax macros handle yielding and resumption. Continuation state costs 2 bytes of RAM per thread (uint16_t lc). Memory allocation is 100% static (zeromalloc()), preventing runtime heap fragmentation.
SyntropicOS is not the first system to use stackless coroutines — Contiki OS (created by Adam Dunkels, who invented protothreads) popularized them for microcontrollers. The difference is that every SyntropicOS module is built from the ground up with the cooperative model in mind. All 70+ drivers, protocol stacks, and subsystems expose non-blocking _poll(), _update(), or _process() APIs that yield cooperatively. There are no blocking wrappers around third-party libraries or hidden busy-waits inside module code.
Architecture & Framework Comparison¶
| Feature | Bare-Metal Super-Loop | Preemptive RTOS (FreeRTOS / Zephyr) | SyntropicOS |
|---|---|---|---|
| RAM per Thread | 0 B | 512 B – 4 KB per task (stack pointer) | 2 B per thread (uint16_t lc) |
| Concurrency Model | Manual state machines in main loop | Preemptive multi-threading | Cooperative protothreads (syn_pt) |
| Memory Allocation | Static | Dynamic heap or static pool allocation | 100% Zero-Heap / Static |
| Context Switch Cost | Zero | CPU register push/pop & stack frame swap | Zero (C99 switch continuation jump) |
| Race Conditions | None (single thread execution) | High (requires mutexes, semaphores, spinlocks) | None across yield points |
| Execution Safety | Low (blocking functions freeze system) | Stack overflow risk | High (no thread stack overflow risk) |
| Target Hardware | 8-bit to 32-bit MCUs | 32-bit MCUs (typically >32 KB RAM) | 8-bit to 32-bit MCUs (2 KB+ RAM) |
Core Concepts Explained¶
1. Stackless Protothreads (syn_pt)¶
Protothreads provide sequential, non-blocking flow control inside standard C functions without requiring separate stacks.
- Continuation via Duff's Device: PT_BEGIN() expands to a switch(pt->lc) statement. When yielding (PT_WAIT_UNTIL or PT_TASK_DELAY_MS), pt->lc records __LINE__ and returns PT_WAITING. Upon re-invocation, the switch jumps directly to the saved line.
- RAM Footprint: Stores only a uint16_t continuation variable (2 bytes RAM).
- Variable Lifetime: Local variables inside a protothread function do not persist across yields. Persistent state must be stored in static variables, global contexts, or a struct passed via user_data.
2. Cooperative Task Scheduler (syn_sched)¶
The scheduler runs an array of SYN_Task descriptors. On each tick, it executes the highest-priority ready task (priority 0 highest). Equal-priority tasks execute round-robin.
- Zero Dynamic Allocation: The application owns and allocates the SYN_Task array statically.
- Tickless Idle: Includes low-power sleep support (syn_sched_run_tickless()) when no tasks are ready.
3. Ground-Up Non-Blocking Module Ecosystem¶
Every driver and protocol module in SyntropicOS is written from scratch as a cooperative, non-blocking state machine. Modules expose _poll(), _update(), or _process() entry points (e.g. syn_modbus_poll(), syn_button_update(), syn_ble_gatt_process_att_pdu()) that do a bounded unit of work and return immediately. No module internally blocks, busy-waits, or calls delay().
Technical Specifications At-a-Glance¶
| Feature | Design Specification |
|---|---|
| Concurrency | Cooperative protothreads (syn_pt). Continuation state costs 2 bytes RAM per thread. |
| Task Scheduler | Cooperative task runner (syn_sched). Task descriptors cost ~16–28 bytes RAM per task. |
| Memory Allocation | 100% Zero-Heap / Static Allocation. No malloc() or dynamic pool fragmentation over long runtimes. |
| Execution Model | All 70+ drivers & protocol stacks are written as non-blocking state machines. |
| Compatibility | Standard C99. Compiles with GCC, Clang, IAR, Keil, STM32CubeIDE, and Arduino IDE. |
Module Documentation Index¶
Quick-jump to specific feature guides and API references:
⚡ Core & Multitasking (Read Core Docs →)¶
- Protothreads (
syn_pt): Stackless coroutines for non-blocking task execution. - Task Scheduler (
syn_sched): Cooperative task runner with priority & delay timers. - Active Objects (
syn_ao): FSM state machine + SPSC queue + task runner actor model. - Event Flags & Mailboxes: Thread-safe inter-task messaging and synchronization.
🎛️ Input / Output Drivers (Read I/O Docs →)¶
- Buttons (
syn_button): Debounced buttons, multi-click tap gestures, long-press, auto-repeat, and combos. - Rotary Encoder (
syn_encoder): Quadrature rotary decoding and velocity tracking. - LED Controller (
syn_led): Pattern blinking, flash sequences, and Morse sequences. - Software PWM (
syn_soft_pwm): Timerless PWM generation on arbitrary GPIO pins.
📡 Communications & Protocol Stacks (Read Comm Docs →)¶
- Ethernet & IP Protocol Suite (
syn_eth/syn_dhcp/syn_icmp/syn_autoip/syn_netcfg): Zero-heap Ethernet II, ARP, DHCP client, ICMP Echo ping, RFC 3927 AutoIP fallback, and Link Up/Down state machine. - COBS Framing (
syn_cobs): Zero-overhead0x00-delimited packet framing. - Packet Router (
syn_router): Addressed packet dispatch (Master/Slave Node IDs) with ACKs. - Industrial Modbus (
syn_modbus): Modbus RTU & Modbus TCP Master/Slave stacks. - Building Automation (
syn_bacnet/syn_dali): BACnet MS/TP (ISO 16484-5) & DALI Lighting (IEC 62386) protocol engines. - M-Bus Metering (
syn_mbus): EN 13757 European utility meter bus decoder. - Automotive ISO-TP & J1939: CAN bus multi-frame transport and heavy vehicle PGN/SPN decoder.
- USB 2.0 Device & Host Core (
syn_usb/syn_usb_host/syn_usb_cdc/syn_usb_hid): Zero-heap USB 2.0 device & host core engines, CDC ACM, HID class drivers, and protothread coroutines.
💾 Storage & Filesystems (Read Storage Docs →)¶
- Persistent Settings (
syn_settings): High-level configuration manager with load-or-default, change-detection & CRC-16. - Flash Wear-Leveling Engine (
syn_param): Raw sector/page wear leveling with two-phase power-fail safety. - Virtual File System (
syn_vfs): POSIX-like VFS abstraction for LittleFS and FAT.
🖥️ Display & Embedded UI (Read Display Docs →)¶
- Display Canvas (
syn_canvas): Hardware-independent 1bpp/16bpp framebuffer & 2D graphics. - Immediate-Mode GUI (
syn_imgui): Zero-heap UI widgets (buttons, sliders, gauges, graphs).
📈 DSP & TinyML Neural Networks (Read DSP & TinyML Docs →)¶
- Fixed-Point Filters (
syn_filter): Biquad lowpass/highpass, EMA, and median spike rejection. - Spectral Analysis (
syn_fft/syn_dsp): Radix-2 FFT, DCT-II, windowing, and peak tracking. - TinyML Neural Networks (
syn_nn): Quantized 1D-CNNs, 1D Pooling, Dense layers, Self-Attention, and Protothread inference.
🔬 Diagnostics & System Services (Read Debug Docs →)¶
- Lightweight Event Tracer (
syn_trace): Timestamped circular event recorder for ISRs & tasks. - Task CPU Profiler (
syn_profiler): Task CPU percentage, peak execution time, and run metrics. - Serial CLI (
syn_cli): Zero-allocation interactive shell with command auto-help. - Software Watchdog (
syn_watchdog): Multi-task heartbeat monitor and deadlock prevention.
Getting Started & Platform Guides¶
- Getting Started Guide — Step-by-step setup for C99 CMake & Makefile projects.
- IDE Integration & Setup Guides — Step-by-step setup for STM32CubeIDE, VS Code, Keil MDK, IAR, and Arduino.
- Arduino Compatibility Guide — Installing via Library Manager and working with Multi-Tab sketch examples.
- Porting & System Integration — Implementing custom GPIO, UART, and timer tick ports.