#include "minidriver.h"
#include "interface.h"
#include "interfaces.h"
+#include "tcl.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
+#include <helper/time_support.h>
+
/**
* @file
* Holds support for accessing JTAG-specific mechanisms from TCl scripts.
}
} /* validate args */
+ assert(e == JIM_OK);
+
tap = jtag_tap_by_jim_obj(interp, args[1]);
if (tap == NULL) {
return JIM_ERR;
}
num_fields = (argc-2)/2;
+ assert(num_fields > 0);
fields = malloc(sizeof(struct scan_field) * num_fields);
for (i = 2; i < argc; i += 2)
{
return true;
}
-static int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
const char *cmd_name = Jim_GetString(argv[0], NULL);
Jim_GetOptInfo goi;
if (strcasecmp(cmd_name, "tapisenabled") == 0) {
// do nothing, just return the value
} else if (strcasecmp(cmd_name, "tapenable") == 0) {
- if (!jtag_tap_enable(t))
+ if (!jtag_tap_enable(t)){
LOG_WARNING("failed to enable tap %s", t->dotted_name);
+ return JIM_ERR;
+ }
} else if (strcasecmp(cmd_name, "tapdisable") == 0) {
- if (!jtag_tap_disable(t))
+ if (!jtag_tap_disable(t)){
LOG_WARNING("failed to disable tap %s", t->dotted_name);
+ return JIM_ERR;
+ }
} else {
LOG_ERROR("command '%s' unknown", cmd_name);
return JIM_ERR;
return JIM_OK;
}
-static int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
{
const char *cmd_name = Jim_GetString(argv[0], NULL);
Jim_GetOptInfo goi;
return ERROR_OK;
}
+COMMAND_HANDLER(handle_wait_srst_deassert)
+{
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ int timeout_ms;
+ COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], timeout_ms);
+ if ((timeout_ms <= 0) || (timeout_ms > 100000))
+ {
+ LOG_ERROR("Timeout must be an integer between 0 and 100000");
+ return ERROR_FAIL;
+ }
+
+ LOG_USER("Waiting for srst assert + deassert for at most %dms", timeout_ms);
+ int asserted_yet;
+ long long then = timeval_ms();
+ while (jtag_srst_asserted(&asserted_yet) == ERROR_OK)
+ {
+ if ((timeval_ms() - then) > timeout_ms)
+ {
+ LOG_ERROR("Timed out");
+ return ERROR_FAIL;
+ }
+ if (asserted_yet)
+ break;
+ }
+ while (jtag_srst_asserted(&asserted_yet) == ERROR_OK)
+ {
+ if ((timeval_ms() - then) > timeout_ms)
+ {
+ LOG_ERROR("Timed out");
+ return ERROR_FAIL;
+ }
+ if (!asserted_yet)
+ break;
+ }
+
+ return ERROR_OK;
+}
+
static const struct command_registration jtag_command_handlers[] = {
/* Specifically for working around DRIVER bugs... */
.usage = "['short'|'long']",
},
+ {
+ .name = "wait_srst_deassert",
+ .handler = handle_wait_srst_deassert,
+ .mode = COMMAND_ANY,
+ .help = "Wait for an SRST deassert. "
+ "Useful for cases where you need something to happen within ms "
+ "of an srst deassert. Timeout in ms ",
+ .usage = "ms",
+ },
{
.name = "jtag",
.mode = COMMAND_ANY,