# latticesemi/emmc_controller architecture

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

- Interactive diagram: https://gitdiagram.com/latticesemi/emmc_controller
- Repository: https://github.com/latticesemi/emmc_controller

## Overview

This repository packages a Lattice eMMC controller IP and includes its C register-level driver plus an SoC example BSP; the supplied tree does not contain the controller RTL. The documented workflow is that firmware configures the controller through APB registers, issues commands, and uses the AXI4 (or AHBL) data interface to transfer blocks to or from an external eMMC device. Driver excerpts show register programming and command handling; README documentation supplies the hardware interface capabilities. BSP connections are limited to relationships evidenced by the sampled source index.

Main entry points: [`example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h`](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h) (RISC-V HAL), [`example_design/soc_emmc/sge/bsp/driver/riscv_rtos/interrupt.c`](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/interrupt.c) (Interrupt control), [`example_design/soc_emmc/sge/bsp/driver/riscv_rtos/cpu.h`](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/cpu.h) (CPU primitives), [`driver/emmc_controller.c`](https://github.com/latticesemi/emmc_controller/blob/main/driver/emmc_controller.c) (eMMC API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_driver["eMMC Driver"]
  node_driver_api["eMMC API<br/>[emmc_controller.c]"]
  node_register_defs["Register map<br/>[emmc_controller.h]"]
end

subgraph group_ip["Controller Interfaces"]
  node_csr["APB control/status"]
  node_transaction["Command sequencing"]
  node_fifo["Data FIFO"]
  node_data_bus["AXI4 / AHBL data"]
  node_irq["Interrupt support"]
end

subgraph group_bsp["Example BSP"]
  node_hal["RISC-V HAL<br/>[hal.h]"]
  node_cpu["CPU primitives<br/>[cpu.h]"]
  node_interrupts["Interrupt control<br/>[interrupt.c]"]
  node_plic["PLIC control<br/>[plic.c]"]
  node_uart["UART driver<br/>[uart.c]"]
  node_local_uart["Local UART<br/>[local_uart.c]"]
  node_pmp["PMP control<br/>[pmp.c]"]
  node_trap["Trap handling<br/>[trap.c]"]
  node_exception["Exception definitions<br/>[exception.h]"]
  node_reg_access["Register access<br/>[reg_access.h]"]
end

node_firmware(("SoC firmware"))
node_device(("eMMC device"))

node_firmware -.->|"calls"| node_driver_api
node_driver_api -->|"uses definitions"| node_register_defs
node_driver_api -->|"programs registers"| node_csr
node_firmware -->|"configures and triggers"| node_csr
node_csr -->|"controls"| node_transaction
node_transaction -->|"sends commands"| node_device
node_transaction -->|"buffers data"| node_fifo
node_data_bus -->|"moves blocks"| node_fifo
node_fifo -->|"transfers data"| node_device
node_transaction -->|"signals status"| node_irq
node_hal -->|"includes primitives"| node_cpu
node_hal -->|"includes control"| node_interrupts
node_hal -->|"includes control"| node_plic
node_hal -->|"includes control"| node_pmp
node_hal -->|"includes access"| node_reg_access
node_hal -->|"includes driver"| node_local_uart
node_interrupts -->|"uses control"| node_plic
node_interrupts -->|"uses primitives"| node_cpu
node_interrupts -.->|"dispatches traps"| node_trap
node_trap -->|"uses primitives"| node_cpu
node_trap -.->|"uses definitions"| node_exception
node_uart -->|"uses HAL"| node_hal
node_local_uart -->|"uses primitives"| node_cpu

click node_driver_api "https://github.com/latticesemi/emmc_controller/blob/main/driver/emmc_controller.c"
click node_register_defs "https://github.com/latticesemi/emmc_controller/blob/main/driver/emmc_controller.h"
click node_hal "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h"
click node_cpu "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/cpu.h"
click node_interrupts "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/interrupt.c"
click node_plic "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/plic.c"
click node_uart "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/uart/uart.c"
click node_local_uart "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/local_uart.c"
click node_pmp "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/pmp.c"
click node_trap "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/trap.c"
click node_exception "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/exception.h"
click node_reg_access "https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/reg_access.h"

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_driver_api,node_register_defs toneBlue
class node_csr,node_transaction,node_fifo,node_data_bus,node_irq toneAmber
class node_hal,node_cpu,node_interrupts,node_plic,node_uart,node_local_uart,node_pmp,node_trap,node_exception,node_reg_access toneMint
class node_firmware,node_device toneIndigo
```

## Components

### eMMC Driver

- [eMMC API](https://github.com/latticesemi/emmc_controller/blob/main/driver/emmc_controller.c): `driver/emmc_controller.c`
- [Register map](https://github.com/latticesemi/emmc_controller/blob/main/driver/emmc_controller.h): `driver/emmc_controller.h`

### Controller Interfaces

- **APB control/status**
- **Command sequencing**
- **Data FIFO**
- **AXI4 / AHBL data**
- **Interrupt support**

### Example BSP

- [RISC-V HAL](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h`
- [CPU primitives](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/cpu.h): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/cpu.h`
- [Interrupt control](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/interrupt.c): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/interrupt.c`
- [PLIC control](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/plic.c): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/plic.c`
- [UART driver](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/uart/uart.c): `example_design/soc_emmc/sge/bsp/driver/uart/uart.c`
- [Local UART](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/local_uart.c): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/local_uart.c`
- [PMP control](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/pmp.c): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/pmp.c`
- [Trap handling](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/trap.c): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/trap.c`
- [Exception definitions](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/exception.h): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/exception.h`
- [Register access](https://github.com/latticesemi/emmc_controller/blob/main/example_design/soc_emmc/sge/bsp/driver/riscv_rtos/reg_access.h): `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/reg_access.h`

### Other components

- **SoC firmware**
- **eMMC device**

## Connections

- SoC firmware → eMMC API: calls
- eMMC API → Register map: uses definitions (evidence: `driver/emmc_controller.c`)
- eMMC API → APB control/status: programs registers (evidence: `driver/emmc_controller.c`)
- SoC firmware → APB control/status: configures and triggers
- APB control/status → Command sequencing: controls
- Command sequencing → eMMC device: sends commands
- Command sequencing → Data FIFO: buffers data
- AXI4 / AHBL data → Data FIFO: moves blocks
- Data FIFO → eMMC device: transfers data
- Command sequencing → Interrupt support: signals status
- RISC-V HAL → CPU primitives: includes primitives (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h`)
- RISC-V HAL → Interrupt control: includes control (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h`)
- RISC-V HAL → PLIC control: includes control (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h`)
- RISC-V HAL → PMP control: includes control (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h`)
- RISC-V HAL → Register access: includes access (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h`)
- RISC-V HAL → Local UART: includes driver (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/hal.h`)
- Interrupt control → PLIC control: uses control (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/interrupt.c`)
- Interrupt control → CPU primitives: uses primitives (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/interrupt.c`)
- Interrupt control → Trap handling: dispatches traps
- Trap handling → CPU primitives: uses primitives (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/trap.c`)
- Trap handling → Exception definitions: uses definitions
- UART driver → RISC-V HAL: uses HAL (evidence: `example_design/soc_emmc/sge/bsp/driver/uart/uart.c`)
- Local UART → CPU primitives: uses primitives (evidence: `example_design/soc_emmc/sge/bsp/driver/riscv_rtos/local_uart.c`)
