/*! * \brief State transition with TMS set to low. */ static void TmsLowTransition(void) { CLR_TMS(); CLR_TCK(); SET_TCK(); }
/*! * \brief Repeat shifting out a TDI value until an expected TDO value appears. * * \param len Number of bits to shift. * \param tdi_val TDI value to shift out. * \param tdo_exp Expected TDO value. Set to NULL if not available. * \param tdo_msk Used to mask out don't care TDO values. * \param sState TAP state during shift operation, either SHIFT-DR or SHIFT-IR. No * retries are allowed with SHIFT-IR. * \param eState TAP state after shift operation. * \param delay Idle time (in microseconds) after each shift. * \param retries Maximum number of retries. Ignored if expected TDO value is not available. * * \return Zero on success, otherwise an error code is returned. */ static int ReShift(int len, unsigned char *tdi_val, unsigned char *tdo_exp, unsigned char *tdo_msk, unsigned char sState, unsigned char eState, long delay, unsigned char retries) { int rc = 0; unsigned char tdo_val[MAX_BITVEC_BYTES]; if (len == 0) { if (delay) { TapStateChange(RUN_TEST_IDLE); XsvfDelay(delay); } } else { int last_byte = (int)((len + 7UL) / 8UL - 1UL); /* * Retry loop. */ do { unsigned char *tdi = &tdi_val[last_byte]; unsigned char *tdo = &tdo_val[last_byte]; int bitcnt; unsigned char bitmsk; TapStateChange(sState); /* * Byte loop. */ for(bitcnt = len; bitcnt;) { *tdo = 0; /* * Bit loop. LSB is shifted first. */ for (bitmsk = 1; bitmsk && bitcnt; bitmsk <<= 1) { if (sState != eState && bitcnt == 1) { /* Exit Shift state with last bit. */ SET_TMS(); TapStateInc(); } /* Shift TDI in and TDO out. */ if(*tdi & bitmsk) { SET_TDI(); } else { CLR_TDI(); } CLR_TCK(); /* * This is time critical, because TDO may be delayed. * The following decrement of our int value consumes * some CPU cycles. */ bitcnt--; if(GET_TDO()) { *tdo |= bitmsk; } SET_TCK(); } tdi--; tdo--; } /* * Compare captured with expected TDO result. */ if (tdo_exp) { if(BitStringCmp(len, tdo_exp, tdo_val, tdo_msk)) { rc = XE_TDOMISMATCH; } else { rc = 0; } } /* * Update TAP controller state. */ if (sState != eState) { if (rc && delay && retries) { /* The TDO value does not match the expected value. */ TapStateChange(PAUSE_DR); TapStateChange(SHIFT_DR); } else { TapStateChange(eState); } /* * If the XRUNTEST time is non-zero, go to the Run-Test/Idle state * and wait for the specified number of microseconds. */ if (delay) { PORTA ^= 0x10; TapStateChange(RUN_TEST_IDLE); //XsvfDelay(delay); XsvfClockCycles(delay); /* In case of another retry, increase idle time by 25%. */ //delay += (delay >> 2); } } } while (rc && retries--); } return rc; }
/*! * \brief State transition with TMS set to high. */ static void TmsHighTransition(void) { SET_TMS(); CLR_TCK(); SET_TCK(); }