Пример #1
0
 def shift_register(self, out, use_last=False):
     """Shift a BitSequence into the current register and retrieve the
        register output"""
     if not isinstance(out, BitSequence):
         return JtagError('Expect a BitSequence')
     length = len(out)
     if use_last:
         (out, self._last) = (out[:-1], int(out[-1]))
     byte_count = len(out) // 8
     pos = 8 * byte_count
     bit_count = len(out) - pos
     if not byte_count and not bit_count:
         raise JtagError("Nothing to shift")
     if byte_count:
         blen = byte_count - 1
         #print "RW OUT %s" % out[:pos]
         cmd = Array('B',
                     [Ftdi.RW_BYTES_PVE_NVE_LSB, blen, (blen >> 8) & 0xff])
         cmd.extend(out[:pos].tobytes(msby=True))
         self._stack_cmd(cmd)
         #print "push %d bytes" % byte_count
     if bit_count:
         #print "RW OUT %s" % out[pos:]
         cmd = Array('B', [Ftdi.RW_BITS_PVE_NVE_LSB, bit_count - 1])
         cmd.append(out[pos:].tobyte())
         self._stack_cmd(cmd)
         #print "push %d bits" % bit_count
     self.sync()
     bs = BitSequence()
     byte_count = length // 8
     pos = 8 * byte_count
     bit_count = length - pos
     if byte_count:
         data = self._ftdi.read_data_bytes(byte_count, 4)
         if not data:
             raise JtagError('Unable to read data from FTDI')
         byteseq = BitSequence(bytes_=data, length=8 * byte_count)
         #print "RW IN %s" % byteseq
         bs.append(byteseq)
         #print "pop %d bytes" % byte_count
     if bit_count:
         data = self._ftdi.read_data_bytes(1, 4)
         if not data:
             raise JtagError('Unable to read data from FTDI')
         byte = data[0]
         # need to shift bits as they are shifted in from the MSB in FTDI
         byte >>= 8 - bit_count
         bitseq = BitSequence(byte, length=bit_count)
         bs.append(bitseq)
         #print "pop %d bits" % bit_count
     if len(bs) != length:
         raise AssertionError("Internal error")
     #self._ftdi.validate_mpsse()
     return bs
Пример #2
0
 def shift_register(self, out, use_last=False):
     """Shift a BitSequence into the current register and retrieve the
        register output"""
     if not isinstance(out, BitSequence):
         return JtagError('Expect a BitSequence')
     length = len(out)
     if use_last:
         (out, self._last) = (out[:-1], int(out[-1]))
     byte_count = len(out)//8
     pos = 8*byte_count
     bit_count = len(out)-pos
     if not byte_count and not bit_count:
         raise JtagError("Nothing to shift")
     if byte_count:
         blen = byte_count-1
         #print "RW OUT %s" % out[:pos]
         cmd = Array('B', [Ftdi.RW_BYTES_PVE_NVE_LSB, blen, (blen>>8)&0xff])
         cmd.extend(out[:pos].tobytes(msby=True))
         self._stack_cmd(cmd)
         #print "push %d bytes" % byte_count
     if bit_count:
         #print "RW OUT %s" % out[pos:]
         cmd = Array('B', [Ftdi.RW_BITS_PVE_NVE_LSB, bit_count-1])
         cmd.append(out[pos:].tobyte())
         self._stack_cmd(cmd)
         #print "push %d bits" % bit_count
     self.sync()
     bs = BitSequence()
     byte_count = length//8
     pos = 8*byte_count
     bit_count = length-pos
     if byte_count:
         data = self._ftdi.read_data_bytes(byte_count, 4)
         if not data:
             raise JtagError('Unable to read data from FTDI')
         byteseq = BitSequence(bytes_=data, length=8*byte_count)
         #print "RW IN %s" % byteseq
         bs.append(byteseq)
         #print "pop %d bytes" % byte_count
     if bit_count:
         data = self._ftdi.read_data_bytes(1, 4)
         if not data:
             raise JtagError('Unable to read data from FTDI')
         byte = data[0]
         # need to shift bits as they are shifted in from the MSB in FTDI
         byte >>= 8-bit_count
         bitseq = BitSequence(byte, length=bit_count)
         bs.append(bitseq)
         #print "pop %d bits" % bit_count
     if len(bs) != length:
         raise AssertionError("Internal error")
     #self._ftdi.validate_mpsse()
     return bs
Пример #3
0
 def read(self, length):
     """Read out a sequence of bits from TDO"""
     byte_count = length//8
     bit_count = length-8*byte_count
     bs = BitSequence()
     if byte_count:
         bytes = self._read_bytes(byte_count)
         bs.append(bytes)
     if bit_count:
         bits = self._read_bits(bit_count)
         bs.append(bits)
     return bs
Пример #4
0
 def read(self, length):
     """Read out a sequence of bits from TDO"""
     byte_count = length // 8
     bit_count = length - 8 * byte_count
     bs = BitSequence()
     if byte_count:
         bytes = self._read_bytes(byte_count)
         bs.append(bytes)
     if bit_count:
         bits = self._read_bits(bit_count)
         bs.append(bits)
     return bs