⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boundary.cpp

📁 边界扫描软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			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] == '(')
						{
							sscanf(buffer + j + 1,"%d",&ofset);
							break;
						}
					break;
				}
			}

			tNum -= ofset;
			}
		strcat(targetstr,": ");

		while(!feof(hfile))
		{
			ReadLine(hfile, buffer);
			if(MatchWord(targetstr,buffer))
			{
				temp = strlen(buffer);
				for(j=strlen(targetstr);j<temp;j++)
				{
					if(buffer[j] == '(')buffer[j] = ' ';
					if(buffer[j] == ' ')continue;
					if(tNum == 0)
					{
						sscanf(buffer+j,"%s,", tPin);
						break;
					}
					if(buffer[j] == ',')tNum--;
				}
				temp = strlen(tPin);
				for(j=0;j<temp;j++)if((tPin[j] == ',')||(tPin[j] == ')')||(tPin[j] == '"'))tPin[j] = 0;
				strcpy(chip->Boundary.Register[i].Pin, tPin);
				break;
			}
		}
	}
	fclose(hfile);
	return TRUE;
};


void FreeDevice(Device * chip)
{
	free(chip->ID.IdCode);
	free(chip->Boundary.Register);
	free(chip->Instruction.ExTest);
	free(chip->Name);
	free(chip);
}

void ConstructChain()
{
	int i, pBound=0, pID=0, pInst=0;
	free(DeviceChain.ID.IdCode);
	free(DeviceChain.Boundary.Register);
	free(DeviceChain.Instruction.ExTest);
	free(SafeCode);
	free(TestCode);
	free(SafeRet);
	free(TestRet);

	DeviceChain.Boundary.Length = 0;
	DeviceChain.ID.Length = 0;
	DeviceChain.Instruction.Length = 0;

	CurrentDevice = FirstDevice;
	while(CurrentDevice != NULL)
	{
		DeviceChain.Boundary.Length += CurrentDevice->Boundary.Length;
		DeviceChain.ID.Length += CurrentDevice->ID.Length;
		DeviceChain.Instruction.Length += CurrentDevice->Instruction.Length;
		CurrentDevice = CurrentDevice->Next;
	}
	DeviceChain.ID.IdCode = (char*)malloc(DeviceChain.ID.Length+1);
	DeviceChain.Boundary.Register = (struct BoundaryRegister *)malloc(sizeof(struct BoundaryRegister)*DeviceChain.Boundary.Length);
	DeviceChain.Instruction.ExTest = (char*)malloc(DeviceChain.Instruction.Length+1);
	SafeCode = (char*)malloc(DeviceChain.Boundary.Length+1);
	TestCode = (char*)malloc(DeviceChain.Boundary.Length+1);
	SafeRet = (char*)malloc(DeviceChain.Boundary.Length+1);
	TestRet = (char*)malloc(DeviceChain.Boundary.Length+1);

	CurrentDevice = FirstDevice;
	while(CurrentDevice != NULL)
	{
		for(i=0;i<CurrentDevice->Boundary.Length;i++,pBound++)
		{
			strcpy(DeviceChain.Boundary.Register[pBound].Cell, CurrentDevice->Name);
			strcpy(DeviceChain.Boundary.Register[pBound].Pin, CurrentDevice->Boundary.Register[i].Pin);
			strcpy(DeviceChain.Boundary.Register[pBound].Signal, CurrentDevice->Boundary.Register[i].Signal);
			strcpy(DeviceChain.Boundary.Register[pBound].Type, CurrentDevice->Boundary.Register[i].Type);
			SafeCode[pBound] = CurrentDevice->Boundary.Register[i].SafeVal;
			if(SafeCode[pBound] == 'X')SafeCode[pBound] = '0';
		}

		for(i=0;i<CurrentDevice->ID.Length;i++,pID++)
			DeviceChain.ID.IdCode[pID] = CurrentDevice->ID.IdCode[CurrentDevice->ID.Length-1-i];

		for(i=0;i<CurrentDevice->Instruction.Length;i++,pInst++)
			DeviceChain.Instruction.ExTest[pInst] = CurrentDevice->Instruction.ExTest[CurrentDevice->Instruction.Length-1-i];
		CurrentDevice = CurrentDevice->Next;
	}
	DeviceChain.Instruction.ExTest[pInst] = 0;
	DeviceChain.ID.IdCode[pID] = 0;
	IDCode = DeviceChain.ID.IdCode;
	SafeCode[pBound] = 0;
	TestCode[pBound] = 0;
}


void reBuildCode(int DevNum, int RegNum)
{
	int i, pBound=0, j = 0;
	strcpy(TestCode,SafeCode);

	CurrentDevice = FirstDevice;
	while(CurrentDevice != NULL)
	{
		for(i=0;i<CurrentDevice->Boundary.Length;i++,pBound++)
		{
			if((DevNum == j)&&(RegNum == i))
			{
				TestCode[pBound] = (SafeCode[pBound] == '0'?'1':'0');
				TestLogic = (SafeCode[pBound] == '0');
				if(CurrentDevice->Boundary.Register[i].ControlReg != -1)
				{
					TestCode[pBound + CurrentDevice->Boundary.Register[i].ControlReg - i] = (CurrentDevice->Boundary.Register[i].ControlVal == '1'?'0':'1');
				}
			}
		}
		CurrentDevice = CurrentDevice->Next;
		j++;
	}



}



///================================================================================
//===================Main Window Control Processing================================

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_BOUNDARY, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_BOUNDARY);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_BOUNDARY);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= (LPCSTR)IDC_BOUNDARY;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      100, 100, 900, 600, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
HWND hListFile,hListDevice,hListPin;
HWND hListNag,hListPos;
HWND hButtonGo, hButtonStop;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
	char path[255], path1[255];
	FILE* htestfile;
	int deviceNum, boundaryNum;
	int i;
	BOOL TempJTAGing;

	switch (message) 
	{
		case WM_TIMER:
			if(wParam != 20008)return 0;
			if(!JTAGing)return 0;
			KillTimer(hWnd,20008);
			//MessageBox(hWnd, "IN", "Timer",MB_OK);
			SendMessage(hListPos, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);
			SendMessage(hListNag, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);			
			ExTest(DeviceChain.Instruction.ExTest, DeviceChain.Instruction.Length, SafeCode, SafeRet, DeviceChain.Boundary.Length);
			ExTest(DeviceChain.Instruction.ExTest, DeviceChain.Instruction.Length, TestCode, TestRet, DeviceChain.Boundary.Length);
			for(i=0;i<DeviceChain.Boundary.Length;i++)
			{
				if( (DeviceChain.Boundary.Register[i].Pin[0] != '*') && (SafeRet[i] != TestRet[i]))
				{
					sprintf(path,"%s  %s  %s  %s%c",DeviceChain.Boundary.Register[i].Cell, DeviceChain.Boundary.Register[i].Pin, DeviceChain.Boundary.Register[i].Signal, DeviceChain.Boundary.Register[i].Type, 0);
					if((TestLogic)^(TestRet[i] == '0'))SendMessage( hListPos, LB_ADDSTRING, (WPARAM) 0l,  (LPARAM) path);
					else SendMessage( hListNag, LB_ADDSTRING, (WPARAM) 0l,  (LPARAM) path);

				}
			}
			if(JTAGing)SetTimer(hWnd,20008,200,NULL);
			break;
		case WM_CREATE:
			hListFile = CreateWindow("LISTBOX","",WS_CHILD|LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER,0,0,200,200,hWnd,(HMENU)20001,hInst,NULL);
			hListDevice = CreateWindow("LISTBOX","",WS_CHILD|LBS_NOTIFY | WS_VSCROLL | WS_BORDER,200,0,200,200,hWnd,(HMENU)20002,hInst,NULL);
			hListPin = CreateWindow("LISTBOX","",WS_CHILD|LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER,400,0,250,200,hWnd,(HMENU)20003,hInst,NULL);
			hListPos = CreateWindow("LISTBOX","",WS_CHILD| LBS_SORT | WS_VSCROLL | WS_BORDER,650,0,250,200,hWnd,(HMENU)20004,hInst,NULL);
			hListNag = CreateWindow("LISTBOX","",WS_CHILD| LBS_SORT | WS_VSCROLL | WS_BORDER,650,200,250,200,hWnd,(HMENU)20005,hInst,NULL);
			hButtonGo = CreateWindow("BUTTON","Go Test!",WS_CHILD,650,400,100,50,hWnd,(HMENU)20006,hInst,NULL);
			hButtonStop = CreateWindow("BUTTON","Stop Test!",WS_CHILD,775,400,100,50,hWnd,(HMENU)20007,hInst,NULL);
			EnableWindow(hButtonStop,FALSE);
			EnableWindow(hButtonGo,FALSE);

            GetCurrentDirectory(255, path); 
            GetCurrentDirectory(255, path1); 
			strcat(path,"\\*.BCL");
            DlgDirList(hWnd, path, 20001, 0, 0); 
			ShowWindow(hListFile, SW_SHOW);
			ShowWindow(hListDevice, SW_SHOW);
			ShowWindow(hListPin, SW_SHOW);
			ShowWindow(hListPos, SW_SHOW);
			ShowWindow(hListNag, SW_SHOW);
			ShowWindow(hButtonGo, SW_SHOW);
			ShowWindow(hButtonStop, SW_SHOW);
			init_timer();
			if(!OpenPort())MessageBox(hWnd,"Port not opened!","PORT ERROR", MB_OK);

			break;
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case 20006://Go button
					EnableWindow(hButtonGo, FALSE);
					EnableWindow(hButtonStop, TRUE);
					JTAGing = TRUE;
					if(!CheckIdCode(IDCode, DeviceChain.ID.Length))MessageBox(hWnd,"IDCODE mismatch!","Error in IDCODE",MB_OK);
					SetTimer(hWnd,20008,200,NULL);
					break;
				case 20007://stop button
					EnableWindow(hButtonGo, TRUE);
					EnableWindow(hButtonStop, FALSE);
					JTAGing = FALSE;
					KillTimer(hWnd,20008);
					break;
				case 20002://Select Device
					switch(wmEvent)
					{
					case LBN_SELCHANGE:
						JTAGing = FALSE;
						EnableWindow(hButtonGo, FALSE);
						EnableWindow(hButtonStop, FALSE);
						SendMessage(hListPin, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);
						SendMessage(hListPos, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);
						SendMessage(hListNag, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);			
						CurrentDevice = FirstDevice;
						deviceNum = SendMessage(hListDevice, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0 );
						while(deviceNum>0)
						{
							CurrentDevice = CurrentDevice->Next;
							if(CurrentDevice == NULL)exit(0);
							deviceNum--;
						}
						for(boundaryNum = 0;boundaryNum<CurrentDevice->Boundary.Length;boundaryNum++)
							if((CurrentDevice->Boundary.Register[boundaryNum].Pin[0] != '*')&&
								((CurrentDevice->Boundary.Register[boundaryNum].Type[0] == 'B')||
								(CurrentDevice->Boundary.Register[boundaryNum].Type[0] == 'O')))
							{
								sprintf(path,"%5s    %c    %s    %d%c",
									CurrentDevice->Boundary.Register[boundaryNum].Pin,
									CurrentDevice->Boundary.Register[boundaryNum].SafeVal,
									CurrentDevice->Boundary.Register[boundaryNum].Signal,
									boundaryNum, 0);
								SendMessage(hListPin, LB_ADDSTRING, (WPARAM)0l, (LPARAM)path);
							}
						//MessageBox(hWnd,CurrentDevice->ID.IdCode,"ID",MB_OK);
						//MessageBox(hWnd,CurrentDevice->Instruction.ExTest,"Instruction",MB_OK);

						break;
					}
					break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				case 20003://Select Pin
					switch(wmEvent)
					{
					case LBN_SELCHANGE:
						KillTimer(hWnd,20008);
						TempJTAGing = JTAGing;
						JTAGing = FALSE;
						SendMessage(hListPos, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);
						SendMessage(hListNag, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);			
						SendMessage(hListPin, LB_GETTEXT, (WPARAM)SendMessage(hListPin, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0 ),  (LPARAM) path);
						sscanf(path,"%*s %*c %*s %d",&boundaryNum);
						deviceNum = SendMessage(hListDevice, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0 );
						reBuildCode(deviceNum, boundaryNum);
						JTAGing = TempJTAGing;
						if(JTAGing)
						{
							SetTimer(hWnd, 20008, 200, NULL);
							EnableWindow(hButtonGo, FALSE);
							EnableWindow(hButtonStop, TRUE);
						}
						else
						{
							EnableWindow(hButtonGo, TRUE);
							EnableWindow(hButtonStop, FALSE);
						}
						//MessageBox(hWnd,SafeCode,"Safe",MB_OK);
						//MessageBox(hWnd,TestCode,"Test",MB_OK);
						break;
					}
					break;
				case 20001://Select Chain
					switch(wmEvent)
					{
					case LBN_SELCHANGE:
						JTAGing = FALSE;
						EnableWindow(hButtonGo, FALSE);
						EnableWindow(hButtonStop, FALSE);
						SendMessage(hListPin, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);
						SendMessage(hListDevice, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);
						SendMessage(hListPos, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);
						SendMessage(hListNag, LB_RESETCONTENT, (WPARAM)0l, (LPARAM)0l);			

						CurrentDevice = LastDevice;
						while(LastDevice != NULL)
						{
							CurrentDevice = LastDevice;
							LastDevice = LastDevice->Prev;
							FreeDevice(CurrentDevice);
						}
						CurrentDevice = LastDevice = FirstDevice = NULL;
						SendMessage(hListFile, LB_GETTEXT, (WPARAM)SendMessage(hListFile, LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0 ),  (LPARAM) path);
						strcpy(path1,"\\TEST\\");
						strcpy(path1,path);
						htestfile = fopen(path1,"r");
						while(!feof(htestfile))
						{
							ReadLine(htestfile, path);
							if((path[0] == 0)||(path[0] == ' '))continue;
							SendMessage( hListDevice, LB_ADDSTRING, (WPARAM) 0l,  (LPARAM) path);
							LastDevice = (struct Device*)malloc(sizeof(Device));
							if(!FillDevice(LastDevice,path))
							{
								MessageBox(hWnd,path,"BSD file not found!",MB_OK);//,"Error in Library"
								exit(0);
							}
							if(FirstDevice == NULL)
								CurrentDevice = FirstDevice = LastDevice;
							else
							{
								CurrentDevice->Next = LastDevice;
								LastDevice->Prev = CurrentDevice;
							}
							CurrentDevice = LastDevice;
						}
						fclose(htestfile);
						ConstructChain();
						//MessageBox(hWnd,DeviceChain.ID.IdCode,"ID",MB_OK);
						//MessageBox(hWnd,DeviceChain.Instruction.ExTest,"Instruction",MB_OK);
						break;
					}
					break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			RECT rt;
			GetClientRect(hWnd, &rt);
			//DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
			EndPaint(hWnd, &ps);
			break;
		case WM_SIZE:
			MoveWindow(hListFile,0,0,200,HIWORD(lParam),TRUE);
			MoveWindow(hListDevice,200,0,200,HIWORD(lParam),TRUE);
			MoveWindow(hListPin,400,0,(LOWORD(lParam)-400)/2,HIWORD(lParam),TRUE);
			MoveWindow(hListPos,400 + (LOWORD(lParam)-400)/2,0,(LOWORD(lParam)-400)/2,(HIWORD(lParam)-100)/2,TRUE);
			MoveWindow(hListNag,400 + (LOWORD(lParam)-400)/2,(HIWORD(lParam)-100)/2,(LOWORD(lParam)-400)/2,(HIWORD(lParam)-100)/2,TRUE);
			MoveWindow(hButtonGo,400 + (LOWORD(lParam)-400)/2,HIWORD(lParam)-100,(LOWORD(lParam)-400)/4,90,TRUE);
			MoveWindow(hButtonStop,400 + (LOWORD(lParam)-400)*3/4,HIWORD(lParam)-100,(LOWORD(lParam)-400)/4,90,TRUE);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
				return TRUE;

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
			{
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -