?? smc.c
字號:
if (temp_address >= ((Uint32)(smc_zone + 1) << 15) )
temp_address = (Uint32)(smc_zone) << 15;
Smc_read_open_C_area(temp_address, 0x05);
byte_5 = Smc_rd_byte(); /* Invalid/Valid block */
byte_6 = Smc_rd_byte(); /* Used/Unused block */
}
while ( ( (byte_6 != 0xFF) && (byte_6 != 0xE8) ) || (byte_5 != 0xFF) );
free_bloc_pos = temp_address >> 5;
gl_buffer[i] = (free_bloc_pos >> 8) + 0x80;
gl_buffer[i + 1] = free_bloc_pos;
}
}
Smc_write_open_B_area(gl_address, 0x00); /* Write second part of LUT */
smc_download_buffer();
/* Write redundant data */
Smc_wr_byte(0xFF); Smc_wr_byte(0xFF); Smc_wr_byte(0xFF);
Smc_wr_byte(0xFF); Smc_wr_byte(0xFF);
Smc_wr_byte(0xFF);
Smc_wr_byte(0xE8); Smc_wr_byte(0xFF); /* Logical block value */
Smc_wr_byte(0xFF); Smc_wr_byte(0xFF); Smc_wr_byte(0xFF); /* ECC area 2 */
Smc_wr_byte(0xE8); Smc_wr_byte(0xFF); /* Logical block value */
Smc_wr_byte(0xFF); Smc_wr_byte(0xFF); Smc_wr_byte(0xFF); /* ECC area 1 */
Smc_send_command(SMC_PAGE_PROGRAM_CMD);
start += 0x80;
end += 0x80;
gl_address++; /* Increase the address of the conversion table */
}
while (start < SMC_BLOCK_PER_ZONE);
}
Smc_wait_busy();
}
/*F**************************************************************************
* NAME: smc_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* SMC initialisation
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit smc_init (void)
{
P2 = SMC_IDLE_STATE_ADD;
if ( Smc_card_detect() == KO )
{
gl_mem_failure = TRUE;
Smc_CS_OFF();
return KO;
}
Smc_CS_ON();
Smc_send_command(SMC_RESET_CMD);
Smc_wait_busy();
do
{
Smc_send_command(SMC_READ_ID_CMD); /* Read ID code */
Smc_send_address(0x00);
Smc_wait_busy();
} while (Smc_rd_byte() == 0x00);
switch (Smc_rd_byte()) /* Device code */
{
case 0x73 : /* 16 Mbyte */
smc_device_type = SMC_SIZE_16MB;
smc_zone_max = 1;
smc_disk_size = SMC_SECTOR_SIZE_16MB;
smc_64 = 0;
break;
case 0x75 : /* 32 Mbyte */
smc_device_type = SMC_SIZE_32MB;
smc_zone_max = 2;
smc_disk_size = SMC_SECTOR_SIZE_32MB;
smc_64 = 0;
break;
case 0x76 : /* 64 Mbyte */
smc_device_type = SMC_SIZE_64MB;
smc_zone_max = 4;
smc_disk_size = SMC_SECTOR_SIZE_64MB;
smc_64 = 1; /* 4 address cycles */
break;
case 0x79 : /* 128 Mbyte */
smc_device_type = SMC_SIZE_128MB;
smc_zone_max = 8;
smc_disk_size = SMC_SECTOR_SIZE_128MB;
smc_64 = 1; /* 4 address cycles */
break;
}
read_spare_byte();
return OK;
}
/*F**************************************************************************
* NAME: smc_read_open
*----------------------------------------------------------------------------
* 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 smc_read_open (Uint32 pos)
{
Uint16 physical_block;
Smc_CS_ON();
if ( Smc_card_detect() == KO )
{
gl_mem_failure = TRUE;
return 0xFF;
}
if (smc_lut_modified)
{
smc_reassign_block();
smc_lut_modified = FALSE;
}
gl_ptr_mem = pos;
gl_cpt_page = 0;
/* Determine the logical block value */
smc_logical_block = (gl_ptr_mem >> 5);
/* Determinate zone */
smc_zone = smc_logical_block / 1000;
/* Each zone have 1000 data blocks */
smc_logical_block = smc_logical_block - (1000 * (Uint16)(smc_zone));
/* Calculate the address where are the physical block value */
gl_address = ((Uint32)(smc_lut_block[smc_zone])<<5) + ((Uint32)(smc_logical_block) >> 8);
gl_address += ((Uint32)(smc_lut_index[smc_zone])<<2);
/* Open the look-up table */
Smc_wait_busy();
if (smc_logical_block & 0x80)
{
Smc_send_command(SMC_READ_B_AREA_CMD); /* 2nd half page */
Smc_send_address( (smc_logical_block << 1) - 256);
}
else
{
Smc_send_command(SMC_READ_A_AREA_CMD); /* first half page */
Smc_send_address(smc_logical_block << 1);
}
Smc_send_address ( ((Byte*)&gl_address)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&gl_address)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&gl_address)[1] ); /* 4th address cycle */
Smc_wait_busy();
/* Read the physical block number */
((Byte*)&physical_block)[0] = Smc_rd_byte();
((Byte*)&physical_block)[1] = Smc_rd_byte();
/* Calculate the physical sector address */
smc_current_physical_sector_addr = ((Uint32)(physical_block) << 5) + (gl_ptr_mem & 0x1F);
Smc_CS_OFF();
return OK;
}
/*F**************************************************************************
* NAME: smc_read_close
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Low level memory read close
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void smc_read_close (void)
{
Smc_CS_OFF();
}
/*F*************************************************************************
* NAME: smc_read_byte
*---------------------------------------------------------------------------
* PARAMS:
*
* return:
* Data read from memory
*---------------------------------------------------------------------------
* PURPOSE:
* Low level memory read function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
****************************************************************************/
Byte smc_read_byte (void)
{
Byte b;
if ( Smc_card_detect() == KO )
{
gl_mem_failure = TRUE;
Smc_CS_OFF();
return KO;
}
Smc_wait_busy();
if (!gl_cpt_page)
{
Smc_CS_ON();
Smc_read_open_A_area(smc_current_physical_sector_addr, 0x00);
b = Smc_rd_byte();
Smc_CS_OFF();
}
else
{
b = Smc_rd_byte();
}
gl_cpt_page++;
/* Detection of the end of data page */
if (gl_cpt_page == SMC_DATA_SIZE)
{
/* read spare data bytes */
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
Smc_rd_byte();
gl_ptr_mem++; /* new page */
gl_cpt_page=0; /* start at column 0 */
if ( !(gl_ptr_mem & 0x1F) ) /* New block ? */
{
smc_read_open(gl_ptr_mem);
}
else
{
smc_current_physical_sector_addr++;
}
}
return b;
}
/*F**************************************************************************
* NAME: smc_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 SMC
* card to USB controller
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
bit smc_read_sector(Uint16 nb_sector)
{
Byte i;
bit begin_ping_pong;
begin_ping_pong = TRUE;
do
{
if ( Smc_card_detect() == KO )
{
gl_mem_failure = TRUE;
Smc_CS_OFF();
return KO;
}
Smc_CS_ON();
Smc_wait_busy();
Smc_read_open_A_area(smc_current_physical_sector_addr, 0x00);
for (i = 8; i != 0; i--)
{
Usb_write_byte(Smc_rd_byte()); /* read 64 bytes from card */
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
Usb_write_byte(Smc_rd_byte());
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -