From 83440065c00cce9d36f23182b439d7bf2306cfb2 Mon Sep 17 00:00:00 2001 From: drath Date: Sun, 5 Nov 2006 17:38:35 +0000 Subject: - correctly enter debug state on a "soft_reset_halt" command - several small fixes - retry reading from a FT2232 device on incomplete reads git-svn-id: svn://svn.berlios.de/openocd/trunk@110 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/jtag/ft2232.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/jtag') diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index e681b3e5..9af57dd1 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -189,15 +189,19 @@ int ft2232_read(u8* buf, int size, u32* bytes_read) #if BUILD_FT2232_FTD2XX == 1 DWORD dw_bytes_read; FT_STATUS status; - if ((status = FT_Read(ftdih, buf, size, &dw_bytes_read)) != FT_OK) + int timeout = 5; + *bytes_read = 0; + + while ((*bytes_read < size) && timeout--) { - *bytes_read = dw_bytes_read; - ERROR("FT_Read returned: %i", status); - return ERROR_JTAG_DEVICE_ERROR; + if ((status = FT_Read(ftdih, buf, size, &dw_bytes_read)) != FT_OK) + { + *bytes_read = 0; + ERROR("FT_Read returned: %i", status); + return ERROR_JTAG_DEVICE_ERROR; + } + *bytes_read += dw_bytes_read; } - *bytes_read = dw_bytes_read; - return ERROR_OK; - #elif BUILD_FT2232_LIBFTDI == 1 int retval; int timeout = 100; @@ -213,8 +217,15 @@ int ft2232_read(u8* buf, int size, u32* bytes_read) } *bytes_read += retval; } - return ERROR_OK; #endif + + if (*bytes_read < size) + { + ERROR("couldn't read the requested number of bytes from FT2232 device (%i < %i)", *bytes_read, size); + return ERROR_JTAG_DEVICE_ERROR; + } + + return ERROR_OK; } int ft2232_speed(int speed) -- cgit v1.2.3