📄 mx29lv320.c
字号:
/*****************************************************************************;; Project : Common platform; Creator : Dan Everett; File : mx29lv320.c; Abstract:;;*****************************************************************************/#include <mips4kc.h>#include <adm5120.h>#include <hw_profile.h>#include "flash.h"#include "mx29lv320.h"/************************* declare global variables *************************/ static int mx29lv320_erase(struct FLASH_DESC_S *cp, char *flash, int cells);static int mx29lv320_read (struct FLASH_DESC_S *cp, char *flash, char *dst, int cells);static int mx29lv320_write(struct FLASH_DESC_S *cp, char *flash, char *src, int cells);static int mx29lv320_protectinfo(struct FLASH_DESC_S *cp);short mx_mfg_id;short mx_dev_id;short mx_factory_protect;unsigned long mx_ssv_lo;unsigned long mx_ssv_med;unsigned long mx_ssv_hi;extern int ssopen;unsigned long mx29lv320_blocks[] ={ 0x00000000, 0x00002000, 0x00004000, 0x00006000, 0x00008000, 0x0000A000, 0x0000C000, 0x0000E000, 0x00010000, 0x00020000, 0x00030000, 0x00040000, 0x00050000, 0x00060000, 0x00070000, 0x00080000, 0x00090000, 0x000a0000, 0x000b0000, 0x000c0000, 0x000d0000, 0x000e0000, 0x000f0000, 0x00100000, 0x00110000, 0x00120000, 0x00130000, 0x00140000, 0x00150000, 0x00160000, 0x00170000, 0x00180000, 0x00190000, 0x001a0000, 0x001b0000, 0x001c0000, 0x001d0000, 0x001e0000, 0x001f0000, 0x00200000, 0x00210000, 0x00220000, 0x00230000, 0x00240000, 0x00250000, 0x00260000, 0x00270000, 0x00280000, 0x00290000, 0x002a0000, 0x002b0000, 0x002c0000, 0x002d0000, 0x002e0000, 0x002f0000, 0x00300000, 0x00310000, 0x00320000, 0x00330000, 0x00340000, 0x00350000, 0x00360000, 0x00370000, 0x00380000, 0x00390000, 0x003a0000, 0x003b0000, 0x003c0000, 0x003d0000, 0x003e0000, 0x003f0000,};unsigned long mx29lv320_sas[] ={ 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, 0x58, 0x60, /* SA16 - SA19 */ 0x68, 0x70, 0x78, 0x80, 0x88, 0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, 0xd8, 0xe0, /* SA32 - SA35 */ 0xe8, 0xf0, 0xf8, 0x100, 0x108, 0x110, 0x118, 0x120, 0x128, 0x130, 0x138, 0x140, 0x148, 0x150, 0x158, 0x160, 0x168, 0x170, 0x178, 0x180, /* SA52 - SA55 */ 0x188, 0x190, 0x198, 0x1a0, 0x1a8, 0x1b0, 0x1b8, 0x1c0, 0x1c8, 0x1d0, 0x1d8, 0x1e0, 0x1e8, 0x1f0, 0x1f8 /* SA68 - SA70 */};FLASH_DESC mx29lv320_dev = { 0, // next 0x400000, // flash_size=4M 1, // addr_inc 2, // byte_width (char *) PA2VA(HWPF_5120_SMEM0_BASE), // start mx29lv320_blocks, // blocks sizeof(mx29lv320_blocks)/sizeof(unsigned long), mx29lv320_erase, mx29lv320_read, mx29lv320_write, mx29lv320_protectinfo};/*---------------------------------------------------------------------- * disable_write * Disable writing to the flash main blocks *----------------------------------------------------------------------*/static void disable_write(){ volatile unsigned long data; volatile unsigned long *reg; /**********************************/ /* flash write protect enable */ /**********************************/ return;}/*---------------------------------------------------------------------- * enable_write * Enable writing to the flash main blocks *----------------------------------------------------------------------*/static void enable_write(){ volatile unsigned long data; volatile unsigned long *reg; /**********************************/ /* flash write protect disable */ /**********************************/ return; }/*---------------------------------------------------------------------- * mx29lv320_erase_block * The routine is called by NV RAM driver or the image updating module * to erase the blocks, whereafter this block can accept new data * written. * * INPUT: * flash_P -- Address of the block to erase. *----------------------------------------------------------------------*/ static int mx29lv320_erase_block(struct FLASH_DESC_S *cp, char *flash){ register int i, ticks; unsigned short val; volatile unsigned short *block = (unsigned short *)flash; volatile unsigned short *p555 = (unsigned short *)((unsigned long)cp->start + 0x0aaa); volatile unsigned short *p2aa = (unsigned short *)((unsigned long)cp->start + 0x0554); /***********************/ /* Unprotect Flash */ /***********************/ enable_write(); /***********************/ /* Issue erase command */ /***********************/ *block = 0xf0; /* Make sure in read state */ *p555 = 0xaa; *p2aa = 0x55; *p555 = 0x80; *p555 = 0xaa; *p2aa = 0x55; *block = 0x30; for (ticks=0, i=0;; i++) { val = *block; /* When Erase operation is completed, DQ7 will produce 1 "1". and DQ6 stops toggling. */ if ((val & 0x80) == 0x80) { // Check DQ6 toggle unsigned short s_val; // Read the second time. s_val = *block; if ((s_val & 0x80) && (s_val & 0x40) == (val & 0x40)) { *block = 0xf0; /* Do reset */ disable_write(); return FLASH_OK; } } else { if (i >= 1024) { i = 0; if (++ticks > 7*100*10) { break; } } } } *block = 0xf0; /* Do reset */ disable_write(); return FLASH_ERROR;} /*---------------------------------------------------------------------- * mx29lv320_erase * The routine is called by NV RAM driver or the image updating module * to erase the blocks, whereafter this block can accept new data * written. * * INPUT: * flash -- Address of the flash start address to be erased * size -- size of the flash portion to be erased *----------------------------------------------------------------------*/static int mx29lv320_erase(struct FLASH_DESC_S *cp, char *flash, int size){ register int i; register char *next; register char *start = cp->start; for (i=0; i<cp->num; i++) { if (flash != (char *)(start + cp->blocks[i])) continue; if (mx29lv320_erase_block(cp, flash) != FLASH_OK) return FLASH_ERROR; // Get next block if (i == cp->num - 1) next = (char *)(start + cp->flash_size); else next = (char *)(start + cp->blocks[i+1]); // subtract erased size size -= (next - flash); if (size <= 0) break; flash = next; } return FLASH_OK;}/*----------------------------------------------------------------------* mx29lv320_read * The routine is called by NV RAM driver to read NV data. * * INPUT: * flash -- Address of the block to read. * dst -- address of this data buffer. * size -- data size to read from the flash.*----------------------------------------------------------------------*/static int mx29lv320_read(struct FLASH_DESC_S *cp, char *flash, char *dst, int size){ register int i; volatile unsigned short *block = (volatile unsigned short *)flash; volatile unsigned short *data = (volatile unsigned short *)dst; /* Convert size in byte to size in word.*/ size = (size + 1) / 2; /***********************/ /* Read data */ /***********************/ for (i = 0; i < size; i++) *data++ = *block++; return FLASH_OK;}/*---------------------------------------------------------------------- * mx29lv320_write * The routine is called by NV RAM driver or the image updating module * to update the date content.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -