Skip to content

Commit 8ba1d2e

Browse files
committed
ExtRAM class is introduced to utilize an external SRAM. Signal types of itype and otype are now customizable. The use of connect_ports method replaced with dedicated signal-name pairs.
1 parent 4dfbb26 commit 8ba1d2e

File tree

2 files changed

+87
-13
lines changed

2 files changed

+87
-13
lines changed

veriloggen/thread/ram.py

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class RAM(_MutexFunction):
2222
def __init__(self, m, name, clk, rst,
2323
datawidth=32, addrwidth=10, numports=1,
2424
initvals=None, nocheck_initvals=False,
25-
ram_style=None, external_ports=None):
25+
ram_style=None, external_ports=None,
26+
itype='Wire', otype='Wire',
27+
ext_itype='Input', ext_otype='Output'):
2628

2729
self.m = m
2830
self.name = name
@@ -45,10 +47,10 @@ def __init__(self, m, name, clk, rst,
4547
for i in range(numports):
4648
if i in external_ports:
4749
interface = RAMInterface(m, name + '_%d' % i, datawidth, addrwidth,
48-
itype='Input', otype='Output', with_enable=True)
50+
itype=ext_itype, otype=ext_otype, with_enable=True)
4951
else:
5052
interface = RAMInterface(m, name + '_%d' % i, datawidth, addrwidth,
51-
itype='Wire', otype='Wire', with_enable=True)
53+
itype=itype, otype=otype, with_enable=True)
5254

5355
self.interfaces.append(interface)
5456

@@ -71,7 +73,14 @@ def __init__(self, m, name, clk, rst,
7173

7274
ports = collections.OrderedDict()
7375
ports['CLK'] = self.clk
74-
ports.update(m.connect_ports(self.definition))
76+
77+
for i, interface in enumerate(self.interfaces):
78+
ports[name + '_%d_addr' % i] = interface.addr
79+
ports[name + '_%d_rdata' % i] = interface.rdata
80+
ports[name + '_%d_wdata' % i] = interface.wdata
81+
ports[name + '_%d_wenable' % i] = interface.wenable
82+
ports[name + '_%d_enable' % i] = interface.enable
83+
7584
self.inst = self.m.Instance(self.definition, 'inst_' + name,
7685
ports=ports)
7786

@@ -317,14 +326,19 @@ class FixedRAM(RAM):
317326
def __init__(self, m, name, clk, rst,
318327
datawidth=32, addrwidth=10, numports=1, point=0,
319328
initvals=None, nocheck_initvals=False, noconvert_initvals=False,
320-
ram_style=None, external_ports=None):
329+
ram_style=None, external_ports=None,
330+
itype='Wire', otype='Wire',
331+
ext_itype='Input', ext_otype='Output'):
321332

322333
if initvals is not None and not noconvert_initvals:
323334
initvals = [fxd.to_fixed(initval, point) for initval in initvals]
324335

325336
RAM.__init__(self, m, name, clk, rst,
326337
datawidth, addrwidth, numports,
327-
initvals, nocheck_initvals, ram_style, external_ports)
338+
initvals, nocheck_initvals,
339+
ram_style, external_ports,
340+
itype, otype,
341+
ext_itype, ext_otype)
328342

329343
self.point = point
330344

@@ -369,7 +383,9 @@ class MultibankRAM(RAM):
369383

370384
def __init__(self, m, name, clk, rst,
371385
datawidth=32, addrwidth=10, numports=1, numbanks=2,
372-
ram_style=None, external_ports=None):
386+
ram_style=None, external_ports=None,
387+
itype='Wire', otype='Wire',
388+
ext_itype='Input', ext_otype='Output'):
373389

374390
if numbanks < 2:
375391
raise ValueError('numbanks must be 2 or more')
@@ -390,7 +406,9 @@ def __init__(self, m, name, clk, rst,
390406
self.shift = util.log2(self.numbanks)
391407
self.rams = [RAM(m, '_'.join([name, '%d' % i]),
392408
clk, rst, datawidth, addrwidth, numports,
393-
ram_style=ram_style, external_ports=external_ports)
409+
ram_style=ram_style, external_ports=external_ports,
410+
itype=itype, otype=otype,
411+
ext_itype=ext_itype, ext_otype=ext_otype)
394412
for i in range(numbanks)]
395413
self.keep_hierarchy = False
396414
self.seq = None
@@ -976,3 +994,46 @@ def to_multibank_ram(rams, name=None, keep_hierarchy=False):
976994
multibank_ram_cache[ids] = ram
977995

