X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Fdrivers%2Fusb_blaster%2Fusb_blaster.c;h=a975bd1e28b5aeded0758ef4fd5681a0e84a99ed;hp=1a43f588f8182294576aa4471859bcda257bb301;hb=5be455a710c57bbbbd49c2d671b42098db7be5dc;hpb=87e91f4db9bea66a7866261130c6152c0304bc29 diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c b/src/jtag/drivers/usb_blaster/usb_blaster.c index 1a43f588f8..a975bd1e28 100644 --- a/src/jtag/drivers/usb_blaster/usb_blaster.c +++ b/src/jtag/drivers/usb_blaster/usb_blaster.c @@ -20,6 +20,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * */ /* @@ -144,12 +147,9 @@ struct drvs_map { }; static struct drvs_map lowlevel_drivers_map[] = { -#if BUILD_USB_BLASTER_LIBFTDI +#if BUILD_USB_BLASTER { .name = "ftdi", .drv_register = ublast_register_ftdi }, #endif -#if BUILD_USB_BLASTER_FTD2XX - { .name = "ftd2xx", .drv_register = ublast_register_ftd2xx }, -#endif #if BUILD_USB_BLASTER_2 { .name = "ublast2", .drv_register = ublast2_register_libusb }, #endif @@ -756,11 +756,41 @@ static void ublast_usleep(int us) jtag_sleep(us); } +static void ublast_initial_wipeout(void) +{ + static uint8_t tms_reset = 0xff; + uint8_t out_value; + uint32_t retlen; + int i; + + out_value = ublast_build_out(SCAN_OUT); + for (i = 0; i < BUF_LEN; i++) + info.buf[i] = out_value | ((i % 2) ? TCK : 0); + + /* + * Flush USB-Blaster queue fifos + * - empty the write FIFO (128 bytes) + * - empty the read FIFO (384 bytes) + */ + ublast_buf_write(info.buf, BUF_LEN, &retlen); + /* + * Put JTAG in RESET state (five 1 on TMS) + */ + ublast_tms_seq(&tms_reset, 5); + tap_set_state(TAP_RESET); +} + static int ublast_execute_queue(void) { struct jtag_command *cmd; + static int first_call = 1; int ret = ERROR_OK; + if (first_call) { + first_call--; + ublast_initial_wipeout(); + } + for (cmd = jtag_command_queue; ret == ERROR_OK && cmd != NULL; cmd = cmd->next) { switch (cmd->type) { @@ -801,14 +831,12 @@ static int ublast_execute_queue(void) * * Initialize the device : * - open the USB device - * - empty the write FIFO (128 bytes) - * - empty the read FIFO (384 bytes) + * - pretend it's initialized while actual init is delayed until first jtag command * * Returns ERROR_OK if USB device found, error if not. */ static int ublast_init(void) { - static uint8_t tms_reset = 0xff; int ret, i; if (info.lowlevel_name) { @@ -846,18 +874,13 @@ static int ublast_init(void) info.flags |= info.drv->flags; ret = info.drv->open(info.drv); - if (ret == ERROR_OK) { - /* - * Flush USB-Blaster queue fifos - */ - uint32_t retlen; - ublast_buf_write(info.buf, BUF_LEN, &retlen); - /* - * Put JTAG in RESET state (five 1 on TMS) - */ - ublast_tms_seq(&tms_reset, 5); - tap_set_state(TAP_RESET); - } + + /* + * Let lie here : the TAP is in an unknown state, but the first + * execute_queue() will trigger a ublast_initial_wipeout(), which will + * put the TAP in RESET. + */ + tap_set_state(TAP_RESET); return ret; } @@ -881,11 +904,10 @@ static int ublast_quit(void) COMMAND_HANDLER(ublast_handle_device_desc_command) { - if (CMD_ARGC == 1) - info.ublast_device_desc = strdup(CMD_ARGV[0]); - else - LOG_ERROR("require exactly one argument to " - "ublast_device_desc "); + if (CMD_ARGC != 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + info.ublast_device_desc = strdup(CMD_ARGV[0]); return ERROR_OK; } @@ -953,7 +975,7 @@ COMMAND_HANDLER(ublast_handle_pin_command) if (strlen(pin_value) > 1) val = '?'; - switch (tolower(val)) { + switch (tolower((unsigned char)val)) { case '0': *steer = FIXED_0; break; @@ -983,21 +1005,20 @@ COMMAND_HANDLER(ublast_handle_pin_command) COMMAND_HANDLER(ublast_handle_lowlevel_drv_command) { - if (CMD_ARGC == 1) - info.lowlevel_name = strdup(CMD_ARGV[0]); - else - LOG_ERROR("require exactly one argument to " - "usb_blaster_lowlevel_driver (ftdi|ftd2xx)"); + if (CMD_ARGC != 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + info.lowlevel_name = strdup(CMD_ARGV[0]); + return ERROR_OK; } COMMAND_HANDLER(ublast_firmware_command) { - if (CMD_ARGC == 1) - info.firmware_path = strdup(CMD_ARGV[0]); - else - LOG_ERROR("require exactly one argument to " - "ublast_firmware_command "); + if (CMD_ARGC != 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + info.firmware_path = strdup(CMD_ARGV[0]); return ERROR_OK; } @@ -1024,8 +1045,8 @@ static const struct command_registration ublast_command_handlers[] = { .name = "usb_blaster_lowlevel_driver", .handler = ublast_handle_lowlevel_drv_command, .mode = COMMAND_CONFIG, - .help = "set the lowlevel access for the USB Blaster (ftdi, ftd2xx, ublast2)", - .usage = "(ftdi|ftd2xx|ublast2)", + .help = "set the lowlevel access for the USB Blaster (ftdi, ublast2)", + .usage = "(ftdi|ublast2)", }, { .name = "usb_blaster_pin",