@@ -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
0 commit comments