1 /* Includes ------------------------------------------------------------------*/ 2 #include "misc.h" 3 4 /** @addtogroup air32f10x_StdPeriph_Driver 5 * @{ 6 */ 7 8 /** @defgroup MISC 9 * @brief MISC driver modules 10 * @{ 11 */ 12 13 /** @defgroup MISC_Private_TypesDefinitions 14 * @{ 15 */ 16 17 /** 18 * @} 19 */ 20 21 /** @defgroup MISC_Private_Defines 22 * @{ 23 */ 24 25 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 26 /** 27 * @} 28 */ 29 30 /** @defgroup MISC_Private_Macros 31 * @{ 32 */ 33 34 /** 35 * @} 36 */ 37 38 /** @defgroup MISC_Private_Variables 39 * @{ 40 */ 41 42 /** 43 * @} 44 */ 45 46 /** @defgroup MISC_Private_FunctionPrototypes 47 * @{ 48 */ 49 50 /** 51 * @} 52 */ 53 54 /** @defgroup MISC_Private_Functions 55 * @{ 56 */ 57 58 /** 59 * @brief Configures the priority grouping: pre-emption priority and subpriority. 60 * @param NVIC_PriorityGroup: specifies the priority grouping bits length. 61 * This parameter can be one of the following values: 62 * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority 63 * 4 bits for subpriority 64 * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority 65 * 3 bits for subpriority 66 * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority 67 * 2 bits for subpriority 68 * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority 69 * 1 bits for subpriority 70 * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority 71 * 0 bits for subpriority 72 * @retval None 73 */ NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)74void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) 75 { 76 /* Check the parameters */ 77 assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); 78 79 /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ 80 SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; 81 } 82 83 /** 84 * @brief Initializes the NVIC peripheral according to the specified 85 * parameters in the NVIC_InitStruct. 86 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains 87 * the configuration information for the specified NVIC peripheral. 88 * @retval None 89 */ NVIC_Init(NVIC_InitTypeDef * NVIC_InitStruct)90void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) 91 { 92 uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; 93 94 /* Check the parameters */ 95 assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 96 assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); 97 assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); 98 99 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 100 { 101 /* Compute the Corresponding IRQ Priority --------------------------------*/ 102 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; 103 tmppre = (0x4 - tmppriority); 104 tmpsub = tmpsub >> tmppriority; 105 106 tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 107 tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; 108 tmppriority = tmppriority << 0x04; 109 110 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; 111 112 /* Enable the Selected IRQ Channels --------------------------------------*/ 113 NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 114 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 115 } 116 else 117 { 118 /* Disable the Selected IRQ Channels -------------------------------------*/ 119 NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 120 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 121 } 122 } 123 124 /** 125 * @brief Sets the vector table location and Offset. 126 * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory. 127 * This parameter can be one of the following values: 128 * @arg NVIC_VectTab_RAM 129 * @arg NVIC_VectTab_FLASH 130 * @param Offset: Vector Table base offset field. This value must be a multiple 131 * of 0x200. 132 * @retval None 133 */ NVIC_SetVectorTable(uint32_t NVIC_VectTab,uint32_t Offset)134void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset) 135 { 136 /* Check the parameters */ 137 assert_param(IS_NVIC_VECTTAB(NVIC_VectTab)); 138 assert_param(IS_NVIC_OFFSET(Offset)); 139 140 SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); 141 } 142 143 /** 144 * @brief Selects the condition for the system to enter low power mode. 145 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 146 * This parameter can be one of the following values: 147 * @arg NVIC_LP_SEVONPEND 148 * @arg NVIC_LP_SLEEPDEEP 149 * @arg NVIC_LP_SLEEPONEXIT 150 * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE. 151 * @retval None 152 */ NVIC_SystemLPConfig(uint8_t LowPowerMode,FunctionalState NewState)153void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 154 { 155 /* Check the parameters */ 156 assert_param(IS_NVIC_LP(LowPowerMode)); 157 assert_param(IS_FUNCTIONAL_STATE(NewState)); 158 159 if (NewState != DISABLE) 160 { 161 SCB->SCR |= LowPowerMode; 162 } 163 else 164 { 165 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 166 } 167 } 168 169 /** 170 * @brief Configures the SysTick clock source. 171 * @param SysTick_CLKSource: specifies the SysTick clock source. 172 * This parameter can be one of the following values: 173 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 174 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 175 * @retval None 176 */ SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)177void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 178 { 179 /* Check the parameters */ 180 assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 181 if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 182 { 183 SysTick->CTRL |= SysTick_CLKSource_HCLK; 184 } 185 else 186 { 187 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 188 } 189 } 190 191 /** 192 * @} 193 */ 194 195 /** 196 * @} 197 */ 198 199 /** 200 * @} 201 */ 202