# cageduke/freertos-kernel architecture

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

- Interactive diagram: https://gitdiagram.com/cageduke/freertos-kernel
- Repository: https://github.com/cageduke/freertos-kernel

## Overview

##### Main Components
- Kernel Core: Represent the core of FreeRTOS that implements task scheduling, queues, and other kernel services. This includes files at the root (tasks.c, queue.c, list.c, timers.c, stream_buffer.c, croutine.c) plus the corresponding declarations and definitions in the “include” directory (e.g., FreeRTOS.h, task.h, queue.h, etc.).
- Portable Layer: Represent the abstraction layer that contains architecture-specific code. The “portable” directory is vast and subdivided by compiler and architecture (e.g., GCC, IAR, ARMClang, CodeWarrior, etc.). This layer ensures that the kernel core can operate seamlessly on various hardware platforms.
- Configuration & Build Tools: Although not part of the runtime system, note the existence of CI/CD workflows (under .github/workflows), code style (uncrustify configuration as mentioned in the README), and the spellcheck lexicon. These support the development process.

##### Relationships and Interactions
- That the Kernel Core “includes” header interfaces (from the “include” folder) which define the public API used in applications and demos.
- How external demo projects (which reside in a different repository as submodules) would integrate with the kernel core.
- That tasks, queues, semaphores, timers and other RTOS objects interact within the kernel core, while the portable layer provides context switching, interrupt handling, and low-level timing operations.

##### Architectural Patterns & Design Principles
- Layered Architecture: Emphasize the separation between the generic kernel functions and the platform-specific implementations.
- Modularity: Break the system into modules such as the scheduler, memory management, and communication (queues, event groups) showing independence and well-defined interfaces.
- Portability: Clearly denote that the portable layer is abstracted to support various hardware architectures using conditional inclusion or multi-directory structure.

##### Relevant Technologies/Frameworks
- Although no external libraries are directly included, mention the use of “uncrustify” for code formatting and the integration with CI/CD tools (GitHub workflows, shell and Python scripts under .github) that further support the development process.
- Role of build scripts or configuration files that help set up the environment for different demo applications (even though demos reside in another repository).

##### Final Detailed Architecture Elements
- Kernel Core Elements:
- Scheduler and Task Management: tasks.c and task.h.
- Queue/Event Manager: queue.c, event_groups.c, stream_buffer.c.
- Timer Management: timers.c.
- Optional Co-Routines: croutine.c.
- Interfaces and APIs: Provided in the “include” directory (FreeRTOS.h, etc.).
- Hardware Abstraction / Portability:
- That these modules provide low-level functions such as context switching, interrupt handling, and port-specific macros.
- Supporting Infrastructure:
- CI/CD Workflows (GitHub actions) and auxiliary scripts that maintain code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Kernel Core Subgraph
    subgraph "Kernel Core"
        direction TB
        TS["Task Scheduler (tasks.c & include/task.h)"]:::core
        QM["Queue/Event Manager (queue.c & include/queue.h)"]:::core
        LM["List Manager (list.c)"]:::core
        TM["Timer Management (timers.c & include/timers.h)"]:::core
        CR["Co-Routine Manager (croutine.c & include/FreeRTOS.h)"]:::core
        SB["Stream Buffer (stream_buffer.c & include/stream_buffer.h)"]:::core
        API["Kernel API Interfaces (include/FreeRTOS.h, etc.)"]:::api
    end

    %% Portable Layer Subgraph
    subgraph "Portable Layer"
        direction TB
        GCC["GCC Ports (portable/GCC)"]:::portable
        IAR["IAR Ports (portable/IAR)"]:::portable
        ARM["ARMClang Ports (portable/ARMClang)"]:::portable
        CW["CodeWarrior Ports (portable/CodeWarrior)"]:::portable
    end

    %% Configuration & Build Tools Subgraph
    subgraph "Configuration & Build Tools"
        direction TB
        CI["GitHub Workflows (.github/workflows)"]:::tools
        SCR["Development Scripts (.github/scripts)"]:::tools
        CSL["Code Style & Spellcheck (.github/lexicon.txt, CONTRIBUTING.md)"]:::tools
    end

    %% Relationships within Kernel Core (API inclusions)
    TS -->|"includes"| API
    QM -->|"includes"| API
    LM -->|"includes"| API
    TM -->|"includes"| API
    CR -->|"includes"| API
    SB -->|"includes"| API

    %% Interaction among Kernel Core modules (illustrative)
    TS -->|"schedule"| QM
    TS -->|"triggers"| TM
    QM -->|"synchronizes_with"| TM

    %% Kernel Core depends on Portable Layer via API interfaces
    API -->|"depends_on"| GCC
    API -->|"depends_on"| IAR
    API -->|"depends_on"| ARM
    API -->|"depends_on"| CW

    %% Supporting Infrastructure Connections
    CI ---|"supports"| TS
    CI ---|"supports"| QM
    CI ---|"supports"| LM
    CI ---|"supports"| TM
    CI ---|"supports"| CR
    CI ---|"supports"| SB

    SCR ---|"assists"| API
    CSL ---|"maintains"| API

    %% Click Events for Kernel Core
    click TS "https://github.com/cageduke/freertos-kernel/blob/main/tasks.c"
    click QM "https://github.com/cageduke/freertos-kernel/blob/main/queue.c"
    click LM "https://github.com/cageduke/freertos-kernel/blob/main/list.c"
    click TM "https://github.com/cageduke/freertos-kernel/blob/main/timers.c"
    click CR "https://github.com/cageduke/freertos-kernel/blob/main/croutine.c"
    click SB "https://github.com/cageduke/freertos-kernel/blob/main/stream_buffer.c"
    click API "https://github.com/cageduke/freertos-kernel/blob/main/include/FreeRTOS.h"

    %% Click Events for Portable Layer
    click GCC "https://github.com/cageduke/freertos-kernel/tree/main/portable/GCC"
    click IAR "https://github.com/cageduke/freertos-kernel/tree/main/portable/IAR"
    click ARM "https://github.com/cageduke/freertos-kernel/tree/main/portable/ARMClang"
    click CW "https://github.com/cageduke/freertos-kernel/tree/main/portable/CodeWarrior"

    %% Click Events for Configuration & Build Tools
    click CI "https://github.com/cageduke/freertos-kernel/tree/main/.github/workflows"
    click SCR "https://github.com/cageduke/freertos-kernel/tree/main/.github/scripts"
    click CSL "https://github.com/cageduke/freertos-kernel/blob/main/.github/lexicon.txt"

    %% Class Definitions for Colors
    classDef core fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef portable fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef tools fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef api fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
