diff --git a/src/cocotb_bus/compat.py b/src/cocotb_bus/compat.py index 810f1af3..0d180a78 100644 --- a/src/cocotb_bus/compat.py +++ b/src/cocotb_bus/compat.py @@ -15,11 +15,20 @@ def TestFactory(*args, **kwargs): return cocotb.regression.TestFactory(*args, **kwargs) -def coroutine(f): - # Note that we want to not use coroutine in beta versions of cocotb 2.0 too. - # Therefore we cannot use 2.0 in comparison, because - # parse_version("2.0a1") < parse_version("2.0") - if parse_version(cocotb.__version__) > parse_version("1.999.0"): +# Note that we want to not use coroutine in beta versions of cocotb 2.0 too. +# Therefore we cannot use 2.0 in comparison, because +# parse_version("2.0a1") < parse_version("2.0") +if parse_version(cocotb.__version__) > parse_version("1.999.0"): + def set_event(event, data): + event.data = data + event.set() + + def coroutine(f): return f - return cocotb.coroutine(f) +else: + def set_event(event, data): + event.set(data) + + def coroutine(f): + return cocotb.coroutine(f) diff --git a/src/cocotb_bus/monitors/__init__.py b/src/cocotb_bus/monitors/__init__.py index c87e448a..f5c37cab 100644 --- a/src/cocotb_bus/monitors/__init__.py +++ b/src/cocotb_bus/monitors/__init__.py @@ -17,7 +17,7 @@ from cocotb.triggers import Event, Timer, First from cocotb_bus.bus import Bus -from cocotb_bus.compat import coroutine +from cocotb_bus.compat import coroutine, set_event class MonitorStatistics: @@ -51,7 +51,10 @@ class Monitor: def __init__(self, callback=None, event=None): self._event = event + if self._event is not None: + self._event.data = None # FIXME: This attribute should be removed on next API break self._wait_event = Event() + self._wait_event.data = None self._recvQ = deque() self._callbacks = [] self.stats = MonitorStatistics() @@ -134,11 +137,11 @@ def _recv(self, transaction): self._recvQ.append(transaction) if self._event is not None: - self._event.set(data=transaction) + set_event(self._event, transaction) # If anyone was waiting then let them know if self._wait_event is not None: - self._wait_event.set(data=transaction) + set_event(self._wait_event, transaction) self._wait_event.clear()