# lmesserstep/libresdrb210 architecture

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

- Interactive diagram: https://gitdiagram.com/lmesserstep/libresdrb210
- Repository: https://github.com/lmesserstep/libresdrb210

## Overview

##### Project type and purpose
- This is not a web or backend service but an FPGA-based firmware project targeting the USRP B210 (XC7A100T + AD9361).
- The README describes swapping out the stock FPGA image with a custom bitstream (usrp_b210_fpga.bin) that embodies your custom HDL design.

##### File structure
- Top-level Vivado project files:
- libreSDR_b210.xpr, .hw, .sim, .srcs, .gen folders, constraint files, project logs, etc.
- HDL sources under lib/… (control, dsp, fifo, gpif2, vita_200, wishbone), and a top-level wrapper in esdr_b210/top/libresdr_b210.v and b200_core.v.
- IP cores auto-generated in fifo_4k_2clk, fifo_short_2clk, gen_clks, clk_wiz_0, vio_0, etc.

##### README for additional insights
- Purpose: build and load a custom FPGA image for UHD (USRP Hardware Driver).

##### Main components
a. External interfaces
- AD9361 analog RF front-end (RX/TX ADC & DAC)
- USB3 (GPIF2 or other) host interface to PC running UHD
- I²C EEPROM (configuration store)
- JTAG / VIO for debug
b. Clock and reset infrastructure
- MMCM / PLL (gen_clks, clk_wiz_0) generating reference clocks
- Reset synchronizers
c. Control plane
- Wishbone or simple SPI control logic for register access (user_settings.v, serial_to_settings.v)
- uC-style control block in b200_core.v
d. Data plane (two symmetric paths)
- RX path: ADC → CIC decimator → DDC chain (cordic, down-conversion) → VITA-49 framer → AXI-FIFO → USB
- TX path: USB → AXI-FIFO → VITA-49 deframer → DUC chain → DAC
e. Clock-domain crossing
- FIFO IP cores (fifo_4k_2clk, fifo_short_2clk) between RF clock, processing clock, and USB clock domains
f. Miscellaneous IP and user modules
- AES-FPGA (for encryption/decryption tests)
- I²C EEPROM model for simulation
- DSP primitives (add, clip, round, MAC, decimator, interpolator)

##### Relationships and interactions
- Within FPGA, group blocks by clock domain (e.g., RF domain on left, processing domain in center, USB domain on right).

##### Architectural patterns and design principles
- Modular HDL library structure (lib/dsp, lib/control, lib/fifo, etc.)
- Clear separation of control vs. data planes.
- Pipeline and streaming design using AXI-stream-style FIFOs.
- Clock-domain crossing handled by parameterized FIFO IP.
- Top-level composition in esdr_b210/top/libresdr_b210.v.

##### Technologies, frameworks, and libraries
- Xilinx Vivado IP integrator for clocking, FIFOs, VIO.
- Verilog/VHDL sources under lib/…
- SSDR packet format via VITA-49 modules under lib/vita_200.
- Simulation scripts under libresdr_b210.sim.

