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