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

📄 jflash.cpp

📁 wince的boot程序下载:并口JFlashmm源代码。 VC6.0编译。如果用新的flash芯片需要修改源代码后编译。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void check_file_info(DWORD *fsize , DWORD *last_non_zero, DWORD *last_non_ff, DWORD rom_size){			short li_WORD;	INT32 li_DWORD;    if(PlatformIs16bit)	{		for(;;)		{			int n = fread((WORD *)&li_WORD, sizeof(WORD) , 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_WORD != 0 && li_WORD != -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_WORD != -1)  // Find point in file were only ff's remain			{        		*last_non_ff = *fsize;			}		}		rewind(in_file);		// if 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	{		for(;;)		{			int n = fread((DWORD *)&li_DWORD, sizeof(DWORD) , 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_DWORD != 0 && li_DWORD != -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_DWORD != -1)  // Find point in file were only ff's remain			{        		*last_non_ff = *fsize;			}		}		rewind(in_file);		// 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");	}}void jtag_unreset(){		_outp(lpt_address+2, 0);				// set all to 0}/********************************************************************************** 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 13KK pin settingsTDI = Data0TCK = Data1TMS = Data2TDO PaperError**** INPUT PARAMETERS: int tdi - test data in** RETURNS:          int - TDO (Test Data Out)** GLOBAL EFFECTS:   None*********************************************************************************/// Future work: this procedure needs to be cleaned up and extended. There is a // strong possibility that that the Altera Byte-Blaster cable could also be// supported. int putp(int tdi, int tms, int rp){	int tdo = -1;	switch(CableType)	{	case Parallel_Jtag:		{			// 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		} break;	case Wiggler_Jtag:		{			// TMS is D1, TDI is D3, and TCK is D2, so construct an output by creating a 			// rising edge on TCK with TMS and TDI data set.			#define WIGGLER_nSRST	0x01	// D0, pin 2			#define WIGGLER_TMS		0x02	// D1, pin 3			#define WIGGLER_TCK		0x04	// D2, pin 4			#define WIGGLER_TDI		0x08	// D3, pin 5			#define WIGGLER_nTRST	0x10	// D4, pin 6//			#define WIGGLER_TDO		0x80	// BUSY, pin 11			#define WIGGLER_TDO_POS	7			int lpt_data = WIGGLER_nTRST;			if(tms == 1) lpt_data |= WIGGLER_TMS;			if(tdi == 1) lpt_data |= WIGGLER_TDI;   			// construct an output by creating a 			// rising edge on TCK with TMS and TDI data set.			lpt_data &= ~WIGGLER_TCK;			_outp(lpt_address, lpt_data);	// TCK low			lpt_data |= WIGGLER_TCK;			_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 &= ~WIGGLER_TCK;				_outp(lpt_address, lpt_data);	// TCK high ??? Low?				tdo = !((int)_inp(lpt_address + 1) >> WIGGLER_TDO_POS);	// get TDO data			}		} break;	case 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_DIN		0x01			#define INSIGHT_CLK		0x02			#define INSIGHT_TMS_IN  0x04  						/* Output Enable for the standard JTAG outputs 			(not TDO since this is an output from the 			chip we want to talk to */			#define nINSIGHT_CTRL	0x08			#define nINSIGHT_PROG	0x10  /* This causes the TDO line to be driven. We'll leave it high.*/			/*the input port (lpt_address + 1)*/			#define TDO_INPUT			0x10			#define TDO_INPUT_BITPOS	4			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 ??? Low?				tdo = ((int)_inp(lpt_address + 1) & TDO_INPUT) >> TDO_INPUT_BITPOS;	// get TDO data			}		} break;	}//	#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){    char constructed_string[35];//    int device;//   	int bitscount = 0;    	IR_Command(IR_Idcode);    pre_DRSCAN();		strcpy(constructed_string, "");	// construct the processor ID	strcat(constructed_string, "**** ");	strcat(constructed_string, &WORDARRAY[p_proc_id][0]);	strcat(constructed_string, " ");	strcat(constructed_string, &WORDARRAY[p_proc_mfg][0]);	strcat(constructed_string, " ");	strcat(constructed_string, &WORDARRAY[p_proc_std][0]);	if(check_id(constructed_string))		error_out("failed to read device ID for this Platform");		DebugProgress |= foundProcID;    post_DRSCAN();}/********************************************************************************** FUNCTION:         IR_Command** DESCRIPTION:      sends an instruction to the controller and puts all other *                   devices into bypass mode.** INPUT PARAMETERS: int	command** RETURNS:          void*********************************************************************************/void IR_Command(int command){    int device;    pre_IRSCAN();	for(device = DEVICES_IN_CHAIN -1 ; device >= 0; device--)	{		if(device == DEVICE_CONTROLLER)		{			if(DEVICEISLAST[device])			{				controller_scan_code(command, IGNORE_PORT, TERMINATE);			}			else // controller is not the last in the chain			{				controller_scan_code(command, IGNORE_PORT, CONTINUE);			}		}		else		{			if(DEVICEISLAST[device])			{				    other_bypass(IGNORE_PORT, TERMINATE, (int)DEVICEIRLENGTH[device]);			}			else 			{				    other_bypass(IGNORE_PORT, CONTINUE, (int)DEVICEIRLENGTH[device]);			}		} 	}    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(int rw, DWORD address, DWORD data, int rp){	DWORD returnvalue;    DWORD HalfData = data & FIRST_HALF_WORD_MASK;	// Get the rightmost half of the word only    // Shift Flash address making A2 the LSB    	if(Debug_Mode)	{	   	if(PlatformIs16bit)		 printf("ACCESS_ROM: inp addr = %X, inp HalfData = %X\n", address, HalfData);		else		 printf("ACCESS_ROM: inp addr = %X, inp data = %X\n", address, data);    }	if(PlatformIs16bit)		returnvalue = (access_bus(rw, address << 1, HalfData, rp) & FIRST_HALF_WORD_MASK);    else		returnvalue = access_bus(rw, address << 2, data, rp);    if(Debug_Mode)    	printf("ACCESS_ROM Returns %X\n", returnvalue);    return returnvalue;}/********************************************************************************** FUNCTION:         Write_Rom** DESCRIPTION:      This routine manipulates the memory bus to do reads *                   and writes to any memory location.** INPUT PARAMETERS: int address - address to which you need to write to rom*					int data    - data you need to write to rom** RETURNS:          none*********************************************************************************/void Write_Rom(DWORD address, DWORD data){	if(Debug_Mode)		printf("Writing to ROM ...\n");	access_rom(SETUP, address, data, IGNORE_PORT);	access_rom(WRITE, address, data, IGNORE_PORT);	access_rom(HOLD, address, data, IGNORE_PORT);}/********************************************************************************** FUNCTION:         Read_Rom** DESCRIPTION:      This routine uses access_rom to read from rom*                   ** INPUT PARAMETERS: int address - address from which you need to read from rom** RETURNS:          DWORD - data read*********************************************************************************/DWORD Read_Rom(DWORD address){	if(Debug_Mode)		printf("Reading from ROM ...\n");				return access_rom(READ, address, 0, READ_PORT);}/********************************************************************************** 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 - retturned data*********************************************************************************/DWORD access_bus(int rw, DWORD address, DWORD data, int rp){	DWORD i;//	int j;	int device;	// 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);    set_address(address);    //----------------------------------------------    if(rw == READ)	{		if(Debug_Mode)        	printf("Read Mode\n");		mem_rw_mode(READ);        set_pin_chip_select(address);	}    //----------------------------------------------	else if(rw == WRITE)	{		if(Debug_Mode)        	printf("Write Mode\n");        mem_write_enable(ENABLE);		mem_output_enable(DISABLE);        mem_data_driver(DRIVE);        set_pin_chip_select(address);        set_data(data);

⌨️ 快捷键说明

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