#define USE_NFCE (0)
#define USE_GPIO (0)
#define TACLS (NAND_TACLS)
#define TWRPH0 (NAND_TWRPH0)
#define TWRPH1 (NAND_TWRPH1)
#define ECCType (23)
//-----------------------------------------------------------------------------
#define CMD_READID (0x90) // ReadID
#define CMD_READ (0x00) // Read
#define CMD_READ2 (0x50) // Read2
#define CMD_READ3 (0x30) // Read3
#define CMD_RESET (0xff) // Reset
#define CMD_ERASE (0x60) // Erase phase 1
#define CMD_ERASE2 (0xd0) // Erase phase 2
#define CMD_WRITE (0x80) // Write phase 1
#define CMD_WRITE2 (0x10) // Write phase 2
#define CMD_STATUS (0x70) // STATUS
#define CMD_RDI (0x85) // Random Data Input
#define CMD_RDO (0x05) // Random Data Output
#define CMD_RDO2 (0xE0) // Random Data Output
#define BADBLOCKMARK (0x00)
// Status bit pattern
#define STATUS_READY (0x40) // Ready
#define STATUS_ERROR (0x01) // Error
#define STATUS_ILLACC (0x20) // Illigar Access
#define NF_ECCERR0_ALL_FF 0x40000000
#define NF_ECCERR0_ECC_READY 0x20000000
//-----------------------------------------------------------------------------
#define NF_ADDR(addr) {g_pNFConReg->NFADDR = (unsigned char)(addr);}
#define NF_nFCE_L() {g_pNFConReg->NFCONT &= ~(1<<1);}
#define NF_nFCE_H() {g_pNFConReg->NFCONT |= (1<<1);}
#define NF_ECC_DIRECTION_IN() {g_pNFConReg->NFCONT &= ~(1<<18);}
#define NF_ECC_DIRECTION_OUT() {g_pNFConReg->NFCONT |= (1<<18);}
#define NF_ECC_8BIT_STOP() {g_pNFConReg->NFCONT |= (1<<12);} //stop the last encode or decode of 8bit mode.
#define NF_RSTECC() {g_pNFConReg->NFCONT |= ((1<<5) | (1<<4));}
#define NF_MSGLENGTH_512() {g_pNFConReg->NFCONF &= ~(1<<25);}
#define NF_MSGLENGTH_24() {g_pNFConReg->NFCONF |= (1<<25);}
#define NF_ECCTYPE_CLR (g_pNFConReg->NFCONF &= ~(3<<23))
#define NF_ECCTYPE_1BIT() {NF_ECCTYPE_CLR;}
#define NF_ECCTYPE_4BIT() {NF_ECCTYPE_CLR |= (1<<24);}
#define NF_ECCTYPE_8BIT() {NF_ECCTYPE_CLR |= (1<<23);}
#define NF_MECC_UnLock() {g_pNFConReg->NFCONT &= ~(1<<7);}
#define NF_MECC_Lock() {g_pNFConReg->NFCONT |= (1<<7);}
#define NF_SECC_UnLock() {g_pNFConReg->NFCONT &= ~(1<<6);}
#define NF_SECC_Lock() {g_pNFConReg->NFCONT |= (1<<6);}
#define NF_CLEAR_RB() {g_pNFConReg->NFSTAT |= (1<<4);} // Have write '1' to clear this bit.
#define NF_DETECT_RB() {while((g_pNFConReg->NFSTAT&0x11)!=0x11);} // RnB_Transdetect & RnB
#define NF_WAITRB() {while (!(g_pNFConReg->NFSTAT & (1<<0))) ; }
#define NF_RDDATA_BYTE() (g_pNFConReg->NFDATA)
#define NF_RDDATA_WORD() (*(UINT32 *)0xb0200010)
#define NF_WRDATA_BYTE(data) {g_pNFConReg->NFDATA = (UINT8)(data);}
#define NF_WRDATA_WORD(data) {*(UINT32 *)0xb0200010 = (UINT32)(data);}
#define NF_RDMECC0() (g_pNFConReg->NFMECC0)