comparison py_avrjtag/cp_ping.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 tests/cp_ping.py@e410832c3280
children cc106f278d7d
comparison
equal deleted inserted replaced
3:e410832c3280 4:6b1594fb668f
1 import cmd_proto
2
3 def cp_ping(seq, data):
4 cmd = cmd_proto.cmd(seq, cmd_proto.CPCMD_PING, data)
5 frame = cmd.to_frame()
6 return frame
7
8 def get_reply(fo):
9 import fcntl, os
10 import time
11
12 reply = ''
13 fcntl.fcntl(fo.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
14 while True:
15 try:
16 s = os.read(fo.fileno(), 256)
17 except OSError:
18 time.sleep(0.5)
19 try:
20 s = os.read(fo.fileno(), 256)
21 except OSError:
22 break
23 pass
24 reply = reply + s
25 pass
26 return reply
27
28 if __name__ == '__main__':
29 import sys
30
31 if len(sys.argv) != 2:
32 print >> sys.stderr, 'Usage: prog <port device>'
33 sys.exit(1)
34 pass
35
36 port = sys.argv[1]
37
38 fo = open(port, 'r+b')
39 cmd_str = cp_ping(0, 'hello')
40 fo.write(cmd_str)
41 fo.flush()
42
43 frame = get_reply(fo)
44 cmd = cmd_proto.cmd()
45 cmd.from_frame(frame)
46 print repr(cmd)
47