litex/migen/actorlib/fifo.py

47 lines
1.3 KiB
Python
Raw Normal View History

2013-09-03 18:01:33 -04:00
from migen.fhdl.std import *
from migen.flow.actor import *
from migen.genlib import fifo
class _FIFOActor(Module):
def __init__(self, fifo_class, layout, depth):
2013-09-03 18:01:33 -04:00
self.sink = Sink(layout)
self.source = Source(layout)
self.busy = Signal()
###
2013-09-03 18:01:33 -04:00
description = self.sink.description
fifo_layout = [("payload", description.payload_layout)]
if description.packetized:
fifo_layout += [("sop", 1), ("eop", 1)]
self.submodules.fifo = fifo_class(fifo_layout, depth)
2013-09-03 18:01:33 -04:00
self.comb += [
self.sink.ack.eq(self.fifo.writable),
self.fifo.we.eq(self.sink.stb),
self.fifo.din.payload.eq(self.sink.payload),
2013-09-03 18:01:33 -04:00
self.source.stb.eq(self.fifo.readable),
self.source.payload.eq(self.fifo.dout.payload),
self.fifo.re.eq(self.source.ack)
]
if description.packetized:
self.comb += [
self.fifo.din.sop.eq(self.sink.sop),
self.fifo.din.eop.eq(self.sink.eop),
self.source.sop.eq(self.fifo.dout.sop),
self.source.eop.eq(self.fifo.dout.eop)
]
2013-09-03 18:01:33 -04:00
class SyncFIFO(_FIFOActor):
2014-11-20 21:46:54 -05:00
def __init__(self, layout, depth, buffered=False):
_FIFOActor.__init__(
self,
fifo.SyncFIFOBuffered if buffered else fifo.SyncFIFO,
layout, depth)
2013-09-03 18:01:33 -04:00
class AsyncFIFO(_FIFOActor):
def __init__(self, layout, depth):
2014-10-20 11:11:59 -04:00
_FIFOActor.__init__(self, fifo.AsyncFIFO, layout, depth)