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

📄 jflash.cpp

📁 ARM 10 KEYPAD DESIGN
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				Write_Rom(0, F_READ_ARRAY);	// put back into read mode								// try forcing asynchronous read mode				Write_Rom(0x8000, F_SET_READ_CFG_REG);				Write_Rom(0x8000, F_SET_READ_CFG_REG_2ND);				//				Write_Rom(0x0, F_READ_ARRAY);	// put back into read mode//				Write_Rom(0x0, F_READ_IDCODES);				   	//			  	FlashCR = (Read_Rom(0x5) & 0xFFFF);//			    FlashCR = (Read_Rom(0x5) & 0xFFFF); // buggy K flash needs another read	//				printf("configuration register = %X\n",FlashCR);								Write_Rom(0, F_READ_ARRAY);	// put back into read mode				access_rom(READ, 0x0L, 0x0L, IGNORE_PORT); //extra read to get the pipeline going			}		}		else		{			IDFound = true;			}	 } while(!IDFound);		DebugProgress |= foundFlashID;	ParseAndLoadFlashData();	InitFlashGlobals();	printf("Found flash type: %s\n", &FLASHWORDARRAY[pf_type][0]); 	// set the required variables by using the previousely defined globals	*max_erase_time = BlockEraseTime;	*dsize = FlashDeviceSize;	*max_write_buffer = FlashBufferSize;}/********************************************************************************** FUNCTION:         check_file_info** DESCRIPTION:      get the file information and check with rom size*                   ** INPUT PARAMETERS: DWORD *fsize			: file size					DWORD *last_non_zero	: the point where only 0 or FF remain					DWORD *last_non_ff		: the point where only ff remain																				    if LUBBOCK_SABINAL or										    LUBBOCK_DBPXA262 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){			WORD li_WORD;	DWORD li_DWORD;    if(PlatformIs16bit)	{		for(;;)		{			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(;;)		{			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");	}}/********************************************************************************** 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*********************************************************************************/// 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;	if(CableType == 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.		/* fixed */		_outp(lpt_address, tms*4+tdi*1+16);				// TCK low 		_outp(lpt_address, tms*4+tdi*1+2+16);				// TCK high 		// if we want to read the port, set TCK low because TDO is sampled on the 		// TCK falling edge.		/* fixed */		if(rp == READ_PORT)			_outp(lpt_address, tms*4+tdi*1+16);			// TCK low		if(rp == READ_PORT)			tdo = ((int)_inp(lpt_address + 1) >> 4);	// get TDO data		tdo &= 0x1;	}	else if (CableType == 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		}	}//	#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[50];		/* fixed *///	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 = %lX, inp HalfData = %lX\n", address, HalfData);		else		 printf("ACCESS_ROM: inp addr = %lX, inp data = %lX\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 %lX\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);

⌨️ 快捷键说明

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