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

📄 jflash.cpp

📁 亿道pxa255烧录Jflash源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
*
* FUNCTION:         clear_chip_selects
*
* DESCRIPTION:      reset all chip selects
*
* INPUT PARAMETERS: None
*
* RETURNS:          none
*
*******************************************************************************
*/

void clear_chip_selects()
{

    // Preset to default values (all others set in cotullajtag.h)
    pin[nCS0_OUT] = 1;
    pin[nCS1_OUT] = 1;
    pin[nCS2_OUT] = 1;
    pin[nCS3_OUT] = 1;
    pin[nCS4_OUT] = 1;
    pin[nCS5_OUT] = 1;

}
/*
*******************************************************************************
*
* 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[nOE_OUT] = 0;
    } 
    else
    {
	    pin[nOE_OUT] = 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[nWE_OUT] = 0;
    } 
    else
    {
	    pin[nWE_OUT] = 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[mdupper_ctrl] = 1;  
        pin[mdlower_ctrl] = 1;
    } 
    else
    {
	    pin[mdupper_ctrl] = 0;  
        pin[mdlower_ctrl] = 0;
    }
}

/*
*******************************************************************************
*
* 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[RD_nWR_OUT] = 0;
    } 
    else
    {
        pin[RD_nWR_OUT] = 1;
    }
}

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

    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()
{
    #ifdef DEBUG
    printf("begin post-IR scan code\n");
    #endif

   	//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()
{
    #ifdef DEBUG
    printf("begin pre-DR scan code\n");
    #endif
    
    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()
{
    #ifdef DEBUG
    printf("begin post-DR scan code\n");
    #endif
	
    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
*
*******************************************************************************
*/
int controller_scan_code(int code, int rp, int ct)
{
    int i;
    int outval = 0;
    int tms = 0;
    
    #ifdef DEBUG
    printf("begin controller scan code\n");
    #endif
    
    for (i = 0; i < COTULLA_IRLENGTH; i++)
    {
        if (ct == TERMINATE) 
        {
            if (i == COTULLA_IRLENGTH -1)
            {
                tms = 1;
            }
        }
        outval |= putp(((code & (1 << i)) >> i), tms, rp) << (COTULLA_IRLENGTH - i - 1);
        
    }
    #ifdef DEBUG
    printf("Controller IR value: %X\n", outval);
    #endif
    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;
    
    #ifdef DEBUG
    printf("begin PZ scan code\n");
    #endif
    
    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:         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(COT_BYPASS, READ_PORT, CONTINUE) != 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)((int)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)((int)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
    {
        addrdat = addrdat | (DWORD)((int)pin[addr_order[i]] << i);
    }
    
    
    printf("Address Bus = %X\n", addrdat);
    printf("Flash address is: %X\n",addrdat >> 2);
    
    printf("Chip Select 0 = %d\n", (int)pin[nCS0_OUT]);
    printf("Chip Select 1 = %d\n", (int)pin[nCS1_OUT]);
    printf("Chip Select 2 = %d\n", (int)pin[nCS2_OUT]);
    printf("Chip Select 3 = %d\n", (int)pin[nCS3_OUT]);
    printf("Chip Select 4 = %d\n", (int)pin[nCS4_OUT]);
    printf("Chip Select 5 = %d\n", (int)pin[nCS5_OUT]);

    printf("Mem Out Enable      = %d\n", (int)pin[nOE_OUT]);    
    printf("Mem Write Enable    = %d\n", (int)pin[nWE_OUT]);    
    printf("Mem READ/WRITE Mode = %d\n", (int)pin[RD_nWR_OUT]);    
    printf("------------------------------------------------------\n");

}   



/*
*******************************************************************************
*
* FUNCTION:         invert_workbuf (not used at this time)
*
* DESCRIPTION:      inverts the workbuffer 
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void invert_workbuf()
{
    int i;
   
    int tempbuf[XHYPER255_CHAIN_LENGTH];
    int size = XHYPER255_CHAIN_LENGTH;
 
    for (i = 0; i < size; i++)
    {
        tempbuf[i] = WORKBUF[size - i - 1];    
    }

    // now copy the temp buffer back
    
    for (i = 0; i < size; i++)
    {
        WORKBUF[i] = tempbuf[i];
    }

}

/* 
*******************************************************************************
*
* FUNCTION:         init_workbuf (not used at this time)
*
* DESCRIPTION:      initializes the work buffer with the resting pin states.
*                   Note that the BSDL file gives offsets from TDO and not TDI.
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/
void init_workbuf()
{
    int i;
    int next = 0;
    
    // devices found after the processor
    if(DEVICES_AFTER != 0)
    {
        for (i = 0; i < DEVICES_AFTER; i++)
        {
            next = i + 1;
            WORKBUF[i] = 0;
        }
    }
   
    // the processor
    for (i = next; i < CHAIN_LENGTH + DEVICES_AFTER; i++)
    {
        WORKBUF[i] = pin[i - DEVICES_AFTER];
        next = i + 1;
    }
   
    // for devices before the processor
    if(DEVICES_BEFORE != 0)
    {
       
        for (i = next; i < CHAIN_LENGTH + DEVICES_BEFORE + DEVICES_AFTER; i++)
        {
            WORKBUF[i] = 0;
        } 
    }
	
    invert_workbuf();

}

⌨️ 快捷键说明

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