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

📄 flashoperation.h

📁 xilinx fpga x3s500e芯片从flashboot的程序代码
💻 H
字号:
#include "xbasic_types.h"#include "xparameters.h"#include "xutil.h"#include "xgpio.h"#include "xgpio_l.h"#include "xuartlite.h"#include "xuartlite_l.h"#define FLASH_READY XPAR_FLASH_READY_BASEADDR#define FLASH_BYTE  XPAR_FLASH_BYTE_BASEADDR#define RS232_BASEADDR XPAR_RS232_BASEADDRvolatile Xuint16 * const ext_flash_16   = (volatile Xuint16 *)XPAR_GENERIC_EXTERNAL_MEMORY_MEM0_BASEADDR;void initialize_flash(){	XGpio_mSetDataDirection(FLASH_READY, 1, 0x1);   //set FLASH_READY GPIO's direction. 0x1 represents the input mode;		XGpio_mSetDataDirection(FLASH_BYTE,1,0x0);  //set to output mode	print("setting...\r\n");	XGpio_mWriteReg(FLASH_BYTE,XGPIO_DATA_OFFSET,0x1);  //write 0 to the gpio	putnum(XGpio_mReadReg(FLASH_BYTE,XGPIO_DATA_OFFSET)); //read from the gpio	print("\r\n");	return;}void wait_at_least_10_us(){	unsigned int i;	int temp;	for(i=0;i<0x64;i++){;} //100 times	return ; }void wait(){	unsigned int i;	int temp;	for(i=0;i<0xFFF;i++){;} 	return ; }unsigned char cfi_erase_bank_16(Xuint16 *flash_base,unsigned char bank_num){	int j;		flash_base[0x555]=0x00F0; 	wait_at_least_10_us();	flash_base[0x555]=0x00AA; 	wait_at_least_10_us();	flash_base[0x2AA]=0x0055;   	wait_at_least_10_us();	flash_base[0x555]=0x0080;	wait_at_least_10_us();   	flash_base[0x555]=0x00AA;  	wait_at_least_10_us();		flash_base[0x2AA]=0x0055; 	wait_at_least_10_us();		flash_base[bank_num*0x8000]=0x0030;		while( (j=XIo_In32(FLASH_READY)) == 0);	return 1;}unsigned char cfi_erase_whole_flash_16(Xuint16 *flash_base){	int j;		flash_base[0x555]=0x00F0; 	wait_at_least_10_us();	flash_base[0x555]=0x00AA; 	wait_at_least_10_us();	flash_base[0x2AA]=0x0055;   	wait_at_least_10_us();	flash_base[0x555]=0x0080;	wait_at_least_10_us();   	flash_base[0x555]=0x00AA;  	wait_at_least_10_us();		flash_base[0x2AA]=0x0055; 	wait_at_least_10_us();		flash_base[0x555]=0x0010;		while( (j=XIo_In32(FLASH_READY)) == 0);	return 1;}unsigned char cfi_flash_write_16(Xuint16 *flash_base,long offset,Xuint16 val){  flash_base[0x555] = 0x00F0;  wait_at_least_10_us();  flash_base[0x555] = 0x00AA; // 1st cycle  addr = XXX, data = AA  wait_at_least_10_us();  flash_base[0x2AA] = 0x0055; // 2nd cycle  addr = XXX, data = 55  wait_at_least_10_us();  flash_base[0x555] = 0x00A0; // 3rd cycle  addr = XXX, data = A0   wait_at_least_10_us();  flash_base[offset] = val;     // 4th cycle  addr = PA, data = PD  wait_at_least_10_us();    while(XIo_In32(FLASH_READY) == 0);  return 1;}void Get_FlashInfo_16(Xuint16 *flash_base){  	flash_base[0x555]=0xF0; 	wait_at_least_10_us();	flash_base[0x555]=0xAA; 	wait_at_least_10_us();	flash_base[0x2AA]=0x55;    //byte   wait_at_least_10_us();	flash_base[0x555]=0x90;	wait_at_least_10_us();	print("base:");	putnum(flash_base);	print("\r\n");	print("Manufacturer ID:");	putnum(flash_base[0x00000]);	print(" \r\n");		print("Device ID:");	putnum(flash_base[0x00001]);	print(" \r\n"); 	print("Sector Protect Verify:");	putnum(flash_base[0x00002]);	print("\r\n");	print("Secured Slilicom Sector Factory Protect Model 04 :");	putnum(flash_base[0x00003]);	print("\r\n");		return;}long program_flash(Xuint16* flash_base_addr,long total_bytes){	long count=0;	Xuint8 low = 0;	Xuint8 high = 0;	Xuint16 val = 0;	//count = 0;//**********************************************Clear THE FIFO*******************************************/    	while(1)   {	      XUartLite_mSetControlReg(RS232_BASEADDR,0x03);      if(XUartLite_mIsReceiveEmpty(RS232_BASEADDR))		{		   break;		}   }/***********************************************START RECEIVE DATA***************************************************/       while(XUartLite_mIsReceiveEmpty(RS232_BASEADDR)); //wait for arrival of the data	while(count<total_bytes) 	{  		if(!XUartLite_mIsReceiveEmpty(RS232_BASEADDR))		{						if (count % 2 == 0)				low = XUartLite_RecvByte(RS232_BASEADDR);			else{				high = XUartLite_RecvByte(RS232_BASEADDR);				val = (high<<8) + low;				cfi_flash_write_16(flash_base_addr,(count-1)/2,val);			}		   count++;				}   }		print("finish");   return count;}long program_flash_down(Xuint16* flash_base_addr,long total_bytes,Xuint32 offset){	long count=0;	Xuint8 low = 0;	Xuint8 high = 0;	Xuint16 val = 0;	//count = 0;//**********************************************Clear THE FIFO*******************************************/    	while(1)   {	      XUartLite_mSetControlReg(RS232_BASEADDR,0x03);      if(XUartLite_mIsReceiveEmpty(RS232_BASEADDR))		{		   break;		}   }/***********************************************START RECEIVE DATA***************************************************/       while(XUartLite_mIsReceiveEmpty(RS232_BASEADDR)); //wait for arrival of the data	while(count<total_bytes) 	{  		if(!XUartLite_mIsReceiveEmpty(RS232_BASEADDR))		{						if (count % 2 == 0)				high = XUartLite_RecvByte(RS232_BASEADDR);			else{				low = XUartLite_RecvByte(RS232_BASEADDR);				val = (high<<8) + low;				cfi_flash_write_16(flash_base_addr,(offset-1-(count-1)/2),val);			}		   count++;					}   }			print("finish");   return count;}

⌨️ 快捷键说明

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