Skip to content

Commit 48ae215

Browse files
committed
Add user parameters to regblock package. #112
1 parent 0a9a3ad commit 48ae215

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed

src/peakrdl_regblock/hwif/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ def top_node(self) -> AddrmapNode:
4949
return self.exp.ds.top_node
5050

5151

52+
def get_extra_package_params(self) -> str:
53+
lines = []
54+
55+
for param in self.top_node.inst.parameters:
56+
value = param.get_value()
57+
if isinstance(value, int):
58+
lines.append(
59+
f"localparam {param.name} = {SVInt(value)};"
60+
)
61+
elif isinstance(value, str):
62+
lines.append(
63+
f"localparam {param.name} = {value};"
64+
)
65+
66+
return "\n".join(lines)
67+
68+
5269
def get_package_contents(self) -> str:
5370
"""
5471
If this hwif requires a package, generate the string

src/peakrdl_regblock/package_tmpl.sv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package {{ds.package_name}};
77
localparam {{ds.module_name.upper()}}_MIN_ADDR_WIDTH = {{ds.addr_width}};
88
localparam {{ds.module_name.upper()}}_SIZE = {{SVInt(ds.top_node.size)}};
99

10+
{{hwif.get_extra_package_params()|indent}}
11+
1012
{{hwif.get_package_contents()|indent}}
1113
endpackage
1214
{# (eof newline anchor) #}

tests/test_pkg_params/__init__.py

Whitespace-only changes.

tests/test_pkg_params/regblock.rdl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
addrmap top #(
2+
longint N_REGS = 1,
3+
longint REGWIDTH = 32,
4+
string NAME = "abcd"
5+
) {
6+
reg reg_t {
7+
regwidth = REGWIDTH;
8+
field {sw=rw; hw=na;} f[REGWIDTH] = 1;
9+
};
10+
reg_t regs[N_REGS];
11+
};

tests/test_pkg_params/tb_template.sv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "lib/tb_base.sv" %}
2+
3+
{% block seq %}
4+
{% sv_line_anchor %}
5+
assert(regblock_pkg::N_REGS == {{testcase.n_regs}});
6+
assert(regblock_pkg::REGWIDTH == {{testcase.regwidth}});
7+
assert(regblock_pkg::NAME == "{{testcase.name}}");
8+
{% endblock %}

tests/test_pkg_params/testcase.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from parameterized import parameterized_class
2+
3+
from ..lib.sim_testcase import SimTestCase
4+
from ..lib.test_params import get_permutations
5+
6+
PARAMS = get_permutations({
7+
"n_regs" : [1, 2],
8+
"regwidth" : [8, 16],
9+
"name" : ["hello", "world"],
10+
})
11+
@parameterized_class(PARAMS)
12+
class TestRetimedFanin(SimTestCase):
13+
n_regs = 20
14+
regwidth = 32
15+
name = "xyz"
16+
17+
@classmethod
18+
def setUpClass(cls):
19+
cls.rdl_elab_params = {
20+
"N_REGS": cls.n_regs,
21+
"REGWIDTH": cls.regwidth,
22+
"NAME": f'"{cls.name}"',
23+
}
24+
super().setUpClass()
25+
26+
def test_dut(self):
27+
self.run_test()

0 commit comments

Comments
 (0)