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

📄 d_loader.r

📁 乐高机器人的源码,开发平台是IAR_for_AVR.
💻 R
字号:
//
// Date init       14.12.2004
//
// Revision date   $Date:: 16-05-06 8:27                                     $
//
// Filename        $Workfile:: d_loader.r                                    $
//
// Version         $Revision:: 8                                             $
//
// Archive         $Archive:: /LMS2006/Sys01/Main/Firmware/Source/d_loader.r $
//
// Platform        C
//

#ifdef    SAM7S256

#define   AT91C_MC_CORRECT_KEY          0x5A000000L

static    ULONG   SectorImage[SECTORSIZE>>2];

#define   LOADERInit


__ramfunc UWORD AT91F_Flash_Ready (void)
{
  UWORD status;
  status = 0;

  //* Wait the end of command
  while ((status & AT91C_MC_FRDY) != AT91C_MC_FRDY )
  {
    status = AT91C_BASE_MC->MC_FSR;
  }
  return status;
}

__ramfunc UWORD      dLoaderWritePage(ULONG Flash_Address, UWORD Size, ULONG *pBuf)
{
  //* set the Flash controller base address
  AT91PS_MC ptMC = AT91C_BASE_MC;
  unsigned int i, page, status;
  unsigned int * Flash;

  //* init flash pointer
  Flash = (unsigned int *) (Flash_Address | (unsigned int)AT91C_IFLASH);

  //* Get the Flash page number
  page = ((Flash_Address & ~(unsigned int)AT91C_IFLASH) >> SECTORSIZESHIFT);

  //* copy the new value
  if (Size & 0x0003)
  {
    Size = Size + (0x0004 - (Size & 0x0003));
  }
	for (i=0; (i < SECTORSIZE) & (Size > 0) ;i++, Flash++,pBuf++,Size-=4 )
  {
	  //* copy the flash to the write buffer ensuring code generation
	  *Flash=*pBuf;
	}

  //* Write the write page command
  ptMC->MC_FCR = AT91C_MC_CORRECT_KEY | AT91C_MC_FCMD_START_PROG | (AT91C_MC_PAGEN & (page <<8));

  //* Wait the end of command
  status = AT91F_Flash_Ready();

  //* Check the result
  if ( (status & ( AT91C_MC_PROGE | AT91C_MC_LOCKE ))!=0)
  {
    return FALSE;
  }
  return TRUE;

}

__ramfunc UWORD      dLoaderErasePage(ULONG Flash_Address)
{
  //* set the Flash controller base address
  AT91PS_MC ptMC = AT91C_BASE_MC;
  unsigned int i, page, status, Size;
  unsigned int * Flash;

  Size = SECTORSIZE;

  //* init flash pointer
  Flash = (unsigned int *) (Flash_Address | (unsigned int)AT91C_IFLASH);

  //* Get the Flash page number
  page = ((Flash_Address & ~(unsigned int)AT91C_IFLASH) >> SECTORSIZESHIFT);

  //* copy the new value
	for (i=0; (i < SECTORSIZE) & (Size > 0) ;i++, Flash++,Size-=4 )
  {
	  //* copy the flash to the write buffer ensuring code generation
	  *Flash=0xFFFFFFFF;
	}

  //* Write the write page command
  ptMC->MC_FCR = AT91C_MC_CORRECT_KEY | AT91C_MC_FCMD_START_PROG | (AT91C_MC_PAGEN & (page <<8));

  //* Wait the end of command
  status = AT91F_Flash_Ready();

  //* Check the result
  if ( (status & ( AT91C_MC_PROGE | AT91C_MC_LOCKE ))!=0)
  {
    return FALSE;
  }
  return TRUE;

}





#endif

⌨️ 快捷键说明

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