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

📄 eval5500.c

📁 boot loader示范程序
💻 C
📖 第 1 页 / 共 3 页
字号:
			if(!EraseBlock(MEMBLOCK(MAINBLK14)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 15");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK15)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 16");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK16)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 17");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK17)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 18");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK18)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 19");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK19)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 20");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK20)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 21");
			if(!EraseBlock(MEMBLOCK(MAINBLK21)))      /* erase main_block1             */
			  return 0;
			printf("\nerase main block 22");		  
			if(!EraseBlock(MEMBLOCK(MAINBLK22)))      /* erase main_block2             */
			  return 0;
			printf("\nerase main block 23");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK23)))      /* erase main_block3             */
			  return 0;
			printf("\nerase main block 24");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK24)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 25");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK25)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 26");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK26)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 27");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK27)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 28");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK28)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 29");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK29)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 30");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK30)))      /* erase main_block4             */
			  return 0;
			printf("\nerase main block 31");		  		  
			if(!EraseBlock(MEMBLOCK(MAINBLK31)))      /* erase main_block4             */
			  return 0;
	
	
		}		
		/* =====================check array is erased================== */
		ptr_to_m = (unsigned short int *)meminfo->start_address;           /* point to lowest _add in FlashROM     */
		*ptr_to_m = READ_ARRAY;               /* read_array command                   */
		
		for(ptr_to_m = (unsigned short int *)meminfo->start_address;       /* point to flash_start and change type*/
		     ptr_to_m < (unsigned short int *)0x8000000;      /* point to flash_end and change type   */
		     ptr_to_m++) {                     /* inc pointer                          */
		
		  if (*ptr_to_m != 0xff){       /* check all bits are set to 1          */
		    return 0;
		  }
		}

	}

  	return 1;
}


int FlashWrite(int entries, UINT32 address, UBYTE *data) {

  	unsigned short int *addr = (unsigned short int *)(address & 0x7fffffff);
	unsigned short *flashdata =(unsigned short *)data;
	int error;
	unsigned short 	 *flashptr, status;
	
	//printf("\n address = %x ", addr);
	if(mfr_id == SST_ID) {
		printf("\n write SST flash");
		if(*flashdata != 0xFFFF) {
			*addr = 0x1010;                   /* clear status_register command        */
			*addr = *flashdata;                    /* write word to addressed location     */

			Check_Toggle_Ready((unsigned short int *)addr);           /* wait for Toggle bit ready */

			if (*addr != *flashdata) {                   /* test s_reg vpp_error_flag            */
				error = 1;                         /* error detected, set flag and report  */
				printf ("Data was 0x%x \n", flashdata);
				/* Here we verify that the word in flash is what we wanted to put there. */
				printf ("Read value is 0x%x \n", *addr);
				exit(1);   /* jump to end of process               */					
			}
		}
	}
	else if(mfr_id == AMD_ID){
		if(*flashdata != 0xFFFF){	
				
			flashptr = (unsigned short *)0x7ff00000;
		
			*flashptr = 0xF0;
	
			while ((status = flash_status(flashptr)) == STATUS_BUSY) {
			};
			if (status == STATUS_ERROR){                   /* on errors..                          */
				exit(1);   /* jump to end of process               */
			}
	
			flashptr[0x555] = 0xAA;       /* unlock 1 */
			flashptr[0x2AA] = 0x55;       /* unlock 2 */
			flashptr[0x555] = 0xA0;

	
			*addr = *flashdata;                    
			while ((status = flash_status(flashptr)) == STATUS_BUSY){
			};
			if (status == STATUS_TIMEOUT){                   /* on errors..                          */
				printf("\n write Error");
				exit(1);   /* jump to end of process               */
			}

			if (status == STATUS_ERROR){                   /* on errors..                          */
				printf("\n write Error");
				exit(1);   /* jump to end of process               */
			}
		}
	}
	else if(mfr_id == MXIC_ID) {
		if(*flashdata != 0xFFFF) {
			if(dev_id == MX29LV160AT) 
			{
				flashptr = (unsigned short *)START_ADDR_2M;
			}
			else
			{
				flashptr = (unsigned short *)START_ADDR_1M;
			}

			flashptr[0x555] = 0xAA;
			flashptr[0x2AA] = 0x55;
			flashptr[0x555] = 0xA0;

			ram_task_delay(1); //01 micro second


			*addr = *flashdata;                    
			ram_task_delay(5); //05 micro second

			Check_Toggle_Ready((unsigned short int *)flashptr);           /* wait for Toggle bit ready */

		  	if (*addr != *flashdata){              /* test s_reg vpp_error_flag            */
		  		printf("\naddress = %x [%x != %x]",addr, *addr, *flashdata);
		  		printf("\n compare error : not same data ");
				return sizeof(unsigned short int);
		    	return 0;
		  	}
		}
	}
	else{ 

	  	*addr = 0x60;
	  	*addr = 0xd0;

		*addr = CLEAR_SREG;                   /* clear status_register command        */
	  	*addr = READ_SREG;                     /* read status_register setup command   */
	  	*addr = PROGRAM_SETUP;                /* setup write word                     */
	  	*addr = *flashdata;                    /* write word to addressed location     */
	  	*addr = READ_SREG;                    /* read status_register setup command   */

	  	while (*addr != 0x80);                /* wait for bit7 of sreg = 1 (=finish)  */

	  	if ((*addr & 0x08) != 0x00) {          /* test s_reg vpp_error_flag    */
	    	return 0;
	  	}
	
	  	if ((*addr & 0x10) != 0x00) {      /* test s_reg prog_error_flag   */
	    	return 0;
	  	}
	
	  	/* Here we verify that the word in flash is what we wanted to put there. */
	  	*addr = READ_ARRAY;
	
	  	if (*addr != *flashdata){              /* test s_reg vpp_error_flag            */
	    	return 0;
	  	}


	}
	return sizeof(unsigned short int);
}


