def con(self): if self.oa is None: if self.serialnum is not None: self.qtadc = openadc_qt.OpenADCQt(includePreview=False, setupLayout=False) self.qtadc.setupParameterTree() self.oaiface = OpenADCInterface_FTDI(self.qtadc) self.oaiface.setSerialNumber(self.serialnum) self.oaiface.con() self.oa = self.qtadc.sc else: print "No OpenADC - did you connect in scope module already and/or set serial number (hit 'REFRESH')?" return # Reset AES Core self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [self.FLAG_RESET], Validate=False) self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [0x00], Validate=False) return True
class ChipWhispererComm(object): CODE_READ = 0x80 CODE_WRITE = 0xC0 ADDR_STATUS = 49 ADDR_FIFO = 50 FLAG_RESET = 0x01 FLAG_WRFULL = 0x02 FLAG_RDEMPTY = 0x04 def __init__(self, standalone=False): self.standalone = standalone self.serialnum = None if standalone: self.setSerial = self._setSerial def _setSerial(self, serialnum): self.serialnum = serialnum def setOpenADC(self, oadc): self.oa = oadc def reset(self): self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [self.FLAG_RESET], Validate=False) time.sleep(0.05) self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [0x00], Validate=False) def con(self): if self.oa is None: if self.serialnum is not None: self.qtadc = openadc_qt.OpenADCQt(includePreview=False, setupLayout=False) self.qtadc.setupParameterTree() self.oaiface = OpenADCInterface_FTDI(self.qtadc) self.oaiface.setSerialNumber(self.serialnum) self.oaiface.con() self.oa = self.qtadc.sc else: print "No OpenADC - did you connect in scope module already and/or set serial number (hit 'REFRESH')?" return # Reset AES Core self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [self.FLAG_RESET], Validate=False) self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [0x00], Validate=False) return True def disconnect(self): return def flush(self): while (self.readStatus() & self.FLAG_RDEMPTY) != self.FLAG_RDEMPTY: self.oa.sendMessage(self.CODE_READ, self.ADDR_FIFO, Validate=False) def readStatus(self): b = self.oa.sendMessage(self.CODE_READ, self.ADDR_STATUS, Validate=False) return b[0] def writeMsg(self, msg): for b in msg: # while (self.readStatus() & self.FLAG_WRFULL) == self.FLAG_WRFULL: # pass self.oa.sendMessage(self.CODE_WRITE, self.ADDR_FIFO, [b], Validate=False) def readMsg(self, nbytes): msg = bytearray() for i in range(0, nbytes): if self.readStatus() & self.FLAG_RDEMPTY: pass b = self.oa.sendMessage(self.CODE_READ, self.ADDR_FIFO, Validate=False) msg.append(b[0]) return msg def write(self, address, MSB, LSB): msg = bytearray(5) msg[0] = 0x01 msg[1] = (address >> 8) & 0xFF # MSB msg[2] = address & 0xFF # LSB msg[3] = MSB msg[4] = LSB # msg = bytearray(strmsg) # print "Write: %x %x %x %x %x"%(msg[0],msg[1],msg[2],msg[3],msg[4]) self.writeMsg(msg) def read(self, address): self.flush() msg = bytearray(3) msg[0] = 0x00 msg[1] = (address >> 8) & 0xFF # MSB msg[2] = address & 0xFF # LSB self.writeMsg(msg) # print "Write: %x %x %x"%(msg[0],msg[1],msg[2]), msg = self.readMsg(2) # print " Read: %x %x"%(msg[0],msg[1]) # Order = MSB, LSB return msg def read128(self, address): self.flush() msg = bytearray(3 * 8) for i in range(0, 8): msg[i * 3] = 0x00 msg[i * 3 + 1] = (address >> 8) & 0xFF msg[i * 3 + 2] = (address & 0xFF) + (i * 2) self.writeMsg(str(msg)) msg = self.readMsg(16) return bytearray(msg) def close(self): pass
class ChipWhispererComm(object): CODE_READ = 0x80 CODE_WRITE = 0xC0 ADDR_STATUS = 49 ADDR_FIFO = 50 FLAG_RESET = 0x01 FLAG_WRFULL = 0x02 FLAG_RDEMPTY = 0x04 def __init__(self, standalone=False): self.standalone = standalone self.serialnum = None if standalone: self.setSerial = self._setSerial def _setSerial(self, serialnum): self.serialnum = serialnum def setOpenADC(self, oadc): self.oa = oadc def reset(self): self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [self.FLAG_RESET], Validate=False) time.sleep(0.05) self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [0x00], Validate=False) def con(self): if self.oa is None: if self.serialnum is not None: self.qtadc = openadc_qt.OpenADCQt(includePreview=False, setupLayout=False) self.qtadc.setupParameterTree() self.oaiface = OpenADCInterface_FTDI(self.qtadc) self.oaiface.setSerialNumber(self.serialnum) self.oaiface.con() self.oa = self.qtadc.sc else: print "No OpenADC - did you connect in scope module already and/or set serial number (hit 'REFRESH')?" return # Reset AES Core self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [self.FLAG_RESET], Validate=False) self.oa.sendMessage(self.CODE_WRITE, self.ADDR_STATUS, [0x00], Validate=False) return True def disconnect(self): return def flush(self): while (self.readStatus() & self.FLAG_RDEMPTY) != self.FLAG_RDEMPTY: self.oa.sendMessage(self.CODE_READ, self.ADDR_FIFO, Validate=False) def readStatus(self): b = self.oa.sendMessage(self.CODE_READ, self.ADDR_STATUS, Validate=False) return b[0] def writeMsg(self, msg): for b in msg: # while (self.readStatus() & self.FLAG_WRFULL) == self.FLAG_WRFULL: # pass self.oa.sendMessage(self.CODE_WRITE, self.ADDR_FIFO, [b], Validate=False) def readMsg(self, nbytes): msg = bytearray() for i in range(0, nbytes): if self.readStatus() & self.FLAG_RDEMPTY: pass b = self.oa.sendMessage(self.CODE_READ, self.ADDR_FIFO, Validate=False) msg.append(b[0]) return msg def write(self, address, MSB, LSB): msg = bytearray(5) msg[0] = 0x01; msg[1] = (address >> 8) & 0xFF; # MSB msg[2] = address & 0xFF; # LSB msg[3] = MSB; msg[4] = LSB; # msg = bytearray(strmsg) # print "Write: %x %x %x %x %x"%(msg[0],msg[1],msg[2],msg[3],msg[4]) self.writeMsg(msg) def read(self, address): self.flush() msg = bytearray(3) msg[0] = 0x00; msg[1] = (address >> 8) & 0xFF; # MSB msg[2] = address & 0xFF; # LSB self.writeMsg(msg) # print "Write: %x %x %x"%(msg[0],msg[1],msg[2]), msg = self.readMsg(2) # print " Read: %x %x"%(msg[0],msg[1]) # Order = MSB, LSB return msg def read128(self, address): self.flush() msg = bytearray(3 * 8) for i in range(0, 8): msg[i * 3] = 0x00; msg[i * 3 + 1] = (address >> 8) & 0xFF; msg[i * 3 + 2] = (address & 0xFF) + (i * 2); self.writeMsg(str(msg)) msg = self.readMsg(16) return bytearray(msg) def close(self): pass