X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fjtag%2Fdrivers%2Fnulink_usb.c;h=0bb5ec4443541ee65c80e5bc196ba3340a898778;hb=5be78fafa9b7c9354956fa72c69dbb82338f6e4a;hp=00738ee4ee2470c5eb715b834ce46c0c3817e321;hpb=be631eed16bd9ef2b735fd64650ca7283d2ca361;p=fw%2Fopenocd diff --git a/src/jtag/drivers/nulink_usb.c b/src/jtag/drivers/nulink_usb.c index 00738ee4e..0bb5ec444 100644 --- a/src/jtag/drivers/nulink_usb.c +++ b/src/jtag/drivers/nulink_usb.c @@ -1,19 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + /*************************************************************************** * Copyright (C) 2016-2017 by Nuvoton * * Zale Yu * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * 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 . * ***************************************************************************/ #ifdef HAVE_CONFIG_H @@ -22,6 +11,7 @@ /* project specific includes */ #include +#include #include #include #include @@ -32,7 +22,9 @@ #include -#define NULINK_READ_TIMEOUT 1000 +#include "libusb_helper.h" + +#define NULINK_READ_TIMEOUT LIBUSB_TIMEOUT_MS #define NULINK_HID_MAX_SIZE (64) #define NULINK2_HID_MAX_SIZE (1024) @@ -253,7 +245,7 @@ static int nulink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val) { struct nulink_usb_handle_s *h = handle; - LOG_DEBUG("nulink_usb_write_debug_reg 0x%08" PRIX32 "0x%08" PRIX32, addr, val); + LOG_DEBUG("nulink_usb_write_debug_reg 0x%08" PRIX32 " 0x%08" PRIX32, addr, val); nulink_usb_init_buffer(handle, 8 + 12 * 1); /* set command ID */ @@ -503,7 +495,7 @@ static int nulink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, aligned_addr = aligned_addr * 4; offset = addr - aligned_addr; LOG_DEBUG("nulink_usb_read_mem8: unaligned address addr 0x%08" PRIx32 - "/aligned addr 0x%08" PRIx32 "offset %" PRIu32, + "/aligned addr 0x%08" PRIx32 " offset %" PRIu32, addr, aligned_addr, offset); addr = aligned_addr; @@ -844,11 +836,11 @@ static int nulink_usb_read_mem(void *handle, uint32_t addr, uint32_t size, /* the nulink only supports 8/32bit memory read/writes * honour 32bit, all others will be handled as 8bit access */ if (size == 4) { - /* When in jtag mode the nulink uses the auto-increment functinality. + /* When in jtag mode the nulink uses the auto-increment functionality. * However it expects us to pass the data correctly, this includes * alignment and any page boundaries. We already do this as part of the * adi_v5 implementation, but the nulink is a hla adapter and so this - * needs implementiong manually. + * needs implementing manually. * currently this only affects jtag mode, they do single * access in SWD mode - but this may change and so we do it for both modes */ @@ -909,11 +901,11 @@ static int nulink_usb_write_mem(void *handle, uint32_t addr, uint32_t size, /* the nulink only supports 8/32bit memory read/writes * honour 32bit, all others will be handled as 8bit access */ if (size == 4) { - /* When in jtag mode the nulink uses the auto-increment functinality. + /* When in jtag mode the nulink uses the auto-increment functionality. * However it expects us to pass the data correctly, this includes * alignment and any page boundaries. We already do this as part of the * adi_v5 implementation, but the nulink is a hla adapter and so this - * needs implementiong manually. + * needs implementing manually. * currently this only affects jtag mode, do single * access in SWD mode - but this may change and so we do it for both modes */ @@ -1054,8 +1046,9 @@ static int nulink_usb_open(struct hl_interface_param_s *param, void **fd) goto error_open; } - if (param->serial) { - size_t len = mbstowcs(NULL, param->serial, 0); + const char *serial = adapter_get_required_serial(); + if (serial) { + size_t len = mbstowcs(NULL, serial, 0); target_serial = calloc(len + 1, sizeof(wchar_t)); if (!target_serial) { @@ -1063,7 +1056,7 @@ static int nulink_usb_open(struct hl_interface_param_s *param, void **fd) goto error_open; } - if (mbstowcs(target_serial, param->serial, len + 1) == (size_t)(-1)) { + if (mbstowcs(target_serial, serial, len + 1) == (size_t)(-1)) { LOG_WARNING("unable to convert serial"); free(target_serial); target_serial = NULL;