Skip to content

Commit

Permalink
migen/actorlib/fifo: add FIFO wrapper function
Browse files Browse the repository at this point in the history
Allow automatic instantiation of the correct fifo (SyncFIFO or AsyncFIFO) according to the clock domains passed in argument.
  • Loading branch information
enjoy-digital committed Jul 24, 2015
1 parent 1f1ff5a commit d0a19c4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions migen/actorlib/fifo.py
Expand Up @@ -55,3 +55,15 @@ def __init__(self, layout, depth, buffered=False):
class AsyncFIFO(_FIFOActor):
def __init__(self, layout, depth):
_FIFOActor.__init__(self, fifo.AsyncFIFO, layout, depth)


def FIFO(layout, depth, buffered=False,
sink_cd="sys", source_cd="sys"):
if sink_cd != source_cd:
if buffered:
ValueError("AsyncFIFO does not support buffered mode")
fifo = AsyncFIFO(layout, depth)
return ClockDomainsRenamer({"write": sink_cd, "read": source_cd})(fifo)
else:
fifo = SyncFIFO(layout, depth, buffered)
return ClockDomainsRenamer(sink_cd)(fifo)

2 comments on commit d0a19c4

@sbourdeauducq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope.

  1. Why have this API for FIFOs and not for other cores? If the problem is the ClockDomainsRenamer syntax is too heavy then that syntax should be fixed. Adding a kludge on top of it is the way to autoconf-style software.
  2. Factory functions are problematic as they break inheritance.

@enjoy-digital
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. (I replaced it by a specific function in UART core)
The main reason was in fact to autoselect the fifo, but since this is only used for UART now and I don't see many use cases for that you are probably right :)

Please sign in to comment.