# macformula/racecar architecture

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

- Interactive diagram: https://gitdiagram.com/macformula/racecar
- Repository: https://github.com/macformula/racecar

## Overview

##### Main System Components

a) Hardware Layer
- STM32F767 microcontrollers
- CAN bus network
- Various peripherals (ADC, PWM, GPIO, etc.)
- Sensors and actuators

b) MCAL (Microcontroller Abstraction Layer)
- Platform-specific implementations (stm32f767, linux, raspi, cli)
- Peripheral drivers (CAN, ADC, GPIO, PWM)
- OS abstractions (RTOS features)

c) Shared Components
- Communication protocols (CAN messaging)
- Control algorithms
- Utility functions
- OS abstractions

d) Application Layer
- Project-specific implementations:
- FrontController
- LVController (Low Voltage)
- TMS (Thermal Management System)
- Demo projects

##### Relationships and Data Flow

- Hardware interfaces between components
- CAN message flow between controllers
- Driver abstraction layers
- Control signal paths

##### Specific Implementation Details

Specialized sections for:
- RTOS implementation
- CAN message routing
- Platform abstraction architecture
- Error handling system

**[Application Layer]**
- ↑↓
**[Shared Components]**
- ↑↓
**[MCAL Abstraction]**
- ↑↓
**[Hardware Layer]**

##### Key Elements to Highlight

- Cross-platform support (STM32, Linux, Raspberry Pi, CLI)
- Real-time operating system capabilities
- CAN bus communication network
- Sensor and actuator interfaces
- Control system implementation

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef hardware fill:#e6e6e6,stroke:#333
    classDef mcal fill:#b3d9ff,stroke:#333
    classDef shared fill:#b3ffb3,stroke:#333
    classDef app fill:#ffd9b3,stroke:#333
    classDef comms fill:#ffb3b3,stroke:#333
    classDef test fill:#e6b3ff,stroke:#333

    %% Hardware Layer
    subgraph HW[Hardware Layer]
        STM32["STM32F767 MCU"]
        PERIPH["Peripherals<br/>(ADC, PWM, GPIO)"]
        SENSORS["Sensors & Actuators"]
        CAN_BUS["CAN Bus Network"]:::comms
    end
    class STM32,PERIPH,SENSORS hardware

    %% MCAL Layer
    subgraph MCAL[MCAL Layer]
        STM["STM32F767 Implementation"]
        LINUX["Linux Implementation"]
        RASPI["Raspberry Pi Implementation"]
        CLI["CLI Implementation"]
    end
    class STM,LINUX,RASPI,CLI mcal

    %% Shared Components
    subgraph SHARED[Shared Components]
        PERIPH_IF["Peripheral Interfaces"]
        OS_ABS["OS Abstractions"]
        COMMS["Communication Protocols"]
        CTRL["Control Algorithms"]
        UTIL["Utility Functions"]
    end
    class PERIPH_IF,OS_ABS,COMMS,CTRL,UTIL shared

    %% Application Layer
    subgraph APP[Application Layer]
        FRONT["FrontController"]
        LV["LVController"]
        TMS["TMS Controller"]
    end
    class FRONT,LV,TMS app

    %% Testing Layer
    subgraph TEST[Testing Infrastructure]
        UNIT["Unit Tests"]
        VAL["Validation"]
    end
    class UNIT,VAL test

    %% Relationships
    HW --> MCAL
    MCAL --> SHARED
    SHARED --> APP
    APP --> TEST
    CAN_BUS --> COMMS

    %% Click Events
    click STM "https://github.com/macformula/racecar/tree/main/firmware/mcal/stm32f767/"
    click LINUX "https://github.com/macformula/racecar/tree/main/firmware/mcal/linux/"
    click RASPI "https://github.com/macformula/racecar/tree/main/firmware/mcal/raspi/"
    click CLI "https://github.com/macformula/racecar/tree/main/firmware/mcal/cli/"
    click PERIPH_IF "https://github.com/macformula/racecar/tree/main/firmware/shared/periph/"
    click OS_ABS "https://github.com/macformula/racecar/tree/main/firmware/shared/os/"
    click COMMS "https://github.com/macformula/racecar/tree/main/firmware/shared/comms/"
    click CTRL "https://github.com/macformula/racecar/tree/main/firmware/shared/controls/"
    click UTIL "https://github.com/macformula/racecar/tree/main/firmware/shared/util/"
    click FRONT "https://github.com/macformula/racecar/tree/main/firmware/projects/FrontController/"
    click LV "https://github.com/macformula/racecar/tree/main/firmware/projects/LVController/"
    click TMS "https://github.com/macformula/racecar/tree/main/firmware/projects/TMS/"
    click UNIT "https://github.com/macformula/racecar/tree/main/firmware/tests/"
    click VAL "https://github.com/macformula/racecar/tree/main/firmware/validation/"

    %% Legend
    subgraph Legend
        H1["Hardware"]:::hardware
        M1["MCAL"]:::mcal
        S1["Shared"]:::shared
        A1["Application"]:::app
        C1["Communication"]:::comms
        T1["Testing"]:::test
    end
```