volatile long int *pio_data       = (long int *)0x20010000;
volatile long int *pio_config_c0  = (long int *)0x20010020;
volatile long int *pio_config_c1  = (long int *)0x20010030;
volatile long int *pio_config_c2  = (long int *)0x20010040;

#define PIO_VALUE(val)          *pio_data        = val;
#define PIO_CONF_C0(val)        *pio_config_c0   = val;
#define PIO_CONF_C1(val)        *pio_config_c1   = val;
#define PIO_CONF_C2(val)        *pio_config_c2   = val;


int BoardInit(void) {
  PIO_CONF_C0 (0xdf);
  PIO_CONF_C1 (0x20);
  PIO_CONF_C2 (0x0);
  return 0;
}


int LedOn(int bit) {
  if(bit & 1) {
    PIO_VALUE (0x00);
   }
  return 0;
}

int LedOff(int bit) {
  if(bit & 1) {
    PIO_VALUE (0xff);
  }
  return 0;
}

void RomClearup5500(void)
{
}

int  VerifyFlash5500(UINT32 flash_addr, UBYTE* source_data_p, ULONG length )
{
 if(memcmp((const void *)flash_addr, (const void *)source_data_p, (int) length) != 0)
   return 0;

  return 1;
}


int  ProgramFlash5500(UINT32 flash_addr, UBYTE* source_data_p, ULONG length )
{
  	int wordSize;
	
  	while(length>0) {
		wordSize = FlashWrite((int)length, flash_addr, source_data_p);
    	if(!wordSize)
      		return 0;
    	flash_addr    += wordSize;
    	length        -= wordSize;
    	source_data_p += wordSize;
  	}
  	return 1;
}



/******************************************************************************************************/
/*PROCEDURE:                         Check_Toggle_Ready                                                       */
/*                                                                                                                                            */
/*During the internal write cycle, any consecutive read operation                                         */
/*on DQ6 will produce alternating 0's and 1's i.e. toggling between                                      */
/* 0 and 1.  When the write cycle is completed, DQ6 of the data  will                                   */
/* stop toggling.  After the DQ6 data bit  stops toggling, the device is ready                         */
/* for next operation.                                                                                                              */
/*                                                                                                                                            */
/* Input:                                                                                                                                  */
/*      Dst     must  already set-up by the caller                                                          */
/*                                                                                                                                            */
/* Output:                                                                                                                               */
/*           None                                                                                                                        */
/*******************************************************************************************************/

void Check_Toggle_Ready (volatile unsigned short int *Dst)
{
	BYTE Loop = TRUE;
	volatile unsigned short int PreData;
	volatile unsigned short int CurrData;
	unsigned long TimeOut = 0;

	PreData = *Dst;
	PreData = PreData & 0x4040;
	while ((TimeOut< 0x07FFFFFF) && (Loop)) {
		CurrData = *Dst;
		CurrData = CurrData & 0x4040;
		if (PreData == CurrData)
			Loop = FALSE;           /* ready to exit the while loop */
		PreData = CurrData;
		TimeOut++;
	}
}


unsigned short int flash_status(unsigned short int *fp){

	BYTE data, togl_data;
	unsigned short int  retry = 1;

AGAIN:

	data = *fp;        /* read data */
	togl_data = data ^ *fp;    /* read it again and see what toggled */

	if (togl_data == 0) {           /* no toggles, nothing's happening */
		return STATUS_READY;
	}
	else if (togl_data == 0x04) { /* erase-suspend */
		if (retry--) goto AGAIN;    /* may have been write completion */
		return STATUS_ERSUSP;
	}
	else if (togl_data & 0x40){
		if (data & 0x20){     /* timeout */
			return STATUS_TIMEOUT;
		}
		else {
		  	return STATUS_BUSY;
		}
	}

	if (retry--) goto AGAIN;    /* may have been write completion */

	return STATUS_ERROR;
}






⌨️ 快捷键说明

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