/**************************************************************
*
* Lattice Semiconductor Corp. Copyright 2008
*
*
***************************************************************/
/**************************************************************
*
* Revision History of slim_pro.c
*
*
* 09/11/07 NN Updated to support version 1.3
* This version supported new POLING STATUS LOOP opcodes (LOOP and ENDLOOP)
* for Flash programming of the Lattice FPGA devices
* 09/11/07 NN type cast all the mismatch variables
***************************************************************/
#include <stdio.h>
#include "opcode.h"
/*************************************************************
* *
* PROTOTYPES *
* *
*************************************************************/
unsigned int ispVMDataSize();
short int ispVMShiftExec(unsigned int a_uiDataSize);
short int ispVMShift(char a_cCommand);
unsigned char GetByte(int a_iCurrentIndex, char a_cAlgo);
void ispVMStateMachine(char a_cNextState);
void ispVMClocks(unsigned int a_usClocks);
void ispVMBypass(unsigned int a_siLength);
void sclock();
short int ispVMRead(unsigned int a_uiDataSize);
void ispVMSend(unsigned int a_uiDataSize);
void ispVMLCOUNT(unsigned short a_usCountSize);
void ispVMLDELAY();
/*************************************************************
* *
* EXTERNAL FUNCTION *
* *
*************************************************************/
extern void ispVMDelay(unsigned int a_usDelay);
extern unsigned char readPort();
extern void writePort(unsigned char a_ucPins, unsigned char a_ucValue);
/*************************************************************
* *
* GLOBAL VARIABLES *
* *
*************************************************************/
int g_iMovingAlgoIndex = 0; /*** variable to hold the current index in the algo array ***/
int g_iMovingDataIndex = 0; /*** variable to hold the current index in the data array ***/
unsigned short g_usDataType = 0x0000; /*** data type register used to hold information ***
**** about the algorithm and data ***/
unsigned char g_cEndDR = 0; /*** used to hold the ENDDR state. ***/
unsigned char g_cEndIR = 0; /*** used to hold the ENDIR state. ***/
short int g_siHeadDR = 0; /*** used to hold the header data register ***/
short int g_siHeadIR = 0; /*** used to hold the header instruction register ***/
short int g_siTailDR = 0; /*** used to hold the trailer data register ***/
short int g_siTailIR = 0; /*** used to hold the trailer instruction register ***/
int g_iMainDataIndex = 0; /*** forward - only index used as a placed holder in the data array ***/
int g_iRepeatIndex = 0; /*** Used to point to the location of REPEAT data ***/
int g_iTDIIndex = 0; /*** Used to point to the location of TDI data ***/
int g_iTDOIndex = 0; /*** Used to point to the location of TDO data ***/
int g_iMASKIndex = 0; /*** Used to point to the location of MASK data ***/
unsigned char g_ucCompressCounter = 0; /*** used to indicate how many times 0xFF is repeated ***/
short int g_siIspPins = 0x00; /*** holds the current byte to be sent to the hardware ***/
char g_cCurrentJTAGState = 0; /*** holds the current state of JTAG state machine ***/
int g_iLoopIndex = 0;
int g_iLoopMovingIndex = 0; /*** Used to point to the location of LOOP data ***/
int g_iLoopDataMovingIndex = 0;
unsigned short g_usLCOUNTSize = 0;
unsigned char g_ucLDELAYState = IDLE;
unsigned short int g_ucLDELAYTCK = 0;
unsigned short int g_ucLDELAYDelay = 0;
unsigned short int m_loopState = 0;
/*************************************************************
* *
* EXTERNAL VARIABLES *
* *
* If the algorithm does not require the data, then *
* declare the variables g_pucDataArray and g_iDataSize *
* as local variables and set them to NULL and 0, *
* respectively. *
* *
* Example: *
* unsigned char * g_pucDataArray = NULL; *
* int g_iDataSize = 0; *
* *
*************************************************************/
unsigned char* g_pucAlgoArray = NULL;
unsigned char* g_pucDataArray = NULL;
int g_iAlgoSize = 0;
int g_iDataSize = 0;
const struct iState
{
/*** JTAG state machine transistion table ***/
unsigned char CurState; /*** From this state ***/
unsigned char NextState; /*** Step to this state ***/
unsigned char Pattern; /*** The pattern of TMS ***/
unsigned char Pulses; /*** The number of steps ***/
} iStates[25] =
{
{ DRPAUSE, SHIFTDR, 0x80, 2 },
{ IRPAUSE, SHIFTIR, 0x80, 2 },
{ SHIFTIR, IRPAUSE, 0x80, 2 },
{ SHIFTDR, DRPAUSE, 0x80, 2 },
{ DRPAUSE, IDLE, 0xC0, 3 },
{ IRPAUSE, IDLE, 0xC0, 3 },
{ RESET, IDLE, 0x00, 1 },
{ RESET, DRPAUSE, 0x50, 5 },
{ RESET, IRPAUSE, 0x68, 6 },
{ IDLE, RESET, 0xE0, 3 },
{ IDLE, DRPAUSE, 0xA0, 4 },
{ IDLE, IRPAUSE, 0xD0, 5 },
{ DRPAUSE, RESET, 0xF8, 5 },
{ DRPAUSE, IRPAUSE, 0xF4, 7 },
{ DRPAUSE, DRPAUSE, 0xE8, 6 }, /* 06/14/06 Support POLING STATUS LOOP*/
{ IRPAUSE, RESET, 0xF8, 5 },
{ IRPAUSE, DRPAUSE, 0xE8, 6 },
{ IRPAUSE, SHIFTDR, 0xE0, 5 },
{ SHIFTIR, IDLE, 0xC0, 3 },
{ SHIFTDR, IDLE, 0xC0, 3 },
{ RESET, RESET, 0xFC, 6 },
{ DRPAUSE, DRCAPTURE, 0xE0, 4 }, /* 11/15/05 Support DRCAPTURE*/
{ DRCAPTURE, DRPAUSE, 0x80, 2 },
{ IDLE, DRCAPTURE, 0x80, 2 },
{ IRPAUSE, DRCAPTURE, 0xE0, 4 }
};
/*************************************************************
* *
* ISPPROCESSVME *
* *
* INPUT: *
* None. *
* *
* RETURN: *
* The return value indicates whether the vme was *
* processed successfully or not. A return value equal *
* to or greater than 0 is passing, and less than 0 is *
* failing. *
* *
* DESCRIPTION: *
* This function is the core of the embedded processor. *
* It extracts the VME file for the high - level tokens *
* such as SIR, SDR, STATE, etc, and calls the *
* appropriate functions to process them. *
* *
*************************************************************/
short int ispProcessVME() //reentrant
{
unsigned char ucOpcode = 0;
unsigned char ucState = 0;
short int siRetCode = 0;
static char cProgram = 0;
unsigned int uiDataSize = 0;
int iLoopCount = 0;
unsigned int iMovingAlgoIndex = 0;
/*************************************************************
*