pcu.c
资源名称:str711USB.rar [点击查看]
上传用户:yyyd609
上传日期:2022-07-18
资源大小:183k
文件大小:4k
源码类别:
微处理器开发
开发平台:
C/C++
- /******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
- * File Name : pcu.c
- * Author : MCD Application Team
- * Date First Issued : 09/09/03
- * Description : This file provides all the Power Control Unit functions
- ********************************************************************************
- * History:
- * 01/01/2004 : V1.2
- * 14/07/2004 : V1.3
- *******************************************************************************/
- #include "pcu.h"
- #include "rccu.h"
- /*******************************************************************************
- * Function Name : PCU_VRConfig
- * Description : This routine is used to configure PCU voltage regultors
- * Input 1 : MVR : Main voltage Regulator
- LPR : Low Power Regulator
- * Input 2 : ENABLE : Enable the Voltage Regulator
- DISABLE: Disable ( ByPass ) the VR
- * Return : None
- *******************************************************************************/
- void PCU_VRConfig ( PCU_VR Xvr, FunctionalState NewState )
- {
- u16 Tmp = PCU->PWRCR;
- switch ( Xvr )
- {
- case PCU_MVR :
- // Configure the Main Voltage Regulator
- if (NewState == DISABLE) Tmp |= PCU_MVR_Mask; else Tmp &= ~PCU_MVR_Mask;
- break;
- case PCU_LPR :
- // Configure the Low power Voltage Regulator
- if (NewState == DISABLE) Tmp |= PCU_LPR_Mask; else Tmp &= ~PCU_LPR_Mask;
- break;
- }
- // Unlock Power Control Register
- PCU->PWRCR |= PCU_WREN_Mask;
- PCU->PWRCR = Tmp | PCU_WREN_Mask;
- }
- /*******************************************************************************
- * Function Name : PCU_WFIEnter
- * Description : This routine is used to force the Device to enter in WFI mode
- * Input 1 : CLOCK2_16 : Clock2_16 as system clock for WFI mode
- * EXTERNAL : external clock as system clock for WFI mode
- * Input 2 : ENABLE : Enable Low Power Regulator during Wait For Interrupt Mode
- * DISABLE: Disable Low Power Regulator during Wait For Interrupt Mode
- * Input 3 : ENABLE : Enable Low Power Mode during Wait For Interrupt Mode
- * DISABLE: Disable Low Power Mode during Wait For Interrupt Mode
- * Return : None
- *******************************************************************************/
- void PCU_WFIEnter ( WFI_CLOCKS Xclock, FunctionalState Xlpr, FunctionalState Xlpm )
- {
- u32 Tmp;
- // Enable Low Power Regulator in WFI mode
- Tmp = PCU->PWRCR;
- // Unlock Power Control Register
- PCU->PWRCR |= PCU_WREN_Mask;
- PCU->PWRCR = Xlpr == ENABLE ? Tmp & ~PCU_LPRWFI_Mask : Tmp | PCU_LPRWFI_Mask;
- // WFI Clock Selection
- Tmp = RCCU->CCR;
- RCCU->CCR = Xclock == WFI_CLOCK2_16 ? Tmp & ~PCU_WFI_CKSEL_Mask : Tmp | PCU_WFI_CKSEL_Mask;
- // Low Power Mode during WFI mode
- Tmp = RCCU->CCR;
- RCCU->CCR = Xlpm == DISABLE ? Tmp & ~PCU_LPOWFI_Mask : Tmp | PCU_LPOWFI_Mask;
- // Enter WFI Mode
- RCCU->SMR &= ~0x0001;
- }
- /*******************************************************************************
- * Function Name : PCU_LPMEnter
- * Description : This routine is used to force the device to enter in low
- * power modes
- * Input : PCU_SLOW : Slow Mode
- PCU_STOP : Stop Mode
- PCU_STANDBY : StandBy Mode
- * Return : None
- *******************************************************************************/
- void PCU_LPMEnter ( LPM_MODES Xmode )
- {
- switch ( Xmode )
- {
- // Slow Mode
- case PCU_SLOW:
- {
- RCCU->PLL1CR |= 0x87;
- RCCU_RCLKSourceConfig ( RCCU_PLL1_Output );
- break;
- }
- // Stop Mode
- case PCU_STOP:
- {
- // Enable Stop EN bit
- RCCU->CCR |= PCU_STOP_EN_Mask;
- // Write '1' to Stop Bit
- XTI->CTRL |= 0x04;
- // Write '0' to Stop Bit
- XTI->CTRL &= 0x03;
- // Write '1' to Stop Bit
- XTI->CTRL |= 0x04;
- // add Delay
- __asm
- {
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- NOP
- }
- break;
- // test if the Device entred in a Stop Mode.
- }
- // PCU_STANDBY Mode
- case PCU_STANDBY:
- {
- PCU->PWRCR |= PCU_WREN_Mask; // Unlock Power Control Register
- PCU->PWRCR |= PCU_PWRDWN_Mask; // Set the Power Down flag
- }
- }
- }
- /******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/