stm32f10x_fsmc.c

来自「stm32 ucos 精简移殖版本 不需作任何修改直接便可运行。包含串口 定时器」· C语言 代码 · 共 864 行 · 第 1/3 页

C
864
字号
  {
    /* Disable the selected NAND Bank ECC function by clearing the ECCEN bit in the PCRx register */
    if(FSMC_Bank == FSMC_Bank2_NAND)
    {
      FSMC_Bank2->PCR2 &= PCR_ECCEN_Reset;
    }
    else
    {
      FSMC_Bank3->PCR3 &= PCR_ECCEN_Reset;
    }
  }
}

/*******************************************************************************
* Function Name  : FSMC_GetECC
* Description    : Returns the error correction code register value.
* Input          : - FSMC_Bank: specifies the FSMC Bank to be used
*                    This parameter can be one of the following values:
*                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
*                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
* Output         : None
* Return         : The Error Correction Code (ECC) value.
*******************************************************************************/
u32 FSMC_GetECC(u32 FSMC_Bank)
{
  u32 eccval = 0x00000000;
  
  if(FSMC_Bank == FSMC_Bank2_NAND)
  {
    /* Get the ECCR2 register value */
    eccval = FSMC_Bank2->ECCR2;
  }
  else
  {
    /* Get the ECCR3 register value */
    eccval = FSMC_Bank3->ECCR3;
  }
  /* Return the error correction code value */
  return(eccval);
}

/*******************************************************************************
* Function Name  : FSMC_ITConfig
* Description    : Enables or disables the specified FSMC interrupts.
* Input          : - FSMC_Bank: specifies the FSMC Bank to be used
*                    This parameter can be one of the following values:
*                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
*                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
*                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
*                  - FSMC_IT: specifies the FSMC interrupt sources to be
*                    enabled or disabled.
*                    This parameter can be any combination of the following values:
*                       - FSMC_IT_RisingEdge: Rising edge detection interrupt. 
*                       - FSMC_IT_Level: Level edge detection interrupt.                                  
*                       - FSMC_IT_FallingEdge: Falling edge detection interrupt.
*                  - NewState: new state of the specified FSMC interrupts.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void FSMC_ITConfig(u32 FSMC_Bank, u32 FSMC_IT, FunctionalState NewState)
{
  assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  assert_param(IS_FSMC_IT(FSMC_IT));	
  assert_param(IS_FUNCTIONAL_STATE(NewState));
  
  if (NewState != DISABLE)
  {
    /* Enable the selected FSMC_Bank2 interrupts */
    if(FSMC_Bank == FSMC_Bank2_NAND)
    {
      FSMC_Bank2->SR2 |= FSMC_IT;
    }
    /* Enable the selected FSMC_Bank3 interrupts */
    else if (FSMC_Bank == FSMC_Bank3_NAND)
    {
      FSMC_Bank3->SR3 |= FSMC_IT;
    }
    /* Enable the selected FSMC_Bank4 interrupts */
    else
    {
      FSMC_Bank4->SR4 |= FSMC_IT;    
    }
  }
  else
  {
    /* Disable the selected FSMC_Bank2 interrupts */
    if(FSMC_Bank == FSMC_Bank2_NAND)
    {
      
      FSMC_Bank2->SR2 &= (u32)~FSMC_IT;
    }
    /* Disable the selected FSMC_Bank3 interrupts */
    else if (FSMC_Bank == FSMC_Bank3_NAND)
    {
      FSMC_Bank3->SR3 &= (u32)~FSMC_IT;
    }
    /* Disable the selected FSMC_Bank4 interrupts */
    else
    {
      FSMC_Bank4->SR4 &= (u32)~FSMC_IT;    
    }
  }
}
                  
/*******************************************************************************
* Function Name  : FSMC_GetFlagStatus
* Description    : Checks whether the specified FSMC flag is set or not.
* Input          : - FSMC_Bank: specifies the FSMC Bank to be used
*                    This parameter can be one of the following values:
*                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
*                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
*                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
*                  - FSMC_FLAG: specifies the flag to check.
*                    This parameter can be one of the following values:
*                       - FSMC_FLAG_RisingEdge: Rising egde detection Flag.
*                       - FSMC_FLAG_Level: Level detection Flag.
*                       - FSMC_FLAG_FallingEdge: Falling egde detection Flag.
*                       - FSMC_FLAG_FEMPT: Fifo empty Flag. 
* Output         : None
* Return         : The new state of FSMC_FLAG (SET or RESET).
*******************************************************************************/                   
FlagStatus FSMC_GetFlagStatus(u32 FSMC_Bank, u32 FSMC_FLAG)
{
  FlagStatus bitstatus = RESET;
  u32 tmpsr = 0x00000000;
  
  /* Check the parameters */
  assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  assert_param(IS_FSMC_GET_FLAG(FSMC_FLAG));
  
  if(FSMC_Bank == FSMC_Bank2_NAND)
  {
    tmpsr = FSMC_Bank2->SR2;
  }  
  else if(FSMC_Bank == FSMC_Bank3_NAND)
  {
    tmpsr = FSMC_Bank3->SR3;
  }
  /* FSMC_Bank4_PCCARD*/
  else
  {
    tmpsr = FSMC_Bank4->SR4;
  } 
  
  /* Get the flag status */
  if ((tmpsr & FSMC_FLAG) != (u16)RESET )
  {
    bitstatus = SET;
  }
  else
  {
    bitstatus = RESET;
  }
  /* Return the flag status */
  return bitstatus;
}

/*******************************************************************************
* Function Name  : FSMC_ClearFlag
* Description    : Clears the FSMC抯 pending flags.
* Input          : - FSMC_Bank: specifies the FSMC Bank to be used
*                    This parameter can be one of the following values:
*                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
*                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
*                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
*                  - FSMC_FLAG: specifies the flag to clear.
*                    This parameter can be any combination of the following values:
*                       - FSMC_FLAG_RisingEdge: Rising egde detection Flag.
*                       - FSMC_FLAG_Level: Level detection Flag.
*                       - FSMC_FLAG_FallingEdge: Falling egde detection Flag.
* Output         : None
* Return         : None
*******************************************************************************/                   
void FSMC_ClearFlag(u32 FSMC_Bank, u32 FSMC_FLAG)
{
 /* Check the parameters */
  assert_param(IS_FSMC_GETFLAG_BANK(FSMC_Bank));
  assert_param(IS_FSMC_CLEAR_FLAG(FSMC_FLAG)) ;
    
  if(FSMC_Bank == FSMC_Bank2_NAND)
  {
    FSMC_Bank2->SR2 &= ~FSMC_FLAG; 
  }  
  else if(FSMC_Bank == FSMC_Bank3_NAND)
  {
    FSMC_Bank3->SR3 &= ~FSMC_FLAG;
  }
  /* FSMC_Bank4_PCCARD*/
  else
  {
    FSMC_Bank4->SR4 &= ~FSMC_FLAG;
  }
}

/*******************************************************************************
* Function Name  : FSMC_GetITStatus
* Description    : Checks whether the specified FSMC interrupt has occurred or not.
* Input          : - FSMC_Bank: specifies the FSMC Bank to be used
*                    This parameter can be one of the following values:
*                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
*                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
*                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
*                  - FSMC_IT: specifies the FSMC interrupt source to check.
*                    This parameter can be one of the following values:
*                       - FSMC_IT_RisingEdge: Rising edge detection interrupt. 
*                       - FSMC_IT_Level: Level edge detection interrupt.                                  
*                       - FSMC_IT_FallingEdge: Falling edge detection interrupt. 
* Output         : None
* Return         : The new state of FSMC_IT (SET or RESET).
*******************************************************************************/ 
ITStatus FSMC_GetITStatus(u32 FSMC_Bank, u32 FSMC_IT)
{
  ITStatus bitstatus = RESET;
  u32 tmpsr = 0x0, itstatus = 0x0, itenable = 0x0; 
  
  /* Check the parameters */
  assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  assert_param(IS_FSMC_GET_IT(FSMC_IT));
  
  if(FSMC_Bank == FSMC_Bank2_NAND)
  {
    tmpsr = FSMC_Bank2->SR2;
  }  
  else if(FSMC_Bank == FSMC_Bank3_NAND)
  {
    tmpsr = FSMC_Bank3->SR3;
  }
  /* FSMC_Bank4_PCCARD*/
  else
  {
    tmpsr = FSMC_Bank4->SR4;
  } 
  
  itstatus = tmpsr & FSMC_IT;
  
  itenable = tmpsr & (FSMC_IT >> 3);

  if ((itstatus != (u32)RESET)  && (itenable != (u32)RESET))
  {
    bitstatus = SET;
  }
  else
  {
    bitstatus = RESET;
  }
  return bitstatus; 
}

/*******************************************************************************
* Function Name  : FSMC_ClearITPendingBit
* Description    : Clears the FSMC抯 interrupt pending bits.
* Input          : - FSMC_Bank: specifies the FSMC Bank to be used
*                    This parameter can be one of the following values:
*                       - FSMC_Bank2_NAND: FSMC Bank2 NAND 
*                       - FSMC_Bank3_NAND: FSMC Bank3 NAND
*                       - FSMC_Bank4_PCCARD: FSMC Bank4 PCCARD
*                  - FSMC_IT: specifies the interrupt pending bit to clear.
*                    This parameter can be any combination of the following values:
*                       - FSMC_IT_RisingEdge: Rising edge detection interrupt. 
*                       - FSMC_IT_Level: Level edge detection interrupt.                                  
*                       - FSMC_IT_FallingEdge: Falling edge detection interrupt.
* Output         : None
* Return         : None
*******************************************************************************/
void FSMC_ClearITPendingBit(u32 FSMC_Bank, u32 FSMC_IT)
{
  /* Check the parameters */
  assert_param(IS_FSMC_IT_BANK(FSMC_Bank));
  assert_param(IS_FSMC_IT(FSMC_IT));
    
  if(FSMC_Bank == FSMC_Bank2_NAND)
  {
    FSMC_Bank2->SR2 &= ~(FSMC_IT >> 3); 
  }  
  else if(FSMC_Bank == FSMC_Bank3_NAND)
  {
    FSMC_Bank3->SR3 &= ~(FSMC_IT >> 3);
  }
  /* FSMC_Bank4_PCCARD*/
  else
  {
    FSMC_Bank4->SR4 &= ~(FSMC_IT >> 3);
  }
}

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

⌨️ 快捷键说明

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