]> git.sur5r.net Git - openocd/commitdiff
ftd2xx: fix build warnings
authorSpencer Oliver <ntfreak@users.sourceforge.net>
Wed, 10 Aug 2011 21:23:29 +0000 (22:23 +0100)
committerSpencer Oliver <ntfreak@users.sourceforge.net>
Thu, 11 Aug 2011 20:36:54 +0000 (21:36 +0100)
Due to build warnings introduced in newer versions of ftd2xx we
use strings to report errors rather than result codes. This also
gives us the same behaviour as libftdi.

Signed-off-by: Spencer Oliver <ntfreak@users.sourceforge.net>
src/jtag/drivers/ft2232.c
src/jtag/drivers/ftd2xx_common.h [new file with mode: 0644]
src/jtag/drivers/presto.c
src/jtag/drivers/usb_blaster.c

index 3168f990100901dd638b61c86944ee670e2a4434..3cca26d92d0c8187d77aed2259917244b5c90683 100644 (file)
@@ -99,6 +99,7 @@
 /* FT2232 access library includes */
 #if BUILD_FT2232_FTD2XX == 1
 #include <ftd2xx.h>
+#include "ftd2xx_common.h"
 
 enum ftdi_interface
 {
@@ -515,7 +516,7 @@ static int ft2232_write(uint8_t* buf, int size, uint32_t* bytes_written)
        if ((status = FT_Write(ftdih, buf, size, &dw_bytes_written)) != FT_OK)
        {
                *bytes_written = dw_bytes_written;
-               LOG_ERROR("FT_Write returned: %" PRIu32, status);
+               LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
        else
@@ -558,7 +559,7 @@ static int ft2232_read(uint8_t* buf, uint32_t size, uint32_t* bytes_read)
                                          *bytes_read, &dw_bytes_read)) != FT_OK)
                {
                        *bytes_read = 0;
-                       LOG_ERROR("FT_Read returned: %" PRIu32, status);
+                       LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
                *bytes_read += dw_bytes_read;
@@ -2215,11 +2216,13 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_mor
 
                if (more)
                {
-                       LOG_WARNING("unable to open ftdi device (trying more): %" PRIu32, status);
+                       LOG_WARNING("unable to open ftdi device (trying more): %s",
+                                       ftd2xx_status_string(status));
                        *try_more = 1;
                        return ERROR_JTAG_INIT_FAILED;
                }
-               LOG_ERROR("unable to open ftdi device: %" PRIu32, status);
+               LOG_ERROR("unable to open ftdi device: %s",
+                               ftd2xx_status_string(status));
                status = FT_ListDevices(&num_devices, NULL, FT_LIST_NUMBER_ONLY);
                if (status == FT_OK)
                {
@@ -2235,7 +2238,7 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_mor
 
                        if (status == FT_OK)
                        {
-                               LOG_ERROR("ListDevices: %" PRIu32, num_devices);
+                               LOG_ERROR("ListDevices: %" PRIu32, (uint32_t)num_devices);
                                for (i = 0; i < num_devices; i++)
                                        LOG_ERROR("%" PRIu32 ": \"%s\"", i, desc_array[i]);
                        }
@@ -2254,7 +2257,8 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_mor
 
        if ((status = FT_SetLatencyTimer(ftdih, ft2232_latency)) != FT_OK)
        {
-               LOG_ERROR("unable to set latency timer: %" PRIu32, status);
+               LOG_ERROR("unable to set latency timer: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
@@ -2263,10 +2267,11 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_mor
                /* ftd2xx 1.04 (linux) has a bug when calling FT_GetLatencyTimer
                 * so ignore errors if using this driver version */
                DWORD dw_version;
-               
+
                status = FT_GetDriverVersion(ftdih, &dw_version);
-               LOG_ERROR("unable to get latency timer: %" PRIu32, status);
-               
+               LOG_ERROR("unable to get latency timer: %s",
+                               ftd2xx_status_string(status));
+
                if ((status == FT_OK) && (dw_version == 0x10004)) {
                        LOG_ERROR("ftd2xx 1.04 detected - this has known issues " \
                                        "with FT_GetLatencyTimer, upgrade to a newer version");
@@ -2282,19 +2287,22 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_mor
 
        if ((status = FT_SetTimeouts(ftdih, 5000, 5000)) != FT_OK)
        {
-               LOG_ERROR("unable to set timeouts: %" PRIu32, status);
+               LOG_ERROR("unable to set timeouts: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
        if ((status = FT_SetBitMode(ftdih, 0x0b, 2)) != FT_OK)
        {
-               LOG_ERROR("unable to enable bit i/o mode: %" PRIu32, status);
+               LOG_ERROR("unable to enable bit i/o mode: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
        if ((status = FT_GetDeviceInfo(ftdih, &ftdi_device, &deviceID, SerialNumber, Description, NULL)) != FT_OK)
        {
-               LOG_ERROR("unable to get FT_GetDeviceInfo: %" PRIu32, status);
+               LOG_ERROR("unable to get FT_GetDeviceInfo: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
        else
@@ -2304,8 +2312,8 @@ static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_mor
                unsigned no_of_known_types = ARRAY_SIZE(type_str) - 1;
                unsigned type_index = ((unsigned)ftdi_device <= no_of_known_types)
                        ? ftdi_device : FT_DEVICE_UNKNOWN;
-               LOG_INFO("device: %" PRIu32 " \"%s\"", ftdi_device, type_str[type_index]);
-               LOG_INFO("deviceID: %" PRIu32, deviceID);
+               LOG_INFO("device: %" PRIu32 " \"%s\"", (uint32_t)ftdi_device, type_str[type_index]);
+               LOG_INFO("deviceID: %" PRIu32, (uint32_t)deviceID);
                LOG_INFO("SerialNumber: %s", SerialNumber);
                LOG_INFO("Description: %s", Description);
        }
@@ -2319,7 +2327,8 @@ static int ft2232_purge_ftd2xx(void)
 
        if ((status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX)) != FT_OK)
        {
-               LOG_ERROR("error purging ftd2xx device: %" PRIu32, status);
+               LOG_ERROR("error purging ftd2xx device: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
@@ -3640,7 +3649,8 @@ static int signalyzer_h_led_set(unsigned char channel, unsigned char led,
        if ((status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
                        ((uint32_t)(channel << 8) | led))) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write  returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write  returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -3648,7 +3658,8 @@ static int signalyzer_h_led_set(unsigned char channel, unsigned char led,
                        (SIGNALYZER_DATA_BUFFER_ADDR + 1),
                        ((uint32_t)(on_time << 8) | off_time))) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write  returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write  returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -3656,14 +3667,16 @@ static int signalyzer_h_led_set(unsigned char channel, unsigned char led,
                        (SIGNALYZER_DATA_BUFFER_ADDR + 2),
                        ((uint32_t)cycles))) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write  returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write  returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
        if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
                        SIGNALYZER_COMMAND_LED_SET)) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write  returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write  returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -3752,7 +3765,8 @@ static int signalyzer_h_init(void)
        if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
                        SIGNALYZER_COMMAND_VERSION)) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -3762,8 +3776,8 @@ static int signalyzer_h_init(void)
                        (SIGNALYZER_DATA_BUFFER_ADDR + i),
                        &read_buf[i])) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_read returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_read returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
        }
@@ -3776,21 +3790,24 @@ static int signalyzer_h_init(void)
        if ((status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
                        (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
        if ((status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR + 1,
                        0x0404)) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
        if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
                        SIGNALYZER_COMMAND_GPIO_STATE)) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -3798,28 +3815,32 @@ static int signalyzer_h_init(void)
        if ((status = signalyzer_h_ctrl_write(SIGNALYZER_DATA_BUFFER_ADDR,
                        ((uint32_t)(signalyzer_h_side << 8) | 0x01))) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
        if ((status = signalyzer_h_ctrl_write(
                        (SIGNALYZER_DATA_BUFFER_ADDR + 1), 0xA000)) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
        if ((status = signalyzer_h_ctrl_write(
                        (SIGNALYZER_DATA_BUFFER_ADDR + 2), 0x0008)) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
        if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
                        SIGNALYZER_COMMAND_I2C)) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -3828,7 +3849,8 @@ static int signalyzer_h_init(void)
        if ((status = signalyzer_h_ctrl_read(SIGNALYZER_COMMAND_ADDR,
                        &read_buf[0])) != FT_OK)
        {
-               LOG_ERROR("signalyzer_h_ctrl_read returned: %" PRIu32, status);
+               LOG_ERROR("signalyzer_h_ctrl_read returned: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -3842,8 +3864,8 @@ static int signalyzer_h_init(void)
                                        (SIGNALYZER_DATA_BUFFER_ADDR + i),
                                        &read_buf[i])) != FT_OK)
                        {
-                               LOG_ERROR("signalyzer_h_ctrl_read returned: %" PRIu32,
-                                       status);
+                               LOG_ERROR("signalyzer_h_ctrl_read returned: %s",
+                                               ftd2xx_status_string(status));
                                return ERROR_JTAG_DEVICE_ERROR;
                        }
                }
@@ -3907,16 +3929,16 @@ static int signalyzer_h_init(void)
                                ((uint32_t)(signalyzer_h_side << 8) | 0x01)))
                        != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                               status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
                if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
                                SIGNALYZER_COMMAND_POWERCONTROL_SET)) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -3925,8 +3947,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_DATA_BUFFER_ADDR,
                                (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -3934,16 +3956,16 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0000))
                        != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
                if ((status = signalyzer_h_ctrl_write(SIGNALYZER_COMMAND_ADDR,
                                SIGNALYZER_COMMAND_GPIO_MODE)) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -3952,8 +3974,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_DATA_BUFFER_ADDR,
                                (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -3961,8 +3983,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x4040))
                        != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -3970,8 +3992,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_COMMAND_ADDR,
                                SIGNALYZER_COMMAND_GPIO_STATE)) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 #endif
