litex/migen/actorlib/dma_wishbone.py

55 lines
1.3 KiB
Python
Raw Normal View History

from migen.fhdl.std import *
from migen.bus import wishbone
from migen.flow.actor import *
2013-04-10 13:12:42 -04:00
class Reader(Module):
2012-06-08 15:31:05 -04:00
def __init__(self):
self.bus = wishbone.Interface()
2013-04-10 13:12:42 -04:00
self.address = Sink([("a", 30)])
self.data = Source([("d", 32)])
self.busy = Signal()
2014-10-17 05:08:37 -04:00
2013-04-10 13:12:42 -04:00
###
2014-10-17 05:08:37 -04:00
2012-06-08 15:31:05 -04:00
bus_stb = Signal()
data_reg_loaded = Signal()
data_reg = Signal(32)
2014-10-17 05:08:37 -04:00
2013-04-10 13:12:42 -04:00
self.comb += [
2012-06-08 15:31:05 -04:00
self.busy.eq(data_reg_loaded),
self.bus.we.eq(0),
2013-04-10 13:12:42 -04:00
bus_stb.eq(self.address.stb & (~data_reg_loaded | self.data.ack)),
2012-06-08 15:31:05 -04:00
self.bus.cyc.eq(bus_stb),
self.bus.stb.eq(bus_stb),
2013-04-10 13:12:42 -04:00
self.bus.adr.eq(self.address.payload.a),
self.address.ack.eq(self.bus.ack),
self.data.stb.eq(data_reg_loaded),
self.data.payload.d.eq(data_reg)
2012-06-08 15:31:05 -04:00
]
2013-04-10 13:12:42 -04:00
self.sync += [
If(self.data.ack, data_reg_loaded.eq(0)),
2012-06-08 15:31:05 -04:00
If(self.bus.ack,
data_reg_loaded.eq(1),
data_reg.eq(self.bus.dat_r)
)
2012-06-08 15:31:05 -04:00
]
2013-04-10 13:12:42 -04:00
class Writer(Module):
2012-06-08 15:31:05 -04:00
def __init__(self):
self.bus = wishbone.Interface()
2013-04-10 13:12:42 -04:00
self.address_data = Sink([("a", 30), ("d", 32)])
self.busy = Signal()
###
2012-06-08 15:31:05 -04:00
2013-04-10 13:12:42 -04:00
self.comb += [
2012-06-08 15:31:05 -04:00
self.busy.eq(0),
self.bus.we.eq(1),
2013-04-10 13:12:42 -04:00
self.bus.cyc.eq(self.address_data.stb),
self.bus.stb.eq(self.address_data.stb),
self.bus.adr.eq(self.address_data.payload.a),
2012-06-08 15:31:05 -04:00
self.bus.sel.eq(0xf),
2013-04-10 13:12:42 -04:00
self.bus.dat_w.eq(self.address_data.payload.d),
self.address_data.ack.eq(self.bus.ack)
2012-06-08 15:31:05 -04:00
]