repairing... just repairing...

This commit is contained in:
Kristjan Komloši @ Home
2017-08-15 15:14:00 +02:00
parent d9f3041c27
commit d5f9c52f03
120 changed files with 8120 additions and 15916 deletions
@@ -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"
@@ -0,0 +1,464 @@
/*
* Command line utility for downloading FW
* 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <signal.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
#include <ctype.h>
#include "../../common/header/CyUSBSerial.h"
#include "../../common/header/CyUSBBootloader.h"
#define CY_MAX_DEVICES 30
#define CY_MAX_INTERFACES 4
typedef struct _CY_DEVICE_STRUCT {
int deviceNumber;
int interfaceFunctionality[CY_MAX_INTERFACES];
bool isI2c;
bool isSpi;
int numInterface;
}CY_DEVICE_STRUCT;
CY_DEVICE_STRUCT *glDevice;
int i2cDeviceIndex[CY_MAX_DEVICES][CY_MAX_INTERFACES];
unsigned char *deviceNumber = NULL;
int cyDevices, i2cDevices = 0, numDevices = 0;
int selectedDeviceNum = -1, selectedInterfaceNum = -1;
bool exitApp = false;
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;
int length, index = 0, numInterfaces, interfaceNum;
bool set1 = false;
unsigned char deviceID[CY_MAX_DEVICES];
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 (&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;
}
if (isPrint){
printf ("\n\n---------------------------------------------------------------------------------\n");
printf ("Device Number | VID | PID | INTERFACE NUMBER | FUNCTIONALITY \n");
printf ("---------------------------------------------------------------------------------\n");
}
cyDevices = 0;
for (devNum = 0; devNum < numDevices; devNum++){
rStatus = CyGetDeviceInfo (devNum, &deviceInfo);
interfaceNum = 0;
if (!rStatus)
{
//if (isCypressDevice (devNum)){
// continue;
//}
strcpy (functionality, "NA");
numInterfaces = deviceInfo.numInterfaces;
glDevice[index].numInterface = numInterfaces;
cyDevices++;
while (numInterfaces){
if (deviceInfo.deviceClass[interfaceNum] == CY_CLASS_VENDOR)
{
glDevice[index].deviceNumber = devNum;
switch (deviceInfo.deviceType[interfaceNum]){
case CY_TYPE_I2C:
glDevice[index].interfaceFunctionality[interfaceNum] = CY_TYPE_I2C;
strcpy (functionality, "VENDOR_I2C");
glDevice[index].isI2c = true;
break;
case CY_TYPE_SPI:
glDevice[index].interfaceFunctionality[interfaceNum] = CY_TYPE_SPI;
strcpy (functionality, "VENDOR_SPI");
glDevice[index].isSpi = true;
break;
default:
strcpy (functionality, "NA");
break;
}
}
else if (deviceInfo.deviceClass[interfaceNum] == CY_CLASS_CDC){
strcpy (functionality, "NA");
}
if (isPrint) {
printf ("%d |%x |%x | %d | %s\n", \
index, \
deviceInfo.vidPid.vid, \
deviceInfo.vidPid.pid, \
interfaceNum, \
functionality \
);
}
interfaceNum++;
numInterfaces--;
}
index++;
}
}
if (isPrint){
printf ("---------------------------------------------------------------------------------\n\n");
}
printf("Cydevices %d",cyDevices);
}
@@ -0,0 +1,435 @@
/*
## 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
##
## <install>/license/license.txt
##
## where <install> 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
/*
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_ */
@@ -0,0 +1,7 @@
#!/bin/bash
pid=`pidof CyUSBSerialTestUtility`
if [ "$pid" ]; then
kill -s SIGUSR1 $pid
fi
Binary file not shown.
+12
View File
@@ -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)'
+137
View File
@@ -0,0 +1,137 @@
================================================================================
Cypress Semiconductor Corporation
CyUSB Serial DVK test utility for I2C/SPI
================================================================================
This utility is used for testing I2C/SPI master mode functionality on the
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:
================================================================================
1. On starting the utility, the Cypress USB Serial devices that are connected
are listed along with their device numbers, interface numbers and
functionalities (SPI or I2C).
$ CyUSBSerial
----------------------------------------------------------------------
Device Number | VID | PID | INTERFACE NUMBER | FUNCTIONALITY
----------------------------------------------------------------------
0 |4b4 |a | 0 | VENDOR_I2C
0 |4b4 |a | 1 | VENDOR_SPI
0 |4b4 |a | 2 | NA
----------------------------------------------------------------------
2. A menu providing the various operations is also printed:
----------------------------------------------------------------------
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
5: Exit
----------------------------------------------------------------------
3. On selecting option 2, the utility prompts for the device and interface
number to be selected for testing.
-----------------------------------
Enter Device number to select:
0
Enter interface number:
1
-----------------------------------
Once the selections are made, the menu will be updated with the details.
----------------------------------------------------------------------
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
5: Exit
----------------------------------------------------------------------
4. Option 3 can be selected now to do data read/write to the I2C/SPI flash
device. The utility prompts for the page address to be written as well as
the length of data to be written.
------------------------------------------------
Enter Page address ... (less than 65536)
1234
Enter length to read/write ... (less than 256)
32
------------------------------------------------
Length needs to be less than or equal to 256 bytes in the case of SPI access,
and less than or equal to 64 bytes in the case of I2C access. Page address
needs to be less than 65536 in case of SPI and 256 in case of I2C.
Once the values are selected, the menu is updated with the details as below:
-------------------------------------------------------------------
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
5: Exit
-------------------------------------------------------------------
5. Selecting option 4 causes the utility to write a randomly generated data
sequence to the flash device, read it back, and verify the data read back.
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
--------------------------------------------------------------------
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
---------------------------------------------------------------------
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
+224
View File
@@ -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 */
+43
View File
@@ -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 */