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

RK0 Wiki

RK0 is designed for MCU-based control systems where deterministic behaviour is crucial. Determinism and clear semantics are core design principles.

  • It offers an O(1) preemptive priority-based scheduler. The choose-next algorithm takes approximately 4 cycles on ARMv7m and 11 cycles on ARMv6M.

  • The kernel mechanisms support two complementary programming paradigms:

    • Shared-memory (procedural) – tasks synchronise using semaphores/mutexes, event flags, and condition variables to share data and coordinate execution. Remarkably, mutexes support fully transitive priority inheritance.

    • Message-passing – tasks exchange data through message queues, ports, and mailboxes, operating within ‘isolated’ contexts.

      • Message queues are flexible, offering blocking or non-blocking, first or last-message semantics, and, along with scheduler policy, are a natural fit for event-based design patterns (e.g., the actor model).

      • Ports utilise priority boosting/demotion for synchronous client-server patterns.

  • The Most-Recent Message Protocol is a purpose-built 1-to-many message-passing mechanism for control loops.

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

  • Timers (delay, periodic, bounded waiting, and callout) are optimised for precision and low overhead (O(1)).


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