summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-05-30 01:32:19 +0000
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-05-30 01:32:19 +0000
commitd00a5cfe97452f9d72aeff31d00fac5979add0ea (patch)
treed3c7e74dac9421011e5084a576598fc1993dc38d /src
parentebcde562d9903a257a3b40a79c94e1010e5b5fc2 (diff)
downloadopenocd+libswd-d00a5cfe97452f9d72aeff31d00fac5979add0ea.tar.gz
openocd+libswd-d00a5cfe97452f9d72aeff31d00fac5979add0ea.tar.bz2
openocd+libswd-d00a5cfe97452f9d72aeff31d00fac5979add0ea.tar.xz
openocd+libswd-d00a5cfe97452f9d72aeff31d00fac5979add0ea.zip
David Brownell <david-b@pacbell.net>:
Make it so the magic "reset_config" keywords can be provided in any order. This eliminates needless error paths, and makes it easier to define things at the right level (adapter, board, target). It also includes two other behavioral changes: (1) When "handle_reset_config" sees a parameter error, it exits without changing anything. This is best viewed as a bugfix. (Old behavior: restore defaults, even if they weren't previously active.) (2) Only the behaviors that were explicitly specified get changed. (Old behavior: everything else gets reset to the "default".) So for example you can now specify SRST drive requirements without saying anything about the three unrelated topics you previously had to specify. That second one might cause confusion for any configs that end up calling "reset_config" twice, so it will deserve to be called out in the release notes. (There were no such configurations in the current OpenOCD source tree.) Update docs accordingly. Note that at least some versions of the texi-to-html tools can't handle "@xref{with spaces}", but those work properly in PDF and in the info files. git-svn-id: svn://svn.berlios.de/openocd/trunk@1944 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src')
-rw-r--r--src/jtag/jtag.c142
1 files changed, 88 insertions, 54 deletions
diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c
index 56a8075b..ecd4931a 100644
--- a/src/jtag/jtag.c
+++ b/src/jtag/jtag.c
@@ -2651,77 +2651,111 @@ static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cm
static int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
+ int new_cfg = 0;
+ int mask = 0;
+
if (argc < 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- if (argc >= 1)
- {
- if (strcmp(args[0], "none") == 0)
- jtag_reset_config = RESET_NONE;
- else if (strcmp(args[0], "trst_only") == 0)
- jtag_reset_config = RESET_HAS_TRST;
- else if (strcmp(args[0], "srst_only") == 0)
- jtag_reset_config = RESET_HAS_SRST;
- else if (strcmp(args[0], "trst_and_srst") == 0)
- jtag_reset_config = RESET_TRST_AND_SRST;
+ /* Original versions cared about the order of these tokens:
+ * reset_config signals [combination [trst_type [srst_type]]]
+ * They also clobbered the previous configuration even on error.
+ *
+ * Here we don't care about the order, and only change values
+ * which have been explicitly specified.
+ */
+ for (; argc; argc--, args++) {
+ int tmp = 0;
+ int m;
+
+ /* signals */
+ m = RESET_HAS_TRST | RESET_HAS_SRST;
+ if (strcmp(*args, "none") == 0)
+ tmp = RESET_NONE;
+ else if (strcmp(*args, "trst_only") == 0)
+ tmp = RESET_HAS_TRST;
+ else if (strcmp(*args, "srst_only") == 0)
+ tmp = RESET_HAS_SRST;
+ else if (strcmp(*args, "trst_and_srst") == 0)
+ tmp = RESET_HAS_TRST | RESET_HAS_SRST;
else
- {
- LOG_ERROR("(1) invalid reset_config argument (%s), defaulting to none", args[0]);
- jtag_reset_config = RESET_NONE;
+ m = 0;
+ if (mask & m) {
+ LOG_ERROR("extra reset_config %s spec (%s)",
+ "signal", *args);
return ERROR_INVALID_ARGUMENTS;
}
- }
-
- if (argc >= 2)
- {
- if (strcmp(args[1], "separate") == 0)
- {
- /* seperate reset lines - default */
- } else
- {
- if (strcmp(args[1], "srst_pulls_trst") == 0)
- jtag_reset_config |= RESET_SRST_PULLS_TRST;
- else if (strcmp(args[1], "trst_pulls_srst") == 0)
- jtag_reset_config |= RESET_TRST_PULLS_SRST;
- else if (strcmp(args[1], "combined") == 0)
- jtag_reset_config |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
- else
- {
- LOG_ERROR("(2) invalid reset_config argument (%s), defaulting to none", args[1]);
- jtag_reset_config = RESET_NONE;
- return ERROR_INVALID_ARGUMENTS;
- }
+ if (m)
+ goto next;
+
+ /* combination (options for broken wiring) */
+ m = RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
+ if (strcmp(*args, "separate") == 0)
+ /* separate reset lines - default */;
+ else if (strcmp(*args, "srst_pulls_trst") == 0)
+ tmp |= RESET_SRST_PULLS_TRST;
+ else if (strcmp(*args, "trst_pulls_srst") == 0)
+ tmp |= RESET_TRST_PULLS_SRST;
+ else if (strcmp(*args, "combined") == 0)
+ tmp |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
+ else
+ m = 0;
+ if (mask & m) {
+ LOG_ERROR("extra reset_config %s spec (%s)",
+ "combination", *args);
+ return ERROR_INVALID_ARGUMENTS;
}
- }
+ if (m)
+ goto next;
- if (argc >= 3)
- {
- if (strcmp(args[2], "trst_open_drain") == 0)
- jtag_reset_config |= RESET_TRST_OPEN_DRAIN;
- else if (strcmp(args[2], "trst_push_pull") == 0)
- jtag_reset_config &= ~RESET_TRST_OPEN_DRAIN;
+ /* trst_type (NOP without HAS_TRST) */
+ m = RESET_TRST_OPEN_DRAIN;
+ if (strcmp(*args, "trst_open_drain") == 0)
+ tmp |= RESET_TRST_OPEN_DRAIN;
+ else if (strcmp(*args, "trst_push_pull") == 0)
+ /* push/pull from adapter - default */;
else
- {
- LOG_ERROR("(3) invalid reset_config argument (%s) defaulting to none", args[2] );
- jtag_reset_config = RESET_NONE;
+ m = 0;
+ if (mask & m) {
+ LOG_ERROR("extra reset_config %s spec (%s)",
+ "trst_type", *args);
return ERROR_INVALID_ARGUMENTS;
}
- }
+ if (m)
+ goto next;
- if (argc >= 4)
- {
- if (strcmp(args[3], "srst_push_pull") == 0)
- jtag_reset_config |= RESET_SRST_PUSH_PULL;
- else if (strcmp(args[3], "srst_open_drain") == 0)
- jtag_reset_config &= ~RESET_SRST_PUSH_PULL;
+ /* srst_type (NOP without HAS_SRST) */
+ m |= RESET_SRST_PUSH_PULL;
+ if (strcmp(*args, "srst_push_pull") == 0)
+ tmp |= RESET_SRST_PUSH_PULL;
+ else if (strcmp(*args, "srst_open_drain") == 0)
+ /* open drain from adapter - default */;
else
- {
- LOG_ERROR("(4) invalid reset_config argument (%s), defaulting to none", args[3]);
- jtag_reset_config = RESET_NONE;
+ m = 0;
+ if (mask & m) {
+ LOG_ERROR("extra reset_config %s spec (%s)",
+ "srst_type", *args);
return ERROR_INVALID_ARGUMENTS;
}
+ if (m)
+ goto next;
+
+ /* caller provided nonsense; fail */
+ LOG_ERROR("unknown reset_config flag (%s)", *args);
+ return ERROR_INVALID_ARGUMENTS;
+
+next:
+ /* Remember the bits which were specified (mask)
+ * and their new values (new_cfg).
+ */
+ mask |= m;
+ new_cfg |= tmp;
}
+ /* clear previous values of those bits, save new values */
+ jtag_reset_config &= ~mask;
+ jtag_reset_config |= new_cfg;
+
return ERROR_OK;
}