Skip to content

Commit

Permalink
Adding HSIZE handling
Browse files Browse the repository at this point in the history
  • Loading branch information
M0stafaRady committed Oct 14, 2024
1 parent e33600e commit ceb3767
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions bus_env/bus_agent/bus_ahb_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async def address_phase(self, tr):
self.vif.HADDR.value = tr.addr
self.vif.HTRANS.value = 0b10
self.vif.HSEL.value = 0b01
self.vif.HSIZE.value = tr.size
self.drv_optional_signals_address(tr)
# TODO: HSIZE should be existed in the DUT wait until it got added
await self.drive_delay()
Expand Down
1 change: 1 addition & 0 deletions bus_env/bus_agent/bus_ahb_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async def address_phase(self, tr):
break
tr.addr = self.vif.HADDR.value.integer
tr.kind = bus_item.WRITE if self.vif.HWRITE.value.integer else bus_item.READ
tr.size = self.vif.HSIZE.value
tr = self.monitor_optional_signals_address(tr)
return tr

Expand Down
7 changes: 7 additions & 0 deletions bus_env/bus_interface/bus_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def __init__(self, dut):
"HRDATA": "HRDATA",
"HREADY": "HREADY",
}
print(f"dddut {dir(dut)}")
print(f"dddut {dut._sub_handles}")
if "HSIZE" in dut._sub_handles:
bus_map["HSIZE"] = "HSIZE"
else:
bus_map["HSIZE"] = ""

sv_if.__init__(self, dut, "", bus_map)


Expand Down
6 changes: 4 additions & 2 deletions bus_env/bus_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, name="bus_item"):
self.rand("kind", [bus_item.READ, bus_item.WRITE])
self.id = bus_item.counter
bus_item.counter += 1
self.size = 2 # 2 for word, 1 for half word, 0 for byte

def convert2string(self):
if self.kind == bus_item.RESET:
Expand All @@ -40,15 +41,16 @@ def convert2string(self):
if self.kind == 1:
kind = "WRITE"
try:
return f"kind={kind} addr={hex(self.addr)} data={hex(self.data)}"
return f"kind={kind} addr={hex(self.addr)} data={hex(self.data)}, size={'word' if self.size == 2 else 'half word' if self.size == 1 else 'byte'}"
except TypeError or ValueError:
return f"kind={kind} addr={self.addr} data={self.data}"
return f"kind={kind} addr={self.addr} data={self.data}, size={'word' if self.size == 2 else 'half word' if self.size == 1 else 'byte'}"

def do_clone(self):
t = bus_item()
t.kind = self.kind
t.addr = self.addr
t.data = self.data
t.size = self.size
return t

def do_compare(self, tr):
Expand Down
11 changes: 6 additions & 5 deletions bus_env/bus_logger/bus_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def configure_logger(self, logger_file="log.txt"):
self.logger_file = f"{os.getcwd()}/loggers/logger_bus.log"
self.logger_file_regs_w = f"{os.getcwd()}/loggers/regs_write.log"
self.logger_irq = f"{os.getcwd()}/loggers/logger_irq.log"
self.col_widths = [10, 10, 10, 10]
self.col_widths = [10, 10, 10, 10, 10]
# # log the header
self.bus_log(None, header_logged=True)
self.regs_log(None, header_logged=True)
Expand All @@ -58,14 +58,14 @@ def bus_log(self, transaction, header_logged=False):
# Define a max width for each column

if header_logged:
headers = [f"{'Time (ns)'}", f"{'Kind'}", f"{'Address'}", f"{'Data'}"]
headers = [f"{'Time (ns)'}", f"{'Kind'}", f"{'Address'}", f"{'Data'}", f"{'Size'}"]
header = self.format_row(headers)
with open(self.logger_file, "w") as f:
f.write(f"{header}\n")
else:
sim_time = f"{cocotb.utils.get_sim_time(units='ns')} ns"
if transaction.kind == bus_item.RESET:
table_data = [f"{sim_time}", "Reset", "--", "--"]
table_data = [f"{sim_time}", "Reset", "--", "--", "--"]
else:
# Ensure each piece of data fits within the specified width
operation = (
Expand All @@ -77,8 +77,9 @@ def bus_log(self, transaction, header_logged=False):
if type(transaction.data) is not int
else f"{hex(transaction.data)}"
)
size = f"{'word' if transaction.size == 2 else 'half word' if transaction.size == 1 else 'byte'}"
# Now, assemble your table_data with the pre-formatted fields
table_data = [f"{sim_time}", f"{operation}", f"{address}", f"{data}"]
table_data = [f"{sim_time}", f"{operation}", f"{address}", f"{data}", f"{size}"]
table = self.format_row(table_data)
with open(self.logger_file, "a") as f:
f.write(f"{table}\n")
Expand Down Expand Up @@ -139,7 +140,7 @@ def regs_log(self, transaction, header_logged=False):
f"{sim_time}",
f"{the_type}",
f"{Name}",
f"{data}",
f"{data}"
]
table = self.format_row(table_data)
with open(self.logger_file_regs_w, "a") as f:
Expand Down

0 comments on commit ceb3767

Please sign in to comment.