@@ -4042,8 +4064,8 @@ static int signalyzer_h_init(void)
                                ((uint32_t)(signalyzer_h_side << 8) | 0x01)))
                        != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -4051,8 +4073,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_COMMAND_ADDR,
                                SIGNALYZER_COMMAND_POWERCONTROL_SET)) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -4063,8 +4085,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_DATA_BUFFER_ADDR,
                                (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -4072,8 +4094,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0060))
                        != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -4081,8 +4103,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_COMMAND_ADDR,
                                SIGNALYZER_COMMAND_GPIO_MODE)) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -4093,8 +4115,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_DATA_BUFFER_ADDR,
                                (uint32_t)(signalyzer_h_side << 8))) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -4102,8 +4124,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_DATA_BUFFER_ADDR + 1, 0x0000))
                        != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 
@@ -4111,8 +4133,8 @@ static int signalyzer_h_init(void)
                                SIGNALYZER_COMMAND_ADDR,
                                SIGNALYZER_COMMAND_GPIO_STATE)) != FT_OK)
                {
-                       LOG_ERROR("signalyzer_h_ctrl_write returned: %" PRIu32,
-                                       status);
+                       LOG_ERROR("signalyzer_h_ctrl_write returned: %s",
+                                       ftd2xx_status_string(status));
                        return ERROR_JTAG_DEVICE_ERROR;
                }
 #endif
