static int jtag_nsrst_delay = 0; /* default to no nSRST delay */
static int jtag_ntrst_delay = 0; /* default to no nTRST delay */
-/* maximum number of JTAG devices expected in the chain
- */
-#define JTAG_MAX_CHAIN_SIZE 20
-
/* callbacks to inform high-level handlers about JTAG state changes */
jtag_event_callback_t *jtag_event_callbacks;
return __jtag_all_taps;
};
-int jtag_NumTotalTaps(void)
+int jtag_tap_count(void)
{
return jtag_num_taps;
}
-int jtag_NumEnabledTaps(void)
+int jtag_tap_count_enabled(void)
{
jtag_tap_t *t;
int n;
alive_sleep(us/1000);
}
+/// maximum number of JTAG devices expected in the chain
+#define JTAG_MAX_CHAIN_SIZE 20
+
+#define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
+#define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
+#define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
+
/* Try to examine chain layout according to IEEE 1149.1 ยง12
*/
static int jtag_examine_chain(void)
}
/* point at the 1st tap */
- tap = jtag_NextEnabledTap(NULL);
+ tap = jtag_tap_next_enabled(NULL);
if( tap == NULL ){
LOG_ERROR("JTAG: No taps enabled?");
return ERROR_JTAG_INIT_FAILED;
break;
}
-#define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
manufacturer = EXTRACT_MFG(idcode);
-#define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
part = EXTRACT_PART(idcode);
-#define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
version = EXTRACT_VER(idcode);
LOG_INFO("JTAG tap: %s tap/device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x)",
bit_count += 32;
}
- if (tap)
- {
- tap->idcode = idcode;
+ device_count++;
+ if (!tap)
+ continue;
- if (tap->expected_ids_cnt > 0) {
- /* Loop over the expected identification codes and test for a match */
- u8 ii;
- for (ii = 0; ii < tap->expected_ids_cnt; ii++) {
- if( tap->idcode == tap->expected_ids[ii] ){
- break;
- }
+ tap->idcode = idcode;
+
+ if (tap->expected_ids_cnt > 0) {
+ /* Loop over the expected identification codes and test for a match */
+ u8 ii;
+ for (ii = 0; ii < tap->expected_ids_cnt; ii++) {
+ if( tap->idcode == tap->expected_ids[ii] ){
+ break;
}
+ }
- /* If none of the expected ids matched, log an error */
- if (ii == tap->expected_ids_cnt) {
- LOG_ERROR("JTAG tap: %s got: 0x%08x (mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
+ /* If none of the expected ids matched, log an error */
+ if (ii == tap->expected_ids_cnt) {
+ LOG_ERROR("JTAG tap: %s got: 0x%08x (mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
+ tap->dotted_name,
+ idcode,
+ EXTRACT_MFG( tap->idcode ),
+ EXTRACT_PART( tap->idcode ),
+ EXTRACT_VER( tap->idcode ) );
+ for (ii = 0; ii < tap->expected_ids_cnt; ii++) {
+ LOG_ERROR("JTAG tap: %s expected %hhu of %hhu: 0x%08x (mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
tap->dotted_name,
- idcode,
- EXTRACT_MFG( tap->idcode ),
- EXTRACT_PART( tap->idcode ),
- EXTRACT_VER( tap->idcode ) );
- for (ii = 0; ii < tap->expected_ids_cnt; ii++) {
- LOG_ERROR("JTAG tap: %s expected %hhu of %hhu: 0x%08x (mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
- tap->dotted_name,
- ii + 1,
- tap->expected_ids_cnt,
- tap->expected_ids[ii],
- EXTRACT_MFG( tap->expected_ids[ii] ),
- EXTRACT_PART( tap->expected_ids[ii] ),
- EXTRACT_VER( tap->expected_ids[ii] ) );
- }
-
- return ERROR_JTAG_INIT_FAILED;
- } else {
- LOG_INFO("JTAG Tap/device matched");
+ ii + 1,
+ tap->expected_ids_cnt,
+ tap->expected_ids[ii],
+ EXTRACT_MFG( tap->expected_ids[ii] ),
+ EXTRACT_PART( tap->expected_ids[ii] ),
+ EXTRACT_VER( tap->expected_ids[ii] ) );
}
+
+ return ERROR_JTAG_INIT_FAILED;
} else {
+ LOG_INFO("JTAG Tap/device matched");
+ }
+ } else {
#if 0
- LOG_INFO("JTAG TAP ID: 0x%08x - Unknown - please report (A) chipname and (B) idcode to the openocd project",
- tap->idcode);
+ LOG_INFO("JTAG TAP ID: 0x%08x - Unknown - please report (A) chipname and (B) idcode to the openocd project",
+ tap->idcode);
#endif
- }
- tap = jtag_NextEnabledTap(tap);
}
- device_count++;
+ tap = jtag_tap_next_enabled(tap);
}
/* see if number of discovered devices matches configuration */
- if (device_count != jtag_NumEnabledTaps())
+ if (device_count != jtag_tap_count_enabled())
{
LOG_ERROR("number of discovered devices in JTAG chain (%i) doesn't match (enabled) configuration (%i), total taps: %d",
- device_count, jtag_NumEnabledTaps(), jtag_NumTotalTaps());
+ device_count, jtag_tap_count_enabled(), jtag_tap_count());
LOG_ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
return ERROR_JTAG_INIT_FAILED;
}
tap = NULL;
total_ir_length = 0;
for(;;){
- tap = jtag_NextEnabledTap(tap);
+ tap = jtag_tap_next_enabled(tap);
if( tap == NULL ){
break;
}
chain_pos = 0;
int val;
for(;;){
- tap = jtag_NextEnabledTap(tap);
+ tap = jtag_tap_next_enabled(tap);
if( tap == NULL ){
break;
}
LOG_DEBUG("Init JTAG chain");
- tap = jtag_NextEnabledTap(NULL);
+ tap = jtag_tap_next_enabled(NULL);
if( tap == NULL ){
LOG_ERROR("There are no enabled taps?");
return ERROR_JTAG_INIT_FAILED;
newargs[0] = Jim_NewStringObj( interp, "jtag", -1 );
newargs[1] = Jim_NewStringObj( interp, "newtap", -1 );
- sprintf( buf, "chip%d", jtag_NumTotalTaps() );
+ sprintf( buf, "chip%d", jtag_tap_count() );
newargs[2] = Jim_NewStringObj( interp, buf, -1 );
- sprintf( buf, "tap%d", jtag_NumTotalTaps() );
+ sprintf( buf, "tap%d", jtag_tap_count() );
newargs[3] = Jim_NewStringObj( interp, buf, -1 );
newargs[4] = Jim_NewStringObj( interp, "-irlen", -1 );
newargs[5] = Jim_NewStringObj( interp, args[0], -1 );
static int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- tap_state_t state;
-
if (argc < 1)
- {
return ERROR_COMMAND_SYNTAX_ERROR;
- }
- else
+
+ tap_state_t state = tap_state_by_name(args[0]);
+ if (state < 0)
{
- state = tap_state_by_name( args[0] );
- if( state < 0 ){
- command_print( cmd_ctx, "Invalid state name: %s\n", args[0] );
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
- jtag_set_end_state(state);
- jtag_execute_queue();
+ command_print( cmd_ctx, "Invalid state name: %s\n", args[0] );
+ return ERROR_COMMAND_SYNTAX_ERROR;
}
- command_print(cmd_ctx, "current endstate: %s", tap_state_name(cmd_queue_end_state));
+ jtag_set_end_state(state);
+ jtag_execute_queue();
+
+ command_print(cmd_ctx, "current endstate: %s",
+ tap_state_name(cmd_queue_end_state));
return ERROR_OK;
}