/********************************************************************/ /* 7188EX + X560 source code */ /* */ /* [14, October, 2005] by Liam */ /********************************************************************/ /********************************************************************/ /* X560: COM3 (3-wire RS-232) */ /* COM4 (3-wire RS-232) */ /* COM5 (3-wire RS-232) */ /* NAND FLASH 8M Bytes */ /********************************************************************/ #define NoError 0 #define TimeOut -5 #define ValError 2 #define DeviceError 3 #define CheckError 4 #define NoInit 5 #define BadPage 6 #define UsedPage 7 #define CrcError 8 #ifdef __cplusplus extern "C" { #endif int X560_Init(void); /* For 4M flash return 4, for 8M flash return 8, for 16M flash return 16, others(or NO flash) return 0 */ int X560_Reset_FLASH(void); void X560_WP_FLASH(char wp); /* wp=0 --> write protect wp=1 --> write enable */ unsigned char X560_Read_FLASH_Status(void); /* definition of status read : BIT 0: 0=erase/program OK, 1=erase/program Error BIT 1: 0 BIT 2: 0 BIT 3: 0 BIT 4: 0 BIT 5: 0 BIT 6: 0=device busy, 1=device ready BIT 7: 0=write protected, 1=not protected */ static void X560_Read_FLASH_ID(unsigned char *maker, unsigned char *device); int X560_Erase_FLASH_Block(unsigned int block); /* block range: 0~(MaxBlock-1) */ int X560_Write_Page(unsigned block,unsigned page, unsigned char far *buf1, unsigned char far *buf2); int X560_Read_Page(unsigned block,unsigned page, unsigned char far *buf1, unsigned char far *buf2); /* block: 0~(MaxBlock-1) page: 0~15 buf1 size=512 bytes(PageDataSize) buf2 size=16 bytes(PageSpareDataSize) */ extern int PageDataSize,PageSpareDataSize,PageNoPerBlock; /* 4M(X600) 8M(X601/X560) 16M(X602) PageDataSize = 512 512 512 PageSpareDataSize = 16 16 16 PageNoPerBlock = 16 16 32 */ extern unsigned MaxBlock; /* for 4M: MaxBlock=512 for 8M: MaxBlock=1024 for 16M: MaxBlock=1024 */ /* FLASH size=MaxBlock * PageNoPerBlock * (PageDataSize+PageSpareDataSize) */ typedef struct { int addr:9; int page:4; int block:10; int reserve:9; }FLASH_ADDR; /* for 4/8M type only */ #ifdef __cplusplus } #endif