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

📄 jb_jtag.c

📁 software for report builder
💻 C
📖 第 1 页 / 共 2 页
字号:
	{
		if(i==dev_seq-1)
			record = ReadTDO(ji_info[i],action,(i==0)? 1:0);
		else
			record = ReadTDO(ji_info[i],JI_BYPASS,(i==0)? 1:0);
	}

	/* Move JSM to UPDATE_IR */
	AdvanceJSM(1);
	AdvanceJSM(1);
}

/******************************************************************/
/* Name:         LoadJI                                           */
/*                                                                */
/* Parameters:   action,dev_count,ji_info                         */
/*               -action is the JTAG instruction to load          */
/*               -dev_count is the maximum number of devices in   */
/*                chain.                                          */
/*               -ji_info is the pointer to an integer array that */
/*                contains the JTAG instruction length for the    */
/*                devices in chain.                               */
/*                                                                */
/* Return Value: 1 if contains error;0 if not.                    */
/*               		                                          */
/* Descriptions: Move the JSM to SHIFT_IR. Load in the JTAG       */
/*               instruction to all devices in chain. Then        */
/*               advance the JSM to UPDATE_IR. Irrespective of    */
/*                                                                */
/******************************************************************/
int LoadJI(int action,int dev_count,int* ji_info)
{
	int i,record=0,error=0;

	/* Move Jtag State Machine (JSM) to RUN/IDLE */
	if(jtag.state!=JS_RUNIDLE && jtag.state!=JS_RESET)
		Js_Runidle();

	/* Move JSM to SHIFT_IR */
	AdvanceJSM(0);
	AdvanceJSM(1);
	AdvanceJSM(1);
	AdvanceJSM(0);
	AdvanceJSM(0);

	for(i=0;i<dev_count;i++)
	{
		record = ReadTDO(ji_info[i],action,(i==(dev_count-1))? 1:0);

		if(record!=0x155)
		{
			error=1;
			fprintf(stderr,"Error: JTAG chain broken!\nError: Bits unloaded: 0x%X\n", record);
			return error;
		}
	}

	/* Move JSM to UPDATE_IR */
	AdvanceJSM(1);
	AdvanceJSM(1);	
		
	return error;
}

/******************************************************************/
/* Name:         ReadTDO                                          */
/*                                                                */
/* Parameters:   bit_count,data,inst                              */
/*               -bit_count is the number of bits to shift out.   */
/*               -data is the value to shift in from lsb to msb.  */
/*               -inst determines if the data is an instruction.  */
/*                if inst=1,the number of bits shifted in/out     */
/*                equals to bit_count-1;if not,the number of bits */
/*                does not change.                                */
/*                                                                */
/* Return Value: The data shifted out from TDO. The first bit     */
/*               shifted out is placed at the lsb of the returned */
/*               integer.                                         */
/*               		                                          */
/* Descriptions: Shift out bit_count bits from TDO while shift in */
/*               data to TDI. During instruction loading, the     */
/*               number of shifting equals to the instruction     */
/*               length minus 1                                   */
/*                                                                */
/******************************************************************/
int ReadTDO(int bit_count,int data,int inst)
{
	unsigned int tdi=0,tdo=0,record=0;
	unsigned int i,max = inst? (bit_count-1):bit_count;

	for(i=0;i<max;i++)
	{		
		unsigned int mask=1;

		tdo = ReadPort(1) & sig_port_maskbit[J_SIG_TDO][1];
		tdo = tdo? 0:(1<<i);
		record = record | tdo;
	
		mask = mask << i;
		tdi = data & mask;
		tdi = tdi >> i;
		DriveSignal(J_SIG_TDI,tdi,1,1);
	}

	return record;
}

/******************************************************************/
/* Name:         Js_Shiftdr                                       */
/*                                                                */
/* Parameters:   None.                                            */
/*                                                                */
/* Return Value: 1 if the current state is not UPDATE_DR or       */
/*               UPDATE_IR. 0 if the opeation is successful.      */
/*               		                                          */
/* Descriptions: Move the JSM to SHIFT_DR. The current state is   */
/*               expected to be UPDATE_DR or UPDATE_IR.           */
/*                                                                */
/******************************************************************/
int Js_Shiftdr()
{
	/* The current JSM state must be in UPDATE_IR or UPDATE_DR */
	if(jtag.state!=JS_UPDATE_DR && jtag.state!=JS_UPDATE_IR)
	{
		if(jtag.state!=JS_RESET && jtag.state!=JS_RUNIDLE)
			return (1);
		else
		{
			AdvanceJSM(0);
			AdvanceJSM(0);
			AdvanceJSM(1);
			AdvanceJSM(0);
			AdvanceJSM(0);

			return (0);
		}
	}

	AdvanceJSM(1);
	AdvanceJSM(0);
	AdvanceJSM(0);

	return (0);
}

/******************************************************************/
/* Name:         Js_Updatedr                                      */
/*                                                                */
/* Parameters:   None.                                            */
/*                                                                */
/* Return Value: 1 if the current state is not SHIFT_DR;0 if the  */
/*               operation is successful.                         */
/*               		                                          */
/* Descriptions: Move the JSM to UPDATE_DR. The current state is  */
/*               expected to be SHIFT_DR                          */
/*                                                                */
/******************************************************************/
int Js_Updatedr()
{
	/* The current JSM state must be in UPDATE_IR or UPDATE_DR */
	if(jtag.state!=JS_SHIFT_DR)
		return (1);

	AdvanceJSM(1);
	AdvanceJSM(1);

	return (0);
}

int Ji_Extest(int dev_count,int* ji_info)
{
	return LoadJI(JI_EXTEST,dev_count,ji_info);
}

int Ji_Program(int dev_count,int* ji_info)
{
	return LoadJI(JI_PROGRAM,dev_count,ji_info);
}

int Ji_Startup(int dev_count,int* ji_info)
{
	return LoadJI(JI_STARTUP,dev_count,ji_info);
}

int Ji_Checkstatus(int dev_count,int* ji_info)
{
	return LoadJI(JI_CHECK_STATUS,dev_count,ji_info);
}

int Ji_Sample(int dev_count,int* ji_info)
{
	return LoadJI(JI_SAMPLE,dev_count,ji_info);
}

int Ji_Idcode(int dev_count,int* ji_info)
{
	return LoadJI(JI_IDCODE,dev_count,ji_info);
}

int Ji_Usercode(int dev_count,int* ji_info)
{
	return LoadJI(JI_USERCODE,dev_count,ji_info);
}

int Ji_Intest(int dev_count,int* ji_info)
{
	return LoadJI(JI_INTEST,dev_count,ji_info);
}

int Ji_Regscan(int dev_count,int* ji_info)
{
	return LoadJI(JI_REGSCAN,dev_count,ji_info);
}

int Ji_User0(int dev_count,int* ji_info)
{
	return LoadJI(JI_USER0,dev_count,ji_info);
}

int Ji_User1(int dev_count,int* ji_info)
{
	return LoadJI(JI_USER1,dev_count,ji_info);
}

int Ji_Bypass(int dev_count,int* ji_info)
{
	return LoadJI(JI_BYPASS,dev_count,ji_info);
}

⌨️ 快捷键说明

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