⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smc_drv.c

📁 ATMEL 89c51sndc mp3外接硬盘源码
💻 C
📖 第 1 页 / 共 3 页
字号:
*           
*
*****************************************************************************/
void smc_copy_block_head(void)
{
Byte j;

  /* address of the source physical block */
  gl_address = (Uint32)(smc_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*)&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();

    smc_upload_buffer();

    /* Write open */
    Smc_send_command (SMC_SEQUENTIAL_DATA_INPUT_CMD);
    Smc_send_address (0x00);
    Smc_send_address ( ((Byte*)&smc_current_physical_sector_addr)[3] );  /* 2nd address cycle         */
    Smc_send_address ( ((Byte*)&smc_current_physical_sector_addr)[2] );  /* 3rd address cycle         */
    if (smc_64)                                                      /* Size of card >= 64Mbytes ?*/
      Smc_send_address ( ((Byte*)&smc_current_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*)&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();

    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*)&smc_current_physical_sector_addr)[3] );  /* 2nd address cycle         */
    Smc_send_address ( ((Byte*)&smc_current_physical_sector_addr)[2] );  /* 3rd address cycle         */
    if (smc_64)                                                      /* Size of card >= 64Mbytes ?*/
      Smc_send_address ( ((Byte*)&smc_current_physical_sector_addr)[1] );/* 4th address cycle         */

    smc_download_buffer();
    Smc_send_command (SMC_PAGE_PROGRAM_CMD);
    Smc_wait_busy();

    /* Update spare data */
    Smc_read_open_C_area(gl_address, 0x00);
    gl_buffer[0] = Smc_rd_byte();
    gl_buffer[1] = Smc_rd_byte();
    gl_buffer[2] = Smc_rd_byte();
    gl_buffer[3] = Smc_rd_byte();
    gl_buffer[4] = Smc_rd_byte();
    gl_buffer[5] = Smc_rd_byte();
    gl_buffer[6] = Smc_rd_byte();
    gl_buffer[7] = Smc_rd_byte();
    gl_buffer[8] = Smc_rd_byte();
    gl_buffer[9] = Smc_rd_byte();
    gl_buffer[10] = Smc_rd_byte();
    gl_buffer[11] = Smc_rd_byte();
    gl_buffer[12] = Smc_rd_byte();
    gl_buffer[13] = Smc_rd_byte();
    gl_buffer[14] = Smc_rd_byte();
    gl_buffer[15] = Smc_rd_byte();
    Smc_write_open_C_area(smc_current_physical_sector_addr, 0x00);
    Smc_wr_byte(gl_buffer[0]);
    Smc_wr_byte(gl_buffer[1]);
    Smc_wr_byte(gl_buffer[2]);
    Smc_wr_byte(gl_buffer[3]);
    Smc_wr_byte(gl_buffer[4]);
    Smc_wr_byte(gl_buffer[5]);
    Smc_wr_byte(gl_buffer[6]);
    Smc_wr_byte(gl_buffer[7]);
    Smc_wr_byte(gl_buffer[8]);
    Smc_wr_byte(gl_buffer[9]);
    Smc_wr_byte(gl_buffer[10]);
    Smc_wr_byte(gl_buffer[11]);
    Smc_wr_byte(gl_buffer[12]);
    Smc_wr_byte(gl_buffer[13]);
    Smc_wr_byte(gl_buffer[14]);
    Smc_wr_byte(gl_buffer[15]);



    Smc_send_command (SMC_PAGE_PROGRAM_CMD);

    /* increase counter */
    smc_current_physical_sector_addr++;
    gl_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;

  smc_current_physical_sector_addr++;

  /* Address of the source block */
  gl_address = ((Uint32)(smc_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*)&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();

    smc_upload_buffer();

    /* Write open  */
    Smc_send_command (SMC_SEQUENTIAL_DATA_INPUT_CMD);
    Smc_send_address (0x00);
    Smc_send_address ( ((Byte*)&smc_current_physical_sector_addr)[3] );  /* 2nd address cycle         */
    Smc_send_address ( ((Byte*)&smc_current_physical_sector_addr)[2] );  /* 3rd address cycle         */
    if (smc_64)                                                      /* Size of card >= 64Mbytes ?*/
      Smc_send_address ( ((Byte*)&smc_current_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*)&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();

    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*)&smc_current_physical_sector_addr)[3] );  /* 2nd address cycle         */
    Smc_send_address ( ((Byte*)&smc_current_physical_sector_addr)[2] );  /* 3rd address cycle         */
    if (smc_64)                                                      /* Size of card >= 64Mbytes ?*/
      Smc_send_address ( ((Byte*)&smc_current_physical_sector_addr)[1] );/* 4th address cycle         */

    smc_download_buffer();

    /* Update spare data */
    smc_update_spare_data();
    
    Smc_send_command (SMC_PAGE_PROGRAM_CMD);

    smc_current_physical_sector_addr++;
    gl_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 (smc_lut_index[smc_zone] == 7)
  {
    if ((smc_buf_free[smc_gl_buf_free_idx] & 0x7FFF) == smc_look_up_table_block)
    {
      smc_gl_buf_free_idx++;
      if (smc_gl_buf_free_idx >= smc_spare_block /*(smc_spare_block_number[smc_zone]>>1)*/ )
      {
        smc_gl_buf_free_idx = 0;
      }      
    }

    /* Source address */
    address2 = ((Uint32)(smc_look_up_table_block)<<5) + 28;

    smc_look_up_table_block =  smc_buf_free[smc_gl_buf_free_idx] & 0x7FFF;
    
    smc_gl_buf_free_idx++;
    if (smc_gl_buf_free_idx >= smc_spare_block /*(smc_spare_block_number[smc_zone]>>1)*/ )
    {
      smc_gl_buf_free_idx = 0;
    }      


    /* Target address : recopy the last 2Kb */
    gl_address = ((Uint32)(smc_look_up_table_block) << 5);

    smc_lut_index[smc_zone] = 0;

  }
  else
  {
    /* Source address */
    address2 = ((Uint32)(smc_look_up_table_block)<<5) + ((Uint32)(smc_lut_index[smc_zone])<<2);

    smc_lut_index[smc_zone]++;

    /* Target address */
    //address = (Uint32)(smc_look_up_table_block) << 5 + (Uint32)(smc_lut_index[smc_zone]<<2);
    gl_address = address2 + 4;

  }

  j = 0;
  k = 0;
  start = 0;
  block_start = smc_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 <= smc_gl_buf_idx_max) && (start <= block_start) && ((start + 128) > block_start))
    {
      gl_buffer[(2 * (block_start & 0x7F))] = smc_buf[k].b[0];
      gl_buffer[(2 * (block_start & 0x7F))+1] = smc_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*)&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         */

    /* 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 <= smc_gl_buf_idx_max) && (start <= block_start) && ((start + 128) > block_start))
    {
      gl_buffer[(2 * (block_start & 0x7F))] = smc_buf[k].b[0];
      gl_buffer[(2 * (block_start & 0x7F))+1] = smc_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] = smc_buf_free[j]>>8;
        gl_buffer[dummy+1] = smc_buf_free[j];  
        dummy += 2;
      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -