📄 nf_drv.c
字号:
Nf_send_address (0x00);
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[1] );/* 4th address cycle */
nf_download_buffer();
/* Update spare data */
nf_update_spare_data();
Nf_send_command (NF_PAGE_PROGRAM_CMD);
/* increase counter */
current_physical_sector_addr++;
address++;
}
Nf_wait_busy();
}
/*F**************************************************************************
* NAME: nf_copy_block_tail
*----------------------------------------------------------------------------
* PARAMS: block : physical block number
*
* RETURN:
*
*----------------------------------------------------------------------------
* PURPOSE: This function copy the last part of a block that is not modified
* during a write operation
*
*****************************************************************************
* NOTE: Uint32 address is global
*
*
*****************************************************************************/
void nf_copy_block_tail(void)
{
Byte j;
current_physical_sector_addr++;
/* Address of the source block */
address = ((Uint32)(block_to_be_deleted) << 5) + (gl_ptr_mem & 0x1F);
for (j = (gl_ptr_mem & 0x1F); j < 0x20; j++)
{
Nf_wait_busy();
/* 1st half page */
/* Read Open */
Nf_send_command (NF_READ_A_AREA_CMD);
Nf_send_address (0x00);
Nf_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
Nf_wait_busy();
nf_upload_buffer();
/* Write open */
Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);
Nf_send_address (0x00);
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[1] );/* 4th address cycle */
nf_download_buffer();
Nf_send_command (NF_PAGE_PROGRAM_CMD);
Nf_wait_busy();
/* 2nd half page */
/* Read Open */
Nf_send_command (NF_READ_B_AREA_CMD);
Nf_send_address (0x00);
Nf_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
Nf_wait_busy();
nf_upload_buffer();
/* Write open */
Nf_send_command (NF_READ_B_AREA_CMD);
Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);
Nf_send_address (0x00);
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)¤t_physical_sector_addr)[1] );/* 4th address cycle */
nf_download_buffer();
/* Update spare data */
nf_update_spare_data();
Nf_send_command (NF_PAGE_PROGRAM_CMD);
current_physical_sector_addr++;
address++;
}
Nf_wait_busy();
}
/*F**************************************************************************
* NAME: nf_reassign_block
*----------------------------------------------------------------------------
* PARAMS: block : reassign the physical block
*
* RETURN:
*
*----------------------------------------------------------------------------
* PURPOSE: This function reassign the block value in LUT (copy of LUT)
*
*
*****************************************************************************
* NOTE:
*
*
*****************************************************************************/
void nf_reassign_block(void)
{
idata Uint16 start;
idata Uint16 block_start;
data Uint32 address2; /* LUT Source address */
char pdata *ptr = gl_buffer; /* gl_buffer pointer */
Byte dummy;
Byte j, k;
if (lut_index[nf_zone] == 7)
{
if ((buf_free[gl_buf_free_idx] & 0x7FFF) == look_up_table_block)
{
gl_buf_free_idx++;
if (gl_buf_free_idx >= spare_block /*(nf_spare_block_number[nf_zone]>>1)*/ )
{
gl_buf_free_idx = 0;
}
}
/* Source address */
address2 = ((Uint32)(look_up_table_block)<<5) + 28;
look_up_table_block = buf_free[gl_buf_free_idx] & 0x7FFF;
gl_buf_free_idx++;
if (gl_buf_free_idx >= spare_block /*(nf_spare_block_number[nf_zone]>>1)*/ )
{
gl_buf_free_idx = 0;
}
/* Target address : recopy the last 2Kb */
address = ((Uint32)(look_up_table_block) << 5);
lut_index[nf_zone] = 0;
}
else
{
/* Source address */
address2 = ((Uint32)(look_up_table_block)<<5) + ((Uint32)(lut_index[nf_zone])<<2);
lut_index[nf_zone]++;
/* Target address */
//address = (Uint32)(look_up_table_block) << 5 + (Uint32)(lut_index[nf_zone]<<2);
address = address2 + 4;
}
j = 0;
k = 0;
start = 0;
block_start = block_min;
do
{
Nf_wait_busy();
/* Open look-up table in read mode */
Nf_send_command(NF_READ_A_AREA_CMD); /* First half array */
Nf_send_address( 0x00);
Nf_send_address ( ((Byte*)&address2)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)&address2)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS ) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)&address2)[1] );/* 4th address cycle */
Nf_wait_busy();
nf_upload_buffer();
while ((k <= gl_buf_idx_max) && (start <= block_start) && ((start + 128) > block_start))
{
gl_buffer[(2 * (block_start & 0x7F))] = buf[k].b[0];
gl_buffer[(2 * (block_start & 0x7F))+1] = buf[k].b[1];
k++;
block_start++;
}
Nf_send_command(NF_READ_A_AREA_CMD); /* First half array */
Nf_send_command(NF_SEQUENTIAL_DATA_INPUT_CMD);
Nf_send_address(0x00);
Nf_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
/* Write 256 bytes from the buffer */
nf_download_buffer();
/* Valid the page programmation */
Nf_send_command(NF_PAGE_PROGRAM_CMD);
start += 128;
/* Wait for R/B signal */
Nf_wait_busy();
/* Open look-up tableread in mode */
Nf_send_command(NF_READ_B_AREA_CMD); /* Second half array */
Nf_send_address(0x00);
Nf_send_address ( ((Byte*)&address2)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)&address2)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)&address2)[1] );/* 4th address cycle */
Nf_wait_busy();
nf_upload_buffer();
while ((k <= gl_buf_idx_max) && (start <= block_start) && ((start + 128) > block_start))
{
gl_buffer[(2 * (block_start & 0x7F))] = buf[k].b[0];
gl_buffer[(2 * (block_start & 0x7F))+1] = buf[k].b[1];
k++;
block_start++;
}
if (start >= 896) /* This part update the free physical block table */
{
dummy = 208;
for (j = 0; j <= 23; j++)
{
gl_buffer[dummy] = buf_free[j]>>8;
gl_buffer[dummy+1] = buf_free[j];
dummy += 2;
}
}
Nf_send_command(NF_READ_B_AREA_CMD); /* Second half array */
/* Send the write open command and addresses */
Nf_send_command(NF_SEQUENTIAL_DATA_INPUT_CMD);
Nf_send_address(0x00);
Nf_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)&address)[1] );/* 4th address cycle */
/* Write 256 bytes from the buffer */
nf_download_buffer();
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xE8);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xE8);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
/* Valid the page programmation */
Nf_send_command(NF_PAGE_PROGRAM_CMD);
start += 128;
address2++;
address++;
}
while (start < 1024);
gl_buf_idx_max = 0;
if (lut_index[nf_zone] == 0)
{
address2 = (Uint32)(lut_block[nf_zone])<<5;
/* Update address of look up table */
Nf_wait_busy();
Nf_send_command (NF_READ_A_AREA_CMD);
Nf_send_command (NF_BLOCK_ERASE_CMD); /* Auto Block Erase Setup */
Nf_send_address ( ((Byte*)&address2)[3] ); /* 2nd address cycle*/
Nf_send_address ( ((Byte*)&address2)[2] ); /* 3rd address cycle*/
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)&address2)[1] ); /* 4th address cycle*/
Nf_send_command(NF_BLOCK_ERASE_CONFIRM_CMD); /* Erase command */
lut_block[nf_zone] = look_up_table_block;
}
Nf_wait_busy();
}
/*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)
{
Nf_wait_busy();
Nf_send_command (NF_READ_C_AREA_CMD);
Nf_send_command (NF_SEQUENTIAL_DATA_INPUT_CMD);
Nf_send_address (0x00);
Nf_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Nf_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS) /* Size of card >= 64Mbytes ?*/
Nf_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0x00);
Nf_wr_byte(0x00);
Nf_wr_byte(0x00);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
Nf_wr_byte(0xFF);
/* Send program command */
Nf_send_command (NF_PAGE_PROGRAM_CMD);
Nf_wait_busy();
}
/*F**************************************************************************
* NAME: nf_block_erase
*----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -