comparison py_avrjtag/cp_tditdo.py @ 4:6b1594fb668f

Improve performance of jtag.c and test it with Python scripts. - cp_tditdo.py send bits to TDI and hope it will feed back from TDO. - Expand loops in jtag.c to improve performance.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 22 Feb 2009 12:54:45 +0800
parents
children
comparison
equal deleted inserted replaced
3:e410832c3280 4:6b1594fb668f
1 import cmd_proto
2
3 def cp_tms(seq, nbits, data):
4 nbits_bytes = chr(nbits & 0xff) + chr(nbits >> 8)
5 cmd = cmd_proto.cmd(seq, cmd_proto.CPCMD_SHIFT_TDI_TDO,
6 nbits_bytes + data)
7 frame = cmd.to_frame()
8 return frame
9
10 def get_reply(fo):
11 import fcntl, os
12 import time
13
14 reply = ''
15 fcntl.fcntl(fo.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
16 while True:
17 try:
18 s = os.read(fo.fileno(), 256)
19 except OSError:
20 time.sleep(0.13)
21 try:
22 s = os.read(fo.fileno(), 256)
23 except OSError:
24 break
25 pass
26 reply = reply + s
27 pass
28 return reply
29
30 if __name__ == '__main__':
31 import sys
32
33 if len(sys.argv) != 2:
34 print >> sys.stderr, 'Usage: prog <port device>'
35 sys.exit(1)
36 pass
37
38 port = sys.argv[1]
39
40 fo = open(port, 'r+b')
41 cmd_str = cp_tms(12, 37, 'hello')
42 fo.write(cmd_str)
43 fo.flush()
44
45 frame = get_reply(fo)
46 cmd = cmd_proto.cmd()
47 r = cmd.from_frame(frame)
48 if r:
49 print 'frame error %s' % (repr(frame))
50 else:
51 print repr(cmd)
52 pass
53 pass
54