Skip to content

Documentation, formatting, and linting for several modules: seq_gen, fast_spi_rx, gpio, spi, pulse_gen#272

Merged
kcaisley merged 45 commits into
masterfrom
cosimulation
May 28, 2026
Merged

Documentation, formatting, and linting for several modules: seq_gen, fast_spi_rx, gpio, spi, pulse_gen#272
kcaisley merged 45 commits into
masterfrom
cosimulation

Conversation

@kcaisley

Copy link
Copy Markdown
Member

I'm opening a pull here, to merge in some of the incremental changes I've been making. The changes are broadly:

  • Update to the fast_spi_rx modules, so that it supports variable output data size
  • Changed main readme RST file to markdown
  • Cleaned up docstrings across touched python hardware drivers, to flesh out documenation and make peace with ruff lint
  • Add include guards across a majority of basil firmware modules, to allow verible/verilator linting. Previously the linting was too noisy to even begin to imagine one could use it.
  • Add RST documenation for fast_spi_rx module
  • Fix some typos and formatting in other RST files (nothing major)
  • Change to behaviral description in blk_mem_gen_8_to_1_2k, instead of hardcoded RAMB16_S1_S9
  • Update/add behavioral modules for several FPGA primitives, like IOBUF, IDDR, IBUFDS, etc
  • Add an icon for the RTD page (e.g. a favicon)

kcaisley added 30 commits May 12, 2026 15:52
Add `ifndef/`define/`endif guards around `bus_to_ip.v` and
`cdc_pulse_sync.v` includes in all basil module files that use them.

These two utilities are shared across multiple module subtrees
(fast_spi_rx, pulse_gen, gpio, spi, seq_gen), so the include guards
prevent MODDUP warnings when the module tree is pulled in from a
common parent (e.g. daq_core.v).

Only a subset of missing imports are addressed here as a starting
point for testing the import pattern. All other transitive
dependencies across the basil module tree should be wired up
following the same pattern.
Add a standalone Python script for verifying and documenting
FPGA/ASIC register address maps. The tool:

- Parses Verilog module port/parameter definitions for bus interfaces
- Parses YAML register-map descriptions (basil-style)
- Generates Markdown tables and ASCII-address-space diagrams
- Detects overlapping address ranges and out-of-range assignments

Useful as a CI gate to catch address-map bugs before synthesis.
- Rename _sim.v files to match module names (BUFG, IBUFDS, etc.)
- Add new simulation models for missing primitives (IBUF, OBUF, IOBUF, ODDR, PLLE2_BASE)
- Add behavioral implementations for buffer primitives
- Keep copyright headers and formatting consistent with existing style
…thods

- Add DATA_SIZE parameter to fast_spi_rx_core.v and fast_spi_rx.v
- Frame counter width, SPI data width, and bit counter threshold
  all depend on DATA_SIZE
- Add get_data_size() and parse_word() to Python driver for
  variable-width FIFO word parsing
- Add FIFO_DATA register (addr 4, 32-bit) to register map
- Fix minor whitespace/comment formatting in sitcp_fifo.py
  and seq_gen_core.v
Document set_en/get_en, get_lost_count, set_size/get_size, parse_word,
and improve existing reset docstring with reset behavior details.
Explain output enable mask, IO_TRI requirement, and StdRegister usage.
…repeat, get_repeat, is_done

Clarify delay is in clock cycles, explain @Property decorator and
relationship between is_ready and is_done.
Document all registers, start/reset behavior, repeat mode (0=forever),
external start, nested loops, and property/alias relationships.
…, get_data, reset

Document READY register, memory size, and clarify reset aborts transfers.
Add unit test placeholder, usage notes (data format, FIFO flush, reset),
and standardize section order to match seq_gen/spi/gpio/pulse_gen.
Add operational notes on tracks, start/repeat modes, output hold,
and START/READY address aliasing. Fix 'friving' typo.
Rename BIT_OUT to SIZE, CONF_EN to EN. Add notes on external start,
repeat mode, and START/DONE address aliasing.
Document StdRegister field-level access and pin direction behavior.
… address

Add notes on start/repeat modes and START/READY address aliasing.
In RST, single backticks render as italics, not monospace. Switch
all register/pin names to double backticks (START, DONE,
READY, EN, etc.) so they render as code font.
Combine RESET/VERSION (addr 0) and START/DONE/READY (addr 1) into
single rows with slashed names and wo/ro access notation, making
the address aliasing clear in the register tables themselves.
- Add DATA_SIZE register (addr 4, ro) to the register decode in
  fast_spi_rx_core.v so the hardware parameter can be read back
- Remove set_size from the Python driver; get_size now reads HW
- Remove DATA_SIZE from YAML config (no longer needed)
- Fix typo 'syncrhonized' -> 'synchronized' in fast_spi_rx_core.v
- Fix docstring style: opening """ on its own line for multi-line
- Delete bus_check.py utility (to be rewritten later)
- Add Kian, Christian, and Rasmus to authors list in pyproject.toml
- Add module-level docstring
- Add missing docstrings for __init__, init, get_nested_start,
  get_nested_stop, get_nested_repeat, get_mem_size
- Fix D205: blank line between summary line and description
- Break long single-line docstrings into multi-line with summary
  and description sections
- Add missing module-level, __init__, and method docstrings
- Fix D205: blank line between summary line and description
- Fix D200/D212: collapse multi-line single-liners
- Fix D400/D401/D415: imperative mood, periods, single-line convention
- Fix D413: blank line after Args/Returns sections
Add DATA_SIZE read-only register at addr 4 requires version bump
from 0 to 1. Update _require_version in Python driver to match.
- Add DATA_SIZE register (addr 4, ro) to the register decode in
  fast_spi_rx_core.v so the hardware parameter can be read back
- Remove set_size from the Python driver; get_size now reads HW
- Remove DATA_SIZE from YAML config (no longer needed)
- Fix typo 'syncrhonized' -> 'synchronized' in fast_spi_rx_core.v
- Fix docstring style: opening """ on its own line for multi-line
- Delete bus_check.py utility (to be rewritten later)
- Add Kian, Christian, and Rasmus to authors list in pyproject.toml
kcaisley added 6 commits May 22, 2026 23:46
Verilator treats warnings as fatal where Icarus accepts the code. Size the fast SPI concatenation explicitly and elaborate only the writable RAM ports used by each SPI memory instance.
@cbespin

cbespin commented May 26, 2026

Copy link
Copy Markdown
Contributor

I have one remaining question: why are the include guards labelled as BASIL_GPAC_ADC_RX_GPAC_ADC_CORE_V? To reflect the include path gpac_adc_rx/gpac_adc_rx_core.v? I am not sure if I like that too much, honestly. It makes it a bit hard to read/understand and could probably be solved with GPAC_ADC_RX_V and GPAC_ADC_RX_V without losing information?
Am I wrong or is there a common standard how it is done? Just curios and genuinely asking.

@kcaisley

kcaisley commented May 27, 2026

Copy link
Copy Markdown
Member Author

Good point @cbespin . I previously ran something like this to add the guards:

from pathlib import Path

root = Path("basil/firmware/modules")

for path in root.rglob("*.v"):
    text = path.read_text()

    # Construct guard from the path below basil/firmware/modules.
    # Example:
    #   gpac_adc_rx/gpac_adc_rx_core.v
    # becomes:
    #   BASIL_GPAC_ADC_RX_GPAC_ADC_RX_CORE_V
    guard = (
        "BASIL_"
        + str(path.relative_to(root).with_suffix(""))
        .upper()
        .replace("/", "_")
        + "_V"
    )

    # Insert the include guard after the initial copyright/header block.
    text = text.replace(
        "*/\n",
        f"*/\n`ifndef {guard}\n`define {guard}\n\n",
        1,
    )

    # Add closing `endif` at the end of the file.
    text = text.rstrip() + "\n\n`endif\n"

    path.write_text(text)

which produced the scheme BASIL_ + PATH + MODULE _V naming to avoid collisions, but it can just be simplified to the modules name.

I'll push a change with the simplified naming in a bit.

@kcaisley kcaisley requested a review from awalsemann May 27, 2026 12:28
@kcaisley

Copy link
Copy Markdown
Member Author

My reason for adding include guards, is the following: Our tests and build systems currently have a mixture of in-file includes plus added file paths in the tool execution paths. I'd like to introduce linting for the verilog files in the repo, but verilog and verible lint are quite picky about double or missing includes. So to quiet the noise, these guards insure each file is included only once.

@kcaisley kcaisley requested review from cbespin and removed request for rpartzsch May 27, 2026 12:46
@awalsemann

Copy link
Copy Markdown
Contributor

Is there a reason to remove the __FILE__ and __LINE__ command from assertions?
These should be valid compiler directives in verilog and might provides useful insights into why an assertion failed.

@cbespin cbespin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment also applies to all other simulation-replacement modules, of course 😀

Comment thread basil/firmware/modules/utils/IBUF.v Outdated
@kcaisley

kcaisley commented May 27, 2026

Copy link
Copy Markdown
Member Author

Is there a reason to remove the __FILE__ and __LINE__ command from assertions? These should be valid compiler directives in verilog and might provides useful insights into why an assertion failed.

For posterity, I had removed this because the files were linted without SystemVerilog 2009 mode being enabled. This had given the warning preprocessing error at "__FILE__" Error expanding macro identifier, might not be defined before. .

However, as long as verible-verilog-syntax --lang sv is run, I guess this warning shouldn't appear.

@kcaisley

Copy link
Copy Markdown
Member Author

Okay, I think this is ready on my end. In my opinion, in the future, we should look to remove the include guards entirely, in favor of explicit targets in the build system (whether that be a synthesis run with vivado or a simulation with cocotb plus verilator or iverilog).

To avoid having to reproduce the same config across these different targets, I think a library like siliconcompiler would be ideal.

@kcaisley kcaisley requested a review from cbespin May 27, 2026 15:25
@kcaisley kcaisley self-assigned this May 27, 2026

@cbespin cbespin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes, looks good to me now!

@kcaisley kcaisley merged commit a350c41 into master May 28, 2026
1 of 6 checks passed
@kcaisley

Copy link
Copy Markdown
Member Author

Oops! I merged in the in the changes from #273 quickly, using the Github web editor, and didn't notice a a missing ] in the pyproject.toml.

Hot fixing this in #276 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants