1 /**
2 ******************************************************************************
3 * @file HAL_misc.c
4 * @author IC Applications Department
5 * @version V0.8
6 * @date 2019_08_02
7 * @brief This file provides all the miscellaneous firmware functions (add-on
8 * to CMSIS functions).
9 ******************************************************************************
10 * @attention
11 *
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, HOLOCENE SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 *
19 * <h2><center>© COPYRIGHT 2016 HOLOCENE</center></h2>
20 ******************************************************************************
21 */
22
23 /* Includes ------------------------------------------------------------------*/
24 #include "HAL_misc.h"
25
26 /** @addtogroup StdPeriph_Driver
27 * @{
28 */
29
30 /** @defgroup MISC
31 * @brief MISC driver modules
32 * @{
33 */
34
35 /** @defgroup MISC_Private_TypesDefinitions
36 * @{
37 */
38
39 /**
40 * @}
41 */
42
43 /** @defgroup MISC_Private_Defines
44 * @{
45 */
46
47 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
48 /**
49 * @}
50 */
51
52 /** @defgroup MISC_Private_Macros
53 * @{
54 */
55
56 /**
57 * @}
58 */
59
60 /** @defgroup MISC_Private_Variables
61 * @{
62 */
63
64 /**
65 * @}
66 */
67
68 /** @defgroup MISC_Private_FunctionPrototypes
69 * @{
70 */
71
72 /**
73 * @}
74 */
75
76 /** @defgroup MISC_Private_Functions
77 * @{
78 */
79
80 /**
81 * @brief Configures the priority grouping: pre-emption priority and subpriority.
82 * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
83 * This parameter can be one of the following values:
84 * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
85 * 4 bits for subpriority
86 * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
87 * 3 bits for subpriority
88 * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
89 * 2 bits for subpriority
90 * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
91 * 1 bits for subpriority
92 * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
93 * 0 bits for subpriority
94 * @retval None
95 */
NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)96 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
97 {
98
99
100 /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
101 SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
102 }
103 //void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState)
104 //{
105 // /* Check the parameters */
106 // assert_param(IS_TIM_ALL_PERIPH(TIMx));
107 // assert_param(IS_TIM_IT(TIM_IT));
108 // assert_param(IS_FUNCTIONAL_STATE(NewState));
109 //
110 // if (NewState != DISABLE)
111 // {
112 // /* Enable the Interrupt sources */
113 // TIMx->DIER |= TIM_IT;
114 // }
115 // else
116 // {
117 // /* Disable the Interrupt sources */
118 // TIMx->DIER &= (uint16_t)~TIM_IT;
119 // }
120 //}
121
122 //void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)
123 //{
124 // /* Check the parameters */
125 // assert_param(IS_TIM_ALL_PERIPH(TIMx));
126 // assert_param(IS_FUNCTIONAL_STATE(NewState));
127 //
128 // if (NewState != DISABLE)
129 // {
130 // /* Enable the TIM Counter */
131 // TIMx->CR1 |= TIM_CR1_CEN;
132 // }
133 // else
134 // {
135 // /* Disable the TIM Counter */
136 // TIMx->CR1 &= (uint16_t)(~((uint16_t)TIM_CR1_CEN));
137 // }
138 //}
139
140 /**
141 * @brief Initializes the NVIC peripheral according to the specified
142 * parameters in the NVIC_InitStruct.
143 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
144 * the configuration information for the specified NVIC peripheral.
145 * @retval None
146 */
NVIC_Init(NVIC_InitTypeDef * NVIC_InitStruct)147 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
148 {
149 uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
150
151
152
153 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
154 {
155 /* Compute the Corresponding IRQ Priority --------------------------------*/
156 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
157 tmppre = (0x4 - tmppriority);
158 tmpsub = tmpsub >> tmppriority;
159
160 tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
161 tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
162 tmppriority = tmppriority << 0x04;
163
164 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
165
166 /* Enable the Selected IRQ Channels --------------------------------------*/
167 NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
168 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
169 }
170 else
171 {
172 /* Disable the Selected IRQ Channels -------------------------------------*/
173 NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
174 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
175 }
176
177 tmppre = NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05];
178 //printf("NVIC->ISER = 0x%x\r\n",tmppre);
179 }
180
181 /**
182 * @brief Sets the vector table location and Offset.
183 * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
184 * This parameter can be one of the following values:
185 * @arg NVIC_VectTab_RAM
186 * @arg NVIC_VectTab_FLASH
187 * @param Offset: Vector Table base offset field. This value must be a multiple
188 * of 0x200.
189 * @retval None
190 */
NVIC_SetVectorTable(uint32_t NVIC_VectTab,uint32_t Offset)191 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
192 {
193
194
195 //SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
196 }
197
198 /**
199 * @brief Selects the condition for the system to enter low power mode.
200 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
201 * This parameter can be one of the following values:
202 * @arg NVIC_LP_SEVONPEND
203 * @arg NVIC_LP_SLEEPDEEP
204 * @arg NVIC_LP_SLEEPONEXIT
205 * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
206 * @retval None
207 */
NVIC_SystemLPConfig(uint8_t LowPowerMode,FunctionalState NewState)208 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
209 {
210
211
212 if (NewState != DISABLE)
213 {
214 SCB->SCR |= LowPowerMode;
215 }
216 else
217 {
218 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
219 }
220 }
221
222 /**
223 * @brief Configures the SysTick clock source.
224 * @param SysTick_CLKSource: specifies the SysTick clock source.
225 * This parameter can be one of the following values:
226 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
227 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
228 * @retval None
229 */
SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)230 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
231 {
232 /* Check the parameters */
233
234 if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
235 {
236 SysTick->CTRL |= SysTick_CLKSource_HCLK;
237 }
238 else
239 {
240 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
241 }
242 }
243
244 /**
245 * @}
246 */
247
248 /**
249 * @}
250 */
251
252 /**
253 * @}
254 */
255
256 /*-------------------------(C) COPYRIGHT 2016 HOLOCENE ----------------------*/
257