ft2232.c is compiled either for ftd2xx or for libftdi. The two init functions had slightly different prototypes, making it neccessary to distinguish between them not only at declaration, but also when they were being called.
Since the code is only compiled for one library type we can homogenize the function parameters and contain the abstraction within a single ft2232_initone() function, which allows removing the CPP conditional in ft2232_init() that determined which function to call. ft2232_init_libftdi() took an extra channel parameter which came from the layout struct. layout is treated as a global variable however, already accessed directly both in ft2232_initone() and ft2232_init(), so the channel parameter is unneccessary, and can be removed without risk for new trouble or limitations. A context parameter that references the layout could be added if and when this code sees more significant cleanup in the future. --- src/jtag/drivers/ft2232.c | 24 +++++++++--------------- 1 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/jtag/drivers/ft2232.c b/src/jtag/drivers/ft2232.c index 1f0269a..cb50c50 100644 --- a/src/jtag/drivers/ft2232.c +++ b/src/jtag/drivers/ft2232.c @@ -2115,7 +2115,8 @@ static int ft2232_execute_queue(void) } #if BUILD_FT2232_FTD2XX == 1 -static int ft2232_init_ftd2xx(uint16_t vid, uint16_t pid, int more, int* try_more) + +static int ft2232_initone(uint16_t vid, uint16_t pid, int more, int* try_more) { FT_STATUS status; DWORD deviceID; @@ -2290,10 +2291,9 @@ static int ft2232_purge_ftd2xx(void) return ERROR_OK; } -#endif /* BUILD_FT2232_FTD2XX == 1 */ +#elif BUILD_FT2232_LIBFTDI == 1 -#if BUILD_FT2232_LIBFTDI == 1 -static int ft2232_init_libftdi(uint16_t vid, uint16_t pid, int more, int* try_more, int channel) +static int ft2232_initone(uint16_t vid, uint16_t pid, int more, int* try_more) { uint8_t latency_timer; @@ -2309,9 +2309,9 @@ static int ft2232_init_libftdi(uint16_t vid, uint16_t pid, int more, int* try_mo return ERROR_JTAG_INIT_FAILED; /* default to INTERFACE_A */ - if(channel == INTERFACE_ANY) { channel = INTERFACE_A; } + if(layout->channel == INTERFACE_ANY) { layout->channel = INTERFACE_A; } - if (ftdi_set_interface(&ftdic, channel) < 0) + if (ftdi_set_interface(&ftdic, layout->channel) < 0) { LOG_ERROR("unable to select FT2232 channel A: %s", ftdic.error_str); return ERROR_JTAG_INIT_FAILED; @@ -2376,7 +2376,7 @@ static int ft2232_purge_libftdi(void) return ERROR_OK; } -#endif /* BUILD_FT2232_LIBFTDI == 1 */ +#endif static int ft2232_set_data_bits_low_byte( uint8_t value, uint8_t direction ) { @@ -2452,14 +2452,8 @@ static int ft2232_init(void) int more = ft2232_vid[i + 1] || ft2232_pid[i + 1]; int try_more = 0; -#if BUILD_FT2232_FTD2XX == 1 - retval = ft2232_init_ftd2xx(ft2232_vid[i], ft2232_pid[i], - more, &try_more); -#elif BUILD_FT2232_LIBFTDI == 1 - retval = ft2232_init_libftdi(ft2232_vid[i], ft2232_pid[i], - more, &try_more, layout->channel); -#endif - if (retval >= 0) + retval = ft2232_initone(ft2232_vid[i], ft2232_pid[i], more, &try_more); + if (ERROR_OK == retval) break; if (!more || !try_more) return retval; -- 1.7.4.1.343.ga91df.dirty _______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development