2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-27 20:28:25 +08:00
artiq/soc/artiqlib/rtio/phy.py

31 lines
1001 B
Python
Raw Normal View History

from migen.fhdl.std import *
from migen.genlib.cdc import MultiReg
2014-07-26 06:23:35 +08:00
from artiqlib.rtio.rbus import create_rbus
2014-09-05 12:03:22 +08:00
2014-07-26 06:23:35 +08:00
class SimplePHY(Module):
2014-11-30 00:13:54 +08:00
def __init__(self, pads, output_only_pads=set()):
self.rbus = create_rbus(0, pads, output_only_pads)
2014-09-05 12:03:22 +08:00
self.loopback_latency = 3
2014-09-05 12:03:22 +08:00
# # #
2014-07-26 06:23:35 +08:00
2014-09-05 12:03:22 +08:00
for pad, chif in zip(pads, self.rbus):
o_pad = Signal()
2014-11-30 00:13:54 +08:00
self.sync.rio += If(chif.o_stb, o_pad.eq(chif.o_value))
2014-09-11 23:09:43 +08:00
if hasattr(chif, "oe"):
2014-09-05 12:03:22 +08:00
ts = TSTriple()
i_pad = Signal()
2014-11-30 00:13:54 +08:00
self.sync.rio += ts.oe.eq(chif.oe)
2014-09-05 12:03:22 +08:00
self.comb += ts.o.eq(o_pad)
2014-11-30 10:50:48 +08:00
self.specials += MultiReg(ts.i, i_pad, "rio"), \
2014-09-05 12:03:22 +08:00
ts.get_tristate(pad)
2014-09-05 12:03:22 +08:00
i_pad_d = Signal()
2014-11-30 00:13:54 +08:00
self.sync.rio += i_pad_d.eq(i_pad)
2014-09-05 12:03:22 +08:00
self.comb += chif.i_stb.eq(i_pad ^ i_pad_d), \
chif.i_value.eq(i_pad)
2014-09-11 23:09:43 +08:00
else:
self.comb += pad.eq(o_pad)