diff --git a/DSP_API/.cproject b/DSP_API/.cproject index 91dc741..0e2ef20 100644 --- a/DSP_API/.cproject +++ b/DSP_API/.cproject @@ -14,7 +14,7 @@ - + @@ -25,11 +25,12 @@ @@ -91,7 +96,7 @@ - + @@ -106,11 +111,12 @@ - + @@ -126,15 +132,18 @@ - + - + diff --git a/DSP_API/SmartSDR_Interface/discovery_client.c b/DSP_API/SmartSDR_Interface/discovery_client.c index cb59590..d6d4461 100644 --- a/DSP_API/SmartSDR_Interface/discovery_client.c +++ b/DSP_API/SmartSDR_Interface/discovery_client.c @@ -38,6 +38,8 @@ #include // for errno #include +#include + #include "common.h" #include "discovery_client.h" #include "cmd.h" // for tokenize @@ -253,6 +255,7 @@ static BOOL _dc_ListenerRecv(uint8* buffer, int32* len, struct sockaddr_in* send static void* _dc_ListenerLoop(void* param) { //printf("_dc_ListenerLoop\n"); + prctl(PR_SET_NAME, "DV-ListenerLoop"); struct sockaddr_in sender; uint8 buf[ETH_FRAME_LEN]; diff --git a/DSP_API/SmartSDR_Interface/hal_listener.c b/DSP_API/SmartSDR_Interface/hal_listener.c index 736a175..7704c63 100644 --- a/DSP_API/SmartSDR_Interface/hal_listener.c +++ b/DSP_API/SmartSDR_Interface/hal_listener.c @@ -41,6 +41,7 @@ #include // for errno #include // for usleep #include +#include // #define LOG_MODULE LOG_MODULE_HAL_LISTENER @@ -430,6 +431,7 @@ static void* _hal_ListenerLoop(void* param) struct sockaddr_in sender; uint8 buf[ETH_FRAME_LEN]; + prctl(PR_SET_NAME, "DV-halListener"); while(!hal_listen_abort) { diff --git a/DSP_API/SmartSDR_Interface/sched_waveform.c b/DSP_API/SmartSDR_Interface/sched_waveform.c index 273d644..b211081 100644 --- a/DSP_API/SmartSDR_Interface/sched_waveform.c +++ b/DSP_API/SmartSDR_Interface/sched_waveform.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "common.h" #include "datatypes.h" @@ -51,6 +52,7 @@ #include "dstar.h" #include "DStarDefines.h" #include "slow_data.h" +#include "ftd2xx.h" //static Queue sched_fft_queue; static pthread_rwlock_t _list_lock; @@ -145,11 +147,11 @@ void sched_waveform_signal() { //#define SCALE_TX_IN 32767.0f // Multiplier // Was 16000 GGH Jan 30, 2015 //#define SCALE_TX_OUT 32767.0f // Divisor -#define SCALE_RX_IN SCALE_AMBE +#define SCALE_RX_IN SCALE_AMBE*2.0 #define SCALE_TX_OUT SCALE_AMBE -#define SCALE_RX_OUT SCALE_AMBE +#define SCALE_RX_OUT SCALE_AMBE*2.0 #define SCALE_TX_IN SCALE_AMBE @@ -185,7 +187,7 @@ Circular_Short_Buffer TX3_cb = &tx3_cb; circular_float_buffer tx4_cb; Circular_Float_Buffer TX4_cb = &tx4_cb; -static int _dv_serial_fd = 0; +static FT_HANDLE _dv_serial_handle = 0; static GMSK_DEMOD _gmsk_demod = NULL; static GMSK_MOD _gmsk_mod = NULL; @@ -353,8 +355,8 @@ void sched_waveform_setMessage( uint32 slice, const char * message) output( "TX Message: '%s' : strlen() = %d \n", _dstar->slow_encoder->message , strlen(_dstar->slow_encoder->message)); } -void sched_waveform_setFD( int fd ) { - _dv_serial_fd = fd; +void sched_waveform_setHandle( FT_HANDLE * handle ) { + _dv_serial_handle = *handle; } void sched_waveform_setEndOfTX( BOOL end_of_transmission ) { @@ -369,6 +371,8 @@ void sched_waveform_setDSTARSlice( uint32 slice ) } static void * _sched_waveform_thread( void * param ) { + + prctl(PR_SET_NAME, "DV-SchedWav"); int nout; int i; // for loop counter @@ -405,7 +409,7 @@ static void * _sched_waveform_thread( void * param ) { // ======================= Initialization Section ========================= - thumbDV_init( &_dv_serial_fd ); + thumbDV_init( &_dv_serial_handle ); // Initialize the Circular Buffers @@ -516,7 +520,7 @@ static void * _sched_waveform_thread( void * param ) { if ( ambe_packet_out == TRUE ) { nout = 0; - nout = thumbDV_decode( _dv_serial_fd, ambe_out, speech_out, DV_PACKET_SAMPLES ); + nout = thumbDV_decode( _dv_serial_handle, ambe_out, speech_out, DV_PACKET_SAMPLES ); uint32 j = 0; for ( j = 0 ; j < nout ; j++ ) @@ -632,7 +636,7 @@ static void * _sched_waveform_thread( void * param ) { } /* DECODE */ - decode_out = thumbDV_encode( _dv_serial_fd, speech_in, mod_out, DV_PACKET_SAMPLES ); + decode_out = thumbDV_encode( _dv_serial_handle, speech_in, mod_out, DV_PACKET_SAMPLES ); } if ( initial_tx ) { diff --git a/DSP_API/SmartSDR_Interface/sched_waveform.h b/DSP_API/SmartSDR_Interface/sched_waveform.h index 250f8ed..7d57c1f 100644 --- a/DSP_API/SmartSDR_Interface/sched_waveform.h +++ b/DSP_API/SmartSDR_Interface/sched_waveform.h @@ -35,6 +35,7 @@ #define SCHED_WAVEFORM_H_ #include "hal_buffer.h" +#include "ftd2xx.h" void sched_waveform_Schedule(BufferDescriptor buf); void sched_waveform_Init(void); @@ -49,7 +50,7 @@ void sched_waveform_setOwnCall2(uint32 slice , const char * owncall2 ); void sched_waveform_setMessage( uint32 slice, const char * message); void sched_waveform_sendStatus(uint32 slice); -void sched_waveform_setFD(int fd); +void sched_waveform_setHandle( FT_HANDLE * handle ); void sched_waveform_setEndOfTX(BOOL end_of_transmission); void sched_waveform_setDSTARSlice( uint32 slice ); #endif /* SCHED_WAVEFORM_H_ */ diff --git a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c index 1b2b356..7f0f11e 100644 --- a/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c +++ b/DSP_API/SmartSDR_Interface/smartsdr_dsp_api.c @@ -38,6 +38,7 @@ #include #include +#include #include // File Control functions #include "common.h" @@ -92,6 +93,7 @@ void SmartSDR_API_Shutdown(void) void* _console_thread(void* param) { + prctl(PR_SET_NAME, "DV-Console"); cmd_banner(); output(PROMPT); // let everybody know we're through printing diff --git a/DSP_API/SmartSDR_Interface/traffic_cop.c b/DSP_API/SmartSDR_Interface/traffic_cop.c index d654547..2581238 100644 --- a/DSP_API/SmartSDR_Interface/traffic_cop.c +++ b/DSP_API/SmartSDR_Interface/traffic_cop.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "common.h" #include "traffic_cop.h" @@ -343,6 +344,8 @@ static void* _tc_thread(void* arg) { uint32 result; + prctl(PR_SET_NAME, "DV-TrafficCop"); + memset(&__local, 0, sizeof(receive_data)); __local.last_ping.tv_sec = 0; __local.recv_buf = safe_malloc(RECV_BUF_SIZE); @@ -575,6 +578,8 @@ static void* _keepalive_thread(void* param) { char* response; + prctl(PR_SET_NAME, "DV-KeepAlive"); + /* Sleep 2 seconds */ usleep(2000000); diff --git a/DSP_API/SmartSDR_Interface/vita_output.c b/DSP_API/SmartSDR_Interface/vita_output.c index 4e546bc..aa69a25 100644 --- a/DSP_API/SmartSDR_Interface/vita_output.c +++ b/DSP_API/SmartSDR_Interface/vita_output.c @@ -135,9 +135,9 @@ static void _vita_formatWaveformPacket(Complex* buffer, uint32 samples, uint32 s } static uint32 _waveform_packet_count = 0; + void emit_waveform_output(BufferDescriptor buf_desc_out) { - int samples_sent, samples_to_send; Complex * buf_pointer; diff --git a/DSP_API/ThumbDV/thumbDV.c b/DSP_API/ThumbDV/thumbDV.c index 173ea18..7302889 100644 --- a/DSP_API/ThumbDV/thumbDV.c +++ b/DSP_API/ThumbDV/thumbDV.c @@ -41,11 +41,13 @@ #include #include #include +#include #include #include #include #include +#include #include @@ -56,10 +58,7 @@ #include "vita_output.h" #include "thumbDV.h" #include "sched_waveform.h" - - -#define DV3000_TTY "/dev/ttyAMA0" -#define DV3000_VERSION "2014-04-23" +#include "ftd2xx.h" #define AMBE3000_HEADER_LEN 4U #define AMBE3000_START_BYTE 0x61U @@ -278,104 +277,86 @@ void thumbDV_dump( char * text, unsigned char * data, unsigned int length ) { } } -static void thumbDV_writeSerial( int serial_fd, const unsigned char * buffer, uint32 bytes ) { - fd_set fds; +static void thumbDV_writeSerial( FT_HANDLE handle , unsigned char * buffer, uint32 bytes ) +{ + FT_STATUS status = FT_OK; + DWORD written = 0; - FD_ZERO( &fds ); - FD_SET( serial_fd, &fds ); + if ( handle != NULL ) + { + status = FT_Write(handle, buffer, bytes, &written); - int32 n = 0; - errno = 0; - struct timeval timeout; - timeout.tv_sec = 1; - timeout.tv_usec = 0; - select( serial_fd + 1, NULL, &fds, NULL, &timeout ); - - if ( FD_ISSET( serial_fd, &fds ) ) { - n = write( serial_fd , buffer, bytes ); - - if ( n != bytes ) { - output( ANSI_RED "Could not write to serial port. errno = %d\n", errno ); + if ( status != FT_OK || written != bytes ) { + output( ANSI_RED "Could not write to serial port. status = %d\n", status ); return; } - } else { + } + else + { output( ANSI_RED "Could not write to serial port. Timeout\n" ANSI_WHITE ); } } -static int _check_serial( int fd ) { +static int _check_serial( FT_HANDLE handle ) +{ + unsigned char reset[5] = { 0x61, 0x00, 0x01, 0x00, 0x33 }; - thumbDV_writeSerial( fd, reset, 5 ); + thumbDV_writeSerial( handle, reset, 5 ); - fd_set fds; - struct timeval timeout; + int ret = thumbDV_processSerial(handle); - FD_ZERO( &fds ); - FD_SET( fd, &fds ); - errno = 0; - timeout.tv_sec = 2; - timeout.tv_usec = 0; - select( fd + 1, &fds, NULL, NULL, &timeout ); - - if ( FD_ISSET( fd, &fds ) ) { - int ret = thumbDV_processSerial( fd ); - - if ( ret != 0 ) { - output( "Could not reset serial port FD = %d \n", fd ); - return -1; - } - } else { - output( "Could not reset serial port FD = %d \n", fd ); + if ( ret != 0 ) + { + output( "Could not reset serial port FD = %d \n", handle ); return -1; } unsigned char get_prodID[5] = {0x61, 0x00, 0x01, 0x00, 0x30 }; - thumbDV_writeSerial( fd, get_prodID, 5 ); + thumbDV_writeSerial( handle, get_prodID, 5 ); - FD_ZERO( &fds ); - FD_SET( fd, &fds ); - errno = 0; - timeout.tv_sec = 2; - timeout.tv_usec = 0; - select( fd + 1, &fds, NULL, NULL, &timeout ); + ret = thumbDV_processSerial(handle); - if ( FD_ISSET( fd, &fds ) ) { - int ret = thumbDV_processSerial( fd ); - - if ( ret != 0 ) { - output( "Could not get prodID serial port FD = %d \n", fd ); - return -1; - } - } else { - output( "Could not prodID serial port FD = %d \n", fd ); + if ( ret != 0 ) + { + output( "Could not reset serial port FD = %d \n", handle ); return -1; } + return 0 ; } -int thumbDV_openSerial( const char * tty_name ) { - struct termios tty; - int fd; +FT_HANDLE thumbDV_openSerial( FT_DEVICE_LIST_INFO_NODE device ) +{ + //struct termios tty; + FT_HANDLE handle = NULL; + FT_STATUS status = FT_OK; - /* TODO: Sanitize tty_name */ + output("Trying to open serial port %s", device.SerialNumber); - fd = open( tty_name, O_RDWR | O_NOCTTY | O_SYNC ); + status = FT_OpenEx(device.SerialNumber, FT_OPEN_BY_SERIAL_NUMBER, &handle); - if ( fd < 0 ) { - output( "ThumbDV: error when opening %s, errno=%d\n", tty_name, errno ); - return fd; + if ( status != FT_OK || handle == NULL ) + { + if ( device.SerialNumber ) + output("Error opening device %s - error 0x%X\n", device.SerialNumber, status); + else + output("Error opening device - error 0x%X\n", status); + + return NULL; } - if ( tcgetattr( fd, &tty ) != 0 ) { - output( "ThumbDV: error %d from tcgetattr\n", errno ); - return -1; - } + FT_SetBaudRate(handle, FT_BAUD_460800); - cfsetospeed( &tty, B460800 ); - cfsetispeed( &tty, B460800 ); + // Set read and write timeout to 2seconds */ + FT_SetTimeouts(handle, 0, 0); + + FT_SetDataCharacteristics(handle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE); + FT_SetFlowControl(handle, FT_FLOW_NONE, 0, 0); + +/* tty.c_cflag = ( tty.c_cflag & ~CSIZE ) | CS8; tty.c_iflag &= ~IGNBRK; tty.c_lflag = 0; @@ -397,72 +378,83 @@ int thumbDV_openSerial( const char * tty_name ) { close( fd ); return -1; } - - if ( _check_serial( fd ) != 0 ) { +*/ + if ( _check_serial(handle) != 0 ) { output( "Could not detect ThumbDV at 460800 Baud. Trying 230400\n" ); - close( fd ); + FT_Close(handle); + handle = (FT_HANDLE)NULL; } else { - return fd; + return handle; } - fd = open( tty_name, O_RDWR | O_NOCTTY | O_SYNC ); + status = FT_OpenEx(device.SerialNumber, FT_OPEN_BY_SERIAL_NUMBER, &handle); - if ( fd < 0 ) { - output( "ThumbDV: error when opening %s, errno=%d\n", tty_name, errno ); - return fd; + if ( status != FT_OK || handle == NULL ) + { + if ( device.SerialNumber ) + output("Error opening device %s - error 0x%X\n", device.SerialNumber, status); + else + output("Error opening device - error 0x%X\n", status); + + return NULL; } - if ( tcgetattr( fd, &tty ) != 0 ) { - output( "ThumbDV: error %d from tcgetattr\n", errno ); - return -1; - } + FT_SetBaudRate(handle, FT_BAUD_230400 ); - cfsetospeed( &tty, B230400 ); - cfsetispeed( &tty, B230400 ); + FT_SetTimeouts(handle, 0, 0); - tty.c_cflag = ( tty.c_cflag & ~CSIZE ) | CS8; - tty.c_iflag &= ~IGNBRK; - tty.c_lflag = 0; - tty.c_oflag = 0; - tty.c_cc[VMIN] = 1; - tty.c_cc[VTIME] = 5; + FT_SetDataCharacteristics(handle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE); + FT_SetFlowControl(handle, FT_FLOW_NONE, 0, 0); - tty.c_iflag &= ~( IXON | IXOFF | IXANY ); - tty.c_cflag |= ( CLOCAL | CREAD ); - - tty.c_cflag &= ~( PARENB | PARODD ); - tty.c_cflag &= ~CSTOPB; - tty.c_cflag &= ~CRTSCTS; - - if ( tcsetattr( fd, TCSANOW, &tty ) != 0 ) { - output( "ThumbDV: error %d from tcsetattr\n", errno ); - close( fd ); - return -1; - } - - if ( _check_serial( fd ) != 0 ) { + if ( _check_serial( handle ) != 0 ) { output( "Could not detect THumbDV at 230400 Baud\n" ); - close( fd ); - return -1; + FT_Close(handle); + handle = NULL; + return NULL; } - return fd; + return handle; } -int thumbDV_processSerial( int serial_fd ) { +int thumbDV_processSerial( FT_HANDLE handle ) +{ unsigned char buffer[BUFFER_LENGTH]; unsigned int respLen; - unsigned int offset; - ssize_t len; + uint32 offset = 0; + unsigned char packet_type; + FT_STATUS status = FT_OK; + DWORD rx_bytes = 0; + DWORD tx_bytes = 0 ; + DWORD event_word = 0; + uint32 max_us_sleep = 100000; // 100 ms + uint32 us_slept = 0; + do + { + status = FT_GetStatus(handle, &rx_bytes, &tx_bytes, &event_word); - errno = 0; - len = read( serial_fd, buffer, 1 ); + if ( rx_bytes >= AMBE3000_HEADER_LEN ) + break; - if ( len != 1 ) { - output( ANSI_RED "ThumbDV: Process serial. error when reading from the serial port, len = %d, errno=%d\n" ANSI_WHITE, len, errno ); + usleep(100); + + us_slept += 100; + + if ( us_slept > max_us_sleep ) + { + output("TimeOut\n"); + return 1; + } + + } while (rx_bytes < AMBE3000_HEADER_LEN && status == FT_OK ); + + status = FT_Read(handle, buffer, AMBE3000_HEADER_LEN, &rx_bytes); + + if ( status != FT_OK || rx_bytes != AMBE3000_HEADER_LEN) + { + output( ANSI_RED "ThumbDV: Process serial. error when reading from the serial port, len = %d, status=%d\n" ANSI_WHITE, rx_bytes, status ); return 1; } @@ -473,26 +465,33 @@ int thumbDV_processSerial( int serial_fd ) { offset = 0U; - while ( offset < ( AMBE3000_HEADER_LEN - 1U ) ) { - len = read( serial_fd, buffer + 1U + offset, AMBE3000_HEADER_LEN - 1 - offset ); - - if ( len == 0 ) - delay( 5UL ); - - offset += len; - } - respLen = buffer[1U] * 256U + buffer[2U]; - offset = 0U; + us_slept = 0; + do + { + status = FT_GetStatus(handle, &rx_bytes, &tx_bytes, &event_word); - while ( offset < respLen ) { - len = read( serial_fd, buffer + AMBE3000_HEADER_LEN + offset, respLen - offset ); + if ( rx_bytes >= respLen ) + break; - if ( len == 0 ) - delay( 5UL ); + usleep(1000); - offset += len; + us_slept += 1000 ; + + if ( us_slept > max_us_sleep ) + { + output("TimeOut\n"); + return 1; + } + + } while (rx_bytes < respLen && status == FT_OK); + + status = FT_Read(handle, buffer + AMBE3000_HEADER_LEN , respLen, &rx_bytes); + + if ( status != FT_OK || rx_bytes != respLen ) + { + output( ANSI_RED "ThumbDV: Process serial. error when reading from the serial port, len = %d, status=%d\n" ANSI_WHITE, rx_bytes, status ); } respLen += AMBE3000_HEADER_LEN; @@ -526,12 +525,12 @@ int thumbDV_processSerial( int serial_fd ) { return 0; } -int thumbDV_decode( int serial_fd, unsigned char * packet_in, short * speech_out, uint8 bytes_in_packet ) { +int thumbDV_decode( FT_HANDLE handle, unsigned char * packet_in, short * speech_out, uint8 bytes_in_packet ) { uint32 i = 0; unsigned char full_packet[15] = {0}; - if ( packet_in != NULL && serial_fd > 0 ) { + if ( packet_in != NULL && handle != NULL ) { full_packet[0] = 0x61; full_packet[1] = 0x00; full_packet[2] = 0x0B; @@ -546,7 +545,7 @@ int thumbDV_decode( int serial_fd, unsigned char * packet_in, short * speech_out // thumbDV_dump("Just AMBE", packet_in, 9); // thumbDV_dump("Encoded packet:", full_packet, 15); - thumbDV_writeSerial( serial_fd, full_packet, 15 ); + thumbDV_writeSerial( handle, full_packet, 15 ); } int32 samples_returned = 0; @@ -584,7 +583,8 @@ int thumbDV_decode( int serial_fd, unsigned char * packet_in, short * speech_out return samples_returned; } -int thumbDV_encode( int serial_fd, short * speech_in, unsigned char * packet_out, uint8 num_of_samples ) { +int thumbDV_encode( FT_HANDLE handle, short * speech_in, unsigned char * packet_out, uint8 num_of_samples ) +{ unsigned char packet[THUMBDV_MAX_PACKET_LEN]; uint16 speech_d_bytes = num_of_samples * sizeof( uint16 ); /* Should be 2 times the number of samples */ @@ -634,8 +634,8 @@ int thumbDV_encode( int serial_fd, short * speech_in, unsigned char * packet_out idx[1] = ( speech_in[i] & 0x00FF ) ; } - if ( serial_fd > 0 ) - thumbDV_writeSerial( serial_fd, packet, length + AMBE3000_HEADER_LEN ); + if ( handle != NULL ) + thumbDV_writeSerial( handle, packet, length + AMBE3000_HEADER_LEN ); int32 samples_returned = 0; BufferDescriptor desc = _thumbDVEncodedList_UnlinkHead(); @@ -655,120 +655,142 @@ int thumbDV_encode( int serial_fd, short * speech_in, unsigned char * packet_out } - -static void _connectSerial( int * serial_fd ) { +static void _connectSerial( FT_HANDLE * ftHandle ) +{ int i = 0 ; - char device[256] = {0} ; + + output("ConnectSerial\n"); + + DWORD numDevs = 0; + FT_DEVICE_LIST_INFO_NODE *devInfo = NULL; + FT_STATUS status = FT_OK; do { - for ( i = 0 ; i < 25 ; i++ ) { - sprintf( device, "/dev/ttyUSB%d", i ); - *serial_fd = thumbDV_openSerial( device ); - if ( *serial_fd > 0 ) { - /* We opened a valid port */ + status = FT_CreateDeviceInfoList(&numDevs); + + devInfo = (FT_DEVICE_LIST_INFO_NODE *) safe_malloc(sizeof(FT_DEVICE_LIST_INFO_NODE) * numDevs); + + status = FT_GetDeviceInfoList(devInfo, &numDevs); + + for ( i = 0 ; i < numDevs ; i++ ) + { + + *ftHandle = thumbDV_openSerial(devInfo[i]); + + if ( *ftHandle != NULL ) + { + /* We opened a valid port and detected the ThumbDV */ break; } } + safe_free(devInfo); - if ( * serial_fd < 0 ) { + if ( *ftHandle == NULL ) { output( "Could not open serial. Waiting 1 second before trying again.\n" ); usleep( 1000 * 1000 ); } - } while ( *serial_fd < 0 ) ; + } while ( *ftHandle == NULL ) ; unsigned char reset[5] = { 0x61, 0x00, 0x01, 0x00, 0x33 }; - thumbDV_writeSerial( *serial_fd, reset, 5 ); + thumbDV_writeSerial( *ftHandle, reset, 5 ); /* Block until we get data from serial port after reset */ - thumbDV_processSerial( *serial_fd ); + thumbDV_processSerial( *ftHandle ); // // unsigned char reset_softcfg[11] = {0x61, 0x00, 0x07, 0x00, 0x34, 0x05, 0x03, 0xEB, 0xFF, 0xFF, 0xFF}; -// thumbDV_writeSerial(*serial_fd, reset_softcfg, 11); -// thumbDV_processSerial(*serial_fd); +// thumbDV_writeSerial(*ftHandle, reset_softcfg, 11); +// thumbDV_processSerial(*ftHandle); unsigned char disable_parity[6] = {0x61, 0x00, 0x02, 0x00, 0x3F, 0x00}; - thumbDV_writeSerial( *serial_fd, disable_parity, 6 ); - thumbDV_processSerial( *serial_fd ); + thumbDV_writeSerial( *ftHandle, disable_parity, 6 ); + thumbDV_processSerial( *ftHandle ); unsigned char get_prodID[5] = {0x61, 0x00, 0x01, 0x00, 0x30 }; unsigned char get_version[5] = {0x61, 0x00, 0x01, 0x00, 0x31}; unsigned char read_cfg[5] = {0x61, 0x00, 0x01, 0x00, 0x37}; unsigned char dstar_mode[17] = {0x61, 0x00, 0x0D, 0x00, 0x0A, 0x01, 0x30, 0x07, 0x63, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48}; - thumbDV_writeSerial( *serial_fd, get_prodID, 5 ); - thumbDV_writeSerial( *serial_fd, get_version, 5 ); - thumbDV_writeSerial( *serial_fd, read_cfg, 5 ); - thumbDV_writeSerial( *serial_fd, dstar_mode, 17 ); + thumbDV_writeSerial( *ftHandle, get_prodID, 5 ); + thumbDV_writeSerial( *ftHandle, get_version, 5 ); + thumbDV_writeSerial( *ftHandle, read_cfg, 5 ); + thumbDV_writeSerial( *ftHandle, dstar_mode, 17 ); //// /* Init */ unsigned char pkt_init[6] = { 0x61, 0x00, 0x02, 0x00, 0x0B, 0x07 }; - thumbDV_writeSerial( *serial_fd, pkt_init, 6 ); + thumbDV_writeSerial( *ftHandle, pkt_init, 6 ); /* PKT GAIN - set to 0dB */ unsigned char pkt_gain[7] = { 0x61, 0x00, 0x03, 0x00, 0x4B, 0x00, 0x00 }; - thumbDV_writeSerial( *serial_fd, pkt_gain, 7 ); + thumbDV_writeSerial( *ftHandle, pkt_gain, 7 ); /* Companding off so it uses 16bit linear */ unsigned char pkt_compand[6] = { 0x61, 0x00, 0x02, 0x00, 0x32, 0x00 }; - thumbDV_writeSerial( *serial_fd, pkt_compand, 6 ); + thumbDV_writeSerial( *ftHandle, pkt_compand, 6 ); unsigned char test_coded[15] = {0x61, 0x00 , 0x0B , 0x01 , 0x01 , 0x48 , 0x5E , 0x83 , 0x12 , 0x3B , 0x98 , 0x79 , 0xDE , 0x13 , 0x90}; - thumbDV_writeSerial( *serial_fd, test_coded, 15 ); + thumbDV_writeSerial( *ftHandle, test_coded, 15 ); unsigned char pkt_fmt[7] = {0x61, 0x00, 0x3, 0x00, 0x15, 0x00, 0x00}; - thumbDV_writeSerial( *serial_fd, pkt_fmt, 7 ); + thumbDV_writeSerial( *ftHandle, pkt_fmt, 7 ); } -static void * _thumbDV_readThread( void * param ) { - int topFd; - fd_set fds; +static void * _thumbDV_readThread( void * param ) +{ int ret; + DWORD rx_bytes; + DWORD tx_bytes; + DWORD event_dword; - int serial_fd = *( int * )param; - topFd = serial_fd + 1; + FT_STATUS status = FT_OK; + FT_HANDLE handle = *( FT_HANDLE * )param; + EVENT_HANDLE event_handle; - output( "Serial FD = %d in thumbDV_readThread(). TopFD = %d\n", serial_fd, topFd ); + prctl(PR_SET_NAME, "DV-Read"); - struct timeval timeout; + pthread_mutex_init(&event_handle.eMutex, NULL); + pthread_cond_init(&event_handle.eCondVar, NULL); - while ( !_readThreadAbort ) { - timeout.tv_sec = 1; - timeout.tv_usec = 0; + while ( !_readThreadAbort ) + { + // Setup RX or Status change event notification + status = FT_SetEventNotification(handle, FT_EVENT_RXCHAR , (PVOID)&event_handle); - FD_ZERO( &fds ); - FD_SET( serial_fd, &fds ); + // Will block until + pthread_mutex_lock(&event_handle.eMutex); + pthread_cond_wait(&event_handle.eCondVar, &event_handle.eMutex); + pthread_mutex_unlock(&event_handle.eMutex); - errno = 0; - ret = select( topFd, &fds, NULL, NULL, &timeout ); + rx_bytes = 0; + status = FT_GetStatus(handle, &rx_bytes, &tx_bytes, &event_dword); - if ( ret < 0 ) { - fprintf( stderr, "ThumbDV: error from select, errno=%d\n", errno ); + if ( status != FT_OK ) + { + fprintf( stderr, "ThumbDV: error from select, status=%d\n", status ); + /* Set invalid FD in sched_waveform so we don't call write functions */ + handle = NULL; + sched_waveform_setHandle(&handle); + /* This function hangs until a new connection is made */ + _connectSerial( &handle ); + /* Update the sched_waveform to new valid serial */ + sched_waveform_setHandle( &handle ); + } + else if ( rx_bytes >= AMBE3000_HEADER_LEN ) + { + ret = thumbDV_processSerial( handle ); } - if ( FD_ISSET( serial_fd, &fds ) ) { - ret = thumbDV_processSerial( serial_fd ); - if ( ret != 0 ) { - /* Set invalid FD in sched_waveform so we don't call write functions */ - sched_waveform_setFD( -1 ); - /* This function hangs until a new connection is made */ - _connectSerial( &serial_fd ); - /* Update the sched_waveform to new valid serial */ - sched_waveform_setFD( serial_fd ); - topFd = serial_fd + 1; - } - } } output( ANSI_YELLOW "thumbDV_readThread has exited\n" ANSI_WHITE ); return 0; } -void thumbDV_init( int * serial_fd ) { +void thumbDV_init( FT_HANDLE * handle ) { pthread_rwlock_init( &_encoded_list_lock, NULL ); pthread_rwlock_init( &_decoded_list_lock, NULL ); @@ -786,13 +808,12 @@ void thumbDV_init( int * serial_fd ) { _decoded_root->prev = _decoded_root; pthread_rwlock_unlock( &_decoded_list_lock ); - _connectSerial( serial_fd ); + _connectSerial( handle ); - pthread_create( &_read_thread, NULL, &_thumbDV_readThread, serial_fd ); + pthread_create( &_read_thread, NULL, &_thumbDV_readThread, handle ); struct sched_param fifo_param; fifo_param.sched_priority = 30; pthread_setschedparam( _read_thread, SCHED_FIFO, &fifo_param ); - } diff --git a/DSP_API/ThumbDV/thumbDV.h b/DSP_API/ThumbDV/thumbDV.h index 6241e78..53b68cd 100644 --- a/DSP_API/ThumbDV/thumbDV.h +++ b/DSP_API/ThumbDV/thumbDV.h @@ -36,12 +36,14 @@ #ifndef THUMBDV_THUMBDV_H_ #define THUMBDV_THUMBDV_H_ -void thumbDV_init( int * serial_fd ); -int thumbDV_openSerial( const char * tty_name ); -int thumbDV_processSerial( int serial_fd ); +#include "ftd2xx.h" -int thumbDV_encode( int serial_fd, short * speech_in, unsigned char * packet_out, uint8 num_of_samples ); -int thumbDV_decode( int serial_fd, unsigned char * packet_in, short * speech_out, uint8 bytes_in_packet ); +void thumbDV_init( FT_HANDLE * serial_fd ); +FT_HANDLE thumbDV_openSerial( FT_DEVICE_LIST_INFO_NODE device ); +int thumbDV_processSerial( FT_HANDLE handle ); + +int thumbDV_encode( FT_HANDLE handle, short * speech_in, unsigned char * packet_out, uint8 num_of_samples ); +int thumbDV_decode( FT_HANDLE handle, unsigned char * packet_in, short * speech_out, uint8 bytes_in_packet ); void thumbDV_dump( char * text, unsigned char * data, unsigned int length ); void thumbDV_flushLists(void); diff --git a/DSP_API/Waveform/ThumbDV.ssdr_waveform b/DSP_API/Waveform/ThumbDV.ssdr_waveform index 42d6c33..67d228a 100644 Binary files a/DSP_API/Waveform/ThumbDV.ssdr_waveform and b/DSP_API/Waveform/ThumbDV.ssdr_waveform differ diff --git a/DSP_API/Waveform/ThumbDV/ThumbDV.cfg b/DSP_API/Waveform/ThumbDV/ThumbDV.cfg index bc2ee48..68e953c 100644 --- a/DSP_API/Waveform/ThumbDV/ThumbDV.cfg +++ b/DSP_API/Waveform/ThumbDV/ThumbDV.cfg @@ -1,6 +1,6 @@ [header] Name: ThumbDV -Version: "1.0.7" +Version: "1.0.8" Minimum-SmartSDR-Version: 1.4.2.0 Author: FlexRadio Systems Support-email: support@flexradio.com diff --git a/DSP_API/include/WinTypes.h b/DSP_API/include/WinTypes.h new file mode 100644 index 0000000..b37c3e5 --- /dev/null +++ b/DSP_API/include/WinTypes.h @@ -0,0 +1,136 @@ +#ifndef __WINDOWS_TYPES__ +#define __WINDOWS_TYPES__ + +#define WINAPI + +typedef unsigned int DWORD; +typedef unsigned int ULONG; +typedef unsigned short USHORT; +typedef unsigned short SHORT; +typedef unsigned char UCHAR; +typedef unsigned short WORD; +typedef unsigned char BYTE; +typedef BYTE *LPBYTE; +typedef unsigned int BOOLU; +typedef unsigned char BOOLEAN; +typedef unsigned char CHAR; +typedef BOOLU *LPBOOL; +typedef UCHAR *PUCHAR; +typedef const char *LPCSTR; +typedef char *PCHAR; +typedef void *PVOID; +typedef void *HANDLE; +typedef unsigned int LONG; +typedef int INT; +typedef unsigned int UINT; +typedef char *LPSTR; +typedef char *LPTSTR; +typedef const char *LPCTSTR; +typedef DWORD *LPDWORD; +typedef WORD *LPWORD; +typedef ULONG *PULONG; +typedef LONG *LPLONG; +typedef PVOID LPVOID; +typedef void VOID; +typedef unsigned long long int ULONGLONG; + +typedef struct _OVERLAPPED { + DWORD Internal; + DWORD InternalHigh; + DWORD Offset; + DWORD OffsetHigh; + HANDLE hEvent; +} OVERLAPPED, *LPOVERLAPPED; + +typedef struct _SECURITY_ATTRIBUTES { + DWORD nLength; + LPVOID lpSecurityDescriptor; + BOOL bInheritHandle; +} SECURITY_ATTRIBUTES , *LPSECURITY_ATTRIBUTES; + +#include +// Substitute for HANDLE returned by Windows CreateEvent API. +// FT_SetEventNotification expects parameter 3 to be the address +// of one of these structures. +typedef struct _EVENT_HANDLE +{ + pthread_cond_t eCondVar; + pthread_mutex_t eMutex; + int iVar; +} EVENT_HANDLE; + +typedef struct timeval SYSTEMTIME; +typedef struct timeval FILETIME; +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +// +// Modem Status Flags +// +#define MS_CTS_ON ((DWORD)0x0010) +#define MS_DSR_ON ((DWORD)0x0020) +#define MS_RING_ON ((DWORD)0x0040) +#define MS_RLSD_ON ((DWORD)0x0080) + +// +// Error Flags +// +#define CE_RXOVER 0x0001 // Receive Queue overflow +#define CE_OVERRUN 0x0002 // Receive Overrun Error +#define CE_RXPARITY 0x0004 // Receive Parity Error +#define CE_FRAME 0x0008 // Receive Framing error +#define CE_BREAK 0x0010 // Break Detected +#define CE_TXFULL 0x0100 // TX Queue is full +#define CE_PTO 0x0200 // LPTx Timeout +#define CE_IOE 0x0400 // LPTx I/O Error +#define CE_DNS 0x0800 // LPTx Device not selected +#define CE_OOP 0x1000 // LPTx Out-Of-Paper +#define CE_MODE 0x8000 // Requested mode unsupported + +// +// Events +// +#define EV_RXCHAR 0x0001 // Any Character received +#define EV_RXFLAG 0x0002 // Received certain character +#define EV_TXEMPTY 0x0004 // Transmit Queue Empty +#define EV_CTS 0x0008 // CTS changed state +#define EV_DSR 0x0010 // DSR changed state +#define EV_RLSD 0x0020 // RLSD changed state +#define EV_BREAK 0x0040 // BREAK received +#define EV_ERR 0x0080 // Line status error occurred +#define EV_RING 0x0100 // Ring signal detected +#define EV_PERR 0x0200 // Printer error occured +#define EV_RX80FULL 0x0400 // Receive buffer is 80 percent full +#define EV_EVENT1 0x0800 // Provider specific event 1 +#define EV_EVENT2 0x1000 // Provider specific event 2 + +// +// Escape Functions +// +#define SETXOFF 1 // Simulate XOFF received +#define SETXON 2 // Simulate XON received +#define SETRTS 3 // Set RTS high +#define CLRRTS 4 // Set RTS low +#define SETDTR 5 // Set DTR high +#define CLRDTR 6 // Set DTR low +#define RESETDEV 7 // Reset device if possible +#define SETBREAK 8 // Set the device break line. +#define CLRBREAK 9 // Clear the device break line. + +// +// PURGE function flags. +// +#define PURGE_TXABORT 0x0001 // Kill the pending/current writes to the comm port. +#define PURGE_RXABORT 0x0002 // Kill the pending/current reads to the comm port. +#define PURGE_TXCLEAR 0x0004 // Kill the transmit queue if there. +#define PURGE_RXCLEAR 0x0008 // Kill the typeahead buffer if there. + +#ifndef INVALID_HANDLE_VALUE +#define INVALID_HANDLE_VALUE 0xFFFFFFFF +#endif + +#endif /* __WINDOWS_TYPES__ */ diff --git a/DSP_API/include/ftd2xx.h b/DSP_API/include/ftd2xx.h new file mode 100644 index 0000000..9ce773c --- /dev/null +++ b/DSP_API/include/ftd2xx.h @@ -0,0 +1,1427 @@ +/*++ + +Copyright © 2001-2011 Future Technology Devices International Limited + +THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +FTDI DRIVERS MAY BE USED ONLY IN CONJUNCTION WITH PRODUCTS BASED ON FTDI PARTS. + +FTDI DRIVERS MAY BE DISTRIBUTED IN ANY FORM AS LONG AS LICENSE INFORMATION IS NOT MODIFIED. + +IF A CUSTOM VENDOR ID AND/OR PRODUCT ID OR DESCRIPTION STRING ARE USED, IT IS THE +RESPONSIBILITY OF THE PRODUCT MANUFACTURER TO MAINTAIN ANY CHANGES AND SUBSEQUENT WHQL +RE-CERTIFICATION AS A RESULT OF MAKING THESE CHANGES. + + +Module Name: + +ftd2xx.h + +Abstract: + +Native USB device driver for FTDI FT232x, FT245x, FT2232x and FT4232x devices +FTD2XX library definitions + +Environment: + +kernel & user mode + + +--*/ + + +#ifndef FTD2XX_H +#define FTD2XX_H + +#ifdef _WIN32 +// Compiling on Windows +#include + +// The following ifdef block is the standard way of creating macros +// which make exporting from a DLL simpler. All files within this DLL +// are compiled with the FTD2XX_EXPORTS symbol defined on the command line. +// This symbol should not be defined on any project that uses this DLL. +// This way any other project whose source files include this file see +// FTD2XX_API functions as being imported from a DLL, whereas this DLL +// sees symbols defined with this macro as being exported. + +#ifdef FTD2XX_EXPORTS +#define FTD2XX_API __declspec(dllexport) +#elif defined(FTD2XX_STATIC) +// Avoid decorations when linking statically to D2XX. +#define FTD2XX_API +#else +#define FTD2XX_API __declspec(dllimport) +#endif + +#else // _WIN32 +// Compiling on non-Windows platform. +#include "WinTypes.h" +// No decorations needed. +#define FTD2XX_API + +#endif // _WIN32 + +typedef PVOID FT_HANDLE; +typedef ULONG FT_STATUS; + +// +// Device status +// +enum { + FT_OK, + FT_INVALID_HANDLE, + FT_DEVICE_NOT_FOUND, + FT_DEVICE_NOT_OPENED, + FT_IO_ERROR, + FT_INSUFFICIENT_RESOURCES, + FT_INVALID_PARAMETER, + FT_INVALID_BAUD_RATE, + + FT_DEVICE_NOT_OPENED_FOR_ERASE, + FT_DEVICE_NOT_OPENED_FOR_WRITE, + FT_FAILED_TO_WRITE_DEVICE, + FT_EEPROM_READ_FAILED, + FT_EEPROM_WRITE_FAILED, + FT_EEPROM_ERASE_FAILED, + FT_EEPROM_NOT_PRESENT, + FT_EEPROM_NOT_PROGRAMMED, + FT_INVALID_ARGS, + FT_NOT_SUPPORTED, + FT_OTHER_ERROR, + FT_DEVICE_LIST_NOT_READY, +}; + + +#define FT_SUCCESS(status) ((status) == FT_OK) + +// +// FT_OpenEx Flags +// + +#define FT_OPEN_BY_SERIAL_NUMBER 1 +#define FT_OPEN_BY_DESCRIPTION 2 +#define FT_OPEN_BY_LOCATION 4 + +#define FT_OPEN_MASK (FT_OPEN_BY_SERIAL_NUMBER | \ + FT_OPEN_BY_DESCRIPTION | \ + FT_OPEN_BY_LOCATION) + +// +// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags +// + +#define FT_LIST_NUMBER_ONLY 0x80000000 +#define FT_LIST_BY_INDEX 0x40000000 +#define FT_LIST_ALL 0x20000000 + +#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL) + +// +// Baud Rates +// + +#define FT_BAUD_300 300 +#define FT_BAUD_600 600 +#define FT_BAUD_1200 1200 +#define FT_BAUD_2400 2400 +#define FT_BAUD_4800 4800 +#define FT_BAUD_9600 9600 +#define FT_BAUD_14400 14400 +#define FT_BAUD_19200 19200 +#define FT_BAUD_38400 38400 +#define FT_BAUD_57600 57600 +#define FT_BAUD_115200 115200 +#define FT_BAUD_230400 230400 +#define FT_BAUD_460800 460800 +#define FT_BAUD_921600 921600 + +// +// Word Lengths +// + +#define FT_BITS_8 (UCHAR) 8 +#define FT_BITS_7 (UCHAR) 7 + +// +// Stop Bits +// + +#define FT_STOP_BITS_1 (UCHAR) 0 +#define FT_STOP_BITS_2 (UCHAR) 2 + +// +// Parity +// + +#define FT_PARITY_NONE (UCHAR) 0 +#define FT_PARITY_ODD (UCHAR) 1 +#define FT_PARITY_EVEN (UCHAR) 2 +#define FT_PARITY_MARK (UCHAR) 3 +#define FT_PARITY_SPACE (UCHAR) 4 + +// +// Flow Control +// + +#define FT_FLOW_NONE 0x0000 +#define FT_FLOW_RTS_CTS 0x0100 +#define FT_FLOW_DTR_DSR 0x0200 +#define FT_FLOW_XON_XOFF 0x0400 + +// +// Purge rx and tx buffers +// +#define FT_PURGE_RX 1 +#define FT_PURGE_TX 2 + +// +// Events +// + +typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD); + +#define FT_EVENT_RXCHAR 1 +#define FT_EVENT_MODEM_STATUS 2 +#define FT_EVENT_LINE_STATUS 4 + +// +// Timeouts +// + +#define FT_DEFAULT_RX_TIMEOUT 300 +#define FT_DEFAULT_TX_TIMEOUT 300 + +// +// Device types +// + +typedef ULONG FT_DEVICE; + +enum { + FT_DEVICE_BM, + FT_DEVICE_AM, + FT_DEVICE_100AX, + FT_DEVICE_UNKNOWN, + FT_DEVICE_2232C, + FT_DEVICE_232R, + FT_DEVICE_2232H, + FT_DEVICE_4232H, + FT_DEVICE_232H, + FT_DEVICE_X_SERIES, + FT_DEVICE_4222H_0, + FT_DEVICE_4222H_1_2, + FT_DEVICE_4222H_3, + FT_DEVICE_4222_PROG, +}; + +// +// Bit Modes +// + +#define FT_BITMODE_RESET 0x00 +#define FT_BITMODE_ASYNC_BITBANG 0x01 +#define FT_BITMODE_MPSSE 0x02 +#define FT_BITMODE_SYNC_BITBANG 0x04 +#define FT_BITMODE_MCU_HOST 0x08 +#define FT_BITMODE_FAST_SERIAL 0x10 +#define FT_BITMODE_CBUS_BITBANG 0x20 +#define FT_BITMODE_SYNC_FIFO 0x40 + +// +// FT232R CBUS Options EEPROM values +// + +#define FT_232R_CBUS_TXDEN 0x00 // Tx Data Enable +#define FT_232R_CBUS_PWRON 0x01 // Power On +#define FT_232R_CBUS_RXLED 0x02 // Rx LED +#define FT_232R_CBUS_TXLED 0x03 // Tx LED +#define FT_232R_CBUS_TXRXLED 0x04 // Tx and Rx LED +#define FT_232R_CBUS_SLEEP 0x05 // Sleep +#define FT_232R_CBUS_CLK48 0x06 // 48MHz clock +#define FT_232R_CBUS_CLK24 0x07 // 24MHz clock +#define FT_232R_CBUS_CLK12 0x08 // 12MHz clock +#define FT_232R_CBUS_CLK6 0x09 // 6MHz clock +#define FT_232R_CBUS_IOMODE 0x0A // IO Mode for CBUS bit-bang +#define FT_232R_CBUS_BITBANG_WR 0x0B // Bit-bang write strobe +#define FT_232R_CBUS_BITBANG_RD 0x0C // Bit-bang read strobe + +// +// FT232H CBUS Options EEPROM values +// + +#define FT_232H_CBUS_TRISTATE 0x00 // Tristate +#define FT_232H_CBUS_TXLED 0x01 // Tx LED +#define FT_232H_CBUS_RXLED 0x02 // Rx LED +#define FT_232H_CBUS_TXRXLED 0x03 // Tx and Rx LED +#define FT_232H_CBUS_PWREN 0x04 // Power Enable +#define FT_232H_CBUS_SLEEP 0x05 // Sleep +#define FT_232H_CBUS_DRIVE_0 0x06 // Drive pin to logic 0 +#define FT_232H_CBUS_DRIVE_1 0x07 // Drive pin to logic 1 +#define FT_232H_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang +#define FT_232H_CBUS_TXDEN 0x09 // Tx Data Enable +#define FT_232H_CBUS_CLK30 0x0A // 30MHz clock +#define FT_232H_CBUS_CLK15 0x0B // 15MHz clock +#define FT_232H_CBUS_CLK7_5 0x0C // 7.5MHz clock + +// +// FT X Series CBUS Options EEPROM values +// + +#define FT_X_SERIES_CBUS_TRISTATE 0x00 // Tristate +#define FT_X_SERIES_CBUS_TXLED 0x01 // Tx LED +#define FT_X_SERIES_CBUS_RXLED 0x02 // Rx LED +#define FT_X_SERIES_CBUS_TXRXLED 0x03 // Tx and Rx LED +#define FT_X_SERIES_CBUS_PWREN 0x04 // Power Enable +#define FT_X_SERIES_CBUS_SLEEP 0x05 // Sleep +#define FT_X_SERIES_CBUS_DRIVE_0 0x06 // Drive pin to logic 0 +#define FT_X_SERIES_CBUS_DRIVE_1 0x07 // Drive pin to logic 1 +#define FT_X_SERIES_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang +#define FT_X_SERIES_CBUS_TXDEN 0x09 // Tx Data Enable +#define FT_X_SERIES_CBUS_CLK24 0x0A // 24MHz clock +#define FT_X_SERIES_CBUS_CLK12 0x0B // 12MHz clock +#define FT_X_SERIES_CBUS_CLK6 0x0C // 6MHz clock +#define FT_X_SERIES_CBUS_BCD_CHARGER 0x0D // Battery charger detected +#define FT_X_SERIES_CBUS_BCD_CHARGER_N 0x0E // Battery charger detected inverted +#define FT_X_SERIES_CBUS_I2C_TXE 0x0F // I2C Tx empty +#define FT_X_SERIES_CBUS_I2C_RXF 0x10 // I2C Rx full +#define FT_X_SERIES_CBUS_VBUS_SENSE 0x11 // Detect VBUS +#define FT_X_SERIES_CBUS_BITBANG_WR 0x12 // Bit-bang write strobe +#define FT_X_SERIES_CBUS_BITBANG_RD 0x13 // Bit-bang read strobe +#define FT_X_SERIES_CBUS_TIMESTAMP 0x14 // Toggle output when a USB SOF token is received +#define FT_X_SERIES_CBUS_KEEP_AWAKE 0x15 // + + +// Driver types +#define FT_DRIVER_TYPE_D2XX 0 +#define FT_DRIVER_TYPE_VCP 1 + + + +#ifdef __cplusplus +extern "C" { +#endif + + + FTD2XX_API + FT_STATUS WINAPI FT_Open( + int deviceNumber, + FT_HANDLE *pHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_OpenEx( + PVOID pArg1, + DWORD Flags, + FT_HANDLE *pHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ListDevices( + PVOID pArg1, + PVOID pArg2, + DWORD Flags + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Close( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Read( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD dwBytesToRead, + LPDWORD lpBytesReturned + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Write( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD dwBytesToWrite, + LPDWORD lpBytesWritten + ); + + FTD2XX_API + FT_STATUS WINAPI FT_IoCtl( + FT_HANDLE ftHandle, + DWORD dwIoControlCode, + LPVOID lpInBuf, + DWORD nInBufSize, + LPVOID lpOutBuf, + DWORD nOutBufSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetBaudRate( + FT_HANDLE ftHandle, + ULONG BaudRate + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetDivisor( + FT_HANDLE ftHandle, + USHORT Divisor + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetDataCharacteristics( + FT_HANDLE ftHandle, + UCHAR WordLength, + UCHAR StopBits, + UCHAR Parity + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetFlowControl( + FT_HANDLE ftHandle, + USHORT FlowControl, + UCHAR XonChar, + UCHAR XoffChar + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ResetDevice( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetDtr( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ClrDtr( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetRts( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ClrRts( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetModemStatus( + FT_HANDLE ftHandle, + ULONG *pModemStatus + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetChars( + FT_HANDLE ftHandle, + UCHAR EventChar, + UCHAR EventCharEnabled, + UCHAR ErrorChar, + UCHAR ErrorCharEnabled + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Purge( + FT_HANDLE ftHandle, + ULONG Mask + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetTimeouts( + FT_HANDLE ftHandle, + ULONG ReadTimeout, + ULONG WriteTimeout + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetQueueStatus( + FT_HANDLE ftHandle, + DWORD *dwRxBytes + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetEventNotification( + FT_HANDLE ftHandle, + DWORD Mask, + PVOID Param + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetStatus( + FT_HANDLE ftHandle, + DWORD *dwRxBytes, + DWORD *dwTxBytes, + DWORD *dwEventDWord + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetBreakOn( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetBreakOff( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetWaitMask( + FT_HANDLE ftHandle, + DWORD Mask + ); + + FTD2XX_API + FT_STATUS WINAPI FT_WaitOnMask( + FT_HANDLE ftHandle, + DWORD *Mask + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetEventStatus( + FT_HANDLE ftHandle, + DWORD *dwEventDWord + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ReadEE( + FT_HANDLE ftHandle, + DWORD dwWordOffset, + LPWORD lpwValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_WriteEE( + FT_HANDLE ftHandle, + DWORD dwWordOffset, + WORD wValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EraseEE( + FT_HANDLE ftHandle + ); + + // + // structure to hold program data for FT_EE_Program, FT_EE_ProgramEx, FT_EE_Read + // and FT_EE_ReadEx functions + // + typedef struct ft_program_data { + + DWORD Signature1; // Header - must be 0x00000000 + DWORD Signature2; // Header - must be 0xffffffff + DWORD Version; // Header - FT_PROGRAM_DATA version + // 0 = original + // 1 = FT2232 extensions + // 2 = FT232R extensions + // 3 = FT2232H extensions + // 4 = FT4232H extensions + // 5 = FT232H extensions + + WORD VendorId; // 0x0403 + WORD ProductId; // 0x6001 + char *Manufacturer; // "FTDI" + char *ManufacturerId; // "FT" + char *Description; // "USB HS Serial Converter" + char *SerialNumber; // "FT000001" if fixed, or NULL + WORD MaxPower; // 0 < MaxPower <= 500 + WORD PnP; // 0 = disabled, 1 = enabled + WORD SelfPowered; // 0 = bus powered, 1 = self powered + WORD RemoteWakeup; // 0 = not capable, 1 = capable + // + // Rev4 (FT232B) extensions + // + UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise + UCHAR IsoIn; // non-zero if in endpoint is isochronous + UCHAR IsoOut; // non-zero if out endpoint is isochronous + UCHAR PullDownEnable; // non-zero if pull down enabled + UCHAR SerNumEnable; // non-zero if serial number to be used + UCHAR USBVersionEnable; // non-zero if chip uses USBVersion + WORD USBVersion; // BCD (0x0200 => USB2) + // + // Rev 5 (FT2232) extensions + // + UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise + UCHAR IsoInA; // non-zero if in endpoint is isochronous + UCHAR IsoInB; // non-zero if in endpoint is isochronous + UCHAR IsoOutA; // non-zero if out endpoint is isochronous + UCHAR IsoOutB; // non-zero if out endpoint is isochronous + UCHAR PullDownEnable5; // non-zero if pull down enabled + UCHAR SerNumEnable5; // non-zero if serial number to be used + UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion + WORD USBVersion5; // BCD (0x0200 => USB2) + UCHAR AIsHighCurrent; // non-zero if interface is high current + UCHAR BIsHighCurrent; // non-zero if interface is high current + UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO + UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR IFAIsFastSer; // non-zero if interface is Fast serial + UCHAR AIsVCP; // non-zero if interface is to use VCP drivers + UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO + UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR IFBIsFastSer; // non-zero if interface is Fast serial + UCHAR BIsVCP; // non-zero if interface is to use VCP drivers + // + // Rev 6 (FT232R) extensions + // + UCHAR UseExtOsc; // Use External Oscillator + UCHAR HighDriveIOs; // High Drive I/Os + UCHAR EndpointSize; // Endpoint size + UCHAR PullDownEnableR; // non-zero if pull down enabled + UCHAR SerNumEnableR; // non-zero if serial number to be used + UCHAR InvertTXD; // non-zero if invert TXD + UCHAR InvertRXD; // non-zero if invert RXD + UCHAR InvertRTS; // non-zero if invert RTS + UCHAR InvertCTS; // non-zero if invert CTS + UCHAR InvertDTR; // non-zero if invert DTR + UCHAR InvertDSR; // non-zero if invert DSR + UCHAR InvertDCD; // non-zero if invert DCD + UCHAR InvertRI; // non-zero if invert RI + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + UCHAR RIsD2XX; // non-zero if using D2XX driver + // + // Rev 7 (FT2232H) Extensions + // + UCHAR PullDownEnable7; // non-zero if pull down enabled + UCHAR SerNumEnable7; // non-zero if serial number to be used + UCHAR ALSlowSlew; // non-zero if AL pins have slow slew + UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input + UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR AHSlowSlew; // non-zero if AH pins have slow slew + UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input + UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BLSlowSlew; // non-zero if BL pins have slow slew + UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input + UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BHSlowSlew; // non-zero if BH pins have slow slew + UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input + UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR IFAIsFifo7; // non-zero if interface is 245 FIFO + UCHAR IFAIsFifoTar7; // non-zero if interface is 245 FIFO CPU target + UCHAR IFAIsFastSer7; // non-zero if interface is Fast serial + UCHAR AIsVCP7; // non-zero if interface is to use VCP drivers + UCHAR IFBIsFifo7; // non-zero if interface is 245 FIFO + UCHAR IFBIsFifoTar7; // non-zero if interface is 245 FIFO CPU target + UCHAR IFBIsFastSer7; // non-zero if interface is Fast serial + UCHAR BIsVCP7; // non-zero if interface is to use VCP drivers + UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs + // + // Rev 8 (FT4232H) Extensions + // + UCHAR PullDownEnable8; // non-zero if pull down enabled + UCHAR SerNumEnable8; // non-zero if serial number to be used + UCHAR ASlowSlew; // non-zero if A pins have slow slew + UCHAR ASchmittInput; // non-zero if A pins are Schmitt input + UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BSlowSlew; // non-zero if B pins have slow slew + UCHAR BSchmittInput; // non-zero if B pins are Schmitt input + UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR CSlowSlew; // non-zero if C pins have slow slew + UCHAR CSchmittInput; // non-zero if C pins are Schmitt input + UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR DSlowSlew; // non-zero if D pins have slow slew + UCHAR DSchmittInput; // non-zero if D pins are Schmitt input + UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN + UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN + UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN + UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN + UCHAR AIsVCP8; // non-zero if interface is to use VCP drivers + UCHAR BIsVCP8; // non-zero if interface is to use VCP drivers + UCHAR CIsVCP8; // non-zero if interface is to use VCP drivers + UCHAR DIsVCP8; // non-zero if interface is to use VCP drivers + // + // Rev 9 (FT232H) Extensions + // + UCHAR PullDownEnableH; // non-zero if pull down enabled + UCHAR SerNumEnableH; // non-zero if serial number to be used + UCHAR ACSlowSlewH; // non-zero if AC pins have slow slew + UCHAR ACSchmittInputH; // non-zero if AC pins are Schmitt input + UCHAR ACDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR ADSlowSlewH; // non-zero if AD pins have slow slew + UCHAR ADSchmittInputH; // non-zero if AD pins are Schmitt input + UCHAR ADDriveCurrentH; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR Cbus0H; // Cbus Mux control + UCHAR Cbus1H; // Cbus Mux control + UCHAR Cbus2H; // Cbus Mux control + UCHAR Cbus3H; // Cbus Mux control + UCHAR Cbus4H; // Cbus Mux control + UCHAR Cbus5H; // Cbus Mux control + UCHAR Cbus6H; // Cbus Mux control + UCHAR Cbus7H; // Cbus Mux control + UCHAR Cbus8H; // Cbus Mux control + UCHAR Cbus9H; // Cbus Mux control + UCHAR IsFifoH; // non-zero if interface is 245 FIFO + UCHAR IsFifoTarH; // non-zero if interface is 245 FIFO CPU target + UCHAR IsFastSerH; // non-zero if interface is Fast serial + UCHAR IsFT1248H; // non-zero if interface is FT1248 + UCHAR FT1248CpolH; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) + UCHAR FT1248LsbH; // FT1248 data is LSB (1) or MSB (0) + UCHAR FT1248FlowControlH; // FT1248 flow control enable + UCHAR IsVCPH; // non-zero if interface is to use VCP drivers + UCHAR PowerSaveEnableH; // non-zero if using ACBUS7 to save power for self-powered designs + + } FT_PROGRAM_DATA, *PFT_PROGRAM_DATA; + + FTD2XX_API + FT_STATUS WINAPI FT_EE_Program( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_ProgramEx( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_Read( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_ReadEx( + FT_HANDLE ftHandle, + PFT_PROGRAM_DATA pData, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_UASize( + FT_HANDLE ftHandle, + LPDWORD lpdwSize + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_UAWrite( + FT_HANDLE ftHandle, + PUCHAR pucData, + DWORD dwDataLen + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_UARead( + FT_HANDLE ftHandle, + PUCHAR pucData, + DWORD dwDataLen, + LPDWORD lpdwBytesRead + ); + + + typedef struct ft_eeprom_header { + FT_DEVICE deviceType; // FTxxxx device type to be programmed + // Device descriptor options + WORD VendorId; // 0x0403 + WORD ProductId; // 0x6001 + UCHAR SerNumEnable; // non-zero if serial number to be used + // Config descriptor options + WORD MaxPower; // 0 < MaxPower <= 500 + UCHAR SelfPowered; // 0 = bus powered, 1 = self powered + UCHAR RemoteWakeup; // 0 = not capable, 1 = capable + // Hardware options + UCHAR PullDownEnable; // non-zero if pull down in suspend enabled + } FT_EEPROM_HEADER, *PFT_EEPROM_HEADER; + + + // FT232B EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_232b { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + } FT_EEPROM_232B, *PFT_EEPROM_232B; + + + // FT2232 EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_2232 { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR AIsHighCurrent; // non-zero if interface is high current + UCHAR BIsHighCurrent; // non-zero if interface is high current + // Hardware options + UCHAR AIsFifo; // non-zero if interface is 245 FIFO + UCHAR AIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR AIsFastSer; // non-zero if interface is Fast serial + UCHAR BIsFifo; // non-zero if interface is 245 FIFO + UCHAR BIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR BIsFastSer; // non-zero if interface is Fast serial + // Driver option + UCHAR ADriverType; // + UCHAR BDriverType; // + } FT_EEPROM_2232, *PFT_EEPROM_2232; + + + // FT232R EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_232r { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR IsHighCurrent; // non-zero if interface is high current + // Hardware options + UCHAR UseExtOsc; // Use External Oscillator + UCHAR InvertTXD; // non-zero if invert TXD + UCHAR InvertRXD; // non-zero if invert RXD + UCHAR InvertRTS; // non-zero if invert RTS + UCHAR InvertCTS; // non-zero if invert CTS + UCHAR InvertDTR; // non-zero if invert DTR + UCHAR InvertDSR; // non-zero if invert DSR + UCHAR InvertDCD; // non-zero if invert DCD + UCHAR InvertRI; // non-zero if invert RI + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + // Driver option + UCHAR DriverType; // + } FT_EEPROM_232R, *PFT_EEPROM_232R; + + + // FT2232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_2232h { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR ALSlowSlew; // non-zero if AL pins have slow slew + UCHAR ALSchmittInput; // non-zero if AL pins are Schmitt input + UCHAR ALDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR AHSlowSlew; // non-zero if AH pins have slow slew + UCHAR AHSchmittInput; // non-zero if AH pins are Schmitt input + UCHAR AHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BLSlowSlew; // non-zero if BL pins have slow slew + UCHAR BLSchmittInput; // non-zero if BL pins are Schmitt input + UCHAR BLDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BHSlowSlew; // non-zero if BH pins have slow slew + UCHAR BHSchmittInput; // non-zero if BH pins are Schmitt input + UCHAR BHDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + // Hardware options + UCHAR AIsFifo; // non-zero if interface is 245 FIFO + UCHAR AIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR AIsFastSer; // non-zero if interface is Fast serial + UCHAR BIsFifo; // non-zero if interface is 245 FIFO + UCHAR BIsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR BIsFastSer; // non-zero if interface is Fast serial + UCHAR PowerSaveEnable; // non-zero if using BCBUS7 to save power for self-powered designs + // Driver option + UCHAR ADriverType; // + UCHAR BDriverType; // + } FT_EEPROM_2232H, *PFT_EEPROM_2232H; + + + // FT4232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_4232h { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR ASlowSlew; // non-zero if A pins have slow slew + UCHAR ASchmittInput; // non-zero if A pins are Schmitt input + UCHAR ADriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR BSlowSlew; // non-zero if B pins have slow slew + UCHAR BSchmittInput; // non-zero if B pins are Schmitt input + UCHAR BDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR CSlowSlew; // non-zero if C pins have slow slew + UCHAR CSchmittInput; // non-zero if C pins are Schmitt input + UCHAR CDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR DSlowSlew; // non-zero if D pins have slow slew + UCHAR DSchmittInput; // non-zero if D pins are Schmitt input + UCHAR DDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + // Hardware options + UCHAR ARIIsTXDEN; // non-zero if port A uses RI as RS485 TXDEN + UCHAR BRIIsTXDEN; // non-zero if port B uses RI as RS485 TXDEN + UCHAR CRIIsTXDEN; // non-zero if port C uses RI as RS485 TXDEN + UCHAR DRIIsTXDEN; // non-zero if port D uses RI as RS485 TXDEN + // Driver option + UCHAR ADriverType; // + UCHAR BDriverType; // + UCHAR CDriverType; // + UCHAR DDriverType; // + } FT_EEPROM_4232H, *PFT_EEPROM_4232H; + + + // FT232H EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_232h { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR ACSlowSlew; // non-zero if AC bus pins have slow slew + UCHAR ACSchmittInput; // non-zero if AC bus pins are Schmitt input + UCHAR ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR ADSlowSlew; // non-zero if AD bus pins have slow slew + UCHAR ADSchmittInput; // non-zero if AD bus pins are Schmitt input + UCHAR ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + // CBUS options + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + UCHAR Cbus5; // Cbus Mux control + UCHAR Cbus6; // Cbus Mux control + UCHAR Cbus7; // Cbus Mux control + UCHAR Cbus8; // Cbus Mux control + UCHAR Cbus9; // Cbus Mux control + // FT1248 options + UCHAR FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) + UCHAR FT1248Lsb; // FT1248 data is LSB (1) or MSB (0) + UCHAR FT1248FlowControl; // FT1248 flow control enable + // Hardware options + UCHAR IsFifo; // non-zero if interface is 245 FIFO + UCHAR IsFifoTar; // non-zero if interface is 245 FIFO CPU target + UCHAR IsFastSer; // non-zero if interface is Fast serial + UCHAR IsFT1248 ; // non-zero if interface is FT1248 + UCHAR PowerSaveEnable; // + // Driver option + UCHAR DriverType; // + } FT_EEPROM_232H, *PFT_EEPROM_232H; + + + // FT X Series EEPROM structure for use with FT_EEPROM_Read and FT_EEPROM_Program + typedef struct ft_eeprom_x_series { + // Common header + FT_EEPROM_HEADER common; // common elements for all device EEPROMs + // Drive options + UCHAR ACSlowSlew; // non-zero if AC bus pins have slow slew + UCHAR ACSchmittInput; // non-zero if AC bus pins are Schmitt input + UCHAR ACDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + UCHAR ADSlowSlew; // non-zero if AD bus pins have slow slew + UCHAR ADSchmittInput; // non-zero if AD bus pins are Schmitt input + UCHAR ADDriveCurrent; // valid values are 4mA, 8mA, 12mA, 16mA + // CBUS options + UCHAR Cbus0; // Cbus Mux control + UCHAR Cbus1; // Cbus Mux control + UCHAR Cbus2; // Cbus Mux control + UCHAR Cbus3; // Cbus Mux control + UCHAR Cbus4; // Cbus Mux control + UCHAR Cbus5; // Cbus Mux control + UCHAR Cbus6; // Cbus Mux control + // UART signal options + UCHAR InvertTXD; // non-zero if invert TXD + UCHAR InvertRXD; // non-zero if invert RXD + UCHAR InvertRTS; // non-zero if invert RTS + UCHAR InvertCTS; // non-zero if invert CTS + UCHAR InvertDTR; // non-zero if invert DTR + UCHAR InvertDSR; // non-zero if invert DSR + UCHAR InvertDCD; // non-zero if invert DCD + UCHAR InvertRI; // non-zero if invert RI + // Battery Charge Detect options + UCHAR BCDEnable; // Enable Battery Charger Detection + UCHAR BCDForceCbusPWREN; // asserts the power enable signal on CBUS when charging port detected + UCHAR BCDDisableSleep; // forces the device never to go into sleep mode + // I2C options + WORD I2CSlaveAddress; // I2C slave device address + DWORD I2CDeviceId; // I2C device ID + UCHAR I2CDisableSchmitt; // Disable I2C Schmitt trigger + // FT1248 options + UCHAR FT1248Cpol; // FT1248 clock polarity - clock idle high (1) or clock idle low (0) + UCHAR FT1248Lsb; // FT1248 data is LSB (1) or MSB (0) + UCHAR FT1248FlowControl; // FT1248 flow control enable + // Hardware options + UCHAR RS485EchoSuppress; // + UCHAR PowerSaveEnable; // + // Driver option + UCHAR DriverType; // + } FT_EEPROM_X_SERIES, *PFT_EEPROM_X_SERIES; + + + FTD2XX_API + FT_STATUS WINAPI FT_EEPROM_Read( + FT_HANDLE ftHandle, + void *eepromData, + DWORD eepromDataSize, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + + + FTD2XX_API + FT_STATUS WINAPI FT_EEPROM_Program( + FT_HANDLE ftHandle, + void *eepromData, + DWORD eepromDataSize, + char *Manufacturer, + char *ManufacturerId, + char *Description, + char *SerialNumber + ); + + + FTD2XX_API + FT_STATUS WINAPI FT_SetLatencyTimer( + FT_HANDLE ftHandle, + UCHAR ucLatency + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetLatencyTimer( + FT_HANDLE ftHandle, + PUCHAR pucLatency + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetBitMode( + FT_HANDLE ftHandle, + UCHAR ucMask, + UCHAR ucEnable + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetBitMode( + FT_HANDLE ftHandle, + PUCHAR pucMode + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetUSBParameters( + FT_HANDLE ftHandle, + ULONG ulInTransferSize, + ULONG ulOutTransferSize + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetDeadmanTimeout( + FT_HANDLE ftHandle, + ULONG ulDeadmanTimeout + ); + +#ifndef _WIN32 + // Extra functions for non-Windows platforms to compensate + // for lack of .INF file to specify Vendor and Product IDs. + + FTD2XX_API + FT_STATUS FT_SetVIDPID( + DWORD dwVID, + DWORD dwPID + ); + + FTD2XX_API + FT_STATUS FT_GetVIDPID( + DWORD * pdwVID, + DWORD * pdwPID + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetDeviceLocId( + FT_HANDLE ftHandle, + LPDWORD lpdwLocId + ); +#endif // _WIN32 + + FTD2XX_API + FT_STATUS WINAPI FT_GetDeviceInfo( + FT_HANDLE ftHandle, + FT_DEVICE *lpftDevice, + LPDWORD lpdwID, + PCHAR SerialNumber, + PCHAR Description, + LPVOID Dummy + ); + + FTD2XX_API + FT_STATUS WINAPI FT_StopInTask( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_RestartInTask( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_SetResetPipeRetryCount( + FT_HANDLE ftHandle, + DWORD dwCount + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ResetPort( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_CyclePort( + FT_HANDLE ftHandle + ); + + + // + // Win32-type functions + // + + FTD2XX_API + FT_HANDLE WINAPI FT_W32_CreateFile( + LPCTSTR lpszName, + DWORD dwAccess, + DWORD dwShareMode, + LPSECURITY_ATTRIBUTES lpSecurityAttributes, + DWORD dwCreate, + DWORD dwAttrsAndFlags, + HANDLE hTemplate + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_CloseHandle( + FT_HANDLE ftHandle + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_ReadFile( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD nBufferSize, + LPDWORD lpBytesReturned, + LPOVERLAPPED lpOverlapped + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_WriteFile( + FT_HANDLE ftHandle, + LPVOID lpBuffer, + DWORD nBufferSize, + LPDWORD lpBytesWritten, + LPOVERLAPPED lpOverlapped + ); + + FTD2XX_API + DWORD WINAPI FT_W32_GetLastError( + FT_HANDLE ftHandle + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_GetOverlappedResult( + FT_HANDLE ftHandle, + LPOVERLAPPED lpOverlapped, + LPDWORD lpdwBytesTransferred, + BOOLU bWait + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_CancelIo( + FT_HANDLE ftHandle + ); + + + // + // Win32 COMM API type functions + // + typedef struct _FTCOMSTAT { + DWORD fCtsHold : 1; + DWORD fDsrHold : 1; + DWORD fRlsdHold : 1; + DWORD fXoffHold : 1; + DWORD fXoffSent : 1; + DWORD fEof : 1; + DWORD fTxim : 1; + DWORD fReserved : 25; + DWORD cbInQue; + DWORD cbOutQue; + } FTCOMSTAT, *LPFTCOMSTAT; + + typedef struct _FTDCB { + DWORD DCBlength; /* sizeof(FTDCB) */ + DWORD BaudRate; /* Baudrate at which running */ + DWORD fBinary: 1; /* Binary Mode (skip EOF check) */ + DWORD fParity: 1; /* Enable parity checking */ + DWORD fOutxCtsFlow:1; /* CTS handshaking on output */ + DWORD fOutxDsrFlow:1; /* DSR handshaking on output */ + DWORD fDtrControl:2; /* DTR Flow control */ + DWORD fDsrSensitivity:1; /* DSR Sensitivity */ + DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */ + DWORD fOutX: 1; /* Enable output X-ON/X-OFF */ + DWORD fInX: 1; /* Enable input X-ON/X-OFF */ + DWORD fErrorChar: 1; /* Enable Err Replacement */ + DWORD fNull: 1; /* Enable Null stripping */ + DWORD fRtsControl:2; /* Rts Flow control */ + DWORD fAbortOnError:1; /* Abort all reads and writes on Error */ + DWORD fDummy2:17; /* Reserved */ + WORD wReserved; /* Not currently used */ + WORD XonLim; /* Transmit X-ON threshold */ + WORD XoffLim; /* Transmit X-OFF threshold */ + BYTE ByteSize; /* Number of bits/byte, 4-8 */ + BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */ + BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */ + char XonChar; /* Tx and Rx X-ON character */ + char XoffChar; /* Tx and Rx X-OFF character */ + char ErrorChar; /* Error replacement char */ + char EofChar; /* End of Input character */ + char EvtChar; /* Received Event character */ + WORD wReserved1; /* Fill for now. */ + } FTDCB, *LPFTDCB; + + typedef struct _FTTIMEOUTS { + DWORD ReadIntervalTimeout; /* Maximum time between read chars. */ + DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */ + DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */ + DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */ + DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */ + } FTTIMEOUTS,*LPFTTIMEOUTS; + + + FTD2XX_API + BOOLU WINAPI FT_W32_ClearCommBreak( + FT_HANDLE ftHandle + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_ClearCommError( + FT_HANDLE ftHandle, + LPDWORD lpdwErrors, + LPFTCOMSTAT lpftComstat + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_EscapeCommFunction( + FT_HANDLE ftHandle, + DWORD dwFunc + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_GetCommModemStatus( + FT_HANDLE ftHandle, + LPDWORD lpdwModemStatus + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_GetCommState( + FT_HANDLE ftHandle, + LPFTDCB lpftDcb + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_GetCommTimeouts( + FT_HANDLE ftHandle, + FTTIMEOUTS *pTimeouts + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_PurgeComm( + FT_HANDLE ftHandle, + DWORD dwMask + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_SetCommBreak( + FT_HANDLE ftHandle + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_SetCommMask( + FT_HANDLE ftHandle, + ULONG ulEventMask + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_GetCommMask( + FT_HANDLE ftHandle, + LPDWORD lpdwEventMask + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_SetCommState( + FT_HANDLE ftHandle, + LPFTDCB lpftDcb + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_SetCommTimeouts( + FT_HANDLE ftHandle, + FTTIMEOUTS *pTimeouts + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_SetupComm( + FT_HANDLE ftHandle, + DWORD dwReadBufferSize, + DWORD dwWriteBufferSize + ); + + FTD2XX_API + BOOLU WINAPI FT_W32_WaitCommEvent( + FT_HANDLE ftHandle, + PULONG pulEvent, + LPOVERLAPPED lpOverlapped + ); + + + // + // Device information + // + + typedef struct _ft_device_list_info_node { + ULONG Flags; + ULONG Type; + ULONG ID; + DWORD LocId; + char SerialNumber[16]; + char Description[64]; + FT_HANDLE ftHandle; + } FT_DEVICE_LIST_INFO_NODE; + + // Device information flags + enum { + FT_FLAGS_OPENED = 1, + FT_FLAGS_HISPEED = 2 + }; + + + FTD2XX_API + FT_STATUS WINAPI FT_CreateDeviceInfoList( + LPDWORD lpdwNumDevs + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetDeviceInfoList( + FT_DEVICE_LIST_INFO_NODE *pDest, + LPDWORD lpdwNumDevs + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetDeviceInfoDetail( + DWORD dwIndex, + LPDWORD lpdwFlags, + LPDWORD lpdwType, + LPDWORD lpdwID, + LPDWORD lpdwLocId, + LPVOID lpSerialNumber, + LPVOID lpDescription, + FT_HANDLE *pftHandle + ); + + + // + // Version information + // + + FTD2XX_API + FT_STATUS WINAPI FT_GetDriverVersion( + FT_HANDLE ftHandle, + LPDWORD lpdwVersion + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetLibraryVersion( + LPDWORD lpdwVersion + ); + + + FTD2XX_API + FT_STATUS WINAPI FT_Rescan( + void + ); + + FTD2XX_API + FT_STATUS WINAPI FT_Reload( + WORD wVid, + WORD wPid + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetComPortNumber( + FT_HANDLE ftHandle, + LPLONG lpdwComPortNumber + ); + + + // + // FT232H additional EEPROM functions + // + + FTD2XX_API + FT_STATUS WINAPI FT_EE_ReadConfig( + FT_HANDLE ftHandle, + UCHAR ucAddress, + PUCHAR pucValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_WriteConfig( + FT_HANDLE ftHandle, + UCHAR ucAddress, + UCHAR ucValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_EE_ReadECC( + FT_HANDLE ftHandle, + UCHAR ucOption, + LPWORD lpwValue + ); + + FTD2XX_API + FT_STATUS WINAPI FT_GetQueueStatusEx( + FT_HANDLE ftHandle, + DWORD *dwRxBytes + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ComPortIdle( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_ComPortCancelIdle( + FT_HANDLE ftHandle + ); + + FTD2XX_API + FT_STATUS WINAPI FT_VendorCmdGet( + FT_HANDLE ftHandle, + UCHAR Request, + UCHAR *Buf, + USHORT Len + ); + + FTD2XX_API + FT_STATUS WINAPI FT_VendorCmdSet( + FT_HANDLE ftHandle, + UCHAR Request, + UCHAR *Buf, + USHORT Len + ); + + FTD2XX_API + FT_STATUS WINAPI FT_VendorCmdGetEx( + FT_HANDLE ftHandle, + USHORT wValue, + UCHAR *Buf, + USHORT Len + ); + + FTD2XX_API + FT_STATUS WINAPI FT_VendorCmdSetEx( + FT_HANDLE ftHandle, + USHORT wValue, + UCHAR *Buf, + USHORT Len + ); + +#ifdef __cplusplus +} +#endif + + +#endif /* FTD2XX_H */ + diff --git a/DSP_API/lib/libftd2xx.a b/DSP_API/lib/libftd2xx.a new file mode 100644 index 0000000..7e39999 Binary files /dev/null and b/DSP_API/lib/libftd2xx.a differ diff --git a/pc/CODEC2 GUI/CODEC2 GUI/Properties/AssemblyInfo.cs b/pc/CODEC2 GUI/CODEC2 GUI/Properties/AssemblyInfo.cs index d9f6e00..fb9b68e 100644 --- a/pc/CODEC2 GUI/CODEC2 GUI/Properties/AssemblyInfo.cs +++ b/pc/CODEC2 GUI/CODEC2 GUI/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -using System.Reflection; +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("FlexRadio Systems")] [assembly: AssemblyProduct("SmartSDR_D-STAR_Waveform")] -[assembly: AssemblyCopyright("Copyright © FlexRadio Systems 2014-2015")] +[assembly: AssemblyCopyright("Copyright © FlexRadio Systems 2014-2015")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.7.0")] -[assembly: AssemblyFileVersion("1.0.7.0")] +[assembly: AssemblyVersion("1.0.8.0")] +[assembly: AssemblyFileVersion("1.0.8.0")] diff --git a/pc/CODEC2 GUI/CODEC2_GUI_INSTALLER/Flex_ThumbDV_Waveform_Inno_Install_Script.iss b/pc/CODEC2 GUI/CODEC2_GUI_INSTALLER/Flex_ThumbDV_Waveform_Inno_Install_Script.iss index 4d0e5aa..d3bc609 100644 --- a/pc/CODEC2 GUI/CODEC2_GUI_INSTALLER/Flex_ThumbDV_Waveform_Inno_Install_Script.iss +++ b/pc/CODEC2 GUI/CODEC2_GUI_INSTALLER/Flex_ThumbDV_Waveform_Inno_Install_Script.iss @@ -6,11 +6,11 @@ ; The App Versions can be passed in and will match the AssemblyInfo for the application #ifndef MyAppVersion - #define MyAppVersion "1.0.7.0" + #define MyAppVersion "1.0.8.0" #endif #ifndef MyAppVersionWithV - #define MyAppVersionWithV "v1.0.7.0" + #define MyAppVersionWithV "v1.0.8.0" #endif #define MyAppName "SmartSDR D-STAR Waveform"