1717
1818LOGGER = logging .getLogger (__name__ )
1919
20- # known CASPER memory-accessible devices and their associated classes and containers
20+ # known CASPER memory-accessible devices and their associated
21+ # classes and containers
2122CASPER_MEMORY_DEVICES = {
22- 'xps:bram' : {'class' : sbram .Sbram , 'container' : 'sbrams' },
23- 'xps:qdr' : {'class' : qdr .Qdr , 'container' : 'qdrs' },
24- 'xps:sw_reg' : {'class' : register .Register , 'container' : 'registers' },
25- 'xps:tengbe_v2' : {'class' : tengbe .TenGbe , 'container' : 'tengbes' },
26- 'casper:snapshot' : {'class' : snap .Snap , 'container' : 'snapshots' },
23+ 'xps:bram' : {'class' : sbram .Sbram , 'container' : 'sbrams' },
24+ 'xps:qdr' : {'class' : qdr .Qdr , 'container' : 'qdrs' },
25+ 'xps:sw_reg' : {'class' : register .Register , 'container' : 'registers' },
26+ 'xps:tengbe_v2' : {'class' : tengbe .TenGbe , 'container' : 'tengbes' },
27+ 'casper:snapshot' : {'class' : snap .Snap , 'container' : 'snapshots' },
2728}
2829
2930
30- # other devices - blocks that aren't memory devices, but about which we'd like to know
31- # tagged in the simulink diagram
31+ # other devices - blocks that aren't memory devices, but about which we'd
32+ # like to know tagged in the simulink diagram
3233CASPER_OTHER_DEVICES = {
3334 'casper:bitsnap' : 'bitsnap' ,
3435 'casper:dec_fir' : 'dec_fir' ,
@@ -79,7 +80,8 @@ def listdev(self):
7980
8081 def deprogram (self ):
8182 """
82- The child class will deprogram the FPGA, we just reset out device information
83+ The child class will deprogram the FPGA, we just reset out
84+ device information
8385 :return:
8486 """
8587 self .__reset_device_info ()
@@ -106,13 +108,14 @@ def __reset_device_info(self):
106108
107109 def test_connection (self ):
108110 """
109- Write to and read from the scratchpad to test the connection to the FPGA.
111+ Write to and read from the scratchpad to test the connection to the FPGA
110112 """
111113 for val in [0xa5a5a5 , 0x000000 ]:
112114 self .write_int ('sys_scratchpad' , val )
113115 rval = self .read_int ('sys_scratchpad' )
114116 if rval != val :
115- raise RuntimeError ('%s: cannot write scratchpad? %i != %i' % (self .host , rval , val ))
117+ raise RuntimeError ('%s: cannot write scratchpad? %i != %i' %
118+ (self .host , rval , val ))
116119 return True
117120
118121# def __getattribute__(self, name):
@@ -136,13 +139,13 @@ def read_dram(self, size, offset=0):
136139 last_dram_page = - 1
137140
138141 dram_indirect_page_size = (64 * 1024 * 1024 )
139- #read_chunk_size = (1024*1024)
142+ # read_chunk_size = (1024*1024)
140143 LOGGER .debug ('%s: reading a total of %8i bytes from offset %8i...' %
141144 (self .host , size , offset ))
142145 while n_reads < size :
143146 dram_page = (offset + n_reads ) / dram_indirect_page_size
144147 local_offset = (offset + n_reads ) % dram_indirect_page_size
145- #local_reads = min(read_chunk_size, size-n_reads, dram_indirect_page_size-(offset%dram_indirect_page_size))
148+ # local_reads = min(read_chunk_size, size-n_reads, dram_indirect_page_size-(offset%dram_indirect_page_size))
146149 local_reads = min (size - n_reads , dram_indirect_page_size - (offset % dram_indirect_page_size ))
147150 if last_dram_page != dram_page :
148151 self .write_int ('dram_controller' , dram_page )
@@ -201,12 +204,14 @@ def write(self, device_name, data, offset=0):
201204 if new_data != data :
202205 unpacked_wrdata = struct .unpack ('>L' , data [0 :4 ])[0 ]
203206 unpacked_rddata = struct .unpack ('>L' , new_data [0 :4 ])[0 ]
204- LOGGER .error ('%s: verification of write to %s at offset %d failed. Wrote 0x%08x... '
205- 'but got back 0x%08x...' % (self .host , device_name , offset ,
206- unpacked_wrdata , unpacked_rddata ))
207- raise ValueError ('%s: verification of write to %s at offset %d failed. Wrote 0x%08x... '
208- 'but got back 0x%08x...' % (self .host , device_name , offset ,
209- unpacked_wrdata , unpacked_rddata ))
207+ LOGGER .error ('%s: verification of write to %s at offset %d failed. '
208+ 'Wrote 0x%08x... but got back 0x%08x...' %
209+ (self .host , device_name , offset ,
210+ unpacked_wrdata , unpacked_rddata ))
211+ raise ValueError ('%s: verification of write to %s at offset %d '
212+ 'failed. Wrote 0x%08x... but got back 0x%08x...' %
213+ (self .host , device_name , offset ,
214+ unpacked_wrdata , unpacked_rddata ))
210215
211216 def read_int (self , device_name , word_offset = 0 ):
212217 """
@@ -242,52 +247,61 @@ def write_int(self, device_name, integer, blindwrite=False, word_offset=0):
242247 # careful of packing input data into 32 bit - check range: if
243248 # negative, must be signed int; if positive over 2^16, must be unsigned
244249 # int.
245- data = struct .pack ('>i' if integer < 0 else '>I' , integer )
250+ try :
251+ data = struct .pack ('>i' if integer < 0 else '>I' , integer )
252+ except Exception as ve :
253+ LOGGER .error ('Writing integer %i failed with error %s' % (
254+ integer , ve .message ))
255+ raise ValueError ('Writing integer %i failed with error %s' % (
256+ integer , ve .message ))
246257 if blindwrite :
247258 self .blindwrite (device_name , data , word_offset * 4 )
248259 else :
249260 self .write (device_name , data , word_offset * 4 )
250- LOGGER .debug ('%s: write_int %8x to register %s at word offset %d okay%s.' %
251- (self .host , integer , device_name ,
252- word_offset , ' (blind)' if blindwrite else '' ))
253-
254- def get_rcs (self , rcs_block_name = 'rcs' ):
255- """Retrieves and decodes a revision control block."""
256- raise NotImplementedError
257- rv = {'user' : self .read_uint (rcs_block_name + '_user' )}
258- app = self .read_uint (rcs_block_name + '_app' )
259- lib = self .read_uint (rcs_block_name + '_lib' )
260- if lib & (1 << 31 ):
261- rv ['compile_timestamp' ] = lib & ((2 ** 31 )- 1 )
262- else :
263- if lib & (1 << 30 ):
264- # type is svn
265- rv ['lib_rcs_type' ] = 'svn'
266- else :
267- # type is git
268- rv ['lib_rcs_type' ] = 'git'
269- if lib & (1 << 28 ):
270- # dirty bit
271- rv ['lib_dirty' ] = True
272- else :
273- rv ['lib_dirty' ] = False
274- rv ['lib_rev' ] = lib & ((2 ** 28 )- 1 )
275- if app & (1 << 31 ):
276- rv ['app_last_modified' ] = app & ((2 ** 31 )- 1 )
277- else :
278- if app & (1 << 30 ):
279- # type is svn
280- rv ['app_rcs_type' ] = 'svn'
281- else :
282- # type is git
283- rv ['app_rcs_type' ] = 'git'
284- if app & (1 << 28 ):
285- # dirty bit
286- rv ['app_dirty' ] = True
287- else :
288- rv ['lib_dirty' ] = False
289- rv ['app_rev' ] = app & ((2 ** 28 )- 1 )
290- return rv
261+ LOGGER .debug ('%s: write_int %8x to register %s at word offset %d '
262+ 'okay%s.' % (self .host , integer , device_name ,
263+ word_offset ,
264+ ' (blind)' if blindwrite else '' ))
265+
266+ # def get_rcs(self, rcs_block_name='rcs'):
267+ # """
268+ # Retrieves and decodes a revision control block.
269+ # """
270+ # raise NotImplementedError
271+ # rv = {'user': self.read_uint(rcs_block_name + '_user')}
272+ # app = self.read_uint(rcs_block_name+'_app')
273+ # lib = self.read_uint(rcs_block_name+'_lib')
274+ # if lib & (1 << 31):
275+ # rv['compile_timestamp'] = lib & ((2 ** 31)-1)
276+ # else:
277+ # if lib & (1 << 30):
278+ # # type is svn
279+ # rv['lib_rcs_type'] = 'svn'
280+ # else:
281+ # # type is git
282+ # rv['lib_rcs_type'] = 'git'
283+ # if lib & (1 << 28):
284+ # # dirty bit
285+ # rv['lib_dirty'] = True
286+ # else:
287+ # rv['lib_dirty'] = False
288+ # rv['lib_rev'] = lib & ((2 ** 28)-1)
289+ # if app & (1 << 31):
290+ # rv['app_last_modified'] = app & ((2 ** 31)-1)
291+ # else:
292+ # if app & (1 << 30):
293+ # # type is svn
294+ # rv['app_rcs_type'] = 'svn'
295+ # else:
296+ # # type is git
297+ # rv['app_rcs_type'] = 'git'
298+ # if app & (1 << 28):
299+ # # dirty bit
300+ # rv['app_dirty'] = True
301+ # else:
302+ # rv['lib_dirty'] = False
303+ # rv['app_rev'] = app & ((2 ** 28)-1)
304+ # return rv
291305
292306 def __create_memory_devices (self , device_dict , memorymap_dict ):
293307 """
0 commit comments