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

📄 jflash.cpp

📁 pxa255用的并口烧写jtag口的源代码。可以修改为其他的cpu等下载工具
💻 CPP
📖 第 1 页 / 共 5 页
字号:
*******************************************************************************
*
* FUNCTION:         mem_output_enable
*
* DESCRIPTION:      enable or disable memory output. This pin is connected to 
*                   the output enables of the memory device.
*
* INPUT PARAMETERS: int - enable or disable
*
* RETURNS:          void
*
*******************************************************************************
*/
void mem_output_enable(int endis)
{
    if (endis == ENABLE)
		pin[OutputEnable] = 0;
    else
		pin[OutputEnable] = 1;
}

/*
*******************************************************************************
*
* FUNCTION:         mem_write_enable
*
* DESCRIPTION:      enable or disable memory writes. This pin is connected to 
*                   the write enables of the memory device.
*
* INPUT PARAMETERS: int - enable or disable
*
* RETURNS:          void
*
*******************************************************************************
*/
void mem_write_enable(int endis)
{
    if (endis == ENABLE)
			pin[WriteEnable] = 0;
    else
			pin[WriteEnable] = 1;
}

/*
*******************************************************************************
*
* FUNCTION:         mem_data_driver
*
* DESCRIPTION:      Sets memory data pins to DRIVE or HIZ. 
*
* INPUT PARAMETERS: int - drive or highz
*
* RETURNS:          void
*
*******************************************************************************
*/

void mem_data_driver(int df)
{
	if (df == DRIVE)
	{
		pin[MdUpperControl] = 1;  
		pin[MdLowerControl] = 1;	// Note for Assabet: MdLowerControl = MdUpperControl 
	}
	else
	{
		pin[MdUpperControl] = 0;
		pin[MdLowerControl] = 0;	// Note for Assabet: MdLowerControl = MdUpperControl
	}
}

/*
*******************************************************************************
*
* FUNCTION:         mem_rw_mode
*
* DESCRIPTION:      Sets memory mode to READ or WRITE. 
*
* INPUT PARAMETERS: int - READ or WRITE
*
* RETURNS:          void
*
*******************************************************************************
*/
void mem_rw_mode(int rw)
{
    if (rw == WRITE)
			pin[ReadWriteMode] = 0;
    else
		    pin[ReadWriteMode] = 1;
}


