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