Skip to content
Browse files

added interface implementation in python.

  • Loading branch information...
1 parent 45e8480 commit 0de3f319c7a004f3d53b8b3f1c766415484f4dca @balau committed
Showing with 88 additions and 3 deletions.
  1. +88 −3 test/jtagduino.py
View
91 test/jtagduino.py
@@ -82,16 +82,27 @@ def fw_ver(self):
return (fw_ver_major, fw_ver_minor)
else:
return None
+ def set_serial_speed(self, baud):
+ self.ser.write(chr(jtagduino_cmd.CMD_SET_SERIAL_SPEED))
+ self.ser.write(chr((baud >> 0) & 0xFF))
+ self.ser.write(chr((baud >> 8) & 0xFF))
+ self.ser.write(chr((baud >> 16) & 0xFF))
+ self.ser.write(chr((baud >> 24) & 0xFF))
+ rsp = ord(self.ser.read(1))
+ if (rsp == jtagduino_rsp.RSP_OK):
+ time.sleep(0.027) #time to switch baud rate for device, worst case.
+ self.ser.baudrate = baud
+ return rsp
def set_pin(self, pin):
self.ser.write(chr(jtagduino_cmd.CMD_SET_PIN))
self.ser.write(chr(pin))
rsp = ord(self.ser.read(1))
- return rsp;
+ return rsp
def clear_pin(self, pin):
self.ser.write(chr(jtagduino_cmd.CMD_CLEAR_PIN))
self.ser.write(chr(pin))
rsp = ord(self.ser.read(1))
- return rsp;
+ return rsp
def get_pin(self, pin):
self.ser.write(chr(jtagduino_cmd.CMD_GET_PIN))
self.ser.write(chr(pin))
@@ -101,6 +112,80 @@ def get_pin(self, pin):
else:
val = 0
return (rsp, val)
-
+ def pulse_high(self, pin, micros):
+ self.ser.write(chr(jtagduino_cmd.CMD_PULSE_HIGH))
+ self.ser.write(chr(pin))
+ self.ser.write(chr((micros >> 0) & 0xFF))
+ self.ser.write(chr((micros >> 8) & 0xFF))
+ rsp = ord(self.ser.read(1))
+ return rsp
+ def pulse_low(self, pin, micros):
+ self.ser.write(chr(jtagduino_cmd.CMD_PULSE_LOW))
+ self.ser.write(chr(pin))
+ self.ser.write(chr((micros >> 0) & 0xFF))
+ self.ser.write(chr((micros >> 8) & 0xFF))
+ rsp = ord(self.ser.read(1))
+ return rsp
+ def assign_pin(self, jtag_pin, arduino_pin):
+ self.ser.write(chr(jtagduino_cmd.CMD_ASSIGN_PIN))
+ self.ser.write(chr(jtag_pin))
+ self.ser.write(chr(arduino_pin))
+ rsp = ord(self.ser.read(1))
+ return rsp
+ def set_jtag_speed(self, khz):
+ self.ser.write(chr(jtagduino_cmd.CMD_SET_JTAG_SPEED))
+ self.ser.write(chr((khz >> 0) & 0xFF))
+ self.ser.write(chr((khz >> 8) & 0xFF))
+ rsp = ord(self.ser.read(1))
+ return rsp
+ def jtag_clock(self, tms, tdi):
+ self.ser.write(chr(jtagduino_cmd.CMD_JTAG_CLOCK))
+ jtag_in = 0
+ if tms:
+ jtag_in = jtag_in | 1
+ if tdi:
+ jtag_in = jtag_in | 2
+ self.ser.write(chr(jtag_in))
+ rsp = ord(self.ser.read(1))
+ if (rsp == jtagduino_rsp.RSP_OK):
+ tdo = ord(self.ser.read(1))
+ else:
+ tdo = 0
+ return (rsp, tdo)
+ def jtag_sequence(self, tms_seq, tdi_seq):
+ if len(tms_seq) != len(tdi_seq):
+ return (jtagduino_rsp.RSP_BAD_SEQUENCE_LEN, None)
+ n_bytes = (len(tms_seq) + 7) >> 3 # ceil(len(tdi_seq)/8)
+ i_seq = 0
+ tms_bytes = bytearray(n_bytes)
+ tdi_bytes = bytearray(n_bytes)
+ while i_seq < len(tms_seq):
+ i_byte = i_seq >> 3
+ bit = 1<<(i_seq & 0x7)
+ if tms_seq[i_seq]:
+ tms_bytes[i_byte] = tms_bytes[i_byte] | bit
+ if tdi_seq[i_seq]:
+ tdi_bytes[i_byte] = tdi_bytes[i_byte] | bit
+ i_seq += 1
+ self.ser.write(chr(jtagduino_cmd.CMD_JTAG_SEQUENCE))
+ self.ser.write(chr(len(tms_seq)))
+ self.ser.write(tms_bytes)
+ self.ser.write(tdi_bytes)
+ tdo_seq = []
+ rsp = ord(self.ser.read(1))
+ if (rsp == jtagduino_rsp.RSP_OK):
+ tdo_bytes = bytearray(n_bytes)
+ for i_byte in range(n_bytes):
+ tdo_bytes[i_byte] = ord(self.ser.read(1))
+ i_seq = 0
+ while i_seq < len(tms_seq):
+ i_byte = i_seq >> 3
+ bit = 1<<(i_seq & 0x7)
+ if (tdo_bytes[i_byte] & bit) != 0:
+ tdo_seq.append(1)
+ else:
+ tdo_seq.append(0)
+ i_seq += 1
+ return (rsp, tdo_seq)

0 comments on commit 0de3f31

Please sign in to comment.
Something went wrong with that request. Please try again.