diff --git a/src/jtag/drivers/ftd2xx_common.h b/src/jtag/drivers/ftd2xx_common.h
new file mode 100644 (file)
index 0000000..46bdfa2
--- /dev/null
@@ -0,0 +1,58 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Spencer Oliver <spen@spen-soft.co.uk>           *
+ *                                                                         *
+ *   Written by Arnim Laeuger, 2008 (from urjtag)                          *
+ *                                                                         *
+ *   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, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef _FTD2XX_COMMON_H
+#define _FTD2XX_COMMON_H
+
+#if BUILD_FT2232_FTD2XX == 1
+#include <ftd2xx.h>
+
+static const char *ftd2xx_status_string(FT_STATUS status)
+{
+       switch (status)
+       {
+               case FT_OK:                                                     return "OK";
+               case FT_INVALID_HANDLE:                         return "invalid handle";
+               case FT_DEVICE_NOT_FOUND:                       return "device not found";
+               case FT_DEVICE_NOT_OPENED:                      return "device not opened";
+               case FT_IO_ERROR:                                       return "io error";
+               case FT_INSUFFICIENT_RESOURCES:         return "insufficient resources";
+               case FT_INVALID_PARAMETER:                      return "invalid parameter";
+               case FT_INVALID_BAUD_RATE:                      return "invalid baud rate";
+
+               case FT_DEVICE_NOT_OPENED_FOR_ERASE: return "device not opened for erase";
+               case FT_DEVICE_NOT_OPENED_FOR_WRITE: return "device not opened for write";
+               case FT_FAILED_TO_WRITE_DEVICE:         return "failed to write device";
+               case FT_EEPROM_READ_FAILED:                     return "eeprom read failed";
+               case FT_EEPROM_WRITE_FAILED:            return "eeprom write failed";
+               case FT_EEPROM_ERASE_FAILED:            return "eeprom erase failed";
+               case FT_EEPROM_NOT_PRESENT:                     return "eeprom not present";
+               case FT_EEPROM_NOT_PROGRAMMED:          return "eeprom not programmed";
+               case FT_INVALID_ARGS:                           return "invalid args";
+               case FT_NOT_SUPPORTED:                          return "not supported";
+               case FT_OTHER_ERROR:                            return "other error";
+       }
+
+       return "undefined FTD2xx error";
+}
+
+#endif
+#endif /* _FTD2XX_COMMON_H */
index 2328c26b593c4eeb30087023763c864816bd5a7f..b23d196b9a3aa8edb619d90e3c7fb5732feab6b2 100644 (file)
@@ -39,6 +39,7 @@
 /* PRESTO access library includes */
 #if BUILD_PRESTO_FTD2XX == 1
 #include <ftd2xx.h>
