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
This commit is contained in:
zwelch
2009-05-30 01:32:19 +00:00
parent ebcde562d9
commit d00a5cfe97
2 changed files with 146 additions and 73 deletions

View File

@@ -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 (m)
goto next;
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 (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;
/* 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
{
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)",
"combination", *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;
/* 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("(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)",
"trst_type", *args);
return ERROR_INVALID_ARGUMENTS;
}
if (m)
goto next;
/* 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
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;
}