📄 复件 boundary.cpp
字号:
// Boundary.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include <stdio.h>
#include <malloc.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
struct DeviceID
{
int Length;
char *IdCode;
};
struct JTAGInstruction
{
int Length;
char *ExTest;
};
struct BoundaryRegister
{
char Cell[16];
char Signal[32];
char Pin[16];
char Type[16];
char SafeVal;
int ControlReg;
char ControlVal;
char DisableVal;
};
struct BoundaryRegisters
{
int Length;
struct BoundaryRegister * Register;
};
struct Device
{
char *Name;
struct JTAGInstruction Instruction;
struct DeviceID ID;
struct BoundaryRegisters Boundary;
struct Device * Next;
struct Device * Prev;
};
Device *FirstDevice = NULL, *CurrentDevice = NULL, *LastDevice = NULL;
BOOL ReadLine(FILE* hfile, char * buffer)
{
char ch;
int count;
count = 0;
while( !feof( hfile ) )
{
ch = fgetc( hfile);
if((ch==0x0d) || (ch == 0x0a)||(ch == 0x1a))ch = 0;
else if((ch<0x20) || (ch > 0x7e)) ch = 0x20;
if((ch>=97) && (ch<=126))ch -= 32;
if(count == 0)
{
if(ch == 32)continue;
else if(ch == 0)continue;
buffer[count] = ch;
count++;
continue;
}
if(ch == 32)if(buffer[count-1] == 32)continue;
if(ch == '-')if(buffer[count-1] == '-')buffer[count-1] = 0;
buffer[count] = ch;
count ++;
if(ch == 0)
{
if(buffer[0] != 0)break;
else count = 0;
}
};
buffer[count] = 0;
if(buffer[strlen(buffer)-1] == ' ')buffer[strlen(buffer)-1] = 0;
return TRUE;
};
BOOL MatchWord(char * str1, char* str2)
{
char i = 0;
BOOL result = TRUE;
while(str1[i] != 0)
{
if(str2[i]!=str1[i])
{
result = FALSE;
break;
}
i++;
}
return result;
};
BOOL FillDevice(Device * chip, char * FileName)
{
int i,j,temp;
FILE* hfile;
char buffer[1024],targetstr[255],targetstr2[255];
int tNum,ofset;
char tCell[16];
char tSignal[32];
char tPin[16];
char tType[16];
char tSafeVal;
int tControlReg;
char tControlVal;
char tDisableVal;
strcpy(buffer,"LIBRARY\\");
strcat(buffer,FileName);
strcat(buffer,".BSD");
hfile = fopen(buffer,"r");
if(hfile == NULL)return(FALSE);
chip->Next = NULL;
chip->Prev = NULL;
//--------------------------------------
//---- Set Name
chip->Name = (char*)malloc(strlen(FileName)+1);
strcpy(chip->Name,FileName);
//--------------------------------------
//----find out instruction length
rewind(hfile);
strcpy(targetstr,"ATTRIBUTE INSTRUCTION_LENGTH OF ");
strcat(targetstr,FileName);
strcat(targetstr," : ENTITY IS");
while(!feof(hfile))
{
ReadLine(hfile, buffer);
if(MatchWord(targetstr,buffer))
{
sscanf(buffer+strlen(targetstr),"%d",&chip->Instruction.Length);
break;
}
}
//--------------------------------------
//----find out Extest instruction
rewind(hfile);
strcpy(targetstr,"\"EXTEST (");
chip->Instruction.ExTest = (char*)malloc(chip->Instruction.Length+1);
chip->Instruction.ExTest[chip->Instruction.Length]=0;
while(!feof(hfile))
{
ReadLine(hfile, buffer);
if(MatchWord(targetstr,buffer))
{
for(i=0;i<chip->Instruction.Length;i++)
chip->Instruction.ExTest[i] = buffer[strlen(targetstr)+i];
break;
}
}
//--------------------------------------
//----find out IDCODE
rewind(hfile);
strcpy(targetstr,"ATTRIBUTE IDCODE_REGISTER OF ");
strcat(targetstr,FileName);
strcat(targetstr," : ENTITY IS");
while(!feof(hfile))
{
ReadLine(hfile, buffer);
if(MatchWord(targetstr,buffer))
{
ReadLine(hfile, buffer);
i=1;
while((buffer[i]=='0')||(buffer[i]=='1'))i++;
chip->ID.Length = i - 1;
chip->ID.IdCode = (char*)malloc(chip->ID.Length+1);
chip->ID.IdCode[chip->ID.Length]=0;
for(j=1;j<i;j++)
chip->ID.IdCode[j-1] = buffer[j];
break;
}
}
if(feof(hfile)) ///chip has no IDCODE
{
chip->ID.Length = 1;
chip->ID.IdCode = (char*)malloc(chip->ID.Length+1);
chip->ID.IdCode[1]=0;
chip->ID.IdCode[0]='X';
}
//--------------------------------------
//----find out boundary Length
rewind(hfile);
strcpy(targetstr,"ATTRIBUTE BOUNDARY_LENGTH OF ");
strcat(targetstr,FileName);
strcat(targetstr," : ENTITY IS");
while(!feof(hfile))
{
ReadLine(hfile, buffer);
if(MatchWord(targetstr,buffer))
{
sscanf(buffer+strlen(targetstr),"%d",&chip->Boundary.Length);
break;
}
}
//--------------------------------------
//----fill boundary
rewind(hfile);
chip->Boundary.Register = (struct BoundaryRegister *)malloc(sizeof(struct BoundaryRegister)*chip->Boundary.Length);
strcpy(targetstr,"ATTRIBUTE BOUNDARY_REGISTER OF ");
strcat(targetstr,FileName);
strcat(targetstr," : ENTITY IS");
while(!feof(hfile))
{
ReadLine(hfile, buffer);
if(MatchWord(targetstr,buffer))
{
while(!feof(hfile))
{
ReadLine(hfile, buffer);
if(buffer[0] != '"')continue;
temp = strlen(buffer);
for(i=0;i<temp;i++)
if(buffer[i] == '(')
{
buffer[i] = ' ';
break;
}
for(i=strlen(buffer);i>0;i--)
if(buffer[i] == ')')
{
buffer[i] = ' ';
break;
}
temp = strlen(buffer);
for(i=0;i<temp;i++)
{
if(buffer[i] == '"')buffer[i] = ' ';
if(buffer[i] == ',')buffer[i] = ' ';
if(buffer[i] == '&')buffer[i] = 0;
}
j = sscanf(buffer,"%d %s %s %s %c %d %c %c", &tNum, tCell, tSignal, tType, &tSafeVal, &tControlReg, &tControlVal, &tDisableVal);
if(j != 8)
{
tControlReg = -1;
tControlVal= 'X';
tDisableVal = 'X';
}
strcpy(chip->Boundary.Register[tNum].Cell, tCell);
strcpy(chip->Boundary.Register[tNum].Signal, tSignal);
strcpy(chip->Boundary.Register[tNum].Type, tType);
chip->Boundary.Register[tNum].SafeVal = tSafeVal;
chip->Boundary.Register[tNum].ControlReg = tControlReg;
chip->Boundary.Register[tNum].ControlVal = tControlVal;
chip->Boundary.Register[tNum].DisableVal = tDisableVal;
}
break;
}
}
//--------------------------------------
//----find Pin
for(i=0;i<chip->Boundary.Length;i++)
{
rewind(hfile);
targetstr[0] = '"';
strcpy(targetstr+1,chip->Boundary.Register[i].Signal);
if(targetstr[1] == 42)
{
chip->Boundary.Register[i].Pin[0] = 0;
continue;
}
tNum = 0;
temp = strlen(targetstr);
for(j=0;j<temp;j++)
if(targetstr[j] == '(')
{
targetstr[j] = 0;
sscanf(targetstr+j+1,"%d",&tNum);
strcpy(targetstr2,targetstr+1);
strcat(targetstr2," : ");
///////////////////
//find pin start value
rewind(hfile);
while(!feof(hfile))
{
ReadLine(hfile, buffer);
if(MatchWord(targetstr2,buffer))
{
temp = strlen(buffer);
for(j=0;j<temp;j++)
if(buffer[j] == '(')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -