# mikxus/atmega328-scheduler architecture

> Architecture diagram of the GitHub repository mikxus/atmega328-scheduler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mikxus/atmega328-scheduler
- Repository: https://github.com/mikxus/atmega328-scheduler

## Overview

This repository is an ATmega328P preemptive scheduler and its supporting runtime drivers. The principal workflow is task creation and scheduling: task state and context are maintained, timer interrupts trigger context switches, and clock, synchronization, IPC, and UART facilities support application tasks. The README also identifies the standalone UART driver as a capability. Several relationships are supported only by headers or documentation; unsampled implementation details are not inferred.

Main entry points: [`src/kernel.cpp`](https://github.com/mikxus/atmega328-scheduler/blob/main/src/kernel.cpp) (Context switching), [`src/drivers/ipc/ipc_fifo.h`](https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/ipc/ipc_fifo.h) (IPC FIFO), [`lib/AVR-UART-LIB/usart.c`](https://github.com/mikxus/atmega328-scheduler/blob/main/lib/AVR-UART-LIB/usart.c) (USART library), [`src/scheduler.cpp`](https://github.com/mikxus/atmega328-scheduler/blob/main/src/scheduler.cpp) (Task lifecycle API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_kernel["Kernel and scheduling"]
  node_scheduler_api["Task lifecycle API<br/>[scheduler.cpp]"]
  node_task_state["Task state<br/>[task.cpp]"]
  node_task_data["Task context data<br/>[task.h]"]
  node_kernel_core["Context switching<br/>[kernel.cpp]"]
  node_round_robin["Round-robin policy<br/>[sched.cpp]"]
end

subgraph group_drivers["Runtime drivers"]
  node_timer["Timer driver<br/>[timer.cpp]"]
  node_clock["System clock<br/>[clock.cpp]"]
  node_fifo["FIFO data type<br/>[fifo.h]"]
end

subgraph group_ipc["Synchronization and IPC"]
  node_mutex["Mutex<br/>[mutex.cpp]"]
  node_ipc_fifo["IPC FIFO<br/>[ipc_fifo.h]"]
end

subgraph group_serial["UART support"]
  node_uart_driver["UART driver<br/>[uart.cpp]"]
  node_uart_lib["USART library<br/>[usart.c]"]
  node_uart_config["USART configuration<br/>[usart_config.h]"]
  node_xmodem_example["XMODEM example<br/>[example&#40;xmodem&#41;.c]"]
end

node_app(("Task application"))

node_app -->|"creates tasks"| node_scheduler_api
node_scheduler_api -.->|"manages tasks"| node_task_state
node_task_state -->|"uses task records"| node_task_data
node_kernel_core -->|"saves context"| node_task_data
node_kernel_core -->|"selects next task"| node_round_robin
node_kernel_core -->|"configures interrupt"| node_timer
node_kernel_core -->|"reads elapsed time"| node_clock
node_app -.->|"synchronizes"| node_mutex
node_ipc_fifo -->|"uses queue"| node_fifo
node_ipc_fifo -->|"uses locking"| node_mutex
node_app -.->|"exchanges messages"| node_ipc_fifo
node_uart_driver -->|"wraps USART"| node_uart_lib
node_uart_lib -->|"uses settings"| node_uart_config
node_xmodem_example -->|"uses USART API"| node_uart_lib
node_app -.->|"uses serial I/O"| node_uart_driver

click node_scheduler_api "https://github.com/mikxus/atmega328-scheduler/blob/main/src/scheduler.cpp"
click node_task_state "https://github.com/mikxus/atmega328-scheduler/blob/main/src/task.cpp"
click node_task_data "https://github.com/mikxus/atmega328-scheduler/blob/main/src/task.h"
click node_kernel_core "https://github.com/mikxus/atmega328-scheduler/blob/main/src/kernel.cpp"
click node_round_robin "https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/scheduling/sched.cpp"
click node_timer "https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/timer/timer.cpp"
click node_clock "https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/clock/clock.cpp"
click node_fifo "https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/data_types/fifo.h"
click node_mutex "https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/synchronization/mutex.cpp"
click node_ipc_fifo "https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/ipc/ipc_fifo.h"
click node_uart_driver "https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/uart/uart.cpp"
click node_uart_lib "https://github.com/mikxus/atmega328-scheduler/blob/main/lib/AVR-UART-LIB/usart.c"
click node_uart_config "https://github.com/mikxus/atmega328-scheduler/blob/main/lib/AVR-UART-LIB/usart_config.h"
click node_xmodem_example "https://github.com/mikxus/atmega328-scheduler/blob/main/lib/AVR-UART-LIB/example(xmodem).c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_scheduler_api,node_task_state,node_task_data,node_kernel_core,node_round_robin toneBlue
class node_timer,node_clock,node_fifo toneAmber
class node_mutex,node_ipc_fifo toneMint
class node_uart_driver,node_uart_lib,node_uart_config,node_xmodem_example,node_app toneRose
```

## Components

### Kernel and scheduling

- [Task lifecycle API](https://github.com/mikxus/atmega328-scheduler/blob/main/src/scheduler.cpp): `src/scheduler.cpp`
- [Task state](https://github.com/mikxus/atmega328-scheduler/blob/main/src/task.cpp): `src/task.cpp`
- [Task context data](https://github.com/mikxus/atmega328-scheduler/blob/main/src/task.h): `src/task.h`
- [Context switching](https://github.com/mikxus/atmega328-scheduler/blob/main/src/kernel.cpp): `src/kernel.cpp`
- [Round-robin policy](https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/scheduling/sched.cpp): `src/drivers/scheduling/sched.cpp`

### Runtime drivers

- [Timer driver](https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/timer/timer.cpp): `src/drivers/timer/timer.cpp`
- [System clock](https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/clock/clock.cpp): `src/drivers/clock/clock.cpp`
- [FIFO data type](https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/data_types/fifo.h): `src/drivers/data_types/fifo.h`

### Synchronization and IPC

- [Mutex](https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/synchronization/mutex.cpp): `src/drivers/synchronization/mutex.cpp`
- [IPC FIFO](https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/ipc/ipc_fifo.h): `src/drivers/ipc/ipc_fifo.h`

### UART support

- [UART driver](https://github.com/mikxus/atmega328-scheduler/blob/main/src/drivers/uart/uart.cpp): `src/drivers/uart/uart.cpp`
- [USART library](https://github.com/mikxus/atmega328-scheduler/blob/main/lib/AVR-UART-LIB/usart.c): `lib/AVR-UART-LIB/usart.c`
- [USART configuration](https://github.com/mikxus/atmega328-scheduler/blob/main/lib/AVR-UART-LIB/usart_config.h): `lib/AVR-UART-LIB/usart_config.h`
- [XMODEM example](https://github.com/mikxus/atmega328-scheduler/blob/main/lib/AVR-UART-LIB/example(xmodem).c): `lib/AVR-UART-LIB/example(xmodem).c`

### Other components

- **Task application**

## Connections

- Task application → Task lifecycle API: creates tasks
- Task lifecycle API → Task state: manages tasks
- Task state → Task context data: uses task records (evidence: `src/task.h`)
- Context switching → Task context data: saves context (evidence: `src/kernel.cpp`)
- Context switching → Round-robin policy: selects next task (evidence: `src/kernel.cpp`)
- Context switching → Timer driver: configures interrupt (evidence: `src/kernel.cpp`)
- Context switching → System clock: reads elapsed time (evidence: `src/kernel.cpp`)
- Task application → Mutex: synchronizes
- IPC FIFO → FIFO data type: uses queue (evidence: `src/drivers/ipc/ipc_fifo.h`)
- IPC FIFO → Mutex: uses locking (evidence: `src/drivers/ipc/ipc_fifo.h`)
- Task application → IPC FIFO: exchanges messages
- UART driver → USART library: wraps USART
- USART library → USART configuration: uses settings
- XMODEM example → USART library: uses USART API (evidence: `lib/AVR-UART-LIB/example(xmodem).c`)
- Task application → UART driver: uses serial I/O