978996
return ram
997+
998+
999+
class ExtRAM(RAM):
1000+
""" Only external RAM interface is synthesized. No RAM instance is synthesized."""
1001+
1002+
def __init__(self, m, name, clk, rst,
1003+
datawidth=32, addrwidth=10, numports=1,
1004+
itype='Output', otype='Input'):
1005+
1006+
self.m = m
1007+
self.name = name
1008+
self.clk = clk
1009+
self.rst = rst
1010+
1011+
self.datawidth = datawidth
1012+
self.addrwidth = addrwidth
1013+
1014+
self.packed_datawidth = datawidth
1015+
self.packed_addrwidth = addrwidth
1016+
1017+
self.numports = numports
1018+
1019+
self.interfaces = []
1020+
1021+
for i in range(numports):
1022+
interface = RAMInterface(m, name + '_%d' % i, datawidth, addrwidth,
1023+
itype=itype, otype=otype, with_enable=True)
1024+
1025+
self.interfaces.append(interface)
1026+
1027+
for interface in self.interfaces:
1028+
interface.wdata.no_write_check = True
1029+
1030+
# default values
1031+
for i, interface in enumerate(self.interfaces):
1032+
interface.addr.assign(vtypes.IntX())
1033+
interface.wdata.assign(vtypes.IntX())
1034+
interface.wenable.assign(0)
1035+
interface.enable.assign(0)
1036+
1037+
self.seq = Seq(m, name, clk, rst)
1038+
1039+
self.mutex = None

veriloggen/types/ram.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,32 @@ class _RAM_RTL(object):
164164

165165
def __init__(self, m, name, clk,
166166
datawidth=32, addrwidth=10, numports=1,
167-
initvals=None, sync=True, with_enable=False):
167+
initvals=None, sync=True, with_enable=False,
168+
itype='Wire', otype='Wire'):
168169

169170
self.m = m
170171
self.name = name
171172
self.clk = clk
172173
self.with_enable = with_enable
173174

174175
self.interfaces = [RAMInterface(m, name + '_%d' % i, datawidth, addrwidth,
175-
itype='Wire', otype='Wire', with_enable=with_enable)
176+
itype=itype, otype=otype, with_enable=with_enable)
176177
for i in range(numports)]
177178

178179
ram_def = mkRAMDefinition(name, datawidth, addrwidth, numports,
179180
initvals, sync, with_enable)
180181

181182
ports = collections.OrderedDict()
182183
ports['CLK'] = self.clk
183-
ports.update(m.connect_ports(ram_def))
184+
185+
for i, interface in enumerate(self.interfaces):
186+
ports[name + '_%d_addr' % i] = interface.addr
187+
ports[name + '_%d_rdata' % i] = interface.rdata
188+
ports[name + '_%d_wdata' % i] = interface.wdata
189+
ports[name + '_%d_wenable' % i] = interface.wenable
190+
if with_enable:
191+
ports[name + '_%d_enable' % i] = interface.enable
192+
184193
self.m.Instance(ram_def, name,
185194
params=(), ports=ports)
186195

@@ -199,7 +208,9 @@ class SyncRAM(_RAM_RTL):
199208

200209
def __init__(self, m, name, clk,
201210
datawidth=32, addrwidth=10, numports=1,
202-
initvals=None, with_enable=False):
211+
initvals=None, with_enable=False,
212+
itype='Wire', otype='Wire'):
213+
203214
_RAM_RTL.__init__(self, m, name, clk,
204215
datawidth, addrwidth, numports,
205216
initvals, sync=True, with_enable=with_enable)
@@ -209,7 +220,9 @@ class AsyncRAM(_RAM_RTL):
209220

210221
def __init__(self, m, name, clk,
211222
datawidth=32, addrwidth=10, numports=1,
212-
initvals=None, with_enable=False):
223+
initvals=None, with_enable=False,
224+
itype='Wire', otype='Wire'):
225+
213226
_RAM_RTL.__init__(self, m, name, clk,
214227
datawidth, addrwidth, numports,
215228
initvals, sync=False)

0 commit comments

Comments
 (0)