1 /** 2 ****************************************************************************** 3 * @file hk32f0xx_misc.c 4 * @version V1.0.1 5 * @date 2019-08-15 6 ****************************************************************************** 7 */ 8 9 /* Includes ------------------------------------------------------------------*/ 10 #include "hk32f0xx_misc.h" 11 12 /** @addtogroup HK32F0xx_StdPeriph_Driver 13 * @{ 14 */ 15 16 /** @defgroup MISC 17 * @brief MISC driver modules 18 * @{ 19 */ 20 21 /* Private typedef -----------------------------------------------------------*/ 22 /* Private define ------------------------------------------------------------*/ 23 /* Private macro -------------------------------------------------------------*/ 24 /* Private variables ---------------------------------------------------------*/ 25 /* Private function prototypes -----------------------------------------------*/ 26 /* Private functions ---------------------------------------------------------*/ 27 28 /** @defgroup MISC_Private_Functions 29 * @{ 30 */ 31 /** 32 * 33 @verbatim 34 ******************************************************************************* 35 ##### Interrupts configuration functions ##### 36 ******************************************************************************* 37 [..] This section provide functions allowing to configure the NVIC interrupts 38 (IRQ). The Cortex-M0 exceptions are managed by CMSIS functions. 39 (#) Enable and Configure the priority of the selected IRQ Channels. 40 The priority can be 0..3. 41 42 -@- Lower priority values gives higher priority. 43 -@- Priority Order: 44 (#@) Lowest priority. 45 (#@) Lowest hardware priority (IRQn position). 46 47 @endverbatim 48 */ 49 50 /** 51 * @brief Initializes the NVIC peripheral according to the specified 52 * parameters in the NVIC_InitStruct. 53 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains 54 * the configuration information for the specified NVIC peripheral. 55 * @retval None 56 */ NVIC_Init(NVIC_InitTypeDef * NVIC_InitStruct)57void NVIC_Init(NVIC_InitTypeDef *NVIC_InitStruct) 58 { 59 uint32_t tmppriority = 0x00; 60 61 /* Check the parameters */ 62 assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 63 assert_param(IS_NVIC_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPriority)); 64 65 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 66 { 67 /* Compute the Corresponding IRQ Priority --------------------------------*/ 68 tmppriority = NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02]; 69 tmppriority &= (uint32_t)(~(((uint32_t)0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8))); 70 tmppriority |= (uint32_t)((((uint32_t)NVIC_InitStruct->NVIC_IRQChannelPriority << 6) & 0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8)); 71 72 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02] = tmppriority; 73 74 /* Enable the Selected IRQ Channels --------------------------------------*/ 75 NVIC->ISER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 76 } 77 else 78 { 79 /* Disable the Selected IRQ Channels -------------------------------------*/ 80 NVIC->ICER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 81 } 82 } 83 84 /** 85 * @brief Selects the condition for the system to enter low power mode. 86 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 87 * This parameter can be one of the following values: 88 * @arg NVIC_LP_SEVONPEND: Low Power SEV on Pend. 89 * @arg NVIC_LP_SLEEPDEEP: Low Power DEEPSLEEP request. 90 * @arg NVIC_LP_SLEEPONEXIT: Low Power Sleep on Exit. 91 * @param NewState: new state of LP condition. 92 * This parameter can be: ENABLE or DISABLE. 93 * @retval None 94 */ NVIC_SystemLPConfig(uint8_t LowPowerMode,FunctionalState NewState)95void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 96 { 97 /* Check the parameters */ 98 assert_param(IS_NVIC_LP(LowPowerMode)); 99 100 assert_param(IS_FUNCTIONAL_STATE(NewState)); 101 102 if (NewState != DISABLE) 103 { 104 SCB->SCR |= LowPowerMode; 105 } 106 else 107 { 108 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 109 } 110 } 111 112 /** 113 * @brief Configures the SysTick clock source. 114 * @param SysTick_CLKSource: specifies the SysTick clock source. 115 * This parameter can be one of the following values: 116 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 117 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 118 * @retval None 119 */ SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)120void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 121 { 122 /* Check the parameters */ 123 assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 124 125 if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 126 { 127 SysTick->CTRL |= SysTick_CLKSource_HCLK; 128 } 129 else 130 { 131 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 132 } 133 } 134 135 /** 136 * @} 137 */ 138 139 /** 140 * @} 141 */ 142 143 /** 144 * @} 145 */ 146 147