OpenOCD
interface.c File Reference
Include dependency graph for interface.c:

Go to the source code of this file.

Data Structures

struct  name_mapping
 
struct  tms_sequences
 

Macros

#define B8(bits, count)   {((uint8_t)B8__(HEX__(bits))), (count)}
 
#define B8__(x)
 
#define HEX__(n)   0x##n##LU
 
#define JTAG_DEBUG_STATE_APPEND(buf, len, bit)    do { buf[len] = bit ? '1' : '0'; } while (0)
 
#define JTAG_DEBUG_STATE_PRINT(a, b, astr, bstr)
 

Typedefs

typedef const struct tms_sequences tms_table[6][6]
 

Functions

tap_state_t jtag_debug_state_machine_ (const void *tms_buf, const void *tdi_buf, unsigned int tap_bits, tap_state_t next_state)
 
tap_state_t tap_get_end_state (void)
 For more information,. More...
 
tap_state_t tap_get_state (void)
 This function gets the state of the "state follower" which tracks the state of the TAPs connected to the cable. More...
 
int tap_get_tms_path (tap_state_t from, tap_state_t to)
 This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of seven TAP clock cycles in order to get from state "from" to state "to". More...
 
int tap_get_tms_path_len (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(). More...
 
bool tap_is_state_stable (tap_state_t astate)
 Function tap_is_state_stable returns true if the astate is stable. More...
 
int tap_move_ndx (tap_state_t astate)
 Function tap_move_ndx when given a stable state, returns an index from 0-5. More...
 
void tap_set_end_state (tap_state_t new_end_state)
 This function sets the state of an "end state follower" which tracks the state that any cable driver thinks will be the end (resultant) state of the current TAP SIR or SDR operation. More...
 
void tap_set_state_impl (tap_state_t new_state)
 implementation of wrapper function tap_set_state() More...
 
tap_state_t tap_state_by_name (const char *name)
 Provides user-friendly name lookup of TAP states. More...
 
const char * tap_state_name (tap_state_t state)
 Function tap_state_name Returns a string suitable for display representing the JTAG tap_state. More...
 
tap_state_t tap_state_transition (tap_state_t cur_state, bool tms)
 Function tap_state_transition takes a current TAP state and returns the next state according to the tms value. More...
 
void tap_use_new_tms_table (bool use_new)
 Allow switching between old and new TMS tables. More...
 
bool tap_uses_new_tms_table (void)
 

Variables

static tap_state_t end_state_follower = TAP_RESET
 
static const struct tms_sequences old_tms_seqs [6][6]
 
static const struct tms_sequences short_tms_seqs [6][6]
 
static tap_state_t state_follower = TAP_RESET
 
static const struct name_mapping tap_name_mapping []
 
static tms_tabletms_seqs = &short_tms_seqs
 

Macro Definition Documentation

◆ B8

#define B8 (   bits,
  count 
)    {((uint8_t)B8__(HEX__(bits))), (count)}

Definition at line 123 of file interface.c.

◆ B8__

#define B8__ (   x)
Value:
((((x) & 0x0000000FLU) ? (1 << 0) : 0) \
+(((x) & 0x000000F0LU) ? (1 << 1) : 0) \
+(((x) & 0x00000F00LU) ? (1 << 2) : 0) \
+(((x) & 0x0000F000LU) ? (1 << 3) : 0) \
+(((x) & 0x000F0000LU) ? (1 << 4) : 0) \
+(((x) & 0x00F00000LU) ? (1 << 5) : 0) \
+(((x) & 0x0F000000LU) ? (1 << 6) : 0) \
+(((x) & 0xF0000000LU) ? (1 << 7) : 0))

Definition at line 113 of file interface.c.

◆ HEX__

#define HEX__ (   n)    0x##n##LU

Definition at line 111 of file interface.c.

◆ JTAG_DEBUG_STATE_APPEND

#define JTAG_DEBUG_STATE_APPEND (   buf,
  len,
  bit 
)     do { buf[len] = bit ? '1' : '0'; } while (0)

Definition at line 368 of file interface.c.

◆ JTAG_DEBUG_STATE_PRINT

#define JTAG_DEBUG_STATE_PRINT (   a,
  b,
  astr,
  bstr 
)
Value:
LOG_DEBUG_IO("TAP/SM: %9s -> %5s\tTMS: %s\tTDI: %s", \
tap_state_name(a), tap_state_name(b), astr, bstr)
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
Definition: interface.c:344
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:101

