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

📄 nf_drv.c

📁 ATMEL 89c51sndc mp3外接硬盘源码
💻 C
📖 第 1 页 / 共 3 页
字号:
      nf_update_spare_data();                                           /* Update spare data */
      Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);                        /* Send program command */ 
      nf_current_physical_sector_addr_odd++;
    }
    state = ~state;
  } 
}



/*F**************************************************************************
* NAME:     nf_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     
*       This function uses the Samsung NF specific command: Copy-Back Program    
*
*****************************************************************************/
void nf_copy_block_head(void)
{
Byte j;
bit state = 0;
Uint32 address2;

  /* address of the source physical block */
  gl_address = (Uint32)(nf_block_to_be_deleted_even) << 5;
  address2 = (Uint32)(nf_block_to_be_deleted_odd) << 5;

  for (j = (gl_ptr_mem & 0x3F); j != 0; j--)
  { 
    if (!state)
    {
      Nf_CS_EVEN();
      Nf_wait_busy_even();
      #ifdef SAMSUNG_NF
        Nf_send_command_even(NF_READ_A_AREA_CMD);
        Nf_send_cl_address_even(gl_address, 0x00);
        Nf_wait_busy_even();
        Nf_send_command_even (NF_COPY_BACK_TO_PAGE);
        Nf_send_cl_address_even(nf_current_physical_sector_addr_even, 0x00);
        Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
      #else
        Nf_send_command_even(NF_READ_A_AREA_CMD);
        Nf_send_cl_address_even(address, 0x00);
        Nf_wait_busy_even();
        nf_upload_buffer_even();
        Nf_write_open_A_area_even(nf_current_physical_sector_addr_even, 0x00);
        nf_download_buffer();
        Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
        Nf_wait_busy_even();
        Nf_send_command_even(NF_READ_B_AREA_CMD);
        Nf_send_cl_address_even(address, 0x00);
        Nf_wait_busy_even();
        nf_upload_buffer_even();
        Nf_write_open_B_area_even(nf_current_physical_sector_addr_even, 0x00);
        nf_download_buffer();
        nf_update_spare_data_even();
        Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
      #endif

      /* increase counter */
      nf_current_physical_sector_addr_even++;
      gl_address++;

    }
    else
    {
      Nf_CS_ODD();
      Nf_wait_busy_odd();
  
      #ifdef SAMSUNG_NF
        Nf_send_command_odd(NF_READ_A_AREA_CMD);
        Nf_send_cl_address_odd(address2, 0x00);
        Nf_wait_busy_odd();
        Nf_send_command_odd (NF_COPY_BACK_TO_PAGE);
        Nf_send_cl_address_odd(nf_current_physical_sector_addr_odd, 0x00);
        Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
      #else
        Nf_send_command_odd(NF_READ_A_AREA_CMD);
        Nf_send_cl_address_odd(address2, 0x00);
        Nf_wait_busy_odd();
        nf_upload_buffer_odd();
        Nf_write_open_A_area_odd();
        Nf_send_cl_address_odd(nf_current_physical_sector_addr_odd, 0x00);
        nf_download_buffer();
        Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
        
        Nf_wait_busy_odd();
        Nf_send_command_odd(NF_READ_B_AREA_CMD);
        Nf_send_cl_address_odd(address2, 0x00);
        Nf_wait_busy_odd();
        nf_upload_buffer_odd();
        Nf_write_open_B_area_odd();
        Nf_send_cl_address_odd(nf_current_physical_sector_addr_odd, 0x00);
        nf_download_buffer();
        nf_update_spare_data_odd();
        Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
      #endif
  
      nf_current_physical_sector_addr_odd++;
      address2++;
    }
    state = ~state;
  }       /* end for */
}


/*F**************************************************************************
* NAME:     nf_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 nf_copy_block_tail(void)
{
Byte j;
Byte state;
Uint32 address2;

  /* Address of the source block */
  gl_address = ((Uint32)(nf_block_to_be_deleted_even) << 5) +  ((gl_ptr_mem & 0x3F) >> 1) + (gl_ptr_mem & 0x01);
  address2 = ((Uint32)(nf_block_to_be_deleted_odd) << 5) +  ((gl_ptr_mem & 0x3F) >> 1);

  state = gl_ptr_mem & 0x01;

  for (j = (gl_ptr_mem & 0x3F); j < 64; j++)
  { 
    switch(state) 
    {
      case 0: // even
      {
        Nf_CS_EVEN();
        Nf_wait_busy_even();
        
        #ifdef SAMSUNG_NF
          Nf_send_command_even(NF_READ_A_AREA_CMD);
          Nf_send_cl_address_even(gl_address, 0x00);
          Nf_wait_busy_even();
          
          Nf_send_command_even (NF_COPY_BACK_TO_PAGE);
          Nf_send_cl_address_even(nf_current_physical_sector_addr_even, 0x00);
          Nf_send_command_even (NF_PAGE_PROGRAM_CMD);

        #else
          Nf_read_open_A_area_even(address, 0x00);
          nf_upload_buffer_even();
          Nf_write_open_A_area_even(nf_current_physical_sector_addr_even, 0x00);
          nf_download_buffer();
          Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
          Nf_wait_busy_even();
          Nf_send_command_even(NF_READ_B_AREA_CMD);
          Nf_read_open_B_area_even(address, 0x00);
          nf_upload_buffer_even();
          Nf_write_open_B_area_even(nf_current_physical_sector_addr_even, 0x00);
          nf_download_buffer();
          nf_update_spare_data();
          Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
        #endif

        /* increase counter */
        nf_current_physical_sector_addr_even++;
        gl_address++;
        
        state = 1;
        
        break;
      }

    default: /* case 1 // odd */
    {
      Nf_CS_ODD();
      Nf_wait_busy_odd();
      
      #ifdef SAMSUNG_NF
        Nf_send_command_odd(NF_READ_A_AREA_CMD);
        Nf_send_cl_address_odd(address2, 0x00);
        Nf_wait_busy_odd();
        Nf_send_command_odd (NF_COPY_BACK_TO_PAGE);
        Nf_send_cl_address_odd(nf_current_physical_sector_addr_odd, 0x00);
        Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
      #else
        Nf_read_open_A_area_odd(address2, 0x00);
        nf_upload_buffer_odd();
        Nf_write_open_A_area_odd(nf_current_physical_sector_addr_odd, 0x00);
        nf_download_buffer();
        Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
        Nf_open_read_B_area_odd(address2, 0x00);
        nf_upload_buffer_odd();
        Nf_write_open_B_area_odd(nf_current_physical_sector_addr_odd, 0x00);
        nf_download_buffer();
        nf_update_spare_data_odd();
        Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
        #endif
        
        nf_current_physical_sector_addr_odd++;
        address2++;
        
        state = 0;
        
        break;
      }
    }
  }
}


/*F**************************************************************************
* NAME:     nf_reassign_block
*----------------------------------------------------------------------------
* PARAMS:   block : reassign the physical block
*
* RETURN:
*
*----------------------------------------------------------------------------
* PURPOSE:  This function reassign the block value in LUT (copy of LUT)
*           
*
*****************************************************************************
* NOTE:     
*           
*
*****************************************************************************/
void nf_reassign_block(void)
{
Byte    dummy;
Byte    j;
Uint16  k;
xdata Uint16  start;
xdata Uint16  block_start;                     
idata Uint32  address2;                         /* LUT Source address */
Byte pdata *ptr = gl_buffer;              /* gl_buffer pointer */

  if (lut_index[nf_zone] >= 3)            /* the LUT can be copied 4 times in a block */
  {
    if ((buf_free[nf_gl_buf_free_idx].even & 0x7FFF) == nf_look_up_table_block)
    {
      nf_gl_buf_free_idx++;
      if (nf_gl_buf_free_idx >= nf_spare_block)
      {
        nf_gl_buf_free_idx = 0;
      }      
    }

    /* Source address */
    address2 = ((Uint32)(nf_look_up_table_block)<<5) + 24;               /* 24 = index of last copied LUT */

    nf_look_up_table_block =  buf_free[nf_gl_buf_free_idx].even & 0x7FFF;
    
    nf_gl_buf_free_idx++;
    if (nf_gl_buf_free_idx >= nf_spare_block)
    {
      nf_gl_buf_free_idx = 0;
    }      

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

    lut_index[nf_zone] = 0;
  }
  else
  {
    /* Source address */
    address2 = ((Uint32)(nf_look_up_table_block)<<5) + ((Uint32)(lut_index[nf_zone])<<3);

    lut_index[nf_zone]++;

    /* Target address */
    gl_address = address2 + 8; /* 8 pages = size of a copy of the lut */
  }

  j = 0;
  k = 0;
  start = 0;
  block_start = block_min;

  Nf_CS_EVEN();

  do
  {
    /* upload the buffer */
    Nf_wait_busy_even();
    Nf_read_open_A_area_even(address2, 0x00);
    nf_upload_buffer();
    /* update the buffer */    
    while ((k <= nf_gl_buf_idx_max) && (start <= block_start) && ((start + 64) > block_start))
    {
      gl_buffer[(4 * (block_start & 0x3F))] = buf[k].even.b[0];
      gl_buffer[(4 * (block_start & 0x3F))+1] = buf[k].even.b[1];
      gl_buffer[(4 * (block_start & 0x3F))+2] = buf[k].odd.b[0];
      gl_buffer[(4 * (block_start & 0x3F))+1+2] = buf[k].odd.b[1];
      k++;
      block_start++;
    }
    Nf_write_open_A_area_even(gl_address, 0x00);
    nf_download_buffer();
    Nf_send_command_even(NF_PAGE_PROGRAM_CMD);

    start += 64;
    Nf_wait_busy_even();
    Nf_read_open_B_area_even(address2, 0x00);
    nf_upload_buffer();

    while ((k <= nf_gl_buf_idx_max) && (start <= block_start) && ((start + 64) > block_start))
    {
      gl_buffer[(4 * (block_start & 0x3F))] = buf[k].even.b[0];
      gl_buffer[(4 * (block_start & 0x3F))+1] = buf[k].even.b[1];
      gl_buffer[(4 * (block_start & 0x3F))+2] = buf[k].odd.b[0];
      gl_buffer[(4 * (block_start & 0x3F))+1+2] = buf[k].odd.b[1];
      k++;
      block_start++;
    }   
 
    if (start >= 960)   /* This part update the free physical block table */
    {                   /* 960 = first logical block in part B of the last page of the Lut */
      dummy = 160;      /* 160 = offset for free blocks in part B of the last page of the Lut */
      for (j = 0; j <= 23; j++)
      {           
        gl_buffer[dummy] = buf_free[j].even>>8;
        gl_buffer[dummy+1] = buf_free[j].even; 
        gl_buffer[dummy+2] = buf_free[j].odd>>8;
        gl_buffer[dummy+1+2] = buf_free[j].odd; 
        dummy += 4;
      }
    }

    Nf_write_open_B_area_even(gl_address, 0x00);
    nf_download_buffer();    /* download the buffer */

    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);

⌨️ 快捷键说明

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