uint32_t us;
};
+/**
+ * Encapsulates a series of bits to be clocked out, affecting state
+ * and mode of the interface.
+ *
+ * In JTAG mode these are clocked out on TMS, using TCK. They may be
+ * used for link resets, transitioning between JTAG and SWD modes, or
+ * to implement JTAG state machine transitions (implementing pathmove
+ * or statemove operations).
+ *
+ * In SWD mode these are clocked out on SWDIO, using SWCLK, and are
+ * used for link resets and transitioning between SWD and JTAG modes.
+ */
+struct tms_command {
+ /** How many bits should be clocked out. */
+ unsigned num_bits;
+ /** The bits to clock out; the LSB is bit 0 of bits[0]. */
+ const uint8_t *bits;
+};
+
/**
* Defines a container type that hold a pointer to a JTAG command
* structure of any defined type.
*/
union jtag_command_container {
- struct scan_command* scan;
- struct statemove_command* statemove;
- struct pathmove_command* pathmove;
- struct runtest_command* runtest;
- struct stableclocks_command* stableclocks;
- struct reset_command* reset;
- struct end_state_command* end_state;
- struct sleep_command* sleep;
+ struct scan_command *scan;
+ struct statemove_command *statemove;
+ struct pathmove_command *pathmove;
+ struct runtest_command *runtest;
+ struct stableclocks_command *stableclocks;
+ struct reset_command *reset;
+ struct end_state_command *end_state;
+ struct sleep_command *sleep;
+ struct tms_command *tms;
};
/**
JTAG_RESET = 4,
JTAG_PATHMOVE = 6,
JTAG_SLEEP = 7,
- JTAG_STABLECLOCKS = 8
+ JTAG_STABLECLOCKS = 8,
+ JTAG_TMS = 9,
};
struct jtag_command {
jtag_notify_event(JTAG_TRST_ASSERTED);
}
+/**
+ * If supported by the underlying adapter, this clocks a raw bit sequence
+ * onto TMS for switching betwen JTAG and SWD modes.
+ *
+ * DO NOT use this to bypass the integrity checks and logging provided
+ * by the jtag_add_pathmove() and jtag_add_statemove() calls.
+ *
+ * @param nbits How many bits to clock out.
+ * @param seq The bit sequence. The LSB is bit 0 of seq[0].
+ * @param state The JTAG tap state to record on completion. Use
+ * TAP_INVALID to represent being in in SWD mode.
+ *
+ * @todo Update naming conventions to stop assuming everything is JTAG.
+ */
+int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state state)
+{
+ int retval;
+
+ if (!(jtag->supported & DEBUG_CAP_TMS_SEQ))
+ return ERROR_JTAG_NOT_IMPLEMENTED;
+
+ jtag_checks();
+ cmd_queue_cur_state = state;
+
+ retval = interface_add_tms_seq(nbits, seq);
+ jtag_set_error(retval);
+ return retval;
+}
+
void jtag_add_pathmove(int num_states, const tap_state_t *path)
{
tap_state_t cur_state = cmd_queue_cur_state;
return ERROR_OK;
}
+int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq)
+{
+ struct jtag_command *cmd;
+
+ cmd = cmd_queue_alloc(sizeof(struct jtag_command));
+ if (cmd == NULL)
+ return ERROR_FAIL;
+
+ cmd->type = JTAG_TMS;
+ cmd->cmd.tms = cmd_queue_alloc(sizeof(*cmd->cmd.tms));
+ if (!cmd->cmd.tms)
+ return ERROR_FAIL;
+
+ /* copy the bits; our caller doesn't guarantee they'll persist */
+ cmd->cmd.tms->num_bits = num_bits;
+ cmd->cmd.tms->bits = buf_cpy(seq,
+ cmd_queue_alloc(DIV_ROUND_UP(num_bits, 8)), num_bits);
+ if (!cmd->cmd.tms->bits)
+ return ERROR_FAIL;
+
+ jtag_queue_command(cmd);
+
+ return ERROR_OK;
+}
+
int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
{
/* allocate memory for a new list member */
}
#endif // _DEBUG_JTAG_IO_
+/**
+ * Represents a driver for a debugging interface.
+ *
+ * @todo Rename; perhaps "debug_driver". This isn't an interface,
+ * it's a driver! Also, not all drivers support JTAG.
+ *
+ * @todo We need a per-instance structure too, and changes to pass
+ * that structure to the driver. Instances can for example be in
+ * either SWD or JTAG modes. This will help remove globals, and
+ * eventually to cope with systems which have more than one such
+ * debugging interface.
+ */
struct jtag_interface {
/// The name of the JTAG interface driver.
char* name;
+ /**
+ * Bit vector listing capabilities exposed by this driver.
+ */
+ unsigned supported;
+#define DEBUG_CAP_TMS_SEQ (1 << 0)
+
/**
* Execute queued commands.
* @returns ERROR_OK on success, or an error code on failure.
void jtag_add_sleep(uint32_t us);
+int jtag_add_tms_seq(unsigned nbits, const uint8_t *seq, enum tap_state t);
+
/**
* Function jtag_add_clocks
* first checks that the state in which the clocks are to be issued is
/**
* Return true if it's safe for a background polling task to access the
* JTAG scan chain. Polling may be explicitly disallowed, and is also
- * unsafe while nTRST is active or the JTAG clock is gated off.,
+ * unsafe while nTRST is active or the JTAG clock is gated off.
*/
bool is_jtag_poll_safe(void);
int interface_jtag_add_pathmove(int num_states, const tap_state_t* path);
int interface_jtag_add_runtest(int num_cycles, tap_state_t endstate);
+int interface_add_tms_seq(unsigned num_bits, const uint8_t *bits);
+
/**
* This drives the actual srst and trst pins. srst will always be 0
* if jtag_reset_config & RESET_SRST_PULLS_TRST != 0 and ditto for
return ERROR_OK;
}
+int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq)
+{
+ /* synchronously do the operation here */
+
+ return ERROR_OK;
+}
+
void embeddedice_write_dcc(struct jtag_tap *tap, int reg_addr, uint8_t *buffer, int little, int count)
{
int i;
return ERROR_OK;
}
-
+int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq)
+{
+ /* FIXME just implement this, like pathmove but without
+ * JTAG-specific state transition checking. Then update
+ * zy1000_interface to report that it's supported.
+ *
+ * Eventually interface_jtag_add_pathmove() could vanish.
+ */
+ return ERROR_JTAG_NOT_IMPLEMENTED;
+}
void embeddedice_write_dcc(struct jtag_tap *tap, int reg_addr, uint8_t *buffer, int little, int count)
{