/*
*******************************************************************************
*
* FUNCTION:         gpio_unlock_flash
*
* DESCRIPTION:      Sets the GPIO bits on the Mainstone that are keeping the 
*                   K3 flash locked. 
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void gpio_unlock_flash()
{

	if (UnlockFlashCtrl1 != 9999) 
	pin[UnlockFlashCtrl1] = UnlockFlashCtrl1Lev;

	if (UnlockFlashCtrl2 != 9999) 
	pin[UnlockFlashCtrl2] = UnlockFlashCtrl2Lev;

	if (UnlockFlashCtrl3 != 9999) 
	pin[UnlockFlashCtrl3] = UnlockFlashCtrl3Lev;

	if (UnlockFlashCtrl4 != 9999) 
	pin[UnlockFlashCtrl4] = UnlockFlashCtrl4Lev;

}

/*
*******************************************************************************
*
* FUNCTION:         gpio_lock_flash
*
* DESCRIPTION:      Clears the GPIO bits on the Mainstone to re-lock the 
*                   K3 flash. 
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void gpio_lock_flash()
{
	if (UnlockFlashCtrl1 != 9999) 
	pin[UnlockFlashCtrl1] = LockFlashCtrl1Lev;

	if (UnlockFlashCtrl2 != 9999) 
	pin[UnlockFlashCtrl2] = LockFlashCtrl2Lev;

	if (UnlockFlashCtrl3 != 9999) 
	pin[UnlockFlashCtrl3] = LockFlashCtrl3Lev;

	if (UnlockFlashCtrl4 != 9999) 
	pin[UnlockFlashCtrl4] = LockFlashCtrl4Lev;

}

/*
*******************************************************************************
*
* FUNCTION:         pre_IRSCAN
*
* DESCRIPTION:      Sets up the state machine to accept an IR SCAN
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void pre_IRSCAN()
{
    if(Debug_Mode)
    printf("begin pre-IR scan code\n");
    

    putp(1,0,IGNORE_PORT);	//Run-Test/Idle
    putp(1,0,IGNORE_PORT);	//Run-Test/Idle
    putp(1,0,IGNORE_PORT);	//Run-Test/Idle
    putp(1,0,IGNORE_PORT);	//Run-Test/Idle
    putp(1,1,IGNORE_PORT);
    putp(1,1,IGNORE_PORT);	//select IR scan
    putp(1,0,IGNORE_PORT);	//capture IR
    putp(1,0,IGNORE_PORT);	//shift IR
}

/*
*******************************************************************************
*
* FUNCTION:         post_IRSCAN
*
* DESCRIPTION:      Get back to IDLE after scanning in the instruction
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void post_IRSCAN()
{
    if(Debug_Mode)
    printf("begin post-IR scan code\n");
    
   	//putp(1,1,IGNORE_PORT);	//Exit1-IR

	putp(1,1,IGNORE_PORT);	//Update-IR
	putp(1,0,IGNORE_PORT);	//Run-Test/Idle
	putp(1,0,IGNORE_PORT);	//Run-Test/Idle
	putp(1,0,IGNORE_PORT);	//Run-Test/Idle
}

/*
*******************************************************************************
*
* FUNCTION:         pre_DRSCAN
*
* DESCRIPTION:      Sets up the state machine to accept an DR SCAN
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void pre_DRSCAN()
{
    if(Debug_Mode)
    printf("begin pre-DR scan code\n");
    
    
    putp(1,0,IGNORE_PORT);	//Run-Test/Idle
    putp(1,0,IGNORE_PORT);	//Run-Test/Idle
    putp(1,0,IGNORE_PORT);	//Run-Test/Idle
    putp(1,0,IGNORE_PORT);	//Run-Test/Idle
    putp(1,1,IGNORE_PORT);  //select DR scan
    putp(1,0,IGNORE_PORT);	//capture DR
//	putp(1,0,IGNORE_PORT);	//shift DR
}

/*
*******************************************************************************
*
* FUNCTION:         post_DRSCAN
*
* DESCRIPTION:      Get back to IDLE after scanning in the data register
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void post_DRSCAN()
{
    if(Debug_Mode)
    	printf("begin post-DR scan code\n");
    
	
    putp(1,1,IGNORE_PORT);	//Exit1-DR
	putp(1,1,IGNORE_PORT);	//Update-DR
	putp(1,0,IGNORE_PORT);	//Run-Test/Idle
	putp(1,0,IGNORE_PORT);	//Run-Test/Idle
	putp(1,0,IGNORE_PORT);	//Run-Test/Idle
}

/*
*******************************************************************************
*
* FUNCTION:         controller_scan_code
*
* DESCRIPTION:      clocks in a specified cotulla IR scan code
*
* INPUT PARAMETERS: int instruction code
*                   int read or ignore port
*                   int continue or terminate instruction stream
*
* RETURNS:          void
*
*******************************************************************************
*/
// NOTE: I think there is a bug here somewhere.	This procedure seems to work,
// but I think the count is off. Future debugging work required. The problem is
// that a 0x1 should be returned from the instruction register after each 
// valid instruction. I'm not getting this value back, but the instructions 
// appear to be valid because the system works. If this bug can be found, then
// the JTAG_TEST procedure could be used again. 

