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;
+ /* FIX!!! there are *many* different cases here. A better
+ * approach is needed for legal combinations of transitions...
+ */
+ if ((jtag_reset_config & RESET_HAS_SRST)&&
+ (jtag_reset_config & RESET_HAS_TRST)&&
+ ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0)&&
+ ((jtag_reset_config & RESET_TRST_PULLS_SRST)==0))
+ {
+ if (((req_tlr_or_trst&&!jtag_trst)||
+ (!req_tlr_or_trst&&jtag_trst))&&
+ ((req_srst&&!jtag_srst)||
+ (!req_srst&&jtag_srst)))
+ {
+ LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined");
+ }
+ }
+
/* 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");
return ERROR_OK;
}
-int jtag_init(struct command_context_s *cmd_ctx)
+static int jtag_init_inner(struct command_context_s *cmd_ctx)
{
int validate_tries = 0;
jtag_device_t *device;
device = device->next;
}
- jtag_add_tms();
+ jtag_add_tlr();
jtag_execute_queue();
/* examine chain first, as this could discover the real chain layout */
return ERROR_OK;
}
+int jtag_init_reset(struct command_context_s *cmd_ctx)
+{
+ int retval;
+ LOG_DEBUG("Trying to bring the JTAG controller to life by asserting TRST / tms");
+
+ /* Reset can happen after a power cycle.
+ *
+ * Ideally we would only assert TRST or run tms before the target reset.
+ *
+ * However w/srst_pulls_trst, trst is asserted together with the target
+ * reset whether we want it or not.
+ *
+ * NB! Some targets have JTAG circuitry disabled until a
+ * trst & srst has been asserted.
+ *
+ * NB! here we assume nsrst/ntrst delay are sufficient!
+ *
+ * NB! order matters!!!! srst *can* disconnect JTAG circuitry
+ *
+ */
+ jtag_add_reset(1, 0); /* TMS or TRST */
+ if (jtag_reset_config & RESET_HAS_SRST)
+ {
+ jtag_add_reset(1, 1);
+ if ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0)
+ jtag_add_reset(0, 1);
+ }
+ jtag_add_reset(0, 0);
+ if ((retval = jtag_execute_queue()) != ERROR_OK)
+ return retval;
+
+ /* Check that we can communication on the JTAG chain + eventually we want to
+ * be able to perform enumeration only after OpenOCD has started
+ * telnet and GDB server
+ *
+ * That would allow users to more easily perform any magic they need to before
+ * reset happens.
+ */
+ return jtag_init_inner(cmd_ctx);
+}
+
+int jtag_init(struct command_context_s *cmd_ctx)
+{
+ if (jtag_init_inner(cmd_ctx)==ERROR_OK)
+ {
+ return ERROR_OK;
+ }
+ return jtag_init_reset(cmd_ctx);
+}
+
static int default_khz(int khz, int *jtag_speed)
{