X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fjtag%2Fdrivers%2Fftdi.c;h=5e7eae073fa4d3a405c85a8851b6c1c5470652e0;hb=4cb3c9fae2a6a6cb5cf2c664179edace22abf5f6;hp=e69707e5a70ee31236b1b010ef9908b2f5af49f2;hpb=1003bc7be7c471d28794280be69632c5f074789f;p=openocd.git diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index e69707e5a7..5e7eae073f 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -53,11 +53,11 @@ * * This code uses information contained in the MPSSE specification which was * found here: - * http://www.ftdichip.com/Documents/AppNotes/AN2232C-01_MPSSE_Cmnd.pdf + * https://www.ftdichip.com/Support/Documents/AppNotes/AN2232C-01_MPSSE_Cmnd.pdf * Hereafter this is called the "MPSSE Spec". * - * The datasheet for the ftdichip.com's FT2232D part is here: - * http://www.ftdichip.com/Documents/DataSheets/DS_FT2232D.pdf + * The datasheet for the ftdichip.com's FT2232H part is here: + * https://www.ftdichip.com/Support/Documents/DataSheets/ICs/DS_FT2232H.pdf * * Also note the issue with code 0x4b (clock data to TMS) noted in * http://developer.intra2net.com/mailarchive/html/libftdi/2009/msg00292.html @@ -69,10 +69,12 @@ #endif /* project specific includes */ +#include #include #include #include #include +#include #if IS_CYGWIN == 1 #include @@ -89,7 +91,6 @@ static char *ftdi_device_desc; static char *ftdi_serial; -static char *ftdi_location; static uint8_t ftdi_channel; static uint8_t ftdi_jtag_mode = JTAG_MODE; @@ -149,11 +150,11 @@ static struct signal *create_signal(const char *name) psig = &(*psig)->next; *psig = calloc(1, sizeof(**psig)); - if (*psig == NULL) + if (!*psig) return NULL; (*psig)->name = strdup(name); - if ((*psig)->name == NULL) { + if (!(*psig)->name) { free(*psig); *psig = NULL; } @@ -213,7 +214,7 @@ static int ftdi_set_signal(const struct signal *s, char value) return ERROR_OK; } -static int ftdi_get_signal(const struct signal *s, uint16_t * value_out) +static int ftdi_get_signal(const struct signal *s, uint16_t *value_out) { uint8_t data_low = 0; uint8_t data_high = 0; @@ -262,7 +263,7 @@ static void move_to_state(tap_state_t goal_state) int tms_count = tap_get_tms_path_len(start_state, goal_state); assert(tms_count <= 8); - DEBUG_JTAG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state)); + LOG_DEBUG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state)); /* Track state transitions step by step */ for (int i = 0; i < tms_count; i++) @@ -288,7 +289,7 @@ static int ftdi_speed(int speed) if (!swd_mode && speed >= 10000000 && ftdi_jtag_mode != JTAG_MODE_ALT) LOG_INFO("ftdi: if you experience problems at higher adapter clocks, try " - "the command \"ftdi_tdo_sample_edge falling\""); + "the command \"ftdi tdo_sample_edge falling\""); return ERROR_OK; } @@ -324,7 +325,7 @@ static void ftdi_execute_runtest(struct jtag_command *cmd) int i; uint8_t zero = 0; - DEBUG_JTAG_IO("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state)); @@ -345,14 +346,14 @@ static void ftdi_execute_runtest(struct jtag_command *cmd) if (tap_get_state() != tap_get_end_state()) move_to_state(tap_get_end_state()); - DEBUG_JTAG_IO("runtest: %i, end in %s", + LOG_DEBUG_IO("runtest: %i, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(tap_get_end_state())); } static void ftdi_execute_statemove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state)); ftdi_end_state(cmd->cmd.statemove->end_state); @@ -368,7 +369,7 @@ static void ftdi_execute_statemove(struct jtag_command *cmd) */ static void ftdi_execute_tms(struct jtag_command *cmd) { - DEBUG_JTAG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); + LOG_DEBUG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); /* TODO: Missing tap state tracking, also missing from ft2232.c! */ mpsse_clock_tms_cs_out(mpsse_ctx, @@ -384,7 +385,7 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) tap_state_t *path = cmd->cmd.pathmove->path; int num_states = cmd->cmd.pathmove->num_states; - DEBUG_JTAG_IO("pathmove: %i states, current: %s end: %s", num_states, + LOG_DEBUG_IO("pathmove: %i states, current: %s end: %s", num_states, tap_state_name(tap_get_state()), tap_state_name(path[num_states-1])); @@ -392,7 +393,7 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) unsigned bit_count = 0; uint8_t tms_byte = 0; - DEBUG_JTAG_IO("-"); + LOG_DEBUG_IO("-"); /* this loop verifies that the path is legal and logs each state in the path */ while (num_states--) { @@ -432,18 +433,18 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) static void ftdi_execute_scan(struct jtag_command *cmd) { - DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", + LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", jtag_scan_type(cmd->cmd.scan)); /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */ while (cmd->cmd.scan->num_fields > 0 && cmd->cmd.scan->fields[cmd->cmd.scan->num_fields - 1].num_bits == 0) { cmd->cmd.scan->num_fields--; - LOG_DEBUG("discarding trailing empty field"); + LOG_DEBUG_IO("discarding trailing empty field"); } if (cmd->cmd.scan->num_fields == 0) { - LOG_DEBUG("empty scan, doing nothing"); + LOG_DEBUG_IO("empty scan, doing nothing"); return; } @@ -462,7 +463,7 @@ static void ftdi_execute_scan(struct jtag_command *cmd) for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) { scan_size += field->num_bits; - DEBUG_JTAG_IO("%s%s field %d/%d %d bits", + LOG_DEBUG_IO("%s%s field %d/%d %d bits", field->in_value ? "in" : "", field->out_value ? "out" : "", i, @@ -482,7 +483,11 @@ static void ftdi_execute_scan(struct jtag_command *cmd) uint8_t last_bit = 0; if (field->out_value) bit_copy(&last_bit, 0, field->out_value, field->num_bits - 1, 1); - uint8_t tms_bits = 0x01; + + /* If endstate is TAP_IDLE, clock out 1-1-0 (->EXIT1 ->UPDATE ->IDLE) + * Otherwise, clock out 1-0 (->EXIT1 ->PAUSE) + */ + uint8_t tms_bits = 0x03; mpsse_clock_tms_cs(mpsse_ctx, &tms_bits, 0, @@ -492,13 +497,24 @@ static void ftdi_execute_scan(struct jtag_command *cmd) last_bit, ftdi_jtag_mode); tap_set_state(tap_state_transition(tap_get_state(), 1)); - mpsse_clock_tms_cs_out(mpsse_ctx, - &tms_bits, - 1, - 1, - last_bit, - ftdi_jtag_mode); - tap_set_state(tap_state_transition(tap_get_state(), 0)); + if (tap_get_end_state() == TAP_IDLE) { + mpsse_clock_tms_cs_out(mpsse_ctx, + &tms_bits, + 1, + 2, + last_bit, + ftdi_jtag_mode); + tap_set_state(tap_state_transition(tap_get_state(), 1)); + tap_set_state(tap_state_transition(tap_get_state(), 0)); + } else { + mpsse_clock_tms_cs_out(mpsse_ctx, + &tms_bits, + 2, + 1, + last_bit, + ftdi_jtag_mode); + tap_set_state(tap_state_transition(tap_get_state(), 0)); + } } else mpsse_clock_data(mpsse_ctx, field->out_value, @@ -512,60 +528,56 @@ static void ftdi_execute_scan(struct jtag_command *cmd) if (tap_get_state() != tap_get_end_state()) move_to_state(tap_get_end_state()); - DEBUG_JTAG_IO("%s scan, %i bits, end in %s", + LOG_DEBUG_IO("%s scan, %i bits, end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(tap_get_end_state())); } -static void ftdi_execute_reset(struct jtag_command *cmd) +static int ftdi_reset(int trst, int srst) { - DEBUG_JTAG_IO("reset trst: %i srst %i", - cmd->cmd.reset->trst, cmd->cmd.reset->srst); - - if (cmd->cmd.reset->trst == 1 - || (cmd->cmd.reset->srst - && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) - tap_set_state(TAP_RESET); - - struct signal *trst = find_signal_by_name("nTRST"); - if (cmd->cmd.reset->trst == 1) { - if (trst) - ftdi_set_signal(trst, '0'); - else - LOG_ERROR("Can't assert TRST: nTRST signal is not defined"); - } else if (trst && jtag_get_reset_config() & RESET_HAS_TRST && - cmd->cmd.reset->trst == 0) { - if (jtag_get_reset_config() & RESET_TRST_OPEN_DRAIN) - ftdi_set_signal(trst, 'z'); - else - ftdi_set_signal(trst, '1'); + struct signal *sig_ntrst = find_signal_by_name("nTRST"); + struct signal *sig_nsrst = find_signal_by_name("nSRST"); + + LOG_DEBUG_IO("reset trst: %i srst %i", trst, srst); + + if (!swd_mode) { + if (trst == 1) { + if (sig_ntrst) + ftdi_set_signal(sig_ntrst, '0'); + else + LOG_ERROR("Can't assert TRST: nTRST signal is not defined"); + } else if (sig_ntrst && jtag_get_reset_config() & RESET_HAS_TRST && + trst == 0) { + if (jtag_get_reset_config() & RESET_TRST_OPEN_DRAIN) + ftdi_set_signal(sig_ntrst, 'z'); + else + ftdi_set_signal(sig_ntrst, '1'); + } } - struct signal *srst = find_signal_by_name("nSRST"); - if (cmd->cmd.reset->srst == 1) { - if (srst) - ftdi_set_signal(srst, '0'); + if (srst == 1) { + if (sig_nsrst) + ftdi_set_signal(sig_nsrst, '0'); else LOG_ERROR("Can't assert SRST: nSRST signal is not defined"); - } else if (srst && jtag_get_reset_config() & RESET_HAS_SRST && - cmd->cmd.reset->srst == 0) { + } else if (sig_nsrst && jtag_get_reset_config() & RESET_HAS_SRST && + srst == 0) { if (jtag_get_reset_config() & RESET_SRST_PUSH_PULL) - ftdi_set_signal(srst, '1'); + ftdi_set_signal(sig_nsrst, '1'); else - ftdi_set_signal(srst, 'z'); + ftdi_set_signal(sig_nsrst, 'z'); } - DEBUG_JTAG_IO("trst: %i, srst: %i", - cmd->cmd.reset->trst, cmd->cmd.reset->srst); + return mpsse_flush(mpsse_ctx); } static void ftdi_execute_sleep(struct jtag_command *cmd) { - DEBUG_JTAG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us); mpsse_flush(mpsse_ctx); jtag_sleep(cmd->cmd.sleep->us); - DEBUG_JTAG_IO("sleep %" PRIi32 " usec while in %s", + LOG_DEBUG_IO("sleep %" PRIu32 " usec while in %s", cmd->cmd.sleep->us, tap_state_name(tap_get_state())); } @@ -589,7 +601,7 @@ static void ftdi_execute_stableclocks(struct jtag_command *cmd) num_cycles -= this_len; } - DEBUG_JTAG_IO("clocks %i while in %s", + LOG_DEBUG_IO("clocks %i while in %s", cmd->cmd.stableclocks->num_cycles, tap_state_name(tap_get_state())); } @@ -597,9 +609,6 @@ static void ftdi_execute_stableclocks(struct jtag_command *cmd) static void ftdi_execute_command(struct jtag_command *cmd) { switch (cmd->type) { - case JTAG_RESET: - ftdi_execute_reset(cmd); - break; case JTAG_RUNTEST: ftdi_execute_runtest(cmd); break; @@ -656,9 +665,14 @@ static int ftdi_initialize(void) else LOG_DEBUG("ftdi interface using shortest path jtag state transitions"); + if (!ftdi_vid[0] && !ftdi_pid[0]) { + LOG_ERROR("Please specify ftdi vid_pid"); + return ERROR_JTAG_INIT_FAILED; + } + for (int i = 0; ftdi_vid[i] || ftdi_pid[i]; i++) { mpsse_ctx = mpsse_open(&ftdi_vid[i], &ftdi_pid[i], ftdi_device_desc, - ftdi_serial, ftdi_location, ftdi_channel); + ftdi_serial, adapter_usb_get_location(), ftdi_channel); if (mpsse_ctx) break; } @@ -694,6 +708,17 @@ static int ftdi_quit(void) { mpsse_close(mpsse_ctx); + struct signal *sig = signals; + while (sig) { + struct signal *next = sig->next; + free((void *)sig->name); + free(sig); + sig = next; + } + + free(ftdi_device_desc); + free(ftdi_serial); + free(swd_cmd_queue); return ERROR_OK; @@ -702,11 +727,10 @@ static int ftdi_quit(void) COMMAND_HANDLER(ftdi_handle_device_desc_command) { if (CMD_ARGC == 1) { - if (ftdi_device_desc) - free(ftdi_device_desc); + free(ftdi_device_desc); ftdi_device_desc = strdup(CMD_ARGV[0]); } else { - LOG_ERROR("expected exactly one argument to ftdi_device_desc "); + LOG_ERROR("expected exactly one argument to ftdi device_desc "); } return ERROR_OK; @@ -715,8 +739,7 @@ COMMAND_HANDLER(ftdi_handle_device_desc_command) COMMAND_HANDLER(ftdi_handle_serial_command) { if (CMD_ARGC == 1) { - if (ftdi_serial) - free(ftdi_serial); + free(ftdi_serial); ftdi_serial = strdup(CMD_ARGV[0]); } else { return ERROR_COMMAND_SYNTAX_ERROR; @@ -725,21 +748,6 @@ COMMAND_HANDLER(ftdi_handle_serial_command) return ERROR_OK; } -#ifdef HAVE_LIBUSB_GET_PORT_NUMBERS -COMMAND_HANDLER(ftdi_handle_location_command) -{ - if (CMD_ARGC == 1) { - if (ftdi_location) - free(ftdi_location); - ftdi_location = strdup(CMD_ARGV[0]); - } else { - return ERROR_COMMAND_SYNTAX_ERROR; - } - - return ERROR_OK; -} -#endif - COMMAND_HANDLER(ftdi_handle_channel_command) { if (CMD_ARGC == 1) @@ -889,12 +897,12 @@ COMMAND_HANDLER(ftdi_handle_get_signal_command) COMMAND_HANDLER(ftdi_handle_vid_pid_command) { if (CMD_ARGC > MAX_USB_IDS * 2) { - LOG_WARNING("ignoring extra IDs in ftdi_vid_pid " + LOG_WARNING("ignoring extra IDs in ftdi vid_pid " "(maximum is %d pairs)", MAX_USB_IDS); CMD_ARGC = MAX_USB_IDS * 2; } if (CMD_ARGC < 2 || (CMD_ARGC & 1)) { - LOG_WARNING("incomplete ftdi_vid_pid configuration directive"); + LOG_WARNING("incomplete ftdi vid_pid configuration directive"); if (CMD_ARGC < 2) return ERROR_COMMAND_SYNTAX_ERROR; /* remove the incomplete trailing id */ @@ -909,7 +917,7 @@ COMMAND_HANDLER(ftdi_handle_vid_pid_command) /* * Explicitly terminate, in case there are multiples instances of - * ftdi_vid_pid. + * ftdi vid_pid. */ ftdi_vid[i >> 1] = ftdi_pid[i >> 1] = 0; @@ -918,60 +926,51 @@ COMMAND_HANDLER(ftdi_handle_vid_pid_command) COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command) { - Jim_Nvp *n; - static const Jim_Nvp nvp_ftdi_jtag_modes[] = { + struct jim_nvp *n; + static const struct jim_nvp nvp_ftdi_jtag_modes[] = { { .name = "rising", .value = JTAG_MODE }, { .name = "falling", .value = JTAG_MODE_ALT }, { .name = NULL, .value = -1 }, }; if (CMD_ARGC > 0) { - n = Jim_Nvp_name2value_simple(nvp_ftdi_jtag_modes, CMD_ARGV[0]); - if (n->name == NULL) + n = jim_nvp_name2value_simple(nvp_ftdi_jtag_modes, CMD_ARGV[0]); + if (!n->name) return ERROR_COMMAND_SYNTAX_ERROR; ftdi_jtag_mode = n->value; } - n = Jim_Nvp_value2name_simple(nvp_ftdi_jtag_modes, ftdi_jtag_mode); - command_print(CMD_CTX, "ftdi samples TDO on %s edge of TCK", n->name); + n = jim_nvp_value2name_simple(nvp_ftdi_jtag_modes, ftdi_jtag_mode); + command_print(CMD, "ftdi samples TDO on %s edge of TCK", n->name); return ERROR_OK; } -static const struct command_registration ftdi_command_handlers[] = { +static const struct command_registration ftdi_subcommand_handlers[] = { { - .name = "ftdi_device_desc", + .name = "device_desc", .handler = &ftdi_handle_device_desc_command, .mode = COMMAND_CONFIG, .help = "set the USB device description of the FTDI device", .usage = "description_string", }, { - .name = "ftdi_serial", + .name = "serial", .handler = &ftdi_handle_serial_command, .mode = COMMAND_CONFIG, .help = "set the serial number of the FTDI device", .usage = "serial_string", }, -#ifdef HAVE_LIBUSB_GET_PORT_NUMBERS - { - .name = "ftdi_location", - .handler = &ftdi_handle_location_command, - .mode = COMMAND_CONFIG, - .help = "set the USB bus location of the FTDI device", - .usage = ":port[,port]...", - }, -#endif { - .name = "ftdi_channel", + .name = "channel", .handler = &ftdi_handle_channel_command, .mode = COMMAND_CONFIG, .help = "set the channel of the FTDI device that is used as JTAG", .usage = "(0-3)", }, { - .name = "ftdi_layout_init", + .name = "layout_init", .handler = &ftdi_handle_layout_init_command, .mode = COMMAND_CONFIG, .help = "initialize the FTDI GPIO signals used " @@ -979,7 +978,7 @@ static const struct command_registration ftdi_command_handlers[] = { .usage = "data direction", }, { - .name = "ftdi_layout_signal", + .name = "layout_signal", .handler = &ftdi_handle_layout_signal_command, .mode = COMMAND_ANY, .help = "define a signal controlled by one or more FTDI GPIO as data " @@ -987,28 +986,28 @@ static const struct command_registration ftdi_command_handlers[] = { .usage = "name [-data mask|-ndata mask] [-oe mask|-noe mask] [-alias|-nalias name]", }, { - .name = "ftdi_set_signal", + .name = "set_signal", .handler = &ftdi_handle_set_signal_command, .mode = COMMAND_EXEC, .help = "control a layout-specific signal", .usage = "name (1|0|z)", }, { - .name = "ftdi_get_signal", + .name = "get_signal", .handler = &ftdi_handle_get_signal_command, .mode = COMMAND_EXEC, .help = "read the value of a layout-specific signal", .usage = "name", }, { - .name = "ftdi_vid_pid", + .name = "vid_pid", .handler = &ftdi_handle_vid_pid_command, .mode = COMMAND_CONFIG, .help = "the vendor ID and product ID of the FTDI device", - .usage = "(vid pid)* ", + .usage = "(vid pid)*", }, { - .name = "ftdi_tdo_sample_edge", + .name = "tdo_sample_edge", .handler = &ftdi_handle_tdo_sample_edge_command, .mode = COMMAND_ANY, .help = "set which TCK clock edge is used for sampling TDO " @@ -1019,6 +1018,17 @@ static const struct command_registration ftdi_command_handlers[] = { COMMAND_REGISTRATION_DONE }; +static const struct command_registration ftdi_command_handlers[] = { + { + .name = "ftdi", + .mode = COMMAND_ANY, + .help = "perform ftdi management", + .chain = ftdi_subcommand_handlers, + .usage = "", + }, + COMMAND_REGISTRATION_DONE +}; + static int create_default_signal(const char *name, uint16_t data_mask) { struct signal *sig = create_signal(name); @@ -1058,7 +1068,7 @@ static int ftdi_swd_init(void) swd_cmd_queue_alloced = 10; swd_cmd_queue = malloc(swd_cmd_queue_alloced * sizeof(*swd_cmd_queue)); - return swd_cmd_queue != NULL ? ERROR_OK : ERROR_FAIL; + return swd_cmd_queue ? ERROR_OK : ERROR_FAIL; } static void ftdi_swd_swdio_en(bool enable) @@ -1068,7 +1078,7 @@ static void ftdi_swd_swdio_en(bool enable) if (oe->data_mask) ftdi_set_signal(oe, enable ? '1' : '0'); else { - /* Sets TDI/DO pin (pin 2) to input during rx when both pins are connected + /* Sets TDI/DO pin to input during rx when both pins are connected to SWDIO */ if (enable) direction |= jtag_direction_init & 0x0002U; @@ -1081,7 +1091,6 @@ static void ftdi_swd_swdio_en(bool enable) /** * Flush the MPSSE queue and process the SWD transaction queue - * @param dap * @return */ static int ftdi_swd_run_queue(void) @@ -1114,17 +1123,17 @@ static int ftdi_swd_run_queue(void) LOG_DEBUG_IO("%s %s %s reg %X = %08"PRIx32, ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK", - swd_cmd_queue[i].cmd & SWD_CMD_APnDP ? "AP" : "DP", - swd_cmd_queue[i].cmd & SWD_CMD_RnW ? "read" : "write", + swd_cmd_queue[i].cmd & SWD_CMD_APNDP ? "AP" : "DP", + swd_cmd_queue[i].cmd & SWD_CMD_RNW ? "read" : "write", (swd_cmd_queue[i].cmd & SWD_CMD_A32) >> 1, buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, - 1 + 3 + (swd_cmd_queue[i].cmd & SWD_CMD_RnW ? 0 : 1), 32)); + 1 + 3 + (swd_cmd_queue[i].cmd & SWD_CMD_RNW ? 0 : 1), 32)); if (ack != SWD_ACK_OK) { queued_retval = ack == SWD_ACK_WAIT ? ERROR_WAIT : ERROR_FAIL; goto skip; - } else if (swd_cmd_queue[i].cmd & SWD_CMD_RnW) { + } else if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) { uint32_t data = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3, 32); int parity = buf_get_u32(swd_cmd_queue[i].trn_ack_data_parity_trn, 1 + 3 + 32, 1); @@ -1134,7 +1143,7 @@ static int ftdi_swd_run_queue(void) goto skip; } - if (swd_cmd_queue[i].dst != NULL) + if (swd_cmd_queue[i].dst) *swd_cmd_queue[i].dst = data; } } @@ -1159,7 +1168,7 @@ static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32 * pointers into the queue which may be invalid after the realloc. */ queued_retval = ftdi_swd_run_queue(); struct swd_cmd_queue_entry *q = realloc(swd_cmd_queue, swd_cmd_queue_alloced * 2 * sizeof(*swd_cmd_queue)); - if (q != NULL) { + if (q) { swd_cmd_queue = q; swd_cmd_queue_alloced *= 2; LOG_DEBUG("Increased SWD command queue to %zu elements", swd_cmd_queue_alloced); @@ -1174,7 +1183,7 @@ static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32 mpsse_clock_data_out(mpsse_ctx, &swd_cmd_queue[i].cmd, 0, 8, SWD_MODE); - if (swd_cmd_queue[i].cmd & SWD_CMD_RnW) { + if (swd_cmd_queue[i].cmd & SWD_CMD_RNW) { /* Queue a read transaction */ swd_cmd_queue[i].dst = dst; @@ -1199,31 +1208,23 @@ static void ftdi_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32 } /* Insert idle cycles after AP accesses to avoid WAIT */ - if (cmd & SWD_CMD_APnDP) + if (cmd & SWD_CMD_APNDP) mpsse_clock_data_out(mpsse_ctx, NULL, 0, ap_delay_clk, SWD_MODE); } static void ftdi_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk) { - assert(cmd & SWD_CMD_RnW); + assert(cmd & SWD_CMD_RNW); ftdi_swd_queue_cmd(cmd, value, 0, ap_delay_clk); } static void ftdi_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk) { - assert(!(cmd & SWD_CMD_RnW)); + assert(!(cmd & SWD_CMD_RNW)); ftdi_swd_queue_cmd(cmd, NULL, value, ap_delay_clk); } -static int_least32_t ftdi_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - freq = mpsse_set_frequency(mpsse_ctx, hz); - - return freq; -} - static int ftdi_swd_switch_seq(enum swd_special_seq seq) { switch (seq) { @@ -1252,7 +1253,6 @@ static int ftdi_swd_switch_seq(enum swd_special_seq seq) static const struct swd_driver ftdi_swd = { .init = ftdi_swd_init, - .frequency = ftdi_swd_frequency, .switch_seq = ftdi_swd_switch_seq, .read_reg = ftdi_swd_read_reg, .write_reg = ftdi_swd_write_reg, @@ -1261,17 +1261,23 @@ static const struct swd_driver ftdi_swd = { static const char * const ftdi_transports[] = { "jtag", "swd", NULL }; -struct jtag_interface ftdi_interface = { - .name = "ftdi", +static struct jtag_interface ftdi_interface = { .supported = DEBUG_CAP_TMS_SEQ, - .commands = ftdi_command_handlers, + .execute_queue = ftdi_execute_queue, +}; + +struct adapter_driver ftdi_adapter_driver = { + .name = "ftdi", .transports = ftdi_transports, - .swd = &ftdi_swd, + .commands = ftdi_command_handlers, .init = ftdi_initialize, .quit = ftdi_quit, + .reset = ftdi_reset, .speed = ftdi_speed, - .speed_div = ftdi_speed_div, .khz = ftdi_khz, - .execute_queue = ftdi_execute_queue, + .speed_div = ftdi_speed_div, + + .jtag_ops = &ftdi_interface, + .swd_ops = &ftdi_swd, };