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=rawEncodes as raw 32-bit words (default)--format=structuredEncodes 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=rawDecodes a raw-encoded binary file (default)--format=structuredDecodes 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-modesupport) - Register name format check (
UPPER_SNAKE_CASE) - Warnings with
--strictsupport
๐ 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