adding decoder logic
This commit is contained in:
@@ -12,7 +12,7 @@ class APB3Cpuif(BaseCpuif):
|
||||
if not child.is_array:
|
||||
return base
|
||||
if child.current_idx is not None:
|
||||
return f"{base}_{'_'.join(map(str, child.current_idx))} [N_{child.inst_name.upper()}S]"
|
||||
return f"{base}_{'_'.join(map(str, child.current_idx))}"
|
||||
return f"{base} [N_{child.inst_name.upper()}S]"
|
||||
|
||||
@property
|
||||
@@ -75,4 +75,4 @@ class APB3Cpuif(BaseCpuif):
|
||||
address on the bus matches the address range of the given node.
|
||||
"""
|
||||
addr_pred = self.get_address_predicate(node)
|
||||
return addr_pred
|
||||
return addr_pred
|
||||
@@ -61,3 +61,4 @@ class APB3CpuifFlat(BaseCpuif):
|
||||
if idx is not None:
|
||||
return f"{base}_{signal}[{idx}]"
|
||||
return f"{base}_{signal}[N_{node.inst_name.upper()}S]"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{%- if cpuif.is_interface -%}
|
||||
{%- if cpuif.is_interface %}
|
||||
`ifndef SYNTHESIS
|
||||
initial begin
|
||||
assert_bad_addr_width: assert($bits({{cpuif.signal("PADDR")}}) >= {{ds.package_name}}::{{ds.module_name|upper}}_MIN_ADDR_WIDTH)
|
||||
@@ -16,14 +16,14 @@ assign cpuif_rd_en = !{{cpuif.signal("PWRITE")}};
|
||||
|
||||
{%- for child in cpuif.addressable_children -%}
|
||||
{%- if child is array -%}
|
||||
for (genvar g_{{child.inst_name|lower}}_idx = 0; g_{{child.inst_name|lower}}_idx < N_{{child.inst_name|upper}}S; g_{{child.inst_name|lower}}_idx++) begin : g_passthrough_{{child.inst_name|lower}}
|
||||
assign {{cpuif.signal("PCLK", child, f"g_{child.inst_name.lower()}_idx")}} = {{cpuif.signal("PCLK")}};
|
||||
assign {{cpuif.signal("PRESETn", child, f"g_{child.inst_name.lower()}_idx")}} = {{cpuif.signal("PRESETn")}};
|
||||
assign {{cpuif.signal("PSELx", child, f"g_{child.inst_name.lower()}_idx")}} = (cpuif_wr_req[{{loop.indx}}] || cpuif_rd_req[{{loop.indx}}]) ? 1'b1 : 1'b0;
|
||||
assign {{cpuif.signal("PENABLE", child, f"g_{child.inst_name.lower()}_idx")}} = {{cpuif.signal("PENABLE")}};
|
||||
assign {{cpuif.signal("PWRITE", child, f"g_{child.inst_name.lower()}_idx")}} = (cpuif_wr_req[{{loop.index}}]) ? 1'b1 : 1'b0;
|
||||
assign {{cpuif.signal("PADDR", child, f"g_{child.inst_name.lower()}_idx")}} = {{cpuif.get_address_slice(cpuif_wr_addr, child)}};
|
||||
assign {{cpuif.signal("PWDATA", child, f"g_{child.inst_name.lower()}_idx")}} = cpuif_wr_data;
|
||||
for (genvar g_idx = 0; g_idx < N_{{child.inst_name|upper}}S; g_idx++) begin : g_passthrough_{{child.inst_name|lower}}
|
||||
assign {{cpuif.signal("PCLK", child, "g_idx")}} = {{cpuif.signal("PCLK")}};
|
||||
assign {{cpuif.signal("PRESETn", child, "g_idx")}} = {{cpuif.signal("PRESETn")}};
|
||||
assign {{cpuif.signal("PSELx", child, "g_idx")}} = (cpuif_wr_req[{{loop.index}}] || cpuif_rd_req[{{loop.index}}]) ? 1'b1 : 1'b0;
|
||||
assign {{cpuif.signal("PENABLE", child, "g_idx")}} = {{cpuif.signal("PENABLE")}};
|
||||
assign {{cpuif.signal("PWRITE", child, "g_idx")}} = (cpuif_wr_req[{{loop.index}}]) ? 1'b1 : 1'b0;
|
||||
assign {{cpuif.signal("PADDR", child, "g_idx")}} = cpuif_wr_addr{{child|address_slice}};
|
||||
assign {{cpuif.signal("PWDATA", child, "g_idx")}} = cpuif_wr_data;
|
||||
assign cpuif_rd_ack[loop.index] = {{cpuif.signal("PREADY", child)}};
|
||||
assign cpuif_rd_data[loop.index] = {{cpuif.signal("PRDATA", child)}};
|
||||
assign cpuif_rd_err[loop.index] = {{cpuif.signal("PSLVERR", child)}};
|
||||
@@ -34,13 +34,13 @@ assign {{cpuif.signal("PRESETn", child)}} = {{cpuif.signal("PRESETn")}};
|
||||
assign {{cpuif.signal("PSELx", child)}} = (cpuif_wr_sel[{{loop.index0}}] || cpuif_rd_sel[{{loop.index0}}]) ? 1'b1 : 1'b0;
|
||||
assign {{cpuif.signal("PENABLE", child)}} = {{cpuif.signal("PENABLE")}};
|
||||
assign {{cpuif.signal("PWRITE", child)}} = (cpuif_wr_req[{{loop.index}}]) ? 1'b1 : 1'b0;
|
||||
assign {{cpuif.signal("PADDR", child)}} = {{cpuif.get_address_slice(cpuif_wr_addr, child)}};
|
||||
assign {{cpuif.signal("PADDR", child)}} = cpuif_wr_addr{{child|address_slice}};
|
||||
assign {{cpuif.signal("PWDATA", child)}} = cpuif_wr_data;
|
||||
assign cpuif_rd_ack[loop.index] = {{cpuif.signal("PREADY", child)}};
|
||||
assign cpuif_rd_data[loop.index] = {{cpuif.signal("PRDATA", child)}};
|
||||
assign cpuif_rd_err[loop.index] = {{cpuif.signal("PSLVERR", child)}};
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endfor%}
|
||||
|
||||
always_comb begin
|
||||
{{cpuif.signal("PREADY")}} = 1'b0;
|
||||
|
||||
@@ -82,6 +82,7 @@ class BaseCpuif:
|
||||
jj_env.filters["clog2"] = clog2 # type: ignore
|
||||
jj_env.filters["is_pow2"] = is_pow2 # type: ignore
|
||||
jj_env.filters["roundup_pow2"] = roundup_pow2 # type: ignore
|
||||
jj_env.filters["address_slice"] = self.get_address_slice # type: ignore
|
||||
|
||||
context = {
|
||||
"cpuif": self,
|
||||
@@ -90,3 +91,34 @@ class BaseCpuif:
|
||||
|
||||
template = jj_env.get_template(self.template_path)
|
||||
return template.render(context)
|
||||
|
||||
def get_address_slice(self, node: AddressableNode) -> str:
|
||||
"""
|
||||
Returns a SystemVerilog expression that extracts the address bits
|
||||
relevant to the given node.
|
||||
"""
|
||||
addr_mask = (1 << self.addr_width) - 1
|
||||
addr = node.absolute_address & addr_mask
|
||||
size = node.size
|
||||
if size == 0:
|
||||
raise ValueError(f"Node size '{size:#X}' must be greater than 0")
|
||||
if (addr % size) != 0:
|
||||
raise ValueError(f"Node address '{addr:#X}' must be aligned to its size '{size:#X}'")
|
||||
|
||||
# Calculate the address range of the node
|
||||
addr_start = addr
|
||||
addr_end = addr + size - 1
|
||||
if addr_end > addr_mask:
|
||||
raise ValueError("Node address range exceeds address width")
|
||||
|
||||
# Calculate the number of bits needed to represent the size
|
||||
size_bits = size.bit_length() - 1
|
||||
if size_bits < 0:
|
||||
size_bits = 0
|
||||
|
||||
if size_bits >= self.addr_width:
|
||||
# Node covers entire address space, so return full address
|
||||
return ""
|
||||
|
||||
# Extract the relevant bits from PADDR
|
||||
return f"[{self.addr_width - 1}:{size_bits}]"
|
||||
|
||||
Reference in New Issue
Block a user