1 |
2 |
sukhanov |
#!/usr/bin/python
|
2 |
|
|
# Wrapper for StaplPlayer
|
3 |
|
|
# Packs program arguments into a STAPL file stapl.stp and plays it using StaplPlayer
|
4 |
|
|
# Version 3 2014-10-21
|
5 |
|
|
|
6 |
|
|
import sys
|
7 |
|
|
|
8 |
|
|
#the following is needed only for -c option
|
9 |
|
|
import wiringpi2
|
10 |
|
|
|
11 |
|
|
if len(sys.argv) < 2:
|
12 |
|
|
print('No arguments\n Usage example : staplcmd i8 1 2 i10 deadface fe0dfe0f')
|
13 |
|
|
print('will do:\nIRSCAN $8; DRSCAN 32 $1; DRSCAN 32 $2;')
|
14 |
|
|
print('IRSCAN $10; DRSCAN 32 $deadface; DRSCAN 32 $fe0dfe0f;')
|
15 |
|
|
exit()
|
16 |
|
|
|
17 |
|
|
f = open('/run/shm/stapl.stp','w')
|
18 |
|
|
f.write('ACTION TRANS = DO_TRANS;\n')
|
19 |
|
|
f.write('DATA PARAMETERS;\n')
|
20 |
|
|
f.write('BOOLEAN idcode_data[32*10];\n')
|
21 |
|
|
f.write('BOOLEAN irdata[10*32];\n')
|
22 |
|
|
f.write('ENDDATA;\n')
|
23 |
|
|
|
24 |
|
|
f.write('PROCEDURE DO_TRANS USES PARAMETERS;\n')
|
25 |
|
|
splayer_option = ''
|
26 |
|
|
work_with_carrier = 0
|
27 |
|
|
|
28 |
|
|
for s in sys.argv[1:]:
|
29 |
|
|
if s == '-g': #use second JTAG chain
|
30 |
|
|
splayer_option = '-g'
|
31 |
|
|
continue
|
32 |
|
|
if s == '-c': # set the path to work with carrier boards
|
33 |
|
|
import wiringpi2
|
34 |
|
|
wiringpi2.wiringPiSetupSys()
|
35 |
|
|
work_with_carrier = 8 # GPIO for the carrier select[0] line in RPiLVDS board
|
36 |
|
|
continue
|
37 |
|
|
if s[0] == 'i':
|
38 |
|
|
f.write('IRSCAN 8, $' + s[1:] + ', CAPTURE irdata[7..0];\n')
|
39 |
|
|
else:
|
40 |
|
|
f.write('DRSCAN 32, $' + s.rjust(8,'0') + ', CAPTURE idcode_data[31..0];\n')
|
41 |
|
|
f.write('EXPORT "Shifted Out:", idcode_data[31..0];\n')
|
42 |
|
|
f.write('ENDPROC;\n')
|
43 |
|
|
f.close()
|
44 |
|
|
|
45 |
|
|
if (work_with_carrier != 0): # set route to carrier board
|
46 |
|
|
if (splayer_option == '-g'):
|
47 |
|
|
work_with_carrier = 7 # GPIO for the carrier select[1] line in RPiLVDS board
|
48 |
|
|
wiringpi2.pinMode(work_with_carrier,1)
|
49 |
|
|
print('Executing wiringpi2.digitalWrite('+str(work_with_carrier)+',1)')
|
50 |
|
|
wiringpi2.digitalWrite(work_with_carrier,1)
|
51 |
|
|
if wiringpi2.digitalRead(work_with_carrier) != 1 :
|
52 |
|
|
print('ERROR JTAG path through FEM using GPIO pin ' + str(work_with_carrier) + ' was not established')
|
53 |
|
|
print('Did you forget "gpio export '+ str(work_with_carrier) + ' out" after reboot?')
|
54 |
|
|
exit(1)
|
55 |
|
|
|
56 |
|
|
#print("Stapl instructions:\n")
|
57 |
|
|
#f = open('stapl.stp','r')
|
58 |
|
|
#for s in f:
|
59 |
|
|
# print(s),
|
60 |
|
|
#f.close()
|
61 |
|
|
|
62 |
|
|
# execute action
|
63 |
|
|
import subprocess
|
64 |
|
|
cmdline = 'StaplPlayer ' + splayer_option + ' -aTRANS /run/shm/stapl.stp'
|
65 |
|
|
#print('Executing:'+cmdline)
|
66 |
|
|
|
67 |
|
|
p = subprocess.Popen(cmdline, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
68 |
|
|
for line in p.stdout.readlines():
|
69 |
|
|
print line,
|
70 |
|
|
retval = p.wait()
|
71 |
|
|
|
72 |
|
|
if (work_with_carrier != 0):
|
73 |
|
|
print('Executing wiringpi2.digitalWrite('+str(work_with_carrier)+',0)')
|
74 |
|
|
wiringpi2.digitalWrite(work_with_carrier,0)
|
75 |
|
|
if wiringpi2.digitalRead(work_with_carrier) != 0 :
|
76 |
|
|
print('ERROR JTAG path through FEM using GPIO pin ' + str(work_with_carrier) + ' was not closed')
|
77 |
|
|
|
78 |
|
|
|