📄 nf_drv.c
字号:
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xE8);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xE8);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
/* Valid the page programmation */
Nf_send_command_even(NF_PAGE_PROGRAM_CMD);
start += 64;
((Byte*)&address2)[3]++;
((Byte*)&gl_address)[3]++;
}
while (start < NF_BLOCK_PER_ZONE);
nf_gl_buf_idx_max = 0;
if (lut_index[nf_zone] == 0)
{
address2 = (Uint32)(lut_block[nf_zone])<<5;
Nf_CS_EVEN();
nf_block_erase(address2);
lut_block[nf_zone] = nf_look_up_table_block;
}
}
/*F**************************************************************************
* NAME: nf_mark_bad_block
*----------------------------------------------------------------------------
* PARAMS:
*
*
* RETURN:
*
*
*----------------------------------------------------------------------------
* PURPOSE: Write 0x00 on block status byte (Byte 5 of spare data)
*
*
*****************************************************************************
* NOTE: This function use the global variable Uint32 address
*
*
*
*
*****************************************************************************/
void nf_mark_bad_block(void)
{
if (nf_parity_bit == NF_ODD)
{
Nf_wait_busy_odd();
Nf_write_open_C_area_odd(gl_address, 0x00);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_send_command_odd (NF_PAGE_PROGRAM_CMD); /* Send program command */
}
else
{
Nf_wait_busy_even();
Nf_write_open_C_area_even(gl_address, 0x00);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
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
*
*
*****************************************************************************
* NOTE:
*
*
*
*
*****************************************************************************/
bit nf_block_erase (Uint32 pos)
{
if (nf_parity_bit == NF_ODD)
{
Nf_wait_busy_odd();
Nf_send_command_odd (NF_READ_A_AREA_CMD);
Nf_send_command_odd (NF_BLOCK_ERASE_CMD); /* Auto Block Erase Setup */
Nf_send_address_odd ( ((Byte*)&pos)[3] ); /* 2nd address cycle */
Nf_send_address_odd ( ((Byte*)&pos)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS_BIT) /* Size of card >= 64Mbytes ? */
Nf_send_address_odd ( ((Byte*)&pos)[1] ); /* 4th address cycle */
Nf_send_command_odd(NF_BLOCK_ERASE_CONFIRM_CMD);/* Erase command */
}
else
{
Nf_wait_busy_even();
Nf_send_command_even (NF_READ_A_AREA_CMD);
Nf_send_command_even (NF_BLOCK_ERASE_CMD); /* Auto Block Erase Setup */
Nf_send_address_even ( ((Byte*)&pos)[3] ); /* 2nd address cycle */
Nf_send_address_even ( ((Byte*)&pos)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS_BIT) /* Size of card >= 64Mbytes ? */
Nf_send_address_even ( ((Byte*)&pos)[1] ); /* 4th address cycle */
Nf_send_command_even (NF_BLOCK_ERASE_CONFIRM_CMD);/* Erase command */
}
return OK;
}
/*F**************************************************************************
* NAME: nf_erase_all_block
*----------------------------------------------------------------------------
* PARAMS:
*
*
* RETURN:
*
*----------------------------------------------------------------------------
* PURPOSE: This function erase all blocks on a NF card and write CIS
* information
*
*
*****************************************************************************
* NOTE:
*
*****************************************************************************/
bit nf_erase_all_block(void)
{
bit bad_block_detect;
Byte i;
/* Erase all block */
for (gl_address = (Uint32)(NF_ZONE_MAX_CPT) * NF_BLOCK_PER_ZONE * NF_PAGE_PER_BLOCK - NF_PAGE_PER_BLOCK; gl_address != 0; gl_address-=NF_PAGE_PER_BLOCK)
{
/* Even part */
/* Read block status byte */
Nf_CS_EVEN();
Nf_wait_busy_even();
Nf_read_open_C_area_even(gl_address, 0x05);
if (Nf_rd_byte_even() == 0xFF) /* Not a bad block */
{
nf_block_erase(gl_address);
if ( nf_check_status() == KO)
{ /* Failure on erase operation */
nf_mark_bad_block();
}
else
{ /* Fill redundant area with 0x00 */
Nf_wait_busy_even();
Nf_write_open_C_area_even(gl_address, 0x00);
for (i = NF_SPARE_SIZE / 4; i != 0; i--)
{
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
}
Nf_send_command_even(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
if ( nf_check_status() == KO)
{ /* Failure on program operation */
nf_mark_bad_block();
}
bad_block_detect = FALSE;
Nf_wait_busy_even();
Nf_read_open_C_area_even(gl_address, 0x00); /* Read 16 bytes */
for (i = NF_SPARE_SIZE; i != 0; i--)
{
if (Nf_rd_byte_even() != 0x00) bad_block_detect = TRUE;
}
if (bad_block_detect)
{
nf_mark_bad_block();
}
else
{
/* Finally, erase the block */
nf_block_erase(gl_address);
if ( nf_check_status() == KO)
{ /* Failure on erase operation */
nf_mark_bad_block();
}
}
}
}
/* Odd part */
/* Read block status byte */
Nf_CS_ODD();
Nf_wait_busy_odd();
Nf_read_open_C_area_odd(gl_address, 0x05);
if (Nf_rd_byte_odd() == 0xFF) /* Not a bad block */
{
nf_block_erase(gl_address);
if ( nf_check_status() == KO)
{ /* Failure on erase operation */
nf_mark_bad_block();
}
else
{ /* Fill redundant area with 0x00 */
Nf_wait_busy_odd();
Nf_write_open_C_area_odd(gl_address, 0x00);
for (i = NF_SPARE_SIZE / 4; i != 0; i--)
{
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
}
Nf_send_command_odd(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
if ( nf_check_status() == KO)
{ /* Failure on program operation */
nf_mark_bad_block();
}
bad_block_detect = FALSE;
Nf_wait_busy_odd();
Nf_read_open_C_area_odd(gl_address, 0x00); /* Read 16 bytes */
for (i = NF_SPARE_SIZE; i != 0; i--)
{
if (Nf_rd_byte_odd() != 0x00) bad_block_detect = TRUE;
}
if (bad_block_detect)
{
nf_mark_bad_block();
}
else
{
/* Finally, erase the block */
nf_block_erase(gl_address);
if ( nf_check_status() == KO)
{ /* Failure on erase operation */
nf_mark_bad_block();
}
}
}
}
}
/* Reserve the First blocks*/
Nf_CS_EVEN();
gl_address = 0x00;
Nf_wait_busy_even();
Nf_write_open_C_area_even(gl_address, 0x00); /* Open in write mode at the address 0x00 */
/* Write spare data */
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0x00);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_wr_byte_even(0xFF);
Nf_send_command_even(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
Nf_CS_ODD();
Nf_write_open_C_area_odd(gl_address, 0x00); /* Open in write mode at the address 0x00 */
/* Write spare data */
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0x00);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_wr_byte_odd(0xFF);
Nf_send_command_odd(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
Nf_wait_busy_odd();
read_spare_byte();
return OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -