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

📄 nf_drv.c

📁 ATMEL公司AT89C51SND1为主控制器MP3源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xE8);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);

    /* Valid the page programmation */
    Nf_send_command_even(NF_PAGE_PROGRAM_CMD);

    start += 64;
    ((Byte*)&address2)[3]++;
    ((Byte*)&gl_address)[3]++;

  }
  while (start < NF_BLOCK_PER_ZONE);

  nf_gl_buf_idx_max = 0;

  if (lut_index[nf_zone] == 0)
  {
    address2 = (Uint32)(lut_block[nf_zone])<<5;
    Nf_CS_EVEN();
    nf_block_erase(address2);
    lut_block[nf_zone] = nf_look_up_table_block;
  }
}




/*F**************************************************************************
* NAME:     nf_mark_bad_block
*----------------------------------------------------------------------------
* PARAMS:   
*           
*
* RETURN:   
*
*
*----------------------------------------------------------------------------
* PURPOSE: Write 0x00 on block status byte (Byte 5 of spare data)
*          
*
*****************************************************************************
* NOTE:     This function use the global variable Uint32 address
*           
*
*
*
*****************************************************************************/
void nf_mark_bad_block(void)
{
  if (nf_parity_bit == NF_ODD)
  {
    Nf_wait_busy_odd();
    Nf_write_open_C_area_odd(gl_address, 0x00);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0x00);
    Nf_wr_byte_odd(0x00);
    Nf_wr_byte_odd(0x00);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_wr_byte_odd(0xFF);
    Nf_send_command_odd (NF_PAGE_PROGRAM_CMD);    /* Send program command */
  }
  else
  {
    Nf_wait_busy_even();
    Nf_write_open_C_area_even(gl_address, 0x00);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0xFF);
    Nf_wr_byte_even(0x00);
    Nf_wr_byte_even(0x00);
    Nf_wr_byte_even(0x00);
    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);
    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);
    Nf_send_command_even (NF_PAGE_PROGRAM_CMD);    /* Send program command */
  }

}



/*F**************************************************************************
* NAME:     nf_block_erase
*----------------------------------------------------------------------------
* PARAMS:   
*           
*
* RETURN:   OK : erase done
*           KO : erase not done
*
*----------------------------------------------------------------------------
* PURPOSE: Erase a block on Nand Flash Media
*         
*
*****************************************************************************
* NOTE:     
*           
*
*
*
*****************************************************************************/
bit nf_block_erase (Uint32 pos)
{
  if (nf_parity_bit == NF_ODD)
  {
    Nf_wait_busy_odd();
    Nf_send_command_odd (NF_READ_A_AREA_CMD);
    Nf_send_command_odd (NF_BLOCK_ERASE_CMD);       /* Auto Block Erase Setup     */
  
    Nf_send_address_odd ( ((Byte*)&pos)[3] );       /* 2nd address cycle          */
    Nf_send_address_odd ( ((Byte*)&pos)[2] );       /* 3rd address cycle          */
    if (NF_4_CYCLE_ADDRESS_BIT)                     /* Size of card >= 64Mbytes ? */
      Nf_send_address_odd ( ((Byte*)&pos)[1] );     /* 4th address cycle          */
    Nf_send_command_odd(NF_BLOCK_ERASE_CONFIRM_CMD);/* Erase command              */
  }
  else
  {
    Nf_wait_busy_even();
    Nf_send_command_even (NF_READ_A_AREA_CMD);
    Nf_send_command_even (NF_BLOCK_ERASE_CMD);        /* Auto Block Erase Setup     */
  
    Nf_send_address_even ( ((Byte*)&pos)[3] );        /* 2nd address cycle          */
    Nf_send_address_even ( ((Byte*)&pos)[2] );        /* 3rd address cycle          */
    if (NF_4_CYCLE_ADDRESS_BIT)                       /* Size of card >= 64Mbytes ? */
      Nf_send_address_even ( ((Byte*)&pos)[1] );      /* 4th address cycle          */
    Nf_send_command_even (NF_BLOCK_ERASE_CONFIRM_CMD);/* Erase command              */
  }

  return OK;

}


/*F**************************************************************************
* NAME:     nf_erase_all_block
*----------------------------------------------------------------------------
* PARAMS:   
*           
*
* RETURN:   
*           
*----------------------------------------------------------------------------
* PURPOSE:  This function erase all blocks on a NF card and write CIS 
*           information
*
*
*****************************************************************************
* NOTE:     
*           
*****************************************************************************/
void nf_erase_all_block(void)
{
Byte i;
Uint16 j;
Uint16 block;
Uint16 block_reserved_space;
bit erase;
 
  /* Erase all block */
  block_reserved_space = (Uint16) (((nf_reserved_space_start >> 6) % 1000));
  gl_address = 0;
  for (nf_zone = 0; nf_zone < NF_ZONE_MAX_CPT; nf_zone++)
  {
    for (j = 1024; j != 0; j--)
    {
      Nf_CS_ODD();
      Nf_wait_busy_odd();
      Nf_read_open_C_area_odd(gl_address, 0x05); /* Read block status byte */
      erase = TRUE;
      if (Nf_rd_byte_odd() != 0xFF) /* if bad block */
      {
        erase = FALSE;          /* don't erase block */
      }
      else
      {
        ((Byte*)&block)[0] = Nf_rd_byte_odd(); /* Read logical block address */
        ((Byte*)&block)[1] = Nf_rd_byte_odd();
        if ( (MEM_RESERVED_SIZE != 0) && (nf_zone == (NF_ZONE_MAX_CPT - 1)))
        {
          if ((((Byte*)&block)[0] & 0xF8) == 0x10)
          {
            block = (block & 0x0FFF) >> 1;
            if (block >= block_reserved_space)      /* If it is a reserved block */
            {
              erase = FALSE;                        /* Don't erase block */
            }
          }
        }
      }

      if (NF_FULL_CHIP_ERASE == FALSE)
      {
        if (((Byte*)&block)[0] != 0xE8)
        {
          erase = FALSE;
        }
      }
      else
      {
        if (((Byte*)&block)[0] == 0x00)
        {
          erase = FALSE;
        }
      }

      if (erase)
      {
        nf_block_erase(gl_address);
        if (nf_check_status() == KO)
        { 
          nf_mark_bad_block(); /* Failure on erase operation */     
        }
        else
        { /* Fill redundant area with 0x00 */
          Nf_write_open_C_area_odd(gl_address, 0x00);
          for (i = 16; i != 0; i--)
            Nf_wr_byte_odd(0x00);
          Nf_send_command_odd(NF_PAGE_PROGRAM_CMD);        /* Valid the page programmation */
          if ( nf_check_status() == KO)
          { 
            nf_mark_bad_block();                        /* Failure on program operation */
          }
          else
          {
            Nf_read_open_C_area_odd(gl_address, 0x00);        /* Read 16 bytes */
            i = 16;
            while ((i != 0) && (Nf_rd_byte_odd() == 0x00)) i--;

            if (i)
            {
              nf_mark_bad_block();
            }
            else
            {
              nf_block_erase(gl_address);          /* Finally, erase the block */      
              if ( nf_check_status() == KO)
              { /* Failure on erase operation */
                nf_mark_bad_block();      
              }
            }
          }
        }
      }
      Nf_CS_EVEN();
      Nf_wait_busy_even();
      Nf_read_open_C_area_even(gl_address, 0x05); /* Read block status byte */
      erase = TRUE;
      if (Nf_rd_byte_even() != 0xFF) /* if bad block */
      {
        erase = FALSE;          /* don't erase block */
      }
      else
      {
        ((Byte*)&block)[0] = Nf_rd_byte_even(); /* Read logical block address */
        ((Byte*)&block)[1] = Nf_rd_byte_even();
        if ( (MEM_RESERVED_SIZE != 0) && (nf_zone == (NF_ZONE_MAX_CPT - 1)))
        {
          if ((((Byte*)&block)[0] & 0xF8) == 0x10)
          {
            block = (block & 0x0FFF) >> 1;
            if (block >= block_reserved_space)      /* If it is a reserved block */
            {
              erase = FALSE;                        /* Don't erase block */
            }
          }
        }
      }

      if (NF_FULL_CHIP_ERASE == FALSE)
      {
        if (((Byte*)&block)[0] != 0xE8)
        {
          erase = FALSE;
        }
      }
      else
      {
        if (((Byte*)&block)[0] == 0x00)
        {
          erase = FALSE;
        }
      }

      if (erase)
      {
        nf_block_erase(gl_address);
        if (nf_check_status() == KO)
        { 
          nf_mark_bad_block(); /* Failure on erase operation */     
        }
        else
        { /* Fill redundant area with 0x00 */
          Nf_write_open_C_area_even(gl_address, 0x00);
          for (i = 16; i != 0; i--)
            Nf_wr_byte_even(0x00);
          Nf_send_command_even(NF_PAGE_PROGRAM_CMD);        /* Valid the page programmation */
          if ( nf_check_status() == KO)
          { 
            nf_mark_bad_block();                        /* Failure on program operation */
          }
          else
          {
            Nf_read_open_C_area_even(gl_address, 0x00);        /* Read 16 bytes */
            i = 16;
            while ((i != 0) && (Nf_rd_byte_even() == 0x00)) i--;

            if (i)
            {
              nf_mark_bad_block();
            }
            else
            {
              nf_block_erase(gl_address);          /* Finally, erase the block */      
              if ( nf_check_status() == KO)
              { /* Failure on erase operation */
                nf_mark_bad_block();      
              }
            }
          }
        }
      }

      gl_address += 32;
    }
  }

}




⌨️ 快捷键说明

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