litex/liteeth/core/etherbone/wishbone.py

69 lines
1.5 KiB
Python
Raw Normal View History

2015-02-11 13:44:02 -05:00
from liteeth.common import *
from migen.bus import wishbone
class LiteEthEtherboneWishboneMaster(Module):
def __init__(self):
2015-02-11 19:12:52 -05:00
self.sink = sink = Sink(eth_etherbone_mmap_description(32))
self.source = source = Source(eth_etherbone_mmap_description(32))
2015-02-11 13:44:02 -05:00
self.bus = bus = wishbone.Interface()
###s
2015-02-11 19:12:52 -05:00
self.submodules.data = data = FlipFlop(32)
2015-02-11 13:44:02 -05:00
self.comb += data.d.eq(bus.dat_r)
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
2015-02-11 19:12:52 -05:00
sink.ack.eq(1),
If(sink.stb & sink.sop,
sink.ack.eq(0),
If(sink.we,
NextState("WRITE_DATA")
).Else(
NextState("READ_DATA")
)
2015-02-11 13:44:02 -05:00
)
)
fsm.act("WRITE_DATA",
2015-02-11 19:12:52 -05:00
bus.adr.eq(sink.addr),
bus.dat_w.eq(sink.data),
bus.sel.eq(sink.be),
bus.stb.eq(sink.stb),
2015-02-11 13:44:02 -05:00
bus.we.eq(1),
bus.cyc.eq(1),
If(bus.stb & bus.ack,
2015-02-11 19:12:52 -05:00
sink.ack.eq(1),
If(sink.eop,
2015-02-11 13:44:02 -05:00
NextState("IDLE")
)
)
)
fsm.act("READ_DATA",
2015-02-11 19:12:52 -05:00
bus.adr.eq(sink.addr),
bus.sel.eq(sink.be),
bus.stb.eq(sink.stb),
2015-02-11 13:44:02 -05:00
bus.cyc.eq(1),
If(bus.stb & bus.ack,
data.ce.eq(1),
NextState("SEND_DATA")
)
)
fsm.act("SEND_DATA",
2015-02-11 19:12:52 -05:00
source.stb.eq(sink.stb),
source.sop.eq(sink.sop),
source.eop.eq(sink.eop),
source.base_addr.eq(sink.base_addr),
source.addr.eq(sink.addr),
source.count.eq(sink.count),
source.be.eq(sink.be),
source.we.eq(1),
source.data.eq(data.q),
If(source.stb & source.ack,
sink.ack.eq(1),
If(source.eop,
2015-02-11 13:44:02 -05:00
NextState("IDLE")
).Else(
NextState("READ_DATA")
)
)
)