int controller_scan_code(int code, int rp, int ct)
{
    int i;
    int outval = 0;
    int tms = 0;
 //   int codebit;
    if(Debug_Mode)
    	printf("begin controller scan code = %x\n", code);
    
    
    for (i = 0; i < IrLength; i++)
    {
        if (ct == TERMINATE)
        {
            if (i == IrLength -1)
            {
                tms = 1;
            }
        }
        outval |= putp(((code & (1 << i)) >> i), tms, rp) << (IrLength - i - 1);
	   //	codebit = code & 1<<(IrLength -1 -i);
	   //	outval |= putp(codebit, tms, rp) << (IrLength -1 -i);		

    }
    if(Debug_Mode)
    	printf("Controller IR value: %X\n", outval);
    
    return outval;
}

/*
*******************************************************************************
*
* FUNCTION:         PZ_scan_code
*
* DESCRIPTION:      clocks in a specified PZxxxx IR scan code
*
* INPUT PARAMETERS: int code
*
* RETURNS:          void
*
*******************************************************************************
*/
int PZ_scan_code(int code, int rp, int ct)
{
    int i;
    int outval = 0;
    int tms = 0;
    
    if(Debug_Mode)
    	printf("begin PZ scan code\n");
    
    
    for (i = 0; i < PZ_IRLENGTH; i++)
    {
        if (ct == TERMINATE) 
        {
            if (i == PZ_IRLENGTH -1)
            {
                tms = 1;
            }
        }
        
        outval |= putp(((code & (1 << i)) >> i), tms, rp) << (PZ_IRLENGTH - i - 1);
    }
    return outval;
}

/*
*******************************************************************************
*
* FUNCTION:         other_bypass
*
* DESCRIPTION:      clocks in a bypass scan code for an arbitrary device
*
* INPUT PARAMETERS: int code
*
* RETURNS:          void
*
*******************************************************************************
*/
int other_bypass(int rp, int ct ,int length)
{
    int i;
    int outval = 0;
    int tms = 0;
    int code = 0;

    if(Debug_Mode)
    	printf("Putting Other Device in Bypass\n");
    
    for(i = 0; i < length; i++)
	{
		code |= 1 << i; // construct a universal bypass instruction
	}

    for (i = 0; i < length; i++)
    {
        if (ct == TERMINATE) 
        {
            if (i == length -1)
            {
                tms = 1;
            }
        }
        
        outval |= putp(((code & (1 << i)) >> i), tms, rp) << (length - i - 1);
    }
    return outval;
}

/*
*******************************************************************************
*
* FUNCTION:         jtag_test
*
* DESCRIPTION:      tests the JTAG connection by reading the steady state 
*                   instruction register.
*
* INPUT PARAMETERS: void
*
* RETURNS:          int - 0 if passed
*
*******************************************************************************
*/
void jtag_test()
{
    // set all devices into bypass mode as a safe instruction

    pre_IRSCAN();

		if (controller_scan_code(IR_Bypass, READ_PORT, TERMINATE) != 0x1)
		{
			error_out("Jtag test failure. Check connections and power.\n"); 
		}


    post_IRSCAN();
    
    printf("JTAG Test Passed\n");

}
/*
*******************************************************************************
*
* FUNCTION:         dump_chain
*
* DESCRIPTION:      This is a debug routine that dumps the contents of the 
*                   current boundary chain to the standard I/O.
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void dump_chain()
{
    DWORD addrdat = 0;
    DWORD obusdat = 0;
    DWORD ibusdat = 0;

    int i;
 
    printf("------------------------------------------------------\n");

	for(i = 0; i < 32; i++)	// convert serial data to single DWORD
	{
		obusdat = obusdat | (DWORD)(pin[dat_order[i]] << i);
    }
    printf("Data Bus (Output) = %X\n", obusdat);
    
	for(i = 0; i < 32; i++)	// convert serial data to single DWORD
	{
		ibusdat = ibusdat | (DWORD)(pin[input_dat_order[i]] << i);
	}
    printf("Data Bus (Input) = %X\n", ibusdat);

    for(i = 0; i < 26; i++) // convert address data into single DWORD
    {

⌨️ 快捷键说明

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