HeliOS is an open-source, free embedded multitasking kernel designed for various low-power embedded devices. It provides a rich, well-documented API that allows for fine control of the system and access to kernel services (system calls), enabling functionalities such as task management, scheduler management, inter-process communication, memory management, and device management, all while maintaining a minimal memory footprint. This article will delve into the core features, usage methods, and latest enhancements of HeliOS.
Lightweight Multitasking: Event-Driven and Cooperative Scheduling
HeliOS supports two multitasking models that can be used in parallel: event-driven and cooperative scheduling.
- • Event-Driven Model: Tasks enter a waiting state and only respond to task events. HeliOS supports two types of task events: direct task notifications (one task sends a notification to another task, waking up the receiving task by the scheduler) and timer-based events (task timers configure tasks to run at regular intervals).
- • Cooperative Scheduling Model: Cooperative tasks are always scheduled to run unless suspended. HeliOS’s cooperative scheduling model employs a unique “runtime balancing” algorithm that adjusts priorities based on the duration of task execution, preventing long-running tasks from monopolizing system resources. Event-driven tasks take precedence over cooperative scheduling tasks.
HeliOS’s multitasking does not rely on context switching, reducing the complexity of user management of shared resources (no need for mutexes and semaphores), and simplifying the development process. However, this also means that if a task does not relinquish control, it will monopolize all runtime, and the HeliOS scheduler cannot guarantee hard real-time performance, only soft real-time performance (meeting the expiration of waiting task timers but possibly missing deadlines).
Efficient Inter-Process Communication: Multiple Modes to Choose From
HeliOS provides three inter-process communication models:
- • Direct Task Notification: An efficient communication channel that avoids wasting runtime when tasks have nothing to do.
- • Message Queue: Created at runtime, can be shared among multiple tasks, providing a flexible FIFO communication channel.
- • Stream Buffer: Similar to a message queue but operates on single-byte streams.
- • Task Parameters: Can be used for simple inter-process communication.
Safe and Reliable Memory Management: Static Heap and Memory Protection
HeliOS has a built-in memory management system that enhances the safety of dynamic memory allocation. It uses statically allocated memory at compile time as a private heap, avoiding the use of standard library <span>malloc()</span> and <span>free()</span> functions, and reserves separate memory areas for kernel objects, reducing the risk of user application memory access corrupting kernel objects. Starting from version 0.4.0, HeliOS also supports complex memory defragmentation and consistency checks, ensuring efficient memory utilization and high integrity.
Flexible Device Driver Model: Easily Extend Functionality
HeliOS supports a kernel-mode device driver model, facilitating the development of various peripheral drivers. When the microcontroller enables MMU or MPU, it may not be able to access memory-mapped registers and I/O from user code, necessitating device drivers. HeliOS provides device driver templates to simplify the development process.
Robustness and Wide Compatibility
HeliOS (version 0.3.0 and above) has undergone static analysis testing and MISRA C:2012 checks to ensure code reliability. Although HeliOS is not certified and should not be used in safety-critical applications where life is at risk, its robustness is sufficient to meet the needs of most embedded applications.
HeliOS supports various platforms, including Arduino, ARM Cortex-M, etc. It can be easily added to projects via the PlatformIO Registry and Arduino Library Manager.
Major Improvements in HeliOS Version 0.4.x
Version 0.4.x has made significant improvements to the system call API and internal structure, making it incompatible with earlier versions. The most notable change is the introduction of a unified return type for all system calls, <span>xReturn</span> (either <span>ReturnOK</span> or <span>ReturnError</span>), which enhances error propagation mechanisms and interfaces.
Quick Start: Case Demonstration and Development Environment
HeliOS provides detailed documentation and example code to help users get started quickly.
- • Arduino IDE: Install HeliOS using the library manager and run the provided example code.
- • PlatformIO IDE: Add HeliOS to your project via the PlatformIO repository.
- • ARM Cortex-M: Download HeliOS and add it to your Keil uVision or other IDE projects, configuring CMSIS support.
- • ESP32: HeliOS does not support the ESP32 Arduino core and needs to be built using Espressif’s SDK.
Example: HeliOS Implementation of Arduino “Blink”
The traditional Arduino “Blink” example uses the <span>delay()</span> function, which causes blocking. The HeliOS version uses event-driven tasks and task timers to avoid blocking and improve efficiency.
Conclusion:
HeliOS is a powerful, lightweight, and easy-to-use embedded operating system that offers efficient multitasking, flexible inter-process communication, and reliable memory management mechanisms. Its simple design and rich features make it an ideal choice for Arduino and Cortex-M projects.
Project Address:https://github.com/heliosproj/HeliOS