Skip to content

Commit

Permalink
Re-add support for event data field that has been removed in cocotb 2.0
Browse files Browse the repository at this point in the history
The .data field of cocotb.triggers.Event has been removed in cocotb 2.0.
This is a part of the API exposed by cocotb-bus because Monitor receives
event from external source. It is probably best to keep the current API
until support for cocotb 1.x has been removed from cocotb-bus.

Accordingly, the simpliest solution for this problem is to detect cocotb
2.0 version and re-add the .data field when event.set is being called on
cocotb 2.0.
  • Loading branch information
p12tic authored and ktbarrett committed Sep 10, 2024
1 parent 1ead8a8 commit b99f1fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/cocotb_bus/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ def TestFactory(*args, **kwargs):
return cocotb.regression.TestFactory(*args, **kwargs)


def coroutine(f):
if parse_version(cocotb.__version__) > parse_version("2.dev0"):
if parse_version(cocotb.__version__) > parse_version("2.dev0"):
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)
9 changes: 6 additions & 3 deletions src/cocotb_bus/monitors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()


Expand Down

0 comments on commit b99f1fa

Please sign in to comment.