Definition at line 370 of file interface.c.

Typedef Documentation

◆ tms_table

typedef const struct tms_sequences tms_table[6][6]

Definition at line 61 of file interface.c.

Function Documentation

◆ jtag_debug_state_machine_()

tap_state_t jtag_debug_state_machine_ ( const void *  tms_buf,
const void *  tdi_buf,
unsigned int  tap_bits,
tap_state_t  next_state 
)

◆ tap_get_end_state()

◆ tap_get_state()

tap_state_t tap_get_state ( void  )

This function gets the state of the "state follower" which tracks the state of the TAPs connected to the cable.

See also
tap_set_state
Returns
tap_state_t The state the TAPs are in now.

Definition at line 37 of file interface.c.

References state_follower.

Referenced by amt_jtagaccel_runtest(), amt_jtagaccel_scan(), amt_jtagaccel_state_move(), angie_queue_pathmove(), angie_queue_runtest(), angie_queue_scan(), angie_queue_stableclocks(), angie_queue_statemove(), armjtagew_path_move(), armjtagew_runtest(), armjtagew_scan(), armjtagew_state_move(), bitbang_path_move(), bitbang_runtest(), bitbang_scan(), bitbang_stableclocks(), bitbang_state_move(), bitq_execute_queue(), bitq_path_move(), bitq_runtest(), bitq_scan_field(), bitq_state_move(), buspirate_path_move(), buspirate_runtest(), buspirate_scan(), buspirate_stableclocks(), buspirate_state_move(), cmsis_dap_execute_scan(), cmsis_dap_pathmove(), cmsis_dap_runtest(), cmsis_dap_stableclocks(), cmsis_dap_state_move(), ftdi_execute_pathmove(), ftdi_execute_runtest(), ftdi_execute_scan(), ftdi_execute_sleep(), ftdi_execute_stableclocks(), ftdi_execute_statemove(), gw16012_path_move(), gw16012_runtest(), gw16012_scan(), gw16012_state_move(), jlink_execute_scan(), jlink_path_move(), jlink_runtest(), jlink_stableclocks(), jlink_state_move(), jtag_vpi_path_move(), jtag_vpi_stableclocks(), jtag_vpi_state_move(), move_to_state(), opendous_path_move(), opendous_runtest(), opendous_scan(), opendous_state_move(), openjtag_execute_runtest(), openjtag_execute_scan(), osbdm_add_pathmove(), osbdm_add_scan(), osbdm_add_stableclocks(), osbdm_add_statemove(), rlink_path_move(), rlink_runtest(), rlink_scan(), rlink_state_move(), syncbb_path_move(), syncbb_runtest(), syncbb_scan(), syncbb_stableclocks(), syncbb_state_move(), ublast_path_move(), ublast_state_move(), ulink_queue_pathmove(), ulink_queue_runtest(), ulink_queue_scan(), ulink_queue_stableclocks(), ulink_queue_statemove(), usbprog_path_move(), usbprog_runtest(), usbprog_scan(), usbprog_state_move(), vdebug_jtag_path_move(), vdebug_jtag_runtest(), vdebug_jtag_scan(), vdebug_jtag_stableclocks(), vdebug_jtag_tlr(), vsllink_execute_queue(), vsllink_path_move(), vsllink_runtest(), vsllink_scan(), vsllink_state_move(), xlnx_pcie_xvc_execute_pathmove(), xlnx_pcie_xvc_execute_runtest(), xlnx_pcie_xvc_execute_scan(), xlnx_pcie_xvc_execute_stableclocks(), and xlnx_pcie_xvc_execute_statemove().

◆ tap_get_tms_path()

int tap_get_tms_path ( tap_state_t  from,
tap_state_t  to 
)

This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of seven TAP clock cycles in order to get from state "from" to state "to".

The length of the sequence must be determined with a parallel call to tap_get_tms_path_len().

Parameters
fromThe starting state.
toThe desired final state.
Returns
int The required TMS bit sequence, with the first bit in the sequence at bit 0.

Definition at line 190 of file interface.c.

References tap_move_ndx(), and tms_seqs.

