-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction.py
474 lines (397 loc) · 15.7 KB
/
Function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
##########################
#Script identification Function Script
##########################
#Author : Hen Lange
#Start Date : 27-3-2016
#Script change By : xxxx
########################################################################################################################
#################################
#Serial RS232 Configuration
#################################
def SerialConfig_1(COM , BAUD_RATE):
global ser
ser = serial.Serial()
ser.close()
ser.port = COM
ser.baudrate = BAUD_RATE
ser.bytesize = BYTE_SIZE
ser.parity = PARIT
ser.stopbits = STOP_BITS
ser.timeout = TIME_SERIAL
ser.open()
print 'ser = \n\n', ser
print '##################################'
print 'Function SerialConfig_1 load !!'
print '##################################'
def SerialConfig_2(COM , BAUD_RATE):
global ser_2
ser_2 = serial.Serial()
ser_2.close()
ser_2.port = COM
ser_2.baudrate = BAUD_RATE
ser_2.bytesize = BYTE_SIZE
ser_2.parity = PARIT
ser_2.stopbits = STOP_BITS
ser_2.timeout = TIME_SERIAL
ser.open()
print 'ser_2 = \n\n', ser_2
print ''
print 'Function SerialConfig_2 load !!'
print '##################################'
####################################################################################################################################
#SYNC withloaded
def Sync ():
D4_received_word = ''
timeout_start = time.time()
timeout = 10
while ((D4_received_word != "OK") and (time.time() < (timeout_start + timeout))):
ser.write(chr(0x0)+chr(0x0)+ chr(0x0)+ chr(0x0)+chr(0x0)+chr(0x0)+ chr(0x0)+ chr(0x0)
+chr(0x0)+chr(0x0)+ chr(0x0)+ chr(0x0)+chr(0x0)+chr(0x0)+ chr(0x0)+ chr(0x0)
+chr(0x0)+chr(0x0)+ chr(0x0)+ chr(0x0)+chr(0x0)+chr(0x0)+ chr(0x0)+ chr(0x0)
+chr(0x0)+chr(0x0)+ chr(0x0)+ chr(0x0)+chr(0x0)+chr(0x0)+ chr(0x0)+ chr(0x0))
D4_received_word = ser.read(2)
if D4_received_word == "OK":
time.sleep(0.1)
Boot_Complete=1
print "#################################"
print "D4_received_word = " ,D4_received_word
print "Got Sync"
Add_To_File("Got Sync")
Add_To_File("\n\n")
print "#################################"
else:
print "#################################"
print "D4_received_word = " ,D4_received_word
print "NO Sync\n"
Add_To_File("NO Sync")
Add_To_File("\n\n")
print "need Restart to the D6"
Add_To_File("need Restart to the D6")
print "#################################"
#log.write("No Sync\n")
time.sleep(0.5)
print ''
print 'Function Sync load !!'
print ''
####################################################################################################################################
#read APB Address
#################################
def read_apb_reg(addr):
print "#####read:"
print ("address: ",addr)
global apb_reg
#addr6="0x"+addr[6]+addr[7]
#addr4="0x"+addr[4]+addr[5]
#addr2="0x"+addr[2]+addr[3]
#addr0="0x"+addr[0]+addr[1]
#convert hexa value to ascii and divide to little indian
asciiaddr6=binascii.unhexlify(addr[6]+addr[7])
asciiaddr4=binascii.unhexlify(addr[4]+addr[5])
asciiaddr2=binascii.unhexlify(addr[2]+addr[3])
asciiaddr0=binascii.unhexlify(addr[0]+addr[1])
#read apb register- command to D4
ser.write(chr(0x5A)+chr(0x07)+asciiaddr6+asciiaddr4+asciiaddr2+asciiaddr0)
time.sleep(0.1)
reg=ser.read(6)
#convert ascii to hex value
apb_reg =binascii.hexlify(reg[5])+binascii.hexlify(reg[4])+binascii.hexlify(reg[3])+binascii.hexlify(reg[2])
print "#################################"
print "Read Address ", addr ,"return value", apb_reg
Add_To_File("Read Address ")
Add_To_File(addr)
Add_To_File(' ')
Add_To_File("return value ")
Add_To_File(apb_reg)
Add_To_File("\n\n")
print "#################################"
print ''
print 'Function read_apb_reg load !!'
print ''
#########################################################################################################################################################
#write APB Address
#################################
def write_apb_reg(addr,value):
print "#####write:"
#fill with zero for 8 bit word
if len(value)<8:
value = value.zfill(8)
if len(addr)<8:
addr = addr.zfill(8)
print ("address: ",addr, "value: ",value)
#convert hexa value to ascii and divide to little indian
asciivalue6=binascii.unhexlify(value[6]+value[7])
asciivalue4=binascii.unhexlify(value[4]+value[5])
asciivalue2=binascii.unhexlify(value[2]+value[3])
asciivalue0=binascii.unhexlify(value[0]+value[1])
#convert hexa value to ascii and divide to little indian
asciiaddr6=binascii.unhexlify(addr[6]+addr[7])
asciiaddr4=binascii.unhexlify(addr[4]+addr[5])
asciiaddr2=binascii.unhexlify(addr[2]+addr[3])
asciiaddr0=binascii.unhexlify(addr[0]+addr[1])
#write apb register- command to D4
ser.write(chr(0x5A)+chr(0x04)+asciiaddr6+asciiaddr4+asciiaddr2+asciiaddr0+asciivalue6+asciivalue4+asciivalue2+asciivalue0)
time.sleep(0.1)
print '#################################'
print "Write Address ", addr ,"with value", value
Add_To_File("Write Address ")
Add_To_File(addr)
Add_To_File(' ')
Add_To_File("with value ")
Add_To_File(value)
Add_To_File("\n\n")
print "#################################"
print ''
print 'Function write_apb_reg load !!'
print '##################################'
#########################################################################################################################################################
#checkSum
#################################
def checkSum():
# Check Checksum
ser.write(chr(0x5A))
ser.write(chr(0x0E))
## FW send echo + Checksum(4 bytes)
ser.flushInput()
ReadSerial = ser.read(8)
time.sleep(0.1)
ser.flushInput()
time.sleep(0.5)
print ''
print 'Function checkSum load !!'
print '##################################'
#########################################################################################################################################################
# create a new directory
#################################
def Make_Dir(Dir_Name):
if not os.path.exists(Dir_Name):
os.makedirs(Dir_Name)
def Open_log(Log_Name):
Make_Dir(Dir_Name) # call to the make dir function
global Current_File_Name
temp = Dir_Name + Log_Name
Current_File_Name = temp
print temp
openfile = open(temp , 'w')
openfile.write(Log_Name)
openfile.write("\n")
openfile.close()
#########################################################################################################################################################
# Add_To_File = Add content to the exists file
#################################
def Add_To_File(Add_Line):
f = open(Current_File_Name, 'a')
f.write(Add_Line)
#f.write("\n")
f.close()
#########################################################################################################################################################
# reset = set GPIO 10 low for reset purpose
#GPIO10 must be physically connected to reset button (SW1-pin 3)!!!!!!!!
#################################
def reset():
#GP_DIR_OUT configure GPIO10 to output
write_apb_reg("04000010","0400")
#GP_DATA_CLR configure GPIO10 to low (set to 0)
write_apb_reg("04000008","0400")
#########################################################################################################################################################
# clear_bit = clear the wanted bits in the register
#################################
def clear_bit(addr,bits_clr_hex):
if len(bits_clr_hex)<8:
bits_clr_hex = bits_clr_hex.zfill(8)
if len(addr)<8:
addr = addr.zfill(8)
print ("addr: ",addr,"clear value: ",bits_clr_hex)
#get current value and change it to binary
read_apb_reg(addr)
reg=int(apb_reg,16)
binReg=bin(reg).zfill(32)
print ("bin reg: ", binReg[2:])
#change the bits clear value from hex to binary
int_bits_clr=int(bits_clr_hex,16)
bin_bits_clr=bin(int_bits_clr).zfill(32)
print ("bin bits clr: ",bin_bits_clr[:])
#execute set by using (A and not(B)) operator between current value to the wanted bits to be set
fin_reg=0
int_fin_reg=0
int_fin_reg=(~(int_bits_clr) & reg)
bin_fin_reg=bin(int_fin_reg).zfill(32)
print ("bin final: ", bin_fin_reg[2:])
#change the value of the register, after set was done, to hex
hex_1=hex(int_fin_reg)
hex_2=hex_1[2:]
hex_fin_reg=hex_2[:8]
print ("hex final: ",hex_fin_reg)
#write the new value to the register
write_apb_reg(addr,hex_fin_reg)
#########################################################################################################################################################
# set_bit = set the wanted bits in the register
#################################
def set_bit(addr,bits_set_hex):
if len(bits_set_hex)<8:
bits_set_hex = bits_set_hex.zfill(8)
if len(addr)<8:
addr = addr.zfill(8)
print ("address: ",addr,"set value: ",bits_set_hex)
#get current value and change it to binary
read_apb_reg(addr)
reg=int(apb_reg,16)
binReg=bin(reg).zfill(32)
print ("bin reg: ", binReg[2:])
#change the bits_set value from hex to binary
int_bits_set=int(bits_set_hex,16)
bin_bits_set=bin(int_bits_set).zfill(32)
print ("bin bits set: ", bin_bits_set[:])
#execute set by using OR operator between current value to the wanted bits to be set
fin_reg=0
int_fin_reg=0
int_fin_reg=(int_bits_set | reg)
bin_fin_reg=bin(int_fin_reg).zfill(32)
print ("bin final: ", bin_fin_reg[2:])
#after set was done, change the value to hex before calling write_apb_reg function
hex_1=hex(int_fin_reg)
hex_2=hex_1[2:]
hex_fin_reg=hex_2[:8]
print ("hex final: ",hex_fin_reg)
#write the new value to the register
write_apb_reg(addr,hex_fin_reg)
# MEM_BIST = function run the BIST test
#################################
def MEM_BIST(test_name,write_val,status_reg,result_val,PLL,LDO):
read_apb_reg("0300004c")
write_apb_reg("0300004c","88025614")
read_apb_reg("0300004c")
write_apb_reg("030000ec","2100")
read_apb_reg("030000ec")
#print "D0"-BIST status register
read_apb_reg("030000d0")
#print "D4"-BIST status register
read_apb_reg("030000d4")
#print "CC"-BIST CNTRL register
read_apb_reg("030000cc")
#configure LDO supply
#input voltage (VCC) is 1.1V
if LDO=="0.9":
set_bit("0300003c","000f") #LC=15, LDO level in VDD =15
set_bit("0300003c","0010") #LDO enable
elif LDO=="bypass":
set_bit("03000044","1") #enable weak pull
clear_bit("0300003c","0010")#LDO disable
clear_bit("03000044","1") #disable weak pull
#configure PLL frequency and the UART new frequency
# if PLL=="25":
if PLL=="49":
write_apb_reg("03000084","80032b02")
write_apb_reg("03000008","8000000")
write_apb_reg("0300004c","88025614")
#uart 1418345
# SerialConfig_1('COM9' , 1418345)
read_apb_reg("03000000")
write_apb_reg("030000ec","2280")
write_apb_reg("0300004c","88025614")
write_apb_reg("03000000","fff")
write_apb_reg("03000004","5db00")
write_apb_reg("03000008","0")
#SerialConfig_1('COM9' , 754974)
#uart 754974
sync()
checkSum()
elif PLL=="73":
write_apb_reg("03000084","80032b02")
write_apb_reg("0300004c","88025614")
#uart 1418345
read_apb_reg("03000000")
write_apb_reg("030000ec","2280")
write_apb_reg("0300004c","88025614")
write_apb_reg("03000000","fff")
write_apb_reg("03000004","8c900")
write_apb_reg("03000008","0")
#uart 1132462
elif PLL=="86":
write_apb_reg("3000084","80032B02")
write_apb_reg("3000008","8000000")
write_apb_reg("300004c","88025614")
#uart 1418345
read_apb_reg("3000000")
write_apb_reg("30000ec","2280")
write_apb_reg("300004c","88025614")
write_apb_reg("3000000","fff")
write_apb_reg("3000004","a4000")
write_apb_reg("3000008","0")
#uart 1320000
elif PLL=="98":
write_apb_reg("3000084","80032B02")
write_apb_reg("3000008","8000000")
write_apb_reg("300004c","88025614")
#uart 1418345
read_apb_reg("3000000")
write_apb_reg("30000ec","2280")
write_apb_reg("300004c","88025614")
write_apb_reg("3000000","fff")
write_apb_reg("3000004","bb700")
elif PLL=="122":
write_apb_reg("3000084","80032B02")
write_apb_reg("3000008","8000000")
write_apb_reg("300004c","88025614")
#uart 1418345
read_apb_reg("3000000")
write_apb_reg("30000ec","2280")
write_apb_reg("300004c","88025614")
write_apb_reg("3000000","fff")
write_apb_reg("3000004","ea500")
write_apb_reg("3000008","0")
#uart 1870000
#added configuration for this two tests
print "#######",test_name,"#######"
if test_name=="HWVAD":
write_apb_reg("03000020","500")
time.sleep(0.5)
if test_name=="PTCM":
write_apb_reg("030000cc","c000")
time.sleep(0.5)
#configure MEM GROUP SELECT + ENABLE BIST
write_apb_reg("030000cc",write_val)
time.sleep(2)
#### Status Register Read
#for ROM test compare signature value
if test_name=="ROM":
ROM_sig="0110100000111101000001101100000010111100011011100000011111111111"
ROM_sig_LSB=ROM_sig[0:32]
ROM_sig_MSB=ROM_sig[32:64]
ROM_sig_LSB_addr="030000d8"
ROM_sig_MSB_addr="030000dc"
read_apb_reg("030000d8")
ROM_sig_LSB_read=apb_reg
reg=int(apb_reg,16)
ROM_sig_LSB_read=bin(reg).zfill(32)
print "LSB register -bin"
print ROM_sig_LSB_read[2:33]
read_apb_reg("030000dc")
reg=int(apb_reg,16)
ROM_sig_MSB_read=bin(reg).zfill(32)
print "MSB register -bin"
print ROM_sig_MSB_read[2:33]
if ((ROM_sig_LSB_read[2:33]==ROM_sig_LSB)&(ROM_sig_MSB_read[2:33]==ROM_sig_MSB)):
end_res=1
else:
end_res=0
else:
read_apb_reg(status_reg)
#show read status register in Binary 32bit
reg=int(apb_reg,16)
binReg=bin(reg).zfill(32)
print "status register -bin"
print binReg[2:33]
#show wanted result comparator in Binary 32bit
result=int(result_val,16)
print "comparator - bin"
print bin(result).zfill(32)
#show the result of comparison in Binary 32bit
end_res=0
end_res=reg & result
print "end result after comparing"
print bin(end_res).zfill(32)
#if the end-result 0 - pass, else - fail
if end_res > 0 :
print "fail"
else:
print "pass"