mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Tue Jan 07 11:00:05 2014 +0000
Revision:
70:c1fbde68b492
Parent:
52:a51c77007319
Child:
84:f54042cbc282
Synchronized with git revision 3f438a307904431f2782db3c8fa49946b9fc1d85

Full URL: https://github.com/mbedmicro/mbed/commit/3f438a307904431f2782db3c8fa49946b9fc1d85/

[NUCLEO_F103RB] license text changed + sleep hal updated

Who changed what in which revision?

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