1 /*! 2 * @file apm32f0xx_misc.c 3 * 4 * @brief This file provides all the miscellaneous firmware functions (add-on to CMSIS functions). 5 * 6 * @version V1.0.3 7 * 8 * @date 2022-09-20 9 * 10 * @attention 11 * 12 * Copyright (C) 2020-2022 Geehy Semiconductor 13 * 14 * You may not use this file except in compliance with the 15 * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE). 16 * 17 * The program is only for reference, which is distributed in the hope 18 * that it will be useful and instructional for customers to develop 19 * their software. Unless required by applicable law or agreed to in 20 * writing, the program is distributed on an "AS IS" BASIS, WITHOUT 21 * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions 23 * and limitations under the License. 24 */ 25 26 /* Includes */ 27 #include "apm32f0xx_misc.h" 28 29 /** @addtogroup APM32F0xx_StdPeriphDriver 30 @{ 31 */ 32 33 /** @addtogroup MISC_Driver 34 @{ 35 */ 36 37 /** @defgroup MISC_Macros Macros 38 @{ 39 */ 40 41 /**@} end of group MISC_Macros*/ 42 43 /** @defgroup MISC_Enumerations Enumerations 44 @{ 45 */ 46 47 /**@} end of group MISC_Enumerations*/ 48 49 /** @defgroup MISC_Structures Structures 50 @{ 51 */ 52 53 /**@} end of group MISC_Structures*/ 54 55 /** @defgroup MISC_Variables Variables 56 @{ 57 */ 58 59 /**@} end of group MISC_Variables*/ 60 61 /** @defgroup MISC_Functions Functions 62 @{ 63 */ 64 65 /*! 66 * @brief Enable NVIC request 67 * 68 * @param irq: The NVIC interrupt request, detailed in IRQn_Type 69 * 70 * @param priority: Specifies the priority needed to set 71 * 72 * @retval None 73 */ NVIC_EnableIRQRequest(IRQn_Type irq,uint8_t priority)74void NVIC_EnableIRQRequest(IRQn_Type irq, uint8_t priority) 75 { 76 NVIC_SetPriority(irq, priority); 77 78 NVIC_EnableIRQ(irq); 79 } 80 81 /*! 82 * @brief Disable NVIC request 83 * 84 * @param irq: The NVIC interrupt request, detailed in IRQn_Type 85 * 86 * @retval None 87 */ NVIC_DisableIRQRequest(IRQn_Type irq)88void NVIC_DisableIRQRequest(IRQn_Type irq) 89 { 90 NVIC_DisableIRQ(irq); 91 } 92 93 /** 94 * @brief Enables the system to enter low power mode. 95 * 96 * @param lowPowerMode: Specifies the system to enter low power mode. 97 * This parameter can be one of the following values: 98 * @arg NVIC_LOWPOER_SEVONPEND: Low Power SEV on Pend. 99 * @arg NVIC_LOWPOER_SLEEPDEEP: Low Power DEEPSLEEP request. 100 * @arg NVIC_LOWPOER_SLEEPONEXIT: Low Power Sleep on Exit. 101 * 102 * @retval None 103 */ NVIC_EnableSystemLowPower(uint8_t lowPowerMode)104void NVIC_EnableSystemLowPower(uint8_t lowPowerMode) 105 { 106 SCB->SCR |= lowPowerMode; 107 } 108 109 /** 110 * @brief Disables the system to enter low power mode. 111 * 112 * @param lowPowerMode: Specifies the system to enter low power mode. 113 * This parameter can be one of the following values: 114 * @arg NVIC_LOWPOER_SEVONPEND: Low Power SEV on Pend. 115 * @arg NVIC_LOWPOER_SLEEPDEEP: Low Power DEEPSLEEP request. 116 * @arg NVIC_LOWPOER_SLEEPONEXIT: Low Power Sleep on Exit. 117 * 118 * @retval None 119 */ NVIC_DisableSystemLowPower(uint8_t lowPowerMode)120void NVIC_DisableSystemLowPower(uint8_t lowPowerMode) 121 { 122 SCB->SCR &= (uint32_t)(~(uint32_t)lowPowerMode); 123 } 124 125 /** 126 * @brief Configures the SysTick clock source. 127 * 128 * @param sysTickCLKSource: specifies the SysTick clock source. 129 * This parameter can be one of the following values: 130 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 131 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 132 * 133 * @retval None 134 */ SysTick_ConfigCLKSource(uint32_t sysTickCLKSource)135void SysTick_ConfigCLKSource(uint32_t sysTickCLKSource) 136 { 137 if (sysTickCLKSource == SysTick_CLKSource_HCLK) 138 { 139 SysTick->CTRL |= SysTick_CLKSource_HCLK; 140 } 141 else 142 { 143 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 144 } 145 } 146 147 /*! 148 * @brief Enter Wait Mode 149 * 150 * @param None 151 * 152 * @retval None 153 */ PMU_EnterWaitMode(void)154void PMU_EnterWaitMode(void) 155 { 156 SCB->SCR &= (uint32_t)(~(uint32_t)NVIC_LOWPOER_SLEEPDEEP); 157 __WFI(); 158 } 159 160 /*! 161 * @brief Enter Stop Mode with WFI instruction 162 * 163 * @param None 164 * 165 * @retval None 166 */ PMU_EnterHaltModeWFI(void)167void PMU_EnterHaltModeWFI(void) 168 { 169 SCB->SCR |= NVIC_LOWPOER_SLEEPDEEP; 170 __DSB(); 171 __WFI(); 172 } 173 174 /*! 175 * @brief Enter Stop Mode with WFE instruction 176 * 177 * @param None 178 * 179 * @retval None 180 */ PMU_EnterHaltModeWFE(void)181void PMU_EnterHaltModeWFE(void) 182 { 183 SCB->SCR |= NVIC_LOWPOER_SLEEPDEEP; 184 __DSB(); 185 __WFE(); 186 } 187 188 /**@} end of group MISC_Functions */ 189 /**@} end of group MISC_Driver */ 190 /**@} end of group APM32F0xx_StdPeriphDriver */ 191