Like with ft2232_init_ftd2xx() and ft2232_init_libftdi() it helps to
keep abstraction between ftd2xx and libftdi in only one place in the
source code; this time in a ft2232_purge() function.
---
 src/jtag/drivers/ft2232.c |   50 ++++++++++++++++++--------------------------
 1 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/src/jtag/drivers/ft2232.c b/src/jtag/drivers/ft2232.c
index 219d41f..9315eff 100644
--- a/src/jtag/drivers/ft2232.c
+++ b/src/jtag/drivers/ft2232.c
@@ -2280,19 +2280,6 @@ static int ft2232_initone(uint16_t vid, uint16_t pid, 
int more, int* try_more)
        return ERROR_OK;
 }
 
-static int ft2232_purge_ftd2xx(void)
-{
-       FT_STATUS status;
-
-       if ((status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX)) != FT_OK)
-       {
-               LOG_ERROR("error purging ftd2xx device: %lu", status);
-               return ERROR_JTAG_INIT_FAILED;
-       }
-
-       return ERROR_OK;
-}
-
 #elif BUILD_FT2232_LIBFTDI == 1
 
 static int ft2232_initone(uint16_t vid, uint16_t pid, int more, int* try_more)
@@ -2367,17 +2354,6 @@ static int ft2232_initone(uint16_t vid, uint16_t pid, 
int more, int* try_more)
        return ERROR_OK;
 }
 
-static int ft2232_purge_libftdi(void)
-{
-       if (ftdi_usb_purge_buffers(&ftdic) < 0)
-       {
-               LOG_ERROR("ftdi_purge_buffers: %s", ftdic.error_str);
-               return ERROR_JTAG_INIT_FAILED;
-       }
-
-       return ERROR_OK;
-}
-
 #endif
 
 static int ft2232_set_data_bits_low_byte( uint8_t value, uint8_t direction )
@@ -2420,6 +2396,26 @@ static int ft2232_set_data_bits_high_byte( uint8_t 
value, uint8_t direction )
        return ERROR_OK;
 }
 
+static int ft2232_purge(void)
+{
+#if BUILD_FT2232_FTD2XX == 1
+       FT_STATUS status;
+
+       if ((status = FT_Purge(ftdih, FT_PURGE_RX | FT_PURGE_TX)) != FT_OK)
+       {
+               LOG_ERROR("error purging ftd2xx device: %lu", status);
+               return ERROR_JTAG_INIT_FAILED;
+       }
+#elif BUILD_FT2232_LIBFTDI == 1
+       if (ftdi_usb_purge_buffers(&ftdic) < 0)
+       {
+               LOG_ERROR("ftdi_purge_buffers: %s", ftdic.error_str);
+               return ERROR_JTAG_INIT_FAILED;
+       }
+#endif
+       return ERROR_OK;
+}
+
 static int ft2232_init(void)
 {
        uint8_t  buf[1];
@@ -2488,11 +2484,7 @@ static int ft2232_init(void)
                goto quit;
        }
 
-#if BUILD_FT2232_FTD2XX == 1
-       if (ft2232_purge_ftd2xx() != ERROR_OK)
-#elif BUILD_FT2232_LIBFTDI == 1
-       if (ft2232_purge_libftdi() != ERROR_OK)
-#endif
+       if (ft2232_purge() != ERROR_OK)
                goto quit;
 
        return ERROR_OK;
-- 
1.7.4.1.343.ga91df.dirty

_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to