
Ultra-leichtes RTOS für IoT mit präemptivem Scheduling, TLS/DTLS, MQTT, CoAP, POSIX-Kompatibilität und MPU-basierter Speicherschutz. Kernel unter 10 KB.
Ein ultraleichtes Echtzeitbetriebssystem für ressourcenbeschränkte IoT- und eingebettete Geräte.
Kernel-Footprint unter 10 KB, 2 KB minimaler RAM, präemptives prioritätsbasiertes Scheduling.
| Kategorie | Details |
|---|---|
| Kernel | Präemptives prioritätsbasiertes Scheduling (256 Stufen), Round-Robin innerhalb gleicher Priorität, O(1)-Prioritätssuche via Bitmap, Prioritätsvererbung |
| Synchronisierung | Mutex (mit Prioritätsvererbung), Semaphore, Bedingungsvariable, Ereignisgruppen, Nachrichtenwarteschlangen |
| Software-Timer | Einmalig und automatisch wiederholend, Millisekundengenauigkeit, Periodenänderung zur Laufzeit |
| Speicher | First-Fit-Allokator mit sofortiger Zusammenführung (8 KB Heap, 8-Byte-ausgerichtet), Stapelüberlauferkennung, High-Water-Mark pro Task |
| Shell | VT100-interaktive Shell — 23 eingebaute Befehle, Befehlshistorie (↑↓), Tab-Vervollständigung, vollständiger Zeileneditor |
| POSIX-Kompatibilität | pthreads (create/join/detach/exit, mutex, cond var) · BSD-Socket-API (socket/bind/listen/accept/connect/send/recv, inet_pton/ntop, htons/htonl) |
| Dateisystem | Journaling-Blockgerät-Dateisystem (WAL, Crash-Wiederherstellung), COW-Block-Sharing, atomare Snapshots, POSIX-ähnliche API |
| Netzwerk | Ethernet, IPv4, ICMP, UDP, TCP, HTTP-Client/Server, DNS |
| TLS / DTLS | TLS 1.2/1.3 über TCP, DTLS 1.2 über UDP (mbedTLS-Backend) |
| MQTT | Vollständig MQTT 3.1.1 — QoS 0/1/2 mit In-Flight-Wiederholungstabelle, Offline-Warteschlange, automatische Wiederverbindung mit exponentiellem Backoff |
| CoAP | RFC 7252-konformer Client/Server, Observe-Muster |
| OTA | A/B-Partition-Firmware-Updates, CRC32-Überprüfung, Rollback |
| Watchdog | Hardware- und Software-Watchdog, Timeout-Überwachung pro Task |
| Energie | Leerlauf-/Schlaf-/Tiefschlafmodi, tickless idle, CPU-Frequenzskalierung |
| Sicherheit | MPU-basierter Speicherschutz, Unterstützung für sicheren Boot |
| HAL | Generische Hardware-Abstraktionsschicht — ARM Cortex-M / RISC-V / AVR; Architekturauswahl zur Kompilierzeit, periphere Operationstabellen |
| Architektur | Beispiele |
|---|---|
| ARM Cortex-M (M0/M0+/M3/M4/M7) | STM32, nRF52, Raspberry Pi Pico |
| RISC-V (RV32I) | ESP32-C3 |
| AVR (experimentell) | ATmega |
sudo apt-get install -y gcc-arm-none-eabi binutils-arm-none-eabi
sudo apt-get install -y qemu-system
Installation überprüfen:```bash
arm-none-eabi-gcc --version # 10.x or later
qemu-system-arm --version # 6.x or later
make
make ARCH=cortex-m0 # Cortex-M0/M0+ make ARCH=cortex-m7 # Cortex-M7 make ARCH=riscv32 # RISC-V RV32I (uses riscv32-unknown-elf-gcc) make ARCH=avr5 # AVR ATmega (uses avr-gcc)
make EXAMPLE=blink_led # LED blink + task scheduler demo make EXAMPLE=event_groups # Event group AND/OR/NOT/SYNC demo make EXAMPLE=iot_sensor # Multi-sensor IoT node make EXAMPLE=shell_demo # Interactive UART shell make EXAMPLE=mqtt_demo # MQTT publish/subscribe make EXAMPLE=condition_variable # Producer/consumer
make example-blink make example-events make example-shell make example-mqtt make example-iot
make size # Print ROM/RAM usage
Build-Artefakte werden in `build/` abgelegt:
| Datei | Beschreibung |
|---|---|
| `build/tinyos.elf` | ELF-Image mit Debug-Symbolen |
| `build/tinyos.bin` | Rohbinärdatei zum Flashen |
| `build/tinyos.map` | Linker-Map (Symbolgrößen) |
### Ausführen auf QEMU
TinyOS läuft auf dem QEMU `mps2-an385`-Ziel (ARM Cortex-M3, 4 MB Flash, 4 MB RAM):```bash
# Run indefinitely (Ctrl-A X to quit)
qemu-system-arm \
-machine mps2-an385 \
-cpu cortex-m3 \
-nographic \
-kernel build/tinyos.elf
# Run for a fixed duration (e.g. 10 seconds)
timeout 10 qemu-system-arm \
-machine mps2-an385 \
-cpu cortex-m3 \
-nographic \
-kernel build/tinyos.elf
# Debug: trace interrupts
qemu-system-arm \
-machine mps2-an385 \
-cpu cortex-m3 \
-nographic \
-d int \
-kernel build/tinyos.elf
Die erwartete Ausgabe von der Interrupt-Trace: wiederholte successful exception return-Zeilen bestätigen, dass der Scheduler läuft, SysTick tickt und PendSV-Kontextwechsel sauber abgeschlossen werden.
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg
-c "program build/tinyos.bin verify reset exit 0x08000000"
pyocd flash --target cortex_m build/tinyos.bin
### Build mit TLS (mbedTLS)
TLS-Unterstützung wird automatisch aktiviert, wenn mbedTLS unter `~/mbedtls` vorhanden ist.
Um einen anderen Pfad zu verwenden:```bash
# Clone and build mbedTLS
git clone https://github.com/Mbed-TLS/mbedtls ~/mbedtls
make -C ~/mbedtls
# Build TinyOS with TLS
make MBEDTLS_DIR=~/mbedtls
Minimales Aufgabenbeispiel:```c #include "tinyos.h"
void my_task(void param) { while (1) { / work */ os_task_delay_ms(100); } }
int main(void) { tcb_t task; os_init(); os_task_create(&task, "my_task", my_task, NULL, PRIORITY_NORMAL); os_start(); }
---
## API-Übersicht
### Aufgabenverwaltung```c
os_task_create(tcb, name, entry, param, priority)
os_task_delete(task)
os_task_suspend(task) / os_task_resume(task)
os_task_delay(ticks) / os_task_delay_ms(ms)
os_task_set_priority(task, priority)
os_task_get_stats(task, stats)
os_task_get_stats_by_index(index, stats) /* iterate all tasks by index */
os_task_find_by_name(name) /* returns tcb_t*, NULL if not found */
os_get_system_stats(stats)
os_get_memory_stats(&free, &used, &allocs, &frees)
os_mutex_init(mutex) / os_mutex_lock(mutex, timeout) / os_mutex_unlock(mutex) os_semaphore_init(sem, count) / os_semaphore_wait(sem, timeout) / os_semaphore_post(sem) os_cond_init(cond) / os_cond_wait(cond, mutex, timeout) os_cond_signal(cond) / os_cond_broadcast(cond) os_event_group_set_bits(eg, bits) / os_event_group_wait_bits(eg, bits, opts, out, timeout) os_queue_init(q, buf, item_size, max) / os_queue_send(q, item, timeout) os_queue_receive(q, item, timeout) / os_queue_peek(q, item, timeout)
### Timer```c
os_timer_create(timer, name, type, period_ms, callback, param)
os_timer_start(timer) / os_timer_stop(timer) / os_timer_reset(timer)
os_timer_change_period(timer, ms) / os_timer_get_remaining_ms(timer)
/* Register custom commands before calling shell_start() */ shell_register_cmd(name, handler_fn, help_text)
/* Provide UART I/O callbacks and start the shell task */ shell_io_t io = { .getc = uart_getc, .puts = uart_puts }; shell_start(&io)
/* Change the prompt at any time */ shell_set_prompt("mydevice> ")
/* Execute a single line programmatically */ shell_exec(line)
**Beispiel für benutzerdefinierten Befehl:**```c
static int cmd_led(int argc, char *argv[]) {
if (argc < 2) return 1; /* non-zero → prints usage */
bool on = (strcmp(argv[1], "on") == 0);
gpio_write(LED_PIN, on);
return 0;
}
/* In main(), before shell_start(): */
shell_register_cmd("led", cmd_led, "led <on|off> Toggle LED");