这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » AT45DB161D 擦除算法

共1条 1/1 1 跳转至

AT45DB161D 擦除算法

专家
2009-03-30 12:18:44     打赏
AT45DB161D 擦除算法

 

// 1 Chip = 16 Sectors = 512 Blocks = 4096 Pages
//            1 Sector = 32 Blocks  = 256 Pages
//                          1 Block = 8 Pages
//------------------------------------------------------------------------------
// Pm ... Pn [Bm ... Bn] [Sm ... Sn] [Bm ... Bn] Pm ... Pn
//------------------------------------------------------------------------------
// Caller must make dwAddress in Page boundary
// Example : AT45_ErasePages(247*512, 1+1*8+1*256+1*8+1);
//
void AT45_ErasePages(u32 dwAddress, u32 dwPageCount)
{

  if ( dwPageCount == 0)
    return;

  if ( ( dwAddress == 0) && ( dwPageCount >= 4096) )
  {
    AT45_ChipErase();
    return;
  }

  if ( dwPageCount >= 256 )
  {
    if ( (dwAddress & 0x1FFFF) == 0x00000000 )   // At Sector boundary
    {
      while ( dwPageCount >= 256 )
      {
        AT45_SectorErase(dwAddress);
        dwAddress += 256 * 512;
        dwPageCount -= 256;
      }

      BOOT_AT45_ErasePages(dwAddress, dwPageCount);
      return;
    }
  }

  if ( dwPageCount >= 8 )                      // Erase Blocks until Sector boundary
  {
    if ( (dwAddress & 0xFFF) == 0x00000000 )   // At Block boundary
    {
      while ( dwPageCount >= 8 )
      {
        if ( (dwAddress & 0x1FFFF) == 0x00000000 )   // At Sector boundary
        {
          if ( dwPageCount >= 256 )
          {
            BOOT_AT45_ErasePages(dwAddress, dwPageCount);
            return;
          }
        }

        AT45_BlockErase(dwAddress);
        dwAddress += 8 * 512;
        dwPageCount -= 8;
      }

      BOOT_AT45_ErasePages(dwAddress, dwPageCount);
      return;

    }
  }

  while ( dwPageCount > 0 )                    // Erase Pages until Block boundary
  {
    if ( (dwAddress & 0xFFF) == 0x00000000 )   // At Block boundary
    {
      if ( dwPageCount >= 8 )
      {
        BOOT_AT45_ErasePages(dwAddress, dwPageCount);
        return;
      }
    }

    AT45_PageErase(dwAddress);
    dwAddress += 1*512;
    dwPageCount -= 1;
  }

}




关键词: AT45DB161D     擦除     算法     dwAddres    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]