📄 nfc.c
字号:
break;
case NFC_CMD_RD_PB_NOECC:
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_READ;
nfc_command_input(NAND_CMD_READ);
nfc_address_cycle(iBlockNum, iPageNum);
nfc_flash_data_output();
if(pMBuf != (uint32_t*)0)
MemoryCopy((void*)NFC_MAB0_BASE, (void*)pMBuf, NAND_PAGE_SIZE);
if(pSBuf != (uint32_t*)0)
MemoryCopy((void*)NFC_SAB0_BASE, (void*)pSBuf, NAND_PAGE_SIZE/32);
break;
case NFC_CMD_RD_SB_ECC:
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_READ|NFC_CONFIG1_SP_ONLY|NFC_CONFIG1_ECC_EN;
nfc_command_input(NAND_CMD_READ2);
nfc_address_cycle(iBlockNum, iPageNum);
nfc_flash_data_output();
if(pSBuf != (uint32_t*)0)
MemoryCopy((void*)NFC_SAB0_BASE, (void*)pSBuf, NAND_PAGE_SIZE/32);
if( *(p_uint16_t)NFC_ECC_STAT_RES )
return ( *(p_uint16_t)NFC_ECC_STAT_RES & 0x0F);
break;
case NFC_CMD_RD_SB_NOECC:
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_READ|NFC_CONFIG1_SP_ONLY;
nfc_command_input(NAND_CMD_READ2);
nfc_address_cycle(iBlockNum, iPageNum);
nfc_flash_data_output();
if(pSBuf != (uint32_t*)0)
MemoryCopy((void*)NFC_SAB0_BASE, (void*)pSBuf, NAND_PAGE_SIZE/32);
break;
default:
return NFC_ILLEGAL_ACCESS;
}
return NFC_NO_ERR;
}
/*****************************************************************************/
/* */
/* NAME */
/* nfc_read_spare (interface function) */
/* DESCRIPTION */
/* This function reads NAND spare area (16Bytes size) */
/* PARAMETERS */
/* iBlockNum wanted block number of the NAND Flash to read */
/* iPageNum wanted page number of the upper blk_num block */
/* of the NAND Flash to read */
/* pSBuf unsigned char type pointer of spare area sized */
/* buffer to read */
/* bEcc flag of using hardware/software ecc or not */
/* RETURN VALUES */
/* This function returns NFC_NO_ERR when it does successfully. */
/* If previous write error occurs, this function returns NFC_WRITE_ERR. */
/* If ECC error occured, ECC related error is returned */
/* */
/*****************************************************************************/
uint32_t
nfc_read_spare(uint16_t iBlockNum, uint16_t iPageNum,
uint32_t* pSBuf, uint8_t bEcc)
{
if(bEcc == ECC_READ)
return(nfc_read(iBlockNum, iPageNum, (uint32_t*)0, (uint32_t*)pSBuf, NFC_CMD_RD_SB_ECC));
else
return(nfc_read(iBlockNum, iPageNum, (uint32_t*)0, (uint32_t*)pSBuf, NFC_CMD_RD_SB_NOECC));
}
/*****************************************************************************/
/* */
/* NAME */
/* nfc_read_main (interface function) */
/* DESCRIPTION */
/* This function reads NAND main area (512Bytes size) */
/* PARAMETERS */
/* iBlockNum wanted block number of the NAND Flash to read */
/* iPageNum wanted page number of the upper blk_num block */
/* of the NAND Flash to read */
/* pMBuf unsigned char type pointer of main area sized */
/* buffer to read */
/* bEcc flag of using hardware/software ecc or not */
/* RETURN VALUES */
/* This function returns EAG_NO_ERR when it does successfully. */
/* If previous write error occurs, this function returns NFC_WRITE_ERR. */
/* If ECC error occured, ECC related error is returned */
/* */
/*****************************************************************************/
uint32_t
nfc_read_main(uint16_t iBlockNum, uint16_t iPageNum,
uint32_t* pMBuf, uint8_t bEcc)
{
if (bEcc == ECC_READ)
return(nfc_read(iBlockNum, iPageNum, (uint32_t*)pMBuf, (uint32_t*)0, NFC_CMD_RD_PB_ECC));
else
return(nfc_read(iBlockNum, iPageNum, (uint32_t*)pMBuf, (uint32_t*)0, NFC_CMD_RD_PB_NOECC));
}
/*****************************************************************************/
/* */
/* NAME */
/* nfc_read_page (interface function) */
/* DESCRIPTION */
/* This function reads NAND page area (528Bytes size) */
/* PARAMETERS */
/* iBlockNum wanted block number of the NAND Flash to read */
/* iPageNum wanted page number of the upper blk_num block */
/* of the NAND Flash to read */
/* pMBuf unsigned char type pointer of main area sized */
/* buffer to read */
/* pSBuf unsigned char type pointer of spare area sized */
/* buffer to read */
/* bEcc flag of using hardware/software ecc or not */
/* RETURN VALUES */
/* This function returns EAG_NO_ERR when it does successfully. */
/* If previous write error occurs, this function returns EAG_WRITE_ERR. */
/* If ECC error occured, ECC related error is returned */
/* */
/*****************************************************************************/
uint32_t
nfc_read_page(uint16_t iBlockNum, uint16_t iPageNum, uint32_t* pMBuf, uint32_t* pSBuf, uint8_t bEcc)
{
if (bEcc == ECC_READ)
return(nfc_read(iBlockNum, iPageNum, (uint32_t*)pMBuf, (uint32_t*)pSBuf, NFC_CMD_RD_PB_ECC));
else
return(nfc_read(iBlockNum, iPageNum, (uint32_t*)pMBuf, (uint32_t*)pSBuf, NFC_CMD_RD_PB_NOECC));
}
/*****************************************************************************/
/* NFC WRITE */
/*****************************************************************************/
/*****************************************************************************/
/* */
/* NAME */
/* nfc_write */
/* DESCRIPTION */
/* This function writes into NAND */
/* PARAMETERS */
/* iBlockNum wanted block number of the NAND Flash to write */
/* iPageNum wanted page number of the upper blk_num block */
/* of the NAND Flash to write */
/* pMBuf unsigned char type pointer of main area sized */
/* buffer to write */
/* pSBuf unsigned char type pointer of spare area sized */
/* buffer to write */
/* iCmdType command type */
/* RETURN VALUES */
/* This function returns NFC_NO_ERR when it does successfully. */
/* If previous write error occurs, this function returns NFC_WRITE_ERR. */
/* Because of interleaving write method, this function doen't check */
/* comletion of current write operation */
/* */
/*****************************************************************************/
uint32_t
nfc_write(uint16_t iBlockNum, uint16_t iPageNum,
uint32_t* pMBuf, uint32_t* pSBuf, uint16_t iCmdType)
{
if((pMBuf == (uint32_t*)0) && (pSBuf == (uint32_t*)0))
return NFC_ILLEGAL_ACCESS;
if(!nfc_status_ready())
return NFC_WRITE_ERR;
nfc_RAM_buffer_select(0);
if (pMBuf != (uint32_t*)0) {
MemoryCopy((void*)pMBuf, (void*)NFC_MAB0_BASE, NAND_PAGE_SIZE);
if (pSBuf == (uint32_t*)0)
MemorySet((void*)NFC_SAB0_BASE, 0xFF, NAND_PAGE_SIZE/32);
else
MemoryCopy((void*)pSBuf, (void*)NFC_SAB0_BASE, NAND_PAGE_SIZE/32);
}
else {
MemoryCopy((void*)pSBuf, (void*)NFC_SAB0_BASE, NAND_PAGE_SIZE/32);
}
switch(iCmdType) {
case NFC_CMD_WR_PB_ECC:
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_READ|NFC_CONFIG1_ECC_EN;
nfc_command_input(NAND_CMD_PAGE_PROG);
nfc_address_cycle(iBlockNum, iPageNum);
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_WRITE|NFC_CONFIG1_ECC_EN;
nfc_flash_data_input();
nfc_command_input(NAND_CMD_PAGE_PROG_CONFIRM);
break;
case NFC_CMD_WR_PB_NOECC:
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_READ;
nfc_command_input(NAND_CMD_PAGE_PROG);
nfc_address_cycle(iBlockNum, iPageNum);
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_WRITE;
nfc_flash_data_input();
nfc_command_input(NAND_CMD_PAGE_PROG_CONFIRM);
break;
case NFC_CMD_WR_SB_ECC:
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_READ|NFC_CONFIG1_SP_ONLY|NFC_CONFIG1_ECC_EN;
nfc_command_input(NAND_CMD_PAGE_PROG);
nfc_address_cycle(iBlockNum, iPageNum);
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_WRITE|NFC_CONFIG1_SP_ONLY|NFC_CONFIG1_ECC_EN;
nfc_flash_data_input();
nfc_command_input(NAND_CMD_PAGE_PROG_CONFIRM);
break;
case NFC_CMD_WR_SB_NOECC:
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_READ|NFC_CONFIG1_SP_ONLY;
nfc_command_input(NAND_CMD_PAGE_PROG);
nfc_address_cycle(iBlockNum, iPageNum);
*(volatile p_uint16_t)NFC_NF_CONFIG1 = NFC_CONFIG1_WRITE|NFC_CONFIG1_SP_ONLY;
nfc_flash_data_input();
nfc_command_input(NAND_CMD_PAGE_PROG_CONFIRM);
break;
default:
return NFC_ILLEGAL_ACCESS;
}
return NFC_NO_ERR;
}
/*****************************************************************************/
/* */
/* NAME */
/* nfc_write_spare (interface function) */
/* DESCRIPTION */
/* This function writes into NAND page area (16Bytes size) */
/* PARAMETERS */
/* iBlockNum wanted block number of the NAND Flash to write */
/* iPageNum wanted page number of the upper blk_num block */
/* of the NAND Flash to write */
/* pSBuf unsigned char type pointer of spare area sized */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -