litex/milkymist/sram/__init__.py

28 lines
785 B
Python
Raw Normal View History

2012-01-27 16:09:03 -05:00
from migen.fhdl.structure import *
from migen.bus import wishbone
class SRAM:
def __init__(self, depth):
2012-02-15 10:55:13 -05:00
self.bus = wishbone.Interface()
2012-01-27 16:09:03 -05:00
self.depth = depth
def get_fragment(self):
# generate write enable signal
we = Signal(BV(4))
2012-02-15 10:55:13 -05:00
comb = [we[i].eq(self.bus.cyc & self.bus.stb & self.bus.we & self.bus.sel[i])
2012-01-27 16:09:03 -05:00
for i in range(4)]
# split address
nbits = bits_for(self.depth-1)
partial_adr = Signal(BV(nbits))
2012-02-15 10:55:13 -05:00
comb.append(partial_adr.eq(self.bus.adr[:nbits]))
2012-01-27 16:09:03 -05:00
# generate ack
sync = [
2012-02-15 10:55:13 -05:00
self.bus.ack.eq(0),
If(self.bus.cyc & self.bus.stb & ~self.bus.ack,
self.bus.ack.eq(1)
2012-01-27 16:09:03 -05:00
)
]
# memory
2012-02-15 10:55:13 -05:00
port = MemoryPort(partial_adr, self.bus.dat_r, we, self.bus.dat_w, we_granularity=8)
2012-01-27 16:09:03 -05:00
return Fragment(comb, sync, memories=[Memory(32, self.depth, port)])