Skip to content

Commit ab9fb75

Browse files
committed
feat(generators/markdown): add show_hardware_mode option
1 parent bacd7d2 commit ab9fb75

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

schemas/corsair-build-schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
"title": "Show Disclaimer",
8181
"type": "boolean"
8282
},
83+
"show_hardware_mode": {
84+
"default": false,
85+
"description": "Enable showing hardware mode for each field.",
86+
"title": "Show Hardware Mode",
87+
"type": "boolean"
88+
},
8389
"wavedrom": {
8490
"$ref": "#/$defs/corsair___generators__wavedrom__WaveDromGenerator__Config",
8591
"default": {

src/corsair/_generators/markdown.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class Config(GeneratorConfig):
4242
show_disclaimer: bool = True
4343
"""Enable generating disclaimer with version at the beginning of the file."""
4444

45+
show_hardware_mode: bool = False
46+
"""Enable showing hardware mode for each field."""
47+
4548
wavedrom: WaveDromGenerator.Config = WaveDromGenerator.Config()
4649
"""Configuration for the WaveDrom generator."""
4750

src/corsair/_templates/regmap.md.j2

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ Generated by [Corsair](https://github.com/esynr3z/corsair) v{{ version }}.
4141
| WOSC | Write Only / Self Clear |
4242
{% endif %}
4343

44+
{% if cfg.show_hardware_mode %}
45+
| Hardware mode | Description |
46+
| :--- | :--- |
47+
| i | Use input value from hardware to update the field |
48+
| o | Enable output value from the field to be accessed by hardware |
49+
| c | Add signal to clear the field (fill with all zeros) |
50+
| s | Add signal to set the field (fill with all ones) |
51+
| e | Add signal to enable the field to capture input value (used with i) |
52+
| l | Add signal to lock the field (to prevent any changes) |
53+
| a | Add signals to notify when bus access to the field is performed (at the same cycle) |
54+
| q | Add simple interface to external queue (LIFO, FIFO) |
55+
| f | Enable fixed mode (field is a constant) |
56+
| n | Not accessible by hardware |
57+
{% endif %}
58+
4459
## Register map summary
4560

4661
**Base address:** {{ literal(regmap.base_address, regmap.address_width) }}
@@ -69,10 +84,10 @@ Generated by [Corsair](https://github.com/esynr3z/corsair) v{{ version }}.
6984
![{{ reg.name.lower()}}]({{ cfg.image_dir }}/{{regmap.name.lower()}}_{{ reg.name.lower()}}.svg)
7085

7186
{% endif %}
72-
| Name | Bits | Mode | Reset | Description |
73-
| :--- | :--- | :--- | :--- | :--- |
87+
| Name | Bits | Access {%- if cfg.show_hardware_mode %} | Hardware {%- endif %} | Reset | Description |
88+
| :--- | :--- | :--- {%- if cfg.show_hardware_mode %} | :--- {%- endif %} | :--- | :--- |
7489
{% for bf in reg.fields_with_reserved[::-1] %}
75-
| {{ "-" if bf.name.startswith("_reserved") else bf.name.upper() }} | {{ range(bf.msb, bf.lsb) }} | {{ bf.access.value.upper() }} | {{ "X" if bf.reset == None else literal(bf.reset, bf.width) }} | {{ bf.doc | replace('\n', '<br>') }} |
90+
| {{ "-" if bf.name.startswith("_reserved") else bf.name.upper() }} | {{ range(bf.msb, bf.lsb) }} | {{ bf.access.value.upper() }} {%- if cfg.show_hardware_mode %} | {{ bf.hardware.value.lower() }} {%- endif %} | {{ "X" if bf.reset == None else literal(bf.reset, bf.width) }} | {{ bf.doc | replace('\n', '<br>') }} |
7691
{% endfor %}
7792

7893
{% for bf in reg.fields %}

tests/generators/test_markdown.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,35 @@ def test_show_disclaimer_false(tmp_path: Path, simple_regmap: csr.Map) -> None:
279279
assert "Generated by [Corsair]" not in content
280280

281281

282+
def test_show_hardware_mode_true(tmp_path: Path, simple_regmap: csr.Map) -> None:
283+
"""Test that hardware mode conventions and column are present when show_hardware_mode is True."""
284+
config = csr.MarkdownGenerator.Config(show_hardware_mode=True)
285+
gen = csr.MarkdownGenerator(
286+
label="test_md_gen_hw_mode_true", register_map=simple_regmap, config=config, output_dir=tmp_path
287+
)
288+
generated_files = list(gen())
289+
output_file = generated_files[0]
290+
content = output_file.read_text()
291+
assert "## Conventions" in content # Assuming conventions are shown by default or with hardware mode
292+
assert "| Hardware mode | Description |" in content
293+
assert "| Hardware |" in content # Check for the column in the fields table
294+
295+
296+
def test_show_hardware_mode_false(tmp_path: Path, simple_regmap: csr.Map) -> None:
297+
"""Test that hardware mode conventions and column are absent when show_hardware_mode is False."""
298+
config = csr.MarkdownGenerator.Config(show_hardware_mode=False)
299+
gen = csr.MarkdownGenerator(
300+
label="test_md_gen_hw_mode_false", register_map=simple_regmap, config=config, output_dir=tmp_path
301+
)
302+
generated_files = list(gen())
303+
output_file = generated_files[0]
304+
content = output_file.read_text()
305+
# Assuming default of show_conventions=True, so "## Conventions" might still be there
306+
# We specifically check for the *hardware mode* conventions table
307+
assert "| Hardware mode | Description |" not in content
308+
assert "| Hardware |" not in content # Check for the column in the fields table
309+
310+
282311
def test_custom_template_and_extra_param(tmp_path: Path, simple_regmap: csr.Map, custom_template: Path) -> None:
283312
"""Test generation with a custom template and extra config parameters."""
284313
template_file = custom_template

0 commit comments

Comments
 (0)