LiLoS: A Minimal Asynchronous Real-Time Operating System, A Tool for Embedded Development

LiLoS is a minimal asynchronous real-time operating system (RTOS) designed for asynchronous programming in microcontrollers using Rust. It occupies a very small space (approximately 2KB Flash and 40 bytes RAM) yet features a complete asynchronous runtime, multi-tasking support, complex concurrency support based on <span>join</span> and <span>select</span>, as well as a simple and easy-to-use API. This article will detail the features, architecture, build methods, and usage examples of LiLoS.

The Core Advantages of LiLoS

The core of LiLoS lies in its extremely low resource consumption and powerful asynchronous programming capabilities. Unlike many large RTOS, LiLoS focuses on core functionalities, providing efficient asynchronous task scheduling and concurrency control mechanisms. Its design philosophy is to offer maximum programming convenience with minimal resource consumption. This makes it particularly suitable for resource-constrained embedded systems, such as various microcontrollers. Since 2019, LiLoS has been successfully deployed in multiple real-world embedded systems and continues to operate stably.

Architecture Design and Code Structure

The codebase of LiLoS adopts a modular design, with different components located in separate subdirectories, and uses the <span>.cargo/config.toml</span> file to configure build settings specific to each component (e.g., target architecture). This allows each component to be built and tested independently, facilitating code maintenance and expansion.

  • <span>os</span> directory: Core operating system code, including the task scheduler, asynchronous runtime, memory management, and other key components.
  • <span>testsuite</span> directory: A test suite for testing the operating system’s functionalities, which can run on Cortex-M0 and above architecture microcontrollers.
  • <span>examples</span> directory: Contains example programs for different microcontrollers, making it easy for users to get started and learn.
  • <span>extra</span> directory: Contains some non-core libraries that provide additional functionalities, such as:
    • <span>handoff</span>: For synchronizing data transfer between tasks, minimizing data copying.
    • <span>semaphore</span>: Implementation of counting semaphores.
    • <span>rwlock</span>: Implementation of read-write locks.

This clear directory structure and modular design make LiLoS easy to understand, extend, and maintain.

Building and Using LiLoS

To build and use LiLoS, you need to install the Rust toolchain (via rustup). LiLoS uses the <span>rust-toolchain.toml</span> file to specify the required toolchain version, ensuring build consistency.

Build process:

  1. Navigate to the target directory (e.g., <span>cd os</span>).
  2. Execute <span>cargo build</span> (or <span>cargo build --release</span> to build smaller binaries).
  3. For example programs on microcontrollers, refer to the README files in each example directory. Typically, executing <span>cargo run</span> in the example directory will suffice.
  4. To build everything in the repository, run the <span>./build-all.sh</span> script.

Example Programs and Application Scenarios

The <span>examples</span> directory of LiLoS provides various example programs for different microcontrollers, demonstrating the application methods and functionalities of LiLoS. These examples cover various common embedded application scenarios, such as simple LED control, sensor data collection and processing, etc. By studying these examples, developers can quickly master the usage of LiLoS and apply it to their projects. The lightweight nature of LiLoS makes it particularly suitable for resource-constrained embedded systems, such as:

  • IoT Devices: LiLoS can serve as the core operating system for IoT devices, efficiently managing various sensors and network connections.
  • Real-Time Control Systems: LiLoS can be used to build real-time control systems, such as industrial automation control and robotic control.
  • Embedded Applications: LiLoS can be used to develop various embedded applications, such as data acquisition systems and remote monitoring systems.

Conclusion

LiLoS is a powerful, resource-efficient asynchronous real-time operating system, particularly suitable for resource-constrained embedded system development. Its simple and easy-to-use API and modular design enable developers to quickly get started and build efficient asynchronous applications. LiLoS has been validated through real projects, demonstrating its stability and reliability. If you are looking for a lightweight and efficient RTOS, LiLoS is an ideal choice.

Project Address: https://github.com/cbiffle/lilos

Leave a Comment