📄 ivm_eprom.c
字号:
/****************************************************************************
* ispVME(EPROM Based) *
* Lattice Semiconductor Corp. Copyright 1998 - 2003. *
* The EPROM Based Version: *
* The VME(Virtual Machine Embedded) File is converted in HEX file and then *
* compiled and linked with the ispVM as a data array vme[]. This eliminates*
* the RAM required to hold a row of data if to read from a file. *
* The 3 modules: *
* 1. ivm_ui9a.c---The user interface module. *
* 2. hardware.c---The data fetching and hardware interface module. *
* The EPROM and pointer based data fetching is employed as *
* well as driving signals to the targeted chip. * *
* The VME file in HEX is included in this module to be *
* linked with ispVM. *
* 3. ivm_core.c---The core of ispVM. *
* The opcode supported by ispVM are decoded and processed *
* accordingly. *
* *
* ispVME 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. *
* This ispVM need less than 100 bytes RAM to hold all the variables it *
* needs. *
* *
* 10/15/01 Changed form V8.0 to V9.0 to support mulitple devices SVF file. *
* *
* 2/14/02 tnt changed from V9.0 to V10.0 to support looping *
* 5/2/03 Update to ispVME v10.1 *
* *
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vmedefinitions.h"
#include "vmopcode.h"
#include "hardware.h"
#include "vme_file.h"
#include "cable.h"
unsigned short InPort = 0x379;
unsigned short OutPort = 0x378;
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*/
/*4/26/01 Added to support multiple devices in a single SVF file*/
*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*/
/*2/14/02 tnt added to support looping*/
*pucHeapMemory=NULL,
*OutDMaskData=NULL; /* local RAM to hold DMASK */
/*2/14/02 tnt added to support looping*/
unsigned short iHEAPSize = 0; /*the current size of HEAP in bytes*/
unsigned short iHeapCounter=0; /*points to the current byte of HEAP*/
extern unsigned short usFlowControl;
extern unsigned short usDataType;
unsigned short delayPercent = 0;
char szCommandLineArg[ 300 ] = { 0 };
char *fp;
extern char ispVMCode(void);
extern unsigned char GetByte(void);
extern void ispVMStart(void);
extern void ispVMEnd(void);
char ispVM(void);
/*************************************************************
* *
* GETBYTE *
* This procedure reads a byte from the ispVM File *
*************************************************************/
unsigned char GetByte()
{
unsigned char data;
static unsigned short index=0;
static unsigned short arrayindex=0;
if (usDataType&HEAP_IN) {
if (iHeapCounter > iHEAPSize)
return -1;
data = pucHeapMemory[iHeapCounter++];
}
else {
if (index==0) {
fp = vmeArray[arrayindex++];
}
data = *fp++;
if (index < (unsigned short)(VMEHEXMAX-1))
index++;
else
index = 0;
}
return (data);
}
/**********************************************************************
* *
* The Entry Point Of ispVM *
* process the given VME file which has algorithm and data included. *
***********************************************************************/
char ispVM()
{
char header[]={"__VME2.0"};
char rcode;
char i;
unsigned char CompressFlag = 0x00;
/*point to the current VMF file*/
for (i = 0; i < 8; i++)
{
if (GetByte() != header[i])
return (-4); /*the file has error*/
}
usDataType = 0x0000;
usFlowControl = 0x0000;
CompressFlag = GetByte();
if(CompressFlag == 0xf1) {
usDataType |= COMPRESS;
}
else if(CompressFlag == 0xf2) {
usDataType &= ~COMPRESS;
}
else {
return -3;
}
ispVMStart(); /*enable Lattice Cable*/
/*force the chain to Test-Logic/Reset*/
rcode= ispVMCode();
ispVMEnd(); /*reset the chain to Test-Logic/Reset*/
/*disable Lattice Cable*/
return (rcode);
}
/**************************************************************************
* *
* MemoryManager *
* Global var: *
* size-----------The size of memory in bytes to be allocated. *
* *
***************************************************************************/
void ispVMMemManager(char target, unsigned short size)
{
switch (target){
case XTDI:
case TDI:
InData = TdiBuf; /*array from vme_file.hex*/
break;
case XTDO:
case TDO:
OutData = TdoBuf; /*array from vme_file.hex*/
break;
case MASK:
OutMaskData = MaskBuf; /*array from vme_file.hex*/
break;
case HIR:
HIRData = HirBuf; /*array from vme file*/
break;
case TIR:
TIRData = TirBuf; /*array from vme file*/
break;
case HDR:
HDRData = HdrBuf; /*array from vme file*/
break;
case TDR:
TDRData = TdrBuf; /*array from vme file*/
break;
case HEAP:
pucHeapMemory = HeapBuf; /*array from vme file*/
break;
case DMASK:
OutDMaskData = DMASKBuf; /*array from vme file*/
break;
default:
return;
}
}
/*************************************************************
* *
* error_handler *
* *
* rcode - error code *
* *
* *
* This procedure return the address of the message string *
* for the corresponding error code. *
* *
*************************************************************/
void error_handler(short rcode, char *message)
{
char *error_message[] = {{"PASS"},
{"Verification Fail"},
{"Can't Find the File"},
{"Wrong File Type"},
{"File Error"},
{"Option Error"}};
strcpy(message, error_message[-rcode]);
}
/*************************************************************
* *
* MAIN *
* *
*************************************************************/
short main(int argc, char *argv[])
{
short int rcode = 0;
printf("\n Lattice Semiconductor Corp.\n");
printf("\n ispVME V10.1.1 Copyright 1998-2004.\n");
printf("\n For Daisy Chain of All In-System Programmable Devices\n\n");
if (argc > 3)
{
printf("\nUsage: vme [option] [number]\n\n");
printf("Example: vme -t 25\n");
printf("option -t: Increase Delay time by percent\n");
printf(" -t 25 \n");
printf(" example: Increase Delay time by 25 percent \n");
exit(1);
}
rcode = Check_Cable_Power();
if (rcode == CABLE_NOT_DETECT) {
printf("Download Cable not detected!\n");
exit(1);
}
if (rcode == POWER_OFF) {
printf("The Power is not ON!\n");
exit(1);
}
/* 2/15/02 tnt: look for delay argument */
if (argc == 3) {
strcpy(szCommandLineArg, argv[1]);
if (!strcmp(strlwr(szCommandLineArg), "-t")) {
strcpy(szCommandLineArg, argv[2]);
delayPercent = atoi(szCommandLineArg);
if (strstr(szCommandLineArg, "-")) {
rcode = -5;
}
if (!delayPercent) {
rcode = -5;
}
}
else {
rcode = -5;
}
}
else if (argc == 2) {
rcode = -5;
}
rcode = 0;
if (rcode == 0)
{
/*start programming and verification*/
rcode = ispVM();
}
if (rcode < 0)
{
error_handler(rcode, szCommandLineArg);
printf("\nFailed Due To %s\n", szCommandLineArg);
printf("\n");
printf("+-------+\n");
printf("| FAIL! |\n");
printf("+-------+\n");
return (-rcode);
}
else
{
printf("\n");
printf("+=======+\n");
printf("| PASS! |\n");
printf("+=======+\n");
}
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -