2 ******************************************************************************
\r
4 * @author MCD Application Team
\r
6 * @date 31-December-2010
\r
7 * @brief This file provides all the miscellaneous firmware functions (add-on
\r
8 * to CMSIS functions).
\r
9 ******************************************************************************
\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
19 * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
\r
20 ******************************************************************************
\r
23 /* Includes ------------------------------------------------------------------*/
\r
26 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
31 * @brief MISC driver modules
\r
35 /* Private typedef -----------------------------------------------------------*/
\r
36 /* Private define ------------------------------------------------------------*/
\r
37 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
\r
39 /* Private macro -------------------------------------------------------------*/
\r
40 /* Private variables ---------------------------------------------------------*/
\r
41 /* Private function prototypes -----------------------------------------------*/
\r
42 /* Private functions ---------------------------------------------------------*/
\r
44 /** @defgroup MISC_Private_Functions
\r
50 *******************************************************************************
\r
51 Interrupts configuration functions
\r
52 *******************************************************************************
\r
54 This section provide functions allowing to configure the NVIC interrupts (IRQ).
\r
55 The Cortex-M3 exceptions are managed by CMSIS functions.
\r
57 1. Configure the NVIC Priority Grouping using NVIC_PriorityGroupConfig() function
\r
58 according to the following table.
\r
60 The table below gives the allowed values of the pre-emption priority and subpriority according
\r
61 to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function
\r
62 ============================================================================================================================
\r
63 NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description
\r
64 ============================================================================================================================
\r
65 NVIC_PriorityGroup_0 | 0 | 0-15 | 0 bits for pre-emption priority
\r
66 | | | 4 bits for subpriority
\r
67 ----------------------------------------------------------------------------------------------------------------------------
\r
68 NVIC_PriorityGroup_1 | 0-1 | 0-7 | 1 bits for pre-emption priority
\r
69 | | | 3 bits for subpriority
\r
70 ----------------------------------------------------------------------------------------------------------------------------
\r
71 NVIC_PriorityGroup_2 | 0-3 | 0-3 | 2 bits for pre-emption priority
\r
72 | | | 2 bits for subpriority
\r
73 ----------------------------------------------------------------------------------------------------------------------------
\r
74 NVIC_PriorityGroup_3 | 0-7 | 0-1 | 3 bits for pre-emption priority
\r
75 | | | 1 bits for subpriority
\r
76 ----------------------------------------------------------------------------------------------------------------------------
\r
77 NVIC_PriorityGroup_4 | 0-15 | 0 | 4 bits for pre-emption priority
\r
78 | | | 0 bits for subpriority
\r
79 ============================================================================================================================
\r
82 2. Enable and Configure the priority of the selected IRQ Channels.
\r
84 @note When the NVIC_PriorityGroup_0 is selected, it will no any nested interrupt,
\r
85 the IRQ priority will be managed only by subpriority.
\r
86 The sub-priority is only used to sort pending exception priorities,
\r
87 and does not affect active exceptions.
\r
89 @note Lower priority values gives higher priority.
\r
91 @note Priority Order:
\r
92 1. Lowest Preemption priority
\r
93 2. Lowest Subpriority
\r
94 3. Lowest hardware priority (IRQn position)
\r
100 * @brief Configures the priority grouping: pre-emption priority and subpriority.
\r
101 * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
\r
102 * This parameter can be one of the following values:
\r
103 * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
\r
104 * 4 bits for subpriority
\r
105 * @note When NVIC_PriorityGroup_0 is selected, it will no be any nested
\r
106 * interrupt. This interrupts priority is managed only with 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
117 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
\r
119 /* Check the parameters */
\r
120 assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
\r
122 /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
\r
123 SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
\r
127 * @brief Initializes the NVIC peripheral according to the specified
\r
128 * parameters in the NVIC_InitStruct.
\r
129 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
\r
130 * function should be called before.
\r
131 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
\r
132 * the configuration information for the specified NVIC peripheral.
\r
135 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
\r
137 uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
\r
139 /* Check the parameters */
\r
140 assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
\r
141 assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
\r
142 assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
\r
144 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
\r
146 /* Compute the Corresponding IRQ Priority --------------------------------*/
\r
147 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
\r
148 tmppre = (0x4 - tmppriority);
\r
149 tmpsub = tmpsub >> tmppriority;
\r
151 tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
\r
152 tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
\r
153 tmppriority = tmppriority << 0x04;
\r
155 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
\r
157 /* Enable the Selected IRQ Channels --------------------------------------*/
\r
158 NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
\r
159 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
\r
163 /* Disable the Selected IRQ Channels -------------------------------------*/
\r
164 NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
\r
165 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
\r
170 * @brief Sets the vector table location and Offset.
\r
171 * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
\r
172 * This parameter can be one of the following values:
\r
173 * @arg NVIC_VectTab_RAM
\r
174 * @arg NVIC_VectTab_FLASH
\r
175 * @param Offset: Vector Table base offset field. This value must be a multiple of 0x200.
\r
178 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
\r
180 /* Check the parameters */
\r
181 assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
\r
182 assert_param(IS_NVIC_OFFSET(Offset));
\r
184 SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
\r
188 * @brief Selects the condition for the system to enter low power mode.
\r
189 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
\r
190 * This parameter can be one of the following values:
\r
191 * @arg NVIC_LP_SEVONPEND
\r
192 * @arg NVIC_LP_SLEEPDEEP
\r
193 * @arg NVIC_LP_SLEEPONEXIT
\r
194 * @param NewState: new state of LP condition.
\r
195 * This parameter can be: ENABLE or DISABLE.
\r
198 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
\r
200 /* Check the parameters */
\r
201 assert_param(IS_NVIC_LP(LowPowerMode));
\r
202 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
204 if (NewState != DISABLE)
\r
206 SCB->SCR |= LowPowerMode;
\r
210 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
\r
215 * @brief Configures the SysTick clock source.
\r
216 * @param SysTick_CLKSource: specifies the SysTick clock source.
\r
217 * This parameter can be one of the following values:
\r
218 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
\r
219 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
\r
222 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
\r
224 /* Check the parameters */
\r
225 assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
\r
227 if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
\r
229 SysTick->CTRL |= SysTick_CLKSource_HCLK;
\r
233 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
\r
249 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
\r