@@ -3084,15 +3084,20 @@ class AxiMemoryModel(object):
30843084 burst_size_width = 8
30853085
30863086 def __init__ (self , m , name , clk , rst ,
3087- datawidth = 32 , addrwidth = 32 , mem_addrwidth = 20 ,
3087+ datawidth = 32 , addrwidth = 32 ,
3088+ mem_datawidth = 31 , mem_addrwidth = 20 ,
30883089 memimg = None , write_delay = 10 , read_delay = 10 , sleep = 4 ):
30893090
3091+ if mem_datawidth % 8 != 0 :
3092+ raise ValueError ('mem_datawidth must be a multiple of 8' )
3093+
30903094 self .m = m
30913095 self .name = name
30923096 self .clk = clk
30933097 self .rst = rst
30943098 self .datawidth = datawidth
30953099 self .addrwidth = addrwidth
3100+ self .mem_datawidth = mem_datawidth
30963101 self .mem_addrwidth = mem_addrwidth
30973102
30983103 itype = util .t_Reg
@@ -3113,8 +3118,9 @@ def __init__(self, m, name, clk, rst,
31133118 if memimg is None :
31143119 filename = '_' .join (['' , self .name , 'memimg' , '.out' ])
31153120 size = 2 ** self .mem_addrwidth
3116- wordsize = 4
3121+ wordsize = self . mem_datawidth // 8
31173122 self ._make_img (filename , size , wordsize )
3123+
31183124 else :
31193125 filename = memimg
31203126
@@ -3130,11 +3136,9 @@ def __init__(self, m, name, clk, rst,
31303136 def _make_img (filename , size , wordsize ):
31313137 with open (filename , 'w' ) as f :
31323138 for i in range (int (size // wordsize )):
3133- s = '%08x' % i
3134- f .write ('%s\n ' % s [6 :8 ])
3135- f .write ('%s\n ' % s [4 :6 ])
3136- f .write ('%s\n ' % s [2 :4 ])
3137- f .write ('%s\n ' % s [0 :2 ])
3139+ s = ('' .join (['%0' , '%d' % (wordsize * 2 ), 'x' ])) % i
3140+ for w in range (wordsize * 2 , 0 , - 2 ):
3141+ f .write ('%s\n ' % s [w - 2 :w ])
31383142
31393143 def _make_fsm (self , write_delay = 10 , read_delay = 10 , sleep = 4 ):
31403144 write_mode = 100
0 commit comments