新闻  |   论坛  |   博客  |   在线研讨会
AT45DB161D 擦除算法
0750long | 2009-04-02 17:23:06    阅读:1695   发布文章

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;
  }

}

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客