?? nf.c
字號:
*----------------------------------------------------------------------------
* PARAMS:
* pos: address of the logic sector to read (size 512 bytes)
*
* return:
* Update memory for reading
*----------------------------------------------------------------------------
* PURPOSE:
* Low level memory read update
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit nf_read_open (Uint32 pos)
{
Uint16 physical_block;
if (nf_lut_modified)
{
nf_reassign_block();
nf_lut_modified = FALSE;
}
gl_ptr_mem = pos;
gl_cpt_page = 0;
/* Determine the logical block value */
nf_logical_block = gl_ptr_mem >> 6; /* 64 pages by block */
nf_zone = 0;
while (nf_logical_block > 999)
{
nf_logical_block -= 1000;
nf_zone++;
}
/* Calculate the address where are the physical block value */
gl_address = (Uint32)(lut_block[nf_zone]) << 5; /* 32 * lut block */
gl_address += ((Uint32)(nf_logical_block) >> 7); /* logical block / 128 = page number of the lut */
gl_address += ((Uint32)(lut_index[nf_zone])<<3); /* lut index * 8 = offset for beginning of lut */
/* Open the look-up table */
Nf_CS_EVEN();
Nf_wait_busy_even();
if (nf_logical_block & 0x40) /* 64 logical blocks by part of lut page */
{
Nf_send_command_even(NF_READ_B_AREA_CMD); /* 2nd half page */
Nf_send_address_even( (nf_logical_block & 0x3F) << 2); /* 4Bytes for one logical block */
}
else
{
Nf_send_command_even(NF_READ_A_AREA_CMD); /* first half page */
Nf_send_address_even((nf_logical_block & 0x3F) << 2);
}
Nf_send_address_even ( ((Byte*)&gl_address)[3] ); /* 2nd address cycle */
Nf_send_address_even ( ((Byte*)&gl_address)[2] ); /* 3rd address cycle */
if (NF_4_CYCLE_ADDRESS_BIT) /* Size of card >= 64Mbytes ?*/
Nf_send_address_even ( ((Byte*)&gl_address)[1] ); /* 4th address cycle */
Nf_wait_busy_even();
/* Read the physical even block number */
((Byte*)&physical_block)[0] = Nf_rd_byte_even();
((Byte*)&physical_block)[1] = Nf_rd_byte_even();
/* Calculate the physical even sector address */
nf_current_physical_sector_addr_even = ((Uint32)(physical_block) << 5) + ((((Byte*)&gl_ptr_mem)[3] & 0x3F) >> 1) + (((Byte*)&gl_ptr_mem)[3] & 0x01);
/* Read the physical odd block number */
((Byte*)&physical_block)[0] = Nf_rd_byte_even();
((Byte*)&physical_block)[1] = Nf_rd_byte_even();
/* Calculate the physical odd sector address */
nf_current_physical_sector_addr_odd = ((Uint32)(physical_block) << 5) + ((((Byte*)&gl_ptr_mem)[3] & 0x3F) >> 1);
if (((Byte*)&gl_ptr_mem)[3] & 0x01)
{
nf_parity_bit = NF_ODD;
}
else
{
nf_parity_bit = NF_EVEN;
}
return OK;
}
/*F**************************************************************************
* NAME: nf_read_close
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Low level memory read close
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void nf_read_close (void)
{
}
/*F*************************************************************************
* NAME: nf_read_byte
*---------------------------------------------------------------------------
* PARAMS:
*
* return:
* Data read from memory
*---------------------------------------------------------------------------
* PURPOSE:
* Low level memory read function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
****************************************************************************/
Byte nf_read_byte (void)
{
Byte b;
if (!gl_cpt_page)
{
if (nf_parity_bit == NF_ODD)
{
Nf_active_ODD();
Nf_wait_busy_odd();
Nf_read_open_A_area_odd(nf_current_physical_sector_addr_odd, 0x00);
b = Nf_rd_byte_odd();
}
else
{
Nf_active_EVEN();
Nf_wait_busy_even();
Nf_read_open_A_area_even(nf_current_physical_sector_addr_even, 0x00);
b = Nf_rd_byte_even();
}
}
else
{
b = (nf_parity_bit == NF_ODD) ? Nf_rd_byte_odd() : Nf_rd_byte_even();
}
gl_cpt_page++;
if (((Byte*)&gl_cpt_page)[0] == 0x02) /* end of page */
{
gl_ptr_mem++; /* new page */
((Byte*)&gl_cpt_page)[0] = 0; /* start at column 0 */
if ( !(((Byte*)&gl_ptr_mem)[3] & 0x3F) ) /* New block ? */
{
nf_read_open(gl_ptr_mem);
}
else
{
nf_parity_bit = ~nf_parity_bit;
if (nf_parity_bit == NF_ODD)
{
((Byte*)&nf_current_physical_sector_addr_even)[3]++;
//nf_current_physical_sector_addr_even++;
}
else
{
((Byte*)&nf_current_physical_sector_addr_odd)[3]++;
//nf_current_physical_sector_addr_odd++;
}
}
}
return b;
}
/*F**************************************************************************
* NAME: nf_read_sector
*----------------------------------------------------------------------------
* PARAMS:
* global: gl_ptr_mem
*
* return: OK read done
* KO read failure
*----------------------------------------------------------------------------
* PURPOSE:
* This function is an optimized function that writes 512 bytes from NF
* to USB controller
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit nf_read_sector(Uint16 nb_sector)
{
Byte i;
bit begin_ping_pong = TRUE;
do
{
if (nf_parity_bit == NF_ODD)
{
Nf_active_ODD();
Nf_wait_busy_odd();
Nf_read_open_A_area_odd(nf_current_physical_sector_addr_odd, 0x00);
((Byte*)&nf_current_physical_sector_addr_odd)[3]++;
//nf_current_physical_sector_addr_odd++;
for (i = 8; i != 0; i--)
{
Usb_write_byte(Nf_rd_byte_odd()); /* read 64 bytes from card */
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
Usb_write_byte(Nf_rd_byte_odd());
if (begin_ping_pong)
{
begin_ping_pong = FALSE;
}
else
{
while (!Usb_tx_complete()); /* wait end of transfer */
Usb_clear_TXCMPL(); /* ack transfer */
}
Usb_set_TXRDY(); /* start usb transfer */
}
}
else
{
Nf_active_EVEN();
Nf_wait_busy_even();
Nf_read_open_A_area_even(nf_current_physical_sector_addr_even, 0x00);
((Byte*)&nf_current_physical_sector_addr_even)[3]++;
//nf_current_physical_sector_addr_even++;
for (i = 8; i != 0; i--)
{
Usb_write_byte(Nf_rd_byte_even()); /* read 64 bytes from card */
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
Usb_write_byte(Nf_rd_byte_even());
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -