📄 73x_prccu.c
字号:
/* return the value of the Main Clock MCLK*/
return(Tmp_CLOCK2 * MUL_Factor /DIV_Factor) ;
}
else /* CSU_CKSEL bit Reset */
{
return Tmp_CLOCK2; /* Set the MCLK value to CLOCK2 */
}
}
else /* CK2_16 bit reset */
{
/* Set the MCLK value to CLOCK2 / 16 */
return (Tmp_CLOCK2 /16) ;
}
} /* end of if "PRCCU_CLOCK_Out"*/
}
/*******************************************************************************
* Function Name : PRCCU_SetExtClkDiv
* Description : Set EXTCLK Divider factor.
* Input : ExtClkDiv : the value of the divider factor to set the Real
* Time Clock prescaling factors. This parameter can be one of
* the following values: 2,4,8,16,32,64,128,256,512,1024.
* Output : None.
* Return : None.
*******************************************************************************/
void PRCCU_SetExtClkDiv(u16 ExtClkDiv)
{
u8 Rtcp = 0;
/* Get the n Value of the ExtClkDiv = 2^n */
while(ExtClkDiv != 2)
{
ExtClkDiv = ExtClkDiv >>1;
Rtcp++ ;
}
/* Set the RTCPR[3:0] bits according to Rtpr value */
PRCCU->RTCPR = Rtcp;
}
/*******************************************************************************
* Function Name : PRCCU_EnterLPM
* Description : Enter the selected Low Power Mode.
* Input : PRCCU_LPM: low power mode to enter. This parameter can be one
* of the following values:
* - PRCCU_LPM_HALT
* - PRCCU_LPM_WFI
* - PRCCU_LPM_LPWFI
* Output : None
* Return : None
*******************************************************************************/
void PRCCU_EnterLPM (PRCCU_LPM NewLPM)
{
switch ( NewLPM)
{
/* The sequence to enter HALT mode */
case PRCCU_LPM_HALT :
{
/* Set the EN_HALT bit in the PRCCU_CCR register */
PRCCU->CCR |= 0x800;
/* Clear the SRESEN bit in the PRCCU_CCR register */
PRCCU->CCR &= 0xFFF7;
/* Set the HALT bit in the PRCCU_SMR register */
PRCCU->SMR |= 0x2;
break;
}
/* The sequence to enter Wait For Interrupt mode */
case PRCCU_LPM_WFI :
{
/* Clear the WFI bit in the PRCCU_SMR register*/
PRCCU->SMR &= 0x0 ;
break;
}
/* The sequence to enter LP Wait For Interrupt mode */
case PRCCU_LPM_LPWFI :
{
/* Set Low Power mode during Wait For Interrupt bit LPOWFI */
PRCCU->CCR |= 0x01;
/* Clear WFI_CKSEL bit in PRCCU_CCR register */
PRCCU->CCR &= 0xFFFFFFFD;
/* Clear the WFI bit in the PRCCU_SMR register*/
PRCCU->SMR &= 0x0 ;
break;
}
}
}
/*******************************************************************************
* Function Name : PRCCU_ITConfig
* Description : Enables or disables the specified PRCCU interrupts.
* Input : PRCCU_IT: specifies the PRCCU interrupts sources to be enabled
* or disabled. This parameter can be any combination of the
* following values:
* - PRCCU_IT_LOCK
* - PRCCU_IT_STOP
* - PRCCU_IT_CLK2_16
* - NewState: new state of the specified PRCCU interrupts.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void PRCCU_ITConfig(u16 PRCCU_IT, FunctionalState NewState)
{
if (NewState == ENABLE)
{
/* Set the equivalent interrupt mask bit in the CCR resgister */
PRCCU->CCR |= PRCCU_IT;
}
else
{
/* ReSet the equivalent interrupt mask bit in the CCR resgister */
PRCCU->CCR &= ~PRCCU_IT;
}
}
/*******************************************************************************
* Function Name : PRCCU_FlagStatus
* Description : Checks whether the specified PRCCU flag is set or not.
* Input : PRCCU_Flag: flag to check. This parameter can be one of the
* following values:
* - PRCCU_FLAG_LOCK
* - PRCCU_FLAG_SOFTRES
* - PRCCU_FLAG_WDGRES
* - PRCCU_FLAG_LVD_INT
* - PRCCU_FLAG_LOCK_I
* - PRCCU_FLAG_CK2_16_I
* - PRCCU_FLAG_STOP_I
* - PRCCU_FLAG_VROK
* Output : None
* Return : The new state of the PRCCU_Flag (SET or RESET).
*******************************************************************************/
FlagStatus PRCCU_FlagStatus(u16 PRCCU_Flag)
{
/* Checks whether PRCCU_Flag is set or reset */
if (PRCCU_Flag == PRCCU_FLAG_VROK)
{
if ((PRCCU->VRCTR & PRCCU_Flag) != RESET)
{
return SET;
}
else
{
return RESET;
}
}
else
{
if ((PRCCU->CFR & PRCCU_Flag) != RESET)
{
return SET;
}
else
{
return RESET;
}
}
}
/*******************************************************************************
* Function Name : PRCCU_FlagClear
* Description : Clears the specified PRCCU flag.
* Input : PRCCU_Flag: flag to clear. This parameter can be one of the
* following values:
* - PRCCU_FLAG_LOCK_I
* - PRCCU_FLAG_CK2_16_I
* - PRCCU_FLAG_STOP_I
* Output : None
* Return : None
*******************************************************************************/
void PRCCU_FlagClear(u16 PRCCU_Flag)
{
/* Clear PRCCU_Flag */
PRCCU->CFR = (PRCCU->CFR & 0xFFFF816B) | PRCCU_Flag;
}
/*******************************************************************************
* Function Name : PRCCU_SwResetGenerate
* Description : Generate a software reset when enabling the Halt bit.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void PRCCU_SwResetGenerate ( )
{
/* Set the EN_HALT bit in the PRCCU_CCR register */
PRCCU->CCR |= 0x808;
/* Set the HALT bit in the PRCCU_SMR register */
PRCCU->SMR |= 0x2;
}
/*******************************************************************************
* Function Name : PRCCU_VRCmd
* Description : Enable or Disable the main Voltage regulator in case of
* LPWFI low power mode and in the case of run mode.
* Input : - V_Regulator : the voltage regulator to enable or to disable.
* this parameter can be:
* - PRCCU_VR_LPWFI : Main VR in LPWFI mode
* - PRCCU_VR_Run : Main VR in Run mode
* - NewState: new state of the specified PRCCU interrupts.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void PRCCU_VRCmd(u8 V_Regulator, FunctionalState NewState)
{
if (NewState == ENABLE)
{
switch(V_Regulator)
{
case PRCCU_VR_LPWFI : PRCCU->VRCTR |= V_Regulator; break;
case PRCCU_VR_Run : PRCCU->VRCTR &= V_Regulator; break;
}
}
else
{
switch(V_Regulator)
{
case PRCCU_VR_LPWFI : PRCCU->VRCTR &= ~V_Regulator; break;
case PRCCU_VR_Run : PRCCU->VRCTR |= ~V_Regulator; break;
}
}
}
/*******************************************************************************
* Function Name : PRCCU_LPVRCurrentConfig
* Description : select the Low-Power Voltage Regulator Current Capability
* (the allowed values are 2;4;6)
* Input : - Current_Capability : the LPVR Output Current to configure
* it can be one of the following values:
* - PRCCU_LPVR_Current_2
* - PRCCU_LPVR_Current_4
* - PRCCU_LPVR_Current_6
* Output : None
* Return : None
*******************************************************************************/
void PRCCU_LPVRCurrentConfig (u8 Current_Capability)
{
/* Set the Low Power Voltage Regulator Current Capability bit LPVRCC[1:0]
depending on the selected LPVR Output Current (mA)*/
switch(Current_Capability)
{
case PRCCU_LPVR_Current_2 : CFG->R1 |=0x3 ; break;
case PRCCU_LPVR_Current_4 : CFG->R1 &=0xFFFFFFFC ; CFG->R1 |=0x2 ; break;
case PRCCU_LPVR_Current_6 : CFG->R1 &=0xFFFFFFFC ; break;
}
}
/******************* (C) COPYRIGHT 2005 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -