Introduce URJ_ERROR_FTD, _USB. Adorn the error detail there w/ the appropriate error print. Introduce urj_error_IO_set that handles errno transparently

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1590 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Rutger Hofman 16 years ago
parent 899f07f7c3
commit 0064c8b83a

@ -7,6 +7,9 @@
parser.
Library commands that produce output (print routines) are equipped with
a urj_log_level_t parameter to control their verbosity.
* include/urjtag/error.h, many more files: introduce error values
URJ_ERROR_FTD, URJ_ERROR_USB. Handle URJ_ERROR_IO specially through macro
urj_error_IO_set that handles errno/strerror().
2009-05-11 Arnim Laeuger <arniml>

@ -47,6 +47,8 @@ typedef enum urj_error {
URJ_ERROR_SYNTAX,
URJ_ERROR_IO, /**< I/O error from OS */
URJ_ERROR_FTD, /**< error from ftdi/ftd2xx */
URJ_ERROR_USB, /**< error from libusb */
URJ_ERROR_BUS,
@ -83,8 +85,9 @@ extern const char *urj_error_string (urj_error_t error);
* Set error state.
*
* @param e urj_error_t value
* @param ... consists of a printf argument set. It needs to start with a
* const char *fmt, followed by arguments used by fmt.
* @param ... error detail message that consists of a printf argument set.
* It needs to start with a const char *fmt, followed by arguments used
* by fmt.
*/
#define urj_error_set(e, ...) \
do { \
@ -119,13 +122,13 @@ extern const char *urj_error_string (urj_error_t error);
* Set I/O error state: do as urj_error_set, but also store errno in
* #urj_error_state and then reset errno.
*
* @param e urj_error_t value
* @param ... consists of a printf argument set. It needs to start with a
* const char *fmt, followed by arguments used by fmt.
* @param ... error detail message that consists of a printf argument set.
* It needs to start with a const char *fmt, followed by arguments used
* by fmt. The error code (URJ_ERROR_IO) is added by this macro.
*/
#define urj_error_IO_set(e, ...) \
#define urj_error_IO_set(...) \
do { \
urj_error_set (e, __VA_ARGS__); \
urj_error_set (URJ_ERROR_IO, __VA_ARGS__); \
urj_error_state.sys_errno = errno; \
errno = 0; \
} while (0)

@ -73,9 +73,7 @@ cmd_flashmem_run (urj_chain_t *chain, char *params[])
f = fopen (params[2], "rb");
if (!f)
{
urj_error_set (URJ_ERROR_IO, _("Unable to open file `%s': %s"),
params[2], strerror (errno));
errno = 0;
urj_error_IO_set (_("Unable to open file `%s'"), params[2]);
return URJ_STATUS_FAIL;
}

@ -64,9 +64,7 @@ cmd_readmem_run (urj_chain_t *chain, char *params[])
f = fopen (params[3], "w");
if (!f)
{
urj_error_set (URJ_ERROR_IO, _("Unable to create file `%s': %s"),
params[3], strerror(errno));
errno = 0;
urj_error_IO_set (_("Unable to create file `%s'"), params[3]);
return URJ_STATUS_FAIL;
}
urj_bus_readmem (urj_bus, f, adr, len);

@ -62,9 +62,7 @@ cmd_writemem_run (urj_chain_t *chain, char *params[])
f = fopen (params[3], "r");
if (!f)
{
urj_error_set (URJ_ERROR_IO, _("Unable to open file `%s': %s"),
params[3], strerror(errno));
errno = 0;
urj_error_IO_set (_("Unable to open file `%s'"), params[3]);
return URJ_STATUS_FAIL;
}
urj_bus_writemem (urj_bus, f, adr, len);

@ -38,6 +38,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <urjtag/error.h>
#include <urjtag/log.h>
@ -164,7 +165,7 @@ urj_flashmsbin (urj_bus_t *bus, FILE *f, int noverify)
fread (&c, sizeof c, 1, f);
if (feof (f))
{
urj_error_set (URJ_ERROR_IO, _("premature end of file"));
urj_error_IO_set (_("premature end of file"));
return URJ_STATUS_FAIL;
}
urj_log (URJ_LOG_LEVEL_NORMAL,
@ -216,12 +217,12 @@ urj_flashmsbin (urj_bus_t *bus, FILE *f, int noverify)
fread (&c, sizeof c, 1, f);
if (feof (f))
{
urj_error_set (URJ_ERROR_IO, _("premature end of file"));
urj_error_IO_set (_("premature end of file"));
return URJ_STATUS_FAIL;
}
urj_log (URJ_LOG_LEVEL_NORMAL, _
("record: start = 0x%08X, len = 0x%08X, checksum = 0x%08X\n"),
a, l, c);
urj_log (URJ_LOG_LEVEL_NORMAL,
_("record: start = 0x%08X, len = 0x%08X, checksum = 0x%08X\n"),
a, l, c);
if ((a == 0) && (c == 0))
break;
if (l & 3)
@ -242,7 +243,7 @@ urj_flashmsbin (urj_bus_t *bus, FILE *f, int noverify)
if (data != readed)
{
urj_error_set (URJ_ERROR_FLASH_PROGRAM,
_("\nverify error: 0x%08X vs. 0x%08X at addr %08X\n"),
_("verify error: 0x%08X vs. 0x%08X at addr %08X"),
readed, data, a);
return URJ_STATUS_FAIL;
}

@ -181,9 +181,7 @@ urj_parse_file (urj_log_level_t ll, urj_chain_t *chain, const char *filename)
f = fopen (filename, "r");
if (!f)
{
urj_error_set (URJ_ERROR_IO, "Cannot open file '%s' to parse: %s",
filename, strerror(errno));
errno = 0;
urj_error_IO_set ("Cannot open file '%s' to parse", filename);
return URJ_STATUS_FAIL;
}

@ -24,6 +24,8 @@
#include <urjtag/sysdep.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
#include <urjtag/log.h>
#include <urjtag/error.h>
@ -111,6 +113,8 @@ urj_error_string (urj_error_t err)
case URJ_ERROR_SYNTAX: return "syntax";
case URJ_ERROR_IO: return "I/O error from OS";
case URJ_ERROR_FTD: return "ftdi/ftd2xx error";
case URJ_ERROR_USB: return "libusb error";
case URJ_ERROR_BUS: return "bus";
@ -129,10 +133,22 @@ urj_error_describe (void)
{
static char msg[URJ_ERROR_MSG_LEN + 1024 + 256 + 20];
snprintf (msg, sizeof msg, "%s:%d %s() %s: %s",
urj_error_state.file, urj_error_state.line,
urj_error_state.function,
urj_error_string (urj_error_state.errnum), urj_error_state.msg);
if (urj_error_state.errnum == URJ_ERROR_IO)
{
snprintf (msg, sizeof msg, "%s:%d %s() %s: %s %s",
urj_error_state.file, urj_error_state.line,
urj_error_state.function,
"System error", strerror(urj_error_state.sys_errno),
urj_error_state.msg);
}
else
{
snprintf (msg, sizeof msg, "%s:%d %s() %s: %s",
urj_error_state.file, urj_error_state.line,
urj_error_state.function,
urj_error_string (urj_error_state.errnum),
urj_error_state.msg);
}
return msg;
}

@ -47,16 +47,7 @@
#include <urjtag/tap_register.h>
#include <urjtag/part_instruction.h>
#include <urjtag/data_register.h>
#if 0
#include <urjtag/svf.h> /* two include files w/ the same name
* this will be resolved when we will have
* include/urjtag/svf.h
* RFHH */
#endif
#include <urjtag/cmd.h>
#include <urjtag/svf.h>
#include "svf.h"
@ -366,7 +357,7 @@ urj_svf_build_bit_string (char *hex_string, int len)
if (!(bit_string = calloc (len + 1, sizeof (char))))
{
urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails",
len + 1, sizeof (char));
(size_t) (len + 1), sizeof (char));
return (NULL);
}
@ -1193,7 +1184,7 @@ urj_svf_run (urj_chain_t *chain, FILE *SVF_FILE, int stop_on_mismatch,
if ((instruction_string = calloc (len + 1, sizeof (char))) == NULL)
{
urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "calloc(%zd,%zd) fails",
(size_t)(len + 1), sizeof (char));
(size_t) (len + 1), sizeof (char));
return 0;
}

@ -62,9 +62,7 @@ find_record (char *filename, urj_tap_register_t *key, struct id_record *idr)
file = fopen (filename, "r");
if (!file)
{
urj_error_set (URJ_ERROR_IO, "Cannot open '%s': %s", filename,
strerror(errno));
errno = 0;
urj_error_IO_set ("Cannot open '%s'", filename);
return 0;
}

@ -155,6 +155,7 @@ direct_parport_alloc (unsigned int port)
{
urj_error_set (URJ_ERROR_IO,
_("Couldn't load InpOut32.dll; maybe not installed?\n"));
urj_error.sys_errno = GetLastError();
return NULL;
}
@ -262,9 +263,7 @@ direct_open (urj_parport_t *parport)
unsigned int port = ((direct_params_t *) parport->params)->port;
if (((port + 3 <= 0x400) ? ioperm (port, 3, 1) : iopl (3)) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioperm(3,1) or iopl(3) fails: %s",
strerror(errno));
errno = 0;
urj_error_IO_set ("ioperm(3,1) or iopl(3) fails");
return URJ_STATUS_FAIL;
}
return URJ_STATUS_OK;
@ -280,9 +279,7 @@ direct_close (urj_parport_t *parport)
unsigned int port = ((direct_params_t *) parport->params)->port;
if (((port + 3 <= 0x400) ? ioperm (port, 3, 0) : iopl (0)) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioperm(3,0) or iopl(0) fails: %s",
strerror(errno));
errno = 0;
urj_error_IO_set ("ioperm(3,0) or iopl(0) fails");
return URJ_STATUS_FAIL;
}
return URJ_STATUS_OK;

@ -158,18 +158,14 @@ ppdev_open (urj_parport_t *parport)
p->fd = open (p->portname, O_RDWR);
if (p->fd < 0)
{
urj_error_set (URJ_ERROR_IO, _("Could not open port %s: %s\n"),
p->portname, strerror (errno));
errno = 0;
urj_error_IO_set (_("Could not open port %s"), p->portname);
return URJ_STATUS_FAIL;
}
if ( /*(ioctl( p->fd, PPEXCL ) == -1) || */
(ioctl (p->fd, PPCLAIM) == -1))
{
urj_error_set (URJ_ERROR_IO, _("Could not claim ppdev device: %s\n"),
strerror (errno));
errno = 0;
urj_error_IO_set (_("Could not claim ppdev device"));
close (p->fd);
p->fd = -1;
return URJ_STATUS_FAIL;
@ -186,17 +182,13 @@ ppdev_close (urj_parport_t *parport)
if (ioctl (p->fd, PPRELEASE) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioctl(PPRELEASE) fails: %s",
strerror (errno));
errno = 0;
urj_error_IO_set ("ioctl(PPRELEASE) fails");
r = URJ_STATUS_FAIL;
}
if (close (p->fd) != 0)
{
urj_error_set (URJ_ERROR_IO, "Cannot close(%d): %s", p->fd,
strerror (errno));
errno = 0;
urj_error_IO_set ("Cannot close(%d)", p->fd);
return URJ_STATUS_FAIL;
}
@ -211,9 +203,7 @@ ppdev_set_data (urj_parport_t *parport, uint8_t data)
if (ioctl (p->fd, PPWDATA, &data) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioctl(PPWDATA) fails: %s",
strerror (errno));
errno = 0;
urj_error_IO_set ("ioctl(PPWDATA) fails");
return URJ_STATUS_FAIL;
}
@ -228,9 +218,7 @@ ppdev_get_data (urj_parport_t *parport)
if (ioctl (p->fd, PPRDATA, &d) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioctl(PPRSTATUS) fails: %s",
strerror (errno));
errno = 0;
urj_error_IO_set ("ioctl(PPRSTATUS) fails");
return -1;
}
@ -245,9 +233,7 @@ ppdev_get_status (urj_parport_t *parport)
if (ioctl (p->fd, PPRSTATUS, &d) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioctl(PPRSTATUS) fails: %s",
strerror (errno));
errno = 0;
urj_error_IO_set ("ioctl(PPRSTATUS) fails");
return -1;
}
@ -263,9 +249,7 @@ ppdev_set_control (urj_parport_t *parport, uint8_t data)
if (ioctl (p->fd, PPWCONTROL, &data) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioctl(PPWDATA) fails: %s",
strerror (errno));
errno = 0;
urj_error_IO_set ("ioctl(PPWDATA) fails");
return URJ_STATUS_FAIL;
}

