26 #define SWD_WAIT_TIMEOUT 500
60 #define CLOCK_IDLE() 0
75 for (i = skip; i < tms_count; i++) {
76 tms = (tms_scan >> i) & 1;
95 unsigned int num_bits =
cmd->cmd.tms->num_bits;
96 const uint8_t *
bits =
cmd->cmd.tms->bits;
101 for (
unsigned int i = 0; i < num_bits; i++) {
102 tms = ((
bits[i/8] >> (i % 8)) & 1);
116 unsigned int num_states =
cmd->num_states;
127 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
162 for (
unsigned int i = 0; i < num_cycles; i++) {
185 for (
unsigned int i = 0; i < num_cycles; i++) {
196 unsigned int scan_size)
199 unsigned int bit_cnt;
215 for (bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
216 int tms = (bit_cnt == scan_size-1) ? 1 : 0;
218 int bytec = bit_cnt/8;
219 int bcval = 1 << (bit_cnt % 8);
256 bit_cnt == scan_size - 1)) {
257 for (
unsigned int i = bit_cnt + 1 - buffered; i <= bit_cnt; i++) {
260 buffer[i/8] &= ~(1 << (i % 8));
263 buffer[i/8] |= 1 << (i % 8);
302 LOG_ERROR(
"BUG: Bitbang interface called, but not yet initialized");
320 cmd->cmd.runtest->num_cycles,
344 cmd->cmd.pathmove->num_states,
353 (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR",
374 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
402 for (
unsigned int i =
offset; i < bit_cnt +
offset; i++) {
404 int bcval = 1 << (i % 8);
405 int swdio = !rnw && (buf[bytec] & bcval);
413 buf[bytec] &= ~bcval;
457 LOG_ERROR(
"Sequence %d not supported", seq);
480 for (
unsigned int retry = 0;; retry++) {
481 uint8_t trn_ack_data_parity_trn[
DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)];
490 int ack =
buf_get_u32(trn_ack_data_parity_trn, 1, 3);
491 uint32_t data =
buf_get_u32(trn_ack_data_parity_trn, 1 + 3, 32);
496 "%s %s read reg %X = %08" PRIx32,
510 LOG_DEBUG(
"SWD WAIT: retried %u times", retry);
545 uint8_t trn_ack_data_parity_trn[
DIV_ROUND_UP(4 + 3 + 32 + 1 + 4, 8)] = {0};
546 for (
unsigned int retry = 0;; retry++) {
547 buf_set_u32(trn_ack_data_parity_trn, 1 + 3 + 1, 32, value);
570 int ack =
buf_get_u32(trn_ack_data_parity_trn, 1, 3);
573 "%s%s %s write reg %X = %08" PRIx32,
574 check_ack ?
"" :
"ack ignored ",
578 buf_get_u32(trn_ack_data_parity_trn, 1 + 3 + 1, 32));
589 LOG_DEBUG(
"SWD WAIT: retried %u times", retry);
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int 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 int first, unsigned int 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_stableclocks(unsigned int num_cycles)
Function bitbang_stableclocks issues a number of clock cycles while staying in a stable state.
static int bitbang_path_move(struct pathmove_command *cmd)
static int bitbang_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, unsigned int scan_size)
static int bitbang_swd_init(void)
static void bitbang_swd_exchange(bool rnw, uint8_t buf[], unsigned int offset, unsigned int bit_cnt)
static int bitbang_runtest(unsigned int num_cycles)
static void bitbang_end_state(tap_state_t state)
static void bitbang_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
static int bitbang_swd_switch_seq(enum swd_special_seq seq)
static void swd_clear_sticky_errors(void)
int bitbang_execute_queue(struct jtag_command *cmd_queue)
const struct swd_driver bitbang_swd
static void bitbang_sleep(unsigned int microseconds)
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)
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 structure, indicating whether the command has the host scan in fr...
@ 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)
The JTAG interface can be implemented with a software or hardware fifo.
#define ERROR_JTAG_QUEUE_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
void alive_sleep(uint64_t ms)
#define LOG_CUSTOM_LEVEL(level, expr ...)
#define LOG_DEBUG_IO(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
Low level callbacks (for bitbang).
int(* sleep)(unsigned int microseconds)
Sleep for some number of microseconds.
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(* flush)(void)
Force a flush.
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.
int(* blink)(bool on)
Blink led (optional).
size_t buf_size
The number of TDO samples that can be buffered up before the caller has to call read_sample.
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
static const unsigned int swd_seq_dormant_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 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 int swd_seq_jtag_to_swd_len
static const unsigned int swd_seq_line_reset_len
static const unsigned int swd_seq_dormant_to_jtag_len
static const unsigned int swd_seq_swd_to_dormant_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
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 unsigned int swd_seq_swd_to_jtag_len
static const unsigned int swd_seq_jtag_to_dormant_len
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)