# quantumleaps/miros architecture

> Architecture diagram of the GitHub repository quantumleaps/miros, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/quantumleaps/miros
- Repository: https://github.com/quantumleaps/miros

## Overview

##### Project Type and Purpose
- MiROS is an open-source teaching-aid RTOS kernel for ARM Cortex-M microcontrollers.
- It provides a simple, priority-based preemptive scheduler compliant with RMA/RMS.
- The project is structured as a library (kernel), board-support packages (BSPs), third-party dependencies (CMSIS), and example applications.

##### Main Architectural Components
a. MiROS Kernel Layer
– Public API (include/miros.h, include/qassert.h)
– Core implementation (src/<toolchain>/miros.c for ARMCLANG, GNU, IAR)
– RTOS primitives: task control blocks, scheduler, context switch, SysTick handler
b. Third-Party Layer
– CMSIS (3rd_party/CMSIS): core headers, NVIC, SysTick, MPU, etc.
– Board Support Packages (3rd_party/ek-tm4c123gxl, nucleo-c031c6, nucleo-l152re): startup code, device headers, system init
c. Example Applications
– “Blinky” demos (examples/blinky_*): tie together board-specific BSP, CMSIS, and MiROS kernel
d. Toolchain Abstraction
– ARMCLANG (src/armclang + project files under examples/*/armclang)
– GNU-ARM (src/gnu + Makefiles under examples/*/gnu)
– IAR EWARM (src/iar + project files under examples/*/iar)

##### Relationships and Data Flows
- Application (examples) → MiROS API calls
- MiROS Kernel → CMSIS core functions (SysTick, NVIC)
- MiROS Kernel → Board-Support (system clock init, GPIO)
- Build Flow: toolchain front-end compiles BSP + CMSIS + MiROS + application → linker produces firmware → flashed to hardware

##### Architectural Patterns and Principles
- Layered architecture
– Hardware at bottom
– CMSIS abstracts Cortex-M core
– BSP abstracts device peripherals
– MiROS provides RTOS services
– Examples sit at top (user code)
- Separation of concerns
– One kernel core, multiple toolchain ports
– Reusable BSP per board
- Minimal coupling, maximal clarity (teaching focus)

##### Essential Elements
– Labels for key files/directories

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Example Applications"
        blink1["Blinky EK-TM4C123GXL"]:::examples
        blink2["Blinky NUCLEO-C031C6"]:::examples
        blink3["Blinky NUCLEO-L152RE"]:::examples
    end

    subgraph "Toolchain Ports"
        armcl["ARMCLANG Port"]:::toolchain
        gnu["GNU-ARM Port"]:::toolchain
        iar["IAR-EWARM Port"]:::toolchain
    end

    subgraph "MiROS Kernel"
        api1["miros.h"]:::kernel
        api2["qassert.h"]:::kernel
        impl1["ARMCLANG miros.c"]:::kernel
        impl2["GNU miros.c"]:::kernel
        impl3["IAR miros.c"]:::kernel
    end

    cmsis["CMSIS (3rd_party/CMSIS)"]:::cmsis

    subgraph "Board Support Packages"
        bsp1["EK-TM4C123GXL BSP"]:::bsp
        bsp2["NUCLEO-C031C6 BSP"]:::bsp
        bsp3["NUCLEO-L152RE BSP"]:::bsp
    end

    firmware["Firmware"]:::artifact

    subgraph "Hardware"
        cpu["Cortex-M CPU"]:::hardware
        periph["Peripherals"]:::hardware
    end

    blink1 -->|"calls API"| api1
    blink1 -->|"calls API"| api2
    blink2 -->|"calls API"| api1
    blink2 -->|"calls API"| api2
    blink3 -->|"calls API"| api1
    blink3 -->|"calls API"| api2

    api1 -->|"uses CMSIS"| cmsis
    api2 -->|"uses CMSIS"| cmsis

    api1 -->|"calls BSP"| bsp1
    api1 -->|"calls BSP"| bsp2
    api1 -->|"calls BSP"| bsp3

    blink1 --> armcl
    blink2 --> armcl
    blink3 --> armcl
    blink1 --> gnu
    blink2 --> gnu
    blink3 --> gnu
    blink1 --> iar
    blink2 --> iar
    blink3 --> iar

    impl1 --> api1
    impl2 --> api1
    impl3 --> api1

    blink1 -->|"compile & link"| firmware
    blink2 -->|"compile & link"| firmware
    blink3 -->|"compile & link"| firmware
    armcl -->|"compile & link"| firmware
    gnu -->|"compile & link"| firmware
    iar -->|"compile & link"| firmware
    impl1 -->|"compile & link"| firmware
    impl2 -->|"compile & link"| firmware
    impl3 -->|"compile & link"| firmware
    cmsis -->|"compile & link"| firmware
    bsp1 -->|"compile & link"| firmware
    bsp2 -->|"compile & link"| firmware
    bsp3 -->|"compile & link"| firmware

    firmware -->|"flashed to"| cpu
    firmware -->|"accesses"| periph

    click api1 "https://github.com/quantumleaps/miros/blob/master/include/miros.h"
    click api2 "https://github.com/quantumleaps/miros/blob/master/include/qassert.h"
    click impl1 "https://github.com/quantumleaps/miros/blob/master/src/armclang/miros.c"
    click impl2 "https://github.com/quantumleaps/miros/blob/master/src/gnu/miros.c"
    click impl3 "https://github.com/quantumleaps/miros/blob/master/src/iar/miros.c"
    click cmsis "https://github.com/quantumleaps/miros/tree/master/3rd_party/CMSIS/Include"
    click bsp1 "https://github.com/quantumleaps/miros/tree/master/3rd_party/ek-tm4c123gxl"
    click bsp2 "https://github.com/quantumleaps/miros/tree/master/3rd_party/nucleo-c031c6"
    click bsp3 "https://github.com/quantumleaps/miros/tree/master/3rd_party/nucleo-l152re"
    click blink1 "https://github.com/quantumleaps/miros/tree/master/examples/blinky_ek-tm4c123gxl"
    click blink2 "https://github.com/quantumleaps/miros/tree/master/examples/blinky_nucleo-c031c6"
    click blink3 "https://github.com/quantumleaps/miros/tree/master/examples/blinky_nucleo-l152re"

    classDef hardware fill:#ccf,stroke:#333,stroke-width:1px;
    classDef cmsis fill:#bbf,stroke:#333,stroke-width:1px;
    classDef bsp fill:#cfc,stroke:#333,stroke-width:1px;
    classDef kernel fill:#fc9,stroke:#333,stroke-width:1px;
    classDef examples fill:#ff9,stroke:#333,stroke-width:1px;
    classDef toolchain fill:#c9f,stroke:#333,stroke-width:1px;
    classDef artifact fill:#eef,stroke:#333,stroke-width:1px;
```
