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

📄 jflash.cpp

📁 jflash linux 2.0.03,linux下的jflash源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
										    LUBBOCK_DALHART_16 is defined,
										    the upper 3 parameters 
											are in 16-bit word number
											else they are in 32-bit DWORD number

					DWORD rom_size			: the rom size in 
*					
					
* RETURNS:          None
*
* GLOBAL EFFECTS:   None
*
*******************************************************************************
*/
void check_file_info(DWORD *fsize , DWORD *last_non_zero, DWORD *last_non_ff, DWORD rom_size)
{	BUS_GRAIN li;
		
	for(;;)
	{
		int n = fread((BUS_GRAIN *)&li, sizeof(BUS_GRAIN) , 1, in_file);

    	if(feof(in_file))break; // Any bytes not on a 4 byte boundry at end-of-file will be ignored
		{
            (*fsize)++;
        }
		if(li != 0 && li != -1) // Find point in file were only 0's and ff's remain
		{						// For 32 bit data bus, -1 is 0xffffffff, for 16 bit data bus -1 is 0xffff
        	*last_non_zero = *fsize;
        }
		if(li != -1)  // Find point in file were only ff's remain
		{
        	*last_non_ff = *fsize;
        }
	}
	

	rewind(in_file);

#if defined(LUBBOCK_SABINAL) || defined(LUBBOCK_DALHART_16)
	// if SABINAL 16-bit data width used, it assume only one 16-bit flash installed
		if ((*fsize) > rom_size)
			error_out("error, file size is bigger than device size");
#else
	// if 32-bit data width used. It assume 2 16-bit flash installed. each flash size=fsize
		if ((*fsize) * 2 > rom_size * 2)
			error_out("error, file size is bigger than device size");
#endif

}


/*
*******************************************************************************
*
* FUNCTION:         putp
*
* DESCRIPTION:      Drives TCK, TDI, and TMS signals and reads TDO signal 
*                   via _outp and _inp calls.
*                   
*                   Cable used had 100 ohm resistors between the following pins
*                   (Cable shipped as part of SA-1110 Development Kit)
*                   Output pins (LPT driving)
*                       LPT D0 Pin 2 and TCK J10 Pin 4
*                       LPT D1 Pin 3 and TDI J10 Pin 11
*                       LPT D2 Pin 4 and TMS J10 Pin 9
*
*                   Input pin (SA-1110 board drives)
*                       LPT Busy Pin 11 and TDO J10 Pin 13
*                   
*                   
*
* INPUT PARAMETERS: int tdi - test data in
*
* RETURNS:          int - TDO (Test Data Out)
*
* GLOBAL EFFECTS:   None
*
*******************************************************************************
*/

int putp(int tdi, int tms, int rp)
{
#ifdef PARALLEL_JTAG
	int tdo = -1;
	// TMS is D2, TDI is D1, and TCK is D0, so construct an output by creating a 
    // rising edge on TCK with TMS and TDI data set.
    _outp(lpt_address, tms*4+tdi*2);	// TCK low
	_outp(lpt_address, tms*4+tdi*2+1);	// TCK high
	
    // if we want to read the port, set TCK low because TDO is sampled on the 
    // TCK falling edge.
    if(rp == READ_PORT)
        _outp(lpt_address, tms*4+tdi*2);	// TCK low
	if(rp == READ_PORT)
        tdo = !((int)_inp(lpt_address + 1) >> 7);	// get TDO data
#endif



#ifdef INSIGHT_JTAG
// There's some bit clearing here that isn't needed. It should make this 
// code easier to understand.

	//defines for the INSIGHT IJC-1 JTAG cable

	/* the output port (lpt_address) */
	#define INSIGHT_CLK		0x02
	#define INSIGHT_DIN		0x01
	#define nINSIGHT_PROG	0x10  /* This causes the TDO line to be driven. We'll leave it high.*/
	#define INSIGHT_TMS_IN  0x04  
	#define nINSIGHT_CTRL	0x08  /* Output Enable for the standard JTAG outputs 
		                             (not TDO since this is an output from the 
			                         chip we want to talk to                    */

	/*the input port (lpt_address + 1)*/
	#define TDO_INPUT			0x10  
	#define TDO_INPUT_BITPOS	4  



	int tdo = -1;
	int lpt_data;
	
	//form the data we want to write to the parallel port
	lpt_data = nINSIGHT_PROG;   //Output to TDO off
	lpt_data &= ~nINSIGHT_CTRL;	//Enable the outputs

	if(tms == 1) lpt_data |= INSIGHT_TMS_IN;
	if(tdi == 1) lpt_data |= INSIGHT_DIN;


   	// construct an output by creating a 
    // rising edge on TCK with TMS and TDI data set.
	lpt_data &= ~INSIGHT_CLK;
	_outp(lpt_address, lpt_data);	// TCK low
	
	lpt_data |= INSIGHT_CLK;
	_outp(lpt_address, lpt_data);	// TCK high
	

    // if we want to read the port, set TCK low because TDO is sampled on the 
    // TCK falling edge.
    if(rp == READ_PORT){
		lpt_data &= ~INSIGHT_CLK;
		_outp(lpt_address, lpt_data);	// TCK high
		tdo = ((int)_inp(lpt_address + 1) & TDO_INPUT) >> TDO_INPUT_BITPOS;	// get TDO data
	}
#endif

//	#ifdef DEBUG
//    printf("TDI = %d, TMS = %d, TDO = %d\n",tdi,tms,tdo);
//  #endif
    return tdo;


}
/*
*******************************************************************************
*
* FUNCTION:         id_command
*
* DESCRIPTION:      extract and verify the id codes of the devices in the chain
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/

void id_command(void)
{
    pre_IRSCAN();

#ifdef SANDGATE_PLATFORM

    controller_scan_code(COT_IDCODE, IGNORE_PORT, CONTINUE);
    PZ_scan_code(PZ_IDCODE, IGNORE_PORT, CONTINUE);    // PZ3128 IDCODE
    PZ_scan_code(PZ_IDCODE, IGNORE_PORT, TERMINATE);   // PZ3032 IDCODE

#endif // SANDGATE_PLATFORM

#ifdef LUBBOCK_PLATFORM
    controller_scan_code(COT_IDCODE, IGNORE_PORT, TERMINATE); 

#endif // LUBBOCK_PLATFORM

#ifdef ASSABET_PLATFORM
#ifndef LUBBOCK_SA1110
    controller_scan_code(SA_IDCODE, IGNORE_PORT, CONTINUE);
    PZ_scan_code(PZ_IDCODE, IGNORE_PORT, CONTINUE);    // PZ3128 IDCODE
    PZ_scan_code(PZ_IDCODE, IGNORE_PORT, TERMINATE);    // PZ3032 IDCODE
#else
    controller_scan_code(SA_IDCODE, IGNORE_PORT, TERMINATE);


#endif
#endif // ASSABET_PLATFORM

    post_IRSCAN();

    pre_DRSCAN();
    
#ifdef SANDGATE_PLATFORM 

    if(check_id(COTULLAID))
		error_out("failed to read device ID for the DBPXA250");
	if(check_id(PZ3128ID))
		error_out("failed to read device ID for the PZ3128");
	if(check_id(PZ3032SID))
		error_out("failed to read device ID for the PZ3032");
        
#endif// SANDGATE_PLATFORM

#ifdef ASSABET_PLATFORM
#ifndef LUBBOCK_SA1110
    if(check_id(SA1110ID))
		error_out("failed to read device ID for the SA1110");
	if(check_id(PZ3128ID))
		error_out("failed to read device ID for the PZ3128");
	if(check_id(PZ3032SID))
		error_out("failed to read device ID for the PZ3032");
#else
    if(check_id(SA1110ID))
		error_out("failed to read device ID for the SA1110");
#endif        
#endif //ASSABET_PLATFORM


#ifdef LUBBOCK_PLATFORM
#if !defined(LUBBOCK_SABINAL) && !defined(LUBBOCK_DALHART_16)

    if(check_id(COTULLAID))
	{
		error_out("failed to read device ID for the DBPXA250");
	}
#endif

// There may still be some A1 Sabinal chips out there. Let's not break when we see one.
#if defined(LUBBOCK_SABINAL) || defined(LUBBOCK_DALHART_16)
    if((check_id(SABINALID)) && (check_id(COTULLAID)))
	{
#ifndef LUBBOCK_DALHART_16
		error_out("failed to read device ID for the DBPXA210");
#else
		error_out("failed to read device ID for the DALHART 16");
#endif
	}

#endif
        
#endif //LUBBOCK_PLATFORM

    
    post_DRSCAN();
}
/*
*******************************************************************************
*
* FUNCTION:         bypass_all
*
* DESCRIPTION:      put all devices into bypass mode
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/

void bypass_all(void)
{
    pre_IRSCAN();

#ifdef SANDGATE_PLATFORM 

    controller_scan_code(COT_BYPASS, IGNORE_PORT, CONTINUE);
    PZ_scan_code(PZ_BYPASS, IGNORE_PORT, CONTINUE);    // PZ3128
    PZ_scan_code(PZ_BYPASS, IGNORE_PORT, TERMINATE);    // PZ3032
    
#endif //SANDGATE_PLATFORM

#ifdef ASSABET_PLATFORM 
#ifndef LUBBOCK_SA1110
    controller_scan_code(SA_BYPASS, IGNORE_PORT, CONTINUE);
    PZ_scan_code(PZ_BYPASS, IGNORE_PORT, CONTINUE);    // PZ3128
    PZ_scan_code(PZ_BYPASS, IGNORE_PORT, TERMINATE);    // PZ3032
#else
    controller_scan_code(SA_BYPASS, IGNORE_PORT, TERMINATE);

#endif    
#endif //SANDGATE_PLATFORM

#ifdef LUBBOCK_PLATFORM 

    controller_scan_code(COT_BYPASS, IGNORE_PORT, TERMINATE);
    
#endif //LUBBOCK_PLATFORM
 
    post_IRSCAN();
}
/*
*******************************************************************************
*
* FUNCTION:         extest
*
* DESCRIPTION:      put the processor into extest (drive pins) mode, and all 
*                   others into bypass mode.
*
* INPUT PARAMETERS: void
*
* RETURNS:          void
*
*******************************************************************************
*/

void extest(void)
{
    pre_IRSCAN();

#ifdef SANDGATE_PLATFORM 

    controller_scan_code(COT_EXTEST, IGNORE_PORT, CONTINUE);
    PZ_scan_code(PZ_BYPASS, IGNORE_PORT, CONTINUE);    // PZ3128
    PZ_scan_code(PZ_BYPASS, IGNORE_PORT, TERMINATE);    // PZ3032
    
#endif //SANDGATE_PLATFORM

#ifdef ASSABET_PLATFORM 
#ifndef LUBBOCK_SA1110
    controller_scan_code(SA_EXTEST, IGNORE_PORT, CONTINUE);
    PZ_scan_code(PZ_BYPASS, IGNORE_PORT, CONTINUE);    // PZ3128
    PZ_scan_code(PZ_BYPASS, IGNORE_PORT, TERMINATE);    // PZ3032
#else
    controller_scan_code(SA_EXTEST, IGNORE_PORT, TERMINATE);

#endif    
#endif //SANDGATE_PLATFORM

#ifdef LUBBOCK_PLATFORM 

    controller_scan_code(COT_EXTEST, IGNORE_PORT, TERMINATE);
    
#endif //LUBBOCK_PLATFORM

    post_IRSCAN();

}
/*
*******************************************************************************
*
* FUNCTION:         access_rom
*
* DESCRIPTION:      This is just an access-bus with the address multiplied by 4
*
* INPUT PARAMETERS: int - rw, or access mode
*                   DWORD - address
*                   DWORD - data
*                   int rp - whether to read or ignore the parallel port
*
* RETURNS:          DWORD - returned data
*
*******************************************************************************
*/

DWORD access_rom_32(int rw, DWORD address, DWORD data, int rp)
{
	DWORD returnvalue;
    
    // Shift Flash address making A2 the LSB
    
	#ifdef DEBUG
    printf("ACCESS_ROM: inp addr = %X, inp data = %X\n", address, data);
    #endif
    
    returnvalue = access_bus(rw, address << 2, data, rp);
    
    #ifdef DEBUG
    printf("ACCESS_ROM Returns %X\n", returnvalue);
    #endif
    
    return returnvalue;
}

WORD access_rom_16(int rw, DWORD address, WORD data16, int rp)
{
	WORD returnvalue;
	DWORD data;

	data=(DWORD)data16;
    
    // Shift Flash address making A2 the LSB
    
	#ifdef DEBUG
    printf("ACCESS_ROM_16: inp addr = %X, inp data = %X\n", address, data);
    #endif
    
    returnvalue =(WORD)access_bus(rw, address << 1, data, rp);
    
    #ifdef DEBUG
    printf("ACCESS_ROM_16 Returns %X\n", returnvalue);
    #endif
    
    return returnvalue;
}

/*
*******************************************************************************
*
* FUNCTION:         access_bus
*
* DESCRIPTION:      This routine manipulates the memory bus to do reads 
*                   and writes to any memory location.
*
* INPUT PARAMETERS: int rw - mode of READ, WRITE, SETUP, HOLD, or RS
*                   DWORD - address of access
*                   DWORD - data to write
*                   int rp - read or ignore port data
*
* RETURNS:          DWORD - returned data
*
*******************************************************************************
*/

DWORD access_bus(int rw, DWORD address, DWORD data, int rp)
{
	int i;

	// Preset SA-1110 or Cotulla pins to default values (all others set in Cotullajtag.h)
    
    clear_chip_selects();
	mem_output_enable(ENABLE);
	mem_write_enable(DISABLE);
	mem_rw_mode(WRITE);
    mem_data_driver(HIZ); 

    #ifdef DEBUG
    printf("Chain initial state\n");
    dump_chain();
    #endif
    
    set_address(address);

    //----------------------------------------------
    if(rw == READ)
	{
		#ifdef DEBUG
        printf("Read Mode\n");
        #endif
		mem_rw_mode(READ);
        set_pin_chip_select(address);
	}
    
    //----------------------------------------------
	if(rw == WRITE)
	{
		#ifdef DEBUG
        printf("Write Mode\n");
        #endif
        mem_write_enable(ENABLE);
		mem_output_enable(DISABLE);

⌨️ 快捷键说明

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