📄 mx29lv640bt.c.bak
字号:
/* *Function: mx29lv640bt_Program_One_Sector *Description : This procedure can be used to program a total of 8192 bytes of data * to the mx29lv640bt. * *Parameters : flash_base_addr - base addr of a flash. * Src - source address containing the data which will be * written to the mx29lv640bt * Dst - destination address which will be written with the * data passed in from Src * Returns : NONE */ static void mx29lv640bt_Program_One_Sector (void *flash_base_addr,unsigned char *Src,unsigned char *Dst,int len){ unsigned char *Temp; unsigned char *SourceBuf; unsigned char *DestBuf; int Index; SourceBuf=Src; DestBuf = Dst; mx29lv640bt_Erase_One_Sector(flash_base_addr,Dst); /* erase the sector first */ for (Index = 0; Index < len; Index++) { Temp = (unsigned char *)((unsigned char *)flash_base_addr+0xaaa); /* set up address to be aaah */ *Temp = 0xaa; /* write data 0xaa to the address */ Temp = (unsigned char *)((unsigned char *)flash_base_addr+0x555); /* set up address to be 555h */ *Temp = 0x55; /* write data 0x55 to the address */ Temp = (unsigned char *)((unsigned char *)flash_base_addr+0xaaa); /* set up address to be 5555h */ *Temp = 0xa0; /* write data 0xa0 to the address */ Temp = DestBuf; /* save the original Destination address */ *DestBuf++ =*SourceBuf++; /* transfer data from source to destination */ mx29lv640bt_Toggle_Ready(Temp); /* wait for TOGGLE bit to get ready */ }}void mx29lv640bt_Program_One_Sector8(void *flash_base_addr,unsigned char *Src,unsigned char *Dst){ return mx29lv640bt_Program_One_Sector(flash_base_addr,Src,Dst,8*1024);} /* *Function: mx29lv640bt_Program_One_Block *Description : This procedure can be used to program a total of 64K bytes of data * to the am29lv320. * *Parameters : flash_base_addr - base addr of a flash. * Src - source address containing the data which will be * written to the am29lv320 * Dst - destination address which will be written with the * data passed in from Src * Returns : NONE */ void mx29lv640bt_Program_One_Block (void *flash_base_addr,unsigned char *Src,unsigned char *Dst){ return mx29lv640bt_Program_One_Sector(flash_base_addr,Src,Dst,64*1024);} /* *Function: mx29lv640bt_Toggle_Ready *Description : During the internal program cycle, any consecutive read operation * on DQ6 will produce alternating 0's and 1's (i.e. toggling between * 0 and 1). When the program cycle is completed, DQ6 of the data will * stop toggling. After the DQ6 data bit stops toggling, the device is * ready for next operation. * *Parameters : Dst - must already be set-up by the caller * *Returns : NONE */ void mx29lv640bt_Toggle_Ready (unsigned char *Dst){ unsigned char Loop = TRUE; unsigned char PreData; unsigned char CurrData; unsigned long TimeOut = 0; PreData = *Dst; PreData = PreData & 0x40; /*Get DQ6*/ while ((TimeOut< 0x07FFFFFF) && (Loop)) { CurrData = *Dst; CurrData = CurrData & 0x40; if (PreData == CurrData) Loop = FALSE; /* ready to exit the while loop */ PreData = CurrData; TimeOut++; } if (Loop == TRUE) printf("Unsucced!"); return;}/* *Function: mx29lv640bt_Erase_Entire_Chip *Description : This procedure can be used to erase the entire chip. * *Parameters : flash_base_addr - base addr of a flash. * *Returns : NONE */ void mx29lv640bt_Erase_Entire_Chip(void *flash_base_addr){ unsigned char *Temp; /* Issue the Chip Erase command to mx29lv640bt */ Temp = (unsigned char *)((unsigned char *)flash_base_addr + 0xaaa); *Temp = 0xaa; /* write data 0xAA to the address */ Temp = (unsigned char *)((unsigned char *)flash_base_addr + 0x555); *Temp = 0x55; /* write data 0x55 to the address */ Temp = (unsigned char *)((unsigned char *)flash_base_addr + 0xaaa); *Temp = 0x80; /* write data 0x80 to the address */ Temp = (unsigned char *)((unsigned char *)flash_base_addr + 0xaaa); *Temp = 0xaa; /* write data 0xAA to the address */ Temp = (unsigned char *)((unsigned char *)flash_base_addr + 0x555); *Temp = 0x55; /* write data 0x55 to the address */ Temp = (unsigned char *)((unsigned char *)flash_base_addr + 0xaaa); *Temp = 0x10; /* write data 0x10 to the address */ mx29lv640bt_Probe_Data_Polling ((unsigned char *)((unsigned char *)flash_base_addr + 0xaaa), (unsigned char)0xff); return;}/* *Function: mx29lv640bt_Probe_Data_Polling *Description : During the internal program cycle, any attempt to read DQ7 of the *last byte loaded during the page/byte-load cycle will receive the *complement of the true data. Once the program cycle is completed, *DQ7 will show true data. * *Parameters : Dst - must already be set-up by the caller * TrueData - Data is the original (true) data * *Returns : NONE */ static void mx29lv640bt_Probe_Data_Polling (unsigned char *Dst, unsigned char TrueData){ unsigned char Loop = TRUE; unsigned char CurrData; unsigned long TimeOut = 0; TrueData = TrueData & 0x80; while ((TimeOut< 0x07FFFFFF) && (Loop)) { CurrData = *Dst; CurrData = CurrData & 0x80; if (TrueData == CurrData) Loop = FALSE; /* ready to exit the while loop */ TimeOut++; }}/*The variaty of delay ruti*/static void mx29lv640bt_Delay_150_Nano_Seconds(void){ long i=20; while(i--){};}void mx29lv640bt_Delay_20_Micro_Seconds(void){ long i; for (i = 0;i < 133;i++) mx29lv640bt_Delay_150_Nano_Seconds();}void mx29lv640bt_Delay_25_Milli_Seconds(void){ long i; for (i = 0;i < 1250;i++) mx29lv640bt_Delay_20_Micro_Seconds();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -