?? nf_drv.c
字號:
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 nf >= 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[1] ); /* Row address Byte 2 */
Nf_send_command_even(NF_RANDOM_DATA_INPUT_CMD);
Nf_send_address_even(0x10);
Nf_send_address_even(0x08);
Nf_wr_byte_even(0xEF);/* set internal page counter to 2048 */
Nf_wr_byte_even(0xFF);/* reset delete block marker */
Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
((Byte*)&nf_current_physical_sector_addr_even)[3]++; /* increase addresses */
((Byte*)&address2)[3]++;
}
nf_parity_bit = ~nf_parity_bit;
}
if (gl_cpt_page != 0)
{
nf_init_buffer();
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 ( ((Byte*)&gl_cpt_page)[1] );
Nf_send_address_odd ( ((Byte*)&gl_cpt_page)[0] );
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 */
}
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 ( ((Byte*)&gl_cpt_page)[1] );
Nf_send_address_even ( ((Byte*)&gl_cpt_page)[0] );
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 nf >= 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[1] ); /* row address Byte 2 */
}
for (j = (gl_cpt_page / 512); j < 4; j++)
{
nf_download_buffer();
nf_download_buffer();
}
if (nf_parity_bit == NF_ODD)
{
Nf_send_command_odd(NF_RANDOM_DATA_INPUT_CMD);/* reset internal page counter */
Nf_send_address_odd(0x10);
Nf_send_address_odd(0x08);
Nf_wr_byte_odd(0xFF);
Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
}
else
{
Nf_send_command_even(NF_RANDOM_DATA_INPUT_CMD); /* reset internal page counter */
Nf_send_address_even(0x10);
Nf_send_address_even(0x08);
Nf_wr_byte_even(0xFF);
Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
}
}
}
/*F**************************************************************************
* NAME: nf_copy_block_tail
*----------------------------------------------------------------------------
* PARAMS:
* even_only bit : if TRUE, only even nf block will be copied
* if FALSE, even and odd block will be copied
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Copy the last part of a block that is not modifiedd uring a write
* operation
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* this function modify :
* gl_address
* gl_ptr_mem
* gl_cpt_page
* nf_current_physical_sector_addr_odd
* nf_current_physical_sector_addr_even
* gl_buffer (reset to 0xFF)
* nf_redundant_logical_block_value must be up to date
*----------------------------------------------------------------------------
* REQUIREMENTS:
*
*****************************************************************************/
void nf_copy_block_tail (bit even_only)
{
Uint32 address2;
Byte j;
/* Address of the source block */
gl_address = ((Uint32)(nf_block_to_be_deleted_odd) << NF_SHIFT_SECTOR_BLOCK) + (((Byte*)&nf_current_physical_sector_addr_odd)[3] & 0x3F);
address2 = ((Uint32)(nf_block_to_be_deleted_even) << NF_SHIFT_SECTOR_BLOCK) + (((Byte*)&nf_current_physical_sector_addr_even)[3] & 0x3F);
nf_parity_bit = ((Byte*)&gl_ptr_mem)[3] & 0x01;
if (gl_cpt_page != 0)
{
nf_init_buffer();
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 nf > 128Mbytes ? */
Nf_send_address_odd ( ((Byte*)&gl_address)[1] ); /* row address Byte 2 */
Nf_send_command_odd (NF_COPY_BACK_CMD); /* send copy back command */
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 nf > 128Mbytes ? */
Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[1] );/* row address Byte 2 */
for (j = ((Byte*)&gl_cpt_page)[0] >> 1; j != 0; j--)
{
nf_download_buffer();
nf_download_buffer();
}
Nf_send_command_odd (NF_RANDOM_DATA_INPUT_CMD); /* spare area */
((Byte*)&gl_cpt_page)[0] = 0x08;
Nf_send_address_odd(0x00);
Nf_send_address_odd(0x08);
nf_update_spare_data(); /* update spare data */
Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
}
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 nf > 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&address2)[1] ); /* row address Byte 2 */
Nf_send_command_even (NF_COPY_BACK_CMD); /* send copy back command */
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 nf > 128Mbytes ? */
Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[1] ); /* row address Byte 2 */
for (j = ((Byte*)&gl_cpt_page)[0] >> 1; j != 0; j--)
{
nf_download_buffer();
nf_download_buffer();
}
Nf_send_command_even (NF_RANDOM_DATA_INPUT_CMD); /* spare area */
((Byte*)&gl_cpt_page)[0] = 0x08;
Nf_send_address_even(0x00);
Nf_send_address_even(0x08);
nf_update_spare_data(); /* update spare data */
Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
}
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)
{
if (even_only == FALSE)
{
Nf_active_ODD();
Nf_wait_busy_odd();
Nf_send_command_odd (NF_READ_CMD);
Nf_send_address_odd (0x00); /* start at column 0 */
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 nf > 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 nf > 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 nf > 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]);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -