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

📄 71x_rccu.c

📁 STR7系列32位ARM控制器的固件库
💻 C
📖 第 1 页 / 共 2 页
字号:
  else
  {
    return RCCU_USBCK;
  }
}

/*******************************************************************************
* Function Name  : RCCU_FrequencyValue
* Description    : Computes and Returns any internal RCCU clock frequency
*                  value passed in parametres.
* Input          : - Internal_Clk: the RCCU internal clock to compute the
*                    frequency.
*                     it can be:
*                     RCCU_CLK2, RCCU_RCLK, RCCU_MCLK, RCCU_PCLK2, RCCU_PCLK1
* Output         : None.
* Return         : The frequency value of the specified clock in Hz of the 
*                  internal clock passed in parameter.
*******************************************************************************/
u32 RCCU_FrequencyValue (RCCU_Clocks Internal_Clk)
{
  u32 Tmp;
  u8 Div = 0;
  u8 Mul = 0;
  RCCU_RCLK_Clocks CurrentRCLK;
 
  if (RCCU_Div2Status() == SET)
  {
    Tmp = RCCU_Main_Osc / 2;	
  }
  else
  {
    Tmp = RCCU_Main_Osc;
  }

  if (Internal_Clk == RCCU_CLK2)
  {
    Div = 1;
    Mul = 1;
  }
  
  else
  {
    CurrentRCLK = RCCU_RCLKClockSource ();
    switch (CurrentRCLK)
    {
      case RCCU_CLOCK2_16 :
        Div = 16;
        Mul = 1;
        break;
        
      case RCCU_CLOCK2 :
        Div = 1;
        Mul = 1;
        break;
        
      case RCCU_PLL1_Output :
      
       if ((RCCU->PLL1CR & RCCU_DX_Mask)&&(RCCU->PLL1CR & RCCU_FREEN_Mask))
        {
          if (RCCU->PLL1CR & 0x10)
          {
            if (RCCU->PLL1CR & RCCU_FREFRANGE_Mask)
            {
              Tmp = 250000;	
            }
            else
            {
              Tmp = 125000;	
            }
          }
          else
          {
            if (RCCU->PLL1CR & RCCU_FREFRANGE_Mask)
            {
              Tmp = 500000;	
            }
            else
            {
              Tmp = 250000;	
            }
          }
          
          Div = 1;
          Mul = 1;
        }
        
       else
       {
         Mul = (RCCU->PLL1CR & RCCU_MX_Mask) >> RCCU_MX_Index;
        
         switch (Mul)
         {
           case 0:
             Mul = 20;
             break;
            
           case 1:
             Mul = 12;
             break;
            
           case 2:
             Mul = 24;
             break;
            
           case 3:
             Mul = 16;
             break;
         }
        
        Div = (RCCU->PLL1CR & RCCU_DX_Mask) + 1;
        }
        break;
        
      case RCCU_CK_AF :
        Mul = 1;
        Div = 1;
        Tmp = RCCU_RTC_Osc;
        break;
    }
  }

  switch (Internal_Clk)
  {
    case RCCU_MCLK :
      Div <<= PCU->MDIVR & RCCU_FACT_Mask;
      break;
      
    case RCCU_PCLK2 :
      Div <<= (PCU->PDIVR & RCCU_FACT2_Mask) >> RCCU_FACT2_Index;
      break;

    case RCCU_PCLK1 :
      Div <<=  PCU->PDIVR & 0x3;
      break;
  }

  return (Tmp * Mul) / Div;
}

/*******************************************************************************
* Function Name  : RCCU_ITConfig
* Description    : Configures the RCCU interrupts
* Input          : - RCCU_IT: the RCCU interrption source it can be:
*                     RCCU_CK2_16_IT, RCCU_CKAF_IT, RCCU_PLL1_LOCK_IT,
*                     RCCU_STOP_IT
*                  - NewState: the new status of the RCCU interrupt.
*                     it can be:
*                     ENABLE: to enable the specified interrupt.
*                     DISABLE: to disable the specified interrupt.
* Output         : None.
* Return         : None.
*******************************************************************************/
void RCCU_ITConfig (RCCU_Interrupts RCCU_IT, FunctionalState NewState)
{
  if (NewState == ENABLE)
  {
    RCCU->CCR |= RCCU_IT;
  }
  else
  {
    RCCU->CCR &= ~RCCU_IT;
  }
}

/*******************************************************************************
* Function Name  : RCCU_FlagStatus
* Description    : Checks whether the specified interrupt is enabled or
*                  disabled.
* Input          : - RCCU flag: the flag to see its status it can be:
*                     RCCU_CK2_16_I, RCCU_CKAF_I, RCCU_PLL1_LOCK_I,
*                     RCCU_CKAF_ST, RCCU_PLL1_LOCK, RCCU_STOP_I
* Output         : None.
* Return         : The flag status: SET or RESET
*******************************************************************************/
FlagStatus RCCU_FlagStatus (RCCU_Flags RCCU_flag)
{
  if (RCCU->CFR & RCCU_flag)
  {
    return SET;
  }
  else
  {
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : RCCU_FlagClear
* Description    : Clears the specified interrupt flag in the RCCU registers 
*                  passed in parameter.
* Input          : - RCCU_Flags: the flag wich will be cleared it can be:
*                     RCCU_PLL1_LOCK_I, RCCU_CKAF_I, RCCU_CK2_16_I, RCCU_STOP_I
* Output         : None.
* Return         : None.
*******************************************************************************/
void RCCU_FlagClear (RCCU_Flags RCCU_flag)
{
  RCCU->CFR |= RCCU_flag;
}

/*******************************************************************************
* Function Name  : RCCU_ResetSources
* Description    : Returns the system reset source.
* Input          : None.
* Output         : None.
* Return         : The reset source.
*******************************************************************************/
RCCU_ResetSources RCCU_ResetSource (void)
{
  switch (RCCU->CFR & RCCU_ResetSources_Mask)
  {
    case 0x00000020:
      return RCCU_SoftwareReset;
    case 0x00000040:
      return RCCU_WDGReset;
    case 0x00000080:
      return RCCU_RTCAlarmReset;
    case 0x00000200:
      return RCCU_LVDReset;
    case 0x00000400:
      return RCCU_WKPReset;
    default :
      return RCCU_ExternalReset;
  }
}

/*******************************************************************************
* Function Name  : RCCU_PLL1FreeRunningModeConfig
* Description    : This function configures the PLL1 in free runnig mode.
* Input          : - NewPll1FreeRunningMode: the new free running mode 
*                     it can be:
*                      RCCU_PLL1FreeRunning125, RCCU_PLL1FreeRunning250,
*                      RCCU_PLL1FreeRunning500 
* Output         : None.
* Return         : None.
*******************************************************************************/
void RCCU_PLL1FreeRunningModeConfig(RCCU_PLL1FreeRunningModes
                                    NewPll1FreeRunningMode)
{
  /* bits DX[2:0] (RCCU_PLL1CR) are set to 111, the PLL1 is switched off */
  RCCU->PLL1CR = RCCU_DX_Mask; 
                                    

  switch (NewPll1FreeRunningMode)
  {
    case RCCU_PLL1FreeRunning250:
    {
         RCCU->PLL1CR |= RCCU_FREEN_Mask | RCCU_FREFRANGE_Mask 
                         | (3 << RCCU_MX_Index);              
      break;
    }
    case RCCU_PLL1FreeRunning500:
    {
       RCCU->PLL1CR |= RCCU_FREEN_Mask | RCCU_FREFRANGE_Mask 
                       | (2 << RCCU_MX_Index);               
      break;
    }
    default:
    {
        RCCU->PLL1CR |= RCCU_FREEN_Mask | (3 << RCCU_MX_Index);                
      break;
    }
  }
}

/*******************************************************************************
* Function Name  : RCCU_PLL1Disable
* Description    : This function switch off the PLL1.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void RCCU_PLL1Disable(void)
{
  /* Stop the PLL1 DX[0..2]=111 and FREEN=0 */
  RCCU->PLL1CR = RCCU_DX_Mask;
}

/*******************************************************************************
* Function Name  : RCCU_PLL2Disable
* Description    : This function switch off the PLL2.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void RCCU_PLL2Disable(void)
{
  /* Stop the PLL2 DX[0..2]=111 */
  PCU->PLL2CR |= RCCU_DX_Mask;
}

/*******************************************************************************
* Function Name  : RCCU_GenerateSWReset
* Description    : This function generates software reset.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void RCCU_GenerateSWReset(void)
{
  /* SRESEN = 1  and EN_HALT = 1 */	
  RCCU->CCR |=0x808;   
  
  /* HALT =1   ==> software reset generation */
  RCCU->SMR |=0x2;  
}

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

⌨️ 快捷键说明

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