2015-06-02 17:41:40 +08:00
|
|
|
from migen.fhdl.std import *
|
|
|
|
from migen.bank.description import *
|
|
|
|
from migen.genlib.cdc import BusSynchronizer
|
|
|
|
|
2015-06-03 18:26:19 +08:00
|
|
|
|
2015-06-02 17:41:40 +08:00
|
|
|
class Monitor(Module, AutoCSR):
|
|
|
|
def __init__(self, channels):
|
|
|
|
chan_probes = [c.probes for c in channels]
|
|
|
|
|
|
|
|
max_chan_probes = max(len(cp) for cp in chan_probes)
|
|
|
|
max_probe_len = max(flen(p) for cp in chan_probes for p in cp)
|
|
|
|
self.chan_sel = CSRStorage(bits_for(len(chan_probes)-1))
|
|
|
|
self.probe_sel = CSRStorage(bits_for(max_chan_probes-1))
|
|
|
|
self.probe_value = CSRStatus(max_probe_len)
|
|
|
|
|
|
|
|
# # #
|
|
|
|
|
|
|
|
chan_probes_sys = []
|
|
|
|
for cp in chan_probes:
|
|
|
|
cp_sys = []
|
|
|
|
for p in cp:
|
|
|
|
vs = BusSynchronizer(flen(p), "rio", "rsys")
|
|
|
|
self.submodules += vs
|
|
|
|
self.comb += vs.i.eq(p)
|
|
|
|
cp_sys.append(vs.o)
|
|
|
|
cp_sys += [0]*(max_chan_probes-len(cp))
|
|
|
|
chan_probes_sys.append(Array(cp_sys)[self.probe_sel.storage])
|
|
|
|
self.comb += self.probe_value.status.eq(
|
|
|
|
Array(chan_probes_sys)[self.chan_sel.storage])
|