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