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

📄 jtag.c

📁 arm7的JTAG调试工具源码
💻 C
字号:
/*
 * jtag.c : implement jtag control interface
 *
 * Copyright (C) 2004, OPEN-JTAG, All rights reserved.
 */


#include <stdio.h>
#include <conio.h>
#include <windows.h>

#include "jtag.h"
#include "xjerr.h"
#include "types.h"

#define in_prefix 0x33
#define out_prefix 0x55
#define recode_lp1 0

//Used to record the status of the parallel port
static u8 port_data = 0;	


/*
 * paral_output() -
 *		Used to output a 8-bit wide data to the parallel
 *		port.
 */
static void paral_output(u8 data)
{	 	
	if(recode_lp1){
	//	store_lp1_out(data); 
	}// pref of output, added by myself
	_outp(PARAL_DATA_PORT, data);
}


/*
 * paral_intput() -
 *		Used to read a 8-bit wide input data from the parallel
 *		port.
 */
static u8 paral_input(void) 
{
	u8 data;
	
	data = _inp(PARAL_STAT_PORT);

	if(recode_lp1){
		store_lp1_in(data);
	}//pref of input,added by myself   

	return data;
}


/* 
 * jtag_load_giveio() -
 *		Load device driver GIVEIO for direct access to 
 *		parallel port.
 */
static BOOL jtag_load_giveio(void) {
	u32 errno;
	BOOL ret = FALSE;
	BOOL status;
	SC_HANDLE drv = 0;
	SC_HANDLE scm = 0;

	scm = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
	drv = OpenService(scm,"giveio",SERVICE_ALL_ACCESS);
	if (drv){
		status = StartService(drv,0,NULL);
		if( status == TRUE)
			ret = TRUE;
		else {
			errno = GetLastError();
			if(errno == ERROR_SERVICE_ALREADY_RUNNING)
				ret = TRUE;
			else
				ret = FALSE;
		}

		CloseServiceHandle(drv);
	}

	CloseServiceHandle(scm);

    return ret;
}


/* 
 * jtag_init() - 
 *		Initialize the parallel port and load the device driver 
 *		(GIVEIO) to allow direct access to paralle port.
 *		This route should be called first before any operation
 *		on the TAP Controller.
 */
int jtag_init(void) 
{
	FILE *fp = NULL;

	if( jtag_load_giveio() == FALSE)
		return XJERR_GIVEIO_FAIL;

	fp = fopen("\\\\.\\giveio","wb");

	paral_output(PARAL_INIT_DATA);

	/* 
	 * Improve our priority in hope of avoiding interruptoins
	 * during I/O operations
	 */
	SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);

	return XJ_OK;
}


/* 
 * jtag_wri_tms() - 
 *		Write the TMS signal. 
 */
void jtag_wri_tms(u8 new_val)
{
	port_data &= (~JTAG_TCK_MASK);

	if(new_val)
		port_data |= JTAG_TMS_MASK;
	else
		port_data &= (~JTAG_TMS_MASK);
	
	paral_output(port_data);	
}


/* 
 * jtag_wri_tdi() - 
 *		Write the TDI signal. 
 */
void jtag_wri_tdi(u8 new_val)
{
	port_data &= (~JTAG_TCK_MASK);

	if(new_val)
		port_data |= JTAG_TDI_MASK;
	else
		port_data &= (~JTAG_TDI_MASK);
	
	paral_output(port_data);	
}


/* 
 * jtag_wri_tck() - 
 *		Write the TCK signal. 
 */
void jtag_wri_tck(void)
{
	port_data |= JTAG_TCK_MASK;
	paral_output(port_data);
}


/* 
 * jtag_wri_ntrst() - 
 *		Write the nTRST signal. 
 */
void jtag_wri_ntrst(u8 new_val)
{
	if(new_val)
		port_data |= JTAG_NTRST_MASK;
	else
		port_data &= (~JTAG_NTRST_MASK);

	paral_output(JTAG_NTRST_MASK);
}



/*
 * jtag_rd_rdo() - 
 *		Read TDO singal.
 *
 *		Please note that: 
 *		If TDO is connected to pin-11 of the parallel port, 
 *		the read signal is inverted automatically in this route.
 */
int jtag_rd_rdo(void)
{
	u8 data;
	
	data = paral_input();

	if(JTAG_TDO_MASK == PARAL_PIN_11){  	//Invert before return
		if(data & JTAG_TDO_MASK)
			return 0;
		else
			return 1;
	}else{									//Don't need to invert	
		if(data & JTAG_TDO_MASK)
			return 1;
		else
			return 0;
	}

}

/*
static store_lp1_in(u8 indata){
	FILE *fp;

	if((fp=fopen("c:\\lp1","ab+"))==NULL){
		printf("Cannot open file strike any key exit!"); 
		return 1;
	}
	fputc(in_prefix,fp); 
	
	fputc(indata,fp); 
	
	fclose(fp); 
}

static store_lp1_out(u8 indata){
	FILE *fp;

	if((fp=fopen("c:\\lp1","ab+"))==NULL){
		printf("Cannot open file strike any key exit!"); 
		return 1;
	}
	fputc(out_prefix,fp); 
	
	fputc(indata,fp); 
	
	fclose(fp); 
}
*/





























































⌨️ 快捷键说明

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