Skip to content

Instantly share code, notes, and snippets.

@XMPPwocky
Created July 26, 2020 07:28
Show Gist options
  • Save XMPPwocky/af5f3d252b76626665756663b87561e6 to your computer and use it in GitHub Desktop.
Save XMPPwocky/af5f3d252b76626665756663b87561e6 to your computer and use it in GitHub Desktop.
class RamWindow(Elaboratable):
"""
Note - the maximum (0xFF..) address isn't usable while shifting samples in!
I don't plan to do anything about it.
Latency (input to output) - (2 + addr) cycles
Latency (addr to output) - 1 cycle (!)
"""
def __init__(self, width, addr_width):
self.width = width
self.addr_width = addr_width
self.shift_in = Signal(reset=1)
self.addr = Signal(self.addr_width)
self.input = Signal(width)
self.output = Signal(width)
def elaborate(self, platform):
depth = 2**self.addr_width
cursor = Signal(self.addr_width, reset=0)
mem = Memory(width=self.width,
depth=depth,
init=[0]*depth)
m = Module()
m.submodules.rdport = rdport = mem.read_port()
m.submodules.wrport = wrport = mem.write_port()
m.d.comb += [
wrport.en.eq(self.shift_in),
wrport.data.eq(self.input),
wrport.addr.eq(cursor+1),
rdport.addr.eq(cursor-self.addr),
self.output.eq(rdport.data),
]
with m.If(self.shift_in):
m.d.sync += cursor.eq(cursor + 1)
return m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment