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