+#include "ftd2xx_common.h"
 #elif BUILD_PRESTO_LIBFTDI == 1
 #include <ftdi.h>
 #else
@@ -102,7 +103,7 @@ static int presto_write(uint8_t *buf, uint32_t size)
        DWORD ftbytes;
        if ((presto->status = FT_Write(presto->handle, buf, size, &ftbytes)) != FT_OK)
        {
-               LOG_ERROR("FT_Write returned: %lu", presto->status);
+               LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(presto->status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -132,7 +133,7 @@ static int presto_read(uint8_t* buf, uint32_t size)
        DWORD ftbytes;
        if ((presto->status = FT_Read(presto->handle, buf, size, &ftbytes)) != FT_OK)
        {
-               LOG_ERROR("FT_Read returned: %lu", presto->status);
+               LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(presto->status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -194,17 +195,17 @@ static int presto_open_ftd2xx(char *req_serial)
 
        if ((presto->status = FT_ListDevices(&numdevs, NULL, FT_LIST_NUMBER_ONLY)) != FT_OK)
        {
-               LOG_ERROR("FT_ListDevices failed: %i", (int)presto->status);
+               LOG_ERROR("FT_ListDevices failed: %s", ftd2xx_status_string(presto->status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
-       LOG_DEBUG("FTDI devices available: %lu", numdevs);
+       LOG_DEBUG("FTDI devices available: %" PRIu32, (uint32_t)numdevs);
        for (i = 0; i < numdevs; i++)
        {
                if ((presto->status = FT_Open(i, &(presto->handle))) != FT_OK)
                {
                        /* this is not fatal, the device may be legitimately open by other process, hence debug message only */
-                       LOG_DEBUG("FT_Open failed: %i", (int)presto->status);
+                       LOG_DEBUG("FT_Open failed: %s", ftd2xx_status_string(presto->status));
                        continue;
                }
                LOG_DEBUG("FTDI device %i open", (int)i);
@@ -217,7 +218,7 @@ static int presto_open_ftd2xx(char *req_serial)
                                break;
                }
                else
-                       LOG_DEBUG("FT_GetDeviceInfo failed: %lu", presto->status);
+                       LOG_DEBUG("FT_GetDeviceInfo failed: %s", ftd2xx_status_string(presto->status));
 
                LOG_DEBUG("FTDI device %i does not match, closing", (int)i);
                FT_Close(presto->handle);
@@ -404,7 +405,7 @@ static int presto_close(void)
        int result = ERROR_OK;
 
 #if BUILD_PRESTO_FTD2XX == 1
-       unsigned long ftbytes;
+       DWORD ftbytes;
 
        if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE)
                return result;
index 382240f52114f53539b929be05f7fbda1b7fc8ec..c5c356ce574599b26b423271dcb0cc2a5bd40f99 100644 (file)
@@ -97,6 +97,7 @@
 /* USB_BLASTER access library includes */
 #if BUILD_USB_BLASTER_FTD2XX == 1
 #include <ftd2xx.h>
+#include "ftd2xx_common.h"
 #elif BUILD_USB_BLASTER_LIBFTDI == 1
 #include <ftdi.h>
 #endif
@@ -135,7 +136,7 @@ static int usb_blaster_buf_write(
        if (status != FT_OK)
        {
                *bytes_written = dw_bytes_written;
-               LOG_ERROR("FT_Write returned: %" PRIu32, status);
+               LOG_ERROR("FT_Write returned: %s", ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
        *bytes_written = dw_bytes_written;
@@ -168,7 +169,7 @@ usb_blaster_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read)
        if (status != FT_OK)
        {
                *bytes_read = dw_bytes_read;
-               LOG_ERROR("FT_Read returned: %" PRIu32, status);
+               LOG_ERROR("FT_Read returned: %s", ftd2xx_status_string(status));
                return ERROR_JTAG_DEVICE_ERROR;
        }
 #ifdef _DEBUG_JTAG_IO_
@@ -384,7 +385,8 @@ static int usb_blaster_init(void)
        {
                DWORD num_devices;
 
-               LOG_ERROR("unable to open ftdi device: %" PRIu32, status);
+               LOG_ERROR("unable to open ftdi device: %s",
+                               ftd2xx_status_string(status));
                status = FT_ListDevices(&num_devices, NULL,
                                FT_LIST_NUMBER_ONLY);
                if (status == FT_OK)
@@ -402,7 +404,7 @@ static int usb_blaster_init(void)
 
                        if (status == FT_OK)
                        {
-                               LOG_ERROR("ListDevices: %" PRIu32, num_devices);
+                               LOG_ERROR("ListDevices: %" PRIu32, (uint32_t)num_devices);
                                for (i = 0; i < num_devices; i++)
                                        LOG_ERROR("%i: %s", i, desc_array[i]);
                        }
@@ -421,14 +423,16 @@ static int usb_blaster_init(void)
        status = FT_SetLatencyTimer(ftdih, 2);
        if (status != FT_OK)
        {
-               LOG_ERROR("unable to set latency timer: %" PRIu32, status);
+               LOG_ERROR("unable to set latency timer: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 
        status = FT_GetLatencyTimer(ftdih, &latency_timer);
        if (status != FT_OK)
        {
-               LOG_ERROR("unable to get latency timer: %" PRIu32, status);
+               LOG_ERROR("unable to get latency timer: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
        LOG_DEBUG("current latency timer: %i", latency_timer);
@@ -436,7 +440,8 @@ static int usb_blaster_init(void)
        status = FT_SetBitMode(ftdih, 0x00, 0);
        if (status != FT_OK)
        {
-               LOG_ERROR("unable to disable bit i/o mode: %" PRIu32, status);
+               LOG_ERROR("unable to disable bit i/o mode: %s",
+                               ftd2xx_status_string(status));
                return ERROR_JTAG_INIT_FAILED;
        }
 #elif BUILD_USB_BLASTER_LIBFTDI == 1