Skip to content

Commit b95ba35

Browse files
committed
Add simulation-time width assertions to SV interfaces. #128
1 parent 48ae215 commit b95ba35

File tree

9 files changed

+61
-0
lines changed

9 files changed

+61
-0
lines changed

src/peakrdl_regblock/cpuif/apb3/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class APB3_Cpuif(CpuifBase):
44
template_path = "apb3_tmpl.sv"
5+
is_interface = True
56

67
@property
78
def port_declaration(self) -> str:
@@ -12,6 +13,8 @@ def signal(self, name:str) -> str:
1213

1314

1415
class APB3_Cpuif_flattened(APB3_Cpuif):
16+
is_interface = False
17+
1518
@property
1619
def port_declaration(self) -> str:
1720
lines = [

src/peakrdl_regblock/cpuif/apb3/apb3_tmpl.sv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
{%- if cpuif.is_interface -%}
2+
`ifndef SYNTHESIS
3+
initial begin
4+
assert($bits({{cpuif.signal("paddr")}}) >= {{ds.package_name}}::{{ds.module_name.upper()}}_MIN_ADDR_WIDTH)
5+
else $error("Interface address width of %0d is too small. Shall be at least %0d bits", $bits({{cpuif.signal("paddr")}}), {{ds.package_name}}::{{ds.module_name.upper()}}_MIN_ADDR_WIDTH);
6+
assert($bits({{cpuif.signal("pwdata")}}) == {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH)
7+
else $error("Interface data width of %0d is incorrect. Shall be %0d bits", $bits({{cpuif.signal("pwdata")}}), {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH);
8+
end
9+
`endif
10+
11+
{% endif -%}
12+
113
// Request
214
logic is_active;
315
always_ff {{get_always_ff_event(cpuif.reset)}} begin

src/peakrdl_regblock/cpuif/apb4/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class APB4_Cpuif(CpuifBase):
44
template_path = "apb4_tmpl.sv"
5+
is_interface = True
56

67
@property
78
def port_declaration(self) -> str:
@@ -12,6 +13,8 @@ def signal(self, name:str) -> str:
1213

1314

1415
class APB4_Cpuif_flattened(APB4_Cpuif):
16+
is_interface = False
17+
1518
@property
1619
def port_declaration(self) -> str:
1720
lines = [

src/peakrdl_regblock/cpuif/apb4/apb4_tmpl.sv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
{%- if cpuif.is_interface -%}
2+
`ifndef SYNTHESIS
3+
initial begin
4+
assert($bits({{cpuif.signal("paddr")}}) >= {{ds.package_name}}::{{ds.module_name.upper()}}_MIN_ADDR_WIDTH)
5+
else $error("Interface address width of %0d is too small. Shall be at least %0d bits", $bits({{cpuif.signal("paddr")}}), {{ds.package_name}}::{{ds.module_name.upper()}}_MIN_ADDR_WIDTH);
6+
assert($bits({{cpuif.signal("pwdata")}}) == {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH)
7+
else $error("Interface data width of %0d is incorrect. Shall be %0d bits", $bits({{cpuif.signal("pwdata")}}), {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH);
8+
end
9+
`endif
10+
11+
{% endif -%}
12+
113
// Request
214
logic is_active;
315
always_ff {{get_always_ff_event(cpuif.reset)}} begin

src/peakrdl_regblock/cpuif/avalon/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
class Avalon_Cpuif(CpuifBase):
55
template_path = "avalon_tmpl.sv"
6+
is_interface = True
67

78
@property
89
def port_declaration(self) -> str:
@@ -17,6 +18,8 @@ def word_addr_width(self) -> int:
1718
return self.addr_width - clog2(self.data_width_bytes)
1819

1920
class Avalon_Cpuif_flattened(Avalon_Cpuif):
21+
is_interface = False
22+
2023
@property
2124
def port_declaration(self) -> str:
2225
lines = [

src/peakrdl_regblock/cpuif/avalon/avalon_tmpl.sv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
{%- if cpuif.is_interface -%}
2+
`ifndef SYNTHESIS
3+
initial begin
4+
assert($bits({{cpuif.signal("address")}}) >= {{cpuif.word_addr_width}})
5+
else $error("Interface address width of %0d is too small. Shall be at least %0d bits", $bits({{cpuif.signal("address")}}), {{cpuif.word_addr_width}});
6+
assert($bits({{cpuif.signal("writedata")}}) == {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH)
7+
else $error("Interface data width of %0d is incorrect. Shall be %0d bits", $bits({{cpuif.signal("writedata")}}), {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH);
8+
end
9+
`endif
10+
11+
{% endif -%}
12+
113
// Request
214
always_comb begin
315
cpuif_req = {{cpuif.signal("read")}} | {{cpuif.signal("write")}};

src/peakrdl_regblock/cpuif/axi4lite/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class AXI4Lite_Cpuif(CpuifBase):
44
template_path = "axi4lite_tmpl.sv"
5+
is_interface = True
56

67
@property
78
def port_declaration(self) -> str:
@@ -34,6 +35,8 @@ def resp_buffer_size(self) -> int:
3435

3536

3637
class AXI4Lite_Cpuif_flattened(AXI4Lite_Cpuif):
38+
is_interface = False
39+
3740
@property
3841
def port_declaration(self) -> str:
3942
lines = [

src/peakrdl_regblock/cpuif/axi4lite/axi4lite_tmpl.sv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
{%- if cpuif.is_interface -%}
2+
`ifndef SYNTHESIS
3+
initial begin
4+
assert($bits({{cpuif.signal("araddr")}}) >= {{ds.package_name}}::{{ds.module_name.upper()}}_MIN_ADDR_WIDTH)
5+
else $error("Interface address width of %0d is too small. Shall be at least %0d bits", $bits({{cpuif.signal("araddr")}}), {{ds.package_name}}::{{ds.module_name.upper()}}_MIN_ADDR_WIDTH);
6+
assert($bits({{cpuif.signal("wdata")}}) == {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH)
7+
else $error("Interface data width of %0d is incorrect. Shall be %0d bits", $bits({{cpuif.signal("wdata")}}), {{ds.package_name}}::{{ds.module_name.upper()}}_DATA_WIDTH);
8+
end
9+
`endif
10+
11+
{% endif -%}
12+
113
// Max Outstanding Transactions: {{cpuif.max_outstanding}}
214
logic [{{clog2(cpuif.max_outstanding+1)-1}}:0] axil_n_in_flight;
315
logic axil_prev_was_rd;

src/peakrdl_regblock/cpuif/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def get_implementation(self) -> str:
6969
"clog2": clog2,
7070
"is_pow2": is_pow2,
7171
"roundup_pow2": roundup_pow2,
72+
"ds": self.exp.ds,
7273
}
7374

7475
template = jj_env.get_template(self.template_path)

0 commit comments

Comments
 (0)