mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Jan 30 12:15:05 2014 +0000
Revision:
80:66393a7b209d
Parent:
76:aeb1df146756
Child:
106:ced8cbb51063
Synchronized with git revision dba523f83fe09b7fce11fc1299dd1216e9776359

Full URL: https://github.com/mbedmicro/mbed/commit/dba523f83fe09b7fce11fc1299dd1216e9776359/

Update of I2C, SPI, SLEEP for NUCLEO_F103RB and L152RE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /**
mbed_official 76:aeb1df146756 2 ******************************************************************************
mbed_official 76:aeb1df146756 3 * @file stm32l1xx_exti.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 80:66393a7b209d 5 * @version V1.3.0
mbed_official 80:66393a7b209d 6 * @date 31-January-2014
mbed_official 76:aeb1df146756 7 * @brief This file provides firmware functions to manage the following
mbed_official 76:aeb1df146756 8 * functionalities of the EXTI peripheral:
mbed_official 76:aeb1df146756 9 * + Initialization and Configuration
mbed_official 76:aeb1df146756 10 * + Interrupts and flags management
mbed_official 76:aeb1df146756 11 *
mbed_official 76:aeb1df146756 12 * @verbatim
mbed_official 76:aeb1df146756 13 ==============================================================================
mbed_official 76:aeb1df146756 14 ##### EXTI features #####
mbed_official 76:aeb1df146756 15 ==============================================================================
mbed_official 76:aeb1df146756 16 [..] External interrupt/event lines are mapped as following:
mbed_official 76:aeb1df146756 17 (#) All available GPIO pins are connected to the 16 external
mbed_official 76:aeb1df146756 18 interrupt/event lines from EXTI0 to EXTI15.
mbed_official 76:aeb1df146756 19 (#) EXTI line 16 is connected to the PVD output.
mbed_official 76:aeb1df146756 20 (#) EXTI line 17 is connected to the RTC Alarm event.
mbed_official 76:aeb1df146756 21 (#) EXTI line 18 is connected to the USB Device FS wakeup event.
mbed_official 76:aeb1df146756 22 (#) EXTI line 19 is connected to the RTC Tamper and TimeStamp events.
mbed_official 76:aeb1df146756 23 (#) EXTI line 20 is connected to the RTC Wakeup event.
mbed_official 76:aeb1df146756 24 (#) EXTI line 21 is connected to the Comparator 1 wakeup event.
mbed_official 76:aeb1df146756 25 (#) EXTI line 22 is connected to the Comparator 2 wakeup event.
mbed_official 76:aeb1df146756 26 (#) EXTI line 23 is connected to the Comparator channel acquisition wakeup event.
mbed_official 76:aeb1df146756 27
mbed_official 76:aeb1df146756 28
mbed_official 76:aeb1df146756 29 ##### How to use this driver #####
mbed_official 76:aeb1df146756 30 ==============================================================================
mbed_official 76:aeb1df146756 31 [..] In order to use an I/O pin as an external interrupt source, follow
mbed_official 76:aeb1df146756 32 steps below:
mbed_official 76:aeb1df146756 33 (#) Configure the I/O in input mode using GPIO_Init()
mbed_official 76:aeb1df146756 34 (#) Select the input source pin for the EXTI line using
mbed_official 76:aeb1df146756 35 SYSCFG_EXTILineConfig()
mbed_official 76:aeb1df146756 36 (#) Select the mode(interrupt, event) and configure the trigger
mbed_official 76:aeb1df146756 37 selection (Rising, falling or both) using EXTI_Init()
mbed_official 76:aeb1df146756 38 (#) Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init()
mbed_official 76:aeb1df146756 39 [..]
mbed_official 76:aeb1df146756 40 (@) SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx
mbed_official 76:aeb1df146756 41 registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
mbed_official 76:aeb1df146756 42
mbed_official 76:aeb1df146756 43 * @endverbatim
mbed_official 76:aeb1df146756 44 *
mbed_official 76:aeb1df146756 45 ******************************************************************************
mbed_official 76:aeb1df146756 46 * @attention
mbed_official 76:aeb1df146756 47 *
mbed_official 80:66393a7b209d 48 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 49 *
mbed_official 76:aeb1df146756 50 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 51 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 52 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 53 *
mbed_official 76:aeb1df146756 54 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 55 *
mbed_official 76:aeb1df146756 56 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 57 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 58 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 59 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 60 * limitations under the License.
mbed_official 76:aeb1df146756 61 *
mbed_official 76:aeb1df146756 62 ******************************************************************************
mbed_official 76:aeb1df146756 63 */
mbed_official 76:aeb1df146756 64
mbed_official 76:aeb1df146756 65 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 66 #include "stm32l1xx_exti.h"
mbed_official 76:aeb1df146756 67
mbed_official 76:aeb1df146756 68 /** @addtogroup STM32L1xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 69 * @{
mbed_official 76:aeb1df146756 70 */
mbed_official 76:aeb1df146756 71
mbed_official 76:aeb1df146756 72 /** @defgroup EXTI
mbed_official 76:aeb1df146756 73 * @brief EXTI driver modules
mbed_official 76:aeb1df146756 74 * @{
mbed_official 76:aeb1df146756 75 */
mbed_official 76:aeb1df146756 76
mbed_official 76:aeb1df146756 77 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 78 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 79 #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
mbed_official 76:aeb1df146756 80
mbed_official 76:aeb1df146756 81 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 82 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 83 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 84 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 85
mbed_official 76:aeb1df146756 86 /** @defgroup EXTI_Private_Functions
mbed_official 76:aeb1df146756 87 * @{
mbed_official 76:aeb1df146756 88 */
mbed_official 76:aeb1df146756 89
mbed_official 76:aeb1df146756 90 /** @defgroup EXTI_Group1 Initialization and Configuration functions
mbed_official 76:aeb1df146756 91 * @brief Initialization and Configuration functions
mbed_official 76:aeb1df146756 92 *
mbed_official 76:aeb1df146756 93 @verbatim
mbed_official 76:aeb1df146756 94 ==============================================================================
mbed_official 76:aeb1df146756 95 ##### Initialization and Configuration functions #####
mbed_official 76:aeb1df146756 96 ==============================================================================
mbed_official 76:aeb1df146756 97
mbed_official 76:aeb1df146756 98 @endverbatim
mbed_official 76:aeb1df146756 99 * @{
mbed_official 76:aeb1df146756 100 */
mbed_official 76:aeb1df146756 101
mbed_official 76:aeb1df146756 102 /**
mbed_official 76:aeb1df146756 103 * @brief Deinitializes the EXTI peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 104 * @param None
mbed_official 76:aeb1df146756 105 * @retval None
mbed_official 76:aeb1df146756 106 */
mbed_official 76:aeb1df146756 107 void EXTI_DeInit(void)
mbed_official 76:aeb1df146756 108 {
mbed_official 76:aeb1df146756 109 EXTI->IMR = 0x00000000;
mbed_official 76:aeb1df146756 110 EXTI->EMR = 0x00000000;
mbed_official 76:aeb1df146756 111 EXTI->RTSR = 0x00000000;
mbed_official 76:aeb1df146756 112 EXTI->FTSR = 0x00000000;
mbed_official 76:aeb1df146756 113 EXTI->PR = 0x00FFFFFF;
mbed_official 76:aeb1df146756 114 }
mbed_official 76:aeb1df146756 115
mbed_official 76:aeb1df146756 116 /**
mbed_official 76:aeb1df146756 117 * @brief Initializes the EXTI peripheral according to the specified
mbed_official 76:aeb1df146756 118 * parameters in the EXTI_InitStruct.
mbed_official 76:aeb1df146756 119 * EXTI_Line specifies the EXTI line (EXTI0....EXTI23).
mbed_official 76:aeb1df146756 120 * EXTI_Mode specifies which EXTI line is used as interrupt or an event.
mbed_official 76:aeb1df146756 121 * EXTI_Trigger selects the trigger. When the trigger occurs, interrupt
mbed_official 76:aeb1df146756 122 * pending bit will be set.
mbed_official 76:aeb1df146756 123 * EXTI_LineCmd controls (Enable/Disable) the EXTI line.
mbed_official 76:aeb1df146756 124 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
mbed_official 76:aeb1df146756 125 * that contains the configuration information for the EXTI peripheral.
mbed_official 76:aeb1df146756 126 * @retval None
mbed_official 76:aeb1df146756 127 */
mbed_official 76:aeb1df146756 128 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
mbed_official 76:aeb1df146756 129 {
mbed_official 76:aeb1df146756 130 uint32_t tmp = 0;
mbed_official 76:aeb1df146756 131
mbed_official 76:aeb1df146756 132 /* Check the parameters */
mbed_official 76:aeb1df146756 133 assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
mbed_official 76:aeb1df146756 134 assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
mbed_official 76:aeb1df146756 135 assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
mbed_official 76:aeb1df146756 136 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
mbed_official 76:aeb1df146756 137
mbed_official 76:aeb1df146756 138 tmp = (uint32_t)EXTI_BASE;
mbed_official 76:aeb1df146756 139
mbed_official 76:aeb1df146756 140 if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
mbed_official 76:aeb1df146756 141 {
mbed_official 76:aeb1df146756 142 /* Clear EXTI line configuration */
mbed_official 76:aeb1df146756 143 EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 144 EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 145
mbed_official 76:aeb1df146756 146 tmp += EXTI_InitStruct->EXTI_Mode;
mbed_official 76:aeb1df146756 147
mbed_official 76:aeb1df146756 148 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 149
mbed_official 76:aeb1df146756 150 /* Clear Rising Falling edge configuration */
mbed_official 76:aeb1df146756 151 EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 152 EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 153
mbed_official 76:aeb1df146756 154 /* Select the trigger for the selected external interrupts */
mbed_official 76:aeb1df146756 155 if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
mbed_official 76:aeb1df146756 156 {
mbed_official 76:aeb1df146756 157 /* Rising Falling edge */
mbed_official 76:aeb1df146756 158 EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 159 EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 160 }
mbed_official 76:aeb1df146756 161 else
mbed_official 76:aeb1df146756 162 {
mbed_official 76:aeb1df146756 163 tmp = (uint32_t)EXTI_BASE;
mbed_official 76:aeb1df146756 164 tmp += EXTI_InitStruct->EXTI_Trigger;
mbed_official 76:aeb1df146756 165
mbed_official 76:aeb1df146756 166 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 167 }
mbed_official 76:aeb1df146756 168 }
mbed_official 76:aeb1df146756 169 else
mbed_official 76:aeb1df146756 170 {
mbed_official 76:aeb1df146756 171 tmp += EXTI_InitStruct->EXTI_Mode;
mbed_official 76:aeb1df146756 172
mbed_official 76:aeb1df146756 173 /* Disable the selected external lines */
mbed_official 76:aeb1df146756 174 *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
mbed_official 76:aeb1df146756 175 }
mbed_official 76:aeb1df146756 176 }
mbed_official 76:aeb1df146756 177
mbed_official 76:aeb1df146756 178 /**
mbed_official 76:aeb1df146756 179 * @brief Fills each EXTI_InitStruct member with its reset value.
mbed_official 76:aeb1df146756 180 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
mbed_official 76:aeb1df146756 181 * be initialized.
mbed_official 76:aeb1df146756 182 * @retval None
mbed_official 76:aeb1df146756 183 */
mbed_official 76:aeb1df146756 184 void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
mbed_official 76:aeb1df146756 185 {
mbed_official 76:aeb1df146756 186 EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
mbed_official 76:aeb1df146756 187 EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
mbed_official 76:aeb1df146756 188 EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
mbed_official 76:aeb1df146756 189 EXTI_InitStruct->EXTI_LineCmd = DISABLE;
mbed_official 76:aeb1df146756 190 }
mbed_official 76:aeb1df146756 191
mbed_official 76:aeb1df146756 192 /**
mbed_official 76:aeb1df146756 193 * @brief Generates a Software interrupt on selected EXTI line.
mbed_official 76:aeb1df146756 194 * @param EXTI_Line: specifies the EXTI line on which the software interrupt
mbed_official 76:aeb1df146756 195 * will be generated.
mbed_official 76:aeb1df146756 196 * This parameter can be any combination of EXTI_Linex where x can be (0..23).
mbed_official 76:aeb1df146756 197 * @retval None
mbed_official 76:aeb1df146756 198 */
mbed_official 76:aeb1df146756 199 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
mbed_official 76:aeb1df146756 200 {
mbed_official 76:aeb1df146756 201 /* Check the parameters */
mbed_official 76:aeb1df146756 202 assert_param(IS_EXTI_LINE(EXTI_Line));
mbed_official 76:aeb1df146756 203
mbed_official 76:aeb1df146756 204 EXTI->SWIER |= EXTI_Line;
mbed_official 76:aeb1df146756 205 }
mbed_official 76:aeb1df146756 206
mbed_official 76:aeb1df146756 207 /**
mbed_official 76:aeb1df146756 208 * @}
mbed_official 76:aeb1df146756 209 */
mbed_official 76:aeb1df146756 210
mbed_official 76:aeb1df146756 211 /** @defgroup EXTI_Group2 Interrupts and flags management functions
mbed_official 76:aeb1df146756 212 * @brief Interrupts and flags management functions
mbed_official 76:aeb1df146756 213 *
mbed_official 76:aeb1df146756 214 @verbatim
mbed_official 76:aeb1df146756 215 ==============================================================================
mbed_official 76:aeb1df146756 216 ##### Interrupts and flags management functions #####
mbed_official 76:aeb1df146756 217 ==============================================================================
mbed_official 76:aeb1df146756 218
mbed_official 76:aeb1df146756 219 @endverbatim
mbed_official 76:aeb1df146756 220 * @{
mbed_official 76:aeb1df146756 221 */
mbed_official 76:aeb1df146756 222
mbed_official 76:aeb1df146756 223 /**
mbed_official 76:aeb1df146756 224 * @brief Checks whether the specified EXTI line flag is set or not.
mbed_official 76:aeb1df146756 225 * @param EXTI_Line: specifies the EXTI line flag to check.
mbed_official 76:aeb1df146756 226 * This parameter can be:
mbed_official 76:aeb1df146756 227 * EXTI_Linex: External interrupt line x where x(0..23).
mbed_official 76:aeb1df146756 228 * @retval The new state of EXTI_Line (SET or RESET).
mbed_official 76:aeb1df146756 229 */
mbed_official 76:aeb1df146756 230 FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
mbed_official 76:aeb1df146756 231 {
mbed_official 76:aeb1df146756 232 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 233 /* Check the parameters */
mbed_official 76:aeb1df146756 234 assert_param(IS_GET_EXTI_LINE(EXTI_Line));
mbed_official 76:aeb1df146756 235
mbed_official 76:aeb1df146756 236 if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 237 {
mbed_official 76:aeb1df146756 238 bitstatus = SET;
mbed_official 76:aeb1df146756 239 }
mbed_official 76:aeb1df146756 240 else
mbed_official 76:aeb1df146756 241 {
mbed_official 76:aeb1df146756 242 bitstatus = RESET;
mbed_official 76:aeb1df146756 243 }
mbed_official 76:aeb1df146756 244 return bitstatus;
mbed_official 76:aeb1df146756 245 }
mbed_official 76:aeb1df146756 246
mbed_official 76:aeb1df146756 247 /**
mbed_official 76:aeb1df146756 248 * @brief Clears the EXTI's line pending flags.
mbed_official 76:aeb1df146756 249 * @param EXTI_Line: specifies the EXTI lines flags to clear.
mbed_official 76:aeb1df146756 250 * This parameter can be any combination of EXTI_Linex where x can be (0..23).
mbed_official 76:aeb1df146756 251 * @retval None
mbed_official 76:aeb1df146756 252 */
mbed_official 76:aeb1df146756 253 void EXTI_ClearFlag(uint32_t EXTI_Line)
mbed_official 76:aeb1df146756 254 {
mbed_official 76:aeb1df146756 255 /* Check the parameters */
mbed_official 76:aeb1df146756 256 assert_param(IS_EXTI_LINE(EXTI_Line));
mbed_official 76:aeb1df146756 257
mbed_official 76:aeb1df146756 258 EXTI->PR = EXTI_Line;
mbed_official 76:aeb1df146756 259 }
mbed_official 76:aeb1df146756 260
mbed_official 76:aeb1df146756 261 /**
mbed_official 76:aeb1df146756 262 * @brief Checks whether the specified EXTI line is asserted or not.
mbed_official 76:aeb1df146756 263 * @param EXTI_Line: specifies the EXTI line to check.
mbed_official 76:aeb1df146756 264 * This parameter can be:
mbed_official 76:aeb1df146756 265 * EXTI_Linex: External interrupt line x where x(0..23).
mbed_official 76:aeb1df146756 266 * @retval The new state of EXTI_Line (SET or RESET).
mbed_official 76:aeb1df146756 267 */
mbed_official 76:aeb1df146756 268 ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
mbed_official 76:aeb1df146756 269 {
mbed_official 76:aeb1df146756 270 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 271 /* Check the parameters */
mbed_official 76:aeb1df146756 272 assert_param(IS_GET_EXTI_LINE(EXTI_Line));
mbed_official 76:aeb1df146756 273
mbed_official 76:aeb1df146756 274 if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 275 {
mbed_official 76:aeb1df146756 276 bitstatus = SET;
mbed_official 76:aeb1df146756 277 }
mbed_official 76:aeb1df146756 278 else
mbed_official 76:aeb1df146756 279 {
mbed_official 76:aeb1df146756 280 bitstatus = RESET;
mbed_official 76:aeb1df146756 281 }
mbed_official 76:aeb1df146756 282 return bitstatus;
mbed_official 76:aeb1df146756 283 }
mbed_official 76:aeb1df146756 284
mbed_official 76:aeb1df146756 285 /**
mbed_official 76:aeb1df146756 286 * @brief Clears the EXTI's line pending bits.
mbed_official 76:aeb1df146756 287 * @param EXTI_Line: specifies the EXTI lines to clear.
mbed_official 76:aeb1df146756 288 * This parameter can be any combination of EXTI_Linex where x can be (0..23).
mbed_official 76:aeb1df146756 289 * @retval None
mbed_official 76:aeb1df146756 290 */
mbed_official 76:aeb1df146756 291 void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
mbed_official 76:aeb1df146756 292 {
mbed_official 76:aeb1df146756 293 /* Check the parameters */
mbed_official 76:aeb1df146756 294 assert_param(IS_EXTI_LINE(EXTI_Line));
mbed_official 76:aeb1df146756 295
mbed_official 76:aeb1df146756 296 EXTI->PR = EXTI_Line;
mbed_official 76:aeb1df146756 297 }
mbed_official 76:aeb1df146756 298
mbed_official 76:aeb1df146756 299 /**
mbed_official 76:aeb1df146756 300 * @}
mbed_official 76:aeb1df146756 301 */
mbed_official 76:aeb1df146756 302
mbed_official 76:aeb1df146756 303 /**
mbed_official 76:aeb1df146756 304 * @}
mbed_official 76:aeb1df146756 305 */
mbed_official 76:aeb1df146756 306
mbed_official 76:aeb1df146756 307 /**
mbed_official 76:aeb1df146756 308 * @}
mbed_official 76:aeb1df146756 309 */
mbed_official 76:aeb1df146756 310
mbed_official 76:aeb1df146756 311 /**
mbed_official 76:aeb1df146756 312 * @}
mbed_official 76:aeb1df146756 313 */
mbed_official 76:aeb1df146756 314
mbed_official 76:aeb1df146756 315 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/