📄 nf_drv.c
字号:
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
Nf_send_command_odd (NF_PAGE_PROGRAM_CMD); /* Send program command */
}
else
{
Nf_wait_busy_even();
Nf_write_open_spare_area_even(gl_address, 0x03);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_send_command_even (NF_PAGE_PROGRAM_CMD); /* Send program command */
}
}
/*F**************************************************************************
* NAME: nf_block_erase
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* OK : erase done
* KO : erase not done
*----------------------------------------------------------------------------
* PURPOSE: Erase a block on Nand Flash Media
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This function use the global variable Uint32 address
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
bit nf_block_erase (Uint32 pos)
{
if (nf_parity_bit == NF_ODD)
{
Nf_active_ODD();
Nf_wait_busy_odd();
Nf_send_command_odd (NF_BLOCK_ERASE_CMD); /* Auto Block Erase Setup */
Nf_send_address_odd ( ((Byte*)&pos)[3] ); /* Row address Byte 0 */
Nf_send_address_odd ( ((Byte*)&pos)[2] ); /* Row address Byte 1 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
Nf_send_address_odd ( ((Byte*)&pos)[1] ); /* Row address Byte 2 */
Nf_send_command_odd(NF_BLOCK_ERASE_CONFIRM_CMD);/* Erase command */
}
else
{
Nf_active_EVEN();
Nf_wait_busy_even();
Nf_send_command_even (NF_BLOCK_ERASE_CMD); /* Auto Block Erase Setup */
Nf_send_address_even ( ((Byte*)&pos)[3] ); /* Row address Byte 0 */
Nf_send_address_even ( ((Byte*)&pos)[2] ); /* Row address Byte 1 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&pos)[1] ); /* Row address Byte 2 */
Nf_send_command_even(NF_BLOCK_ERASE_CONFIRM_CMD);/* Erase command */
}
return OK;
}
/*F**************************************************************************
* NAME: nf_erase_all_block
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* OK : erase done
* KO : erase not done
*----------------------------------------------------------------------------
* PURPOSE:
* This function erase all blocks on a NF card and write CIS information
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This function use the global variable Uint32 address
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
bit nf_erase_all_block (void)
{
bit bad_block_detect;
Byte i;
Byte step_even, step_odd;
for (gl_address = 0; gl_address < (Uint32)(NF_ZONE_MAX_CPT) * NF_BLOCK_PER_ZONE * NF_PAGE_PER_BLOCK; gl_address+=NF_PAGE_PER_BLOCK)
{
/* read block status byte */
step_even = 0; step_odd = 0;
Nf_CS_EVEN();
Nf_wait_busy_even();
Nf_read_open_spare_area_even(gl_address, 0x05);
if ( 1 || (Nf_rd_byte_even() == 0xFF)) /* if block even valid */
{
nf_block_erase(gl_address); /* erase even block */
step_even = 1; /* next even step */
}
Nf_CS_ODD();
Nf_wait_busy_odd();
Nf_read_open_spare_area_odd(gl_address, 0x05);
if (1 || (Nf_rd_byte_odd() == 0xFF)) /* if block odd valid */
{
nf_block_erase(gl_address); /* erase odd block */
step_odd = 1; /* next odd step */
}
/* check status after erase for even and odd block */
if (step_even == 1)
{
Nf_CS_EVEN();
if ( nf_check_status() == KO) /* if even block erase is ko */
{
nf_mark_bad_block(); /* then mark even block as invalid */
}
else
{
step_even = 2; /* else next even step */
}
}
if (step_odd == 1)
{
Nf_CS_ODD();
if ( nf_check_status() == KO) /* if odd block erase is ko */
{
nf_mark_bad_block(); /* then mark odd block as invalid */
}
else
{
step_odd = 2; /* else next odd step */
}
}
/* write spare data in first sector of each block for even and odd */
if (step_even == 2)
{
Nf_active_EVEN();
Nf_wait_busy_even(); /* Fill redundant area with 0x00 */
Nf_write_open_even(gl_address);
Nf_write_open_spare_area_even(gl_address, 0x00);
for (i = 64; i != 0; i--)
Nf_wr_byte_even (0x00);
Nf_send_command_even(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
}
if (step_odd == 2)
{
Nf_active_ODD();
Nf_wait_busy_odd(); /* Fill redundant area with 0x00 */
Nf_write_open_odd(gl_address);
Nf_write_open_spare_area_odd(gl_address, 0x00);
for (i = 64; i != 0; i--)
Nf_wr_byte_odd (0x00);
Nf_send_command_odd(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
}
/* check program status for even and odd */
if (step_even == 2)
{
Nf_CS_EVEN();
if ( nf_check_status() == KO) /* if even program status ko */
{
nf_mark_bad_block(); /* then even block is invalid */
}
else
{
step_even = 3; /* else next even step */
}
}
if (step_odd == 2)
{
Nf_CS_ODD();
if (nf_check_status() == KO) /* if odd program status ko */
{
nf_mark_bad_block(); /* then odd block is invalid */
}
else
{
step_odd = 3; /* else next odd step */
}
}
/* check if all spare data are correct for even and odd */
if (step_even == 3)
{
Nf_CS_EVEN(); /* send even read command */
Nf_send_command_even (NF_READ_CMD);
Nf_send_address_even ( 0x00 );
Nf_send_address_even ( NF_SPARE_PAGE );
Nf_send_address_even ( ((Byte*)&gl_address)[3] );
Nf_send_address_even ( ((Byte*)&gl_address)[2] );
if (NF_5_CYCLE_ADDRESS_BIT)
Nf_send_address_even ( ((Byte*)&gl_address)[1] );
Nf_send_command_even (NF_READ_CMD2);
bad_block_detect = FALSE;
Nf_wait_busy_even();
for (i = 64; i != 0; i--)
{
if (Nf_rd_byte_even() != 0x00)
{
bad_block_detect = TRUE;
}
}
if (bad_block_detect)
{
nf_mark_bad_block();
}
else
{
step_even = 4;
}
}
if (step_odd == 3)
{
Nf_CS_ODD(); /* send odd read command */
Nf_send_command_odd (NF_READ_CMD);
Nf_send_address_odd ( 0x00 );
Nf_send_address_odd ( NF_SPARE_PAGE );
Nf_send_address_odd ( ((Byte*)&gl_address)[3] );
Nf_send_address_odd ( ((Byte*)&gl_address)[2] );
if (NF_5_CYCLE_ADDRESS_BIT)
Nf_send_address_odd ( ((Byte*)&gl_address)[1] );
Nf_send_command_odd (NF_READ_CMD2);
bad_block_detect = FALSE;
Nf_wait_busy_odd();
for (i = 64; i != 0; i--)
{
if (Nf_rd_byte_odd() != 0x00)
{
bad_block_detect = TRUE;
}
}
if (bad_block_detect)
{
nf_mark_bad_block();
}
else
{
step_odd = 4;
}
}
if (step_even == 4)
{
Nf_CS_EVEN();
nf_block_erase(gl_address); /* Finally, erase the block */
}
if (step_odd == 4)
{
Nf_CS_ODD();
nf_block_erase(gl_address); /* Finally, erase the block */
}
if (step_even == 4)
{
Nf_CS_EVEN();
if ( nf_check_status() == KO)
{
nf_mark_bad_block();
}
}
if (step_odd == 4)
{
Nf_CS_ODD();
if ( nf_check_status() == KO)
{
nf_mark_bad_block();
}
}
}
return (read_spare_byte());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -