-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsi_test.py
2607 lines (2372 loc) · 90.9 KB
/
si_test.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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import argparse
import importlib
import json
from caravel import Dio, Test
from io_config import Device, device, connect_devices, UART, SPI
import os
import csv
import time
import datetime
import subprocess
import signal
import sys
from rich.table import Table
from WF_SDK import logic, wavegen, static, scope
import matplotlib.pyplot as plt
import numpy as np
def init_ad_ios(device1_data, device2_data, device3_data):
"""
Initialize the DIO maps for three devices and return them as a tuple.
Args:
device1_data: Data for device 1
device2_data: Data for device 2
device3_data: Data for device 3
Returns:
Tuple: Three DIO maps for device 1, device 2, and device 3
"""
device1_dio_map = {
# "rstb": Dio(0, device1_data, True),
"rstb": Dio(0, device1_data),
"gpio_mgmt": Dio(1, device1_data),
0: Dio(2, device1_data),
1: Dio(3, device1_data),
2: Dio(4, device1_data),
3: Dio(5, device1_data),
4: Dio(6, device1_data),
5: Dio(7, device1_data),
6: Dio(8, device1_data),
7: Dio(9, device1_data),
8: Dio(10, device1_data),
9: Dio(11, device1_data),
10: Dio(12, device1_data),
11: Dio(13, device1_data),
12: Dio(14, device1_data),
13: Dio(15, device1_data),
}
device2_dio_map = {
22: Dio(0, device2_data),
23: Dio(1, device2_data),
24: Dio(2, device2_data),
25: Dio(3, device2_data),
26: Dio(4, device2_data),
27: Dio(5, device2_data),
28: Dio(6, device2_data),
29: Dio(7, device2_data),
30: Dio(8, device2_data),
31: Dio(9, device2_data),
32: Dio(10, device2_data),
33: Dio(11, device2_data),
34: Dio(12, device2_data),
35: Dio(13, device2_data),
36: Dio(14, device2_data),
37: Dio(15, device2_data),
}
device3_dio_map = {
14: Dio(2, device3_data),
15: Dio(3, device3_data),
16: Dio(4, device3_data),
17: Dio(5, device3_data),
18: Dio(6, device3_data),
19: Dio(7, device3_data),
20: Dio(8, device3_data),
21: Dio(9, device3_data),
}
return device1_dio_map, device2_dio_map, device3_dio_map
def process_mgmt_gpio(test, verbose):
"""
Process the management of GPIO, running various tests and returning the status of each test.
Args:
test: The test object used to run the tests.
verbose: A boolean indicating whether to print detailed logs.
Returns:
A list of tuples containing the test name and a boolean indicating the test status.
"""
test_names = ["send_packet", "receive_packet", "uart_io"]
status = []
counter = 0
for name in test_names:
test.test_name = name
if test.test_name == "receive_packet":
io = test.device1v8.dio_map[0]
pulse_count = test.receive_packet(25)
if pulse_count == 2:
test.print_and_log(f"Running test {test.test_name}...")
for i in range(5, 8):
while not io.get_value():
pass
test.send_packet(i, 1)
while io.get_value():
pass
pulse_count = test.receive_packet(25)
if pulse_count == i:
counter += 1
else:
test.print_and_log("[red]failed")
status.append((test.test_name, False))
if counter == 3:
test.print_and_log("[green]passed")
status.append((test.test_name, True))
else:
test.print_and_log("[red]failed")
status.append((test.test_name, False))
elif name == "uart_io":
pulse_count = test.receive_packet(25)
if pulse_count == 2:
test.print_and_log(f"Running test {test.test_name}...")
received = test.io_receive(4, 6)
if not received:
test.print_and_log("[red]failed")
status.append((test.test_name, False))
else:
if verbose:
test.print_and_log("IO[6] Passed")
pulse_count = test.receive_packet(25)
if pulse_count == 3:
if verbose:
test.print_and_log("Send 4 packets to IO[5]")
time.sleep(5)
test.send_pulse(4, 5, 5)
ack_pulse = test.receive_packet(25)
if ack_pulse == 9:
test.print_and_log("[red]failed")
status.append((test.test_name, False))
elif ack_pulse == 4:
test.print_and_log("[green]passed")
status.append((test.test_name, True))
else:
phase = 0
test.print_and_log(f"Running test {test.test_name}...")
for passing in [8]:
pulse_count = test.receive_packet(25)
if pulse_count == passing:
if verbose:
test.print_and_log(f"pass phase {phase}")
phase = phase + 1
if pulse_count == 9:
test.print_and_log("[red]failed")
status.append((test.test_name, False))
if len([8]) == phase:
test.print_and_log("[green]passed")
status.append((test.test_name, True))
return status
def process_uart(test, uart, verbose):
"""Function to test all UART functionality
First test: IO[5] as input to caravel and IO[6] as output from caravel
Second test: UART as output from caravel
Third test: UART as input to caravel
Fourth test: UART loopback (tests both input and output)
"""
test_names = ["uart", "uart_reception", "uart_loopback", "IRQ_uart_rx"]
status = []
for name in test_names:
test.test_name = name
pulse_count = test.receive_packet(25)
if pulse_count == 1:
if verbose:
test.print_and_log(f"Start Test: {name}")
if test.test_name == "uart":
pulse_count = test.receive_packet(25)
if pulse_count == 2:
test.print_and_log(f"Running test {test.test_name}...")
uart_data = uart.read_data(test)
uart_data = uart_data.decode("utf-8", "ignore")
if "UART Timeout!" in uart_data:
test.print_and_log("[red]UART Timeout!")
status.append((test.test_name, False))
if "Monitor: Test UART passed" in uart_data:
test.print_and_log("[green]passed")
status.append((test.test_name, True))
else:
test.print_and_log("[red]failed")
status.append((test.test_name, False))
pulse_count = test.receive_packet(25)
if pulse_count == 5:
if verbose:
test.print_and_log("end UART transmission")
elif test.test_name == "uart_reception":
passed = True
pulse_count = test.receive_packet(25)
if pulse_count == 2:
test.print_and_log(f"Running test {test.test_name}...")
uart.open()
timeout = time.time() + 50
for i in ["M", "B", "A"]:
pulse_count = test.receive_packet(25)
if pulse_count == 4:
uart.write(i)
pulse_count = test.receive_packet(25)
if pulse_count == 6:
passed = True
if verbose:
test.print_and_log(f"Received {i} successfully")
if pulse_count == 9:
test.print_and_log("[red]failed")
uart.close()
passed = False
status.append((test.test_name, False))
break
if time.time() > timeout:
test.print_and_log("[red]UART Timeout!")
uart.close()
passed = False
status.append((test.test_name, False))
break
if passed:
test.print_and_log("[green]passed")
status.append((test.test_name, True))
elif test.test_name == "uart_loopback":
passed = True
uart.open()
timeout = time.time() + 50
test.print_and_log(f"Running test {test.test_name}...")
for i in range(0, 5):
while time.time() < timeout:
uart_data, count = uart.read_uart()
if uart_data:
uart_data[count.value] = 0
dat = uart_data.value.decode("utf-8", "ignore")
uart.write(dat)
pulse_count = test.receive_packet(25)
if pulse_count == 6:
passed = True
if verbose:
test.print_and_log(f"sent {dat} successfully")
break
if pulse_count == 9:
test.print_and_log("[red]failed")
uart.close()
status.append((test.test_name, False))
break
if passed:
test.print_and_log("[green]passed")
status.append((test.test_name, True))
elif test.test_name == "IRQ_uart_rx":
pulse_count = test.receive_packet(25)
if pulse_count == 2:
test.print_and_log(f"Running test {test.test_name}...")
uart.open()
uart.write("I")
pulse_count = test.receive_packet(25)
if pulse_count == 5:
test.print_and_log("[green]passed")
status.append((test.test_name, True))
break
if pulse_count == 9:
test.print_and_log("[red]failed")
uart.close()
status.append((test.test_name, False))
return status
def process_soc(test, uart):
"""
Process SOC function to control GPIO and UART, read UART data, and handle different test cases.
This is the default test function.
Parameters:
- test: An object representing the test environment
- uart: An object representing the UART communication
Returns:
- status: A list of tuples containing the test name and its corresponding status (True or False)
"""
status = []
test.gpio_mgmt.set_state(True)
test.gpio_mgmt.set_value(0)
while True:
uart_data = uart.read_data(test)
uart_data = uart_data.decode("utf-8", "ignore")
if "UART Timeout!" in uart_data:
test.print_and_log("[red]UART Timeout!")
status.append((test.test_name, False))
break
if "Start Test:" in uart_data:
test.test_name = uart_data.strip().split(": ")[1]
test.print_and_log(f"Running test {test.test_name}...")
elif "End Test" in uart_data:
test.print_and_log("End Test")
break
if test.test_name == "IRQ_external" or test.test_name == "IRQ_external2":
if test.test_name == "IRQ_external":
channel = 7
else:
channel = 12
channel = test.device1v8.dio_map[channel]
channel.set_state(True)
channel.set_value(1)
elif test.test_name == "IRQ_uart_rx":
uart.open()
uart.write("I")
uart_data = uart.read_data(test)
uart_data = uart_data.decode("utf-8", "ignore")
if "UART Timeout!" in uart_data:
test.print_and_log("[red]UART Timeout!")
status.append((test.test_name, False))
break
if "passed" in uart_data:
test.print_and_log("[green]passed")
status.append((test.test_name, True))
elif "failed" in uart_data:
test.print_and_log("[red]failed")
status.append((test.test_name, False))
return status
def hk_stop(close):
"""
A function stops the housekeeping from interrupting the test.
"""
global pid
if not close:
# test.print_and_log("running caravel_hkstop.py...")
p = subprocess.Popen(
["python3", "silicon_tests/util/caravel_hkstop.py"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
pid = p.pid
# test.print_and_log("subprocess pid:", pid)
elif pid:
# test.print_and_log("stopping caravel_hkstop.py...")
os.kill(pid, signal.SIGTERM)
pid = None
def process_io(test, uart, verbose, analog, dft):
"""
Function that tests the GPIO Input and Output.
Args:
test: The test object for GPIO management.
uart: The UART object for communication.
verbose: A boolean indicating whether to print verbose output.
Returns:
A tuple containing a boolean indicating success or failure, and a list of failed channels if any.
"""
test.gpio_mgmt.set_state(True)
test.gpio_mgmt.set_value(0)
hk_stop(False)
fail = []
uart_data = uart.read_data(test)
uart_data = uart_data.decode("utf-8", "ignore")
if "UART Timeout!" in uart_data:
test.print_and_log("[red]UART Timeout!")
return False, None
if "Start Test:" in uart_data:
test.test_name = uart_data.strip().split(": ")[1]
test.print_and_log(f"Running test {test.test_name}...")
for i in range(38):
if i == 5 or i == 6:
pass
elif dft and 26 < i < 32:
pass
else:
io_pulse = 0
uart.write("g: " + str(i) + "\n")
channel = i
if channel > 4:
hk_stop(True)
if test.test_name == "gpio_o" or test.test_name == "bitbang_o":
if channel > 13 and channel < 22:
io = test.deviced.dio_map[channel]
elif channel > 21:
io = test.device3v3.dio_map[channel]
else:
io = test.device1v8.dio_map[channel]
if analog and channel > 13 and channel < 25:
pass
else:
if verbose:
test.print_and_log(f"IO[{channel}]")
timeout = time.time() + 5
state = "LOW"
while 1:
uart_data = uart.read_data(test, 5)
if b"UART Timeout!" in uart_data:
test.print_and_log(
f"[red]Timeout failure on IO[{channel}]!"
)
fail.append(channel)
break
# uart_data = uart_data.decode('utf-8', 'ignore')
if b"d" in uart_data and state == "HI":
if not io.get_value():
state = "LOW"
io_pulse += 1
if b"u" in uart_data and state == "LOW":
if io.get_value():
state = "HI"
io_pulse += 1
if io_pulse == 4:
io_pulse = 0
if verbose:
test.print_and_log(f"[green]IO[{channel}] Passed")
break
if time.time() > timeout:
test.print_and_log(
f"[red]Timeout failure on IO[{channel}]!"
)
fail.append(channel)
break
elif test.test_name == "gpio_i" or test.test_name == "bitbang_i":
if verbose:
test.print_and_log(f"IO[{channel}]")
test.send_pulse(4, channel, 1)
uart_data = uart.read_data(test, 5)
if b"UART Timeout!" in uart_data:
test.print_and_log("[red]UART Timeout!")
fail.append(channel)
if b"p" in uart_data:
if verbose:
test.print_and_log(f"[green]IO[{channel}] Passed")
elif b"f" in uart_data:
test.print_and_log(f"[red]IO[{channel}] Failed")
fail.append(channel)
hk_stop(True)
test.gpio_mgmt.set_state(True)
test.gpio_mgmt.set_value(1)
time.sleep(1)
if len(fail) == 0:
test.print_and_log("[green]passed")
return True, None
else:
test.print_and_log("[red]failed")
return False, fail
def process_io_plud(test, uart, analog, dft):
"""
Process IO polarity test function to handle IO operations and test results.
Args:
test: The test object containing GPIO management and test information.
uart: The UART object for reading data.
Returns:
bool: True if the test passed, False if it failed.
"""
p1_rt = False
p2_rt = False
uart_data = uart.read_data(test)
uart_data = uart_data.decode("utf-8", "ignore")
if "UART Timeout!" in uart_data:
test.print_and_log("[red]UART Timeout!")
return False, None
if "Start Test:" in uart_data:
test.test_name = uart_data.strip().split(": ")[1]
test.print_and_log(f"Running test {test.test_name}...")
# uart_data = uart.read_data(test)
# uart_data = uart_data.decode('utf-8', 'ignore')
# if "Start Test:" in uart_data:
# test.test_name = uart_data.strip().split(": ")[1]
# test.print_and_log(f"Running test {test.test_name}...")
if test.test_name == "gpio_lpu_ho":
default_val = 1
default_val_n = 0
p1_rt = run_io_plud(default_val, default_val_n, False, analog, dft)
p2_rt = run_io_plud(default_val, default_val_n, True, analog, dft)
elif test.test_name == "gpio_lpd_ho":
default_val = 0
default_val_n = 1
p1_rt = run_io_plud(default_val, default_val_n, False, analog, dft)
p2_rt = run_io_plud(default_val, default_val_n, True, analog, dft)
elif test.test_name == "gpio_lo_hpu":
default_val = 1
default_val_n = 0
p1_rt = run_io_plud_h(default_val, default_val_n, False, analog, dft)
p2_rt = run_io_plud_h(default_val, default_val_n, True, analog, dft)
elif test.test_name == "gpio_lo_hpd":
default_val = 0
default_val_n = 1
p1_rt = run_io_plud_h(default_val, default_val_n, False, analog, dft)
p2_rt = run_io_plud_h(default_val, default_val_n, True, analog, dft)
test.gpio_mgmt.set_state(True)
test.gpio_mgmt.set_value(1)
if p1_rt and p2_rt:
test.print_and_log("[green]passed")
return True
else:
test.print_and_log("[red]failed")
return False
def run_io_plud(default_val, default_val_n, first_itter, analog, dft):
"""
A function to run the IO_PLUD test.
Args:
- default_val: the default value
- default_val_n: the default value for N
- first_itter: a flag indicating if it's the first iteration
Returns:
- True if the test passes, False otherwise
"""
test_counter = 0
flag = False
hk_stop(False)
for channel in range(0, 38):
if channel - 19 == 5 or channel - 19 == 6:
continue
if channel > 13 and channel < 22:
io = test.deviced.dio_map[channel]
elif channel > 21:
io = test.device3v3.dio_map[channel]
else:
io = test.device1v8.dio_map[channel]
if channel < 19 and first_itter:
io.set_state(True)
io.set_value(default_val_n)
elif channel < 19:
io.set_state(False)
elif first_itter:
if not flag:
time.sleep(1)
flag = True
io_state = io.get_value()
if io_state == default_val_n:
test_counter += 1
elif analog and channel > 13 and channel < 25:
test_counter += 1
elif dft and 26 < channel < 32:
test_counter += 1
else:
test.print_and_log(f"[red]channel {channel-19} FAILED!")
else:
if not flag:
time.sleep(1)
flag = True
io_state = io.get_value()
if io_state == default_val:
test_counter += 1
elif analog and channel > 13 and channel < 25:
test_counter += 1
elif dft and 26 < channel < 32:
test_counter += 1
else:
test.print_and_log(f"[red]channel {channel-19} FAILED!")
hk_stop(True)
if test_counter >= 17:
# test.print_and_log(
# f"[green]{test.test_name} test passed"
# )
return True
else:
return False
def run_io_plud_h(default_val, default_val_n, first_itter, analog, dft):
"""
Function to run a series of IO operations based on specified conditions.
Parameters:
- default_val: the default value for IO operations
- default_val_n: the default value for IO operations when first_itter is true
- first_itter: a boolean flag indicating if it's the first iteration
Returns:
- True if the test passed, False if it failed
"""
test_counter = 0
flag = False
hk_stop(False)
for channel in range(37, -1, -1):
if channel == 5 or channel == 6:
continue
if channel > 13 and channel < 22:
io = test.deviced.dio_map[channel]
elif channel > 21:
io = test.device3v3.dio_map[channel]
else:
io = test.device1v8.dio_map[channel]
if channel > 18 and first_itter:
io.set_state(True)
io.set_value(default_val_n)
elif channel > 18:
io.set_state(False)
elif first_itter:
if not flag:
time.sleep(1)
flag = True
io_state = io.get_value()
if io_state == default_val_n:
test_counter += 1
elif analog and channel > 13 and channel < 25:
test_counter += 1
elif dft and (26-19) < channel < (32-19):
test_counter += 1
else:
test.print_and_log(f"[red]channel {channel+19} FAILED!")
else:
if not flag:
time.sleep(1)
flag = True
io_state = io.get_value()
if io_state == default_val:
test_counter += 1
elif analog and channel > 13 and channel < 25:
test_counter += 1
elif dft and (26-19) < channel < (32-19):
test_counter += 1
else:
test.print_and_log(f"[red]channel {channel+19} FAILED!")
hk_stop(True)
if test_counter >= 17:
# test.print_and_log(
# f"[green]{test.test_name} test Passed"
# )
return True
else:
return False
def concat_csv(root_directory, file_name):
"""
Concatenates CSV files from a specified run directory into a single output file.
Args:
root_directory (str): The run directory containing the CSV files to be concatenated.
file_name (str): The name of the CSV file to be concatenated.
Returns:
None
"""
# Initialize a flag to track whether the header has been written
header_written = False
# Open the output file in write mode
with open(
f"{root_directory}/concatenated_{file_name}.csv", "w", newline=""
) as outfile:
writer = csv.writer(outfile)
# Traverse the directory tree
for dirpath, dirnames, filenames in os.walk(root_directory):
# Loop through each file
for filename in filenames:
if filename == f"{file_name}.csv":
filepath = os.path.join(dirpath, filename)
with open(filepath, "r", newline="") as infile:
reader = csv.reader(infile)
# Skip header except for the first file
if not header_written:
header_written = True
else:
next(reader) # Skip the header
# Write rows to the output file
writer.writerows(reader)
def flash_test(
test,
hex_file,
flash_flag,
uart,
uart_data,
mgmt_gpio,
io,
plud,
flash_only,
verbose,
analog,
dft,
and_flag,
chain,
fpga_io,
alu,
sec_count,
fpga_ram,
ana,
):
"""
A function to perform flash testing with various parameters and return the results.
Args:
test: The test object
hex_file: The hex file to be flashed
flash_flag: Flag to indicate if flashing is required
uart: Flag to indicate if UART is required
uart_data: Data for UART
mgmt_gpio: Flag to indicate if management GPIO is required
io: Flag to indicate if IO is required
plud: Flag to indicate if PLUD is required
flash_only: Flag to indicate if only flash is required
verbose: Flag to indicate if verbose output is required
Returns:
The results of the flash test or a boolean value
"""
if flash_only:
run_only = False
else:
run_only = True
# test.reset_devices()
# test.reset()
if flash_flag or flash_only:
test.print_and_log(
"=============================================================================="
)
test.print_and_log(
f" Flashing : {test.test_name} : {datetime.datetime.now()} | Analog : {analog}"
)
test.print_and_log(
"=============================================================================="
)
test.progress.update(
test.task,
description=f"Flashing {test.test_name}",
)
test.power_down()
test.apply_reset()
test.power_up_1v8()
test.flash(hex_file)
test.power_down()
test.release_reset()
else:
test.power_down()
test.device1v8.supply.set_voltage(test.l_voltage)
test.device3v3.supply.set_voltage(test.h_voltage)
test.power_up()
test.reset()
test.print_and_log(
"=============================================================================="
)
test.print_and_log(
f" Running : {test.test_name} : {datetime.datetime.now()} | Analog : {analog}"
)
test.print_and_log(
"=============================================================================="
)
results = None
if run_only:
test.progress.update(
test.task,
advance=1,
description=f"Running {test.test_name} on low voltage {test.l_voltage}v and high voltage {test.h_voltage}v",
visible=True,
)
if uart:
results = process_uart(test, uart_data, verbose)
elif mgmt_gpio:
results = process_mgmt_gpio(test, verbose)
elif io:
results = process_io(test, uart_data, verbose, analog, dft)
elif plud:
results = process_io_plud(test, uart_data, analog, dft)
elif and_flag:
results = and_test(test, uart_data)
elif chain:
results = chain_test(test, uart_data)
elif fpga_io:
results = fpga_io_test(test, uart_data)
elif alu:
results = fpga_ALU_test(test, uart_data)
elif sec_count:
results = fpga_counter_test(test, uart_data)
elif fpga_ram:
results = fpga_ram_test(test)
elif ana:
results = adc_test(test, uart_data, verbose)
else:
results = process_soc(test, uart_data)
return results
else:
return True
def reformat_csv(test, temp=None):
"""
Read the original CSV file, create a new CSV file with the desired format, and write the reformatted data to the new CSV file.
Parameters:
test: The test object containing the date directory.
temp: The temperature value (optional).
"""
# Read the original CSV file
with open(f"{test.date_dir}/results.csv", "r") as file:
reader = csv.reader(file)
data = list(reader)
ran_tests = []
for d in data:
if d[0] != "Test_name" and d[0] not in ran_tests:
ran_tests.append(d[0])
voltage_combinations = []
for d in data:
if d[0] != "Test_name":
if [d[1], d[2]] not in voltage_combinations:
voltage_combinations.append([d[1], d[2]])
# Create a new CSV file with the desired format
with open(f"{test.date_dir}/formatted_results.csv", "w", newline="") as file:
writer = csv.writer(file)
if temp:
header_row = ["Temp (C)", temp]
else:
header_row = ["Temp (C)", "N/A"]
writer.writerow(header_row)
header_row = ["VCCD (v)"]
for v in voltage_combinations:
header_row.append(v[0])
writer.writerow(header_row)
header_row = ["VDDIO (v)"]
for v in voltage_combinations:
header_row.append(v[1])
writer.writerow(header_row)
for t in ran_tests:
header_row = [t]
for d in data:
if d[0] != "Test_name" and d[0] == t:
header_row.append(d[3])
writer.writerow(header_row)
def config_fpga(test):
"""
Configures the FPGA by setting the state and value of various pins. Returns the states and values of the configured pins.
"""
prog_clk = test.device3v3.dio_map[37]
prog_rst = test.device3v3.dio_map[29]
io_isol_n = test.device1v8.dio_map[1]
op_rst = test.device1v8.dio_map[11]
ccff_head = test.device3v3.dio_map[34]
ccff_tail = test.device3v3.dio_map[23]
clk_sel = test.device3v3.dio_map[35]
prog_clk.set_state(True)
prog_rst.set_state(True)
io_isol_n.set_state(True)
ccff_head.set_state(True)
clk_sel.set_state(True)
op_rst.set_state(True)
ccff_tail.set_state(False)
prog_rst.set_value(0)
prog_clk.set_value(0)
clk_sel.set_value(0)
io_isol_n.set_value(0)
ccff_head.set_value(0)
op_rst.set_value(0)
return prog_clk, prog_rst, io_isol_n, op_rst, ccff_head, ccff_tail, clk_sel
def program_fpga(test, prog_clk, prog_rst, ccff_head, binary_array):
"""
Program the FPGA using the provided test, programming clock, programming reset, ccff head, and binary array.
"""
test.print_and_log("Programming FPGA...")
prog_rst.set_value(1)
time.sleep(0.1)
for i in binary_array:
ccff_head.set_value(i)
prog_clk.set_value(1)
prog_clk.set_value(0)
prog_clk.set_value(0)
def load_bitstream(bitstream):
"""
Load a bitstream from the specified file path and return it as a binary array.
Parameters:
bitstream (str): The name of the bitstream file to load.
Returns:
list: The binary array representing the loaded bitstream.
"""
file_path = f"{os.path.dirname(os.path.realpath(__file__))}/silicon_tests/clear/bit_streams/{bitstream}.bit"
binary_array = []
with open(file_path, "r") as file:
# Skip lines until reaching the binary data
for line in file:
if line.startswith("//"):
continue
else:
# Remove any leading/trailing whitespace and append the binary values
binary_array.extend([int(bit) for bit in line.strip()])
return binary_array
def chain_test(test, uart):
"""
Function to perform chain test using UART communication and FPGA programming.
Args:
- test: Test object containing GPIO management and UART communication methods.
- uart: UART object for reading data from the test.
Returns:
- bool: True if the chain test passed, False otherwise.
"""
test.gpio_mgmt.set_state(True)
test.gpio_mgmt.set_value(0)
uart_data = uart.read_data(test)
uart_data = uart_data.decode("utf-8", "ignore")
if "UART Timeout!" in uart_data:
test.print_and_log("[red]UART Timeout!")
return False
if "ST:" in uart_data:
test.test_name = uart_data.strip().split(": ")[1]
test.print_and_log(f"Running test {test.test_name}...")
prog_clk, prog_rst, io_isol_n, op_rst, ccff_head, ccff_tail, clk_sel = config_fpga(
test
)
binary_array = load_bitstream("and_3")
program_fpga(test, prog_clk, prog_rst, ccff_head, binary_array)
tail_value = []
test.print_and_log("Reading data from chain tail")
# time.sleep(0.1)
for i in binary_array:
chain_value = ccff_tail.get_value()
if chain_value:
chain_value = 1
else:
chain_value = 0
tail_value.append(chain_value)
prog_clk.set_value(1)
prog_clk.set_value(0)
if tail_value == binary_array:
test.print_and_log("[green]Chain test passed")
return True
else:
with open(f"bin_arr_and3.json", "w") as file:
# Dump the array into the file using json.dump
json.dump(binary_array, file)
with open(f"tail_arr_and3.json", "w") as file:
# Dump the array into the file using json.dump
json.dump(tail_value, file)
test.print_and_log("[red]Chain test failed")
return False
def ALU_4bits(operand_A_bits, operand_B_bits, operation_bits, operand_a, operand_b):
"""
Perform the 4-bit ALU operation using the given operand bits and operation bits.
Parameters:
- operand_A_bits: list of 4 bits representing operand A
- operand_B_bits: list of 4 bits representing operand B
- operation_bits: list of bits representing the operation
- operand_a: list of indices for setting operand A bits
- operand_b: list of indices for setting operand B bits
"""
for i in range(4):
bit_A = operand_A_bits[i]
test.device1v8.dio_map[operand_a[i]].set_value(bit_A)
# time.sleep(0.1)
bit_B = operand_B_bits[i]
test.device1v8.dio_map[operand_b[i]].set_value(bit_B)
# time.sleep(0.1)
def config_alu(test, arr, dir):
"""
Configures the ALU based on the input test, array, and direction.
Parameters:
test (obj): The test object containing device information.
arr (list): The array of values to iterate through.