Mercurial > avr_jtag
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/py_avrjtag/cp_ping.py Sun Feb 22 12:54:45 2009 +0800 @@ -0,0 +1,47 @@ +import cmd_proto + +def cp_ping(seq, data): + cmd = cmd_proto.cmd(seq, cmd_proto.CPCMD_PING, data) + frame = cmd.to_frame() + return frame + +def get_reply(fo): + import fcntl, os + import time + + reply = '' + fcntl.fcntl(fo.fileno(), fcntl.F_SETFL, os.O_NONBLOCK) + while True: + try: + s = os.read(fo.fileno(), 256) + except OSError: + time.sleep(0.5) + try: + s = os.read(fo.fileno(), 256) + except OSError: + break + pass + reply = reply + s + pass + return reply + +if __name__ == '__main__': + import sys + + if len(sys.argv) != 2: + print >> sys.stderr, 'Usage: prog <port device>' + sys.exit(1) + pass + + port = sys.argv[1] + + fo = open(port, 'r+b') + cmd_str = cp_ping(0, 'hello') + fo.write(cmd_str) + fo.flush() + + frame = get_reply(fo) + cmd = cmd_proto.cmd() + cmd.from_frame(frame) + print repr(cmd) +