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