litex/migen/flow/isd.py

70 lines
1.6 KiB
Python
Raw Normal View History

2012-08-03 12:49:04 -04:00
from migen.fhdl.structure import *
2013-03-30 12:28:41 -04:00
from migen.fhdl.module import Module
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()
2012-08-03 12:49:04 -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)
2012-08-03 12:49:04 -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):
2013-03-30 12:28:41 -04:00
self._r_magic = CSRStatus(16)
self._r_neps = CSRStatus(8)
self._r_nbits = CSRStatus(8)
self._r_freeze = CSRStorage()
self._r_reset = CSR()
2012-08-03 12:49:04 -04:00
2013-03-30 12:28:41 -04:00
###
DFGHook.__init__(self, dfg,
lambda u, ep, v: EndpointReporter(u.endpoints[ep], nbits))
self.comb += [
self._r_magic.status.eq(ISD_MAGIC),
self._r_neps.status.eq(len(self.hooks_iter())),
self._r_nbits.status.eq(nbits)
2012-08-03 12:49:04 -04:00
]
2012-08-04 17:39:52 -04:00
for h in self.hooks_iter():
2013-03-30 12:28:41 -04:00
self.comb += [
h.freeze.eq(self._r_freeze.storage),
2012-08-04 17:39:52 -04:00
h.reset.eq(self._r_reset.re)
]