Skip to content
Antonio Giacomelli edited this page Dec 5, 2025 · 378 revisions

RK0 Wiki

RK0 is designed for MCU-based control systems demanding real-time correctness. Determinism by construction and clear semantics are core design principles.

  • It implements an O(1) preemptive priority-based scheduler aligned with Rate-Monotonic Scheduling.

  • The kernel mechanisms support two complementary programming paradigms:

    • Shared variables: Semaphores, Mutexes, Task's Event Flags and Condition Variables are used to coordinate Tasks execution and communication. Remarkably, Mutexes support fully transitive priority inheritance.

    • Message-passing: coordination and data exchange is performed altogether via Message Queues (Mailboxes) and Ports. Message queues are flexible, offering blocking or non-blocking, first or last-message semantics, plus ownership. Ports are server endpoints for synchronous client-server, and handle priority inversion. The Most-Recent Message Protocol is a higher-level, 1-to-many mechanism, purpose-built for control loops: it guarantees data freshness and integrity.

  • A well-proven fixed-size Memory Allocator ensures efficient memory management, avoiding fragmentation and providing predictable memory latency (O(1)).

  • Timers (sleep delays, bounded waiting, and callouts) are optimised for precision and low overhead (O(1)).

  • Features are modular (self-contained) and composable.


Configuring the kernel

  • core/kconfig.h contains defines to enable or disable features and other critical configurations.

  • It is essential that the number of tasks in your application matches the number defined in RK_CONF_N_USRTASKS, and the lowest effective priority task number (the highest number) aligns with what is defined in RK_CONF_MIN_PRIO (maximum priority is 31).

  • If you’re using application timers, the stack size of the system task that runs the callouts might need to be adjusted on RK_CONF_TIMHANDLER_STACKSIZE. Remember, this value is in words (a word has 4 bytes). If you’re including any hooks on the IdleTask, also adjust RK_CONF_IDLE_STACKSIZE. These values must be a multiple of 8, which is a general rule for stack sizes.

  • To declare the objects needed for a task, you can use the convenience macro RK_DECLARE_TASK(). Check kapi.h for more information. Importantly, convenience macros that start with RK_ don’t need a trailing ; because they’re not meant to be seen as functions (some don’t even take arguments). Macros that start with a K_ are function-like macros.


More help?

  • Sections explaining the QEMU building system and its integration to VSCode on macOS, Windows, and Linux are available on the Wiki links.

  • A comprehensive Docbook explains kernel mechanisms (including the design rationale) and usage examples.

  • Complete application code for QEMU (on this repo) and Nucleo boards (on a wiki page) are useful for understanding how to structure your code.

Clone this wiki locally