@ -130,13 +130,14 @@ ppi_connect (const char **par, int parnum)
for (pn = ports; pn; pn = pn->next)
if (strcmp (pn->port->params, par[0]) == 0)
{
printf (_("Disconnecting %s from ppi port %s\n"),
_(pn->port->cable->driver->description), par[0]);
urj_log (URJ_LOG_LEVEL_NORMAL,
_("Disconnecting %s from ppi port %s\n"),
_(pn->port->cable->driver->description), par[0]);
pn->port->cable->driver->disconnect (pn->port->cable);
break;
}
printf (_("Initializing on ppi port %s\n"), par[0]);
urj_log (URJ_LOG_LEVEL_NORMAL, _("Initializing on ppi port %s\n"), par[0]);
parport = ppi_parport_alloc (par[0]);
if (!parport)
@ -155,9 +156,7 @@ ppi_open (urj_parport_t *parport)
p->fd = open (p->portname, O_RDWR);
if (p->fd < 0)
{
urj_error_set (URJ_ERROR_IO, "Cannot open(%s): %s", p->portname,
strerror(errno));
errno = 0;
urj_error_IO_set ("Cannot open(%s)", p->portname);
return URJ_STATUS_FAIL;
}
@ -172,9 +171,7 @@ ppi_close (urj_parport_t *parport)
if (close (p->fd) != 0)
{
urj_error_set (URJ_ERROR_IO, "Cannot close(%d): %s", p->fd,
strerror(errno));
errno = 0;
urj_error_IO_set ("Cannot close(%d)", p->fd);
return URJ_STATUS_FAIL;
}
@ -189,9 +186,7 @@ ppi_set_data (urj_parport_t *parport, uint8_t data)
if (ioctl (p->fd, PPISDATA, &data) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioctl(PPISDATA) fails: %s",
strerror (errno));
errno = 0;
urj_error_IO_set ("ioctl(PPISDATA) fails");
return URJ_STATUS_FAIL;
}
@ -206,9 +201,7 @@ ppi_get_data (urj_parport_t *parport)
if (ioctl (p->fd, PPIGDATA, &d) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioctl(PPIGDATA) fails: %s",
strerror (errno));
errno = 0;
urj_error_IO_set ("ioctl(PPIGDATA) fails");
return -1;
}
@ -223,9 +216,7 @@ ppi_get_status (urj_parport_t *parport)
if (ioctl (p->fd, PPIGSTATUS, &d) == -1)
{
urj_error_set (URJ_ERROR_IO, "ioctl(PPIGSTATUS) fails: %s",
strerror (errno));
errno = 0;
urj_error_IO_set ("ioctl(PPIGSTATUS) fails");
return -1;
}

