Esempio n. 1
0
File: jtag.py Progetto: eblot/pyftdi
 def detect_register_size(self):
     # Freely inpired from UrJTAG
     # Need to contact authors, or to replace this code to comply with
     # the GPL license (GPL vs. LGPL with Python is a bit fuzzy for me)
     if not self._engine._sm.state_of("shift"):
         raise JtagError("Invalid state: %s" % self._engine._sm.state())
     if self._engine._sm.state_of("capture"):
         bs = BitSequence(False)
         self._engine._ctrl.write_tms(bs)
         self._engine._sm.handle_events(bs)
     MAX_REG_LEN = 1024
     PATTERN_LEN = 8
     stuck = None
     for length in range(1, MAX_REG_LEN):
         print_("Testing for length %d" % length)
         if length > 5:
             return
         zero = BitSequence(length=length)
         inj = BitSequence(length=length + PATTERN_LEN)
         inj.inc()
         ok = False
         for p in range(1, 1 << PATTERN_LEN):
             ok = False
             self._engine.write(zero, False)
             rcv = self._engine.shift_register(inj)
             try:
                 tdo = rcv.invariant()
             except ValueError:
                 tdo = None
             if stuck is None:
                 stuck = tdo
             if stuck != tdo:
                 stuck = None
             rcv >>= length
             if rcv == inj:
                 ok = True
             else:
                 break
             inj.inc()
         if ok:
             print_("Register detected length: %d" % length)
             return length
     if stuck is not None:
         raise JtagError("TDO seems to be stuck")
     raise JtagError("Unable to detect register length")
Esempio n. 2
0
 def detect_register_size(self):
     # Freely inpired from UrJTAG
     # Need to contact authors, or to replace this code to comply with
     # the GPL license (GPL vs. LGPL with Python is a bit fuzzy for me)
     if not self._engine._sm.state_of('shift'):
         raise JtagError("Invalid state: %s" % self._engine._sm.state())
     if self._engine._sm.state_of('capture'):
         bs = BitSequence(False)
         self._engine._ctrl.write_tms(bs)
         self._engine._sm.handle_events(bs)
     MAX_REG_LEN = 1024
     PATTERN_LEN = 8
     stuck = None
     for length in range(1, MAX_REG_LEN):
         print_("Testing for length %d" % length)
         if length > 5:
             return
         zero = BitSequence(length=length)
         inj = BitSequence(length=length + PATTERN_LEN)
         inj.inc()
         ok = False
         for p in range(1, 1 << PATTERN_LEN):
             ok = False
             self._engine.write(zero, False)
             rcv = self._engine.shift_register(inj)
             try:
                 tdo = rcv.invariant()
             except ValueError:
                 tdo = None
             if stuck is None:
                 stuck = tdo
             if stuck != tdo:
                 stuck = None
             rcv >>= length
             if rcv == inj:
                 ok = True
             else:
                 break
             inj.inc()
         if ok:
             print_("Register detected length: %d" % length)
             return length
     if stuck is not None:
         raise JtagError('TDO seems to be stuck')
     raise JtagError('Unable to detect register length')