How tencent/tencentos-tiny works
Project Type and Purpose
• This is a real-time operating system (RTOS) for IoT devices (TobudOS, formerly TencentOS Tiny).
• It provides a small-footprint, modular RTOS kernel plus a set of IoT protocol stacks and peripheral drivers that can be configured, trimmed, and ported to various MCUs (e.g., STM32, LoRa, NB-IoT modules).
High-Level Architectural Components
a. Hardware Platform Layer
• Target microcontroller or SoC
• On-chip peripherals (timers, UART, SPI, I²C, ADC, etc.)
b. Hardware Abstraction Layer (HAL) / Board Support Package (BSP)
• MCU startup code (reset, vector table)
• Low-level drivers exposing uniform APIs
• MCU-specific configurations (clock, NVIC)
c. RTOS Kernel Core
• Scheduler (tick or tickless)
• Thread/task management
• Inter-task communication (queues, semaphores, mutexes, event flags)
• Memory management (heap, stack, pool)
• Timers and tick management
• Interrupt dispatcher
d. Kernel Components (configurable modules)
• Dynamic memory allocator (optional)
• Power management hooks
• Hook and trace interfaces
e. Middleware / Protocol Stack Layer
• Networking stacks: CoAP, MQTT, TLS/DTLS, LoRaWAN, NB-IoT
• File systems (if any)
• Device management protocols
f. Application Layer
• User-defined tasks and services
• Sample demos (sensor reading, connectivity examples)
g. Build & Configuration
• Kconfig or menuconfig-style configuration files
• Board / architecture directories
• Makefiles or CMake scripts
h. External Services
• Cloud IoT platforms (MQTT broker, CoAP server)
• OTA update servers
Relationships and Data Flow
• Application tasks invoke RTOS APIs (taskCreate, msgQueueSend, etc.).
• RTOS Kernel dispatches tasks based on priority and timing.
• Tasks interact with HAL drivers for peripherals (e.g., SPI_Read).
• Networking middleware uses sockets or driver APIs to send/receive data via the hardware NIC or modem.
• Kernel timers trigger callbacks in middleware or application for scheduled events.
• Interrupts enter the kernel’s ISR entry points, possibly signaling tasks or semaphores.
Architectural Patterns and Design Principles
• Layered architecture: clear separation of hardware, kernel core, middleware, and application.
• Modular and configurable components: compile-time inclusion/exclusion of kernel modules and protocol stacks.
• Hardware abstraction for portability: BSP and HAL isolate MCU specifics.
• Event-driven and preemptive scheduling model for real-time responsiveness.
• Hook interfaces for custom tracing, power management, or debug.
Essential Elements to Capture
• All RTOS subsystems (scheduler, IPC, memory).
• HAL modules mapped to hardware peripherals.
• Middleware protocols as optional modules.
• Build/configuration layer showing how features are enabled or disabled.
• External cloud or service endpoints.