Skip to content
Snippets Groups Projects
ivm_core.c 65.6 KiB
Newer Older
/*
 * Porting to u-boot:
 *
 * (C) Copyright 2010
 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
 *
 * Lattice ispVME Embedded code to load Lattice's FPGA:
 *
 * Copyright 2009 Lattice Semiconductor Corp.
 *
 * 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/11/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
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <linux/string.h>
#include <malloc.h>
#include <lattice.h>

#define vme_out_char(c)	printf("%c", c)
#define vme_out_hex(c)	printf("%x", c)
#define vme_out_string(s) printf("%s", s)

/*
 *
 * 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.
 *
 */

static unsigned short g_usFlowControl;
unsigned short g_usDataType;

/*
 *
 * 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.
 *
 */

static unsigned short g_usHeadDR;
static unsigned short g_usHeadIR;
static unsigned short g_usTailDR;
static unsigned short g_usTailIR;

/*
 *
 * Global variable to store the number of bits of data or instruction
 * to be shifted into or out from the device.
 *
 */

static unsigned short g_usiDataSize;

/*
 *
 * Stores the frequency. Default to 1 MHz.
 *
 */

static int g_iFrequency = 1000;

/*
 *
 * Stores the maximum amount of ram needed to hold a row of data.
 *
 */

static unsigned short g_usMaxSize;

/*
 *
 * Stores the LSH or RSH value.
 *
 */

static unsigned short g_usShiftValue;

/*
 *
 * Stores the current repeat loop value.
 *
 */

static unsigned short g_usRepeatLoops;

/*
 *
 * Stores the current vendor.
 *
 */

static signed char g_cVendor = LATTICE;

/*
 *
 * Stores the VME file CRC.
 *
 */

unsigned short g_usCalculatedCRC;

/*
 *
 * Stores the Device Checksum.
 *
 */
/* 08/28/08 NN Added Calculate checksum support. */
unsigned long g_usChecksum;
static unsigned int g_uiChecksumIndex;

/*
 *
 * Stores the current state of the JTAG state machine.
 *
 */

static signed char g_cCurrentJTAGState;

/*
 *
 * 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;
unsigned short g_iHeapCounter;
unsigned short g_iHEAPSize;
static unsigned short previous_size;

/*
 *
 * 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;
unsigned short g_usIntelBufferSize;
Loading
Loading full blame...