litex/migen/actorlib/dma_asmi.py

84 lines
2.2 KiB
Python
Raw Normal View History

2012-06-12 15:04:47 -04:00
from migen.fhdl.structure import *
2013-04-10 13:12:42 -04:00
from migen.fhdl.module import Module
2012-06-12 15:04:47 -04:00
from migen.flow.actor import *
2013-02-22 17:19:37 -05:00
from migen.genlib.buffers import ReorderBuffer
2012-06-12 15:04:47 -04:00
2013-04-10 13:12:42 -04:00
class SequentialReader(Module):
2012-06-12 15:04:47 -04:00
def __init__(self, port):
2013-04-10 13:12:42 -04:00
assert(len(port.slots) == 1)
self.address = Sink([("a", port.hub.aw)])
self.data = Source([("d", port.hub.dw)])
self.busy = Signal()
2012-06-12 15:04:47 -04:00
2013-04-10 13:12:42 -04:00
###
2012-06-12 15:04:47 -04:00
sample = Signal()
data_reg_loaded = Signal()
2013-04-10 13:12:42 -04:00
data_reg = Signal(port.hub.dw)
2012-06-12 15:04:47 -04:00
accept_new = Signal()
2013-04-10 13:12:42 -04:00
# We check that len(port.slots) == 1
# and therefore we can assume that port.ack
2012-06-12 15:04:47 -04:00
# goes low until the data phase.
2013-04-10 13:12:42 -04:00
self.comb += [
self.busy.eq(~data_reg_loaded | ~port.ack),
port.adr.eq(self.address.payload.a),
port.we.eq(0),
accept_new.eq(~data_reg_loaded | self.data.ack),
port.stb.eq(self.address.stb & accept_new),
self.address.ack.eq(port.ack & accept_new),
self.data.stb.eq(data_reg_loaded),
self.data.payload.d.eq(data_reg)
2012-06-12 15:04:47 -04:00
]
2013-04-10 13:12:42 -04:00
self.sync += [
If(self.data.ack, data_reg_loaded.eq(0)),
2012-06-12 15:04:47 -04:00
If(sample,
data_reg_loaded.eq(1),
2013-04-10 13:12:42 -04:00
data_reg.eq(port.dat_r)
2012-06-12 15:04:47 -04:00
),
2013-04-10 13:12:42 -04:00
sample.eq(port.get_call_expression())
2012-06-12 15:04:47 -04:00
]
2013-04-10 13:12:42 -04:00
class OOOReader(Module):
def __init__(self, port):
2013-04-10 13:12:42 -04:00
assert(len(port.slots) > 1)
self.address = Sink([("a", port.hub.aw)])
self.data = Source([("d", port.hub.dw)])
self.busy = Signal() # TODO: drive busy
2013-04-10 13:12:42 -04:00
###
tag_width = len(port.tag_call)
data_width = port.hub.dw
depth = len(port.slots)
rob = ReorderBuffer(tag_width, data_width, depth)
2013-04-10 13:12:42 -04:00
self.submodules += rob
2013-04-10 13:12:42 -04:00
self.comb += [
port.adr.eq(self.address.payload.a),
port.we.eq(0),
port.stb.eq(self.address.stb & rob.can_issue),
self.address.ack.eq(port.ack & rob.can_issue),
rob.issue.eq(self.address.stb & port.ack),
rob.tag_issue.eq(port.base + port.tag_issue),
2013-04-10 13:12:42 -04:00
rob.data_call.eq(port.dat_r),
2013-04-10 13:12:42 -04:00
self.data.stb.eq(rob.can_read),
rob.read.eq(self.data.ack),
self.data.payload.d.eq(rob.data_read)
]
2013-04-10 13:12:42 -04:00
self.sync += [
# Data is announced one cycle in advance.
# Register the call to synchronize it with the data signal.
2013-04-10 13:12:42 -04:00
rob.call.eq(port.call),
rob.tag_call.eq(port.tag_call)
]
2013-04-10 13:12:42 -04:00
def Reader(port):
if len(port.slots) == 1:
return SequentialReader(port)
else:
return OOOReader(port)