Skip to content

Commit

Permalink
AHB read correct data if size is not word
Browse files Browse the repository at this point in the history
  • Loading branch information
M0stafaRady committed Oct 16, 2024
1 parent def1adc commit 8f5447c
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions bus_env/bus_agent/bus_ahb_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,19 @@ async def data_phase(self, tr):
if tr.size == bus_item.WORD_ACCESS:
tr.data = self.vif.HRDATA.value.integer
elif tr.size == bus_item.HALF_WORD_ACCESS:
tr.data = self.vif.HRDATA.value.integer & 0xFFFF
if tr.addr % 4 == 0:
tr.data = self.vif.HRDATA.value.integer & 0xFFFF
else:
tr.data = self.vif.HRDATA.value.integer >> 16
elif tr.size == bus_item.BYTE_ACCESS:
tr.data = self.vif.HRDATA.value.integer & 0xFF
if tr.addr % 4 == 0:
tr.data = self.vif.HRDATA.value.integer & 0xFF
elif tr.addr % 4 == 1:
tr.data = (self.vif.HRDATA.value.integer >> 8) & 0xFF
elif tr.addr % 4 == 2:
tr.data = (self.vif.HRDATA.value.integer >> 16) & 0xFF
elif tr.addr % 4 == 3:
tr.data = (self.vif.HRDATA.value.integer >> 24) & 0xFF
except ValueError:
uvm_warning(
self.tag, f"HRDATA is not an integer {self.vif.HRDATA.value.binstr}"
Expand All @@ -98,12 +108,22 @@ async def data_phase(self, tr):
tr.data = self.vif.HRDATA.value.binstr
elif tr.size == bus_item.HALF_WORD_ACCESS:
try:
tr.data = int(self.vif.HRDATA.value.binstr[16:], 2)
if tr.addr % 4 == 0:
tr.data = int(self.vif.HRDATA.value.binstr[0:16], 2)
else:
tr.data = int(self.vif.HRDATA.value.binstr[16:], 2)
except ValueError:
tr.data = self.vif.HRDATA.value.binstr
elif tr.size == bus_item.BYTE_ACCESS:
try:
tr.data = int(self.vif.HRDATA.value.binstr[24:], 2)
if tr.addr % 4 == 0:
tr.data = int(self.vif.HRDATA.value.binstr[0:8], 2)
elif tr.addr % 4 == 1:
tr.data = int(self.vif.HRDATA.value.binstr[8:16], 2)
elif tr.addr % 4 == 2:
tr.data = int(self.vif.HRDATA.value.binstr[16:24], 2)
elif tr.addr % 4 == 3:
tr.data = int(self.vif.HRDATA.value.binstr[24:], 2)
except ValueError:
tr.data = self.vif.HRDATA.value.binstr
if self.data_phase_lock.locked:
Expand Down

0 comments on commit 8f5447c

Please sign in to comment.