mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_misc.c@637:ed69428d4850, 2015-12-22 (annotated)
- Committer:
- jaerts
- Date:
- Tue Dec 22 13:22:16 2015 +0000
- Revision:
- 637:ed69428d4850
- Parent:
- 155:8435094ec241
Add very shady LPC1768 CAN Filter implementation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 155:8435094ec241 | 1 | /** |
mbed_official | 155:8435094ec241 | 2 | ****************************************************************************** |
mbed_official | 155:8435094ec241 | 3 | * @file stm32f30x_misc.c |
mbed_official | 155:8435094ec241 | 4 | * @author MCD Application Team |
mbed_official | 155:8435094ec241 | 5 | * @version V1.1.0 |
mbed_official | 155:8435094ec241 | 6 | * @date 27-February-2014 |
mbed_official | 155:8435094ec241 | 7 | * @brief This file provides all the miscellaneous firmware functions (add-on |
mbed_official | 155:8435094ec241 | 8 | * to CMSIS functions). |
mbed_official | 155:8435094ec241 | 9 | * |
mbed_official | 155:8435094ec241 | 10 | @verbatim |
mbed_official | 155:8435094ec241 | 11 | |
mbed_official | 155:8435094ec241 | 12 | =============================================================================== |
mbed_official | 155:8435094ec241 | 13 | ##### How to configure Interrupts using driver ##### |
mbed_official | 155:8435094ec241 | 14 | =============================================================================== |
mbed_official | 155:8435094ec241 | 15 | [..] This section provide functions allowing to configure the NVIC interrupts |
mbed_official | 155:8435094ec241 | 16 | (IRQ). The Cortex-M4 exceptions are managed by CMSIS functions. |
mbed_official | 155:8435094ec241 | 17 | (#) Configure the NVIC Priority Grouping using NVIC_PriorityGroupConfig() |
mbed_official | 155:8435094ec241 | 18 | function according to the following table. |
mbed_official | 155:8435094ec241 | 19 | The table below gives the allowed values of the pre-emption priority |
mbed_official | 155:8435094ec241 | 20 | and subpriority according to the Priority Grouping configuration |
mbed_official | 155:8435094ec241 | 21 | performed by NVIC_PriorityGroupConfig function. |
mbed_official | 155:8435094ec241 | 22 | |
mbed_official | 155:8435094ec241 | 23 | (#) Enable and Configure the priority of the selected IRQ Channels. |
mbed_official | 155:8435094ec241 | 24 | [..] |
mbed_official | 155:8435094ec241 | 25 | (@) When the NVIC_PriorityGroup_0 is selected, it will no any nested interrupt, |
mbed_official | 155:8435094ec241 | 26 | the IRQ priority will be managed only by subpriority. |
mbed_official | 155:8435094ec241 | 27 | The sub-priority is only used to sort pending exception priorities, |
mbed_official | 155:8435094ec241 | 28 | and does not affect active exceptions. |
mbed_official | 155:8435094ec241 | 29 | (@) Lower priority values gives higher priority. |
mbed_official | 155:8435094ec241 | 30 | (@) Priority Order: |
mbed_official | 155:8435094ec241 | 31 | (#@) Lowest Preemption priority. |
mbed_official | 155:8435094ec241 | 32 | (#@) Lowest Subpriority. |
mbed_official | 155:8435094ec241 | 33 | (#@) Lowest hardware priority (IRQn position). |
mbed_official | 155:8435094ec241 | 34 | |
mbed_official | 155:8435094ec241 | 35 | @endverbatim |
mbed_official | 155:8435094ec241 | 36 | |
mbed_official | 155:8435094ec241 | 37 | ****************************************************************************** |
mbed_official | 155:8435094ec241 | 38 | * @attention |
mbed_official | 155:8435094ec241 | 39 | * |
mbed_official | 155:8435094ec241 | 40 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 155:8435094ec241 | 41 | * |
mbed_official | 155:8435094ec241 | 42 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 155:8435094ec241 | 43 | * are permitted provided that the following conditions are met: |
mbed_official | 155:8435094ec241 | 44 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 155:8435094ec241 | 45 | * this list of conditions and the following disclaimer. |
mbed_official | 155:8435094ec241 | 46 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 155:8435094ec241 | 47 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 155:8435094ec241 | 48 | * and/or other materials provided with the distribution. |
mbed_official | 155:8435094ec241 | 49 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 155:8435094ec241 | 50 | * may be used to endorse or promote products derived from this software |
mbed_official | 155:8435094ec241 | 51 | * without specific prior written permission. |
mbed_official | 155:8435094ec241 | 52 | * |
mbed_official | 155:8435094ec241 | 53 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 155:8435094ec241 | 54 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 155:8435094ec241 | 55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 155:8435094ec241 | 56 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 155:8435094ec241 | 57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 155:8435094ec241 | 58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 155:8435094ec241 | 59 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 155:8435094ec241 | 60 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 155:8435094ec241 | 61 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 155:8435094ec241 | 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 155:8435094ec241 | 63 | * |
mbed_official | 155:8435094ec241 | 64 | ****************************************************************************** |
mbed_official | 155:8435094ec241 | 65 | */ |
mbed_official | 155:8435094ec241 | 66 | |
mbed_official | 155:8435094ec241 | 67 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 68 | #include "stm32f30x_misc.h" |
mbed_official | 155:8435094ec241 | 69 | |
mbed_official | 155:8435094ec241 | 70 | /** @addtogroup STM32F30x_StdPeriph_Driver |
mbed_official | 155:8435094ec241 | 71 | * @{ |
mbed_official | 155:8435094ec241 | 72 | */ |
mbed_official | 155:8435094ec241 | 73 | |
mbed_official | 155:8435094ec241 | 74 | /** @defgroup MISC |
mbed_official | 155:8435094ec241 | 75 | * @brief MISC driver modules |
mbed_official | 155:8435094ec241 | 76 | * @{ |
mbed_official | 155:8435094ec241 | 77 | */ |
mbed_official | 155:8435094ec241 | 78 | |
mbed_official | 155:8435094ec241 | 79 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 80 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 81 | #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) |
mbed_official | 155:8435094ec241 | 82 | |
mbed_official | 155:8435094ec241 | 83 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 84 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 85 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 86 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 155:8435094ec241 | 87 | |
mbed_official | 155:8435094ec241 | 88 | /** @defgroup MISC_Private_Functions |
mbed_official | 155:8435094ec241 | 89 | * @{ |
mbed_official | 155:8435094ec241 | 90 | */ |
mbed_official | 155:8435094ec241 | 91 | |
mbed_official | 155:8435094ec241 | 92 | /** |
mbed_official | 155:8435094ec241 | 93 | * @brief Configures the priority grouping: pre-emption priority and subpriority. |
mbed_official | 155:8435094ec241 | 94 | * @param NVIC_PriorityGroup: specifies the priority grouping bits length. |
mbed_official | 155:8435094ec241 | 95 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 96 | * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority. |
mbed_official | 155:8435094ec241 | 97 | * 4 bits for subpriority. |
mbed_official | 155:8435094ec241 | 98 | * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority. |
mbed_official | 155:8435094ec241 | 99 | * 3 bits for subpriority. |
mbed_official | 155:8435094ec241 | 100 | * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority. |
mbed_official | 155:8435094ec241 | 101 | * 2 bits for subpriority. |
mbed_official | 155:8435094ec241 | 102 | * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority. |
mbed_official | 155:8435094ec241 | 103 | * 1 bits for subpriority. |
mbed_official | 155:8435094ec241 | 104 | * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority. |
mbed_official | 155:8435094ec241 | 105 | * 0 bits for subpriority. |
mbed_official | 155:8435094ec241 | 106 | * @note When NVIC_PriorityGroup_0 is selected, it will no be any nested |
mbed_official | 155:8435094ec241 | 107 | * interrupt. This interrupts priority is managed only with subpriority. |
mbed_official | 155:8435094ec241 | 108 | * @retval None |
mbed_official | 155:8435094ec241 | 109 | */ |
mbed_official | 155:8435094ec241 | 110 | void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) |
mbed_official | 155:8435094ec241 | 111 | { |
mbed_official | 155:8435094ec241 | 112 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 113 | assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); |
mbed_official | 155:8435094ec241 | 114 | |
mbed_official | 155:8435094ec241 | 115 | /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ |
mbed_official | 155:8435094ec241 | 116 | SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; |
mbed_official | 155:8435094ec241 | 117 | } |
mbed_official | 155:8435094ec241 | 118 | |
mbed_official | 155:8435094ec241 | 119 | /** |
mbed_official | 155:8435094ec241 | 120 | * @brief Initializes the NVIC peripheral according to the specified |
mbed_official | 155:8435094ec241 | 121 | * parameters in the NVIC_InitStruct. |
mbed_official | 155:8435094ec241 | 122 | * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig() |
mbed_official | 155:8435094ec241 | 123 | * function should be called before. |
mbed_official | 155:8435094ec241 | 124 | * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains |
mbed_official | 155:8435094ec241 | 125 | * the configuration information for the specified NVIC peripheral. |
mbed_official | 155:8435094ec241 | 126 | * @retval None |
mbed_official | 155:8435094ec241 | 127 | */ |
mbed_official | 155:8435094ec241 | 128 | void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) |
mbed_official | 155:8435094ec241 | 129 | { |
mbed_official | 155:8435094ec241 | 130 | uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; |
mbed_official | 155:8435094ec241 | 131 | |
mbed_official | 155:8435094ec241 | 132 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 133 | assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); |
mbed_official | 155:8435094ec241 | 134 | assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); |
mbed_official | 155:8435094ec241 | 135 | assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); |
mbed_official | 155:8435094ec241 | 136 | |
mbed_official | 155:8435094ec241 | 137 | if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) |
mbed_official | 155:8435094ec241 | 138 | { |
mbed_official | 155:8435094ec241 | 139 | /* Compute the Corresponding IRQ Priority --------------------------------*/ |
mbed_official | 155:8435094ec241 | 140 | tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; |
mbed_official | 155:8435094ec241 | 141 | tmppre = (0x4 - tmppriority); |
mbed_official | 155:8435094ec241 | 142 | tmpsub = tmpsub >> tmppriority; |
mbed_official | 155:8435094ec241 | 143 | |
mbed_official | 155:8435094ec241 | 144 | tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; |
mbed_official | 155:8435094ec241 | 145 | tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; |
mbed_official | 155:8435094ec241 | 146 | tmppriority = tmppriority << 0x04; |
mbed_official | 155:8435094ec241 | 147 | |
mbed_official | 155:8435094ec241 | 148 | NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; |
mbed_official | 155:8435094ec241 | 149 | |
mbed_official | 155:8435094ec241 | 150 | /* Enable the Selected IRQ Channels --------------------------------------*/ |
mbed_official | 155:8435094ec241 | 151 | NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = |
mbed_official | 155:8435094ec241 | 152 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); |
mbed_official | 155:8435094ec241 | 153 | } |
mbed_official | 155:8435094ec241 | 154 | else |
mbed_official | 155:8435094ec241 | 155 | { |
mbed_official | 155:8435094ec241 | 156 | /* Disable the Selected IRQ Channels -------------------------------------*/ |
mbed_official | 155:8435094ec241 | 157 | NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = |
mbed_official | 155:8435094ec241 | 158 | (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); |
mbed_official | 155:8435094ec241 | 159 | } |
mbed_official | 155:8435094ec241 | 160 | } |
mbed_official | 155:8435094ec241 | 161 | |
mbed_official | 155:8435094ec241 | 162 | /** |
mbed_official | 155:8435094ec241 | 163 | * @brief Sets the vector table location and Offset. |
mbed_official | 155:8435094ec241 | 164 | * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory. |
mbed_official | 155:8435094ec241 | 165 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 166 | * @arg NVIC_VectTab_RAM |
mbed_official | 155:8435094ec241 | 167 | * @arg NVIC_VectTab_FLASH |
mbed_official | 155:8435094ec241 | 168 | * @param Offset: Vector Table base offset field. This value must be a multiple of 0x200. |
mbed_official | 155:8435094ec241 | 169 | * @retval None |
mbed_official | 155:8435094ec241 | 170 | */ |
mbed_official | 155:8435094ec241 | 171 | void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset) |
mbed_official | 155:8435094ec241 | 172 | { |
mbed_official | 155:8435094ec241 | 173 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 174 | assert_param(IS_NVIC_VECTTAB(NVIC_VectTab)); |
mbed_official | 155:8435094ec241 | 175 | assert_param(IS_NVIC_OFFSET(Offset)); |
mbed_official | 155:8435094ec241 | 176 | |
mbed_official | 155:8435094ec241 | 177 | SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); |
mbed_official | 155:8435094ec241 | 178 | } |
mbed_official | 155:8435094ec241 | 179 | |
mbed_official | 155:8435094ec241 | 180 | /** |
mbed_official | 155:8435094ec241 | 181 | * @brief Selects the condition for the system to enter low power mode. |
mbed_official | 155:8435094ec241 | 182 | * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. |
mbed_official | 155:8435094ec241 | 183 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 184 | * @arg NVIC_LP_SEVONPEND |
mbed_official | 155:8435094ec241 | 185 | * @arg NVIC_LP_SLEEPDEEP |
mbed_official | 155:8435094ec241 | 186 | * @arg NVIC_LP_SLEEPONEXIT |
mbed_official | 155:8435094ec241 | 187 | * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE. |
mbed_official | 155:8435094ec241 | 188 | * @retval None |
mbed_official | 155:8435094ec241 | 189 | */ |
mbed_official | 155:8435094ec241 | 190 | void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) |
mbed_official | 155:8435094ec241 | 191 | { |
mbed_official | 155:8435094ec241 | 192 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 193 | assert_param(IS_NVIC_LP(LowPowerMode)); |
mbed_official | 155:8435094ec241 | 194 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 155:8435094ec241 | 195 | |
mbed_official | 155:8435094ec241 | 196 | if (NewState != DISABLE) |
mbed_official | 155:8435094ec241 | 197 | { |
mbed_official | 155:8435094ec241 | 198 | SCB->SCR |= LowPowerMode; |
mbed_official | 155:8435094ec241 | 199 | } |
mbed_official | 155:8435094ec241 | 200 | else |
mbed_official | 155:8435094ec241 | 201 | { |
mbed_official | 155:8435094ec241 | 202 | SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); |
mbed_official | 155:8435094ec241 | 203 | } |
mbed_official | 155:8435094ec241 | 204 | } |
mbed_official | 155:8435094ec241 | 205 | |
mbed_official | 155:8435094ec241 | 206 | /** |
mbed_official | 155:8435094ec241 | 207 | * @brief Configures the SysTick clock source. |
mbed_official | 155:8435094ec241 | 208 | * @param SysTick_CLKSource: specifies the SysTick clock source. |
mbed_official | 155:8435094ec241 | 209 | * This parameter can be one of the following values: |
mbed_official | 155:8435094ec241 | 210 | * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. |
mbed_official | 155:8435094ec241 | 211 | * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. |
mbed_official | 155:8435094ec241 | 212 | * @retval None |
mbed_official | 155:8435094ec241 | 213 | */ |
mbed_official | 155:8435094ec241 | 214 | void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) |
mbed_official | 155:8435094ec241 | 215 | { |
mbed_official | 155:8435094ec241 | 216 | /* Check the parameters */ |
mbed_official | 155:8435094ec241 | 217 | assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); |
mbed_official | 155:8435094ec241 | 218 | if (SysTick_CLKSource == SysTick_CLKSource_HCLK) |
mbed_official | 155:8435094ec241 | 219 | { |
mbed_official | 155:8435094ec241 | 220 | SysTick->CTRL |= SysTick_CLKSource_HCLK; |
mbed_official | 155:8435094ec241 | 221 | } |
mbed_official | 155:8435094ec241 | 222 | else |
mbed_official | 155:8435094ec241 | 223 | { |
mbed_official | 155:8435094ec241 | 224 | SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; |
mbed_official | 155:8435094ec241 | 225 | } |
mbed_official | 155:8435094ec241 | 226 | } |
mbed_official | 155:8435094ec241 | 227 | |
mbed_official | 155:8435094ec241 | 228 | /** |
mbed_official | 155:8435094ec241 | 229 | * @} |
mbed_official | 155:8435094ec241 | 230 | */ |
mbed_official | 155:8435094ec241 | 231 | |
mbed_official | 155:8435094ec241 | 232 | /** |
mbed_official | 155:8435094ec241 | 233 | * @} |
mbed_official | 155:8435094ec241 | 234 | */ |
mbed_official | 155:8435094ec241 | 235 | |
mbed_official | 155:8435094ec241 | 236 | /** |
mbed_official | 155:8435094ec241 | 237 | * @} |
mbed_official | 155:8435094ec241 | 238 | */ |
mbed_official | 155:8435094ec241 | 239 | |
mbed_official | 155:8435094ec241 | 240 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |