Commit 29000b20 authored by drath's avatar drath
Browse files

- reworked presto.c to allow use of either FTD2XX or libftdi (libftdi not...

- reworked presto.c to allow use of either FTD2XX or libftdi (libftdi not functional yet). Configure option changed from --enable-presto to 
--enable-presto_ftd2xx and --enable-presto_libftdi
- completed trace point support for use with ARM7/9 DCC
- completed debug message output with support for HEX dumps (1, 2 or 4 byte quantities)
- fixed bug in delete_debug_msg_receiver (thanks to Pavel Chromy)
- fixed bug in image_add_section (thanks to Pavel Chromy)
- at91sam7 sector erase reworked (thanks to Pavel Chromy)
- merge consecutive sections during flash image write to work around possible section alignment issues with LPC2000 targets



git-svn-id: svn://svn.berlios.de/openocd/trunk@194 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent abbd2b62
...@@ -68,9 +68,13 @@ AC_ARG_ENABLE(gw16012, ...@@ -68,9 +68,13 @@ AC_ARG_ENABLE(gw16012,
AS_HELP_STRING([--enable-gw16012], [Enable building support for the Gateworks GW16012 JTAG Programmer]), AS_HELP_STRING([--enable-gw16012], [Enable building support for the Gateworks GW16012 JTAG Programmer]),
[build_gw16012=$enableval], [build_gw16012=no]) [build_gw16012=$enableval], [build_gw16012=no])
AC_ARG_ENABLE(presto, AC_ARG_ENABLE(presto_libftdi,
AS_HELP_STRING([--enable-presto], [Enable building support for ASIX Presto Programmer]), AS_HELP_STRING([--enable-presto_libftdi], [Enable building support for ASIX Presto Programmer using the libftdi driver]),
[build_presto=$enableval], [build_presto=no]) [build_presto_libftdi=$enableval], [build_presto_libftdi=no])
AC_ARG_ENABLE(presto_ftd2xx,
AS_HELP_STRING([--enable-presto_ftd2xx], [Enable building support for ASIX Presto Programmer using the FTD2XX driver]),
[build_presto_ftd2xx=$enableval], [build_presto_ftd2xx=no])
AC_ARG_ENABLE(usbprog, AC_ARG_ENABLE(usbprog,
AS_HELP_STRING([--enable-usbprog], [Enable building support for the usbprog JTAG Programmer]), AS_HELP_STRING([--enable-usbprog], [Enable building support for the usbprog JTAG Programmer]),
...@@ -185,11 +189,18 @@ else ...@@ -185,11 +189,18 @@ else
AC_DEFINE(BUILD_GW16012, 0, [0 if you don't want the Gateworks GW16012 driver.]) AC_DEFINE(BUILD_GW16012, 0, [0 if you don't want the Gateworks GW16012 driver.])
fi fi
if test $build_presto = yes; then if test $build_presto_libftdi = yes; then
build_bitq=yes
AC_DEFINE(BUILD_PRESTO_LIBFTDI, 1, [1 if you want the ASIX PRESTO driver using libftdi.])
else
AC_DEFINE(BUILD_PRESTO_LIBFTDI, 0, [0 if you don't want the ASIX PRESTO driver using libftdi.])
fi
if test $build_presto_ftd2xx = yes; then
build_bitq=yes build_bitq=yes
AC_DEFINE(BUILD_PRESTO, 1, [1 if you want the ASIX PRESTO driver.]) AC_DEFINE(BUILD_PRESTO_FTD2XX, 1, [1 if you want the ASIX PRESTO driver using FTD2XX.])
else else
AC_DEFINE(BUILD_PRESTO, 0, [0 if you don't want the ASIX PRESTO driver.]) AC_DEFINE(BUILD_PRESTO_FTD2XX, 0, [0 if you don't want the ASIX PRESTO driver using FTD2XX.])
fi fi
if test $build_bitq = yes; then if test $build_bitq = yes; then
...@@ -222,7 +233,8 @@ AM_CONDITIONAL(FT2232_LIBFTDI, test $build_ft2232_libftdi = yes) ...@@ -222,7 +233,8 @@ AM_CONDITIONAL(FT2232_LIBFTDI, test $build_ft2232_libftdi = yes)
AM_CONDITIONAL(FT2232_FTD2XX, test $build_ft2232_ftd2xx = yes) AM_CONDITIONAL(FT2232_FTD2XX, test $build_ft2232_ftd2xx = yes)
AM_CONDITIONAL(AMTJTAGACCEL, test $build_amtjtagaccel = yes) AM_CONDITIONAL(AMTJTAGACCEL, test $build_amtjtagaccel = yes)
AM_CONDITIONAL(GW16012, test $build_gw16012 = yes) AM_CONDITIONAL(GW16012, test $build_gw16012 = yes)
AM_CONDITIONAL(PRESTO, test $build_presto = yes) AM_CONDITIONAL(PRESTO_LIBFTDI, test $build_presto_libftdi = yes)
AM_CONDITIONAL(PRESTO_FTD2XX, test $build_presto_ftd2xx = yes)
AM_CONDITIONAL(USBPROG, test $build_usbprog = yes) AM_CONDITIONAL(USBPROG, test $build_usbprog = yes)
AM_CONDITIONAL(OOCD_TRACE, test $build_oocd_trace = yes) AM_CONDITIONAL(OOCD_TRACE, test $build_oocd_trace = yes)
AM_CONDITIONAL(IS_CYGWIN, test $is_cygwin = yes) AM_CONDITIONAL(IS_CYGWIN, test $is_cygwin = yes)
......
...@@ -19,6 +19,9 @@ endif ...@@ -19,6 +19,9 @@ endif
if FT2232_LIBFTDI if FT2232_LIBFTDI
FTDI2232LIB = -lftdi FTDI2232LIB = -lftdi
else else
if PRESTO_LIBFTDI
FTDI2232LIB = -lftdi
endif
FTDI2232LIB = FTDI2232LIB =
endif endif
...@@ -41,7 +44,7 @@ endif ...@@ -41,7 +44,7 @@ endif
if FT2232_FTD2XX if FT2232_FTD2XX
FTD2XXLIB = $(FTD2XXLDADD) FTD2XXLIB = $(FTD2XXLDADD)
else else
if PRESTO if PRESTO_FTD2XX
FTD2XXLIB = $(FTD2XXLDADD) FTD2XXLIB = $(FTD2XXLDADD)
else else
FTD2XXLIB = FTD2XXLIB =
......
...@@ -326,7 +326,15 @@ int at91sam7_read_part_info(struct flash_bank_s *bank) ...@@ -326,7 +326,15 @@ int at91sam7_read_part_info(struct flash_bank_s *bank)
at91sam7_info->cidr_version = cidr&0x001F; at91sam7_info->cidr_version = cidr&0x001F;
bank->size = NVPSIZ[at91sam7_info->cidr_nvpsiz]; bank->size = NVPSIZ[at91sam7_info->cidr_nvpsiz];
at91sam7_info->target_name = "Unknown"; at91sam7_info->target_name = "Unknown";
/* Support just for bulk erase of the whole device */
bank->num_sectors = 1;
bank->sectors = malloc(sizeof(flash_sector_t));
bank->sectors[0].offset = 0;
bank->sectors[0].size = bank->size;
bank->sectors[0].is_erased = -1;
bank->sectors[0].is_protected = -1;
DEBUG("nvptyp: 0x%3.3x, arch: 0x%4.4x", at91sam7_info->cidr_nvptyp, at91sam7_info->cidr_arch ); DEBUG("nvptyp: 0x%3.3x, arch: 0x%4.4x", at91sam7_info->cidr_nvptyp, at91sam7_info->cidr_arch );
/* Read main and master clock freqency register */ /* Read main and master clock freqency register */
...@@ -565,22 +573,27 @@ int at91sam7_erase(struct flash_bank_s *bank, int first, int last) ...@@ -565,22 +573,27 @@ int at91sam7_erase(struct flash_bank_s *bank, int first, int last)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
if ((first < 0) || (last < first) || (last >= at91sam7_info->num_lockbits)) if ((first < 0) || (last < first) || (last >= bank->num_sectors))
{ {
return ERROR_FLASH_SECTOR_INVALID; if ((first == 0) && (last == (at91sam7_info->num_lockbits-1)))
{
WARNING("Sector numbers based on lockbit count, probably a deprecated script");
last = bank->num_sectors-1;
}
else return ERROR_FLASH_SECTOR_INVALID;
} }
/* Configure the flash controller timing */ if ((first != 0) || (last != (bank->num_sectors-1)))
at91sam7_read_clock_info(bank);
at91sam7_set_flash_mode(bank,FMR_TIMING_FLASH);
if ((first == 0) && (last == (at91sam7_info->num_lockbits-1)))
{ {
return at91sam7_flash_command(bank, EA, 0); WARNING("Can only erase the whole flash area, pages are autoerased on write");
return ERROR_FLASH_OPERATION_FAILED;
} }
WARNING("Can only erase the whole flash area, pages are autoerased on write"); /* Configure the flash controller timing */
return ERROR_FLASH_OPERATION_FAILED; at91sam7_read_clock_info(bank);
at91sam7_set_flash_mode(bank,FMR_TIMING_FLASH);
return at91sam7_flash_command(bank, EA, 0);
} }
int at91sam7_protect(struct flash_bank_s *bank, int set, int first, int last) int at91sam7_protect(struct flash_bank_s *bank, int set, int first, int last)
......
...@@ -738,24 +738,36 @@ int flash_erase(target_t *target, u32 addr, u32 length) ...@@ -738,24 +738,36 @@ int flash_erase(target_t *target, u32 addr, u32 length)
int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_str, u32 *failed) int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_str, u32 *failed)
{ {
int last_section;
int section; int section;
int next_section;
int retval; int retval;
*image_size = 0; *image_size = 0;
/* for each section in the image */ /* for each section in the image */
for (section = 0; section < image->num_sections; section++) last_section = 0;
section = 0;
while (section < image->num_sections)
{ {
u32 offset = 0; u32 offset = 0;
u32 address = image->sections[section].base_address; u32 address = image->sections[section].base_address;
u32 size = image->sections[section].size; u32 size = image->sections[section].size;
failed[section] = 0; /* collect consecutive sections */
next_section = section + 1;
while ((next_section < image->num_sections)
&& (image->sections[next_section].base_address == (address + size)))
{
size += image->sections[next_section].size;
next_section++;
}
while (size != 0) while (size != 0)
{ {
flash_bank_t *c; flash_bank_t *c;
u32 thisrun_size = size; u32 thisrun_size = size;
u32 buffer_size;
u32 size_read; u32 size_read;
u8 *buffer; u8 *buffer;
...@@ -767,23 +779,50 @@ int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_ ...@@ -767,23 +779,50 @@ int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_
break; break;
} }
/* check whether it fits, split into multiple runs if not */ /* check whether cumulated sections fit the bank, split into multiple runs if not */
if ((address + size) > (c->base + c->size)) if ((address + size) > (c->base + c->size))
thisrun_size = c->base + c->size - address; thisrun_size = c->base + c->size - address;
buffer = malloc(thisrun_size); buffer = malloc(thisrun_size);
if (((retval = image_read_section(image, section, offset, size, buffer, &size_read)) != ERROR_OK) buffer_size = 0;
|| (thisrun_size != size_read))
while (buffer_size < thisrun_size)
{ {
*error_str = malloc(FLASH_MAX_ERROR_STR); u32 thissection_size = image->sections[section].size - offset;
snprintf(*error_str, FLASH_MAX_ERROR_STR, "error reading from image");
return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE; if ((retval = image_read_section(image, section, offset,
MIN(thisrun_size, thissection_size),
buffer + buffer_size, &size_read)) != ERROR_OK)
{
*error_str = malloc(FLASH_MAX_ERROR_STR);
snprintf(*error_str, FLASH_MAX_ERROR_STR, "error reading from image");
return ERROR_IMAGE_TEMPORARILY_UNAVAILABLE;
}
/* see if we're done with the current section */
if (thissection_size < thisrun_size)
{
/* start with the next section */
offset = 0;
failed[section] = 0;
section++;
}
else
{
/* continue inside the current section */
offset += size_read;
}
buffer_size += size_read;
} }
if ((retval = c->driver->write(c, buffer, address - c->base, thisrun_size)) != ERROR_OK) if ((retval = c->driver->write(c, buffer, address - c->base, thisrun_size)) != ERROR_OK)
{ {
/* mark the current section as failed */ int i;
failed[section] = 1; /* mark sections as failed */
for (i = last_section; i <= section; i++)
failed[i] = 1;
*error_str = malloc(FLASH_MAX_ERROR_STR); *error_str = malloc(FLASH_MAX_ERROR_STR);
switch (retval) switch (retval)
{ {
...@@ -817,12 +856,11 @@ int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_ ...@@ -817,12 +856,11 @@ int flash_write(target_t *target, image_t *image, u32 *image_size, char **error_
free(buffer); free(buffer);
offset += thisrun_size;
address += thisrun_size; address += thisrun_size;
size -= thisrun_size; size -= thisrun_size;
*image_size += thisrun_size;
last_section = section;
} }
*image_size += image->sections[section].size;
} }
return ERROR_OK; return ERROR_OK;
......
...@@ -256,7 +256,7 @@ int handle_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, cha ...@@ -256,7 +256,7 @@ int handle_nand_device_command(struct command_context_s *cmd_ctx, char *cmd, cha
int nand_register_commands(struct command_context_s *cmd_ctx) int nand_register_commands(struct command_context_s *cmd_ctx)
{ {
nand_cmd = register_command(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, NULL); nand_cmd = register_command(cmd_ctx, NULL, "nand", NULL, COMMAND_ANY, "NAND specific commands");
register_command(cmd_ctx, nand_cmd, "device", handle_nand_device_command, COMMAND_CONFIG, NULL); register_command(cmd_ctx, nand_cmd, "device", handle_nand_device_command, COMMAND_CONFIG, NULL);
......
...@@ -65,9 +65,12 @@ else ...@@ -65,9 +65,12 @@ else
BITQFILES = BITQFILES =
endif endif
if PRESTO if PRESTO_LIBFTDI
PRESTOFILES = presto.c PRESTOFILES = presto.c
else else
if PRESTO_FTD2XX
PRESTOFILES = presto.c
endif
PRESTOFILES = PRESTOFILES =
endif endif
......
...@@ -162,7 +162,7 @@ jtag_event_callback_t *jtag_event_callbacks; ...@@ -162,7 +162,7 @@ jtag_event_callback_t *jtag_event_callbacks;
extern jtag_interface_t gw16012_interface; extern jtag_interface_t gw16012_interface;
#endif #endif
#if BUILD_PRESTO == 1 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
extern jtag_interface_t presto_interface; extern jtag_interface_t presto_interface;
#endif #endif
...@@ -192,7 +192,7 @@ jtag_interface_t *jtag_interfaces[] = { ...@@ -192,7 +192,7 @@ jtag_interface_t *jtag_interfaces[] = {
#if BUILD_GW16012 == 1 #if BUILD_GW16012 == 1
&gw16012_interface, &gw16012_interface,
#endif #endif
#if BUILD_PRESTO == 1 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
&presto_interface, &presto_interface,
#endif #endif
#if BUILD_USBPROG == 1 #if BUILD_USBPROG == 1
......
...@@ -44,7 +44,12 @@ ...@@ -44,7 +44,12 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include "ftd2xx.h" /* PRESTO access library includes */
#if BUILD_PRESTO_FTD2XX == 1
#include <ftd2xx.h>
#elif BUILD_PRESTO_LIBFTDI == 1
#include <ftdi.h>
#endif
int presto_jtag_speed(int speed); int presto_jtag_speed(int speed);
...@@ -67,7 +72,7 @@ jtag_interface_t presto_interface = ...@@ -67,7 +72,7 @@ jtag_interface_t presto_interface =
int presto_bitq_out(int tms, int tdi, int tdo_req); int presto_bitq_out(int tms, int tdi, int tdo_req);
int presto_bitq_flush(void); int presto_bitq_flush(void);
int presto_bitq_sleep(unsigned long us); int presto_bitq_sleep(unsigned long us);
int presto_bitq_reset(int rst, int en); int presto_bitq_reset(int trst, int srst);
int presto_bitq_in_rdy(void); int presto_bitq_in_rdy(void);
int presto_bitq_in(void); int presto_bitq_in(void);
...@@ -89,25 +94,27 @@ bitq_interface_t presto_bitq = ...@@ -89,25 +94,27 @@ bitq_interface_t presto_bitq =
#define FT_DEVICE_SERNUM_LEN 64 #define FT_DEVICE_SERNUM_LEN 64
#define PRESTO_VID_PID 0x0403f1a0 #define PRESTO_VID_PID 0x0403f1a0
#define PRESTO_VID (0x0403)
#define PRST_OK 0 #define PRESTO_PID (0xf1a0)
#define PRST_ERR 1
#define PRST_TIMEOUT 2
#define BUFFER_SIZE (64*62) #define BUFFER_SIZE (64*62)
typedef struct presto_s typedef struct presto_s
{ {
#if BUILD_PRESTO_FTD2XX == 1
FT_HANDLE handle; FT_HANDLE handle;
FT_STATUS status; FT_STATUS status;
#elif BUILD_PRESTO_LIBFTDI == 1
struct ftdi_context ftdic;
int retval;
#endif
char serial[FT_DEVICE_SERNUM_LEN]; char serial[FT_DEVICE_SERNUM_LEN];
BYTE buff_out[BUFFER_SIZE]; u8 buff_out[BUFFER_SIZE];
int buff_out_pos; int buff_out_pos;
BYTE buff_in[BUFFER_SIZE]; u8 buff_in[BUFFER_SIZE];
int buff_in_exp; /* expected in buffer length */ int buff_in_exp; /* expected in buffer length */
int buff_in_len; /* length of data received */ int buff_in_len; /* length of data received */
int buff_in_pos; int buff_in_pos;
...@@ -124,15 +131,88 @@ typedef struct presto_s ...@@ -124,15 +131,88 @@ typedef struct presto_s
} presto_t; } presto_t;
presto_t presto_state; presto_t presto_state;
presto_t *presto=&presto_state; presto_t *presto = &presto_state;
BYTE presto_init_seq[] = u8 presto_init_seq[] =
{ {
0x80, 0xA0, 0xA8, 0xB0, 0xC0, 0xE0 0x80, 0xA0, 0xA8, 0xB0, 0xC0, 0xE0
}; };
int presto_write(u8 *buf, int size, u32* bytes_written)
{
#if BUILD_PRESTO_FTD2XX == 1
DWORD dw_bytes_written;
if ((presto->status = FT_Write(presto->handle, buf, size, &dw_bytes_written)) != FT_OK)
{
*bytes_written = dw_bytes_written;
ERROR("FT_Write returned: %lu", presto->status);
return ERROR_JTAG_DEVICE_ERROR;
}
else
{
*bytes_written = dw_bytes_written;
return ERROR_OK;
}
#elif BUILD_PRESTO_LIBFTDI == 1
if ((presto->retval = ftdi_write_data(&presto->ftdic, buf, size)) < 0)
{
*bytes_written = 0;
ERROR("ftdi_write_data: %s", ftdi_get_error_string(&presto->ftdic));
return ERROR_JTAG_DEVICE_ERROR;
}
else
{
*bytes_written = retval;
return ERROR_OK;
}
#endif
}
int presto_open(char *req_serial) int presto_read(u8* buf, int size, u32* bytes_read)
{
#if BUILD_PRESTO_FTD2XX == 1
DWORD dw_bytes_read;
int timeout = 5;
*bytes_read = 0;
while ((*bytes_read < size) && timeout--)
{
if ((presto->status = FT_Read(presto->handle, buf + *bytes_read, size -
*bytes_read, &dw_bytes_read)) != FT_OK)
{
*bytes_read = 0;
ERROR("FT_Read returned: %lu", presto->status);
return ERROR_JTAG_DEVICE_ERROR;
}
*bytes_read += dw_bytes_read;
}
#elif BUILD_PRESTO_LIBFTDI == 1
int timeout = 100;
*bytes_read = 0;
while ((*bytes_read < size) && timeout--)
{
if ((presto->retval = ftdi_read_data(&presto->ftdic, buf + *bytes_read, size - *bytes_read)) < 0)
{
*bytes_read = 0;
ERROR("ftdi_read_data: %s", ftdi_get_error_string(&presto->ftdic));
return ERROR_JTAG_DEVICE_ERROR;
}
*bytes_read += retval;
}
#endif
if (*bytes_read < size)
{
ERROR("couldn't read the requested number of bytes from PRESTO (%i < %i)", *bytes_read, size);
return ERROR_JTAG_DEVICE_ERROR;
}
return ERROR_OK;
}
#if BUILD_PRESTO_FTD2XX == 1
int presto_open_ftd2xx(char *req_serial)
{ {
int i; int i;
DWORD numdevs; DWORD numdevs;
...@@ -144,90 +224,204 @@ int presto_open(char *req_serial) ...@@ -144,90 +224,204 @@ int presto_open(char *req_serial)
unsigned long ftbytes; unsigned long ftbytes;
presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE; presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE;
#if IS_WIN32 == 0
/* Add non-standard Vid/Pid to the linux driver */
if ((presto->status = FT_SetVIDPID(PRESTO_VID, PRESTO_PID)) != FT_OK)
{
ERROR("couldn't add PRESTO VID/PID");
exit(-1);
}
#endif
presto->buff_out_pos=0; if ((presto->status = FT_ListDevices(&numdevs, NULL, FT_LIST_NUMBER_ONLY)) != FT_OK)
presto->buff_in_pos=0;
presto->buff_in_len=0;
presto->buff_in_exp=0;
presto->total_out=0;
presto->total_in=0;
presto->jtag_tms=0;
presto->jtag_tck=0;
presto->jtag_tdi_data=0;
presto->jtag_tdi_count=0;
if (FT_ListDevices(&numdevs, NULL, FT_LIST_NUMBER_ONLY)!=FT_OK) return PRST_ERR;
for (i=0; i<numdevs; i++)
{ {
if (FT_Open(i, &(presto->handle))!=FT_OK) continue; ERROR("FT_ListDevices failed: %i", (int)presto->status);
if (FT_GetDeviceInfo(presto->handle,&device,&vidpid,presto->serial,devname,NULL)==FT_OK) return ERROR_JTAG_INIT_FAILED;
}
for (i = 0; i < numdevs; i++)
{
if (FT_Open(i, &(presto->handle)) != FT_OK)
{ {
if (vidpid==PRESTO_VID_PID && (req_serial==NULL || !strcmp(presto->serial,req_serial))) ERROR("FT_Open failed: %i", (int)presto->status);
continue;
}
if (FT_GetDeviceInfo(presto->handle, &device, &vidpid,
presto->serial, devname, NULL) == FT_OK)
{
if (vidpid == PRESTO_VID_PID
&& (req_serial == NULL || !strcmp(presto->serial, req_serial)))
break; break;
} }
FT_Close(presto->handle); FT_Close(presto->handle);
presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE; presto->handle = (FT_HANDLE)INVALID_HANDLE_VALUE;
} }
if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE) return PRST_ERR; if (presto->handle == (FT_HANDLE)INVALID_HANDLE_VALUE)
return ERROR_JTAG_INIT_FAILED;
if ((presto->status=FT_SetLatencyTimer(presto->handle,1))!=FT_OK) return PRST_ERR; if ((presto->status = FT_SetLatencyTimer(presto->handle, 1)) != FT_OK)
if ((presto->status=FT_SetTimeouts(presto->handle,100,0))!=FT_OK) return PRST_ERR; return ERROR_JTAG_INIT_FAILED;
if ((presto->status=FT_Purge(presto->handle, FT_PURGE_TX|FT_PURGE_RX))!=FT_OK) return PRST_ERR; if ((presto->status