Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void initEMC(void)
- {
- initPins();
- LPC_SC->PCONP |= 0x00000800;
- LPC_EMC->Control =1;
- LPC_EMC->Config = 0x00000000;
- EMC_StaMemConfigMW (NAND_CH,EMC_StaticConfig_MW_8BITS);
- EMC_StaMemConfigPB(NAND_CH,EMC_StaticConfig_PB);
- EMC_SetStaMemoryParameter(NAND_CH, EMC_STA_MEM_WAITWEN, EMC_StaticWaitWen_WAITWEN(0xF));
- EMC_SetStaMemoryParameter(NAND_CH, EMC_STA_MEM_WAITOEN, EMC_StaticWaitOen_WAITOEN(0xF));
- EMC_SetStaMemoryParameter(NAND_CH, EMC_STA_MEM_WAITRD, EMC_StaticWaitRd_WAITRD(0x1F));
- EMC_SetStaMemoryParameter(NAND_CH, EMC_STA_MEM_WAITPAGE, EMC_StaticwaitPage_WAITPAGE(0x1F));
- EMC_SetStaMemoryParameter(NAND_CH, EMC_STA_MEM_WAITWR, EMC_StaticWaitwr_WAITWR(0x1F));
- EMC_SetStaMemoryParameter(NAND_CH, EMC_STA_MEM_WAITTURN, EMC_StaticWaitTurn_WAITTURN(0x1F));
- delayMs(0, 10);
- }
- void NandFlash_WaitForReady( void )
- {
- u32 i;
- //while( FIO2PIN & (1 << 29) ); /* from high to low once */
- while( !(FIO2PIN & (1 << 29)) );
- return;
- }
- Bool NandFlash_PageProgram( u32 pageNum, u32 blockNum, u8 *bufPtr )
- {
- volatile u8 *pCLE = K9F1G_CLE;
- volatile u8 *pALE = K9F1G_ALE;
- volatile u8 *pDATA = K9F1G_DATA;
- u32 i, curAddr, curColumm;
- curAddr = NANDFLASH_BASE_ADDR + blockNum * NANDFLASH_BLOCK_FSIZE
- + pageNum * NANDFLASH_PAGE_FSIZE;
- curColumm = curAddr % NANDFLASH_PAGE_FSIZE;
- curAddr -= curColumm;
- *pCLE = K9FXX_BLOCK_PROGRAM_1;
- *pALE = (u8)(curColumm & 0x000000FF); /* column address low */
- *pALE = (u8)((curColumm & 0x00000F00) >> 8); /* column address high */
- *pALE = (u8)((curAddr & 0x00FF0000) >> 16); /* row address low */
- *pALE = (u8)((curAddr & 0xFF000000) >> 24); /* row address high */
- //Not write to spare area for the NandFlash valid block checking
- for ( i = 0; i < NANDFLASH_RW_PAGE_SIZE; i++ )
- {
- *pDATA = *bufPtr++;
- }
- *pCLE = K9FXX_BLOCK_PROGRAM_2;
- NandFlash_WaitForReady();
- return( NandFlash_ReadStatus( K9FXX_BLOCK_PROGRAM_1 ) );
- }
- Bool NandFlash_BlockErase( u32 blockNum )
- {
- volatile u8 *pCLE = K9F1G_CLE;
- volatile u8 *pALE = K9F1G_ALE;
- u32 rowAddr;
- rowAddr = (NANDFLASH_BASE_ADDR + blockNum * NANDFLASH_BLOCK_FSIZE);
- rowAddr = rowAddr - (rowAddr % NANDFLASH_BLOCK_FSIZE);
- *pCLE = K9FXX_BLOCK_ERASE_1;
- *pALE = (u8)(rowAddr & 0x00FF); /* column address low */
- *pALE = (u8)((rowAddr & 0xFF00) >> 8); /* column address high */
- *pCLE = K9FXX_BLOCK_ERASE_2;
- NandFlash_WaitForReady();
- return(NandFlash_ReadStatus(K9FXX_BLOCK_ERASE_1));
- }
- void NandFlash_Reset( void )
- {
- volatile u8 *pCLE;
- /* Reset NAND FLASH through NAND FLASH command */
- pCLE = K9F1G_CLE;
- *pCLE = K9FXX_RESET;
- delayMs(0, 2);
- return;
- }
- int NandFlash_ReadFromAddr(u32 addrInWholeNand, u8* bufPtr, u32 size)
- {
- volatile u8 *pCLE = K9F1G_CLE;
- volatile u8 *pALE = K9F1G_ALE;
- volatile u8 *pDATA = K9F1G_DATA;
- u32 i = 0, curColumm, curRow;
- curColumm = addrInWholeNand % NANDFLASH_PAGE_FSIZE;
- curRow = addrInWholeNand - curColumm;
- *pCLE = K9FXX_READ_1;
- *pALE = (u8)(curColumm & 0x000000FF); /* column address low */
- *pALE = (u8)((curColumm & 0x00000F00) >> 8); /* column address high */
- *pALE = (u8)((curRow & 0x00FF0000) >> 16); /* row address low */
- *pALE = (u8)((curRow & 0xFF000000) >> 24); /* row address high */
- *pCLE = K9FXX_READ_2;
- NandFlash_WaitForReady();
- //Get data from the current address in the page til the end of the page
- for ( i = 0; i < (NANDFLASH_PAGE_FSIZE - curColumm); i++ )
- {
- *bufPtr = *pDATA;
- bufPtr++;
- if((i + 1) >= size)
- break;
- }
- // Ok, return
- return i;
- }
- int NandFlash_PageReadFromAddr(u32 blockNum, u32 pageNum,
- u32 addrInPage, u8* bufPtr, u32 size)
- {
- u32 curAddr = 0;
- curAddr += NANDFLASH_BASE_ADDR + blockNum * NANDFLASH_BLOCK_FSIZE;
- curAddr += pageNum * NANDFLASH_PAGE_FSIZE;
- curAddr += addrInPage;
- return (NandFlash_ReadFromAddr(curAddr, bufPtr, size));
- }
- int NandFlash_PageReadFromBeginning(u32 blockNum, u32 pageNum, u8* bufPtr)
- {
- return (NandFlash_PageReadFromAddr(blockNum, pageNum, 0, bufPtr, NANDFLASH_PAGE_FSIZE));
- }
- u32 NandFlash_ReadId( void )
- {
- u8 a, b, c, d;
- volatile u8 *pCLE = K9F1G_CLE;
- volatile u8 *pALE = K9F1G_ALE;
- volatile u8 *pDATA = K9F1G_DATA;
- *pCLE = K9FXX_READ_ID;
- *pALE = 0;
- a = *pDATA;
- a = *pDATA;
- b = *pDATA;
- c = *pDATA;
- d = *pDATA;
- return ((a << 24) | (b << 16) | (c << 8) | d);
- }
Add Comment
Please, Sign In to add comment