From 0d4ebace3efaaab2bf7ddb0f5ed6c9878f0f1add Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Fri, 11 Jan 2019 17:28:45 +0700 Subject: [PATCH 1/4] [platform/cel] Add cpld upgrade tool. --- .../sonic-platform-modules-cel/debian/rules | 7 + .../tools/ispvme_12.2/Makefile | 25 + .../tools/ispvme_12.2/hardware.c | 313 ++ .../tools/ispvme_12.2/ispvm_ui.c | 784 +++++ .../tools/ispvme_12.2/ivm_core.c | 3082 +++++++++++++++++ .../tools/ispvme_12.2/vmopcode.h | 191 + 6 files changed, 4402 insertions(+) create mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/Makefile create mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/hardware.c create mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c create mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ivm_core.c create mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/vmopcode.h diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/rules b/platform/broadcom/sonic-platform-modules-cel/debian/rules index 5086302b70b2..07946f9a23a2 100755 --- a/platform/broadcom/sonic-platform-modules-cel/debian/rules +++ b/platform/broadcom/sonic-platform-modules-cel/debian/rules @@ -6,6 +6,7 @@ KVERSION ?= $(shell uname -r) KERNEL_SRC := /lib/modules/$(KVERSION) MOD_SRC_DIR:= $(shell pwd) MODULE_DIRS:= dx010 haliburton +TOOL_DIRS := tools %: dh $@ @@ -14,13 +15,18 @@ override_dh_auto_build: (for mod in $(MODULE_DIRS); do \ make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \ done) + make -C $(MOD_SRC_DIR)/tools/ispvme_12.2; override_dh_auto_install: (for mod in $(MODULE_DIRS); do \ dh_installdirs -pplatform-modules-$${mod} \ $(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ + dh_installdirs -pplatform-modules-$${mod} \ + /usr/local/bin; \ cp $(MOD_SRC_DIR)/$${mod}/modules/*.ko \ debian/platform-modules-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ + cp $(MOD_SRC_DIR)/tools/ispvme_12.2/ispvm \ + debian/platform-modules-$${mod}/usr/local/bin/; \ done) override_dh_usrlocal: @@ -30,4 +36,5 @@ override_dh_clean: (for mod in $(MODULE_DIRS); do \ make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules clean; \ done) + make -C $(MOD_SRC_DIR)/tools/ispvme_12.2 clean; diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/Makefile b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/Makefile new file mode 100644 index 000000000000..ef403e67f8c0 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/Makefile @@ -0,0 +1,25 @@ +CC = gcc +AR = ar +# CFLAGS = -Wall -W -Wunused -lpthread -g -O2 -ggdb -DIPMI_PRJ -DDIAG_DEBUG -DDIAG_API -DHAVE_CONFIG_H -DFCS_CTRL_NO_BURST -DFCS_DEBUG -DHAVE_NANOSLEEP +CFLAGS = -Wall -W -Wunused -lpthread -g -O0 -ggdb -DDIAG_DEBUG -DDIAG_API -DHAVE_CONFIG_H -DFCS_DEBUG -DHAVE_NANOSLEEP +LFLAGS = -lm -pthread +DEL_FILE = rm -f +MV_FILE = mv -f +OBJ_FILE_NODE = ./*.o +#VPATH = +INCPATH = -I../include/ +TARGET = ispvm +# OBJECTS += cpld_ops.o i2c_dev.o i2c_chips.o sys_eeprom.o crc32.o bsp_ifc.o hpcsfp.o smartfan.o test.o path.o + +OBJECTS += hardware.o ispvm_ui.o ivm_core.o + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< +$(TARGET):$(OBJECTS) + $(CC) -o $(TARGET) $(OBJECTS) + +clean: + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) $(OBJ_FILE_NODE) + + diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/hardware.c b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/hardware.c new file mode 100644 index 000000000000..24f4edc23c08 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/hardware.c @@ -0,0 +1,313 @@ +/********************************************************************************* +* Lattice Semiconductor Corp. Copyright 2000-2008 +* +* This is the hardware.c of ispVME V12.1 for JTAG programmable devices. +* All the functions requiring customization are organized into this file for +* the convinience of porting. +*********************************************************************************/ +/********************************************************************************* + * Revision History: + * + * 09/11/07 NN Type cast mismatch variables + * 09/24/07 NN Added calibration function. + * Calibration will help to determine the system clock frequency + * and the count value for one micro-second delay of the target + * specific hardware. + * Modified the ispVMDelay function + * Removed Delay Percent support + * Moved the sclock() function from ivm_core.c to hardware.c + *********************************************************************************/ +#include "vmopcode.h" +#include +#include +/******************************************************************************** +* Declaration of global variables +* +*********************************************************************************/ +#ifndef IPMI_PRJ +unsigned long g_siIspPins = 0x00000000; /*Keeper of JTAG pin state*/ +unsigned short g_usInPort = 0x588; /*Address of the TDO pin*/ +unsigned short g_usOutPort = 0x588; /*Address of TDI, TMS, TCK pin*/ +unsigned short g_usCpu_Frequency = 2400; // Here is Intel rangely CPU frequence /*Enter your CPU frequency here, unit in MHz.*/ +#else +unsigned long g_siIspPins = 0x00000000; /*Keeper of JTAG pin state*/ +unsigned short g_usInPort = 0x548; /*Address of the TDO pin*/ +unsigned short g_usOutPort = 0x548; /*Address of TDI, TMS, TCK pin*/ +unsigned short g_usCpu_Frequency = 4000; // Here is Intel rangely CPU frequence /*Enter your CPU frequency here, unit in MHz.*/ +#endif + +/********************************************************************************* +* This is the definition of the bit locations of each respective +* signal in the global variable g_siIspPins. +* +* NOTE: Users must add their own implementation here to define +* the bit location of the signal to target their hardware. +* The example below is for the Lattice download cable on +* on the parallel port. +* +*********************************************************************************/ + +#ifndef IPMI_PRJ +const unsigned long g_ucPinTDI = 0x00000100; /* Bit address of TDI */ +const unsigned long g_ucPinTCK = 0x00000010; /* Bit address of TCK */ +const unsigned long g_ucPinTMS = 0x00000020; /* Bit address of TMS */ +const unsigned long g_ucPinENABLE = 0x08; /* Bit address of ENABLE */ +const unsigned long g_ucPinTRST = 0x10; /* Bit address of TRST */ +const unsigned long g_ucPinTDO = 0x00040000; /* Bit address of TDO*/ +#else +const unsigned long g_ucPinTDI = 0x00000010; /* Bit address of TDI Bit4*/ +const unsigned long g_ucPinTCK = 0x00000020; /* Bit address of TCK Bit5*/ +const unsigned long g_ucPinTMS = 0x00000004; /* Bit address of TMS Bit2*/ +const unsigned long g_ucPinENABLE = 0x08; /* Bit address of ENABLE */ +const unsigned long g_ucPinTRST = 0x10; /* Bit address of TRST */ +const unsigned long g_ucPinTDO = 0x00000008; /* Bit address of TDO Bit3*/ +#endif +/*************************************************************** +* +* Functions declared in hardware.c module. +* +***************************************************************/ +void writePort( unsigned long a_ucPins, unsigned char a_ucValue ); +unsigned char readPort(); +void sclock(); +void ispVMDelay( unsigned short a_usTimeDelay ); +void calibration(void); + +/******************************************************************************** +* writePort +* To apply the specified value to the pins indicated. This routine will +* be modified for specific systems. +* As an example, this code uses the IBM-PC standard Parallel port, along with the +* schematic shown in Lattice documentation, to apply the signals to the +* JTAG pins. +* +* PC Parallel port pin Signal name Port bit address +* 2 g_ucPinTDI 1 +* 3 g_ucPinTCK 2 +* 4 g_ucPinTMS 4 +* 5 g_ucPinENABLE 8 +* 6 g_ucPinTRST 16 +* 10 g_ucPinTDO 64 +* +* Parameters: +* - a_ucPins, which is actually a set of bit flags (defined above) +* that correspond to the bits of the data port. Each of the I/O port +* bits that drives an isp programming pin is assigned a flag +* (through a #define) corresponding to the signal it drives. To +* change the value of more than one pin at once, the flags are added +* together, much like file access flags are. +* +* The bit flags are only set if the pin is to be changed. Bits that +* do not have their flags set do not have their levels changed. The +* state of the port is always manintained in the static global +* variable g_siIspPins, so that each pin can be addressed individually +* without disturbing the others. +* +* - a_ucValue, which is either HIGH (0x01 ) or LOW (0x00 ). Only these two +* values are valid. Any non-zero number sets the pin(s) high. +* +*********************************************************************************/ + +void writePort( unsigned long a_ucPins, unsigned char a_ucValue ) +{ + if ( a_ucValue ) { + g_siIspPins = (a_ucPins | g_siIspPins); + } + else { + g_siIspPins = (~a_ucPins & g_siIspPins); + } + + outl_p( g_siIspPins, g_usOutPort ); + /* This is a sample code for Windows/DOS without Windows Driver. + _outp( g_usOutPort, g_siIspPins ); + */ +} + +/********************************************************************************* +* +* readPort +* +* Returns the value of the TDO from the device. +* +**********************************************************************************/ +unsigned char readPort() +{ + unsigned char ucRet = 0; + + if ( inl_p( g_usInPort ) & g_ucPinTDO ) { + ucRet = 0x01; + } + else { + ucRet = 0x00; + } + //printf("Read Port: 0x%x\n", ucRet); + return ( ucRet ); +} + +/********************************************************************************* +* sclock +* +* Apply a pulse to TCK. +* +* This function is located here so that users can modify to slow down TCK if +* it is too fast (> 25MHZ). Users can change the IdleTime assignment from 0 to +* 1, 2... to effectively slowing down TCK by half, quarter... +* +*********************************************************************************/ +void sclock() +{ + unsigned short IdleTime = 0; //change to > 0 if need to slow down TCK + unsigned short usIdleIndex = 0; + IdleTime++; + for ( usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++ ) { + writePort( g_ucPinTCK, 0x01 ); + } + for ( usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++ ) { + writePort( g_ucPinTCK, 0x00 ); + } +} +/******************************************************************************** +* +* ispVMDelay +* +* +* Users must implement a delay to observe a_usTimeDelay, where +* bit 15 of the a_usTimeDelay defines the unit. +* 1 = milliseconds +* 0 = microseconds +* Example: +* a_usTimeDelay = 0x0001 = 1 microsecond delay. +* a_usTimeDelay = 0x8001 = 1 millisecond delay. +* +* This subroutine is called upon to provide a delay from 1 millisecond to a few +* hundreds milliseconds each time. +* It is understood that due to a_usTimeDelay is defined as unsigned short, a 16 bits +* integer, this function is restricted to produce a delay to 64000 micro-seconds +* or 32000 milli-second maximum. The VME file will never pass on to this function +* a delay time > those maximum number. If it needs more than those maximum, the VME +* file will launch the delay function several times to realize a larger delay time +* cummulatively. +* It is perfectly alright to provide a longer delay than required. It is not +* acceptable if the delay is shorter. +* +* Delay function example--using the machine clock signal of the native CPU------ +* When porting ispVME to a native CPU environment, the speed of CPU or +* the system clock that drives the CPU is usually known. +* The speed or the time it takes for the native CPU to execute one for loop +* then can be calculated as follows: +* The for loop usually is compiled into the ASSEMBLY code as shown below: +* LOOP: DEC RA; +* JNZ LOOP; +* If each line of assembly code needs 4 machine cycles to execute, +* the total number of machine cycles to execute the loop is 2 x 4 = 8. +* Usually system clock = machine clock (the internal CPU clock). +* Note: Some CPU has a clock multiplier to double the system clock for + the machine clock. +* +* Let the machine clock frequency of the CPU be F, or 1 machine cycle = 1/F. +* The time it takes to execute one for loop = (1/F ) x 8. +* Or one micro-second = F(MHz)/8; +* +* Example: The CPU internal clock is set to 100Mhz, then one micro-second = 100/8 = 12 +* +* The C code shown below can be used to create the milli-second accuracy. +* Users only need to enter the speed of the cpu. +* +**********************************************************************************/ +void ispVMDelay( unsigned short a_usTimeDelay ) +{ + unsigned short loop_index = 0; + unsigned short ms_index = 0; + unsigned short us_index = 0; + + if ( a_usTimeDelay & 0x8000 ) /*Test for unit*/ + { + a_usTimeDelay &= ~0x8000; /*unit in milliseconds*/ + } + else { /*unit in microseconds*/ + a_usTimeDelay = (unsigned short) (a_usTimeDelay/1000); /*convert to milliseconds*/ + if ( a_usTimeDelay <= 0 ) { + a_usTimeDelay = 1; /*delay is 1 millisecond minimum*/ + } + } + /*Users can replace the following section of code by their own*/ + for( ms_index = 0; ms_index < a_usTimeDelay; ms_index++) + { + /*Loop 1000 times to produce the milliseconds delay*/ + for (us_index = 0; us_index < 1000; us_index++) + { /*each loop should delay for 1 microsecond or more.*/ + loop_index = 0; + do { + /*The NOP fakes the optimizer out so that it doesn't toss out the loop code entirely*/ + asm("nop"); + }while (loop_index++ < ((g_usCpu_Frequency/8)+(+ ((g_usCpu_Frequency % 8) ? 1 : 0))));/*use do loop to force at least one loop*/ + } + } +} + +/********************************************************************************* +* +* calibration +* +* It is important to confirm if the delay function is indeed providing +* the accuracy required. Also one other important parameter needed +* checking is the clock frequency. +* Calibration will help to determine the system clock frequency +* and the loop_per_micro value for one micro-second delay of the target +* specific hardware. +* +**********************************************************************************/ +void calibration(void) +{ + /*Apply 2 pulses to TCK.*/ + writePort( g_ucPinTCK, 0x00 ); + writePort( g_ucPinTCK, 0x01 ); + writePort( g_ucPinTCK, 0x00 ); + writePort( g_ucPinTCK, 0x01 ); + writePort( g_ucPinTCK, 0x00 ); + + /*Delay for 1 millisecond. Pass on 1000 or 0x8001 both = 1ms delay.*/ + ispVMDelay(0x8001); + + /*Apply 2 pulses to TCK*/ + writePort( g_ucPinTCK, 0x01 ); + writePort( g_ucPinTCK, 0x00 ); + writePort( g_ucPinTCK, 0x01 ); + writePort( g_ucPinTCK, 0x00 ); +} + +void port_test(void) +{ + int siRetCode; + unsigned char cbit; + + printf("TDI set HIGH.\n"); + scanf("%d",&siRetCode); + writePort( g_ucPinTDI, 0x01); + printf("TDI set LOW.\n"); + scanf("%d",&siRetCode); + writePort( g_ucPinTDI, 0x00); + printf("TMS set HIGH.\n"); + scanf("%d",&siRetCode); + writePort(g_ucPinTMS, 0x01); + printf("TMS set LOW.\n"); + scanf("%d",&siRetCode); + writePort(g_ucPinTMS, 0x00); + printf("TCK set HIGH.\n"); + scanf("%d",&siRetCode); + writePort(g_ucPinTCK, 0x01); + printf("TCK set LOW.\n"); + scanf("%d",&siRetCode); + writePort(g_ucPinTCK, 0x00); + printf("write finished.read begin:\n"); + scanf("%d",&siRetCode); + cbit = readPort(); + printf("Read date is %d\n", cbit); + printf("read begin:\n"); + scanf("%d",&siRetCode); + cbit = readPort(); + printf("Read date is %d\n", cbit); + printf("read finished.\n"); + scanf("%d",&siRetCode); + /******test JTAG ports**********/ +} diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c new file mode 100644 index 000000000000..b22210336901 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c @@ -0,0 +1,784 @@ +/************************************************************** +* +* Lattice Semiconductor Corp. Copyright 2008 +* +* ispVME Embedded allows programming of Lattice's suite of FPGA +* devices on embedded systems through the JTAG port. The software +* is distributed in source code form and is open to re - distribution +* and modification where applicable. +* +* ispVME Embedded C Source comprised with 3 modules: +* ispvm_ui.c is the module provides input and output support. +* ivm_core.c is the module interpret the VME file(s). +* hardware.c is the module access the JTAG port of the device(s). +* +* The optional module cable.c is for supporting Lattice's parallel +* port ispDOWNLOAD cable on DOS and Windows 95/98 O/S. It can be +* requested from Lattice's ispVMSupport. +* +***************************************************************/ + + +/************************************************************** +* +* Revision History of ispvm_ui.c +* +* 3/6/07 ht Added functions vme_out_char(),vme_out_hex(), +* vme_out_string() to provide output resources. +* Consolidate all printf() calls into the added output +* functions. +* +* 09/11/07 NN Added Global variables initialization +* 09/24/07 NN Added a switch allowing users to do calibration. +* Calibration will help to determine the system clock frequency +* and the count value for one micro-second delay of the target +* specific hardware. +* Removed Delay Percent support +* 11/15/07 NN moved the checking of the File CRC to the end of processing +* 08/28/08 NN Added Calculate checksum support. +***************************************************************/ + + +#include +#include +#include +#include +#include "vmopcode.h" + +/*************************************************************** +* +* File pointer to the VME file. +* +***************************************************************/ + +FILE * g_pVMEFile = NULL; + +#define DEBUG +#ifdef DEBUG +#define Debug_printf(fmt, args...) printf(fmt, ##args); +#else +#define Debug_printf(fmt, args...) +#endif + +/*************************************************************** +* +* Functions declared in this ispvm_ui.c module +* +***************************************************************/ +unsigned char GetByte(void); +void vme_out_char(unsigned char charOut); +void vme_out_hex(unsigned char hexOut); +void vme_out_string(char *stringOut); +void ispVMMemManager( signed char cTarget, unsigned short usSize ); +void ispVMFreeMem(void); +void error_handler( short a_siRetCode, char * pszMessage ); +signed char ispVM( const char * a_pszFilename ); + +/*************************************************************** +* +* Global variables. +* +***************************************************************/ +unsigned short g_usPreviousSize = 0; +unsigned short g_usExpectedCRC = 0; + +/*************************************************************** +* +* External variables and functions declared in ivm_core.c module. +* +***************************************************************/ +extern signed char ispVMCode(); +extern void ispVMCalculateCRC32( unsigned char a_ucData ); +extern void ispVMStart(); +extern void ispVMEnd(); +extern unsigned short g_usCalculatedCRC; +extern unsigned short g_usDataType; +extern unsigned char * g_pucOutMaskData, + * g_pucInData, + * g_pucOutData, + * g_pucHIRData, + * g_pucTIRData, + * g_pucHDRData, + * g_pucTDRData, + * g_pucOutDMaskData, + * g_pucIntelBuffer; +extern unsigned char * g_pucHeapMemory; +extern unsigned short g_iHeapCounter; +extern unsigned short g_iHEAPSize; +extern unsigned short g_usIntelDataIndex; +extern unsigned short g_usIntelBufferSize; +extern LVDSPair * g_pLVDSList; +//08/28/08 NN Added Calculate checksum support. +extern unsigned long g_usChecksum; +extern unsigned int g_uiChecksumIndex; +/*************************************************************** +* +* External variables and functions declared in hardware.c module. +* +***************************************************************/ +extern void calibration(void); +extern unsigned short g_usCpu_Frequency; + +/*************************************************************** +* +* Supported VME versions. +* +***************************************************************/ + +const char * const g_szSupportedVersions[] = { "__VME2.0", "__VME3.0", "____12.0", "____12.1", 0 }; + +/*************************************************************** +* +* GetByte +* +* Returns a byte to the caller. The returned byte depends on the +* g_usDataType register. If the HEAP_IN bit is set, then the byte +* is returned from the HEAP. If the LHEAP_IN bit is set, then +* the byte is returned from the intelligent buffer. Otherwise, +* the byte is returned directly from the VME file. +* +***************************************************************/ + +unsigned char GetByte() +{ + unsigned char ucData = 0; + + if ( g_usDataType & HEAP_IN ) { + + /*************************************************************** + * + * Get data from repeat buffer. + * + ***************************************************************/ + + if ( g_iHeapCounter > g_iHEAPSize ) { + + /*************************************************************** + * + * Data over-run. + * + ***************************************************************/ + + return 0xFF; + } + + ucData = g_pucHeapMemory[ g_iHeapCounter++ ]; + } + else if ( g_usDataType & LHEAP_IN ) { + + /*************************************************************** + * + * Get data from intel buffer. + * + ***************************************************************/ + + if ( g_usIntelDataIndex >= g_usIntelBufferSize ) { + + /*************************************************************** + * + * Data over-run. + * + ***************************************************************/ + + return 0xFF; + } + + ucData = g_pucIntelBuffer[ g_usIntelDataIndex++ ]; + } + else { + + /*************************************************************** + * + * Get data from file. + * + ***************************************************************/ + + ucData = (unsigned char)fgetc( g_pVMEFile ); + + if ( feof( g_pVMEFile ) ) { + + /*************************************************************** + * + * Reached EOF. + * + ***************************************************************/ + + return 0xFF; + } + /*************************************************************** + * + * Calculate the 32-bit CRC if the expected CRC exist. + * + ***************************************************************/ + if( g_usExpectedCRC != 0) + { + ispVMCalculateCRC32(ucData); + } + } + + return ( ucData ); +} + +/*************************************************************** +* +* vme_out_char +* +* Send a character out to the output resource if available. +* The monitor is the default output resource. +* +* +***************************************************************/ +void vme_out_char(unsigned char charOut) +{ + printf("%c",charOut); +} +/*************************************************************** +* +* vme_out_hex +* +* Send a character out as in hex format to the output resource +* if available. The monitor is the default output resource. +* +* +***************************************************************/ +void vme_out_hex(unsigned char hexOut) +{ + printf("%.2X",hexOut); +} +/*************************************************************** +* +* vme_out_string +* +* Send a text string out to the output resource if available. +* The monitor is the default output resource. +* +* +***************************************************************/ +void vme_out_string(char *stringOut) +{ + if(stringOut) + { + printf("%s",stringOut); + } + +} +/*************************************************************** +* +* ispVMMemManager +* +* Allocate memory based on cTarget. The memory size is specified +* by usSize. +* +***************************************************************/ + +void ispVMMemManager( signed char cTarget, unsigned short usSize ) +{ + switch ( cTarget ) { + case XTDI: + case TDI: + if ( g_pucInData != NULL ) { + if ( g_usPreviousSize == usSize ) {/*memory exist*/ + break; + } + else { + free( g_pucInData ); + g_pucInData = NULL; + } + } + g_pucInData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + g_usPreviousSize = usSize; + case XTDO: + case TDO: + if ( g_pucOutData!= NULL ) { + if ( g_usPreviousSize == usSize ) { /*already exist*/ + break; + } + else { + free( g_pucOutData ); + g_pucOutData = NULL; + } + } + g_pucOutData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + g_usPreviousSize = usSize; + break; + case MASK: + if ( g_pucOutMaskData != NULL ) { + if ( g_usPreviousSize == usSize ) {/*already allocated*/ + break; + } + else { + free( g_pucOutMaskData ); + g_pucOutMaskData = NULL; + } + } + g_pucOutMaskData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + g_usPreviousSize = usSize; + break; + case HIR: + if ( g_pucHIRData != NULL ) { + free( g_pucHIRData ); + g_pucHIRData = NULL; + } + g_pucHIRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + break; + case TIR: + if ( g_pucTIRData != NULL ) { + free( g_pucTIRData ); + g_pucTIRData = NULL; + } + g_pucTIRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + break; + case HDR: + if ( g_pucHDRData != NULL ) { + free( g_pucHDRData ); + g_pucHDRData = NULL; + } + g_pucHDRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + break; + case TDR: + if ( g_pucTDRData != NULL ) { + free( g_pucTDRData ); + g_pucTDRData = NULL; + } + g_pucTDRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + break; + case HEAP: + if ( g_pucHeapMemory != NULL ) { + free( g_pucHeapMemory ); + g_pucHeapMemory = NULL; + } + g_pucHeapMemory = ( unsigned char * ) malloc( usSize + 2 ); + break; + case DMASK: + if ( g_pucOutDMaskData != NULL ) { + if ( g_usPreviousSize == usSize ) { /*already allocated*/ + break; + } + else { + free( g_pucOutDMaskData ); + g_pucOutDMaskData = NULL; + } + } + g_pucOutDMaskData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + g_usPreviousSize = usSize; + break; + case LHEAP: + if ( g_pucIntelBuffer != NULL ) { + free( g_pucIntelBuffer ); + g_pucIntelBuffer = NULL; + } + g_pucIntelBuffer = ( unsigned char * ) malloc( usSize + 2 ); + break; + case LVDS: + if ( g_pLVDSList != NULL ) { + free( g_pLVDSList ); + g_pLVDSList = NULL; + } + g_pLVDSList = ( LVDSPair * ) calloc( usSize, sizeof( LVDSPair ) ); + break; + default: + return; + } +} + +/*************************************************************** +* +* ispVMFreeMem +* +* Free memory that were dynamically allocated. +* +***************************************************************/ + +void ispVMFreeMem() +{ + if ( g_pucHeapMemory != NULL ) { + free( g_pucHeapMemory ); + g_pucHeapMemory = NULL; + } + + if ( g_pucOutMaskData != NULL ) { + free( g_pucOutMaskData ); + g_pucOutMaskData = NULL; + } + + if ( g_pucInData != NULL ) { + free( g_pucInData ); + g_pucInData = NULL; + } + + if ( g_pucOutData != NULL ) { + free( g_pucOutData ); + g_pucOutData = NULL; + } + + if ( g_pucHIRData != NULL ) { + free( g_pucHIRData ); + g_pucHIRData = NULL; + } + + if ( g_pucTIRData != NULL ) { + free( g_pucTIRData ); + g_pucTIRData = NULL; + } + + if ( g_pucHDRData != NULL ) { + free( g_pucHDRData ); + g_pucHDRData = NULL; + } + + if ( g_pucTDRData != NULL ) { + free( g_pucTDRData ); + g_pucTDRData = NULL; + } + + if ( g_pucOutDMaskData != NULL ) { + free( g_pucOutDMaskData ); + g_pucOutDMaskData = NULL; + } + + if ( g_pucIntelBuffer != NULL ) { + free( g_pucIntelBuffer ); + g_pucIntelBuffer = NULL; + } + + if ( g_pLVDSList != NULL ) { + free( g_pLVDSList ); + g_pLVDSList = NULL; + } +} + +/*************************************************************** +* +* error_handler +* +* Reports the error message. +* +***************************************************************/ + +void error_handler( short a_siRetCode, char * pszMessage ) +{ + const char * pszErrorMessage[] = { "pass", + "verification fail", + "can't find the file", + "wrong file type", + "file error", + "option error", + "crc verification error" }; + + strcpy( pszMessage, pszErrorMessage[ -a_siRetCode ] ); +} +/*************************************************************** +* +* ispVM +* +* The entry point of the ispVM embedded. If the version and CRC +* are verified, then the VME will be processed. +* +***************************************************************/ + +signed char ispVM( const char * a_pszFilename ) +{ + char szFileVersion[ 9 ] = { 0 }; + signed char cRetCode = 0; + signed char cIndex = 0; + signed char cVersionIndex = 0; + unsigned char ucReadByte = 0; + + /*************************************************************** + * + * Global variables initialization. + * + * 09/11/07 NN Added + ***************************************************************/ + g_pucHeapMemory = NULL; + g_iHeapCounter = 0; + g_iHEAPSize = 0; + g_usIntelDataIndex = 0; + g_usIntelBufferSize = 0; + g_usPreviousSize = 0; + + /*************************************************************** + * + * Open a file pointer to the VME file. + * + ***************************************************************/ + + if ( ( g_pVMEFile = fopen( a_pszFilename, "rb" ) ) == NULL ) { + return VME_FILE_READ_FAILURE; + } + g_usCalculatedCRC = 0; + g_usExpectedCRC = 0; + ucReadByte = GetByte(); + switch( ucReadByte ) { + case FILE_CRC: + + /*************************************************************** + * + * Read and store the expected CRC to do the comparison at the end. + * Only versions 3.0 and higher support CRC protection. + * + ***************************************************************/ + + g_usExpectedCRC = (unsigned char ) fgetc( g_pVMEFile ); + g_usExpectedCRC <<= 8; + g_usExpectedCRC |= fgetc( g_pVMEFile ); + + + /*************************************************************** + * + * Read and store the version of the VME file. + * + ***************************************************************/ + + for ( cIndex = 0; cIndex < 8; cIndex++ ) { + szFileVersion[ cIndex ] = GetByte(); + } + + break; + default: + + /*************************************************************** + * + * Read and store the version of the VME file. Must be version 2.0. + * + ***************************************************************/ + + szFileVersion[ 0 ] = ( signed char ) ucReadByte; + for ( cIndex = 1; cIndex < 8; cIndex++ ) { + szFileVersion[ cIndex ] = GetByte(); + } + + break; + } + + /*************************************************************** + * + * Compare the VME file version against the supported version. + * + ***************************************************************/ + + for ( cVersionIndex = 0; g_szSupportedVersions[ cVersionIndex ] != 0; cVersionIndex++ ) { + for ( cIndex = 0; cIndex < 8; cIndex++ ) { + if ( szFileVersion[ cIndex ] != g_szSupportedVersions[ cVersionIndex ][ cIndex ] ) { + cRetCode = VME_VERSION_FAILURE; + break; + } + cRetCode = 0; + } + + if ( cRetCode == 0 ) { + + /*************************************************************** + * + * Found matching version, break. + * + ***************************************************************/ + + break; + } + } + + if ( cRetCode < 0 ) { + + /*************************************************************** + * + * VME file version failed to match the supported versions. + * + ***************************************************************/ + + fclose( g_pVMEFile ); + g_pVMEFile = NULL; + return VME_VERSION_FAILURE; + } + + /*************************************************************** + * + * Enable the JTAG port to communicate with the device. + * Set the JTAG state machine to the Test-Logic/Reset State. + * + ***************************************************************/ + + ispVMStart(); + + /*************************************************************** + * + * Process the VME file. + * + ***************************************************************/ + + cRetCode = ispVMCode(); + + /*************************************************************** + * + * Set the JTAG State Machine to Test-Logic/Reset state then disable + * the communication with the JTAG port. + * + ***************************************************************/ + + ispVMEnd(); + + fclose( g_pVMEFile ); + g_pVMEFile = NULL; + + + ispVMFreeMem(); + + /*************************************************************** + * + * Compare the expected CRC versus the calculated CRC. + * + ***************************************************************/ + + if ( cRetCode == 0 && g_usExpectedCRC != 0 && ( g_usExpectedCRC != g_usCalculatedCRC ) ) { + printf( "Expected CRC: 0x%.4X\n", g_usExpectedCRC ); + printf( "Calculated CRC: 0x%.4X\n", g_usCalculatedCRC ); + return VME_CRC_FAILURE; + } + + return ( cRetCode ); +} + +/*************************************************************** +* +* main +* +***************************************************************/ + +char *strlwr(char *str) +{ + char *orig = str; + + for (; *str != '\0'; str++) + *str = tolower(*str); + + return orig; +} + +int main( int argc, char * argv[] ) +{ + unsigned short iCommandLineIndex = 0; + short siRetCode = 0; + char szExtension[ 5 ] = { 0 }; + char szCommandLineArg[ 300 ] = { 0 }; + short sicalibrate = 0; + unsigned char set_freq = 0; + + //08/28/08 NN Added Calculate checksum support. + g_usChecksum = 0; + g_uiChecksumIndex = 0; + + vme_out_string( " Lattice Semiconductor Corp.\n" ); + vme_out_string( "\n ispVME(tm) V"); + vme_out_string( VME_VERSION_NUMBER ); + vme_out_string(" Copyright 1998-2011.\n"); + vme_out_string( "\nFor daisy chain programming of all in-system programmable devices\n\n" ); + + if ( argc < 2 ) { + vme_out_string( "\nUsage: vme [option] vme_file [vme_file]\n" ); + vme_out_string( "Example: vme vme_file1.vme vme_file2.vme\n" ); + vme_out_string( "option -c: do the calibration.\n" ); + vme_out_string( "Example: vme -c\n" ); + vme_out_string( "Example: vme -c vme_file1.vme vme_file2.vme\n" ); + vme_out_string( "\n\n"); + exit( 1 ); + } + for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) { + strcpy( szCommandLineArg, argv[ iCommandLineIndex ] ); + if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex == 1 ) ) { + sicalibrate = 1; + } + else if ( !strcmp( strlwr( szCommandLineArg ), "-f" ) && ( iCommandLineIndex == 2 ) ) { + g_usCpu_Frequency = strtoul(argv[iCommandLineIndex+1],NULL,0); + set_freq = 1; + printf("CPU Freq set as %d MHZ\n", g_usCpu_Frequency); + } + else if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex != 1 ) ) { + vme_out_string( "Error: calibrate option -c must be the first argument\n\n" ); + exit( 1 ); + } + else if(((iCommandLineIndex >= 4)&&(set_freq == 1)) || (set_freq == 0)) + { + strcpy( szExtension, &szCommandLineArg[ strlen( szCommandLineArg ) - 4 ] ); + strlwr( szExtension ); + if ( strcmp( szExtension, ".vme" ) ) { + vme_out_string( "Error: VME files must end with the extension *.vme\n\n" ); + exit( 1 ); + } + } + } + if (iopl(3)) + { + perror("iopl"); + exit(1);/* reminder here: do not use "return", I warned */ + } + else + { +#ifndef IPMI_PRJ + outl_p((inl_p(0x580) | 0x40130), 0x580); + outl_p((inl_p(0x584) & 0xFFFFFECF), 0x584); + outl_p((inl_p(0x584) | 0x00040000), 0x584); +#else + //outl_p((inl_p(0x540) | 0x3C0), 0x540); //Pebble:2->cs,5->clk, offset 0x540 + outl_p((inl_p(0x540) | 0xFFFFFFFF), 0x540); //Pebble:2->cs,5->clk, offset 0x540 + //printf("IPMI GPIO init: 0x%x 0x%x 0x%x\n", + // inl_p(0x540), inl_p(0x544), inl_p(0x548)); + outl_p((inl_p(0x544) & 0xFFFFFFCB), 0x544); //Pebble:2,4,5->output:0 3->input:1 + outl_p((inl_p(0x544) | 0x8), 0x544); + //printf("IPMI GPIO init finished: 0x%x 0x%x 0x%x\n", + // inl_p(0x540), inl_p(0x544), inl_p(0x548)); +#endif + } + /******test JTAG ports**********/ + //port_test(); + /******test JTAG ports**********/ + siRetCode = 0; + if(sicalibrate) + { + calibration(); + } + for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) { /* Process all VME files sequentially */ + strcpy( szCommandLineArg, argv[ iCommandLineIndex ] ); + if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex == 1 ) ) { + } + else if ( !strcmp( strlwr( szCommandLineArg ), "-checksum" )) {} + else if(((iCommandLineIndex >= 4)&&(set_freq == 1)) || (set_freq == 0)) + { + vme_out_string( "Processing virtual machine file ("); + vme_out_string( szCommandLineArg ); + vme_out_string (")......\n\n"); + siRetCode = ispVM( szCommandLineArg ); + if ( siRetCode < 0 ) { + break; + } + } + } + if ( siRetCode < 0 ) { + error_handler( siRetCode, szCommandLineArg ); + vme_out_string( "Failed due to "); + vme_out_string ( szCommandLineArg ); + vme_out_string ("\n\n"); + vme_out_string( "+=======+\n" ); + vme_out_string( "| FAIL! |\n" ); + vme_out_string( "+=======+\n\n" ); + } + else { + vme_out_string( "+=======+\n" ); + vme_out_string( "| PASS! |\n" ); + vme_out_string( "+=======+\n\n" ); + //08/28/08 NN Added Calculate checksum support. + if(g_usChecksum != 0) + { + g_usChecksum &= 0xFFFF; + printf("Data Checksum: %.4X\n\n",g_usChecksum); + g_usChecksum = 0; + } + } + + if (iopl(0)) + { + perror("iopl"); + exit(1);/* reminder here: do not use "return", I warned */ + } + exit( siRetCode ); +} + diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ivm_core.c b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ivm_core.c new file mode 100644 index 000000000000..430d67c5a0fe --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ivm_core.c @@ -0,0 +1,3082 @@ +/*************************************************************** +* +* Lattice Semiconductor Corp. Copyright 2009 +* +* ispVME Embedded allows programming of Lattice's suite of FPGA +* devices on embedded systems through the JTAG port. The software +* is distributed in source code form and is open to re - distribution +* and modification where applicable. +* +* Revision History of ivm_core.c module: +* 4/25/06 ht Change some variables from unsigned short or int +* to long int to make the code compiler independent. +* 5/24/06 ht Support using RESET (TRST) pin as a special purpose +* control pin such as triggering the loading of known +* state exit. +* 3/6/07 ht added functions to support output to terminals +* +* 09/24/07 NN Type cast mismatch variables +* Moved the sclock() function to hardware.c +* 08/28/08 NN Added Calculate checksum support. +* 4/1/09 Nguyen replaced the recursive function call codes on +* the ispVMLCOUNT function +* +***************************************************************/ + +#include +#include +#include "vmopcode.h" + +#undef VME_DEBUG +//#define VME_DEBUG +/*************************************************************** +* +* Global variables used to specify the flow control and data type. +* +* g_usFlowControl: flow control register. Each bit in the +* register can potentially change the +* personality of the embedded engine. +* g_usDataType: holds the data type of the current row. +* +***************************************************************/ + +unsigned short g_usFlowControl = 0x0000; +unsigned short g_usDataType = 0x0000; + +/*************************************************************** +* +* Global variables used to specify the ENDDR and ENDIR. +* +* g_ucEndDR: the state that the device goes to after SDR. +* g_ucEndIR: the state that the device goes to after SIR. +* +***************************************************************/ + +unsigned char g_ucEndDR = DRPAUSE; +unsigned char g_ucEndIR = IRPAUSE; + +/*************************************************************** +* +* Global variables used to support header/trailer. +* +* g_usHeadDR: the number of lead devices in bypass. +* g_usHeadIR: the sum of IR length of lead devices. +* g_usTailDR: the number of tail devices in bypass. +* g_usTailIR: the sum of IR length of tail devices. +* +***************************************************************/ + +unsigned short g_usHeadDR = 0; +unsigned short g_usHeadIR = 0; +unsigned short g_usTailDR = 0; +unsigned short g_usTailIR = 0; + +/*************************************************************** +* +* Global variable to store the number of bits of data or instruction +* to be shifted into or out from the device. +* +***************************************************************/ + +unsigned short g_usiDataSize = 0; + +/*************************************************************** +* +* Stores the frequency. Default to 1 MHz. +* +***************************************************************/ + +int g_iFrequency = 1000; + +/*************************************************************** +* +* Stores the maximum amount of ram needed to hold a row of data. +* +***************************************************************/ + +unsigned short g_usMaxSize = 0; + +/*************************************************************** +* +* Stores the LSH or RSH value. +* +***************************************************************/ + +unsigned short g_usShiftValue = 0; + +/*************************************************************** +* +* Stores the current repeat loop value. +* +***************************************************************/ + +unsigned short g_usRepeatLoops = 0; + +/*************************************************************** +* +* Stores the current vendor. +* +***************************************************************/ + +signed char g_cVendor = LATTICE; + +/*************************************************************** +* +* Stores the VME file CRC. +* +***************************************************************/ + +unsigned short g_usCalculatedCRC = 0; + +/*************************************************************** +* +* Stores the Device Checksum. +* +***************************************************************/ +//08/28/08 NN Added Calculate checksum support. +unsigned long g_usChecksum = 0; +unsigned int g_uiChecksumIndex = 0; + +/*************************************************************** +* +* Stores the current state of the JTAG state machine. +* +***************************************************************/ + +signed char g_cCurrentJTAGState = 0; + +/*************************************************************** +* +* Global variables used to support looping. +* +* g_pucHeapMemory: holds the entire repeat loop. +* g_iHeapCounter: points to the current byte in the repeat loop. +* g_iHEAPSize: the current size of the repeat in bytes. +* +***************************************************************/ + +unsigned char * g_pucHeapMemory = NULL; +unsigned short g_iHeapCounter = 0; +unsigned short g_iHEAPSize = 0; + +/*************************************************************** +* +* Global variables used to support intelligent programming. +* +* g_usIntelDataIndex: points to the current byte of the +* intelligent buffer. +* g_usIntelBufferSize: holds the size of the intelligent +* buffer. +* +***************************************************************/ + +unsigned short g_usIntelDataIndex = 0; +unsigned short g_usIntelBufferSize = 0; + +/**************************************************************************** +* +* Holds the maximum size of each respective buffer. These variables are used +* to write the HEX files when converting VME to HEX. +* +*****************************************************************************/ + +unsigned short g_usTDOSize = 0; +unsigned short g_usMASKSize = 0; +unsigned short g_usTDISize = 0; +unsigned short g_usDMASKSize = 0; +unsigned short g_usLCOUNTSize = 0; +unsigned short g_usHDRSize = 0; +unsigned short g_usTDRSize = 0; +unsigned short g_usHIRSize = 0; +unsigned short g_usTIRSize = 0; +unsigned short g_usHeapSize = 0; + +/*************************************************************** +* +* Global variables used to store data. +* +* g_pucOutMaskData: local RAM to hold one row of MASK data. +* g_pucInData: local RAM to hold one row of TDI data. +* g_pucOutData: local RAM to hold one row of TDO data. +* g_pucHIRData: local RAM to hold the current SIR header. +* g_pucTIRData: local RAM to hold the current SIR trailer. +* g_pucHDRData: local RAM to hold the current SDR header. +* g_pucTDRData: local RAM to hold the current SDR trailer. +* g_pucIntelBuffer: local RAM to hold the current intelligent buffer. +* g_pucOutDMaskData: local RAM to hold one row of DMASK data. +* +***************************************************************/ + +unsigned char * g_pucOutMaskData = NULL, + * g_pucInData = NULL, + * g_pucOutData = NULL, + * g_pucHIRData = NULL, + * g_pucTIRData = NULL, + * g_pucHDRData = NULL, + * g_pucTDRData = NULL, + * g_pucIntelBuffer = NULL, + * g_pucOutDMaskData = NULL; + +/*************************************************************** +* +* JTAG state machine transition table. +* +***************************************************************/ + +struct { + unsigned char CurState; /* From this state */ + unsigned char NextState; /* Step to this state */ + unsigned char Pattern; /* The tragetory of TMS */ + unsigned char Pulses; /* The number of steps */ +} g_JTAGTransistions[ 25 ] = { +{ RESET, RESET, 0xFC, 6 }, /* Transitions from RESET */ +{ RESET, IDLE, 0x00, 1 }, +{ RESET, DRPAUSE, 0x50, 5 }, +{ RESET, IRPAUSE, 0x68, 6 }, +{ IDLE, RESET, 0xE0, 3 }, /* Transitions from IDLE */ +{ IDLE, DRPAUSE, 0xA0, 4 }, +{ IDLE, IRPAUSE, 0xD0, 5 }, +{ DRPAUSE, RESET, 0xF8, 5 }, /* Transitions from DRPAUSE */ +{ DRPAUSE, IDLE, 0xC0, 3 }, +{ DRPAUSE, IRPAUSE, 0xF4, 7 }, +{ DRPAUSE, DRPAUSE, 0xE8, 6 }, /* 06/14/06 Support POLING STATUS LOOP*/ +{ IRPAUSE, RESET, 0xF8, 5 }, /* Transitions from IRPAUSE */ +{ IRPAUSE, IDLE, 0xC0, 3 }, +{ IRPAUSE, DRPAUSE, 0xE8, 6 }, +{ DRPAUSE, SHIFTDR, 0x80, 2 }, /* Extra transitions using SHIFTDR */ +{ IRPAUSE, SHIFTDR, 0xE0, 5 }, +{ SHIFTDR, DRPAUSE, 0x80, 2 }, +{ SHIFTDR, IDLE, 0xC0, 3 }, +{ IRPAUSE, SHIFTIR, 0x80, 2 }, /* Extra transitions using SHIFTIR */ +{ SHIFTIR, IRPAUSE, 0x80, 2 }, +{ SHIFTIR, IDLE, 0xC0, 3 }, +{ DRPAUSE, DRCAPTURE, 0xE0, 4 }, /* 11/15/05 Support DRCAPTURE*/ +{ DRCAPTURE, DRPAUSE, 0x80, 2 }, +{ IDLE, DRCAPTURE, 0x80, 2 }, +{ IRPAUSE, DRCAPTURE, 0xE0, 4 } +}; + +/*************************************************************** +* +* List to hold all LVDS pairs. +* +***************************************************************/ + +LVDSPair * g_pLVDSList = NULL; +unsigned short g_usLVDSPairCount = 0; + +/*************************************************************** +* +* Function prototypes. +* +***************************************************************/ + +signed char ispVMCode(); +signed char ispVMDataCode(); +long int ispVMDataSize(); +void ispVMData( unsigned char * Data ); +signed char ispVMShift( signed char Code ); +signed char ispVMAmble( signed char Code ); +signed char ispVMLoop( unsigned short a_usLoopCount ); +signed char ispVMBitShift( signed char mode, unsigned short bits ); +void ispVMComment( unsigned short a_usCommentSize ); +void ispVMHeader( unsigned short a_usHeaderSize ); +signed char ispVMLCOUNT( unsigned short a_usCountSize ); +void ispVMClocks( unsigned short Clocks ); +void ispVMBypass( signed char ScanType, unsigned short Bits ); +void ispVMStateMachine( signed char NextState ); +void ispVMStart(); +void ispVMEnd(); +signed char ispVMSend(unsigned short int); +signed char ispVMRead(unsigned short int); +signed char ispVMReadandSave(unsigned short int); +signed char ispVMProcessLVDS( unsigned short a_usLVDSCount ); + + +/*************************************************************** +* +* External variables and functions in ispvm_ui.c module +* +***************************************************************/ +extern void vme_out_char(unsigned char charOut); +extern void vme_out_hex(unsigned char hexOut); +extern void vme_out_string(char *stringOut); +extern unsigned char GetByte(); +extern void ispVMMemManager( signed char types, unsigned short size ); + +/*************************************************************** +* +* External variables and functions in hardware.c module +* +***************************************************************/ +extern void ispVMDelay( unsigned short int a_usMicroSecondDelay ); +extern unsigned char readPort(); +extern void writePort( unsigned long pins, unsigned char value ); +extern void sclock(); +extern signed char g_cCurrentJTAGState; +extern const unsigned long g_ucPinTDI; +extern const unsigned long g_ucPinTCK; +extern const unsigned long g_ucPinTMS; +extern const unsigned long g_ucPinENABLE; +extern const unsigned long g_ucPinTRST; +extern const unsigned long g_ucPinTDO; + +#ifdef VME_DEBUG + +/*************************************************************** +* +* GetState +* +* Returns the state as a string based on the opcode. Only used +* for debugging purposes. +* +***************************************************************/ + +const char * GetState( unsigned char a_ucState ) +{ + switch( a_ucState ) { + case RESET: + return( "RESET" ); + case IDLE: + return( "IDLE" ); + case IRPAUSE: + return( "IRPAUSE" ); + case DRPAUSE: + return( "DRPAUSE" ); + case SHIFTIR: + return( "SHIFTIR" ); + case SHIFTDR: + return( "SHIFTDR" ); + case DRCAPTURE:/* 11/15/05 support DRCAPTURE*/ + return( "DRCAPTURE" ); + default: + break; + } + + return 0; +} + +/*************************************************************** +* +* PrintData +* +* Prints the data. Only used for debugging purposes. +* +***************************************************************/ + +void PrintData( unsigned short a_iDataSize, unsigned char * a_pucData ) +{ + //09/11/07 NN added local variables initialization + unsigned short usByteSize = 0; + unsigned short usBitIndex = 0; + signed short usByteIndex = 0; + unsigned char ucByte = 0; + unsigned char ucFlipByte = 0; + + if ( a_iDataSize % 8 ) { + //09/11/07 NN Type cast mismatch variables + usByteSize = (unsigned short)(a_iDataSize / 8 + 1); + } + else { + //09/11/07 NN Type cast mismatch variables + usByteSize = (unsigned short)(a_iDataSize / 8); + } + printf( "(" ); + //09/11/07 NN Type cast mismatch variables + for ( usByteIndex = (signed short)(usByteSize - 1); usByteIndex >= 0; usByteIndex-- ) { + ucByte = a_pucData[ usByteIndex ]; + ucFlipByte = 0x00; + + /*************************************************************** + * + * Flip each byte. + * + ***************************************************************/ + + for ( usBitIndex = 0; usBitIndex < 8; usBitIndex++ ) { + ucFlipByte <<= 1; + if ( ucByte & 0x1) { + ucFlipByte |= 0x1; + } + + ucByte >>= 1; + } + + /*************************************************************** + * + * Print the flipped byte. + * + ***************************************************************/ + + printf( "%.02X", ucFlipByte ); + if ( ( usByteSize - usByteIndex ) % 40 == 39 ) { + printf( "\n\t\t" ); + } + if(usByteIndex < 0) + break; + } + printf( ")" ); +} +#endif //VME_DEBUG + +/*************************************************************** +* +* ispVMDataSize +* +* Returns a VME-encoded number, usually used to indicate the +* bit length of an SIR/SDR command. +* +***************************************************************/ + +long int ispVMDataSize() +{ + //09/11/07 NN added local variables initialization + long int iSize = 0; + signed char cCurrentByte = 0; + signed char cIndex = 0; + cIndex = 0; + while ( ( cCurrentByte = GetByte() ) & 0x80 ) { + iSize |= ( ( long int ) ( cCurrentByte & 0x7F ) ) << cIndex; + cIndex += 7; + } + iSize |= ( ( long int ) ( cCurrentByte & 0x7F ) ) << cIndex; + return iSize; +} + +/*************************************************************** +* +* ispVMCode +* +* This is the heart of the embedded engine. All the high-level opcodes +* are extracted here. Once they have been identified, then it +* will call other functions to handle the processing. +* +***************************************************************/ + +signed char ispVMCode() +{ + //09/11/07 NN added local variables initialization + unsigned short iRepeatSize = 0; + signed char cOpcode = 0; + signed char cRetCode = 0; + unsigned char ucState = 0; + unsigned short usDelay = 0; + unsigned short usToggle = 0; + unsigned char usByte = 0; + + /*************************************************************** + * + * Check the compression flag only if this is the first time + * this function is entered. Do not check the compression flag if + * it is being called recursively from other functions within + * the embedded engine. + * + ***************************************************************/ + + if ( !( g_usDataType & LHEAP_IN ) && !( g_usDataType & HEAP_IN ) ) { + usByte = GetByte(); + if ( usByte == 0xf1 ) { + g_usDataType |= COMPRESS; + } + else if ( usByte == 0xf2 ) { + g_usDataType &= ~COMPRESS; + } + else { + return VME_INVALID_FILE; + } + } + + /*************************************************************** + * + * Begin looping through all the VME opcodes. + * + ***************************************************************/ + + while ( ( cOpcode = GetByte() ) >= 0 ) { + + switch ( cOpcode ) { + case STATE: + + /*************************************************************** + * + * Step the JTAG state machine. + * + ***************************************************************/ + + ucState = GetByte(); + + /*************************************************************** + * + * Step the JTAG state machine to DRCAPTURE to support Looping. + * + ***************************************************************/ + + if ( (g_usDataType & LHEAP_IN) && + (ucState == DRPAUSE ) && + ( g_cCurrentJTAGState == ucState )) + { + ispVMStateMachine( DRCAPTURE ); + } + + ispVMStateMachine( ucState ); + +#ifdef VME_DEBUG + if ( g_usDataType & LHEAP_IN ) { + printf( "LDELAY %s ", GetState( ucState ) ); + } + else { + printf( "STATE %s;\n", GetState( ucState ) ); + } +#endif //VME_DEBUG + break; + case SIR: + case SDR: + case XSDR: + +#ifdef VME_DEBUG + switch( cOpcode ) { + case SIR: + printf( "SIR " ); + break; + case SDR: + case XSDR: + if ( g_usDataType & LHEAP_IN ) { + printf( "LSDR " ); + } + else { + printf( "SDR " ); + } + break; + } +#endif //VME_DEBUG + /*************************************************************** + * + * Shift in data into the device. + * + ***************************************************************/ + + cRetCode = ispVMShift( cOpcode ); + if ( cRetCode != 0 ) { + return ( cRetCode ); + } + break; + case WAIT: + + /*************************************************************** + * + * Observe delay. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + usDelay = (unsigned short) ispVMDataSize(); + ispVMDelay( usDelay ); + +#ifdef VME_DEBUG + if ( usDelay & 0x8000 ) { + + /*************************************************************** + * + * Since MSB is set, the delay time must be decoded to + * millisecond. The SVF2VME encodes the MSB to represent + * millisecond. + * + ***************************************************************/ + + usDelay &= ~0x8000; + if ( g_usDataType & LHEAP_IN ) { + printf( "%.2E SEC;\n", ( float ) usDelay / 1000 ); + } + else { + printf( "RUNTEST %.2E SEC;\n", ( float ) usDelay / 1000 ); + } + } + else { + + /*************************************************************** + * + * Since MSB is not set, the delay time is given as microseconds. + * + ***************************************************************/ + + if ( g_usDataType & LHEAP_IN ) { + printf( "%.2E SEC;\n", ( float ) usDelay / 1000000 ); + } + else { + printf( "RUNTEST %.2E SEC;\n", ( float ) usDelay / 1000000 ); + } + } +#endif //VME_DEBUG + break; + case TCK: + + /*************************************************************** + * + * Issue clock toggles. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + usToggle = (unsigned short) ispVMDataSize(); + ispVMClocks( usToggle ); + +#ifdef VME_DEBUG + printf( "RUNTEST %d TCK;\n", usToggle ); +#endif //VME_DEBUG + break; + case ENDDR: + + /*************************************************************** + * + * Set the ENDDR. + * + ***************************************************************/ + + g_ucEndDR = GetByte(); + +#ifdef VME_DEBUG + printf( "ENDDR %s;\n", GetState( g_ucEndDR ) ); +#endif //VME_DEBUG + break; + case ENDIR: + + /*************************************************************** + * + * Set the ENDIR. + * + ***************************************************************/ + + g_ucEndIR = GetByte(); + +#ifdef VME_DEBUG + printf( "ENDIR %s;\n", GetState( g_ucEndIR ) ); +#endif //VME_DEBUG + break; + case HIR: + case TIR: + case HDR: + case TDR: + +#ifdef VME_DEBUG + switch( cOpcode ) { + case HIR: + printf( "HIR " ); + break; + case TIR: + printf( "TIR " ); + break; + case HDR: + printf( "HDR " ); + break; + case TDR: + printf( "TDR " ); + break; + } +#endif //VME_DEBUG + + /*************************************************************** + * + * Set the header/trailer of the device in order to bypass + * successfully. + * + ***************************************************************/ + + cRetCode = ispVMAmble( cOpcode ); + if ( cRetCode != 0 ) { + return ( cRetCode ); + } + +#ifdef VME_DEBUG + printf( ";\n" ); +#endif //VME_DEBUG + break; + case MEM: + + /*************************************************************** + * + * The maximum RAM required to support processing one row of the + * VME file. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + g_usMaxSize = (unsigned short) ispVMDataSize(); + +#ifdef VME_DEBUG + printf( "// MEMSIZE %d\n", g_usMaxSize ); +#endif //VME_DEBUG + break; + case VENDOR: + + /*************************************************************** + * + * Set the VENDOR type. + * + ***************************************************************/ + + cOpcode = GetByte(); + switch ( cOpcode ) { + case LATTICE: +#ifdef VME_DEBUG + printf( "// VENDOR LATTICE\n" ); +#endif //VME_DEBUG + g_cVendor = LATTICE; + break; + case ALTERA: +#ifdef VME_DEBUG + printf( "// VENDOR ALTERA\n" ); +#endif //VME_DEBUG + g_cVendor = ALTERA; + break; + case XILINX: +#ifdef VME_DEBUG + printf( "// VENDOR XILINX\n" ); +#endif //VME_DEBUG + g_cVendor = XILINX; + break; + default: + break; + } + break; + case SETFLOW: + + /*************************************************************** + * + * Set the flow control. Flow control determines the personality + * of the embedded engine. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + g_usFlowControl |= (unsigned short) ispVMDataSize(); + break; + case RESETFLOW: + + /*************************************************************** + * + * Unset the flow control. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + g_usFlowControl &= (unsigned short) ~( ispVMDataSize() ); + break; + case HEAP: + + /*************************************************************** + * + * Allocate heap size to store loops. + * + ***************************************************************/ + + cRetCode = GetByte(); + if ( cRetCode != SECUREHEAP ) { + return VME_INVALID_FILE; + } + //09/11/07 NN Type cast mismatch variables + g_iHEAPSize = (unsigned short) ispVMDataSize(); + + /**************************************************************************** + * + * Store the maximum size of the HEAP buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_iHEAPSize > g_usHeapSize ) { + g_usHeapSize = g_iHEAPSize; + } + + ispVMMemManager( HEAP, ( unsigned short ) g_iHEAPSize ); + break; + case REPEAT: + + /*************************************************************** + * + * Execute loops. + * + ***************************************************************/ + + g_usRepeatLoops = 0; + + //09/11/07 NN Type cast mismatch variables + iRepeatSize = (unsigned short) ispVMDataSize(); + + cRetCode = ispVMLoop( ( unsigned short ) iRepeatSize ); + if ( cRetCode != 0 ) { + return ( cRetCode ); + } + break; + case ENDLOOP: + + /*************************************************************** + * + * Exit point from processing loops. + * + ***************************************************************/ + + return ( cRetCode ); + case ENDVME: + + /*************************************************************** + * + * The only valid exit point that indicates end of programming. + * + ***************************************************************/ + + return ( cRetCode ); + case SHR: + + /*************************************************************** + * + * Right-shift address. + * + ***************************************************************/ + + g_usFlowControl |= SHIFTRIGHT; + + //09/11/07 NN Type cast mismatch variables + g_usShiftValue = (unsigned short) (g_usRepeatLoops * (unsigned short)GetByte()); + break; + case SHL: + + /*************************************************************** + * + * Left-shift address. + * + ***************************************************************/ + + g_usFlowControl |= SHIFTLEFT; + + //09/11/07 NN Type cast mismatch variables + g_usShiftValue = (unsigned short)(g_usRepeatLoops * (unsigned short)GetByte()); + break; + case FREQUENCY: + + /*************************************************************** + * + * Set the frequency. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + g_iFrequency = (int) (ispVMDataSize() ); + //10/23/08 NN changed to check if the frequency smaller than 1000 + if(g_iFrequency >= 1000) + { + g_iFrequency = g_iFrequency / 1000; + if(g_iFrequency == 1) + g_iFrequency = 1000; +#ifdef VME_DEBUG + printf( "FREQUENCY %.2E HZ;\n", ( float ) g_iFrequency * 1000 ); +#endif //VME_DEBUG + } + else + { + if(g_iFrequency == 0) + g_iFrequency = 1000; +#ifdef VME_DEBUG + printf( "FREQUENCY %.2E HZ;\n", ( float ) g_iFrequency ); +#endif //VME_DEBUG + } + break; + case LCOUNT: + + /*************************************************************** + * + * Process LCOUNT command. + * + ***************************************************************/ + + cRetCode = ispVMLCOUNT( ( unsigned short ) ispVMDataSize() ); + if ( cRetCode != 0 ) { + return ( cRetCode ); + } + break; + case VUES: + + /*************************************************************** + * + * Set the flow control to verify USERCODE. + * + ***************************************************************/ + + g_usFlowControl |= VERIFYUES; + break; + case COMMENT: + + /*************************************************************** + * + * Display comment. + * + ***************************************************************/ + + ispVMComment( ( unsigned short ) ispVMDataSize() ); + break; + case LVDS: + + /*************************************************************** + * + * Process LVDS command. + * + ***************************************************************/ + + ispVMProcessLVDS( ( unsigned short ) ispVMDataSize() ); + break; + case HEADER: + + /*************************************************************** + * + * Discard header. + * + ***************************************************************/ + + ispVMHeader( ( unsigned short ) ispVMDataSize() ); + break; + /* 03/14/06 Support Toggle ispENABLE signal*/ + case ispEN: + ucState = GetByte(); + if((ucState == ON)||(ucState == 0x01)) + writePort( g_ucPinENABLE, 0x01 ); + else + writePort( g_ucPinENABLE, 0x00 ); + ispVMDelay( 1 ); + break; + /* 05/24/06 support Toggle TRST pin*/ + case TRST: + ucState = GetByte(); + if(ucState == 0x01) + writePort( g_ucPinTRST, 0x01 ); + else + writePort( g_ucPinTRST, 0x00 ); + ispVMDelay( 1 ); + break; + default: + + /*************************************************************** + * + * Invalid opcode encountered. + * + ***************************************************************/ + +#ifdef VME_DEBUG + printf( "\nINVALID OPCODE: 0x%.2X\n", cOpcode ); +#endif //VME_DEBUG + + return VME_INVALID_FILE; + } + } + + /*************************************************************** + * + * Invalid exit point. Processing the token 'ENDVME' is the only + * valid way to exit the embedded engine. + * + ***************************************************************/ + + return ( VME_INVALID_FILE ); +} + +/*************************************************************** +* +* ispVMDataCode +* +* Processes the TDI/TDO/MASK/DMASK etc of an SIR/SDR command. +* +***************************************************************/ + +signed char ispVMDataCode() +{ + //09/11/07 NN added local variables initialization + signed char cDataByte = 0; + signed char siDataSource = 0; /*source of data from file by default*/ + + if ( g_usDataType & HEAP_IN ) { + siDataSource = 1; /*the source of data from memory*/ + } + + /**************************************************************************** + * + * Clear the data type register. + * + *****************************************************************************/ + + g_usDataType &= ~( MASK_DATA + TDI_DATA + TDO_DATA + DMASK_DATA + CMASK_DATA ); + + /**************************************************************************** + * + * Iterate through SIR/SDR command and look for TDI, TDO, MASK, etc. + * + *****************************************************************************/ + + while ( ( cDataByte = GetByte() ) >= 0 ) { + + ispVMMemManager( cDataByte, g_usMaxSize ); + switch ( cDataByte ) { + case TDI: + + /**************************************************************************** + * + * Store the maximum size of the TDI buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTDISize ) { + g_usTDISize = g_usiDataSize; + } + /**************************************************************************** + * + * Updated data type register to indicate that TDI data is currently being + * used. Process the data in the VME file into the TDI buffer. + * + *****************************************************************************/ + + g_usDataType |= TDI_DATA; + ispVMData( g_pucInData ); + break; + case XTDO: + + /**************************************************************************** + * + * Store the maximum size of the TDO buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTDOSize ) { + g_usTDOSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Updated data type register to indicate that TDO data is currently being + * used. + * + *****************************************************************************/ + + g_usDataType |= TDO_DATA; + break; + case TDO: + + /**************************************************************************** + * + * Store the maximum size of the TDO buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTDOSize ) { + g_usTDOSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Updated data type register to indicate that TDO data is currently being + * used. Process the data in the VME file into the TDO buffer. + * + *****************************************************************************/ + + g_usDataType |= TDO_DATA; + ispVMData( g_pucOutData ); + break; + case MASK: + + /**************************************************************************** + * + * Store the maximum size of the MASK buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usMASKSize ) { + g_usMASKSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Updated data type register to indicate that MASK data is currently being + * used. Process the data in the VME file into the MASK buffer. + * + *****************************************************************************/ + + g_usDataType |= MASK_DATA; + ispVMData( g_pucOutMaskData ); + break; + case DMASK: + + /**************************************************************************** + * + * Store the maximum size of the DMASK buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usDMASKSize ) { + g_usDMASKSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Updated data type register to indicate that DMASK data is currently being + * used. Process the data in the VME file into the DMASK buffer. + * + *****************************************************************************/ + + g_usDataType |= DMASK_DATA; + ispVMData( g_pucOutDMaskData ); + break; + case CMASK: + + /**************************************************************************** + * + * Updated data type register to indicate that CMASK data is currently being + * used. Process the data in the VME file into the CMASK buffer. + * + *****************************************************************************/ + + g_usDataType |= CMASK_DATA; + ispVMData( g_pucOutMaskData ); + break; + case CONTINUE: + return ( 0 ); + default: + + /**************************************************************************** + * + * Encountered invalid opcode. + * + *****************************************************************************/ + + return ( VME_INVALID_FILE ); + } + + switch ( cDataByte ) { + case TDI: + + /**************************************************************************** + * + * Left bit shift. Used when performing algorithm looping. + * + *****************************************************************************/ + + if ( g_usFlowControl & SHIFTLEFT ) { + ispVMBitShift( SHL, g_usShiftValue ); + g_usFlowControl &= ~SHIFTLEFT; + } + + /**************************************************************************** + * + * Right bit shift. Used when performing algorithm looping. + * + *****************************************************************************/ + + if ( g_usFlowControl & SHIFTRIGHT ) { + ispVMBitShift( SHR, g_usShiftValue ); + g_usFlowControl &= ~SHIFTRIGHT; + } + default: + break; + } + + if ( siDataSource ) { + g_usDataType |= HEAP_IN; /*restore data from memory*/ + } + } + + if ( siDataSource ) { /*fetch data from heap memory upon return*/ + g_usDataType |= HEAP_IN; + } + + if ( cDataByte < 0 ) { + + /**************************************************************************** + * + * Encountered invalid opcode. + * + *****************************************************************************/ + + return ( VME_INVALID_FILE ); + } + else { + return ( 0 ); + } +} + +/*************************************************************** +* +* ispVMData +* Extract one row of data operand from the current data type opcode. Perform +* the decompression if necessary. Extra RAM is not required for the +* decompression process. The decompression scheme employed in this module +* is on row by row basis. The format of the data stream: +* [compression code][compressed data stream] +* 0x00 --No compression +* 0x01 --Compress by 0x00. +* Example: +* Original stream: 0x000000000000000000000001 +* Compressed stream: 0x01000901 +* Detail: 0x01 is the code, 0x00 is the key, +* 0x09 is the count of 0x00 bytes, +* 0x01 is the uncompressed byte. +* 0x02 --Compress by 0xFF. +* Example: +* Original stream: 0xFFFFFFFFFFFFFFFFFFFFFF01 +* Compressed stream: 0x02FF0901 +* Detail: 0x02 is the code, 0xFF is the key, +* 0x09 is the count of 0xFF bytes, +* 0x01 is the uncompressed byte. +* 0x03 +* : : +* 0xFE -- Compress by nibble blocks. +* Example: +* Original stream: 0x84210842108421084210 +* Compressed stream: 0x0584210 +* Detail: 0x05 is the code, means 5 nibbles block. +* 0x84210 is the 5 nibble blocks. +* The whole row is 80 bits given by g_usiDataSize. +* The number of times the block repeat itself +* is found by g_usiDataSize/(4*0x05) which is 4. +* 0xFF -- Compress by the most frequently happen byte. +* Example: +* Original stream: 0x04020401030904040404 +* Compressed stream: 0xFF04(0,1,0x02,0,1,0x01,1,0x03,1,0x09,0,0,0) +* or: 0xFF044090181C240 +* Detail: 0xFF is the code, 0x04 is the key. +* a bit of 0 represent the key shall be put into +* the current bit position and a bit of 1 +* represent copying the next of 8 bits of data +* in. +* +***************************************************************/ + +void ispVMData( unsigned char * ByteData ) +{ + //09/11/07 NN added local variables initialization + unsigned short size = 0; + unsigned short i, j, m, getData = 0; + unsigned char cDataByte = 0; + unsigned char compress = 0; + unsigned short FFcount = 0; + unsigned char compr_char = 0xFF; + unsigned short index = 0; + signed char compression = 0; + + /*convert number in bits to bytes*/ + if (g_usiDataSize%8>0) { + //09/11/07 NN Type cast mismatch variables + size = (unsigned short)(g_usiDataSize/8 + 1); + } + else { + //09/11/07 NN Type cast mismatch variables + size = (unsigned short)(g_usiDataSize/8); + } + + /* If there is compression, then check if compress by key of 0x00 or 0xFF + or by other keys or by nibble blocks*/ + + if ( g_usDataType & COMPRESS ) { + compression = 1; + if ( ( ( compress = GetByte() ) == VAR ) && ( g_usDataType & HEAP_IN ) ) { + getData = 1; + g_usDataType &= ~(HEAP_IN); + compress = GetByte(); + } + + switch (compress){ + case 0x00: + /* No compression */ + compression = 0; + break; + case 0x01: + /* Compress by byte 0x00 */ + compr_char = 0x00; + break; + case 0x02: + /* Compress by byte 0xFF */ + compr_char = 0xFF; + break; + case 0xFF: + /* Huffman encoding */ + compr_char = GetByte(); + i = 8; + for ( index = 0; index < size; index++ ) { + ByteData[ index ] = 0x00; + if ( i > 7 ) { + cDataByte = GetByte(); + i = 0; + } + if ((cDataByte << i++) & 0x80) + m = 8; + else { + ByteData[index] = compr_char; + m = 0; + } + + for (j = 0; j < m; j++) { + if (i > 7) { + cDataByte = GetByte(); + i = 0; + } + ByteData[index] |=((cDataByte << i++)&0x80) >> j; + } + } + size = 0; + break; + default: + for (index = 0; index < size; index++) + ByteData[index] = 0x00; + for (index = 0; index < compress; index++) { + if (index%2 == 0) + cDataByte = GetByte(); + for (i = 0; i < size*2/compress; i++){ + //09/11/07 NN Type cast mismatch variables + j = (unsigned short)(index + (i*(unsigned short)compress)); + /*clear the nibble to zero first*/ + if (j%2) { + if (index%2) + ByteData[j/2] |= cDataByte & 0x0F; + else + ByteData[j/2] |= cDataByte >> 4; + } + else { + if (index%2) + ByteData[j/2] |= cDataByte << 4; + else + ByteData[j/2] |= cDataByte & 0xF0; + } + } + } + size = 0; + break; + } + } + + FFcount = 0; + + /* Decompress by byte 0x00 or 0xFF */ + for (index = 0; index < size; index++) { + if (FFcount <= 0) { + cDataByte = GetByte(); + if ((cDataByte == VAR) && (g_usDataType&HEAP_IN) && !getData && !(g_usDataType&COMPRESS)) { + getData = 1; + g_usDataType &= ~(HEAP_IN); + cDataByte = GetByte(); + } + ByteData[index] = cDataByte; + if ((compression) &&(cDataByte == compr_char)) /*decompression is on*/ + //09/11/07 NN Type cast mismatch variables + FFcount = (unsigned short) ispVMDataSize(); /*The number of 0xFF or 0x00 bytes*/ + } + else { + FFcount--; /*Use up the 0xFF chain first*/ + ByteData[index] = compr_char; + } + } + + if (getData) { + g_usDataType |= HEAP_IN; + getData = 0; + } +} + +/*************************************************************** +* +* ispVMShift +* +* Processes the SDR/XSDR/SIR commands. +* +***************************************************************/ + +signed char ispVMShift( signed char a_cCode ) +{ + //09/11/07 NN added local variables initialization + unsigned short iDataIndex = 0; + unsigned short iReadLoop = 0; + signed char cRetCode = 0; + + cRetCode=0; + //09/11/07 NN Type cast mismatch variables + g_usiDataSize = (unsigned short) ispVMDataSize(); + + g_usDataType &= ~( SIR_DATA + EXPRESS + SDR_DATA ); /*clear the flags first*/ + switch ( a_cCode ) { + case SIR: + g_usDataType |= SIR_DATA; + /* 1/15/04 If performing cascading, then go directly to SHIFTIR. Else, + go to IRPAUSE before going to SHIFTIR */ + if ( g_usFlowControl & CASCADE ) { + ispVMStateMachine( SHIFTIR ); + } + else { + ispVMStateMachine( IRPAUSE ); + ispVMStateMachine( SHIFTIR ); + if ( g_usHeadIR > 0 ){ + ispVMBypass( HIR, g_usHeadIR ); + sclock(); + } + } + break; + case XSDR: + g_usDataType |= EXPRESS; /*mark simultaneous in and out*/ + case SDR: + g_usDataType |= SDR_DATA; + /* 1/15/04 If already in SHIFTDR, then do not move state or shift in header. + This would imply that the previously shifted frame was a cascaded frame. */ + if ( g_cCurrentJTAGState != SHIFTDR ) { + /* 1/15/04 If performing cascading, then go directly to SHIFTDR. Else, + go to DRPAUSE before going to SHIFTDR */ + if ( g_usFlowControl & CASCADE ) { + if ( g_cCurrentJTAGState == DRPAUSE ) { + ispVMStateMachine( SHIFTDR ); + /* 1/15/04 If cascade flag has been set and the current state is + DRPAUSE, this implies that the first cascaded frame is about to + be shifted in. The header must be shifted prior to shifting + the first cascaded frame. */ + if ( g_usHeadDR > 0 ) { + ispVMBypass( HDR, g_usHeadDR ); + sclock(); + } + } + else { + ispVMStateMachine( SHIFTDR ); + } + } + else { + ispVMStateMachine( DRPAUSE ); + ispVMStateMachine( SHIFTDR ); + if ( g_usHeadDR > 0 ) { + ispVMBypass( HDR, g_usHeadDR ); + sclock(); + } + } + } + break; + default: + return ( VME_INVALID_FILE ); + } + + cRetCode = ispVMDataCode(); + + if ( cRetCode != 0 ) { + return ( VME_INVALID_FILE ); + } + +#ifdef VME_DEBUG + printf( "%d ", g_usiDataSize ); + + if ( g_usDataType & TDI_DATA ) { + printf( "TDI " ); + PrintData( g_usiDataSize, g_pucInData ); + } + + if ( g_usDataType & TDO_DATA ) { + printf( "\n\t\tTDO " ); + PrintData( g_usiDataSize, g_pucOutData ); + } + + if ( g_usDataType & MASK_DATA ) { + printf( "\n\t\tMASK " ); + PrintData( g_usiDataSize, g_pucOutMaskData ); + } + + if ( g_usDataType & DMASK_DATA ) { + printf( "\n\t\tDMASK " ); + PrintData( g_usiDataSize, g_pucOutDMaskData ); + } + + printf( ";\n" ); +#endif //VME_DEBUG + + if ( g_usDataType & TDO_DATA || g_usDataType & DMASK_DATA ) { + if(g_usDataType & DMASK_DATA){ + cRetCode = ispVMReadandSave( g_usiDataSize ); + if(!cRetCode){ + if ( g_usTailDR > 0 ) { + sclock(); + ispVMBypass( TDR, g_usTailDR ); + } + ispVMStateMachine( DRPAUSE ); + ispVMStateMachine( SHIFTDR ); + if( g_usHeadDR > 0 ){ + ispVMBypass( HDR, g_usHeadDR ); + sclock(); + } + for ( iDataIndex=0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++ ) + g_pucInData[ iDataIndex ] = g_pucOutData[ iDataIndex ]; + g_usDataType &= ~( TDO_DATA+ DMASK_DATA ); + cRetCode = ispVMSend( g_usiDataSize ); + } + } + else{ + cRetCode = ispVMRead( g_usiDataSize ); + if ( cRetCode == -1 && g_cVendor == XILINX ) { + for( iReadLoop = 0; iReadLoop < 30; iReadLoop++ ){ + cRetCode = ispVMRead( g_usiDataSize ); + if( !cRetCode ) { + break; + } + else { + ispVMStateMachine( DRPAUSE ); /*Always DRPAUSE*/ + /*Bypass other devices when appropriate*/ + ispVMBypass( TDR, g_usTailDR ); + ispVMStateMachine( g_ucEndDR ); + ispVMStateMachine( IDLE ); + ispVMDelay( 1000 ); + } + } + } + } + } + else { /*TDI only*/ + cRetCode = ispVMSend( g_usiDataSize ); + } + + /*transfer the input data to the output buffer for the next verify*/ + if ( ( g_usDataType & EXPRESS ) || ( a_cCode == SDR ) ) { + if ( g_pucOutData ) { + for ( iDataIndex=0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++ ) + g_pucOutData[ iDataIndex ] = g_pucInData[ iDataIndex ]; + } + } + + switch( a_cCode ) { + case SIR: + /* 1/15/04 If not performing cascading, then shift ENDIR */ + if ( !( g_usFlowControl & CASCADE ) ) { + if ( g_usTailIR > 0 ) { + sclock(); + ispVMBypass( TIR, g_usTailIR ); + } + ispVMStateMachine( g_ucEndIR ); + } + break; + case XSDR: + case SDR: + /* 1/15/04 If not performing cascading, then shift ENDDR */ + if ( !( g_usFlowControl & CASCADE ) ) { + if ( g_usTailDR > 0 ) { + sclock(); + ispVMBypass( TDR, g_usTailDR ); + } + ispVMStateMachine( g_ucEndDR ); + } + break; + default: + break; + } + + return ( cRetCode ); +} + +/*************************************************************** +* +* ispVMAmble +* +* This routine is to extract Header and Trailer parameter for SIR and +* SDR operations. +* +* The Header and Trailer parameter are the pre-amble and post-amble bit +* stream need to be shifted into TDI or out of TDO of the devices. Mostly +* is for the purpose of bypassing the leading or trailing devices. ispVM +* supports only shifting data into TDI to bypass the devices. +* +* For a single device, the header and trailer parameters are all set to 0 +* as default by ispVM. If it is for multiple devices, the header and trailer +* value will change as specified by the VME file. +* +***************************************************************/ + +signed char ispVMAmble( signed char Code ) +{ + signed char compress = 0; + //09/11/07 NN Type cast mismatch variables + g_usiDataSize = (unsigned short)ispVMDataSize(); + +#ifdef VME_DEBUG + printf( "%d", g_usiDataSize ); +#endif //VME_DEBUG + + if ( g_usiDataSize ) { + + /**************************************************************************** + * + * Discard the TDI byte and set the compression bit in the data type register + * to false if compression is set because TDI data after HIR/HDR/TIR/TDR is not + * compressed. + * + *****************************************************************************/ + + GetByte(); + if ( g_usDataType & COMPRESS ) { + g_usDataType &= ~( COMPRESS ); + compress = 1; + } + } + + switch ( Code ) { + case HIR: + + /**************************************************************************** + * + * Store the maximum size of the HIR buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usHIRSize ) { + g_usHIRSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Assign the HIR value and allocate memory. + * + *****************************************************************************/ + + g_usHeadIR = g_usiDataSize; + if ( g_usHeadIR ) { + ispVMMemManager( HIR, g_usHeadIR ); + ispVMData( g_pucHIRData ); + +#ifdef VME_DEBUG + printf( " TDI " ); + PrintData( g_usHeadIR, g_pucHIRData ); +#endif //VME_DEBUG + } + break; + case TIR: + + /**************************************************************************** + * + * Store the maximum size of the TIR buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTIRSize ) { + g_usTIRSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Assign the TIR value and allocate memory. + * + *****************************************************************************/ + + g_usTailIR = g_usiDataSize; + if ( g_usTailIR ) { + ispVMMemManager( TIR, g_usTailIR ); + ispVMData( g_pucTIRData ); + +#ifdef VME_DEBUG + printf( " TDI " ); + PrintData( g_usTailIR, g_pucTIRData ); +#endif //VME_DEBUG + } + break; + case HDR: + + /**************************************************************************** + * + * Store the maximum size of the HDR buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usHDRSize ) { + g_usHDRSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Assign the HDR value and allocate memory. + * + *****************************************************************************/ + + g_usHeadDR = g_usiDataSize; + if ( g_usHeadDR ) { + ispVMMemManager( HDR, g_usHeadDR ); + ispVMData( g_pucHDRData ); + +#ifdef VME_DEBUG + printf( " TDI " ); + PrintData( g_usHeadDR, g_pucHDRData ); +#endif //VME_DEBUG + } + break; + case TDR: + + /**************************************************************************** + * + * Store the maximum size of the TDR buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTDRSize ) { + g_usTDRSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Assign the TDR value and allocate memory. + * + *****************************************************************************/ + + g_usTailDR = g_usiDataSize; + if ( g_usTailDR ) { + ispVMMemManager( TDR, g_usTailDR ); + ispVMData( g_pucTDRData ); + +#ifdef VME_DEBUG + printf( " TDI " ); + PrintData( g_usTailDR, g_pucTDRData ); +#endif //VME_DEBUG + } + break; + default: + break; + } + + /**************************************************************************** + * + * Re-enable compression if it was previously set. + * + *****************************************************************************/ + + if ( compress ) { + g_usDataType |= COMPRESS; + } + + if ( g_usiDataSize ) { + Code = GetByte(); + if ( Code == CONTINUE ) { + return 0; + } + else { + + /**************************************************************************** + * + * Encountered invalid opcode. + * + *****************************************************************************/ + + return VME_INVALID_FILE; + } + } + + return 0; +} + +/*************************************************************** +* +* ispVMLoop +* +* Perform the function call upon by the REPEAT opcode. +* Memory is to be allocated to store the entire loop from REPEAT to ENDLOOP. +* After the loop is stored then execution begin. The REPEATLOOP flag is set +* on the g_usFlowControl register to indicate the repeat loop is in session +* and therefore fetch opcode from the memory instead of from the file. +* +***************************************************************/ + +signed char ispVMLoop(unsigned short a_usLoopCount) +{ + //09/11/07 NN added local variables initialization + signed char cRetCode = 0; + unsigned short iHeapIndex = 0; + unsigned short iLoopIndex = 0; + + g_usShiftValue = 0; + for ( iHeapIndex = 0; iHeapIndex < g_iHEAPSize; iHeapIndex++ ) { + g_pucHeapMemory[ iHeapIndex ] = GetByte(); + } + + if ( g_pucHeapMemory[ iHeapIndex - 1 ] != ENDLOOP ) { + return( VME_INVALID_FILE ); + } + + g_usFlowControl |= REPEATLOOP; + g_usDataType |= HEAP_IN; + + for ( iLoopIndex = 0; iLoopIndex < a_usLoopCount; iLoopIndex++ ) { + g_iHeapCounter = 0; + cRetCode = ispVMCode(); + g_usRepeatLoops++; + if ( cRetCode < 0 ) { + break; + } + } + + g_usDataType &= ~( HEAP_IN ); + g_usFlowControl &= ~( REPEATLOOP ); + return ( cRetCode ); +} + +/*************************************************************** +* +* ispVMBitShift +* +* Shift the TDI stream left or right by the number of bits. The data in +* *g_pucInData is of the VME format, so the actual shifting is the reverse of +* IEEE 1532 or SVF format. +* +***************************************************************/ + +signed char ispVMBitShift(signed char mode, unsigned short bits) +{ + //09/11/07 NN added local variables initialization + unsigned short i = 0; + unsigned short size = 0; + unsigned short tmpbits = 0; + + if (g_usiDataSize%8>0) { + //09/11/07 NN Type cast mismatch variables + size = (unsigned short)(g_usiDataSize/8 + 1); + } + else { + //09/11/07 NN Type cast mismatch variables + size = (unsigned short)(g_usiDataSize/8); + } + + switch(mode) { + case SHR: + for (i = 0; i < size; i++) { + if (g_pucInData[i] != 0) { + tmpbits = bits; + while (tmpbits > 0) { + g_pucInData[i] <<= 1; + if (g_pucInData[i] == 0) { + i--; + g_pucInData[i] = 1; + } + tmpbits--; + } + } + } + break; + case SHL: + for (i = 0; i < size; i++) { + if (g_pucInData[i] != 0) { + tmpbits = bits; + while (tmpbits > 0) { + g_pucInData[i] >>= 1; + if (g_pucInData[i] == 0) { + i--; + g_pucInData[i] = 8; + } + tmpbits--; + } + } + } + break; + default: + return ( VME_INVALID_FILE ); + } + + return (0); +} + +/*************************************************************** +* +* ispVMComment +* +* Displays the SVF comments. +* +***************************************************************/ + +void ispVMComment( unsigned short a_usCommentSize ) +{ + char cCurByte = 0; + for ( ; a_usCommentSize > 0; a_usCommentSize-- ) { + /**************************************************************************** + * + * Print character to the terminal. + * + *****************************************************************************/ + cCurByte = GetByte(); + vme_out_char( cCurByte ); + } + cCurByte = '\n'; + vme_out_char(cCurByte ); +} + +/*************************************************************** +* +* ispVMHeader +* +* Iterate the length of the header and discard it. +* +***************************************************************/ + +void ispVMHeader( unsigned short a_usHeaderSize ) +{ + for ( ; a_usHeaderSize > 0; a_usHeaderSize-- ) { + GetByte(); + } +} + +/*************************************************************** +* +* ispVMCalculateCRC32 +* +* Calculate the 32-bit CRC. +* +***************************************************************/ + +void ispVMCalculateCRC32( unsigned char a_ucData ) +{ + //09/11/07 NN added local variables initialization + unsigned char ucIndex = 0; + unsigned char ucFlipData = 0; + unsigned short usCRCTableEntry = 0; + unsigned int crc_table[ 16 ] = { + 0x0000, 0xCC01, 0xD801, + 0x1400, 0xF001, 0x3C00, + 0x2800, 0xE401, 0xA001, + 0x6C00, 0x7800, 0xB401, + 0x5000, 0x9C01, 0x8801, + 0x4400 + }; + + for ( ucIndex = 0; ucIndex < 8; ucIndex++ ) { + ucFlipData <<= 1; + if ( a_ucData & 0x01 ) { + ucFlipData |= 0x01; + } + a_ucData >>= 1; + } + + //09/11/07 NN Type cast mismatch variables + usCRCTableEntry = (unsigned short)(crc_table[ g_usCalculatedCRC & 0xF ]); + g_usCalculatedCRC = (unsigned short)(( g_usCalculatedCRC >> 4 ) & 0x0FFF); + g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[ ucFlipData & 0xF ]); + usCRCTableEntry = (unsigned short)(crc_table[ g_usCalculatedCRC & 0xF ]); + g_usCalculatedCRC = (unsigned short)(( g_usCalculatedCRC >> 4 ) & 0x0FFF); + g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[ ( ucFlipData >> 4 ) & 0xF ]); +} + +/*************************************************************** +* +* ispVMLCOUNT +* +* Process the intelligent programming loops. +* +***************************************************************/ + +signed char ispVMLCOUNT( unsigned short a_usCountSize ) +{ + unsigned short usContinue = 1; + unsigned short usIntelBufferIndex = 0; + unsigned short usCountIndex = 0; + signed char cRetCode = 0; + signed char cRepeatHeap = 0; + signed char cOpcode = 0; + unsigned char ucState = 0; + unsigned short usDelay = 0; + unsigned short usToggle = 0; + unsigned char usByte = 0; + + g_usIntelBufferSize = (unsigned short)ispVMDataSize(); + + /**************************************************************************** + * + * Allocate memory for intel buffer. + * + *****************************************************************************/ + + ispVMMemManager( LHEAP, g_usIntelBufferSize ); + + /**************************************************************************** + * + * Store the maximum size of the intelligent buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usIntelBufferSize > g_usLCOUNTSize ) { + g_usLCOUNTSize = g_usIntelBufferSize; + } + + /**************************************************************************** + * + * Copy intel data to the buffer. + * + *****************************************************************************/ + + for ( usIntelBufferIndex = 0; usIntelBufferIndex < g_usIntelBufferSize; usIntelBufferIndex++ ) { + g_pucIntelBuffer[ usIntelBufferIndex ] = GetByte(); + } + + /**************************************************************************** + * + * Set the data type register to get data from the intelligent data buffer. + * + *****************************************************************************/ + + g_usDataType |= LHEAP_IN; + + /**************************************************************************** + * + * If the HEAP_IN flag is set, temporarily unset the flag so data will be + * retrieved from the status buffer. + * + *****************************************************************************/ + + if ( g_usDataType & HEAP_IN ) { + g_usDataType &= ~HEAP_IN; + cRepeatHeap = 1; + } + +#ifdef VME_DEBUG + printf( "LCOUNT %d;\n", a_usCountSize ); +#endif //VME_DEBUG + + /**************************************************************************** + * + * Iterate through the intelligent programming command. + * + *****************************************************************************/ + + for ( usCountIndex = 0; usCountIndex < a_usCountSize; usCountIndex++ ) { + + /**************************************************************************** + * + * Initialize the intel data index to 0 before each iteration. + * + *****************************************************************************/ + + g_usIntelDataIndex = 0; + cOpcode = 0; + ucState = 0; + usDelay = 0; + usToggle = 0; + usByte = 0; + usContinue = 1; + + /*************************************************************** + * + * Begin looping through all the VME opcodes. + * + ***************************************************************/ + /*************************************************************** + * 4/1/09 Nguyen replaced the recursive function call codes on + * the ispVMLCOUNT function + * + ***************************************************************/ + while ( usContinue ) + { + cOpcode = GetByte(); + switch ( cOpcode ) { + case HIR: + case TIR: + case HDR: + case TDR: + /*************************************************************** + * + * Set the header/trailer of the device in order to bypass + * successfully. + * + ***************************************************************/ + + ispVMAmble( cOpcode ); + break; + case STATE: + + /*************************************************************** + * + * Step the JTAG state machine. + * + ***************************************************************/ + + ucState = GetByte(); + /*************************************************************** + * + * Step the JTAG state machine to DRCAPTURE to support Looping. + * + ***************************************************************/ + + if ( (g_usDataType & LHEAP_IN) && + (ucState == DRPAUSE ) && + ( g_cCurrentJTAGState == ucState )) + { + ispVMStateMachine( DRCAPTURE ); + } + ispVMStateMachine( ucState ); +#ifdef VME_DEBUG + printf( "LDELAY %s ", GetState( ucState ) ); +#endif //VME_DEBUG + break; + case SIR: +#ifdef VME_DEBUG + printf( "SIR " ); +#endif //VME_DEBUG + /*************************************************************** + * + * Shift in data into the device. + * + ***************************************************************/ + + cRetCode = ispVMShift( cOpcode ); + break; + case SDR: + +#ifdef VME_DEBUG + printf( "LSDR " ); +#endif //VME_DEBUG + /*************************************************************** + * + * Shift in data into the device. + * + ***************************************************************/ + + cRetCode = ispVMShift( cOpcode ); + break; + case WAIT: + + /*************************************************************** + * + * Observe delay. + * + ***************************************************************/ + + usDelay = (unsigned short)ispVMDataSize(); + ispVMDelay( usDelay ); + +#ifdef VME_DEBUG + if ( usDelay & 0x8000 ) { + + /*************************************************************** + * + * Since MSB is set, the delay time must be decoded to + * millisecond. The SVF2VME encodes the MSB to represent + * millisecond. + * + ***************************************************************/ + + usDelay &= ~0x8000; + printf( "%.2E SEC;\n", ( float ) usDelay / 1000 ); + } + else { + + /*************************************************************** + * + * Since MSB is not set, the delay time is given as microseconds. + * + ***************************************************************/ + + printf( "%.2E SEC;\n", ( float ) usDelay / 1000000 ); + } +#endif //VME_DEBUG + break; + case TCK: + + /*************************************************************** + * + * Issue clock toggles. + * + ***************************************************************/ + + usToggle = (unsigned short)ispVMDataSize(); + ispVMClocks( usToggle ); + +#ifdef VME_DEBUG + printf( "RUNTEST %d TCK;\n", usToggle ); +#endif //VME_DEBUG + break; + case ENDLOOP: + + /*************************************************************** + * + * Exit point from processing loops. + * + ***************************************************************/ + usContinue = 0; + break; + + case COMMENT: + + /*************************************************************** + * + * Display comment. + * + ***************************************************************/ + + ispVMComment( ( unsigned short ) ispVMDataSize() ); + break; + case ispEN: + ucState = GetByte(); + if((ucState == ON)||(ucState == 0x01)) + writePort( g_ucPinENABLE, 0x01 ); + else + writePort( g_ucPinENABLE, 0x00 ); + ispVMDelay( 1 ); + break; + case TRST: + if(GetByte() == 0x01) + writePort( g_ucPinTRST, 0x01 ); + else + writePort( g_ucPinTRST, 0x00 ); + ispVMDelay( 1 ); + break; + default: + + /*************************************************************** + * + * Invalid opcode encountered. + * + ***************************************************************/ + +#ifdef VME_DEBUG + printf( "\nINVALID OPCODE: 0x%.2X\n", cOpcode ); +#endif //VME_DEBUG + + return VME_INVALID_FILE; + } + } + if ( cRetCode >= 0 ) { + /**************************************************************************** + * + * Break if intelligent programming is successful. + * + *****************************************************************************/ + + break; + } + + } + /**************************************************************************** + * + * If HEAP_IN flag was temporarily disabled, re-enable it before exiting. + * + *****************************************************************************/ + + if ( cRepeatHeap ) { + g_usDataType |= HEAP_IN; + } + + /**************************************************************************** + * + * Set the data type register to not get data from the intelligent data buffer. + * + *****************************************************************************/ + + g_usDataType &= ~LHEAP_IN; + return cRetCode; +} + +/*************************************************************** +* +* ispVMClocks +* +* Applies the specified number of pulses to TCK. +* +***************************************************************/ + +void ispVMClocks( unsigned short Clocks ) +{ + unsigned short iClockIndex = 0; + for ( iClockIndex = 0; iClockIndex < Clocks; iClockIndex++ ) { + sclock(); + } +} + +/*************************************************************** +* +* ispVMBypass +* +* This procedure takes care of the HIR, HDR, TIR, TDR for the +* purpose of putting the other devices into Bypass mode. The +* current state is checked to find out if it is at DRPAUSE or +* IRPAUSE. If it is at DRPAUSE, perform bypass register scan. +* If it is at IRPAUSE, scan into instruction registers the bypass +* instruction. +* +***************************************************************/ + +void ispVMBypass( signed char ScanType, unsigned short Bits ) +{ + //09/11/07 NN added local variables initialization + unsigned short iIndex = 0; + unsigned short iSourceIndex = 0; + unsigned char cBitState = 0; + unsigned char cCurByte = 0; + unsigned char * pcSource = NULL; + + if ( Bits <= 0 ) { + return; + } + + switch ( ScanType ) { + case HIR: + pcSource = g_pucHIRData; + break; + case TIR: + pcSource = g_pucTIRData; + break; + case HDR: + pcSource = g_pucHDRData; + break; + case TDR: + pcSource = g_pucTDRData; + break; + default: + break; + } + if(pcSource) + { + iSourceIndex = 0; + cBitState = 0; + for ( iIndex = 0; iIndex < Bits - 1; iIndex++ ) { + /* Scan instruction or bypass register */ + if ( iIndex % 8 == 0 ) { + cCurByte = pcSource[ iSourceIndex++ ]; + } + cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); + writePort( g_ucPinTDI, cBitState ); + sclock(); + } + + if ( iIndex % 8 == 0 ) { + cCurByte = pcSource[ iSourceIndex++ ]; + } + + cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); + writePort( g_ucPinTDI, cBitState ); + } +} + +/*************************************************************** +* +* ispVMStateMachine +* +* This procedure steps all devices in the daisy chain from a given +* JTAG state to the next desirable state. If the next state is TLR, +* the JTAG state machine is brute forced into TLR by driving TMS +* high and pulse TCK 6 times. +* +***************************************************************/ + +void ispVMStateMachine( signed char cNextJTAGState ) +{ + //09/11/07 NN added local variables initialization + signed char cPathIndex = 0; + signed char cStateIndex = 0; + short int found = 0; + + if ( ( g_cCurrentJTAGState == cNextJTAGState ) && ( cNextJTAGState != RESET ) ) { + return; + } + + for ( cStateIndex = 0; cStateIndex < 25; cStateIndex++ ) { + if ( ( g_cCurrentJTAGState == g_JTAGTransistions[ cStateIndex ].CurState ) && ( cNextJTAGState == g_JTAGTransistions[cStateIndex].NextState ) ) { + found = 1; + break; + } + } + if(found) + { + g_cCurrentJTAGState = cNextJTAGState; + for ( cPathIndex = 0; cPathIndex < g_JTAGTransistions[ cStateIndex ].Pulses; cPathIndex++ ) { + if ( ( g_JTAGTransistions[ cStateIndex ].Pattern << cPathIndex ) & 0x80 ) { + writePort( g_ucPinTMS, ( unsigned char ) 0x01 ); + } + else { + writePort( g_ucPinTMS, ( unsigned char ) 0x00 ); + } + sclock(); + } + + writePort( g_ucPinTDI, 0x00 ); + writePort( g_ucPinTMS, 0x00 ); + } +} + +/*************************************************************** +* +* ispVMStart +* +* Enable the port to the device and set the state to RESET (TLR). +* +***************************************************************/ + +void ispVMStart() +{ +#ifdef VME_DEBUG + printf( "// ISPVM EMBEDDED ADDED\n" ); + printf( "STATE RESET;\n" ); +#endif + + ispVMStateMachine( RESET ); /*step devices to RESET state*/ +} + +/*************************************************************** +* +* ispVMEnd +* +* Set the state of devices to RESET to enable the devices and disable +* the port. +* +***************************************************************/ + +void ispVMEnd() +{ +#ifdef VME_DEBUG + printf( "// ISPVM EMBEDDED ADDED\n" ); + printf( "STATE RESET;\n" ); + printf( "RUNTEST 1.00E-001 SEC;\n" ); +#endif + + ispVMStateMachine( RESET ); /*step devices to RESET state */ + ispVMDelay( 1000 ); /*wake up devices*/ +} + +/*************************************************************** +* +* ispVMSend +* +* Send the TDI data stream to devices. The data stream can be +* instructions or data. +* +***************************************************************/ + +signed char ispVMSend( unsigned short a_usiDataSize ) +{ + //09/11/07 NN added local variables initialization + unsigned short iIndex = 0; + unsigned short iInDataIndex = 0; + unsigned char cCurByte = 0; + unsigned char cBitState = 0; + + for ( iIndex = 0; iIndex < a_usiDataSize - 1; iIndex++ ) { + if ( iIndex % 8 == 0 ) { + cCurByte = g_pucInData[ iInDataIndex++ ]; + } + cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); + writePort( g_ucPinTDI, cBitState ); + sclock(); + } + + if ( iIndex % 8 == 0 ) { + /* Take care of the last bit */ + cCurByte = g_pucInData[ iInDataIndex ]; + } + + cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); + + writePort( g_ucPinTDI, cBitState ); + if ( g_usFlowControl & CASCADE ) { + /* 1/15/04 Clock in last bit for the first n-1 cascaded frames */ + sclock(); + } + + return 0; +} + +/*************************************************************** +* +* ispVMRead +* +* Read the data stream from devices and verify. +* +***************************************************************/ + +signed char ispVMRead( unsigned short a_usiDataSize ) +{ + //09/11/07 NN added local variables initialization + unsigned short usDataSizeIndex = 0; + unsigned short usErrorCount = 0; + unsigned short usLastBitIndex = 0; + unsigned char cDataByte = 0; + unsigned char cMaskByte = 0; + unsigned char cInDataByte = 0; + unsigned char cCurBit = 0; + unsigned char cByteIndex = 0; + unsigned short usBufferIndex = 0; + unsigned char ucDisplayByte = 0x00; + unsigned char ucDisplayFlag = 0x01; + char StrChecksum[256] = {0}; + unsigned char g_usCalculateChecksum = 0x00; + + //09/11/07 NN Type cast mismatch variables + usLastBitIndex = (unsigned short)(a_usiDataSize - 1); + +#ifndef VME_DEBUG + /**************************************************************************** + * + * If mask is not all zeros, then set the display flag to 0x00, otherwise + * it shall be set to 0x01 to indicate that data read from the device shall + * be displayed. If VME_DEBUG is defined, always display data. + * + *****************************************************************************/ + + for ( usDataSizeIndex = 0; usDataSizeIndex < ( a_usiDataSize + 7 ) / 8; usDataSizeIndex++ ) { + if ( g_usDataType & MASK_DATA ) { + if ( g_pucOutMaskData[ usDataSizeIndex ] != 0x00 ) { + ucDisplayFlag = 0x00; + break; + } + } + else if ( g_usDataType & CMASK_DATA ) { + g_usCalculateChecksum = 0x01; + ucDisplayFlag = 0x00; + break; + } + else { + ucDisplayFlag = 0x00; + break; + } + } +#endif //VME_DEBUG + + /**************************************************************************** + * + * Begin shifting data in and out of the device. + * + *****************************************************************************/ + + for ( usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++ ) { + if ( cByteIndex == 0 ) { + + /*************************************************************** + * + * Grab byte from TDO buffer. + * + ***************************************************************/ + + if ( g_usDataType & TDO_DATA ) { + cDataByte = g_pucOutData[ usBufferIndex ]; + } + + /*************************************************************** + * + * Grab byte from MASK buffer. + * + ***************************************************************/ + + if ( g_usDataType & MASK_DATA ) { + cMaskByte = g_pucOutMaskData[ usBufferIndex ]; + } + else { + cMaskByte = 0xFF; + } + + /*************************************************************** + * + * Grab byte from CMASK buffer. + * + ***************************************************************/ + + if ( g_usDataType & CMASK_DATA ) { + cMaskByte = 0x00; + g_usCalculateChecksum = 0x01; + } + + /*************************************************************** + * + * Grab byte from TDI buffer. + * + ***************************************************************/ + + if ( g_usDataType & TDI_DATA ) { + cInDataByte = g_pucInData[ usBufferIndex ]; + } + + usBufferIndex++; + } + + cCurBit = readPort(); + + if ( ucDisplayFlag ) { + ucDisplayByte <<= 1; + ucDisplayByte |= cCurBit; + } + + /**************************************************************************** + * + * Check if data read from port matches with expected TDO. + * + *****************************************************************************/ + + if ( g_usDataType & TDO_DATA ) { + //08/28/08 NN Added Calculate checksum support. + if( g_usCalculateChecksum ) + { + if(cCurBit == 0x01) + g_usChecksum += (1 << (g_uiChecksumIndex % 8)); + g_uiChecksumIndex++; + } + else + { + if ( ( ( ( cMaskByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { + if ( cCurBit != ( unsigned char ) ( ( ( cDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { + usErrorCount++; + } + } + } + } + + /**************************************************************************** + * + * Write TDI data to the port. + * + *****************************************************************************/ + + writePort( g_ucPinTDI, ( unsigned char ) ( ( ( cInDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ); + + if ( usDataSizeIndex < usLastBitIndex ) { + + /**************************************************************************** + * + * Clock data out from the data shift register. + * + *****************************************************************************/ + + sclock(); + } + else if ( g_usFlowControl & CASCADE ) { + + /**************************************************************************** + * + * Clock in last bit for the first N - 1 cascaded frames. + * + *****************************************************************************/ + + sclock(); + } + + /*************************************************************** + * + * Increment the byte index. If it exceeds 7, then reset it back + * to zero. + * + ***************************************************************/ + + cByteIndex++; + if ( cByteIndex >= 8 ) { + if ( ucDisplayFlag ) { + + /*************************************************************** + * + * Store displayed data in the TDO buffer. By reusing the TDO + * buffer to store displayed data, there is no need to allocate + * a buffer simply to hold display data. This will not cause any + * false verification errors because the true TDO byte has already + * been consumed. + * + ***************************************************************/ + + g_pucOutData[ usBufferIndex - 1 ] = ucDisplayByte; + ucDisplayByte = 0; + } + + cByteIndex = 0; + } + //09/12/07 Nguyen changed to display the 1 bit expected data + else if(a_usiDataSize == 1) + { + if ( ucDisplayFlag ) { + + /*************************************************************** + * + * Store displayed data in the TDO buffer. By reusing the TDO + * buffer to store displayed data, there is no need to allocate + * a buffer simply to hold display data. This will not cause any + * false verification errors because the true TDO byte has already + * been consumed. + * + ***************************************************************/ + + /**************************************************************************** + * + * Flip ucDisplayByte and store it in cDataByte. + * + *****************************************************************************/ + cDataByte = 0x00; + for ( usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++ ) { + cDataByte <<= 1; + if ( ucDisplayByte & 0x01 ) { + cDataByte |= 0x01; + } + ucDisplayByte >>= 1; + } + g_pucOutData[ 0 ] = cDataByte; + ucDisplayByte = 0; + } + + cByteIndex = 0; + } + } + if ( ucDisplayFlag ) { + + /**************************************************************************** + * + * Display data read from the device. + * + *****************************************************************************/ + +#ifdef VME_DEBUG + printf( "RECIEVED TDO (" ); +#else + vme_out_string( "Display Data: 0x" ); +#endif //VME_DEBUG + + //09/11/07 NN Type cast mismatch variables + for ( usDataSizeIndex = (unsigned short)( ( a_usiDataSize + 7 ) / 8 ); usDataSizeIndex > 0 ; usDataSizeIndex-- ) { + cMaskByte = g_pucOutData[ usDataSizeIndex - 1 ]; + cDataByte = 0x00; + + /**************************************************************************** + * + * Flip cMaskByte and store it in cDataByte. + * + *****************************************************************************/ + + for ( usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++ ) { + cDataByte <<= 1; + if ( cMaskByte & 0x01 ) { + cDataByte |= 0x01; + } + cMaskByte >>= 1; + } +#ifdef VME_DEBUG + printf( "%.2X", cDataByte ); + if ( ( ( ( a_usiDataSize + 7 ) / 8 ) - usDataSizeIndex ) % 40 == 39 ) { + printf( "\n\t\t" ); + } +#else + vme_out_hex( cDataByte ); +#endif //VME_DEBUG + } + +#ifdef VME_DEBUG + printf( ")\n\n" ); +#else + vme_out_string( "\n\n" ); +#endif //VME_DEBUG + //09/02/08 Nguyen changed to display the data Checksum + if(g_usChecksum != 0) + { + g_usChecksum &= 0xFFFF; + sprintf(StrChecksum,"Data Checksum: %.4X\n\n",g_usChecksum); + vme_out_string(StrChecksum); + g_usChecksum = 0; + } + } + + if ( usErrorCount > 0 ) { + if ( g_usFlowControl & VERIFYUES ) { + vme_out_string( "USERCODE verification failed. Continue programming......\n\n" ); + g_usFlowControl &= ~( VERIFYUES ); + return 0; + } + else { + +#ifdef VME_DEBUG + printf( "TOTAL ERRORS: %d\n", usErrorCount ); +#endif //VME_DEBUG + + return VME_VERIFICATION_FAILURE; + } + } + else { + if ( g_usFlowControl & VERIFYUES ) { + vme_out_string( "USERCODE verification passed. Programming aborted. \n\n" ); + g_usFlowControl &= ~( VERIFYUES ); + return 1; + } + else { + return 0; + } + } +} + +/*************************************************************** +* +* ispVMReadandSave +* +* Support dynamic I/O. +* +***************************************************************/ + +signed char ispVMReadandSave( unsigned short int a_usiDataSize ) +{ + //09/11/07 NN added local variables initialization + unsigned short int usDataSizeIndex = 0; + unsigned short int usLastBitIndex = 0; + unsigned short int usBufferIndex = 0; + unsigned short int usOutBitIndex = 0; + unsigned short int usLVDSIndex = 0; + unsigned char cDataByte = 0; + unsigned char cDMASKByte = 0; + unsigned char cInDataByte = 0; + unsigned char cCurBit = 0; + unsigned char cByteIndex = 0; + signed char cLVDSByteIndex = 0; + + //09/11/07 NN Type cast mismatch variables + usLastBitIndex = (unsigned short) (a_usiDataSize - 1); + + /*************************************************************** + * + * Iterate through the data bits. + * + ***************************************************************/ + + for ( usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++ ) { + if ( cByteIndex == 0 ) { + + /*************************************************************** + * + * Grab byte from DMASK buffer. + * + ***************************************************************/ + + if ( g_usDataType & DMASK_DATA ) { + cDMASKByte = g_pucOutDMaskData[ usBufferIndex ]; + } + else { + cDMASKByte = 0x00; + } + + /*************************************************************** + * + * Grab byte from TDI buffer. + * + ***************************************************************/ + + if ( g_usDataType & TDI_DATA ) { + cInDataByte = g_pucInData[ usBufferIndex ]; + } + + usBufferIndex++; + } + + cCurBit = readPort(); + cDataByte = ( unsigned char ) ( ( ( cInDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ); + + /*************************************************************** + * + * Initialize the byte to be zero. + * + ***************************************************************/ + + if ( usOutBitIndex % 8 == 0 ) { + g_pucOutData[ usOutBitIndex / 8 ] = 0x00; + } + + /*************************************************************** + * + * Use TDI, DMASK, and device TDO to create new TDI (actually + * stored in g_pucOutData). + * + ***************************************************************/ + + if ( ( ( ( cDMASKByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { + + if ( g_pLVDSList ) { + for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { + if ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex == usDataSizeIndex ) { + g_pLVDSList[ usLVDSIndex ].ucUpdate = 0x01; + break; + } + } + } + + /*************************************************************** + * + * DMASK bit is 1, use TDI. + * + ***************************************************************/ + + g_pucOutData[ usOutBitIndex / 8 ] |= ( unsigned char ) ( ( ( cDataByte & 0x1 ) ? 0x01 : 0x00 ) << ( 7 - usOutBitIndex % 8 ) ); + } + else { + + /*************************************************************** + * + * DMASK bit is 0, use device TDO. + * + ***************************************************************/ + + g_pucOutData[ usOutBitIndex / 8 ] |= ( unsigned char ) ( ( ( cCurBit & 0x1 ) ? 0x01 : 0x00 ) << ( 7 - usOutBitIndex % 8 ) ); + } + + /*************************************************************** + * + * Shift in TDI in order to get TDO out. + * + ***************************************************************/ + + usOutBitIndex++; + writePort( g_ucPinTDI, cDataByte ); + if ( usDataSizeIndex < usLastBitIndex ) { + sclock(); + } + + /*************************************************************** + * + * Increment the byte index. If it exceeds 7, then reset it back + * to zero. + * + ***************************************************************/ + + cByteIndex++; + if ( cByteIndex >= 8 ) { + cByteIndex = 0; + } + } + + /*************************************************************** + * + * If g_pLVDSList exists and pairs need updating, then update + * the negative-pair to receive the flipped positive-pair value. + * + ***************************************************************/ + + if ( g_pLVDSList ) { + for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { + if ( g_pLVDSList[ usLVDSIndex ].ucUpdate ) { + + /*************************************************************** + * + * Read the positive value and flip it. + * + ***************************************************************/ + + cDataByte = ( unsigned char ) ( ( ( g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usPositiveIndex / 8 ] << ( g_pLVDSList[ usLVDSIndex ].usPositiveIndex % 8 ) ) & 0x80 ) ? 0x01 : 0x00 ); + //09/11/07 NN Type cast mismatch variables + cDataByte = ( unsigned char ) (!cDataByte); + + /*************************************************************** + * + * Get the byte that needs modification. + * + ***************************************************************/ + + cInDataByte = g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ]; + + if ( cDataByte ) { + + /*************************************************************** + * + * Copy over the current byte and set the negative bit to 1. + * + ***************************************************************/ + + cDataByte = 0x00; + for ( cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex-- ) { + cDataByte <<= 1; + if ( 7 - ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex % 8 ) == cLVDSByteIndex ) { + + /*************************************************************** + * + * Set negative bit to 1. + * + ***************************************************************/ + + cDataByte |= 0x01; + } + else if ( cInDataByte & 0x80 ) { + cDataByte |= 0x01; + } + + cInDataByte <<= 1; + } + + /*************************************************************** + * + * Store the modified byte. + * + ***************************************************************/ + + g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ] = cDataByte; + } + else { + + /*************************************************************** + * + * Copy over the current byte and set the negative bit to 0. + * + ***************************************************************/ + + cDataByte = 0x00; + for ( cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex-- ) { + cDataByte <<= 1; + if ( 7 - ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex % 8 ) == cLVDSByteIndex ) { + + /*************************************************************** + * + * Set negative bit to 0. + * + ***************************************************************/ + + cDataByte |= 0x00; + } + else if ( cInDataByte & 0x80 ) { + cDataByte |= 0x01; + } + + cInDataByte <<= 1; + } + + /*************************************************************** + * + * Store the modified byte. + * + ***************************************************************/ + + g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ] = cDataByte; + } + + break; + } + } + } + + return( 0 ); +} + +signed char ispVMProcessLVDS( unsigned short a_usLVDSCount ) +{ + unsigned short usLVDSIndex = 0; + + /*************************************************************** + * + * Allocate memory to hold LVDS pairs. + * + ***************************************************************/ + + ispVMMemManager( LVDS, a_usLVDSCount ); + g_usLVDSPairCount = a_usLVDSCount; + +#ifdef VME_DEBUG + printf( "LVDS %d (", a_usLVDSCount ); +#endif //VME_DEBUG + + /*************************************************************** + * + * Iterate through each given LVDS pair. + * + ***************************************************************/ + + for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { + + /*************************************************************** + * + * Assign the positive and negative indices of the LVDS pair. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + g_pLVDSList[ usLVDSIndex ].usPositiveIndex = (unsigned short) ispVMDataSize(); + //09/11/07 NN Type cast mismatch variables + g_pLVDSList[ usLVDSIndex ].usNegativeIndex = (unsigned short)ispVMDataSize(); + +#ifdef VME_DEBUG + if ( usLVDSIndex < g_usLVDSPairCount - 1 ) { + printf( "%d:%d, ", g_pLVDSList[ usLVDSIndex ].usPositiveIndex, g_pLVDSList[ usLVDSIndex ].usNegativeIndex ); + } + else { + printf( "%d:%d", g_pLVDSList[ usLVDSIndex ].usPositiveIndex, g_pLVDSList[ usLVDSIndex ].usNegativeIndex ); + } +#endif //VME_DEBUG + + } + +#ifdef VME_DEBUG + printf( ");\n", a_usLVDSCount ); +#endif //VME_DEBUG + + return( 0 ); +} diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/vmopcode.h b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/vmopcode.h new file mode 100644 index 000000000000..d72364a47cee --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/vmopcode.h @@ -0,0 +1,191 @@ +/*************************************************************** +* +* This is the include file for Lattice Semiconductor's ispVM +* Embedded software application. +* +***************************************************************/ + +/*************************************************************** +* +* VME version. +* +* History: +* +***************************************************************/ +#define VME_VERSION_NUMBER "12.2" + +/*************************************************************** +* +* Maximum declarations. +* +***************************************************************/ + +#define VMEHEXMAX 60000L /* The hex file is split 60K per file. */ +#define SCANMAX 64000L /* The maximum SDR/SIR burst. */ + +/*************************************************************** +* +* Supported JTAG state transitions. +* +***************************************************************/ + +#define RESET 0x00 +#define IDLE 0x01 +#define IRPAUSE 0x02 +#define DRPAUSE 0x03 +#define SHIFTIR 0x04 +#define SHIFTDR 0x05 +#define DRCAPTURE 0x06 + +/*************************************************************** +* +* Flow control register bit definitions. A set bit indicates +* that the register currently exhibits the corresponding mode. +* +***************************************************************/ + +#define INTEL_PRGM 0x0001 /* Intelligent programming is in effect. */ +#define CASCADE 0x0002 /* Currently splitting large SDR. */ +#define REPEATLOOP 0x0008 /* Currently executing a repeat loop. */ +#define SHIFTRIGHT 0x0080 /* The next data stream needs a right shift. */ +#define SHIFTLEFT 0x0100 /* The next data stream needs a left shift. */ +#define VERIFYUES 0x0200 /* Continue if fail is in effect. */ + +/*************************************************************** +* +* DataType register bit definitions. A set bit indicates +* that the register currently holds the corresponding type of data. +* +***************************************************************/ + +#define EXPRESS 0x0001 /* Simultaneous program and verify. */ +#define SIR_DATA 0x0002 /* SIR is the active SVF command. */ +#define SDR_DATA 0x0004 /* SDR is the active SVF command. */ +#define COMPRESS 0x0008 /* Data is compressed. */ +#define TDI_DATA 0x0010 /* TDI data is present. */ +#define TDO_DATA 0x0020 /* TDO data is present. */ +#define MASK_DATA 0x0040 /* MASK data is present. */ +#define HEAP_IN 0x0080 /* Data is from the heap. */ +#define LHEAP_IN 0x0200 /* Data is from intel data buffer. */ +#define VARIABLE 0x0400 /* Data is from a declared variable. */ +#define CRC_DATA 0x0800 /* CRC data is pressent. */ +#define CMASK_DATA 0x1000 /* CMASK data is pressent. */ +#define RMASK_DATA 0x2000 /* RMASK data is pressent. */ +#define READ_DATA 0x4000 /* READ data is pressent. */ +#define DMASK_DATA 0x8000 /* DMASK data is pressent. */ + +/*************************************************************** +* +* Pin opcodes. +* +***************************************************************/ + +#define signalENABLE 0x1C /* ispENABLE pin. */ +#define signalTMS 0x1D /* TMS pin. */ +#define signalTCK 0x1E /* TCK pin. */ +#define signalTDI 0x1F /* TDI pin. */ +#define signalTRST 0x20 /* TRST pin. */ + +/*************************************************************** +* +* Supported vendors. +* +***************************************************************/ + +#define VENDOR 0x56 +#define LATTICE 0x01 +#define ALTERA 0x02 +#define XILINX 0x03 + +/*************************************************************** +* +* Opcode definitions. +* +* Note: opcodes must be unique. +* +***************************************************************/ + +#define ENDDATA 0x00 /* The end of the current SDR data stream. */ +#define RUNTEST 0x01 /* The duration to stay at the stable state. */ +#define ENDDR 0x02 /* The stable state after SDR. */ +#define ENDIR 0x03 /* The stable state after SIR. */ +#define ENDSTATE 0x04 /* The stable state after RUNTEST. */ +#define TRST 0x05 /* Assert the TRST pin. */ +#define HIR 0x06 /* The sum of the IR bits of the leading devices. */ +#define TIR 0x07 /* The sum of the IR bits of the trailing devices. */ +#define HDR 0x08 /* The number of leading devices. */ +#define TDR 0x09 /* The number of trailing devices. */ +#define ispEN 0x0A /* Assert the ispEN pin. */ +#define FREQUENCY 0x0B /* The maximum clock rate to run the JTAG state machine. */ +#define STATE 0x10 /* Move to the next stable state. */ +#define SIR 0x11 /* The instruction stream follows. */ +#define SDR 0x12 /* The data stream follows. */ +#define TDI 0x13 /* The following data stream feeds into the device. */ +#define TDO 0x14 /* The following data stream is compared against the device. */ +#define MASK 0x15 /* The following data stream is used as mask. */ +#define XSDR 0x16 /* The following data stream is for simultaneous program and verify. */ +#define XTDI 0x17 /* The following data stream is for shift in only. It must be stored for the next XSDR. */ +#define XTDO 0x18 /* There is not data stream. The data stream was stored from the previous XTDI. */ +#define MEM 0x19 /* The maximum memory needed to allocate in order hold one row of data. */ +#define WAIT 0x1A /* The duration of delay to observe. */ +#define TCK 0x1B /* The number of TCK pulses. */ +#define SHR 0x23 /* Set the flow control register for right shift. */ +#define SHL 0x24 /* Set the flow control register for left shift. */ +#define HEAP 0x32 /* The memory size needed to hold one loop. */ +#define REPEAT 0x33 /* The beginning of the loop. */ +#define LEFTPAREN 0x35 /* The beginning of data following the loop. */ +#define VAR 0x55 /* Plac holder for loop data. */ +#define SEC 0x1C /* The delay time in seconds that must be observed. */ +#define SMASK 0x1D /* The mask for TDI data. */ +#define MAX 0x1E /* The absolute maximum wait time. */ +#define ON 0x1F /* Assert the targeted pin. */ +#define OFF 0x20 /* Dis-assert the targeted pin. */ +#define SETFLOW 0x30 /* Change the flow control register. */ +#define RESETFLOW 0x31 /* Clear the flow control register. */ +#define CRC 0x47 /* The following data stream is used for CRC calculation. */ +#define CMASK 0x48 /* The following data stream is used as mask for CRC calculation. */ +#define RMASK 0x49 /* The following data stream is used as mask for read and save. */ +#define READ 0x50 /* The following data stream is used for read and save. */ +#define ENDLOOP 0x59 /* The end of the repeat loop. */ +#define SECUREHEAP 0x60 /* Used to secure the HEAP opcode. */ +#define VUES 0x61 /* Support continue if fail. */ +#define DMASK 0x62 /* The following data stream is used for dynamic I/O. */ +#define COMMENT 0x63 /* Support SVF comments in the VME file. */ +#define HEADER 0x64 /* Support header in VME file. */ +#define FILE_CRC 0x65 /* Support crc-protected VME file. */ +#define LCOUNT 0x66 /* Support intelligent programming. */ +#define LDELAY 0x67 /* Support intelligent programming. */ +#define LSDR 0x68 /* Support intelligent programming. */ +#define LHEAP 0x69 /* Memory needed to hold intelligent data buffer */ +#define CONTINUE 0x70 /* Allow continuation. */ +#define LVDS 0x71 /* Support LVDS. */ +#define ENDVME 0x7F /* End of the VME file. */ +#define HIGH 0x80 /* Assert the targeted pin. */ +#define LOW 0x81 /* Dis-assert the targeted pin. */ +#define ENDFILE 0xFF /* End of file. */ + +/*************************************************************** +* +* ispVM Embedded Return Codes. +* +***************************************************************/ + +#define VME_VERIFICATION_FAILURE -1 +#define VME_FILE_READ_FAILURE -2 +#define VME_VERSION_FAILURE -3 +#define VME_INVALID_FILE -4 +#define VME_ARGUMENT_FAILURE -5 +#define VME_CRC_FAILURE -6 + +/*************************************************************** +* +* Type definitions. +* +***************************************************************/ + +/* Support LVDS */ +typedef struct { + unsigned short usPositiveIndex; + unsigned short usNegativeIndex; + unsigned char ucUpdate; +} LVDSPair; From 4045360b628f7e582b967fc3c16c1f7d2be1c483 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Mon, 21 Jan 2019 15:00:22 +0700 Subject: [PATCH 2/4] [platform/cel] Add ispvm tool license. --- .../tools/ispvme_12.2/license.txt | 355 ++++++++++++++++++ 1 file changed, 355 insertions(+) create mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/license.txt diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/license.txt b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/license.txt new file mode 100644 index 000000000000..8f1eac2d2a13 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/license.txt @@ -0,0 +1,355 @@ +License Agreement +This is a legal agreement between you, the end user, and Lattice Semiconductor Corporation if you are an end user located in the United States or Lattice SG Pte. Ltd. if you are an end user located in a country other than the United States. By proceeding with the installation or use of the Software: (1) You acknowledge you have read this Agreement, you understand it, and you agree to be bound by the terms and conditions of this Agreement; and (2) You represent that you are not an employee, agent of or otherwise affiliated with the following companies: Cadence Design Systems, Inc. or Mentor Graphics Corporation. If you do not agree to the terms and conditions of this Agreement, do not use, download, or install the Software, and if you have already obtained the Software from an authorized source, promptly return the media package and all accompanying items (including written materials and binders or other containers) to the place you obtained them for a full refund of any applicable license fees. +Lattice Semiconductor Corporation or Lattice SG Pte. Ltd. ("Lattice") and the individual or entity acquiring the Software ("Licensee") agree as follows: +1. DEFINITIONS +"Software" means the computer program(s) in machine-readable form furnished to Licensee by Lattice, in whatever media and by whatever method, which are enabled for use pursuant to Lattice's software protection mechanism, and for which Licensee has paid any applicable license fees. Software includes any related update or upgrade programs that may be added from time to time. +2. SOFTWARE LICENSE +a. Lattice hereby grants to Licensee a non-exclusive, nontransferable license to use the Software for Licensee's internal purposes only on any computer possessed by Licensee on which the Software is designed to operate, such use to be in accordance with and subject to the terms and conditions of this Agreement. +b. Pursuant to this Agreement, Licensee may (i) physically transfer any Software from one computer to another provided that the Software is used on only one such computer at a time and (ii) use the Software and any output files generated by the Software for the sole purpose of designing and programming semiconductor components manufactured by or for Lattice and sold by Lattice or its authorized distributors ("Lattice Devices") and (iii) make one (1) copy of the Software for Licensee's own use solely for backup or archive purposes. Licensee may also merge the Software (or a portion thereof) into any other software to form an updated work; provided that, upon termination of Licensee's license, the Software shall be completely removed from the updated work and treated as if permission to merge had never been granted. The use of any portion of the Software included in any such updated work remains at all times subject to the terms and conditions of this Agreement. +c. Lattice DiamondTM Programmer and ispVMTM Software License Terms. Notwithstanding Section 2b of this Agreement, Lattice grants to Licensee the right to use and distribute, as part of Licensee's systems, the Lattice Diamond Programmer Software and the ispVM Software (“the Programmer Software”), in compiled version, for the sole purpose of programming and reprogramming silicon devices supported by the Programmer Software. Notwithstanding the foregoing, any output files generated by the Software may only be used to program Lattice Devices. All intellectual property notices of Lattice and its partners included in the master copy of the Programmer Software shall be included in and upon any media or documentation distributed with any system that includes the Programmer Software. Provided that the above conditions are met, Licensee may make multiple copies of the Programmer Software for use on multiple computers. The Lattice Diamond Programmer Embedded Software (and ispVM Embedded Software) is subject to the terms and conditions of the license that appears below in the Lattice Diamond Programmer Embedded and ispVM Embedded Software License Terms section. +d. The Software can be used to create Modules. For purposes of this Agreement, a 'Module' is one or more files that can be directly incorporated into a design being targeted to Lattice Devices and represents specific functions performed by Lattice Devices. Modules are provided in source code form and can be created through tools, including Lattice's Module/IP Manager software tool. Lattice hereby grants to Licensee a non-exclusive, nontransferable license to: (i) modify Modules for the sole purpose of designing and programming Lattice Devices; (ii) incorporate the Modules into Lattice Devices; and (iii) distribute the Modules in machine executable form only for use with Lattice Devices. For purposes of clarity, Software as used throughout this Agreement includes Modules. +e. Licensee shall include Lattice's (and Lattice's suppliers', as applicable) copyrights, trademarks, and other proprietary notices on any copies and merged versions of the Software. +f. Licensee shall not distribute, copy, transfer, lend, incorporate, modify, or use the Software for any purpose except as expressly provided herein. +g. If Licensee fails to comply with the provisions of this Agreement, this license is automatically terminated. +h. Except for the rights expressly granted herein to Licensee, the title and all intellectual property rights in and to the Software and any copy of the Software which may be made by Licensee hereunder remain the sole and exclusive property of Lattice and/or Lattice's licensors. +i. Licensee acknowledges that obtaining a license for the Software does not entitle Licensee to technical support from Lattice regarding the Software. However, Lattice will use commercially reasonable efforts to respond to technical support inquiries from Licensee regarding the Software. Response times to inquiries for technical support are not guaranteed and will be established by Lattice in its sole discretion. +j. If Licensee is using the encryption software used in areas such as programming Lattice Devices, the licensor is Lattice Semiconductor Corporation. +3. LIMITED WARRANTY AND REMEDIES +a. If the Software has been provided on tangible media, then Lattice warrants to Licensee that the media containing the Software will be free from defects in materials and workmanship under normal use and service for a period of ninety (90) days from the date of delivery. +b. Subject to applicable laws, during the 90-day warranty period, the entire liability of Lattice and its licensors to Licensee, and Licensee's exclusive remedy under this warranty after Licensee's return of the defective Software media, will be for Lattice, at its option, either to replace any such Software media or refund any applicable license fee paid by Licensee to Lattice and terminate this License Agreement. Any replacement Software or media will be warranted for the remainder of the original warranty period or thirty (30) days, whichever is longer. +c. Any products which are not returned to Lattice within the warranty period or which have been subject to accident, abuse, misuse, alteration, neglect, or unauthorized repair or installation are not covered by warranty. +4. WARRANTY DISCLAIMER +EXCEPT FOR THE ABOVE EXPRESSED LIMITED WARRANTIES, LATTICE MAKES NO WARRANTIES ON THE SOFTWARE, WHETHER EXPRESSED, IMPLIED, STATUTORY, OR IN ANY OTHER PROVISION OF THIS AGREEMENT OR COMMUNICATION WITH LICENSEE, AND LATTICE SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. LATTICE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE SOFTWARE WILL MEET LICENSEE'S REQUIREMENTS, OR THAT LICENSEE'S OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS IN THE SOFTWARE WILL BE CORRECTED. LICENSEE ASSUMES RESPONSIBILITY FOR SELECTION OF THE SOFTWARE TO ACHIEVE ITS INTENDED RESULTS, AND FOR THE PROPER INSTALLATION, USE, AND RESULTS OBTAINED FROM THE SOFTWARE. EXCEPT FOR THE ABOVE EXPRESSED LIMITED WARRANTIES, LICENSEE ASSUMES THE ENTIRE RISK OF THE SOFTWARE PROVING DEFECTIVE OR FAILING TO PERFORM PROPERLY AND IN SUCH EVENT, LICENSEE SHALL ASSUME THE ENTIRE COST AND RISK OF ANY REPAIR, SERVICE, CORRECTION, OR ANY OTHER LIABILITIES OR DAMAGES CAUSED BY OR ASSOCIATED WITH THE SOFTWARE. LATTICE'S SOLE LIABILITY, AND LICENSEE'S SOLE REMEDY, IS SET FORTH ABOVE. LATTICE DOES NOT WARRANT THAT USE OF THE SOFTWARE DOES NOT INFRINGE ON THIRD PARTIES' INTELLECTUAL PROPERTY RIGHTS. +5. SOURCE CODE +Licensee shall not attempt to reverse translate, decompile or otherwise attempt to derive the source code of the Software. In the event any source code is explicitly licensed to Licensee as part of the Software, such limitation will not apply to such source code. Licensee shall not alter or remove from the Software any copyright, trademark or other proprietary notices of Lattice and/or Lattice's licensors. Any use or attempted use of the Software in violation of the foregoing restrictions is a breach of the Agreement which will cause irreparable harm to Lattice, entitling Lattice to injunctive relief in addition to all legal remedies. +6. LIMITATION OF LIABILITY +a. Licensee agrees that Lattice's entire liability to Licensee and Licensee's sole remedy hereunder for any cause whatsoever, regardless of the form of the action, shall be limited to the price paid to Lattice for the Software. +b. IN NO EVENT WILL LATTICE OR ANY OF ITS SUPPLIERS BE LIABLE TO LICENSEE OR ANY OTHER PERSON FOR ANY DAMAGES, INCLUDING ANY DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, OR SPECIAL DAMAGES, INCLUDING EXPENSES, LOST PROFITS, LOST SAVINGS, OR OTHER DAMAGES OF ANY SORT ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF LATTICE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OR EXCLUSION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE ABOVE LIMITATIONS OR EXCLUSIONS MAY NOT APPLY TO YOU. +7. DEFAULT AND TERMINATION +Lattice licenses Software for either a fixed subscription period or for an indefinite term. Aldec tools licenses are for a fixed period not to exceed one year. If Licensee has a subscription license to use the Software, then Lattice issues Licensee an activation key that enables Licensee to run the Software for a period of either six months or one year. If Licensee has a subscription license, then Licensee's right to use the Software and this Agreement will terminate at the end of the subscription period. Otherwise, this Agreement will continue indefinitely, until and unless terminated. If Licensee purchased an initial subscription license, then, upon Licensee's payment of any applicable fees for renewal of the subscription, Licensee shall have the right to continue to run the Software for an additional fixed period of time. The terms and conditions for Licensee's use of the Software pursuant to a renewal of a subscription license will be the same as set forth in this Agreement. This Agreement will terminate automatically in the event Licensee fails to perform any of its obligations hereunder. Licensee may terminate this Agreement at any time by returning to Lattice the original and all copies of the Software or by destroying the Software together with all copies thereof, including all modifications and merged portions in any form. Upon termination of this Agreement for any reason, Licensee shall either return to Lattice the original and all copies of the Software, or, upon Lattice's request, destroy such original and copies and provide Lattice with written certification of their destruction. The obligations of Lattice and Licensee under the provisions of Sections 2.h, 4, 5, 6, 7, 8, 9, 10, 11, and 12 will survive any termination of this Agreement. +8. EXPORT CONTROL +Licensee shall not export the Software or the direct product thereof without first obtaining any necessary U.S. or other governmental licenses and approvals. In connection with such export control compliance, Licensee certifies as follows: +* that Licensee is not on the Denied Persons List maintained by the U.S. Bureau of Industry and Security; +* that Licensee is not on the list of Specially Designated Nationals and Blocked Persons maintained by the U.S. Department of the Treasury; +* that Licensee is not a citizen or resident of, or an agent of, Cuba, Iran, Iraq, North Korea, Sudan, or Syria, or any other country to which export of the referenced Software is prohibited; and +* that Licensee is legally permitted, under all applicable export and commerce control laws and regulations, to receive the referenced Software. +9. U.S. GOVERNMENT RESTRICTED RIGHTS +The Software and any accompanying documentation provided to agencies of the U.S. Government are "commercial computer software" and "commercial computer software documentation" pursuant to DFARS 227.7202 and FAR 12.212, and their successors. All use, reproduction, release, performance, display or disclosure of the Software and related documentation by or for the U.S. Government shall be in strict accordance with the terms and conditions of this Agreement. Contractor/manufacturer is Lattice Semiconductor Limited c/o Lattice Semiconductor Corporation, 111 SW 5th Ave., Portland, Oregon 97204 and its licensors. +10. ADDITIONAL TERMS AND CONDITIONS APPLICABLE TO LATTICE PROGRAMMING HARDWARE. +Lattice programmers, ispDOWNLOADTM cables, and other hardware sold for use in conjunction with Lattice software ("Programming Hardware") are designed and intended for use solely with semiconductor components manufactured by Lattice Semiconductor Limited. Programming Hardware is warranted to meet Lattice Specifications only for a period of ninety (90) days; in all other respects the terms and conditions of sale of Programming Hardware shall be Lattice's standard terms and conditions set forth in Lattice's Sales Order Acknowledgement. Furthermore, Lattice Specifications for the ispDOWNLOAD cable limit its use to low-volume engineering applications only, and not for volume production use. As with all other Programming Hardware, Lattice shall not be liable for any use of the ispDOWNLOAD cable in production, or use of worn or improperly installed hardware or use with incompatible systems or components. +11. INFORMATION REGARDING PERSONAL DATA. + If you downloaded this Software from our website, we have collected information about you, including your name and contact information, from the information you provided when you registered to use the website. If you acquired the Software from a source other than our website, we will ask you for certain information, including your name and contact information, as part of the installation procedure. Some of our Software comes bundled with software from third party providers, including Aldec, Inc. and Synopsys, Inc. If you obtain a license key from us for such Software, we will provide your name, corporate affiliation, address, phone number, fax number, and email address, along with information about the software version you have chosen, to the appropriate third party provider. +12. GENERAL. +IF LICENSEE IS LOCATED IN THE UNITED STATES, THIS AGREEMENT WILL BE GOVERNED BY THE LAWS OF THE STATE OF OREGON, U.S.A. WITHOUT REFERENCE TO ANY CONFLICT OF LAW PRINCIPLES. IF LICENSEE IS LOCATED IN A COUNTRY OTHER THAN THE UNITED STATES, THIS AGREEMENT WILL BE GOVERNED BY THE LAWS OF THE REPUBLIC OF SINGAPORE WITHOUT REFERENCE TO ANY CONFLICT OF LAW PRINCIPLES. THE APPLICATION OF THE UNITED NATIONS CONVENTION ON CONTRACTS FOR THE INTERNATIONAL SALE OF GOODS IS EXPRESSLY EXCLUDED. NOTHING IN THIS AGREEMENT WILL BE INTERPRETED OR CONSTRUED SO AS TO LIMIT OR EXCLUDE THE RIGHTS OR OBLIGATIONS OF LICENSEE OR LATTICE WHICH IT IS UNLAWFUL TO LIMIT OR EXCLUDE UNDER APPLICABLE LAWS, INCLUDING THE LAWS OF ANY MEMBER STATE OF THE EUROPEAN UNION WHICH IMPLEMENTS RELEVANT EUROPEAN COMMUNITIES COUNCIL DIRECTIVES. Except as specifically provided in this Agreement, Licensee may not sublicense, assign, or transfer this license or the Software. Any attempted assignment, transfer or sublicense by Licensee in violation of this provision shall be void. Subject to the foregoing, this Agreement shall be binding upon and inure to the benefit of the successors and permitted assigns of the parties. The prevailing party in any legal action or arbitration arising out of this Agreement shall be entitled to reimbursement for reasonable attorneys fees and expenses, in addition to any other rights and remedies such party may have. This Agreement is the entire agreement between the parties with respect to use of the Software and supersedes any other communications or prior agreements, oral or written, regarding the Software. If any provision of this Agreement is held invalid, the remainder of the Agreement shall continue in full force and effect. +Please direct all inquiries, in writing, to Lattice Semiconductor Corporation, +111 SW 5th Ave, Portland, Oregon 97204. +Copyright (c) 2017 Lattice Semiconductor Corporation. All rights reserved. +Intellectual Property Notice +The Software governed by this License Agreement is: +Copyright (c), 1992-2017, Lattice Semiconductor Corporation, All Rights Reserved +Portions Copyright (c) 1993-1998, Data I/O Corporation +Portions Copyright (c) 1997-1998, MINC Washington Corporation +Portions Copyright (c) Alan Phillips, Lancaster University Computer Centre 1992-1998 +Portions Copyright (c) 1991-1994 NeoCAD, Inc. +Portions Copyright (c) 1995 AT&T Corporation +Portions Copyright (c) 1995-2001 Lucent Technologies, Inc. +Portions Copyright (c) 2001 Agere Systems, Inc. +Portions Copyright (c) 1996-2006 Macrovision Corporation and/or Macrovision Europe Ltd. +Portions Copyright (c) 1998-2008 Verific Design Automation, Inc. +Portions Copyright (c) ALDEC, Inc. +Portions Copyright (c) 1994-2012 Synopsys, Inc. +Portions Copyright (c) 1994-2008 Sun Microsystems, Inc. +Portions Copyright (c) 1996-2013 Digia USA Inc. +Microsoft Corporation is a third party beneficiary of certain provisions of the License Agreement. +Portions Copyright 1998-2002 by Neil Hodgson + +LATTICE DIAMOND PROGRAMMER EMBEDDED AND ispVM EMBEDDED SOFTWARE LICENSE TERMS +The Lattice Diamond Programmer Embedded Software (and ispVM Embedded Software) is subject to the following licensing terms: +Copyright (c) 2017, Lattice Semiconductor Corporation. All rights reserved. +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +* Neither the name of Lattice Semiconductor Corporation, its affiliates, or the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +TCL/TK LICENSE TERMS +The Tcl/Tk software is copyrighted by the Regents of the University of California, Sun Microsystems, Inc., Scriptics Corporation, and other parties. The following terms apply to all files associated with the Tcl/Tk software unless explicitly disclaimed in individual files. The authors hereby grant permission to use, copy, modify, distribute, and license the Tcl/Tk software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to the Tcl/Tk software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. +IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. +GOVERNMENT USE: If you are acquiring this software on behalf of the U.S. government, the Government shall have only "Restricted Rights" in the software and related documentation as defined in the Federal Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are acquiring the software on behalf of the Department of Defense, the software shall be classified as "Commercial Computer Software" and the Government shall have only "Restricted Rights" as defined in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the authors grant the U.S. Government and others acting in its behalf permission to use and distribute the software in accordance with the terms specified in this license. +LICENSE FOR SCINTILLA AND SCITE +Copyright 1998-2002 by Neil Hodgson +All Rights Reserved +Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. +NEIL HODGSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NEIL HODGSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +Lattice Patent Rights +This Software is made available for use under a license from Lattice to all applicable U.S. and foreign patents, subject to the conditions and restrictions provided by this License Agreement. Applicable patents include the following U.S. patents: +5,526,278 7,681,160 7,743,296 7,768,300 7,788,620 7,890,913 +6,813,754 6,848,095 7,000,210 7,032,203 7,788,623 7,895,555 +7,509,598 7,536,615 7,557,606 7,570,078 7,831,856 7,992,120 +8,060,784 8,069,431 8,086,986 8,104,009 8,108,754 8,11,2731 +8,181,139 8,286,116 8,555,217 8,856,718 9,152,753 9,125,756 +Lattice does not represent that products described herein are free from patent infringement or from any third-party right. +Trademark Rights +This Software may contain registered trademarks of third parties. Such trademarks are the property of their respective owners. +Synplify and Synplify Pro are distributed pursuant to the terms and conditions of the Synopsys End-User Software License and Maintenance Agreement set forth below. +2017.03.27  +SYNOPSYS +END-USER SOFTWARE LICENSE AND MAINTENANCE AGREEMENT +This agreement covers the products and services you license (or purchase) from Synopsys, unless and until we enter into a new agreement that expressly replaces this one. If you use the Synopsys products and services as an employee of or for the benefit of your company, you represent that you have the power and authority to accept this agreement on behalf of your company. Your company will be the licensee under this agreement. By clicking on the "Accept” button of this agreement, or by downloading, installing or using the Synopsys products or services, you consent to the terms and conditions of this agreement on behalf of yourself and the company on whose behalf you will use the Synopsys products and services provided under this agreement. The effective date of this agreement is the date that you first download, install or use the Synopsys products or services. If you do not agree to the terms and conditions of this agreement or if you do not have the power and authority to accept the terms and conditions of this agreement on behalf of your company, you may not use the Synopsys products and services and Synopsys is unwilling to provide you with them. +1. Products and Services +1.1. The Synopsys products and services that you may license or purchase under this agreement are identified in the Purchasing Agreements that you and Synopsys enter into from time to time under this agreement. These products and services may include (but are not limited to): +(a) DesignWare, which means any software products (including Implementation IP and Verification IP), other than DesignWare Fee-Per-Use Cores, marketed by Synopsys under the brand name "DesignWare". +(b) Licensed Software, which means a Synopsys software product other than DesignWare and DesignWare Fee-Per-Use Cores. +(c) Maintenance Services, which means the software maintenance and support services described in section 5. +(d) Training Services, which means education in the use of Synopsys software products through standard curriculum educational services courses. +1.2. The term "Licensed Products" means Licensed Software and DesignWare. +1.3. Additional terms and conditions (beyond those stated here and in any attached supplements) may apply to certain Licensed Products. When ordering these Licensed Products, you will be given an opportunity to review the additional terms and conditions that must be accepted for you to receive the Licensed Products. If the additional terms and conditions conflict in any way with the terms and conditions stated here, the additional terms and conditions will prevail. +2. Licenses +2.1. Your License Rights: When you purchase a license (other than an evaluation license) to a Licensed Product, upon its delivery you will have a nonexclusive right to: +(a) install the Licensed Product on one or more computers; +(b) install the License Key for the Licensed Product on the computer specifically identified in the License Key; +(c) allow your End Users to use the Licensed Product and Design Techniques, during the License Term, solely for the purpose of creating, modifying, and simulating your own Designs (in the case of DesignWare, this includes validating, testing, and simulating Designs, electronic circuits and devices); +(d) in the case of DesignWare, share Design Databases with a Licensed Design Partner only to allow the Licensed Design Partner to work cooperatively on your Design to the extent permitted by its own DesignWare license (but not sublicense or assign any of your rights in the DesignWare to such Licensed Design Partner); +(e) in the case of ARC Software Development Products, use this Licensed Product, during the License Term, solely for the purpose of creating, debugging, and profiling executable software source code for execution on a System-on-Chip with an embedded ARC microprocessor or on a model of such System-on-Chip; +(f) in the case of ARC MQX Products, until you discontinue the sale and distribution of the applicable ARC MQX Licensee Products, use the ARC MQX Products to (i) customize the Board Support Package Features in the ARC MQX Product solely as necessary for use with your ARC MQX Licensee Product; (ii) create and support an ARC MQX Licensee Executable; (iii) if you have purchased a license to the "closed system license” version of an ARC MQX Product, then you may distribute, solely in an ARC MQX Licensee Product and only to ARC MQX End Customers, an ARC MQX Licensee Executable that does not expose, directly or indirectly, any APIs of the ARC MQX Product; and (iv) if you have purchased a license to the "binary” version of an ARC MQX Product, then you may additionally distribute to ARC MQX End Customers only that portion of the Documentation necessary for ARC MQX End Customers to access the APIs; provided that neither (ii) nor (iii) above shall entitle ARC MQX End Customers to expose any of the APIs to their customers or any other third parties. +(g) make a reasonable number of copies of the Licensed Product solely for backup or archival purposes; and +(h) make a reasonable number of copies of the Documentation for the Licensed Product, and use the Documentation solely to support your use of the Licensed Product. +2.2. Implementation IP License: In addition, when you are granted a license to any Implementation IP, you will have a nonexclusive right to: +(a) integrate the Implementation IP into your Designs to create one or more Integrated Designs; +(b) make, use, and sell physical implementations (commonly referred to as semiconductor chips) of one or more of the Integrated Designs; +(c) distribute the Implementation IP in netlist or GDSII format as part of any of your Integrated Designs to any third party that provides foundry services to you, solely for the purpose of having that foundry make physical implementations of one or more of entire Integrated Designs of yours, as long as the third-party foundry is subject to confidentiality obligations regarding the Implementation IP that are no less restrictive than the confidentiality obligations in this agreement; and +(d) if you purchased from Synopsys the right to use certain Implementation IP in source code format, you may modify that Implementation IP in support of your development of Integrated Designs. +2.3. Node-Locked License. If you have obtained the Licensed Product under a node-locked license, then a "node” refers to a specific machine and the License Product may be installed only on the number of nodes indicated on the applicable Synopsys Purchasing Agreement, must be used only on the node(s) on which it is installed, and may be accessed only by users who are physically present at that node. Further, a node-locked license may only be used by one (1) user at a time running one (1) instance of the Licensed Product at a time. +2.4. Evaluation Licenses: If you obtain an evaluation license for a Licensed Product, you will have the same license rights as described above except that you may use the Licensed Product only for the purpose of evaluating it and deciding whether to purchase a license to use it for production purposes. You shall not use the Licensed Product to design any integrated circuits for production or pre-production purposes or any other commercial use including, but not limited to, for the benefit of your customers. If you breach the forgoing restrictions, then you shall pay to Synopsys a license fee equal to Synopsys’s perpetual list price plus maintenance for the commercial version of the Licensed Product. You agree that damages for such a breach would be difficult to assess, and such payment represents a reasonable assessment of the potential damage to Synopsys. You recognized and agree that this amount is a reasonable, liquidated amount and not a penalty. Also, evaluation copies of Licensed Products are provided "AS IS”. Therefore the warranty and indemnification provisions in this agreement do not apply to evaluation licenses. +2.5. End Users: You may designate any of your employees whose primary work location is in the designated Use Area as End Users. +2.6. Use Area; Telecommuting Employees; Use Over a WAN: You must ensure that your End Users use the Licensed Product only when they are in the designated Use Area, except that any End User who is your employee, whose primary work location is in the designated Use Area, and whose primary residence is within 50 miles of the designated Use Area, may access the Licensed Product from his primary residence through a secure network that requires a secure ID card or other more protective security safeguards. If you have purchased the right to use a Licensed Product over your wide area network (commonly referred to as a "WAN”), then unless the Purchasing Agreement states otherwise, the Licensed Product may be used by your End Users who are located at any of your facilities worldwide (if you purchased the right to use over a global WAN) or at any of your facilities on the same continent on which your Key Server is located (if you purchased the right to use over a continental WAN). This section 2.6 does not apply to Licensed Products obtained under a node-locked license as referenced in section 2.3. +2.7. Key Servers; Hardware Relocation: You may not permanently relocate a Key Server outside of the designated Use Area without obtaining written approval from Synopsys. If a Key Server becomes inoperative due to malfunction, repair, or maintenance, you may request Synopsys’s permission to set up and temporarily use a single back-up Key Server on another computer in the same Use Area until the original Key Server returns to service. +2.8. Conditions: Your right to use the Licensed Product is conditioned upon your timely payment of the full amount of Fees due for the Licensed Product and your compliance with the terms of this agreement, including the following restrictions. When the License Term expires, your license rights also expire and you may no longer use the Licensed Product. +2.9. Restrictions: You may not (and may not allow anyone else to): +(a) copy or use any Licensed Product (or Documentation) in any manner that is not expressly allowed by the license rights stated above; +(b) decompile, reverse engineer, or otherwise attempt to derive the source code for any Licensed Product or any underlying algorithms, user interface techniques, or other ideas embodied in a Licensed Product; +(c) tamper with, or attempt to circumvent or disable, any License Key (this includes, for example, resetting the CPU time in order to extend the License Term, or using a false host ID number or additional virtualized copy(ies) of the host ID number to enable unauthorized copies of a License Key); +(d) distribute any copy of a Licensed Product (or Documentation) except as expressly allowed by the license rights stated above, or allow anyone other than your End Users to have access to or use (such as in a timesharing, service bureau, or application service provider model) any Licensed Product; +(e) use a Licensed Product (except ARC MQX Products) or its output to create, modify, or simulate Designs for third parties; +(f) use a Licensed Product or its output to develop or enhance any product that competes with a Synopsys product; +(g) modify or create a derivative work of any part of a Licensed Product or Documentation; +(h) disclose the results of any benchmarking of a Licensed Product (whether or not the results were obtained with assistance from Synopsys) to any third party; or +(i) use a Licensed Product in the development of any product if the failure or malfunction of that product could reasonably be expected to result in personal injury, death, or catastrophic loss. +If the License Key limits the number of End Users who may use a Licensed Product simultaneously or the number of simultaneous Clients, you must ensure that this limit is not exceeded, by platform virtualization or any other means. +2.10. Copies: If you make backup or archival copies of a Licensed Product or Documentation, you must reproduce all copyright, trademark, and other notices that appear on the original copy. +2.11. Transfers and Assignments: You may not transfer or assign your license rights to any other person in any manner (by assignment, operation of law or otherwise) unless you have obtained written consent from Synopsys. If you attempt to transfer or assign any of your license rights without Synopsys's consent, the transfer or assignment will be ineffective, null, and void (and you will be in material breach of this agreement). For purposes of this section 2.11, a transfer or assignment of your license rights will be deemed to have occurred (a) if a third party (or group of third parties acting in concert) acquires beneficial ownership of fifty percent (50%) or more of either (i) your or a Parent Entity's assets or (ii) the stock or other equity interests entitled to vote for your or a Parent Entity's directors or equivalent managing authority, or (b) in the event of a merger, consolidation or other business combination between you or a Parent Entity and one or more third parties where your or a Parent Entity's stockholders immediately before that transaction own (directly or indirectly), after that transaction, less than fifty percent (50%) of the stock or other equity interests entitled to vote for the directors or equivalent managing authority of the surviving entity. +2.12. Open Source Software: The Licensed Product may be delivered with software that is subject to open source licensing terms ("Open Source Software”) which are available at http://www.synopsys.com/. If the Open Source Software license also requires source code to be made available, Licensee may reference http://www.synopsys.com/ for information on how to obtain such source code. Licensee agrees that all Open Source Software shall be and shall remain subject to the terms and conditions under which it is provided. The Open Source Software is provided "AS IS,” WITHOUT ANY WARRANTY OF ANY KIND, AND SYNOPSYS FURTHER DISCLAIMS ALL OTHER WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, WITH RESPECT TO OPEN SOURCE SOFTWARE, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. NEITHER SYNOPSYS NOR THE LICENSORS OF OPEN SOURCE SOFTWARE SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE OPEN SOURCE SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Copyrights to the Open Source Software are held by the copyright holders indicated in the copyright notices in the corresponding source files. +3. Order and Delivery +3.1. Ordering Synopsys Products: You may order the products and services identified in the Purchasing Agreements at any time by submitting an order to Synopsys through Synopsys's on-line ordering system or as otherwise directed by Synopsys. When using Synopsys's on-line ordering system, you shall be responsible for ensuring that all information you provide is accurate and complete and that any person placing an order on your behalf has your authority to do so. Once you submit an order, you may not cancel or change it. Your order must indicate which products and services you want to purchase (including, in the case of Licensed Products, the type of license, the quantity, the License Term or in the case of ARC MQX Products the applicable ARC MQX Licensee Product, the location(s) of your facility(ies) where the Licensed Products may be used (we may refer to this as the "Authorized Sites” in a Purchasing Agreement), and any other information Synopsys would need to fulfill your order (including any information needed to generate a License Key). Synopsys may, in its reasonable discretion, accept or reject your order. Synopsys may accept your order by sending you written or electronic notice of acceptance or simply by fulfilling your order. +3.2. Delivery: If Synopsys accepts your order for one or more Licensed Products, Synopsys will then deliver to you the Licensed Products along with the corresponding Documentation and License Keys. Synopsys will deliver these materials to you electronically except where prohibited by law. +3.3. EST: When Synopsys delivers a Licensed Product by EST, Synopsys will send you an e-mail to your designated EST e-mail address(es) to notify you that the Licensed Product is available. Synopsys's obligation to deliver the Licensed Product will be fulfilled when this e-mail notice is sent. You will be responsible for downloading or requesting for delivery the Licensed Product and Documentation from the FTP Server and the License Key from Synopsys's website at www.synopsys.com, unless Synopsys gives you other instructions. You must notify Synopsys in writing if you change your EST e-mail address(es). +3.4. Tangible Media: When Synopsys delivers Licensed Products to you on tangible media, the media may contain other software programs in addition to the Licensed Products. If it does, you will not have a license to use (and the License Keys for the Licensed Products will not permit you to use) these other software programs, and you must not attempt to access, use, reproduce, modify, reverse engineer, or otherwise tamper with these other software programs. If you lose or damage the media, Synopsys will, at your request, provide a replacement at a nominal charge. All deliveries of tangible items by Synopsys, Inc. will be made F.O.B. Origin; all deliveries of tangible items by other Synopsys entities will be made Ex Works (EXW) Origin. +4. Fees and Payment +4.1. Fees: The Fees for the products and services you may purchase under this agreement will be identified in the Purchasing Agreements. You agree to pay the Fees according to the payment terms in the applicable Purchasing Agreement. +4.2. Payments: If the applicable Purchasing Agreement does not contain specific payment terms for the Fees in question, payment of those Fees will be due within 30 days after the date of Synopsys's invoice. If you do not pay an amount by the scheduled due date, Synopsys will have the right to withhold the delivery of License Keys and/or terminate this agreement or a Purchasing Agreement and accelerate the due date of all remaining payments. In this event, you will owe the entire outstanding balance as soon as you receive written notice from Synopsys that your payment is due. All payments you make to Synopsys are non-refundable. You may not offset any amounts you believe Synopsys owes you against any payments you make to Synopsys under this agreement. You must make payments in U.S. dollars. If you do not pay an amount by the due date, you must also pay a late payment charge of 1.5% per month or the highest rate permitted by law, whichever is less. +4.3. Taxes: You will be solely responsible for paying all taxes (including sales, use, consumption, withholding, and value-added taxes and similar taxes), other than Synopsys's income taxes, that are imposed on or result from your purchase, license, or use of Synopsys products and services. If Synopsys is required by law to collect and remit any such taxes, Synopsys may invoice you for such taxes and you agree to pay the invoiced amount to Synopsys. If you are required by the respective jurisdiction where the Licensed Products are used, or where services are provided, to withhold taxes from payments to Synopsys, you may withhold from the total amount due to the respective Synopsys distributing entity the minimum amount required (but no more). You may only withhold taxes related to a payment at the time of such payment. You must then promptly pay that amount to the appropriate tax authority and provide Synopsys with an official receipt for the payment within 60 days of your payment. +4.4. Bankruptcy: If you become the subject of any bankruptcy, dissolution, liquidation, or similar proceedings or make a general assignment for the benefit of your creditors, Synopsys may apply any payments you have previously made to Synopsys for products or services not yet delivered by Synopsys against any amounts you owe Synopsys at that time for products or services that have been delivered by Synopsys (under this agreement or otherwise). +5. Services +5.1. Maintenance Services: Maintenance Services consist of the following: +(a) Support: Synopsys will provide you with access to SolvNet and online Documentation, and will use commercially reasonable efforts to make available the Synopsys Support Center on Monday through Friday, during Synopsys's normal business hours, excluding Synopsys's scheduled holidays. A valid corporate email address is required to access SolvNet and online Documentation. +(b) Software Updates: Synopsys will use commercially reasonable efforts to provide error corrections to the Licensed Products, as well as minor improvements to the Licensed Products, as such corrections and improvements become generally available. Any other upgrades or enhancements to the Licensed Products are not made available by Synopsys as part of Maintenance Services and may be subject to additional charges. +5.2. Updates to Terms: Synopsys may update its Maintenance Services terms on 60 days prior written notice, provided that these updates are applied generally to its Maintenance Service customers. +5.3. Conditions: In order to receive Maintenance Services for a Licensed Product, all of the following conditions must be met: +(a) you must have purchased Maintenance Services for such Licensed Product (unless it is licensed under a TSL, in which case Maintenance Services are included); +(b) you must appoint a qualified contact person to interface with Synopsys regarding Maintenance Services, and identify such person to Synopsys in advance; +(c) such qualified contact person must be trained in the use of such Licensed Product; +(d) you must provide Synopsys with access to the information and system facilities reasonably necessary to provide the Maintenance Services; +(e) you must follow the directions provided by the Synopsys Support Center to resolve technical problems; +(f) you must follow the operating instructions and procedures for the Licensed Product as specified in the Documentation or provided by Synopsys; and +(g) you must notify Synopsys of any error or other problem in the Licensed Product using Synopsys's current problem reporting procedure. +5.4. Exclusions: Synopsys will have no obligation to provide Maintenance Services for any Licensed Products that are damaged, modified (by anyone other than Synopsys), incorporated into other software, or installed in any computing environment not supported by Synopsys; or for any version of a Licensed Product other than the latest and immediately preceding version; or for any problems caused by your negligence, abuse, misuse, or by any causes beyond Synopsys's reasonable control. +5.5. Reinstatement of Maintenance Services: If Maintenance Services are terminated for any reason, or if you wish to renew Maintenance Services more than thirty (30) days after Maintenance Services have been terminated, you may be permitted to reinstate or renew Maintenance Services, at Synopsys's sole option, provided that (a) Synopsys offers Maintenance Services to its customers generally for the Licensed Product in question, and (b) you pay Synopsys the following: all applicable Maintenance Services fees for the period during which you were off Maintenance Services, and Synopsys's then-current reinstatement fee plus payment for the new Maintenance Services term. +5.6. ViewConnect: If you wish to permit Synopsys to deliver Maintenance Services through the use of a shared customer desktop, you must download and install the ViewConnect Tool and related publicly-available, third-party software modules. You are not required to use the ViewConnect Tool, but if you choose to do so, you have the nonexclusive right to use the ViewConnect Tool only to enable Synopsys to remotely access your computer system for the purpose of providing Maintenance Services. Your rights to the third-party software modules are separately described in their accompanying license terms. Neither section 8 nor section 9 of this agreement applies to the ViewConnect Tool or to the third-party software modules. +5.7. Disclaimer Regarding ViewConnect: The ViewConnect Tool is licensed "as is,” and Synopsys makes no warranties, express, implied, statutory, or otherwise, regarding the ViewConnect Tool. Synopsys disclaims all liability of any kind in connection with such third-party software modules, and specifically disclaims any implied warranties of noninfringement, title, merchantability, or fitness for a particular purpose, or arising from a course of dealing or usage of trade both with respect to the ViewConnect Tool and the third-party software modules. +5.8 Training Services: Synopsys offers Training Services, which may be purchased and ordered through the online registration system found at www.synopsys.com. +6. Confidentiality +6.1. Confidentiality Obligations: Each party (you and Synopsys) agrees to abide by the following confidentiality obligations with respect to the other party's Confidential Information: +(a) do not disclose it to any third party unless (i) the other party has given its specific and express prior written approval, (ii) the disclosure is expressly allowed under this agreement, or (iii) the disclosure is necessary to comply with a valid court order or subpoena; +(b) do not use it for any reason other than to exercise its rights and perform its obligation under this agreement; and +(c) protect it from unauthorized dissemination in the same manner as that party protects its own Confidential Information, and in any event with reasonable precautions (which include limiting access to employees and contractors on a "need-to-know” basis). +6.2. Mandatory Disclosures: If you believe you must disclose Synopsys's Confidential Information in order to comply with a valid court order or subpoena, you must promptly notify Synopsys and cooperate with Synopsys if Synopsys chooses to contest the disclosure requirement, seek confidential treatment of the information to be disclosed, or to limit the nature or scope of the information to be disclosed. Synopsys will do the same if it believes it must disclose your Confidential Information in these circumstances. +6.3. Additional Obligations: In addition to your general obligations of confidentiality regarding the Licensed Products and Documentation, you must take the following steps to help prevent any unauthorized access to or use of the same: +(a) you must ensure that each End User who is your independent contractor (not your employee) has access to and uses the Licensed Products and Documentation only while working on your physical premises; and +(b) you must monitor each End User's use of the Licensed Products to ensure that the End User abides by the terms of this agreement. +7. Term and Termination +7.1. Term of Agreement: The term of this agreement will begin on the effective date stated on the signature page and will end when the last Purchasing Agreement expires, unless this agreement is terminated sooner by either party. +7.2. Term of Purchasing Agreement: Each Purchasing Agreement will have its own term, as indicated on that Purchasing Agreement. +7.3. Rights to Terminate: Each party has the right to terminate this agreement, by giving written notice of termination to the other party, if (a) the other party breaches this agreement and (b) either the breach cannot be cured or, if the breach can be cured, it is not cured by the breaching party within 15 days after receiving written notice of the breach from the non-breaching party. A substantial deviation of a Licensed Product from the specifications in the corresponding Documentation will not be considered a breach of this agreement that allows you to terminate the agreement, but it could give rise to a warranty claim under section 8. +7.4. Consequences of Termination: If and when either you or Synopsys terminates this agreement, all Purchasing Agreements in effect at that time will also terminate. When this agreement, a Purchasing Agreement or an individual license to a Licensed Product expires or is terminated: +(a) you must (i) immediately cease all use of the Licensed Products, Documentation, and Design Techniques, (ii) promptly return to Synopsys or destroy all copies of the Licensed Products and Documentation in your possession or control, and (iii) certify in writing to Synopsys that you have complied with clauses (i) and (ii), except, however, that your license to Implementation IP incorporated into Designs prior to termination shall continue according to its terms; +(b) you will remain obligated to pay any amounts you owe to Synopsys at that time; and +(c) the provisions of sections 4, 6, 7.4, 8.4 and 10, and the warranty disclaimers in section 8, will remain in effect. +8. Limited Warranty +8.1. Warranty: For a period of 90 days from when Synopsys delivers a Licensed Product to you (the "warranty period”), Synopsys warrants that the Licensed Product will have no Errors when used on the correct platform and according to the instructions in the corresponding Documentation. This warranty will be void if you, or anyone else other than Synopsys, modifies or attempts to modify the Licensed Product. +8.2. Warranty Claims: To claim a breach of this warranty, you must, during the warranty period, notify Synopsys in writing of the Error or Errors that you have encountered and provide Synopsys with all the information you have, in written or electronic form, about those Errors, so that Synopsys can attempt to reproduce, diagnose, and correct the Errors. +8.3. Exclusive Remedy: Your exclusive remedy for any breach of this warranty is that Synopsys will use commercially reasonable efforts to (at Synopsys's option) correct the Errors you have reported or provide a replacement product that does not contain these Errors, or if Synopsys is unable to provide a correction or a replacement or determines that it will not be feasible to do so, Synopsys will refund the Fees you paid for that Licensed Product. +8.4. Disclaimer: This is the only warranty Synopsys provides for the Licensed Products. Except for this warranty, all Licensed Products, Documentation, and Design Techniques are provided "AS IS”. Synopsys disclaims all other warranties (express, implied, or statutory), including any warranties of merchantability, fitness for a particular purpose, title, or non-infringement and any warranties arising from a course of dealing or usage of trade. +9. Infringement Claims +9.1. Indemnity: Synopsys will, at its own expense, be entitled to defend (or at its sole option, settle) any claim asserted against you by a third party that any Licensed Product you obtained from Synopsys under this agreement directly infringes any U.S. patent, copyright, trademark, or trade secret. Synopsys will indemnify you for any damages you suffer and costs you reasonably incur that are directly attributable to any such claim and that are assessed against you in a final, non-appealable judgment or agreed upon by Synopsys in a settlement. +9.2. Conditions: Synopsys's obligations to defend and indemnify you with respect to a particular claim are subject to the following conditions: +(a) you must promptly give Synopsys written notice of the claim; +(b) you must identify the specific Licensed Product(s) at issue in the claim and indicate how the Licensed Product(s) is(are) utilized by you or your products; +(c) you must give Synopsys sole control and authority over the defense and settlement of the claim; and +(d) you must provide Synopsys with all information you have regarding the claim and cooperate with Synopsys when Synopsys defends or attempts to settle the claim. +9.3. Pro-Active Steps: If any Licensed Product is, or Synopsys believes is likely to become, the subject of a claim for which Synopsys would be obligated to defend and indemnify you, then Synopsys may, at its option, do any of the following: +(a) obtain for you (at no cost to you) the right for you to continue using the Licensed Product as permitted by this agreement; +(b) replace or modify the Licensed Product to avoid the infringement problem, as long as there is no material loss of functionality; or +(c) if Synopsys reasonably concludes that it will not be feasible to do either of the above, terminate your license for the Licensed Product and give you a prorated refund (based on how much of the License Term has elapsed) of the Fees you paid for that license. +9.4. Exclusions: Synopsys will have no obligation to defend or indemnify you (notwithstanding the first paragraph of this section) with respect to any claim that is based on or attributable to any of the following: +(a) any modification made to the Licensed Product by anyone other than Synopsys; +(b) the combination or use of the Licensed Product with other products, processes, or materials not supplied by Synopsys or specified in the Documentation as being necessary to use the Licensed Product; +(c) your continued engagement in infringing activities after you were notified of the infringement or after Synopsys informed you of a modification or workaround that would have avoided the infringement; and +(d) your use of the Licensed Product in a manner not permitted by this agreement. +9.5. Burden of Proof: You will have the burden of showing that indemnification is required pursuant to this section 9 and that the exclusions in section 9.4 are not applicable. +9.6. No Other Obligations: Except as expressly stated in this section 9, Synopsys has no obligation or liability to you for any actual or alleged infringement related to the Licensed Products, Documentation, or Design Techniques. +10. Other Terms +10.1. Ownership of IP Rights: Synopsys and its licensors own all Intellectual Property Rights in the Licensed Products, Documentation, and Design Techniques. Your only rights in the Licensed Products, Documentation, and Design Techniques are the rights expressly granted in this agreement; all other rights are reserved by Synopsys. Synopsys's licensors are third-party beneficiaries of, and thus may enforce against you, the license restrictions and confidentiality obligations in this agreement with respect to their intellectual property and proprietary information. You will own all Intellectual Property Rights in the Designs you create using the Licensed Products, Documentation, and Design Techniques, subject to Synopsys's (and its licensors’) ownership of the Intellectual Property Rights in the Licensed Products, Documentation, and Design Techniques. Synopsys may freely use and disseminate any Feedback you provide. You agree not to claim that Synopsys owes you any compensation for its use or dissemination of such Feedback. +10.2. Audit and Compliance: Synopsys may audit (using its own employees and those of an independent auditing firm that is subject to appropriate confidentiality obligations) your use of the Licensed Products and Documentation to verify your compliance with this agreement. You agree to give Synopsys (or the auditing firm) reasonable access to your facilities and records for purposes of conducting these audits. Synopsys will give you at least five days advance notice before conducting an audit. Audits will be conducted during normal business hours and no more than once per year, unless Synopsys has a good-faith basis for believing that more frequent audits are warranted. Synopsys will bear all the costs it incurs (including the fees and expenses of the auditing firm, if any) in conducting an audit, unless the audit reveals that you have failed to comply with this agreement in a material way, in which case you agree to reimburse Synopsys for these costs. +10.3. Automatic Updates: Licensed Products communicate with Synopsys servers for the purpose of providing Updates, detecting software piracy and verifying that customers are using Licensed Products in conformity with the applicable License Key for such Licensed Products. Synopsys will use information gathered in connection with this process to deliver software updates and pursue software pirates and infringers. +10.4. Limitation of Liability: For each product or service you license or purchase from Synopsys under this agreement, Synopsys's total, cumulative liability to you, including under section 9, is limited to the amount of Fees you paid for that product or service (regardless of the nature of the liability or the nature or number of claims giving rise to the liability). Synopsys will not, under any circumstances or any theory of liability, be liable to you for any lost profits, loss of data, or consequential, incidental, or special damages arising from this agreement or the products and services provided to you under this agreement. However, this disclaimer of Synopsys's liability for consequential damages does not limit or reduce Synopsys's obligations to defend and indemnify you under section 9. The limitations of liability in this section are a fundamental part of this agreement and enable Synopsys to provide products and services to you at lower prices. These limitations of liability are intended to apply even if an exclusive remedy is found to have failed of its essential purpose. +10.5. Export Controls: You agree that the goods, software, and technology subject to this agreement are subject to the export control laws and regulations of the United States, including but not limited to the Export Administration Regulations ("EAR”), and sanctions regulations of the U.S. Department of Treasury, Office of Foreign Asset Controls and that you will comply with these laws and regulations. Without limiting the foregoing, if any technology, software or source code governed by this agreement, or the direct product of any such technology, software or source code (each is a "Controlled Product"), is subject to the national security controls as identified on the Commerce Control List (the "Controlled Products"), you will not, without a U.S. Bureau of Industry and Security license or license exception, export, re-export, or transfer a Controlled Product, either directly or indirectly, to any national of any country identified in Country Groups D:1 or E:1 as defined in the EARs. In addition, goods, software and any technology subject to this agreement may not be exported, reexported, or transferred to (a) any person or entity listed on the "Entity List", "Denied Persons List" or the list of "Specifically Designated Nationals and Blocked Persons" as such lists are maintained by the U.S. Government, or (b) an end-user engaged in activities related to weapons of mass destruction. Such activities include but are not necessarily limited to activities related to: (i) the design, development, production, or use of nuclear materials, nuclear facilities, or nuclear weapons; (ii) the design, development, production, or use of missiles or support of missiles projects; and (iii) the design, development, production, or use of chemical or biological weapons. +10.6. Governing Law; Jurisdiction: This agreement is governed by the laws of the United States and the State of California, without regard to conflicts of laws principles. The federal and state courts located in Santa Clara County, California have exclusive jurisdiction over any disputes arising from or relating to this agreement, and each party consents to such jurisdiction and venue. +10.7. Notices: Any notice, approval, consent, or other communication intended to have legal effect under this agreement must be given to the other party in writing, must be sent by first-class, registered, or overnight mail or private overnight courier (to the address for the other party stated on the signature page, unless the other party has given notice of a new address), and will be deemed given upon receipt or when delivery is refused. A copy of any communication sent to Synopsys must also be sent to the attention of the General Counsel. +10.8. Waivers: Either party's failure to enforce any provision of this agreement will not be deemed a waiver of the future enforcement of that provision or enforcement of any other provision. In order to be binding, a waiver must be in writing and signed by the party giving the waiver. +10.9. Independent Contractors: The parties to this agreement are independent contractors. Neither party is the agent or partner of the other party, or has any power or authority to act on behalf of the other party. +10.10. Severability: If any provision in this agreement is found to be invalid or unenforceable as written, the remaining provisions will remain in full force and effect and the invalid or unenforceable provision is to be construed (and, if necessary, modified) so that it is valid and enforceable to the greatest extent possible. +10.11. Attorneys’ Fees: The prevailing party in any action to enforce this agreement will be entitled to recover costs and expenses including reasonable attorneys' fees. +10.12. Remedies: Except where this agreement expressly provides exclusive remedies, all rights and remedies of either party (including termination rights) are cumulative. You agree that monetary damages alone would not be an adequate remedy, and therefore Synopsys will be entitled to injunctive relief if you materially breach the license restrictions or confidentiality provisions in this agreement. +10.13. Force Majeure: Each party will be excused from performance of its obligations under this agreement, except payment obligations, to the extent that performance is rendered impossible by earthquake, fire, flood, governmental action, labor disruptions, supplier failures, or any other event or circumstance beyond that party's reasonable control. +10.14. Construction: Section headings in this agreement are for convenience only. The word "including" (and variations thereof) is not intended to be limiting. No rule of strict construction is to be used when interpreting this agreement. +10.15. Press Release: The parties intend to work together to prepare and publish a mutually acceptable press release concerning this agreement. +10.16. Government Users: If you are a branch or agency of the United States Government, or are acquiring any Licensed Product on behalf of any branch or agency of the United States Government, then the following provision applies. The Licensed Products and Documentation are comprised of "commercial computer software" and "commercial computer software documentation", as such terms are used in 48 C.F.R. 12.212, and are provided to the Government (a) for acquisition by or on behalf of civilian agencies, consistent with the policy set forth in 48 C.F.R. 12.212; or (b) for acquisition by or on behalf of units of the Department of Defense, consistent with the policies set forth in 48 C.F.R. 227.7202-1 and 227.7202-3. +10.17. Synopsys Entities: Synopsys, Inc. and its wholly-owned subsidiaries, including, but not limited to, Synopsys International Limited, Synopsys International Limited Taiwan Branch, Synopsys Global Kft and Nihon Synopsys, G.K., have agreed to their respective rights and obligations regarding the distribution of the Licensed Products and the performance of obligations related to the Licensed Products. You acknowledge that: (a) Synopsys Inc. or any directly or indirectly wholly-owned subsidiary or branch of Synopsys, Inc. may treat a purchase order addressed to that entity, representative office or branch as having been addressed to the appropriate entity or entities or branch with distribution rights for the geographic region in which the Licensed Products will be used; and (b) delivery will be completed by the Synopsys entity or branch with distribution rights for the geographic region in which the Licensed Products will be used or service will be provided. For products used or services provided in a country in the Americas or Africa, the distributing Synopsys entity is Synopsys, Inc., based in California, USA. For products used or services provided in Taiwan, the distributing Synopsys entity is Synopsys International Limited Taiwan Branch, based in Taiwan. For products used or services provided in Hungary, Australia, Belarus, Bulgaria, Israel, Poland, the Republic of Korea, Romania, Russia, Ukraine or Vietnam, the distributing Synopsys entity is Synopsys Global Kft, based in Hungary. For products used or services provided in Japan, the distributing Synopsys entity is Nihon Synopsys G. K., based in Japan. For products used or services provided in any country other than those identified above, the distributing Synopsys entity is Synopsys International Limited, based in Ireland. +10.18. Entire Agreement: This agreement and any applicable attachments and Purchasing Agreements are the entire agreement between the parties concerning its subject matter, and supersede any prior or contemporaneous agreements, communications, or understandings (whether written or oral). However, any confidentiality or nondisclosure agreements that Synopsys previously entered into with you will remain in effect (according to their terms) with respect to the confidential information disclosed thereunder. +10.19. Amendments: This agreement may be amended only by means of a written instrument signed by authorized representatives of both parties that specifically refers to this agreement and states the parties’ intention to amend it. No additional or inconsistent terms on any purchase order or similar document you may submit to Synopsys will be binding on Synopsys or have any legal effect. +Glossary of Definitions - EULM +API means application programming interface for accessing specific functionality of an ARC MQX Product. +ARC MQX End Customer means a customer to whom you distribute an ARC MQX Licensee Product and who shall be obligated to maintain the confidentiality of any provided Documentation, and not expose any API of the ARC MQX Product to any third party. +ARC MQX Licensee Executable means an application program, in executable form, statically linked with and using certain APIs of an ARC MQX Product, for execution solely on an embedded ARC processor. +ARC MQX Licensee Product means a product owned by you, that is specifically identified to Synopsys in a Purchasing Agreement or other document accepted by Synopsys, and that incorporates an embedded processor and the ARC MQX Licensee Executable. +ARC MQX Product means the Synopsys real-time operating system platform for the ARC processor architecture including associated source files, application programming interfaces files, and utilities for use in creating applications that run on the ARC processor architecture. +ARC Software Development Product means any MetaWare Products, nSIM Products and xCAM Products. +Board Support Package Features means those configuration files in an ARC MQX Product that define hardware components with which the ARC MQX Licensee Executable is intended to interoperate. +Client means an instance of a Licensed Product running on a computer. This means, for example, that two Clients can be either two instances of a Licensed Product running on the same computer or one instance of a Licensed Product running on each of two computers. +Confidential Information of Synopsys means (a) the Licensed Products (in any form), the Documentation, the License Keys, and SolvNet; (b) Design Techniques and all ideas and information (such as algorithms, design rules, and design techniques) contained or embodied in the Licensed Products, Documentation, License Keys, or SolvNet; (c) the prices, discounts, payment terms, and other information in the Purchasing Agreements; (d) Synopsys Training Services materials including without limitation presentations, demonstrations, software and course handouts, and (e) any other confidential or proprietary information that Synopsys provides to you in connection with this agreement. Your Confidential Information is any confidential or proprietary information in (i) written form that you provide to Synopsys in order for Synopsys to fulfill your orders and provide products and services to you under this agreement, and (ii) oral form that you provide to Synopsys in order to receive Maintenance Services; as long as you notify Synopsys at the time of disclosure that such information is to be treated as confidential under this agreement. However, Feedback is not your Confidential Information. Also, Confidential Information does not include any of the following: +(a) information that has become generally available to the public, through no fault of yours (in the case of Synopsys Confidential Information) or Synopsys (in the case of your Confidential Information) and that is not still regarded as a trade secret under laws governing information that was negligently or maliciously distributed; +(b) information that the receiving party had already obtained in a tangible form, through lawful means, before obtaining it under this agreement; +(c) information that the receiving party developed independently, without the use of any materials or information obtained from the other party in connection with this agreement; +(d) information that the receiving party has lawfully obtained, in a tangible form, from a third party that had the right to provide it to the receiving party; or +(e) information that the disclosing party releases for publication in writing. +Design means a representation of an electronic circuit or device that you create through the use of one or more Licensed Products. The representation may exist in various formats including, but not limited to, equations, truth tables, schematic diagrams, textual descriptions, hardware description languages, executable software source code and netlists. +DesignWare has the meaning given in section 1 of the Terms and Conditions. +Design Database means a design database for your Design that incorporates DesignWare in any format (except unencrypted source code for Implementation IP), along with all copyright and other proprietary legends for such DesignWare. +Design Techniques means Synopsys-supplied algorithms, data, circuit and logic elements, libraries, rule bases, search strategies, and other technical information used in the process of creating Designs. +DesignWare Fee-Per-Use Core means an IP core (as this term is understood in the semiconductor industry) for which Synopsys charges an additional fee each time it is used in the design of an integrated circuit. +Documentation means any user manuals, reference manuals, release, application and methodology notes, written utility programs, and other materials in any form provided by Synopsys for use with a Licensed Product. +End User means an individual who works for you as an employee or independent contractor and whom you designate and authorize to access and use a Licensed Product as permitted by this agreement. +Error means a defect in a Licensed Product that causes it to deviate substantially from the specifications in the corresponding Documentation. +EST means electronic software transfer. +Feedback means any ideas or suggestions you voluntarily provide to Synopsys (in any manner, whether in writing or orally or otherwise) regarding the Licensed Products, Documentation, or Design Techniques, including possible enhancements or improvements. +Fees means the amounts you must pay when you purchase products and services from Synopsys under this agreement, as identified in each Purchasing Agreement. +FTP Server means a Synopsys server that you can access via the Internet in order to download Licensed Products you have ordered. +Implementation IP means synthesizable designs (other than Verification IP). +Integrated Design means a Design that combines Implementation IP with the Design and does not consist primarily of Implementation IP. +Intellectual Property Rights means all patent rights, copyrights, trade secret rights, mask works, and trademark rights (including service marks and trade names), and any applications for these rights, in all countries. +Key Server means the computer with the host I.D. number that is identified in the License Key and which controls access to and enables the use of a Licensed Product. +License Key means a document (in physical or electronic format) provided by Synopsys that identifies: (a) the Licensed Product, including version number, licensed to you; (b) the Key Server; (c) the number of permitted Clients; and (d) the codes that initialize use of the Key Server. +License Term means the period of time during which you may use a Licensed Product under a particular license. +Licensed Design Partner means a third party that (a) you have engaged to work with you on a common Design; and (b) has a valid Synopsys end user license agreement for the DesignWare used in your Design. +Licensed Products has the meaning given in section 1 of the Terms and Conditions. +Licensed Software has the meaning given in section 1 of the Terms and Conditions. +Maintenance Services has the meaning given in section 1 of the Terms and Conditions. +MetaWare Product means a Synopsys software development tool used to create, profile and debug software applications that run on an embedded microprocessor, identified by Synopsys with the product name "MetaWare". +nSIM Product means a Synopsys software model of the instruction set of an embedded ARC microprocessor, identified by Synopsys with the product name "nSIM". +Open Source Software has the meaning given in section 2.12 of the Terms and Conditions. +Parent Entity means a person, company or other entity that owns, directly or indirectly, fifty percent (50%) or more of your assets or of the stock or other equity interests entitled to vote for your directors or equivalent managing authority. +Purchasing Agreement means the applicable Synopsys sales quotation, FSA schedule, purchase agreement or other agreement describing (among other things) the products and services that you have licensed or purchased, including pricing information. +SolvNet means Synopsys's suite of online support services accessible via the Internet. +Synopsys Competitor means any corporation or other legal entity in the business of developing and/or marketing (including making generally commercially available to end user customers) one or more electronic design automation software products or intellectual property cores or related services. +System-on-Chip means an integrated circuit which integrates the microcontroller, microprocessor, peripherals and interfaces in a single Design. +TSL means a time-based technology subscription license of a Licensed Product. A TSL lasts for a specific period of time (the License Term) from when the license is delivered and includes (at no additional charge) Maintenance Services for the Licensed Product in question. +Use Area for a Licensed Product means a single geographical site that you own or occupy as your place of business, which may consist of one or more buildings located within 5 miles of one another, and in which the Key Servers, Clients, and End Users for that Licensed Product are all located, except as modified by the right to allow End Users to telecommute or use over a WAN in section 2.6. +Verification IP means test benches (including software models, test suites, and monitors) that simulate, test, and verify the functionality of certain electronic circuits or devices. +WAN means a wide area network as referred to in section 2.6. +xCAM Product means a Synopsys software development tool that creates and uses cycle-accurate software models of an embedded ARC microprocessor, identified by Synopsys with the product name "xCAM". +You (and variations thereof) means the entity that signs or agrees to this agreement as the customer. +ATTACHMENT FOR DESIGNWARE FEE-PER-USE CORES +1. Core Related Software and Services +1.1. This Attachment For DesignWare Fee-Per-Use Cores ("Attachment") works in conjunction with your End-User License and Maintenance Agreement and applies to your license of Synopsys's DesignWare Fee-Per-Use Core (DFPUC) products. These products and services are identified in the Purchasing Agreements governed by this Attachment and include: +(a) DesignWare Fee-Per-Use Cores (or "DesignWare Cores"), which are software products that represent an integrated circuit function which can be implemented in your Licensee IC, and which typically include associated design files in a variety of formats (such as synthesized gate-level netlists, GDSII files, MEBES or other mask writing databases, finished masks, or reticles); +(b) Verification Environments, which are simulation and test software used in connection with DesignWare Cores, such as simulation modules and simulation data analysis tools; and +(c) Core Support Services, which means the support services described in section 4. +1.2. The term "Core Software" means DesignWare Cores, Verification Environments, and any Modifications furnished to you by Synopsys while providing Core Support Services, together with any documentation and other materials that may accompany them. In addition to the specific terms in this Attachment and except as modified by this Attachment, sections 2.8 through 2.12, 3, 4, 6, and 10 of the End-User License Agreement also apply to your acquisition and use of Core Software, and the Core Software shall be deemed to be a "Licensed Product" for purposes of those sections. Capitalized terms that are not defined in this Supplement have the same meaning as specified in the End-User License Agreement. +2. Licenses +2.1. Your License Rights: When you purchase a license to Core Software, upon delivery of the Core Software you will have a nonexclusive right to: +(a) internally use and reproduce the Core Software solely to design, test, and verify the applicable Licensee IC for your manufacture and subsequent sale; +(b) create Modifications to the Core Software solely to the extent necessary to design, test, and verify the applicable Licensee IC, subject to sections 2.4 and 2.5; and +(c) manufacture (or have manufactured by a third party, as described in section 2.3) the applicable Licensee ICs incorporating the licensed DesignWare Core. +2.2. Users: Except as described in sections 2.2 and 2.3, you will allow only those of your employees who are on the single design team responsible for designing or testing your Licensee IC to access the Core Software. You are responsible for the acts and omissions of your employees, agents, and permitted Contractors and third-party manufacturers with respect to any use of the Core Software or Synopsys Confidential Information, including any breaches of this Attachment that they may commit. +2.3. Contractors: You may also allow Contractors to access certain parts of the Core Software as follows: +(a) For Core Software that is in netlist or encrypted RTL form, you may allow Contractors that are not Synopsys Competitors to access that Core Software either on your physical premises or on theirs. Contractors that are Synopsys Competitors may access the netlist or encrypted RTL only while on your physical premises. +(b) For Core Software that is in source code form, you may allow Contractors that are not Synopsys Competitors to access that Core Software only on your physical premises. You may not allow Contractors that are Synopsys Competitors to access this source code at all. +(c) In all cases, you may allow Contractors to access the Core Software only on a "need-to-know" basis, only to allow them to perform design services on the Licensee IC in accordance with your license, and subject to a written confidentiality agreement that is at least as protective as the confidentiality terms set forth in the End-User License and Maintenance Agreement. +2.4. Third-Party Manufacturers: You may have a third-party manufacturer make Licensee ICs incorporating the licensed DesignWare Core for you if you make sure all of the following conditions are met: +(a) the resulting Licensee ICs must be made for sale or use only by you; +(b) the designs and specifications you give to the manufacturer contain sufficient detail so that no additional design work is performed by the manufacturer (except for the simple adaptation of your designs to the manufacturer's own normal production processes); +(c) you provide those designs and specifications to the manufacturer only for the purpose of making the Licensee ICs for you, and subject to confidentiality provisions that are at least as protective as those in the End-User License and Maintenance Agreement; and +(d) you do not give source code for any Core Software to the manufacturer. +2.5. Hard IP Cores: If you license any DesignWare Cores that are Hard IP Cores, you understand that you may be required to obtain appropriate licenses to technology libraries (such as standard cell and I/O libraries) from a supplier of such libraries for the applicable manufacturer, and that if this is case, you are responsible for getting these licenses at your own cost. You also agree that you may not make Modifications to Hard IP Cores without first obtaining Synopsys's prior written consent. Your use of each Hard IP Core is limited to the applicable manufacturer and process node specified in the purchase order, and you may not use the Hard IP Core for any other manufacturer or process node. +2.6. Ownership: The Core Software and all Modifications (including all Intellectual Property Rights in them) are owned by Synopsys and its licensors. If you have any rights in any Modifications, you hereby irrevocably assign ownership of those Modifications (and all Intellectual Property Rights in them) to Synopsys. However, you are under no obligation to actually disclose any such Modifications to Synopsys, and they will automatically be licensed to you as "Core Software" pursuant to section 2.1. There are no implied licenses granted under this Attachment, and all rights not expressly granted to you are reserved to Synopsys. +3. Fees and Payment +3.1. Fees and Royalties: The applicable license fees and royalties for the Core Software are specified in the Purchasing Agreement. The payment and reporting terms applicable to royalties are described below in section 3.2. Otherwise, the fees and payment terms described in section 4 of the End-User License and Maintenance Agreement shall apply. +3.2. Royalty Reporting and Payment: If royalties are applicable, then within 30 days after the end of each calendar quarter following the effective date of this Attachment, you will submit a royalty report to Synopsys via email to royalty@synopsys.com, on a form approved by Synopsys, that accurately sets forth the number of units of each Licensee IC that you sold, distributed, or otherwise disposed of during that quarter, along with payment of all reported amounts. You are to submit a royalty report even during quarters where you report no sales, distributions, or disposals of Licensee ICs. Note that you will continue to be obligated to make royalty reports and pay royalties until you permanently discontinue sales or distributions of the applicable Licensee IC. In the event of such a discontinuation, you will provide Synopsys with a written certification that the Licensee IC has been discontinued, along with a final royalty report for the applicable Licensee IC. +3.3. Royalty Audits: You shall keep full, clear, and accurate records regarding your use of the Core Software, sales and other disposals of Licensee ICs, and royalties due under this Attachment. On 5 days’ prior written notice, Synopsys may audit those records during normal business hours, and you will provide Synopsys with all necessary access to your premises where those records are located. If an audit reveals an underpayment of fees, you will immediately pay the shortfall, plus a late fee applied at a rate equal to the lesser of 1.5% per month or the highest rate allowable under law. Synopsys will bear its own expenses of the audit, except if the audit discloses an underpayment of 5% or more for the audited period, in which case you will reimburse Synopsys for all of its reasonable expenses. +4. Core Support Services +4.1. Core Support Services: Core Support Services, for the first 6 months after the initial delivery of the Core Software, are included in the price of a Use of the Core Software. In providing Core Support Services, Synopsys will use commercially reasonable efforts to perform the following: +(a) provide you with bug-fix releases to the extent necessary to conform the Core Software to any applicable technical standard specification that was in existence at the time the Core Software was delivered to you; +(b) provide you with workarounds for material errors in the Core Software; +(c) provide you with 24/7 access to electronic assistance regarding the operation of the Core Software, as Synopsys may make available from time to time (such as through the SolvNet online web support service); +(d) if electronic assistance does not yield an appropriate resolution, give you access to a reasonable amount of telephone support for the Core Software, during normal business hours, through your designated support contact; and +(e) deliver bulletins as they are released by Synopsys from time to time, which contain information on bug-fix releases, application techniques, and workarounds for the Core Software. +4.2. Designated Support Contacts: You may appoint up to 4 designated support contacts for each supported Licensee IC, and will give Synopsys the names of all designated support contacts before making initial contact with the Synopsys support center. All technical communications, information, and materials exchanged between you and Synopsys regarding the Core Software will be conducted through your designated support contacts. You may change any designated support contact at any time by notifying Synopsys. +4.3. Limitations. The Core Support Services described in this section are the only services that Synopsys makes available for the Core Software, and no other warranties or support and maintenance services apply. Synopsys has no obligation to provide support for Core Software that has been altered, damaged, or modified by anyone other than Synopsys. If you wish to continue receiving Core Support Services after the 6 month period following the initial delivery of the Core Software, you must separately purchase extended Core Support Services from Synopsys for an additional fee pursuant to an accepted purchase order. Reuse fees for Core Software do not include Core Support Services. +The Core Software and Core Support Services are provided "AS IS". Synopsys disclaims all other warranties (express, implied, or statutory), including any warranties of merchantability, fitness for a particular purpose, title, or non-infringement and any warranties arising from a course of dealing or usage of trade. +5. Term and Termination +5.1. Term of Individual Licenses: The term of each license for the Core Software granted under this Attachment shall begin upon the delivery date of the Core Software, and shall continue until you discontinue the sale and distribution of the applicable Licensee ICs, or until the End-User License and Maintenance Agreement expires or terminates, whichever is sooner. +5.2. Term of Attachment: The term of this Attachment shall continue until all licenses granted hereunder terminate, or until the End-User License and Maintenance Agreement expires or terminates, whichever is sooner. +5.3 Effect of Termination: When each license granted under this Attachment expires or terminates, you shall either destroy or return to Synopsys all copies of the previously-licensed Core Software and related Confidential Information in your possession or control (or in the possession of any third party to whom you provided such materials), except, however, that your license to a DesignWare Core Instantiated into a Licensee IC prior to termination shall continue according to its terms. You shall certify to Synopsys with a written officer's certificate that you have complied with these obligations within 30 days after such expiration or termination. +6. Third-Party Licenses and Indemnification +6.1. Indemnity: Synopsys will, at its own expense, be entitled to defend (or at its sole option, settle) any claim asserted against you by a third party that any Core Software you obtained from Synopsys under this Attachment directly infringes any U.S. patent that issued before Synopsys's delivery to you of the applicable Core Software, copyright, trademark, or trade secret. Synopsys will indemnify you for any damages you suffer and costs you reasonably incur that are directly attributable to any such claim and that are assessed against you in a final, non-appealable judgment or agreed upon by Synopsys in a settlement. +6.2. Conditions: Synopsys's obligations to defend and indemnify you with respect to a particular claim are subject to the following conditions: +(a) you must promptly give Synopsys written notice of the claim; +(b) you must identify the specific Core Software at issue in the claim and indicate how the Core Software is utilized by you or your products; +(c) you must give Synopsys sole control and authority over the defense and settlement of the claim; and +(d) you must provide Synopsys with all information you have regarding the claim and cooperate with Synopsys when Synopsys defends or attempts to settle the claim. +6.3. Pro-Active Steps: If any Core Software is, or Synopsys believes is likely to become, the subject of a claim for which Synopsys would be obligated to defend and indemnify you, then Synopsys may, at its option, do any of the following: +(a) obtain for you (at no cost to you) the right for you to continue using the Core Software as permitted by this Attachment; +(b) replace or modify the Core Software to avoid the infringement problem, as long as there is no material loss of functionality; or +(c) if Synopsys reasonably concludes that it will not be feasible to do either of the above, terminate your license for the Core Software and give you a refund of the Fees you paid to Synopsys for that license. +6.4. Exclusions: Synopsys will have no obligation to defend or indemnify you (notwithstanding the first paragraph of this section) with respect to any claim that is based on or attributable to any of the following: +(a) any modification made to the Core Software by anyone other than Synopsys; +(b) the combination or use of the Core Software with other products or materials not supplied by Synopsys or specified in the Documentation as being necessary to use the Core Software; +(c) your continued engagement in infringing activities after you were notified of the infringement or after Synopsys informed you of a modification or workaround that would have avoided the infringement; +(d) the failure to obtain a license available from a standards organization, or which would be available as a result of an undertaking to a standards organization; +(e) the methods or processes employed in using the Core Software, other than those inherent methods and processes that are necessarily employed in the intended mode of operation of the Core Software and without which a material function of the Core Software would not operate; +(f) compliance with your directions, instructions, specifications, or technical requirements (including any requirement that the Core Software or Licensee IC support or comply with industry or technical standards), if there are no known commercially-reasonable means of complying with such directions, instructions, specifications, or technical requirements free of a claim of infringement; or +(g) your use of the Core Software in a manner not permitted by this Attachment. +6.5. Burden of Proof: You will have the burden of showing that indemnification is required pursuant to this section 6 and that the exclusions in section 6.4 are not applicable. +6.6. No Other Obligations: Except as expressly stated in this section 6, Synopsys has no obligation or liability to you for any actual or alleged infringement related to the Core Software. +6.7. Limitation of Liability. For each Core Software you license from Synopsys under this Attachment, Synopsys's total, cumulative liability to you for indemnity and defense under this section 6 (including without limitation for attorneys’ fees and costs that Synopsys or you incur in defending the third-party claims) is limited to the amount of Fees you paid Synopsys for that Core Software (regardless of the number of claims giving rise to the liability). Synopsys will not, under any circumstances or any theory of liability, be liable to you for any lost profits, loss of data, or consequential, incidental, or special damages arising from this agreement or the products and services provided to you under this agreement. However, this disclaimer of Synopsys's liability for consequential damages does not limit or reduce Synopsys's obligations to defend and indemnify you under section 6 of this Attachment. The limitations of liability in this section are a fundamental part of this Attachment and enable Synopsys to provide products and services to you at lower prices. These limitations of liability are intended to apply even if an exclusive remedy is found to have failed of its essential purpose. +GLOSSARY OF DEFINITIONS - DFPUC +Contractor means a third-party entity engaged by you to provide design services directly related to your Licensee IC. +Core Support Services has the meaning given in section 4 of this Attachment. +Hard IP Core means a DesignWare Core that is delivered in a format that is non-synthesizable and suitable for implementation using a specific manufacturing process. +IC means integrated circuit. +Instantiation (and variations thereof) means an implementation of a single DesignWare Core a single time in an IC. Implementation of the same DesignWare Core two times in a single IC constitutes two Instantiations. +Licensee IC means an IC owned by you and specifically identified to Synopsys in a Purchasing Agreement or other document accepted by Synopsys, which contains at least one Instantiation of a DesignWare Core. +Modification means a bug fix, modification, enhancement, or revision of any aspect of the Core Software. +Reuse means an additional Use of any aspect of the Core Software in a new Licensee IC (i.e. one that functions differently from the IC that was the subject of the initial Use, such as an IC that implements a change in timing, electrical or power specifications, retargeting to a different process technology or other changes in form, features or functionality); provided, however, that "Reuse" specifically excludes any Use: (a) in connection with a revised version of an IC that was the subject of the initial Use for which you have already obtained a paid-up license, where the only change is to implement bug fixes or error corrections in an IC and (b) in connection with a new IC that uses the same physical GDSII as the IC that was the subject of the initial Use and for which you have already obtained a paid-up license (as in the case of a bond out option). +Use means, with respect to a specific Licensee IC, a single Instantiation of a DesignWare Core in that specific Licensee IC. + +EULMD2 - Rev. 21 Sep. 2012 From 1056fa473a472ee13c6bd9e92387960020d645bc Mon Sep 17 00:00:00 2001 From: Pradchaya P Date: Thu, 9 May 2019 12:12:04 +0800 Subject: [PATCH 3/4] [platform/cel] cpld upgrade tool code cleanup *Format indentation. *Remove unused code comment. *Remove trailing space. --- .../tools/ispvme_12.2/Makefile | 3 - .../tools/ispvme_12.2/hardware.c | 270 +- .../tools/ispvme_12.2/ispvm_ui.c | 1057 ++-- .../tools/ispvme_12.2/ivm_core.c | 4728 ++++++++--------- .../tools/ispvme_12.2/vmopcode.h | 50 +- 5 files changed, 3050 insertions(+), 3058 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/Makefile b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/Makefile index ef403e67f8c0..135cc38e9422 100644 --- a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/Makefile +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/Makefile @@ -1,15 +1,12 @@ CC = gcc AR = ar -# CFLAGS = -Wall -W -Wunused -lpthread -g -O2 -ggdb -DIPMI_PRJ -DDIAG_DEBUG -DDIAG_API -DHAVE_CONFIG_H -DFCS_CTRL_NO_BURST -DFCS_DEBUG -DHAVE_NANOSLEEP CFLAGS = -Wall -W -Wunused -lpthread -g -O0 -ggdb -DDIAG_DEBUG -DDIAG_API -DHAVE_CONFIG_H -DFCS_DEBUG -DHAVE_NANOSLEEP LFLAGS = -lm -pthread DEL_FILE = rm -f MV_FILE = mv -f OBJ_FILE_NODE = ./*.o -#VPATH = INCPATH = -I../include/ TARGET = ispvm -# OBJECTS += cpld_ops.o i2c_dev.o i2c_chips.o sys_eeprom.o crc32.o bsp_ifc.o hpcsfp.o smartfan.o test.o path.o OBJECTS += hardware.o ispvm_ui.o ivm_core.o diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/hardware.c b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/hardware.c index 24f4edc23c08..9e8ddfb4f85c 100644 --- a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/hardware.c +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/hardware.c @@ -1,17 +1,17 @@ /********************************************************************************* * Lattice Semiconductor Corp. Copyright 2000-2008 -* +* * This is the hardware.c of ispVME V12.1 for JTAG programmable devices. -* All the functions requiring customization are organized into this file for -* the convinience of porting. +* All the functions requiring customization are organized into this file for +* the convinience of porting. *********************************************************************************/ /********************************************************************************* * Revision History: - * + * * 09/11/07 NN Type cast mismatch variables * 09/24/07 NN Added calibration function. * Calibration will help to determine the system clock frequency - * and the count value for one micro-second delay of the target + * and the count value for one micro-second delay of the target * specific hardware. * Modified the ispVMDelay function * Removed Delay Percent support @@ -21,18 +21,18 @@ #include #include /******************************************************************************** -* Declaration of global variables +* Declaration of global variables * *********************************************************************************/ #ifndef IPMI_PRJ unsigned long g_siIspPins = 0x00000000; /*Keeper of JTAG pin state*/ unsigned short g_usInPort = 0x588; /*Address of the TDO pin*/ -unsigned short g_usOutPort = 0x588; /*Address of TDI, TMS, TCK pin*/ +unsigned short g_usOutPort = 0x588; /*Address of TDI, TMS, TCK pin*/ unsigned short g_usCpu_Frequency = 2400; // Here is Intel rangely CPU frequence /*Enter your CPU frequency here, unit in MHz.*/ #else unsigned long g_siIspPins = 0x00000000; /*Keeper of JTAG pin state*/ unsigned short g_usInPort = 0x548; /*Address of the TDO pin*/ -unsigned short g_usOutPort = 0x548; /*Address of TDI, TMS, TCK pin*/ +unsigned short g_usOutPort = 0x548; /*Address of TDI, TMS, TCK pin*/ unsigned short g_usCpu_Frequency = 4000; // Here is Intel rangely CPU frequence /*Enter your CPU frequency here, unit in MHz.*/ #endif @@ -76,7 +76,7 @@ void calibration(void); /******************************************************************************** * writePort * To apply the specified value to the pins indicated. This routine will -* be modified for specific systems. +* be modified for specific systems. * As an example, this code uses the IBM-PC standard Parallel port, along with the * schematic shown in Lattice documentation, to apply the signals to the * JTAG pins. @@ -88,19 +88,19 @@ void calibration(void); * 5 g_ucPinENABLE 8 * 6 g_ucPinTRST 16 * 10 g_ucPinTDO 64 -* +* * Parameters: * - a_ucPins, which is actually a set of bit flags (defined above) * that correspond to the bits of the data port. Each of the I/O port -* bits that drives an isp programming pin is assigned a flag -* (through a #define) corresponding to the signal it drives. To -* change the value of more than one pin at once, the flags are added +* bits that drives an isp programming pin is assigned a flag +* (through a #define) corresponding to the signal it drives. To +* change the value of more than one pin at once, the flags are added * together, much like file access flags are. * -* The bit flags are only set if the pin is to be changed. Bits that -* do not have their flags set do not have their levels changed. The -* state of the port is always manintained in the static global -* variable g_siIspPins, so that each pin can be addressed individually +* The bit flags are only set if the pin is to be changed. Bits that +* do not have their flags set do not have their levels changed. The +* state of the port is always manintained in the static global +* variable g_siIspPins, so that each pin can be addressed individually * without disturbing the others. * * - a_ucValue, which is either HIGH (0x01 ) or LOW (0x00 ). Only these two @@ -110,17 +110,17 @@ void calibration(void); void writePort( unsigned long a_ucPins, unsigned char a_ucValue ) { - if ( a_ucValue ) { - g_siIspPins = (a_ucPins | g_siIspPins); - } - else { - g_siIspPins = (~a_ucPins & g_siIspPins); - } + if ( a_ucValue ) { + g_siIspPins = (a_ucPins | g_siIspPins); + } + else { + g_siIspPins = (~a_ucPins & g_siIspPins); + } - outl_p( g_siIspPins, g_usOutPort ); - /* This is a sample code for Windows/DOS without Windows Driver. - _outp( g_usOutPort, g_siIspPins ); - */ + outl_p( g_siIspPins, g_usOutPort ); + /* This is a sample code for Windows/DOS without Windows Driver. + _outp( g_usOutPort, g_siIspPins ); + */ } /********************************************************************************* @@ -132,17 +132,17 @@ void writePort( unsigned long a_ucPins, unsigned char a_ucValue ) **********************************************************************************/ unsigned char readPort() { - unsigned char ucRet = 0; + unsigned char ucRet = 0; - if ( inl_p( g_usInPort ) & g_ucPinTDO ) { - ucRet = 0x01; - } - else { - ucRet = 0x00; - } - //printf("Read Port: 0x%x\n", ucRet); - return ( ucRet ); -} + if ( inl_p( g_usInPort ) & g_ucPinTDO ) { + ucRet = 0x01; + } + else { + ucRet = 0x00; + } + //printf("Read Port: 0x%x\n", ucRet); + return ( ucRet ); +} /********************************************************************************* * sclock @@ -150,21 +150,21 @@ unsigned char readPort() * Apply a pulse to TCK. * * This function is located here so that users can modify to slow down TCK if -* it is too fast (> 25MHZ). Users can change the IdleTime assignment from 0 to +* it is too fast (> 25MHZ). Users can change the IdleTime assignment from 0 to * 1, 2... to effectively slowing down TCK by half, quarter... * *********************************************************************************/ void sclock() -{ - unsigned short IdleTime = 0; //change to > 0 if need to slow down TCK - unsigned short usIdleIndex = 0; - IdleTime++; - for ( usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++ ) { - writePort( g_ucPinTCK, 0x01 ); - } - for ( usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++ ) { - writePort( g_ucPinTCK, 0x00 ); - } +{ + unsigned short IdleTime = 0; //change to > 0 if need to slow down TCK + unsigned short usIdleIndex = 0; + IdleTime++; + for ( usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++ ) { + writePort( g_ucPinTCK, 0x01 ); + } + for ( usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++ ) { + writePort( g_ucPinTCK, 0x00 ); + } } /******************************************************************************** * @@ -179,29 +179,29 @@ void sclock() * a_usTimeDelay = 0x0001 = 1 microsecond delay. * a_usTimeDelay = 0x8001 = 1 millisecond delay. * -* This subroutine is called upon to provide a delay from 1 millisecond to a few -* hundreds milliseconds each time. +* This subroutine is called upon to provide a delay from 1 millisecond to a few +* hundreds milliseconds each time. * It is understood that due to a_usTimeDelay is defined as unsigned short, a 16 bits -* integer, this function is restricted to produce a delay to 64000 micro-seconds +* integer, this function is restricted to produce a delay to 64000 micro-seconds * or 32000 milli-second maximum. The VME file will never pass on to this function * a delay time > those maximum number. If it needs more than those maximum, the VME * file will launch the delay function several times to realize a larger delay time * cummulatively. -* It is perfectly alright to provide a longer delay than required. It is not +* It is perfectly alright to provide a longer delay than required. It is not * acceptable if the delay is shorter. * * Delay function example--using the machine clock signal of the native CPU------ -* When porting ispVME to a native CPU environment, the speed of CPU or -* the system clock that drives the CPU is usually known. -* The speed or the time it takes for the native CPU to execute one for loop +* When porting ispVME to a native CPU environment, the speed of CPU or +* the system clock that drives the CPU is usually known. +* The speed or the time it takes for the native CPU to execute one for loop * then can be calculated as follows: * The for loop usually is compiled into the ASSEMBLY code as shown below: * LOOP: DEC RA; * JNZ LOOP; -* If each line of assembly code needs 4 machine cycles to execute, +* If each line of assembly code needs 4 machine cycles to execute, * the total number of machine cycles to execute the loop is 2 x 4 = 8. -* Usually system clock = machine clock (the internal CPU clock). -* Note: Some CPU has a clock multiplier to double the system clock for +* Usually system clock = machine clock (the internal CPU clock). +* Note: Some CPU has a clock multiplier to double the system clock for the machine clock. * * Let the machine clock frequency of the CPU be F, or 1 machine cycle = 1/F. @@ -210,104 +210,104 @@ void sclock() * * Example: The CPU internal clock is set to 100Mhz, then one micro-second = 100/8 = 12 * -* The C code shown below can be used to create the milli-second accuracy. +* The C code shown below can be used to create the milli-second accuracy. * Users only need to enter the speed of the cpu. * **********************************************************************************/ void ispVMDelay( unsigned short a_usTimeDelay ) { - unsigned short loop_index = 0; - unsigned short ms_index = 0; - unsigned short us_index = 0; + unsigned short loop_index = 0; + unsigned short ms_index = 0; + unsigned short us_index = 0; - if ( a_usTimeDelay & 0x8000 ) /*Test for unit*/ - { - a_usTimeDelay &= ~0x8000; /*unit in milliseconds*/ - } - else { /*unit in microseconds*/ - a_usTimeDelay = (unsigned short) (a_usTimeDelay/1000); /*convert to milliseconds*/ - if ( a_usTimeDelay <= 0 ) { - a_usTimeDelay = 1; /*delay is 1 millisecond minimum*/ - } - } - /*Users can replace the following section of code by their own*/ - for( ms_index = 0; ms_index < a_usTimeDelay; ms_index++) - { - /*Loop 1000 times to produce the milliseconds delay*/ - for (us_index = 0; us_index < 1000; us_index++) - { /*each loop should delay for 1 microsecond or more.*/ - loop_index = 0; - do { - /*The NOP fakes the optimizer out so that it doesn't toss out the loop code entirely*/ - asm("nop"); - }while (loop_index++ < ((g_usCpu_Frequency/8)+(+ ((g_usCpu_Frequency % 8) ? 1 : 0))));/*use do loop to force at least one loop*/ - } - } + if ( a_usTimeDelay & 0x8000 ) /*Test for unit*/ + { + a_usTimeDelay &= ~0x8000; /*unit in milliseconds*/ + } + else { /*unit in microseconds*/ + a_usTimeDelay = (unsigned short) (a_usTimeDelay/1000); /*convert to milliseconds*/ + if ( a_usTimeDelay <= 0 ) { + a_usTimeDelay = 1; /*delay is 1 millisecond minimum*/ + } + } + /*Users can replace the following section of code by their own*/ + for( ms_index = 0; ms_index < a_usTimeDelay; ms_index++) + { + /*Loop 1000 times to produce the milliseconds delay*/ + for (us_index = 0; us_index < 1000; us_index++) + { /*each loop should delay for 1 microsecond or more.*/ + loop_index = 0; + do { + /*The NOP fakes the optimizer out so that it doesn't toss out the loop code entirely*/ + asm("nop"); + }while (loop_index++ < ((g_usCpu_Frequency/8)+(+ ((g_usCpu_Frequency % 8) ? 1 : 0))));/*use do loop to force at least one loop*/ + } + } } /********************************************************************************* * * calibration * -* It is important to confirm if the delay function is indeed providing -* the accuracy required. Also one other important parameter needed -* checking is the clock frequency. -* Calibration will help to determine the system clock frequency -* and the loop_per_micro value for one micro-second delay of the target +* It is important to confirm if the delay function is indeed providing +* the accuracy required. Also one other important parameter needed +* checking is the clock frequency. +* Calibration will help to determine the system clock frequency +* and the loop_per_micro value for one micro-second delay of the target * specific hardware. -* +* **********************************************************************************/ void calibration(void) { - /*Apply 2 pulses to TCK.*/ - writePort( g_ucPinTCK, 0x00 ); - writePort( g_ucPinTCK, 0x01 ); - writePort( g_ucPinTCK, 0x00 ); - writePort( g_ucPinTCK, 0x01 ); - writePort( g_ucPinTCK, 0x00 ); + /*Apply 2 pulses to TCK.*/ + writePort( g_ucPinTCK, 0x00 ); + writePort( g_ucPinTCK, 0x01 ); + writePort( g_ucPinTCK, 0x00 ); + writePort( g_ucPinTCK, 0x01 ); + writePort( g_ucPinTCK, 0x00 ); - /*Delay for 1 millisecond. Pass on 1000 or 0x8001 both = 1ms delay.*/ - ispVMDelay(0x8001); + /*Delay for 1 millisecond. Pass on 1000 or 0x8001 both = 1ms delay.*/ + ispVMDelay(0x8001); - /*Apply 2 pulses to TCK*/ - writePort( g_ucPinTCK, 0x01 ); - writePort( g_ucPinTCK, 0x00 ); - writePort( g_ucPinTCK, 0x01 ); - writePort( g_ucPinTCK, 0x00 ); + /*Apply 2 pulses to TCK*/ + writePort( g_ucPinTCK, 0x01 ); + writePort( g_ucPinTCK, 0x00 ); + writePort( g_ucPinTCK, 0x01 ); + writePort( g_ucPinTCK, 0x00 ); } void port_test(void) { - int siRetCode; - unsigned char cbit; + int siRetCode; + unsigned char cbit; - printf("TDI set HIGH.\n"); - scanf("%d",&siRetCode); - writePort( g_ucPinTDI, 0x01); - printf("TDI set LOW.\n"); - scanf("%d",&siRetCode); - writePort( g_ucPinTDI, 0x00); - printf("TMS set HIGH.\n"); - scanf("%d",&siRetCode); - writePort(g_ucPinTMS, 0x01); - printf("TMS set LOW.\n"); - scanf("%d",&siRetCode); - writePort(g_ucPinTMS, 0x00); - printf("TCK set HIGH.\n"); - scanf("%d",&siRetCode); - writePort(g_ucPinTCK, 0x01); - printf("TCK set LOW.\n"); - scanf("%d",&siRetCode); - writePort(g_ucPinTCK, 0x00); - printf("write finished.read begin:\n"); - scanf("%d",&siRetCode); - cbit = readPort(); - printf("Read date is %d\n", cbit); - printf("read begin:\n"); - scanf("%d",&siRetCode); - cbit = readPort(); - printf("Read date is %d\n", cbit); - printf("read finished.\n"); - scanf("%d",&siRetCode); - /******test JTAG ports**********/ + printf("TDI set HIGH.\n"); + scanf("%d",&siRetCode); + writePort( g_ucPinTDI, 0x01); + printf("TDI set LOW.\n"); + scanf("%d",&siRetCode); + writePort( g_ucPinTDI, 0x00); + printf("TMS set HIGH.\n"); + scanf("%d",&siRetCode); + writePort(g_ucPinTMS, 0x01); + printf("TMS set LOW.\n"); + scanf("%d",&siRetCode); + writePort(g_ucPinTMS, 0x00); + printf("TCK set HIGH.\n"); + scanf("%d",&siRetCode); + writePort(g_ucPinTCK, 0x01); + printf("TCK set LOW.\n"); + scanf("%d",&siRetCode); + writePort(g_ucPinTCK, 0x00); + printf("write finished.read begin:\n"); + scanf("%d",&siRetCode); + cbit = readPort(); + printf("Read date is %d\n", cbit); + printf("read begin:\n"); + scanf("%d",&siRetCode); + cbit = readPort(); + printf("Read date is %d\n", cbit); + printf("read finished.\n"); + scanf("%d",&siRetCode); + /******test JTAG ports**********/ } diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c index b22210336901..af173a0fea3d 100644 --- a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c @@ -1,7 +1,7 @@ /************************************************************** * * Lattice Semiconductor Corp. Copyright 2008 -* +* * ispVME Embedded allows programming of Lattice's suite of FPGA * devices on embedded systems through the JTAG port. The software * is distributed in source code form and is open to re - distribution @@ -10,28 +10,28 @@ * ispVME Embedded C Source comprised with 3 modules: * ispvm_ui.c is the module provides input and output support. * ivm_core.c is the module interpret the VME file(s). -* hardware.c is the module access the JTAG port of the device(s). +* hardware.c is the module access the JTAG port of the device(s). * -* The optional module cable.c is for supporting Lattice's parallel -* port ispDOWNLOAD cable on DOS and Windows 95/98 O/S. It can be +* The optional module cable.c is for supporting Lattice's parallel +* port ispDOWNLOAD cable on DOS and Windows 95/98 O/S. It can be * requested from Lattice's ispVMSupport. * ***************************************************************/ /************************************************************** -* +* * Revision History of ispvm_ui.c -* -* 3/6/07 ht Added functions vme_out_char(),vme_out_hex(), +* +* 3/6/07 ht Added functions vme_out_char(),vme_out_hex(), * vme_out_string() to provide output resources. -* Consolidate all printf() calls into the added output -* functions. +* Consolidate all printf() calls into the added output +* functions. * * 09/11/07 NN Added Global variables initialization * 09/24/07 NN Added a switch allowing users to do calibration. * Calibration will help to determine the system clock frequency -* and the count value for one micro-second delay of the target +* and the count value for one micro-second delay of the target * specific hardware. * Removed Delay Percent support * 11/15/07 NN moved the checking of the File CRC to the end of processing @@ -95,12 +95,12 @@ extern unsigned short g_usCalculatedCRC; extern unsigned short g_usDataType; extern unsigned char * g_pucOutMaskData, * g_pucInData, - * g_pucOutData, - * g_pucHIRData, - * g_pucTIRData, - * g_pucHDRData, - * g_pucTDRData, - * g_pucOutDMaskData, + * g_pucOutData, + * g_pucHIRData, + * g_pucTIRData, + * g_pucHDRData, + * g_pucTDRData, + * g_pucOutDMaskData, * g_pucIntelBuffer; extern unsigned char * g_pucHeapMemory; extern unsigned short g_iHeapCounter; @@ -141,125 +141,125 @@ const char * const g_szSupportedVersions[] = { "__VME2.0", "__VME3.0", "____12.0 unsigned char GetByte() { - unsigned char ucData = 0; - - if ( g_usDataType & HEAP_IN ) { - - /*************************************************************** - * - * Get data from repeat buffer. - * - ***************************************************************/ - - if ( g_iHeapCounter > g_iHEAPSize ) { - - /*************************************************************** - * - * Data over-run. - * - ***************************************************************/ - - return 0xFF; - } - - ucData = g_pucHeapMemory[ g_iHeapCounter++ ]; - } - else if ( g_usDataType & LHEAP_IN ) { - - /*************************************************************** - * - * Get data from intel buffer. - * - ***************************************************************/ - - if ( g_usIntelDataIndex >= g_usIntelBufferSize ) { - - /*************************************************************** - * - * Data over-run. - * - ***************************************************************/ - - return 0xFF; - } - - ucData = g_pucIntelBuffer[ g_usIntelDataIndex++ ]; - } - else { - - /*************************************************************** - * - * Get data from file. - * - ***************************************************************/ - - ucData = (unsigned char)fgetc( g_pVMEFile ); - - if ( feof( g_pVMEFile ) ) { - - /*************************************************************** - * - * Reached EOF. - * - ***************************************************************/ - - return 0xFF; - } - /*************************************************************** - * - * Calculate the 32-bit CRC if the expected CRC exist. - * - ***************************************************************/ - if( g_usExpectedCRC != 0) - { - ispVMCalculateCRC32(ucData); - } - } - - return ( ucData ); + unsigned char ucData = 0; + + if ( g_usDataType & HEAP_IN ) { + + /*************************************************************** + * + * Get data from repeat buffer. + * + ***************************************************************/ + + if ( g_iHeapCounter > g_iHEAPSize ) { + + /*************************************************************** + * + * Data over-run. + * + ***************************************************************/ + + return 0xFF; + } + + ucData = g_pucHeapMemory[ g_iHeapCounter++ ]; + } + else if ( g_usDataType & LHEAP_IN ) { + + /*************************************************************** + * + * Get data from intel buffer. + * + ***************************************************************/ + + if ( g_usIntelDataIndex >= g_usIntelBufferSize ) { + + /*************************************************************** + * + * Data over-run. + * + ***************************************************************/ + + return 0xFF; + } + + ucData = g_pucIntelBuffer[ g_usIntelDataIndex++ ]; + } + else { + + /*************************************************************** + * + * Get data from file. + * + ***************************************************************/ + + ucData = (unsigned char)fgetc( g_pVMEFile ); + + if ( feof( g_pVMEFile ) ) { + + /*************************************************************** + * + * Reached EOF. + * + ***************************************************************/ + + return 0xFF; + } + /*************************************************************** + * + * Calculate the 32-bit CRC if the expected CRC exist. + * + ***************************************************************/ + if( g_usExpectedCRC != 0) + { + ispVMCalculateCRC32(ucData); + } + } + + return ( ucData ); } /*************************************************************** * * vme_out_char * -* Send a character out to the output resource if available. -* The monitor is the default output resource. +* Send a character out to the output resource if available. +* The monitor is the default output resource. * * ***************************************************************/ void vme_out_char(unsigned char charOut) { - printf("%c",charOut); + printf("%c",charOut); } /*************************************************************** * * vme_out_hex * -* Send a character out as in hex format to the output resource -* if available. The monitor is the default output resource. +* Send a character out as in hex format to the output resource +* if available. The monitor is the default output resource. * * ***************************************************************/ void vme_out_hex(unsigned char hexOut) { - printf("%.2X",hexOut); + printf("%.2X",hexOut); } /*************************************************************** * * vme_out_string * -* Send a text string out to the output resource if available. -* The monitor is the default output resource. +* Send a text string out to the output resource if available. +* The monitor is the default output resource. * * ***************************************************************/ void vme_out_string(char *stringOut) { - if(stringOut) - { - printf("%s",stringOut); - } + if(stringOut) + { + printf("%s",stringOut); + } } /*************************************************************** @@ -273,111 +273,111 @@ void vme_out_string(char *stringOut) void ispVMMemManager( signed char cTarget, unsigned short usSize ) { - switch ( cTarget ) { - case XTDI: - case TDI: - if ( g_pucInData != NULL ) { - if ( g_usPreviousSize == usSize ) {/*memory exist*/ - break; - } - else { - free( g_pucInData ); - g_pucInData = NULL; - } - } - g_pucInData = ( unsigned char * ) malloc( usSize / 8 + 2 ); - g_usPreviousSize = usSize; + switch ( cTarget ) { + case XTDI: + case TDI: + if ( g_pucInData != NULL ) { + if ( g_usPreviousSize == usSize ) {/*memory exist*/ + break; + } + else { + free( g_pucInData ); + g_pucInData = NULL; + } + } + g_pucInData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + g_usPreviousSize = usSize; case XTDO: case TDO: - if ( g_pucOutData!= NULL ) { - if ( g_usPreviousSize == usSize ) { /*already exist*/ - break; - } - else { - free( g_pucOutData ); - g_pucOutData = NULL; - } - } - g_pucOutData = ( unsigned char * ) malloc( usSize / 8 + 2 ); - g_usPreviousSize = usSize; - break; + if ( g_pucOutData!= NULL ) { + if ( g_usPreviousSize == usSize ) { /*already exist*/ + break; + } + else { + free( g_pucOutData ); + g_pucOutData = NULL; + } + } + g_pucOutData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + g_usPreviousSize = usSize; + break; case MASK: - if ( g_pucOutMaskData != NULL ) { - if ( g_usPreviousSize == usSize ) {/*already allocated*/ - break; - } - else { - free( g_pucOutMaskData ); - g_pucOutMaskData = NULL; - } - } - g_pucOutMaskData = ( unsigned char * ) malloc( usSize / 8 + 2 ); - g_usPreviousSize = usSize; - break; + if ( g_pucOutMaskData != NULL ) { + if ( g_usPreviousSize == usSize ) {/*already allocated*/ + break; + } + else { + free( g_pucOutMaskData ); + g_pucOutMaskData = NULL; + } + } + g_pucOutMaskData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + g_usPreviousSize = usSize; + break; case HIR: - if ( g_pucHIRData != NULL ) { - free( g_pucHIRData ); - g_pucHIRData = NULL; - } - g_pucHIRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); - break; + if ( g_pucHIRData != NULL ) { + free( g_pucHIRData ); + g_pucHIRData = NULL; + } + g_pucHIRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + break; case TIR: - if ( g_pucTIRData != NULL ) { - free( g_pucTIRData ); - g_pucTIRData = NULL; - } - g_pucTIRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); - break; + if ( g_pucTIRData != NULL ) { + free( g_pucTIRData ); + g_pucTIRData = NULL; + } + g_pucTIRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + break; case HDR: - if ( g_pucHDRData != NULL ) { - free( g_pucHDRData ); - g_pucHDRData = NULL; - } - g_pucHDRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); - break; + if ( g_pucHDRData != NULL ) { + free( g_pucHDRData ); + g_pucHDRData = NULL; + } + g_pucHDRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + break; case TDR: - if ( g_pucTDRData != NULL ) { - free( g_pucTDRData ); - g_pucTDRData = NULL; - } - g_pucTDRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); - break; + if ( g_pucTDRData != NULL ) { + free( g_pucTDRData ); + g_pucTDRData = NULL; + } + g_pucTDRData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + break; case HEAP: - if ( g_pucHeapMemory != NULL ) { - free( g_pucHeapMemory ); - g_pucHeapMemory = NULL; - } - g_pucHeapMemory = ( unsigned char * ) malloc( usSize + 2 ); - break; - case DMASK: - if ( g_pucOutDMaskData != NULL ) { - if ( g_usPreviousSize == usSize ) { /*already allocated*/ - break; - } - else { - free( g_pucOutDMaskData ); - g_pucOutDMaskData = NULL; - } - } - g_pucOutDMaskData = ( unsigned char * ) malloc( usSize / 8 + 2 ); - g_usPreviousSize = usSize; - break; - case LHEAP: - if ( g_pucIntelBuffer != NULL ) { - free( g_pucIntelBuffer ); - g_pucIntelBuffer = NULL; - } - g_pucIntelBuffer = ( unsigned char * ) malloc( usSize + 2 ); - break; - case LVDS: - if ( g_pLVDSList != NULL ) { - free( g_pLVDSList ); - g_pLVDSList = NULL; - } - g_pLVDSList = ( LVDSPair * ) calloc( usSize, sizeof( LVDSPair ) ); - break; - default: - return; + if ( g_pucHeapMemory != NULL ) { + free( g_pucHeapMemory ); + g_pucHeapMemory = NULL; + } + g_pucHeapMemory = ( unsigned char * ) malloc( usSize + 2 ); + break; + case DMASK: + if ( g_pucOutDMaskData != NULL ) { + if ( g_usPreviousSize == usSize ) { /*already allocated*/ + break; + } + else { + free( g_pucOutDMaskData ); + g_pucOutDMaskData = NULL; + } + } + g_pucOutDMaskData = ( unsigned char * ) malloc( usSize / 8 + 2 ); + g_usPreviousSize = usSize; + break; + case LHEAP: + if ( g_pucIntelBuffer != NULL ) { + free( g_pucIntelBuffer ); + g_pucIntelBuffer = NULL; + } + g_pucIntelBuffer = ( unsigned char * ) malloc( usSize + 2 ); + break; + case LVDS: + if ( g_pLVDSList != NULL ) { + free( g_pLVDSList ); + g_pLVDSList = NULL; + } + g_pLVDSList = ( LVDSPair * ) calloc( usSize, sizeof( LVDSPair ) ); + break; + default: + return; } } @@ -391,61 +391,61 @@ void ispVMMemManager( signed char cTarget, unsigned short usSize ) void ispVMFreeMem() { - if ( g_pucHeapMemory != NULL ) { - free( g_pucHeapMemory ); - g_pucHeapMemory = NULL; - } - - if ( g_pucOutMaskData != NULL ) { - free( g_pucOutMaskData ); - g_pucOutMaskData = NULL; - } - - if ( g_pucInData != NULL ) { - free( g_pucInData ); - g_pucInData = NULL; - } - - if ( g_pucOutData != NULL ) { - free( g_pucOutData ); - g_pucOutData = NULL; - } - - if ( g_pucHIRData != NULL ) { - free( g_pucHIRData ); - g_pucHIRData = NULL; - } - - if ( g_pucTIRData != NULL ) { - free( g_pucTIRData ); - g_pucTIRData = NULL; - } - - if ( g_pucHDRData != NULL ) { - free( g_pucHDRData ); - g_pucHDRData = NULL; - } - - if ( g_pucTDRData != NULL ) { - free( g_pucTDRData ); - g_pucTDRData = NULL; - } - - if ( g_pucOutDMaskData != NULL ) { - free( g_pucOutDMaskData ); - g_pucOutDMaskData = NULL; - } - - if ( g_pucIntelBuffer != NULL ) { - free( g_pucIntelBuffer ); - g_pucIntelBuffer = NULL; - } - - if ( g_pLVDSList != NULL ) { - free( g_pLVDSList ); - g_pLVDSList = NULL; - } -} + if ( g_pucHeapMemory != NULL ) { + free( g_pucHeapMemory ); + g_pucHeapMemory = NULL; + } + + if ( g_pucOutMaskData != NULL ) { + free( g_pucOutMaskData ); + g_pucOutMaskData = NULL; + } + + if ( g_pucInData != NULL ) { + free( g_pucInData ); + g_pucInData = NULL; + } + + if ( g_pucOutData != NULL ) { + free( g_pucOutData ); + g_pucOutData = NULL; + } + + if ( g_pucHIRData != NULL ) { + free( g_pucHIRData ); + g_pucHIRData = NULL; + } + + if ( g_pucTIRData != NULL ) { + free( g_pucTIRData ); + g_pucTIRData = NULL; + } + + if ( g_pucHDRData != NULL ) { + free( g_pucHDRData ); + g_pucHDRData = NULL; + } + + if ( g_pucTDRData != NULL ) { + free( g_pucTDRData ); + g_pucTDRData = NULL; + } + + if ( g_pucOutDMaskData != NULL ) { + free( g_pucOutDMaskData ); + g_pucOutDMaskData = NULL; + } + + if ( g_pucIntelBuffer != NULL ) { + free( g_pucIntelBuffer ); + g_pucIntelBuffer = NULL; + } + + if ( g_pLVDSList != NULL ) { + free( g_pLVDSList ); + g_pLVDSList = NULL; + } +} /*************************************************************** * @@ -457,15 +457,15 @@ void ispVMFreeMem() void error_handler( short a_siRetCode, char * pszMessage ) { - const char * pszErrorMessage[] = { "pass", - "verification fail", - "can't find the file", - "wrong file type", - "file error", - "option error", - "crc verification error" }; - - strcpy( pszMessage, pszErrorMessage[ -a_siRetCode ] ); + const char * pszErrorMessage[] = { "pass", + "verification fail", + "can't find the file", + "wrong file type", + "file error", + "option error", + "crc verification error" }; + + strcpy( pszMessage, pszErrorMessage[ -a_siRetCode ] ); } /*************************************************************** * @@ -478,163 +478,163 @@ void error_handler( short a_siRetCode, char * pszMessage ) signed char ispVM( const char * a_pszFilename ) { - char szFileVersion[ 9 ] = { 0 }; - signed char cRetCode = 0; - signed char cIndex = 0; - signed char cVersionIndex = 0; - unsigned char ucReadByte = 0; - - /*************************************************************** - * - * Global variables initialization. - * - * 09/11/07 NN Added - ***************************************************************/ - g_pucHeapMemory = NULL; - g_iHeapCounter = 0; - g_iHEAPSize = 0; - g_usIntelDataIndex = 0; - g_usIntelBufferSize = 0; - g_usPreviousSize = 0; - - /*************************************************************** - * - * Open a file pointer to the VME file. - * - ***************************************************************/ - - if ( ( g_pVMEFile = fopen( a_pszFilename, "rb" ) ) == NULL ) { - return VME_FILE_READ_FAILURE; - } - g_usCalculatedCRC = 0; - g_usExpectedCRC = 0; - ucReadByte = GetByte(); - switch( ucReadByte ) { - case FILE_CRC: - - /*************************************************************** - * - * Read and store the expected CRC to do the comparison at the end. - * Only versions 3.0 and higher support CRC protection. - * - ***************************************************************/ - - g_usExpectedCRC = (unsigned char ) fgetc( g_pVMEFile ); - g_usExpectedCRC <<= 8; - g_usExpectedCRC |= fgetc( g_pVMEFile ); - - - /*************************************************************** - * - * Read and store the version of the VME file. - * - ***************************************************************/ - - for ( cIndex = 0; cIndex < 8; cIndex++ ) { - szFileVersion[ cIndex ] = GetByte(); - } - - break; - default: - - /*************************************************************** - * - * Read and store the version of the VME file. Must be version 2.0. - * - ***************************************************************/ - - szFileVersion[ 0 ] = ( signed char ) ucReadByte; - for ( cIndex = 1; cIndex < 8; cIndex++ ) { - szFileVersion[ cIndex ] = GetByte(); - } - - break; - } - - /*************************************************************** - * - * Compare the VME file version against the supported version. - * - ***************************************************************/ - - for ( cVersionIndex = 0; g_szSupportedVersions[ cVersionIndex ] != 0; cVersionIndex++ ) { - for ( cIndex = 0; cIndex < 8; cIndex++ ) { - if ( szFileVersion[ cIndex ] != g_szSupportedVersions[ cVersionIndex ][ cIndex ] ) { - cRetCode = VME_VERSION_FAILURE; - break; - } - cRetCode = 0; - } - - if ( cRetCode == 0 ) { - - /*************************************************************** - * - * Found matching version, break. - * - ***************************************************************/ - - break; - } - } - - if ( cRetCode < 0 ) { - - /*************************************************************** - * - * VME file version failed to match the supported versions. - * - ***************************************************************/ - - fclose( g_pVMEFile ); - g_pVMEFile = NULL; - return VME_VERSION_FAILURE; - } - - /*************************************************************** - * - * Enable the JTAG port to communicate with the device. + char szFileVersion[ 9 ] = { 0 }; + signed char cRetCode = 0; + signed char cIndex = 0; + signed char cVersionIndex = 0; + unsigned char ucReadByte = 0; + + /*************************************************************** + * + * Global variables initialization. + * + * 09/11/07 NN Added + ***************************************************************/ + g_pucHeapMemory = NULL; + g_iHeapCounter = 0; + g_iHEAPSize = 0; + g_usIntelDataIndex = 0; + g_usIntelBufferSize = 0; + g_usPreviousSize = 0; + + /*************************************************************** + * + * Open a file pointer to the VME file. + * + ***************************************************************/ + + if ( ( g_pVMEFile = fopen( a_pszFilename, "rb" ) ) == NULL ) { + return VME_FILE_READ_FAILURE; + } + g_usCalculatedCRC = 0; + g_usExpectedCRC = 0; + ucReadByte = GetByte(); + switch( ucReadByte ) { + case FILE_CRC: + + /*************************************************************** + * + * Read and store the expected CRC to do the comparison at the end. + * Only versions 3.0 and higher support CRC protection. + * + ***************************************************************/ + + g_usExpectedCRC = (unsigned char ) fgetc( g_pVMEFile ); + g_usExpectedCRC <<= 8; + g_usExpectedCRC |= fgetc( g_pVMEFile ); + + + /*************************************************************** + * + * Read and store the version of the VME file. + * + ***************************************************************/ + + for ( cIndex = 0; cIndex < 8; cIndex++ ) { + szFileVersion[ cIndex ] = GetByte(); + } + + break; + default: + + /*************************************************************** + * + * Read and store the version of the VME file. Must be version 2.0. + * + ***************************************************************/ + + szFileVersion[ 0 ] = ( signed char ) ucReadByte; + for ( cIndex = 1; cIndex < 8; cIndex++ ) { + szFileVersion[ cIndex ] = GetByte(); + } + + break; + } + + /*************************************************************** + * + * Compare the VME file version against the supported version. + * + ***************************************************************/ + + for ( cVersionIndex = 0; g_szSupportedVersions[ cVersionIndex ] != 0; cVersionIndex++ ) { + for ( cIndex = 0; cIndex < 8; cIndex++ ) { + if ( szFileVersion[ cIndex ] != g_szSupportedVersions[ cVersionIndex ][ cIndex ] ) { + cRetCode = VME_VERSION_FAILURE; + break; + } + cRetCode = 0; + } + + if ( cRetCode == 0 ) { + + /*************************************************************** + * + * Found matching version, break. + * + ***************************************************************/ + + break; + } + } + + if ( cRetCode < 0 ) { + + /*************************************************************** + * + * VME file version failed to match the supported versions. + * + ***************************************************************/ + + fclose( g_pVMEFile ); + g_pVMEFile = NULL; + return VME_VERSION_FAILURE; + } + + /*************************************************************** + * + * Enable the JTAG port to communicate with the device. * Set the JTAG state machine to the Test-Logic/Reset State. - * - ***************************************************************/ + * + ***************************************************************/ ispVMStart(); - /*************************************************************** - * - * Process the VME file. - * - ***************************************************************/ + /*************************************************************** + * + * Process the VME file. + * + ***************************************************************/ cRetCode = ispVMCode(); - /*************************************************************** - * - * Set the JTAG State Machine to Test-Logic/Reset state then disable + /*************************************************************** + * + * Set the JTAG State Machine to Test-Logic/Reset state then disable * the communication with the JTAG port. - * - ***************************************************************/ + * + ***************************************************************/ ispVMEnd(); - + fclose( g_pVMEFile ); - g_pVMEFile = NULL; + g_pVMEFile = NULL; + + ispVMFreeMem(); - ispVMFreeMem(); + /*************************************************************** + * + * Compare the expected CRC versus the calculated CRC. + * + ***************************************************************/ - /*************************************************************** - * - * Compare the expected CRC versus the calculated CRC. - * - ***************************************************************/ + if ( cRetCode == 0 && g_usExpectedCRC != 0 && ( g_usExpectedCRC != g_usCalculatedCRC ) ) { + printf( "Expected CRC: 0x%.4X\n", g_usExpectedCRC ); + printf( "Calculated CRC: 0x%.4X\n", g_usCalculatedCRC ); + return VME_CRC_FAILURE; + } - if ( cRetCode == 0 && g_usExpectedCRC != 0 && ( g_usExpectedCRC != g_usCalculatedCRC ) ) { - printf( "Expected CRC: 0x%.4X\n", g_usExpectedCRC ); - printf( "Calculated CRC: 0x%.4X\n", g_usCalculatedCRC ); - return VME_CRC_FAILURE; - } - return ( cRetCode ); } @@ -646,139 +646,134 @@ signed char ispVM( const char * a_pszFilename ) char *strlwr(char *str) { - char *orig = str; + char *orig = str; - for (; *str != '\0'; str++) - *str = tolower(*str); + for (; *str != '\0'; str++) + *str = tolower(*str); - return orig; + return orig; } int main( int argc, char * argv[] ) { - unsigned short iCommandLineIndex = 0; - short siRetCode = 0; - char szExtension[ 5 ] = { 0 }; - char szCommandLineArg[ 300 ] = { 0 }; - short sicalibrate = 0; - unsigned char set_freq = 0; - - //08/28/08 NN Added Calculate checksum support. - g_usChecksum = 0; - g_uiChecksumIndex = 0; - - vme_out_string( " Lattice Semiconductor Corp.\n" ); - vme_out_string( "\n ispVME(tm) V"); + unsigned short iCommandLineIndex = 0; + short siRetCode = 0; + char szExtension[ 5 ] = { 0 }; + char szCommandLineArg[ 300 ] = { 0 }; + short sicalibrate = 0; + unsigned char set_freq = 0; + + //08/28/08 NN Added Calculate checksum support. + g_usChecksum = 0; + g_uiChecksumIndex = 0; + + vme_out_string( " Lattice Semiconductor Corp.\n" ); + vme_out_string( "\n ispVME(tm) V"); vme_out_string( VME_VERSION_NUMBER ); vme_out_string(" Copyright 1998-2011.\n"); - vme_out_string( "\nFor daisy chain programming of all in-system programmable devices\n\n" ); - - if ( argc < 2 ) { - vme_out_string( "\nUsage: vme [option] vme_file [vme_file]\n" ); - vme_out_string( "Example: vme vme_file1.vme vme_file2.vme\n" ); - vme_out_string( "option -c: do the calibration.\n" ); - vme_out_string( "Example: vme -c\n" ); - vme_out_string( "Example: vme -c vme_file1.vme vme_file2.vme\n" ); - vme_out_string( "\n\n"); - exit( 1 ); - } - for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) { - strcpy( szCommandLineArg, argv[ iCommandLineIndex ] ); - if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex == 1 ) ) { - sicalibrate = 1; - } - else if ( !strcmp( strlwr( szCommandLineArg ), "-f" ) && ( iCommandLineIndex == 2 ) ) { - g_usCpu_Frequency = strtoul(argv[iCommandLineIndex+1],NULL,0); - set_freq = 1; - printf("CPU Freq set as %d MHZ\n", g_usCpu_Frequency); - } - else if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex != 1 ) ) { - vme_out_string( "Error: calibrate option -c must be the first argument\n\n" ); - exit( 1 ); - } - else if(((iCommandLineIndex >= 4)&&(set_freq == 1)) || (set_freq == 0)) - { - strcpy( szExtension, &szCommandLineArg[ strlen( szCommandLineArg ) - 4 ] ); - strlwr( szExtension ); - if ( strcmp( szExtension, ".vme" ) ) { - vme_out_string( "Error: VME files must end with the extension *.vme\n\n" ); - exit( 1 ); - } - } - } - if (iopl(3)) - { - perror("iopl"); - exit(1);/* reminder here: do not use "return", I warned */ - } - else - { + vme_out_string( "\nFor daisy chain programming of all in-system programmable devices\n\n" ); + + if ( argc < 2 ) { + vme_out_string( "\nUsage: vme [option] vme_file [vme_file]\n" ); + vme_out_string( "Example: vme vme_file1.vme vme_file2.vme\n" ); + vme_out_string( "option -c: do the calibration.\n" ); + vme_out_string( "Example: vme -c\n" ); + vme_out_string( "Example: vme -c vme_file1.vme vme_file2.vme\n" ); + vme_out_string( "\n\n"); + exit( 1 ); + } + for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) { + strcpy( szCommandLineArg, argv[ iCommandLineIndex ] ); + if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex == 1 ) ) { + sicalibrate = 1; + } + else if ( !strcmp( strlwr( szCommandLineArg ), "-f" ) && ( iCommandLineIndex == 2 ) ) { + g_usCpu_Frequency = strtoul(argv[iCommandLineIndex+1],NULL,0); + set_freq = 1; + printf("CPU Freq set as %d MHZ\n", g_usCpu_Frequency); + } + else if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex != 1 ) ) { + vme_out_string( "Error: calibrate option -c must be the first argument\n\n" ); + exit( 1 ); + } + else if(((iCommandLineIndex >= 4)&&(set_freq == 1)) || (set_freq == 0)) + { + strcpy( szExtension, &szCommandLineArg[ strlen( szCommandLineArg ) - 4 ] ); + strlwr( szExtension ); + if ( strcmp( szExtension, ".vme" ) ) { + vme_out_string( "Error: VME files must end with the extension *.vme\n\n" ); + exit( 1 ); + } + } + } + if (iopl(3)) + { + perror("iopl"); + exit(1);/* reminder here: do not use "return", I warned */ + } + else + { #ifndef IPMI_PRJ - outl_p((inl_p(0x580) | 0x40130), 0x580); - outl_p((inl_p(0x584) & 0xFFFFFECF), 0x584); - outl_p((inl_p(0x584) | 0x00040000), 0x584); + outl_p((inl_p(0x580) | 0x40130), 0x580); + outl_p((inl_p(0x584) & 0xFFFFFECF), 0x584); + outl_p((inl_p(0x584) | 0x00040000), 0x584); #else - //outl_p((inl_p(0x540) | 0x3C0), 0x540); //Pebble:2->cs,5->clk, offset 0x540 - outl_p((inl_p(0x540) | 0xFFFFFFFF), 0x540); //Pebble:2->cs,5->clk, offset 0x540 - //printf("IPMI GPIO init: 0x%x 0x%x 0x%x\n", - // inl_p(0x540), inl_p(0x544), inl_p(0x548)); - outl_p((inl_p(0x544) & 0xFFFFFFCB), 0x544); //Pebble:2,4,5->output:0 3->input:1 - outl_p((inl_p(0x544) | 0x8), 0x544); - //printf("IPMI GPIO init finished: 0x%x 0x%x 0x%x\n", - // inl_p(0x540), inl_p(0x544), inl_p(0x548)); + outl_p((inl_p(0x540) | 0xFFFFFFFF), 0x540); + outl_p((inl_p(0x544) & 0xFFFFFFCB), 0x544); + outl_p((inl_p(0x544) | 0x8), 0x544); #endif - } - /******test JTAG ports**********/ - //port_test(); - /******test JTAG ports**********/ - siRetCode = 0; - if(sicalibrate) - { - calibration(); - } - for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) { /* Process all VME files sequentially */ - strcpy( szCommandLineArg, argv[ iCommandLineIndex ] ); - if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex == 1 ) ) { - } - else if ( !strcmp( strlwr( szCommandLineArg ), "-checksum" )) {} - else if(((iCommandLineIndex >= 4)&&(set_freq == 1)) || (set_freq == 0)) - { - vme_out_string( "Processing virtual machine file ("); - vme_out_string( szCommandLineArg ); - vme_out_string (")......\n\n"); - siRetCode = ispVM( szCommandLineArg ); - if ( siRetCode < 0 ) { - break; - } - } - } - if ( siRetCode < 0 ) { - error_handler( siRetCode, szCommandLineArg ); - vme_out_string( "Failed due to "); - vme_out_string ( szCommandLineArg ); - vme_out_string ("\n\n"); - vme_out_string( "+=======+\n" ); - vme_out_string( "| FAIL! |\n" ); - vme_out_string( "+=======+\n\n" ); - } - else { - vme_out_string( "+=======+\n" ); - vme_out_string( "| PASS! |\n" ); - vme_out_string( "+=======+\n\n" ); - //08/28/08 NN Added Calculate checksum support. - if(g_usChecksum != 0) - { - g_usChecksum &= 0xFFFF; - printf("Data Checksum: %.4X\n\n",g_usChecksum); - g_usChecksum = 0; - } - } - - if (iopl(0)) - { - perror("iopl"); - exit(1);/* reminder here: do not use "return", I warned */ - } - exit( siRetCode ); -} + } + /******test JTAG ports**********/ + //port_test(); + /******test JTAG ports**********/ + siRetCode = 0; + if(sicalibrate) + { + calibration(); + } + for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) { /* Process all VME files sequentially */ + strcpy( szCommandLineArg, argv[ iCommandLineIndex ] ); + if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex == 1 ) ) { + } + else if ( !strcmp( strlwr( szCommandLineArg ), "-checksum" )) {} + else if(((iCommandLineIndex >= 4)&&(set_freq == 1)) || (set_freq == 0)) + { + vme_out_string( "Processing virtual machine file ("); + vme_out_string( szCommandLineArg ); + vme_out_string (")......\n\n"); + siRetCode = ispVM( szCommandLineArg ); + if ( siRetCode < 0 ) { + break; + } + } + } + if ( siRetCode < 0 ) { + error_handler( siRetCode, szCommandLineArg ); + vme_out_string( "Failed due to "); + vme_out_string ( szCommandLineArg ); + vme_out_string ("\n\n"); + vme_out_string( "+=======+\n" ); + vme_out_string( "| FAIL! |\n" ); + vme_out_string( "+=======+\n\n" ); + } + else { + vme_out_string( "+=======+\n" ); + vme_out_string( "| PASS! |\n" ); + vme_out_string( "+=======+\n\n" ); + //08/28/08 NN Added Calculate checksum support. + if(g_usChecksum != 0) + { + g_usChecksum &= 0xFFFF; + printf("Data Checksum: %.4X\n\n",g_usChecksum); + g_usChecksum = 0; + } + } + + if (iopl(0)) + { + perror("iopl"); + exit(1);/* reminder here: do not use "return", I warned */ + } + exit( siRetCode ); +} diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ivm_core.c b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ivm_core.c index 430d67c5a0fe..d2d2da31642e 100644 --- a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ivm_core.c +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ivm_core.c @@ -10,17 +10,17 @@ * Revision History of ivm_core.c module: * 4/25/06 ht Change some variables from unsigned short or int * to long int to make the code compiler independent. -* 5/24/06 ht Support using RESET (TRST) pin as a special purpose -* control pin such as triggering the loading of known -* state exit. +* 5/24/06 ht Support using RESET (TRST) pin as a special purpose +* control pin such as triggering the loading of known +* state exit. * 3/6/07 ht added functions to support output to terminals -* +* * 09/24/07 NN Type cast mismatch variables -* Moved the sclock() function to hardware.c +* Moved the sclock() function to hardware.c * 08/28/08 NN Added Calculate checksum support. -* 4/1/09 Nguyen replaced the recursive function call codes on +* 4/1/09 Nguyen replaced the recursive function call codes on * the ispVMLCOUNT function -* +* ***************************************************************/ #include @@ -33,22 +33,22 @@ * * Global variables used to specify the flow control and data type. * -* g_usFlowControl: flow control register. Each bit in the +* g_usFlowControl: flow control register. Each bit in the * register can potentially change the * personality of the embedded engine. -* g_usDataType: holds the data type of the current row. +* g_usDataType: holds the data type of the current row. * ***************************************************************/ -unsigned short g_usFlowControl = 0x0000; -unsigned short g_usDataType = 0x0000; +unsigned short g_usFlowControl = 0x0000; +unsigned short g_usDataType = 0x0000; /*************************************************************** * * Global variables used to specify the ENDDR and ENDIR. * -* g_ucEndDR: the state that the device goes to after SDR. -* g_ucEndIR: the state that the device goes to after SIR. +* g_ucEndDR: the state that the device goes to after SDR. +* g_ucEndIR: the state that the device goes to after SIR. * ***************************************************************/ @@ -59,10 +59,10 @@ unsigned char g_ucEndIR = IRPAUSE; * * Global variables used to support header/trailer. * -* g_usHeadDR: the number of lead devices in bypass. -* g_usHeadIR: the sum of IR length of lead devices. -* g_usTailDR: the number of tail devices in bypass. -* g_usTailIR: the sum of IR length of tail devices. +* g_usHeadDR: the number of lead devices in bypass. +* g_usHeadIR: the sum of IR length of lead devices. +* g_usTailDR: the number of tail devices in bypass. +* g_usTailIR: the sum of IR length of tail devices. * ***************************************************************/ @@ -149,29 +149,29 @@ signed char g_cCurrentJTAGState = 0; * * Global variables used to support looping. * -* g_pucHeapMemory: holds the entire repeat loop. -* g_iHeapCounter: points to the current byte in the repeat loop. -* g_iHEAPSize: the current size of the repeat in bytes. +* g_pucHeapMemory: holds the entire repeat loop. +* g_iHeapCounter: points to the current byte in the repeat loop. +* g_iHEAPSize: the current size of the repeat in bytes. * ***************************************************************/ -unsigned char * g_pucHeapMemory = NULL; -unsigned short g_iHeapCounter = 0; +unsigned char * g_pucHeapMemory = NULL; +unsigned short g_iHeapCounter = 0; unsigned short g_iHEAPSize = 0; /*************************************************************** * * Global variables used to support intelligent programming. * -* g_usIntelDataIndex: points to the current byte of the -* intelligent buffer. -* g_usIntelBufferSize: holds the size of the intelligent -* buffer. +* g_usIntelDataIndex: points to the current byte of the +* intelligent buffer. +* g_usIntelBufferSize: holds the size of the intelligent +* buffer. * ***************************************************************/ -unsigned short g_usIntelDataIndex = 0; -unsigned short g_usIntelBufferSize = 0; +unsigned short g_usIntelDataIndex = 0; +unsigned short g_usIntelBufferSize = 0; /**************************************************************************** * @@ -181,41 +181,41 @@ unsigned short g_usIntelBufferSize = 0; *****************************************************************************/ unsigned short g_usTDOSize = 0; -unsigned short g_usMASKSize = 0; -unsigned short g_usTDISize = 0; +unsigned short g_usMASKSize = 0; +unsigned short g_usTDISize = 0; unsigned short g_usDMASKSize = 0; unsigned short g_usLCOUNTSize = 0; -unsigned short g_usHDRSize = 0; -unsigned short g_usTDRSize = 0; -unsigned short g_usHIRSize = 0; -unsigned short g_usTIRSize = 0; -unsigned short g_usHeapSize = 0; +unsigned short g_usHDRSize = 0; +unsigned short g_usTDRSize = 0; +unsigned short g_usHIRSize = 0; +unsigned short g_usTIRSize = 0; +unsigned short g_usHeapSize = 0; /*************************************************************** * * Global variables used to store data. * -* g_pucOutMaskData: local RAM to hold one row of MASK data. -* g_pucInData: local RAM to hold one row of TDI data. -* g_pucOutData: local RAM to hold one row of TDO data. -* g_pucHIRData: local RAM to hold the current SIR header. -* g_pucTIRData: local RAM to hold the current SIR trailer. -* g_pucHDRData: local RAM to hold the current SDR header. -* g_pucTDRData: local RAM to hold the current SDR trailer. -* g_pucIntelBuffer: local RAM to hold the current intelligent buffer. -* g_pucOutDMaskData: local RAM to hold one row of DMASK data. +* g_pucOutMaskData: local RAM to hold one row of MASK data. +* g_pucInData: local RAM to hold one row of TDI data. +* g_pucOutData: local RAM to hold one row of TDO data. +* g_pucHIRData: local RAM to hold the current SIR header. +* g_pucTIRData: local RAM to hold the current SIR trailer. +* g_pucHDRData: local RAM to hold the current SDR header. +* g_pucTDRData: local RAM to hold the current SDR trailer. +* g_pucIntelBuffer: local RAM to hold the current intelligent buffer. +* g_pucOutDMaskData: local RAM to hold one row of DMASK data. * ***************************************************************/ -unsigned char * g_pucOutMaskData = NULL, +unsigned char * g_pucOutMaskData = NULL, * g_pucInData = NULL, - * g_pucOutData = NULL, - * g_pucHIRData = NULL, - * g_pucTIRData = NULL, - * g_pucHDRData = NULL, - * g_pucTDRData = NULL, - * g_pucIntelBuffer = NULL, - * g_pucOutDMaskData = NULL; + * g_pucOutData = NULL, + * g_pucHIRData = NULL, + * g_pucTIRData = NULL, + * g_pucHDRData = NULL, + * g_pucTDRData = NULL, + * g_pucIntelBuffer = NULL, + * g_pucOutDMaskData = NULL; /*************************************************************** * @@ -224,36 +224,36 @@ unsigned char * g_pucOutMaskData = NULL, ***************************************************************/ struct { - unsigned char CurState; /* From this state */ - unsigned char NextState; /* Step to this state */ - unsigned char Pattern; /* The tragetory of TMS */ - unsigned char Pulses; /* The number of steps */ + unsigned char CurState; /* From this state */ + unsigned char NextState; /* Step to this state */ + unsigned char Pattern; /* The tragetory of TMS */ + unsigned char Pulses; /* The number of steps */ } g_JTAGTransistions[ 25 ] = { -{ RESET, RESET, 0xFC, 6 }, /* Transitions from RESET */ -{ RESET, IDLE, 0x00, 1 }, -{ RESET, DRPAUSE, 0x50, 5 }, -{ RESET, IRPAUSE, 0x68, 6 }, -{ IDLE, RESET, 0xE0, 3 }, /* Transitions from IDLE */ -{ IDLE, DRPAUSE, 0xA0, 4 }, -{ IDLE, IRPAUSE, 0xD0, 5 }, -{ DRPAUSE, RESET, 0xF8, 5 }, /* Transitions from DRPAUSE */ -{ DRPAUSE, IDLE, 0xC0, 3 }, -{ DRPAUSE, IRPAUSE, 0xF4, 7 }, -{ DRPAUSE, DRPAUSE, 0xE8, 6 }, /* 06/14/06 Support POLING STATUS LOOP*/ -{ IRPAUSE, RESET, 0xF8, 5 }, /* Transitions from IRPAUSE */ -{ IRPAUSE, IDLE, 0xC0, 3 }, -{ IRPAUSE, DRPAUSE, 0xE8, 6 }, -{ DRPAUSE, SHIFTDR, 0x80, 2 }, /* Extra transitions using SHIFTDR */ -{ IRPAUSE, SHIFTDR, 0xE0, 5 }, -{ SHIFTDR, DRPAUSE, 0x80, 2 }, -{ SHIFTDR, IDLE, 0xC0, 3 }, -{ IRPAUSE, SHIFTIR, 0x80, 2 }, /* Extra transitions using SHIFTIR */ -{ SHIFTIR, IRPAUSE, 0x80, 2 }, -{ SHIFTIR, IDLE, 0xC0, 3 }, -{ DRPAUSE, DRCAPTURE, 0xE0, 4 }, /* 11/15/05 Support DRCAPTURE*/ -{ DRCAPTURE, DRPAUSE, 0x80, 2 }, -{ IDLE, DRCAPTURE, 0x80, 2 }, -{ IRPAUSE, DRCAPTURE, 0xE0, 4 } +{ RESET, RESET, 0xFC, 6 }, /* Transitions from RESET */ +{ RESET, IDLE, 0x00, 1 }, +{ RESET, DRPAUSE, 0x50, 5 }, +{ RESET, IRPAUSE, 0x68, 6 }, +{ IDLE, RESET, 0xE0, 3 }, /* Transitions from IDLE */ +{ IDLE, DRPAUSE, 0xA0, 4 }, +{ IDLE, IRPAUSE, 0xD0, 5 }, +{ DRPAUSE, RESET, 0xF8, 5 }, /* Transitions from DRPAUSE */ +{ DRPAUSE, IDLE, 0xC0, 3 }, +{ DRPAUSE, IRPAUSE, 0xF4, 7 }, +{ DRPAUSE, DRPAUSE, 0xE8, 6 }, /* 06/14/06 Support POLING STATUS LOOP*/ +{ IRPAUSE, RESET, 0xF8, 5 }, /* Transitions from IRPAUSE */ +{ IRPAUSE, IDLE, 0xC0, 3 }, +{ IRPAUSE, DRPAUSE, 0xE8, 6 }, +{ DRPAUSE, SHIFTDR, 0x80, 2 }, /* Extra transitions using SHIFTDR */ +{ IRPAUSE, SHIFTDR, 0xE0, 5 }, +{ SHIFTDR, DRPAUSE, 0x80, 2 }, +{ SHIFTDR, IDLE, 0xC0, 3 }, +{ IRPAUSE, SHIFTIR, 0x80, 2 }, /* Extra transitions using SHIFTIR */ +{ SHIFTIR, IRPAUSE, 0x80, 2 }, +{ SHIFTIR, IDLE, 0xC0, 3 }, +{ DRPAUSE, DRCAPTURE, 0xE0, 4 }, /* 11/15/05 Support DRCAPTURE*/ +{ DRCAPTURE, DRPAUSE, 0x80, 2 }, +{ IDLE, DRCAPTURE, 0x80, 2 }, +{ IRPAUSE, DRCAPTURE, 0xE0, 4 } }; /*************************************************************** @@ -334,26 +334,26 @@ extern const unsigned long g_ucPinTDO; const char * GetState( unsigned char a_ucState ) { - switch( a_ucState ) { - case RESET: - return( "RESET" ); - case IDLE: - return( "IDLE" ); - case IRPAUSE: - return( "IRPAUSE" ); - case DRPAUSE: - return( "DRPAUSE" ); - case SHIFTIR: - return( "SHIFTIR" ); - case SHIFTDR: - return( "SHIFTDR" ); - case DRCAPTURE:/* 11/15/05 support DRCAPTURE*/ - return( "DRCAPTURE" ); - default: - break; - } - - return 0; + switch( a_ucState ) { + case RESET: + return( "RESET" ); + case IDLE: + return( "IDLE" ); + case IRPAUSE: + return( "IRPAUSE" ); + case DRPAUSE: + return( "DRPAUSE" ); + case SHIFTIR: + return( "SHIFTIR" ); + case SHIFTDR: + return( "SHIFTDR" ); + case DRCAPTURE:/* 11/15/05 support DRCAPTURE*/ + return( "DRCAPTURE" ); + default: + break; + } + + return 0; } /*************************************************************** @@ -366,56 +366,56 @@ const char * GetState( unsigned char a_ucState ) void PrintData( unsigned short a_iDataSize, unsigned char * a_pucData ) { - //09/11/07 NN added local variables initialization - unsigned short usByteSize = 0; - unsigned short usBitIndex = 0; - signed short usByteIndex = 0; - unsigned char ucByte = 0; - unsigned char ucFlipByte = 0; - - if ( a_iDataSize % 8 ) { - //09/11/07 NN Type cast mismatch variables - usByteSize = (unsigned short)(a_iDataSize / 8 + 1); - } - else { - //09/11/07 NN Type cast mismatch variables - usByteSize = (unsigned short)(a_iDataSize / 8); - } - printf( "(" ); - //09/11/07 NN Type cast mismatch variables - for ( usByteIndex = (signed short)(usByteSize - 1); usByteIndex >= 0; usByteIndex-- ) { - ucByte = a_pucData[ usByteIndex ]; - ucFlipByte = 0x00; - - /*************************************************************** - * - * Flip each byte. - * - ***************************************************************/ - - for ( usBitIndex = 0; usBitIndex < 8; usBitIndex++ ) { - ucFlipByte <<= 1; - if ( ucByte & 0x1) { - ucFlipByte |= 0x1; - } - - ucByte >>= 1; - } - - /*************************************************************** - * - * Print the flipped byte. - * - ***************************************************************/ - - printf( "%.02X", ucFlipByte ); - if ( ( usByteSize - usByteIndex ) % 40 == 39 ) { - printf( "\n\t\t" ); - } - if(usByteIndex < 0) - break; - } - printf( ")" ); + //09/11/07 NN added local variables initialization + unsigned short usByteSize = 0; + unsigned short usBitIndex = 0; + signed short usByteIndex = 0; + unsigned char ucByte = 0; + unsigned char ucFlipByte = 0; + + if ( a_iDataSize % 8 ) { + //09/11/07 NN Type cast mismatch variables + usByteSize = (unsigned short)(a_iDataSize / 8 + 1); + } + else { + //09/11/07 NN Type cast mismatch variables + usByteSize = (unsigned short)(a_iDataSize / 8); + } + printf( "(" ); + //09/11/07 NN Type cast mismatch variables + for ( usByteIndex = (signed short)(usByteSize - 1); usByteIndex >= 0; usByteIndex-- ) { + ucByte = a_pucData[ usByteIndex ]; + ucFlipByte = 0x00; + + /*************************************************************** + * + * Flip each byte. + * + ***************************************************************/ + + for ( usBitIndex = 0; usBitIndex < 8; usBitIndex++ ) { + ucFlipByte <<= 1; + if ( ucByte & 0x1) { + ucFlipByte |= 0x1; + } + + ucByte >>= 1; + } + + /*************************************************************** + * + * Print the flipped byte. + * + ***************************************************************/ + + printf( "%.02X", ucFlipByte ); + if ( ( usByteSize - usByteIndex ) % 40 == 39 ) { + printf( "\n\t\t" ); + } + if(usByteIndex < 0) + break; + } + printf( ")" ); } #endif //VME_DEBUG @@ -430,17 +430,17 @@ void PrintData( unsigned short a_iDataSize, unsigned char * a_pucData ) long int ispVMDataSize() { - //09/11/07 NN added local variables initialization - long int iSize = 0; - signed char cCurrentByte = 0; - signed char cIndex = 0; - cIndex = 0; - while ( ( cCurrentByte = GetByte() ) & 0x80 ) { - iSize |= ( ( long int ) ( cCurrentByte & 0x7F ) ) << cIndex; - cIndex += 7; - } - iSize |= ( ( long int ) ( cCurrentByte & 0x7F ) ) << cIndex; - return iSize; + //09/11/07 NN added local variables initialization + long int iSize = 0; + signed char cCurrentByte = 0; + signed char cIndex = 0; + cIndex = 0; + while ( ( cCurrentByte = GetByte() ) & 0x80 ) { + iSize |= ( ( long int ) ( cCurrentByte & 0x7F ) ) << cIndex; + cIndex += 7; + } + iSize |= ( ( long int ) ( cCurrentByte & 0x7F ) ) << cIndex; + return iSize; } /*************************************************************** @@ -455,525 +455,525 @@ long int ispVMDataSize() signed char ispVMCode() { - //09/11/07 NN added local variables initialization - unsigned short iRepeatSize = 0; - signed char cOpcode = 0; - signed char cRetCode = 0; - unsigned char ucState = 0; - unsigned short usDelay = 0; - unsigned short usToggle = 0; - unsigned char usByte = 0; - - /*************************************************************** - * - * Check the compression flag only if this is the first time - * this function is entered. Do not check the compression flag if - * it is being called recursively from other functions within - * the embedded engine. - * - ***************************************************************/ - - if ( !( g_usDataType & LHEAP_IN ) && !( g_usDataType & HEAP_IN ) ) { - usByte = GetByte(); - if ( usByte == 0xf1 ) { - g_usDataType |= COMPRESS; - } - else if ( usByte == 0xf2 ) { - g_usDataType &= ~COMPRESS; - } - else { - return VME_INVALID_FILE; - } - } - - /*************************************************************** - * - * Begin looping through all the VME opcodes. - * - ***************************************************************/ - - while ( ( cOpcode = GetByte() ) >= 0 ) { - - switch ( cOpcode ) { - case STATE: - - /*************************************************************** - * - * Step the JTAG state machine. - * - ***************************************************************/ - - ucState = GetByte(); - - /*************************************************************** - * - * Step the JTAG state machine to DRCAPTURE to support Looping. - * - ***************************************************************/ - - if ( (g_usDataType & LHEAP_IN) && - (ucState == DRPAUSE ) && - ( g_cCurrentJTAGState == ucState )) - { - ispVMStateMachine( DRCAPTURE ); - } - - ispVMStateMachine( ucState ); + //09/11/07 NN added local variables initialization + unsigned short iRepeatSize = 0; + signed char cOpcode = 0; + signed char cRetCode = 0; + unsigned char ucState = 0; + unsigned short usDelay = 0; + unsigned short usToggle = 0; + unsigned char usByte = 0; + + /*************************************************************** + * + * Check the compression flag only if this is the first time + * this function is entered. Do not check the compression flag if + * it is being called recursively from other functions within + * the embedded engine. + * + ***************************************************************/ + + if ( !( g_usDataType & LHEAP_IN ) && !( g_usDataType & HEAP_IN ) ) { + usByte = GetByte(); + if ( usByte == 0xf1 ) { + g_usDataType |= COMPRESS; + } + else if ( usByte == 0xf2 ) { + g_usDataType &= ~COMPRESS; + } + else { + return VME_INVALID_FILE; + } + } + + /*************************************************************** + * + * Begin looping through all the VME opcodes. + * + ***************************************************************/ + + while ( ( cOpcode = GetByte() ) >= 0 ) { + + switch ( cOpcode ) { + case STATE: + + /*************************************************************** + * + * Step the JTAG state machine. + * + ***************************************************************/ + + ucState = GetByte(); + + /*************************************************************** + * + * Step the JTAG state machine to DRCAPTURE to support Looping. + * + ***************************************************************/ + + if ( (g_usDataType & LHEAP_IN) && + (ucState == DRPAUSE ) && + ( g_cCurrentJTAGState == ucState )) + { + ispVMStateMachine( DRCAPTURE ); + } + + ispVMStateMachine( ucState ); #ifdef VME_DEBUG - if ( g_usDataType & LHEAP_IN ) { - printf( "LDELAY %s ", GetState( ucState ) ); - } - else { - printf( "STATE %s;\n", GetState( ucState ) ); - } + if ( g_usDataType & LHEAP_IN ) { + printf( "LDELAY %s ", GetState( ucState ) ); + } + else { + printf( "STATE %s;\n", GetState( ucState ) ); + } #endif //VME_DEBUG - break; - case SIR: - case SDR: - case XSDR: + break; + case SIR: + case SDR: + case XSDR: #ifdef VME_DEBUG - switch( cOpcode ) { - case SIR: - printf( "SIR " ); - break; - case SDR: - case XSDR: - if ( g_usDataType & LHEAP_IN ) { - printf( "LSDR " ); - } - else { - printf( "SDR " ); - } - break; - } + switch( cOpcode ) { + case SIR: + printf( "SIR " ); + break; + case SDR: + case XSDR: + if ( g_usDataType & LHEAP_IN ) { + printf( "LSDR " ); + } + else { + printf( "SDR " ); + } + break; + } #endif //VME_DEBUG - /*************************************************************** - * - * Shift in data into the device. - * - ***************************************************************/ - - cRetCode = ispVMShift( cOpcode ); - if ( cRetCode != 0 ) { - return ( cRetCode ); - } - break; - case WAIT: - - /*************************************************************** - * - * Observe delay. - * - ***************************************************************/ - - //09/11/07 NN Type cast mismatch variables - usDelay = (unsigned short) ispVMDataSize(); - ispVMDelay( usDelay ); + /*************************************************************** + * + * Shift in data into the device. + * + ***************************************************************/ + + cRetCode = ispVMShift( cOpcode ); + if ( cRetCode != 0 ) { + return ( cRetCode ); + } + break; + case WAIT: + + /*************************************************************** + * + * Observe delay. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + usDelay = (unsigned short) ispVMDataSize(); + ispVMDelay( usDelay ); #ifdef VME_DEBUG - if ( usDelay & 0x8000 ) { - - /*************************************************************** - * - * Since MSB is set, the delay time must be decoded to - * millisecond. The SVF2VME encodes the MSB to represent - * millisecond. - * - ***************************************************************/ - - usDelay &= ~0x8000; - if ( g_usDataType & LHEAP_IN ) { - printf( "%.2E SEC;\n", ( float ) usDelay / 1000 ); - } - else { - printf( "RUNTEST %.2E SEC;\n", ( float ) usDelay / 1000 ); - } - } - else { - - /*************************************************************** - * - * Since MSB is not set, the delay time is given as microseconds. - * - ***************************************************************/ - - if ( g_usDataType & LHEAP_IN ) { - printf( "%.2E SEC;\n", ( float ) usDelay / 1000000 ); - } - else { - printf( "RUNTEST %.2E SEC;\n", ( float ) usDelay / 1000000 ); - } - } + if ( usDelay & 0x8000 ) { + + /*************************************************************** + * + * Since MSB is set, the delay time must be decoded to + * millisecond. The SVF2VME encodes the MSB to represent + * millisecond. + * + ***************************************************************/ + + usDelay &= ~0x8000; + if ( g_usDataType & LHEAP_IN ) { + printf( "%.2E SEC;\n", ( float ) usDelay / 1000 ); + } + else { + printf( "RUNTEST %.2E SEC;\n", ( float ) usDelay / 1000 ); + } + } + else { + + /*************************************************************** + * + * Since MSB is not set, the delay time is given as microseconds. + * + ***************************************************************/ + + if ( g_usDataType & LHEAP_IN ) { + printf( "%.2E SEC;\n", ( float ) usDelay / 1000000 ); + } + else { + printf( "RUNTEST %.2E SEC;\n", ( float ) usDelay / 1000000 ); + } + } #endif //VME_DEBUG - break; - case TCK: + break; + case TCK: - /*************************************************************** - * - * Issue clock toggles. - * - ***************************************************************/ + /*************************************************************** + * + * Issue clock toggles. + * + ***************************************************************/ - //09/11/07 NN Type cast mismatch variables - usToggle = (unsigned short) ispVMDataSize(); - ispVMClocks( usToggle ); + //09/11/07 NN Type cast mismatch variables + usToggle = (unsigned short) ispVMDataSize(); + ispVMClocks( usToggle ); #ifdef VME_DEBUG - printf( "RUNTEST %d TCK;\n", usToggle ); + printf( "RUNTEST %d TCK;\n", usToggle ); #endif //VME_DEBUG - break; - case ENDDR: + break; + case ENDDR: - /*************************************************************** - * - * Set the ENDDR. - * - ***************************************************************/ + /*************************************************************** + * + * Set the ENDDR. + * + ***************************************************************/ - g_ucEndDR = GetByte(); + g_ucEndDR = GetByte(); #ifdef VME_DEBUG - printf( "ENDDR %s;\n", GetState( g_ucEndDR ) ); + printf( "ENDDR %s;\n", GetState( g_ucEndDR ) ); #endif //VME_DEBUG - break; - case ENDIR: + break; + case ENDIR: - /*************************************************************** - * - * Set the ENDIR. - * - ***************************************************************/ + /*************************************************************** + * + * Set the ENDIR. + * + ***************************************************************/ - g_ucEndIR = GetByte(); + g_ucEndIR = GetByte(); #ifdef VME_DEBUG - printf( "ENDIR %s;\n", GetState( g_ucEndIR ) ); + printf( "ENDIR %s;\n", GetState( g_ucEndIR ) ); #endif //VME_DEBUG - break; - case HIR: - case TIR: - case HDR: - case TDR: + break; + case HIR: + case TIR: + case HDR: + case TDR: #ifdef VME_DEBUG - switch( cOpcode ) { - case HIR: - printf( "HIR " ); - break; - case TIR: - printf( "TIR " ); - break; - case HDR: - printf( "HDR " ); - break; - case TDR: - printf( "TDR " ); - break; - } + switch( cOpcode ) { + case HIR: + printf( "HIR " ); + break; + case TIR: + printf( "TIR " ); + break; + case HDR: + printf( "HDR " ); + break; + case TDR: + printf( "TDR " ); + break; + } #endif //VME_DEBUG - - /*************************************************************** - * - * Set the header/trailer of the device in order to bypass - * successfully. - * - ***************************************************************/ - - cRetCode = ispVMAmble( cOpcode ); - if ( cRetCode != 0 ) { - return ( cRetCode ); - } + + /*************************************************************** + * + * Set the header/trailer of the device in order to bypass + * successfully. + * + ***************************************************************/ + + cRetCode = ispVMAmble( cOpcode ); + if ( cRetCode != 0 ) { + return ( cRetCode ); + } #ifdef VME_DEBUG - printf( ";\n" ); + printf( ";\n" ); #endif //VME_DEBUG - break; - case MEM: + break; + case MEM: - /*************************************************************** - * - * The maximum RAM required to support processing one row of the - * VME file. - * - ***************************************************************/ + /*************************************************************** + * + * The maximum RAM required to support processing one row of the + * VME file. + * + ***************************************************************/ - //09/11/07 NN Type cast mismatch variables - g_usMaxSize = (unsigned short) ispVMDataSize(); + //09/11/07 NN Type cast mismatch variables + g_usMaxSize = (unsigned short) ispVMDataSize(); #ifdef VME_DEBUG - printf( "// MEMSIZE %d\n", g_usMaxSize ); + printf( "// MEMSIZE %d\n", g_usMaxSize ); #endif //VME_DEBUG - break; - case VENDOR: - - /*************************************************************** - * - * Set the VENDOR type. - * - ***************************************************************/ - - cOpcode = GetByte(); - switch ( cOpcode ) { - case LATTICE: + break; + case VENDOR: + + /*************************************************************** + * + * Set the VENDOR type. + * + ***************************************************************/ + + cOpcode = GetByte(); + switch ( cOpcode ) { + case LATTICE: #ifdef VME_DEBUG - printf( "// VENDOR LATTICE\n" ); + printf( "// VENDOR LATTICE\n" ); #endif //VME_DEBUG - g_cVendor = LATTICE; - break; - case ALTERA: + g_cVendor = LATTICE; + break; + case ALTERA: #ifdef VME_DEBUG - printf( "// VENDOR ALTERA\n" ); + printf( "// VENDOR ALTERA\n" ); #endif //VME_DEBUG - g_cVendor = ALTERA; - break; - case XILINX: + g_cVendor = ALTERA; + break; + case XILINX: #ifdef VME_DEBUG - printf( "// VENDOR XILINX\n" ); + printf( "// VENDOR XILINX\n" ); #endif //VME_DEBUG - g_cVendor = XILINX; - break; - default: - break; - } - break; - case SETFLOW: - - /*************************************************************** - * - * Set the flow control. Flow control determines the personality - * of the embedded engine. - * - ***************************************************************/ - - //09/11/07 NN Type cast mismatch variables - g_usFlowControl |= (unsigned short) ispVMDataSize(); - break; - case RESETFLOW: - - /*************************************************************** - * - * Unset the flow control. - * - ***************************************************************/ - - //09/11/07 NN Type cast mismatch variables - g_usFlowControl &= (unsigned short) ~( ispVMDataSize() ); - break; - case HEAP: - - /*************************************************************** - * - * Allocate heap size to store loops. - * - ***************************************************************/ - - cRetCode = GetByte(); - if ( cRetCode != SECUREHEAP ) { - return VME_INVALID_FILE; - } - //09/11/07 NN Type cast mismatch variables - g_iHEAPSize = (unsigned short) ispVMDataSize(); - - /**************************************************************************** - * - * Store the maximum size of the HEAP buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_iHEAPSize > g_usHeapSize ) { - g_usHeapSize = g_iHEAPSize; - } - - ispVMMemManager( HEAP, ( unsigned short ) g_iHEAPSize ); - break; - case REPEAT: - - /*************************************************************** - * - * Execute loops. - * - ***************************************************************/ - - g_usRepeatLoops = 0; - - //09/11/07 NN Type cast mismatch variables - iRepeatSize = (unsigned short) ispVMDataSize(); - - cRetCode = ispVMLoop( ( unsigned short ) iRepeatSize ); - if ( cRetCode != 0 ) { - return ( cRetCode ); - } - break; - case ENDLOOP: - - /*************************************************************** - * - * Exit point from processing loops. - * - ***************************************************************/ - - return ( cRetCode ); - case ENDVME: - - /*************************************************************** - * - * The only valid exit point that indicates end of programming. - * - ***************************************************************/ - - return ( cRetCode ); - case SHR: - - /*************************************************************** - * - * Right-shift address. - * - ***************************************************************/ - - g_usFlowControl |= SHIFTRIGHT; - - //09/11/07 NN Type cast mismatch variables - g_usShiftValue = (unsigned short) (g_usRepeatLoops * (unsigned short)GetByte()); - break; - case SHL: - - /*************************************************************** - * - * Left-shift address. - * - ***************************************************************/ - - g_usFlowControl |= SHIFTLEFT; - - //09/11/07 NN Type cast mismatch variables - g_usShiftValue = (unsigned short)(g_usRepeatLoops * (unsigned short)GetByte()); - break; - case FREQUENCY: - - /*************************************************************** - * - * Set the frequency. - * - ***************************************************************/ - - //09/11/07 NN Type cast mismatch variables - g_iFrequency = (int) (ispVMDataSize() ); - //10/23/08 NN changed to check if the frequency smaller than 1000 - if(g_iFrequency >= 1000) - { - g_iFrequency = g_iFrequency / 1000; - if(g_iFrequency == 1) - g_iFrequency = 1000; + g_cVendor = XILINX; + break; + default: + break; + } + break; + case SETFLOW: + + /*************************************************************** + * + * Set the flow control. Flow control determines the personality + * of the embedded engine. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + g_usFlowControl |= (unsigned short) ispVMDataSize(); + break; + case RESETFLOW: + + /*************************************************************** + * + * Unset the flow control. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + g_usFlowControl &= (unsigned short) ~( ispVMDataSize() ); + break; + case HEAP: + + /*************************************************************** + * + * Allocate heap size to store loops. + * + ***************************************************************/ + + cRetCode = GetByte(); + if ( cRetCode != SECUREHEAP ) { + return VME_INVALID_FILE; + } + //09/11/07 NN Type cast mismatch variables + g_iHEAPSize = (unsigned short) ispVMDataSize(); + + /**************************************************************************** + * + * Store the maximum size of the HEAP buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_iHEAPSize > g_usHeapSize ) { + g_usHeapSize = g_iHEAPSize; + } + + ispVMMemManager( HEAP, ( unsigned short ) g_iHEAPSize ); + break; + case REPEAT: + + /*************************************************************** + * + * Execute loops. + * + ***************************************************************/ + + g_usRepeatLoops = 0; + + //09/11/07 NN Type cast mismatch variables + iRepeatSize = (unsigned short) ispVMDataSize(); + + cRetCode = ispVMLoop( ( unsigned short ) iRepeatSize ); + if ( cRetCode != 0 ) { + return ( cRetCode ); + } + break; + case ENDLOOP: + + /*************************************************************** + * + * Exit point from processing loops. + * + ***************************************************************/ + + return ( cRetCode ); + case ENDVME: + + /*************************************************************** + * + * The only valid exit point that indicates end of programming. + * + ***************************************************************/ + + return ( cRetCode ); + case SHR: + + /*************************************************************** + * + * Right-shift address. + * + ***************************************************************/ + + g_usFlowControl |= SHIFTRIGHT; + + //09/11/07 NN Type cast mismatch variables + g_usShiftValue = (unsigned short) (g_usRepeatLoops * (unsigned short)GetByte()); + break; + case SHL: + + /*************************************************************** + * + * Left-shift address. + * + ***************************************************************/ + + g_usFlowControl |= SHIFTLEFT; + + //09/11/07 NN Type cast mismatch variables + g_usShiftValue = (unsigned short)(g_usRepeatLoops * (unsigned short)GetByte()); + break; + case FREQUENCY: + + /*************************************************************** + * + * Set the frequency. + * + ***************************************************************/ + + //09/11/07 NN Type cast mismatch variables + g_iFrequency = (int) (ispVMDataSize() ); + //10/23/08 NN changed to check if the frequency smaller than 1000 + if(g_iFrequency >= 1000) + { + g_iFrequency = g_iFrequency / 1000; + if(g_iFrequency == 1) + g_iFrequency = 1000; #ifdef VME_DEBUG - printf( "FREQUENCY %.2E HZ;\n", ( float ) g_iFrequency * 1000 ); + printf( "FREQUENCY %.2E HZ;\n", ( float ) g_iFrequency * 1000 ); #endif //VME_DEBUG - } - else - { - if(g_iFrequency == 0) - g_iFrequency = 1000; + } + else + { + if(g_iFrequency == 0) + g_iFrequency = 1000; #ifdef VME_DEBUG - printf( "FREQUENCY %.2E HZ;\n", ( float ) g_iFrequency ); + printf( "FREQUENCY %.2E HZ;\n", ( float ) g_iFrequency ); #endif //VME_DEBUG - } - break; - case LCOUNT: - - /*************************************************************** - * - * Process LCOUNT command. - * - ***************************************************************/ - - cRetCode = ispVMLCOUNT( ( unsigned short ) ispVMDataSize() ); - if ( cRetCode != 0 ) { - return ( cRetCode ); - } - break; - case VUES: - - /*************************************************************** - * - * Set the flow control to verify USERCODE. - * - ***************************************************************/ - - g_usFlowControl |= VERIFYUES; - break; - case COMMENT: - - /*************************************************************** - * - * Display comment. - * - ***************************************************************/ - - ispVMComment( ( unsigned short ) ispVMDataSize() ); - break; - case LVDS: - - /*************************************************************** - * - * Process LVDS command. - * - ***************************************************************/ - - ispVMProcessLVDS( ( unsigned short ) ispVMDataSize() ); - break; - case HEADER: - - /*************************************************************** - * - * Discard header. - * - ***************************************************************/ - - ispVMHeader( ( unsigned short ) ispVMDataSize() ); - break; - /* 03/14/06 Support Toggle ispENABLE signal*/ - case ispEN: - ucState = GetByte(); - if((ucState == ON)||(ucState == 0x01)) - writePort( g_ucPinENABLE, 0x01 ); - else - writePort( g_ucPinENABLE, 0x00 ); - ispVMDelay( 1 ); - break; + } + break; + case LCOUNT: + + /*************************************************************** + * + * Process LCOUNT command. + * + ***************************************************************/ + + cRetCode = ispVMLCOUNT( ( unsigned short ) ispVMDataSize() ); + if ( cRetCode != 0 ) { + return ( cRetCode ); + } + break; + case VUES: + + /*************************************************************** + * + * Set the flow control to verify USERCODE. + * + ***************************************************************/ + + g_usFlowControl |= VERIFYUES; + break; + case COMMENT: + + /*************************************************************** + * + * Display comment. + * + ***************************************************************/ + + ispVMComment( ( unsigned short ) ispVMDataSize() ); + break; + case LVDS: + + /*************************************************************** + * + * Process LVDS command. + * + ***************************************************************/ + + ispVMProcessLVDS( ( unsigned short ) ispVMDataSize() ); + break; + case HEADER: + + /*************************************************************** + * + * Discard header. + * + ***************************************************************/ + + ispVMHeader( ( unsigned short ) ispVMDataSize() ); + break; + /* 03/14/06 Support Toggle ispENABLE signal*/ + case ispEN: + ucState = GetByte(); + if((ucState == ON)||(ucState == 0x01)) + writePort( g_ucPinENABLE, 0x01 ); + else + writePort( g_ucPinENABLE, 0x00 ); + ispVMDelay( 1 ); + break; /* 05/24/06 support Toggle TRST pin*/ - case TRST: - ucState = GetByte(); - if(ucState == 0x01) - writePort( g_ucPinTRST, 0x01 ); - else - writePort( g_ucPinTRST, 0x00 ); - ispVMDelay( 1 ); - break; - default: - - /*************************************************************** - * - * Invalid opcode encountered. - * - ***************************************************************/ + case TRST: + ucState = GetByte(); + if(ucState == 0x01) + writePort( g_ucPinTRST, 0x01 ); + else + writePort( g_ucPinTRST, 0x00 ); + ispVMDelay( 1 ); + break; + default: + + /*************************************************************** + * + * Invalid opcode encountered. + * + ***************************************************************/ #ifdef VME_DEBUG - printf( "\nINVALID OPCODE: 0x%.2X\n", cOpcode ); + printf( "\nINVALID OPCODE: 0x%.2X\n", cOpcode ); #endif //VME_DEBUG - return VME_INVALID_FILE; - } - } - - /*************************************************************** - * - * Invalid exit point. Processing the token 'ENDVME' is the only - * valid way to exit the embedded engine. - * - ***************************************************************/ - - return ( VME_INVALID_FILE ); + return VME_INVALID_FILE; + } + } + + /*************************************************************** + * + * Invalid exit point. Processing the token 'ENDVME' is the only + * valid way to exit the embedded engine. + * + ***************************************************************/ + + return ( VME_INVALID_FILE ); } /*************************************************************** @@ -986,215 +986,215 @@ signed char ispVMCode() signed char ispVMDataCode() { - //09/11/07 NN added local variables initialization - signed char cDataByte = 0; - signed char siDataSource = 0; /*source of data from file by default*/ - - if ( g_usDataType & HEAP_IN ) { - siDataSource = 1; /*the source of data from memory*/ - } - - /**************************************************************************** - * - * Clear the data type register. - * - *****************************************************************************/ - - g_usDataType &= ~( MASK_DATA + TDI_DATA + TDO_DATA + DMASK_DATA + CMASK_DATA ); - - /**************************************************************************** - * - * Iterate through SIR/SDR command and look for TDI, TDO, MASK, etc. - * - *****************************************************************************/ - - while ( ( cDataByte = GetByte() ) >= 0 ) { - - ispVMMemManager( cDataByte, g_usMaxSize ); - switch ( cDataByte ) { - case TDI: - - /**************************************************************************** - * - * Store the maximum size of the TDI buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usTDISize ) { - g_usTDISize = g_usiDataSize; - } - /**************************************************************************** - * - * Updated data type register to indicate that TDI data is currently being - * used. Process the data in the VME file into the TDI buffer. - * - *****************************************************************************/ - - g_usDataType |= TDI_DATA; - ispVMData( g_pucInData ); - break; - case XTDO: - - /**************************************************************************** - * - * Store the maximum size of the TDO buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usTDOSize ) { - g_usTDOSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Updated data type register to indicate that TDO data is currently being - * used. - * - *****************************************************************************/ - - g_usDataType |= TDO_DATA; - break; + //09/11/07 NN added local variables initialization + signed char cDataByte = 0; + signed char siDataSource = 0; /*source of data from file by default*/ + + if ( g_usDataType & HEAP_IN ) { + siDataSource = 1; /*the source of data from memory*/ + } + + /**************************************************************************** + * + * Clear the data type register. + * + *****************************************************************************/ + + g_usDataType &= ~( MASK_DATA + TDI_DATA + TDO_DATA + DMASK_DATA + CMASK_DATA ); + + /**************************************************************************** + * + * Iterate through SIR/SDR command and look for TDI, TDO, MASK, etc. + * + *****************************************************************************/ + + while ( ( cDataByte = GetByte() ) >= 0 ) { + + ispVMMemManager( cDataByte, g_usMaxSize ); + switch ( cDataByte ) { + case TDI: + + /**************************************************************************** + * + * Store the maximum size of the TDI buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTDISize ) { + g_usTDISize = g_usiDataSize; + } + /**************************************************************************** + * + * Updated data type register to indicate that TDI data is currently being + * used. Process the data in the VME file into the TDI buffer. + * + *****************************************************************************/ + + g_usDataType |= TDI_DATA; + ispVMData( g_pucInData ); + break; + case XTDO: + + /**************************************************************************** + * + * Store the maximum size of the TDO buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTDOSize ) { + g_usTDOSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Updated data type register to indicate that TDO data is currently being + * used. + * + *****************************************************************************/ + + g_usDataType |= TDO_DATA; + break; case TDO: - /**************************************************************************** - * - * Store the maximum size of the TDO buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usTDOSize ) { - g_usTDOSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Updated data type register to indicate that TDO data is currently being - * used. Process the data in the VME file into the TDO buffer. - * - *****************************************************************************/ - - g_usDataType |= TDO_DATA; - ispVMData( g_pucOutData ); - break; + /**************************************************************************** + * + * Store the maximum size of the TDO buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTDOSize ) { + g_usTDOSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Updated data type register to indicate that TDO data is currently being + * used. Process the data in the VME file into the TDO buffer. + * + *****************************************************************************/ + + g_usDataType |= TDO_DATA; + ispVMData( g_pucOutData ); + break; case MASK: - /**************************************************************************** - * - * Store the maximum size of the MASK buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usMASKSize ) { - g_usMASKSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Updated data type register to indicate that MASK data is currently being - * used. Process the data in the VME file into the MASK buffer. - * - *****************************************************************************/ - - g_usDataType |= MASK_DATA; - ispVMData( g_pucOutMaskData ); - break; - case DMASK: - - /**************************************************************************** - * - * Store the maximum size of the DMASK buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usDMASKSize ) { - g_usDMASKSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Updated data type register to indicate that DMASK data is currently being - * used. Process the data in the VME file into the DMASK buffer. - * - *****************************************************************************/ - - g_usDataType |= DMASK_DATA; - ispVMData( g_pucOutDMaskData ); - break; - case CMASK: - - /**************************************************************************** - * - * Updated data type register to indicate that CMASK data is currently being - * used. Process the data in the VME file into the CMASK buffer. - * - *****************************************************************************/ - - g_usDataType |= CMASK_DATA; - ispVMData( g_pucOutMaskData ); - break; - case CONTINUE: - return ( 0 ); - default: - - /**************************************************************************** - * - * Encountered invalid opcode. - * - *****************************************************************************/ - - return ( VME_INVALID_FILE ); - } - - switch ( cDataByte ) { - case TDI: - - /**************************************************************************** - * - * Left bit shift. Used when performing algorithm looping. - * - *****************************************************************************/ - - if ( g_usFlowControl & SHIFTLEFT ) { - ispVMBitShift( SHL, g_usShiftValue ); - g_usFlowControl &= ~SHIFTLEFT; - } - - /**************************************************************************** - * - * Right bit shift. Used when performing algorithm looping. - * - *****************************************************************************/ - - if ( g_usFlowControl & SHIFTRIGHT ) { - ispVMBitShift( SHR, g_usShiftValue ); - g_usFlowControl &= ~SHIFTRIGHT; - } - default: - break; - } - - if ( siDataSource ) { - g_usDataType |= HEAP_IN; /*restore data from memory*/ - } - } - - if ( siDataSource ) { /*fetch data from heap memory upon return*/ - g_usDataType |= HEAP_IN; - } - - if ( cDataByte < 0 ) { - - /**************************************************************************** - * - * Encountered invalid opcode. - * - *****************************************************************************/ - - return ( VME_INVALID_FILE ); - } - else { - return ( 0 ); - } + /**************************************************************************** + * + * Store the maximum size of the MASK buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usMASKSize ) { + g_usMASKSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Updated data type register to indicate that MASK data is currently being + * used. Process the data in the VME file into the MASK buffer. + * + *****************************************************************************/ + + g_usDataType |= MASK_DATA; + ispVMData( g_pucOutMaskData ); + break; + case DMASK: + + /**************************************************************************** + * + * Store the maximum size of the DMASK buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usDMASKSize ) { + g_usDMASKSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Updated data type register to indicate that DMASK data is currently being + * used. Process the data in the VME file into the DMASK buffer. + * + *****************************************************************************/ + + g_usDataType |= DMASK_DATA; + ispVMData( g_pucOutDMaskData ); + break; + case CMASK: + + /**************************************************************************** + * + * Updated data type register to indicate that CMASK data is currently being + * used. Process the data in the VME file into the CMASK buffer. + * + *****************************************************************************/ + + g_usDataType |= CMASK_DATA; + ispVMData( g_pucOutMaskData ); + break; + case CONTINUE: + return ( 0 ); + default: + + /**************************************************************************** + * + * Encountered invalid opcode. + * + *****************************************************************************/ + + return ( VME_INVALID_FILE ); + } + + switch ( cDataByte ) { + case TDI: + + /**************************************************************************** + * + * Left bit shift. Used when performing algorithm looping. + * + *****************************************************************************/ + + if ( g_usFlowControl & SHIFTLEFT ) { + ispVMBitShift( SHL, g_usShiftValue ); + g_usFlowControl &= ~SHIFTLEFT; + } + + /**************************************************************************** + * + * Right bit shift. Used when performing algorithm looping. + * + *****************************************************************************/ + + if ( g_usFlowControl & SHIFTRIGHT ) { + ispVMBitShift( SHR, g_usShiftValue ); + g_usFlowControl &= ~SHIFTRIGHT; + } + default: + break; + } + + if ( siDataSource ) { + g_usDataType |= HEAP_IN; /*restore data from memory*/ + } + } + + if ( siDataSource ) { /*fetch data from heap memory upon return*/ + g_usDataType |= HEAP_IN; + } + + if ( cDataByte < 0 ) { + + /**************************************************************************** + * + * Encountered invalid opcode. + * + *****************************************************************************/ + + return ( VME_INVALID_FILE ); + } + else { + return ( 0 ); + } } /*************************************************************** @@ -1210,14 +1210,14 @@ signed char ispVMDataCode() * Example: * Original stream: 0x000000000000000000000001 * Compressed stream: 0x01000901 -* Detail: 0x01 is the code, 0x00 is the key, +* Detail: 0x01 is the code, 0x00 is the key, * 0x09 is the count of 0x00 bytes, * 0x01 is the uncompressed byte. * 0x02 --Compress by 0xFF. * Example: * Original stream: 0xFFFFFFFFFFFFFFFFFFFFFF01 * Compressed stream: 0x02FF0901 -* Detail: 0x02 is the code, 0xFF is the key, +* Detail: 0x02 is the code, 0xFF is the key, * 0x09 is the count of 0xFF bytes, * 0x01 is the uncompressed byte. * 0x03 @@ -1246,132 +1246,132 @@ signed char ispVMDataCode() void ispVMData( unsigned char * ByteData ) { - //09/11/07 NN added local variables initialization - unsigned short size = 0; - unsigned short i, j, m, getData = 0; - unsigned char cDataByte = 0; - unsigned char compress = 0; - unsigned short FFcount = 0; - unsigned char compr_char = 0xFF; - unsigned short index = 0; - signed char compression = 0; - - /*convert number in bits to bytes*/ - if (g_usiDataSize%8>0) { - //09/11/07 NN Type cast mismatch variables - size = (unsigned short)(g_usiDataSize/8 + 1); - } - else { - //09/11/07 NN Type cast mismatch variables - size = (unsigned short)(g_usiDataSize/8); - } - - /* If there is compression, then check if compress by key of 0x00 or 0xFF - or by other keys or by nibble blocks*/ - - if ( g_usDataType & COMPRESS ) { - compression = 1; - if ( ( ( compress = GetByte() ) == VAR ) && ( g_usDataType & HEAP_IN ) ) { - getData = 1; - g_usDataType &= ~(HEAP_IN); - compress = GetByte(); - } - - switch (compress){ - case 0x00: - /* No compression */ - compression = 0; - break; - case 0x01: - /* Compress by byte 0x00 */ - compr_char = 0x00; - break; - case 0x02: - /* Compress by byte 0xFF */ - compr_char = 0xFF; - break; - case 0xFF: - /* Huffman encoding */ - compr_char = GetByte(); - i = 8; - for ( index = 0; index < size; index++ ) { - ByteData[ index ] = 0x00; - if ( i > 7 ) { - cDataByte = GetByte(); - i = 0; - } - if ((cDataByte << i++) & 0x80) - m = 8; - else { - ByteData[index] = compr_char; - m = 0; - } - - for (j = 0; j < m; j++) { - if (i > 7) { - cDataByte = GetByte(); - i = 0; - } - ByteData[index] |=((cDataByte << i++)&0x80) >> j; - } - } - size = 0; - break; - default: - for (index = 0; index < size; index++) - ByteData[index] = 0x00; - for (index = 0; index < compress; index++) { - if (index%2 == 0) - cDataByte = GetByte(); - for (i = 0; i < size*2/compress; i++){ - //09/11/07 NN Type cast mismatch variables - j = (unsigned short)(index + (i*(unsigned short)compress)); - /*clear the nibble to zero first*/ - if (j%2) { - if (index%2) - ByteData[j/2] |= cDataByte & 0x0F; - else - ByteData[j/2] |= cDataByte >> 4; - } - else { - if (index%2) - ByteData[j/2] |= cDataByte << 4; - else - ByteData[j/2] |= cDataByte & 0xF0; - } - } - } - size = 0; - break; - } - } - - FFcount = 0; - - /* Decompress by byte 0x00 or 0xFF */ - for (index = 0; index < size; index++) { - if (FFcount <= 0) { - cDataByte = GetByte(); - if ((cDataByte == VAR) && (g_usDataType&HEAP_IN) && !getData && !(g_usDataType&COMPRESS)) { - getData = 1; - g_usDataType &= ~(HEAP_IN); - cDataByte = GetByte(); - } - ByteData[index] = cDataByte; - if ((compression) &&(cDataByte == compr_char)) /*decompression is on*/ - //09/11/07 NN Type cast mismatch variables - FFcount = (unsigned short) ispVMDataSize(); /*The number of 0xFF or 0x00 bytes*/ - } - else { - FFcount--; /*Use up the 0xFF chain first*/ - ByteData[index] = compr_char; - } - } - - if (getData) { - g_usDataType |= HEAP_IN; - getData = 0; - } + //09/11/07 NN added local variables initialization + unsigned short size = 0; + unsigned short i, j, m, getData = 0; + unsigned char cDataByte = 0; + unsigned char compress = 0; + unsigned short FFcount = 0; + unsigned char compr_char = 0xFF; + unsigned short index = 0; + signed char compression = 0; + + /*convert number in bits to bytes*/ + if (g_usiDataSize%8>0) { + //09/11/07 NN Type cast mismatch variables + size = (unsigned short)(g_usiDataSize/8 + 1); + } + else { + //09/11/07 NN Type cast mismatch variables + size = (unsigned short)(g_usiDataSize/8); + } + + /* If there is compression, then check if compress by key of 0x00 or 0xFF + or by other keys or by nibble blocks*/ + + if ( g_usDataType & COMPRESS ) { + compression = 1; + if ( ( ( compress = GetByte() ) == VAR ) && ( g_usDataType & HEAP_IN ) ) { + getData = 1; + g_usDataType &= ~(HEAP_IN); + compress = GetByte(); + } + + switch (compress){ + case 0x00: + /* No compression */ + compression = 0; + break; + case 0x01: + /* Compress by byte 0x00 */ + compr_char = 0x00; + break; + case 0x02: + /* Compress by byte 0xFF */ + compr_char = 0xFF; + break; + case 0xFF: + /* Huffman encoding */ + compr_char = GetByte(); + i = 8; + for ( index = 0; index < size; index++ ) { + ByteData[ index ] = 0x00; + if ( i > 7 ) { + cDataByte = GetByte(); + i = 0; + } + if ((cDataByte << i++) & 0x80) + m = 8; + else { + ByteData[index] = compr_char; + m = 0; + } + + for (j = 0; j < m; j++) { + if (i > 7) { + cDataByte = GetByte(); + i = 0; + } + ByteData[index] |=((cDataByte << i++)&0x80) >> j; + } + } + size = 0; + break; + default: + for (index = 0; index < size; index++) + ByteData[index] = 0x00; + for (index = 0; index < compress; index++) { + if (index%2 == 0) + cDataByte = GetByte(); + for (i = 0; i < size*2/compress; i++){ + //09/11/07 NN Type cast mismatch variables + j = (unsigned short)(index + (i*(unsigned short)compress)); + /*clear the nibble to zero first*/ + if (j%2) { + if (index%2) + ByteData[j/2] |= cDataByte & 0x0F; + else + ByteData[j/2] |= cDataByte >> 4; + } + else { + if (index%2) + ByteData[j/2] |= cDataByte << 4; + else + ByteData[j/2] |= cDataByte & 0xF0; + } + } + } + size = 0; + break; + } + } + + FFcount = 0; + + /* Decompress by byte 0x00 or 0xFF */ + for (index = 0; index < size; index++) { + if (FFcount <= 0) { + cDataByte = GetByte(); + if ((cDataByte == VAR) && (g_usDataType&HEAP_IN) && !getData && !(g_usDataType&COMPRESS)) { + getData = 1; + g_usDataType &= ~(HEAP_IN); + cDataByte = GetByte(); + } + ByteData[index] = cDataByte; + if ((compression) &&(cDataByte == compr_char)) /*decompression is on*/ + //09/11/07 NN Type cast mismatch variables + FFcount = (unsigned short) ispVMDataSize(); /*The number of 0xFF or 0x00 bytes*/ + } + else { + FFcount--; /*Use up the 0xFF chain first*/ + ByteData[index] = compr_char; + } + } + + if (getData) { + g_usDataType |= HEAP_IN; + getData = 0; + } } /*************************************************************** @@ -1384,196 +1384,196 @@ void ispVMData( unsigned char * ByteData ) signed char ispVMShift( signed char a_cCode ) { - //09/11/07 NN added local variables initialization - unsigned short iDataIndex = 0; - unsigned short iReadLoop = 0; - signed char cRetCode = 0; - - cRetCode=0; - //09/11/07 NN Type cast mismatch variables - g_usiDataSize = (unsigned short) ispVMDataSize(); - - g_usDataType &= ~( SIR_DATA + EXPRESS + SDR_DATA ); /*clear the flags first*/ - switch ( a_cCode ) { - case SIR: - g_usDataType |= SIR_DATA; - /* 1/15/04 If performing cascading, then go directly to SHIFTIR. Else, - go to IRPAUSE before going to SHIFTIR */ - if ( g_usFlowControl & CASCADE ) { - ispVMStateMachine( SHIFTIR ); - } - else { - ispVMStateMachine( IRPAUSE ); - ispVMStateMachine( SHIFTIR ); - if ( g_usHeadIR > 0 ){ - ispVMBypass( HIR, g_usHeadIR ); - sclock(); - } - } - break; - case XSDR: - g_usDataType |= EXPRESS; /*mark simultaneous in and out*/ + //09/11/07 NN added local variables initialization + unsigned short iDataIndex = 0; + unsigned short iReadLoop = 0; + signed char cRetCode = 0; + + cRetCode=0; + //09/11/07 NN Type cast mismatch variables + g_usiDataSize = (unsigned short) ispVMDataSize(); + + g_usDataType &= ~( SIR_DATA + EXPRESS + SDR_DATA ); /*clear the flags first*/ + switch ( a_cCode ) { + case SIR: + g_usDataType |= SIR_DATA; + /* 1/15/04 If performing cascading, then go directly to SHIFTIR. Else, + go to IRPAUSE before going to SHIFTIR */ + if ( g_usFlowControl & CASCADE ) { + ispVMStateMachine( SHIFTIR ); + } + else { + ispVMStateMachine( IRPAUSE ); + ispVMStateMachine( SHIFTIR ); + if ( g_usHeadIR > 0 ){ + ispVMBypass( HIR, g_usHeadIR ); + sclock(); + } + } + break; + case XSDR: + g_usDataType |= EXPRESS; /*mark simultaneous in and out*/ case SDR: - g_usDataType |= SDR_DATA; - /* 1/15/04 If already in SHIFTDR, then do not move state or shift in header. - This would imply that the previously shifted frame was a cascaded frame. */ - if ( g_cCurrentJTAGState != SHIFTDR ) { - /* 1/15/04 If performing cascading, then go directly to SHIFTDR. Else, - go to DRPAUSE before going to SHIFTDR */ - if ( g_usFlowControl & CASCADE ) { - if ( g_cCurrentJTAGState == DRPAUSE ) { - ispVMStateMachine( SHIFTDR ); - /* 1/15/04 If cascade flag has been set and the current state is - DRPAUSE, this implies that the first cascaded frame is about to - be shifted in. The header must be shifted prior to shifting - the first cascaded frame. */ - if ( g_usHeadDR > 0 ) { - ispVMBypass( HDR, g_usHeadDR ); - sclock(); - } - } - else { - ispVMStateMachine( SHIFTDR ); - } - } - else { - ispVMStateMachine( DRPAUSE ); - ispVMStateMachine( SHIFTDR ); - if ( g_usHeadDR > 0 ) { - ispVMBypass( HDR, g_usHeadDR ); - sclock(); - } - } - } - break; - default: - return ( VME_INVALID_FILE ); - } - - cRetCode = ispVMDataCode(); - - if ( cRetCode != 0 ) { - return ( VME_INVALID_FILE ); - } + g_usDataType |= SDR_DATA; + /* 1/15/04 If already in SHIFTDR, then do not move state or shift in header. + This would imply that the previously shifted frame was a cascaded frame. */ + if ( g_cCurrentJTAGState != SHIFTDR ) { + /* 1/15/04 If performing cascading, then go directly to SHIFTDR. Else, + go to DRPAUSE before going to SHIFTDR */ + if ( g_usFlowControl & CASCADE ) { + if ( g_cCurrentJTAGState == DRPAUSE ) { + ispVMStateMachine( SHIFTDR ); + /* 1/15/04 If cascade flag has been set and the current state is + DRPAUSE, this implies that the first cascaded frame is about to + be shifted in. The header must be shifted prior to shifting + the first cascaded frame. */ + if ( g_usHeadDR > 0 ) { + ispVMBypass( HDR, g_usHeadDR ); + sclock(); + } + } + else { + ispVMStateMachine( SHIFTDR ); + } + } + else { + ispVMStateMachine( DRPAUSE ); + ispVMStateMachine( SHIFTDR ); + if ( g_usHeadDR > 0 ) { + ispVMBypass( HDR, g_usHeadDR ); + sclock(); + } + } + } + break; + default: + return ( VME_INVALID_FILE ); + } + + cRetCode = ispVMDataCode(); + + if ( cRetCode != 0 ) { + return ( VME_INVALID_FILE ); + } #ifdef VME_DEBUG - printf( "%d ", g_usiDataSize ); + printf( "%d ", g_usiDataSize ); - if ( g_usDataType & TDI_DATA ) { - printf( "TDI " ); - PrintData( g_usiDataSize, g_pucInData ); - } + if ( g_usDataType & TDI_DATA ) { + printf( "TDI " ); + PrintData( g_usiDataSize, g_pucInData ); + } - if ( g_usDataType & TDO_DATA ) { - printf( "\n\t\tTDO " ); - PrintData( g_usiDataSize, g_pucOutData ); - } + if ( g_usDataType & TDO_DATA ) { + printf( "\n\t\tTDO " ); + PrintData( g_usiDataSize, g_pucOutData ); + } - if ( g_usDataType & MASK_DATA ) { - printf( "\n\t\tMASK " ); - PrintData( g_usiDataSize, g_pucOutMaskData ); - } + if ( g_usDataType & MASK_DATA ) { + printf( "\n\t\tMASK " ); + PrintData( g_usiDataSize, g_pucOutMaskData ); + } - if ( g_usDataType & DMASK_DATA ) { - printf( "\n\t\tDMASK " ); - PrintData( g_usiDataSize, g_pucOutDMaskData ); - } + if ( g_usDataType & DMASK_DATA ) { + printf( "\n\t\tDMASK " ); + PrintData( g_usiDataSize, g_pucOutDMaskData ); + } - printf( ";\n" ); + printf( ";\n" ); #endif //VME_DEBUG - - if ( g_usDataType & TDO_DATA || g_usDataType & DMASK_DATA ) { - if(g_usDataType & DMASK_DATA){ - cRetCode = ispVMReadandSave( g_usiDataSize ); - if(!cRetCode){ - if ( g_usTailDR > 0 ) { - sclock(); - ispVMBypass( TDR, g_usTailDR ); - } - ispVMStateMachine( DRPAUSE ); - ispVMStateMachine( SHIFTDR ); - if( g_usHeadDR > 0 ){ - ispVMBypass( HDR, g_usHeadDR ); - sclock(); - } - for ( iDataIndex=0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++ ) - g_pucInData[ iDataIndex ] = g_pucOutData[ iDataIndex ]; - g_usDataType &= ~( TDO_DATA+ DMASK_DATA ); - cRetCode = ispVMSend( g_usiDataSize ); - } - } - else{ - cRetCode = ispVMRead( g_usiDataSize ); - if ( cRetCode == -1 && g_cVendor == XILINX ) { - for( iReadLoop = 0; iReadLoop < 30; iReadLoop++ ){ - cRetCode = ispVMRead( g_usiDataSize ); - if( !cRetCode ) { - break; - } - else { - ispVMStateMachine( DRPAUSE ); /*Always DRPAUSE*/ - /*Bypass other devices when appropriate*/ - ispVMBypass( TDR, g_usTailDR ); - ispVMStateMachine( g_ucEndDR ); - ispVMStateMachine( IDLE ); - ispVMDelay( 1000 ); - } - } - } - } - } - else { /*TDI only*/ - cRetCode = ispVMSend( g_usiDataSize ); - } - - /*transfer the input data to the output buffer for the next verify*/ - if ( ( g_usDataType & EXPRESS ) || ( a_cCode == SDR ) ) { - if ( g_pucOutData ) { - for ( iDataIndex=0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++ ) - g_pucOutData[ iDataIndex ] = g_pucInData[ iDataIndex ]; - } - } - - switch( a_cCode ) { - case SIR: - /* 1/15/04 If not performing cascading, then shift ENDIR */ - if ( !( g_usFlowControl & CASCADE ) ) { - if ( g_usTailIR > 0 ) { - sclock(); - ispVMBypass( TIR, g_usTailIR ); - } - ispVMStateMachine( g_ucEndIR ); - } - break; + + if ( g_usDataType & TDO_DATA || g_usDataType & DMASK_DATA ) { + if(g_usDataType & DMASK_DATA){ + cRetCode = ispVMReadandSave( g_usiDataSize ); + if(!cRetCode){ + if ( g_usTailDR > 0 ) { + sclock(); + ispVMBypass( TDR, g_usTailDR ); + } + ispVMStateMachine( DRPAUSE ); + ispVMStateMachine( SHIFTDR ); + if( g_usHeadDR > 0 ){ + ispVMBypass( HDR, g_usHeadDR ); + sclock(); + } + for ( iDataIndex=0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++ ) + g_pucInData[ iDataIndex ] = g_pucOutData[ iDataIndex ]; + g_usDataType &= ~( TDO_DATA+ DMASK_DATA ); + cRetCode = ispVMSend( g_usiDataSize ); + } + } + else{ + cRetCode = ispVMRead( g_usiDataSize ); + if ( cRetCode == -1 && g_cVendor == XILINX ) { + for( iReadLoop = 0; iReadLoop < 30; iReadLoop++ ){ + cRetCode = ispVMRead( g_usiDataSize ); + if( !cRetCode ) { + break; + } + else { + ispVMStateMachine( DRPAUSE ); /*Always DRPAUSE*/ + /*Bypass other devices when appropriate*/ + ispVMBypass( TDR, g_usTailDR ); + ispVMStateMachine( g_ucEndDR ); + ispVMStateMachine( IDLE ); + ispVMDelay( 1000 ); + } + } + } + } + } + else { /*TDI only*/ + cRetCode = ispVMSend( g_usiDataSize ); + } + + /*transfer the input data to the output buffer for the next verify*/ + if ( ( g_usDataType & EXPRESS ) || ( a_cCode == SDR ) ) { + if ( g_pucOutData ) { + for ( iDataIndex=0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++ ) + g_pucOutData[ iDataIndex ] = g_pucInData[ iDataIndex ]; + } + } + + switch( a_cCode ) { + case SIR: + /* 1/15/04 If not performing cascading, then shift ENDIR */ + if ( !( g_usFlowControl & CASCADE ) ) { + if ( g_usTailIR > 0 ) { + sclock(); + ispVMBypass( TIR, g_usTailIR ); + } + ispVMStateMachine( g_ucEndIR ); + } + break; case XSDR: - case SDR: - /* 1/15/04 If not performing cascading, then shift ENDDR */ - if ( !( g_usFlowControl & CASCADE ) ) { - if ( g_usTailDR > 0 ) { - sclock(); - ispVMBypass( TDR, g_usTailDR ); - } - ispVMStateMachine( g_ucEndDR ); - } - break; + case SDR: + /* 1/15/04 If not performing cascading, then shift ENDDR */ + if ( !( g_usFlowControl & CASCADE ) ) { + if ( g_usTailDR > 0 ) { + sclock(); + ispVMBypass( TDR, g_usTailDR ); + } + ispVMStateMachine( g_ucEndDR ); + } + break; default: - break; - } - - return ( cRetCode ); + break; + } + + return ( cRetCode ); } /*************************************************************** * * ispVMAmble * -* This routine is to extract Header and Trailer parameter for SIR and +* This routine is to extract Header and Trailer parameter for SIR and * SDR operations. * * The Header and Trailer parameter are the pre-amble and post-amble bit * stream need to be shifted into TDI or out of TDO of the devices. Mostly * is for the purpose of bypassing the leading or trailing devices. ispVM -* supports only shifting data into TDI to bypass the devices. +* supports only shifting data into TDI to bypass the devices. * * For a single device, the header and trailer parameters are all set to 0 * as default by ispVM. If it is for multiple devices, the header and trailer @@ -1583,180 +1583,180 @@ signed char ispVMShift( signed char a_cCode ) signed char ispVMAmble( signed char Code ) { - signed char compress = 0; - //09/11/07 NN Type cast mismatch variables - g_usiDataSize = (unsigned short)ispVMDataSize(); - + signed char compress = 0; + //09/11/07 NN Type cast mismatch variables + g_usiDataSize = (unsigned short)ispVMDataSize(); + #ifdef VME_DEBUG - printf( "%d", g_usiDataSize ); + printf( "%d", g_usiDataSize ); #endif //VME_DEBUG - if ( g_usiDataSize ) { - - /**************************************************************************** - * - * Discard the TDI byte and set the compression bit in the data type register - * to false if compression is set because TDI data after HIR/HDR/TIR/TDR is not - * compressed. - * - *****************************************************************************/ - - GetByte(); - if ( g_usDataType & COMPRESS ) { - g_usDataType &= ~( COMPRESS ); - compress = 1; - } - } - - switch ( Code ) { - case HIR: - - /**************************************************************************** - * - * Store the maximum size of the HIR buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usHIRSize ) { - g_usHIRSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Assign the HIR value and allocate memory. - * - *****************************************************************************/ - - g_usHeadIR = g_usiDataSize; - if ( g_usHeadIR ) { - ispVMMemManager( HIR, g_usHeadIR ); - ispVMData( g_pucHIRData ); + if ( g_usiDataSize ) { + + /**************************************************************************** + * + * Discard the TDI byte and set the compression bit in the data type register + * to false if compression is set because TDI data after HIR/HDR/TIR/TDR is not + * compressed. + * + *****************************************************************************/ + + GetByte(); + if ( g_usDataType & COMPRESS ) { + g_usDataType &= ~( COMPRESS ); + compress = 1; + } + } + + switch ( Code ) { + case HIR: + + /**************************************************************************** + * + * Store the maximum size of the HIR buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usHIRSize ) { + g_usHIRSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Assign the HIR value and allocate memory. + * + *****************************************************************************/ + + g_usHeadIR = g_usiDataSize; + if ( g_usHeadIR ) { + ispVMMemManager( HIR, g_usHeadIR ); + ispVMData( g_pucHIRData ); #ifdef VME_DEBUG - printf( " TDI " ); - PrintData( g_usHeadIR, g_pucHIRData ); + printf( " TDI " ); + PrintData( g_usHeadIR, g_pucHIRData ); #endif //VME_DEBUG - } - break; - case TIR: - - /**************************************************************************** - * - * Store the maximum size of the TIR buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usTIRSize ) { - g_usTIRSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Assign the TIR value and allocate memory. - * - *****************************************************************************/ - - g_usTailIR = g_usiDataSize; - if ( g_usTailIR ) { - ispVMMemManager( TIR, g_usTailIR ); - ispVMData( g_pucTIRData ); + } + break; + case TIR: + + /**************************************************************************** + * + * Store the maximum size of the TIR buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTIRSize ) { + g_usTIRSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Assign the TIR value and allocate memory. + * + *****************************************************************************/ + + g_usTailIR = g_usiDataSize; + if ( g_usTailIR ) { + ispVMMemManager( TIR, g_usTailIR ); + ispVMData( g_pucTIRData ); #ifdef VME_DEBUG - printf( " TDI " ); - PrintData( g_usTailIR, g_pucTIRData ); + printf( " TDI " ); + PrintData( g_usTailIR, g_pucTIRData ); #endif //VME_DEBUG - } - break; - case HDR: - - /**************************************************************************** - * - * Store the maximum size of the HDR buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usHDRSize ) { - g_usHDRSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Assign the HDR value and allocate memory. - * - *****************************************************************************/ - - g_usHeadDR = g_usiDataSize; - if ( g_usHeadDR ) { - ispVMMemManager( HDR, g_usHeadDR ); - ispVMData( g_pucHDRData ); + } + break; + case HDR: + + /**************************************************************************** + * + * Store the maximum size of the HDR buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usHDRSize ) { + g_usHDRSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Assign the HDR value and allocate memory. + * + *****************************************************************************/ + + g_usHeadDR = g_usiDataSize; + if ( g_usHeadDR ) { + ispVMMemManager( HDR, g_usHeadDR ); + ispVMData( g_pucHDRData ); #ifdef VME_DEBUG - printf( " TDI " ); - PrintData( g_usHeadDR, g_pucHDRData ); + printf( " TDI " ); + PrintData( g_usHeadDR, g_pucHDRData ); #endif //VME_DEBUG - } - break; - case TDR: - - /**************************************************************************** - * - * Store the maximum size of the TDR buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usiDataSize > g_usTDRSize ) { - g_usTDRSize = g_usiDataSize; - } - - /**************************************************************************** - * - * Assign the TDR value and allocate memory. - * - *****************************************************************************/ - - g_usTailDR = g_usiDataSize; - if ( g_usTailDR ) { - ispVMMemManager( TDR, g_usTailDR ); - ispVMData( g_pucTDRData ); + } + break; + case TDR: + + /**************************************************************************** + * + * Store the maximum size of the TDR buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usiDataSize > g_usTDRSize ) { + g_usTDRSize = g_usiDataSize; + } + + /**************************************************************************** + * + * Assign the TDR value and allocate memory. + * + *****************************************************************************/ + + g_usTailDR = g_usiDataSize; + if ( g_usTailDR ) { + ispVMMemManager( TDR, g_usTailDR ); + ispVMData( g_pucTDRData ); #ifdef VME_DEBUG - printf( " TDI " ); - PrintData( g_usTailDR, g_pucTDRData ); + printf( " TDI " ); + PrintData( g_usTailDR, g_pucTDRData ); #endif //VME_DEBUG - } - break; - default: - break; - } - - /**************************************************************************** - * - * Re-enable compression if it was previously set. - * - *****************************************************************************/ - - if ( compress ) { - g_usDataType |= COMPRESS; - } - - if ( g_usiDataSize ) { - Code = GetByte(); - if ( Code == CONTINUE ) { - return 0; - } - else { - - /**************************************************************************** - * - * Encountered invalid opcode. - * - *****************************************************************************/ - - return VME_INVALID_FILE; - } - } - - return 0; + } + break; + default: + break; + } + + /**************************************************************************** + * + * Re-enable compression if it was previously set. + * + *****************************************************************************/ + + if ( compress ) { + g_usDataType |= COMPRESS; + } + + if ( g_usiDataSize ) { + Code = GetByte(); + if ( Code == CONTINUE ) { + return 0; + } + else { + + /**************************************************************************** + * + * Encountered invalid opcode. + * + *****************************************************************************/ + + return VME_INVALID_FILE; + } + } + + return 0; } /*************************************************************** @@ -1773,99 +1773,99 @@ signed char ispVMAmble( signed char Code ) signed char ispVMLoop(unsigned short a_usLoopCount) { - //09/11/07 NN added local variables initialization - signed char cRetCode = 0; - unsigned short iHeapIndex = 0; - unsigned short iLoopIndex = 0; - - g_usShiftValue = 0; - for ( iHeapIndex = 0; iHeapIndex < g_iHEAPSize; iHeapIndex++ ) { - g_pucHeapMemory[ iHeapIndex ] = GetByte(); - } - - if ( g_pucHeapMemory[ iHeapIndex - 1 ] != ENDLOOP ) { - return( VME_INVALID_FILE ); - } - - g_usFlowControl |= REPEATLOOP; - g_usDataType |= HEAP_IN; - - for ( iLoopIndex = 0; iLoopIndex < a_usLoopCount; iLoopIndex++ ) { - g_iHeapCounter = 0; - cRetCode = ispVMCode(); - g_usRepeatLoops++; - if ( cRetCode < 0 ) { - break; - } - } - - g_usDataType &= ~( HEAP_IN ); - g_usFlowControl &= ~( REPEATLOOP ); - return ( cRetCode ); + //09/11/07 NN added local variables initialization + signed char cRetCode = 0; + unsigned short iHeapIndex = 0; + unsigned short iLoopIndex = 0; + + g_usShiftValue = 0; + for ( iHeapIndex = 0; iHeapIndex < g_iHEAPSize; iHeapIndex++ ) { + g_pucHeapMemory[ iHeapIndex ] = GetByte(); + } + + if ( g_pucHeapMemory[ iHeapIndex - 1 ] != ENDLOOP ) { + return( VME_INVALID_FILE ); + } + + g_usFlowControl |= REPEATLOOP; + g_usDataType |= HEAP_IN; + + for ( iLoopIndex = 0; iLoopIndex < a_usLoopCount; iLoopIndex++ ) { + g_iHeapCounter = 0; + cRetCode = ispVMCode(); + g_usRepeatLoops++; + if ( cRetCode < 0 ) { + break; + } + } + + g_usDataType &= ~( HEAP_IN ); + g_usFlowControl &= ~( REPEATLOOP ); + return ( cRetCode ); } /*************************************************************** * * ispVMBitShift * -* Shift the TDI stream left or right by the number of bits. The data in +* Shift the TDI stream left or right by the number of bits. The data in * *g_pucInData is of the VME format, so the actual shifting is the reverse of -* IEEE 1532 or SVF format. +* IEEE 1532 or SVF format. * ***************************************************************/ signed char ispVMBitShift(signed char mode, unsigned short bits) { - //09/11/07 NN added local variables initialization - unsigned short i = 0; - unsigned short size = 0; - unsigned short tmpbits = 0; - - if (g_usiDataSize%8>0) { - //09/11/07 NN Type cast mismatch variables - size = (unsigned short)(g_usiDataSize/8 + 1); - } - else { - //09/11/07 NN Type cast mismatch variables - size = (unsigned short)(g_usiDataSize/8); - } - - switch(mode) { - case SHR: - for (i = 0; i < size; i++) { - if (g_pucInData[i] != 0) { - tmpbits = bits; - while (tmpbits > 0) { - g_pucInData[i] <<= 1; - if (g_pucInData[i] == 0) { - i--; - g_pucInData[i] = 1; - } - tmpbits--; - } - } - } - break; - case SHL: - for (i = 0; i < size; i++) { - if (g_pucInData[i] != 0) { - tmpbits = bits; - while (tmpbits > 0) { - g_pucInData[i] >>= 1; - if (g_pucInData[i] == 0) { - i--; - g_pucInData[i] = 8; - } - tmpbits--; - } - } - } - break; - default: - return ( VME_INVALID_FILE ); - } - - return (0); + //09/11/07 NN added local variables initialization + unsigned short i = 0; + unsigned short size = 0; + unsigned short tmpbits = 0; + + if (g_usiDataSize%8>0) { + //09/11/07 NN Type cast mismatch variables + size = (unsigned short)(g_usiDataSize/8 + 1); + } + else { + //09/11/07 NN Type cast mismatch variables + size = (unsigned short)(g_usiDataSize/8); + } + + switch(mode) { + case SHR: + for (i = 0; i < size; i++) { + if (g_pucInData[i] != 0) { + tmpbits = bits; + while (tmpbits > 0) { + g_pucInData[i] <<= 1; + if (g_pucInData[i] == 0) { + i--; + g_pucInData[i] = 1; + } + tmpbits--; + } + } + } + break; + case SHL: + for (i = 0; i < size; i++) { + if (g_pucInData[i] != 0) { + tmpbits = bits; + while (tmpbits > 0) { + g_pucInData[i] >>= 1; + if (g_pucInData[i] == 0) { + i--; + g_pucInData[i] = 8; + } + tmpbits--; + } + } + } + break; + default: + return ( VME_INVALID_FILE ); + } + + return (0); } /*************************************************************** @@ -1878,18 +1878,18 @@ signed char ispVMBitShift(signed char mode, unsigned short bits) void ispVMComment( unsigned short a_usCommentSize ) { - char cCurByte = 0; - for ( ; a_usCommentSize > 0; a_usCommentSize-- ) { - /**************************************************************************** - * - * Print character to the terminal. - * - *****************************************************************************/ - cCurByte = GetByte(); - vme_out_char( cCurByte ); - } - cCurByte = '\n'; - vme_out_char(cCurByte ); + char cCurByte = 0; + for ( ; a_usCommentSize > 0; a_usCommentSize-- ) { + /**************************************************************************** + * + * Print character to the terminal. + * + *****************************************************************************/ + cCurByte = GetByte(); + vme_out_char( cCurByte ); + } + cCurByte = '\n'; + vme_out_char(cCurByte ); } /*************************************************************** @@ -1902,9 +1902,9 @@ void ispVMComment( unsigned short a_usCommentSize ) void ispVMHeader( unsigned short a_usHeaderSize ) { - for ( ; a_usHeaderSize > 0; a_usHeaderSize-- ) { - GetByte(); - } + for ( ; a_usHeaderSize > 0; a_usHeaderSize-- ) { + GetByte(); + } } /*************************************************************** @@ -1915,36 +1915,36 @@ void ispVMHeader( unsigned short a_usHeaderSize ) * ***************************************************************/ -void ispVMCalculateCRC32( unsigned char a_ucData ) +void ispVMCalculateCRC32( unsigned char a_ucData ) { - //09/11/07 NN added local variables initialization - unsigned char ucIndex = 0; - unsigned char ucFlipData = 0; - unsigned short usCRCTableEntry = 0; - unsigned int crc_table[ 16 ] = { - 0x0000, 0xCC01, 0xD801, - 0x1400, 0xF001, 0x3C00, - 0x2800, 0xE401, 0xA001, - 0x6C00, 0x7800, 0xB401, - 0x5000, 0x9C01, 0x8801, - 0x4400 - }; - - for ( ucIndex = 0; ucIndex < 8; ucIndex++ ) { - ucFlipData <<= 1; - if ( a_ucData & 0x01 ) { - ucFlipData |= 0x01; - } - a_ucData >>= 1; - } - - //09/11/07 NN Type cast mismatch variables - usCRCTableEntry = (unsigned short)(crc_table[ g_usCalculatedCRC & 0xF ]); - g_usCalculatedCRC = (unsigned short)(( g_usCalculatedCRC >> 4 ) & 0x0FFF); - g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[ ucFlipData & 0xF ]); - usCRCTableEntry = (unsigned short)(crc_table[ g_usCalculatedCRC & 0xF ]); - g_usCalculatedCRC = (unsigned short)(( g_usCalculatedCRC >> 4 ) & 0x0FFF); - g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[ ( ucFlipData >> 4 ) & 0xF ]); + //09/11/07 NN added local variables initialization + unsigned char ucIndex = 0; + unsigned char ucFlipData = 0; + unsigned short usCRCTableEntry = 0; + unsigned int crc_table[ 16 ] = { + 0x0000, 0xCC01, 0xD801, + 0x1400, 0xF001, 0x3C00, + 0x2800, 0xE401, 0xA001, + 0x6C00, 0x7800, 0xB401, + 0x5000, 0x9C01, 0x8801, + 0x4400 + }; + + for ( ucIndex = 0; ucIndex < 8; ucIndex++ ) { + ucFlipData <<= 1; + if ( a_ucData & 0x01 ) { + ucFlipData |= 0x01; + } + a_ucData >>= 1; + } + + //09/11/07 NN Type cast mismatch variables + usCRCTableEntry = (unsigned short)(crc_table[ g_usCalculatedCRC & 0xF ]); + g_usCalculatedCRC = (unsigned short)(( g_usCalculatedCRC >> 4 ) & 0x0FFF); + g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[ ucFlipData & 0xF ]); + usCRCTableEntry = (unsigned short)(crc_table[ g_usCalculatedCRC & 0xF ]); + g_usCalculatedCRC = (unsigned short)(( g_usCalculatedCRC >> 4 ) & 0x0FFF); + g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[ ( ucFlipData >> 4 ) & 0xF ]); } /*************************************************************** @@ -1957,302 +1957,302 @@ void ispVMCalculateCRC32( unsigned char a_ucData ) signed char ispVMLCOUNT( unsigned short a_usCountSize ) { - unsigned short usContinue = 1; - unsigned short usIntelBufferIndex = 0; - unsigned short usCountIndex = 0; - signed char cRetCode = 0; - signed char cRepeatHeap = 0; - signed char cOpcode = 0; - unsigned char ucState = 0; - unsigned short usDelay = 0; - unsigned short usToggle = 0; - unsigned char usByte = 0; - - g_usIntelBufferSize = (unsigned short)ispVMDataSize(); - - /**************************************************************************** - * - * Allocate memory for intel buffer. - * - *****************************************************************************/ - - ispVMMemManager( LHEAP, g_usIntelBufferSize ); - - /**************************************************************************** - * - * Store the maximum size of the intelligent buffer. Used to convert VME to HEX. - * - *****************************************************************************/ - - if ( g_usIntelBufferSize > g_usLCOUNTSize ) { - g_usLCOUNTSize = g_usIntelBufferSize; - } - - /**************************************************************************** - * - * Copy intel data to the buffer. - * - *****************************************************************************/ - - for ( usIntelBufferIndex = 0; usIntelBufferIndex < g_usIntelBufferSize; usIntelBufferIndex++ ) { - g_pucIntelBuffer[ usIntelBufferIndex ] = GetByte(); - } - - /**************************************************************************** - * - * Set the data type register to get data from the intelligent data buffer. - * - *****************************************************************************/ - - g_usDataType |= LHEAP_IN; - - /**************************************************************************** - * - * If the HEAP_IN flag is set, temporarily unset the flag so data will be - * retrieved from the status buffer. - * - *****************************************************************************/ - - if ( g_usDataType & HEAP_IN ) { - g_usDataType &= ~HEAP_IN; - cRepeatHeap = 1; - } + unsigned short usContinue = 1; + unsigned short usIntelBufferIndex = 0; + unsigned short usCountIndex = 0; + signed char cRetCode = 0; + signed char cRepeatHeap = 0; + signed char cOpcode = 0; + unsigned char ucState = 0; + unsigned short usDelay = 0; + unsigned short usToggle = 0; + unsigned char usByte = 0; + + g_usIntelBufferSize = (unsigned short)ispVMDataSize(); + + /**************************************************************************** + * + * Allocate memory for intel buffer. + * + *****************************************************************************/ + + ispVMMemManager( LHEAP, g_usIntelBufferSize ); + + /**************************************************************************** + * + * Store the maximum size of the intelligent buffer. Used to convert VME to HEX. + * + *****************************************************************************/ + + if ( g_usIntelBufferSize > g_usLCOUNTSize ) { + g_usLCOUNTSize = g_usIntelBufferSize; + } + + /**************************************************************************** + * + * Copy intel data to the buffer. + * + *****************************************************************************/ + + for ( usIntelBufferIndex = 0; usIntelBufferIndex < g_usIntelBufferSize; usIntelBufferIndex++ ) { + g_pucIntelBuffer[ usIntelBufferIndex ] = GetByte(); + } + + /**************************************************************************** + * + * Set the data type register to get data from the intelligent data buffer. + * + *****************************************************************************/ + + g_usDataType |= LHEAP_IN; + + /**************************************************************************** + * + * If the HEAP_IN flag is set, temporarily unset the flag so data will be + * retrieved from the status buffer. + * + *****************************************************************************/ + + if ( g_usDataType & HEAP_IN ) { + g_usDataType &= ~HEAP_IN; + cRepeatHeap = 1; + } #ifdef VME_DEBUG - printf( "LCOUNT %d;\n", a_usCountSize ); + printf( "LCOUNT %d;\n", a_usCountSize ); #endif //VME_DEBUG - /**************************************************************************** - * - * Iterate through the intelligent programming command. - * - *****************************************************************************/ - - for ( usCountIndex = 0; usCountIndex < a_usCountSize; usCountIndex++ ) { - - /**************************************************************************** - * - * Initialize the intel data index to 0 before each iteration. - * - *****************************************************************************/ - - g_usIntelDataIndex = 0; - cOpcode = 0; - ucState = 0; - usDelay = 0; - usToggle = 0; - usByte = 0; - usContinue = 1; - - /*************************************************************** - * - * Begin looping through all the VME opcodes. - * - ***************************************************************/ - /*************************************************************** - * 4/1/09 Nguyen replaced the recursive function call codes on - * the ispVMLCOUNT function - * - ***************************************************************/ - while ( usContinue ) - { - cOpcode = GetByte(); - switch ( cOpcode ) { - case HIR: - case TIR: - case HDR: - case TDR: - /*************************************************************** - * - * Set the header/trailer of the device in order to bypass - * successfully. - * - ***************************************************************/ - - ispVMAmble( cOpcode ); - break; - case STATE: - - /*************************************************************** - * - * Step the JTAG state machine. - * - ***************************************************************/ - - ucState = GetByte(); - /*************************************************************** - * - * Step the JTAG state machine to DRCAPTURE to support Looping. - * - ***************************************************************/ - - if ( (g_usDataType & LHEAP_IN) && - (ucState == DRPAUSE ) && - ( g_cCurrentJTAGState == ucState )) - { - ispVMStateMachine( DRCAPTURE ); - } - ispVMStateMachine( ucState ); + /**************************************************************************** + * + * Iterate through the intelligent programming command. + * + *****************************************************************************/ + + for ( usCountIndex = 0; usCountIndex < a_usCountSize; usCountIndex++ ) { + + /**************************************************************************** + * + * Initialize the intel data index to 0 before each iteration. + * + *****************************************************************************/ + + g_usIntelDataIndex = 0; + cOpcode = 0; + ucState = 0; + usDelay = 0; + usToggle = 0; + usByte = 0; + usContinue = 1; + + /*************************************************************** + * + * Begin looping through all the VME opcodes. + * + ***************************************************************/ + /*************************************************************** + * 4/1/09 Nguyen replaced the recursive function call codes on + * the ispVMLCOUNT function + * + ***************************************************************/ + while ( usContinue ) + { + cOpcode = GetByte(); + switch ( cOpcode ) { + case HIR: + case TIR: + case HDR: + case TDR: + /*************************************************************** + * + * Set the header/trailer of the device in order to bypass + * successfully. + * + ***************************************************************/ + + ispVMAmble( cOpcode ); + break; + case STATE: + + /*************************************************************** + * + * Step the JTAG state machine. + * + ***************************************************************/ + + ucState = GetByte(); + /*************************************************************** + * + * Step the JTAG state machine to DRCAPTURE to support Looping. + * + ***************************************************************/ + + if ( (g_usDataType & LHEAP_IN) && + (ucState == DRPAUSE ) && + ( g_cCurrentJTAGState == ucState )) + { + ispVMStateMachine( DRCAPTURE ); + } + ispVMStateMachine( ucState ); #ifdef VME_DEBUG - printf( "LDELAY %s ", GetState( ucState ) ); + printf( "LDELAY %s ", GetState( ucState ) ); #endif //VME_DEBUG - break; - case SIR: + break; + case SIR: #ifdef VME_DEBUG - printf( "SIR " ); + printf( "SIR " ); #endif //VME_DEBUG - /*************************************************************** - * - * Shift in data into the device. - * - ***************************************************************/ + /*************************************************************** + * + * Shift in data into the device. + * + ***************************************************************/ - cRetCode = ispVMShift( cOpcode ); - break; - case SDR: + cRetCode = ispVMShift( cOpcode ); + break; + case SDR: #ifdef VME_DEBUG - printf( "LSDR " ); + printf( "LSDR " ); #endif //VME_DEBUG - /*************************************************************** - * - * Shift in data into the device. - * - ***************************************************************/ + /*************************************************************** + * + * Shift in data into the device. + * + ***************************************************************/ - cRetCode = ispVMShift( cOpcode ); - break; - case WAIT: + cRetCode = ispVMShift( cOpcode ); + break; + case WAIT: - /*************************************************************** - * - * Observe delay. - * - ***************************************************************/ + /*************************************************************** + * + * Observe delay. + * + ***************************************************************/ - usDelay = (unsigned short)ispVMDataSize(); - ispVMDelay( usDelay ); + usDelay = (unsigned short)ispVMDataSize(); + ispVMDelay( usDelay ); #ifdef VME_DEBUG - if ( usDelay & 0x8000 ) { - - /*************************************************************** - * - * Since MSB is set, the delay time must be decoded to - * millisecond. The SVF2VME encodes the MSB to represent - * millisecond. - * - ***************************************************************/ - - usDelay &= ~0x8000; - printf( "%.2E SEC;\n", ( float ) usDelay / 1000 ); - } - else { - - /*************************************************************** - * - * Since MSB is not set, the delay time is given as microseconds. - * - ***************************************************************/ - - printf( "%.2E SEC;\n", ( float ) usDelay / 1000000 ); - } + if ( usDelay & 0x8000 ) { + + /*************************************************************** + * + * Since MSB is set, the delay time must be decoded to + * millisecond. The SVF2VME encodes the MSB to represent + * millisecond. + * + ***************************************************************/ + + usDelay &= ~0x8000; + printf( "%.2E SEC;\n", ( float ) usDelay / 1000 ); + } + else { + + /*************************************************************** + * + * Since MSB is not set, the delay time is given as microseconds. + * + ***************************************************************/ + + printf( "%.2E SEC;\n", ( float ) usDelay / 1000000 ); + } #endif //VME_DEBUG - break; - case TCK: + break; + case TCK: - /*************************************************************** - * - * Issue clock toggles. - * - ***************************************************************/ + /*************************************************************** + * + * Issue clock toggles. + * + ***************************************************************/ - usToggle = (unsigned short)ispVMDataSize(); - ispVMClocks( usToggle ); + usToggle = (unsigned short)ispVMDataSize(); + ispVMClocks( usToggle ); #ifdef VME_DEBUG - printf( "RUNTEST %d TCK;\n", usToggle ); + printf( "RUNTEST %d TCK;\n", usToggle ); #endif //VME_DEBUG - break; - case ENDLOOP: - - /*************************************************************** - * - * Exit point from processing loops. - * - ***************************************************************/ - usContinue = 0; - break; - - case COMMENT: - - /*************************************************************** - * - * Display comment. - * - ***************************************************************/ - - ispVMComment( ( unsigned short ) ispVMDataSize() ); - break; - case ispEN: - ucState = GetByte(); - if((ucState == ON)||(ucState == 0x01)) - writePort( g_ucPinENABLE, 0x01 ); - else - writePort( g_ucPinENABLE, 0x00 ); - ispVMDelay( 1 ); - break; - case TRST: - if(GetByte() == 0x01) - writePort( g_ucPinTRST, 0x01 ); - else - writePort( g_ucPinTRST, 0x00 ); - ispVMDelay( 1 ); - break; - default: - - /*************************************************************** - * - * Invalid opcode encountered. - * - ***************************************************************/ + break; + case ENDLOOP: + + /*************************************************************** + * + * Exit point from processing loops. + * + ***************************************************************/ + usContinue = 0; + break; + + case COMMENT: + + /*************************************************************** + * + * Display comment. + * + ***************************************************************/ + + ispVMComment( ( unsigned short ) ispVMDataSize() ); + break; + case ispEN: + ucState = GetByte(); + if((ucState == ON)||(ucState == 0x01)) + writePort( g_ucPinENABLE, 0x01 ); + else + writePort( g_ucPinENABLE, 0x00 ); + ispVMDelay( 1 ); + break; + case TRST: + if(GetByte() == 0x01) + writePort( g_ucPinTRST, 0x01 ); + else + writePort( g_ucPinTRST, 0x00 ); + ispVMDelay( 1 ); + break; + default: + + /*************************************************************** + * + * Invalid opcode encountered. + * + ***************************************************************/ #ifdef VME_DEBUG - printf( "\nINVALID OPCODE: 0x%.2X\n", cOpcode ); + printf( "\nINVALID OPCODE: 0x%.2X\n", cOpcode ); #endif //VME_DEBUG - return VME_INVALID_FILE; - } - } - if ( cRetCode >= 0 ) { - /**************************************************************************** - * - * Break if intelligent programming is successful. - * - *****************************************************************************/ - - break; - } - - } - /**************************************************************************** - * - * If HEAP_IN flag was temporarily disabled, re-enable it before exiting. - * - *****************************************************************************/ - - if ( cRepeatHeap ) { - g_usDataType |= HEAP_IN; - } - - /**************************************************************************** - * - * Set the data type register to not get data from the intelligent data buffer. - * - *****************************************************************************/ - - g_usDataType &= ~LHEAP_IN; - return cRetCode; + return VME_INVALID_FILE; + } + } + if ( cRetCode >= 0 ) { + /**************************************************************************** + * + * Break if intelligent programming is successful. + * + *****************************************************************************/ + + break; + } + + } + /**************************************************************************** + * + * If HEAP_IN flag was temporarily disabled, re-enable it before exiting. + * + *****************************************************************************/ + + if ( cRepeatHeap ) { + g_usDataType |= HEAP_IN; + } + + /**************************************************************************** + * + * Set the data type register to not get data from the intelligent data buffer. + * + *****************************************************************************/ + + g_usDataType &= ~LHEAP_IN; + return cRetCode; } /*************************************************************** @@ -2265,10 +2265,10 @@ signed char ispVMLCOUNT( unsigned short a_usCountSize ) void ispVMClocks( unsigned short Clocks ) { - unsigned short iClockIndex = 0; - for ( iClockIndex = 0; iClockIndex < Clocks; iClockIndex++ ) { - sclock(); - } + unsigned short iClockIndex = 0; + for ( iClockIndex = 0; iClockIndex < Clocks; iClockIndex++ ) { + sclock(); + } } /*************************************************************** @@ -2276,8 +2276,8 @@ void ispVMClocks( unsigned short Clocks ) * ispVMBypass * * This procedure takes care of the HIR, HDR, TIR, TDR for the -* purpose of putting the other devices into Bypass mode. The -* current state is checked to find out if it is at DRPAUSE or +* purpose of putting the other devices into Bypass mode. The +* current state is checked to find out if it is at DRPAUSE or * IRPAUSE. If it is at DRPAUSE, perform bypass register scan. * If it is at IRPAUSE, scan into instruction registers the bypass * instruction. @@ -2286,54 +2286,54 @@ void ispVMClocks( unsigned short Clocks ) void ispVMBypass( signed char ScanType, unsigned short Bits ) { - //09/11/07 NN added local variables initialization - unsigned short iIndex = 0; - unsigned short iSourceIndex = 0; - unsigned char cBitState = 0; - unsigned char cCurByte = 0; - unsigned char * pcSource = NULL; - - if ( Bits <= 0 ) { - return; - } - - switch ( ScanType ) { - case HIR: - pcSource = g_pucHIRData; - break; - case TIR: - pcSource = g_pucTIRData; - break; - case HDR: - pcSource = g_pucHDRData; - break; - case TDR: - pcSource = g_pucTDRData; - break; - default: - break; - } - if(pcSource) - { - iSourceIndex = 0; - cBitState = 0; - for ( iIndex = 0; iIndex < Bits - 1; iIndex++ ) { - /* Scan instruction or bypass register */ - if ( iIndex % 8 == 0 ) { - cCurByte = pcSource[ iSourceIndex++ ]; - } - cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); - writePort( g_ucPinTDI, cBitState ); - sclock(); - } - - if ( iIndex % 8 == 0 ) { - cCurByte = pcSource[ iSourceIndex++ ]; - } - - cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); - writePort( g_ucPinTDI, cBitState ); - } + //09/11/07 NN added local variables initialization + unsigned short iIndex = 0; + unsigned short iSourceIndex = 0; + unsigned char cBitState = 0; + unsigned char cCurByte = 0; + unsigned char * pcSource = NULL; + + if ( Bits <= 0 ) { + return; + } + + switch ( ScanType ) { + case HIR: + pcSource = g_pucHIRData; + break; + case TIR: + pcSource = g_pucTIRData; + break; + case HDR: + pcSource = g_pucHDRData; + break; + case TDR: + pcSource = g_pucTDRData; + break; + default: + break; + } + if(pcSource) + { + iSourceIndex = 0; + cBitState = 0; + for ( iIndex = 0; iIndex < Bits - 1; iIndex++ ) { + /* Scan instruction or bypass register */ + if ( iIndex % 8 == 0 ) { + cCurByte = pcSource[ iSourceIndex++ ]; + } + cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); + writePort( g_ucPinTDI, cBitState ); + sclock(); + } + + if ( iIndex % 8 == 0 ) { + cCurByte = pcSource[ iSourceIndex++ ]; + } + + cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); + writePort( g_ucPinTDI, cBitState ); + } } /*************************************************************** @@ -2349,37 +2349,37 @@ void ispVMBypass( signed char ScanType, unsigned short Bits ) void ispVMStateMachine( signed char cNextJTAGState ) { - //09/11/07 NN added local variables initialization - signed char cPathIndex = 0; - signed char cStateIndex = 0; - short int found = 0; - - if ( ( g_cCurrentJTAGState == cNextJTAGState ) && ( cNextJTAGState != RESET ) ) { - return; - } - - for ( cStateIndex = 0; cStateIndex < 25; cStateIndex++ ) { - if ( ( g_cCurrentJTAGState == g_JTAGTransistions[ cStateIndex ].CurState ) && ( cNextJTAGState == g_JTAGTransistions[cStateIndex].NextState ) ) { - found = 1; - break; - } - } - if(found) - { - g_cCurrentJTAGState = cNextJTAGState; - for ( cPathIndex = 0; cPathIndex < g_JTAGTransistions[ cStateIndex ].Pulses; cPathIndex++ ) { - if ( ( g_JTAGTransistions[ cStateIndex ].Pattern << cPathIndex ) & 0x80 ) { - writePort( g_ucPinTMS, ( unsigned char ) 0x01 ); - } - else { - writePort( g_ucPinTMS, ( unsigned char ) 0x00 ); - } - sclock(); - } - - writePort( g_ucPinTDI, 0x00 ); - writePort( g_ucPinTMS, 0x00 ); - } + //09/11/07 NN added local variables initialization + signed char cPathIndex = 0; + signed char cStateIndex = 0; + short int found = 0; + + if ( ( g_cCurrentJTAGState == cNextJTAGState ) && ( cNextJTAGState != RESET ) ) { + return; + } + + for ( cStateIndex = 0; cStateIndex < 25; cStateIndex++ ) { + if ( ( g_cCurrentJTAGState == g_JTAGTransistions[ cStateIndex ].CurState ) && ( cNextJTAGState == g_JTAGTransistions[cStateIndex].NextState ) ) { + found = 1; + break; + } + } + if(found) + { + g_cCurrentJTAGState = cNextJTAGState; + for ( cPathIndex = 0; cPathIndex < g_JTAGTransistions[ cStateIndex ].Pulses; cPathIndex++ ) { + if ( ( g_JTAGTransistions[ cStateIndex ].Pattern << cPathIndex ) & 0x80 ) { + writePort( g_ucPinTMS, ( unsigned char ) 0x01 ); + } + else { + writePort( g_ucPinTMS, ( unsigned char ) 0x00 ); + } + sclock(); + } + + writePort( g_ucPinTDI, 0x00 ); + writePort( g_ucPinTMS, 0x00 ); + } } /*************************************************************** @@ -2393,18 +2393,18 @@ void ispVMStateMachine( signed char cNextJTAGState ) void ispVMStart() { #ifdef VME_DEBUG - printf( "// ISPVM EMBEDDED ADDED\n" ); - printf( "STATE RESET;\n" ); + printf( "// ISPVM EMBEDDED ADDED\n" ); + printf( "STATE RESET;\n" ); #endif - ispVMStateMachine( RESET ); /*step devices to RESET state*/ + ispVMStateMachine( RESET ); /*step devices to RESET state*/ } /*************************************************************** * * ispVMEnd * -* Set the state of devices to RESET to enable the devices and disable +* Set the state of devices to RESET to enable the devices and disable * the port. * ***************************************************************/ @@ -2412,13 +2412,13 @@ void ispVMStart() void ispVMEnd() { #ifdef VME_DEBUG - printf( "// ISPVM EMBEDDED ADDED\n" ); - printf( "STATE RESET;\n" ); - printf( "RUNTEST 1.00E-001 SEC;\n" ); + printf( "// ISPVM EMBEDDED ADDED\n" ); + printf( "STATE RESET;\n" ); + printf( "RUNTEST 1.00E-001 SEC;\n" ); #endif - ispVMStateMachine( RESET ); /*step devices to RESET state */ - ispVMDelay( 1000 ); /*wake up devices*/ + ispVMStateMachine( RESET ); /*step devices to RESET state */ + ispVMDelay( 1000 ); /*wake up devices*/ } /*************************************************************** @@ -2432,35 +2432,35 @@ void ispVMEnd() signed char ispVMSend( unsigned short a_usiDataSize ) { - //09/11/07 NN added local variables initialization - unsigned short iIndex = 0; - unsigned short iInDataIndex = 0; - unsigned char cCurByte = 0; - unsigned char cBitState = 0; - - for ( iIndex = 0; iIndex < a_usiDataSize - 1; iIndex++ ) { - if ( iIndex % 8 == 0 ) { - cCurByte = g_pucInData[ iInDataIndex++ ]; - } - cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); - writePort( g_ucPinTDI, cBitState ); - sclock(); - } - - if ( iIndex % 8 == 0 ) { - /* Take care of the last bit */ - cCurByte = g_pucInData[ iInDataIndex ]; - } - - cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); - - writePort( g_ucPinTDI, cBitState ); - if ( g_usFlowControl & CASCADE ) { - /* 1/15/04 Clock in last bit for the first n-1 cascaded frames */ - sclock(); - } - - return 0; + //09/11/07 NN added local variables initialization + unsigned short iIndex = 0; + unsigned short iInDataIndex = 0; + unsigned char cCurByte = 0; + unsigned char cBitState = 0; + + for ( iIndex = 0; iIndex < a_usiDataSize - 1; iIndex++ ) { + if ( iIndex % 8 == 0 ) { + cCurByte = g_pucInData[ iInDataIndex++ ]; + } + cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); + writePort( g_ucPinTDI, cBitState ); + sclock(); + } + + if ( iIndex % 8 == 0 ) { + /* Take care of the last bit */ + cCurByte = g_pucInData[ iInDataIndex ]; + } + + cBitState = ( unsigned char ) ( ( ( cCurByte << iIndex % 8 ) & 0x80 ) ? 0x01 : 0x00 ); + + writePort( g_ucPinTDI, cBitState ); + if ( g_usFlowControl & CASCADE ) { + /* 1/15/04 Clock in last bit for the first n-1 cascaded frames */ + sclock(); + } + + return 0; } /*************************************************************** @@ -2473,312 +2473,312 @@ signed char ispVMSend( unsigned short a_usiDataSize ) signed char ispVMRead( unsigned short a_usiDataSize ) { - //09/11/07 NN added local variables initialization - unsigned short usDataSizeIndex = 0; - unsigned short usErrorCount = 0; - unsigned short usLastBitIndex = 0; - unsigned char cDataByte = 0; - unsigned char cMaskByte = 0; - unsigned char cInDataByte = 0; - unsigned char cCurBit = 0; - unsigned char cByteIndex = 0; - unsigned short usBufferIndex = 0; - unsigned char ucDisplayByte = 0x00; - unsigned char ucDisplayFlag = 0x01; - char StrChecksum[256] = {0}; - unsigned char g_usCalculateChecksum = 0x00; - - //09/11/07 NN Type cast mismatch variables - usLastBitIndex = (unsigned short)(a_usiDataSize - 1); - + //09/11/07 NN added local variables initialization + unsigned short usDataSizeIndex = 0; + unsigned short usErrorCount = 0; + unsigned short usLastBitIndex = 0; + unsigned char cDataByte = 0; + unsigned char cMaskByte = 0; + unsigned char cInDataByte = 0; + unsigned char cCurBit = 0; + unsigned char cByteIndex = 0; + unsigned short usBufferIndex = 0; + unsigned char ucDisplayByte = 0x00; + unsigned char ucDisplayFlag = 0x01; + char StrChecksum[256] = {0}; + unsigned char g_usCalculateChecksum = 0x00; + + //09/11/07 NN Type cast mismatch variables + usLastBitIndex = (unsigned short)(a_usiDataSize - 1); + #ifndef VME_DEBUG - /**************************************************************************** - * - * If mask is not all zeros, then set the display flag to 0x00, otherwise - * it shall be set to 0x01 to indicate that data read from the device shall - * be displayed. If VME_DEBUG is defined, always display data. - * - *****************************************************************************/ - - for ( usDataSizeIndex = 0; usDataSizeIndex < ( a_usiDataSize + 7 ) / 8; usDataSizeIndex++ ) { - if ( g_usDataType & MASK_DATA ) { - if ( g_pucOutMaskData[ usDataSizeIndex ] != 0x00 ) { - ucDisplayFlag = 0x00; - break; - } - } - else if ( g_usDataType & CMASK_DATA ) { - g_usCalculateChecksum = 0x01; - ucDisplayFlag = 0x00; - break; - } - else { - ucDisplayFlag = 0x00; - break; - } - } + /**************************************************************************** + * + * If mask is not all zeros, then set the display flag to 0x00, otherwise + * it shall be set to 0x01 to indicate that data read from the device shall + * be displayed. If VME_DEBUG is defined, always display data. + * + *****************************************************************************/ + + for ( usDataSizeIndex = 0; usDataSizeIndex < ( a_usiDataSize + 7 ) / 8; usDataSizeIndex++ ) { + if ( g_usDataType & MASK_DATA ) { + if ( g_pucOutMaskData[ usDataSizeIndex ] != 0x00 ) { + ucDisplayFlag = 0x00; + break; + } + } + else if ( g_usDataType & CMASK_DATA ) { + g_usCalculateChecksum = 0x01; + ucDisplayFlag = 0x00; + break; + } + else { + ucDisplayFlag = 0x00; + break; + } + } #endif //VME_DEBUG - - /**************************************************************************** - * - * Begin shifting data in and out of the device. - * - *****************************************************************************/ - - for ( usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++ ) { - if ( cByteIndex == 0 ) { - - /*************************************************************** - * - * Grab byte from TDO buffer. - * - ***************************************************************/ - - if ( g_usDataType & TDO_DATA ) { - cDataByte = g_pucOutData[ usBufferIndex ]; - } - - /*************************************************************** - * - * Grab byte from MASK buffer. - * - ***************************************************************/ - - if ( g_usDataType & MASK_DATA ) { - cMaskByte = g_pucOutMaskData[ usBufferIndex ]; - } - else { - cMaskByte = 0xFF; - } - - /*************************************************************** - * - * Grab byte from CMASK buffer. - * - ***************************************************************/ - - if ( g_usDataType & CMASK_DATA ) { - cMaskByte = 0x00; - g_usCalculateChecksum = 0x01; - } - - /*************************************************************** - * - * Grab byte from TDI buffer. - * - ***************************************************************/ - - if ( g_usDataType & TDI_DATA ) { - cInDataByte = g_pucInData[ usBufferIndex ]; - } - - usBufferIndex++; - } - - cCurBit = readPort(); - - if ( ucDisplayFlag ) { - ucDisplayByte <<= 1; - ucDisplayByte |= cCurBit; - } - - /**************************************************************************** - * - * Check if data read from port matches with expected TDO. - * - *****************************************************************************/ - - if ( g_usDataType & TDO_DATA ) { - //08/28/08 NN Added Calculate checksum support. - if( g_usCalculateChecksum ) - { - if(cCurBit == 0x01) - g_usChecksum += (1 << (g_uiChecksumIndex % 8)); - g_uiChecksumIndex++; - } - else - { - if ( ( ( ( cMaskByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { - if ( cCurBit != ( unsigned char ) ( ( ( cDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { - usErrorCount++; - } - } - } - } - - /**************************************************************************** - * - * Write TDI data to the port. - * - *****************************************************************************/ - - writePort( g_ucPinTDI, ( unsigned char ) ( ( ( cInDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ); - - if ( usDataSizeIndex < usLastBitIndex ) { - - /**************************************************************************** - * - * Clock data out from the data shift register. - * - *****************************************************************************/ - - sclock(); - } - else if ( g_usFlowControl & CASCADE ) { - - /**************************************************************************** - * - * Clock in last bit for the first N - 1 cascaded frames. - * - *****************************************************************************/ - - sclock(); - } - - /*************************************************************** - * - * Increment the byte index. If it exceeds 7, then reset it back - * to zero. - * - ***************************************************************/ - - cByteIndex++; - if ( cByteIndex >= 8 ) { - if ( ucDisplayFlag ) { - - /*************************************************************** - * - * Store displayed data in the TDO buffer. By reusing the TDO - * buffer to store displayed data, there is no need to allocate - * a buffer simply to hold display data. This will not cause any - * false verification errors because the true TDO byte has already - * been consumed. - * - ***************************************************************/ - - g_pucOutData[ usBufferIndex - 1 ] = ucDisplayByte; - ucDisplayByte = 0; - } - - cByteIndex = 0; - } - //09/12/07 Nguyen changed to display the 1 bit expected data - else if(a_usiDataSize == 1) - { - if ( ucDisplayFlag ) { - - /*************************************************************** - * - * Store displayed data in the TDO buffer. By reusing the TDO - * buffer to store displayed data, there is no need to allocate - * a buffer simply to hold display data. This will not cause any - * false verification errors because the true TDO byte has already - * been consumed. - * - ***************************************************************/ - - /**************************************************************************** - * - * Flip ucDisplayByte and store it in cDataByte. - * - *****************************************************************************/ - cDataByte = 0x00; - for ( usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++ ) { - cDataByte <<= 1; - if ( ucDisplayByte & 0x01 ) { - cDataByte |= 0x01; - } - ucDisplayByte >>= 1; - } - g_pucOutData[ 0 ] = cDataByte; - ucDisplayByte = 0; - } - - cByteIndex = 0; - } - } - if ( ucDisplayFlag ) { - - /**************************************************************************** - * - * Display data read from the device. - * - *****************************************************************************/ + + /**************************************************************************** + * + * Begin shifting data in and out of the device. + * + *****************************************************************************/ + + for ( usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++ ) { + if ( cByteIndex == 0 ) { + + /*************************************************************** + * + * Grab byte from TDO buffer. + * + ***************************************************************/ + + if ( g_usDataType & TDO_DATA ) { + cDataByte = g_pucOutData[ usBufferIndex ]; + } + + /*************************************************************** + * + * Grab byte from MASK buffer. + * + ***************************************************************/ + + if ( g_usDataType & MASK_DATA ) { + cMaskByte = g_pucOutMaskData[ usBufferIndex ]; + } + else { + cMaskByte = 0xFF; + } + + /*************************************************************** + * + * Grab byte from CMASK buffer. + * + ***************************************************************/ + + if ( g_usDataType & CMASK_DATA ) { + cMaskByte = 0x00; + g_usCalculateChecksum = 0x01; + } + + /*************************************************************** + * + * Grab byte from TDI buffer. + * + ***************************************************************/ + + if ( g_usDataType & TDI_DATA ) { + cInDataByte = g_pucInData[ usBufferIndex ]; + } + + usBufferIndex++; + } + + cCurBit = readPort(); + + if ( ucDisplayFlag ) { + ucDisplayByte <<= 1; + ucDisplayByte |= cCurBit; + } + + /**************************************************************************** + * + * Check if data read from port matches with expected TDO. + * + *****************************************************************************/ + + if ( g_usDataType & TDO_DATA ) { + //08/28/08 NN Added Calculate checksum support. + if( g_usCalculateChecksum ) + { + if(cCurBit == 0x01) + g_usChecksum += (1 << (g_uiChecksumIndex % 8)); + g_uiChecksumIndex++; + } + else + { + if ( ( ( ( cMaskByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { + if ( cCurBit != ( unsigned char ) ( ( ( cDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { + usErrorCount++; + } + } + } + } + + /**************************************************************************** + * + * Write TDI data to the port. + * + *****************************************************************************/ + + writePort( g_ucPinTDI, ( unsigned char ) ( ( ( cInDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ); + + if ( usDataSizeIndex < usLastBitIndex ) { + + /**************************************************************************** + * + * Clock data out from the data shift register. + * + *****************************************************************************/ + + sclock(); + } + else if ( g_usFlowControl & CASCADE ) { + + /**************************************************************************** + * + * Clock in last bit for the first N - 1 cascaded frames. + * + *****************************************************************************/ + + sclock(); + } + + /*************************************************************** + * + * Increment the byte index. If it exceeds 7, then reset it back + * to zero. + * + ***************************************************************/ + + cByteIndex++; + if ( cByteIndex >= 8 ) { + if ( ucDisplayFlag ) { + + /*************************************************************** + * + * Store displayed data in the TDO buffer. By reusing the TDO + * buffer to store displayed data, there is no need to allocate + * a buffer simply to hold display data. This will not cause any + * false verification errors because the true TDO byte has already + * been consumed. + * + ***************************************************************/ + + g_pucOutData[ usBufferIndex - 1 ] = ucDisplayByte; + ucDisplayByte = 0; + } + + cByteIndex = 0; + } + //09/12/07 Nguyen changed to display the 1 bit expected data + else if(a_usiDataSize == 1) + { + if ( ucDisplayFlag ) { + + /*************************************************************** + * + * Store displayed data in the TDO buffer. By reusing the TDO + * buffer to store displayed data, there is no need to allocate + * a buffer simply to hold display data. This will not cause any + * false verification errors because the true TDO byte has already + * been consumed. + * + ***************************************************************/ + + /**************************************************************************** + * + * Flip ucDisplayByte and store it in cDataByte. + * + *****************************************************************************/ + cDataByte = 0x00; + for ( usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++ ) { + cDataByte <<= 1; + if ( ucDisplayByte & 0x01 ) { + cDataByte |= 0x01; + } + ucDisplayByte >>= 1; + } + g_pucOutData[ 0 ] = cDataByte; + ucDisplayByte = 0; + } + + cByteIndex = 0; + } + } + if ( ucDisplayFlag ) { + + /**************************************************************************** + * + * Display data read from the device. + * + *****************************************************************************/ #ifdef VME_DEBUG - printf( "RECIEVED TDO (" ); + printf( "RECIEVED TDO (" ); #else - vme_out_string( "Display Data: 0x" ); + vme_out_string( "Display Data: 0x" ); #endif //VME_DEBUG - //09/11/07 NN Type cast mismatch variables - for ( usDataSizeIndex = (unsigned short)( ( a_usiDataSize + 7 ) / 8 ); usDataSizeIndex > 0 ; usDataSizeIndex-- ) { - cMaskByte = g_pucOutData[ usDataSizeIndex - 1 ]; - cDataByte = 0x00; - - /**************************************************************************** - * - * Flip cMaskByte and store it in cDataByte. - * - *****************************************************************************/ - - for ( usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++ ) { - cDataByte <<= 1; - if ( cMaskByte & 0x01 ) { - cDataByte |= 0x01; - } - cMaskByte >>= 1; - } + //09/11/07 NN Type cast mismatch variables + for ( usDataSizeIndex = (unsigned short)( ( a_usiDataSize + 7 ) / 8 ); usDataSizeIndex > 0 ; usDataSizeIndex-- ) { + cMaskByte = g_pucOutData[ usDataSizeIndex - 1 ]; + cDataByte = 0x00; + + /**************************************************************************** + * + * Flip cMaskByte and store it in cDataByte. + * + *****************************************************************************/ + + for ( usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++ ) { + cDataByte <<= 1; + if ( cMaskByte & 0x01 ) { + cDataByte |= 0x01; + } + cMaskByte >>= 1; + } #ifdef VME_DEBUG - printf( "%.2X", cDataByte ); - if ( ( ( ( a_usiDataSize + 7 ) / 8 ) - usDataSizeIndex ) % 40 == 39 ) { - printf( "\n\t\t" ); - } + printf( "%.2X", cDataByte ); + if ( ( ( ( a_usiDataSize + 7 ) / 8 ) - usDataSizeIndex ) % 40 == 39 ) { + printf( "\n\t\t" ); + } #else - vme_out_hex( cDataByte ); + vme_out_hex( cDataByte ); #endif //VME_DEBUG - } + } #ifdef VME_DEBUG - printf( ")\n\n" ); + printf( ")\n\n" ); #else - vme_out_string( "\n\n" ); + vme_out_string( "\n\n" ); #endif //VME_DEBUG - //09/02/08 Nguyen changed to display the data Checksum - if(g_usChecksum != 0) - { - g_usChecksum &= 0xFFFF; - sprintf(StrChecksum,"Data Checksum: %.4X\n\n",g_usChecksum); - vme_out_string(StrChecksum); - g_usChecksum = 0; - } - } - - if ( usErrorCount > 0 ) { - if ( g_usFlowControl & VERIFYUES ) { - vme_out_string( "USERCODE verification failed. Continue programming......\n\n" ); - g_usFlowControl &= ~( VERIFYUES ); - return 0; - } - else { + //09/02/08 Nguyen changed to display the data Checksum + if(g_usChecksum != 0) + { + g_usChecksum &= 0xFFFF; + sprintf(StrChecksum,"Data Checksum: %.4X\n\n",g_usChecksum); + vme_out_string(StrChecksum); + g_usChecksum = 0; + } + } + + if ( usErrorCount > 0 ) { + if ( g_usFlowControl & VERIFYUES ) { + vme_out_string( "USERCODE verification failed. Continue programming......\n\n" ); + g_usFlowControl &= ~( VERIFYUES ); + return 0; + } + else { #ifdef VME_DEBUG - printf( "TOTAL ERRORS: %d\n", usErrorCount ); + printf( "TOTAL ERRORS: %d\n", usErrorCount ); #endif //VME_DEBUG - return VME_VERIFICATION_FAILURE; - } - } - else { - if ( g_usFlowControl & VERIFYUES ) { - vme_out_string( "USERCODE verification passed. Programming aborted. \n\n" ); - g_usFlowControl &= ~( VERIFYUES ); - return 1; - } - else { - return 0; - } - } + return VME_VERIFICATION_FAILURE; + } + } + else { + if ( g_usFlowControl & VERIFYUES ) { + vme_out_string( "USERCODE verification passed. Programming aborted. \n\n" ); + g_usFlowControl &= ~( VERIFYUES ); + return 1; + } + else { + return 0; + } + } } /*************************************************************** @@ -2791,292 +2791,292 @@ signed char ispVMRead( unsigned short a_usiDataSize ) signed char ispVMReadandSave( unsigned short int a_usiDataSize ) { - //09/11/07 NN added local variables initialization - unsigned short int usDataSizeIndex = 0; - unsigned short int usLastBitIndex = 0; - unsigned short int usBufferIndex = 0; - unsigned short int usOutBitIndex = 0; - unsigned short int usLVDSIndex = 0; - unsigned char cDataByte = 0; - unsigned char cDMASKByte = 0; - unsigned char cInDataByte = 0; - unsigned char cCurBit = 0; - unsigned char cByteIndex = 0; - signed char cLVDSByteIndex = 0; - - //09/11/07 NN Type cast mismatch variables - usLastBitIndex = (unsigned short) (a_usiDataSize - 1); - - /*************************************************************** - * - * Iterate through the data bits. - * - ***************************************************************/ - - for ( usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++ ) { - if ( cByteIndex == 0 ) { - - /*************************************************************** - * - * Grab byte from DMASK buffer. - * - ***************************************************************/ - - if ( g_usDataType & DMASK_DATA ) { - cDMASKByte = g_pucOutDMaskData[ usBufferIndex ]; - } - else { - cDMASKByte = 0x00; - } - - /*************************************************************** - * - * Grab byte from TDI buffer. - * - ***************************************************************/ - - if ( g_usDataType & TDI_DATA ) { - cInDataByte = g_pucInData[ usBufferIndex ]; - } - - usBufferIndex++; - } - - cCurBit = readPort(); - cDataByte = ( unsigned char ) ( ( ( cInDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ); - - /*************************************************************** - * - * Initialize the byte to be zero. - * - ***************************************************************/ - - if ( usOutBitIndex % 8 == 0 ) { - g_pucOutData[ usOutBitIndex / 8 ] = 0x00; - } - - /*************************************************************** - * - * Use TDI, DMASK, and device TDO to create new TDI (actually - * stored in g_pucOutData). - * - ***************************************************************/ - - if ( ( ( ( cDMASKByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { - - if ( g_pLVDSList ) { - for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { - if ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex == usDataSizeIndex ) { - g_pLVDSList[ usLVDSIndex ].ucUpdate = 0x01; - break; - } - } - } - - /*************************************************************** - * - * DMASK bit is 1, use TDI. - * - ***************************************************************/ - - g_pucOutData[ usOutBitIndex / 8 ] |= ( unsigned char ) ( ( ( cDataByte & 0x1 ) ? 0x01 : 0x00 ) << ( 7 - usOutBitIndex % 8 ) ); - } - else { - - /*************************************************************** - * - * DMASK bit is 0, use device TDO. - * - ***************************************************************/ - - g_pucOutData[ usOutBitIndex / 8 ] |= ( unsigned char ) ( ( ( cCurBit & 0x1 ) ? 0x01 : 0x00 ) << ( 7 - usOutBitIndex % 8 ) ); - } - - /*************************************************************** - * - * Shift in TDI in order to get TDO out. - * - ***************************************************************/ - - usOutBitIndex++; - writePort( g_ucPinTDI, cDataByte ); - if ( usDataSizeIndex < usLastBitIndex ) { - sclock(); - } - - /*************************************************************** - * - * Increment the byte index. If it exceeds 7, then reset it back - * to zero. - * - ***************************************************************/ - - cByteIndex++; - if ( cByteIndex >= 8 ) { - cByteIndex = 0; - } - } - - /*************************************************************** - * - * If g_pLVDSList exists and pairs need updating, then update - * the negative-pair to receive the flipped positive-pair value. - * - ***************************************************************/ - - if ( g_pLVDSList ) { - for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { - if ( g_pLVDSList[ usLVDSIndex ].ucUpdate ) { - - /*************************************************************** - * - * Read the positive value and flip it. - * - ***************************************************************/ - - cDataByte = ( unsigned char ) ( ( ( g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usPositiveIndex / 8 ] << ( g_pLVDSList[ usLVDSIndex ].usPositiveIndex % 8 ) ) & 0x80 ) ? 0x01 : 0x00 ); - //09/11/07 NN Type cast mismatch variables - cDataByte = ( unsigned char ) (!cDataByte); - - /*************************************************************** - * - * Get the byte that needs modification. - * - ***************************************************************/ - - cInDataByte = g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ]; - - if ( cDataByte ) { - - /*************************************************************** - * - * Copy over the current byte and set the negative bit to 1. - * - ***************************************************************/ - - cDataByte = 0x00; - for ( cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex-- ) { - cDataByte <<= 1; - if ( 7 - ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex % 8 ) == cLVDSByteIndex ) { - - /*************************************************************** - * - * Set negative bit to 1. - * - ***************************************************************/ - - cDataByte |= 0x01; - } - else if ( cInDataByte & 0x80 ) { - cDataByte |= 0x01; - } - - cInDataByte <<= 1; - } - - /*************************************************************** - * - * Store the modified byte. - * - ***************************************************************/ - - g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ] = cDataByte; - } - else { - - /*************************************************************** - * - * Copy over the current byte and set the negative bit to 0. - * - ***************************************************************/ - - cDataByte = 0x00; - for ( cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex-- ) { - cDataByte <<= 1; - if ( 7 - ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex % 8 ) == cLVDSByteIndex ) { - - /*************************************************************** - * - * Set negative bit to 0. - * - ***************************************************************/ - - cDataByte |= 0x00; - } - else if ( cInDataByte & 0x80 ) { - cDataByte |= 0x01; - } - - cInDataByte <<= 1; - } - - /*************************************************************** - * - * Store the modified byte. - * - ***************************************************************/ - - g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ] = cDataByte; - } - - break; - } - } - } - - return( 0 ); + //09/11/07 NN added local variables initialization + unsigned short int usDataSizeIndex = 0; + unsigned short int usLastBitIndex = 0; + unsigned short int usBufferIndex = 0; + unsigned short int usOutBitIndex = 0; + unsigned short int usLVDSIndex = 0; + unsigned char cDataByte = 0; + unsigned char cDMASKByte = 0; + unsigned char cInDataByte = 0; + unsigned char cCurBit = 0; + unsigned char cByteIndex = 0; + signed char cLVDSByteIndex = 0; + + //09/11/07 NN Type cast mismatch variables + usLastBitIndex = (unsigned short) (a_usiDataSize - 1); + + /*************************************************************** + * + * Iterate through the data bits. + * + ***************************************************************/ + + for ( usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++ ) { + if ( cByteIndex == 0 ) { + + /*************************************************************** + * + * Grab byte from DMASK buffer. + * + ***************************************************************/ + + if ( g_usDataType & DMASK_DATA ) { + cDMASKByte = g_pucOutDMaskData[ usBufferIndex ]; + } + else { + cDMASKByte = 0x00; + } + + /*************************************************************** + * + * Grab byte from TDI buffer. + * + ***************************************************************/ + + if ( g_usDataType & TDI_DATA ) { + cInDataByte = g_pucInData[ usBufferIndex ]; + } + + usBufferIndex++; + } + + cCurBit = readPort(); + cDataByte = ( unsigned char ) ( ( ( cInDataByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ); + + /*************************************************************** + * + * Initialize the byte to be zero. + * + ***************************************************************/ + + if ( usOutBitIndex % 8 == 0 ) { + g_pucOutData[ usOutBitIndex / 8 ] = 0x00; + } + + /*************************************************************** + * + * Use TDI, DMASK, and device TDO to create new TDI (actually + * stored in g_pucOutData). + * + ***************************************************************/ + + if ( ( ( ( cDMASKByte << cByteIndex ) & 0x80 ) ? 0x01 : 0x00 ) ) { + + if ( g_pLVDSList ) { + for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { + if ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex == usDataSizeIndex ) { + g_pLVDSList[ usLVDSIndex ].ucUpdate = 0x01; + break; + } + } + } + + /*************************************************************** + * + * DMASK bit is 1, use TDI. + * + ***************************************************************/ + + g_pucOutData[ usOutBitIndex / 8 ] |= ( unsigned char ) ( ( ( cDataByte & 0x1 ) ? 0x01 : 0x00 ) << ( 7 - usOutBitIndex % 8 ) ); + } + else { + + /*************************************************************** + * + * DMASK bit is 0, use device TDO. + * + ***************************************************************/ + + g_pucOutData[ usOutBitIndex / 8 ] |= ( unsigned char ) ( ( ( cCurBit & 0x1 ) ? 0x01 : 0x00 ) << ( 7 - usOutBitIndex % 8 ) ); + } + + /*************************************************************** + * + * Shift in TDI in order to get TDO out. + * + ***************************************************************/ + + usOutBitIndex++; + writePort( g_ucPinTDI, cDataByte ); + if ( usDataSizeIndex < usLastBitIndex ) { + sclock(); + } + + /*************************************************************** + * + * Increment the byte index. If it exceeds 7, then reset it back + * to zero. + * + ***************************************************************/ + + cByteIndex++; + if ( cByteIndex >= 8 ) { + cByteIndex = 0; + } + } + + /*************************************************************** + * + * If g_pLVDSList exists and pairs need updating, then update + * the negative-pair to receive the flipped positive-pair value. + * + ***************************************************************/ + + if ( g_pLVDSList ) { + for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { + if ( g_pLVDSList[ usLVDSIndex ].ucUpdate ) { + + /*************************************************************** + * + * Read the positive value and flip it. + * + ***************************************************************/ + + cDataByte = ( unsigned char ) ( ( ( g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usPositiveIndex / 8 ] << ( g_pLVDSList[ usLVDSIndex ].usPositiveIndex % 8 ) ) & 0x80 ) ? 0x01 : 0x00 ); + //09/11/07 NN Type cast mismatch variables + cDataByte = ( unsigned char ) (!cDataByte); + + /*************************************************************** + * + * Get the byte that needs modification. + * + ***************************************************************/ + + cInDataByte = g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ]; + + if ( cDataByte ) { + + /*************************************************************** + * + * Copy over the current byte and set the negative bit to 1. + * + ***************************************************************/ + + cDataByte = 0x00; + for ( cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex-- ) { + cDataByte <<= 1; + if ( 7 - ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex % 8 ) == cLVDSByteIndex ) { + + /*************************************************************** + * + * Set negative bit to 1. + * + ***************************************************************/ + + cDataByte |= 0x01; + } + else if ( cInDataByte & 0x80 ) { + cDataByte |= 0x01; + } + + cInDataByte <<= 1; + } + + /*************************************************************** + * + * Store the modified byte. + * + ***************************************************************/ + + g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ] = cDataByte; + } + else { + + /*************************************************************** + * + * Copy over the current byte and set the negative bit to 0. + * + ***************************************************************/ + + cDataByte = 0x00; + for ( cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex-- ) { + cDataByte <<= 1; + if ( 7 - ( g_pLVDSList[ usLVDSIndex ].usNegativeIndex % 8 ) == cLVDSByteIndex ) { + + /*************************************************************** + * + * Set negative bit to 0. + * + ***************************************************************/ + + cDataByte |= 0x00; + } + else if ( cInDataByte & 0x80 ) { + cDataByte |= 0x01; + } + + cInDataByte <<= 1; + } + + /*************************************************************** + * + * Store the modified byte. + * + ***************************************************************/ + + g_pucOutData[ g_pLVDSList[ usLVDSIndex ].usNegativeIndex / 8 ] = cDataByte; + } + + break; + } + } + } + + return( 0 ); } signed char ispVMProcessLVDS( unsigned short a_usLVDSCount ) { - unsigned short usLVDSIndex = 0; - - /*************************************************************** - * - * Allocate memory to hold LVDS pairs. - * - ***************************************************************/ + unsigned short usLVDSIndex = 0; + + /*************************************************************** + * + * Allocate memory to hold LVDS pairs. + * + ***************************************************************/ - ispVMMemManager( LVDS, a_usLVDSCount ); - g_usLVDSPairCount = a_usLVDSCount; + ispVMMemManager( LVDS, a_usLVDSCount ); + g_usLVDSPairCount = a_usLVDSCount; #ifdef VME_DEBUG - printf( "LVDS %d (", a_usLVDSCount ); + printf( "LVDS %d (", a_usLVDSCount ); #endif //VME_DEBUG - /*************************************************************** - * - * Iterate through each given LVDS pair. - * - ***************************************************************/ + /*************************************************************** + * + * Iterate through each given LVDS pair. + * + ***************************************************************/ - for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { + for ( usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++ ) { - /*************************************************************** - * - * Assign the positive and negative indices of the LVDS pair. - * - ***************************************************************/ + /*************************************************************** + * + * Assign the positive and negative indices of the LVDS pair. + * + ***************************************************************/ - //09/11/07 NN Type cast mismatch variables - g_pLVDSList[ usLVDSIndex ].usPositiveIndex = (unsigned short) ispVMDataSize(); - //09/11/07 NN Type cast mismatch variables - g_pLVDSList[ usLVDSIndex ].usNegativeIndex = (unsigned short)ispVMDataSize(); + //09/11/07 NN Type cast mismatch variables + g_pLVDSList[ usLVDSIndex ].usPositiveIndex = (unsigned short) ispVMDataSize(); + //09/11/07 NN Type cast mismatch variables + g_pLVDSList[ usLVDSIndex ].usNegativeIndex = (unsigned short)ispVMDataSize(); #ifdef VME_DEBUG - if ( usLVDSIndex < g_usLVDSPairCount - 1 ) { - printf( "%d:%d, ", g_pLVDSList[ usLVDSIndex ].usPositiveIndex, g_pLVDSList[ usLVDSIndex ].usNegativeIndex ); - } - else { - printf( "%d:%d", g_pLVDSList[ usLVDSIndex ].usPositiveIndex, g_pLVDSList[ usLVDSIndex ].usNegativeIndex ); - } + if ( usLVDSIndex < g_usLVDSPairCount - 1 ) { + printf( "%d:%d, ", g_pLVDSList[ usLVDSIndex ].usPositiveIndex, g_pLVDSList[ usLVDSIndex ].usNegativeIndex ); + } + else { + printf( "%d:%d", g_pLVDSList[ usLVDSIndex ].usPositiveIndex, g_pLVDSList[ usLVDSIndex ].usNegativeIndex ); + } #endif //VME_DEBUG - } + } #ifdef VME_DEBUG - printf( ");\n", a_usLVDSCount ); + printf( ");\n", a_usLVDSCount ); #endif //VME_DEBUG - return( 0 ); + return( 0 ); } diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/vmopcode.h b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/vmopcode.h index d72364a47cee..7dd6fcb3ca36 100644 --- a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/vmopcode.h +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/vmopcode.h @@ -10,7 +10,7 @@ * VME version. * * History: -* +* ***************************************************************/ #define VME_VERSION_NUMBER "12.2" @@ -39,7 +39,7 @@ /*************************************************************** * -* Flow control register bit definitions. A set bit indicates +* Flow control register bit definitions. A set bit indicates * that the register currently exhibits the corresponding mode. * ***************************************************************/ @@ -68,11 +68,11 @@ #define HEAP_IN 0x0080 /* Data is from the heap. */ #define LHEAP_IN 0x0200 /* Data is from intel data buffer. */ #define VARIABLE 0x0400 /* Data is from a declared variable. */ -#define CRC_DATA 0x0800 /* CRC data is pressent. */ +#define CRC_DATA 0x0800 /* CRC data is pressent. */ #define CMASK_DATA 0x1000 /* CMASK data is pressent. */ -#define RMASK_DATA 0x2000 /* RMASK data is pressent. */ +#define RMASK_DATA 0x2000 /* RMASK data is pressent. */ #define READ_DATA 0x4000 /* READ data is pressent. */ -#define DMASK_DATA 0x8000 /* DMASK data is pressent. */ +#define DMASK_DATA 0x8000 /* DMASK data is pressent. */ /*************************************************************** * @@ -92,10 +92,10 @@ * ***************************************************************/ -#define VENDOR 0x56 -#define LATTICE 0x01 -#define ALTERA 0x02 -#define XILINX 0x03 +#define VENDOR 0x56 +#define LATTICE 0x01 +#define ALTERA 0x02 +#define XILINX 0x03 /*************************************************************** * @@ -134,7 +134,7 @@ #define HEAP 0x32 /* The memory size needed to hold one loop. */ #define REPEAT 0x33 /* The beginning of the loop. */ #define LEFTPAREN 0x35 /* The beginning of data following the loop. */ -#define VAR 0x55 /* Plac holder for loop data. */ +#define VAR 0x55 /* Plac holder for loop data. */ #define SEC 0x1C /* The delay time in seconds that must be observed. */ #define SMASK 0x1D /* The mask for TDI data. */ #define MAX 0x1E /* The absolute maximum wait time. */ @@ -142,15 +142,15 @@ #define OFF 0x20 /* Dis-assert the targeted pin. */ #define SETFLOW 0x30 /* Change the flow control register. */ #define RESETFLOW 0x31 /* Clear the flow control register. */ -#define CRC 0x47 /* The following data stream is used for CRC calculation. */ -#define CMASK 0x48 /* The following data stream is used as mask for CRC calculation. */ +#define CRC 0x47 /* The following data stream is used for CRC calculation. */ +#define CMASK 0x48 /* The following data stream is used as mask for CRC calculation. */ #define RMASK 0x49 /* The following data stream is used as mask for read and save. */ -#define READ 0x50 /* The following data stream is used for read and save. */ +#define READ 0x50 /* The following data stream is used for read and save. */ #define ENDLOOP 0x59 /* The end of the repeat loop. */ #define SECUREHEAP 0x60 /* Used to secure the HEAP opcode. */ -#define VUES 0x61 /* Support continue if fail. */ +#define VUES 0x61 /* Support continue if fail. */ #define DMASK 0x62 /* The following data stream is used for dynamic I/O. */ -#define COMMENT 0x63 /* Support SVF comments in the VME file. */ +#define COMMENT 0x63 /* Support SVF comments in the VME file. */ #define HEADER 0x64 /* Support header in VME file. */ #define FILE_CRC 0x65 /* Support crc-protected VME file. */ #define LCOUNT 0x66 /* Support intelligent programming. */ @@ -158,7 +158,7 @@ #define LSDR 0x68 /* Support intelligent programming. */ #define LHEAP 0x69 /* Memory needed to hold intelligent data buffer */ #define CONTINUE 0x70 /* Allow continuation. */ -#define LVDS 0x71 /* Support LVDS. */ +#define LVDS 0x71 /* Support LVDS. */ #define ENDVME 0x7F /* End of the VME file. */ #define HIGH 0x80 /* Assert the targeted pin. */ #define LOW 0x81 /* Dis-assert the targeted pin. */ @@ -170,12 +170,12 @@ * ***************************************************************/ -#define VME_VERIFICATION_FAILURE -1 -#define VME_FILE_READ_FAILURE -2 -#define VME_VERSION_FAILURE -3 -#define VME_INVALID_FILE -4 -#define VME_ARGUMENT_FAILURE -5 -#define VME_CRC_FAILURE -6 +#define VME_VERIFICATION_FAILURE -1 +#define VME_FILE_READ_FAILURE -2 +#define VME_VERSION_FAILURE -3 +#define VME_INVALID_FILE -4 +#define VME_ARGUMENT_FAILURE -5 +#define VME_CRC_FAILURE -6 /*************************************************************** * @@ -185,7 +185,7 @@ /* Support LVDS */ typedef struct { - unsigned short usPositiveIndex; - unsigned short usNegativeIndex; - unsigned char ucUpdate; + unsigned short usPositiveIndex; + unsigned short usNegativeIndex; + unsigned char ucUpdate; } LVDSPair; From a35960bf0c4e2f72dd6c8279b06c7d399e0edc54 Mon Sep 17 00:00:00 2001 From: Pradchaya P Date: Thu, 9 May 2019 15:32:09 +0800 Subject: [PATCH 4/4] [platform/cel] fix cpld upgrade tool reject mixed-case image file name --- .../sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c index af173a0fea3d..ec3ad8c07252 100644 --- a/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c +++ b/platform/broadcom/sonic-platform-modules-cel/tools/ispvme_12.2/ispvm_ui.c @@ -734,10 +734,10 @@ int main( int argc, char * argv[] ) for ( iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++ ) { /* Process all VME files sequentially */ strcpy( szCommandLineArg, argv[ iCommandLineIndex ] ); if ( !strcmp( strlwr( szCommandLineArg ), "-c" ) && ( iCommandLineIndex == 1 ) ) { + continue; } - else if ( !strcmp( strlwr( szCommandLineArg ), "-checksum" )) {} - else if(((iCommandLineIndex >= 4)&&(set_freq == 1)) || (set_freq == 0)) - { + else if (((iCommandLineIndex >= 4)&&(set_freq == 1)) || (set_freq == 0)) { + strcpy( szCommandLineArg, argv[ iCommandLineIndex ] ); vme_out_string( "Processing virtual machine file ("); vme_out_string( szCommandLineArg ); vme_out_string (")......\n\n");