litex/migen/flow/isd.py

70 lines
1.5 KiB
Python
Raw Normal View History

from migen.fhdl.std import *
2012-08-03 12:49:04 -04:00
from migen.bank.description import *
from migen.flow.hooks import DFGHook
ISD_MAGIC = 0x6ab4
2013-03-30 12:28:41 -04:00
class EndpointReporter(Module, AutoCSR):
2012-08-03 12:49:04 -04:00
def __init__(self, endpoint, nbits):
self.reset = Signal()
2012-08-04 17:39:52 -04:00
self.freeze = Signal()
2014-10-17 05:08:37 -04:00
2013-03-30 12:28:41 -04:00
self._ack_count = CSRStatus(nbits)
self._nack_count = CSRStatus(nbits)
self._cur_status = CSRStatus(2)
2014-10-17 05:08:37 -04:00
2013-03-30 12:28:41 -04:00
###
2012-08-03 12:49:04 -04:00
stb = Signal()
ack = Signal()
2013-03-30 12:28:41 -04:00
self.comb += self._cur_status.status.eq(Cat(stb, ack))
ack_count = Signal(nbits)
nack_count = Signal(nbits)
self.sync += [
2012-08-03 12:49:04 -04:00
# register monitored signals
2013-03-30 12:28:41 -04:00
stb.eq(endpoint.stb),
ack.eq(endpoint.ack),
2012-08-03 12:49:04 -04:00
# count operations
If(self.reset,
ack_count.eq(0),
nack_count.eq(0)
).Else(
If(stb,
If(ack,
ack_count.eq(ack_count + 1)
).Else(
nack_count.eq(nack_count + 1)
)
)
2012-08-04 17:39:52 -04:00
),
If(~self.freeze,
2013-03-30 12:28:41 -04:00
self._ack_count.status.eq(ack_count),
self._nack_count.status.eq(nack_count)
2012-08-03 12:49:04 -04:00
)
]
2013-03-30 12:28:41 -04:00
class DFGReporter(DFGHook, AutoCSR):
2012-08-03 12:49:04 -04:00
def __init__(self, dfg, nbits):
2015-04-02 06:15:56 -04:00
self._magic = CSRStatus(16)
self._neps = CSRStatus(8)
self._nbits = CSRStatus(8)
self._freeze = CSRStorage()
self._reset = CSR()
2014-10-17 05:08:37 -04:00
2013-03-30 12:28:41 -04:00
###
DFGHook.__init__(self, dfg,
2013-11-20 11:45:09 -05:00
lambda u, ep, v: EndpointReporter(getattr(u, ep), nbits))
hooks = list(self.hooks_iter())
2013-03-30 12:28:41 -04:00
self.comb += [
2015-04-02 06:15:56 -04:00
self._magic.status.eq(ISD_MAGIC),
self._neps.status.eq(len(hooks)),
self._nbits.status.eq(nbits)
2012-08-03 12:49:04 -04:00
]
2013-11-20 11:45:09 -05:00
for h in hooks:
2013-03-30 12:28:41 -04:00
self.comb += [
2015-04-02 06:15:56 -04:00
h.freeze.eq(self._freeze.storage),
h.reset.eq(self._reset.re)
2012-08-04 17:39:52 -04:00
]