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

📄 73x_flash.c

📁 国外LPC2000系列的一些源程序,请大家快快下载
💻 C
📖 第 1 页 / 共 2 页
字号:
* Return         : The data value at the specified address.
*******************************************************************************/
u32 FLASH_WordRead(u32 SourceAddr)
{
  /* wait for the end of last task */
  FLASH_WaitForLastTask();

  /* add the Flash offset(0x80000000) to SourceAddr and return the word value
   pointed by this absolute address */
  return(*(u32 *)(FLASH_Base + SourceAddr ));
}

/*******************************************************************************
* Function Name  : FLASH_BlockRead
* Description    : Reads a block of data from a specified address in the Flash
*                  and store it in the RAM.
* Input          : - SourceAddr: specifies the address, in the Flash, of the
*                    block of data to be read.
*                  - DestAddr: specifies the destination address in the RAM
*                    where that data will be copied.
*                  - NbrWordToRead: specifies the number of words to be read
*                    from the Flash.
* Output         : None
* Return         : None
*******************************************************************************/
void FLASH_BlockRead(u32 SourceAddr, u32 DestAddr, u32 NbrWordToRead)
{
  /* wait for the end of last task */
  FLASH_WaitForLastTask();

  while(NbrWordToRead--) /* while the whole data are not yet read */
  {
    *(u32 *)DestAddr = *(u32 *)(FLASH_Base + SourceAddr);

    /* increase the source address */
    SourceAddr += 4;

    /* increase the destination address */
    DestAddr += 4;
  }
}

/*******************************************************************************
* Function Name  : FLASH_SectorErase
* Description    : Erases the specified Flash sectors.
* Input          : FLASH_Sector: sectors to be erased. This parameter can be
*                  any combination of the following values:
*                         - FLASH_SectorX: Bank0 Flash SectorX will be erased
*                           (X can be [0..7])
*                         - FLASH_Module: All Bank0 Sectors will be erased
* Output         : None
* Return         : None
*******************************************************************************/
void FLASH_SectorErase(u8 FLASH_Sector)
{
  /* wait for the end of last task */
  FLASH_WaitForLastTask();

  /* set the SER bit in CR0 register */
  FLASHR->CR0 |= FLASH_SER;

  /* select the sectors to be erased in the CR1 register */
  FLASHR->CR1 |= FLASH_Sector;

  /* set the start bit WMS in CR0 register */
  FLASHR->CR0 |= FLASH_WMS;
}

/*******************************************************************************
* Function Name  : FLASH_Suspend
* Description    : Suspends an on-going operation on the Flash.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void FLASH_Suspend(void)
{
  /* set the SUSP bit in CR0 register */
  FLASHR->CR0 |= FLASH_SUSP;

  /* wait for the end of last task */
  FLASH_WaitForLastTask();
}

/*******************************************************************************
* Function Name  : FLASH_Resume
* Description    : Resumes a suspended operation on the Flash.
* Input          : OperToResume: specifies the operation that has been
*                  suspended and needs to be resumed. This parameter can be
*                  one of the following values:
*                         - FLASH_SER: Sector Erase operation will be resumed
*                         - FLASH_WPG: Word Program operation will be resumed
*                         - FLASH_DWPG: Double Word Program operation will be resumed
* Output         : None
* Return         : None
*******************************************************************************/
void FLASH_Resume(u32 OperToResume)
{
  /* clear the SUSP bit in CR0 register */
  FLASHR->CR0 &= ~FLASH_SUSP;

  /* configure CR0 register with the operation that needs to be resumed */
  FLASHR->CR0 |= OperToResume;

  /* set the start bit WMS in CR0 register */
  FLASHR->CR0 |= FLASH_WMS;
}

/*******************************************************************************
* Function Name  : FLASH_FlagStatus
* Description    : Checks whether the specified Flash flag is set or not.
* Input          : FLASH_Flag: flag to check. This parameter can be one of the
*                  following values:
*                         - FLASH_FLAG_BSY0: Bank0 busy flag
*                         - FLASH_FLAG_LOCK: Flash register access locked flag
*                         - FLASH_FLAG_JBL: JTAG boot mode latched flag
*                         - FLASH_FLAG_INTP: End of write interrupt pending flag
*                         - FLASH_FLAG_BSM: Boot from system memory flag
*                         - FLASH_FLAG_ERR: Write error flag
*                         - FLASH_FLAG_ERER: Erase error flag
*                         - FLASH_FLAG_PGER: Program error flag
*                         - FLASH_FLAG_10ER: 1 over 0 error flag
*                         - FLASH_FLAG_SEQER: Sequence error flag
*                         - FLASH_FLAG_RESER: Resume error flag
*                         - FLASH_FLAG_WPF: Write protection flag
* Output         : None
* Return         : The new state of FLASH_Flag (SET or RESET).
*******************************************************************************/
FlagStatus FLASH_FlagStatus(u8 FLASH_Flag)
{
  u8 FlashReg = 0, FlagPos = 0;

  /* get the Flash register index */
  FlashReg = FLASH_Flag >> 5;

  /* get the flag position */
  FlagPos = FLASH_Flag & FLASH_Flag_Mask;

  if(FlashReg == 1) /* the flag to check is in CR0 register */
  {  
    if((FLASHR->CR0 & (1<<FlagPos))!= RESET)
    {
      return SET;
    }
    else
    {
      return RESET;
    }
  } 
  else /* (FlashReg == 2 )  The flag to check is in ER register */
  {   
    if((FLASHR->ER & (1<<FlagPos)) != RESET)
    {
      return SET;
    }
    else
    {
      return RESET;
    }
  }
}

/*******************************************************************************
* Function Name  : FLASH_FlagClear
* Description    : Clears the specified Flash flag.
* Input          : FLASH_Flag: flag to clear. This parameter can be
*                  one of the following values:
*                         - FLASH_FLAG_JBL: JTAG boot mode latched flag
*                         - FLASH_FLAG_INTP: End of write interrupt pending flag
*                         - FLASH_FLAG_BSM: Boot from system memory flag
*                         - FLASH_FLAG_ERR: Write error flag
*                         - FLASH_FLAG_ERER: Erase error flag
*                         - FLASH_FLAG_PGER: Program error flag
*                         - FLASH_FLAG_10ER: 1 over 0 error flag
*                         - FLASH_FLAG_SEQER: Sequence error flag
*                         - FLASH_FLAG_RESER: Resume error flag
*                         - FLASH_FLAG_WPF: Write protection flag
* Output         : None
* Return         : None
*******************************************************************************/
void FLASH_FlagClear(u8 FLASH_Flag)
{
  u8 FlashReg = 0, FlagPos = 0;

  /* get the Flash register index */
  FlashReg = FLASH_Flag >> 5;

  /* get the flag position */
  FlagPos = FLASH_Flag & FLASH_Flag_Mask;

  switch(FlashReg)
  {
    case 1 : /* the flag to clear is in CR0 register */
      FLASHR->CR0 &= ~(1<<FlagPos);
    break;

    case 2 : /* the flag to clear is in ER register */
      FLASHR->ER &= ~(1<<FlagPos);
    break;
  }
}

/*******************************************************************************
* Function Name  : FLASH_WaitForLastTask
* Description    : Waits for the end of last task.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
static void FLASH_WaitForLastTask(void)
{
  /* wait until the Flash controller acknowledges the end of the last
    operation resetting the BSY0 and LOCK bits in the CR0 register */
  while((FLASHR->CR0 & FLASH_FLAG_LOCKBSY0) != RESET);
}

/*******************************************************************************
* Function Name  : FLASH_PowerDownConfig
* Description    : Enables or disables the Flash power down mode.
* Input          : NewState : new state of the Flash power down mode.
*                  This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void FLASH_PowerDownConfig(FunctionalState NewState)
{
  if(NewState == ENABLE)
  { /* enable Flash power down mode */
    FLASHR->CR0  |= FLASH_PWD;
  }
  else
  { /* disable Flash power down mode */
    FLASHR->CR0  &= ~FLASH_PWD;
  }
}

/******************* (C) COPYRIGHT 2005 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

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