regbank utils

System Register Bank Utilities

This toolkit manages your self-describing FPGA register bank using a YAML source file as the single source of truth. It auto-generates:

  • Encoded binary + hex files for FPGA BRAM
  • Python constants for software tests
  • VHDL constants for ROM depth
  • (Optional) Deserializer for runtime SW inspection

๐Ÿ“ Folder Layout

regbank-utils/ โ”œโ”€โ”€ add_register.py # Add a register via CLI prompts โ”œโ”€โ”€ remove_register.py # Remove register by name or address โ”œโ”€โ”€ validate_schema.py # Validate schema structure and sanity โ”œโ”€โ”€ generate_regbank_pkg.py # Generate VHDL system_regbank_pkg.vhd โ”œโ”€โ”€ gen_info_pkg.py # Generate VHDL rom_info_pkg.vhd โ”œโ”€โ”€ check_regbank_version.py # Skip regeneration if versions match โ”œโ”€โ”€ payload_encoder.py # YAML โ†’ MsgPack/hex for BRAM โ”œโ”€โ”€ payload_decoder.py # Binary โ†’ Structured/Text decoding โ”œโ”€โ”€ markdown_encoder.py # Generate Markdown docs from YAML โ”œโ”€โ”€ yml_to_csv.py # Export YAML to CSV โ”œโ”€โ”€ bin_to_hex.py # Convert raw binary to hex file โ”œโ”€โ”€ regbank_schema.yml # ๐Ÿ“œ Main register schema example โ””โ”€โ”€ tests/ # ๐Ÿงช Automated tests โ””โ”€โ”€ test_regbank_utils.py

๐Ÿ“ฆ Requirements

pip install -r requirements.txt

โš™๏ธ Usage

๐Ÿ”„ Encode Register Map

python payload_encoder.py register_map.yaml

Output:

  • regbank_manifest.hex (for FPGA)
  • regbank_manifest.bin (for software tools)

Flags:

  • --format=raw Encodes as raw 32-bit words (default)
  • --format=structured Encodes as msgpack dictionary with metadata
  • --bin=<bin_file_name> Defines the output binary file name

๐Ÿง  Generate Python Constants

python generate_constants.py register_map.yaml regbank_constants.py

๐Ÿงฎ Generate VHDL Info Package

python gen_info_pkg.py $(ROOT_DIR) $(MANIFEST_FILE) $(CONFIG_FILE)

Generates src/pkg/rom_info_pkg.vhd containing build info and register bank version constants.

๐Ÿ“– Generate VHDL Register Package

python generate_regbank_pkg.py register_map.yaml system_regbank_pkg.vhd

Generates system_regbank_pkg.vhd containing register index constants and types.

๐Ÿ“– Decode from Binary (optional)

python payload_decoder.py regbank_manifest.bin python payload_decoder.py regbank_manifest.bin --out decoded.txt

Flags:

  • --format=raw Decodes a raw-encoded binary file (default)
  • --format=structured Decodes a structured-packed binary file
  • --out=<out_file_name> Defines the output file (text or binary depending on mode)

๐Ÿ“ Generate Documentation

python markdown_encoder.py register_map.yaml -o register_bank.md

๐Ÿ“Š Export to CSV

python yml_to_csv.py register_map.yaml register_map.csv

๐Ÿ” Register Bank Schema Validators

  • Duplicate address detection
  • Bitfield overlap validation
  • 4-byte alignment check (with --address-mode support)
  • Register name format check (UPPER_SNAKE_CASE)
  • Warnings with --strict support

๐Ÿ›  Example CLI Usage

Add a register interactively

python add_register.py regbank_schema.yml

Remove one by name or address

python remove_register.py regbank_schema.yml INJ_CONTROL python remove_register.py regbank_schema.yml 0x84

Validate schema before generation

python validate_schema.py regbank_schema.yml --strict

Only regenerate if version changed

python check_regbank_version.py regbank_schema.yml rom_info_pkg.vhd || \ python generate_regbank_pkg.py regbank_schema.yml system_regbank_pkg.vhd

๐Ÿ›  Integrate into Makefile

regbank_gen: regbank_manifest.hex system_regbank_pkg.vhd regbank_constants.py regbank_manifest.hex regbank_manifest.bin: register_map.yaml python tools/regbank-utils/payload_encoder.py $< system_regbank_pkg.vhd: register_map.yaml python tools/regbank-utils/generate_regbank_pkg.py $< $@ regbank_constants.py: register_map.yaml python tools/regbank-utils/generate_constants.py $< $@ synthesis: regbank_gen $(VIVADO_XLNX) $(ROOT_DIR)/tcl/gen_synthesis.tcl -tclargs $(ROOT_DIR)

๐Ÿค– Future Ideas

  • Auto-generate C headers / Rust bindings
  • Simulator-aware register dumping
  • Register ABI diff tool

Welcome to spec-driven FPGA development. Maintain once. Generate everywhere. โšก

  • No redundant copies of constants
  • No manual doc editing
  • Fully traceable, testable, and git-friendly