54 #define CLOCK_IDLE() 0
69 for (i = skip; i < tms_count; i++) {
70 tms = (tms_scan >> i) & 1;
89 unsigned num_bits =
cmd->cmd.tms->num_bits;
90 const uint8_t *
bits =
cmd->cmd.tms->bits;
95 for (
unsigned i = 0; i < num_bits; i++) {
96 tms = ((
bits[i/8] >> (i % 8)) & 1);
110 int num_states =
cmd->num_states;
121 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
158 for (i = 0; i < num_cycles; i++) {
182 for (i = 0; i < num_cycles; i++) {
212 for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
213 int tms = (bit_cnt == scan_size-1) ? 1 : 0;
215 int bytec = bit_cnt/8;
216 int bcval = 1 << (bit_cnt % 8);
253 bit_cnt == scan_size - 1)) {
254 for (
unsigned i = bit_cnt + 1 - buffered; i <= bit_cnt; i++) {
257 buffer[i/8] &= ~(1 << (i % 8));
260 buffer[i/8] |= 1 << (i % 8);
290 LOG_ERROR(
"BUG: Bitbang interface called, but not yet initialized");
308 cmd->cmd.runtest->num_cycles,
332 cmd->cmd.pathmove->num_states,
341 (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR",
360 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
388 for (
unsigned int i =
offset; i < bit_cnt +
offset; i++) {
390 int bcval = 1 << (i % 8);
391 int swdio = !rnw && (buf[bytec] & bcval);
399 buf[bytec] &= ~bcval;
443 LOG_ERROR(
"Sequence %d not supported", seq);
466 uint8_t trn_ack_data_parity_trn[
DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)];
475 int ack =
buf_get_u32(trn_ack_data_parity_trn, 1, 3);
476 uint32_t data =
buf_get_u32(trn_ack_data_parity_trn, 1 + 3, 32);
519 uint8_t trn_ack_data_parity_trn[
DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)] = {0};
521 buf_set_u32(trn_ack_data_parity_trn, 1 + 3 + 1, 32, value);
532 int ack =
buf_get_u32(trn_ack_data_parity_trn, 1, 3);
535 check_ack ?
"" :
"ack ignored ",
539 buf_get_u32(trn_ack_data_parity_trn, 1 + 3 + 1, 32));
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static int bitbang_execute_tms(struct jtag_command *cmd)
Clock a bunch of TMS (or SWDIO) transitions, to change the JTAG (or SWD) state machine.
struct bitbang_interface * bitbang_interface
static int bitbang_path_move(struct pathmove_command *cmd)
int bitbang_execute_queue(void)
static int bitbang_swd_init(void)
static void bitbang_swd_exchange(bool rnw, uint8_t buf[], unsigned int offset, unsigned int bit_cnt)
static void bitbang_end_state(tap_state_t state)
static int bitbang_runtest(int num_cycles)
static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
static int bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, unsigned scan_size)
static int bitbang_swd_switch_seq(enum swd_special_seq seq)
static void swd_clear_sticky_errors(void)
static int bitbang_stableclocks(int num_cycles)
Function bitbang_stableclocks issues a number of clock cycles while staying in a stable state.
const struct swd_driver bitbang_swd
static int bitbang_state_move(int skip)
static void bitbang_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
static int bitbang_swd_run_queue(void)
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
enum scan_type jtag_scan_type(const struct scan_command *cmd)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
scan_type
The inferred type of a scan_command_s structure, indicating whether the command has the host scan in ...
@ SCAN_IN
From device to host,.
@ SCAN_OUT
From host to device,.
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
tap_state_t tap_get_end_state(void)
For more information,.
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_QUEUE_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_DEBUG_IO(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
Low level callbacks (for bitbang).
int(* swdio_read)(void)
Sample SWDIO and return the value.
int(* swd_write)(int swclk, int swdio)
Set SWCLK and SWDIO to the given value.
int(* sample)(void)
Sample TDO and put the result in a buffer.
bb_value_t(* read)(void)
Sample TDO and return the value.
bb_value_t(* read_sample)(void)
Return the next unread value from the buffer.
int(* write)(int tck, int tms, int tdi)
Set TCK, TMS, and TDI to the given values.
void(* swdio_drive)(bool on)
Set direction of SWDIO.
size_t buf_size
The number of TDO samples that can be buffered up before the caller has to call read_sample.
int(* blink)(int on)
Blink led (optional).
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
static const unsigned swd_seq_swd_to_jtag_len
static const unsigned swd_seq_jtag_to_swd_len
static const uint8_t swd_seq_dormant_to_jtag[]
Dormant-to-JTAG sequence.
static const uint8_t swd_seq_dormant_to_swd[]
Dormant-to-SWD sequence.
static const uint8_t swd_seq_jtag_to_dormant[]
JTAG-to-dormant sequence.
static const unsigned swd_seq_dormant_to_swd_len
static bool swd_cmd_returns_ack(uint8_t cmd)
Test if we can rely on ACK returned by SWD command.
static int swd_ack_to_error_code(uint8_t ack)
Convert SWD ACK value returned from DP to OpenOCD error code.
static uint8_t swd_cmd(bool is_read, bool is_ap, uint8_t regnum)
Construct a "cmd" byte, in lSB bit order, which swd_driver.read_reg() and swd_driver....
static const unsigned swd_seq_jtag_to_dormant_len
static const unsigned swd_seq_dormant_to_jtag_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
static const unsigned swd_seq_line_reset_len
static const unsigned swd_seq_swd_to_dormant_len
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
static const uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
static unsigned int parity(unsigned int v)