From 84a975baae936c3566b496b799405fdf0c87f445 Mon Sep 17 00:00:00 2001 From: Daniel Kondys Date: Wed, 6 Nov 2024 21:34:28 +0100 Subject: [PATCH 1/2] fix: check if an EOF has been set without an SOF in the Cocotb MFB monitor --- .../cocotbext/cocotbext/ofm/mfb/monitors.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/python/cocotbext/cocotbext/ofm/mfb/monitors.py b/python/cocotbext/cocotbext/ofm/mfb/monitors.py index 79ad4b921..9e1606414 100644 --- a/python/cocotbext/cocotbext/ofm/mfb/monitors.py +++ b/python/cocotbext/cocotbext/ofm/mfb/monitors.py @@ -78,16 +78,19 @@ async def _monitor_recv(self): self.log.debug(f"ee_idx {str(ee_idx)}") self.log.debug(f"ss_idx {str(ss_idx)}") - if (self._eof_arr[rr] == 1) and (in_frame): - # Checks if there is a packet that is being processed and if it ends in this region. - self.log.debug("Frame End") - in_frame = False - eof_done = True - frame += data_bytes[rs_inx:ee_idx] - self.item_cnt += len(data_bytes[rs_inx:ee_idx])*8 // self._item_width - self.log.debug(f"frame done {frame.hex()}") - self._recv(frame) - self.frame_cnt += 1 + if self._eof_arr[rr] == 1: + if in_frame: + # Checks if there is a packet that is being processed and if it ends in this region. + self.log.debug("Frame End") + in_frame = False + eof_done = True + frame += data_bytes[rs_inx:ee_idx] + self.item_cnt += len(data_bytes[rs_inx:ee_idx])*8 // self._item_width + self.log.debug(f"frame done {frame.hex()}") + self._recv(frame) + self.frame_cnt += 1 + elif self._sof_arr[rr] == 1 and (self._eof_pos_arr[rr] < self._sof_pos_arr[rr]): + raise MFBProtocolError("MFB error: an end-of-frame received before a start-of-frame!") if in_frame: # Region with a valid 'middle of packet'. From f1423f32aa3257ccb8da62a01841d21d7ab2ecc7 Mon Sep 17 00:00:00 2001 From: Daniel Kondys Date: Wed, 6 Nov 2024 21:35:58 +0100 Subject: [PATCH 2/2] style: improve error messages in the Cocotb MFB monitor considering duplicit SOFs and EOFs --- python/cocotbext/cocotbext/ofm/mfb/monitors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cocotbext/cocotbext/ofm/mfb/monitors.py b/python/cocotbext/cocotbext/ofm/mfb/monitors.py index 9e1606414..159b9637f 100644 --- a/python/cocotbext/cocotbext/ofm/mfb/monitors.py +++ b/python/cocotbext/cocotbext/ofm/mfb/monitors.py @@ -102,7 +102,7 @@ async def _monitor_recv(self): # Checking for beginning of a packet. self.log.debug("Frame Start") if in_frame: - raise MFBProtocolError("Duplicate start-of-frame received on MFB bus!") + raise MFBProtocolError("MFB error: a start-of-frame received without an end-of-frame!") in_frame = True frame = b"" @@ -110,7 +110,7 @@ async def _monitor_recv(self): # Checking if the packet ends in the same regions where it began. self.log.debug("Frame End in single region") if not in_frame: - raise MFBProtocolError("Duplicate end-of-frame received on MFB bus!") + raise MFBProtocolError("MFB error: an end-of-frame received without a start-of-frame!") in_frame = False frame += data_bytes[ss_idx:ee_idx] self.item_cnt += len(data_bytes[ss_idx:ee_idx])*8 // self._item_width