Skip to content

Commit 28f00c3

Browse files
author
Sebastien Bourdeauducq
committedJan 27, 2012
Add on-chip SRAM
1 parent 6fde54c commit 28f00c3

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
 

‎milkymist/sram/__init__.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from migen.fhdl.structure import *
2+
from migen.bus import wishbone
3+
4+
class SRAM:
5+
def __init__(self, depth):
6+
self.bus = wishbone.Slave("sram")
7+
self.depth = depth
8+
9+
def get_fragment(self):
10+
# generate write enable signal
11+
we = Signal(BV(4))
12+
comb = [we[i].eq(self.bus.cyc_i & self.bus.stb_i & self.bus.sel_i[3-i])
13+
for i in range(4)]
14+
# split address
15+
nbits = bits_for(self.depth-1)
16+
partial_adr = Signal(BV(nbits))
17+
comb.append(partial_adr.eq(self.bus.adr_i[:nbits]))
18+
# generate ack
19+
sync = [
20+
self.bus.ack_o.eq(0),
21+
If(self.bus.cyc_i & self.bus.stb_i & ~self.bus.ack_o,
22+
self.bus.ack_o.eq(1)
23+
)
24+
]
25+
# memory
26+
port = MemoryPort(partial_adr, self.bus.dat_o, we, self.bus.dat_i, we_granularity=8)
27+
return Fragment(comb, sync, memories=[Memory(32, self.depth, port)])

‎top.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
from migen.fhdl import tools, verilog, autofragment
33
from migen.bus import wishbone, csr, wishbone2csr
44

5-
from milkymist import m1reset, clkfx, lm32, norflash, uart
5+
from milkymist import m1reset, clkfx, lm32, norflash, uart, sram
66
import constraints
77

88
def get():
99
MHz = 1000000
1010
clk_freq = 80*MHz
11+
sram_size = 4096 # in kilobytes
1112

1213
clkfx_sys = clkfx.ClkFX(50*MHz, clk_freq)
1314
reset0 = m1reset.M1Reset()
1415

1516
cpu0 = lm32.LM32()
1617
norflash0 = norflash.NorFlash(25, 12)
18+
sram0 = sram.SRAM(sram_size//4)
1719
wishbone2csr0 = wishbone2csr.WB2CSR()
1820
wishbonecon0 = wishbone.InterconnectShared(
1921
[cpu0.ibus, cpu0.dbus],
20-
[(0, norflash0.bus), (3, wishbone2csr0.wishbone)],
22+
[(0, norflash0.bus), (1, sram0.bus), (3, wishbone2csr0.wishbone)],
2123
register=True,
2224
offset=1)
2325
uart0 = uart.UART(0, clk_freq, baud=115200)

0 commit comments

Comments
 (0)
Please sign in to comment.