Source code for hwtLib.handshaked.intfBiDirectional
from collections import deque
from hwt.hdl.constants import DIRECTION
from hwt.interfaces.agents.handshaked import HandshakedAgent
from hwt.interfaces.std import Handshaked, VectSignal, Signal
from hwtSimApi.hdlSimulator import HdlSimulator
[docs]class HandshakedBiDirectionalAgent(HandshakedAgent):
"""
Simulation agent for :class:`.HandshakedBiDirectional` interface
:attention: for monitor number of items in dinData
has to match with number of received items
"""
[docs] def __init__(self, sim, intf):
HandshakedAgent.__init__(self, sim, intf)
self.dinData = deque()
self._isMonitor = False
[docs] def getMonitors(self):
self._isMonitor = True
return HandshakedAgent.getMonitors(self)
[docs] def notReset(self):
nr = HandshakedAgent.notReset(self)
if self._isMonitor:
return nr and self.dinData
else:
return nr
[docs] def onMonitorReady(self):
"write din"
d = self.dinData.popleft()
self.intf.din.write(d)
[docs] def onDriverWriteAck(self):
"read din"
d = self.intf.din.read()
self.dinData.append(d)
[docs] def get_data(self):
"""extract data from interface"""
return self.intf.dout.read()
[docs] def set_data(self, data):
"""write data to interface"""
self.intf.dout.write(data)
[docs]class HandshakedBiDirectional(Handshaked):
"""
:class:`hwt.interfaces.std.Handshaked` interface with data
channels in bout direction
.. hwt-autodoc::
"""
def _declr(self):
self.din = VectSignal(self.DATA_WIDTH, masterDir=DIRECTION.IN)
self.dout = VectSignal(self.DATA_WIDTH)
self.vld = Signal()
self.rd = Signal(masterDir=DIRECTION.IN)
[docs] def _initSimAgent(self, sim: HdlSimulator):
self._ag = HandshakedBiDirectionalAgent(sim, self)