##### Essential architectural elements
- Do not merely list files – show how FIFO blocks link processing pipelines across clock domains.
- Top-level wrapper module and how it instantiates core submodules.
- Path from PC⟶USB⟶AXI-FIFO⟶DDC⟶RF and bidirectional for TX.
- AD9361 DEVICE interface, I²C config chain, and system clocks feeding all sub-blocks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-Level Wrapper
    subgraph "Top-Level Wrapper"
        TOP["libresdr_b210.v"]:::top
        CORE["b200_core.v"]:::top
    end

    %% External Interfaces
    subgraph "External Interfaces"
        AD9361["AD9361 RF Front-End"]:::rf
        USB3["USB3 (GPIF2)"]:::host
        I2C["I²C EEPROM"]:::control
        JTAG["JTAG/VIO"]:::control
    end

    %% Clock & Reset Infrastructure
    subgraph "Clock & Reset"
        GENCLK["gen_clks IP"]:::clock
        CLKWIZ["clk_wiz_0"]:::clock
        RESET["reset_sync.v"]:::control
    end

    %% Control Plane
    subgraph "Control Plane"
        SER2SET["serial_to_settings.v"]:::control
        USSET["user_settings.v"]:::control
        WBUART["simple_uart.v"]:::control
    end

    %% Data Plane
    subgraph "Data Plane"
        subgraph "RF Domain" 
            ADC["RF ADC"]:::rf
            DAC["RF DAC"]:::rf
        end
        subgraph "Processing Domain"
            CICD["cic_decim.v"]:::dsp
            DDC["ddc_chain.v"]:::dsp
            VITA_RX["new_rx_framer.v"]:::dsp
            VITA_TX["new_tx_deframer.v"]:::dsp
            DUC["duc_chain.v"]:::dsp
            CICI["cic_interp.v"]:::dsp
        end
        subgraph "USB Domain"
            FIFO_L["fifo_4k_2clk"]:::fifo
            FIFO_S["fifo_short_2clk"]:::fifo
            GPIF2["gpif2_slave_fifo32.v"]:::host
        end
    end

    %% Connections Top-Level
    TOP --> CORE

    %% Clocks & Reset
    CORE -->|drives clocks| GENCLK
    CORE -->|drives clocks| CLKWIZ
    CORE -->|reset sync| RESET

    %% External to CORE
    AD9361 -->|IQ samples| CORE
    USB3 -->|stream| CORE
    I2C -->|config| CORE
    JTAG -->|debug| CORE

    %% Control Plane Links
    CORE -->|config bus| SER2SET
    CORE -->|registers| USSET
    USB3 -->|UART| WBUART

    %% Data Flows RX
    ADC -->|raw IQ| CICD
    CICD -->|decimated IQ| DDC
    DDC -->|baseband IQ| VITA_RX
    VITA_RX -->|framed packets| FIFO_L
    FIFO_L -->|cross-domain| GPIF2
    GPIF2 -->|USB stream| USB3

    %% Data Flows TX
    USB3 -->|USB stream| GPIF2
    GPIF2 -->|cross-domain| FIFO_S
    FIFO_S -->|packets| VITA_TX
    VITA_TX -->|IQ samples| DUC
    DUC -->|interpolated IQ| CICI
    CICI -->|analog IQ| DAC

    %% Top-Level to Interfaces
    CORE --> GENCLK
    CORE --> CLKWIZ

    %% Click Events
    click TOP "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/esdr_b210/top/libresdr_b210.v"
    click CORE "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/esdr_b210/top/b200_core.v"
    click GENCLK "https://github.com/lmesserstep/libresdrb210/tree/main/LibreSDR/libresdr_b210.gen/gen_clks/ip/gen_clks/"
    click CLKWIZ "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/ip/clk_wiz_0/clk_wiz_0.xci"
    click RESET "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/control/reset_sync.v"
    click SER2SET "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/control/serial_to_settings.v"
    click USSET "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/control/user_settings.v"
    click WBUART "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/wishbone/simple_uart.v"
    click FIFO_L "https://github.com/lmesserstep/libresdrb210/tree/main/LibreSDR/libresdr_b210.gen/fifo_4k_2clk/ip/fifo_4k_2clk/"
    click FIFO_S "https://github.com/lmesserstep/libresdrb210/tree/main/LibreSDR/libresdr_b210.gen/fifo_short_2clk/ip/fifo_short_2clk/"
    click CICD "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/dsp/cic_decim.v"
    click DDC "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/dsp/ddc_chain.v"
    click DUC "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/dsp/duc_chain.v"
    click CICI "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/dsp/cic_interp.v"
    click VITA_RX "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/vita_200/new_rx_framer.v"
    click VITA_TX "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/vita_200/new_tx_deframer.v"
    click GPIF2 "https://github.com/lmesserstep/libresdrb210/blob/main/LibreSDR/libresdr_b210.srcs/sources_1/imports/lib/gpif2/gpif2_slave_fifo32.v"

    %% Styles
    classDef top fill:#eeeeee,stroke:#333,stroke-width:2px
    classDef rf fill:#cce5ff,stroke:#004085
    classDef dsp fill:#d4edda,stroke:#155724
    classDef clock fill:#fff3cd,stroke:#856404
    classDef control fill:#f8d7da,stroke:#721c24
    classDef fifo fill:#e2e3e5,stroke:#6c757d
    classDef host fill:#f5c6cb,stroke:#721c24
```
