📄 nf_drv.c
字号:
((Byte*)&gl_cpt_page)[0]++;
if ( ((Byte*)&gl_cpt_page)[0] == 0x08) /* end of sector */
{
gl_cpt_page = 0;
gl_ptr_mem++;
if (nf_parity_bit == NF_ODD)
{
((Byte*)&nf_current_physical_sector_addr_odd)[3]++;
((Byte*)&gl_address)[3]++;
}
else
{
((Byte*)&nf_current_physical_sector_addr_even)[3]++;
((Byte*)&address2)[3]++;
}
nf_parity_bit = ~nf_parity_bit;
}
}
if (((Byte*)&gl_ptr_mem)[3] & 0x7F)
{
for (j = (((Byte*)&gl_ptr_mem)[3] & 0x7F); j < 0x80; j++)
{
if (nf_parity_bit == NF_ODD)
{
Nf_active_ODD();
Nf_wait_busy_odd();
Nf_send_command_odd (NF_READ_CMD);
Nf_send_address_odd (0x00);
Nf_send_address_odd (0x00);
Nf_send_address_odd ( ((Byte*)&gl_address)[3] ); /* Row address Byte 0 */
Nf_send_address_odd ( ((Byte*)&gl_address)[2] ); /* Row address Byte 1 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
Nf_send_address_odd ( ((Byte*)&gl_address)[1] ); /* Row address Byte 2 */
Nf_send_command_odd (NF_COPY_BACK_CMD);
Nf_wait_busy_odd();
Nf_send_command_odd (NF_RANDOM_DATA_INPUT_CMD);
Nf_send_address_odd (0x00);
Nf_send_address_odd (0x00);
Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[3] ); /* Row address Byte 0 */
Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[2] ); /* Row address Byte 1 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[1] ); /* Row address Byte 2 */
Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
((Byte*)&nf_current_physical_sector_addr_odd)[3]++;
((Byte*)&gl_address)[3]++;
}
else
{
Nf_active_EVEN();
Nf_wait_busy_even();
Nf_send_command_even (NF_READ_CMD);
Nf_send_address_even (0x00);
Nf_send_address_even (0x00);
Nf_send_address_even ( ((Byte*)&address2)[3] ); /* Row address Byte 0 */
Nf_send_address_even ( ((Byte*)&address2)[2] ); /* Row address Byte 1 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&address2)[1] ); /* Row address Byte 2 */
Nf_send_command_even (NF_COPY_BACK_CMD);
Nf_wait_busy_even();
Nf_send_command_even (NF_RANDOM_DATA_INPUT_CMD);
Nf_send_address_even (0x00);
Nf_send_address_even (0x00);
Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[3] ); /* Row address Byte 0 */
Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[2] ); /* Row address Byte 1 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[1] ); /* Row address Byte 2 */
Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
((Byte*)&nf_current_physical_sector_addr_even)[3]++;
((Byte*)&address2)[3]++;
}
nf_parity_bit = ~nf_parity_bit;
}
}
}
/*F**************************************************************************
* NAME: nf_reassign_block
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Reassign the block value in LUT (copy of LUT)
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
void nf_reassign_block (void)
{
Byte i; /* Counter */
Uint16 start;
Uint32 address2; /* LUT source address */
if (nf_lut_index[nf_zone] == 31)
{
if ((nf_buf_free[gl_buf_free_idx].even & 0x7FFF) == nf_look_up_table_block)
{
gl_buf_free_idx++;
if (gl_buf_free_idx >= nf_spare_block)
{
gl_buf_free_idx = 0;
}
}
/* Source address */
address2 = ((Uint32)(nf_look_up_table_block)<<NF_SHIFT_SECTOR_BLOCK) + 62;
nf_look_up_table_block = nf_buf_free[gl_buf_free_idx].even & 0x7FFF;
gl_buf_free_idx++;
if (gl_buf_free_idx >= nf_spare_block)
{
gl_buf_free_idx = 0;
}
/* Target addres */
gl_address = ((Uint32)(nf_look_up_table_block) << NF_SHIFT_SECTOR_BLOCK);
nf_lut_index[nf_zone] = 0;
}
else
{
/* Source address */
address2 = ((Uint32)(nf_look_up_table_block) << NF_SHIFT_SECTOR_BLOCK) +
((Uint32)(nf_lut_index[nf_zone]) << 1);
nf_lut_index[nf_zone]++;
gl_address = address2 + 2; /* Target address */
}
Nf_active_EVEN();
Nf_wait_busy_even();
Nf_send_command_even (NF_READ_CMD);
Nf_send_address_even (0x00);
Nf_send_address_even (0x00);
Nf_send_address_even (((Byte*)&address2)[3]);
Nf_send_address_even (((Byte*)&address2)[2]);
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of NF >= 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&address2)[1] ); /* Row address Byte 2 */
Nf_send_command_even (NF_COPY_BACK_CMD);
if (nf_block_min < 512)
{
start = nf_block_min << 2;
}
else
{
start = 0;
}
Nf_wait_busy_even();
Nf_send_command_even (NF_RANDOM_DATA_INPUT_CMD);
Nf_send_address_even (((Byte*)&start)[1]); /* Column address Byte 0 */
Nf_send_address_even (((Byte*)&start)[0]); /* Column address Byte 1 */
Nf_send_address_even ( ((Byte*)&gl_address)[3] ); /* Row address Byte 0 */
Nf_send_address_even ( ((Byte*)&gl_address)[2] ); /* Row address Byte 1 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&gl_address)[1] ); /* Row address Byte 2 */
if (nf_block_min < 512)
{
for (i = 0; (i <= nf_gl_buf_idx_max) && ((Uint16)(i) < (Uint16)((2048 - start) / 4)); i++)
{
Nf_wr_byte_even (nf_buf[i].even.b[0]);
Nf_wr_byte_even (nf_buf[i].even.b[1]);
Nf_wr_byte_even (nf_buf[i].odd.b[0]);
Nf_wr_byte_even (nf_buf[i].odd.b[1]);
}
}
Nf_send_command_even (NF_RANDOM_DATA_INPUT_CMD); /* Spare block */
Nf_send_address_even(0x00); /* logical block > 1000 */
Nf_send_address_even(0x08);
Nf_wr_byte_even(0xFF); Nf_wr_byte_even(0xFF); Nf_wr_byte_even(0xFF); Nf_wr_byte_even(0xFF); /* Spare area */
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_send_command_even(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
((Byte*)&address2)[3]++;
((Byte*)&gl_address)[3]++;
Nf_wait_busy_even();
Nf_send_command_even (NF_READ_CMD);
Nf_send_address_even (0x00);
Nf_send_address_even (0x00);
Nf_send_address_even (((Byte*)&address2)[3]);
Nf_send_address_even (((Byte*)&address2)[2]);
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of card >= 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&address2)[1] ); /* Row address Byte 2 */
Nf_send_command_even (NF_COPY_BACK_CMD);
if (((Uint16)(nf_block_min) + i) >= 512)
start = (nf_block_min + i - 512) << 2;
else
start = 0;
Nf_wait_busy_even();
Nf_send_command_even (NF_RANDOM_DATA_INPUT_CMD);
Nf_send_address_even (((Byte*)&start)[1]); /* Column address Byte 0 */
Nf_send_address_even (((Byte*)&start)[0]); /* Column address Byte 1 */
Nf_send_address_even ( ((Byte*)&gl_address)[3] ); /* Row address Byte 0 */
Nf_send_address_even ( ((Byte*)&gl_address)[2] ); /* Row address Byte 1 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of nf >= 128Mb? */
Nf_send_address_even ( ((Byte*)&gl_address)[1] ); /* Row address Byte 2 */
for (; i <= nf_gl_buf_idx_max; i++)
{
Nf_wr_byte_even (nf_buf[i].even.b[0]);
Nf_wr_byte_even (nf_buf[i].even.b[1]);
Nf_wr_byte_even (nf_buf[i].odd.b[0]);
Nf_wr_byte_even (nf_buf[i].odd.b[1]);
}
Nf_send_command_even (NF_RANDOM_DATA_INPUT_CMD); /* Spare block */
Nf_send_address_even(0xA0); /* logical block > 1000 */
Nf_send_address_even(0x07);
for (i = 0; i <= 23; i++)
{
Nf_wr_byte_even (nf_buf_free[i].even>>8);
Nf_wr_byte_even (nf_buf_free[i].even);
Nf_wr_byte_even (nf_buf_free[i].odd>>8);
Nf_wr_byte_even (nf_buf_free[i].odd);
}
/* write spare area */
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(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_send_command_even(NF_PAGE_PROGRAM_CMD); /* Valid the page programmation */
nf_gl_buf_idx_max = 0;
if (nf_lut_index[nf_zone] == 0) /* Erase old lut */
{
address2 = (Uint32)(nf_lut_block[nf_zone])<<NF_SHIFT_SECTOR_BLOCK;
nf_lut_block[nf_zone] = nf_look_up_table_block; /* Update address of look up table */
Nf_wait_busy_even();
Nf_send_command_even (NF_BLOCK_ERASE_CMD); /* Auto Block Erase Setup */
Nf_send_address_even ( ((Byte*)&address2)[3] ); /* Row address Byte 1 */
Nf_send_address_even ( ((Byte*)&address2)[2] ); /* Row address Byte 2 */
if (NF_5_CYCLE_ADDRESS_BIT) /* Size of nf >= 128Mbytes? */
Nf_send_address_even ( ((Byte*)&address2)[1] ); /* Row address Byte 3 */
Nf_send_command_even(NF_BLOCK_ERASE_CONFIRM_CMD); /* Erase command */
}
Nf_wait_busy_even();
}
/*F**************************************************************************
* NAME: nf_mark_bad_block
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Write 0x00 on block status byte (Byte 5 of spare data)
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This function use the global variable Uint32 address
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
void nf_mark_bad_block (void)
{
if (nf_parity_bit == NF_ODD)
{
Nf_wait_busy_odd();
Nf_write_open_spare_area_odd(gl_address, 0x03);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -