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

📄 nf_drv.c

📁 ATMEL MP3 源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Copy the first part of a block that is not modified during a write
*   operation
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS: 
* ram/xram:
* cycle:
* stack: 
* code:
*****************************************************************************/
void nf_copy_block_head (void)
{
Byte j;
Uint32 address2;
  nf_parity_bit = NF_EVEN;

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

  for (j = (((Byte*)&gl_ptr_mem)[3] & 0x7F); j != 0; j--)
  { 
    if (nf_parity_bit == NF_ODD)
    {
      Nf_active_ODD();
      Nf_wait_busy_odd();
      Nf_send_command_odd (NF_READ_CMD);
      Nf_send_address_odd (0x00);
      Nf_send_address_odd (0x00);
      Nf_send_address_odd ( ((Byte*)&gl_address)[3] );      /* Row address Byte 0           */
      Nf_send_address_odd ( ((Byte*)&gl_address)[2] );      /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                           /* Size of nf >= 128Mbytes ?    */
        Nf_send_address_odd ( ((Byte*)&gl_address)[1] );    /* Row address Byte 2           */

      Nf_send_command_odd (NF_COPY_BACK_CMD);               /* Send copy back command       */
      Nf_wait_busy_odd();
      Nf_send_command_odd (NF_RANDOM_DATA_INPUT_CMD);
      Nf_send_address_odd (0x00);
      Nf_send_address_odd (0x00);
      Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[3] );     /* Row address Byte 0         */
      Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[2] );     /* Row address Byte 1         */
      if (NF_5_CYCLE_ADDRESS_BIT)                                                   /* Size of nf >= 128Mbytes?   */
        Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[1] );   /* Row address Byte 2         */

      Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
      ((Byte*)&nf_current_physical_sector_addr_odd)[3]++;                           /* increase addresses         */
      ((Byte*)&gl_address)[3]++;
    }
    else
    {
      Nf_active_EVEN();
      Nf_wait_busy_even();
      Nf_send_command_even (NF_READ_CMD);
      Nf_send_address_even (0x00);
      Nf_send_address_even (0x00);
      Nf_send_address_even ( ((Byte*)&address2)[3] );       /* Row address Byte 0           */
      Nf_send_address_even ( ((Byte*)&address2)[2] );       /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                           /* Size of nf >= 128Mbytes ?    */
        Nf_send_address_even ( ((Byte*)&address2)[1] );     /* Row address Byte 2           */

      Nf_send_command_even (NF_COPY_BACK_CMD);              /* Send copy back command       */
      Nf_wait_busy_even();
      Nf_send_command_even (NF_RANDOM_DATA_INPUT_CMD);
      Nf_send_address_even (0x00);
      Nf_send_address_even (0x00);
      Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[3] );     /* Row address Byte 0         */
      Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[2] );     /* Row address Byte 1         */
      if (NF_5_CYCLE_ADDRESS_BIT)                                                     /* Size of nf >= 128Mbytes ?  */
        Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[1] );   /* Row address Byte 2         */

      Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
      ((Byte*)&nf_current_physical_sector_addr_even)[3]++;                            /* increase addresses         */
      ((Byte*)&address2)[3]++;
    }
    nf_parity_bit = ~nf_parity_bit;
  }

  if (gl_cpt_page != 0)
  {
    nf_init_buffer();
    if (nf_parity_bit == NF_ODD)
    {
      Nf_active_ODD();
      Nf_wait_busy_odd();
      Nf_send_command_odd (NF_READ_CMD);
      Nf_send_address_odd (0x00);
      Nf_send_address_odd (0x00);
      Nf_send_address_odd ( ((Byte*)&gl_address)[3] );    /* Row address Byte 0           */
      Nf_send_address_odd ( ((Byte*)&gl_address)[2] );    /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                     /* Size of card >= 128Mbytes ?  */
        Nf_send_address_odd( ((Byte*)&gl_address)[1] );  /* Row address Byte 2           */

      Nf_send_command_odd (NF_COPY_BACK_CMD);
      Nf_wait_busy_odd();
      Nf_send_command_odd (NF_RANDOM_DATA_INPUT_CMD);
      Nf_send_address_odd ( ((Byte*)&gl_cpt_page)[1] );
      Nf_send_address_odd ( ((Byte*)&gl_cpt_page)[0] );
      Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[3] );     /* Row address Byte 0           */
      Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[2] );     /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                                           /* Size of card >= 128Mbytes ?  */
        Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[1] );   /* Row address Byte 2           */
    }
    else
    {
      Nf_active_EVEN();
      Nf_wait_busy_even();
      Nf_send_command_even (NF_READ_CMD);
      Nf_send_address_even (0x00);
      Nf_send_address_even (0x00);
      Nf_send_address_even ( ((Byte*)&address2)[3] );    /* Row address Byte 0           */
      Nf_send_address_even ( ((Byte*)&address2)[2] );    /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                     /* Size of card >= 128Mbytes ?  */
        Nf_send_address_even ( ((Byte*)&address2)[1] );  /* Row address Byte 2           */

      Nf_send_command_even (NF_COPY_BACK_CMD);
      Nf_wait_busy_even();
      Nf_send_command_even (NF_RANDOM_DATA_INPUT_CMD);
      Nf_send_address_even ( ((Byte*)&gl_cpt_page)[1] );
      Nf_send_address_even ( ((Byte*)&gl_cpt_page)[0] );
      Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[3] );     /* Row address Byte 0           */
      Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[2] );     /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                                           /* Size of card >= 128Mbytes ?  */
        Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[1] );   /* Row address Byte 2           */

    }
    for (j = (gl_cpt_page / 512); j < 4; j++)
    {
      nf_download_buffer();
      nf_download_buffer();
    }
    if (nf_parity_bit == NF_ODD)
    {
      Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
    }
    else
    {
      Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
    }
  }
}


/*F**************************************************************************
* NAME: nf_copy_block_tail
*----------------------------------------------------------------------------
* PARAMS:
*   block : physical block number
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Copy the last part of a block that is not modifiedd uring a write
*   operation
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS: 
* ram/xram:
* cycle:
* stack: 
* code:
*****************************************************************************/
void nf_copy_block_tail (void)
{
Uint32 address2;
Byte j;

  /* Address of the source block */
  gl_address = ((Uint32)(nf_block_to_be_deleted_odd)  << NF_SHIFT_SECTOR_BLOCK) + (((Byte*)&nf_current_physical_sector_addr_odd)[3] & 0x3F);
  address2 =   ((Uint32)(nf_block_to_be_deleted_even) << NF_SHIFT_SECTOR_BLOCK) + (((Byte*)&nf_current_physical_sector_addr_even)[3] & 0x3F);

  nf_parity_bit = ((Byte*)&gl_ptr_mem)[3] & 0x01;
  while (gl_cpt_page != 0)
  {
    if (nf_parity_bit == NF_ODD)
    {
      Nf_active_ODD();
      Nf_wait_busy_odd();
      Nf_send_command_odd (NF_READ_CMD);
      Nf_send_address_odd ( 0x00);
      Nf_send_address_odd ( ((Byte*)&gl_cpt_page)[0]);
      Nf_send_address_odd ( ((Byte*)&gl_address)[3] );      /* Row address Byte 0           */
      Nf_send_address_odd ( ((Byte*)&gl_address)[2] );      /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                           /* Size of card >= 128Mbytes ?  */
        Nf_send_address_odd ( ((Byte*)&gl_address)[1] );    /* Row address Byte 2           */
      Nf_send_command_odd (NF_READ_CMD2);
      Nf_wait_busy_odd();
  
      nf_upload_buffer();
  
      Nf_send_command_odd (NF_SEQUENTIAL_DATA_INPUT_CMD); 
      Nf_send_address_odd ( 0x00 );
      Nf_send_address_odd ( ((Byte*)&gl_cpt_page)[0] );
      Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[3]);        /* Row address Byte 0           */
      Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[2]);        /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                                                     /* Size of card >= 128Mbytes ?  */
        Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[1] );     /* Row address Byte 2           */
  
      nf_download_buffer();
  
      Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
  
      ((Byte*)&gl_cpt_page)[0]++;
      
      Nf_wait_busy_odd();
  
      Nf_send_command_odd (NF_READ_CMD);
      Nf_send_address_odd ( 0x00);
      Nf_send_address_odd ( ((Byte*)&gl_cpt_page)[0]);
      Nf_send_address_odd ( ((Byte*)&gl_address)[3] );      /* Row address Byte 0           */
      Nf_send_address_odd ( ((Byte*)&gl_address)[2] );      /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                           /* Size of card >= 128Mbytes ?  */
        Nf_send_address_odd ( ((Byte*)&gl_address)[1] );    /* Row address Byte 2           */
      Nf_send_command_odd (NF_READ_CMD2);
      Nf_wait_busy_odd();
  
      nf_upload_buffer();
  
      Nf_send_command_odd (NF_SEQUENTIAL_DATA_INPUT_CMD); 
      Nf_send_address_odd ( 0x00 );
      Nf_send_address_odd ( ((Byte*)&gl_cpt_page)[0]);
      Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[3]);
      Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[2]);
      if (NF_5_CYCLE_ADDRESS_BIT)                                                   /* Size of card >= 128Mbytes ?  */
        Nf_send_address_odd ( ((Byte*)&nf_current_physical_sector_addr_odd)[1] );   /* Row address Byte 2           */
  
      nf_download_buffer();
      Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);
    }
    else
    {
      Nf_active_EVEN();
      Nf_wait_busy_even();
      Nf_send_command_even (NF_READ_CMD);
      Nf_send_address_even ( 0x00);
      Nf_send_address_even ( ((Byte*)&gl_cpt_page)[0]);
      Nf_send_address_even ( ((Byte*)&address2)[3] );      /* Row address Byte 0           */
      Nf_send_address_even ( ((Byte*)&address2)[2] );      /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                          /* Size of card >= 128Mbytes ?  */
        Nf_send_address_even ( ((Byte*)&address2)[1] );    /* Row address Byte 2           */
      Nf_send_command_even (NF_READ_CMD2);
      Nf_wait_busy_even();
  
      nf_upload_buffer();
  
      Nf_send_command_even (NF_SEQUENTIAL_DATA_INPUT_CMD); 
      Nf_send_address_even ( 0x00 );
      Nf_send_address_even ( ((Byte*)&gl_cpt_page)[0] );
      Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[3]);        /* Row address Byte 0           */
      Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[2]);        /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                                                       /* Size of card >= 128Mbytes ?  */
        Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[1] );     /* Row address Byte 2           */
  
      nf_download_buffer();
  
      Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
  
      ((Byte*)&gl_cpt_page)[0]++;
      
      Nf_wait_busy_even();
  
      Nf_send_command_even (NF_READ_CMD);
      Nf_send_address_even ( 0x00);
      Nf_send_address_even ( ((Byte*)&gl_cpt_page)[0]);
      Nf_send_address_even ( ((Byte*)&address2)[3] );       /* Row address Byte 0           */
      Nf_send_address_even ( ((Byte*)&address2)[2] );       /* Row address Byte 1           */
      if (NF_5_CYCLE_ADDRESS_BIT)                           /* Size of nf >= 128Mbytes ?    */
        Nf_send_address_even ( ((Byte*)&address2)[1] );     /* Row address Byte 2           */
      Nf_send_command_even (NF_READ_CMD2);
      Nf_wait_busy_even();
  
      nf_upload_buffer();
  
      Nf_send_command_even (NF_SEQUENTIAL_DATA_INPUT_CMD); 
      Nf_send_address_even ( 0x00 );
      Nf_send_address_even ( ((Byte*)&gl_cpt_page)[0]);
      Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[3]);
      Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[2]);
      if (NF_5_CYCLE_ADDRESS_BIT)                                                   /* Size of nf >= 128Mbytes ?  */
        Nf_send_address_even ( ((Byte*)&nf_current_physical_sector_addr_even)[1] ); /* Row address Byte 2         */
  
      nf_download_buffer();
      Nf_send_command_even (NF_PAGE_PROGRAM_CMD);
    }

⌨️ 快捷键说明

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