diff --git a/autobuilder b/autobuilder index 2c3c665..5dcbd49 100755 --- a/autobuilder +++ b/autobuilder @@ -25,24 +25,30 @@ echo " --------------------------" #fancy banner! echo " Autobuilder for TinI/O 0.1" echo " --------------------------" echo " Verifying main directory..." -[ -d cylib ] && [ -d tinio ] && proceed=1 #check if we're in the right dir +[ -d configutility ] && [ -d tinio ] && proceed=1 #check if we're in the right dir proceed #error check echo " DONE!" echo " Entering the library directory..." -cd cylib/build && proceed=1 #cd to the lib dir +cd cylib && proceed=1 #cd to the lib dir proceed #error check echo " DONE!" echo " Compiling and installing the library..." -cmake .. && make && sudo make install && proceed=1 #compiles the lib - #according to the lib docs +make && proceed=1 #compiles the lib according to the lib docs proceed echo " DONE!" echo " Library installation complete." echo " Going back..." -cd ../.. && proceed=1 #goes from cylib/build to cylib then to main dir +cd .. && proceed=1 #to main dir proceed echo " DONE!" sleep 1 # sleep for 1 sec to let the user see the output echo " Entering the TinI/O build directory" cd tinio && proceed=1 echo " DONE!" +proceed +echo " Compiling TinI/O..." +cd tinio && make && make install && proceed=1 +proceed +echo " DONE!" +echo " Compiling the flasher tool" +cd ../tool && make && proceed=1 diff --git a/configutility/README.txt b/configutility/README.txt new file mode 100644 index 0000000..96450c3 --- /dev/null +++ b/configutility/README.txt @@ -0,0 +1,36 @@ +======================================================================================== + Cypress Semiconductor Corporation + CyUSB Serial library. +========================================================================================= +Pre-requisite: +1. libusb-1.0.9 is required for compilation and functioning of the APIs in the library. +2. GNU Make and the GCC tool-chain are used for the build process. + +Installation steps: + +1.cd to the main directory where the library source files are extracted and goto ./linux/library + +2.Type 'sudo make'. + +2.This will generate shared library libcyusbserial.so.1 and its soft link libcyusbserial.so. + Both of them will be copied/installed to /usr/local/lib. + +3.Go to ./linux/testUtility (I2C/SPI test utility program) and type 'sudo make'. +This will generate CyUSBSerialTestUtility binary (Refer to README in testUtility folder). + +4.User can launch the application and test the communication with Cypress USB-Serial DVk in vendor mode. + +Changing USB device node permission: + +By default the USB device node created in linux do not have read/write permission +for normal user. In order to make the USB device node accessable, copy 90-cyusb.rules +which is inside the library folder of release package to /etc/udev/rules.d folder (Default VID mentioned is Cypress VID +which is 0x4B4, if VID is changed then update it in ATTR{idVendor} section of rules file). + +*** IMPORTANT: +Some distribution of linux have libusb (older version) as part of their package. Uninstall +the older version and update it with libusb-1.0.9. + +**Note: +Refer to ./common/doc/CyUSBSerial API documentation.pdf for description of all +the vendor mode APIs. The header file of the library is in ./common/header/CyUSBSerial.h. diff --git a/configutility/common/header/CyUSBBootloader.h b/configutility/common/header/CyUSBBootloader.h new file mode 100644 index 0000000..f68f7d7 --- /dev/null +++ b/configutility/common/header/CyUSBBootloader.h @@ -0,0 +1,447 @@ +/* +## Cypress USB Serial Library header file (CyUSBSerial.h) +## =========================== +## +## Copyright Cypress Semiconductor Corporation, 2012-2013, +## All Rights Reserved +## UNPUBLISHED, LICENSED SOFTWARE. +## +## CONFIDENTIAL AND PROPRIETARY INFORMATION +## WHICH IS THE PROPERTY OF CYPRESS. +## +## Use of this file is governed +## by the license agreement included in the file +## +## /license/license.txt +## +## where is the Cypress software +## installation root directory path. +## +## =========================== +*/ + +#ifndef _INCLUDED_CYUSBBOOTLOADER_H_ +#define _INCLUDED_CYUSBBOOTLOADER_H_ + +/*This is to export windows API*/ +#ifdef CYWINEXPORT +#undef CYWINEXPORT +#endif +#ifdef WIN32 + +#ifdef CYUSBSERIAL_EXPORTS + #define CYWINEXPORT extern "C" __declspec(dllexport) + #define WINCALLCONVEN + #else + #define CYWINEXPORT extern "C" __declspec(dllimport) + #define WINCALLCONVEN + #endif +#else /*Linux and MAC*/ + #define CYWINEXPORT + #define WINCALLCONVEN + #ifndef BOOL + typedef bool BOOL; + #endif +#endif + + + +#include "CyUSBSerial.h" + +/* Summary +Enumeration defining return status of USB serial library APIs + +Description +The enumeration CY_RETURN_STATUS holds the different return status of all the +APIs supported by USB Serial library. +*/ + /*API Failed because the SPI/UART status monitor thread already exists*/ +/* +Summary +Structure to hold Boot mode data buffer information. + +Description +This strucuture is used by boot mode data transaction API to perform read, write +operations. + +Before using a variable of this strucutre users need to initialize various members appropriately. + buffer - Need to be initialized to pre-allocated memory only, and user is + expected to deallocate the memory in his application. + length - Contains total length the buffer to be used while performing + read/write operations. + bytesReturned - Specifies the number of bytes actually read/written. + address - Address from where the data need to written/read + +See Also +CyReadFlash +CyProgFlash +CyVerifyFlash +CyReadMemory +CyWriteMemory + +CY_BOOTLOADER_VERSION +*/ +typedef struct _CY_BOOTLD_BUFFER { + + UCHAR *buffer; /*Address of the buffer*/ + UINT32 length; /*total length to be read/written */ + UINT32 *bytesReturned; /*Total length of bytes that was written/read*/ + UINT32 address; /*Address from where data needs to be written/read in device*/ + +} CY_BOOTLD_BUFFER,*PCY_BOOTLD_BUFFER; + +/* +Summary +This structure is used to hold Boot loader version. + +Description +This data type holds the information of version of the bootloader in device. It has major version, +minor version and patch number. + +See Also +CY_BOOTLD_BUFFER +*/ +typedef struct _CY_BOOTLOADER_VERSION { + + UCHAR majorVersion; /*Major version of BootLoader*/ + UCHAR minorVersion; /*Minor version of the BootLoader*/ + UINT16 patchNumber; /*Patch Number of the BootLoader*/ + +} CY_BOOTLOADER_VERSION; + + +/*************************************************************************************/ +/****************************BOOTLOADER API'S*****************************************/ +/*************************************************************************************/ + +/*@@BOOTLoader API + +These APIs provide an interface for configuring the device when it is in BOOT mode. + +The API's under this group gives user to option to configure the device when the device is in BOOT +mode. The APIs include support for device configuration, SCB level configuration, USB interface +configuration, checksum, firmware download. + +*/ + + +/* +Summary +This API retrieves the BootLoader version. + +Description +This API gets the bootloader version of the USB Serial device. + + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyGetSiliconID + +CY_BOOTLOADER_VERSION +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyGetBootLoaderVersion ( + CY_HANDLE handle, /*Valid device handle*/ + CY_BOOTLOADER_VERSION *bootLoaderVersion /*Boot Loader version.*/ + ); +/* +Summary +This API retrieves the silicon ID. + +Description +This API gets the silicon ID of the USB Serial device into the argument siliconID. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyGetBootLoaderVersion + +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyGetSiliconID ( + CY_HANDLE handle, /*Valid device handle*/ + UINT32 *siliconID /*Boot Loader version.*/ + ); + +/* +Summary +This API can be used to change the device operational mode from device firmware to bootloader. + +Description +This API changes the device operational mode from device firmware to bootloader or +Manufacturing mode. + +Call the API GetSignature to identify the current operational mode. This API should be called only +when the device is in firmware mode. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyGetSignature + +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyJumpToMfgMode ( + CY_HANDLE handle); + +/* +Summary +This API can be used to read device configuration + +Description +This API reads the device configuration from the device configuration table. It fills the device +configuration as a series of bytes in the argument deviceConfig + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyWriteDeviceConfig +*/ + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyReadDeviceConfig ( + CY_HANDLE handle, /* Valid device handle*/ + UCHAR *deviceConfig /* Device configuration value.*/ + ); + +/* +Summary +This API can be used to update the device configuration table. + +Description; +This API updates the device configuration in the configuration table of device. The device +configuration must be supplied as an array of bytes. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyReadDeviceConfig + +*/ + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyWriteDeviceConfig ( + CY_HANDLE handle, /*Valid Device handle*/ + UCHAR *deviceConfig /*Device configuration value */ + ); + +/* +Summary +This API can be used to read the content of flash from specified address. + +Description +The readBuffer structure must be filled and with address to be read from, appropriate buffer +and number of bytes to be read. + +The actual bytes read will be available in bytesReturned member of CY_BOOTLD_BUFFER. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CY_BOOTLD_BUFFER +CyProgFlash +CyVerifyFlash +*/ + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyReadFlash ( + CY_HANDLE handle, /*Valid device handle*/ + CY_BOOTLD_BUFFER *readBuffer, /*Buffer pointer containing buffer address, length and address of flash*/ + UINT32 timeout /*API timeout value*/ + ); + +/* +Summary +This API can be used to program the flash at specified address. + +Description +The writeBuffer structure must be filled and with address to be written to, appropriate buffer location +and number of bytes to be written. + +The actual bytes written will be available in bytesReturned member of CY_BOOTLD_BUFFER. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CY_BOOTLD_BUFFER +CyReadFlash +CyVerifyFlash +*/ + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyProgFlash ( + CY_HANDLE handle, /*Valid device handle*/ + CY_BOOTLD_BUFFER *writeBuffer, /*Buffer pointer containing the address of buffer pointer, length and address of flash*/ + UINT32 timeout /*API timeout value*/ + ); +/* +Summary +This API can be used to read the memory content of SRAM from specified address. + +Description +This API reads the content of flash in USB Serial device. The argument readBuffer need to be +initialized with address, number of bytes to be read and buffer location before invoking +this API. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CY_BOOTLD_BUFFER +CyWriteMemory + +*/ + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyReadMemory ( + CY_HANDLE handle, /*Valid handle to communicate with device*/ + CY_BOOTLD_BUFFER *readBuffer, /*Bootloader read buffer details*/ + UINT32 timeout /*API timeout value*/ + ); + +/* +Summary +This API can be used to write content to SRAM at specified address. + +Description +This API writes the buffer content to SRAM. The argument writeBuffer need to be initialized with +target address, number of bytes to be written and buffer location before invoking this API. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CY_BOOTLD_BUFFER +CyReadMemory +*/ + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyWriteMemory ( + CY_HANDLE handle, /*Valid handle to communicate with device*/ + CY_BOOTLD_BUFFER *writeBuffer, /*Bootloader write buffer details*/ + UINT32 timeout /*API timeout value*/ + ); + +/* +Summary +This API can be used calculate the checksum of the firmware loaded and compares it with the checksum in +device configuration table. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyUpdateChecksum +*/ + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyValidateChecksum ( + CY_HANDLE handle /*Valid handle to communicate with device*/ + ); +/* +Summary +This API can be used to read boot configuration. + +Description +This API reads the boot configuration from the boot configuration table of device. The bootConfig +need to be parsed to obtain actual configuration values. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyWriteBootConfig + +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyReadBootConfig ( + CY_HANDLE handle, /*Valid handle to communicate with device*/ + UCHAR *bootConfig /*Current Boot configuration value read back*/ + ); +/* +Summary +This API updates the device boot configuration table. + +Description; +This API updates the boot configuration in the boot configuration table of device. +The bootConfig is pointer to an array of bytes contain the configuration. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyReadBootConfig +*/ + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyWriteBootConfig ( + CY_HANDLE handle, /*Valid handle to communicate with device*/ + UCHAR *bootConfig /*Boot configuration value to be updated*/ + ); +/* +Summary +This API can be used to download firmware on to USB Serial device. + +Description; +This API downloads the firmware specified in filePath on to flash of the USB Serial device. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyReadBootConfig +CyWriteBootConfig +CyReadFlash +CyProgFlash +CyReadMemory +CyWriteMemory +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyDownloadFirmware ( + CY_HANDLE handle, /*Valid handle to communicate with device*/ + CHAR *filePath /*Path of Firmware file*/ + ); + +/* +Summary +This API can be used enable flash configuration on USB Serial device. + +Description; +This API configures the the firmware and allows user to enable/diable flash changes. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyReadBootConfig +CyWriteBootConfig +CyReadFlash +CyProgFlash +CyReadMemory +CyWriteMemory +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyFlashConfigEnable ( + CY_HANDLE handle, /*Valid handle to communicate with device*/ + BOOL enable /*Set to TRUE to enable flash configuration + FALSE to disable flash configuration */ + ); + +/* +Summary +This API can be used to obtain the Silicon Serial No. + +Description; +This API can be used to obtain the Silicon Serial No. + +Return Value +CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + +See Also +CyReadBootConfig +CyWriteBootConfig +CyReadFlash +CyProgFlash +CyReadMemory +CyWriteMemory +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetSiliconSerialID ( + CY_HANDLE handle, /*Valid device handle*/ + UCHAR buffer[8] /*Buffer to contain 8 bytes of data.*/ + ); + +#endif /* _INCLUDED_CYUSBBOOTLOADER_H_ */ diff --git a/configutility/common/header/CyUSBSerial.h b/configutility/common/header/CyUSBSerial.h new file mode 100644 index 0000000..138ad40 --- /dev/null +++ b/configutility/common/header/CyUSBSerial.h @@ -0,0 +1,1845 @@ +/* +## Cypress USB Serial Library header file (CyUSBSerial.h) +## =========================== +## +## Copyright Cypress Semiconductor Corporation, 2012-2013, +## All Rights Reserved +## UNPUBLISHED, LICENSED SOFTWARE. +## +## CONFIDENTIAL AND PROPRIETARY INFORMATION +## WHICH IS THE PROPERTY OF CYPRESS. +## +## Use of this file is governed +## by the license agreement included in the file +## +## /license/license.txt +## +## where is the Cypress software +## installation root directory path. +## +## =========================== +*/ +#ifndef _INCLUDED_CYUSBSERIAL_H_ +#define _INCLUDED_CYUSBSERIAL_H_ + +#ifdef __cplusplus + #define CppCALLCONVEN extern "C" +#else + #define CppCALLCONVEN +#endif + +/*This is to export Windows API*/ +#ifdef WIN32 + #ifdef CYUSBSERIAL_EXPORTS + #define CYWINEXPORT CppCALLCONVEN __declspec(dllexport) + #define WINCALLCONVEN + #define LINUXCALLCONVEN + #else + #define CYWINEXPORT CppCALLCONVEN __declspec(dllimport) + #define WINCALLCONVEN + #define LINUXCALLCONVEN + #endif +#else /*Linux and MAC*/ + #define CYWINEXPORT CppCALLCONVEN + #define WINCALLCONVEN + #define LINUXCALLCONVEN + #ifndef BOOL + typedef bool BOOL; + #endif +#endif +/*************************************************************************************/ +/*******************************Constants*********************************************/ +/*************************************************************************************/ + +/*@@Constants +This section contains details of the all the constants +that are part of Cypress USB Serial driver library. +*/ +#define CY_STRING_DESCRIPTOR_SIZE 256 /*String descriptor size */ +#define CY_MAX_DEVICE_INTERFACE 5 /*Maximum number of interfaces */ + +/* +Summary +This section contains USB Serial library version information. +*/ + +/* Major version number for library. */ +#define CY_US_VERSION_MAJOR (1) + +/* Minor version number for library. */ +#define CY_US_VERSION_MINOR (0) + +/* Patch version number for library. */ +#define CY_US_VERSION_PATCH (0) + +/* Version number for the device. */ +#define CY_US_VERSION ((CY_US_VERSION_MAJOR) | \ + (CY_US_VERSION_MINOR << 8) | \ + (CY_US_VERSION_PATCH << 16)) +/* Library build number. */ +#define CY_US_VERSION_BUILD (59) + + +/*************************************************************************************/ +/****************************Data Type Definitions************************************/ +/*************************************************************************************/ + +/*@@Data Types +This section defines the data types that are used by +Cypress USB Serial driver library. +*/ +#ifndef UINT32 + typedef unsigned int UINT32; +#endif +#ifndef UINT8 + typedef unsigned char UINT8; +#endif +#ifndef UINT16 + typedef unsigned short UINT16; +#endif +#ifndef CHAR + typedef char CHAR; +#endif +#ifndef UCHAR + typedef unsigned char UCHAR; +#endif + +/* Summary + CyUSB Device Handle. + + Description + The handle is used by application to communicate with USB serial device. + The handle is obtained by calling CyOpen. + + See Also + * CyOpen +*/ +typedef void* CY_HANDLE; + +/* +Summary +Function pointer for getting async error/success notification on UART/SPI + +Description +This function pointer that will be passed to CySetEventNotification and get +a callback with a 2 byte value bit map that reports error/events triggered during UART/SPI transaction. +The bit map is defined in CY_CALLBACK_EVENTS. + +See also +* CY_CALLBACK_EVENTS +*/ +typedef void (*CY_EVENT_NOTIFICATION_CB_FN)(UINT16 eventsNotified); + +/* +Summary +This structure is used to hold VID and PID of USB device + +Description +This Strucuture holds the VID and PID of a USB device. + +See Also +* CY_DEVICE_INFO +* CyGetDeviceInfoVidPid +*/ +typedef struct _CY_VID_PID { + + UINT16 vid; /*Holds the VID of the device*/ + UINT16 pid; /*Holds the PID of the device*/ + +} CY_VID_PID, *PCY_VID_PID; + +/* Summary +This structure is used to hold version information of the library. + +Description +This structure can be used to retrive the version information of the library. + +See Also +* CyGetLibraryVersion +*/ +typedef struct _CY_LIBRARY_VERSION { + + UINT8 majorVersion; /*The major version of the library*/ + UINT8 minorVersion; /*The minor version of the library*/ + UINT16 patch; /*The patch number of the library*/ + UINT8 buildNumber; /*The build number of the library*/ + +} CY_LIBRARY_VERSION, *PCY_LIBRARY_VERSION; + +/* +Summary +This structure is used to hold firmware version of the USB Serial device. + +Description +This structure holds the version information of the USB serial device. +It has major version, minor version, patch number and build number. + +See Also +* CyGetFirmwareVersion +*/ +typedef struct _CY_FIRMWARE_VERSION { + + UINT8 majorVersion; /*Major version of the Firmware*/ + UINT8 minorVersion; /*Minor version of the Firmware*/ + UINT16 patchNumber; /*Patch Number of the Firmware*/ + UINT32 buildNumber; /*Build Number of the Firmware*/ + +} CY_FIRMWARE_VERSION, *PCY_FIRMWARE_VERSION; + +/* Summary +Enumeration defining list of USB device classes supported by USB Serial device. + +Description +This is the list of USB device classes supported by USB Serial device. + +See Also +* CY_DEVICE_INFO +* CyGetDeviceInfo +* CyGetDeviceInfoVidPid +*/ +typedef enum _CY_DEVICE_CLASS{ + + CY_CLASS_DISABLED = 0, /*None or the interface is disabled */ + CY_CLASS_CDC = 0x02, /*CDC ACM class*/ + CY_CLASS_PHDC = 0x0F, /*PHDC class */ + CY_CLASS_VENDOR = 0xFF /*VENDOR specific class*/ + +} CY_DEVICE_CLASS; + +/* Summary +Enumeration defining list of device types supported by USB Serial device in each interface. + +Description +This is the list of device types supported by USB Serial device when the interface type is +configured as CY_CLASS_VENDOR. The interface type can be queried from the device by using CyGetDeviceInfo +and CyGetDeviceInfoVidPid APIs. + +The member of CY_DEVICE_INFO structure contains the interface type. + +See Also +* CY_DEVICE_INFO +* CyGetDeviceInfo +* CyGetDeviceInfoVidPid +*/ +typedef enum _CY_DEVICE_TYPE { + + CY_TYPE_DISABLED = 0, /*Invalid device type or interface is not CY_CLASS_VENDOR*/ + CY_TYPE_UART, /*Interface of device is of type UART*/ + CY_TYPE_SPI, /*Interface of device is of type SPI */ + CY_TYPE_I2C, /*Interface of device is of type I2C */ + CY_TYPE_JTAG, /*Interface of device is of type JTAG*/ + CY_TYPE_MFG /*Interface of device is in Manufacturing mode*/ + +} CY_DEVICE_TYPE; + +/* Summary +This enumeration type defines the available device serial blocks. + +Description +USB Serial device has up to two configurable serial blocks. UART, SPI, I2C or JTAG functionality can be +configured and used in these serial block. Windows driver binds to a serial block rather than the entire device. +So, it is essential to find out which serial block to which current communications are directed. These enumeration +structure provides the possible SERIAL BLOCK Options. + +This enumration data type is a member of CY_DEVICE_INFO structure. + +This data type information doesn't apply for non-windows operating system. + +See Also +CY_DEVICE_INFO +CyGetDeviceInfo +CyGetDeviceInfoVidPid +*/ + +typedef enum _CY_DEVICE_SERIAL_BLOCK +{ + SerialBlock_SCB0 = 0, /*Serial Block Number 0*/ + SerialBlock_SCB1, /*Serial Block Number 1*/ + SerialBlock_MFG /*Serial Block Manufacturing Interface.*/ + +} CY_DEVICE_SERIAL_BLOCK; + +/* Summary +Structure to hold information of the device connected to host. + +Description +The structure holds the information about device currently connected to host. The information +can be obtained by using CyGetDeviceInfo and CyGetDeviceInfoVidPid APIs. + +The information includes VID, PID, number of interfaces, string descriptors, device type +and device class supported by each interface. Device type is valid only if the interface is CY_CLASS_VENDOR. + +See Also +CY_VID_PID +CY_DEVICE_CLASS +CY_DEVICE_TYPE +CyGetDeviceInfo +CyGetDeviceInfoVidPid +*/ +typedef struct _CY_DEVICE_INFO { + + CY_VID_PID vidPid; /*VID and PID*/ + UCHAR numInterfaces; /*Number of interfaces supported*/ + UCHAR manufacturerName [CY_STRING_DESCRIPTOR_SIZE]; /*Manufacturer name*/ + UCHAR productName [CY_STRING_DESCRIPTOR_SIZE]; /*Product name*/ + UCHAR serialNum [CY_STRING_DESCRIPTOR_SIZE]; /*Serial number*/ + UCHAR deviceFriendlyName [CY_STRING_DESCRIPTOR_SIZE]; /*Device friendly name : Windows only*/ + CY_DEVICE_TYPE deviceType [CY_MAX_DEVICE_INTERFACE]; /*Type of the device each interface has(Valid only + for USB Serial Device) and interface in vendor class*/ + CY_DEVICE_CLASS deviceClass [CY_MAX_DEVICE_INTERFACE]; /*Interface class of each interface*/ + +#ifdef WIN32 + CY_DEVICE_SERIAL_BLOCK deviceBlock; /* On Windows, each USB Serial device interface is associated with a + separate driver instance. This variable represents the present driver + interface instance that is associated with a serial block. */ +#else + UINT8 busNumber; /*Bus number of the device*/ + UINT8 deviceAddress; /*Unigue Identification number of the device*/ +#endif + +} CY_DEVICE_INFO,*PCY_DEVICE_INFO; + +/* Summary +This structure is used to hold data buffer information. + +Description +This strucuture is used by all the data transaction APIs in the library to perform read, write +operations. +Before using a variable of this strucutre users need to initialize various members appropriately. + +See Also +* CyUartRead +* CyUartWrite +* CyI2cRead +* CyI2cWrite +* CySpiReadWrite +* CyJtagWrite +* CyJtagRead +*/ +typedef struct _CY_DATA_BUFFER { + + UCHAR *buffer; /*Pointer to the buffer from where the data is read/written */ + UINT32 length; /*Length of the buffer */ + UINT32 transferCount; /*Number of bytes actually read/written*/ + +} CY_DATA_BUFFER,*PCY_DATA_BUFFER; + +/* Summary +Enumeration defining return status of USB serial library APIs + +Description +The enumeration CY_RETURN_STATUS holds the different return status of all the +APIs supported by USB Serial library. +*/ +typedef enum _CY_RETURN_STATUS{ + + CY_SUCCESS = 0, /*API returned successfully without any errors.*/ + CY_ERROR_ACCESS_DENIED, /*Access of the API is denied for the application */ + CY_ERROR_DRIVER_INIT_FAILED, /*Driver initialisation failed*/ + CY_ERROR_DEVICE_INFO_FETCH_FAILED, /*Device information fetch failed */ + CY_ERROR_DRIVER_OPEN_FAILED, /*Failed to open a device in the library */ + CY_ERROR_INVALID_PARAMETER, /*One or more parameters sent to the API was invalid*/ + CY_ERROR_REQUEST_FAILED, /*Request sent to USB Serial device failed */ + CY_ERROR_DOWNLOAD_FAILED, /*Firmware download to the device failed */ + CY_ERROR_FIRMWARE_INVALID_SIGNATURE, /*Invalid Firmware signature in firmware file*/ + CY_ERROR_INVALID_FIRMWARE, /*Invalid firmware */ + CY_ERROR_DEVICE_NOT_FOUND, /*Device disconnected */ + CY_ERROR_IO_TIMEOUT, /*Timed out while processing a user request*/ + CY_ERROR_PIPE_HALTED, /*Pipe halted while trying to transfer data*/ + CY_ERROR_BUFFER_OVERFLOW, /*OverFlow of buffer while trying to read/write data */ + CY_ERROR_INVALID_HANDLE, /*Device handle is invalid */ + CY_ERROR_ALLOCATION_FAILED, /*Error in Allocation of the resource inside the library*/ + CY_ERROR_I2C_DEVICE_BUSY, /*I2C device busy*/ + CY_ERROR_I2C_NAK_ERROR, /*I2C device NAK*/ + CY_ERROR_I2C_ARBITRATION_ERROR, /*I2C bus arbitration error*/ + CY_ERROR_I2C_BUS_ERROR, /*I2C bus error*/ + CY_ERROR_I2C_BUS_BUSY, /*I2C bus is busy*/ + CY_ERROR_I2C_STOP_BIT_SET, /*I2C master has sent a stop bit during a transaction*/ + CY_ERROR_STATUS_MONITOR_EXIST /*API Failed because the SPI/UART status monitor thread already exists*/ +} CY_RETURN_STATUS; + +/* Summary +This structure is used to store configuration of I2C module. + +Description +The structure contains parameters that are used in configuring I2C module of +Cypress USB Serial device. CyGetI2cConfig and CySetI2cConfig APIs can be used to +retrieve and configure I2C module respectively. + +See Also +* CyGetI2cConfig +* CySetI2cConfig +*/ +typedef struct _CY_I2C_CONFIG{ + + UINT32 frequency; /* I2C clock frequency 1KHz to 400KHz*/ + UINT8 slaveAddress; /* Slave address of the I2C module, when it is configured as slave*/ + BOOL isMaster; /* true- Master , false- slave*/ + BOOL isClockStretch; /* true- Stretch clock in case of no data availability + (Valid only for slave mode) + false- Do not Stretch clock*/ +} CY_I2C_CONFIG,*PCY_I2C_CONFIG; + +/* Summary +This structure is used to configure each I2C data transaction. + +Description +This structure defines parameters that are used for configuring +I2C module during each data transaction. Which includes setting slave address +(when device is in I2C slave mode), stopbit (to enable or disable) and +Nak bit (to enable or disable). + +See Also +* CyI2cWrite +* CyI2cRead +*/ +typedef struct _CY_I2C_DATA_CONFIG +{ + UCHAR slaveAddress; /*Slave address the master will communicate with*/ + BOOL isStopBit; /*Set when stop bit is used*/ + BOOL isNakBit; /*Set when I2C master wants to NAK the slave after read + Applicable only when doing I2C read*/ +} CY_I2C_DATA_CONFIG, *PCY_I2C_DATA_CONFIG; + +/* Summary +Enumeration defining SPI protocol types supported by USB Serial SPI module. + +Description +These are the different protocols supported by USB-Serial SPI module. + +See Also +* CY_SPI_CONFIG +* CyGetSpiConfig +* CySetSpiConfig +*/ +typedef enum _CY_SPI_PROTOCOL { + + CY_SPI_MOTOROLA = 0, /*In master mode, when not transmitting data (SELECT is inactive), SCLK is stable at CPOL. + In slave mode, when not selected, SCLK is ignored; i.e. it can be either stable or clocking. + In master mode, when there is no data to transmit (TX FIFO is empty), SELECT is inactive. + */ + CY_SPI_TI, /*In master mode, when not transmitting data, SCLK is stable at '0'. + In slave mode, when not selected, SCLK is ignored - i.e. it can be either stable or clocking. + In master mode, when there is no data to transmit (TX FIFO is empty), SELECT is inactive - + i.e. no pulse is generated. + *** It supports only mode 1 whose polarity values are + CPOL = 0 + CPHA = 1 + */ + CY_SPI_NS /*In master mode, when not transmitting data, SCLK is stable at '0'. In slave mode, + when not selected, SCLK is ignored; i.e. it can be either stable or clocking. + In master mode, when there is no data to transmit (TX FIFO is empty), SELECT is inactive. + *** It supports only mode 0 whose polarity values are + CPOL = 0 + CPHA = 0 + */ +} CY_SPI_PROTOCOL; + +/* Summary +This structure is used to configure the SPI module of USB Serial device. + +Description +This structure defines configuration parameters that are used for configuring the SPI module . + +See Also +* CY_SPI_PROTOCOL +* CY_SPI_DATA_TRANSFER_MODE +* CyGetSpiConfig +* CySetSpiConfig +*/ +typedef struct _CY_SPI_CONFIG +{ + + UINT32 frequency; /*SPI clock frequency. + ** IMPORTANT: The frequency range supported by SPI module is + 1000(1KHz) to 3000000(3MHz) + */ + + UCHAR dataWidth; /*Data width in bits. The valid values are from 4 to 16.*/ + + CY_SPI_PROTOCOL protocol ; /*SPI Protocols to be used as defined in CY_SPI_PROTOCOL*/ + + BOOL isMsbFirst; /*false -> least significant bit is sent out first + true -> most significant bit is sent out first */ + + BOOL isMaster; /*false --> Slave mode selected: + true --> Master mode selected*/ + + BOOL isContinuousMode; /*true - Slave select line is not asserted i.e + de-asserted for every word. + false- Slave select line is always asserted*/ + + BOOL isSelectPrecede; /*Valid only in TI mode. + true - The start pulse precedes the first data + false - The start pulse is in sync with first data. */ + + BOOL isCpha; /*false - Clock phase is 0; true - Clock phase is 1. */ + + BOOL isCpol; /*false - Clock polarity is 0;true - Clock polarity is 1.*/ + +}CY_SPI_CONFIG,*PCY_SPI_CONFIG; + +/* Summary +Enumeration defines UART baud rates supported by UART module of USB Serial device. + +Description +The enumeration lists the various baud rates supported by the UART when it is in UART +vendor mode. + +See Also +* CY_UART_CONFIG +* CySetUartConfig +* CyGetUartConfig +*/ +typedef enum _CY_UART_BAUD_RATE +{ + CY_UART_BAUD_300 = 300, /* Baud rate of 300. */ + CY_UART_BAUD_600 = 600, /* Baud rate of 600. */ + CY_UART_BAUD_1200 = 1200, /* Baud rate of 1200. */ + CY_UART_BAUD_2400 = 2400, /* Baud rate of 2400. */ + CY_UART_BAUD_4800 = 4800, /* Baud rate of 4800. */ + CY_UART_BAUD_9600 = 9600, /* Baud rate of 9600. */ + CY_UART_BAUD_14400 = 14400, /* Baud rate of 14400. */ + CY_UART_BAUD_19200 = 19200, /* Baud rate of 19200. */ + CY_UART_BAUD_38400 = 38400, /* Baud rate of 38400. */ + CY_UART_BAUD_56000 = 56000, /* Baud rate of 56000. */ + CY_UART_BAUD_57600 = 57600, /* Baud rate of 57600. */ + CY_UART_BAUD_115200 = 115200, /* Baud rate of 115200. */ + CY_UART_BAUD_230400 = 230400, /* Baud rate of 230400. */ + CY_UART_BAUD_460800 = 460800, /* Baud rate of 460800. */ + CY_UART_BAUD_921600 = 921600, /* Baud rate of 921600. */ + CY_UART_BAUD_1000000 = 1000000, /* Baud rate of 1000000. */ + CY_UART_BAUD_3000000 = 3000000, /* Baud rate of 3000000. */ + +}CY_UART_BAUD_RATE; + +/* +Summary +Enumeration defines the different parity modes supported by UART module of USB Serial device. + +Description +This enumeration defines the different parity modes of USB Serial UART module. +It supports odd, even, mark and space parity modes. + +See Also +* CY_UART_CONFIG +* CySetUartConfig +* CyGetUartConfig +*/ +typedef enum _CY_UART_PARITY_MODE { + + CY_DATA_PARITY_DISABLE = 0, /*Data parity disabled*/ + CY_DATA_PARITY_ODD, /*Odd Parity*/ + CY_DATA_PARITY_EVEN, /*Even Parity*/ + CY_DATA_PARITY_MARK, /*Mark parity*/ + CY_DATA_PARITY_SPACE /*Space parity*/ + +} CY_UART_PARITY_MODE; + +/* +Summary +Enumeration defines the different stop bit values supported by UART module of USB Serial device. + +See Also +* CY_UART_CONFIG +* CySetUartConfig +* CyGetUartConfig +*/ +typedef enum _CY_UART_STOP_BIT { + + CY_UART_ONE_STOP_BIT = 1, /*One stop bit*/ + CY_UART_TWO_STOP_BIT /*Two stop bits*/ + +} CY_UART_STOP_BIT; + +/* +Summary +Enumeration defines flow control modes supported by UART module of USB Serial device. + +Description +The list provides the various flow control modes supported by USB Serial device. + +See Also +* CyUartSetHwFlowControl +* CyUartGetHwFlowControl +*/ +typedef enum _CY_FLOW_CONTROL_MODES { + + CY_UART_FLOW_CONTROL_DISABLE = 0, /*Disable Flow control*/ + CY_UART_FLOW_CONTROL_DSR, /*Enable DSR mode of flow control*/ + CY_UART_FLOW_CONTROL_RTS_CTS, /*Enable RTS CTS mode of flow control*/ + CY_UART_FLOW_CONTROL_ALL /*Enable RTS CTS and DSR flow control */ + +} CY_FLOW_CONTROL_MODES; + +/* +Summary +Structure holds configuration of UART module of USB Serial device. + +Description +This structure defines parameters used for configuring the UART module. +CySetUartConfig and CyGetUartConfig APIs are used to configure and retrieve +the UART configuration information. + +See Also +* CySetUartConfig +* CyGetUartConfig +*/ +typedef struct _CY_UART_CONFIG { + + CY_UART_BAUD_RATE baudRate; /*Baud rate as defined in CY_UART_BAUD_RATE*/ + UINT8 dataWidth; /*Data width: valid values 7 or 8*/ + CY_UART_STOP_BIT stopBits; /*Number of stop bits to be used 1 or 2*/ + CY_UART_PARITY_MODE parityMode; /*UART parity mode as defined in CY_UART_PARITY_MODE*/ + BOOL isDropOnRxErrors; /*Whether to ignore framing as well as parity errors and receive data */ + +} CY_UART_CONFIG,*PCY_UART_CONFIG; + +/* +Summary +Enumeration defining UART/SPI transfer error or status bit maps. + +Description +Enumeration lists the bit maps that are used to report error or status during +UART/SPI transfer. + +See Also +* CySetEventNotification +*/ +typedef enum _CY_CALLBACK_EVENTS { + + CY_UART_CTS_BIT = 0x01, /*CTS pin notification bit*/ + CY_UART_DSR_BIT = 0x02, /*State of transmission carrier. This signal + corresponds to V.24 signal 106 and RS-232 signal DSR.*/ + CY_UART_BREAK_BIT = 0x04, /*State of break detection mechanism of the device */ + CY_UART_RING_SIGNAL_BIT = 0x08, /*State of ring signal detection of the device*/ + CY_UART_FRAME_ERROR_BIT = 0x10, /*A framing error has occurred*/ + CY_UART_PARITY_ERROR_BIT = 0x20, /*A parity error has occured*/ + CY_UART_DATA_OVERRUN_BIT = 0x40, /*Received data has been discarded due to overrun in + the device*/ + CY_UART_DCD_BIT = 0x100, /*State of receiver carrier detection mechanism of + device. This signal corresponds to V.24 signal 109 + and RS-232 signal DCD*/ + CY_SPI_TX_UNDERFLOW_BIT = 0x200, /*Notification sent when SPI fifo is empty*/ + CY_SPI_BUS_ERROR_BIT = 0x400, /*Spi bus error has been detected*/ + CY_ERROR_EVENT_FAILED_BIT = 0x800 /*Event thread failed*/ + +} CY_CALLBACK_EVENTS; + +/*************************************************************************************/ +/*********************USB Initialization APIs************************************/ +/*************************************************************************************/ + +/*@@USB Initialization API +This section has all the APIs that handle device initialization and +fetching information about the device connected. +*/ + +/* + Summary + This API is used to initialize the library. + + Description + The API is used to initialize the underlying libusb library and + is expected to be called when the application is being started. + + Note: The API is used only in Linux and Mac OS. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_DRIVER_INIT_FAILED on failure + (Failure could be because of not calling CyLibraryExit previously) + + See Also + * CyOpen + * CyLibraryExit +*/ +CYWINEXPORT CY_RETURN_STATUS LINUXCALLCONVEN CyLibraryInit (); + +/* + Summary + This API is used to free the library. + + Description + The API is used to free the library and should be called + when exiting the application. + + Note: This API is used only in Linux and Mac library. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_REQUEST_FAILED on failure + + See Also + * CyOpen + * CyClose + * CyLibraryInit +*/ +CYWINEXPORT CY_RETURN_STATUS LINUXCALLCONVEN CyLibraryExit (); + +/* + Summary + This API retrieves number of USB devices connected to the host. + + Description + This API retrieves the number of devices connected to the host. + In Windows family of operating systems the API retrieves only the number of devices that are attached + to CyUSB3.SYS driver. For other operating systems, it retrieves the total number of USB devices present + on the bus. It includes both USB Serial device as well as other devices. + + Note: In case of Linux and Mac apart from providing number of devices connected, it builds the + device list which is used for opening the device and obtaining device handle. Thus the API should be + called during device discovery in the application. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_DEVICE_NOT_FOUND if there are no devices attached. + * CY_ERROR_REQUEST_FAILED if library was not initialized. + + See Also + * CyGetDeviceInfo + * CyGetDeviceInfoVidPid + * CyOpen + * CyClose +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetListofDevices ( + UINT8* numDevices /*Number of Devices connected*/ + ); + +/* + Summary + This API retrieves the device information of a USB device. + + Description + This API retrieves information about a device connected to host. In order to + get the device information on particular device user needs to provide the device number. + To identify the device of interest, the application needs to loop through all devices connected + and obtain the information. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_REQUEST_FAILED if library is not initialized (Only for Linux and Mac). + * CY_ERROR_INVALID_PARAMETER if the input parameters are invalid. + * CY_ERROR_DEVICE_INFO_FETCH_FAILED if failed to fetch device information. + * CY_ERROR_ACCESS_DENIED if access is denied by operating system. + * CY_ERROR_DEVICE_NOT_FOUND if specified device number is invalid. + + See Also + * CY_DEVICE_INFO + * CY_DEVICE_TYPE + * CY_DEVICE_CLASS + * CyGetListofDevices + * CyGetDeviceInfoVidPid + * CyOpen + * CyClose +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetDeviceInfo( + UINT8 deviceNumber, /*Device number of the device of interest*/ + CY_DEVICE_INFO *deviceInfo /*Info of device returned*/ + ); + +/* + Summary + This API is used to retrieve the information of all devices with specified Vendor ID and Product ID. + + Description + For a given VID and PID, the API returns deviceIdList and deviceInfoList. + The deviceIdList contains the device numbers of all the devices with specified VID and PID. + Using deviceInfoList application can identify the device of interest. + Information that is provided includes interface number, string descriptor, deviceType and deviceClass. + + + Return Value + * CY_SUCCESS on success else error codes as defined in the enumeration CY_RETURN_STATUS. + * CY_ERROR_REQUEST_FAILED on if library is not initialized (Only for Linux and Mac) + * CY_ERROR_INVALID_PARAMETER if the input parameters are invalid. + * CY_ERROR_DEVICE_INFO_FETCH_FAILED if failed to fetch device information. + * CY_ERROR_ACCESS_DENIED if access is denied by operating system. + * CY_ERROR_DEVICE_NOT_FOUND if specified device number is invalid. + + See Also + * CY_DEVICE_INFO + * CY_DEVICE_CLASS + * CY_DEVICE_TYPE + * CyGetListofDevices + * CyGetDeviceInfo + * CyOpen + * CyClose +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetDeviceInfoVidPid ( + CY_VID_PID vidPid, /*VID and PID of device of interest*/ + UINT8 *deviceIdList, /*Array of device ID's returned*/ + CY_DEVICE_INFO *deviceInfoList, /*Array of pointers to device info list*/ + UINT8 *deviceCount, /*Count of devices with specified VID PID*/ + UINT8 infoListLength /*Total length of the deviceInfoList allocated + (Size of deviceInfoList array)*/ + ); + +/* + Summary + This API is used to open the USB Serial device. + + Description + This API is used to open USB Serial device based on the device number. + + Note: The argument interfaceNum is used on Linux and Mac OS while obtaining handle for specific + interface. In Windows family of operating systems, this argument should be set to zero. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_REQUEST_FAILED on if library is not initialized (Only for Linux and Mac) + * CY_ERROR_INVALID_PARAMETER if the input parameters are invalid. + * CY_ERROR_DRIVER_OPEN_FAILED if open was unsuccessful. + * CY_ERROR_ACCESS_DENIED if access is denied by operating system. + * CY_ERROR_ALLOCATION_FAILED if memory allocation was failed. + * CY_ERROR_DEVICE_NOT_FOUND if specified device number is invalid. + + See Also + * CyGetListofDevices + * CyGetDeviceInfoVidPid + * CyGetDeviceInfo + * CyClose +*/ +CYWINEXPORT CY_RETURN_STATUS CyOpen ( + UINT8 deviceNumber, /*Device number of device that needs to be opened*/ + UINT8 interfaceNum, /*Interface Number*/ + CY_HANDLE *handle /*Handle returned by the API*/ + ); + +/* + Summary + This API closes the specified device handle and releases all resources associated with it. + + Description + This API closes the device handle and releases all the resources allocated internally in the + library. This API should be invoked using a valid device handle and upon successful return + of CyOpen. + + Return Value + * CY_SUCCESS on success. + * CY_ERROR_INVALID_HANDLE if handle is invalid in case of Linux/Mac. + * CY_ERROR_INVALID_PARAMETER if handle is invalid in case of Windows. + * CY_ERROR_REQUEST_FAILED on error in case of library being not initialized (Only for Linux and Mac). + + See Also + * CyOpen +*/ +CYWINEXPORT CY_RETURN_STATUS CyClose ( + CY_HANDLE handle /*Handle of the device that needs to be closed*/ + ); + +/* + Summary + This API is used to power cycle the host port. + + Description + This API will power cycle the upstream port. It will reenumerate the device after the power cycle. + + Note: This API is not supported on Linux and Mac + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid in case of Linux/Mac. + * CY_ERROR_INVALID_PARAMETER if handle is invalid in case of Windows. + * CY_ERROR_REQUEST_FAILED on error if request was failed by driver. + + See Also + * CyResetDevice +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyCyclePort ( + CY_HANDLE handle /*Valid device handle */ + ); + +/*************************************************************************************/ +/********************************Common APIs*********************************************/ +/*************************************************************************************/ + +/*@@Common APIs + + These APIs provide an interface for accessing GPIO pins, error status notification on UART/SPI, + getting library and firmware version and signature. +*/ + +/* + Summary + This API sets the value of a GPIO. + + Description + This API is used to set the value of a GPIO. It can only set the value of a + GPIO that is configured as an output. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED on error when request is failed by USB Serial device. + + See Also + * CyGetGpioValue +*/ +CYWINEXPORT CY_RETURN_STATUS CySetGpioValue ( + CY_HANDLE handle, /*Valid device handle*/ + UINT8 gpioNumber, /*GPIO number*/ + UINT8 value /*Value that needs to be set*/ + ); + +/* + Summary + This API retrieves the value of a GPIO. + + Description + This API retrieves the value of a GPIO. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range and + also when handle is invalid in case of Windows. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device. + + See Also + * CySetGpioValue +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetGpioValue ( + CY_HANDLE handle, /*Valid device handle*/ + UINT8 gpioNumber, /*GPIO number*/ + UINT8 *value /*Current state of the GPIO*/ + ); + + +/* + Summary + This API is used to register a callback for error/event notifications + during UART/SPI data transfers. + + Description + The API is used to register a callback for error/event notifications while + doing data transfer on UART or SPI. A callback will be issued based on the + error/events sent by the device. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_STATUS_MONITOR_EXIST if notification callback is already registered. + + See Also + * CY_CALLBACK_EVENTS + * CY_EVENT_NOTIFICATION_CB_FN + * CyAbortEventNotification +*/ +CYWINEXPORT CY_RETURN_STATUS CySetEventNotification( + CY_HANDLE handle, /*Valid device handle*/ + CY_EVENT_NOTIFICATION_CB_FN notificationCbFn /*Callback function pointer*/ + ); + +/* + Summary + The API is used to unregister the event callback. + + Description + The API is used to unregister the event callback. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_REQUEST_FAILED if API is called before registering callback. + + See Also + * CySetEventNotification +*/ +CYWINEXPORT CY_RETURN_STATUS CyAbortEventNotification( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API retrieves the version of USB Serial library. + + Description + This API retrieves the version of USB Serial library. + + Return Value + * CY_SUCCESS + + See Also + * CyGetFirmwareVersion +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetLibraryVersion ( + CY_HANDLE handle, /*Valid device handle*/ + PCY_LIBRARY_VERSION version /*Library version of the current library*/ + ); + +/* + Summary + This API retrieves the firmware version of the USB Serial device. + + Description + This API retrieves the firmware version of the USB Serial device. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device. + + See Also + * CyGetLibraryVersion +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetFirmwareVersion ( + CY_HANDLE handle, /*Valid device handle*/ + PCY_FIRMWARE_VERSION firmwareVersion /*Firmware version.*/ + ); + +/* + Summary + This API resets the device by sending a vendor request. + + Description + The API will reset the device by sending a vendor request to the firmware. The device + will be re-enumerated. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device. + + See Also + * CyCyclePort +*/ +CYWINEXPORT CY_RETURN_STATUS CyResetDevice ( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + The API writes to the user flash area on the USB Serial device. + + Description + The API programs user flash area. The total space available is 512 bytes. + The flash area address offset is from 0x0000 to 0x00200 and should be written + page wise (page size is 128 bytes). + On return, transferCount parameter in CY_DATA_BUFFER will specify the number of bytes actually + programmed. + + Note: Length and page address needs to be 128 bytes aligned. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device. + + See Also + * CyReadUserFlash +*/ +CYWINEXPORT CY_RETURN_STATUS CyProgUserFlash ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER *progBuffer, /*Data buffer containing buffer address, length to write*/ + UINT32 flashAddress, /*Address to the data is written*/ + UINT32 timeout /*Timeout value of the API*/ + ); + +/* + Summary + The API reads from the flash address specified. + + Description + Read from user flash area.The total space available is 512 bytes. + The flash area address offset is from 0x0000 to 0x00200 and should be read + page wise (page size is 128 bytes). + On return transferCount parameter in CY_DATA_BUFFER will specify the number of bytes actually + read. + + Note: Length and page address needs to be 128 bytes aligned. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device. + + See Also + * CyProgUserFlash +*/ +CYWINEXPORT CY_RETURN_STATUS CyReadUserFlash ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER *readBuffer, /*data buffer containing buffer address, length to read*/ + UINT32 flashAddress, /*Address from which the data is read*/ + UINT32 timeout /*Timeout value of the API*/ + ); + +/* + Summary + This API retrieves the signature of the device firmware. + + Description + This API retrieves the signature of the device firmware. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device. + */ +CYWINEXPORT CY_RETURN_STATUS CyGetSignature ( + CY_HANDLE handle, /*Valid device handle*/ + UCHAR *pSignature /*Signature returned*/ + ); + +/****************************************************************************************/ +/********************************UART API's**********************************************/ +/****************************************************************************************/ + +/*@@UART API + APIs used to communicate with UART module of the USB Serial device. + These APIs provide support for configuration, data transfer and flow control. +*/ + +/* + Summary + This API retrieves the UART configuration from the USB Serial device. + + Description + This API retrieves the UART configuration from the USB Serial device. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not UART. + + See Also + * CY_UART_CONFIG + * CySetUartConfig +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetUartConfig ( + CY_HANDLE handle, /*Valid device handle*/ + CY_UART_CONFIG *uartConfig /*UART configuration value read back*/ + ); + +/* + Summary + This API sets the UART configuration of USB Serial device. + + Description + This API sets the UART configuration of USB Serial device. + + Note: Using this API during an active transaction of UART may result in data loss. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not UART. + + See Also + * CY_UART_CONFIG + * CyGetUartConfig +*/ +CYWINEXPORT CY_RETURN_STATUS CySetUartConfig ( + CY_HANDLE handle, /*Valid device handle*/ + CY_UART_CONFIG *uartConfig /*UART configuration value */ + ); + +/* + Summary + This API reads data from UART device. + + Description + This API is used to read data from UART device. User needs to initialize the readBuffer with buffer pointer, + number of bytes to read before invoking this API. + On return the transferCount parameter in CY_DATA_BUFFER will contain the number of bytes read. + + Return Value + * CY_SUCCESS on success. + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if input parameters were invalid. + * CY_ERROR_REQUEST_FAILED if the device type is not UART. + * CY_ERROR_IO_TIMEOUT if transfer was timed out. + * CY_ERROR_PIPE_HALTED if pipe was stalled during data transfer. + * CY_ERROR_DEVICE_NOT_FOUND if device was disconnected. + * CY_ERROR_BUFFER_OVERFLOW if data received from USB Serial device is more than requested. + * CY_ERROR_ALLOCATION_FAILED if transaction transmit buffer allocation was failed (Only in Windows). + + See Also + * CY_DATA_BUFFER + * CyUartWrite +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartRead ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER* readBuffer, /*Read buffer details*/ + UINT32 timeout /*API timeout value*/ + ); + +/* + Summary + This API writes the data to UART device. + + Description + This API writes the data to UART device. User need to initialize the + writeBuffer with buffer pointer, number of bytes to write before invoking the API. + On return the transferCount parameter in CY_DATA_BUFFER will contain the number + of bytes written. + + Return Value + * CY_SUCCESS on success. + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if input parameters were invalid. + * CY_ERROR_REQUEST_FAILED if the device type is not UART. + * CY_ERROR_IO_TIMEOUT if transfer was timed out. + * CY_ERROR_PIPE_HALTED if pipe was stalled during data transfer. + * CY_ERROR_DEVICE_NOT_FOUND if device was disconnected. + * CY_ERROR_BUFFER_OVERFLOW if data received from USB Serial device is more than requested. + * CY_ERROR_ALLOCATION_FAILED if transaction transmit buffer allocation was failed (Only in Windows). + + See Also + * CY_DATA_BUFFER + * CyUartRead +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartWrite ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER* writeBuffer, /*Write buffer details*/ + UINT32 timeout /*API timeout value*/ + ); + +/* + Summary + This API enables hardware flow control. + + Description + This API enables hardware flow control. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE on error if handle is invalid in case of Linux/Mac. + * CY_ERROR_INVALID_PARAMETER on error if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT on error if request was timed out. + * CY_ERROR_REQUEST_FAILED on error if request was failed by device or if device type + is not UART. + + See Also + * CyUartGetHwFlowControl +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartSetHwFlowControl( + CY_HANDLE handle, /*Valid device handle*/ + CY_FLOW_CONTROL_MODES mode /*Flow control mode*/ + ); + +/* + Summary + This API retrieves the current hardware flow control status. + + Description + This API retrieves the current hardware flow control status. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not UART. + + See Also + * CyUartSetHwFlowControl +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartGetHwFlowControl( + CY_HANDLE handle, /*Valid device handle*/ + CY_FLOW_CONTROL_MODES *mode /*Flow control mode*/ + ); + +/* + Summary + This API sets RTS signal in UART module. + + Description + This API is used to set the RTS pin to logical low.. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not UART. + + See Also + * CyUartClearRts + * CyUartSetDtr + * CyUartClearDtr +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartSetRts( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API can be used to clear RTS signal in UART module. + + Description + This API used clear the RTS. It sets the RTS pin to logical high. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not UART. + + See Also + * CyUartSetRts + * CyUartSetDtr + * CyUartClearDtr +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartClearRts( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API sets DTR signal in UART. + + Description + This API used set the DTR. It sets the DTR pin to logical low. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not UART. + + See Also + * CyUartClearRts + * CyUartSetRts + * CyUartClearDtr +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartSetDtr( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API can be used to clear DTR signal in UART. + + Description + This API can be used clear the DTR. It sets the DTR pin to logical high. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not UART. + + See Also + * CyUartSetRts + * CyUartSetDtr + * CyUartClearRts +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartClearDtr( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API can be used to set break timeout value . + + Description + This API can be used to set break timeout value . + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not UART. + + See Also + * CyUartSetFlowControl +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartSetBreak( + CY_HANDLE handle, /*Valid device handle*/ + UINT16 timeout /*Break timeout value in milliseconds */ + ); + +/***********************************************************************************************/ +/**********************************I2C API's****************************************************/ +/***********************************************************************************************/ + +/*@@I2C API + + These set of APIs provide an interface to configure I2C module and do + read/write on the I2C device connected to USB Serial device. +*/ + +/* + Summary + This API retrieves the configuration of I2C module of USB Serial device. + + Description + This API retrieves the configuration of I2C module of USB Serial device. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not I2C. + + See Also + * CY_I2C_CONFIG + * CySetI2cConfig +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetI2cConfig ( + CY_HANDLE handle, /*Valid device handle*/ + CY_I2C_CONFIG *i2cConfig /*I2C configuration value read back*/ + ); + +/* + Summary + This API configures the I2C module of USB Serial device. + + Description + This API configures the I2C module of USB Serial device. + + Note: Using this API during an active transaction of I2C may result in data loss. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not I2C. + + See Also + * CY_I2C_CONFIG + * CySetI2cConfig +*/ +CYWINEXPORT CY_RETURN_STATUS CySetI2cConfig ( + CY_HANDLE handle, /*Valid device handle*/ + CY_I2C_CONFIG *i2cConfig /*I2C configuration value*/ + ); + +/* + Summary + This API reads data from the USB Serial I2C module. + + Description + This API provides an interface to read data from the I2C device + connected to USB Serial. + + The readBuffer parameter needs to be initialized with buffer pointer, number of bytes to be read + before invoking the API. On return, the transferCount field will contain the number of bytes + read back from device. + CY_I2C_DATA_CONFIG structure specifies parameters such as setting stop bit, NAK and + slave address of the I2C device. + + Return Value + * CY_SUCCESS on success. + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if input parameters were invalid. + * CY_ERROR_REQUEST_FAILED if the device type is not I2C + * CY_ERROR_IO_TIMEOUT if transfer was timed out. + * CY_ERROR_DEVICE_NOT_FOUND if device was disconnected. + * CY_ERROR_BUFFER_OVERFLOW if data received from USB Serial device is more than requested. + * CY_ERROR_ALLOCATION_FAILED if transaction transmit buffer allocation was failed (Only in Windows). + * CY_ERROR_I2C_DEVICE_BUSY if I2C device was busy processing previous request. + * CY_ERROR_I2C_NAK_ERROR if request was nacked by I2C device. + * CY_ERROR_I2C_ARBITRATION_ERROR if a I2C bus arbitration error occured. + * CY_ERROR_I2C_BUS_ERROR if there was any I2C bus error while an on going transaction. + * CY_ERROR_I2C_STOP_BIT_SET if stop bit was set by I2C master. + + See Also + * CY_DATA_BUFFER + * CY_DATA_CONFIG + * CyI2cCWrite +*/ +CYWINEXPORT CY_RETURN_STATUS CyI2cRead ( + CY_HANDLE handle, /*Valid device handle*/ + CY_I2C_DATA_CONFIG *dataConfig, /*I2C data config*/ + CY_DATA_BUFFER *readBuffer, /*Read buffer details*/ + UINT32 timeout /*API timeout value*/ + ); + +/* + Summary + This API writes data to USB Serial I2C module . + + Description + This API provides an interface to write data to the I2C device + connected to USB Serial. + The writeBuffer parameter needs to be initialized with buffer pointer, number of bytes to be written + before invoking the API. On return, transferCount field contains number of bytes actually written to the device. + CY_I2C_DATA_CONFIG structure specifies parameter such as setting stop bit, Nak and slave address + of the I2C device being communicated when USB Serial is master. + + Return Value + * CY_SUCCESS on success. + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if input parameters were invalid. + * CY_ERROR_REQUEST_FAILED if the device type is not I2C + * CY_ERROR_IO_TIMEOUT if transfer was timed out. + * CY_ERROR_PIPE_HALTED if pipe was stalled during data transfer. + * CY_ERROR_DEVICE_NOT_FOUND if device was disconnected. + * CY_ERROR_BUFFER_OVERFLOW if data received from USB Serial device is more than requested. + * CY_ERROR_ALLOCATION_FAILED if transaction transmit buffer allocation was failed (Only in Windows). + * CY_ERROR_I2C_DEVICE_BUSY if I2C device was busy processing previous request. + * CY_ERROR_I2C_NAK_ERROR if request was nacked by I2C device. + * CY_ERROR_I2C_ARBITRATION_ERROR if a I2C bus arbitration error occured. + * CY_ERROR_I2C_BUS_ERROR if there was any I2C bus error while an on going transaction. + * CY_ERROR_I2C_STOP_BIT_SET if stop bit was set by I2C master. + + See Also + * CY_DATA_BUFFER + * CY_DATA_CONFIG + * CyI2cRead +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyI2cWrite ( + CY_HANDLE handle, /*Valid device handle*/ + CY_I2C_DATA_CONFIG *dataConfig, /*I2C Slave address */ + CY_DATA_BUFFER *writeBuffer, /*Write buffer details*/ + UINT32 timeout /*API timeout value*/ + ); + +/* + Summary + This API resets the I2C module in USB Serial device. + + Description + This API resets the I2C module whenever there is an error in data transaction. + + If resetMode = 0 the I2C read module will be reset. + If resetMode = 1 the I2C write module will be reset. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not I2C. + + See Also + * CyI2CRead + * CyI2CWrite +*/ +CYWINEXPORT CY_RETURN_STATUS CyI2cReset( + CY_HANDLE handle, /*Valid device handle*/ + BOOL resetMode /*Reset mode*/ + ); + +/***********************************************************************************************/ +/**********************************SPI APIs****************************************************/ +/***********************************************************************************************/ + +/*@@SPI API + These set of APIs provide an interface to configure SPI module and perform + read/write operations with the SPI device connected to USB Serial device. +*/ + +/* + Summary + This API retrieves the configuration of SPI module of USB Serial device. + + Description + This API retrieves the configuration of SPI module of USB Serial device. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not SPI. + + See Also + * CY_SPI_CONFIG + * CySetSpiConfig +*/ +CYWINEXPORT CY_RETURN_STATUS CyGetSpiConfig ( + CY_HANDLE handle, /*Valid device handle*/ + CY_SPI_CONFIG *spiConfig /*SPI configuration structure value read back*/ + ); + +/* + Summary + This API sets the configuration of the SPI module on USB Serial device. + + Description; + This API sets the configuration of the SPI module in USB Serial device. + + NOTE: Using this API during an active transaction of SPI may result in data loss. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if the request is timed out. + * CY_ERROR_REQUEST_FAILED when request is failed by USB Serial device or when device type is + not SPI. + + See Also + * CY_SPI_CONFIG + * CyGetSpiConfig +*/ +CYWINEXPORT CY_RETURN_STATUS CySetSpiConfig ( + CY_HANDLE handle, /*Valid device handle*/ + CY_SPI_CONFIG *spiConfig /*SPI configuration structure value*/ + ); + +/* + Summary + This API reads and writes data to SPI device connected to USB Serial device. + + Description + This API provides an interface to do data transfer with the SPI slave/master + connected to USB Serial device. + To perform read only operation, pass NULL as argument for writeBuffer and to perform + write only operation pass NULL as an argument for readBuffer. + On return, the transferCount field will contain the number of bytes read and/or written. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid in case of Linux/Mac. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_REQUEST_FAILED if the device type is not SPI or when libusb reported + unknown error in case of Linux/Mac. + * CY_ERROR_IO_TIMEOUT if transfer was timed out. + * CY_ERROR_PIPE_HALTED if pipe was stalled during data transfer. + * CY_ERROR_DEVICE_NOT_FOUND if device was disconnected. + * CY_ERROR_BUFFER_OVERFLOW if data received from USB Serial device is more than requested. + + See Also + * CY_DATA_BUFFER + * CyGetSpiConfig + * CySetSpiConfig +*/ +CYWINEXPORT CY_RETURN_STATUS CySpiReadWrite ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER* readBuffer, /*Read data buffer*/ + CY_DATA_BUFFER* writeBuffer, /*Write data buffer*/ + UINT32 timeout /*Time out value of the API*/ + ); + +/**************************************************************************************/ +/*****************************************JTAG APIs***********************************/ +/**************************************************************************************/ + +/*@@JTAG API + These set of APIs can be used to enable or disable JTAG module on the USB Serial device. + Once the JTAG is enabled, read and write operations can be performed. + When JTAG is enabled other modules in the USB Serial device cannot be used. +*/ + +/* + Summary + This API enables JTAG module. + + Description + This API enables JTAG module in USB Serial device and the function disables all other functionality + till CyJtagDisable is invoked. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid in case of Linux/Mac. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if request was timed out. + * CY_ERROR_REQUEST_FAILED if request was failed by device or if device type + is not JTAG. + + See Also + * CyJtagDisable +*/ +CYWINEXPORT CY_RETURN_STATUS CyJtagEnable ( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API disables JTAG module. + + Description + This API disables Jtag interface in USB Serial device. This API must be invoked before exiting the + application if CyJtagEnable was previously invoked. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid in case of Linux/Mac. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_IO_TIMEOUT if request was timed out. + * CY_ERROR_REQUEST_FAILED if request was failed by device or if device type + is not JTAG. + + See Also + * CyJtagEnable +*/ +CYWINEXPORT CY_RETURN_STATUS CyJtagDisable ( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API can be used to write data to JTAG module. + + Description + This API provides an interface to write data to JTAG device connected to USB Serial device. + The writeBuffer need to be initialized with buffer and length of data to be written before invoking + the API. Upon return, transferCount field in CY_DATA_BUFFER is updated with actual number of bytes written. + + Note: CyJtagEnable must be called before invoking this API. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid in case of Linux/Mac. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_REQUEST_FAILED if device type is not JTAG or when encountered + unknown libusb errors in Linux/Mac. + * CY_ERROR_PIPE_HALTED if there was any pipe error during transaction. + * CY_ERROR_IO_TIMEOUT if transfer was timed out. + * CY_ERROR_DEVICE_NOT_FOUND if device was disconnected. + + See Also + * CY_DATA_BUFFER + * CyJtagRead + * CyJtagEnable +*/ +CYWINEXPORT CY_RETURN_STATUS CyJtagWrite ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER *writeBuffer, /*Write buffer details*/ + UINT32 timeout /*API timeout value*/ + ); + +/* + Summary + This API reads data from JTAG device. + + Description + This API provides an interface to read data from JTAG device. + The readBuffer need to be initialized with buffer and length of data to be written before invoking + the API. Upon return, transferCount field in CY_DATA_BUFFER structure + is updated with actual number of bytes read. + + Note: CyJtagEnable must be called before invoking this API. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle is invalid in case of Linux/Mac. + * CY_ERROR_INVALID_PARAMETER if specified parameters are invalid or out of range. + * CY_ERROR_REQUEST_FAILED if device type is not JTAG or when encountered + unknown libusb errors in Linux/Mac. + * CY_ERROR_IO_TIMEOUT if transfer was timed out. + * CY_ERROR_DEVICE_NOT_FOUND if device was disconnected. + * CY_ERROR_BUFFER_OVERFLOW if data received from USB Serial device is more than requested. + + See Also + * CY_DATA_BUFFER + * CyJtagWrite + * CyJtagEnable +*/ +CYWINEXPORT CY_RETURN_STATUS CyJtagRead ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER *readBuffer, /*Read buffer parameters*/ + UINT32 timeout /*API timeout value*/ + ); + +/**************************************************************************************/ +/*****************************************PHDC APIs***********************************/ +/**************************************************************************************/ + +/*@@PHDC API + Set of PHDC class request APIs. The PHDC class requests include set, clear feature and + PHDC get status. +*/ + +/* + Summary + This API sends a PHDC clear feature command. + + Description + This API sends a PHDC clear feature command. + + Note: Meta data feature is not supported by USB Serial device. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle was invalid. + * CY_ERROR_IO_TIMEOUT if request timed out. + * CY_ERROR_REQUEST_FAILED if request was failed by device. + + See Also + * CyPhdcSetFeature + * CyPhdcGetStatus +*/ +CYWINEXPORT CY_RETURN_STATUS CyPhdcClrFeature ( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API sends a PHDC set feature command. + + Description + This API sends a PHDC set feature command. + + Note: Meta data feature is not supported by USB Serial device. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle was invalid. + * CY_ERROR_IO_TIMEOUT if request timed out. + * CY_ERROR_REQUEST_FAILED if request was failed by device. + + See Also + * CyPhdcClrFeature + * CyPhdcGetStatus +*/ +CYWINEXPORT CY_RETURN_STATUS CyPhdcSetFeature ( + CY_HANDLE handle /*Valid device handle*/ + ); + +/* + Summary + This API retrieves the endpoint status of PHDC transaction. + + Description + The API retrieves the status of PHDC transaction. It returns 2 bytes of data pending bit map + which is defined as per PHDC spec. + + Return Value + * CY_SUCCESS on success + * CY_ERROR_INVALID_HANDLE if handle was invalid. + * CY_ERROR_IO_TIMEOUT if request timed out. + * CY_ERROR_REQUEST_FAILED if request was failed by device. + + See Also + * CyPhdcClrFeature + * CyPhdcSetFeature +*/ +CYWINEXPORT CY_RETURN_STATUS CyPhdcGetStatus ( + CY_HANDLE handle, /*Valid device handle*/ + UINT16 *dataStatus /*Data pending status bit map*/ + ); + +#endif /*_INCLUDED_Cypress USB Serial_H_*/ diff --git a/cylib/COPYING.LESSER.txt b/configutility/license/license.txt similarity index 97% rename from cylib/COPYING.LESSER.txt rename to configutility/license/license.txt index 4362b49..5faba9d 100644 --- a/cylib/COPYING.LESSER.txt +++ b/configutility/license/license.txt @@ -1,502 +1,504 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/configutility/linux/library/90-cyusb.rules b/configutility/linux/library/90-cyusb.rules new file mode 100644 index 0000000..21cbba2 --- /dev/null +++ b/configutility/linux/library/90-cyusb.rules @@ -0,0 +1,5 @@ +# Cypress USB driver for FX2 and FX3 (C) Cypress Semiconductor Corporation / ATR-LABS +# Rules written by V. Radhakrishnan ( rk@atr-labs.com ) +# Cypress USB vendor ID = 0x04b4 +KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="add", ATTR{idVendor}=="04b4", MODE="666" +KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="remove", TAG=="cyusb_dev" diff --git a/configutility/linux/library/CyUSBCommon.h b/configutility/linux/library/CyUSBCommon.h new file mode 100644 index 0000000..211b632 --- /dev/null +++ b/configutility/linux/library/CyUSBCommon.h @@ -0,0 +1,219 @@ +/* + * Common header file of Cypress USB Serial + * Copyright (C) 2013 Cypress Semiconductor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../common/header/CyUSBSerial.h" +#pragma pack(1) +typedef struct CY_DEVICE { + + unsigned char inEndpoint; + unsigned char outEndpoint; + unsigned char interruptEndpoint; + unsigned char interfaceNum; + bool i2cCancelEvent; + bool spiCancelEvent; + bool uartCancelEvent; + bool rtsValue; + bool dtrValue; + unsigned short numEndpoints; + CY_FLOW_CONTROL_MODES uartFlowControlMode; + struct libusb_transfer *spiTransfer; + struct libusb_transfer *uartTransfer; + libusb_device_handle *devHandle; + pthread_t spiThreadId; + pthread_t uartThreadId; + pthread_mutex_t readLock; + pthread_mutex_t writeLock; + pthread_mutex_t notificationLock; + CY_DEVICE_TYPE deviceType; + +}CY_DEVICE,*PCY_DEVICE; +#pragma pack() + +CY_RETURN_STATUS CyResetPipe (CY_HANDLE handl, UINT8); +#define CY_DEBUG_PRINT_INFO(...) //User need to enable this +#define CY_DEBUG_PRINT_ERROR(...) //printf +#define DUMP_DATA 1 +#ifdef DUMP_DATA +#define CY_DUMP_DATA(INPUT,LEN)\ +{\ + int i = 0, len = LEN;\ + while ((len)) {\ + printf ("%x ", (INPUT)[i++]);\ + len--;\ + }\ + printf ("\n");\ +} +#else +#define CY_DUMP_DATA (INPUT, LEN) do { }while (0); +#endif +#define CY_USB_SERIAL_TIMEOUT 5000 +#define CY_EVENT_NOTIFICATION_TIMEOUT 0 //This will make the transfer infinite + +#define CY_VENDOR_REQUEST_DEVICE_TO_HOST 0xC0 +#define CY_VENDOR_REQUEST_HOST_TO_DEVICE 0x40 + +#define CY_CLASS_INTERFACE_REQUEST_DEVICE_TO_HOST 0XA1 +#define CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE 0x21 +//I2C related macros +#define CY_SCB_INDEX_POS 15 +#define CY_I2C_CONFIG_LENGTH 16 +#define CY_I2C_WRITE_COMMAND_POS 3 +#define CY_I2C_WRITE_COMMAND_LEN_POS 4 +#define CY_I2C_GET_STATUS_LEN 3 +#define CY_I2C_MODE_WRITE 1 +#define CY_I2C_MODE_READ 0 +#define CY_I2C_ERROR_BIT (1) +#define CY_I2C_ARBITRATION_ERROR_BIT (1 << 1) +#define CY_I2C_NAK_ERROR_BIT (1 << 2) +#define CY_I2C_BUS_ERROR_BIT (1 << 3) +#define CY_I2C_STOP_BIT_ERROR (1 << 4) +#define CY_I2C_BUS_BUSY_ERROR (1 << 5) +#define CY_I2C_ENABLE_PRECISE_TIMING 1 +#define CY_I2C_EVENT_NOTIFICATION_LEN 3 +//SPI related Macros +#define CY_SPI_CONFIG_LEN 16 +#define CY_SPI_EVENT_NOTIFICATION_LEN 2 +#define CY_SPI_READ_BIT (1) +#define CY_SPI_WRITE_BIT (1 << 1) +#define CY_SPI_SCB_INDEX_BIT (1 << 15) +#define CY_SPI_GET_STATUS_LEN 4 +#define CY_SPI_UNDERFLOW_ERROR (1) +#define CY_SPI_BUS_ERROR (1 << 1) +//Vendor UART related macros +#define CY_UART_SET_FLOW_CONTROL_CMD 0x60 +#define CY_UART_SEND_BREAK_CMD 0x17 +#define CY_UART_CONFIG_LEN 16 +#define CY_SET_LINE_CONTROL_STATE_CMD 0x22 +#define CY_UART_EVENT_NOTIFICATION_LEN 10 + +#define CY_UART_SERIAL_STATE_CARRIER_DETECT 1 +#define CY_UART_SERIAL_STATE_TRANSMISSION_CARRIER (1 << 1) +#define CY_UART_SERIAL_STATE_BREAK_DETECTION (1<< 2) +#define CY_UART_SERIAL_STATE_RING_SIGNAL_DETECTION (1 << 3) +#define CY_UART_SERIAL_STATE_FRAMING_ERROR (1 << 4) +#define CY_UART_SERIAL_STATE_PARITY_ERROR (1 << 5) +#define CY_UART_SERIAL_STATUE_OVERRUN (1 << 6) +//Bootloader related macros +#define CY_BOOT_CONFIG_SIZE 64 +#define CY_DEVICE_CONFIG_SIZE 512 +#define CY_FIRMWARE_BREAKUP_SIZE 4096 +#define CY_GET_SILICON_ID_LEN 4 +#define CY_GET_FIRMWARE_VERSION_LEN 8 +#define CY_GET_SIGNATURE_LEN 4 +//PHDC related macros +#define CY_PHDC_SET_FEATURE 0X03 +#define CY_PHDC_CLR_FEATURE 0X01 +#define CY_PHDC_GET_DATA_STATUS 0x00 + +typedef enum CY_VENDOR_CMDS +{ + CY_GET_VERSION_CMD = 0xB0, /* Get the version of the boot-loader. + value = 0, index = 0, length = 4; + data_in = 32 bit version. */ + + CY_GET_SIGNATURE_CMD = 0xBD, /*Get the signature of the firmware + It is suppose to be 'CYUS' for normal firmware + and 'CYBL' for Bootloader.*/ + CY_UART_GET_CONFIG_CMD = 0xC0, /* Retreive the 16 byte UART configuration information. + MS bit of value indicates the SCB index. + length = 16, data_in = 16 byte configuration. */ + CY_UART_SET_CONFIG_CMD, /* Update the 16 byte UART configuration information. + MS bit of value indicates the SCB index. + length = 16, data_out = 16 byte configuration information. */ + CY_SPI_GET_CONFIG_CMD, /* Retreive the 16 byte SPI configuration information. + MS bit of value indicates the SCB index. + length = 16, data_in = 16 byte configuration. */ + CY_SPI_SET_CONFIG_CMD, /* Update the 16 byte SPI configuration information. + MS bit of value indicates the SCB index. + length = 16, data_out = 16 byte configuration information. */ + CY_I2C_GET_CONFIG_CMD, /* Retreive the 16 byte I2C configuration information. + MS bit of value indicates the SCB index. + length = 16, data_in = 16 byte configuration. */ + CY_I2C_SET_CONFIG_CMD = 0xC5, /* Update the 16 byte I2C configuration information. + MS bit of value indicates the SCB index. + length = 16, data_out = 16 byte configuration information. */ + CY_I2C_WRITE_CMD, /* Perform I2C write operation. + value = bit0 - start, bit1 - stop, bit3 - start on idle, + bits[14:8] - slave address, bit15 - scbIndex. length = 0. The + data is provided over the bulk endpoints. */ + CY_I2C_READ_CMD, /* Perform I2C read operation. + value = bit0 - start, bit1 - stop, bit2 - Nak last byte, + bit3 - start on idle, bits[14:8] - slave address, bit15 - scbIndex, + length = 0. The data is provided over the bulk endpoints. */ + CY_I2C_GET_STATUS_CMD, /* Retreive the I2C bus status. + value = bit0 - 0: TX 1: RX, bit15 - scbIndex, length = 3, + data_in = byte0: bit0 - flag, bit1 - bus_state, bit2 - SDA state, + bit3 - TX underflow, bit4 - arbitration error, bit5 - NAK + bit6 - bus error, + byte[2:1] Data count remaining. */ + CY_I2C_RESET_CMD, /* The command cleans up the I2C state machine and frees the bus. + value = bit0 - 0: TX path, 1: RX path; bit15 - scbIndex, + length = 0. */ + CY_SPI_READ_WRITE_CMD = 0xCA, /* The command starts a read / write operation at SPI. + value = bit 0 - RX enable, bit 1 - TX enable, bit 15 - scbIndex; + index = length of transfer. */ + CY_SPI_RESET_CMD, /* The command resets the SPI pipes and allows it to receive new + request. + value = bit 15 - scbIndex */ + CY_SPI_GET_STATUS_CMD, /* The command returns the current transfer status. The count will match + the TX pipe status at SPI end. For completion of read, read all data + at the USB end signifies the end of transfer. + value = bit 15 - scbIndex */ + CY_JTAG_ENABLE_CMD = 0xD0, /* Enable JTAG module */ + CY_JTAG_DISABLE_CMD, /* Disable JTAG module */ + CY_JTAG_READ_CMD, /* JTAG read vendor command */ + CY_JTAG_WRITE_CMD, /* JTAG write vendor command */ + CY_GPIO_GET_CONFIG_CMD = 0xD8, /* Get the GPIO configuration: */ + CY_GPIO_SET_CONFIG_CMD, /* Set the GPIO configuration */ + CY_GPIO_GET_VALUE_CMD, /* Get GPIO value: */ + CY_GPIO_SET_VALUE_CMD, /* Set the GPIO value:*/ + CY_PROG_USER_FLASH_CMD = 0xE0, /*Program user flash area. The total space available is 512 bytes. + This can be accessed by the user from USB. The flash area + address offset is from 0x0000 to 0x00200 and can be written to + page wise (128 byte).*/ + CY_READ_USER_FLASH_CMD, /*Read user flash area. The total space available is 512 bytes. + This can be accessed by the user from USB. The flash area + address offset is from 0x0000 to 0x00200 and can be written to + page wise (128 byte).*/ + CY_DEVICE_RESET_CMD = 0xE3, /*Performs a device reset from firmware*/ + +} CY_VENDOR_CMDS; + +//JTAG related Macros +#define CY_JTAG_OUT_EP 0x04 +#define CY_JTAG_IN_EP 0x85 + +//GPIO related Macros +#define CY_GPIO_GET_LEN 2 +#define CY_GPIO_SET_LEN 1 + +//PHDC related macros +#define CY_PHDC_GET_STATUS_LEN 2 +#define CY_PHDC_CLR_FEATURE_WVALUE 0x1 +#define CY_PHDC_SET_FEATURE_WVALUE 0x0101 + diff --git a/configutility/linux/library/Makefile b/configutility/linux/library/Makefile new file mode 100644 index 0000000..4e67473 --- /dev/null +++ b/configutility/linux/library/Makefile @@ -0,0 +1,20 @@ +all: + gcc -fPIC -g -Wall -o libcyusb.o -c cyusb.c -I ../../common/header + gcc -fPIC -g -Wall -o libcyuart.o -c cyuart.c -I ../../common/header + gcc -fPIC -g -Wall -o libcyi2c.o -c cyi2c.c -I ../../common/header + gcc -fPIC -g -Wall -o libcyspi.o -c cyspi.c -I ../../common/header + gcc -fPIC -g -Wall -o libcyphdc.o -c cyphdc.c -I ../../common/header + gcc -fPIC -g -Wall -o libcyjtag.o -c cyjtag.c -I ../../common/header + gcc -fPIC -g -Wall -o libcymisc.o -c cymisc.c -I ../../common/header + gcc -fPIC -g -Wall -o libcyboot.o -c cyboot.c -I ../../common/header + + gcc -shared -g -Wl,-soname,libcyusbserial.so -o libcyusbserial.so.1 libcyusb.o libcyuart.o libcyi2c.o libcyspi.o libcyphdc.o libcyjtag.o libcymisc.o libcyboot.o -l usb-1.0 + cp libcyusbserial.so.1 /usr/local/lib + ln -sf /usr/local/lib/libcyusbserial.so.1 /usr/local/lib/libcyusbserial.so + ldconfig + rm -f libcyusb.o libcyuart.o libcyspi.o libcyi2c.o libcyphdc.o libcyjtag.o libcymisc.o libcyboot.o +clean: + rm -f libcyusbserial.so libcyusbserial.so.1 +help: + @echo 'make would compile and create the library and create a link' + @echo 'make clean would remove the library and the soft link to the library (soname)' diff --git a/configutility/linux/library/cyboot.c b/configutility/linux/library/cyboot.c new file mode 100644 index 0000000..d8e2bd0 --- /dev/null +++ b/configutility/linux/library/cyboot.c @@ -0,0 +1,668 @@ +#include "CyUSBCommon.h" +#include "CyUSBBootloader.h" +/* + CyReadFlash will read the content of flash from the + specified address + */ + +UINT32 fmVersion; +UINT32 fmChecksum; +UINT32 firmwareSize = 0; +UINT32 firmwareEntry; +UINT32 firmwareStart; +typedef enum CY_BOOT_VENDOR_CMDS +{ + CY_CMD_GET_VERSION = 0xB0, /* Get the version of the boot-loader. + value = 0, index = 0, length = 4; + data_in = 32 bit version. */ + CY_BOOT_CMD_GET_SILICON_ID= 0xB1, /* Get the silicon ID for the device. + value = 0, index = 0, length = 4; + data_in = 32 bit silicon id. */ + CY_BOOT_CMD_READ_FLASH, /* Read flash content: + value = MS word of address, + index = LS word of address(4 byte aligned), + length = length of read (4 byte multiple); + data_in = requested data from flash. */ + CY_BOOT_CMD_PROG_FLASH, /* Program data into flash: + value = MS word of address, + index = LS word of address(128 byte aligned), + length = length of write (128 byte multiple); + data_out = data to be written to flash. */ + CY_BOOT_CMD_RESERVED_0, /* Reserved*/ + CY_BOOT_CMD_READ_CONFIG = 0xB5, /* Read the device configuration table: + value = 0, index = 0, length = 512; + data_in = device configuration table. */ + CY_BOOT_CMD_PROG_CONFIG = 0xB6, /* Program the device configuration table: + value = 0, index = 0, length = 512; + data_out = device configuration table. */ + CY_BOOT_CMD_READ_BOOT_CONFIG, /* Read the boot-loader configuration table; + value = 0, index = 0, length = 256; + data_in = boot-loader configuration table. */ + CY_BOOT_CMD_PROG_BOOT_CONFIG, /* Program the boot-loader configuration table; + value = 0, index = 0, length = 256; + data_out = boot-loader configuration table. */ + CY_BOOT_CMD_RESERVED_1, /* RESERVED */ + CY_BOOT_CMD_VALIDATE_CHECKSUM = 0xBA,/* Calculate checksum and compare against the + content of the device configuration table. */ + CY_BOOT_CMD_READ_MEM, /* Read from the SRAM memory: + index = LS word of address(4 byte aligned), + length = length of read (4 byte multiple); + data_in = requested data from SRAM. */ + CY_BOOT_CMD_WRITE_MEM, /* Program data into SRAM memory: + value = MS word of address, + index = LS word of address(4 byte aligned), + length = length of write (4 byte multiple); + data_out = data to be written to SRAM. */ + CY_VENDOR_GET_SIGNATURE, /*Get the signature of the firmware + It is suppose to be 'CYUS' for normal firmware + and 'CYBL' for Bootloader.*/ + CY_BOOT_CMD_MFG_JUMP, /*Jump to bootloader mode*/ + + CY_VENDOR_ENTER_MFG_MODE = 0xE2 /* Enter the configuration mode. This needs to be invoked to enter + the manufacturing mode. If this is not set, then the device shall + not allow any of the configuration requests (B0 to BF) to go through. + Value = ~"CY" = 0xA6BC, index = ~"OF" = 0xB9B0: for disable, + Value = ~"CY" = 0xA6BC, ~"ON" = 0xB1B0: for enable, + Length = 0. */ + +} CY_BOOT_VENDOR_CMDS; + +#define CY_DEVICE_CONFIG_SIZE 512 +#define CY_GET_SILICON_ID_LEN 4 +#define CY_USB_SERIAL_TIMEOUT 0 + +CY_RETURN_STATUS CyReadFlash ( + CY_HANDLE handle, + PCY_BOOTLD_BUFFER readBuffer, + UINT32 ioTimeout + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (readBuffer == NULL || readBuffer->buffer == NULL || readBuffer->length == 0) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_BOOT_CMD_READ_FLASH; + wValue = ((readBuffer->address & 0xFFFF0000 ) >> 16); + wIndex = (readBuffer->address & 0x0000FFFF ); + + wLength = (readBuffer->length); + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, readBuffer->buffer, wLength, ioTimeout); + if (rStatus > 0){ + *(readBuffer->bytesReturned) = rStatus; + CY_DEBUG_PRINT_ERROR ("CY:The Length is %d\n", rStatus); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Device Timed out.. \n"); + *(readBuffer->bytesReturned) = 0; + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error in process the request.. libusb error is %d \n", rStatus); + *(readBuffer->bytesReturned) = 0; + return CY_ERROR_REQUEST_FAILED; + } +} +/* + CyProgFlash will write the content of flash from the + specified address + */ +CY_RETURN_STATUS CyProgFlash ( + CY_HANDLE handle, + PCY_BOOTLD_BUFFER writeBuffer, + UINT32 ioTimeout + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (writeBuffer == NULL || writeBuffer->buffer == NULL || writeBuffer->length == 0) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_BOOT_CMD_PROG_FLASH; + wValue = ((writeBuffer->address & 0xFFFF0000 ) >> 16); + wIndex = (writeBuffer->address & 0x0000FFFF ); + + wLength = (writeBuffer->length); + CY_DEBUG_PRINT_INFO ("CY:The Length is %d , Value is %d and index is %d\n", wLength, wValue, wIndex); + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, writeBuffer->buffer, wLength, ioTimeout); + if (rStatus > 0){ + *(writeBuffer->bytesReturned) = rStatus; + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Device Timed out.. \n"); + *(writeBuffer->bytesReturned) = 0; + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error in process the request..libusb error is %d \n", rStatus); + *(writeBuffer->bytesReturned) = 0; + return CY_ERROR_REQUEST_FAILED; + } +} +/* CyReadMemory will read the content of SRAM from the + specified address + */ +CY_RETURN_STATUS CyReadMemory ( + CY_HANDLE handle, + PCY_BOOTLD_BUFFER readBuffer, + UINT32 ioTimeout + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (readBuffer == NULL || readBuffer->buffer == NULL || readBuffer->length == 0) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_BOOT_CMD_READ_MEM; + wValue = ((readBuffer->address & 0xFFFF0000 ) >> 16); + wIndex = (readBuffer->address & 0x0000FFFF ); + wLength = (readBuffer->length); + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, readBuffer->buffer, wLength, ioTimeout); + if (rStatus > 0){ + *(readBuffer->bytesReturned) = rStatus; + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Device Timed out.. \n"); + *(readBuffer->bytesReturned) = 0; + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error in processing the request.. libusb error is %d \n", rStatus); + *(readBuffer->bytesReturned) = 0; + return CY_ERROR_REQUEST_FAILED; + } +} +/* + CyWriteMemory will write the content to specified address + in SRAM + */ +CY_RETURN_STATUS CyWriteMemory ( + CY_HANDLE handle, + PCY_BOOTLD_BUFFER writeBuffer, + UINT32 ioTimeout + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (writeBuffer == NULL || writeBuffer->buffer == NULL || writeBuffer->length == 0) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_BOOT_CMD_WRITE_MEM; + wValue = ((writeBuffer->address & 0xFFFF0000 ) >> 16); + wIndex = (writeBuffer->address & 0x0000FFFF ); + wLength = (writeBuffer->length); + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, writeBuffer->buffer, wLength, ioTimeout); + if (rStatus > 0){ + *(writeBuffer->bytesReturned) = rStatus; + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Device Timed out.. \n"); + *(writeBuffer->bytesReturned) = 0; + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error in process the request..libusb error is %d \n", rStatus); + *(writeBuffer->bytesReturned) = 0; + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This function will update the checksum value in device configuration table. + */ +CY_RETURN_STATUS CyValidateChecksum ( + CY_HANDLE handle + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_BOOT_CMD_VALIDATE_CHECKSUM; + wValue = 0x00; + wIndex = 0x00; + wLength = 0; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus >= 0){ + return CY_SUCCESS; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Validate Checksum Failed..libusb error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + CyReadBootConfig will read the entire boot configuration table + */ +CY_RETURN_STATUS CyReadBootConfig ( + CY_HANDLE handle, + UINT8 *bootConfig + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (bootConfig == NULL) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_BOOT_CMD_READ_BOOT_CONFIG; + wValue = 0x00; + wIndex = 0x00; + wLength = CY_BOOT_CONFIG_SIZE; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, bootConfig, wLength, ioTimeout); + if (rStatus == CY_BOOT_CONFIG_SIZE){ + CY_DEBUG_PRINT_INFO ("CY:Successfully read Boot loader configuration ... \n"); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY: There was a Time out error in Reading Boot config .. \n"); + return CY_ERROR_IO_TIMEOUT; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY: There was an error in Reading Boot config... libusb error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + CyWriteBootConfig will write the entire boot configuration table + */ +CY_RETURN_STATUS CyWriteBootConfig ( + CY_HANDLE handle, + UINT8 *bootConfig + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (bootConfig == NULL) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_BOOT_CMD_PROG_BOOT_CONFIG; + wValue = 0x00; + wIndex = 0x00; + wLength = CY_BOOT_CONFIG_SIZE; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, bootConfig, wLength, ioTimeout); + + if (rStatus == CY_BOOT_CONFIG_SIZE){ + CY_DEBUG_PRINT_INFO ("CY:Successfully wrote boot configuration \n"); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY: There was a Time out error in Writing Boot config .. \n"); + return CY_ERROR_IO_TIMEOUT; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY: There was an error in Writing Boot config ..libusb error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This Api will download the firmware on to Cy USB serial device + */ +CY_RETURN_STATUS CyDownloadFirmware ( + CY_HANDLE handle, + CHAR *filePath + ) +{ + UINT32 fd, bytesRead, totalLength, bytesRemaining, ioTimeout = CY_USB_SERIAL_TIMEOUT, rStatus; + UINT32 address, *tempAdd; + UINT32 checkStart = 0; + UCHAR buffer[CY_FIRMWARE_BREAKUP_SIZE]; + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (filePath == NULL) + return CY_ERROR_INVALID_PARAMETER; + fd = open (filePath, O_RDONLY); + if (fd < 0){ + CY_DEBUG_PRINT_ERROR ("CY:Error in Opening the File ... \n"); + return CY_ERROR_DOWNLOAD_FAILED; + } + bytesRead = read (fd, buffer, 4); + if (bytesRead != 4){ + CY_DEBUG_PRINT_ERROR ("CY: Error in Read Length ... \n"); + close (fd); + return CY_ERROR_INVALID_FIRMWARE; + } + if (strncmp ((char*)buffer, "CYUS", 4)){ + CY_DEBUG_PRINT_ERROR ("CY:Not a valid image,no valid signature .... \n"); + close (fd); + return CY_ERROR_FIRMWARE_INVALID_SIGNATURE; + } + // Read off the Version before reading the length of the section + bytesRead = read (fd, buffer, 4); + if (bytesRead != 4){ + CY_DEBUG_PRINT_ERROR ("CY: Error in Reading firmware version... \n"); + close (fd); + return CY_ERROR_INVALID_FIRMWARE; + } + tempAdd = (UINT32 *)buffer; + fmVersion = *tempAdd; + CY_DEBUG_PRINT_ERROR ("CY:The firmware version is %d \n", fmVersion); + while (1){ + bytesRead = read (fd, buffer, 4); + if (bytesRead != 4){ + CY_DEBUG_PRINT_ERROR ("CY: Error in reading firmware Length ... \n"); + close (fd); + return CY_ERROR_DOWNLOAD_FAILED;; + + } + tempAdd = (UINT32 *)buffer; + totalLength = (totalLength * 4); + firmwareSize = firmwareSize + totalLength; + bytesRead = read(fd, buffer, 4); + if (bytesRead != 4){ + CY_DEBUG_PRINT_ERROR ("CY: Error in reading Address ... \n"); + close (fd); + return CY_ERROR_DOWNLOAD_FAILED; + } + tempAdd = (UINT32 *)buffer; + address = *tempAdd; + bytesRemaining = totalLength; + if (checkStart == 0){ + // Get the Firmware Start Address so that + // it is updated in the device configuration table + firmwareStart = address; + CY_DEBUG_PRINT_INFO ("CY: The firmware start address is %x \n", firmwareStart); + checkStart++; + } + if (bytesRemaining == 0){ + break; + } + else { + while (bytesRemaining >= CY_FIRMWARE_BREAKUP_SIZE) { + bytesRead = read(fd, buffer, CY_FIRMWARE_BREAKUP_SIZE); + bytesRemaining -= bytesRead; + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_BOOT_CMD_PROG_FLASH; + wIndex = (address & 0x0000FFFF); + wValue = ((address & 0xFFFF0000) >> 16); + wLength = bytesRead; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, buffer, wLength, ioTimeout); + if (rStatus <= LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY: Error in programming device %d... \n", rStatus); + close (fd); + return CY_ERROR_DOWNLOAD_FAILED; + } + else { + CY_DEBUG_PRINT_INFO ("CY:The number of bytes is %d \n",rStatus); + } + address += CY_FIRMWARE_BREAKUP_SIZE; + } + if (bytesRemaining != 0){ + bytesRead = read(fd, buffer, bytesRemaining); + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_BOOT_CMD_PROG_FLASH; + wIndex = (address & 0x0000FFFF); + wValue = ( (address & 0xFFFF0000) >> 16 ); + wLength = bytesRead; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, buffer, wLength, ioTimeout); + if (rStatus <= LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY: Error in programming device %d... \n", rStatus); + close (fd); + return CY_ERROR_DOWNLOAD_FAILED; + } + } + } + } + CY_DEBUG_PRINT_INFO ("Firmware Size is %d \n", firmwareSize); + // Reading firmwareEntry so that it is updated in device configuration + // Table. + firmwareSize = (firmwareSize / 4); + firmwareEntry = address; + CY_DEBUG_PRINT_INFO ("CY: Firmare entry %p ...\n", firmwareEntry); + bytesRead = read (fd,buffer, 4); + tempAdd = (UINT32*)buffer; + // Get the firmware checksum. + fmChecksum = *tempAdd; + CY_DEBUG_PRINT_INFO ("CY:The Checksum value is %x \n",(*tempAdd)); + close (fd); + return CY_SUCCESS; +} +/* + This API is used to Read the Silicon ID + */ +CY_RETURN_STATUS CyGetSiliconID( + CY_HANDLE handle, + UINT32 *siliconID + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (siliconID == NULL) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_BOOT_CMD_GET_SILICON_ID; + wValue = 0x00; + wIndex = 0x00; + wLength = CY_GET_SILICON_ID_LEN; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (UINT8 *)siliconID, wLength, ioTimeout); + + if (rStatus > 0){ + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY: There was a Time out error in Reading SiliconID .. \n"); + return CY_ERROR_IO_TIMEOUT; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY: There was an error doing read of silicon ID..Libusb error is %d\n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This API reads the SCB configurations and can be + used only at the time of manufacturing and programming + the device + */ +CY_RETURN_STATUS CyReadDeviceConfig ( + CY_HANDLE handle, + UINT8 *deviceConfig + ) +{ + + UINT8 bmRequestType, bmRequest; + UINT16 wValue, wIndex, wLength; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 rStatus, timeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (deviceConfig == NULL) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_BOOT_CMD_READ_CONFIG; + wValue = 0x00; + wIndex = 0x00; + wLength = CY_DEVICE_CONFIG_SIZE; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, deviceConfig, wLength, timeout); + if (rStatus == CY_DEVICE_CONFIG_SIZE){ + CY_DEBUG_PRINT_INFO ("CY:Successfully Read the configuration ... \n"); + return CY_SUCCESS; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY:Error in reading Device configuration... Libusb error is %d\n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This Api writes the device configuration on to the device table of CY Usb Serial + It is used only when the device is in bootloader mode and at the time of configuring the + device + */ +CY_RETURN_STATUS CyWriteDeviceConfig ( + CY_HANDLE handle, + UINT8 *deviceConfig + ) +{ + UINT8 bmRequestType, bmRequest; + UINT16 wValue, wIndex, wLength; + UINT32 rStatus, timeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (deviceConfig == NULL) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_BOOT_CMD_PROG_CONFIG; + wValue = 0x00; + wIndex = 0x00; + + wLength = CY_DEVICE_CONFIG_SIZE; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, deviceConfig, wLength, timeout); + if (rStatus == CY_DEVICE_CONFIG_SIZE){ + CY_DEBUG_PRINT_INFO ("CY:Successfully wrote the configuration ... \n"); + return CY_SUCCESS; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY: Error in Writing Device config ... Libusb error is %d\n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* Flash config enable will enable reading/writing on flash*/ +CY_RETURN_STATUS CyFlashConfigEnable ( + CY_HANDLE handle, + BOOL isEnable + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + UINT32 rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (isEnable){ + wValue = 0xA6BC; + wIndex = 0xB1B0; //ON + } + else{ + wValue = 0xA6B6; + wIndex = 0xB9B0; //OFF + } + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_VENDOR_ENTER_MFG_MODE; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, 5000); + if (rStatus >= 0){ + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY: There was a Time out error in Flash config enable .. \n"); + return CY_ERROR_IO_TIMEOUT; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY: There was an error in Flash config enable..Libusb error is %d\n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} + diff --git a/cylib/lib/cyi2c.c b/configutility/linux/library/cyi2c.c similarity index 81% rename from cylib/lib/cyi2c.c rename to configutility/linux/library/cyi2c.c index af6a4eb..10d52fe 100644 --- a/cylib/lib/cyi2c.c +++ b/configutility/linux/library/cyi2c.c @@ -1,686 +1,690 @@ -/* - * I2C routines of Cypress USB Serial - * Copyright (C) 2013 Cypress Semiconductor - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "CyUSBCommon.h" -#pragma pack(1) -typedef struct -{ - UINT32 frequency; /**< Frequency of operation. Only valid values are - 100KHz and 400KHz. */ - UINT8 sAddress; /**< Slave address to be used when in slave mode. */ - BOOL isMsbFirst; /**< Whether to transmit most significant bit first. */ - BOOL isMaster; /**< Whether to block is to be configured as a master: - CyTrue - The block functions as I2C master. - CyFalse - The block functions as I2C slave. */ - BOOL sIgnore; /**< Ignore general call in slave mode. */ - BOOL clockStretch; /**< Wheteher to stretch clock in case of no FIFO availability. */ - BOOL isLoopback; /**< Whether to loop back TX data to RX. Valid only - for debug purposes. */ - UCHAR reserved[6]; /**< Reserved for future use */ -} CyUsI2cConfig_t; -#pragma pack() -#ifdef CY_I2C_ENABLE_PRECISE_TIMING -struct timeval startTimeWrite, endTimeWrite, startTimeRead, endTimeRead; -//Timer helper functions for proper timing -void startI2cTick (bool isWrite) { - if (isWrite) - gettimeofday (&startTimeWrite, NULL); - else - gettimeofday (&startTimeRead, NULL); -} - -UINT32 getI2cLapsedTime (bool isWrite){ - - signed int currentTime_sec, currentTime_usec, currentTime; - if (isWrite){ - gettimeofday (&endTimeWrite, NULL); - currentTime_sec = (endTimeWrite.tv_sec - startTimeWrite.tv_sec) * 1000; - currentTime_usec = ((endTimeWrite.tv_usec - startTimeWrite.tv_usec)) / 1000; - currentTime = currentTime_sec + currentTime_usec; - return (unsigned int)currentTime; - } - else{ - gettimeofday (&endTimeRead, NULL); - currentTime_sec = (endTimeRead.tv_sec - startTimeRead.tv_sec) * 1000; - currentTime_usec = ((endTimeRead.tv_usec - startTimeRead.tv_usec)) / 1000; - currentTime = currentTime_sec + currentTime_usec; - return (unsigned int)currentTime; - } -} -#endif -CY_RETURN_STATUS handleI2cError (UINT8 i2cStatus){ - - if (i2cStatus & CY_I2C_NAK_ERROR_BIT){ - CY_DEBUG_PRINT_ERROR ("CY:Error Nacked by device ...Function is %s\n", __func__); - return CY_ERROR_I2C_NAK_ERROR; - } - if (i2cStatus & CY_I2C_BUS_ERROR_BIT){ - CY_DEBUG_PRINT_ERROR ("CY:Error bus error occured... Function is %s\n", __func__); - return CY_ERROR_I2C_BUS_ERROR; - } - if (i2cStatus & CY_I2C_ARBITRATION_ERROR_BIT){ - CY_DEBUG_PRINT_ERROR ("CY:Error Arbitration error occured.. Function is %s\n", __func__); - return CY_ERROR_I2C_ARBITRATION_ERROR; - } - if (i2cStatus & CY_I2C_STOP_BIT_ERROR){ - CY_DEBUG_PRINT_ERROR ("CY:Error Stop bit set by master..Function is %s\n", __func__); - return CY_ERROR_I2C_STOP_BIT_SET; - } - else { - //We should never hit this case!!!! - CY_DEBUG_PRINT_ERROR ("CY:Unknown error..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } -} -//Used internally by read and write API to check if data is received at the I2C end. -CY_RETURN_STATUS CyI2cGetStatus (CY_HANDLE handle, bool mode, UCHAR *i2cStatus); -CY_RETURN_STATUS waitForNotification (CY_HANDLE handle, UINT16 *bytesPending, UINT32 ioTimeout); -/* - * This API gets the current I2C config - * for the particluar interface of the device - */ -CY_RETURN_STATUS CyGetI2cConfig ( - CY_HANDLE handle, - CY_I2C_CONFIG *i2cConfig - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - CyUsI2cConfig_t localI2cConfig; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT16 scbIndex = 0; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (i2cConfig == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_I2C) { - CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c ..Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - scbIndex = device->interfaceNum; - if (scbIndex > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_I2C_GET_CONFIG_CMD; - wValue = (scbIndex << CY_SCB_INDEX_POS); - wIndex = 0x00; - wLength = CY_I2C_CONFIG_LENGTH; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)&localI2cConfig, wLength, ioTimeout); - if (rStatus == CY_I2C_CONFIG_LENGTH){ - CY_DEBUG_PRINT_INFO ("CY: Read I2C config ...size is %d \n", rStatus); - i2cConfig->frequency = localI2cConfig.frequency; - i2cConfig->slaveAddress = localI2cConfig.sAddress; - i2cConfig->isMaster = localI2cConfig.isMaster; - i2cConfig->isClockStretch = localI2cConfig.clockStretch; - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Error time out ....Function is %s\n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in doing I2C read ...libusb error is %d function is %s!\n", rStatus, __func__); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - * This API sets I2C config of the device for that - * interface - */ -CY_RETURN_STATUS CySetI2cConfig ( - CY_HANDLE handle, - CY_I2C_CONFIG *i2cConfig - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - CyUsI2cConfig_t localI2cConfig; - int rStatus; - CY_DEVICE *device = NULL; - libusb_device_handle *devHandle; - UINT16 scbIndex = 0; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (i2cConfig == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - if (i2cConfig->frequency < 1000 || i2cConfig->frequency > 400000){ - CY_DEBUG_PRINT_ERROR ("CY:Error frequency trying to set in out of ..range Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - if ((i2cConfig->slaveAddress % 2) != 0){ - CY_DEBUG_PRINT_ERROR ("CY:Error slave address needs to even..Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - scbIndex = device->interfaceNum; - if (device->deviceType != CY_TYPE_I2C) { - CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c ..Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (scbIndex > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_I2C_SET_CONFIG_CMD; - wValue = (scbIndex << CY_SCB_INDEX_POS); - wIndex = 0x00; - wLength = CY_I2C_CONFIG_LENGTH; - //We need to pass entire 16 bytes config structure to firmware - //but we will not expose all the structure elements to user. - //so filling some of the values. - memset (&localI2cConfig, 0, CY_I2C_CONFIG_LENGTH); - localI2cConfig.frequency = i2cConfig->frequency; - localI2cConfig.sAddress = i2cConfig->slaveAddress; - localI2cConfig.isMaster = i2cConfig->isMaster; - localI2cConfig.clockStretch = i2cConfig->isClockStretch; - localI2cConfig.isMsbFirst = 1; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)&localI2cConfig, wLength, ioTimeout); - if (rStatus == CY_I2C_CONFIG_LENGTH){ - CY_DEBUG_PRINT_INFO ("CY: Setting I2C config successful ...\n"); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Error time out ....Function is %s\n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in doing I2C read ...libusb error is %d function is %s!\n", rStatus, __func__); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - * This API reads I2C data from the specified interface of the device - * interface - */ -CY_RETURN_STATUS CyI2cRead ( - CY_HANDLE handle, - CY_I2C_DATA_CONFIG *i2cDataConfig, - CY_DATA_BUFFER *readBuffer, - UINT32 ioTimeout - ) -{ - int rStatus; - CY_DEVICE *device = NULL; - libusb_device_handle *devHandle; - UINT16 wValue = 0, wIndex, wLength, bytesPending = 0; - UINT8 bmRequestType, bmRequest; - UCHAR i2cStatus[CY_I2C_GET_STATUS_LEN]; - UINT16 scbIndex = 0; - bool mode = CY_I2C_MODE_READ; - UINT32 elapsedTime; - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if ((readBuffer == NULL) || (readBuffer->buffer == NULL) || (readBuffer->length == 0)){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - readBuffer->transferCount = 0; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_I2C) { - CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c ..Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (pthread_mutex_trylock (&device->readLock) == 0){ - scbIndex = device->interfaceNum; - if (scbIndex > 0) - scbIndex = 1; - i2cDataConfig->slaveAddress = ((i2cDataConfig->slaveAddress & 0x7F) | (scbIndex << 7)); - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_I2C_READ_CMD; - wValue = ((i2cDataConfig->isStopBit) | (i2cDataConfig->isNakBit << 1)); - wValue |= (((i2cDataConfig->slaveAddress) << 8)); - wIndex = readBuffer->length; - wLength = 0; - rStatus = CyI2cGetStatus (handle, mode, (UCHAR *)i2cStatus); - if (rStatus == CY_SUCCESS) - { - if ((i2cStatus[0] & CY_I2C_ERROR_BIT)){ - CY_DEBUG_PRINT_ERROR ("CY:Error device busy ... function is %s \n", __func__); - pthread_mutex_unlock (&device->readLock); - return CY_ERROR_I2C_DEVICE_BUSY; - } - } - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus == LIBUSB_ERROR_NO_DEVICE){ - CY_DEBUG_PRINT_ERROR ("CY:Error device disconnected ... \n"); - pthread_mutex_unlock (&device->readLock); - return CY_ERROR_DEVICE_NOT_FOUND; - } - if (rStatus < 0){ - CY_DEBUG_PRINT_ERROR ("CY:Error in sending Read vendor command ... Libusb Error is %d .. Function is %s \n", rStatus, __func__); - pthread_mutex_unlock (&device->readLock); - return CY_ERROR_I2C_DEVICE_BUSY; - } - //Hoping that previous calls do not take much time!! -#ifdef CY_I2C_ENABLE_PRECISE_TIMING - startI2cTick(false); -#endif - rStatus = libusb_bulk_transfer (devHandle, device->inEndpoint, readBuffer->buffer, readBuffer->length, - (int*)&readBuffer->transferCount, ioTimeout); -#ifdef CY_I2C_ENABLE_PRECISE_TIMING - elapsedTime = getI2cLapsedTime(false); - //Giving an extra 10 msec to notification to findout the status - ioTimeout = (ioTimeout - elapsedTime); - if (ioTimeout == 0) - ioTimeout = 10; -#endif - if (rStatus == LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_INFO ("CY: Successfully read i2c data.. %d bytes Read ...\n", readBuffer->transferCount); - bytesPending = readBuffer->length; - rStatus = waitForNotification (handle, &bytesPending, ioTimeout); - if (rStatus) - readBuffer->transferCount = (readBuffer->length - bytesPending); - else - readBuffer->transferCount = readBuffer->length; - pthread_mutex_unlock (&device->readLock); - return rStatus; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Timeout error ..Function is %s\n", __func__); - pthread_mutex_unlock (&device->readLock); - return CY_ERROR_IO_TIMEOUT; - } - else if (rStatus == LIBUSB_ERROR_PIPE){ - CY_DEBUG_PRINT_INFO ("Pipe Error \n"); - rStatus = CyResetPipe (handle, device->outEndpoint); - if (rStatus != CY_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("Error in reseting the pipe \n"); - } - else { - CY_DEBUG_PRINT_INFO ("Reset pipe succeded \n"); - } - - rStatus = CyI2cGetStatus (handle, mode, (UCHAR *)i2cStatus); - if (rStatus == CY_SUCCESS) - { - CyI2cReset (handle, mode); - rStatus = handleI2cError (i2cStatus[0]); - pthread_mutex_unlock (&device->readLock); - return rStatus; - } - else { - pthread_mutex_unlock (&device->readLock); - return CY_ERROR_I2C_DEVICE_BUSY; - } - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - pthread_mutex_unlock (&device->readLock); - CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else { - pthread_mutex_unlock (&device->readLock); - CY_DEBUG_PRINT_ERROR ("CY: Error in doing I2C read ...libusb error is %d function is %s!\n", rStatus, __func__); - return CY_ERROR_REQUEST_FAILED; - } - } - else{ - CY_DEBUG_PRINT_ERROR ("CY: Error API busy in servicing previous request... function is %s!\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - * This API writes I2C data into the specified interface of the device - */ -CY_RETURN_STATUS CyI2cWrite ( - CY_HANDLE handle, - CY_I2C_DATA_CONFIG *i2cDataConfig, - CY_DATA_BUFFER *writeBuffer, - UINT32 ioTimeout - ) -{ - int rStatus; - UCHAR i2cStatus[CY_I2C_GET_STATUS_LEN]; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT16 wValue = 0, wIndex, wLength, bytesPending = 0; - UINT8 bmRequestType, bmRequest; - UINT16 scbIndex = 0; - BOOL mode = CY_I2C_MODE_WRITE; - UINT32 elapsedTime; - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if ((writeBuffer == NULL) || (writeBuffer->buffer == NULL) || (writeBuffer->length == 0)){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - writeBuffer->transferCount = 0; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - scbIndex = device->interfaceNum; - if (device->deviceType != CY_TYPE_I2C){ - CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c ..Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (pthread_mutex_trylock (&device->writeLock) == 0){ - if (scbIndex > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_I2C_WRITE_CMD; - i2cDataConfig->slaveAddress = ((i2cDataConfig->slaveAddress & 0x7F) | (scbIndex << 7)); - wValue = ((i2cDataConfig->isStopBit)); - wValue |= (((i2cDataConfig->slaveAddress) << 8)); - wIndex = (UINT16)(writeBuffer->length); - wLength = 0; - CY_DEBUG_PRINT_INFO ("wValue is %x \n", wValue); - //Send I2C write vendor command before actually sending the data over bulk ep - rStatus = CyI2cGetStatus (handle, mode, (UCHAR *)i2cStatus); - if (rStatus == CY_SUCCESS) - { - if ((i2cStatus[0] & CY_I2C_ERROR_BIT)){ - CY_DEBUG_PRINT_ERROR ("CY:Error ... Device busy ... function is %s \n", __func__); - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_I2C_DEVICE_BUSY; - } - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE){ - CY_DEBUG_PRINT_ERROR ("CY:Error device not found \n"); - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_DEVICE_NOT_FOUND; - } - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus == LIBUSB_ERROR_NO_DEVICE){ - CY_DEBUG_PRINT_ERROR ("CY:Error device not found \n"); - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_DEVICE_NOT_FOUND; - } - if (rStatus < 0){ - CY_DEBUG_PRINT_ERROR ("CY:Error in sending write vendor command ... Libusb Error is %d \n", rStatus); - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_I2C_DEVICE_BUSY; - } - //After vendor command is sent send the actual data to be sent to i2c devic -#ifdef CY_I2C_ENABLE_PRECISE_TIMING - startI2cTick(true); -#endif - rStatus = libusb_bulk_transfer (devHandle, device->outEndpoint, writeBuffer->buffer, writeBuffer->length, - (int*)&(writeBuffer->transferCount), ioTimeout); -#ifdef CY_I2C_ENABLE_PRECISE_TIMING - elapsedTime = getI2cLapsedTime(true); - ioTimeout = (ioTimeout - elapsedTime); - //Giving an extra 10 msec to notification to findout the status - if (ioTimeout == 0) - ioTimeout = 10; -#endif - //Once the data is sent to usbserial, check if it was actually written to i2c device. - if (rStatus == LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_INFO ("CY: Successfully written i2c data.. %d bytes written ...\n", writeBuffer->transferCount); - bytesPending = writeBuffer->length; - rStatus = waitForNotification (handle, &bytesPending, ioTimeout); - if (rStatus) - writeBuffer->transferCount = (writeBuffer->length - bytesPending); - else - writeBuffer->transferCount = writeBuffer->length; - pthread_mutex_unlock (&device->writeLock); - return rStatus; - } - //Transaction is stallled when we hit some I2C error while the transfer - //was going on. After we hit this error clear stall and check why we hit this by - //CyGetStatus. - else if (rStatus == LIBUSB_ERROR_PIPE){ - CY_DEBUG_PRINT_INFO ("CY:Pipe Error ... Function is %s\n", __func__); - rStatus = CyResetPipe (handle, device->outEndpoint); - if (rStatus != CY_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in reseting the pipe ..Function is %s\n", __func__); - } - else { - CY_DEBUG_PRINT_INFO ("Reset pipe succeded \n"); - } - - rStatus = CyI2cGetStatus (handle, mode, (UCHAR *)i2cStatus); - if (rStatus == CY_SUCCESS) - { - CyI2cReset (handle, mode); - rStatus = handleI2cError (i2cStatus[0]); - pthread_mutex_unlock (&device->writeLock); - return rStatus; - } - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Error time out ....Function is %s\n", __func__); - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_IO_TIMEOUT; - } - else{ - CY_DEBUG_PRINT_ERROR ("CY: Error in doing I2C read ...libusb error is %d function is %s!\n", rStatus, __func__); - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_REQUEST_FAILED; - } - } - else{ - CY_DEBUG_PRINT_ERROR ("CY:API busy with servicing previous request... function is %s!\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_REQUEST_FAILED; -} -/* - * This API gets the current status of the I2C data transaction - */ -CY_RETURN_STATUS CyI2cGetStatus ( - CY_HANDLE handle, - bool mode, - UCHAR *i2cStatus - ) -{ - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT16 wValue, wIndex, wLength, bmRequestType, bmRequest;; - UINT16 scbIndex = 0; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - if (i2cStatus == NULL) - return CY_ERROR_INVALID_PARAMETER; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_I2C) { - CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c .. \n"); - return CY_ERROR_REQUEST_FAILED; - } - scbIndex = device->interfaceNum; - if (scbIndex > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_I2C_GET_STATUS_CMD; - wValue = ((scbIndex << CY_SCB_INDEX_POS) | mode); - wIndex = 0; - wLength = CY_I2C_GET_STATUS_LEN; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, (UCHAR*)i2cStatus, wLength, ioTimeout); - if (rStatus < CY_I2C_GET_STATUS_LEN){ - CY_DEBUG_PRINT_INFO ("CY:Error in sending I2C Get Status command...Libusb error is %d\n", rStatus); - return rStatus; - } - return CY_SUCCESS; -} -/* - * This API resets the I2C module - */ -CY_RETURN_STATUS CyI2cReset ( - CY_HANDLE handle, - BOOL resetMode - ) -{ - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT16 wValue, wIndex, wLength, bmRequestType, bmRequest; - UINT16 scbIndex = 0; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_I2C) { - CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c .. \n"); - return CY_ERROR_REQUEST_FAILED; - } - scbIndex = device->interfaceNum; - if (scbIndex > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_I2C_RESET_CMD; - wValue = ((scbIndex << CY_SCB_INDEX_POS) | resetMode ); - wIndex = 0; - wLength = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus < 0){ - CY_DEBUG_PRINT_ERROR ("CY:Error in sending I2C Reset command ..libusb error is %d\n", rStatus); - return CY_ERROR_REQUEST_FAILED; - } - return CY_SUCCESS; -} -static void LIBUSB_CALL i2c_notification_cb(struct libusb_transfer *transfer) -{ - UINT32 *completed = transfer->user_data; - *completed = 1; -} - -CY_RETURN_STATUS waitForNotification (CY_HANDLE handle, UINT16 *bytesPending, UINT32 ioTimeout){ - - UINT32 transferCompleted = 0, length = CY_I2C_EVENT_NOTIFICATION_LEN; - CY_DEVICE *device; - libusb_device_handle *devHandle; - struct libusb_transfer *transfer; - CY_RETURN_STATUS errorStatus, rStatus; - UCHAR i2cStatus[CY_I2C_EVENT_NOTIFICATION_LEN]; - struct timeval time; - - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - transfer = libusb_alloc_transfer(0); - if (transfer == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error in allocating trasnfer \n"); - errorStatus = CY_ERROR_ALLOCATION_FAILED; - (*bytesPending) = 0; - return errorStatus; - //callbackFn (errorStatus, 0); - } - libusb_fill_interrupt_transfer (transfer, devHandle, device->interruptEndpoint, i2cStatus, length, - i2c_notification_cb, &transferCompleted, ioTimeout); - if (libusb_submit_transfer (transfer)){ - CY_DEBUG_PRINT_ERROR ("CY:Error in submitting interrupt transfer ...\n"); - libusb_cancel_transfer (transfer); - libusb_free_transfer (transfer); - (*bytesPending) = 0; - //callbackFn (CY_ERROR_REQUEST_FAILED, 0); - return CY_ERROR_REQUEST_FAILED; - } - time.tv_sec = 0; - time.tv_usec = 50;//polling timeout. - while (transferCompleted == 0){ - libusb_handle_events_timeout (glContext, &time); - } - transferCompleted = 0; - if (transfer->status == LIBUSB_TRANSFER_COMPLETED){ - CY_DEBUG_PRINT_INFO ("CY:Info successfully recieved data on interrupt pipe length is %d \n", transfer->actual_length); - if (i2cStatus[0] & 0x80){ //Error notification is for write - if ((i2cStatus[0] & CY_I2C_ERROR_BIT)){ - CY_DEBUG_PRINT_INFO ("Bytes pending is %x %x %x", i2cStatus[0], i2cStatus[1], i2cStatus[2]); - //There was some error, so reset the i2c module and usb module - //of the device, so branch out of the loop(Check below for the errors reported). - rStatus = CyI2cReset (device, CY_I2C_MODE_WRITE); - if (rStatus != CY_SUCCESS){ - CY_DEBUG_PRINT_INFO ("CY:i2c reset failed \n"); - } - //Report the amount of byte that were actually written - memcpy(bytesPending, &i2cStatus[1], 2); - errorStatus = handleI2cError (i2cStatus[0]); - } - else - errorStatus = CY_SUCCESS; - } - else //Error notification is for read - { - if ((i2cStatus[0] & CY_I2C_ERROR_BIT)){ - CY_DEBUG_PRINT_INFO ("Bytes pending is %x %x %x", i2cStatus[0], i2cStatus[1], i2cStatus[2]); - rStatus = CyI2cReset (device, CY_I2C_MODE_READ); - if (rStatus != CY_SUCCESS){ - CY_DEBUG_PRINT_INFO ("CY:i2c reset failed \n"); - } - //Report the amount of byte that were actually written - memcpy(bytesPending, &i2cStatus[1], 2); - errorStatus = handleI2cError (i2cStatus[0]); - } - else - errorStatus = CY_SUCCESS; - } - libusb_free_transfer (transfer); - return errorStatus; - } - else{ - libusb_cancel_transfer (transfer); - if (transfer->status == LIBUSB_TRANSFER_TIMED_OUT){ - CY_DEBUG_PRINT_ERROR ("CY:Error Timeout in getting i2c transfer status ....\n"); - CyI2cGetStatus (handle, 1, (UCHAR *)&errorStatus); - errorStatus = CY_ERROR_IO_TIMEOUT; - } - if (transfer->status == LIBUSB_TRANSFER_OVERFLOW){ - CY_DEBUG_PRINT_ERROR ("CY:Error buffer overFlow in i2c transfer status ....\n"); - errorStatus = CY_ERROR_BUFFER_OVERFLOW; - } - if (transfer->status != LIBUSB_TRANSFER_COMPLETED){ - CY_DEBUG_PRINT_ERROR ("CY:Error in i2c transfer status ... Libusb transfer error is %d \n", transfer->status); - errorStatus = CY_ERROR_REQUEST_FAILED; - } - libusb_free_transfer (transfer); - return CY_ERROR_REQUEST_FAILED; - } -} +/* + * I2C routines of Cypress USB Serial + * Copyright (C) 2013 Cypress Semiconductor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "CyUSBCommon.h" +#pragma pack(1) +typedef struct +{ + UINT32 frequency; /* Frequency of operation. Only valid values are + 100KHz and 400KHz. */ + UINT8 sAddress; /* Slave address to be used when in slave mode. */ + BOOL isMsbFirst; /* Whether to transmit most significant bit first. */ + BOOL isMaster; /* Whether to block is to be configured as a master: + CyTrue - The block functions as I2C master; + CyFalse - The block functions as I2C slave. */ + BOOL sIgnore; /* Ignore general call in slave mode. */ + BOOL clockStretch; /* Wheteher to stretch clock in case of no FIFO availability. */ + BOOL isLoopback; /* Whether to loop back TX data to RX. Valid only + for debug purposes. */ + UCHAR reserved[6]; /*Reserved for future use*/ +} CyUsI2cConfig_t; +#pragma pack() +#ifdef CY_I2C_ENABLE_PRECISE_TIMING +struct timeval startTimeWrite, endTimeWrite, startTimeRead, endTimeRead; +//Timer helper functions for proper timing +void startI2cTick (bool isWrite) { + if (isWrite) + gettimeofday (&startTimeWrite, NULL); + else + gettimeofday (&startTimeRead, NULL); +} + +UINT32 getI2cLapsedTime (bool isWrite){ + + signed int currentTime_sec, currentTime_usec, currentTime; + if (isWrite){ + gettimeofday (&endTimeWrite, NULL); + currentTime_sec = (endTimeWrite.tv_sec - startTimeWrite.tv_sec) * 1000; + currentTime_usec = ((endTimeWrite.tv_usec - startTimeWrite.tv_usec)) / 1000; + currentTime = currentTime_sec + currentTime_usec; + return (unsigned int)currentTime; + } + else{ + gettimeofday (&endTimeRead, NULL); + currentTime_sec = (endTimeRead.tv_sec - startTimeRead.tv_sec) * 1000; + currentTime_usec = ((endTimeRead.tv_usec - startTimeRead.tv_usec)) / 1000; + currentTime = currentTime_sec + currentTime_usec; + return (unsigned int)currentTime; + } +} +#endif +CY_RETURN_STATUS handleI2cError (UINT8 i2cStatus){ + + if (i2cStatus & CY_I2C_NAK_ERROR_BIT){ + CY_DEBUG_PRINT_ERROR ("CY:Error Nacked by device ...Function is %s\n", __func__); + return CY_ERROR_I2C_NAK_ERROR; + } + if (i2cStatus & CY_I2C_BUS_ERROR_BIT){ + CY_DEBUG_PRINT_ERROR ("CY:Error bus error occured... Function is %s\n", __func__); + return CY_ERROR_I2C_BUS_ERROR; + } + if (i2cStatus & CY_I2C_ARBITRATION_ERROR_BIT){ + CY_DEBUG_PRINT_ERROR ("CY:Error Arbitration error occured.. Function is %s\n", __func__); + return CY_ERROR_I2C_ARBITRATION_ERROR; + } + if (i2cStatus & CY_I2C_STOP_BIT_ERROR){ + CY_DEBUG_PRINT_ERROR ("CY:Error Stop bit set by master..Function is %s\n", __func__); + return CY_ERROR_I2C_STOP_BIT_SET; + } + else { + //We should never hit this case!!!! + CY_DEBUG_PRINT_ERROR ("CY:Unknown error..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } +} +//Used internally by read and write API to check if data is received at the I2C end. +CY_RETURN_STATUS CyI2cGetStatus (CY_HANDLE handle, bool mode, UCHAR *i2cStatus); +CY_RETURN_STATUS waitForNotification (CY_HANDLE handle, UINT16 *bytesPending, UINT32 ioTimeout); +/* + This API gets the current I2C config + for the particluar interface of the device + */ +CY_RETURN_STATUS CyGetI2cConfig ( + CY_HANDLE handle, + CY_I2C_CONFIG *i2cConfig + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + CyUsI2cConfig_t localI2cConfig; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT16 scbIndex = 0; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (i2cConfig == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_I2C) { + CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c ..Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + scbIndex = device->interfaceNum; + if (scbIndex > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_I2C_GET_CONFIG_CMD; + wValue = (scbIndex << CY_SCB_INDEX_POS); + wIndex = 0x00; + wLength = CY_I2C_CONFIG_LENGTH; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)&localI2cConfig, wLength, ioTimeout); + if (rStatus == CY_I2C_CONFIG_LENGTH){ + CY_DEBUG_PRINT_INFO ("CY: Read I2C config ...size is %d \n", rStatus); + i2cConfig->frequency = localI2cConfig.frequency; + i2cConfig->slaveAddress = localI2cConfig.sAddress; + i2cConfig->isMaster = localI2cConfig.isMaster; + i2cConfig->isClockStretch = localI2cConfig.clockStretch; + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Error time out ....Function is %s\n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in doing I2C read ...libusb error is %d function is %s!\n", rStatus, __func__); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This API sets I2C config of the device for that + interface + */ +CY_RETURN_STATUS CySetI2cConfig ( + CY_HANDLE handle, + CY_I2C_CONFIG *i2cConfig + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + CyUsI2cConfig_t localI2cConfig; + int rStatus; + CY_DEVICE *device = NULL; + libusb_device_handle *devHandle; + UINT16 scbIndex = 0; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (i2cConfig == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + if (i2cConfig->frequency < 1000 || i2cConfig->frequency > 400000){ + CY_DEBUG_PRINT_ERROR ("CY:Error frequency trying to set in out of ..range Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + if ((i2cConfig->slaveAddress % 2) != 0){ + CY_DEBUG_PRINT_ERROR ("CY:Error slave address needs to even..Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + scbIndex = device->interfaceNum; + if (device->deviceType != CY_TYPE_I2C) { + CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c ..Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (scbIndex > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_I2C_SET_CONFIG_CMD; + wValue = (scbIndex << CY_SCB_INDEX_POS); + wIndex = 0x00; + wLength = CY_I2C_CONFIG_LENGTH; + //We need to pass entire 16 bytes config structure to firmware + //but we will not expose all the structure elements to user. + //so filling some of the values. + memset (&localI2cConfig, 0, CY_I2C_CONFIG_LENGTH); + localI2cConfig.frequency = i2cConfig->frequency; + localI2cConfig.sAddress = i2cConfig->slaveAddress; + localI2cConfig.isMaster = i2cConfig->isMaster; + localI2cConfig.clockStretch = i2cConfig->isClockStretch; + localI2cConfig.isMsbFirst = 1; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)&localI2cConfig, wLength, ioTimeout); + if (rStatus == CY_I2C_CONFIG_LENGTH){ + CY_DEBUG_PRINT_INFO ("CY: Setting I2C config successful ...\n"); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Error time out ....Function is %s\n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in doing I2C read ...libusb error is %d function is %s!\n", rStatus, __func__); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This API reads I2C data from the specified interface of the device + interface + */ +CY_RETURN_STATUS CyI2cRead ( + CY_HANDLE handle, + CY_I2C_DATA_CONFIG *i2cDataConfig, + CY_DATA_BUFFER *readBuffer, + UINT32 ioTimeout + ) +{ + int rStatus; + CY_DEVICE *device = NULL; + libusb_device_handle *devHandle; + UINT16 wValue = 0, wIndex, wLength, bytesPending = 0; + UINT8 bmRequestType, bmRequest; + UCHAR i2cStatus[CY_I2C_GET_STATUS_LEN]; + UINT16 scbIndex = 0; + bool mode = CY_I2C_MODE_READ; + UINT32 elapsedTime; + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if ((readBuffer == NULL) || (readBuffer->buffer == NULL) || (readBuffer->length == 0)){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + readBuffer->transferCount = 0; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_I2C) { + CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c ..Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (pthread_mutex_trylock (&device->readLock) == 0){ + scbIndex = device->interfaceNum; + if (scbIndex > 0) + scbIndex = 1; + i2cDataConfig->slaveAddress = ((i2cDataConfig->slaveAddress & 0x7F) | (scbIndex << 7)); + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_I2C_READ_CMD; + wValue = ((i2cDataConfig->isStopBit) | (i2cDataConfig->isNakBit << 1)); + wValue |= (((i2cDataConfig->slaveAddress) << 8)); + wIndex = readBuffer->length; + wLength = 0; + rStatus = CyI2cGetStatus (handle, mode, (UCHAR *)i2cStatus); + if (rStatus == CY_SUCCESS) + { + if ((i2cStatus[0] & CY_I2C_ERROR_BIT)){ + CY_DEBUG_PRINT_ERROR ("CY:Error device busy ... function is %s \n", __func__); + pthread_mutex_unlock (&device->readLock); + return CY_ERROR_I2C_DEVICE_BUSY; + } + } + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus == LIBUSB_ERROR_NO_DEVICE){ + CY_DEBUG_PRINT_ERROR ("CY:Error device disconnected ... \n"); + pthread_mutex_unlock (&device->readLock); + return CY_ERROR_DEVICE_NOT_FOUND; + } + if (rStatus < 0){ + CY_DEBUG_PRINT_ERROR ("CY:Error in sending Read vendor command ... Libusb Error is %d .. Function is %s \n", rStatus, __func__); + pthread_mutex_unlock (&device->readLock); + return CY_ERROR_I2C_DEVICE_BUSY; + } + //Hoping that previous calls do not take much time!! +#ifdef CY_I2C_ENABLE_PRECISE_TIMING + startI2cTick(false); +#endif + rStatus = libusb_bulk_transfer (devHandle, device->inEndpoint, readBuffer->buffer, readBuffer->length, + (int*)&readBuffer->transferCount, ioTimeout); +#ifdef CY_I2C_ENABLE_PRECISE_TIMING + elapsedTime = getI2cLapsedTime(false); + //Giving an extra 10 msec to notification to findout the status + ioTimeout = (ioTimeout - elapsedTime); + if (ioTimeout == 0) + ioTimeout = 10; +#endif + if (rStatus == LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_INFO ("CY: Successfully read i2c data.. %d bytes Read ...\n", readBuffer->transferCount); + bytesPending = readBuffer->length; + rStatus = waitForNotification (handle, &bytesPending, ioTimeout); + if (rStatus) + readBuffer->transferCount = (readBuffer->length - bytesPending); + else + readBuffer->transferCount = readBuffer->length; + pthread_mutex_unlock (&device->readLock); + return rStatus; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Timeout error ..Function is %s\n", __func__); + pthread_mutex_unlock (&device->readLock); + return CY_ERROR_IO_TIMEOUT; + } + else if (rStatus == LIBUSB_ERROR_PIPE){ + CY_DEBUG_PRINT_INFO ("Pipe Error \n"); + rStatus = CyResetPipe (handle, device->outEndpoint); + if (rStatus != CY_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("Error in reseting the pipe \n"); + } + else + CY_DEBUG_PRINT_INFO ("Reset pipe succeded \n"); + + rStatus = CyI2cGetStatus (handle, mode, (UCHAR *)i2cStatus); + if (rStatus == CY_SUCCESS) + { + CyI2cReset (handle, mode); + rStatus = handleI2cError (i2cStatus[0]); + pthread_mutex_unlock (&device->readLock); + return rStatus; + } + else { + pthread_mutex_unlock (&device->readLock); + return CY_ERROR_I2C_DEVICE_BUSY; + } + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + pthread_mutex_unlock (&device->readLock); + CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + pthread_mutex_unlock (&device->readLock); + CY_DEBUG_PRINT_ERROR ("CY:Error time out ....Function is %s\n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + pthread_mutex_unlock (&device->readLock); + CY_DEBUG_PRINT_ERROR ("CY: Error in doing I2C read ...libusb error is %d function is %s!\n", rStatus, __func__); + return CY_ERROR_REQUEST_FAILED; + } + } + else{ + CY_DEBUG_PRINT_ERROR ("CY: Error API busy in servicing previous request... function is %s!\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This API writes I2C data into the specified interface of the device + */ +CY_RETURN_STATUS CyI2cWrite ( + CY_HANDLE handle, + CY_I2C_DATA_CONFIG *i2cDataConfig, + CY_DATA_BUFFER *writeBuffer, + UINT32 ioTimeout + ) +{ + int rStatus; + UCHAR i2cStatus[CY_I2C_GET_STATUS_LEN]; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT16 wValue = 0, wIndex, wLength, bytesPending = 0; + UINT8 bmRequestType, bmRequest; + UINT16 scbIndex = 0; + BOOL mode = CY_I2C_MODE_WRITE; + UINT32 elapsedTime; + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if ((writeBuffer == NULL) || (writeBuffer->buffer == NULL) || (writeBuffer->length == 0)){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + writeBuffer->transferCount = 0; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + scbIndex = device->interfaceNum; + if (device->deviceType != CY_TYPE_I2C){ + CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c ..Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (pthread_mutex_trylock (&device->writeLock) == 0){ + if (scbIndex > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_I2C_WRITE_CMD; + i2cDataConfig->slaveAddress = ((i2cDataConfig->slaveAddress & 0x7F) | (scbIndex << 7)); + wValue = ((i2cDataConfig->isStopBit)); + wValue |= (((i2cDataConfig->slaveAddress) << 8)); + wIndex = (UINT16)(writeBuffer->length); + wLength = 0; + CY_DEBUG_PRINT_INFO ("wValue is %x \n", wValue); + //Send I2C write vendor command before actually sending the data over bulk ep + rStatus = CyI2cGetStatus (handle, mode, (UCHAR *)i2cStatus); + if (rStatus == CY_SUCCESS) + { + if ((i2cStatus[0] & CY_I2C_ERROR_BIT)){ + CY_DEBUG_PRINT_ERROR ("CY:Error ... Device busy ... function is %s \n", __func__); + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_I2C_DEVICE_BUSY; + } + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE){ + CY_DEBUG_PRINT_ERROR ("CY:Error device not found \n"); + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_DEVICE_NOT_FOUND; + } + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus == LIBUSB_ERROR_NO_DEVICE){ + CY_DEBUG_PRINT_ERROR ("CY:Error device not found \n"); + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_DEVICE_NOT_FOUND; + } + if (rStatus < 0){ + CY_DEBUG_PRINT_ERROR ("CY:Error in sending write vendor command ... Libusb Error is %d \n", rStatus); + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_I2C_DEVICE_BUSY; + } + //After vendor command is sent send the actual data to be sent to i2c devic +#ifdef CY_I2C_ENABLE_PRECISE_TIMING + startI2cTick(true); +#endif + rStatus = libusb_bulk_transfer (devHandle, device->outEndpoint, writeBuffer->buffer, writeBuffer->length, + (int*)&(writeBuffer->transferCount), ioTimeout); +#ifdef CY_I2C_ENABLE_PRECISE_TIMING + elapsedTime = getI2cLapsedTime(true); + ioTimeout = (ioTimeout - elapsedTime); + //Giving an extra 10 msec to notification to findout the status + if (ioTimeout == 0) + ioTimeout = 10; +#endif + //Once the data is sent to usbserial, check if it was actually written to i2c device. + if (rStatus == LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_INFO ("CY: Successfully written i2c data.. %d bytes written ...\n", writeBuffer->transferCount); + bytesPending = writeBuffer->length; + rStatus = waitForNotification (handle, &bytesPending, ioTimeout); + if (rStatus) + writeBuffer->transferCount = (writeBuffer->length - bytesPending); + else + writeBuffer->transferCount = writeBuffer->length; + pthread_mutex_unlock (&device->writeLock); + return rStatus; + } + //Transaction is stallled when we hit some I2C error while the transfer + //was going on. After we hit this error clear stall and check why we hit this by + //CyGetStatus. + else if (rStatus == LIBUSB_ERROR_PIPE){ + CY_DEBUG_PRINT_INFO ("CY:Pipe Error ... Function is %s\n", __func__); + rStatus = CyResetPipe (handle, device->outEndpoint); + if (rStatus != CY_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in reseting the pipe ..Function is %s\n", __func__); + } + else + CY_DEBUG_PRINT_INFO ("Reset pipe succeded \n"); + + rStatus = CyI2cGetStatus (handle, mode, (UCHAR *)i2cStatus); + if (rStatus == CY_SUCCESS) + { + CyI2cReset (handle, mode); + rStatus = handleI2cError (i2cStatus[0]); + pthread_mutex_unlock (&device->writeLock); + return rStatus; + } + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Error time out ....Function is %s\n", __func__); + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_IO_TIMEOUT; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY: Error in doing I2C read ...libusb error is %d function is %s!\n", rStatus, __func__); + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_REQUEST_FAILED; + } + } + else{ + CY_DEBUG_PRINT_ERROR ("CY:API busy with servicing previous request... function is %s!\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + return CY_ERROR_REQUEST_FAILED; +} +/* + This Api gets the current status of the I2C data transaction + */ +CY_RETURN_STATUS CyI2cGetStatus ( + CY_HANDLE handle, + bool mode, + UCHAR *i2cStatus + ) +{ + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT16 wValue, wIndex, wLength, bmRequestType, bmRequest;; + UINT16 scbIndex = 0; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if (i2cStatus == NULL) + return CY_ERROR_INVALID_PARAMETER; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_I2C) { + CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c .. \n"); + return CY_ERROR_REQUEST_FAILED; + } + scbIndex = device->interfaceNum; + if (scbIndex > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_I2C_GET_STATUS_CMD; + wValue = ((scbIndex << CY_SCB_INDEX_POS) | mode); + wIndex = 0; + wLength = CY_I2C_GET_STATUS_LEN; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, (UCHAR*)i2cStatus, wLength, ioTimeout); + if (rStatus < CY_I2C_GET_STATUS_LEN){ + CY_DEBUG_PRINT_INFO ("CY:Error in sending I2C Get Status command...Libusb error is %d\n", rStatus); + return rStatus; + } + return CY_SUCCESS; +} +/* + This Api resets the I2C module + */ +CY_RETURN_STATUS CyI2cReset ( + CY_HANDLE handle, + BOOL resetMode + ) +{ + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT16 wValue, wIndex, wLength, bmRequestType, bmRequest; + UINT16 scbIndex = 0; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_I2C) { + CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not i2c .. \n"); + return CY_ERROR_REQUEST_FAILED; + } + scbIndex = device->interfaceNum; + if (scbIndex > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_I2C_RESET_CMD; + wValue = ((scbIndex << CY_SCB_INDEX_POS) | resetMode ); + wIndex = 0; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus < 0){ + CY_DEBUG_PRINT_ERROR ("CY:Error in sending I2C Reset command ..libusb error is %d\n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } + return CY_SUCCESS; +} +static void LIBUSB_CALL i2c_notification_cb(struct libusb_transfer *transfer) +{ + UINT32 *completed = transfer->user_data; + *completed = 1; +} + +CY_RETURN_STATUS waitForNotification (CY_HANDLE handle, UINT16 *bytesPending, UINT32 ioTimeout){ + + UINT32 transferCompleted = 0, length = CY_I2C_EVENT_NOTIFICATION_LEN; + CY_DEVICE *device; + libusb_device_handle *devHandle; + struct libusb_transfer *transfer; + CY_RETURN_STATUS errorStatus, rStatus; + UCHAR i2cStatus[CY_I2C_EVENT_NOTIFICATION_LEN]; + struct timeval time; + + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + transfer = libusb_alloc_transfer(0); + if (transfer == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error in allocating trasnfer \n"); + errorStatus = CY_ERROR_ALLOCATION_FAILED; + (*bytesPending) = 0; + return errorStatus; + //callbackFn (errorStatus, 0); + } + libusb_fill_interrupt_transfer (transfer, devHandle, device->interruptEndpoint, i2cStatus, length, + i2c_notification_cb, &transferCompleted, ioTimeout); + if (libusb_submit_transfer (transfer)){ + CY_DEBUG_PRINT_ERROR ("CY:Error in submitting interrupt transfer ...\n"); + libusb_cancel_transfer (transfer); + libusb_free_transfer (transfer); + (*bytesPending) = 0; + //callbackFn (CY_ERROR_REQUEST_FAILED, 0); + return CY_ERROR_REQUEST_FAILED; + } + time.tv_sec = 0; + time.tv_usec = 50;//polling timeout. + while (transferCompleted == 0){ + libusb_handle_events_timeout (NULL, &time); + } + transferCompleted = 0; + if (transfer->status == LIBUSB_TRANSFER_COMPLETED){ + CY_DEBUG_PRINT_INFO ("CY:Info successfully recieved data on interrupt pipe length is %d \n", transfer->actual_length); + if (i2cStatus[0] & 0x80){ //Error notification is for write + if ((i2cStatus[0] & CY_I2C_ERROR_BIT)){ + CY_DEBUG_PRINT_INFO ("Bytes pending is %x %x %x", i2cStatus[0], i2cStatus[1], i2cStatus[2]); + if (i2cStatus[0] & 0x1E){ + //There was some error, so reset the i2c module and usb module + //of the device, so branch out of the loop(Check below for the errors reported). + rStatus = CyI2cReset (device, CY_I2C_MODE_WRITE); + if (rStatus != CY_SUCCESS) + CY_DEBUG_PRINT_INFO ("CY:i2c reset failed \n"); + //Report the amount of byte that were actually written + memcpy(bytesPending, &i2cStatus[1], 2); + errorStatus = handleI2cError (i2cStatus[0]); + } + } + else + errorStatus = CY_SUCCESS; + } + else //Error notification is for read + { + if ((i2cStatus[0] & CY_I2C_ERROR_BIT)){ + CY_DEBUG_PRINT_INFO ("Bytes pending is %x %x %x", i2cStatus[0], i2cStatus[1], i2cStatus[2]); + if (i2cStatus[0] & 0x1E){ + rStatus = CyI2cReset (device, CY_I2C_MODE_READ); + if (rStatus != CY_SUCCESS) + CY_DEBUG_PRINT_INFO ("CY:i2c reset failed \n"); + //Report the amount of byte that were actually written + memcpy(bytesPending, &i2cStatus[1], 2); + errorStatus = handleI2cError (i2cStatus[0]); + } + } + else + errorStatus = CY_SUCCESS; + } + libusb_free_transfer (transfer); + return errorStatus; + } + else{ + libusb_cancel_transfer (transfer); + if (transfer->status == LIBUSB_TRANSFER_TIMED_OUT){ + CY_DEBUG_PRINT_ERROR ("CY:Error Timeout in getting i2c transfer status ....\n"); + CyI2cGetStatus (handle, 1, (UCHAR *)&errorStatus); + errorStatus = CY_ERROR_IO_TIMEOUT; + } + if (transfer->status == LIBUSB_TRANSFER_OVERFLOW){ + CY_DEBUG_PRINT_ERROR ("CY:Error buffer overFlow in i2c transfer status ....\n"); + errorStatus = CY_ERROR_BUFFER_OVERFLOW; + } + if (transfer->status != LIBUSB_TRANSFER_COMPLETED || transfer->status != LIBUSB_TRANSFER_COMPLETED){ + CY_DEBUG_PRINT_ERROR ("CY:Error in i2c transfer status ... Libusb transfer error is %d \n", transfer->status); + errorStatus = CY_ERROR_REQUEST_FAILED; + } + libusb_free_transfer (transfer); + return CY_ERROR_REQUEST_FAILED; + } +} diff --git a/cylib/lib/cyjtag.c b/configutility/linux/library/cyjtag.c similarity index 88% rename from cylib/lib/cyjtag.c rename to configutility/linux/library/cyjtag.c index 0ec81fa..f286a70 100644 --- a/cylib/lib/cyjtag.c +++ b/configutility/linux/library/cyjtag.c @@ -1,248 +1,247 @@ -/* - * JTAG routines of Cypress USB Serial - * Copyright (C) 2013 Cypress Semiconductor - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "CyUSBCommon.h" -/* - * This API enables the Jtag module - */ -CY_RETURN_STATUS CyJtagEnable ( - CY_HANDLE handle - ) -{ - UINT16 wValue, wIndex, wLength; - UINT16 bmRequestType, bmRequest; - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_JTAG) { - CY_DEBUG_PRINT_ERROR ("CY:Error device type is not jtag ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_JTAG_ENABLE_CMD; - wValue = 0x00; - wIndex = 0; - wLength = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus >= 0){ - CY_DEBUG_PRINT_INFO ("CY: JTAG enable successfully \n"); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - * This API disables the Jtag module - */ -CY_RETURN_STATUS CyJtagDisable ( - CY_HANDLE handle - ) -{ - UINT16 wValue, wIndex, wLength; - UINT16 bmRequestType, bmRequest; - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_JTAG) { - CY_DEBUG_PRINT_ERROR ("CY:Error device type is not jtag ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_JTAG_DISABLE_CMD; - wValue = 0x00; - wIndex = 0; - wLength = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus >= 0){ - CY_DEBUG_PRINT_INFO ("CY: JTAG disable successfully \n"); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error while enabling JTAG ..\n"); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY:Error while enabling JTAG ...libusb error is %d function is %s!\n", rStatus, __func__); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - * This API is used to do jtag write - */ -CY_RETURN_STATUS CyJtagWrite ( - CY_HANDLE handle, - CY_DATA_BUFFER *writeBuffer, - UINT32 ioTimeout - ) -{ - int rStatus = 0; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT16 wValue, wIndex, wLength; - UINT16 bmRequestType, bmRequest; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if ((writeBuffer == NULL) || (writeBuffer->buffer == NULL) || (writeBuffer->length == 0)){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_JTAG) { - CY_DEBUG_PRINT_ERROR ("CY:Error device type is not jtag ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_JTAG_WRITE_CMD; - wValue = writeBuffer->length; - wIndex = 0; - wLength = 0; - writeBuffer->transferCount = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus < 0){ - CY_DEBUG_PRINT_ERROR ("CY: JTAG Vendor command failed %d...function is %s \n", rStatus, __func__); - return CY_ERROR_REQUEST_FAILED; - } - rStatus = libusb_bulk_transfer (devHandle, CY_JTAG_OUT_EP, writeBuffer->buffer, writeBuffer->length, - (int*)&(writeBuffer->transferCount), ioTimeout); - if (rStatus == CY_SUCCESS) { - CY_DEBUG_PRINT_ERROR ("CY: Number of bytes written is .... %d \n", writeBuffer->transferCount); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:TimeOut error ...Function is %s %d\n", __func__, writeBuffer->transferCount); - return CY_ERROR_IO_TIMEOUT; - } - else if (rStatus == LIBUSB_ERROR_PIPE){ - CY_DEBUG_PRINT_ERROR ("CY:Pipe error Function is %s \n", __func__); - CyResetPipe (handle, CY_JTAG_OUT_EP); - return CY_ERROR_PIPE_HALTED; - } - else if (rStatus == LIBUSB_ERROR_OVERFLOW){ - CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow..Function is %s \n", __func__); - return CY_ERROR_BUFFER_OVERFLOW; - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s \n", __func__); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in Function %s...Libusb Error is %d !\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This API is used to read JTAG data from device interface - */ -CY_RETURN_STATUS CyJtagRead ( - CY_HANDLE handle, - CY_DATA_BUFFER *readBuffer, - UINT32 ioTimeout - ) -{ - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT16 wValue, wIndex, wLength; - UINT16 bmRequestType, bmRequest; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if ((readBuffer == NULL) || (readBuffer->buffer == NULL) || (readBuffer->length == 0)){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_JTAG) { - CY_DEBUG_PRINT_ERROR ("CY:Error device type is not jtag ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_JTAG_READ_CMD; - wValue = readBuffer->length; - wIndex = 0; - wLength = 0; - - readBuffer->transferCount = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus < 0){ - CY_DEBUG_PRINT_INFO ("CY: JTAG Vendor Command failed %d.. Function is %s \n", rStatus, __func__); - return CY_ERROR_REQUEST_FAILED; - } - rStatus = libusb_bulk_transfer (devHandle, CY_JTAG_IN_EP, readBuffer->buffer, readBuffer->length, - (int*)&(readBuffer->transferCount), ioTimeout); - if (rStatus == CY_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY: Number of bytes read is .... %d \n", readBuffer->transferCount); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:TimeOut error ...Function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else if (rStatus == LIBUSB_ERROR_PIPE){ - CY_DEBUG_PRINT_ERROR ("CY:Pipe error Function is %s \n", __func__); - CyResetPipe (handle, CY_JTAG_IN_EP); - return CY_ERROR_PIPE_HALTED; - } - else if (rStatus == LIBUSB_ERROR_OVERFLOW){ - CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow..Function is %s \n", __func__); - return CY_ERROR_BUFFER_OVERFLOW; - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s \n", __func__); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function is %s ...Libusb Error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} +/* + * JTAG routines of Cypress USB Serial + * Copyright (C) 2013 Cypress Semiconductor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "CyUSBCommon.h" +/* + * This API enables the Jtag module + */ +CY_RETURN_STATUS CyJtagEnable ( + CY_HANDLE handle + ) +{ + UINT16 wValue, wIndex, wLength; + UINT16 bmRequestType, bmRequest; + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_JTAG) { + CY_DEBUG_PRINT_ERROR ("CY:Error device type is not jtag ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_JTAG_ENABLE_CMD; + wValue = 0x00; + wIndex = 0; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus >= 0){ + CY_DEBUG_PRINT_INFO ("CY: JTAG enable successfully \n"); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + * This API disables the Jtag module + */ +CY_RETURN_STATUS CyJtagDisable ( + CY_HANDLE handle + ) +{ + UINT16 wValue, wIndex, wLength; + UINT16 bmRequestType, bmRequest; + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_JTAG) { + CY_DEBUG_PRINT_ERROR ("CY:Error device type is not jtag ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_JTAG_DISABLE_CMD; + wValue = 0x00; + wIndex = 0; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus >= 0){ + CY_DEBUG_PRINT_INFO ("CY: JTAG disable successfully \n"); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error while enabling JTAG ..\n"); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error while enabling JTAG ...libusb error is %d function is %s!\n", rStatus, __func__); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + * This API is used to do jtag write + */ +CY_RETURN_STATUS CyJtagWrite ( + CY_HANDLE handle, + CY_DATA_BUFFER *writeBuffer, + UINT32 ioTimeout + ) +{ + int rStatus = 0; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT16 wValue, wIndex, wLength; + UINT16 bmRequestType, bmRequest; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if ((writeBuffer == NULL) || (writeBuffer->buffer == NULL) || (writeBuffer->length == 0)){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_JTAG) { + CY_DEBUG_PRINT_ERROR ("CY:Error device type is not jtag ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_JTAG_WRITE_CMD; + wValue = writeBuffer->length; + wIndex = 0; + wLength = 0; + writeBuffer->transferCount = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus < 0){ + CY_DEBUG_PRINT_ERROR ("CY: JTAG Vendor command failed %d...function is %s \n", rStatus, __func__); + return CY_ERROR_REQUEST_FAILED; + } + rStatus = libusb_bulk_transfer (devHandle, CY_JTAG_OUT_EP, writeBuffer->buffer, writeBuffer->length, + (int*)&(writeBuffer->transferCount), ioTimeout); + if ((rStatus == CY_SUCCESS)) { + CY_DEBUG_PRINT_ERROR ("CY: Number of bytes written is .... %d \n", writeBuffer->transferCount); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:TimeOut error ...Function is %s %d\n", __func__, writeBuffer->transferCount); + return CY_ERROR_IO_TIMEOUT; + } + else if (rStatus == LIBUSB_ERROR_PIPE){ + CY_DEBUG_PRINT_ERROR ("CY:Pipe error Function is %s \n", __func__); + CyResetPipe (handle, CY_JTAG_OUT_EP); + return CY_ERROR_PIPE_HALTED; + } + else if (rStatus == LIBUSB_ERROR_OVERFLOW){ + CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow..Function is %s \n", __func__); + return CY_ERROR_BUFFER_OVERFLOW; + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s \n", __func__); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in Function %s...Libusb Error is %d !\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This API is used to read JTAG data from device interface + */ +CY_RETURN_STATUS CyJtagRead ( + CY_HANDLE handle, + CY_DATA_BUFFER *readBuffer, + UINT32 ioTimeout + ) +{ + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT16 wValue, wIndex, wLength; + UINT16 bmRequestType, bmRequest; + + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_JTAG_READ_CMD; + wValue = readBuffer->length; + wIndex = 0; + wLength = 0; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if ((readBuffer == NULL) || (readBuffer->buffer == NULL) || (readBuffer->length == 0)){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_JTAG) { + CY_DEBUG_PRINT_ERROR ("CY:Error device type is not jtag ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + readBuffer->transferCount = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus < 0){ + CY_DEBUG_PRINT_INFO ("CY: JTAG Vendor Command failed %d.. Function is %s \n", rStatus, __func__); + return CY_ERROR_REQUEST_FAILED; + } + rStatus = libusb_bulk_transfer (devHandle, CY_JTAG_IN_EP, readBuffer->buffer, readBuffer->length, + (int*)&(readBuffer->transferCount), ioTimeout); + if (rStatus == CY_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY: Number of bytes read is .... %d \n", readBuffer->transferCount); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:TimeOut error ...Function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else if (rStatus == LIBUSB_ERROR_PIPE){ + CY_DEBUG_PRINT_ERROR ("CY:Pipe error Function is %s \n", __func__); + CyResetPipe (handle, CY_JTAG_IN_EP); + return CY_ERROR_PIPE_HALTED; + } + else if (rStatus == LIBUSB_ERROR_OVERFLOW){ + CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow..Function is %s \n", __func__); + return CY_ERROR_BUFFER_OVERFLOW; + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s \n", __func__); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function is %s ...Libusb Error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} diff --git a/cylib/lib/cymisc.c b/configutility/linux/library/cymisc.c similarity index 86% rename from cylib/lib/cymisc.c rename to configutility/linux/library/cymisc.c index dd72904..0321e39 100644 --- a/cylib/lib/cymisc.c +++ b/configutility/linux/library/cymisc.c @@ -1,591 +1,584 @@ -/* - * Miscellaneous routines of Cypress USB Serial - * Copyright (C) 2013 Cypress Semiconductor - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "CyUSBCommon.h" - -typedef struct NOTIFICATION_CB_PARAM{ - - CY_HANDLE handle; - CY_EVENT_NOTIFICATION_CB_FN notificationCbFn; - -}NOTIFICATION_CB_PARAM; -/* - This API is used to Read the Bootloder version - */ -CY_RETURN_STATUS CyGetFirmwareVersion( - CY_HANDLE handle, - CY_FIRMWARE_VERSION *firmwareVersion - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_GET_VERSION_CMD; - wValue = 0x00; - wIndex = 0x00; - wLength = CY_GET_FIRMWARE_VERSION_LEN; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)firmwareVersion, wLength, ioTimeout); - - if (rStatus > 0){ - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* -The API resets the device -*/ -CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyResetDevice ( - CY_HANDLE handle /*Valid device handle*/ - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle \n"); - return CY_ERROR_INVALID_HANDLE; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_DEVICE_RESET_CMD; - wValue = 0xA6B6; - wIndex = 0xADBA; - wLength = 0; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - //return buffer will tell the status of the command - if (rStatus == LIBUSB_SUCCESS) - return CY_SUCCESS; - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} - -CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CySetGpioValue ( - CY_HANDLE handle, /*Valid device handle*/ - UINT8 gpioNumber, /*GPIO configuration value*/ - UINT8 value /*Value that needs to be set*/ - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest, buffer[CY_GPIO_SET_LEN]; - int rStatus; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (value) - value = 1; - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_GPIO_SET_VALUE_CMD; - wValue = gpioNumber; - wIndex = value; - wLength = 0; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, buffer, wLength, ioTimeout); - if (rStatus >= 0){ - CY_DEBUG_PRINT_INFO ("CY: Get Configuration of GPIO succedded...size is %d \n", rStatus); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} - -CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyGetGpioValue ( - CY_HANDLE handle, /*Valid device handle*/ - UINT8 gpioNumber, /*GPIO configuration value*/ - UINT8 *value /*Value that needs to be set*/ - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest, buffer[CY_GPIO_GET_LEN]; - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_GPIO_GET_VALUE_CMD; - wValue = gpioNumber; - wIndex = 0x00; - wLength = CY_GPIO_GET_LEN; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, buffer, wLength, ioTimeout); - if (rStatus == CY_GPIO_GET_LEN){ - CY_DEBUG_PRINT_INFO ("CY: Get GPIO Configuration succedded...size is %d \n", rStatus); - //return buffer will tell the status of the command - if (buffer[0] == 0){ - (*value) = buffer[1]; - return CY_SUCCESS; - } - else - return CY_ERROR_REQUEST_FAILED; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -static void LIBUSB_CALL uart_notification_cb(struct libusb_transfer *transfer) -{ - UINT32 *completed = transfer->user_data; - *completed = 1; -} - -void* uartSetEventNotifcation (void *inputParameters) -{ - int rStatus, transferCompleted = 0, length = CY_UART_EVENT_NOTIFICATION_LEN; - CY_DEVICE *device; - libusb_device_handle *devHandle; - struct libusb_transfer *transfer; - UINT16 errorStatus = 0; - UCHAR uartStatus[CY_UART_EVENT_NOTIFICATION_LEN]; - struct timeval time; - CY_EVENT_NOTIFICATION_CB_FN callbackFn; - NOTIFICATION_CB_PARAM *cbParameters = (NOTIFICATION_CB_PARAM*)inputParameters; - callbackFn = cbParameters->notificationCbFn; - - device = (CY_DEVICE *)cbParameters->handle; - devHandle = device->devHandle; - callbackFn = cbParameters->notificationCbFn; - device->uartTransfer = transfer = libusb_alloc_transfer(0); - if (transfer == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error in allocating trasnfer \n"); - errorStatus |= CY_ERROR_EVENT_FAILED_BIT; - callbackFn(errorStatus); - goto END; - } - while (device->uartCancelEvent == false){ - libusb_fill_interrupt_transfer (transfer, devHandle, device->interruptEndpoint, uartStatus, length, - uart_notification_cb, &transferCompleted, CY_EVENT_NOTIFICATION_TIMEOUT); - rStatus = libusb_submit_transfer (transfer); - if (rStatus){ - CY_DEBUG_PRINT_ERROR ("CY:Error submitting uart interrupt token ... Libusb error is %d\n", rStatus); - errorStatus |= CY_ERROR_EVENT_FAILED_BIT; - callbackFn(errorStatus); - break; - } - time.tv_sec = 0; - time.tv_usec = 50;//polling timeout. - while (transferCompleted == 0){ - libusb_handle_events_timeout (glContext, &time); - } - transferCompleted = 0; - if (transfer->status == LIBUSB_TRANSFER_COMPLETED){ - CY_DEBUG_PRINT_INFO ("Successfully read and recieved data %d \n", transfer->actual_length); - memcpy (&errorStatus, &uartStatus[8], 2); - printf ("%x %x ", uartStatus[8], uartStatus[9]); - callbackFn (errorStatus); - errorStatus = 0; - } - else{ - errorStatus |= CY_ERROR_EVENT_FAILED_BIT; - if (device->uartCancelEvent == false){ - CY_DEBUG_PRINT_ERROR ("CY:Error uart interrupt thread encountered error... Libusb transmission error is %d \n", transfer->status); - pthread_join (device->uartThread, NULL); - device->uartThreadRunning = false; - callbackFn(errorStatus); - } - break; - } - } - CY_DEBUG_PRINT_INFO ("Exiting notification thread \n"); - libusb_free_transfer (transfer); -END: - free (inputParameters); - return NULL; -} - -static void LIBUSB_CALL spi_notification_cb(struct libusb_transfer *transfer) -{ - UINT32 *completed = transfer->user_data; - *completed = 1; -} - -void* spiSetEventNotifcation (void *inputParameters) -{ - int transferCompleted = 0, length = CY_SPI_EVENT_NOTIFICATION_LEN; - CY_DEVICE *device; - libusb_device_handle *devHandle; - struct libusb_transfer *transfer; - UINT16 spiStatus = 0; - unsigned char spiStatusBuffer[2] = {0, 0}; - UINT16 errorStatus = 0; - struct timeval time; - CY_EVENT_NOTIFICATION_CB_FN callbackFn; - NOTIFICATION_CB_PARAM *cbParameters = (NOTIFICATION_CB_PARAM*)inputParameters; - - callbackFn = cbParameters->notificationCbFn; - device = (CY_DEVICE *)cbParameters->handle; - devHandle = device->devHandle; - callbackFn = cbParameters->notificationCbFn; - device->spiTransfer = transfer = libusb_alloc_transfer(0); - if (transfer == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error in allocating trasnfer \n"); - errorStatus |= CY_ERROR_EVENT_FAILED_BIT; - callbackFn (errorStatus); - goto END; - } - libusb_fill_interrupt_transfer (transfer, devHandle, device->interruptEndpoint, spiStatusBuffer, length, - spi_notification_cb, &transferCompleted, CY_EVENT_NOTIFICATION_TIMEOUT); - while (device->spiCancelEvent == false){ - if (libusb_submit_transfer (transfer)){ - CY_DEBUG_PRINT_ERROR ("CY:Error submitting spi interrupt token ... \n"); - errorStatus |= CY_ERROR_EVENT_FAILED_BIT; - callbackFn(errorStatus); - break; - } - time.tv_sec = 0; - time.tv_usec = 50;//polling timeout. - while (transferCompleted == 0){ - libusb_handle_events_timeout (glContext, &time); - } - transferCompleted = 0; - spiStatus = (spiStatusBuffer[1] << 8) | spiStatusBuffer[0]; - if (transfer->status == LIBUSB_TRANSFER_COMPLETED){ - CY_DEBUG_PRINT_INFO ("Successfully read and recieved data %d \n", transfer->actual_length); - if (spiStatus & CY_SPI_UNDERFLOW_ERROR){ - errorStatus |= (CY_SPI_TX_UNDERFLOW_BIT); - } - if (spiStatus & CY_SPI_BUS_ERROR){ - errorStatus |= (CY_SPI_BUS_ERROR_BIT); - } - callbackFn (errorStatus); - errorStatus = 0; - } - else{ - spiStatus |= CY_ERROR_EVENT_FAILED_BIT; - if (device->spiCancelEvent == false){ - pthread_join (device->spiThread, NULL); - device->spiThreadRunning = false; - CY_DEBUG_PRINT_ERROR ("CY:Error spi interrupt thread was cancelled... Libusb transmission error is %d \n", transfer->status); - callbackFn (spiStatus); - } - break; - } - } - libusb_free_transfer (transfer); -END: - free (inputParameters); - pthread_exit (NULL); - return NULL; -} - -CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CySetEventNotification( - CY_HANDLE handle, /*Valid handle to communicate with device*/ - CY_EVENT_NOTIFICATION_CB_FN notificationCbFn /*Call back function in case on error during Uart data transfers*/ - ) -{ - CY_DEVICE *device; - NOTIFICATION_CB_PARAM *args = NULL; - int ret; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (notificationCbFn == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE*)handle; - pthread_mutex_lock (&device->notificationLock); - args = (NOTIFICATION_CB_PARAM *)malloc (sizeof (NOTIFICATION_CB_PARAM)); - args->handle = handle; - args->notificationCbFn = notificationCbFn; - if (device->deviceType == CY_TYPE_SPI){ - if (device->spiThreadRunning) { - CY_DEBUG_PRINT_ERROR ("CY:Error already notification thread exists ... Function is %s \n", __func__); - free (args); - pthread_mutex_unlock (&device->notificationLock); - return CY_ERROR_STATUS_MONITOR_EXIST; - } - ret = pthread_create (&device->spiThread, NULL, spiSetEventNotifcation, (void *) args); - if (ret == 0){ - device->spiThreadRunning = true; - pthread_mutex_unlock (&device->notificationLock); - return CY_SUCCESS; - } - else { - pthread_join (device->spiThread, NULL); - device->spiThreadRunning = false; - free (args); - pthread_mutex_unlock (&device->notificationLock); - CY_DEBUG_PRINT_ERROR ("CY:Error creating spi notification thread ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - } - else if (device->deviceType == CY_TYPE_UART){ - if (device->uartThreadRunning) { - CY_DEBUG_PRINT_ERROR ("CY:Error already notification thread exists ... Function is %s \n", __func__); - free (args); - pthread_mutex_unlock (&device->notificationLock); - return CY_ERROR_STATUS_MONITOR_EXIST; - } - ret = pthread_create (&device->uartThread, NULL, uartSetEventNotifcation, (void *) args); - if (ret == 0){ - device->uartThreadRunning = true; - pthread_mutex_unlock (&device->notificationLock); - return CY_SUCCESS; - } - else { - pthread_join (device->uartThread, NULL); - device->uartThreadRunning = false; - free (args); - pthread_mutex_unlock (&device->notificationLock); - CY_DEBUG_PRINT_ERROR ("CY:Error creating uart notification thread ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - } - else { - CY_DEBUG_PRINT_ERROR ("CY:Error unknown device type ....Function is %s \n", __func__); - free (args); - pthread_mutex_unlock (&device->notificationLock); - return CY_ERROR_REQUEST_FAILED; - } -} -/*The API is used to cancel the uart Event notification*/ -CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyAbortEventNotification( - CY_HANDLE handle /*Valid handle to communicate with device*/ - ) -{ - CY_DEVICE *device; - device = (CY_DEVICE*)handle; - pthread_mutex_lock (&device->notificationLock); - if (device->deviceType == CY_TYPE_UART){ - if (!device->uartThreadRunning){ - CY_DEBUG_PRINT_ERROR ("CY:Error uart event notification not created ....function is %s \n", __func__); - pthread_mutex_unlock (&device->notificationLock); - return CY_ERROR_REQUEST_FAILED; - } - device->uartCancelEvent = true; - libusb_cancel_transfer (device->uartTransfer); - pthread_join (device->uartThread, NULL); - device->uartThreadRunning = false; - device->uartCancelEvent = false; - pthread_mutex_unlock (&device->notificationLock); - return CY_SUCCESS; - } - else if (device->deviceType == CY_TYPE_SPI){ - if (!device->spiThreadRunning){ - CY_DEBUG_PRINT_ERROR ("CY:Error spi event notification not created ....function is %s \n", __func__); - pthread_mutex_unlock (&device->notificationLock); - return CY_ERROR_REQUEST_FAILED; - } - device->spiCancelEvent = true; - libusb_cancel_transfer (device->spiTransfer); - pthread_join (device->spiThread, NULL); - device->spiThreadRunning = false; - device->spiCancelEvent = false; - pthread_mutex_unlock (&device->notificationLock); - return CY_SUCCESS; - } - else { - CY_DEBUG_PRINT_ERROR ("CY:Error.. unknown device type ....function is %s \n", __func__); - pthread_mutex_unlock (&device->notificationLock); - return CY_ERROR_REQUEST_FAILED; - } -} -/* -The API is used to programme user flash area -*/ -CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyProgUserFlash ( - CY_HANDLE handle, /*Valid device handle*/ - CY_DATA_BUFFER *progBuffer, /*data buffer containing buffer address, length to write*/ - UINT32 flashAddress, /*Address to the data is written*/ - UINT32 ioTimeout /*Timeout value of the API*/ - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - if ((progBuffer == NULL) || (progBuffer->buffer == NULL)) - return CY_ERROR_INVALID_PARAMETER; - - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_PROG_USER_FLASH_CMD; - wValue = 0; - wIndex = flashAddress; - wLength = progBuffer->length; - - CY_DEBUG_PRINT_INFO ("CY:The Length is %d , Value is %d and index is %d\n", wLength, wValue, wIndex); - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, progBuffer->buffer, wLength, ioTimeout); - if (rStatus > 0){ - (progBuffer->transferCount) = rStatus; - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - (progBuffer->transferCount) = 0; - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - (progBuffer->transferCount) = 0; - return CY_ERROR_REQUEST_FAILED; - } -} -/* -The API is used to programme user flash area -*/ -CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyReadUserFlash ( - CY_HANDLE handle, /*Valid device handle*/ - CY_DATA_BUFFER *readBuffer, /*data buffer containing buffer address, length to write*/ - UINT32 flashAddress, /*Address to the data is written*/ - UINT32 ioTimeout /*Timeout value of the API*/ - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - if (readBuffer == NULL) - return CY_ERROR_INVALID_PARAMETER; - - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_READ_USER_FLASH_CMD; - wValue = 0; - wIndex = flashAddress; - wLength = readBuffer->length; - - CY_DEBUG_PRINT_INFO ("CY:The Length is %d , Value is %d and index is %d\n", wLength, wValue, wIndex); - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, readBuffer->buffer, wLength, ioTimeout); - if (rStatus > 0){ - (readBuffer->transferCount) = rStatus; - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - (readBuffer->transferCount) = 0; - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - (readBuffer->transferCount) = 0; - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This API is used to get the signature of the device. It would be CYUS when we are in actual device mode - and CYBL when we are bootloader mode - */ -CY_RETURN_STATUS CyGetSignature ( - CY_HANDLE handle, - UCHAR *signature - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_GET_SIGNATURE_CMD; - wValue = 0x00; - wIndex = 0x00; - wLength = CY_GET_SIGNATURE_LEN; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)signature, wLength, ioTimeout); - if (rStatus > 0){ - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} +/* + * Miscellaneous routines of Cypress USB Serial + * Copyright (C) 2013 Cypress Semiconductor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "CyUSBCommon.h" + +typedef struct NOTIFICATION_CB_PARAM{ + + CY_HANDLE handle; + CY_EVENT_NOTIFICATION_CB_FN notificationCbFn; + +}NOTIFICATION_CB_PARAM; +/* + This API is used to Read the Bootloder version + */ +CY_RETURN_STATUS CyGetFirmwareVersion( + CY_HANDLE handle, + CY_FIRMWARE_VERSION *firmwareVersion + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_GET_VERSION_CMD; + wValue = 0x00; + wIndex = 0x00; + wLength = CY_GET_FIRMWARE_VERSION_LEN; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)firmwareVersion, wLength, ioTimeout); + + if (rStatus > 0){ + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* +The API resets the device +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyResetDevice ( + CY_HANDLE handle /*Valid device handle*/ + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle \n"); + return CY_ERROR_INVALID_HANDLE; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_DEVICE_RESET_CMD; + wValue = 0xA6B6; + wIndex = 0xADBA; + wLength = 0; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + //return buffer will tell the status of the command + if (rStatus == LIBUSB_SUCCESS) + return CY_SUCCESS; + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CySetGpioValue ( + CY_HANDLE handle, /*Valid device handle*/ + UINT8 gpioNumber, /*GPIO configuration value*/ + UINT8 value /*Value that needs to be set*/ + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest, buffer[CY_GPIO_SET_LEN]; + int rStatus; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (value) + value = 1; + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_GPIO_SET_VALUE_CMD; + wValue = gpioNumber; + wIndex = value; + wLength = 0; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, buffer, wLength, ioTimeout); + if (rStatus >= 0){ + CY_DEBUG_PRINT_INFO ("CY: Get Configuration of GPIO succedded...size is %d \n", rStatus); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyGetGpioValue ( + CY_HANDLE handle, /*Valid device handle*/ + UINT8 gpioNumber, /*GPIO configuration value*/ + UINT8 *value /*Value that needs to be set*/ + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest, buffer[CY_GPIO_GET_LEN]; + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_GPIO_GET_VALUE_CMD; + wValue = gpioNumber; + wIndex = 0x00; + wLength = CY_GPIO_GET_LEN; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, buffer, wLength, ioTimeout); + if (rStatus == CY_GPIO_GET_LEN){ + CY_DEBUG_PRINT_INFO ("CY: Get GPIO Configuration succedded...size is %d \n", rStatus); + //return buffer will tell the status of the command + if (buffer[0] == 0){ + (*value) = buffer[1]; + return CY_SUCCESS; + } + else + return CY_ERROR_REQUEST_FAILED; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +static void LIBUSB_CALL uart_notification_cb(struct libusb_transfer *transfer) +{ + UINT32 *completed = transfer->user_data; + *completed = 1; +} + +void* uartSetEventNotifcation (void *inputParameters) +{ + int rStatus, transferCompleted = 0, length = CY_UART_EVENT_NOTIFICATION_LEN; + CY_DEVICE *device; + libusb_device_handle *devHandle; + struct libusb_transfer *transfer; + UINT16 errorStatus = 0; + UCHAR uartStatus[CY_UART_EVENT_NOTIFICATION_LEN]; + struct timeval time; + CY_EVENT_NOTIFICATION_CB_FN callbackFn; + NOTIFICATION_CB_PARAM *cbParameters = (NOTIFICATION_CB_PARAM*)inputParameters; + callbackFn = cbParameters->notificationCbFn; + + device = (CY_DEVICE *)cbParameters->handle; + devHandle = device->devHandle; + callbackFn = cbParameters->notificationCbFn; + device->uartTransfer = transfer = libusb_alloc_transfer(0); + if (transfer == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error in allocating trasnfer \n"); + errorStatus |= CY_ERROR_EVENT_FAILED_BIT; + callbackFn(errorStatus); + goto END; + } + while (device->uartCancelEvent == false){ + libusb_fill_interrupt_transfer (transfer, devHandle, device->interruptEndpoint, uartStatus, length, + uart_notification_cb, &transferCompleted, CY_EVENT_NOTIFICATION_TIMEOUT); + rStatus = libusb_submit_transfer (transfer); + if (rStatus){ + CY_DEBUG_PRINT_ERROR ("CY:Error submitting uart interrupt token ... Libusb error is %d\n", rStatus); + errorStatus |= CY_ERROR_EVENT_FAILED_BIT; + callbackFn(errorStatus); + break; + } + time.tv_sec = 0; + time.tv_usec = 50;//polling timeout. + while (transferCompleted == 0){ + libusb_handle_events_timeout (NULL, &time); + } + transferCompleted = 0; + if (transfer->status == LIBUSB_TRANSFER_COMPLETED){ + CY_DEBUG_PRINT_INFO ("Successfully read and recieved data %d \n", transfer->actual_length); + memcpy (&errorStatus, &uartStatus[8], 2); + printf ("%x %x ", uartStatus[8], uartStatus[9]); + callbackFn (errorStatus); + errorStatus = 0; + } + else{ + errorStatus |= CY_ERROR_EVENT_FAILED_BIT; + if (device->uartCancelEvent == false){ + CY_DEBUG_PRINT_ERROR ("CY:Error uart interrupt thread encountered error... Libusb transmission error is %d \n", transfer->status); + device->uartThreadId = 0; + callbackFn(errorStatus); + } + break; + } + } + CY_DEBUG_PRINT_INFO ("Exiting notification thread \n"); + libusb_free_transfer (transfer); +END: + free (inputParameters); + return NULL; +} + +static void LIBUSB_CALL spi_notification_cb(struct libusb_transfer *transfer) +{ + UINT32 *completed = transfer->user_data; + *completed = 1; +} + +void* spiSetEventNotifcation (void *inputParameters) +{ + int transferCompleted = 0, length = CY_SPI_EVENT_NOTIFICATION_LEN; + CY_DEVICE *device; + libusb_device_handle *devHandle; + struct libusb_transfer *transfer; + UINT8 spiStatus = 0; + UINT16 errorStatus = 0; + struct timeval time; + CY_EVENT_NOTIFICATION_CB_FN callbackFn; + NOTIFICATION_CB_PARAM *cbParameters = (NOTIFICATION_CB_PARAM*)inputParameters; + + callbackFn = cbParameters->notificationCbFn; + device = (CY_DEVICE *)cbParameters->handle; + devHandle = device->devHandle; + callbackFn = cbParameters->notificationCbFn; + device->spiTransfer = transfer = libusb_alloc_transfer(0); + if (transfer == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error in allocating trasnfer \n"); + errorStatus |= CY_ERROR_EVENT_FAILED_BIT; + callbackFn (errorStatus); + goto END; + } + libusb_fill_interrupt_transfer (transfer, devHandle, device->interruptEndpoint, &spiStatus, length, + spi_notification_cb, &transferCompleted, CY_EVENT_NOTIFICATION_TIMEOUT); + while (device->spiCancelEvent == false){ + if (libusb_submit_transfer (transfer)){ + CY_DEBUG_PRINT_ERROR ("CY:Error submitting spi interrupt token ... \n"); + errorStatus |= CY_ERROR_EVENT_FAILED_BIT; + callbackFn(errorStatus); + break; + } + time.tv_sec = 0; + time.tv_usec = 50;//polling timeout. + while (transferCompleted == 0){ + libusb_handle_events_timeout (NULL, &time); + } + transferCompleted = 0; + if (transfer->status == LIBUSB_TRANSFER_COMPLETED){ + CY_DEBUG_PRINT_INFO ("Successfully read and recieved data %d \n", transfer->actual_length); + if (spiStatus & CY_SPI_UNDERFLOW_ERROR){ + errorStatus |= (CY_SPI_TX_UNDERFLOW_BIT); + } + if (spiStatus & CY_SPI_BUS_ERROR){ + errorStatus |= (CY_SPI_BUS_ERROR_BIT); + } + callbackFn (errorStatus); + errorStatus = 0; + } + else{ + spiStatus |= CY_ERROR_EVENT_FAILED_BIT; + if (device->spiCancelEvent == false){ + device->spiThreadId = 0; + CY_DEBUG_PRINT_ERROR ("CY:Error spi interrupt thread was cancelled... Libusb transmission error is %d \n", transfer->status); + callbackFn (spiStatus); + } + break; + } + } + libusb_free_transfer (transfer); +END: + + free (inputParameters); + pthread_exit (NULL); + return NULL; +} + +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CySetEventNotification( + CY_HANDLE handle, /*Valid handle to communicate with device*/ + CY_EVENT_NOTIFICATION_CB_FN notificationCbFn /*Call back function in case on error during Uart data transfers*/ + ) +{ + CY_DEVICE *device; + NOTIFICATION_CB_PARAM *args = NULL; + int ret; + pthread_t threadID; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (notificationCbFn == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE*)handle; + pthread_mutex_lock (&device->notificationLock); + args = (NOTIFICATION_CB_PARAM *)malloc (sizeof (NOTIFICATION_CB_PARAM)); + args->handle = handle; + args->notificationCbFn = notificationCbFn; + if (device->deviceType == CY_TYPE_SPI){ + if (device->spiThreadId != 0) { + CY_DEBUG_PRINT_ERROR ("CY:Error already notification thread exists ... Function is %s \n", __func__); + pthread_mutex_unlock (&device->notificationLock); + return CY_ERROR_STATUS_MONITOR_EXIST; + } + ret = pthread_create (&threadID, NULL, spiSetEventNotifcation, (void *) args); + if (ret == 0){ + device->spiThreadId = threadID; + pthread_mutex_unlock (&device->notificationLock); + return CY_SUCCESS; + } + else { + device->spiThreadId = 0; + free (args); + pthread_mutex_unlock (&device->notificationLock); + CY_DEBUG_PRINT_ERROR ("CY:Error creating spi notification thread ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + } + else if (device->deviceType == CY_TYPE_UART){ + if (device->uartThreadId != 0) { + CY_DEBUG_PRINT_ERROR ("CY:Error already notification thread exists ... Function is %s \n", __func__); + pthread_mutex_unlock (&device->notificationLock); + return CY_ERROR_STATUS_MONITOR_EXIST; + } + ret = pthread_create (&threadID, NULL, uartSetEventNotifcation, (void *) args); + if (ret == 0){ + device->uartThreadId = threadID; + pthread_mutex_unlock (&device->notificationLock); + return CY_SUCCESS; + } + else { + device->uartThreadId = 0; + free (args); + pthread_mutex_unlock (&device->notificationLock); + CY_DEBUG_PRINT_ERROR ("CY:Error creating uart notification thread ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error unknown device type ....Function is %s \n", __func__); + pthread_mutex_unlock (&device->notificationLock); + return CY_ERROR_REQUEST_FAILED; + } +} +/*The API is used to cancel the uart Event notification*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyAbortEventNotification( + CY_HANDLE handle /*Valid handle to communicate with device*/ + ) +{ + CY_DEVICE *device; + device = (CY_DEVICE*)handle; + pthread_mutex_lock (&device->notificationLock); + if (device->deviceType == CY_TYPE_UART){ + if ((device->uartThreadId == 0)){ + CY_DEBUG_PRINT_ERROR ("CY:Error uart event notification not created ....function is %s \n", __func__); + pthread_mutex_unlock (&device->notificationLock); + return CY_ERROR_REQUEST_FAILED; + } + device->uartCancelEvent = true; + libusb_cancel_transfer (device->uartTransfer); + pthread_join (device->uartThreadId, NULL); + device->uartThreadId = 0; + device->uartCancelEvent = false; + pthread_mutex_unlock (&device->notificationLock); + return CY_SUCCESS; + } + else if (device->deviceType == CY_TYPE_SPI){ + if ((device->spiThreadId == 0)){ + CY_DEBUG_PRINT_ERROR ("CY:Error spi event notification not created ....function is %s \n", __func__); + pthread_mutex_unlock (&device->notificationLock); + return CY_ERROR_REQUEST_FAILED; + } + device->spiCancelEvent = true; + libusb_cancel_transfer (device->spiTransfer); + pthread_join (device->spiThreadId, NULL); + device->spiThreadId = 0; + device->spiCancelEvent = false; + pthread_mutex_unlock (&device->notificationLock); + return CY_SUCCESS; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error.. unknown device type ....function is %s \n", __func__); + pthread_mutex_unlock (&device->notificationLock); + return CY_ERROR_REQUEST_FAILED; + } +} +/* +The API is used to programme user flash area +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyProgUserFlash ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER *progBuffer, /*data buffer containing buffer address, length to write*/ + UINT32 flashAddress, /*Address to the data is written*/ + UINT32 ioTimeout /*Timeout value of the API*/ + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if ((progBuffer == NULL) || (progBuffer->buffer == NULL)) + return CY_ERROR_INVALID_PARAMETER; + + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_PROG_USER_FLASH_CMD; + wValue = 0; + wIndex = flashAddress; + wLength = progBuffer->length; + + CY_DEBUG_PRINT_INFO ("CY:The Length is %d , Value is %d and index is %d\n", wLength, wValue, wIndex); + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, progBuffer->buffer, wLength, ioTimeout); + if (rStatus > 0){ + (progBuffer->transferCount) = rStatus; + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + (progBuffer->transferCount) = 0; + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + (progBuffer->transferCount) = 0; + return CY_ERROR_REQUEST_FAILED; + } +} +/* +The API is used to programme user flash area +*/ +CYWINEXPORT CY_RETURN_STATUS WINCALLCONVEN CyReadUserFlash ( + CY_HANDLE handle, /*Valid device handle*/ + CY_DATA_BUFFER *readBuffer, /*data buffer containing buffer address, length to write*/ + UINT32 flashAddress, /*Address to the data is written*/ + UINT32 ioTimeout /*Timeout value of the API*/ + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + if ((readBuffer == NULL) || (readBuffer == NULL)) + return CY_ERROR_INVALID_PARAMETER; + + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_READ_USER_FLASH_CMD; + wValue = 0; + wIndex = flashAddress; + wLength = readBuffer->length; + + CY_DEBUG_PRINT_INFO ("CY:The Length is %d , Value is %d and index is %d\n", wLength, wValue, wIndex); + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, readBuffer->buffer, wLength, ioTimeout); + if (rStatus > 0){ + (readBuffer->transferCount) = rStatus; + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + (readBuffer->transferCount) = 0; + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + (readBuffer->transferCount) = 0; + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This Api is used to get the signature of the device. It would be CYUS when we are in actual device mode + and CYBL when we are bootloader modeñ + */ +CY_RETURN_STATUS CyGetSignature ( + CY_HANDLE handle, + UCHAR *signature + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_GET_SIGNATURE_CMD; + wValue = 0x00; + wIndex = 0x00; + wLength = CY_GET_SIGNATURE_LEN; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)signature, wLength, ioTimeout); + if (rStatus > 0){ + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} diff --git a/cylib/lib/cyphdc.c b/configutility/linux/library/cyphdc.c similarity index 95% rename from cylib/lib/cyphdc.c rename to configutility/linux/library/cyphdc.c index a5a6434..9dd44b9 100644 --- a/cylib/lib/cyphdc.c +++ b/configutility/linux/library/cyphdc.c @@ -1,130 +1,130 @@ -/* - * PHDC routines of Cypress USB Serial - * Copyright (C) 2013 Cypress Semiconductor - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "CyUSBCommon.h" -/* - PHDC clear feature -*/ -CY_RETURN_STATUS CyPhdcClrFeature (CY_HANDLE handle) -{ - - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_PHDC_CLR_FEATURE; - wValue = CY_PHDC_CLR_FEATURE_WVALUE; - wIndex = device->interfaceNum; - wLength = 0; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus == 0) - return CY_SUCCESS; - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } - return CY_SUCCESS; -} -/* - PHDC set feature -*/ -CY_RETURN_STATUS CyPhdcSetFeature (CY_HANDLE handle) -{ - - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_PHDC_SET_FEATURE; - wValue = CY_PHDC_SET_FEATURE_WVALUE; - wIndex = device->interfaceNum; - wLength = 0; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus == 0) - return CY_SUCCESS; - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - PHDC clear feature -*/ -CY_RETURN_STATUS CyPhdcGetStatus (CY_HANDLE handle, UINT16 *dataStatus) -{ - - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT ; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - bmRequestType = CY_CLASS_INTERFACE_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_PHDC_GET_DATA_STATUS; - wValue = 0x00; - wIndex = device->interfaceNum; - wLength = CY_PHDC_GET_STATUS_LEN; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)dataStatus, wLength, ioTimeout); - if (rStatus > 0) - return CY_SUCCESS; - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} +/* + * PHDC routines of Cypress USB Serial + * Copyright (C) 2013 Cypress Semiconductor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "CyUSBCommon.h" +/* + PHDC clear feature +*/ +CY_RETURN_STATUS CyPhdcClrFeature (CY_HANDLE handle) +{ + + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_PHDC_CLR_FEATURE; + wValue = CY_PHDC_CLR_FEATURE_WVALUE; + wIndex = device->interfaceNum; + wLength = 0; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus == 0) + return CY_SUCCESS; + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } + return CY_SUCCESS; +} +/* + PHDC set feature +*/ +CY_RETURN_STATUS CyPhdcSetFeature (CY_HANDLE handle) +{ + + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_PHDC_SET_FEATURE; + wValue = CY_PHDC_SET_FEATURE_WVALUE; + wIndex = device->interfaceNum; + wLength = 0; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus == 0) + return CY_SUCCESS; + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + PHDC clear feature +*/ +CY_RETURN_STATUS CyPhdcGetStatus (CY_HANDLE handle, UINT16 *dataStatus) +{ + + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT ; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + bmRequestType = CY_CLASS_INTERFACE_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_PHDC_GET_DATA_STATUS; + wValue = 0x00; + wIndex = device->interfaceNum; + wLength = CY_PHDC_GET_STATUS_LEN; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)dataStatus, wLength, ioTimeout); + if (rStatus > 0) + return CY_SUCCESS; + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..function is %s \n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ...libusb error is %d!\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} diff --git a/cylib/lib/cyspi.c b/configutility/linux/library/cyspi.c similarity index 91% rename from cylib/lib/cyspi.c rename to configutility/linux/library/cyspi.c index e33a479..56beee5 100644 --- a/cylib/lib/cyspi.c +++ b/configutility/linux/library/cyspi.c @@ -1,644 +1,644 @@ -/* - * SPI routines of Cypress USB Serial - * Copyright (C) 2013 Cypress Semiconductor - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "CyUSBCommon.h" -#include -#include -#pragma pack (1) -typedef struct args { - CY_HANDLE handle; - UCHAR *readBuffer; - UINT32 length; - UINT32 ioTimeout; - CY_RETURN_STATUS rStatus; - UINT32 transferCount; -}args; - -typedef struct -{ - UINT32 frequency; - UINT8 dataWidth; - UCHAR mode; - UCHAR xferMode; - BOOL isMsbFirst; - BOOL isMaster; - BOOL isContinuous; - BOOL isSelectPrecede; - BOOL cpha; - BOOL cpol; - BOOL isLoopback; - UCHAR reserved[2]; -} CyUsSpiConfig_t; -#pragma pack() - -struct timeval startSpiTimeWrite, endSpiTimeWrite, startSpiTimeRead, endSpiTimeRead; -//Timer helper functions for proper timing -void startSpiTick (bool isWrite) { - if (isWrite) - gettimeofday (&startSpiTimeWrite, NULL); - else - gettimeofday (&startSpiTimeRead, NULL); -} - -UINT32 getSpiLapsedTime (bool isWrite){ - - signed int currentTime_sec, currentTime_usec, currentTime; - if (isWrite){ - gettimeofday (&endSpiTimeWrite, NULL); - currentTime_sec = (endSpiTimeWrite.tv_sec - startSpiTimeWrite.tv_sec) * 1000; - currentTime_usec = ((endSpiTimeWrite.tv_usec - startSpiTimeWrite.tv_usec)) / 1000; - currentTime = currentTime_sec + currentTime_usec; - return (unsigned int)currentTime; - } - else{ - gettimeofday (&endSpiTimeRead, NULL); - currentTime_sec = (endSpiTimeRead.tv_sec - startSpiTimeRead.tv_sec) * 1000; - currentTime_usec = ((endSpiTimeRead.tv_usec - startSpiTimeRead.tv_usec)) / 1000; - currentTime = currentTime_sec + currentTime_usec; - return (unsigned int)currentTime; - } -} -/* - This API gets the current SPI config - for the particluar interface of the device - */ -CY_RETURN_STATUS CyGetSpiConfig ( - CY_HANDLE handle, - CY_SPI_CONFIG *spiConfig - ) -{ - UINT16 wValue, wIndex, wLength; - UINT16 bmRequestType, bmRequest; - CyUsSpiConfig_t localSpiConfig; - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - UINT8 scbIndex = 0; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (spiConfig == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_SPI) { - CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not spi ..Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (device->interfaceNum > 0) - scbIndex = 1; - - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_SPI_GET_CONFIG_CMD; - wValue = (scbIndex << CY_SCB_INDEX_POS); - wIndex = 0; - wLength = CY_SPI_CONFIG_LEN; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)&localSpiConfig, wLength, ioTimeout); - if (rStatus == CY_SPI_CONFIG_LEN){ - //CY_DUMP_DATA ((unsigned char*)&localSpiConfig, wLength); - CY_DEBUG_PRINT_INFO ("CY: Read SPI config successfully %d\n", rStatus); - spiConfig->frequency = localSpiConfig.frequency; - spiConfig->dataWidth = localSpiConfig.dataWidth; - spiConfig->protocol = localSpiConfig.mode; - spiConfig->isMsbFirst = localSpiConfig.isMsbFirst; - spiConfig->isMaster = localSpiConfig.isMaster; - spiConfig->isContinuousMode = localSpiConfig.isContinuous; - spiConfig->isSelectPrecede = localSpiConfig.isSelectPrecede; - spiConfig->isCpha = localSpiConfig.cpha; - spiConfig->isCpol = localSpiConfig.cpol; - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ... Function is %s\n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s...libusb error is %d !\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This API sets SPI config of the device for that - interface - */ -CY_RETURN_STATUS CySetSpiConfig ( - CY_HANDLE handle, - CY_SPI_CONFIG *spiConfig - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - CyUsSpiConfig_t localSpiConfig; - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - UINT8 scbIndex = 0; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (spiConfig == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_SPI) { - CY_DEBUG_PRINT_ERROR ("CY:Error device type is not spi ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (spiConfig->frequency < 1000 || spiConfig->frequency > 3000000){ - CY_DEBUG_PRINT_ERROR ("CY:Error frequency trying to set in out of range ... Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - if (spiConfig->protocol == CY_SPI_TI){ - if (!(spiConfig->isCpol == false && spiConfig->isCpha == true && spiConfig->isContinuousMode == false)){ - CY_DEBUG_PRINT_ERROR ("CY:Error ... Wrong configuration for SPI TI mode \n"); - return CY_ERROR_REQUEST_FAILED; - } - } - if (spiConfig->protocol == CY_SPI_NS){ - if (!(spiConfig->isCpol == false && spiConfig->isCpha == false && spiConfig->isSelectPrecede == false)){ - CY_DEBUG_PRINT_ERROR ("CY:Error ... Wrong configuration for SPI ti mode \n"); - return CY_ERROR_REQUEST_FAILED; - } - } - else{ - if (spiConfig->isSelectPrecede != false){ - CY_DEBUG_PRINT_ERROR ("CY:Error ... Wrong configuration for SPI motorola mode \n"); - return CY_ERROR_REQUEST_FAILED; - } - } - if (device->interfaceNum > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_SPI_SET_CONFIG_CMD; - wValue = (scbIndex << CY_SCB_INDEX_POS); - wIndex = 0; - wLength = CY_SPI_CONFIG_LEN; - //We will not expose all the spi config structure elements to user. - //Fill in rest of the values. - - memset (&localSpiConfig, 0, CY_SPI_CONFIG_LEN); - localSpiConfig.frequency = spiConfig->frequency; - localSpiConfig.dataWidth = spiConfig->dataWidth; - localSpiConfig.mode = spiConfig->protocol; - localSpiConfig.isMsbFirst = spiConfig->isMsbFirst; - localSpiConfig.isMaster = spiConfig->isMaster; - localSpiConfig.isContinuous = spiConfig->isContinuousMode; - localSpiConfig.isSelectPrecede = spiConfig->isSelectPrecede; - localSpiConfig.cpha = spiConfig->isCpha; - localSpiConfig.cpol = spiConfig->isCpol; - //CY_DUMP_DATA ((unsigned char*)&localSpiConfig, wLength); - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)&localSpiConfig, wLength, ioTimeout); - if (rStatus == CY_SPI_CONFIG_LEN){ - CY_DEBUG_PRINT_INFO ("CY: Setting SPI config success ...\n"); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Time out error ..Function is %s\n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ... !libusb error is %d\n", __func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/*Api will reset the spi module*/ -CY_RETURN_STATUS CySpiReset (CY_HANDLE handle) -{ - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT16 wValue, wIndex, wLength, bmRequestType, bmRequest;; - UINT16 scbIndex = 0; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_SPI) { - CY_DEBUG_PRINT_ERROR ("CY:Error device type is not spi ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - scbIndex = device->interfaceNum; - if (scbIndex > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_SPI_RESET_CMD; - wValue = ((scbIndex << CY_SCB_INDEX_POS)); - wIndex = 0; - wLength = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus < 0){ - CY_DEBUG_PRINT_ERROR ("CY:Error in sending spi reset command...Libusb error is %d\n", rStatus); - return rStatus; - } - return CY_SUCCESS; -} -/* - This API reads SPI data from the specified interface of the device - interface - */ - -static void LIBUSB_CALL spi_read_cb(struct libusb_transfer *transfer) -{ - UINT32 *completed = transfer->user_data; - *completed = 1; -} -//We adopted for async method here because there are 2 thread polling same fd -// i.e both read and write are polling same fd when one event triggers and other one is -//not completed then another thread will wait for more than 60sec. -CY_RETURN_STATUS CySpiRead ( - CY_HANDLE handle, - CY_DATA_BUFFER *readBuffer, - UINT32 ioTimeout - ) -{ - struct libusb_transfer *readTransfer; - CY_DEVICE *device; - libusb_device_handle *devHandle; - int readCompleted = 0; - struct timeval time; - int r; - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - readBuffer->transferCount = 0; - readTransfer = libusb_alloc_transfer(0); - if (readTransfer == NULL){ - CY_DEBUG_PRINT_ERROR("CY:Error in allocating transfers \n"); - return CY_ERROR_ALLOCATION_FAILED; - } - libusb_fill_bulk_transfer(readTransfer, devHandle, device->inEndpoint, readBuffer->buffer, readBuffer->length, - spi_read_cb, &readCompleted, ioTimeout); - libusb_submit_transfer (readTransfer); - time.tv_sec = (ioTimeout / 1000); - time.tv_usec = ((ioTimeout % 1000) * 1000);//polling timeout. - while (readCompleted == 0){ - r = libusb_handle_events_timeout_completed(glContext, &time, &readCompleted); - if (r < 0) { - if (r == LIBUSB_ERROR_INTERRUPTED) - continue; - libusb_cancel_transfer(readTransfer); - while (!readCompleted) - if (libusb_handle_events_completed(glContext, &readCompleted) < 0) - break; - readBuffer->transferCount = readTransfer->actual_length; - libusb_free_transfer(readTransfer); - return r; - } - } - if (readTransfer->status == LIBUSB_TRANSFER_COMPLETED){ - readBuffer->transferCount = readTransfer->actual_length; - libusb_free_transfer (readTransfer); - return CY_SUCCESS; - } - else{ - if (readTransfer->status == LIBUSB_TRANSFER_TIMED_OUT){ - //We should not be hitting this case.. As the time out is infinite!! - CY_DEBUG_PRINT_ERROR ("CY:Timeout error in doing SPI read/write .... %d Libusb errors %d\n", - readTransfer->actual_length,readTransfer->status); - readBuffer->transferCount = readTransfer->actual_length; - CySpiReset (handle); - libusb_free_transfer (readTransfer); - return CY_ERROR_IO_TIMEOUT; - } - if (readTransfer->status == LIBUSB_TRANSFER_OVERFLOW){ - //Need to handle this properly! - CY_DEBUG_PRINT_ERROR ("CY:OverFlow error in doing SPI read/write .... Libusb errors %d %d \n", - readTransfer->status, readTransfer->actual_length); - readBuffer->transferCount = readTransfer->actual_length; - CySpiReset (handle); - libusb_free_transfer (readTransfer); - return CY_ERROR_BUFFER_OVERFLOW; - } - if (readTransfer->status != LIBUSB_TRANSFER_COMPLETED){ - CY_DEBUG_PRINT_ERROR ("CY:Error in doing SPI read/write .... Libusb errors are %d %d\n", - readTransfer->status, readTransfer->actual_length); - readBuffer->transferCount = readTransfer->actual_length; - CySpiReset (handle); - libusb_free_transfer (readTransfer); - //If timer is not completed then it implies we have timeout error - return CY_ERROR_REQUEST_FAILED; - } - } - return CY_ERROR_REQUEST_FAILED; -} -/*Internal SPI get status API for Write operation*/ -CY_RETURN_STATUS CyGetSpiStatus (CY_HANDLE handle, - int *spiStatus - ) -{ - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT16 wValue, wIndex, wLength, bmRequestType, bmRequest;; - UINT16 scbIndex = 0; - UINT32 ioTimeout = 0; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_SPI) { - CY_DEBUG_PRINT_ERROR ("CY:Error device type is not spi ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - scbIndex = device->interfaceNum; - if (scbIndex > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_SPI_GET_STATUS_CMD; - wValue = ((scbIndex << CY_SCB_INDEX_POS)); - wIndex = 0; - wLength = CY_SPI_GET_STATUS_LEN; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, (UCHAR*)spiStatus, wLength, ioTimeout); - if (rStatus < CY_SPI_GET_STATUS_LEN){ - CY_DEBUG_PRINT_INFO ("CY:Error in sending spi Get Status command...Libusb error is %d\n", rStatus); - return rStatus; - } - return CY_SUCCESS; -} -/* Function to write on to SPI alone*/ -CY_RETURN_STATUS CySpiWrite ( - CY_HANDLE handle, - CY_DATA_BUFFER *writeBuffer, - UINT32 ioTimeout - ) -{ - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - int spiStatus = 1; - UINT32 newIoTimeout = ioTimeout, elapsedTime = 0, loopCount = 1; - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_SPI) { - CY_DEBUG_PRINT_ERROR ("CY:Error device type is not spi ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - startSpiTick (true); - rStatus = libusb_bulk_transfer (devHandle, device->outEndpoint, writeBuffer->buffer, writeBuffer->length, - (int*)&(writeBuffer->transferCount), newIoTimeout); - elapsedTime = getSpiLapsedTime(true); - newIoTimeout = ioTimeout - elapsedTime; - //because we have a sleep of 1 msec after every getstatus - if (newIoTimeout) - loopCount = (newIoTimeout); - if (rStatus == LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_INFO ("CY: Successfully written SPI data.. %d bytes Read ...\n", writeBuffer->transferCount); - while (loopCount){ - usleep (1000); - rStatus = CyGetSpiStatus (handle, &spiStatus); - if (rStatus == CY_SUCCESS){ - if (spiStatus == 0){ - return CY_SUCCESS; - } - } - else { - //Should never hit this case - CY_DEBUG_PRINT_ERROR ("CY:Error in getting spi status \n"); - return CY_ERROR_REQUEST_FAILED; - } - if (ioTimeout) - loopCount--; - } - if (loopCount == 0 && spiStatus > 0){ - writeBuffer->length = 0; - CySpiReset (handle); - return CY_ERROR_IO_TIMEOUT; - } - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:Error TimeOut ...function is %s\n", __func__); - CySpiReset (handle); - return CY_ERROR_IO_TIMEOUT; - } - else if (rStatus == LIBUSB_ERROR_PIPE){ - CY_DEBUG_PRINT_ERROR ("CY:Error Pipe error..function is %s\n", __func__); - CySpiReset (handle); - CyResetPipe (handle, device->outEndpoint); - return CY_ERROR_PIPE_HALTED; - } - else if (rStatus == LIBUSB_ERROR_OVERFLOW){ - CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow...function is %s\n", __func__); - return CY_ERROR_BUFFER_OVERFLOW; - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - CY_DEBUG_PRINT_ERROR ("CY:Error Device Disconnected ...function is %s\n", __func__); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else { - CY_DEBUG_PRINT_ERROR ("CY:Error in writing SPI data ...Libusb Error is %d and bytes read is %d!\n", rStatus, writeBuffer->transferCount); - return CY_ERROR_REQUEST_FAILED; - } - return CY_ERROR_REQUEST_FAILED; -}/* - API to wrap up the data - */ -void spiCollectData (void *inputParameters) { - - UINT32 readLength = 0, length; - CY_DATA_BUFFER readBuffer; - args *inputData = (args *) inputParameters; - UCHAR *buffer; - CY_RETURN_STATUS rStatus = CY_SUCCESS; - buffer = readBuffer.buffer = inputData->readBuffer; - length = readBuffer.length = inputData->length; - CY_HANDLE handle = inputData->handle; - int newTimeout = inputData->ioTimeout, elapsedTime; - while (readLength != length && newTimeout >= 0 && rStatus == CY_SUCCESS){ - //Get current time - //Buffer is pointing to next address where we are suppose to fill the data - readBuffer.buffer = &buffer[readLength]; - //Updated length which total length minus the total length of data read - readBuffer.length = length - readLength; - //Libusb fix for mac os!! - //ISSUE:when api times out in MAC it comes back and say read length = 0!! -#ifdef __APPLE__ - if (readBuffer.length > 64) - readBuffer.length = 64; -#endif - startSpiTick (false); - rStatus = CySpiRead (handle, &readBuffer, newTimeout); - elapsedTime = getSpiLapsedTime (false); - //Do this only when newTimeout is non zero - if (newTimeout){ - newTimeout = newTimeout - elapsedTime; - //If timeout is 0 then libusb considers that as infinite - //So forcefully make the loop to comeout - if (newTimeout <= 0) - rStatus = CY_ERROR_IO_TIMEOUT; - } - if (rStatus != CY_SUCCESS){ - readLength += readBuffer.transferCount; - break; - } - readLength += readBuffer.transferCount; - } - if (readLength != length && rStatus == CY_ERROR_IO_TIMEOUT){ - CySpiReset (handle); - } - inputData->transferCount = readLength; - inputData->rStatus = rStatus; -} -/* - * Api used to do read as well as write on spi - */ -CY_RETURN_STATUS CySpiReadWrite (CY_HANDLE handle, - CY_DATA_BUFFER *readBuffer, - CY_DATA_BUFFER *writeBuffer, - UINT32 ioTimeout) -{ - struct args threadParameter; - UINT32 ret; - pthread_t readThreadID; - CY_DEVICE *device; - libusb_device_handle *devHandle; - CY_RETURN_STATUS rStatus; - unsigned short spiTransferMode = 0, scbIndex = 0; - UINT16 wValue, wIndex = 0, wLength; - UINT16 bmRequestType, bmRequest; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (readBuffer == NULL && writeBuffer == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_SPI) { - CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not spi .. \n"); - return CY_ERROR_REQUEST_FAILED; - } - //Set both the bits and change it accordingly based on parameters parameters - spiTransferMode |= ((CY_SPI_READ_BIT) | (CY_SPI_WRITE_BIT)); - if ((readBuffer == NULL || readBuffer->length == 0 || readBuffer->buffer == NULL)) - spiTransferMode &= ~(CY_SPI_READ_BIT); - if ((writeBuffer == NULL || writeBuffer->length == 0 || writeBuffer->buffer == NULL)) - spiTransferMode &= ~(CY_SPI_WRITE_BIT); - //if none of the bit is set it implies parameters sent is wrong - if (spiTransferMode == 0){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - if (device->interfaceNum > 0) - scbIndex = 1; - //In read only case we take length to be equal to readBuffer length. - //But in write or in write/read case we take length = writeBuffer length. - if (spiTransferMode == 0x1) - wIndex = readBuffer->length; - else - wIndex = writeBuffer->length; - spiTransferMode |= (scbIndex << 15); - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_SPI_READ_WRITE_CMD; - wValue = (spiTransferMode); - wLength = 0; - if (pthread_mutex_trylock (&device->writeLock) == 0){ - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, 5000); - if (rStatus){ - CY_DEBUG_PRINT_ERROR ("CY:Error Sending spi read write vendor command failed ... Libusb error is %d\n", rStatus); - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_REQUEST_FAILED; - } - //Read Bit is not set then write Only - if (!(spiTransferMode & CY_SPI_READ_BIT)) { - writeBuffer->transferCount = 0; - if (readBuffer) - readBuffer->transferCount = 0; - rStatus = CySpiWrite (handle, writeBuffer, ioTimeout); - pthread_mutex_unlock (&device->writeLock); - return rStatus; - } - //Write Bit is not set then read only - if (!(spiTransferMode & CY_SPI_WRITE_BIT)) { - // We are starting a thread so that we can collect all the data - // FIX for short length packet issue on SPI. - readBuffer->transferCount = 0; - if (writeBuffer) - writeBuffer->transferCount = 0; - threadParameter.handle = handle; - threadParameter.readBuffer = readBuffer->buffer; - threadParameter.length = readBuffer->length; - threadParameter.ioTimeout = ioTimeout; - ret = pthread_create (&readThreadID, NULL, (void *)spiCollectData, (void *)&threadParameter); - if (ret){ - CY_DEBUG_PRINT_ERROR ("CY:Error in creating read thread ... Reading failed \n"); - pthread_mutex_unlock (&device->writeLock); - readBuffer->transferCount = 0; - return CY_ERROR_REQUEST_FAILED; - } - pthread_join (readThreadID, NULL); - readBuffer->transferCount = threadParameter.transferCount; - pthread_mutex_unlock (&device->writeLock); - return threadParameter.rStatus; - } - writeBuffer->transferCount = 0; - readBuffer->transferCount = 0; - threadParameter.handle = handle; - threadParameter.readBuffer = readBuffer->buffer; - threadParameter.length = readBuffer->length; - threadParameter.ioTimeout = ioTimeout; - ret = pthread_create (&readThreadID, NULL, (void *)spiCollectData, (void *)&threadParameter); - if (ret){ - CY_DEBUG_PRINT_ERROR ("CY:Error in creating read thread ... Reading failed \n"); - readBuffer->transferCount = 0; - pthread_mutex_unlock (&device->writeLock); - return CY_ERROR_REQUEST_FAILED; - } - rStatus = CySpiWrite (handle, writeBuffer, ioTimeout); - if (rStatus == CY_SUCCESS) { - pthread_join (readThreadID, NULL); - rStatus = threadParameter.rStatus; - readBuffer->transferCount = threadParameter.transferCount; - } - else { - pthread_join (readThreadID, NULL); - readBuffer->transferCount = threadParameter.transferCount; - } - pthread_mutex_unlock (&device->writeLock); - return rStatus; - } - else{ - CY_DEBUG_PRINT_ERROR ("CY:Error API busy in service previous request ... Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - return rStatus; -} +/* + * SPI routines of Cypress USB Serial + * Copyright (C) 2013 Cypress Semiconductor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "CyUSBCommon.h" +#include +#include +#pragma pack (1) +typedef struct args { + CY_HANDLE handle; + UCHAR *readBuffer; + UINT32 length; + UINT32 ioTimeout; + CY_RETURN_STATUS rStatus; + UINT32 transferCount; +}args; + +typedef struct +{ + UINT32 frequency; + UINT8 dataWidth; + UCHAR mode; + UCHAR xferMode; + BOOL isMsbFirst; + BOOL isMaster; + BOOL isContinuous; + BOOL isSelectPrecede; + BOOL cpha; + BOOL cpol; + BOOL isLoopback; + UCHAR reserver[2]; +} CyUsSpiConfig_t; +#pragma pack() + +struct timeval startSpiTimeWrite, endSpiTimeWrite, startSpiTimeRead, endSpiTimeRead; +//Timer helper functions for proper timing +void startSpiTick (bool isWrite) { + if (isWrite) + gettimeofday (&startSpiTimeWrite, NULL); + else + gettimeofday (&startSpiTimeRead, NULL); +} + +UINT32 getSpiLapsedTime (bool isWrite){ + + signed int currentTime_sec, currentTime_usec, currentTime; + if (isWrite){ + gettimeofday (&endSpiTimeWrite, NULL); + currentTime_sec = (endSpiTimeWrite.tv_sec - startSpiTimeWrite.tv_sec) * 1000; + currentTime_usec = ((endSpiTimeWrite.tv_usec - startSpiTimeWrite.tv_usec)) / 1000; + currentTime = currentTime_sec + currentTime_usec; + return (unsigned int)currentTime; + } + else{ + gettimeofday (&endSpiTimeRead, NULL); + currentTime_sec = (endSpiTimeRead.tv_sec - startSpiTimeRead.tv_sec) * 1000; + currentTime_usec = ((endSpiTimeRead.tv_usec - startSpiTimeRead.tv_usec)) / 1000; + currentTime = currentTime_sec + currentTime_usec; + return (unsigned int)currentTime; + } +} +/* + This API gets the current SPI config + for the particluar interface of the device + */ +CY_RETURN_STATUS CyGetSpiConfig ( + CY_HANDLE handle, + CY_SPI_CONFIG *spiConfig + ) +{ + UINT16 wValue, wIndex, wLength; + UINT16 bmRequestType, bmRequest; + CyUsSpiConfig_t localSpiConfig; + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + UINT8 scbIndex = 0; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (spiConfig == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_SPI) { + CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not spi ..Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (device->interfaceNum > 0) + scbIndex = 1; + + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_SPI_GET_CONFIG_CMD; + wValue = (scbIndex << CY_SCB_INDEX_POS); + wIndex = 0; + wLength = CY_SPI_CONFIG_LEN; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)&localSpiConfig, wLength, ioTimeout); + if (rStatus == CY_SPI_CONFIG_LEN){ + //CY_DUMP_DATA ((unsigned char*)&localSpiConfig, wLength); + CY_DEBUG_PRINT_INFO ("CY: Read SPI config successfully %d\n", rStatus); + spiConfig->frequency = localSpiConfig.frequency; + spiConfig->dataWidth = localSpiConfig.dataWidth; + spiConfig->protocol = localSpiConfig.mode; + spiConfig->isMsbFirst = localSpiConfig.isMsbFirst; + spiConfig->isMaster = localSpiConfig.isMaster; + spiConfig->isContinuousMode = localSpiConfig.isContinuous; + spiConfig->isSelectPrecede = localSpiConfig.isSelectPrecede; + spiConfig->isCpha = localSpiConfig.cpha; + spiConfig->isCpol = localSpiConfig.cpol; + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ... Function is %s\n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s...libusb error is %d !\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This API sets SPI config of the device for that + interface + */ +CY_RETURN_STATUS CySetSpiConfig ( + CY_HANDLE handle, + CY_SPI_CONFIG *spiConfig + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + CyUsSpiConfig_t localSpiConfig; + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + UINT8 scbIndex = 0; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (spiConfig == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_SPI) { + CY_DEBUG_PRINT_ERROR ("CY:Error device type is not spi ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (spiConfig->frequency < 1000 || spiConfig->frequency > 3000000){ + CY_DEBUG_PRINT_ERROR ("CY:Error frequency trying to set in out of range ... Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + if (spiConfig->protocol == CY_SPI_TI){ + if (!(spiConfig->isCpol == false && spiConfig->isCpha == true && spiConfig->isContinuousMode == false)){ + CY_DEBUG_PRINT_ERROR ("CY:Error ... Wrong configuration for SPI TI mode \n"); + return CY_ERROR_REQUEST_FAILED; + } + } + if (spiConfig->protocol == CY_SPI_NS){ + if (!(spiConfig->isCpol == false && spiConfig->isCpha == false && spiConfig->isSelectPrecede == false)){ + CY_DEBUG_PRINT_ERROR ("CY:Error ... Wrong configuration for SPI ti mode \n"); + return CY_ERROR_REQUEST_FAILED; + } + } + else{ + if (spiConfig->isSelectPrecede != false){ + CY_DEBUG_PRINT_ERROR ("CY:Error ... Wrong configuration for SPI motorola mode \n"); + return CY_ERROR_REQUEST_FAILED; + } + } + if (device->interfaceNum > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_SPI_SET_CONFIG_CMD; + wValue = (scbIndex << CY_SCB_INDEX_POS); + wIndex = 0; + wLength = CY_SPI_CONFIG_LEN; + //We will not expose all the spi config structure elements to user. + //Fill in rest of the values. + + memset (&localSpiConfig, 0, CY_SPI_CONFIG_LEN); + localSpiConfig.frequency = spiConfig->frequency; + localSpiConfig.dataWidth = spiConfig->dataWidth; + localSpiConfig.mode = spiConfig->protocol; + localSpiConfig.isMsbFirst = spiConfig->isMsbFirst; + localSpiConfig.isMaster = spiConfig->isMaster; + localSpiConfig.isContinuous = spiConfig->isContinuousMode; + localSpiConfig.isSelectPrecede = spiConfig->isSelectPrecede; + localSpiConfig.cpha = spiConfig->isCpha; + localSpiConfig.cpol = spiConfig->isCpol; + //CY_DUMP_DATA ((unsigned char*)&localSpiConfig, wLength); + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)&localSpiConfig, wLength, ioTimeout); + if (rStatus == CY_SPI_CONFIG_LEN){ + CY_DEBUG_PRINT_INFO ("CY: Setting SPI config success ...\n"); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Time out error ..Function is %s\n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in function %s ... !libusb error is %d\n", __func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/*Api will reset the spi module*/ +CY_RETURN_STATUS CySpiReset (CY_HANDLE handle) +{ + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT16 wValue, wIndex, wLength, bmRequestType, bmRequest;; + UINT16 scbIndex = 0; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_SPI) { + CY_DEBUG_PRINT_ERROR ("CY:Error device type is not spi ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + scbIndex = device->interfaceNum; + if (scbIndex > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_SPI_RESET_CMD; + wValue = ((scbIndex << CY_SCB_INDEX_POS)); + wIndex = 0; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus < 0){ + CY_DEBUG_PRINT_ERROR ("CY:Error in sending spi reset command...Libusb error is %d\n", rStatus); + return rStatus; + } + return CY_SUCCESS; +} +/* + This API reads SPI data from the specified interface of the device + interface + */ + +static void LIBUSB_CALL spi_read_cb(struct libusb_transfer *transfer) +{ + UINT32 *completed = transfer->user_data; + *completed = 1; +} +//We adopted for async method here because there are 2 thread polling same fd +// i.e both read and write are polling same fd when one event triggers and other one is +//not completed then another thread will wait for more than 60sec. +CY_RETURN_STATUS CySpiRead ( + CY_HANDLE handle, + CY_DATA_BUFFER *readBuffer, + UINT32 ioTimeout + ) +{ + struct libusb_transfer *readTransfer; + CY_DEVICE *device; + libusb_device_handle *devHandle; + int readCompleted = 0; + struct timeval time; + int r; + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + readBuffer->transferCount = 0; + readTransfer = libusb_alloc_transfer(0); + if (readTransfer == NULL){ + CY_DEBUG_PRINT_ERROR("CY:Error in allocating transfers \n"); + return CY_ERROR_ALLOCATION_FAILED; + } + libusb_fill_bulk_transfer(readTransfer, devHandle, device->inEndpoint, readBuffer->buffer, readBuffer->length, + spi_read_cb, &readCompleted, ioTimeout); + libusb_submit_transfer (readTransfer); + time.tv_sec = (ioTimeout / 1000); + time.tv_usec = ((ioTimeout % 1000) * 1000);//polling timeout. + while (readCompleted == 0){ + r = libusb_handle_events_timeout_completed(NULL, &time, &readCompleted); + if (r < 0) { + if (r == LIBUSB_ERROR_INTERRUPTED) + continue; + libusb_cancel_transfer(readTransfer); + while (!readCompleted) + if (libusb_handle_events_completed(NULL, &readCompleted) < 0) + break; + readBuffer->transferCount = readTransfer->actual_length; + libusb_free_transfer(readTransfer); + return r; + } + } + if ((readTransfer->status == LIBUSB_TRANSFER_COMPLETED)){ + readBuffer->transferCount = readTransfer->actual_length; + libusb_free_transfer (readTransfer); + return CY_SUCCESS; + } + else{ + if (readTransfer->status == LIBUSB_TRANSFER_TIMED_OUT){ + //We should not be hitting this case.. As the time out is infinite!! + CY_DEBUG_PRINT_ERROR ("CY:Timeout error in doing SPI read/write .... %d Libusb errors %d\n", + readTransfer->actual_length,readTransfer->status); + readBuffer->transferCount = readTransfer->actual_length; + CySpiReset (handle); + libusb_free_transfer (readTransfer); + return CY_ERROR_IO_TIMEOUT; + } + if (readTransfer->status == LIBUSB_TRANSFER_OVERFLOW){ + //Need to handle this properly! + CY_DEBUG_PRINT_ERROR ("CY:OverFlow error in doing SPI read/write .... Libusb errors %d %d \n", + readTransfer->status, readTransfer->actual_length); + readBuffer->transferCount = readTransfer->actual_length; + CySpiReset (handle); + libusb_free_transfer (readTransfer); + return CY_ERROR_BUFFER_OVERFLOW; + } + if (readTransfer->status != LIBUSB_TRANSFER_COMPLETED){ + CY_DEBUG_PRINT_ERROR ("CY:Error in doing SPI read/write .... Libusb errors are %d %d\n", + readTransfer->status, readTransfer->actual_length); + readBuffer->transferCount = readTransfer->actual_length; + CySpiReset (handle); + libusb_free_transfer (readTransfer); + //If timer is not completed then it implies we have timeout error + return CY_ERROR_REQUEST_FAILED; + } + } + return CY_ERROR_REQUEST_FAILED; +} +/*Internal SPI get status API for Write operation*/ +CY_RETURN_STATUS CyGetSpiStatus (CY_HANDLE handle, + int *spiStatus + ) +{ + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT16 wValue, wIndex, wLength, bmRequestType, bmRequest;; + UINT16 scbIndex = 0; + UINT32 ioTimeout = 0; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_SPI) { + CY_DEBUG_PRINT_ERROR ("CY:Error device type is not spi ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + scbIndex = device->interfaceNum; + if (scbIndex > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_SPI_GET_STATUS_CMD; + wValue = ((scbIndex << CY_SCB_INDEX_POS)); + wIndex = 0; + wLength = CY_SPI_GET_STATUS_LEN; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest,wValue, wIndex, (UCHAR*)spiStatus, wLength, ioTimeout); + if (rStatus < CY_SPI_GET_STATUS_LEN){ + CY_DEBUG_PRINT_INFO ("CY:Error in sending spi Get Status command...Libusb error is %d\n", rStatus); + return rStatus; + } + return CY_SUCCESS; +} +/* Function to write on to SPI alone*/ +CY_RETURN_STATUS CySpiWrite ( + CY_HANDLE handle, + CY_DATA_BUFFER *writeBuffer, + UINT32 ioTimeout + ) +{ + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + int spiStatus = 1; + UINT32 newIoTimeout = ioTimeout, elapsedTime = 0, loopCount = 1; + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_SPI) { + CY_DEBUG_PRINT_ERROR ("CY:Error device type is not spi ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + startSpiTick (true); + rStatus = libusb_bulk_transfer (devHandle, device->outEndpoint, writeBuffer->buffer, writeBuffer->length, + (int*)&(writeBuffer->transferCount), newIoTimeout); + elapsedTime = getSpiLapsedTime(true); + newIoTimeout = ioTimeout - elapsedTime; + //because we have a sleep of 1 msec after every getstatus + if (newIoTimeout) + loopCount = (newIoTimeout); + if ((rStatus == LIBUSB_SUCCESS)){ + CY_DEBUG_PRINT_INFO ("CY: Successfully written SPI data.. %d bytes Read ...\n", writeBuffer->transferCount); + while (loopCount){ + usleep (1000); + rStatus = CyGetSpiStatus (handle, &spiStatus); + if (rStatus == CY_SUCCESS){ + if (spiStatus == 0){ + return CY_SUCCESS; + } + } + else { + //Should never hit this case + CY_DEBUG_PRINT_ERROR ("CY:Error in getting spi status \n"); + return CY_ERROR_REQUEST_FAILED; + } + if (ioTimeout) + loopCount--; + } + if (loopCount == 0 && spiStatus > 0){ + writeBuffer->length = 0; + CySpiReset (handle); + return CY_ERROR_IO_TIMEOUT; + } + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:Error TimeOut ...function is %s\n", __func__); + CySpiReset (handle); + return CY_ERROR_IO_TIMEOUT; + } + else if (rStatus == LIBUSB_ERROR_PIPE){ + CY_DEBUG_PRINT_ERROR ("CY:Error Pipe error..function is %s\n", __func__); + CySpiReset (handle); + CyResetPipe (handle, device->outEndpoint); + return CY_ERROR_PIPE_HALTED; + } + else if (rStatus == LIBUSB_ERROR_OVERFLOW){ + CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow...function is %s\n", __func__); + return CY_ERROR_BUFFER_OVERFLOW; + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + CY_DEBUG_PRINT_ERROR ("CY:Error Device Disconnected ...function is %s\n", __func__); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error in writing SPI data ...Libusb Error is %d and bytes read is %d!\n", rStatus, writeBuffer->transferCount); + return CY_ERROR_REQUEST_FAILED; + } + return CY_ERROR_REQUEST_FAILED; +}/* + API to wrap up the data + */ +void spiCollectData (void *inputParameters) { + + UINT32 readLength = 0, length; + CY_DATA_BUFFER readBuffer; + args *inputData = (args *) inputParameters; + UCHAR *buffer; + CY_RETURN_STATUS rStatus = CY_SUCCESS; + buffer = readBuffer.buffer = inputData->readBuffer; + length = readBuffer.length = inputData->length; + CY_HANDLE handle = inputData->handle; + int newTimeout = inputData->ioTimeout, elapsedTime; + while (readLength != length && newTimeout >= 0 && rStatus == CY_SUCCESS){ + //Get current time + //Buffer is pointing to next address where we are suppose to fill the data + readBuffer.buffer = &buffer[readLength]; + //Updated length which total length minus the total length of data read + readBuffer.length = length - readLength; + //Libusb fix for mac os!! + //ISSUE:when api times out in MAC it comes back and say read length = 0!! +#ifdef __APPLE__ + if (readBuffer.length > 64) + readBuffer.length = 64; +#endif + startSpiTick (false); + rStatus = CySpiRead (handle, &readBuffer, newTimeout); + elapsedTime = getSpiLapsedTime (false); + //Do this only when newTimeout is non zero + if (newTimeout){ + newTimeout = newTimeout - elapsedTime; + //If timeout is 0 then libusb considers that as infinite + //So forcefully make the loop to comeout + if (newTimeout <= 0) + rStatus = CY_ERROR_IO_TIMEOUT; + } + if (rStatus != CY_SUCCESS){ + readLength += readBuffer.transferCount; + break; + } + readLength += readBuffer.transferCount; + } + if (readLength != length && rStatus == CY_ERROR_IO_TIMEOUT){ + CySpiReset (handle); + } + inputData->transferCount = readLength; + inputData->rStatus = rStatus; +} +/* + * Api used to do read as well as write on spi + */ +CY_RETURN_STATUS CySpiReadWrite (CY_HANDLE handle, + CY_DATA_BUFFER *readBuffer, + CY_DATA_BUFFER *writeBuffer, + UINT32 ioTimeout) +{ + struct args threadParameter; + UINT32 ret; + pthread_t readThreadID = (pthread_t)0; + CY_DEVICE *device; + libusb_device_handle *devHandle; + CY_RETURN_STATUS rStatus; + unsigned short spiTransferMode = 0, scbIndex = 0; + UINT16 wValue, wIndex = 0, wLength; + UINT16 bmRequestType, bmRequest; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle.. Function is %s \n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (readBuffer == NULL && writeBuffer == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_SPI) { + CY_DEBUG_PRINT_ERROR ("CY:Error opened device is not spi .. \n"); + return CY_ERROR_REQUEST_FAILED; + } + //Set both the bits and change it accordingly based on parameters parameters + spiTransferMode |= ((CY_SPI_READ_BIT) | (CY_SPI_WRITE_BIT)); + if ((readBuffer == NULL || readBuffer->length == 0 || readBuffer->buffer == NULL)) + spiTransferMode &= ~(CY_SPI_READ_BIT); + if ((writeBuffer == NULL || writeBuffer->length == 0 || writeBuffer->buffer == NULL)) + spiTransferMode &= ~(CY_SPI_WRITE_BIT); + //if none of the bit is set it implies parameters sent is wrong + if (spiTransferMode == 0){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter.. Function is %s \n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + if (device->interfaceNum > 0) + scbIndex = 1; + //In read only case we take length to be equal to readBuffer length. + //But in write or in write/read case we take length = writeBuffer length. + if (spiTransferMode == 0x1) + wIndex = readBuffer->length; + else + wIndex = writeBuffer->length; + spiTransferMode |= (scbIndex << 15); + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_SPI_READ_WRITE_CMD; + wValue = (spiTransferMode); + wLength = 0; + if (pthread_mutex_trylock (&device->writeLock) == 0){ + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, 5000); + if (rStatus){ + CY_DEBUG_PRINT_ERROR ("CY:Error Sending spi read write vendor command failed ... Libusb error is %d\n", rStatus); + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_REQUEST_FAILED; + } + //Read Bit is not set then write Only + if (!(spiTransferMode & CY_SPI_READ_BIT)) { + writeBuffer->transferCount = 0; + if (readBuffer) + readBuffer->transferCount = 0; + rStatus = CySpiWrite (handle, writeBuffer, ioTimeout); + pthread_mutex_unlock (&device->writeLock); + return rStatus; + } + //Write Bit is not set then read only + if (!(spiTransferMode & CY_SPI_WRITE_BIT)) { + // We are starting a thread so that we can collect all the data + // FIX for short length packet issue on SPI. + readBuffer->transferCount = 0; + if (writeBuffer) + writeBuffer->transferCount = 0; + threadParameter.handle = handle; + threadParameter.readBuffer = readBuffer->buffer; + threadParameter.length = readBuffer->length; + threadParameter.ioTimeout = ioTimeout; + ret = pthread_create (&readThreadID, NULL, (void *)spiCollectData, (void *)&threadParameter); + if (ret){ + CY_DEBUG_PRINT_ERROR ("CY:Error in creating read thread ... Reading failed \n"); + pthread_mutex_unlock (&device->writeLock); + readBuffer->transferCount = 0; + return CY_ERROR_REQUEST_FAILED; + } + pthread_join (readThreadID, NULL); + readBuffer->transferCount = threadParameter.transferCount; + pthread_mutex_unlock (&device->writeLock); + return threadParameter.rStatus; + } + writeBuffer->transferCount = 0; + readBuffer->transferCount = 0; + threadParameter.handle = handle; + threadParameter.readBuffer = readBuffer->buffer; + threadParameter.length = readBuffer->length; + threadParameter.ioTimeout = ioTimeout; + ret = pthread_create (&readThreadID, NULL, (void *)spiCollectData, (void *)&threadParameter); + if (ret){ + CY_DEBUG_PRINT_ERROR ("CY:Error in creating read thread ... Reading failed \n"); + readBuffer->transferCount = 0; + pthread_mutex_unlock (&device->writeLock); + return CY_ERROR_REQUEST_FAILED; + } + rStatus = CySpiWrite (handle, writeBuffer, ioTimeout); + if (rStatus == CY_SUCCESS) { + pthread_join (readThreadID, NULL); + rStatus = threadParameter.rStatus; + readBuffer->transferCount = threadParameter.transferCount; + } + else { + pthread_join (readThreadID, NULL); + readBuffer->transferCount = threadParameter.transferCount; + } + pthread_mutex_unlock (&device->writeLock); + return rStatus; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY:Error API busy in service previous request ... Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + return rStatus; +} diff --git a/cylib/lib/cyuart.c b/configutility/linux/library/cyuart.c similarity index 90% rename from cylib/lib/cyuart.c rename to configutility/linux/library/cyuart.c index 01d05a7..f6ecb04 100644 --- a/cylib/lib/cyuart.c +++ b/configutility/linux/library/cyuart.c @@ -1,588 +1,589 @@ -/* - * UART routines of Cypress USB Serial - * Copyright (C) 2013 Cypress Semiconductor - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "CyUSBCommon.h" -#pragma pack(1) -typedef struct { - CY_UART_BAUD_RATE baudRate; - UINT8 pinType; - UINT8 dataWidth; - UINT8 stopBits; - UINT8 mode; - UINT8 parity; - UINT8 isMsbFirst; - UINT8 txRetry; - UINT8 rxInvertPolarity; - UINT8 rxIgnoreError; - UINT8 isFlowControl; - UINT8 isLoopBack; - UINT8 flags; -}CyUsUartConfig_t; -#pragma pack() -//Timer helper functions for proper timing -UINT32 getUartLapsedTime (struct timeval startTime){ - signed int currentTime_sec, currentTime_usec, currentTime; - struct timeval endTime; - gettimeofday (&endTime, NULL); - currentTime_sec = (endTime.tv_sec - startTime.tv_sec) * 1000; - currentTime_usec = ((endTime.tv_usec - startTime.tv_usec)) / 1000; - currentTime = currentTime_sec + currentTime_usec; - return (unsigned int)currentTime; -} -/* - This API gets the current UART configuration of the - device.Such as GPIO's assigned, flowcontrol, BaudRate - etc. - */ -CY_RETURN_STATUS CyGetUartConfig ( - CY_HANDLE handle, - PCY_UART_CONFIG uartConfig - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - CY_DEVICE *device; - CyUsUartConfig_t localUartConfig; - libusb_device_handle *devHandle; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - UINT8 scbIndex = 0; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (uartConfig == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameter..Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (device->interfaceNum > 0) - scbIndex = 1; - bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; - bmRequest = CY_UART_GET_CONFIG_CMD; - wValue = (scbIndex << CY_SCB_INDEX_POS); - wIndex = 0; - wLength = CY_UART_CONFIG_LEN; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)&localUartConfig, wLength, ioTimeout); - //Since we are not exposing all the configuration elements - //parse and fill only relevant elements. - if (rStatus == CY_UART_CONFIG_LEN){ - uartConfig->dataWidth = localUartConfig.dataWidth; - uartConfig->baudRate = localUartConfig.baudRate; - uartConfig->stopBits = localUartConfig.stopBits; - uartConfig->parityMode = (CY_UART_PARITY_MODE)localUartConfig.parity;; - uartConfig->isDropOnRxErrors = localUartConfig.rxIgnoreError; - //We are currently ignoring rest of the bits - CY_DEBUG_PRINT_INFO ("CY:Successfully read UART Config\n"); - return CY_SUCCESS; - } - else{ - CY_DEBUG_PRINT_ERROR ("CY:Error in reading UART config ... Libusb Error is %d \n", rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This API sets the current UART configuration of the - device.Such as GPIO's assigned, flowcontrol, BaudRate - etc. - */ -CY_RETURN_STATUS CySetUartConfig ( - CY_HANDLE handle, - CY_UART_CONFIG *uartConfig - ) -{ - UINT16 wValue, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - CyUsUartConfig_t localUartConfig; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - UINT8 scbIndex = 0; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (uartConfig == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameter..Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - if (uartConfig->dataWidth < 7 || uartConfig->dataWidth > 8){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameter..Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - if (uartConfig->stopBits < 1 || uartConfig->stopBits > 2){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameter..Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->interfaceNum > 0) - scbIndex = 1; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_UART_SET_CONFIG_CMD; - wValue = (scbIndex << CY_SCB_INDEX_POS); - wIndex = 0; - wLength = CY_UART_CONFIG_LEN; - - memset (&localUartConfig, 0, CY_UART_CONFIG_LEN); - //Fill in rest of the UART config structure elements - //that are not exposed in API with default values - localUartConfig.baudRate = uartConfig->baudRate; - localUartConfig.dataWidth = uartConfig->dataWidth; - localUartConfig.stopBits = uartConfig->stopBits; - localUartConfig.parity = (UCHAR) uartConfig->parityMode; - localUartConfig.rxIgnoreError = uartConfig->isDropOnRxErrors; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, (unsigned char*)&localUartConfig, wLength, ioTimeout); - if (rStatus == CY_UART_CONFIG_LEN){ - CY_DEBUG_PRINT_INFO ("CY:Successfully Set UART Config \n"); - return CY_SUCCESS; - } - else{ - CY_DEBUG_PRINT_ERROR ("CY:Error in Setting UART config ... Libusb Error is %d \n", rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This Api writes the Data to UART block of the - device. - */ -CY_RETURN_STATUS CyUartWrite ( - CY_HANDLE handle, - CY_DATA_BUFFER* writeBuffer, - unsigned int ioTimeOut - ) - -{ - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if ((writeBuffer == NULL) || (writeBuffer->buffer == NULL) || (writeBuffer->length == 0)){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameters..Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - writeBuffer->transferCount = 0; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - rStatus = libusb_bulk_transfer (devHandle, device->outEndpoint, writeBuffer->buffer, writeBuffer->length, - (int *)&((writeBuffer->transferCount)), ioTimeOut); - if (rStatus == CY_SUCCESS) { - CY_DEBUG_PRINT_INFO ("CY: SuccessFull in Wrting Data,%d bytes were transfered \n", (writeBuffer->transferCount)); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - CY_DEBUG_PRINT_ERROR ("CY:TimeOut error ...Function is %s\n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else if (rStatus == LIBUSB_ERROR_PIPE){ - CY_DEBUG_PRINT_ERROR ("CY:Pipe error endpoint Halted ...Function is %s\n", __func__); - CyResetPipe (handle, device->outEndpoint); - return CY_ERROR_PIPE_HALTED; - } - else if (rStatus == LIBUSB_ERROR_OVERFLOW){ - CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow occured ...Function is %s\n", __func__); - return CY_ERROR_BUFFER_OVERFLOW; - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected .... Function is %s\n", __func__); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Unknown error ....Libusb error is %d Function is %s\n", rStatus, __func__); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This Api Reads the Data from UART block of the - device. - */ -CY_RETURN_STATUS CyUartRead ( - CY_HANDLE handle, - CY_DATA_BUFFER* readBuffer, - unsigned int ioTimeOut - ) - -{ - int rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - UINT32 length, totalRead = 0, newIoTimeout = ioTimeOut, elapsedTime; - int transferCount; - UCHAR *buffer; - struct timeval startTime; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if ((readBuffer == NULL) || (readBuffer->buffer == NULL) || (readBuffer->length == 0)){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameters..Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - length = readBuffer->length; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - readBuffer->transferCount = 0; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - //Collect all the data in low baud rate for uart. As we get data in short packet - do { - // buffer will be pointing to new pointer - buffer = &(readBuffer->buffer[totalRead]); - //Start the tick - gettimeofday(&startTime, NULL); - rStatus = libusb_bulk_transfer (devHandle, device->inEndpoint, buffer, length, - &transferCount, newIoTimeout); - elapsedTime = getUartLapsedTime(startTime); - //Get the new timeout. - newIoTimeout = newIoTimeout - elapsedTime; - //Initialise totalRead to initially read + bytes returned now - totalRead += transferCount; - //length will initial length - transferCount - length = (length - transferCount); - - }while ((rStatus == CY_SUCCESS) && (totalRead != readBuffer->length) && (newIoTimeout > 0)); - if (newIoTimeout <= 0 && totalRead != readBuffer->length) - rStatus = LIBUSB_ERROR_TIMEOUT; - if (rStatus == CY_SUCCESS){ - //CY_DUMP_DATA (readBuffer->buffer, readBuffer->transferCount); - readBuffer->transferCount = totalRead; - CY_DEBUG_PRINT_INFO ("CY: SuccessFull in Reading Data,%d bytes were transfered \n", (readBuffer->transferCount)); - return CY_SUCCESS; - } - else if (rStatus == LIBUSB_ERROR_TIMEOUT){ - readBuffer->transferCount = totalRead; - CY_DEBUG_PRINT_ERROR ("CY:TimeOut error... Function is %s\n", __func__); - return CY_ERROR_IO_TIMEOUT; - } - else if (rStatus == LIBUSB_ERROR_PIPE){ - readBuffer->transferCount = totalRead; - CY_DEBUG_PRINT_ERROR ("CY:Pipe error endpoint Halted ...Function is %s\n", __func__); - CyResetPipe (handle, device->inEndpoint); - return CY_ERROR_PIPE_HALTED; - } - else if (rStatus == LIBUSB_ERROR_OVERFLOW){ - readBuffer->transferCount = totalRead; - CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow occured ...Function is %s\n", __func__); - return CY_ERROR_BUFFER_OVERFLOW; - } - else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { - readBuffer->transferCount = totalRead; - CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); - return CY_ERROR_DEVICE_NOT_FOUND; - } - else { - readBuffer->transferCount = totalRead; - CY_DEBUG_PRINT_ERROR ("CY: Unknown error ....Libusb error is %d Function is %s\n", rStatus, __func__); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This Api sets the hardware flow control - */ -CY_RETURN_STATUS CyUartSetHwFlowControl ( - CY_HANDLE handle, - CY_FLOW_CONTROL_MODES mode - ) - -{ - UINT16 wValue = 0, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (mode > 3){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter..Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_UART_SET_FLOW_CONTROL_CMD; - wValue |= mode; - wIndex = device->interfaceNum; - wLength = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus < 0){ - CY_DEBUG_PRINT_ERROR ("CY:Error in setting uart flow control ... Libusb Error is %d \n", rStatus); - return CY_ERROR_REQUEST_FAILED; - } - device->uartFlowControlMode = mode; - return CY_SUCCESS; -} -/* -Api gets the current flow control mode -*/ -CY_RETURN_STATUS CyUartGetHwFlowControl ( - CY_HANDLE handle, - CY_FLOW_CONTROL_MODES *mode - ) -{ - CY_DEVICE *device; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - if (mode == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameters..Function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - device = (CY_DEVICE *)handle; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - (*mode) = device->uartFlowControlMode; - return CY_SUCCESS; -} -/* The API is used to break -*/ -CYWINEXPORT CY_RETURN_STATUS CyUartSetBreak( - CY_HANDLE handle, /*Valid handle to communicate with device*/ - UINT16 timeout /*Break timeout value in milliseconds */ - ) -{ - UINT16 wValue = 0, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_UART_SEND_BREAK_CMD; - wValue = timeout; - wIndex = device->interfaceNum; - wLength = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in setting break ... Libusb Error is %d \n", rStatus); - return CY_ERROR_REQUEST_FAILED; - } - return CY_SUCCESS; -} -/* - This Api sets the RTS UART pins High - */ -CY_RETURN_STATUS CyUartSetRts ( - CY_HANDLE handle - ) -{ - UINT16 wValue = 0, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus; - UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_SET_LINE_CONTROL_STATE_CMD; - wValue |= (1 << 1) | (device->dtrValue); - wIndex = device->interfaceNum; - wLength = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus == CY_SUCCESS){ - device->rtsValue = 1; - return CY_SUCCESS; - } - else { - CY_DEBUG_PRINT_ERROR ("CY:Error in setting RTS of UART ... Libusb Error is %d \n", rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This Api clears the RTS UART pin and makes it low - */ -CY_RETURN_STATUS CyUartClearRts ( - CY_HANDLE handle - ) -{ - UINT16 wValue = 0, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_SET_LINE_CONTROL_STATE_CMD; - wValue = (device->dtrValue); - wIndex = device->interfaceNum; - wLength = 0; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus == CY_SUCCESS){ - device->rtsValue = 0; - return CY_SUCCESS; - } - else { - CY_DEBUG_PRINT_ERROR ("CY:Error in clearing RTS of UART ... Libusb Error is %d \n", rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} -/* - This Api sets the DTR UART pin High - */ -CY_RETURN_STATUS CyUartSetDtr ( - CY_HANDLE handle - ) - -{ - UINT16 wValue = 0, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_SET_LINE_CONTROL_STATE_CMD; - wValue = ((device->rtsValue) << 1) | 1; - wIndex = device->interfaceNum; - wLength = 0; - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus == CY_SUCCESS){ - device->dtrValue = 1; - return CY_SUCCESS; - } - else { - CY_DEBUG_PRINT_ERROR ("CY:Error in setting DTR of UART ... Libusb Error is %d \n", rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} - -/* - This Api clears the DTR UART pin and makes it low - */ - -CY_RETURN_STATUS CyUartClearDtr ( - CY_HANDLE handle - ) -{ - UINT16 wValue = 0, wIndex, wLength; - UINT8 bmRequestType, bmRequest; - int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); - return CY_ERROR_INVALID_HANDLE; - } - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - if (device->deviceType != CY_TYPE_UART){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - - bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; - bmRequest = CY_SET_LINE_CONTROL_STATE_CMD; - wValue = ((device->rtsValue) << 1); - wIndex = device->interfaceNum; - wLength = 0; - - rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, - wValue, wIndex, NULL, wLength, ioTimeout); - if (rStatus == CY_SUCCESS){ - device->dtrValue = 0; - return CY_SUCCESS; - } - else{ - CY_DEBUG_PRINT_ERROR ("CY:Error in function %s... Libusb Error is %d \n",__func__, rStatus); - return CY_ERROR_REQUEST_FAILED; - } -} +/* + * UART routines of Cypress USB Serial + * Copyright (C) 2013 Cypress Semiconductor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "CyUSBCommon.h" +#pragma pack(1) +typedef struct { + CY_UART_BAUD_RATE baudRate; + UINT8 pinType; + UINT8 dataWidth; + UINT8 stopBits; + UINT8 mode; + UINT8 parity; + UINT8 isMsbFirst; + UINT8 txRetry;; + UINT8 rxInvertPolarity; + UINT8 rxIgnoreError; + UINT8 isFlowControl; + UINT8 isLoopBack; + UINT8 flags; +}CyUsUartConfig_t; +#pragma pack() +//Timer helper functions for proper timing +UINT32 getUartLapsedTime (struct timeval startTime){ + + signed int currentTime_sec, currentTime_usec, currentTime; + struct timeval endTime; + gettimeofday (&endTime, NULL); + currentTime_sec = (endTime.tv_sec - startTime.tv_sec) * 1000; + currentTime_usec = ((endTime.tv_usec - startTime.tv_usec)) / 1000; + currentTime = currentTime_sec + currentTime_usec; + return (unsigned int)currentTime; +} +/* + This API gets the current UART configuration of the + device.Such as GPIO's assigned, flowcontrol, BaudRate + etc. + */ +CY_RETURN_STATUS CyGetUartConfig ( + CY_HANDLE handle, + PCY_UART_CONFIG uartConfig + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + CY_DEVICE *device; + CyUsUartConfig_t localUartConfig; + libusb_device_handle *devHandle; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + UINT8 scbIndex = 0; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (uartConfig == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameter..Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (device->interfaceNum > 0) + scbIndex = 1; + bmRequestType = CY_VENDOR_REQUEST_DEVICE_TO_HOST; + bmRequest = CY_UART_GET_CONFIG_CMD; + wValue = (scbIndex << CY_SCB_INDEX_POS); + wIndex = 0; + wLength = CY_UART_CONFIG_LEN; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)&localUartConfig, wLength, ioTimeout); + //Since we are not exposing all the configuration elements + //parse and fill only relevant elements. + if (rStatus == CY_UART_CONFIG_LEN){ + uartConfig->dataWidth = localUartConfig.dataWidth; + uartConfig->baudRate = localUartConfig.baudRate; + uartConfig->stopBits = localUartConfig.stopBits; + uartConfig->parityMode = (CY_UART_PARITY_MODE)localUartConfig.parity;; + uartConfig->isDropOnRxErrors = localUartConfig.rxIgnoreError; + //We are currently ignoring rest of the bits + CY_DEBUG_PRINT_INFO ("CY:Successfully read UART Config\n"); + return CY_SUCCESS; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY:Error in reading UART config ... Libusb Error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This API sets the current UART configuration of the + device.Such as GPIO's assigned, flowcontrol, BaudRate + etc. + */ +CY_RETURN_STATUS CySetUartConfig ( + CY_HANDLE handle, + CY_UART_CONFIG *uartConfig + ) +{ + UINT16 wValue, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + CyUsUartConfig_t localUartConfig; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + UINT8 scbIndex = 0; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (uartConfig == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameter..Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + if (uartConfig->dataWidth < 7 || uartConfig->dataWidth > 8){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameter..Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + if (uartConfig->stopBits < 1 || uartConfig->stopBits > 2){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameter..Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->interfaceNum > 0) + scbIndex = 1; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_VENDOR_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_UART_SET_CONFIG_CMD; + wValue = (scbIndex << CY_SCB_INDEX_POS); + wIndex = 0; + wLength = CY_UART_CONFIG_LEN; + + memset (&localUartConfig, 0, CY_UART_CONFIG_LEN); + //Fill in rest of the UART config structure elements + //that are not exposed in API with default values + localUartConfig.baudRate = uartConfig->baudRate; + localUartConfig.dataWidth = uartConfig->dataWidth; + localUartConfig.stopBits = uartConfig->stopBits; + localUartConfig.parity = (UCHAR) uartConfig->parityMode; + localUartConfig.rxIgnoreError = uartConfig->isDropOnRxErrors; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, (unsigned char*)&localUartConfig, wLength, ioTimeout); + if (rStatus == CY_UART_CONFIG_LEN){ + CY_DEBUG_PRINT_INFO ("CY:Successfully Set UART Config \n"); + return CY_SUCCESS; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY:Error in Setting UART config ... Libusb Error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This Api writes the Data to UART block of the + device. + */ +CY_RETURN_STATUS CyUartWrite ( + CY_HANDLE handle, + CY_DATA_BUFFER* writeBuffer, + unsigned int ioTimeOut + ) + +{ + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if ((writeBuffer == NULL) || (writeBuffer->buffer == NULL) || (writeBuffer->length == 0)){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameters..Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + writeBuffer->transferCount = 0; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + rStatus = libusb_bulk_transfer (devHandle, device->outEndpoint, writeBuffer->buffer, writeBuffer->length, + (int *)&((writeBuffer->transferCount)), ioTimeOut); + if ((rStatus == CY_SUCCESS)) { + CY_DEBUG_PRINT_INFO ("CY: SuccessFull in Wrting Data,%d bytes were transfered \n", (writeBuffer->transferCount)); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + CY_DEBUG_PRINT_ERROR ("CY:TimeOut error ...Function is %s\n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else if (rStatus == LIBUSB_ERROR_PIPE){ + CY_DEBUG_PRINT_ERROR ("CY:Pipe error endpoint Halted ...Function is %s\n", __func__); + CyResetPipe (handle, device->outEndpoint); + return CY_ERROR_PIPE_HALTED; + } + else if (rStatus == LIBUSB_ERROR_OVERFLOW){ + CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow occured ...Function is %s\n", __func__); + return CY_ERROR_BUFFER_OVERFLOW; + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected .... Function is %s\n", __func__); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Unknown error ....Libusb error is %d Function is %s\n", rStatus, __func__); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This Api Reads the Data from UART block of the + device. + */ +CY_RETURN_STATUS CyUartRead ( + CY_HANDLE handle, + CY_DATA_BUFFER* readBuffer, + unsigned int ioTimeOut + ) + +{ + int rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + UINT32 length, totalRead = 0, newIoTimeout = ioTimeOut, elapsedTime; + int transferCount; + UCHAR *buffer; + struct timeval startTime; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if ((readBuffer == NULL) || (readBuffer->buffer == NULL) || (readBuffer->length == 0)){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameters..Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + length = readBuffer->length; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + readBuffer->transferCount = 0; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + //Collect all the data in low baud rate for uart. As we get data in short packet + do { + // buffer will be pointing to new pointer + buffer = &(readBuffer->buffer[totalRead]); + //Start the tick + gettimeofday(&startTime, NULL); + rStatus = libusb_bulk_transfer (devHandle, device->inEndpoint, buffer, length, + &transferCount, newIoTimeout); + elapsedTime = getUartLapsedTime(startTime); + //Get the new timeout. + newIoTimeout = newIoTimeout - elapsedTime; + //Initialise totalRead to initially read + bytes returned now + totalRead += transferCount; + //length will initial length - transferCount + length = (length - transferCount); + + }while ((rStatus == CY_SUCCESS) && (totalRead != readBuffer->length) && (newIoTimeout > 0)); + if (newIoTimeout <= 0 && totalRead != readBuffer->length) + rStatus = LIBUSB_ERROR_TIMEOUT; + if (rStatus == CY_SUCCESS){ + //CY_DUMP_DATA (readBuffer->buffer, readBuffer->transferCount); + readBuffer->transferCount = totalRead; + CY_DEBUG_PRINT_INFO ("CY: SuccessFull in Reading Data,%d bytes were transfered \n", (readBuffer->transferCount)); + return CY_SUCCESS; + } + else if (rStatus == LIBUSB_ERROR_TIMEOUT){ + readBuffer->transferCount = totalRead; + CY_DEBUG_PRINT_ERROR ("CY:TimeOut error... Function is %s\n", __func__); + return CY_ERROR_IO_TIMEOUT; + } + else if (rStatus == LIBUSB_ERROR_PIPE){ + readBuffer->transferCount = totalRead; + CY_DEBUG_PRINT_ERROR ("CY:Pipe error endpoint Halted ...Function is %s\n", __func__); + CyResetPipe (handle, device->inEndpoint); + return CY_ERROR_PIPE_HALTED; + } + else if (rStatus == LIBUSB_ERROR_OVERFLOW){ + readBuffer->transferCount = totalRead; + CY_DEBUG_PRINT_ERROR ("CY:Error Buffer Overflow occured ...Function is %s\n", __func__); + return CY_ERROR_BUFFER_OVERFLOW; + } + else if (rStatus == LIBUSB_ERROR_NO_DEVICE) { + readBuffer->transferCount = totalRead; + CY_DEBUG_PRINT_ERROR ("CY: Device Disconnected ....Function is %s\n", __func__); + return CY_ERROR_DEVICE_NOT_FOUND; + } + else { + readBuffer->transferCount = totalRead; + CY_DEBUG_PRINT_ERROR ("CY: Unknown error ....Libusb error is %d Function is %s\n", rStatus, __func__); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This Api sets the hardware flow control + */ +CY_RETURN_STATUS CyUartSetHwFlowControl ( + CY_HANDLE handle, + CY_FLOW_CONTROL_MODES mode + ) + +{ + UINT16 wValue = 0, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (mode < 0 || mode > 3){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid parameter..Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_UART_SET_FLOW_CONTROL_CMD; + wValue |= mode; + wIndex = device->interfaceNum; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus < 0){ + CY_DEBUG_PRINT_ERROR ("CY:Error in setting uart flow control ... Libusb Error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } + device->uartFlowControlMode = mode; + return CY_SUCCESS; +} +/* +Api gets the current flow control mode +*/ +CY_RETURN_STATUS CyUartGetHwFlowControl ( + CY_HANDLE handle, + CY_FLOW_CONTROL_MODES *mode + ) +{ + CY_DEVICE *device; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + if (mode == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid input parameters..Function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + device = (CY_DEVICE *)handle; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + (*mode) = device->uartFlowControlMode; + return CY_SUCCESS; +} +/* The API is used to break +*/ +CYWINEXPORT CY_RETURN_STATUS CyUartSetBreak( + CY_HANDLE handle, /*Valid handle to communicate with device*/ + UINT16 timeout /*Break timeout value in milliseconds */ + ) +{ + UINT16 wValue = 0, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_UART_SEND_BREAK_CMD; + wValue = timeout; + wIndex = device->interfaceNum; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in setting break ... Libusb Error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } + return CY_SUCCESS; +} +/* + This Api sets the RTS UART pins High + */ +CY_RETURN_STATUS CyUartSetRts ( + CY_HANDLE handle + ) +{ + UINT16 wValue = 0, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus; + UINT32 ioTimeout = CY_USB_SERIAL_TIMEOUT; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_SET_LINE_CONTROL_STATE_CMD; + wValue |= (1 << 1) | (device->dtrValue); + wIndex = device->interfaceNum; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus == CY_SUCCESS){ + device->rtsValue = 1; + return CY_SUCCESS; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error in setting RTS of UART ... Libusb Error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This Api clears the RTS UART pin and makes it low + */ +CY_RETURN_STATUS CyUartClearRts ( + CY_HANDLE handle + ) +{ + UINT16 wValue = 0, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_SET_LINE_CONTROL_STATE_CMD; + wValue = (device->dtrValue); + wIndex = device->interfaceNum; + wLength = 0; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus == CY_SUCCESS){ + device->rtsValue = 0; + return CY_SUCCESS; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error in clearing RTS of UART ... Libusb Error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} +/* + This Api sets the DTR UART pin High + */ +CY_RETURN_STATUS CyUartSetDtr ( + CY_HANDLE handle + ) + +{ + UINT16 wValue = 0, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_SET_LINE_CONTROL_STATE_CMD; + wValue = ((device->rtsValue) << 1) | 1; + wIndex = device->interfaceNum; + wLength = 0; + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus == CY_SUCCESS){ + device->dtrValue = 1; + return CY_SUCCESS; + } + else { + CY_DEBUG_PRINT_ERROR ("CY:Error in setting DTR of UART ... Libusb Error is %d \n", rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} + +/* + This Api clears the DTR UART pin and makes it low + */ + +CY_RETURN_STATUS CyUartClearDtr ( + CY_HANDLE handle + ) +{ + UINT16 wValue = 0, wIndex, wLength; + UINT8 bmRequestType, bmRequest; + int rStatus, ioTimeout = CY_USB_SERIAL_TIMEOUT ; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid handle..Function is %s\n", __func__); + return CY_ERROR_INVALID_HANDLE; + } + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + if (device->deviceType != CY_TYPE_UART){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device type needs to be uart..Function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + + bmRequestType = CY_CLASS_INTERFACE_REQUEST_HOST_TO_DEVICE; + bmRequest = CY_SET_LINE_CONTROL_STATE_CMD; + wValue = ((device->rtsValue) << 1); + wIndex = device->interfaceNum; + wLength = 0; + + rStatus = libusb_control_transfer (devHandle, bmRequestType, bmRequest, + wValue, wIndex, NULL, wLength, ioTimeout); + if (rStatus == CY_SUCCESS){ + device->dtrValue = 0; + return CY_SUCCESS; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY:Error in function %s... Libusb Error is %d \n",__func__, rStatus); + return CY_ERROR_REQUEST_FAILED; + } +} diff --git a/cylib/lib/cyusb.c b/configutility/linux/library/cyusb.c similarity index 87% rename from cylib/lib/cyusb.c rename to configutility/linux/library/cyusb.c index b3ddada..eb6010d 100644 --- a/cylib/lib/cyusb.c +++ b/configutility/linux/library/cyusb.c @@ -1,638 +1,643 @@ -/* - * USB routines of Cypress USB Serial - * Copyright (C) 2013 Cypress Semiconductor - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "CyUSBCommon.h" - -libusb_context *glContext = NULL; -static bool glDriverInit = false; -static libusb_device **glDeviceList; -static int glNumDevices; -/*The API initializes the Libusb library -*/ -pthread_mutex_t criticalSection; -CY_RETURN_STATUS CyLibraryInit () -{ - int rStatus = LIBUSB_SUCCESS; - - if (!glContext) - rStatus = libusb_init (&glContext); - - if (glDriverInit != true){ - if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Driver Init Failed ...\n"); - return CY_ERROR_DRIVER_INIT_FAILED; - } - glNumDevices = libusb_get_device_list (glContext, &glDeviceList); - if (glNumDevices < 0){ - CY_DEBUG_PRINT_ERROR ("CY:Building device list Failed ...\n"); - glNumDevices = -1; - return CY_ERROR_DRIVER_INIT_FAILED; - } - pthread_mutex_init (&criticalSection, NULL); - glDriverInit = true; - return CY_SUCCESS; - } - else{ - CY_DEBUG_PRINT_ERROR ("CY:Error ... library already initialized \n"); - return CY_ERROR_DRIVER_INIT_FAILED; - } -} -/* - This API needs to be called after Calling CyGetListofDevices. - */ -CY_RETURN_STATUS CyLibraryExit () -{ - if (glDriverInit == true){ - if (glNumDevices >= 0) - libusb_free_device_list (glDeviceList, 1); - if (glContext) { - libusb_exit (glContext); - glContext = NULL; - } - glDriverInit = false; - pthread_mutex_destroy (&criticalSection); - return CY_SUCCESS; - } - CY_DEBUG_PRINT_ERROR ("CY:Error ... Library not initialized \n"); - return CY_ERROR_REQUEST_FAILED; -} -/* - * This function Gets the number of all the devices currently - * Connected to the host (It includes Cypress Device as well as - * no Cypress Devices connected) - */ -CY_RETURN_STATUS CyGetListofDevices ( - UINT8 *numDevices - ) -{ - // Use this variable to call libusb_close and exit of the application - if (numDevices == NULL) - return CY_ERROR_INVALID_PARAMETER; - if (!glDriverInit){ - CY_DEBUG_PRINT_ERROR ("CY:Error Library not initialised ...function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - pthread_mutex_lock (&criticalSection); - libusb_free_device_list (glDeviceList, 1); - glNumDevices = (*numDevices) = libusb_get_device_list (glContext, &glDeviceList); - pthread_mutex_unlock (&criticalSection); - if (glNumDevices < 0){ - CY_DEBUG_PRINT_ERROR ("CY:Building device list Failed ...function is %s\n", __func__); - glNumDevices = -1; - (*numDevices) = -1; - return CY_ERROR_REQUEST_FAILED; - } - return CY_SUCCESS; -} -/* This function gets all the neccessary info such as VID,PID, - String Descriptors and if is a cypress serial device you will - get the info on class and device type - */ -CY_RETURN_STATUS CyGetDeviceInfo ( - UINT8 deviceNumber, - CY_DEVICE_INFO *deviceInfo - ) -{ - struct libusb_device_descriptor deviceDesc; - int rStatus; - UINT32 numInterfaces; - UINT8 iManufacturer, iProduct, iSerial; - libusb_device *usbDevice;; - struct libusb_config_descriptor *configDesc; - libusb_device_handle *devHandle; - - // Get the list of descriptor info for the device - if (glDriverInit == false){ - CY_DEBUG_PRINT_ERROR ("CY:Error Library not initialised ...function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (deviceInfo == NULL) - return CY_ERROR_INVALID_PARAMETER; - pthread_mutex_lock (&criticalSection); - if (deviceNumber >= glNumDevices){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device number... \n"); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_INVALID_PARAMETER; - } - usbDevice = glDeviceList[deviceNumber]; - rStatus = libusb_get_device_descriptor (usbDevice, &deviceDesc); - if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error ... unable to retrieve device descriptor \n"); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DEVICE_INFO_FETCH_FAILED; - } - - deviceInfo->vidPid.vid = deviceDesc.idVendor; - deviceInfo->vidPid.pid = deviceDesc.idProduct; - // Get the all the index of the String descriptors so that it can be used - // to retrieve the string descriptor info. - iManufacturer = deviceDesc.iManufacturer; - iProduct = deviceDesc.iProduct; - iSerial = deviceDesc.iSerialNumber; - //Get the Device handle so that we can communicate with the device retreiving - // descriptor info - deviceInfo->manufacturerName[0] = '\0'; - deviceInfo->productName[0] = '\0'; - deviceInfo->serialNum[0] = '\0'; - rStatus = libusb_open (usbDevice, &devHandle); - if (rStatus == LIBUSB_ERROR_ACCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error ...Insufficient permission... Libusb error is %d \n", rStatus); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_ACCESS_DENIED; - } - else if (rStatus != CY_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in opening the device... Libusb error is %d \n", rStatus); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DEVICE_INFO_FETCH_FAILED; - } - if (iManufacturer > 0){ - rStatus = libusb_get_string_descriptor_ascii (devHandle, iManufacturer, deviceInfo->manufacturerName, 256); - if (rStatus <= LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in Getting Manufacturer name Error is <%x> \n", rStatus); - } - } - if (iProduct > 0){ - rStatus = libusb_get_string_descriptor_ascii (devHandle, iProduct, deviceInfo->productName, 256); - if (rStatus <= LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in Getting product name Error is <%d> \n", rStatus); - } - } - if (iSerial > 0){ - rStatus = libusb_get_string_descriptor_ascii (devHandle, iSerial, deviceInfo->serialNum, 256); - if (rStatus <= LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in Getting Serial name <%d>\n", rStatus); - } - } - rStatus = libusb_get_config_descriptor (usbDevice, 0, &configDesc); - if (rStatus == LIBUSB_SUCCESS){ - UINT32 index_i = 0; - const struct libusb_interface *interface; - numInterfaces = configDesc->bNumInterfaces; - deviceInfo->numInterfaces = numInterfaces; - interface = configDesc->interface; - while ((numInterfaces) && (index_i < CY_MAX_DEVICE_INTERFACE)){ - deviceInfo->deviceClass[index_i] = (CY_DEVICE_CLASS)interface->altsetting->bInterfaceClass; - if (deviceInfo->deviceClass[index_i] == CY_CLASS_VENDOR){ - deviceInfo->deviceType[index_i] = (CY_DEVICE_TYPE)interface->altsetting->bInterfaceSubClass; - } - else - deviceInfo->deviceType[index_i] = CY_TYPE_DISABLED; - index_i++; - numInterfaces--; - interface++; - } - libusb_free_config_descriptor(configDesc); - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in Getting config descriptor ...Libusb error is %d \n", rStatus); - if (devHandle) - libusb_close (devHandle); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DEVICE_INFO_FETCH_FAILED; - } - if (devHandle) - libusb_close (devHandle); - pthread_mutex_unlock (&criticalSection); - return CY_SUCCESS; -} -/* This function gets all the neccessary info such as VID,PID, - String Descriptors and if is a cypress serial device you will - get the info on class and device type - */ -CY_RETURN_STATUS CyGetDeviceInfoVidPid ( - CY_VID_PID vidPid, - UINT8 *deviceNumber, - PCY_DEVICE_INFO deviceInfoList, - UINT8 *deviceCount, - UINT8 infoListLength - ) -{ - struct libusb_device_descriptor deviceDesc; - int rStatus = CY_ERROR_DRIVER_INIT_FAILED; - UINT32 numInterfaces, index = 0; - int devNum; - UINT8 iManufacturer, iProduct, iSerial; - libusb_device *usbDevice; - struct libusb_config_descriptor *configDesc; - libusb_device_handle *devHandle = NULL; - PCY_DEVICE_INFO deviceInfo; - - if (glDriverInit == false){ - CY_DEBUG_PRINT_ERROR ("CY:Error Library not initialised ...function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if ((infoListLength) < 1){ - CY_DEBUG_PRINT_ERROR ("CY:Error invalid device info list length specified should be > 0 .. function is %s\n", __func__); - return CY_ERROR_INVALID_PARAMETER; - } - if (deviceNumber == NULL || deviceInfoList == NULL || deviceCount == NULL) - return CY_ERROR_INVALID_PARAMETER; - // Get the list of descriptor info for the device - (*deviceCount) = 0; - pthread_mutex_lock (&criticalSection); - for (devNum = 0; devNum < glNumDevices; devNum++) { - //We are making sure that we do not overrun - //the list. - deviceInfo = &(deviceInfoList [index]); - usbDevice = glDeviceList[devNum]; - rStatus = libusb_get_device_descriptor (usbDevice, &deviceDesc); - if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in getting device descriptor for device-%d... Libusb Error is %d \n", devNum, rStatus); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DEVICE_INFO_FETCH_FAILED; - } - if ((deviceDesc.idVendor != vidPid.vid) || (deviceDesc.idProduct != vidPid.pid)){ - continue; - } - (*deviceCount)++; - if (index > infoListLength){ - continue; - } - rStatus = libusb_open (usbDevice, &devHandle); - if (rStatus == LIBUSB_ERROR_ACCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Insufficient permission ... Libusb error is %d \n", rStatus); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_ACCESS_DENIED; - } - else if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in Opening the Device ...Error is %d \n", rStatus); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DEVICE_INFO_FETCH_FAILED; - } - deviceNumber[index] = devNum; - index++; - deviceInfo->vidPid.vid = deviceDesc.idVendor; - deviceInfo->vidPid.pid = deviceDesc.idProduct; - // Get all the index of the String descriptors so that it can be used - // to retrieve the string descriptor info. - iManufacturer = deviceDesc.iManufacturer; - iProduct = deviceDesc.iProduct; - iSerial = deviceDesc.iSerialNumber; - //Get the Device handle so that we can communicate with the device retreiving - // descriptor info - //Initialise manufacturer, product and serial names - deviceInfo->manufacturerName[0] = '\0'; - deviceInfo->productName[0] = '\0'; - deviceInfo->serialNum[0] = '\0'; - if (iManufacturer > 0) { - rStatus = libusb_get_string_descriptor_ascii (devHandle, iManufacturer, deviceInfo->manufacturerName, 256); - if (rStatus <= LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_INFO ("CY:Error in Getting Manufacturer name Error is <%d> \n",rStatus); - } - } - if (iProduct > 0){ - rStatus = libusb_get_string_descriptor_ascii (devHandle, iProduct, deviceInfo->productName, 256); - if (rStatus <= LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_INFO ("CY:Error in Getting product name Error is <%d> \n", rStatus); - } - } - if (iSerial > 0){ - rStatus = libusb_get_string_descriptor_ascii (devHandle, iSerial, deviceInfo->serialNum, 256); - if (rStatus <= LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_INFO ("CY:Error in Getting Serial name <%d>\n", rStatus); - } - } - CY_DEBUG_PRINT_INFO ("Manufacturer name <%s> \nProduct Name <%s> \nserial number <%s> \n", - deviceInfo->manufacturerName,deviceInfo->productName,deviceInfo->serialNum); - rStatus = libusb_get_config_descriptor (usbDevice, 0, &configDesc); - if (rStatus == LIBUSB_SUCCESS){ - int index_i = 0; - const struct libusb_interface *interfaceDesc; - numInterfaces = configDesc->bNumInterfaces; - deviceInfo->numInterfaces = numInterfaces; - interfaceDesc = configDesc->interface; - while ((numInterfaces) && (index_i < CY_MAX_DEVICE_INTERFACE)){ - deviceInfo->deviceClass[index_i] = (CY_DEVICE_CLASS)interfaceDesc->altsetting->bInterfaceClass; - if (deviceInfo->deviceClass[index_i] == CY_CLASS_VENDOR) - deviceInfo->deviceType[index_i] = (CY_DEVICE_TYPE)interfaceDesc->altsetting->bInterfaceSubClass; - else - deviceInfo->deviceType[index_i] = CY_TYPE_DISABLED; - - index_i++; - numInterfaces--; - interfaceDesc++; - } - } - else { - CY_DEBUG_PRINT_ERROR ("CY: Error in Getting config descriptor ... Libusb Error is %d\n", rStatus); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DEVICE_INFO_FETCH_FAILED; - } - libusb_free_config_descriptor (configDesc); - libusb_close (devHandle); - } - if ((*deviceCount) == 0) - rStatus = CY_ERROR_DEVICE_NOT_FOUND; - pthread_mutex_unlock (&criticalSection); - return rStatus; -} -/* - This API will claim the interface in the device - To make sure only claimed application speaks to device. - */ -CY_RETURN_STATUS CySelectInterface ( - CY_HANDLE handle, - UINT8 interfaceNum - ) -{ - UINT32 rStatus, numEP; - CY_DEVICE *device; - libusb_device_handle *devHandle; - libusb_device *usbDev; - struct libusb_config_descriptor *configDesc; - const struct libusb_interface *interfaceDesc; - const struct libusb_endpoint_descriptor *epDesc; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - usbDev = libusb_get_device (devHandle); - if (usbDev == NULL){ - CY_DEBUG_PRINT_ERROR ("CY:Error Invalide handle ..function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - //Get the config descriptor and parse it to get the - //interface and endpoint descriptor - rStatus = libusb_get_config_descriptor (usbDev, 0, &configDesc); - if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in Getting Config Desc ...function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - interfaceDesc = configDesc->interface; - //Interface Number should be a valid one and should not exceed - // total number of interfaces - if (interfaceNum >= configDesc->bNumInterfaces){ - CY_DEBUG_PRINT_ERROR ("CY:Interface Number not valid... \n"); - libusb_free_config_descriptor (configDesc); - return CY_ERROR_REQUEST_FAILED; - } - if (libusb_kernel_driver_active (devHandle, interfaceNum)){ - CY_DEBUG_PRINT_ERROR ("CY:Kernel driver active on the interface number %d \n", interfaceNum);; - //User can uncomment this section if needed. -#ifdef CY_DETACH_KERNEL_DRIVER - if (!libusb_detach_kernel_driver (devHandle, interfaceNum)){ - CY_DEBUG_PRINT_ERROR ("CY:Kernel driver detach failed %d\n", interfaceNum); - return CY_ERROR_REQUEST_FAILED; - } -#else - return CY_ERROR_REQUEST_FAILED; -#endif - } - rStatus = libusb_claim_interface (devHandle, interfaceNum); - if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in claiming interface -interface num %d... Libusb error is %d \n", interfaceNum, rStatus); - return CY_ERROR_REQUEST_FAILED; - } - device->interfaceNum = interfaceNum; - while (interfaceNum--) - interfaceDesc++; - - epDesc = interfaceDesc->altsetting->endpoint; - numEP = interfaceDesc->altsetting->bNumEndpoints; - device->numEndpoints = numEP; - // Check the total number of endpoints interface has - // and get all the endpoint add - CY_DEBUG_PRINT_INFO ("CY:Info The total number of endpoints are %d \n", numEP); - while (numEP){ - if (epDesc->bmAttributes == 0x2){ //Bulk EP checking - if (epDesc->bEndpointAddress & 0x80) - device->inEndpoint = epDesc->bEndpointAddress; - else - device->outEndpoint = epDesc->bEndpointAddress; - } - else if (epDesc->bmAttributes == 0x3) //Interrupt EP checking (We have only one interrupt EP) - device->interruptEndpoint = epDesc->bEndpointAddress; - epDesc++; - numEP--; - } - CY_DEBUG_PRINT_INFO ("CY:Info The Endpoints are in %d and out %d and interrup %d\n", - device->inEndpoint, device->outEndpoint, device->interruptEndpoint); - libusb_free_config_descriptor (configDesc); - return CY_SUCCESS; -} -/* - * This API selects the type of the device - */ -void CySelectDeviceType (CY_DEVICE *device, libusb_device *libUsbdev, unsigned char interfaceNum) -{ - int rStatus, numInterfaces; - struct libusb_config_descriptor *configDesc; - int index = 0; - const struct libusb_interface *interfaceDesc; - device->deviceType = CY_TYPE_DISABLED; - - rStatus = libusb_get_config_descriptor (libUsbdev, 0, &configDesc); - if (0 == rStatus){ - interfaceDesc = configDesc->interface; - numInterfaces = configDesc->bNumInterfaces; - if (interfaceNum >= numInterfaces) - return; - while (index != interfaceNum) { - index++; - interfaceDesc++; - } - if (interfaceDesc->altsetting->bInterfaceClass == CY_CLASS_VENDOR) - device->deviceType = (CY_DEVICE_TYPE)interfaceDesc->altsetting->bInterfaceSubClass; - libusb_free_config_descriptor (configDesc); - } - CY_DEBUG_PRINT_INFO ("CY:Info The device type is %d \n", device->deviceType); -} -/* - The Api Gets the handle for the specified device number - (refer to usage guide and example for usage) - and this handle should be called for further communication - with the device - */ -CY_RETURN_STATUS CyOpen ( - unsigned char deviceNumber, - unsigned char interfaceNum, - CY_HANDLE *handle - ) -{ - libusb_device_handle *devHandle; - libusb_device *dev; - CY_DEVICE *device; - int rStatus; - - if (glDriverInit == false){ - CY_DEBUG_PRINT_ERROR ("CY:Error Library not initialised ...function is %s\n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - pthread_mutex_lock (&criticalSection); - if (glDriverInit == true){ - if (deviceNumber >= glNumDevices){ - CY_DEBUG_PRINT_ERROR ("CY:Error ... Invalid device number ... \n"); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_INVALID_PARAMETER; - } - dev = glDeviceList [deviceNumber]; - rStatus = libusb_open (dev, &devHandle); - if (rStatus == LIBUSB_ERROR_ACCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in opening the device ..Access denied \n"); - handle = NULL; - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_ACCESS_DENIED; - } - if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in Opening the Device ...Error is %d \n", rStatus); - handle = NULL; - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DRIVER_OPEN_FAILED; - } - device = (CY_DEVICE *)malloc(sizeof (CY_DEVICE)); - if (device == NULL){ - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_ALLOCATION_FAILED; - } - device->devHandle = devHandle; - (*handle) = device; - rStatus = CySelectInterface (device, interfaceNum); - if (rStatus != CY_SUCCESS){ - libusb_close (devHandle); - free (device); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DRIVER_OPEN_FAILED; - } - CySelectDeviceType (device, dev, interfaceNum); - if (device->deviceType == CY_TYPE_UART) { - CyUartSetRts (*handle); - CyUartSetDtr (*handle); - if (!CyUartSetHwFlowControl (*handle, CY_UART_FLOW_CONTROL_DISABLE)) - device->uartFlowControlMode = CY_UART_FLOW_CONTROL_DISABLE; - } - //initialising structure elements - device->spiThreadRunning = false; - device->uartThreadRunning = false; - device->spiCancelEvent = false; - device->uartCancelEvent = false; - device->spiTransfer = NULL; - device->uartTransfer = NULL; - if (pthread_mutex_init (&device->readLock, NULL)){ - CY_DEBUG_PRINT_ERROR ("CY:Error initializing the read mutex .. Function is %s \n", __func__); - libusb_close (devHandle); - free (device); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DRIVER_OPEN_FAILED; - } - if (pthread_mutex_init (&device->writeLock, NULL)){ - CY_DEBUG_PRINT_ERROR ("CY:Error initializing the write mutex .. Function is %s \n", __func__); - libusb_close (devHandle); - free (device); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DRIVER_OPEN_FAILED; - } - if (pthread_mutex_init (&device->notificationLock, NULL)){ - CY_DEBUG_PRINT_ERROR ("CY:Error initializing the write mutex .. Function is %s \n", __func__); - libusb_close (devHandle); - free (device); - pthread_mutex_unlock (&criticalSection); - return CY_ERROR_DRIVER_OPEN_FAILED; - } - pthread_mutex_unlock (&criticalSection); - return CY_SUCCESS; - } - else{ - CY_DEBUG_PRINT_ERROR ("CY:Error iniitalise library by calling CyLibraryInit()....function is %s\n", __func__); - return CY_ERROR_DRIVER_OPEN_FAILED; - } -} -/* - The Api Closes the handle and needs to be called only if CyGetNumDevices - or CyOpen is called - */ -CY_RETURN_STATUS CyClose ( - CY_HANDLE handle - ) -{ - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - if (device->deviceType == CY_TYPE_UART) { - CyUartClearRts (handle); - CyUartClearDtr (handle); - CyUartSetHwFlowControl (handle, CY_UART_FLOW_CONTROL_DISABLE); - } - if (glDriverInit == true){ - if (device->deviceType == CY_TYPE_SPI || device->deviceType == CY_TYPE_UART){ - if (device->spiThreadRunning || device->uartThreadRunning){ - CyAbortEventNotification(handle); - } - } - if (pthread_mutex_destroy (&device->readLock)){ - CY_DEBUG_PRINT_ERROR ("CY:Error de initializing the read mutex .. Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (pthread_mutex_destroy (&device->writeLock)){ - CY_DEBUG_PRINT_ERROR ("CY:Error de initializing the write mutex .. Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - if (pthread_mutex_destroy (&device->notificationLock)){ - CY_DEBUG_PRINT_ERROR ("CY:Error de initializing the write mutex .. Function is %s \n", __func__); - return CY_ERROR_REQUEST_FAILED; - } - libusb_close ((libusb_device_handle*)devHandle); - free (device); - } - return CY_SUCCESS; -} -/* - This Api will reset the pipe and clears the endpoint - */ -CY_RETURN_STATUS CyResetPipe ( - CY_HANDLE handle, - UINT8 endPointAddress - ) -{ - UINT32 rStatus; - CY_DEVICE *device; - libusb_device_handle *devHandle; - - if (handle == NULL) - return CY_ERROR_INVALID_HANDLE; - device = (CY_DEVICE *)handle; - devHandle = device->devHandle; - - rStatus = libusb_clear_halt ((libusb_device_handle *)devHandle, endPointAddress); - if (rStatus != LIBUSB_SUCCESS){ - CY_DEBUG_PRINT_ERROR ("CY:Error in resetting the pipe ... \n"); - return CY_ERROR_REQUEST_FAILED; - } - return CY_SUCCESS; -} -/* - This Api will get the library version,patch - and build number - */ -CY_RETURN_STATUS CyGetLibraryVersion ( - CY_HANDLE handle, - PCY_LIBRARY_VERSION version - ) -{ - version->majorVersion = CY_US_VERSION_MAJOR; - version->minorVersion = CY_US_VERSION_MINOR; - version->patch = CY_US_VERSION_PATCH; - version->buildNumber = CY_US_VERSION_BUILD; - return CY_SUCCESS; -} +/* + * USB routines of Cypress USB Serial + * Copyright (C) 2013 Cypress Semiconductor + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "CyUSBCommon.h" + +static bool glDriverInit = false; +static libusb_device **glDeviceList; +static UINT32 glNumDevices; +/*The API initializes the Libusb library +*/ +pthread_mutex_t criticalSection; +CY_RETURN_STATUS CyLibraryInit () +{ + UINT32 rStatus; + rStatus = libusb_init (NULL); + + if (glDriverInit != true){ + if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Driver Init Failed ...\n"); + return CY_ERROR_DRIVER_INIT_FAILED; + } + glNumDevices = libusb_get_device_list (NULL, &glDeviceList); + if (glNumDevices < 0){ + CY_DEBUG_PRINT_ERROR ("CY:Building device list Failed ...\n"); + glNumDevices = -1; + return CY_ERROR_DRIVER_INIT_FAILED; + } + pthread_mutex_init (&criticalSection, NULL); + glDriverInit = true; + return CY_SUCCESS; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY:Error ... library already initialized \n"); + return CY_ERROR_DRIVER_INIT_FAILED; + } +} +/* + This API needs to be called after Calling CyGetListofDevices. + */ +CY_RETURN_STATUS CyLibraryExit () +{ + if (glDriverInit == true){ + if (glNumDevices >= 0) + libusb_free_device_list (glDeviceList, 1); + libusb_exit (NULL); + glDriverInit = false; + pthread_mutex_destroy (&criticalSection); + return CY_SUCCESS; + } + CY_DEBUG_PRINT_ERROR ("CY:Error ... Library not initialized \n"); + return CY_ERROR_REQUEST_FAILED; +} +/* + * This function Gets the number of all the devices currently + * Connected to the host (It includes Cypress Device as well as + * no Cypress Devices connected) + */ +CY_RETURN_STATUS CyGetListofDevices ( + UINT8 *numDevices + ) +{ + // Use this variable to call libusb_close and exit of the application + if (numDevices == NULL) + return CY_ERROR_INVALID_PARAMETER; + if (!glDriverInit){ + CY_DEBUG_PRINT_ERROR ("CY:Error Library not initialised ...function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + pthread_mutex_lock (&criticalSection); + libusb_free_device_list (glDeviceList, 1); + glNumDevices = (*numDevices) = libusb_get_device_list (NULL, &glDeviceList); + pthread_mutex_unlock (&criticalSection); + if (glNumDevices < 0){ + CY_DEBUG_PRINT_ERROR ("CY:Building device list Failed ...function is %s\n", __func__); + glNumDevices = -1; + (*numDevices) = -1; + return CY_ERROR_REQUEST_FAILED; + } + return CY_SUCCESS; +} +/* This function gets all the neccessary info such as VID,PID, + String Descriptors and if is a cypress serial device you will + get the info on class and device type + */ +CY_RETURN_STATUS CyGetDeviceInfo ( + UINT8 deviceNumber, + CY_DEVICE_INFO *deviceInfo + ) +{ + struct libusb_device_descriptor deviceDesc; + UINT32 rStatus, numInterfaces; + UINT8 iManufacturer, iProduct, iSerial; + libusb_device *usbDevice;; + struct libusb_config_descriptor *configDesc; + libusb_device_handle *devHandle; + + // Get the list of descriptor info for the device + if (glDriverInit == false){ + CY_DEBUG_PRINT_ERROR ("CY:Error Library not initialised ...function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (deviceInfo == NULL) + return CY_ERROR_INVALID_PARAMETER; + pthread_mutex_lock (&criticalSection); + if (deviceNumber >= glNumDevices){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device number... \n"); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_INVALID_PARAMETER; + } + usbDevice = glDeviceList[deviceNumber]; + rStatus = libusb_get_device_descriptor (usbDevice, &deviceDesc); + if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error ... unable to retrieve device descriptor \n"); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_DEVICE_INFO_FETCH_FAILED; + } + + deviceInfo->vidPid.vid = deviceDesc.idVendor; + deviceInfo->vidPid.pid = deviceDesc.idProduct; + // Get the all the index of the String descriptors so that it can be used + // to retrieve the string descriptor info. + iManufacturer = deviceDesc.iManufacturer; + iProduct = deviceDesc.iProduct; + iSerial = deviceDesc.iSerialNumber; + //Get the Device handle so that we can communicate with the device retreiving + // descriptor info + deviceInfo->manufacturerName[0] = '\0'; + deviceInfo->productName[0] = '\0'; + deviceInfo->serialNum[0] = '\0'; + rStatus = libusb_open (usbDevice, &devHandle); + if (rStatus == LIBUSB_ERROR_ACCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error ...Insufficient permission... Libusb error is %d \n", rStatus); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_ACCESS_DENIED; + } + else if (rStatus != CY_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in opening the device... Libusb error is %d \n", rStatus); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_DEVICE_INFO_FETCH_FAILED; + } + if (iManufacturer > 0){ + rStatus = libusb_get_string_descriptor_ascii (devHandle, iManufacturer, deviceInfo->manufacturerName, 256); + if (rStatus <= LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in Getting Manufacturer name Error is <%x> \n", rStatus); + } + } + if (iProduct > 0){ + rStatus = libusb_get_string_descriptor_ascii (devHandle, iProduct, deviceInfo->productName, 256); + if (rStatus <= LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in Getting product name Error is <%d> \n", rStatus); + } + } + if (iSerial > 0){ + rStatus = libusb_get_string_descriptor_ascii (devHandle, iSerial, deviceInfo->serialNum, 256); + if (rStatus <= LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in Getting Serial name <%d>\n", rStatus); + } + } + rStatus = libusb_get_config_descriptor (usbDevice, 0, &configDesc); + if (rStatus == LIBUSB_SUCCESS){ + UINT32 index_i = 0; + const struct libusb_interface *interface; + numInterfaces = configDesc->bNumInterfaces; + deviceInfo->numInterfaces = numInterfaces; + interface = configDesc->interface; + while ((numInterfaces) && (index_i < CY_MAX_DEVICE_INTERFACE)){ + deviceInfo->deviceClass[index_i] = (CY_DEVICE_CLASS)interface->altsetting->bInterfaceClass; + if (deviceInfo->deviceClass[index_i] == CY_CLASS_VENDOR){ + deviceInfo->deviceType[index_i] = (CY_DEVICE_CLASS)interface->altsetting->bInterfaceSubClass; + } + else + deviceInfo->deviceType[index_i] = CY_TYPE_DISABLED; + index_i++; + numInterfaces--; + interface++; + } + libusb_free_config_descriptor(configDesc); + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in Getting config descriptor ...Libusb error is %d \n", rStatus); + if (devHandle) + libusb_close (devHandle); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_DEVICE_INFO_FETCH_FAILED; + } + if (devHandle) + libusb_close (devHandle); + pthread_mutex_unlock (&criticalSection); + return CY_SUCCESS; +} +/* This function gets all the neccessary info such as VID,PID, + String Descriptors and if is a cypress serial device you will + get the info on class and device type + */ +CY_RETURN_STATUS CyGetDeviceInfoVidPid ( + CY_VID_PID vidPid, + UINT8 *deviceNumber, + PCY_DEVICE_INFO deviceInfoList, + UINT8 *deviceCount, + UINT8 infoListLength + ) +{ + struct libusb_device_descriptor deviceDesc; + UINT32 rStatus = CY_ERROR_DRIVER_INIT_FAILED, numInterfaces, index = 0, devNum; + uint8_t iManufacturer, iProduct, iSerial; + libusb_device *usbDevice; + struct libusb_config_descriptor *configDesc; + libusb_device_handle *devHandle = NULL; + PCY_DEVICE_INFO deviceInfo; + + if (glDriverInit == false){ + CY_DEBUG_PRINT_ERROR ("CY:Error Library not initialised ...function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if ((infoListLength) < 1){ + CY_DEBUG_PRINT_ERROR ("CY:Error invalid device info list length specified should be > 0 .. function is %s\n", __func__); + return CY_ERROR_INVALID_PARAMETER; + } + if (deviceNumber == NULL || deviceInfoList == NULL || deviceCount == NULL) + return CY_ERROR_INVALID_PARAMETER; + // Get the list of descriptor info for the device + (*deviceCount) = 0; + pthread_mutex_lock (&criticalSection); + for (devNum = 0; devNum < glNumDevices; devNum++) { + //We are making sure that we do not overrun + //the list. + deviceInfo = &(deviceInfoList [index]); + usbDevice = glDeviceList[devNum]; + rStatus = libusb_get_device_descriptor (usbDevice, &deviceDesc); + if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in getting device descriptor for device-%d... Libusb Error is %d \n", devNum, rStatus); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_DEVICE_INFO_FETCH_FAILED; + } + if ((deviceDesc.idVendor != vidPid.vid) || (deviceDesc.idProduct != vidPid.pid)){ + continue; + } + (*deviceCount)++; + if (index > infoListLength){ + continue; + } + rStatus = libusb_open (usbDevice, &devHandle); + if (rStatus == LIBUSB_ERROR_ACCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Insufficient permission ... Libusb error is %d \n", rStatus); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_ACCESS_DENIED; + } + else if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in Opening the Device ...Error is %d \n", rStatus); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_DEVICE_INFO_FETCH_FAILED; + } + deviceNumber[index] = devNum; + index++; + deviceInfo->vidPid.vid = deviceDesc.idVendor; + deviceInfo->vidPid.pid = deviceDesc.idProduct; + // Get all the index of the String descriptors so that it can be used + // to retrieve the string descriptor info. + iManufacturer = deviceDesc.iManufacturer; + iProduct = deviceDesc.iProduct; + iSerial = deviceDesc.iSerialNumber; + //Get the Device handle so that we can communicate with the device retreiving + // descriptor info + //Initialise manufacturer, product and serial names + deviceInfo->manufacturerName[0] = '\0'; + deviceInfo->productName[0] = '\0'; + deviceInfo->serialNum[0] = '\0'; + if (iManufacturer > 0) { + rStatus = libusb_get_string_descriptor_ascii (devHandle, iManufacturer, deviceInfo->manufacturerName, 256); + if (rStatus <= LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_INFO ("CY:Error in Getting Manufacturer name Error is <%d> \n",rStatus); + } + } + if (iProduct > 0){ + rStatus = libusb_get_string_descriptor_ascii (devHandle, iProduct, deviceInfo->productName, 256); + if (rStatus <= LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_INFO ("CY:Error in Getting product name Error is <%d> \n", rStatus); + } + } + if (iSerial > 0){ + rStatus = libusb_get_string_descriptor_ascii (devHandle, iSerial, deviceInfo->serialNum, 256); + if (rStatus <= LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_INFO ("CY:Error in Getting Serial name <%d>\n", rStatus); + } + } + CY_DEBUG_PRINT_INFO ("Manufacturer name <%s> \nProduct Name <%s> \nserial number <%s> \n", + deviceInfo->manufacturerName,deviceInfo->productName,deviceInfo->serialNum); + rStatus = libusb_get_config_descriptor (usbDevice, 0, &configDesc); + if (rStatus == LIBUSB_SUCCESS){ + int index_i = 0; + const struct libusb_interface *interfaceDesc; + numInterfaces = configDesc->bNumInterfaces; + deviceInfo->numInterfaces = numInterfaces; + interfaceDesc = configDesc->interface; + while ((numInterfaces) && (index_i < CY_MAX_DEVICE_INTERFACE)){ + deviceInfo->deviceClass[index_i] = (CY_DEVICE_CLASS)interfaceDesc->altsetting->bInterfaceClass; + if (deviceInfo->deviceClass[index_i] == CY_CLASS_VENDOR) + deviceInfo->deviceType[index_i] = (CY_DEVICE_CLASS)interfaceDesc->altsetting->bInterfaceSubClass; + else + deviceInfo->deviceType[index_i] = CY_TYPE_DISABLED; + + index_i++; + numInterfaces--; + interfaceDesc++; + } + } + else { + CY_DEBUG_PRINT_ERROR ("CY: Error in Getting config descriptor ... Libusb Error is %d\n", rStatus); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_DEVICE_INFO_FETCH_FAILED; + } + libusb_free_config_descriptor (configDesc); + libusb_close (devHandle); + } + if ((*deviceCount) == 0) + rStatus = CY_ERROR_DEVICE_NOT_FOUND; + pthread_mutex_unlock (&criticalSection); + return rStatus; +} +/* + This API will claim the interface in the device + To make sure only claimed application speaks to device. + */ +CY_RETURN_STATUS CySelectInterface ( + CY_HANDLE handle, + UINT8 interfaceNum + ) +{ + UINT32 rStatus, numEP; + CY_DEVICE *device; + libusb_device_handle *devHandle; + libusb_device *usbDev; + struct libusb_config_descriptor *configDesc; + const struct libusb_interface *interfaceDesc; + const struct libusb_endpoint_descriptor *epDesc; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + usbDev = libusb_get_device (devHandle); + if (usbDev == NULL){ + CY_DEBUG_PRINT_ERROR ("CY:Error Invalide handle ..function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + //Get the config descriptor and parse it to get the + //interface and endpoint descriptor + rStatus = libusb_get_config_descriptor (usbDev, 0, &configDesc); + if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in Getting Config Desc ...function is %s\n", __func__); + printf("\n rstatus10= %d",rStatus); + return CY_ERROR_REQUEST_FAILED; + } + interfaceDesc = configDesc->interface; + //Interface Number should be a valid one and should not exceed + // total number of interfaces + if (interfaceNum >= configDesc->bNumInterfaces){ + CY_DEBUG_PRINT_ERROR ("CY:Interface Number not valid... \n"); + libusb_free_config_descriptor (configDesc); + printf("\n rstatus11= %d",rStatus); + return CY_ERROR_REQUEST_FAILED; + } + if (libusb_kernel_driver_active (devHandle, interfaceNum)){ + CY_DEBUG_PRINT_ERROR ("CY:Kernel driver active on the interface number %d \n", interfaceNum);; + /*User can uncomment this section if needed. +#ifdef CY_DETACH_KERNEL_DRIVER + if (!libusb_detach_kernel_driver (devHandle, interfaceNum)){ + CY_DEBUG_PRINT_ERROR ("CY:Kernel driver detach failed %d\n", interfaceNum); +printf("\n rstatus12= %d",rStatus); + return CY_ERROR_REQUEST_FAILED; + } +#else + printf("\n rstatus13= %d",rStatus); + return CY_ERROR_REQUEST_FAILED; +#endif + } + rStatus = libusb_claim_interface (devHandle, interfaceNum); + if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in claiming interface -interface num %d... Libusb error is %d \n", interfaceNum, rStatus); + printf("\n rstatus14= %d",rStatus); + return CY_ERROR_REQUEST_FAILED; + }*/ +} + device->interfaceNum = interfaceNum; + while (interfaceNum--) + interfaceDesc++; + + epDesc = interfaceDesc->altsetting->endpoint; + numEP = interfaceDesc->altsetting->bNumEndpoints; + device->numEndpoints = numEP; + // Check the total number of endpoints interface has + // and get all the endpoint add + CY_DEBUG_PRINT_INFO ("CY:Info The total number of endpoints are %d \n", numEP); + while (numEP){ + if (epDesc->bmAttributes == 0x2){ //Bulk EP checking + if (epDesc->bEndpointAddress & 0x80) + device->inEndpoint = epDesc->bEndpointAddress; + else + device->outEndpoint = epDesc->bEndpointAddress; + } + else if (epDesc->bmAttributes == 0x3) //Interrupt EP checking (We have only one interrupt EP) + device->interruptEndpoint = epDesc->bEndpointAddress; + epDesc++; + numEP--; + } + CY_DEBUG_PRINT_INFO ("CY:Info The Endpoints are in %d and out %d and interrup %d\n", + device->inEndpoint, device->outEndpoint, device->interruptEndpoint); + libusb_free_config_descriptor (configDesc); + return CY_SUCCESS; +} +/* + * This API selects the type of the device + */ +void CySelectDeviceType (CY_DEVICE *device, libusb_device *libUsbdev, unsigned char interfaceNum) +{ + int rStatus, numInterfaces; + struct libusb_config_descriptor *configDesc; + int index = 0; + const struct libusb_interface *interfaceDesc; + device->deviceType = CY_TYPE_DISABLED; + + rStatus = libusb_get_config_descriptor (libUsbdev, 0, &configDesc); + if (0 == rStatus){ + interfaceDesc = configDesc->interface; + numInterfaces = configDesc->bNumInterfaces; + if (interfaceNum >= numInterfaces) + return; + while (index != interfaceNum) { + index++; + interfaceDesc++; + } + if (interfaceDesc->altsetting->bInterfaceClass == CY_CLASS_VENDOR) + device->deviceType = (CY_DEVICE_CLASS)interfaceDesc->altsetting->bInterfaceSubClass; + libusb_free_config_descriptor (configDesc); + } + CY_DEBUG_PRINT_INFO ("CY:Info The device type is %d \n", device->deviceType); +} +/* + The Api Gets the handle for the specified device number + (refer to usage guide and example for usage) + and this handle should be called for further communication + with the device + */ +CY_RETURN_STATUS CyOpen ( + unsigned char deviceNumber, + unsigned char interfaceNum, + CY_HANDLE *handle + ) +{ + libusb_device_handle *devHandle; + libusb_device *dev; + CY_DEVICE *device; + UINT32 rStatus; + + if (glDriverInit == false){ + CY_DEBUG_PRINT_ERROR ("CY:Error Library not initialised ...function is %s\n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + pthread_mutex_lock (&criticalSection); + if (glDriverInit == true){ + if (deviceNumber >= glNumDevices){ + CY_DEBUG_PRINT_ERROR ("CY:Error ... Invalid device number ... \n"); + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_INVALID_PARAMETER; + } + dev = glDeviceList [deviceNumber]; + rStatus = libusb_open (dev, &devHandle); + if (rStatus == LIBUSB_ERROR_ACCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in opening the device ..Access denied \n"); + handle = NULL; + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_ACCESS_DENIED; + } + if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in Opening the Device ...Error is %d \n", rStatus); + printf("rstatus1 %d", rStatus); + handle = NULL; + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_DRIVER_OPEN_FAILED; + } + device = (CY_DEVICE *)malloc(sizeof (CY_DEVICE)); + if (device == NULL){ + pthread_mutex_unlock (&criticalSection); + return CY_ERROR_ALLOCATION_FAILED; + } + device->devHandle = devHandle; + (*handle) = device; + rStatus = CySelectInterface (device, interfaceNum); + if (rStatus != CY_SUCCESS){ + libusb_close (devHandle); + free (device); + pthread_mutex_unlock (&criticalSection); +printf("rstatus2 %d", rStatus); + return CY_ERROR_DRIVER_OPEN_FAILED; + } + CySelectDeviceType (device, dev, interfaceNum); + if (device->deviceType == CY_TYPE_UART) { + CyUartSetRts (*handle); + CyUartSetDtr (*handle); + if (!CyUartSetHwFlowControl (*handle, CY_UART_FLOW_CONTROL_DISABLE)) + device->uartFlowControlMode = CY_UART_FLOW_CONTROL_DISABLE; + } + //initialising structure elements + device->spiThreadId = (pthread_t)0; + device->uartThreadId = (pthread_t)0; + device->spiCancelEvent = false; + device->uartCancelEvent = false; + device->spiTransfer = NULL; + device->uartTransfer = NULL; + if (pthread_mutex_init (&device->readLock, NULL)){ + CY_DEBUG_PRINT_ERROR ("CY:Error initializing the read mutex .. Function is %s \n", __func__); + libusb_close (devHandle); + free (device); + pthread_mutex_unlock (&criticalSection); +printf("rstatus3 %d", rStatus); + return CY_ERROR_DRIVER_OPEN_FAILED; + } + if (pthread_mutex_init (&device->writeLock, NULL)){ + CY_DEBUG_PRINT_ERROR ("CY:Error initializing the write mutex .. Function is %s \n", __func__); + libusb_close (devHandle); + free (device); + pthread_mutex_unlock (&criticalSection); +printf("rstatus4 %d", rStatus); + return CY_ERROR_DRIVER_OPEN_FAILED; + } + if (pthread_mutex_init (&device->notificationLock, NULL)){ + CY_DEBUG_PRINT_ERROR ("CY:Error initializing the write mutex .. Function is %s \n", __func__); + libusb_close (devHandle); + free (device); + pthread_mutex_unlock (&criticalSection); +printf("rstatus5 %d", rStatus); + return CY_ERROR_DRIVER_OPEN_FAILED; + } + pthread_mutex_unlock (&criticalSection); + return CY_SUCCESS; + } + else{ + CY_DEBUG_PRINT_ERROR ("CY:Error iniitalise library by calling CyLibraryInit()....function is %s\n", __func__); +printf("rstatus6 %d", rStatus); + return CY_ERROR_DRIVER_OPEN_FAILED; + } + + +} +/* + The Api Closes the handle and needs to be called only if CyGetNumDevices + or CyOpen is called + */ +CY_RETURN_STATUS CyClose ( + CY_HANDLE handle + ) +{ + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + if (device->deviceType == CY_TYPE_UART) { + CyUartClearRts (handle); + CyUartClearDtr (handle); + CyUartSetHwFlowControl (handle, CY_UART_FLOW_CONTROL_DISABLE); + } + if (glDriverInit == true){ + if (device->deviceType == CY_TYPE_SPI || device->deviceType == CY_TYPE_UART){ + if (device->spiThreadId != 0 || device->uartThreadId != 0){ + CyAbortEventNotification(handle); + } + } + if (pthread_mutex_destroy (&device->readLock)){ + CY_DEBUG_PRINT_ERROR ("CY:Error de initializing the read mutex .. Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (pthread_mutex_destroy (&device->writeLock)){ + CY_DEBUG_PRINT_ERROR ("CY:Error de initializing the write mutex .. Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + if (pthread_mutex_destroy (&device->notificationLock)){ + CY_DEBUG_PRINT_ERROR ("CY:Error de initializing the write mutex .. Function is %s \n", __func__); + return CY_ERROR_REQUEST_FAILED; + } + libusb_close ((libusb_device_handle*)devHandle); + free (device); + } + return CY_SUCCESS; +} +/* + This Api will reset the pipe and clears the endpoint + */ +CY_RETURN_STATUS CyResetPipe ( + CY_HANDLE handle, + UINT8 endPointAddress + ) +{ + UINT32 rStatus; + CY_DEVICE *device; + libusb_device_handle *devHandle; + + if (handle == NULL) + return CY_ERROR_INVALID_HANDLE; + device = (CY_DEVICE *)handle; + devHandle = device->devHandle; + + rStatus = libusb_clear_halt ((libusb_device_handle *)devHandle, endPointAddress); + if (rStatus != LIBUSB_SUCCESS){ + CY_DEBUG_PRINT_ERROR ("CY:Error in resetting the pipe ... \n"); + return CY_ERROR_REQUEST_FAILED; + } + return CY_SUCCESS; +} +/* + This Api will get the library version,patch + and build number + */ +CY_RETURN_STATUS CyGetLibraryVersion ( + CY_HANDLE handle, + PCY_LIBRARY_VERSION version + ) +{ + version->majorVersion = CY_US_VERSION_MAJOR; + version->minorVersion = CY_US_VERSION_MINOR; + version->patch = CY_US_VERSION_PATCH; + version->buildNumber = CY_US_VERSION_BUILD; + return CY_SUCCESS; +} diff --git a/configutility/linux/library/libcyusbserial.so b/configutility/linux/library/libcyusbserial.so new file mode 100644 index 0000000..09240c7 --- /dev/null +++ b/configutility/linux/library/libcyusbserial.so @@ -0,0 +1 @@ +libcyusbserial.so.1 \ No newline at end of file diff --git a/configutility/linux/library/libcyusbserial.so.1 b/configutility/linux/library/libcyusbserial.so.1 new file mode 100755 index 0000000..2490c93 Binary files /dev/null and b/configutility/linux/library/libcyusbserial.so.1 differ diff --git a/configutility/linux/testUtility/90-cyusb.rules b/configutility/linux/testUtility/90-cyusb.rules new file mode 100644 index 0000000..4494809 --- /dev/null +++ b/configutility/linux/testUtility/90-cyusb.rules @@ -0,0 +1,5 @@ +# Cypress USB driver for FX2 and FX3 (C) Cypress Semiconductor Corporation / ATR-LABS +# Rules written by V. Radhakrishnan ( rk@atr-labs.com ) +# Cypress USB vendor ID = 0x04b4 +KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="add", ATTR{idVendor}=="04b4", MODE="666", TAG="cyusb_dev", RUN+="/usr/bin/CyUSBSerial.sh A" +KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="remove", TAG=="cyusb_dev", RUN+="/usr/bin/CyUSBSerial.sh R" diff --git a/tinio/cy-config.c b/configutility/linux/testUtility/Command_Utility.c similarity index 90% rename from tinio/cy-config.c rename to configutility/linux/testUtility/Command_Utility.c index f64abb8..01ef543 100644 --- a/tinio/cy-config.c +++ b/configutility/linux/testUtility/Command_Utility.c @@ -30,8 +30,8 @@ #include #include -#include "include/CyUSBSerial.h" -#include "include/CyUSBBootloader.h" +#include "../../common/header/CyUSBSerial.h" +#include "../../common/header/CyUSBBootloader.h" #define CY_MAX_DEVICES 30 #define CY_MAX_INTERFACES 4 @@ -41,7 +41,7 @@ typedef struct _CY_DEVICE_STRUCT { int interfaceFunctionality[CY_MAX_INTERFACES]; bool isI2c; bool isSpi; - int numInterface; + int numInterface; }CY_DEVICE_STRUCT; CY_DEVICE_STRUCT *glDevice; @@ -54,7 +54,331 @@ unsigned short pageAddress = -1; short readWriteLength = -1; bool deviceAddedRemoved = false; unsigned char read_buffer[512]; +int getUserInput() +{ + char userInput[6], x; + int output,i = 0; + bool isDigit = true; + x = getchar(); + while (x != '\n'){ + if (i < 5){ + userInput[i] = x; + i++; + } + if (!isdigit(x)) + isDigit = false; + x = getchar(); + } + userInput[i] = '\0'; + if (isDigit == false) + return -1; + output = atoi(userInput); + return output; +} + + +unsigned int GetCheckSum(unsigned int *buff, unsigned int length) +{ + unsigned int i,val; + unsigned int checkSum =0; + + for (i = 0; i < length; i++) // start at 12th byte + { + checkSum += buff[i]; + } + + return checkSum; +} + + +void deviceHotPlug () { + + CY_RETURN_STATUS rStatus; + deviceAddedRemoved = true; + selectedDeviceNum = -1; + selectedInterfaceNum = -1; + printf ("Device of interest Removed/Added \n"); + rStatus = CyGetListofDevices (&numDevices); + if (rStatus != CY_SUCCESS) { + printf ("CY:Error in Getting List of Devices: Error NO:<%d> \n", rStatus); + return rStatus; + } + printListOfDevices (false); +} + +int main (int argc, char **argv) +{ + int index = 0, i, j, userInput; + int output; + int count=0,h=0,cnt; + int size_buffer,size_checksum; + FILE *fp=NULL; + CY_HANDLE handle; + unsigned char buff[516]; + int silicon_id; + int tempSelectedDeviceNum, tempSelectedInterfaceNum; + CY_RETURN_STATUS rStatus; + signal (SIGUSR1, deviceHotPlug); + char src_file[100]; + char id[4]; + + memset(buff,0,sizeof(buff)); + + + glDevice = (CY_DEVICE_STRUCT *)malloc (CY_MAX_DEVICES *sizeof (CY_DEVICE_STRUCT)); + if (glDevice == NULL){ + printf ("Memory allocation failed ...!! \n"); + return -1; + } + rStatus = CyLibraryInit (); + if (rStatus != CY_SUCCESS) { + printf ("CY:Error in Doing library init Error NO:<%d> \n", rStatus); + return rStatus; + } + rStatus = CyGetListofDevices (&numDevices); + if (rStatus != CY_SUCCESS) { + printf ("CY:Error in Getting List of Devices: Error NO:<%d> \n", rStatus); + return rStatus; + } + printListOfDevices(true); + do { + + printf ("-------------------------------------------------------------------\n"); + printf ("1: Print list of devices \n"); + if (selectedDeviceNum != -1 && selectedInterfaceNum != -1){ + printf ("2: Change device selection--selected device: [Device number %d] : [Interface No %d]",\ + selectedDeviceNum, selectedInterfaceNum); + if (glDevice[selectedDeviceNum].interfaceFunctionality[selectedInterfaceNum] == CY_TYPE_I2C) + printf (" : I2C\n"); + else if (glDevice[selectedDeviceNum].interfaceFunctionality[selectedInterfaceNum] == CY_TYPE_SPI) + printf (" : SPI\n"); + else if (glDevice[selectedDeviceNum].interfaceFunctionality[selectedInterfaceNum] == CY_TYPE_UART) + printf ("UART : \n"); + else + printf (" : NA\n"); + + } + else + printf ("2: Select device...No device selected !!\n"); + + + userInput = getUserInput(); + if (userInput < 1 || userInput > 5){ + printf ("Wrong selection code ... Enter again \n"); + continue; + } + + switch (userInput){ + + case 1: + printListOfDevices(true); + break; + case 2: + if (cyDevices == 0) { + printf ("No device of interest connected ...!!\n"); + continue; + } + printf ("Enter Device number to be selected.. \n"); + tempSelectedDeviceNum = getUserInput(); + //printf ("Selected device number is %d \n",tempSelectedDeviceNum); + if (tempSelectedDeviceNum >= cyDevices || tempSelectedDeviceNum == -1){ + printf ("Wrong device selection \n"); + continue; + } + printf ("Enter interface number..\n"); + tempSelectedInterfaceNum = getUserInput(); + //printf ("Selected device number is %d %d\n",tempSelectedInterfaceNum, glDevice[tempSelectedDeviceNum].numInterface); + + if (tempSelectedInterfaceNum >= glDevice[tempSelectedDeviceNum].numInterface || + tempSelectedInterfaceNum == -1) { + printf ("Wrong interface Selection selection \n"); + continue; + } + + if (deviceAddedRemoved == true) { + printf ("Device of interest was added/removed .... Print and select from new list\n"); + continue; + } + selectedDeviceNum = tempSelectedDeviceNum; + selectedInterfaceNum = tempSelectedInterfaceNum; + + + rStatus = CyOpen (selectedDeviceNum,selectedInterfaceNum , &handle); + //printf("return status = %d", rStatus); + if (rStatus == CY_SUCCESS){ + //printf("device opened \n"); + } + else + { + printf("fail \n"); + } + + + + // printf("Please enter file to be opened"); + + fp = fopen(argv[1],"rb+"); + // printf("%s", src_file); + rStatus = CyFlashConfigEnable(handle,1); + + if (rStatus == CY_SUCCESS){ + // printf("Flash is configured"); + } + else + { + printf("Manufacturing mode of FLASH is not configured"); + } + // printf("status %d",rStatus); + + if(fp == NULL) + { + printf("\n fopen() Error!!!\n"); + return 1; + } + printf("\n File opened successfully\n"); + if(sizeof(buff) != fread(buff,1,516,fp)) + { + printf("\n fread() failed\n"); + return 1; + } + printf("\n Bytes successfully read \n"); + // printf("reached here"); + + // silicon_id = *(unsigned int *)buff; + + rStatus=CyGetSiliconID(handle,&silicon_id); + if (rStatus == CY_SUCCESS){ + // printf(" Correct silicon id"); + + } + else + { + printf("Not correct ID"); + } + + // printf("silicon id %04x,%d",silicon_id,sizeof(silicon_id)); + id[0]= (silicon_id); + id[1]= ((silicon_id >> 8) & 0xFF); + id[2]= ((silicon_id >> 16) & 0xFF); + id[3]= ((silicon_id >> 24) & 0xFF); + + + + rStatus=CyReadDeviceConfig(handle,&read_buffer); + if (rStatus == CY_SUCCESS){ + // printf(" Got the data"); + + } + else + { + printf("Not done"); + } + + /*printf (" 0 %02x, %02x \r \n", id[0],read_buffer[0]); + printf (" 1 %02x, %02x \r \n", id[1],read_buffer[1]); + printf (" 2 %02x, %02x \r \n", id[2],read_buffer[2]); + printf (" 3 %02x, %02x\r \n", id[3],read_buffer[3]);*/ + + size_buffer = sizeof(read_buffer); + //printf("The size is %d, buff %d", size_buffer,sizeof(buff)); + + /*for (i = 4; i < 516; i +=16) + { + printf("\n%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", + buff[i], buff[i+1], buff[i+2], buff[i+3], buff[i+4], buff[i+5], buff[i+6], buff[i+7], buff[i+8], + buff[i+9], buff[i+10], buff[i+11], buff[i+12], buff[i+13], buff[i+14], buff[i+15]); + } + for (i = 0; i < 512; i +=16) + { + printf("\n%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", + read_buffer[i], read_buffer[i+1], read_buffer[i+2], read_buffer[i+3], read_buffer[i+4], read_buffer[i+5], read_buffer[i+6], + read_buffer[i+7], read_buffer[i+8], + read_buffer[i+9], read_buffer[i+10], read_buffer[i+11], read_buffer[i+12], read_buffer[i+13], read_buffer[i+14], read_buffer[i+15]); + }*/ + memcpy (&buff[4], read_buffer, 28); + + size_checksum= GetCheckSum((unsigned int *)(&buff[16]), 125); + // printf("The checksum size is %d",size_checksum); + + buff[12]= (size_checksum & 0xFF); + buff[13]= ((size_checksum >> 8) & 0xFF); + buff[14]= ((size_checksum >> 16) & 0xFF); + buff[15]= ((size_checksum >> 24) & 0xFF); + + // printf("checksum 0x%08x\n", size_checksum); + /* for (i = 4; i < 516; i +=16) + { + printf("\n%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", + buff[i], buff[i+1], buff[i+2], buff[i+3], buff[i+4], buff[i+5], buff[i+6], buff[i+7], buff[i+8], + buff[i+9], buff[i+10], buff[i+11], buff[i+12], buff[i+13], buff[i+14], buff[i+15]); + }*/ + + // if(((id[0] == ffffffA1) || (id[0] == ffffffA2) || (id[0] == ffffffA3)) && (id[1] == 08)) + if((silicon_id == 0x08A1) || (silicon_id == 0x08A2) || (silicon_id == 0x08A3)) + { + + rStatus= CyWriteDeviceConfig(handle,&buff[4]); + if (rStatus == CY_SUCCESS){ + printf(" Programming Flash is done"); + } + else + { + printf("Not done"); + } + } + else + { + printf("wrong silicon id"); + } + + fclose(fp); + + printf("\n File stream closed \n"); + + + + rStatus= CyClose(handle); + if (rStatus == CY_SUCCESS){ + //printf("Device closed"); + } + else + { + printf("Not closed"); + } + + + break; + case 3: + exitApp = true; + CyLibraryExit (); + break; + } + }while (exitApp == false); + free (glDevice); +} +bool isCypressDevice (int deviceNum) { + CY_HANDLE handle; + unsigned char interfaceNum = 0; + unsigned char sig[6]; +int op; + CY_RETURN_STATUS rStatus; + rStatus = CyOpen (deviceNum, interfaceNum, &handle); + //op= libusb_detach_kernel_driver(handle,0); + if (rStatus == CY_SUCCESS){ + rStatus = CyGetSignature (handle, sig); + if (rStatus == CY_SUCCESS){ + CyClose (handle); + return true; + } + else { + CyClose (handle); + return false; + } + } + else + return false; +} void printListOfDevices (bool isPrint) { int index_i = 0, index_j = 0, i, j, countOfDevice = 0, devNum; @@ -62,15 +386,15 @@ void printListOfDevices (bool isPrint) bool set1 = false; unsigned char deviceID[CY_MAX_DEVICES]; - char functionality[64]; + unsigned char functionality[64]; CY_DEVICE_INFO deviceInfo; CY_DEVICE_CLASS deviceClass[CY_MAX_INTERFACES]; CY_DEVICE_TYPE deviceType[CY_MAX_INTERFACES]; CY_RETURN_STATUS rStatus; - deviceAddedRemoved = false; - CyGetListofDevices ((UINT8 *)&numDevices); - //printf ("The number of devices is %d \n", numDevices); + deviceAddedRemoved = false; + CyGetListofDevices (&numDevices); + //printf ("The number of devices is %d \n", numDevices); for (i = 0; i < numDevices; i++){ for (j = 0; j< CY_MAX_INTERFACES; j++) glDevice[i].interfaceFunctionality[j] = -1; @@ -111,14 +435,14 @@ void printListOfDevices (bool isPrint) break; default: strcpy (functionality, "NA"); - break; + break; } } else if (deviceInfo.deviceClass[interfaceNum] == CY_CLASS_CDC){ strcpy (functionality, "NA"); } if (isPrint) { - printf ("%d |%x |%x | %d | %s\n", \ + printf ("%d |%x |%x | %d | %s\n", \ index, \ deviceInfo.vidPid.vid, \ deviceInfo.vidPid.pid, \ @@ -138,328 +462,3 @@ void printListOfDevices (bool isPrint) printf("Cydevices %d",cyDevices); } -void deviceHotPlug () { - - CY_RETURN_STATUS rStatus; - deviceAddedRemoved = true; - selectedDeviceNum = -1; - selectedInterfaceNum = -1; - printf ("Device of interest Removed/Added \n"); - rStatus = CyGetListofDevices ((UINT8 *)&numDevices); - if (rStatus != CY_SUCCESS) { - printf ("CY:Error in Getting List of Devices: Error NO:<%d> \n", rStatus); - return; - } - printListOfDevices (false); -} - -int getUserInput() -{ - char userInput[6], x; - int output,i = 0; - bool isDigit = true; - x = getchar(); - while (x != '\n'){ - if (i < 5){ - userInput[i] = x; - i++; - } - if (!isdigit(x)) - isDigit = false; - - x = getchar(); - } - userInput[i] = '\0'; - if (isDigit == false) - return -1; - output = atoi(userInput); - return output; -} - - -unsigned int GetCheckSum(unsigned int *buff, unsigned int length) -{ - unsigned int i,val; - unsigned int checkSum =0; - - for (i = 0; i < length; i++) // start at 12th byte - { - checkSum += buff[i]; - } - - return checkSum; -} - - -int main (int argc, char **argv) -{ - int index = 0, i, j, userInput; - int output; - int count=0,h=0,cnt; - int size_buffer,size_checksum; - FILE *fp=NULL; - CY_HANDLE handle; - unsigned char buff[516]; - int silicon_id; - int tempSelectedDeviceNum, tempSelectedInterfaceNum; - CY_RETURN_STATUS rStatus; - //signal (SIGUSR1, deviceHotPlug); - char src_file[100]; - char id[4]; - - memset(buff,0,sizeof(buff)); - - - glDevice = (CY_DEVICE_STRUCT *)malloc (CY_MAX_DEVICES *sizeof (CY_DEVICE_STRUCT)); - if (glDevice == NULL){ - printf ("Memory allocation failed ...!! \n"); - return -1; - } - rStatus = CyLibraryInit (); - if (rStatus != CY_SUCCESS) { - printf ("CY:Error in Doing library init Error NO:<%d> \n", rStatus); - return rStatus; - } - rStatus = CyGetListofDevices ((UINT8 *)&numDevices); - if (rStatus != CY_SUCCESS) { - printf ("CY:Error in Getting List of Devices: Error NO:<%d> \n", rStatus); - return rStatus; - } - printListOfDevices(true); - do { - - printf ("-------------------------------------------------------------------\n"); - printf ("1: Print list of devices \n"); - if (selectedDeviceNum != -1 && selectedInterfaceNum != -1){ - printf ("2: Change device selection--selected device: [Device number %d] : [Interface No %d]",\ - selectedDeviceNum, selectedInterfaceNum); - if (glDevice[selectedDeviceNum].interfaceFunctionality[selectedInterfaceNum] == CY_TYPE_I2C) - printf (" : I2C\n"); - else if (glDevice[selectedDeviceNum].interfaceFunctionality[selectedInterfaceNum] == CY_TYPE_SPI) - printf (" : SPI\n"); - else if (glDevice[selectedDeviceNum].interfaceFunctionality[selectedInterfaceNum] == CY_TYPE_UART) - printf ("UART : \n"); - else - printf (" : NA\n"); - - } - else - printf ("2: Select device...No device selected !!\n"); - - - userInput = getUserInput(); - if (userInput < 1 || userInput > 5){ - printf ("Wrong selection code ... Enter again \n"); - continue; - } - - switch (userInput){ - - case 1: - printListOfDevices(true); - break; - case 2: - if (cyDevices == 0) { - printf ("No device of interest connected ...!!\n"); - continue; - } - printf ("Enter Device number to be selected.. \n"); - tempSelectedDeviceNum = getUserInput(); - //printf ("Selected device number is %d \n",tempSelectedDeviceNum); - if (tempSelectedDeviceNum >= cyDevices || tempSelectedDeviceNum == -1){ - printf ("Wrong device selection \n"); - continue; - } - printf ("Enter interface number..\n"); - tempSelectedInterfaceNum = getUserInput(); - //printf ("Selected device number is %d %d\n",tempSelectedInterfaceNum, glDevice[tempSelectedDeviceNum].numInterface); - - if (tempSelectedInterfaceNum >= glDevice[tempSelectedDeviceNum].numInterface || - tempSelectedInterfaceNum == -1) { - printf ("Wrong interface Selection selection \n"); - continue; - } - - if (deviceAddedRemoved == true) { - printf ("Device of interest was added/removed .... Print and select from new list\n"); - continue; - } - selectedDeviceNum = tempSelectedDeviceNum; - selectedInterfaceNum = tempSelectedInterfaceNum; - - - rStatus = CyOpen (selectedDeviceNum,selectedInterfaceNum , &handle); - //printf("return status = %d", rStatus); - if (rStatus == CY_SUCCESS){ - //printf("device opened \n"); - } - else - { - printf("fail \n"); - } - - - - // printf("Please enter file to be opened"); - - fp = fopen(argv[1],"rb+"); - // printf("%s", src_file); - rStatus = CyFlashConfigEnable(handle,1); - - if (rStatus == CY_SUCCESS){ - // printf("Flash is configured"); - } - else - { - printf("Manufacturing mode of FLASH is not configured"); - } - // printf("status %d",rStatus); - - if(fp == NULL) - { - printf("\n fopen() Error!!!\n"); - return 1; - } - printf("\n File opened successfully\n"); - if(sizeof(buff) != fread(buff,1,516,fp)) - { - printf("\n fread() failed\n"); - return 1; - } - printf("\n Bytes successfully read \n"); - // printf("reached here"); - - // silicon_id = *(unsigned int *)buff; - - rStatus=CyGetSiliconID(handle,(UINT32 *)&silicon_id); - if (rStatus == CY_SUCCESS){ - // printf(" Correct silicon id"); - - } - else - { - printf("Not correct ID"); - } - - // printf("silicon id %04x,%d",silicon_id,sizeof(silicon_id)); - id[0]= (silicon_id); - id[1]= ((silicon_id >> 8) & 0xFF); - id[2]= ((silicon_id >> 16) & 0xFF); - id[3]= ((silicon_id >> 24) & 0xFF); - - - - rStatus=CyReadDeviceConfig(handle, (UCHAR *)&read_buffer); - if (rStatus == CY_SUCCESS){ - // printf(" Got the data"); - - } - else - { - printf("Not done"); - } - - /*printf (" 0 %02x, %02x \r \n", id[0],read_buffer[0]); - printf (" 1 %02x, %02x \r \n", id[1],read_buffer[1]); - printf (" 2 %02x, %02x \r \n", id[2],read_buffer[2]); - printf (" 3 %02x, %02x\r \n", id[3],read_buffer[3]);*/ - - size_buffer = sizeof(read_buffer); - //printf("The size is %d, buff %d", size_buffer,sizeof(buff)); - - /*for (i = 4; i < 516; i +=16) - { - printf("\n%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - buff[i], buff[i+1], buff[i+2], buff[i+3], buff[i+4], buff[i+5], buff[i+6], buff[i+7], buff[i+8], - buff[i+9], buff[i+10], buff[i+11], buff[i+12], buff[i+13], buff[i+14], buff[i+15]); - } - for (i = 0; i < 512; i +=16) - { - printf("\n%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - read_buffer[i], read_buffer[i+1], read_buffer[i+2], read_buffer[i+3], read_buffer[i+4], read_buffer[i+5], read_buffer[i+6], - read_buffer[i+7], read_buffer[i+8], - read_buffer[i+9], read_buffer[i+10], read_buffer[i+11], read_buffer[i+12], read_buffer[i+13], read_buffer[i+14], read_buffer[i+15]); - }*/ - memcpy (&buff[4], read_buffer, 28); - - size_checksum= GetCheckSum((unsigned int *)(&buff[16]), 125); - // printf("The checksum size is %d",size_checksum); - - buff[12]= (size_checksum & 0xFF); - buff[13]= ((size_checksum >> 8) & 0xFF); - buff[14]= ((size_checksum >> 16) & 0xFF); - buff[15]= ((size_checksum >> 24) & 0xFF); - - // printf("checksum 0x%08x\n", size_checksum); - /* for (i = 4; i < 516; i +=16) - { - printf("\n%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - buff[i], buff[i+1], buff[i+2], buff[i+3], buff[i+4], buff[i+5], buff[i+6], buff[i+7], buff[i+8], - buff[i+9], buff[i+10], buff[i+11], buff[i+12], buff[i+13], buff[i+14], buff[i+15]); - }*/ - - // if(((id[0] == ffffffA1) || (id[0] == ffffffA2) || (id[0] == ffffffA3)) && (id[1] == 08)) - if((silicon_id == 0x08A1) || (silicon_id == 0x08A2) || (silicon_id == 0x08A3)) - { - - rStatus= CyWriteDeviceConfig(handle,&buff[4]); - if (rStatus == CY_SUCCESS){ - printf(" Programming Flash is done"); - } - else - { - printf("Not done"); - } - } - else - { - printf("wrong silicon id"); - } - - fclose(fp); - - printf("\n File stream closed \n"); - - - - rStatus= CyClose(handle); - if (rStatus == CY_SUCCESS){ - //printf("Device closed"); - } - else - { - printf("Not closed"); - } - - - break; - case 3: - exitApp = true; - CyLibraryExit (); - break; - } - }while (exitApp == false); - free (glDevice); -} -bool isCypressDevice (int deviceNum) { - CY_HANDLE handle; - unsigned char interfaceNum = 0; - unsigned char sig[6]; -int op; - CY_RETURN_STATUS rStatus; - rStatus = CyOpen (deviceNum, interfaceNum, &handle); - //op= libusb_detach_kernel_driver(handle,0); - if (rStatus == CY_SUCCESS){ - rStatus = CyGetSignature (handle, sig); - if (rStatus == CY_SUCCESS){ - CyClose (handle); - return true; - } - else { - CyClose (handle); - return false; - } - } - else - return false; -} diff --git a/tinio/include/CyUSBBootloader.h b/configutility/linux/testUtility/CyUSBBootloader.h similarity index 100% rename from tinio/include/CyUSBBootloader.h rename to configutility/linux/testUtility/CyUSBBootloader.h diff --git a/configutility/linux/testUtility/CyUSBSerial.sh b/configutility/linux/testUtility/CyUSBSerial.sh new file mode 100644 index 0000000..b2a4265 --- /dev/null +++ b/configutility/linux/testUtility/CyUSBSerial.sh @@ -0,0 +1,7 @@ +#!/bin/bash +pid=`pidof CyUSBSerialTestUtility` + +if [ "$pid" ]; then + kill -s SIGUSR1 $pid +fi + diff --git a/configutility/linux/testUtility/CyUSBSerialCommandUtility b/configutility/linux/testUtility/CyUSBSerialCommandUtility new file mode 100755 index 0000000..eebd671 Binary files /dev/null and b/configutility/linux/testUtility/CyUSBSerialCommandUtility differ diff --git a/configutility/linux/testUtility/Makefile b/configutility/linux/testUtility/Makefile new file mode 100644 index 0000000..7369bcd --- /dev/null +++ b/configutility/linux/testUtility/Makefile @@ -0,0 +1,12 @@ +all: + # gcc -g -o CyUSBSerialTestUtility Test_Utility.c -lcyusbserial -w + gcc -g -o CyUSBSerialCommandUtility Command_Utility.c -lcyusbserial + cp 90-cyusb.rules /etc/udev/rules.d + cp CyUSBSerialCommandUtility /usr/bin + cp CyUSBSerial.sh /usr/bin + chmod 777 /usr/bin/CyUSBSerial.sh +clean: + rm -f CyUSBSerialCommandUtility +help: + @echo 'make would compile and create the library and create a link' + @echo 'make clean would remove the library and the soft link to the library (soname)' diff --git a/cylib/tools/README.txt b/configutility/linux/testUtility/README.txt similarity index 65% rename from cylib/tools/README.txt rename to configutility/linux/testUtility/README.txt index 1f15f81..c255cd4 100644 --- a/cylib/tools/README.txt +++ b/configutility/linux/testUtility/README.txt @@ -9,6 +9,37 @@ Cypress CyUSBSerial DVK. The utility writes to I2C/SPI flash devices on the DVK, reads the data back and verifies the data read for integrity. +Release components: +================================================================================ +1. Test_Utility.c ==> Source file of the command line test utility +2. 90-cyusb.rules ==> udev rules for changing the mode of usb device node. +3. CyUSBSerial.sh ==> Script file for implementing hotplug feature in linux. +4. Makefile ==> make file for compiling and installing the application. +================================================================================ + + +Pre-requisites: +================================================================================ +1. libusb-1.0.9 is required for compilation and functioning of the APIs in the + USB Serial library. +2. The CyUSBSerial library (libcyusbserial.so) should be compiled and installed + on the test machine. +3. GNU Make and the GCC tool-chain are used for the build process. +================================================================================ + +Installation steps: +================================================================================ +1. Change to the folder where the utility source files are extracted. +2. Invoke 'make' to build compile the utility, and to install the configuration + files at the appropriate locations. This should be done from a super-user + (sudo) shell, because the configuration files need to be copied into system + folders (/usr/local/bin). +3. Use the CyUSBSerial command to start the test utility. + +Note: +The udev daemon needs to be restarted to reflect the udev rule changes that +are installed as part of the make command. +================================================================================ Using the test utility: ================================================================================ @@ -18,7 +49,7 @@ Using the test utility: $ CyUSBSerial ---------------------------------------------------------------------- - Device Number | VID | PID | INTERFACE NUMBER | FUNCTIONALITY + Device Number | VID | PID | INTERFACE NUMBER | FUNCTIONALITY ---------------------------------------------------------------------- 0 |4b4 |a | 0 | VENDOR_I2C 0 |4b4 |a | 1 | VENDOR_SPI @@ -27,7 +58,7 @@ Using the test utility: 2. A menu providing the various operations is also printed: ---------------------------------------------------------------------- - 1: Print list of devices + 1: Print list of devices 2: Select device...No device selected !! 3: Enter I2C/SPI Flash page address and length to write/read. 4: Verify data @@ -46,7 +77,7 @@ Using the test utility: Once the selections are made, the menu will be updated with the details. ---------------------------------------------------------------------- - 1: Print list of devices + 1: Print list of devices 2: Change device selection--selected device: [Device number 0] : [Interface No 1] : SPI 3: Enter I2C/SPI Flash page address and length to write/read. 4: Verify data @@ -70,7 +101,7 @@ Using the test utility: Once the values are selected, the menu is updated with the details as below: ------------------------------------------------------------------- - 1: Print list of devices + 1: Print list of devices 2: Change device selection--selected device: [Device number 0] : [Interface No 1] : SPI 3: Change Flash page address and length ...Entered is page address 1234 and length 123 4: Verify data @@ -82,18 +113,25 @@ Using the test utility: The data pattern written and read back will be displayed as shown below: -------------------------------------------------------------------- - 67 c6 69 73 51 ff 4a ec 29 cd ba ab f2 fb e3 46 7c c2 54 f8 1b e8 e7 8d 76 5a 2e 63 33 9f c9 9a + 67 c6 69 73 51 ff 4a ec 29 cd ba ab f2 fb e3 46 7c c2 54 f8 1b e8 e7 8d 76 5a 2e 63 33 9f c9 9a -------------------------------------------------------------------- Data Read back is: --------------------------------------------------------------------- - 67 c6 69 73 51 ff 4a ec 29 cd ba ab f2 fb e3 46 7c c2 54 f8 1b e8 e7 8d 76 5a 2e 63 33 9f c9 9a + 67 c6 69 73 51 ff 4a ec 29 cd ba ab f2 fb e3 46 7c c2 54 f8 1b e8 e7 8d 76 5a 2e 63 33 9f c9 9a --------------------------------------------------------------------- - Data verified successfully + Data verified successfully ------------------------------------------------------------------- 6. The utility runs through these menu options until the user selects the exit option (5). +7. If a new Cypress USB Serial device is attached or an existing device is + removed while the utility is running, a notification is printed on the + console. + + --------------------------------------- + Device of interest Removed/Added + --------------------------------------- ================================================================================ EOF diff --git a/configutility/linux/testUtility/jbiexprt.h b/configutility/linux/testUtility/jbiexprt.h new file mode 100644 index 0000000..9b38b4c --- /dev/null +++ b/configutility/linux/testUtility/jbiexprt.h @@ -0,0 +1,224 @@ +/********************************************************************************/ +/* */ +/* Module: jbiexprt.h */ +/* */ +/* Copyright (C) Altera Corporation 1998-2001 */ +/* */ +/* Description: Jam STAPL ByteCode Player Export Header File */ +/* */ +/* Revisions: */ +/* */ +/********************************************************************************/ + +#ifndef INC_JBIEXPRT_H +#define INC_JBIEXPRT_H + +/********************************************************************************/ +/* */ +/* Return codes from most JBI functions */ +/* */ +/********************************************************************************/ + +#define JBI_RETURN_TYPE int + +#define JBIC_SUCCESS 0 +#define JBIC_OUT_OF_MEMORY 1 +#define JBIC_IO_ERROR 2 +/* #define JAMC_SYNTAX_ERROR 3 */ +#define JBIC_UNEXPECTED_END 4 +#define JBIC_UNDEFINED_SYMBOL 5 +/* #define JAMC_REDEFINED_SYMBOL 6 */ +#define JBIC_INTEGER_OVERFLOW 7 +#define JBIC_DIVIDE_BY_ZERO 8 +#define JBIC_CRC_ERROR 9 +#define JBIC_INTERNAL_ERROR 10 +#define JBIC_BOUNDS_ERROR 11 +/* #define JAMC_TYPE_MISMATCH 12 */ +/* #define JAMC_ASSIGN_TO_CONST 13 */ +/* #define JAMC_NEXT_UNEXPECTED 14 */ +/* #define JAMC_POP_UNEXPECTED 15 */ +/* #define JAMC_RETURN_UNEXPECTED 16 */ +/* #define JAMC_ILLEGAL_SYMBOL 17 */ +#define JBIC_VECTOR_MAP_FAILED 18 +#define JBIC_USER_ABORT 19 +#define JBIC_STACK_OVERFLOW 20 +#define JBIC_ILLEGAL_OPCODE 21 +/* #define JAMC_PHASE_ERROR 22 */ +/* #define JAMC_SCOPE_ERROR 23 */ +#define JBIC_ACTION_NOT_FOUND 24 + +/********************************************************************************/ +/* */ +/* Macro Definitions */ +/* */ +/********************************************************************************/ + +/* +* For DOS port, program data is stored in a set of 16K pages, accessed +* through a pointer table. For 32-bit version, the buffer is continuous. +* The macro GET_BYTE gets a single byte for either case. +*/ +#if PORT==DOS +#define PROGRAM_PTR unsigned char ** +#else +#define PROGRAM_PTR unsigned char * +#endif + +#if PORT==DOS +#define GET_BYTE(x) (jbi_program[(x) >> 14L][(x) & 0x3fffL]) +#else +#define GET_BYTE(x) (program[x]) +#endif + +#define GET_WORD(x) \ + (((((unsigned short) GET_BYTE(x)) << 8) & 0xFF00) | \ + (((unsigned short) GET_BYTE((x)+1)) & 0x00FF)) + +#define GET_DWORD(x) \ + (((((unsigned long) GET_BYTE(x)) << 24L) & 0xFF000000L) | \ + ((((unsigned long) GET_BYTE((x)+1)) << 16L) & 0x00FF0000L) | \ + ((((unsigned long) GET_BYTE((x)+2)) << 8L) & 0x0000FF00L) | \ + (((unsigned long) GET_BYTE((x)+3)) & 0x000000FFL)) + +/********************************************************************************/ +/* */ +/* Structured Types */ +/* */ +/********************************************************************************/ + +typedef struct JBI_PROCINFO_STRUCT +{ + char *name; + unsigned char attributes; + struct JBI_PROCINFO_STRUCT *next; +} +JBI_PROCINFO; + +/********************************************************************************/ +/* */ +/* Global Data Prototypes */ +/* */ +/********************************************************************************/ + +#if PORT==DOS +extern unsigned char jbi_aca_out_buffer[8192 + 1024]; +#endif + +extern PROGRAM_PTR jbi_program; + +extern char *jbi_workspace; + +extern long jbi_workspace_size; + +/********************************************************************************/ +/* */ +/* Function Prototypes */ +/* */ +/********************************************************************************/ + +JBI_RETURN_TYPE jbi_execute +( + PROGRAM_PTR program, + long program_size, + char *workspace, + long workspace_size, + char *action, + char **init_list, + int reset_jtag, + long *error_address, + int *exit_code, + int *format_version +); + +JBI_RETURN_TYPE jbi_get_note +( + PROGRAM_PTR program, + long program_size, + long *offset, + char *key, + char *value, + int length +); + +JBI_RETURN_TYPE jbi_check_crc +( + PROGRAM_PTR program, + long program_size, + unsigned short *expected_crc, + unsigned short *actual_crc +); + +JBI_RETURN_TYPE jbi_get_file_info +( + PROGRAM_PTR program, + long program_size, + int *format_version, + int *action_count, + int *procedure_count +); + +JBI_RETURN_TYPE jbi_get_action_info +( + PROGRAM_PTR program, + long program_size, + int index, + char **name, + char **description, + JBI_PROCINFO **procedure_list +); + +int jbi_jtag_io +( + int tms, + int tdi, + int read_tdo +); + +void jbi_message +( + char *message_text +); + +void jbi_export_integer +( + char *key, + long value +); + +void jbi_export_boolean_array +( + char *key, + unsigned char *data, + long count +); + +void jbi_delay +( + long microseconds +); + +int jbi_vector_map +( + int signal_count, + char **signals +); + +int jbi_vector_io +( + int signal_count, + long *dir_vect, + long *data_vect, + long *capture_vect +); + +void *jbi_malloc +( + unsigned int size +); + +void jbi_free +( + void *ptr +); + +#endif /* INC_JBIEXPRT_H */ diff --git a/configutility/linux/testUtility/jbiport.h b/configutility/linux/testUtility/jbiport.h new file mode 100644 index 0000000..f57533e --- /dev/null +++ b/configutility/linux/testUtility/jbiport.h @@ -0,0 +1,43 @@ +/****************************************************************************/ +/* */ +/* Module: jbiport.h */ +/* */ +/* Copyright (C) Altera Corporation 2000-2001 */ +/* */ +/* Description: Defines porting macros */ +/* */ +/****************************************************************************/ + +#ifndef INC_JBIPORT_H +#define INC_JBIPORT_H + +/* +* PORT defines the target platform: DOS, WINDOWS, UNIX, or EMBEDDED +* +* PORT = DOS means a 16-bit DOS console-mode application +* +* PORT = WINDOWS means a 32-bit WIN32 console-mode application for +* Windows 95, 98, 2000, ME or NT. On NT this will use the +* DeviceIoControl() API to access the Parallel Port. +* +* PORT = UNIX means any UNIX system. BitBlaster access is support via +* the standard ANSI system calls open(), read(), write(). +* The ByteBlaster is not supported. +* +* PORT = EMBEDDED means all DOS, WINDOWS, and UNIX code is excluded. +* Remaining code supports 16 and 32-bit compilers. +* Additional porting steps may be necessary. See readme +* file for more details. +*/ + +#define DOS 2 +#define WINDOWS 3 +#define UNIX 4 +#define EMBEDDED 5 + +#ifndef PORT +/* change this line to build a different port */ +#define PORT EMBEDDED +#endif + +#endif /* INC_JBIPORT_H */ diff --git a/cy-config.o b/cy-config.o deleted file mode 100644 index fe6253a..0000000 Binary files a/cy-config.o and /dev/null differ diff --git a/cylib b/cylib new file mode 120000 index 0000000..f0d7b7c --- /dev/null +++ b/cylib @@ -0,0 +1 @@ +configutility/linux/library/ \ No newline at end of file diff --git a/cylib/CMakeLists.txt b/cylib/CMakeLists.txt deleted file mode 100644 index 4d42eb2..0000000 --- a/cylib/CMakeLists.txt +++ /dev/null @@ -1,142 +0,0 @@ -cmake_minimum_required(VERSION 2.8.4) - -project(libcyusbserial C) - -set(CMAKE_HELPERS_BINARY_DIR ${PROJECT_SOURCE_DIR}/cmake/helpers) -set(CMAKE_HELPERS_SOURCE_DIR ${PROJECT_SOURCE_DIR}/cmake/helpers) -list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) - -set(CMAKE_LEGACY_CYGWIN_WIN32 0) - -include(FindLibUSB) - -################################################################################ -# System configuration -################################################################################ - -# OSX -if(APPLE) - set(CMAKE_MACOSX_RPATH ON) - set(CMAKE_SKIP_BUILD_RPATH FALSE) - set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) - set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") - set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) - if(${isSystemDir} STREQUAL "-1") - set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") - endif() -endif() - -# Windows -if(WIN32 AND NOT CMAKE_CROSSCOMPILING) - find_package(LibPThreadsWin32) - if(LIBPTHREADSWIN32_FOUND) - set(WIN_RUNTIME_ITEMS ${WIN_RUNTIME_ITEMS} - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt" - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/pthreadVC2.dll") - - add_custom_command( - OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt" - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${LIBPTHREADSWIN32_LIB_COPYING}" - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/pthreads-win32/COPYING.LIB.txt" - COMMENT "Copying pthreads-win32 license to output directory..." - ) - - add_custom_command( - OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/pthreadVC2.dll" - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${LIBPTHREADSWIN32_PATH}/dll/${LIBPTHREADSWIN32_LIBRARY_PATH_SUFFIX}/pthreadVC2.dll" - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/" - COMMENT "Copying pthreadVC2.dll to output directory..." - ) - endif(LIBPTHREADSWIN32_FOUND) - - if(LIBUSB_FOUND) - set(WIN_RUNTIME_ITEMS ${WIN_RUNTIME_ITEMS} - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libusb/COPYING" - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/libusb-1.0.dll") - - # The libusb Windows release does not appear to include a COPYING file. - # Since it's LGPLv2.1, we'll copy the equivalent license from our - # license directory - add_custom_command( - OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libusb/COPYING.LESSER.txt" - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LESSER.txt" - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libusb/COPYING.LESSER.txt" - COMMENT "Copying libusb license to output directory..." - ) - - add_custom_command( - OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/libusb-1.0.dll" - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${LIBUSB_PATH}/${LIBUSB_LIBRARY_PATH_SUFFIX}/libusb-1.0.dll" - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/" - COMMENT "Copying libusb-1.0.dll to output directory..." - ) - endif(LIBUSB_FOUND) - - set(WIN_RUNTIME_ITEMS ${WIN_RUNTIME_ITEMS} - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libcyusbserial/COPYING.LESSER.txt" - ) - - add_custom_command( - OUTPUT "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libcyusbserial/COPYING.LESSER.txt" - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LESSER.txt" - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/licenses/libcyusbserial/COPYING.LESSER.txt" - COMMENT "Copying libcyusbserial COPYING.LESSER.txt file to output directory..." - ) - - include_directories(${PROJECT_SOURCE_DIR}/windows/include) -endif(WIN32 AND NOT CMAKE_CROSSCOMPILING) - -################################################################################ -# GCC and Clang -################################################################################ -if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR - CMAKE_C_COMPILER_ID STREQUAL "Clang") - - add_definitions(-Wall) - add_definitions(-Wextra) - add_definitions(-Wno-unused-parameter) - - if(TREAT_WARNINGS_AS_ERRORS) - add_definitions(-Werror) - endif() - - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-DDEBUG=1) - add_definitions(-O0) - endif(CMAKE_BUILD_TYPE STREQUAL "Debug") - -endif(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR - CMAKE_C_COMPILER_ID STREQUAL "Clang") - -################################################################################ -# MS Visual Studio -################################################################################ -if(MSVC) - if(TREAT_WARNINGS_AS_ERRORS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") - endif() - - # Prior to V12.0 2013, certain C99 headers we use were not supported. - # We have to supply our own. - if(MSVC_VERSION LESS 1800) - set(MSVC_C99_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/windows/include/c99) - endif() -endif(MSVC) - -################################################################################ -# Process subdirectories -################################################################################ -include_directories(${PROJECT_SOURCE_DIR}/include) -add_subdirectory(include) -add_subdirectory(lib) - -# Only build the tools on Linux -if(NOT WIN32 OR CMAKE_CROSSCOMPILING) - add_subdirectory(tools) -endif(NOT WIN32 OR CMAKE_CROSSCOMPILING) diff --git a/cylib/Doxyfile b/cylib/Doxyfile deleted file mode 100644 index 0bd67d5..0000000 --- a/cylib/Doxyfile +++ /dev/null @@ -1,2437 +0,0 @@ -# Doxyfile 1.8.10 - -# This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project. -# -# All text after a double hash (##) is considered a comment and is placed in -# front of the TAG it is preceding. -# -# All text after a single hash (#) is considered a comment and will be ignored. -# The format is: -# TAG = value [value, ...] -# For lists, items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (\" \"). - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- - -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all text -# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv -# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv -# for the list of possible encodings. -# The default value is: UTF-8. - -DOXYFILE_ENCODING = UTF-8 - -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by -# double-quotes, unless you are using Doxywizard) that should identify the -# project for which the documentation is generated. This name is used in the -# title of most generated pages and in a few other places. -# The default value is: My Project. - -PROJECT_NAME = libcyusbserial - -# The PROJECT_NUMBER tag can be used to enter a project or revision number. This -# could be handy for archiving the generated documentation or if some version -# control system is used. - -PROJECT_NUMBER = 1.0.0 - -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer a -# quick idea about the purpose of the project. Keep the description short. - -PROJECT_BRIEF = "A library to enable userspace control of Cypress USB-Serial bridge devices" - -# With the PROJECT_LOGO tag one can specify a logo or an icon that is included -# in the documentation. The maximum height of the logo should not exceed 55 -# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy -# the logo to the output directory. - -PROJECT_LOGO = - -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path -# into which the generated documentation will be written. If a relative path is -# entered, it will be relative to the location where doxygen was started. If -# left blank the current directory will be used. - -OUTPUT_DIRECTORY = doc - -# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- -# directories (in 2 levels) under the output directory of each output format and -# will distribute the generated files over these directories. Enabling this -# option can be useful when feeding doxygen a huge amount of source files, where -# putting all generated files in the same directory would otherwise causes -# performance problems for the file system. -# The default value is: NO. - -CREATE_SUBDIRS = NO - -# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII -# characters to appear in the names of generated files. If set to NO, non-ASCII -# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode -# U+3044. -# The default value is: NO. - -ALLOW_UNICODE_NAMES = NO - -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, -# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), -# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, -# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), -# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, -# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, -# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, -# Ukrainian and Vietnamese. -# The default value is: English. - -OUTPUT_LANGUAGE = English - -# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member -# descriptions after the members that are listed in the file and class -# documentation (similar to Javadoc). Set to NO to disable this. -# The default value is: YES. - -BRIEF_MEMBER_DESC = YES - -# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief -# description of a member or function before the detailed description -# -# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the -# brief descriptions will be completely suppressed. -# The default value is: YES. - -REPEAT_BRIEF = YES - -# This tag implements a quasi-intelligent brief description abbreviator that is -# used to form the text in various listings. Each string in this list, if found -# as the leading text of the brief description, will be stripped from the text -# and the result, after processing the whole list, is used as the annotated -# text. Otherwise, the brief description is used as-is. If left blank, the -# following values are used ($name is automatically replaced with the name of -# the entity):The $name class, The $name widget, The $name file, is, provides, -# specifies, contains, represents, a, an and the. - -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the - -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# doxygen will generate a detailed section even if there is only a brief -# description. -# The default value is: NO. - -ALWAYS_DETAILED_SEC = NO - -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment -# operators of the base classes will not be shown. -# The default value is: NO. - -INLINE_INHERITED_MEMB = NO - -# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path -# before files name in the file list and in the header files. If set to NO the -# shortest path that makes the file name unique will be used -# The default value is: YES. - -FULL_PATH_NAMES = YES - -# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. -# Stripping is only done if one of the specified strings matches the left-hand -# part of the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the path to -# strip. -# -# Note that you can specify absolute paths here, but also relative paths, which -# will be relative from the directory where doxygen is started. -# This tag requires that the tag FULL_PATH_NAMES is set to YES. - -STRIP_FROM_PATH = - -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the -# path mentioned in the documentation of a class, which tells the reader which -# header file to include in order to use a class. If left blank only the name of -# the header file containing the class definition is used. Otherwise one should -# specify the list of include paths that are normally passed to the compiler -# using the -I flag. - -STRIP_FROM_INC_PATH = - -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but -# less readable) file names. This can be useful is your file systems doesn't -# support long names like on DOS, Mac, or CD-ROM. -# The default value is: NO. - -SHORT_NAMES = NO - -# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the -# first line (until the first dot) of a Javadoc-style comment as the brief -# description. If set to NO, the Javadoc-style will behave just like regular Qt- -# style comments (thus requiring an explicit @brief command for a brief -# description.) -# The default value is: NO. - -JAVADOC_AUTOBRIEF = NO - -# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first -# line (until the first dot) of a Qt-style comment as the brief description. If -# set to NO, the Qt-style will behave just like regular Qt-style comments (thus -# requiring an explicit \brief command for a brief description.) -# The default value is: NO. - -QT_AUTOBRIEF = NO - -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a -# multi-line C++ special comment block (i.e. a block of //! or /// comments) as -# a brief description. This used to be the default behavior. The new default is -# to treat a multi-line C++ comment block as a detailed description. Set this -# tag to YES if you prefer the old behavior instead. -# -# Note that setting this tag to YES also means that rational rose comments are -# not recognized any more. -# The default value is: NO. - -MULTILINE_CPP_IS_BRIEF = NO - -# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the -# documentation from any documented member that it re-implements. -# The default value is: YES. - -INHERIT_DOCS = YES - -# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new -# page for each member. If set to NO, the documentation of a member will be part -# of the file/class/namespace that contains it. -# The default value is: NO. - -SEPARATE_MEMBER_PAGES = NO - -# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen -# uses this value to replace tabs by spaces in code fragments. -# Minimum value: 1, maximum value: 16, default value: 4. - -TAB_SIZE = 4 - -# This tag can be used to specify a number of aliases that act as commands in -# the documentation. An alias has the form: -# name=value -# For example adding -# "sideeffect=@par Side Effects:\n" -# will allow you to put the command \sideeffect (or @sideeffect) in the -# documentation, which will result in a user-defined paragraph with heading -# "Side Effects:". You can put \n's in the value part of an alias to insert -# newlines. - -ALIASES = - -# This tag can be used to specify a number of word-keyword mappings (TCL only). -# A mapping has the form "name=value". For example adding "class=itcl::class" -# will allow you to use the command class in the itcl::class meaning. - -TCL_SUBST = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources -# only. Doxygen will then generate output that is more tailored for C. For -# instance, some of the names that are used will be different. The list of all -# members will be omitted, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_FOR_C = YES - -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or -# Python sources only. Doxygen will then generate output that is more tailored -# for that language. For instance, namespaces will be presented as packages, -# qualified scopes will look different, etc. -# The default value is: NO. - -OPTIMIZE_OUTPUT_JAVA = NO - -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources. Doxygen will then generate output that is tailored for Fortran. -# The default value is: NO. - -OPTIMIZE_FOR_FORTRAN = NO - -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for VHDL. -# The default value is: NO. - -OPTIMIZE_OUTPUT_VHDL = NO - -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given -# extension. Doxygen has a built-in mapping, but you can override or extend it -# using this tag. The format is ext=language, where ext is a file extension, and -# language is one of the parsers supported by doxygen: IDL, Java, Javascript, -# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: -# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: -# Fortran. In the later case the parser tries to guess whether the code is fixed -# or free formatted code, this is the default for Fortran type files), VHDL. For -# instance to make doxygen treat .inc files as Fortran files (default is PHP), -# and .f files as C (default is Fortran), use: inc=Fortran f=C. -# -# Note: For files without extension you can use no_extension as a placeholder. -# -# Note that for custom extensions you also need to set FILE_PATTERNS otherwise -# the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments -# according to the Markdown format, which allows for more readable -# documentation. See http://daringfireball.net/projects/markdown/ for details. -# The output of markdown processing is further processed by doxygen, so you can -# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in -# case of backward compatibilities issues. -# The default value is: YES. - -MARKDOWN_SUPPORT = YES - -# When enabled doxygen tries to link words that correspond to documented -# classes, or namespaces to their corresponding documentation. Such a link can -# be prevented in individual cases by putting a % sign in front of the word or -# globally by setting AUTOLINK_SUPPORT to NO. -# The default value is: YES. - -AUTOLINK_SUPPORT = YES - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should set this -# tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); -# versus func(std::string) {}). This also make the inheritance and collaboration -# diagrams that involve STL classes more complete and accurate. -# The default value is: NO. - -BUILTIN_STL_SUPPORT = NO - -# If you use Microsoft's C++/CLI language, you should set this option to YES to -# enable parsing support. -# The default value is: NO. - -CPP_CLI_SUPPORT = NO - -# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: -# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen -# will parse them like normal C++ but will assume all classes use public instead -# of private inheritance when no explicit protection keyword is present. -# The default value is: NO. - -SIP_SUPPORT = NO - -# For Microsoft's IDL there are propget and propput attributes to indicate -# getter and setter methods for a property. Setting this option to YES will make -# doxygen to replace the get and set methods by a property in the documentation. -# This will only work if the methods are indeed getting or setting a simple -# type. If this is not the case, or you want to show the methods anyway, you -# should set this option to NO. -# The default value is: YES. - -IDL_PROPERTY_SUPPORT = YES - -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default -# all members of a group must be documented explicitly. -# The default value is: NO. - -DISTRIBUTE_GROUP_DOC = NO - -# If one adds a struct or class to a group and this option is enabled, then also -# any nested class or struct is added to the same group. By default this option -# is disabled and one has to add nested compounds explicitly via \ingroup. -# The default value is: NO. - -GROUP_NESTED_COMPOUNDS = NO - -# Set the SUBGROUPING tag to YES to allow class member groups of the same type -# (for instance a group of public functions) to be put as a subgroup of that -# type (e.g. under the Public Functions section). Set it to NO to prevent -# subgrouping. Alternatively, this can be done per class using the -# \nosubgrouping command. -# The default value is: YES. - -SUBGROUPING = YES - -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions -# are shown inside the group in which they are included (e.g. using \ingroup) -# instead of on a separate page (for HTML and Man pages) or section (for LaTeX -# and RTF). -# -# Note that this feature does not work in combination with -# SEPARATE_MEMBER_PAGES. -# The default value is: NO. - -INLINE_GROUPED_CLASSES = NO - -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions -# with only public data fields or simple typedef fields will be shown inline in -# the documentation of the scope in which they are defined (i.e. file, -# namespace, or group documentation), provided this scope is documented. If set -# to NO, structs, classes, and unions are shown on a separate page (for HTML and -# Man pages) or section (for LaTeX and RTF). -# The default value is: NO. - -INLINE_SIMPLE_STRUCTS = NO - -# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or -# enum is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically be -# useful for C code in case the coding convention dictates that all compound -# types are typedef'ed and only the typedef is referenced, never the tag name. -# The default value is: NO. - -TYPEDEF_HIDES_STRUCT = NO - -# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This -# cache is used to resolve symbols given their name and scope. Since this can be -# an expensive process and often the same symbol appears multiple times in the -# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small -# doxygen will become slower. If the cache is too large, memory is wasted. The -# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range -# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 -# symbols. At the end of a run doxygen will report the cache usage and suggest -# the optimal cache size from a speed point of view. -# Minimum value: 0, maximum value: 9, default value: 0. - -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- - -# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in -# documentation are documented, even if no documentation was available. Private -# class members and static file members will be hidden unless the -# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. -# Note: This will also disable the warnings about undocumented members that are -# normally produced when WARNINGS is set to YES. -# The default value is: NO. - -EXTRACT_ALL = NO - -# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will -# be included in the documentation. -# The default value is: NO. - -EXTRACT_PRIVATE = NO - -# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal -# scope will be included in the documentation. -# The default value is: NO. - -EXTRACT_PACKAGE = NO - -# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be -# included in the documentation. -# The default value is: NO. - -EXTRACT_STATIC = NO - -# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined -# locally in source files will be included in the documentation. If set to NO, -# only classes defined in header files are included. Does not have any effect -# for Java sources. -# The default value is: YES. - -EXTRACT_LOCAL_CLASSES = YES - -# This flag is only useful for Objective-C code. If set to YES, local methods, -# which are defined in the implementation section but not in the interface are -# included in the documentation. If set to NO, only methods in the interface are -# included. -# The default value is: NO. - -EXTRACT_LOCAL_METHODS = NO - -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base name of -# the file that contains the anonymous namespace. By default anonymous namespace -# are hidden. -# The default value is: NO. - -EXTRACT_ANON_NSPACES = NO - -# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all -# undocumented members inside documented classes or files. If set to NO these -# members will be included in the various overviews, but no documentation -# section is generated. This option has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_MEMBERS = NO - -# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. If set -# to NO, these classes will be included in the various overviews. This option -# has no effect if EXTRACT_ALL is enabled. -# The default value is: NO. - -HIDE_UNDOC_CLASSES = NO - -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend -# (class|struct|union) declarations. If set to NO, these declarations will be -# included in the documentation. -# The default value is: NO. - -HIDE_FRIEND_COMPOUNDS = NO - -# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any -# documentation blocks found inside the body of a function. If set to NO, these -# blocks will be appended to the function's detailed documentation block. -# The default value is: NO. - -HIDE_IN_BODY_DOCS = NO - -# The INTERNAL_DOCS tag determines if documentation that is typed after a -# \internal command is included. If the tag is set to NO then the documentation -# will be excluded. Set it to YES to include the internal documentation. -# The default value is: NO. - -INTERNAL_DOCS = NO - -# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file -# names in lower-case letters. If set to YES, upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. -# The default value is: system dependent. - -CASE_SENSE_NAMES = NO - -# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with -# their full class and namespace scopes in the documentation. If set to YES, the -# scope will be hidden. -# The default value is: NO. - -HIDE_SCOPE_NAMES = YES - -# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will -# append additional text to a page's title, such as Class Reference. If set to -# YES the compound reference will be hidden. -# The default value is: NO. - -HIDE_COMPOUND_REFERENCE= NO - -# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of -# the files that are included by a file in the documentation of that file. -# The default value is: YES. - -SHOW_INCLUDE_FILES = YES - -# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each -# grouped member an include statement to the documentation, telling the reader -# which file to include in order to use the member. -# The default value is: NO. - -SHOW_GROUPED_MEMB_INC = NO - -# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include -# files with double quotes in the documentation rather than with sharp brackets. -# The default value is: NO. - -FORCE_LOCAL_INCLUDES = NO - -# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the -# documentation for inline members. -# The default value is: YES. - -INLINE_INFO = YES - -# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the -# (detailed) documentation of file and class members alphabetically by member -# name. If set to NO, the members will appear in declaration order. -# The default value is: YES. - -SORT_MEMBER_DOCS = YES - -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief -# descriptions of file, namespace and class members alphabetically by member -# name. If set to NO, the members will appear in declaration order. Note that -# this will also influence the order of the classes in the class list. -# The default value is: NO. - -SORT_BRIEF_DOCS = NO - -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the -# (brief and detailed) documentation of class members so that constructors and -# destructors are listed first. If set to NO the constructors will appear in the -# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. -# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief -# member documentation. -# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting -# detailed member documentation. -# The default value is: NO. - -SORT_MEMBERS_CTORS_1ST = NO - -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy -# of group names into alphabetical order. If set to NO the group names will -# appear in their defined order. -# The default value is: NO. - -SORT_GROUP_NAMES = NO - -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by -# fully-qualified names, including namespaces. If set to NO, the class list will -# be sorted only by class name, not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the alphabetical -# list. -# The default value is: NO. - -SORT_BY_SCOPE_NAME = NO - -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper -# type resolution of all parameters of a function it will reject a match between -# the prototype and the implementation of a member function even if there is -# only one candidate or it is obvious which candidate to choose by doing a -# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still -# accept a match between prototype and implementation in such cases. -# The default value is: NO. - -STRICT_PROTO_MATCHING = NO - -# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo -# list. This list is created by putting \todo commands in the documentation. -# The default value is: YES. - -GENERATE_TODOLIST = YES - -# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test -# list. This list is created by putting \test commands in the documentation. -# The default value is: YES. - -GENERATE_TESTLIST = YES - -# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug -# list. This list is created by putting \bug commands in the documentation. -# The default value is: YES. - -GENERATE_BUGLIST = YES - -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) -# the deprecated list. This list is created by putting \deprecated commands in -# the documentation. -# The default value is: YES. - -GENERATE_DEPRECATEDLIST= YES - -# The ENABLED_SECTIONS tag can be used to enable conditional documentation -# sections, marked by \if ... \endif and \cond -# ... \endcond blocks. - -ENABLED_SECTIONS = - -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the -# initial value of a variable or macro / define can have for it to appear in the -# documentation. If the initializer consists of more lines than specified here -# it will be hidden. Use a value of 0 to hide initializers completely. The -# appearance of the value of individual variables and macros / defines can be -# controlled using \showinitializer or \hideinitializer command in the -# documentation regardless of this setting. -# Minimum value: 0, maximum value: 10000, default value: 30. - -MAX_INITIALIZER_LINES = 30 - -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at -# the bottom of the documentation of classes and structs. If set to YES, the -# list will mention the files that were used to generate the documentation. -# The default value is: YES. - -SHOW_USED_FILES = YES - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This -# will remove the Files entry from the Quick Index and from the Folder Tree View -# (if specified). -# The default value is: YES. - -SHOW_FILES = YES - -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces -# page. This will remove the Namespaces entry from the Quick Index and from the -# Folder Tree View (if specified). -# The default value is: YES. - -SHOW_NAMESPACES = YES - -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command command input-file, where command is the value of the -# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided -# by doxygen. Whatever the program writes to standard output is used as the file -# version. For an example see the documentation. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. To create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. You can -# optionally specify a file name after the option, if omitted DoxygenLayout.xml -# will be used as the name of the layout file. -# -# Note that if you run doxygen from a directory containing a file called -# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE -# tag is left empty. - -LAYOUT_FILE = - -# The CITE_BIB_FILES tag can be used to specify one or more bib files containing -# the reference definitions. This must be a list of .bib files. The .bib -# extension is automatically appended if omitted. This requires the bibtex tool -# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. -# For LaTeX the style of the bibliography can be controlled using -# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the -# search path. See also \cite for info how to create references. - -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- - -# The QUIET tag can be used to turn on/off the messages that are generated to -# standard output by doxygen. If QUIET is set to YES this implies that the -# messages are off. -# The default value is: NO. - -QUIET = NO - -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES -# this implies that the warnings are on. -# -# Tip: Turn warnings on while writing the documentation. -# The default value is: YES. - -WARNINGS = YES - -# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate -# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag -# will automatically be disabled. -# The default value is: YES. - -WARN_IF_UNDOCUMENTED = YES - -# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some parameters -# in a documented function, or documenting parameters that don't exist or using -# markup commands wrongly. -# The default value is: YES. - -WARN_IF_DOC_ERROR = YES - -# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that -# are documented, but have no documentation for their parameters or return -# value. If set to NO, doxygen will only warn about wrong or incomplete -# parameter documentation, but not about the absence of documentation. -# The default value is: NO. - -WARN_NO_PARAMDOC = NO - -# The WARN_FORMAT tag determines the format of the warning messages that doxygen -# can produce. The string should contain the $file, $line, and $text tags, which -# will be replaced by the file and line number from which the warning originated -# and the warning text. Optionally the format may contain $version, which will -# be replaced by the version of the file (if it could be obtained via -# FILE_VERSION_FILTER) -# The default value is: $file:$line: $text. - -WARN_FORMAT = "$file:$line: $text" - -# The WARN_LOGFILE tag can be used to specify a file to which warning and error -# messages should be written. If left blank the output is written to standard -# error (stderr). - -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- - -# The INPUT tag is used to specify the files and/or directories that contain -# documented source files. You may enter file names like myfile.cpp or -# directories like /usr/src/myproject. Separate the files or directories with -# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING -# Note: If this tag is empty the current directory is searched. - -INPUT = . \ - include \ - lib - -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses -# libiconv (or the iconv built into libc) for the transcoding. See the libiconv -# documentation (see: http://www.gnu.org/software/libiconv) for the list of -# possible encodings. -# The default value is: UTF-8. - -INPUT_ENCODING = UTF-8 - -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and -# *.h) to filter out the source-files in the directories. -# -# Note that for custom extensions or not directly supported extensions you also -# need to set EXTENSION_MAPPING for the extension otherwise the files are not -# read by doxygen. -# -# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, -# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, -# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, -# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, -# *.vhdl, *.ucf, *.qsf, *.as and *.js. - -FILE_PATTERNS = *.c \ - *.cc \ - *.cxx \ - *.cpp \ - *.c++ \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.idl \ - *.ddl \ - *.odl \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ \ - *.cs \ - *.d \ - *.php \ - *.php4 \ - *.php5 \ - *.phtml \ - *.inc \ - *.m \ - *.markdown \ - *.md \ - *.mm \ - *.dox \ - *.py \ - *.f90 \ - *.f \ - *.for \ - *.tcl \ - *.vhd \ - *.vhdl \ - *.ucf \ - *.qsf \ - *.as \ - *.js - -# The RECURSIVE tag can be used to specify whether or not subdirectories should -# be searched for input files as well. -# The default value is: NO. - -RECURSIVE = NO - -# The EXCLUDE tag can be used to specify files and/or directories that should be -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# -# Note that relative paths are relative to the directory from which doxygen is -# run. - -EXCLUDE = - -# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded -# from the input. -# The default value is: NO. - -EXCLUDE_SYMLINKS = NO - -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories for example use the pattern */test/* - -EXCLUDE_PATTERNS = - -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test -# -# Note that the wildcards are matched against the file with absolute path, so to -# exclude all test directories use the pattern */test/* - -EXCLUDE_SYMBOLS = - -# The EXAMPLE_PATH tag can be used to specify one or more files or directories -# that contain example code fragments that are included (see the \include -# command). - -EXAMPLE_PATH = - -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and -# *.h) to filter out the source-files in the directories. If left blank all -# files are included. - -EXAMPLE_PATTERNS = * - -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude commands -# irrespective of the value of the RECURSIVE tag. -# The default value is: NO. - -EXAMPLE_RECURSIVE = NO - -# The IMAGE_PATH tag can be used to specify one or more files or directories -# that contain images that are to be included in the documentation (see the -# \image command). - -IMAGE_PATH = - -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command: -# -# -# -# where is the value of the INPUT_FILTER tag, and is the -# name of an input file. Doxygen will then use the output that the filter -# program writes to standard output. If FILTER_PATTERNS is specified, this tag -# will be ignored. -# -# Note that the filter must not add or remove lines; it is applied before the -# code is scanned, but not when the output code is generated. If lines are added -# or removed, the anchors will not be placed correctly. - -INPUT_FILTER = - -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: pattern=filter -# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how -# filters are used. If the FILTER_PATTERNS tag is empty or if none of the -# patterns match the file name, INPUT_FILTER is applied. - -FILTER_PATTERNS = - -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will also be used to filter the input files that are used for -# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). -# The default value is: NO. - -FILTER_SOURCE_FILES = NO - -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and -# it is also possible to disable source filtering for a specific pattern using -# *.ext= (so without naming a filter). -# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. - -FILTER_SOURCE_PATTERNS = - -# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that -# is part of the input, its contents will be placed on the main page -# (index.html). This can be useful if you have a project on for instance GitHub -# and want to reuse the introduction page also for the doxygen output. - -USE_MDFILE_AS_MAINPAGE = - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- - -# If the SOURCE_BROWSER tag is set to YES then a list of source files will be -# generated. Documented entities will be cross-referenced with these sources. -# -# Note: To get rid of all source code in the generated output, make sure that -# also VERBATIM_HEADERS is set to NO. -# The default value is: NO. - -SOURCE_BROWSER = NO - -# Setting the INLINE_SOURCES tag to YES will include the body of functions, -# classes and enums directly into the documentation. -# The default value is: NO. - -INLINE_SOURCES = NO - -# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any -# special comment blocks from generated source code fragments. Normal C, C++ and -# Fortran comments will always remain visible. -# The default value is: YES. - -STRIP_CODE_COMMENTS = YES - -# If the REFERENCED_BY_RELATION tag is set to YES then for each documented -# function all documented functions referencing it will be listed. -# The default value is: NO. - -REFERENCED_BY_RELATION = NO - -# If the REFERENCES_RELATION tag is set to YES then for each documented function -# all documented entities called/used by that function will be listed. -# The default value is: NO. - -REFERENCES_RELATION = NO - -# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set -# to YES then the hyperlinks from functions in REFERENCES_RELATION and -# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will -# link to the documentation. -# The default value is: YES. - -REFERENCES_LINK_SOURCE = YES - -# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the -# source code will show a tooltip with additional information such as prototype, -# brief description and links to the definition and documentation. Since this -# will make the HTML file larger and loading of large files a bit slower, you -# can opt to disable this feature. -# The default value is: YES. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -SOURCE_TOOLTIPS = YES - -# If the USE_HTAGS tag is set to YES then the references to source code will -# point to the HTML generated by the htags(1) tool instead of doxygen built-in -# source browser. The htags tool is part of GNU's global source tagging system -# (see http://www.gnu.org/software/global/global.html). You will need version -# 4.8.6 or higher. -# -# To use it do the following: -# - Install the latest version of global -# - Enable SOURCE_BROWSER and USE_HTAGS in the config file -# - Make sure the INPUT points to the root of the source tree -# - Run doxygen as normal -# -# Doxygen will invoke htags (and that will in turn invoke gtags), so these -# tools must be available from the command line (i.e. in the search path). -# -# The result: instead of the source browser generated by doxygen, the links to -# source code will now point to the output of htags. -# The default value is: NO. -# This tag requires that the tag SOURCE_BROWSER is set to YES. - -USE_HTAGS = NO - -# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a -# verbatim copy of the header file for each class for which an include is -# specified. Set to NO to disable this. -# See also: Section \class. -# The default value is: YES. - -VERBATIM_HEADERS = YES - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- - -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all -# compounds will be generated. Enable this if the project contains a lot of -# classes, structs, unions or interfaces. -# The default value is: YES. - -ALPHABETICAL_INDEX = YES - -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all classes will -# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag -# can be used to specify a prefix (or a list of prefixes) that should be ignored -# while generating the index headers. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- - -# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output -# The default value is: YES. - -GENERATE_HTML = YES - -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a -# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of -# it. -# The default directory is: html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_OUTPUT = html - -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each -# generated HTML page (for example: .htm, .php, .asp). -# The default value is: .html. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FILE_EXTENSION = .html - -# The HTML_HEADER tag can be used to specify a user-defined HTML header file for -# each generated HTML page. If the tag is left blank doxygen will generate a -# standard header. -# -# To get valid HTML the header file that includes any scripts and style sheets -# that doxygen needs, which is dependent on the configuration options used (e.g. -# the setting GENERATE_TREEVIEW). It is highly recommended to start with a -# default header using -# doxygen -w html new_header.html new_footer.html new_stylesheet.css -# YourConfigFile -# and then modify the file new_header.html. See also section "Doxygen usage" -# for information on how to generate the default header that doxygen normally -# uses. -# Note: The header is subject to change so you typically have to regenerate the -# default header when upgrading to a newer version of doxygen. For a description -# of the possible markers and block names see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each -# generated HTML page. If the tag is left blank doxygen will generate a standard -# footer. See HTML_HEADER for more information on how to generate a default -# footer and what special commands can be used inside the footer. See also -# section "Doxygen usage" for information on how to generate the default footer -# that doxygen normally uses. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style -# sheet that is used by each HTML page. It can be used to fine-tune the look of -# the HTML output. If left blank doxygen will generate a default style sheet. -# See also section "Doxygen usage" for information on how to generate the style -# sheet that doxygen normally uses. -# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as -# it is more robust and this tag (HTML_STYLESHEET) will in the future become -# obsolete. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_STYLESHEET = - -# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined -# cascading style sheets that are included after the standard style sheets -# created by doxygen. Using this option one can overrule certain style aspects. -# This is preferred over using HTML_STYLESHEET since it does not replace the -# standard style sheet and is therefore more robust against future updates. -# Doxygen will copy the style sheet files to the output directory. -# Note: The order of the extra style sheet files is of importance (e.g. the last -# style sheet in the list overrules the setting of the previous ones in the -# list). For an example see the documentation. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that the -# files will be copied as-is; there are no commands or markers available. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen -# will adjust the colors in the style sheet and background images according to -# this color. Hue is specified as an angle on a colorwheel, see -# http://en.wikipedia.org/wiki/Hue for more information. For instance the value -# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 -# purple, and 360 is red again. -# Minimum value: 0, maximum value: 359, default value: 220. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_HUE = 220 - -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors -# in the HTML output. For a value of 0 the output will use grayscales only. A -# value of 255 will produce the most vivid colors. -# Minimum value: 0, maximum value: 255, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_SAT = 100 - -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the -# luminance component of the colors in the HTML output. Values below 100 -# gradually make the output lighter, whereas values above 100 make the output -# darker. The value divided by 100 is the actual gamma applied, so 80 represents -# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not -# change the gamma. -# Minimum value: 40, maximum value: 240, default value: 80. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_COLORSTYLE_GAMMA = 80 - -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting this -# to YES can help to show when doxygen was last run and thus if the -# documentation is up to date. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_TIMESTAMP = NO - -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_DYNAMIC_SECTIONS = NO - -# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries -# shown in the various tree structured indices initially; the user can expand -# and collapse entries dynamically later on. Doxygen will expand the tree to -# such a level that at most the specified number of entries are visible (unless -# a fully collapsed tree already exceeds this amount). So setting the number of -# entries 1 will produce a full collapsed tree by default. 0 is a special value -# representing an infinite number of entries and will result in a full expanded -# tree by default. -# Minimum value: 0, maximum value: 9999, default value: 100. -# This tag requires that the tag GENERATE_HTML is set to YES. - -HTML_INDEX_NUM_ENTRIES = 100 - -# If the GENERATE_DOCSET tag is set to YES, additional index files will be -# generated that can be used as input for Apple's Xcode 3 integrated development -# environment (see: http://developer.apple.com/tools/xcode/), introduced with -# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a -# Makefile in the HTML output directory. Running make will produce the docset in -# that directory and running make install will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at -# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_DOCSET = NO - -# This tag determines the name of the docset feed. A documentation feed provides -# an umbrella under which multiple documentation sets from a single provider -# (such as a company or product suite) can be grouped. -# The default value is: Doxygen generated docs. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_FEEDNAME = "Doxygen generated docs" - -# This tag specifies a string that should uniquely identify the documentation -# set bundle. This should be a reverse domain-name style string, e.g. -# com.mycompany.MyDocSet. Doxygen will append .docset to the name. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_BUNDLE_ID = org.doxygen.Project - -# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style -# string, e.g. com.mycompany.MyDocSet.documentation. -# The default value is: org.doxygen.Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_ID = org.doxygen.Publisher - -# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. -# The default value is: Publisher. -# This tag requires that the tag GENERATE_DOCSET is set to YES. - -DOCSET_PUBLISHER_NAME = Publisher - -# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three -# additional HTML index files: index.hhp, index.hhc, and index.hhk. The -# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop -# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on -# Windows. -# -# The HTML Help Workshop contains a compiler that can convert all HTML output -# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML -# files are now used as the Windows 98 help format, and will replace the old -# Windows help format (.hlp) on all Windows platforms in the future. Compressed -# HTML files also contain an index, a table of contents, and you can search for -# words in the documentation. The HTML workshop also contains a viewer for -# compressed HTML files. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_HTMLHELP = NO - -# The CHM_FILE tag can be used to specify the file name of the resulting .chm -# file. You can add a path in front of the file if the result should not be -# written to the html output directory. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_FILE = - -# The HHC_LOCATION tag can be used to specify the location (absolute path -# including file name) of the HTML help compiler (hhc.exe). If non-empty, -# doxygen will try to run the HTML help compiler on the generated index.hhp. -# The file has to be specified with full path. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -HHC_LOCATION = - -# The GENERATE_CHI flag controls if a separate .chi index file is generated -# (YES) or that it should be included in the master .chm file (NO). -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -GENERATE_CHI = NO - -# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) -# and project file content. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -CHM_INDEX_ENCODING = - -# The BINARY_TOC flag controls whether a binary table of contents is generated -# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it -# enables the Previous and Next buttons. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -BINARY_TOC = NO - -# The TOC_EXPAND flag can be set to YES to add extra items for group members to -# the table of contents of the HTML help documentation and to the tree view. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTMLHELP is set to YES. - -TOC_EXPAND = NO - -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that -# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help -# (.qch) of the generated HTML documentation. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_QHP = NO - -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify -# the file name of the resulting .qch file. The path specified is relative to -# the HTML output folder. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QCH_FILE = - -# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help -# Project output. For more information please see Qt Help Project / Namespace -# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_NAMESPACE = org.doxygen.Project - -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt -# Help Project output. For more information please see Qt Help Project / Virtual -# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- -# folders). -# The default value is: doc. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_VIRTUAL_FOLDER = doc - -# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom -# filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_NAME = - -# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see Qt Help Project / Custom -# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- -# filters). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_CUST_FILTER_ATTRS = - -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's filter section matches. Qt Help Project / Filter Attributes (see: -# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHP_SECT_FILTER_ATTRS = - -# The QHG_LOCATION tag can be used to specify the location of Qt's -# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the -# generated .qhp file. -# This tag requires that the tag GENERATE_QHP is set to YES. - -QHG_LOCATION = - -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be -# generated, together with the HTML files, they form an Eclipse help plugin. To -# install this plugin and make it available under the help contents menu in -# Eclipse, the contents of the directory containing the HTML and XML files needs -# to be copied into the plugins directory of eclipse. The name of the directory -# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. -# After copying Eclipse needs to be restarted before the help appears. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_ECLIPSEHELP = NO - -# A unique identifier for the Eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have this -# name. Each documentation set should have its own identifier. -# The default value is: org.doxygen.Project. -# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. - -ECLIPSE_DOC_ID = org.doxygen.Project - -# If you want full control over the layout of the generated HTML pages it might -# be necessary to disable the index and replace it with your own. The -# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top -# of each HTML page. A value of NO enables the index and the value YES disables -# it. Since the tabs in the index contain the same information as the navigation -# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -DISABLE_INDEX = NO - -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. If the tag -# value is set to YES, a side panel will be generated containing a tree-like -# index structure (just like the one that is generated for HTML Help). For this -# to work a browser that supports JavaScript, DHTML, CSS and frames is required -# (i.e. any modern browser). Windows users are probably better off using the -# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can -# further fine-tune the look of the index. As an example, the default style -# sheet generated by doxygen has an example that shows how to put an image at -# the root of the tree instead of the PROJECT_NAME. Since the tree basically has -# the same information as the tab index, you could consider setting -# DISABLE_INDEX to YES when enabling this option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -GENERATE_TREEVIEW = NO - -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that -# doxygen will group on one line in the generated HTML documentation. -# -# Note that a value of 0 will completely suppress the enum values from appearing -# in the overview section. -# Minimum value: 0, maximum value: 20, default value: 4. -# This tag requires that the tag GENERATE_HTML is set to YES. - -ENUM_VALUES_PER_LINE = 4 - -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used -# to set the initial width (in pixels) of the frame in which the tree is shown. -# Minimum value: 0, maximum value: 1500, default value: 250. -# This tag requires that the tag GENERATE_HTML is set to YES. - -TREEVIEW_WIDTH = 250 - -# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to -# external symbols imported via tag files in a separate window. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -EXT_LINKS_IN_WINDOW = NO - -# Use this tag to change the font size of LaTeX formulas included as images in -# the HTML documentation. When you change the font size after a successful -# doxygen run you need to manually remove any form_*.png images from the HTML -# output directory to force them to be regenerated. -# Minimum value: 8, maximum value: 50, default value: 10. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_FONTSIZE = 10 - -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are not -# supported properly for IE 6.0, but are supported on all modern browsers. -# -# Note that when changing this option you need to delete any form_*.png files in -# the HTML output directory before the changes have effect. -# The default value is: YES. -# This tag requires that the tag GENERATE_HTML is set to YES. - -FORMULA_TRANSPARENT = YES - -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see -# http://www.mathjax.org) which uses client side Javascript for the rendering -# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX -# installed or if you want to formulas look prettier in the HTML output. When -# enabled you may also need to install MathJax separately and configure the path -# to it using the MATHJAX_RELPATH option. -# The default value is: NO. -# This tag requires that the tag GENERATE_HTML is set to YES. - -USE_MATHJAX = NO - -# When MathJax is enabled you can set the default output format to be used for -# the MathJax output. See the MathJax site (see: -# http://docs.mathjax.org/en/latest/output.html) for more details. -# Possible values are: HTML-CSS (which is slower, but has the best -# compatibility), NativeMML (i.e. MathML) and SVG. -# The default value is: HTML-CSS. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_FORMAT = HTML-CSS - -# When MathJax is enabled you need to specify the location relative to the HTML -# output directory using the MATHJAX_RELPATH option. The destination directory -# should contain the MathJax.js script. For instance, if the mathjax directory -# is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax -# Content Delivery Network so you can quickly see the result without installing -# MathJax. However, it is strongly recommended to install a local copy of -# MathJax from http://www.mathjax.org before deployment. -# The default value is: http://cdn.mathjax.org/mathjax/latest. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest - -# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax -# extension names that should be enabled during MathJax rendering. For example -# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_EXTENSIONS = - -# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces -# of code that will be used on startup of the MathJax code. See the MathJax site -# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an -# example see the documentation. -# This tag requires that the tag USE_MATHJAX is set to YES. - -MATHJAX_CODEFILE = - -# When the SEARCHENGINE tag is enabled doxygen will generate a search box for -# the HTML output. The underlying search engine uses javascript and DHTML and -# should work on any modern browser. Note that when using HTML help -# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) -# there is already a search function so this one should typically be disabled. -# For large projects the javascript based search engine can be slow, then -# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to -# search using the keyboard; to jump to the search box use + S -# (what the is depends on the OS and browser, but it is typically -# , /