summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorØyvind Harboe <oyvind.harboe@zylin.com>2011-02-24 15:19:27 +0100
committerØyvind Harboe <oyvind.harboe@zylin.com>2011-02-25 16:36:42 +0100
commitc3c6a6e1d4b7cf121adb86d4021775ed8ced7fb4 (patch)
tree0e8f13a694f7bd0ff48421dd9c8ae34f021ae0f9 /src
parent6ddcee7d20ee873f1c214736c22f29d9781dded4 (diff)
downloadopenocd+libswd-c3c6a6e1d4b7cf121adb86d4021775ed8ced7fb4.tar.gz
openocd+libswd-c3c6a6e1d4b7cf121adb86d4021775ed8ced7fb4.tar.bz2
openocd+libswd-c3c6a6e1d4b7cf121adb86d4021775ed8ced7fb4.tar.xz
openocd+libswd-c3c6a6e1d4b7cf121adb86d4021775ed8ced7fb4.zip
jtag: add wait_srst_deassert command
Useful to do something *real quick* after a SRST deassert. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Diffstat (limited to 'src')
-rw-r--r--src/jtag/tcl.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c
index 3e6074b8..267802ed 100644
--- a/src/jtag/tcl.c
+++ b/src/jtag/tcl.c
@@ -40,6 +40,8 @@
#include <strings.h>
#endif
+#include <helper/time_support.h>
+
/**
* @file
* Holds support for accessing JTAG-specific mechanisms from TCl scripts.
@@ -1266,6 +1268,46 @@ COMMAND_HANDLER(handle_jtag_flush_queue_sleep)
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[] = {
@@ -1358,6 +1400,15 @@ static const struct command_registration jtag_command_handlers[] = {
.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,
.help = "perform jtag tap actions",