Skip to content

Commit

Permalink
Fix RTL generation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanlippuner committed Nov 5, 2023
1 parent 25bc89e commit 37527fe
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion proto/cheby/hdl/axi4litebus.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def expand_bus_r(self, root, module, ibus, opts):

module.stmts.append(HDLAssign(axi_rerr, RESP_OKAY))
proc.rst_stmts.append(
HDLAssign(root.h_bus['rdata'], HDLReplicate(bit_0, root.c_addr_bits)))
HDLAssign(root.h_bus['rdata'], HDLReplicate(bit_0, root.c_word_bits)))

proc.sync_stmts.append(HDLAssign(ibus.rd_req, bit_0))
if opts.bus_error:
Expand Down
3 changes: 2 additions & 1 deletion proto/cheby/hdl/genmemory.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ def gen_processes_reg(self, ibus, reg):
if ibus.wr_sel is not None:
# Translate bit-wise write mask of internal bus to Byte-wise write mask
# of memory
mem_name = mem.c_name + '_' + str(i) if multiword else mem.c_name
bwselw_int = self.module.new_HDLSignal(
mem.c_name + "_sel_int", self.root.c_word_bits // tree.BYTE_SIZE
mem_name + "_sel_int", self.root.c_word_bits // tree.BYTE_SIZE
)

proc = HDLComb()
Expand Down
30 changes: 21 additions & 9 deletions proto/cheby/hdl/wbbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,27 @@ def gen_bus_slave(self, root, module, prefix, n, opts):
def slice_addr(self, addr, root, n):
"""Slice the input :param addr: (from the root bus) so that is can be
assigned to the slave. Take care of various sizes."""
res = HDLSlice(addr, root.c_addr_word_bits, n.c_addr_bits)
if not n.h_busgroup:
return res
if n.c_addr_bits < 32:
res = HDLConcat(HDLReplicate(
bit_0, 32 - root.c_addr_word_bits - n.c_addr_bits, False), res)
if root.c_addr_word_bits > 0:
res = HDLConcat(res,
HDLReplicate(bit_0, root.c_addr_word_bits, False))
if n.c_addr_bits > 0:
res = HDLSlice(addr, root.c_addr_word_bits, n.c_addr_bits)
else:
res = None

if n.h_busgroup:
if n.c_addr_bits < 32:
repl = HDLReplicate(bit_0, 32 - root.c_addr_word_bits - n.c_addr_bits, False)
if res is None:
res = repl
else:
res = HDLConcat(repl, res)
if root.c_addr_word_bits > 0:
repl = HDLReplicate(bit_0, root.c_addr_word_bits, False)
if res is None:
res = repl
else:
res = HDLConcat(res, repl)

if res is None:
raise AssertionError('Sliced address is empty')
return res

def wire_bus_slave(self, root, module, n, ibus):
Expand Down
17 changes: 14 additions & 3 deletions proto/cheby/print_verilog.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def generate_interface_modport(fd, itf, dirn, dirname):
w(fd, " {}".format(p.name))
return not first

# Check if the interface has a port with the given direction dirn
def generate_interface_has_dir(itf, dirn):
for p in itf.ports:
if p.dir == dirn:
return True
return False


def generate_interface(fd, itf, indent):
generate_decl_comment(fd, itf.comment, indent)
windent(fd, indent)
Expand All @@ -81,16 +89,19 @@ def generate_interface(fd, itf, indent):
windent(fd, indent + 1)
wln(fd, "logic {}{};".format(generate_verilog_type(p), p.name))
windent(fd, indent + 1)

has_in = generate_interface_has_dir(itf, 'IN')
has_out = generate_interface_has_dir(itf, 'OUT')
w(fd, "modport master(")
p = generate_interface_modport(fd, itf, 'IN', 'input')
if p:
if has_in and has_out:
w(fd, ', ')
generate_interface_modport(fd, itf, 'OUT', 'output')
wln(fd, ');')
windent(fd, indent + 1)
w(fd, "modport slave(")
p = generate_interface_modport(fd, itf, 'IN', 'output')
if p:
if has_in and has_out:
w(fd, ', ')
generate_interface_modport(fd, itf, 'OUT', 'input')
wln(fd, ');')
Expand Down Expand Up @@ -148,7 +159,7 @@ def generate_decl(fd, d, indent):

operator = {hdltree.HDLAnd: (' & ', 4),
hdltree.HDLOr: (' | ', 3),
hdltree.HDLNot: ('!', 5),
hdltree.HDLNot: ('~', 5),
hdltree.HDLSub: ('-', 1),
hdltree.HDLMul: ('*', 2),
hdltree.HDLEq: (' == ', 5),
Expand Down

0 comments on commit 37527fe

Please sign in to comment.