"JTAG controller reset(tms or TRST)"
};
+/* kludge!!!! these are just global variables that the
+ * interface use internally. They really belong
+ * inside the drivers, but we don't want to break
+ * linking the drivers!!!!
+ */
enum tap_state end_state = TAP_TLR;
enum tap_state cur_state = TAP_TLR;
int jtag_trst = 0;
/* callbacks to inform high-level handlers about JTAG state changes */
jtag_event_callback_t *jtag_event_callbacks;
+/* speed in kHz*/
+static int speed1 = 0, speed2 = 0;
+/* flag if the kHz speed was defined */
+static int hasKHz = 0;
+
/* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
*/
return ERROR_OK;
}
-void jtag_add_tms()
+void jtag_add_tlr()
{
jtag_prelude(TAP_TLR);
int retval;
- retval=interface_jtag_add_tms();
+ retval=interface_jtag_add_tlr();
if (retval!=ERROR_OK)
jtag_error=retval;
}
-int MINIDRIVER(interface_jtag_add_tms)()
+int MINIDRIVER(interface_jtag_add_tlr)()
{
enum tap_state state = TAP_TLR;
jtag_command_t **last_cmd = jtag_get_last_command_p();
jtag_error=retval;
}
-void jtag_add_reset(int req_tms_or_trst, int req_srst)
+void jtag_add_reset(int req_tlr_or_trst, int req_srst)
{
- int trst_with_tms = 0;
+ int trst_with_tlr = 0;
int retval;
/* Make sure that jtag_reset_config allows the requested reset */
/* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
- if (((jtag_reset_config & RESET_SRST_PULLS_TRST) && (req_srst == 1)) && (!req_tms_or_trst))
+ if (((jtag_reset_config & RESET_SRST_PULLS_TRST) && (req_srst == 1)) && (!req_tlr_or_trst))
{
LOG_ERROR("BUG: requested reset would assert trst");
jtag_error=ERROR_FAIL;
}
/* if TRST pulls SRST, we reset with TAP T-L-R */
- if (((jtag_reset_config & RESET_TRST_PULLS_SRST) && (req_tms_or_trst)) && (req_srst == 0))
+ if (((jtag_reset_config & RESET_TRST_PULLS_SRST) && (req_tlr_or_trst)) && (req_srst == 0))
{
- trst_with_tms = 1;
+ trst_with_tlr = 1;
}
if (req_srst && !(jtag_reset_config & RESET_HAS_SRST))
return;
}
- if (req_tms_or_trst)
+ if (req_tlr_or_trst)
{
- if (!trst_with_tms && (jtag_reset_config & RESET_HAS_TRST))
+ if (!trst_with_tlr && (jtag_reset_config & RESET_HAS_TRST))
{
jtag_trst = 1;
} else
{
- trst_with_tms = 1;
+ trst_with_tlr = 1;
}
} else
{
jtag_add_sleep(jtag_nsrst_delay * 1000);
}
- if (trst_with_tms)
+ if (trst_with_tlr)
{
LOG_DEBUG("JTAG reset with tms instead of TRST");
jtag_add_end_state(TAP_TLR);
- jtag_add_tms();
+ jtag_add_tlr();
jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
return;
}
register_command(cmd_ctx, NULL, "reset_config", handle_reset_config_command,
COMMAND_CONFIG, NULL);
register_command(cmd_ctx, NULL, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command,
- COMMAND_CONFIG, NULL);
+ COMMAND_ANY, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
register_command(cmd_ctx, NULL, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command,
- COMMAND_CONFIG, NULL);
+ COMMAND_ANY, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
register_command(cmd_ctx, NULL, "scan_chain", handle_scan_chain_command,
COMMAND_EXEC, "print current scan chain configuration");
LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
return ERROR_JTAG_INVALID_INTERFACE;
}
+ if(hasKHz)
+ {
+ /*stay on "reset speed"*/
+ if (jtag_interface->khz(speed1, &speed1) == ERROR_OK)
+ jtag_speed = speed1;
+ if (jtag_interface->khz(speed2, &speed2) == ERROR_OK)
+ jtag_speed_post_reset = speed2;
+ hasKHz = 0;
+ }
if (jtag_interface->init() != ERROR_OK)
return ERROR_JTAG_INIT_FAILED;
+
+
jtag = jtag_interface;
return ERROR_OK;
}
device = device->next;
}
- jtag_add_tms();
+ jtag_add_tlr();
jtag_execute_queue();
/* examine chain first, as this could discover the real chain layout */
while (jtag_validate_chain() != ERROR_OK)
{
validate_tries++;
+
if (validate_tries > 5)
{
LOG_ERROR("Could not validate JTAG chain, exit");
}
usleep(10000);
}
-
+
return ERROR_OK;
}
int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
int cur_speed = 0;
- if ((argc<1) || (argc>2))
- return ERROR_COMMAND_SYNTAX_ERROR;
-
- if (argc >= 1)
- cur_speed = jtag_speed = jtag_speed_post_reset = strtoul(args[0], NULL, 0);
- if (argc == 2)
- cur_speed = jtag_speed_post_reset = strtoul(args[1], NULL, 0);
+
+ if (argc != 0)
+ {
+ if ((argc<1) || (argc>2))
+ return ERROR_COMMAND_SYNTAX_ERROR;
- /* this command can be called during CONFIG,
- * in which case jtag isn't initialized */
- if (jtag)
- jtag->speed(cur_speed);
-
+ LOG_DEBUG("handle jtag speed");
+
+ if (argc >= 1)
+ cur_speed = jtag_speed = jtag_speed_post_reset = strtoul(args[0], NULL, 0);
+ if (argc == 2)
+ cur_speed = jtag_speed_post_reset = strtoul(args[1], NULL, 0);
+
+ /* this command can be called during CONFIG,
+ * in which case jtag isn't initialized */
+ if (jtag)
+ jtag->speed(cur_speed);
+ }
+ command_print(cmd_ctx, "jtag_speed: %d, %d", jtag_speed, jtag_speed_post_reset);
+
return ERROR_OK;
}
int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- int cur_speed = 0;
- int speed1, speed2;
+ LOG_DEBUG("handle jtag khz");
+
if ((argc<1) || (argc>2))
return ERROR_COMMAND_SYNTAX_ERROR;
- if (jtag == NULL)
- {
- LOG_ERROR("Interface not selected yet");
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
if (argc >= 1)
- speed1 = strtoul(args[0], NULL, 0);
+ speed1 = speed2 = strtoul(args[0], NULL, 0);
if (argc == 2)
speed2 = strtoul(args[1], NULL, 0);
-
- if (jtag->khz(speed1, &speed1)!=ERROR_OK)
- return ERROR_OK;
-
- if (jtag->khz(speed2, &speed2)!=ERROR_OK)
- return ERROR_OK;
-
- if (argc >= 1)
- cur_speed = jtag_speed = jtag_speed_post_reset = speed1;
-
- if (argc == 2)
- cur_speed = jtag_speed_post_reset = speed2;
-
- jtag->speed(cur_speed);
+ if (jtag != NULL)
+ {
+ int cur_speed = 0;
+ LOG_DEBUG("have interface set up");
+ int speed_div1, speed_div2;
+ if (jtag->khz(speed1, &speed_div1)!=ERROR_OK)
+ return ERROR_OK;
+ if (jtag->khz(speed2, &speed_div2)!=ERROR_OK)
+ return ERROR_OK;
+
+ if (argc >= 1)
+ cur_speed = jtag_speed = jtag_speed_post_reset = speed_div1;
+ if (argc == 2)
+ cur_speed = jtag_speed_post_reset = speed_div2;
+
+ jtag->speed(cur_speed);
+ } else
+ {
+ hasKHz = 1;
+ }
+
return ERROR_OK;
}
}
}
}
- command_print(cmd_ctx, "current endstate: %s", tap_state_strings[end_state]);
+ command_print(cmd_ctx, "current endstate: %s", tap_state_strings[cmd_queue_end_state]);
return ERROR_OK;
}