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

📄 jb_jtag.c

📁 software for report builder
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************/
/*                                                                */
/* Module:       jb_jtag.c                                        */
/*                                                                */
/* Descriptions: Manages JTAG State Machine (JSM), loading of     */
/*               JTAG instructions and reading of data from TDO.  */
/*                                                                */
/* Revisions:    1.0 02/22/02                                     */
/*                                                                */
/******************************************************************/

#include <stdio.h>
#include <string.h>
#include "jb_jtag.h"

#define MAX_JS_CHAR_COUNT 10
#define JSM_RESET_COUNT 5

/* JTAG Configuration Signals */
#define J_SIG_TCK  0 /* TCK */
#define J_SIG_TMS  1 /* TMS */
#define J_SIG_TDI  2 /* TDI */
#define J_SIG_TDO  3 /* TDO */

/* States of JTAG State Machine */
#define JS_RESET         0
#define JS_RUNIDLE       1
#define JS_SELECT_IR     2
#define JS_CAPTURE_IR    3
#define JS_SHIFT_IR      4
#define JS_EXIT1_IR      5
#define JS_PAUSE_IR      6
#define JS_EXIT2_IR      7
#define JS_UPDATE_IR     8
#define JS_SELECT_DR     9
#define JS_CAPTURE_DR    10
#define JS_SHIFT_DR      11
#define JS_EXIT1_DR      12
#define JS_PAUSE_DR      13
#define JS_EXIT2_DR      14
#define JS_UPDATE_DR     15
#define JS_UNDEFINE      16


extern void DriveSignal(int signal,int data,int clk,int test);
extern int  ReadPort(int port);
extern int  sig_port_maskbit[4][2];

/* JTAG State Machine */
const int JSM[16][2] = {
/*-State-      -mode= '0'-    -mode= '1'- */
/*RESET     */ {JS_RUNIDLE,   JS_RESET    },
/*RUNIDLE   */ {JS_RUNIDLE,   JS_SELECT_DR},
/*SELECTIR  */ {JS_CAPTURE_IR,JS_RESET    },
/*CAPTURE_IR*/ {JS_SHIFT_IR,  JS_EXIT1_IR },
/*SHIFT_IR  */ {JS_SHIFT_IR,  JS_EXIT1_IR },
/*EXIT1_IR  */ {JS_PAUSE_IR,  JS_UPDATE_IR},
/*PAUSE_IR  */ {JS_PAUSE_IR,  JS_EXIT2_IR },
/*EXIT2_IR  */ {JS_SHIFT_IR,  JS_UPDATE_IR},
/*UPDATE_IR */ {JS_RUNIDLE,   JS_SELECT_DR},
/*SELECT_DR */ {JS_CAPTURE_DR,JS_SELECT_IR},
/*CAPTURE_DR*/ {JS_SHIFT_DR,  JS_EXIT1_DR },
/*SHIFT_DR  */ {JS_SHIFT_DR,  JS_EXIT1_DR },
/*EXIT1_DR  */ {JS_PAUSE_DR,  JS_UPDATE_DR},
/*PAUSE_DR  */ {JS_PAUSE_DR,  JS_EXIT2_DR },
/*EXIT2_DR  */ {JS_SHIFT_DR,  JS_UPDATE_DR},
/*UPDATE_DR */ {JS_RUNIDLE,   JS_SELECT_DR} 
};

/* JTAG Instructions */
const int JI_EXTEST       = 0x000;
const int JI_PROGRAM      = 0x002;
const int JI_STARTUP      = 0x003;
const int JI_CHECK_STATUS = 0x004;
const int JI_SAMPLE       = 0x005;
const int JI_IDCODE       = 0x006;
const int JI_USERCODE     = 0x007;
const int JI_INTEST       = 0x008;
const int JI_REGSCAN      = 0x009;
const int JI_USER0        = 0x00C;
const int JI_USER1        = 0x00E;
const int JI_BYPASS       = 0x3FF;

const char JS_NAME[][MAX_JS_CHAR_COUNT+1] = {
"RESET",
"RUN/IDLE",
"SELECT_IR",
"CAPTURE_IR",
"SHIFT_IR",
"EXIT1_IR",
"PAUSE_IR",
"EXIT2_IR",
"UPDATE_IR",
"SELECT_DR",
"CAPTURE_DR",
"SHIFT_DR",
"EXIT1_DR",
"PAUSE_DR",
"EXIT2_DR",
"UPDATE_DR",
"UNDEFINE" };

struct states
{
	int state;
} jtag;

/******************************************************************/
/* Name:         Js_Reset                                         */
/*                                                                */
/* Parameters:   None.                                            */
/*                                                                */
/* Return Value: None.                                            */
/*               		                                          */
/* Descriptions: Reset the JSM by issuing JSM_RESET_COUNT of clock*/
/*               with the TMS at HIGH.                            */
/*                                                                */
/******************************************************************/
void Js_Reset()
{
	int i;

	for(i=0;i<JSM_RESET_COUNT;i++)
		AdvanceJSM(1);
}

/******************************************************************/
/* Name:         Runidle                                          */
/*                                                                */
/* Parameters:   None.                                            */
/*                                                                */
/* Return Value: None.                                            */
/*               		                                          */
/* Descriptions: If the current JSM is not at UPDATE_DR or        */
/*               UPDATE_IR state, RESET JSM and move to RUNIDLE,  */
/*               if it is, clock once with TMS LOW and move to    */
/*               RUNIDLE.                                         */
/*                                                                */
/******************************************************************/
void Js_Runidle()
{
	int i=0;
	
	/* If the current state is not UPDATE_DR or UPDATE_IR, reset the JSM and move to RUN/IDLE */
	if(jtag.state!=JS_UPDATE_IR && jtag.state!=JS_UPDATE_DR)
	{
		for(i=0;i<JSM_RESET_COUNT;i++)
			AdvanceJSM(1);
	}

	AdvanceJSM(0);
}

/******************************************************************/
/* Name:         AdvanceJSM                                       */
/*                                                                */
/* Parameters:   mode                                             */
/*               -the input mode to JSM.                          */
/*                                                                */
/* Return Value: The current JSM state.                           */
/*               		                                          */
/* Descriptions: Function that keep track of the JSM state. It    */
/*               drives out signals to TMS associated with a      */
/*               clock pulse at TCK and updates the current state */
/*               variable.                                        */
/*                                                                */
/******************************************************************/
int AdvanceJSM(int mode)
{
	DriveSignal(J_SIG_TMS,mode,1,1);
		
	jtag.state = JSM[jtag.state][mode];

	return (jtag.state);
}

/******************************************************************/
/* Name:         PrintJS                                          */
/*                                                                */
/* Parameters:   None.                                            */
/*                                                                */
/* Return Value: None.                                            */
/*               		                                          */
/* Descriptions: Print the current state of the JSM.              */
/*                                                                */
/******************************************************************/
void PrintJS()
{
	char state[MAX_JS_CHAR_COUNT+1];

	strcpy(state, JS_NAME[jtag.state]);
	
	fprintf(stdout, "Info: JSM: %s\n", state );
}

/******************************************************************/
/* Name:         SetupChain                                       */
/*                                                                */
/* Parameters:   dev_count,dev_seq,ji_info,action                 */
/*               -device_count is the total device in chain       */
/*               -dev_seq is the device sequence in chain         */
/*               -ji_info is the pointer to an integer array that */
/*                contains the JTAG instruction length for the    */
/*                devices in chain.                               */ 
/*               -action is the JTAG instruction to load          */
/*                                                                */
/* Return Value: None.                                            */
/*               		                                          */
/* Descriptions: Move the JSM to SHIFT_IR. Issue the JTAG         */
/*               instruction, "action" to the target device and   */
/*               BYPASS to the rest of the devices. Then, move    */
/*               the JSM to UPDATE_IR.                            */
/*                                                                */
/******************************************************************/
void SetupChain(int dev_count,int dev_seq,int* ji_info,int action)
{
	int i,record=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=dev_count-1;i>=0;i--)

⌨️ 快捷键说明

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