All Projects → r3-os → r3

r3-os / r3

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
R3-OS — Experimental static (μITRON-esque) RTOS for deeply embedded systems, testing the limit of Rust's const eval and generics

Programming Languages

rust
11053 projects
typescript
32286 projects

Projects that are alternatives of or similar to r3

Rt Thread
RT-Thread is an open source IoT operating system.
Stars: ✭ 6,466 (+7332.18%)
Mutual labels:  kernel, cortex-m, embedded-systems, rtos, risc-v, cortex-a
DoraOS
DoraOS 是我个人所写的RTOS内核,结合FreeRTOS、uCOS, RT-Thread, LiteOS 的特性所写,取其精华,去其糟粕,本项目将持续维护,欢迎大家fork与star。
Stars: ✭ 102 (+17.24%)
Mutual labels:  cortex-m, embedded-systems, rtos
Prettyos
A Preemptive Hard Real Time kernel for embedded devices.
Stars: ✭ 36 (-58.62%)
Mutual labels:  kernel, embedded-systems, rtos
Tock
A secure embedded operating system for microcontrollers
Stars: ✭ 3,258 (+3644.83%)
Mutual labels:  kernel, cortex-m, risc-v
mdepx
MDEPX — A BSD-style RTOS
Stars: ✭ 17 (-80.46%)
Mutual labels:  cortex-m, rtos, risc-v
Pikort
A tiny Linux-like real-time kernel optimized for ARM Cortex-M chips
Stars: ✭ 268 (+208.05%)
Mutual labels:  kernel, cortex-m, rtos
nuclei-sdk
Nuclei RISC-V Software Development Kit
Stars: ✭ 65 (-25.29%)
Mutual labels:  embedded-systems, rtos, risc-v
rnk
rnk is a RTOS targeting ARM architecture.
Stars: ✭ 22 (-74.71%)
Mutual labels:  kernel, cortex-m, rtos
Rust Raspberrypi Os Tutorials
📚 Learn to write an embedded OS in Rust 🦀
Stars: ✭ 7,275 (+8262.07%)
Mutual labels:  kernel, embedded-rust
qp-arduino
QP real-time embedded frameworks/RTOS for Arduino (AVR and SAM)
Stars: ✭ 37 (-57.47%)
Mutual labels:  kernel, rtos
Diosix
A lightweight, secure, multiprocessor bare-metal hypervisor written in Rust for RISC-V
Stars: ✭ 116 (+33.33%)
Mutual labels:  kernel, risc-v
Mylinux
myLinux is a small UNIX like OS for embedded systems based on Westermo NetBox
Stars: ✭ 53 (-39.08%)
Mutual labels:  kernel, embedded-systems
Uc Os2
µC/OS-II is a preemptive, highly portable, and scalable real-time kernels. Designed for ease of use on a huge number of CPU architectures.
Stars: ✭ 120 (+37.93%)
Mutual labels:  kernel, rtos
Uc Os3
µC/OS-III is a preemptive, highly portable, and scalable real-time kernel. Designed for ease of use on a huge number of CPU architectures.
Stars: ✭ 284 (+226.44%)
Mutual labels:  kernel, rtos
Os kernel lab
OS kernel labs based on Rust/C Lang & RISC-V 64/X86-32
Stars: ✭ 3,332 (+3729.89%)
Mutual labels:  kernel, risc-v
Zeke
A POSIX-like OS for ARM processors.
Stars: ✭ 79 (-9.2%)
Mutual labels:  kernel, rtos
IntrOS
Free cooperative operating system (OS) for microcontrollers
Stars: ✭ 38 (-56.32%)
Mutual labels:  cortex-m, rtos
Talks
schedule and materials about my presentations
Stars: ✭ 245 (+181.61%)
Mutual labels:  kernel, rtos
FPGAmp
720p FPGA Media Player (RISC-V + Motion JPEG + SD + HDMI on an Artix 7)
Stars: ✭ 190 (+118.39%)
Mutual labels:  rtos, risc-v
phoenix-rtos-kernel
Phoenix-RTOS microkernel repository
Stars: ✭ 77 (-11.49%)
Mutual labels:  kernel, rtos

R3 Real-Time Operating System

Experimental static component-oriented RTOS for deeply embedded systems

Try it on Repl.it

R3-OS (or simply R3) is an experimental static RTOS that utilizes Rust's compile-time function evaluation mechanism for static configuration (creation of kernel objects and memory allocation) and const traits to decouple kernel interfaces from implementation.

  • All kernel objects are defined statically for faster boot times, compile-time checking, predictable execution, reduced RAM consumption, no runtime allocation failures, and extra security.
  • A kernel and its configurator don't require an external build tool or a specialized procedural macro, maintaining transparency and inter-crate composability.
  • The kernel API is not tied to any specific kernel implementations. Kernels are provided as separate crates, one of which an application chooses and instantiates using the trait system.
  • Leverages Rust's type safety for access control of kernel objects. Safe code can't access an object that it doesn't own.

R3 API

  • Tasks are the standard way to spawn application threads. They are kernel objects encapsulating the associated threads' execution states and can be activated by application code or automatically at boot time. Tasks have dynamic priorities and can block to relinquish the processor for lower-priority tasks.

  • R3 provides a unified interface to control interrupt lines and register interrupt handlers. Some kernels (e.g., the Arm M-Profile port of the original kernel) support unmanaged interrupt lines, which aren't masked when the kernel is handling a system call and thus provide superior real-time performance.

  • R3 supports common synchronization primitives such as mutexes, semaphores, and event groups. The mutexes can use the priority ceiling protocol to avoid unbounded priority inversion and mutual deadlock. Tasks can park themselves.

  • The kernel timing mechanism drives software timers and a system-global clock with microsecond precision. The system clock can be rewound or fast-forwarded for drift compensation.

  • Bindings are a statically-defined storage with runtime initialization and configuration-time borrow checking. They can be bound to tasks and other objects to provide safe mutable access.

  • Procedural kernel configuration facilitates componentization. The utility library includes safe container types such as Mutex and RecursiveMutex, which are built upon low-level synchronization primitives.

The Kernel

The R3 original kernel is provided as a separate package r3_kernel.

  • Traditional uniprocessor tickless real-time kernel with preemptive scheduling

  • Implements a software-based scheduler supporting a customizable number of task priorities (up to 2¹⁵ levels on a 32-bit target, though the implementation is heavily optimized for a smaller number of priorities) and an unlimited number of tasks.

  • Provides a scalable kernel timing mechanism with a logarithmic time complexity. This implementation is robust against a large interrupt processing delay.

  • Supports Arm M-Profile (all versions shipped so far), Armv7-A (no FPU), RISC-V as well as the simulator port that runs on a host system.

Example

#![feature(const_refs_to_cell)]
#![feature(const_trait_impl)]
#![feature(naked_functions)]
#![feature(const_mut_refs)]
#![feature(asm_const)]
#![feature(asm_sym)]
#![no_std]
#![no_main]

// ----------------------------------------------------------------

// Instantiate the Armv7-M port
use r3_port_arm_m as port;

type System = r3_kernel::System<SystemTraits>;
port::use_port!(unsafe struct SystemTraits);
port::use_rt!(unsafe SystemTraits);
port::use_systick_tickful!(unsafe impl PortTimer for SystemTraits);

impl port::ThreadingOptions for SystemTraits {}

impl port::SysTickOptions for SystemTraits {
    // STMF401 default clock configuration
    // SysTick = AHB/8, AHB = HSI (internal 16-MHz RC oscillator)
    const FREQUENCY: u64 = 2_000_000;
}

// ----------------------------------------------------------------

use r3::{bind::bind, kernel::StaticTask, prelude::*};

struct Objects {
    task: StaticTask<System>,
}

// Instantiate the kernel, allocate object IDs
const COTTAGE: Objects = r3_kernel::build!(SystemTraits, configure_app => Objects);

/// Root configuration
const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
    System::configure_systick(b);

    // Runtime-initialized static storage
    let count = bind((), || 1u32).finish(b);

    Objects {
        // Create a task, giving the ownership of `count`
        task: StaticTask::define()
            .start_with_bind((count.borrow_mut(),), task_body)
            .priority(2)
            .active(true)
            .finish(b),
    }
}

fn task_body(count: &mut u32) {
    // ...
}

Explore the examples directory for example projects.

Prerequisites

You need a Nightly Rust compiler. This project is heavily reliant on unstable features, so it might or might not work with a newer compiler version. See the file rust-toolchain.toml to find out which compiler version this project is currently tested with.

You also need to install Rust's cross-compilation support for your target architecture. If it's not installed, you will see a compile error like this:

error[E0463]: can't find crate for `core`
  |
  = note: the `thumbv7m-none-eabi` target may not be installed

In this case, you need to run rustup target add thumbv7m-none-eabi.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].