-COMMAND_HANDLER(handle_reset_config_command)
-{
- int new_cfg = 0;
- int mask = 0;
-
- /* 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 (; CMD_ARGC; CMD_ARGC--, CMD_ARGV++) {
- int tmp = 0;
- int m;
-
- /* gating */
- m = RESET_SRST_NO_GATING;
- if (strcmp(*CMD_ARGV, "srst_gates_jtag") == 0)
- /* default: don't use JTAG while SRST asserted */;
- else if (strcmp(*CMD_ARGV, "srst_nogate") == 0)
- tmp = RESET_SRST_NO_GATING;
- else
- m = 0;
- if (mask & m) {
- LOG_ERROR("extra reset_config %s spec (%s)",
- "gating", *CMD_ARGV);
- return ERROR_INVALID_ARGUMENTS;
- }
- if (m)
- goto next;
-
- /* signals */
- m = RESET_HAS_TRST | RESET_HAS_SRST;
- if (strcmp(*CMD_ARGV, "none") == 0)
- tmp = RESET_NONE;
- else if (strcmp(*CMD_ARGV, "trst_only") == 0)
- tmp = RESET_HAS_TRST;
- else if (strcmp(*CMD_ARGV, "srst_only") == 0)
- tmp = RESET_HAS_SRST;
- else if (strcmp(*CMD_ARGV, "trst_and_srst") == 0)
- tmp = RESET_HAS_TRST | RESET_HAS_SRST;
- else
- m = 0;
- if (mask & m) {
- LOG_ERROR("extra reset_config %s spec (%s)",
- "signal", *CMD_ARGV);
- return ERROR_INVALID_ARGUMENTS;
- }
- if (m)
- goto next;
-
- /* combination (options for broken wiring) */
- m = RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
- if (strcmp(*CMD_ARGV, "separate") == 0)
- /* separate reset lines - default */;
- else if (strcmp(*CMD_ARGV, "srst_pulls_trst") == 0)
- tmp |= RESET_SRST_PULLS_TRST;
- else if (strcmp(*CMD_ARGV, "trst_pulls_srst") == 0)
- tmp |= RESET_TRST_PULLS_SRST;
- else if (strcmp(*CMD_ARGV, "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", *CMD_ARGV);
- return ERROR_INVALID_ARGUMENTS;
- }
- if (m)
- goto next;
-
- /* trst_type (NOP without HAS_TRST) */
- m = RESET_TRST_OPEN_DRAIN;
- if (strcmp(*CMD_ARGV, "trst_open_drain") == 0)
- tmp |= RESET_TRST_OPEN_DRAIN;
- else if (strcmp(*CMD_ARGV, "trst_push_pull") == 0)
- /* push/pull from adapter - default */;
- else
- m = 0;
- if (mask & m) {
- LOG_ERROR("extra reset_config %s spec (%s)",
- "trst_type", *CMD_ARGV);
- return ERROR_INVALID_ARGUMENTS;
- }
- if (m)
- goto next;
-
- /* srst_type (NOP without HAS_SRST) */
- m |= RESET_SRST_PUSH_PULL;
- if (strcmp(*CMD_ARGV, "srst_push_pull") == 0)
- tmp |= RESET_SRST_PUSH_PULL;
- else if (strcmp(*CMD_ARGV, "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", *CMD_ARGV);
- return ERROR_INVALID_ARGUMENTS;
- }
- if (m)
- goto next;
-
- /* caller provided nonsense; fail */
- LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV);
- 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 */
- if (mask) {
- int old_cfg = jtag_get_reset_config();
-
- old_cfg &= ~mask;
- new_cfg |= old_cfg;
- jtag_set_reset_config(new_cfg);
- } else
- new_cfg = jtag_get_reset_config();
-
-
- /*
- * Display the (now-)current reset mode
- */
- char *modes[5];
-
- /* minimal JTAG has neither SRST nor TRST (so that's the default) */
- switch (new_cfg & (RESET_HAS_TRST | RESET_HAS_SRST)) {
- case RESET_HAS_SRST:
- modes[0] = "srst_only";
- break;
- case RESET_HAS_TRST:
- modes[0] = "trst_only";
- break;
- case RESET_TRST_AND_SRST:
- modes[0] = "trst_and_srst";
- break;
- default:
- modes[0] = "none";
- break;
- }
-
- /* normally SRST and TRST are decoupled; but bugs happen ... */
- switch (new_cfg & (RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST)) {
- case RESET_SRST_PULLS_TRST:
- modes[1] = "srst_pulls_trst";
- break;
- case RESET_TRST_PULLS_SRST:
- modes[1] = "trst_pulls_srst";
- break;
- case RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST:
- modes[1] = "combined";
- break;
- default:
- modes[1] = "separate";
- break;
- }
-
- /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
- if (new_cfg & RESET_HAS_TRST) {
- if (new_cfg & RESET_TRST_OPEN_DRAIN)
- modes[3] = " trst_open_drain";
- else
- modes[3] = " trst_push_pull";
- } else
- modes[3] = "";
-
- /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
- if (new_cfg & RESET_HAS_SRST) {
- if (new_cfg & RESET_SRST_NO_GATING)
- modes[2] = " srst_nogate";
- else
- modes[2] = " srst_gates_jtag";
-
- if (new_cfg & RESET_SRST_PUSH_PULL)
- modes[4] = " srst_push_pull";
- else
- modes[4] = " srst_open_drain";
- } else {
- modes[2] = "";
- modes[4] = "";
- }
-
- command_print(CMD_CTX, "%s %s%s%s%s",
- modes[0], modes[1],
- modes[2], modes[3], modes[4]);
-
- return ERROR_OK;
-}
-
-COMMAND_HANDLER(handle_jtag_nsrst_delay_command)
-{
- if (CMD_ARGC > 1)
- return ERROR_COMMAND_SYNTAX_ERROR;
- if (CMD_ARGC == 1)
- {
- unsigned delay;
- COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
-
- jtag_set_nsrst_delay(delay);
- }
- command_print(CMD_CTX, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
- return ERROR_OK;
-}
-