# williamzhang20/protocol-emulator architecture

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

- Interactive diagram: https://gitdiagram.com/williamzhang20/protocol-emulator
- Repository: https://github.com/williamzhang20/protocol-emulator

## Overview

This is a Tiny Tapeout RTL design for a deterministic, SRAM-programmed, bit-level protocol emulator. The principal workflow is that a host loads bytecode and exchanges payload bytes, then starts the engine; the VM and real-time action lanes execute protocol-neutral timing, shifting, GPIO, waits, and branches, with UART behavior supplied by the SRAM image. The README also documents register/ALU, CRC/timer, FIFO, GPIO mapping, and pin-claim capabilities. Relationships below follow those README statements; RTL source was not sampled, so internal call-level wiring is not asserted.

Main entry points: [`src/vm_sequencer.v`](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/vm_sequencer.v) (VM Sequencer), [`src/action_dispatcher.v`](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/action_dispatcher.v) (Action Dispatcher), [`src/action_lane.v`](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/action_lane.v) (Action Lane), [`src/program_memory.v`](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/program_memory.v) (Program Memory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host_mem["Host and Memory"]
  node_host_if["Host Interface<br/>[host_interface.v]"]
  node_program_memory["Program Memory<br/>[program_memory.v]"]
  node_sram_macro["Foundry SRAM"]
end

subgraph group_execution["Program Execution"]
  node_vm["VM Sequencer<br/>[vm_sequencer.v]"]
  node_decoder["Instruction Decoder"]
  node_register_file["Register File and ALU<br/>[register_file.v]"]
  node_event_engine["Event Engine<br/>[event_engine.v]"]
end

subgraph group_actions["Real-Time Actions"]
  node_action_dispatcher["Action Dispatcher"]
  node_action_engine["Action Engine<br/>[action_engine.v]"]
  node_action_lane["Action Lane<br/>[action_lane.v]"]
end

subgraph group_io["Pins and Serial"]
  node_serial_shifter["Serial Shifter<br/>[serial_shifter.v]"]
  node_gpio_arbiter["GPIO Arbiter<br/>[gpio_arbiter.v]"]
  node_gpio_datapath["GPIO Datapath<br/>[gpio_datapath.v]"]
  node_uart_tx["UART TX"]
  node_uart_rx["UART RX"]
end

subgraph group_resources["Shared Resources"]
  node_tx_fifo["TX FIFO<br/>[byte_fifo.v]"]
  node_rx_fifo["RX FIFO<br/>[byte_fifo.v]"]
  node_crc_engine["CRC Engine<br/>[crc_engine.v]"]
  node_timer["Timer Counter<br/>[timer_counter.v]"]
end

node_host(("Host"))
node_protocol_pins(("Protocol Pins"))

node_host -->|"loads and starts"| node_host_if
node_host_if -->|"loads bytecode"| node_program_memory
node_program_memory -->|"stores image"| node_sram_macro
node_vm -->|"executes bytecode"| node_program_memory
node_vm -->|"decodes instructions"| node_decoder
node_vm -->|"uses ALU and registers"| node_register_file
node_vm -->|"uses timing events"| node_event_engine
node_action_dispatcher -->|"dispatches actions"| node_action_engine
node_action_engine -->|"runs action lanes"| node_action_lane
node_action_lane -->|"shifts and samples"| node_serial_shifter
node_action_lane -->|"pulls TX bytes"| node_tx_fifo
node_action_lane -->|"pushes RX bytes"| node_rx_fifo
node_action_dispatcher -->|"arbitrates FIFO ports"| node_tx_fifo
node_action_dispatcher -->|"arbitrates FIFO ports"| node_rx_fifo
node_action_dispatcher -->|"admits pin claims"| node_gpio_arbiter
node_gpio_arbiter -->|"controls pin mapping"| node_gpio_datapath
node_uart_tx -->|"drives UART output"| node_protocol_pins
node_protocol_pins -->|"provides UART input"| node_uart_rx
node_vm -->|"uses generic CRC"| node_crc_engine
node_vm -->|"uses generic timer"| node_timer

click node_host_if "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/host_interface.v"
click node_program_memory "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/program_memory.v"
click node_sram_macro "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/RM_IHPSG13_1P_1024x8_c2_bm_bist.v"
click node_vm "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/vm_sequencer.v"
click node_decoder "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/instruction_decoder.v"
click node_register_file "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/register_file.v"
click node_event_engine "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/event_engine.v"
click node_action_dispatcher "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/action_dispatcher.v"
click node_action_engine "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/action_engine.v"
click node_action_lane "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/action_lane.v"
click node_tx_fifo "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/byte_fifo.v"
click node_rx_fifo "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/byte_fifo.v"
click node_serial_shifter "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/serial_shifter.v"
click node_gpio_arbiter "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/gpio_arbiter.v"
click node_gpio_datapath "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/gpio_datapath.v"
click node_uart_tx "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/protocol_emulator_core.v"
click node_uart_rx "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/protocol_emulator_core.v"
click node_crc_engine "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/crc_engine.v"
click node_timer "https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/timer_counter.v"

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_host_if,node_program_memory,node_sram_macro toneBlue
class node_vm,node_decoder,node_register_file,node_event_engine toneAmber
class node_action_dispatcher,node_action_engine,node_action_lane toneMint
class node_serial_shifter,node_gpio_arbiter,node_gpio_datapath,node_uart_tx,node_uart_rx toneRose
class node_tx_fifo,node_rx_fifo,node_crc_engine,node_timer,node_host,node_protocol_pins toneIndigo
```

## Components

### Host and Memory

- [Host Interface](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/host_interface.v): `src/host_interface.v`
- [Program Memory](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/program_memory.v): `src/program_memory.v`
- [Foundry SRAM](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/RM_IHPSG13_1P_1024x8_c2_bm_bist.v): `src/RM_IHPSG13_1P_1024x8_c2_bm_bist.v`

### Program Execution

- [VM Sequencer](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/vm_sequencer.v): `src/vm_sequencer.v`
- [Instruction Decoder](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/instruction_decoder.v): `src/instruction_decoder.v`
- [Register File and ALU](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/register_file.v): `src/register_file.v`
- [Event Engine](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/event_engine.v): `src/event_engine.v`

### Real-Time Actions

- [Action Dispatcher](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/action_dispatcher.v): `src/action_dispatcher.v`
- [Action Engine](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/action_engine.v): `src/action_engine.v`
- [Action Lane](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/action_lane.v): `src/action_lane.v`

### Pins and Serial

- [Serial Shifter](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/serial_shifter.v): `src/serial_shifter.v`
- [GPIO Arbiter](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/gpio_arbiter.v): `src/gpio_arbiter.v`
- [GPIO Datapath](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/gpio_datapath.v): `src/gpio_datapath.v`
- [UART TX](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/protocol_emulator_core.v): `src/protocol_emulator_core.v`
- [UART RX](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/protocol_emulator_core.v): `src/protocol_emulator_core.v`

### Shared Resources

- [TX FIFO](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/byte_fifo.v): `src/byte_fifo.v`
- [RX FIFO](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/byte_fifo.v): `src/byte_fifo.v`
- [CRC Engine](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/crc_engine.v): `src/crc_engine.v`
- [Timer Counter](https://github.com/williamzhang20/protocol-emulator/blob/cmos5l/src/timer_counter.v): `src/timer_counter.v`

### Other components

- **Host**
- **Protocol Pins**

## Connections

- Host → Host Interface: loads and starts (evidence: `README.md`)
- Host Interface → Program Memory: loads bytecode (evidence: `README.md`)
- Program Memory → Foundry SRAM: stores image (evidence: `README.md`)
- VM Sequencer → Program Memory: executes bytecode (evidence: `README.md`)
- VM Sequencer → Instruction Decoder: decodes instructions (evidence: `README.md`)
- VM Sequencer → Register File and ALU: uses ALU and registers (evidence: `README.md`)
- VM Sequencer → Event Engine: uses timing events (evidence: `README.md`)
- Action Dispatcher → Action Engine: dispatches actions (evidence: `README.md`)
- Action Engine → Action Lane: runs action lanes (evidence: `README.md`)
- Action Lane → Serial Shifter: shifts and samples (evidence: `README.md`)
- Action Lane → TX FIFO: pulls TX bytes (evidence: `README.md`)
- Action Lane → RX FIFO: pushes RX bytes (evidence: `README.md`)
- Action Dispatcher → TX FIFO: arbitrates FIFO ports (evidence: `README.md`)
- Action Dispatcher → RX FIFO: arbitrates FIFO ports (evidence: `README.md`)
- Action Dispatcher → GPIO Arbiter: admits pin claims (evidence: `README.md`)
- GPIO Arbiter → GPIO Datapath: controls pin mapping (evidence: `README.md`)
- UART TX → Protocol Pins: drives UART output (evidence: `README.md`)
- Protocol Pins → UART RX: provides UART input (evidence: `README.md`)
- VM Sequencer → CRC Engine: uses generic CRC (evidence: `README.md`)
- VM Sequencer → Timer Counter: uses generic timer (evidence: `README.md`)
