Skip to content

Commit

Permalink
lib.fifo: annotate for use with CLI. (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Sep 5, 2023
1 parent b0e43eb commit 617fc9a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions amaranth/lib/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .. import *
from ..asserts import *
from .._utils import log2_int
from .wiring import Signature, In, Out
from .coding import GrayEncoder, GrayDecoder
from .cdc import FFSynchronizer, AsyncFFSynchronizer

Expand Down Expand Up @@ -64,7 +65,7 @@ class FIFOInterface:
w_attributes="",
r_attributes="")

def __init__(self, *, width, depth, fwft):
def __init__(self, *, width: int, depth: int, fwft):
if not isinstance(width, int) or width < 0:
raise TypeError("FIFO width must be a non-negative integer, not {!r}"
.format(width))
Expand All @@ -85,6 +86,17 @@ def __init__(self, *, width, depth, fwft):
self.r_en = Signal()
self.r_level = Signal(range(depth + 1))

@property
def signature(self):
return Signature({
"w_data": In(self.width),
"w_rdy": Out(1),
"w_en": In(1),
"r_data": Out(self.width),
"r_rdy": Out(1),
"w_en": In(1),
})


def _incr(signal, modulo):
if modulo == 2 ** len(signal):
Expand Down Expand Up @@ -116,7 +128,7 @@ class SyncFIFO(Elaboratable, FIFOInterface):
r_attributes="",
w_attributes="")

def __init__(self, *, width, depth, fwft=True):
def __init__(self, *, width: int, depth: int, fwft=True):
super().__init__(width=width, depth=depth, fwft=fwft)

self.level = Signal(range(depth + 1))
Expand Down Expand Up @@ -220,7 +232,7 @@ class SyncFIFOBuffered(Elaboratable, FIFOInterface):
r_attributes="",
w_attributes="")

def __init__(self, *, width, depth):
def __init__(self, *, width: int, depth: int):
super().__init__(width=width, depth=depth, fwft=True)

self.level = Signal(range(depth + 1))
Expand Down Expand Up @@ -295,7 +307,7 @@ class AsyncFIFO(Elaboratable, FIFOInterface):
""".strip(),
w_attributes="")

def __init__(self, *, width, depth, r_domain="read", w_domain="write", exact_depth=False):
def __init__(self, *, width: int, depth: int, r_domain="read", w_domain="write", exact_depth=False):
if depth != 0:
try:
depth_bits = log2_int(depth, need_pow2=exact_depth)
Expand Down

0 comments on commit 617fc9a

Please sign in to comment.