@ -73,6 +73,36 @@ urj_usbconn_driver_t urj_tap_usbconn_ftd2xx_mpsse_driver;
static int usbconn_ftd2xx_common_open (urj_usbconn_t *conn, urj_log_level_t ll);
static void usbconn_ftd2xx_free (urj_usbconn_t *conn);
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";
}
/* ---------------------------------------------------------------------- */
/** @return number of flushed bytes on success; -1 on error */
@ -99,7 +129,11 @@ usbconn_ftd2xx_flush (ftd2xx_param_t *p)
if ((status = FT_Write (p->fc, p->send_buf, p->send_buffered,
&xferred)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("FT_Write() failed"));
{
urj_error_set (URJ_ERROR_FTD, _("FT_Write() failed: %s"),
ftd2xx_status_string(status));
return -1;
}
if (xferred < p->send_buffered)
{
@ -131,8 +165,8 @@ usbconn_ftd2xx_flush (ftd2xx_param_t *p)
while (recvd == 0)
if ((status = FT_Read (p->fc, &(p->recv_buf[p->recv_write_idx]),
p->to_recv, &recvd)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Error from FT_Read(): %d"),
(int) status);
urj_error_set (URJ_ERROR_FTD, _("Error from FT_Read(): %s"),
ftd2xx_status_string(status));
if (recvd < p->to_recv)
urj_log (URJ_LOG_LEVEL_NORMAL,
@ -193,8 +227,8 @@ usbconn_ftd2xx_read (urj_usbconn_t *conn, uint8_t *buf, int len)
while (recvd == 0)
if ((status =
FT_Read (p->fc, &(buf[cpy_len]), len, &recvd)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Error from FT_Read(): %d"),
(int) status);
urj_error_set (URJ_ERROR_FTD, _("Error from FT_Read(): %s"),
ftd2xx_status_string(status));
}
urj_log (URJ_LOG_LEVEL_DETAIL, "%sread end : status %ld, length %d\n",
@ -373,8 +407,8 @@ usbconn_ftd2xx_common_open (urj_usbconn_t *conn, urj_log_level_t ll)
if (status != FT_OK)
{
urj_error_set (URJ_ERROR_IO, "Unable to open TFDI device");
urj_log (ll, "Unable to open FTDI device.\n");
urj_error_set (URJ_ERROR_FTD, "Unable to open TFDI device: %s",
ftd2xx_status_string(status));
/* mark ftd2xx layer as not initialized */
p->fc = NULL;
return URJ_STATUS_FAIL;
@ -399,18 +433,22 @@ usbconn_ftd2xx_open (urj_usbconn_t *conn)
fc = p->fc;
if ((status = FT_ResetDevice (fc)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't reset device"));
urj_error_set (URJ_ERROR_FTD, _("Can't reset device: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status = FT_Purge (fc, FT_PURGE_RX)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't purge RX buffer"));
urj_error_set (URJ_ERROR_FTD, _("Can't purge RX buffer: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status = FT_SetLatencyTimer (fc, 2)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't set latency timer"));
urj_error_set (URJ_ERROR_FTD, _("Can't set latency timer: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status = FT_SetBaudRate (fc, 3E6)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't set baudrate"));
urj_error_set (URJ_ERROR_FTD, _("Can't set baudrate: %s"),
ftd2xx_status_string(status));
if (status != FT_OK)
{
@ -442,39 +480,47 @@ usbconn_ftd2xx_mpsse_open (urj_usbconn_t *conn)
Ref. FTCJTAGPG10.pdf
Intermittent problems will occur when certain steps are skipped. */
if ((status = FT_ResetDevice (fc)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't reset device"));
urj_error_set (URJ_ERROR_FTD, _("Can't reset device: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status = FT_Purge (fc, FT_PURGE_RX)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("s(): Can't purge RX buffer"));
urj_error_set (URJ_ERROR_FTD, _("s(): Can't purge RX buffer: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status =
FT_SetUSBParameters (fc, URJ_USBCONN_FTDX_MAXSEND_MPSSE,
URJ_USBCONN_FTDX_MAXSEND_MPSSE)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't set USB parameters"));
urj_error_set (URJ_ERROR_FTD, _("Can't set USB parameters: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status = FT_SetChars (fc, 0, 0, 0, 0)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't set special characters"));
urj_error_set (URJ_ERROR_FTD, _("Can't set special characters: %s"),
ftd2xx_status_string(status));
/* set a reasonable latency timer value
if this value is too low then the chip will send intermediate result data
in short packets (suboptimal performance) */
if (status == FT_OK)
if ((status = FT_SetLatencyTimer (fc, 16)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't set target latency timer"));
urj_error_set (URJ_ERROR_FTD, _("Can't set target latency timer: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status =
FT_SetBitMode (fc, 0x0b, 0x02 /* BITMODE_MPSSE */ )) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't set MPSSE bitmode"));
urj_error_set (URJ_ERROR_FTD, _("Can't set MPSSE bitmode: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status = FT_ResetDevice (fc)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't reset device"));
urj_error_set (URJ_ERROR_FTD, _("Can't reset device: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status = FT_Purge (fc, FT_PURGE_RX)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't purge RX buffer"));
urj_error_set (URJ_ERROR_FTD, _("Can't purge RX buffer: %s"),
ftd2xx_status_string(status));
/* set TCK Divisor */
if (status == FT_OK)
@ -496,10 +542,12 @@ usbconn_ftd2xx_mpsse_open (urj_usbconn_t *conn)
if (status == FT_OK)
if ((status = FT_ResetDevice (fc)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't reset device"));
urj_error_set (URJ_ERROR_FTD, _("Can't reset device: %s"),
ftd2xx_status_string(status));
if (status == FT_OK)
if ((status = FT_Purge (fc, FT_PURGE_RX)) != FT_OK)
urj_error_set (URJ_ERROR_IO, _("Can't purge RX buffer"));
urj_error_set (URJ_ERROR_FTD, _("Can't purge RX buffer: %s"),
ftd2xx_status_string(status));
if (status != FT_OK)
{

@ -84,7 +84,7 @@ usbconn_ftdi_flush (ftdi_param_t *p)
return 0;
if ((xferred = ftdi_write_data (p->fc, p->send_buf, p->send_buffered)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_write_data() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_write_data() failed: %s"),
ftdi_get_error_string (p->fc));
if (xferred < p->send_buffered)
@ -118,7 +118,7 @@ usbconn_ftdi_flush (ftdi_param_t *p)
if ((recvd = ftdi_read_data (p->fc,
&(p->recv_buf[p->recv_write_idx]),
p->to_recv)) < 0)
urj_error_set (URJ_ERROR_IO,
urj_error_set (URJ_ERROR_FTD,
_("Error from ftdi_read_data(): %s"),
ftdi_get_error_string (p->fc));
@ -174,7 +174,7 @@ usbconn_ftdi_read (urj_usbconn_t *conn, uint8_t *buf, int len)
/* need to get more data directly from the device */
while (recvd == 0)
if ((recvd = ftdi_read_data (p->fc, &(buf[cpy_len]), len)) < 0)
urj_error_set (URJ_ERROR_IO,
urj_error_set (URJ_ERROR_FTD,
_("Error from ftdi_read_data(): %s"),
ftdi_get_error_string (p->fc));
}
@ -342,7 +342,7 @@ usbconn_ftdi_common_open (urj_usbconn_t *conn, urj_log_level_t ll)
if (status != -3)
urj_log (ll, _("%s(): ftdi_usb_open_desc() failed: %s"),
__func__, ftdi_get_error_string (fc));
urj_error_set (URJ_ERROR_IO, _("ftdi_usb_open_desc() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_usb_open_desc() failed: %s"),
ftdi_get_error_string (fc));
ftdi_deinit (fc);
/* mark ftdi layer as not initialized */
@ -367,11 +367,11 @@ seq_purge (struct ftdi_context *fc, int purge_rx, int purge_tx)
#ifndef LIBFTDI_UNIMPLEMENTED
if ((r = ftdi_usb_purge_buffers (fc)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_usb_purge_buffers() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_usb_purge_buffers() failed: %s"),
ftdi_get_error_string (fc));
if (r >= 0)
if ((r = ftdi_read_data (fc, &buf, 1)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_read_data() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_read_data() failed: %s"),
ftdi_get_error_string (fc));
#else /* not yet available */
{
@ -380,19 +380,19 @@ seq_purge (struct ftdi_context *fc, int purge_rx, int purge_tx)
if (purge_rx)
for (rx_loop = 0; (rx_loop < 6) && (r >= 0); rx_loop++)
if ((r = ftdi_usb_purge_rx_buffer (fc)) < 0)
urj_error_set (URJ_ERROR_IO,
urj_error_set (URJ_ERROR_FTD,
_("ftdi_usb_purge_rx_buffer() failed: %s"),
ftdi_get_error_string (fc));
if (purge_tx)
if (r >= 0)
if ((r = ftdi_usb_purge_tx_buffer (fc)) < 0)
urj_error_set (URJ_ERROR_IO,
urj_error_set (URJ_ERROR_FTD,
_("ftdi_usb_purge_tx_buffer() failed: %s"),
ftdi_get_error_string (fc));
if (r >= 0)
if ((r = ftdi_read_data (fc, &buf, 1)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_read_data() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_read_data() failed: %s"),
ftdi_get_error_string (fc));
}
#endif
@ -409,12 +409,12 @@ seq_reset (struct ftdi_context *fc)
{
unsigned short status;
if ((r = ftdi_poll_status (fc, &status)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_poll_status() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_poll_status() failed: %s"),
ftdi_get_error_string (fc));
}
#endif
if ((r = ftdi_usb_reset (fc)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_usb_reset() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_usb_reset() failed: %s"),
ftdi_get_error_string (fc));
if (r >= 0)
@ -440,7 +440,7 @@ usbconn_ftdi_open (urj_usbconn_t *conn)
if (r >= 0)
if ((r = ftdi_set_latency_timer (fc, 2)) < 0)
urj_error_set (URJ_ERROR_IO,
urj_error_set (URJ_ERROR_FTD,
_("ftdi_set_latency_timer() failed: %s"),
ftdi_get_error_string (fc));
@ -451,13 +451,14 @@ usbconn_ftdi_open (urj_usbconn_t *conn)
if (usb_control_msg
(fc->usb_dev, 0x40, 3, 1, 0, NULL, 0, fc->usb_write_timeout) != 0)
{
urj_error_set (URJ_ERROR_IO, "Can't set max baud rate");
urj_error_set (URJ_ERROR_FTD, "Can't set max baud rate: %s"
ftdi_get_error_string (fc));
r = -1;
}
#else
if (r >= 0)
if ((r = ftdi_set_baudrate (fc, 3E6)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_set_baudrate() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_set_baudrate() failed: %s"),
ftdi_get_error_string (fc));
#endif
@ -519,18 +520,18 @@ usbconn_ftdi_mpsse_open (urj_usbconn_t *conn)
in short packets (suboptimal performance) */
if (r >= 0)
if ((r = ftdi_set_latency_timer (fc, 16)) < 0)
urj_error_set (URJ_ERROR_IO,
urj_error_set (URJ_ERROR_FTD,
_("ftdi_set_latency_timer() failed: %s"),
ftdi_get_error_string (fc));
if (r >= 0)
if ((r = ftdi_set_bitmode (fc, 0x0b, BITMODE_MPSSE)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_set_bitmode() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_set_bitmode() failed: %s"),
ftdi_get_error_string (fc));
if (r >= 0)
if ((r = ftdi_usb_reset (fc)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_usb_reset() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_usb_reset() failed: %s"),
ftdi_get_error_string (fc));
if (r >= 0)
r = seq_purge (fc, 1, 0);
@ -552,7 +553,7 @@ usbconn_ftdi_mpsse_open (urj_usbconn_t *conn)
if (r >= 0)
if ((r = ftdi_usb_reset (fc)) < 0)
urj_error_set (URJ_ERROR_IO, _("ftdi_usb_reset() failed: %s"),
urj_error_set (URJ_ERROR_FTD, _("ftdi_usb_reset() failed: %s"),
ftdi_get_error_string (fc));
if (r >= 0)
r = seq_purge (fc, 1, 0);

@ -70,7 +70,7 @@ libusb_match_desc (struct usb_device *dev, char *desc)
handle = usb_open (dev);
if (handle == NULL)
{
urj_error_set (URJ_ERROR_IO, "usb_open() failed: %s", strerror(errno));
urj_error_set (URJ_ERROR_USB, "usb_open() failed: %s", usb_strerror());
errno = 0;
return 0;
}
@ -123,15 +123,15 @@ usbconn_libusb_connect (const char **param, int paramc,
usb_init ();
if (usb_find_busses () < 0)
{
urj_error_set (URJ_ERROR_IO, "usb_find_busses() failed: %s",
strerror(errno));
urj_error_set (URJ_ERROR_USB, "usb_find_busses() failed: %s",
usb_strerror());
errno = 0;
return NULL;
}
if (usb_find_devices () < 0)
{
urj_error_set (URJ_ERROR_IO, "usb_find_devices() failed: %s",
strerror(errno));
urj_error_set (URJ_ERROR_USB, "usb_find_devices() failed: %s",
usb_strerror());
errno = 0;
return NULL;
}
@ -196,7 +196,7 @@ usbconn_libusb_open (urj_usbconn_t *conn)
p->handle = usb_open (p->dev);
if (p->handle == NULL)
{
urj_error_set (URJ_ERROR_IO, "usb_open() failed: %s", strerror(errno));
urj_error_set (URJ_ERROR_USB, "usb_open() failed: %s", usb_strerror());
errno = 0;
}
else
@ -208,8 +208,8 @@ usbconn_libusb_open (urj_usbconn_t *conn)
if (usb_claim_interface (p->handle, 0) != 0)
{
usb_close (p->handle);
urj_error_set (URJ_ERROR_IO, "usb_claim_interface failed: %s",
strerror(errno));
urj_error_set (URJ_ERROR_USB, "usb_claim_interface failed: %s",
usb_strerror());
errno = 0;
p->handle = NULL;
}

Loading…
Cancel
Save