📄 smc_drv.c
字号:
/*F**************************************************************************
* NAME: smc_copy_block_head
*----------------------------------------------------------------------------
* PARAMS: block : physical block number
* nb_sector : number of sector to be copied
*
* RETURN:
*
*----------------------------------------------------------------------------
* PURPOSE: This function copy the first part of a block that is not modified
* during a write operation
*
*****************************************************************************
* NOTE: Uint32 address is global
*
*
*****************************************************************************/
void smc_copy_block_head(void)
{
Byte j;
/* address of the source physical block */
address = (Uint32)(block_to_be_deleted) << 5;
for (j = (gl_ptr_mem & 0x1F); j != 0; j--)
{
Smc_wait_busy();
/* 1st half page */
/* Read Open */
Smc_send_command (SMC_READ_A_AREA_CMD);
Smc_send_address (0x00);
Smc_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
Smc_wait_busy();
smc_upload_buffer();
/* Write open */
Smc_send_command (SMC_SEQUENTIAL_DATA_INPUT_CMD);
Smc_send_address (0x00);
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[1] );/* 4th address cycle */
smc_download_buffer();
Smc_send_command (SMC_PAGE_PROGRAM_CMD);
Smc_wait_busy();
/* 2nd half page */
/* Read Open */
Smc_send_command (SMC_READ_B_AREA_CMD);
Smc_send_address (0x00);
Smc_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
Smc_wait_busy();
smc_upload_buffer();
/* Write open */
Smc_send_command (SMC_READ_B_AREA_CMD);
Smc_send_command (SMC_SEQUENTIAL_DATA_INPUT_CMD);
Smc_send_address (0x00);
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[1] );/* 4th address cycle */
smc_download_buffer();
/* Update spare data */
smc_update_spare_data();
Smc_send_command (SMC_PAGE_PROGRAM_CMD);
/* increase counter */
current_physical_sector_addr++;
address++;
}
Smc_wait_busy();
}
/*F**************************************************************************
* NAME: smc_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 smc_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++)
{
Smc_wait_busy();
/* 1st half page */
/* Read Open */
Smc_send_command (SMC_READ_A_AREA_CMD);
Smc_send_address (0x00);
Smc_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
Smc_wait_busy();
smc_upload_buffer();
/* Write open */
Smc_send_command (SMC_SEQUENTIAL_DATA_INPUT_CMD);
Smc_send_address (0x00);
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[1] );/* 4th address cycle */
smc_download_buffer();
Smc_send_command (SMC_PAGE_PROGRAM_CMD);
Smc_wait_busy();
/* 2nd half page */
/* Read Open */
Smc_send_command (SMC_READ_B_AREA_CMD);
Smc_send_address (0x00);
Smc_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
Smc_wait_busy();
smc_upload_buffer();
/* Write open */
Smc_send_command (SMC_READ_B_AREA_CMD);
Smc_send_command (SMC_SEQUENTIAL_DATA_INPUT_CMD);
Smc_send_address (0x00);
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)¤t_physical_sector_addr)[1] );/* 4th address cycle */
smc_download_buffer();
/* Update spare data */
smc_update_spare_data();
Smc_send_command (SMC_PAGE_PROGRAM_CMD);
current_physical_sector_addr++;
address++;
}
Smc_wait_busy();
}
/*F**************************************************************************
* NAME: smc_reassign_block
*----------------------------------------------------------------------------
* PARAMS: block : reassign the physical block
*
* RETURN:
*
*----------------------------------------------------------------------------
* PURPOSE: This function reassign the block value in LUT (copy of LUT)
*
*
*****************************************************************************
* NOTE:
*
*
*****************************************************************************/
void smc_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[smc_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 /*(smc_spare_block_number[smc_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 /*(smc_spare_block_number[smc_zone]>>1)*/ )
{
gl_buf_free_idx = 0;
}
/* Target address : recopy the last 2Kb */
address = ((Uint32)(look_up_table_block) << 5);
lut_index[smc_zone] = 0;
}
else
{
/* Source address */
address2 = ((Uint32)(look_up_table_block)<<5) + ((Uint32)(lut_index[smc_zone])<<2);
lut_index[smc_zone]++;
/* Target address */
//address = (Uint32)(look_up_table_block) << 5 + (Uint32)(lut_index[smc_zone]<<2);
address = address2 + 4;
}
j = 0;
k = 0;
start = 0;
block_start = block_min;
do
{
Smc_wait_busy();
/* Open look-up table in read mode */
Smc_send_command(SMC_READ_A_AREA_CMD); /* First half array */
Smc_send_address( 0x00);
Smc_send_address ( ((Byte*)&address2)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&address2)[2] ); /* 3rd address cycle */
if (smc_64 ) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&address2)[1] );/* 4th address cycle */
Smc_wait_busy();
smc_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++;
}
Smc_send_command(SMC_READ_A_AREA_CMD); /* First half array */
Smc_send_command(SMC_SEQUENTIAL_DATA_INPUT_CMD);
Smc_send_address(0x00);
Smc_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&address)[1] ); /* 4th address cycle */
/* Write 256 bytes from the buffer */
smc_download_buffer();
/* Valid the page programmation */
Smc_send_command(SMC_PAGE_PROGRAM_CMD);
start += 128;
/* Wait for R/B signal */
Smc_wait_busy();
/* Open look-up tableread in mode */
Smc_send_command(SMC_READ_B_AREA_CMD); /* Second half array */
Smc_send_address(0x00);
Smc_send_address ( ((Byte*)&address2)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&address2)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&address2)[1] );/* 4th address cycle */
Smc_wait_busy();
smc_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;
}
}
Smc_send_command(SMC_READ_B_AREA_CMD); /* Second half array */
/* Send the write open command and addresses */
Smc_send_command(SMC_SEQUENTIAL_DATA_INPUT_CMD);
Smc_send_address(0x00);
Smc_send_address ( ((Byte*)&address)[3] ); /* 2nd address cycle */
Smc_send_address ( ((Byte*)&address)[2] ); /* 3rd address cycle */
if (smc_64) /* Size of card >= 64Mbytes ?*/
Smc_send_address ( ((Byte*)&address)[1] );/* 4th address cycle */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -