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

📄 91x_fmi.c

📁 STR912 arm9实现的以太网通信程序
💻 C
📖 第 1 页 / 共 2 页
字号:

  return OTP_Data;
}

/*******************************************************************************
* Function Name  : FMI_GetFlagStatus
* Description    : Check whether the specified FMI flag is set or not.
* Input1         : FMI_Flag: flag to check.
*                  This parameter can be one of the following values:
*                     - FMI_FLAG_SPS: Sector Protection Status Flag.
*                     - FMI_FLAG_PSS: Program Suspend Status Flag.
*                     - FMI_FLAG_PS: Program Status Flag.
*                     - FMI_FLAG_ES: Erase Status Flag.
*                     - FMI_FLAG_ESS: Erase Suspend Status Flag.
*                     - FMI_FLAG_PECS: FPEC Status Flag.
* Input2         : FMI_Bank: specifies the needed bank.
*                  This parameter can be one of the following values:
*                     - FMI_BANK_0: FMI bank 0.
*                     - FMI_BANK_1: FMI bank 1.
* Output         : None
* Return         : None
*******************************************************************************/
FlagStatus FMI_GetFlagStatus(u8 FMI_Flag, vu32 FMI_Bank)
{    
  u16 FMI_Status_Register = 0;

  /* Write a read status register command */
  *(vu16 *)FMI_Bank = 0x70;

  /* Wait until operation completion */
  while(!((*(vu16 *)FMI_Bank) & 0x80));

  /* Read the status register */
  FMI_Status_Register = *(vu16 *)FMI_Bank;

  /* Write a read array command */
  *(vu16 *)FMI_Bank = 0xFF;
   
  if((FMI_Status_Register & FMI_Flag) != RESET)
  {
    return SET;
  }
  else
  {
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : FMI_GetReadWaitStateValue
* Description    : Get the current Read wait state value.
* Input          : None
* Output         : None
* Return         : The current read wait states value.
*******************************************************************************/
u16 FMI_GetReadWaitStateValue(void)
{ 
  u16 FMI_Configuration_Register = 0;
  /*Write a read RSIG command to any word address in Bank1*/
  *(vu16 *)FMI_BANK_1 = 0x90;

  /* Read the flash configuration register */
#ifdef Flash_512KB_256KB
  FMI_Configuration_Register = *(vu16 *)(FMI_BANK_1 + 0x14);
#endif

#ifdef  Flash_2MB_1MB
  FMI_Configuration_Register = *(vu16 *)(FMI_BANK_1 + 0x1C);
#endif
  /* Write a read array command */
  *(vu16 *)FMI_BANK_1 = 0xFF;

  FMI_Configuration_Register = ((FMI_Configuration_Register >> 11) + 1) & 0x3;

  /* Return the wait states value */
  return FMI_Configuration_Register;
}

/*******************************************************************************
* Function Name  : FMI_GetWriteWaitStateValue
* Description    : Get the current write wait state value.
* Input          : None
* Output         : None
* Return         : The current write wait states value.
*******************************************************************************/
u16 FMI_GetWriteWaitStateValue(void)
{
  return ((u16)((FMI->CR & 0x100) >> 8));
}

/*******************************************************************************
* Function Name  : FMI_SuspendEnable
* Description    : Suspend command enable.
* Input          : FMI_Bank: specifies the bank to be suspended.
*                  This parameter can be one of the following values:
*                     - FMI_BANK_0: FMI bank 0.
*                     - FMI_BANK_1: FMI bank 1.
* Output         : None
* Return         : None
*******************************************************************************/
void FMI_SuspendEnable(vu32 FMI_Bank)
{
  /* Write a suspend command to the bank */
  *(vu16 *)FMI_Bank = 0xB0;
}

/*******************************************************************************
* Function Name  : FMI_ResumeEnable
* Description    : Resume the suspended command.
* Input          : FMI_Bank: specifies the suspended bank.
*                  This parameter can be one of the following values:
*                     - FMI_BANK_0: FMI bank 0.
*                     - FMI_BANK_1: FMI bank 1.
* Output         : None
* Return         : None
*******************************************************************************/
void FMI_ResumeEnable(vu32 FMI_Bank)
{
  /* Write a resume command to the bank */
  *(vu16 *)FMI_Bank = 0xD0;
}

/*******************************************************************************
* Function Name  : FMI_ClearFlag
* Description    : Clear the FMI Flags on the correspondent bank.
* Input          : FMI_Bank: specifies the needed bank.
*                  This parameter can be one of the following values:
*                     - FMI_BANK_0: FMI bank 0.
*                     - FMI_BANK_1: FMI bank 1.
* Output         : None
* Return         : None
*******************************************************************************/
void FMI_ClearFlag(vu32 FMI_Bank)
{
  /* Write a clear status register command */
  *(vu16 *)FMI_Bank = 0x50;
}

/*******************************************************************************
* Function Name  : FMI_WriteProtectionCmd
* Description    : Enable or disable the write protection for the needed sector.
* Input1         : FMI_Sector: specifies the sector to be protected or   
*                  unprotected. 
*                  This parameter can be one of the following values:
*
*                     - FMI_B0S0:  FMI bank 0 sector 0. 
*                       ...
*                     - FMI_B0S31: FMI bank 0 sector 31.
*
*
*                     - FMI_B1S0: FMI bank 1 sector 0.
*                      ...
*                     - FMI_B1S7: FMI bank 1 sector 7.
*
* Input2         : FMI_NewState: specifies the protection status.
*                  This parameter can be one of the following values:
*                     - ENABLE:  Enable the protection.
*                     - DISABLE: Disable the protection.
* Output         : None
* Return         : None
*******************************************************************************/
void FMI_WriteProtectionCmd(vu32 FMI_Sector, FunctionalState FMI_NewState)
{
  if (FMI_NewState == ENABLE)
  {
    *(vu16*)FMI_Sector = 0x60;
    *(vu16*)FMI_Sector = 0x01;
    *(vu16*)FMI_Sector = 0xFF;
  }
  else /* DISABLE */
  {
    *(vu16*)FMI_Sector = 0x60;
    *(vu16*)FMI_Sector = 0xD0;
    *(vu16*)FMI_Sector = 0xFF;
  }
}


/*******************************************************************************
* Function Name  : FMI_WaitForLastOperation
* Description    : Wait until the last operation (Write halfword, Write OTP 
*                  halfword, Erase sector and Erase bank) completion.
* Input          : FMI_Bank: specifies the bank where the operation is on going.
*                  This parameter can be one of the following values:
*                     - FMI_BANK_0: FMI bank 0.
*                     - FMI_BANK_1: FMI bank 1.
* Output         : None
* Return         : The timeout status.
*                  This parameter can be one of the following values:
*                     - FMI_TIME_OUT_ERROR: Timeout error occurred.
*                     - FMI_NO_TIME_OUT_ERROR: No timeout error.
*******************************************************************************/
u8 FMI_WaitForLastOperation(vu32 FMI_Bank)
{
  u32 Time_Out = 0;
 
  /* Write a read status register command */
  *(vu16 *)(FMI_Bank) = 0x70;

  /* Wait until operation compeletion */
  while((!((*(vu16 *)FMI_Bank) & 0x80))&&(Time_Out < TIMEOUT ))
  {
    Time_Out ++;  /* Time Out */
  }

  /* Write a read array command */
  *(vu16 *)FMI_Bank = 0xFF;
 
  if (Time_Out == TIMEOUT)
  {
    return FMI_TIME_OUT_ERROR;
  }
  else
  {
    return FMI_NO_TIME_OUT_ERROR;
  }
}

/*******************************************************************************
* Function Name  : FMI_ReadRSIGData
* Description    : Read the Electronic Signature stored in the user configuration 
*                  sector of Bank 1.
* Input          :  FMI_LSB_RSIGAddress: specifies the low byte of the address
*                   to select the register.
*                  This parameter can be one of the following values:
*                     - FMI_ReadRSIGData_0. 
*                     - FMI_ReadRSIGData_1. 
*                     - FMI_ReadRSIGData_2. 
*                     - FMI_ReadRSIGData_3. 
*                     - FMI_ReadRSIGData_4. 
*                     - FMI_ReadRSIGData_5.
*                     - FMI_ReadRSIGData_6. 
*                     - FMI_ReadRSIGData_7. 
*                     
* Output         : None
* Return         : The needed RSIG data.
*******************************************************************************/

u32 FMI_ReadRSIGData(u8 FMI_LSB_RSIGAddress)
{
  u32 RSIG_Data = 0x0;
  
  /*Write a read RSIG command to any word address in Bank1*/ 
  *(vu16 *)(FMI_BANK_1) = 0x90; 
  
  /*Read any RSIG register from any address in Bank1*/ 
  RSIG_Data = (*(vu32*)(FMI_BANK_1 + (FMI_LSB_RSIGAddress<<2))); 

  /*write a Read Array command (FFh) to any word address in Bank 1 to*/
  /*return it to Read Array mode.*/
  *(vu16 *)FMI_BANK_1 = 0xFF; 

  return RSIG_Data;
}

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

⌨️ 快捷键说明

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