#define DEBUG_JTAG_IOZ 64
#endif
+/*-----<Macros>--------------------------------------------------*/
+
+/** When given an array, compute its DIMension, i.e. number of elements in the array */
+#define DIM(x) (sizeof(x)/sizeof((x)[0]))
+
+/** Calculate the number of bytes required to hold @a n TAP scan bits */
+#define TAP_SCAN_BYTES(n) CEIL(n, 8)
+
+/*-----</Macros>-------------------------------------------------*/
+
+
/*
* Tap states from ARM7TDMI-S Technical reference manual.
*
* N.B. tap_get_tms_path() was changed to reflect this corrected
* numbering and ordering of the TAP states.
+ *
+ * DANGER!!!! some interfaces care about the actual numbers used
+ * as they are handed off directly to hardware implementations.
*/
+
typedef enum tap_state
{
+#if BUILD_ECOSBOARD
+/* These are the old numbers. Leave as-is for now... */
+ TAP_RESET = 0, TAP_IDLE = 8,
+ TAP_DRSELECT = 1, TAP_DRCAPTURE = 2, TAP_DRSHIFT = 3, TAP_DREXIT1 = 4,
+ TAP_DRPAUSE = 5, TAP_DREXIT2 = 6, TAP_DRUPDATE = 7,
+ TAP_IRSELECT = 9, TAP_IRCAPTURE = 10, TAP_IRSHIFT = 11, TAP_IREXIT1 = 12,
+ TAP_IRPAUSE = 13, TAP_IREXIT2 = 14, TAP_IRUPDATE = 15,
+
+ TAP_NUM_STATES = 16, TAP_INVALID = -1,
+#else
+ /* Proper ARM recommended numbers */
TAP_DREXIT2 = 0x0,
TAP_DREXIT1 = 0x1,
TAP_DRSHIFT = 0x2,
TAP_NUM_STATES = 0x10,
TAP_INVALID = -1,
+#endif
} tap_state_t;
-
+
typedef struct tap_transition_s
{
tap_state_t high;
*/
int tap_get_tms_path(tap_state_t from, tap_state_t to);
+
+/**
+ * Function int tap_get_tms_path_len
+ * returns the total number of bits that represents a TMS path
+ * transition as given by the function tap_get_tms_path().
+ *
+ * For at least one interface (JLink) it's not OK to simply "pad" TMS sequences
+ * to fit a whole byte. (I suspect this is a general TAP problem within OOCD.)
+ * Padding TMS causes all manner of instability that's not easily
+ * discovered. Using this routine we can apply EXACTLY the state transitions
+ * required to make something work - no more - no less.
+ *
+ * @param from is the starting state
+ * @param to is the resultant or final state
+ * @return int - the total number of bits in a transition.
+ */
+int tap_get_tms_path_len(tap_state_t from, tap_state_t to);
+
+
/**
* Function tap_move_ndx
* when given a stable state, returns an index from 0-5. The index corresponds to a
*/
const char* tap_state_name(tap_state_t state);
+#ifdef _DEBUG_JTAG_IO_
+/**
+ * @brief Prints verbose TAP state transitions for the given TMS/TDI buffers.
+ * @param tms_buf must points to a buffer containing the TMS bitstream.
+ * @param tdi_buf must points to a buffer containing the TDI bitstream.
+ * @param tap_len must specify the length of the TMS/TDI bitstreams.
+ * @param start_tap_state must specify the current TAP state.
+ * @returns the final TAP state; pass as @a start_tap_state in following call.
+ */
+tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf,
+ unsigned tap_len, tap_state_t start_tap_state);
+#else
+static inline tap_state_t jtag_debug_state_machine(const void *tms_buf,
+ const void *tdi_buf, unsigned tap_len, tap_state_t start_tap_state)
+{
+ return start_tap_state;
+}
+#endif // _DEBUG_JTAG_IO_
+
/*-----</Cable Helper API>------------------------------------------*/
};
extern jtag_tap_t* jtag_AllTaps(void);
extern jtag_tap_t* jtag_TapByPosition(int n);
-extern jtag_tap_t* jtag_TapByPosition(int n);
extern jtag_tap_t* jtag_TapByString(const char* dotted_name);
extern jtag_tap_t* jtag_TapByJimObj(Jim_Interp* interp, Jim_Obj* obj);
extern jtag_tap_t* jtag_TapByAbsPosition(int abs_position);
extern void jtag_add_tlr(void);
extern int interface_jtag_add_tlr(void);
-/* Do not use jtag_add_pathmove() unless you need to, but do use it
+/* Application code *must* assume that interfaces will
+ * implement transitions between states with different
+ * paths and path lengths through the state diagram. The
+ * path will vary across interface and also across versions
+ * of the same interface over time. Even if the OpenOCD code
+ * is unchanged, the actual path taken may vary over time
+ * and versions of interface firmware or PCB revisions.
+ *
+ * Use jtag_add_pathmove() when specific transition sequences
+ * are required.
+ *
+ * Do not use jtag_add_pathmove() unless you need to, but do use it
* if you have to.
*
* DANGER! If the target is dependent upon a particular sequence