?? ispvm_ui.c
字號:
/****************************************************************************
ispvm_ui.c of ispVM(tm) Embedded (File Based)
Lattice Semiconductor Corp. Copyright 1998-2003.
ispVM(tm) ISP Virtual Machine provide multiple vendor In-System
Programming support.
All In-System Programmable devices can be supported by 4 simple constructs:
SIR, SDR, STATE and WAIT.
Complex tool is not required to support those 4 constructs. Lattice's
ispVM(tm) Embedded supports those 4 basic constructs through the most
efficient manner.
By using those 4 basic constructs and by adding a few high level
ispVM(tm) opcodes, In-System Programmable devices from any vendors can
be daisy chained together for programming by the ispVM(tm).
Other ispVM(tm) opcodes such as read and save, checksum calculation,
branching, indirect data addressing, operation selection etc. are all
deleted from this ispVM(tm) Embedded Version to make the footprint of the
ispVM(tm) Embedded the most ideal solution for embedded applications.
ispVME(tm) ispVM(tm) Embedded for Embedded Applications Where Resources
is A Premium.
This is the scale down version of the full ispVM target for embedded
applications. The footprint of this VM is less than 8K bytes in size.
Huffman encoding is used to minimize the Virtual Machine Format file size
without increasing the VM footprint and addtional RAM for decompression
is not required.
Typically only 100 bytes of RAM is required to hold one row of data when
processing the VMF file. The VM itself also need less than 100 bytes of
RAM to hold all the variables it needs.
Even if repeat looping is selected to reduce the VME file size, only
about 50 bytes of extra RAM will be required to hold the entire
repeat loop.
This module is the front end of the ispVME(tm) where the VME (Virtual
Machine Embedded) file resides on a hard disk.
The executable vme.exe comprises with the 3 modules:
ispvm_ui.c The User Interface of ispVME(tm);
ivm_Core.c The Core of the ispVM(tm).
hardware.c The hardware interface.
The VME files can be obtained by using the SVF2VME.exe utility to convert
SVF files from any vendors.
The VME file for ispLSI and ispGDX devices can be generated by using the
dld2vme.exe utility.
The daisy chaining process is automatically done by the utility. Example:
svf2vme ispLSI.svf ispMACH.svf 6 9500XL.svf 7000AE.svf -o chain.vme
A single VME file by the name of chain.vme is created which program
the ispLSI, ispMACH, 9500XL and 7000AE sequentially.
Simply launch the ispVME(tm) by typing:
vme chain.vme
The functional modules:
GetByte() Read a byte of code from the targeted VME file.
ispVMMemManager() Allocate memory to hold a row of data.
ispVM() Launch the ispVM(tm) with the given VME file.
error_handler() Supply error messages.
7.000 Howard Tang 8/20/98 convert form ispCODE5C.c v5c.001
7.001 Howard Tang 11/9/98 take care of last bits of data.
8.000 Howard Tang Employ splitting process for large data burst:
Example:
The large burst: SDR 120000 TDI (0000000.....);
Split into: ENDDR DRPAUSE;
SDR 60000 TDI (000000..);
SDR 60000 TDI (000000..);
9.000 Howard Tang 4/26/01 Enhance ispVMBypass function to accept
HIR 32 TDI (00000000);
so that multiple device in a single SVF file is
supported.
NOTE: The more complicated construct of Header like
HIR 32 TDI (00000000) TDO (00000000)
are not supported.
9.001 ht 8/23/01 Add a flow control register to turn on
and off SDR cascading due to the splitting of a large
burst.
Add support to token based ispSTREAM file from
ispcode V7.0 created by dld2isp V7.0. The Token
based ispSTREAM file is smaller in size than a VME
file. However the token based ispSTREAM file is
for ispLSI and ispGDX devices only. All MACH devices
shall use SVF file the convert to VME file.
* tnt 10/22/02 set freed memory to null *
* tnt 10/22/02 free memory after each vme file processed if multiple *
* vme files are given *
* 4/28/03 Update to v10.1. v10.1 supports Continue If Fail (USERCODE *
* Verification). Also changed were the preprocessor definitions *
* to make them clearer and easier to remove. *
* Those definitions are: VME_NT, VME_1532, VME_DEBUG. *
* By simply defining these in the make file, they will enable their*
* respective functions. *
* Note: VME_NT will include source code that Lattice Semiconductor *
* Corporation does not release regularly. Justifications must be *
* necessary to obtain the required files to compile for the NT *
* platform. *
* 2/11/03 Remove IEEE 1532 support. *
* *
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vmopcode.h"
#include "hardware.h"
#include "vmedefinitions.h"
#include "cable.h"
FILE * fptrVME; /*file pointer to the VME file*/
unsigned char * pucHeapMemory = NULL; /*holds the entire repeat loop*/
unsigned short iHeapCounter = 0; /*points to the current byte of HEAP*/
unsigned short iHEAPSize = 0; /*the current size of HEAP in bytes*/
unsigned char * OutMaskData = NULL, /*local RAM hold one row of MASK data*/
* InData = NULL, /*local RAM hold one row of TDI data*/
* OutData = NULL, /*local RAM hold one row of TDO data*/
* HIRData = NULL, /*local RAM hold the current SIR header*/
* TIRData = NULL, /*local RAM hold the current SIR trailer*/
* HDRData = NULL, /*local RAM hold the current SDR header*/
* TDRData = NULL; /*local RAM hold the current SDR trailer*/
unsigned short InPort = 0x379;
unsigned short OutPort = 0x378;
unsigned short delayPercent = 0;
char szCommandLineArg[ 300 ] = { 0 };
extern unsigned short usFlowControl;
extern unsigned short usDataType;
/* In IVM_CORE.c */
extern char ispVMCode(void);
extern unsigned char File_Compress;
extern char GetByte(void);
char ispVM( char * );
char GetByte(void);
void ispvMMemManager(char, unsigned short);
char ispVMFreeMem(void);
/* 05/27/03 Nguyen added to support Dynamic IO */
unsigned char *OutDMaskData=NULL; /*local RAM hold one row of MASK data*/
/****************************************************************************
GETBYTE
This procedure reads a byte from the VME File
8/29/01 ht Enhanced to copy the file into memory for repeat loop support.
Enhanced to read form the repeat loop memory base on the
usDataType flag.
Gobal:
usDataType------It controls the source of getting data.
pucHeapMemory-------It is to hold the entire repeat loop for execution.
*****************************************************************************/
unsigned char GetByte()
{
unsigned char ucData;
#ifdef VME_DEBUG
if ( usDataType & HEAP_IN ) {
printf( "Data retrieved from HEAP\n" );
}
else {
printf( "Data retrieved from FILE\n" );
}
#endif
if ( usDataType & HEAP_IN ) { /*fetch data from HEAP memory where repeat loop is*/
if ( iHeapCounter > iHEAPSize ) {
return -1; /*heap over-run occur*/
}
ucData = pucHeapMemory[ iHeapCounter++ ]; /*fetch data from the stored repeat loop*/
}
else {
ucData = fgetc( fptrVME );
if ( feof( fptrVME ) ) {
return -1;
}
}
#ifdef VME_DEBUG
printf( "%.2X\n", ucData );
#endif
return ( ucData );
}
/***************************************************************************
ispVMMemManager
Input:
cTarget---------Memory for holding one row of TDI, TDO or MASK data.
usSize-----------The size (in bytes) of memory to be allocated.
Each VME file contains an MEM opcode which is to inform the ispVM on the
worst case RAM size it needs to hold a row of data. This size actaully
is user controllable. By default it is 8000 bytes maximum. Typical size
is 100 bytes.
Memory is allocated upon on need basis to minimize waste.
****************************************************************************/
void ispVMMemManager( char cTarget, unsigned short usSize )
{
static unsigned short usPreviousSize = 0;
switch ( cTarget ) {
case XTDI:
case TDI:
if ( InData != NULL ) {
if ( usPreviousSize == usSize ) {/*memory exist*/
break;
}
else {
free( InData );
InData = NULL;
}
}
InData = ( unsigned char * ) malloc( usSize / 8 + 2 );
usPreviousSize = usSize;
break;
case XTDO:
case TDO:
if ( OutData!= NULL ) {
if ( usPreviousSize == usSize ) { /*already exist*/
break;
}
else {
free( OutData );
OutData = NULL;
}
}
OutData = ( unsigned char * ) malloc( usSize / 8 + 2 );
usPreviousSize = usSize;
break;
case MASK:
if ( OutMaskData != NULL ) {
if ( usPreviousSize == usSize ) {/*already allocated*/
break;
}
else {
free( OutMaskData );
OutMaskData = NULL;
}
}
OutMaskData = ( unsigned char * ) malloc( usSize / 8 + 2 );
usPreviousSize = usSize;
break;
case HIR:
if ( HIRData != NULL ) {
free( HIRData );
HIRData = NULL;
}
HIRData = ( unsigned char * ) malloc( usSize / 8 + 2 );
break;
case TIR:
if ( TIRData != NULL ) {
free( TIRData );
TIRData = NULL;
}
TIRData = ( unsigned char * ) malloc( usSize / 8 + 2 );
break;
case HDR:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -