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

📄 73x_prccu.c

📁 国外LPC2000系列的一些源程序,请大家快快下载
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************** (C) COPYRIGHT 2005 STMicroelectronics ********************
* File Name          : 73x_prccu.c
* Author             : MCD Application Team
* Date First Issued  : 09/27/2005 :  V1.0 
* Description        : This file provides all the PRCCU software functions.
**********************************************************************************
* History:
* 09/27/2005 :  V1.0
**********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*********************************************************************************/

/* Standard include ----------------------------------------------------------*/
#include "73x_prccu.h"
#include "73x_cmu.h"

/* Include of other module interface headers ---------------------------------*/
/* Local includes ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Interface functions -------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************
* Function Name  : PRCCU_Init
* Description    : Initializes the PRCCU  peripheral according to the specified
*                  parameters in the PRCCU_InitTypeDef structure.
* Input          : PRCCU_InitStruct: pointer to a PRCCU_InitTypeDef structure that
*                  contains the configuration information for the PRCCU peripheral.
* Output         : None
* Return         : None
******************************************************************************/
void PRCCU_Init(PRCCU_InitTypeDef* PRCCU_InitStruct)
{
  u32 Tmp_CLOCK2=0, CLOCK1=0;
 
  PRCCU->CFR |= PRCCU_CFR_Mask;      /* set DIV2 and CK2_16 bits to reset value */
  PRCCU->CFR &= PRCCU_CFR_Mask1;     /* set CSU_CKSEL bit to reset value */
  PRCCU->PLLCR = PRCCU_PLLCR_Mask;   /* set FREEN, FREF_RANGE and MX[1:0] bits to their reset values */ 
                                     /* reset DX[2:0] value to 0x0 */
  
  /* DIV2 part of the PLL-----------------------------------------------------*/
  /* Enable or disable the DIV2 of the Clock unit */
  if(PRCCU_InitStruct->PRCCU_DIV2 == ENABLE)
  {
    /* Enable DIV2 by setting DIV2 bit in PRCCU_CFR register */
    PRCCU->CFR |= PRCCU_DIV2_Enable;
  }
  else
  {
    /* Disable DIV2 by resetting DIV2 bit in PRCCU_CFR register */
    PRCCU->CFR &= PRCCU_DIV2_Disable;
  }

  /* MCLK source Clock selection part ----------------------------------------*/
  switch(PRCCU_InitStruct->PRCCU_MCLKSRC_SRC)
  {
    /* select the CLOCK2 as MCLK Source*/
    case PRCCU_MCLKSRC_CLOCK2 :
    {
      /* Disable PLL by resetting CSU_CKSEL bit in PRCCU_CFR register */
      PRCCU->CFR &= PRCCU_CSU_CKSEL_Disable;
      /* Disable CK2_16 by setting CK2_16 bit in PRCCU_CFR register */
      PRCCU->CFR |= PRCCU_CK2_16_Disable;
      /* switch off the PLL*/
      PRCCU->PLLCR = PRCCU_PLL_SwitchOff;
      break;
    }

    /* select the CLOCK2/16 as MCLK Source*/
    case PRCCU_MCLKSRC_CLOCK2_16 :
    {
      /* Enable CK2_16 by resetting CK2_16 bit in PRCCU_CFR register */
      PRCCU->CFR &= PRCCU_CK2_16_Enable;
      /*  Switch off the PLL */
      PRCCU->PLLCR = PRCCU_PLL_SwitchOff;
      break;
    }

    /* select the PLL output as MCLK Source*/
    case PRCCU_MCLKSRC_PLL :
    {
      if((CMU->CTRL & CMU_CKSEL0_CKOSC) == CMU_CKSEL0_CKOSC)
      {
        CLOCK1 = RCCU_Main_Osc ;
      }
      else
      {
        CLOCK1 = RCCU_RTC_Osc;
      }
      if((PRCCU->CFR & PRCCU_DIV2_Enable) != 0)
      {
        /* Set CLOCK2 value to half CLOCK1 */
        Tmp_CLOCK2 = CLOCK1 / 2;  
      }
      else /* DIV2_EN bit is reset */
      {
        /* Set CLOCK2 value equal to CLOCK1 */
        Tmp_CLOCK2 =  CLOCK1;
      }
      if(Tmp_CLOCK2 < 3000000)
      {
        /* PLL input in 1.5-3MHz */
        PRCCU->PLLCR &= PRCCU_FREF_RANGE_Low ;
      }
      else if(Tmp_CLOCK2 < 5000000)
      {
        /* PLL input in 3-5MHz  */
        PRCCU->PLLCR |= PRCCU_FREF_RANGE_High ;
      }

      /* configure the PLL Division Factors */
      PRCCU->PLLCR |= PRCCU_InitStruct->PRCCU_PLLDIV - 1;
      /* configure the PLL Multiplication Factor  */
      PRCCU->PLLCR |= PRCCU_InitStruct->PRCCU_PLLMUL;
      /* Enable PLL by setting CSU_CKSEL bit in PRCCU_CFR register */
      PRCCU->CFR |= PRCCU_CSU_CKSEL_Enable;
      /* Disable CK2_16 by setting CK2_16 bit in PRCCU_CFR register */
      PRCCU->CFR |= PRCCU_CK2_16_Disable;
    }
  }
  /* Free running mode for PLL -----------------------------------------------*/
  /* Enable or disable the Free running mode for PLL */
  if(PRCCU_InitStruct->PRCCU_FREEN == ENABLE)
  {
    /* Enable Free running mode for PLL by setting FREEN bit in PRCCU_PLLCR register */
    PRCCU->PLLCR |= PRCCU_FREEN_Enable;
    /* switch off the PLL*/
    PRCCU->PLLCR &= 0xFFFFFFF8;
    PRCCU->PLLCR |= PRCCU_PLL_SwitchOff;
  }
  else
  {
    /* Disable Free running mode for PLL by resetting FREEN bit in PRCCU_PLLCR register */
    PRCCU->PLLCR &= PRCCU_FREEN_Disable;
  }
}

/******************************************************************************
* Function Name  : PRCCU_DeInit
* Description    : Deinitializes the PRCCU peripheral registers to their default
                   reset values.
* Input          : None
* Output         : None
* Return         : None
******************************************************************************/
void PRCCU_DeInit(void)
{
  PRCCU->CCR = 0x0;
  PRCCU->VRCTR = 0x14;
  PRCCU->CFR  = 0x8008;
  PRCCU->PLLCR = 0x07;
  PRCCU->SMR = 0x01;
  PRCCU->RTCPR = 0x0F;
}

/******************************************************************************
* Function Name  : PRCCU_StructInit
* Description    : Fills in a PRCCU_InitTypeDef structure with the reset value of
*                  each parameter.
* Input          : PRCCU_InitStruct : pointer to a PRCCU_InitTypeDef structure
                   which will be initialized.
* Output         : None
* Return         : None
******************************************************************************/
void PRCCU_StructInit(PRCCU_InitTypeDef* PRCCU_InitStruct)
{
  PRCCU_InitStruct->PRCCU_DIV2 = ENABLE;
  PRCCU_InitStruct->PRCCU_MCLKSRC_SRC = PRCCU_MCLKSRC_CLOCK2;
  PRCCU_InitStruct->PRCCU_PLLDIV = 0x7;
  PRCCU_InitStruct->PRCCU_PLLMUL = 0x0;
  PRCCU_InitStruct->PRCCU_FREEN = DISABLE; 
}

/*******************************************************************************
* Function Name  : PRCCU_GetFrequencyValue
* Description    : Retrieves the value of the clock passed as parameter.
* Input          : PRCCU_CLOCK : the Clock to get its value .
*                  This parameter can be one of the following values:
*                   - PRCCU_CLOCK_EXT
*                   - PRCCU_CLOCK_MCLK
* Output         : None
* Return         : The value of the clock passed as parameter in Hz.
*******************************************************************************/
u32 PRCCU_GetFrequencyValue (PRCCU_OUTPUT PRCCU_CLOCK_Out)
{
  u8 MUL_Factor=1, DIV_Factor=1;
  u32 Tmp=0, Tmp_CLOCK2=0, CLOCK1=0;
  
  if((CMU->CTRL & CMU_CKSEL0_CKOSC) == CMU_CKSEL0_CKOSC)
  {
    CLOCK1 = RCCU_Main_Osc ;
  }
  else
  {
    CLOCK1 = RCCU_RTC_Osc;
  }
  
  /* Depending on the needed value*/
  if(PRCCU_CLOCK_Out == PRCCU_CLOCK_EXT)
  {
    /* Get the value of the RT Clock Frequency (fEXT)*/
    /* Check if the RT Clock Frequency (fEXT) is stopped or not */
    if (PRCCU->RTCPR <= 9)
    {
       /* Calculate the value of the RT Clock Frequency (fEXT) which depends on the RTCPR value  */
       return (RCCU_Main_Osc /(2<<PRCCU->RTCPR));
    }
    else /* PRCCU->RTCPR > 9 */
    {
      /* RT Clock Frequency (fEXT) is stopped  */
       return (0);
    }
  }
  else   /* PRCCU_CLOCK_Out == PRCCU_CLOCK_MCLK */ 
  {
    /* Get the value of the fMCLK to CPU and peripherals */
    /* Depending on the status of the DIV2_EN bit get the CLOCK2 value  */
    if((PRCCU->CFR & PRCCU_DIV2_Enable) != 0)
    {
      Tmp_CLOCK2 = CLOCK1 / 2;  /* Set CLOCK2 value to Half CLOCK1 */
    }
    else /* DIV2_EN bit is reset */
    {
      /* Set CLOCK2 value equal to CLOCK1 */
      Tmp_CLOCK2 =  CLOCK1;
    }
    
    if((PRCCU->CFR & PRCCU_CK2_16_Disable) != 0)
    {
      if ((PRCCU->CFR & PRCCU_CSU_CKSEL_Enable) !=0 )
      {
        /* Get the PLL Multiplication and the Division Factor */
        Tmp = PRCCU->PLLCR;
        MUL_Factor =  ((Tmp & 0x30) >> 4);
        switch (MUL_Factor)
        {
          case 0: MUL_Factor = 20; break;
          case 1: MUL_Factor = 12; break;
          case 2: MUL_Factor = 28; break;
          case 3: MUL_Factor = 16; break;
        }
        
        DIV_Factor = (Tmp& 0x07) +1;
        

⌨️ 快捷键说明

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