Referenced by angie_queue_scan(), angie_queue_statemove(), armjtagew_state_move(), bitbang_state_move(), bitq_state_move(), buspirate_state_move(), cmsis_dap_state_move(), gw16012_state_move(), jlink_state_move(), jtag_add_statemove(), jtag_vpi_state_move(), move_to_state(), opendous_state_move(), osbdm_add_statemove(), rlink_state_move(), syncbb_state_move(), ublast_state_move(), ulink_queue_scan(), ulink_queue_statemove(), usbprog_state_move(), vdebug_jtag_runtest(), vdebug_jtag_scan(), vdebug_jtag_tlr(), vsllink_state_move(), and xlnx_pcie_xvc_execute_statemove().

◆ tap_get_tms_path_len()

int tap_get_tms_path_len ( 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.

Parameters
fromis the starting state
tois the resultant or final state
Returns
int - the total number of bits in a transition.

Definition at line 195 of file interface.c.

References tap_move_ndx(), and tms_seqs.

Referenced by angie_queue_scan(), angie_queue_statemove(), armjtagew_state_move(), bitbang_state_move(), bitq_state_move(), buspirate_state_move(), cmsis_dap_state_move(), ftdi_initialize(), gw16012_state_move(), jlink_state_move(), jtag_add_statemove(), jtag_vpi_state_move(), move_to_state(), opendous_state_move(), osbdm_add_statemove(), rlink_state_move(), syncbb_state_move(), ublast_state_move(), ulink_queue_scan(), ulink_queue_statemove(), vdebug_jtag_runtest(), vdebug_jtag_scan(), vdebug_jtag_tlr(), vsllink_state_move(), and xlnx_pcie_xvc_execute_statemove().

◆ tap_is_state_stable()

◆ tap_move_ndx()

int tap_move_ndx ( tap_state_t  astate)

Function tap_move_ndx when given a stable state, returns an index from 0-5.

The index corresponds to a sequence of stable states which are given in this order:

{ TAP_RESET, TAP_IDLE, TAP_DRSHIFT, TAP_DRPAUSE, TAP_IRSHIFT, TAP_IRPAUSE }

This sequence corresponds to look up tables which are used in some of the cable drivers.

Parameters
astateis the stable state to find in the sequence. If a non stable state is passed, this may cause the program to output an error message and terminate.
Returns
int - the array (or sequence) index as described above

Definition at line 61 of file interface.c.

Referenced by amt_jtagaccel_scan(), amt_jtagaccel_state_move(), tap_get_tms_path(), and tap_get_tms_path_len().

◆ tap_set_end_state()

◆ tap_set_state_impl()

void tap_set_state_impl ( tap_state_t  new_state)

implementation of wrapper function tap_set_state()

Definition at line 31 of file interface.c.

References state_follower.

◆ tap_state_by_name()

tap_state_t tap_state_by_name ( const char *  name)

Provides user-friendly name lookup of TAP states.

Definition at line 355 of file interface.c.

References ARRAY_SIZE, name, TAP_INVALID, and tap_name_mapping.

Referenced by COMMAND_HANDLER(), and reset_jtag().

◆ tap_state_name()

◆ tap_state_transition()

◆ tap_use_new_tms_table()

void tap_use_new_tms_table ( bool  use_new)

Allow switching between old and new TMS tables.

See also
tap_get_tms_path

Definition at line 447 of file interface.c.

References old_tms_seqs, short_tms_seqs, and tms_seqs.

Referenced by COMMAND_HANDLER().

◆ tap_uses_new_tms_table()

bool tap_uses_new_tms_table ( void  )
Returns
True if new TMS table is active; false otherwise.

Definition at line 451 of file interface.c.

References short_tms_seqs, and tms_seqs.

Referenced by COMMAND_HANDLER().

Variable Documentation

◆ end_state_follower

tap_state_t end_state_follower = TAP_RESET
static
See also
tap_set_end_state() and tap_get_end_state() accessors. Actual name is not important because accessors hide it.

Definition at line 46 of file interface.c.

Referenced by tap_get_end_state(), and tap_set_end_state().

◆ old_tms_seqs

const struct tms_sequences old_tms_seqs[6][6]
static
Initial value:
= {
{B8(1111111, 7), B8(0000000, 7), B8(0010111, 7), B8(0001010, 7), B8(0011011, 7), B8(0010110, 7)},
{B8(1111111, 7), B8(0000000, 7), B8(0100101, 7), B8(0000101, 7), B8(0101011, 7), B8(0001011, 7)},
{B8(1111111, 7), B8(0110001, 7), B8(0000000, 7), B8(0000001, 7), B8(0001111, 7), B8(0101111, 7)},
{B8(1111111, 7), B8(0110000, 7), B8(0100000, 7), B8(0010111, 7), B8(0011110, 7), B8(0101111, 7)},
{B8(1111111, 7), B8(0110001, 7), B8(0000111, 7), B8(0010111, 7), B8(0000000, 7), B8(0000001, 7)},
{B8(1111111, 7), B8(0110000, 7), B8(0011100, 7), B8(0010111, 7), B8(0011110, 7), B8(0101111, 7)},
}
#define B8(bits, count)
Definition: interface.c:123

Definition at line 61 of file interface.c.

Referenced by tap_use_new_tms_table().

◆ short_tms_seqs

const struct tms_sequences short_tms_seqs[6][6]
static
Initial value:
= {
{B8(1111111, 7), B8(0000000, 7), B8(0010111, 7), B8(0001010, 7), B8(0011011, 7), B8(0010110, 7)},
{B8(1111111, 7), B8(0000000, 7), B8(001, 3), B8(0101, 4), B8(0011, 4), B8(01011, 5)},
{B8(1111111, 7), B8(011, 3), B8(00111, 5), B8(01, 2), B8(001111, 6), B8(0101111, 7)},
{B8(1111111, 7), B8(011, 3), B8(01, 2), B8(0, 1), B8(001111, 6), B8(0101111, 7)},
{B8(1111111, 7), B8(011, 3), B8(00111, 5), B8(010111, 6), B8(001111, 6), B8(01, 2)},
{B8(1111111, 7), B8(011, 3), B8(00111, 5), B8(010111, 6), B8(01, 2), B8(0, 1)}
}

Definition at line 61 of file interface.c.

Referenced by tap_use_new_tms_table(), and tap_uses_new_tms_table().

◆ state_follower

tap_state_t state_follower = TAP_RESET
static
See also
tap_set_state() and tap_get_state() accessors. Actual name is not important since accessors hide it.

Definition at line 29 of file interface.c.

Referenced by tap_get_state(), and tap_set_state_impl().

◆ tap_name_mapping

const struct name_mapping tap_name_mapping[]
static
Initial value:
= {
{ TAP_RESET, "RESET", },
{ TAP_IDLE, "RUN/IDLE", },
{ TAP_DRSELECT, "DRSELECT", },
{ TAP_DRCAPTURE, "DRCAPTURE", },
{ TAP_DRSHIFT, "DRSHIFT", },
{ TAP_DREXIT1, "DREXIT1", },
{ TAP_DRPAUSE, "DRPAUSE", },
{ TAP_DREXIT2, "DREXIT2", },
{ TAP_DRUPDATE, "DRUPDATE", },
{ TAP_IRSELECT, "IRSELECT", },
{ TAP_IRCAPTURE, "IRCAPTURE", },
{ TAP_IRSHIFT, "IRSHIFT", },
{ TAP_IREXIT1, "IREXIT1", },
{ TAP_IRPAUSE, "IRPAUSE", },
{ TAP_IREXIT2, "IREXIT2", },
{ TAP_IRUPDATE, "IRUPDATE", },
{ TAP_IDLE, "IDLE", },
}
@ TAP_IRCAPTURE
Definition: jtag.h:55
@ TAP_RESET
Definition: jtag.h:56
@ TAP_DRCAPTURE
Definition: jtag.h:47
@ TAP_DRSELECT
Definition: jtag.h:48
@ TAP_DREXIT1
Definition: jtag.h:42
@ TAP_IREXIT1
Definition: jtag.h:50
@ TAP_DRPAUSE
Definition: jtag.h:44
@ TAP_IRSELECT
Definition: jtag.h:45
@ TAP_IRUPDATE
Definition: jtag.h:54
@ TAP_IREXIT2
Definition: jtag.h:49
@ TAP_IRSHIFT
Definition: jtag.h:51
@ TAP_DREXIT2
Definition: jtag.h:41
@ TAP_IDLE
Definition: jtag.h:53
@ TAP_DRSHIFT
Definition: jtag.h:43
@ TAP_IRPAUSE
Definition: jtag.h:52
@ TAP_DRUPDATE
Definition: jtag.h:46

Referenced by tap_state_by_name(), and tap_state_name().

◆ tms_seqs