mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Jan 27 14:30:07 2014 +0000
Revision:
76:aeb1df146756
Child:
80:66393a7b209d
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd

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

Add NUCLEO_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_iwdg.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 76:aeb1df146756 5 * @version V1.2.0
mbed_official 76:aeb1df146756 6 * @date 22-February-2013
mbed_official 76:aeb1df146756 7 * @brief This file provides firmware functions to manage the following
mbed_official 76:aeb1df146756 8 * functionalities of the Independent watchdog (IWDG) peripheral:
mbed_official 76:aeb1df146756 9 * + Prescaler and Counter configuration
mbed_official 76:aeb1df146756 10 * + IWDG activation
mbed_official 76:aeb1df146756 11 * + Flag management
mbed_official 76:aeb1df146756 12 *
mbed_official 76:aeb1df146756 13 * @verbatim
mbed_official 76:aeb1df146756 14 *
mbed_official 76:aeb1df146756 15 ==============================================================================
mbed_official 76:aeb1df146756 16 ##### IWDG features #####
mbed_official 76:aeb1df146756 17 ==============================================================================
mbed_official 76:aeb1df146756 18 [..] The IWDG can be started by either software or hardware (configurable
mbed_official 76:aeb1df146756 19 through option byte).
mbed_official 76:aeb1df146756 20
mbed_official 76:aeb1df146756 21 [..] The IWDG is clocked by its own dedicated low-speed clock (LSI) and
mbed_official 76:aeb1df146756 22 thus stays active even if the main clock fails.
mbed_official 76:aeb1df146756 23 Once the IWDG is started, the LSI is forced ON and cannot be disabled
mbed_official 76:aeb1df146756 24 (LSI cannot be disabled too), and the counter starts counting down from
mbed_official 76:aeb1df146756 25 the reset value of 0xFFF. When it reaches the end of count value (0x000)
mbed_official 76:aeb1df146756 26 a system reset is generated.
mbed_official 76:aeb1df146756 27 The IWDG counter should be reloaded at regular intervals to prevent
mbed_official 76:aeb1df146756 28 an MCU reset.
mbed_official 76:aeb1df146756 29
mbed_official 76:aeb1df146756 30 [..] The IWDG is implemented in the VDD voltage domain that is still functional
mbed_official 76:aeb1df146756 31 in STOP and STANDBY mode (IWDG reset can wake-up from STANDBY).
mbed_official 76:aeb1df146756 32
mbed_official 76:aeb1df146756 33 [..] IWDGRST flag in RCC_CSR register can be used to inform when a IWDG
mbed_official 76:aeb1df146756 34 reset occurs.
mbed_official 76:aeb1df146756 35
mbed_official 76:aeb1df146756 36 [..] Min-max timeout value @37KHz (LSI): ~108us / ~28.3s
mbed_official 76:aeb1df146756 37 The IWDG timeout may vary due to LSI frequency dispersion. STM32L1xx
mbed_official 76:aeb1df146756 38 devices provide the capability to measure the LSI frequency (LSI clock
mbed_official 76:aeb1df146756 39 connected internally to TIM10 CH1 input capture). The measured value
mbed_official 76:aeb1df146756 40 can be used to have an IWDG timeout with an acceptable accuracy.
mbed_official 76:aeb1df146756 41 For more information, please refer to the STM32L1xx Reference manual.
mbed_official 76:aeb1df146756 42
mbed_official 76:aeb1df146756 43 ##### How to use this driver #####
mbed_official 76:aeb1df146756 44 ==============================================================================
mbed_official 76:aeb1df146756 45 [..]
mbed_official 76:aeb1df146756 46 (#) Enable write access to IWDG_PR and IWDG_RLR registers using
mbed_official 76:aeb1df146756 47 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable) function.
mbed_official 76:aeb1df146756 48 (#) Configure the IWDG prescaler using IWDG_SetPrescaler() function.
mbed_official 76:aeb1df146756 49
mbed_official 76:aeb1df146756 50 (#) Configure the IWDG counter value using IWDG_SetReload() function.
mbed_official 76:aeb1df146756 51 This value will be loaded in the IWDG counter each time the counter
mbed_official 76:aeb1df146756 52 is reloaded, then the IWDG will start counting down from this value.
mbed_official 76:aeb1df146756 53
mbed_official 76:aeb1df146756 54 (#) Start the IWDG using IWDG_Enable() function, when the IWDG is used
mbed_official 76:aeb1df146756 55 in software mode (no need to enable the LSI, it will be enabled
mbed_official 76:aeb1df146756 56 by hardware).
mbed_official 76:aeb1df146756 57
mbed_official 76:aeb1df146756 58 (#) Then the application program must reload the IWDG counter at regular
mbed_official 76:aeb1df146756 59 intervals during normal operation to prevent an MCU reset, using
mbed_official 76:aeb1df146756 60 IWDG_ReloadCounter() function.
mbed_official 76:aeb1df146756 61
mbed_official 76:aeb1df146756 62 @endverbatim
mbed_official 76:aeb1df146756 63 *
mbed_official 76:aeb1df146756 64 ******************************************************************************
mbed_official 76:aeb1df146756 65 * @attention
mbed_official 76:aeb1df146756 66 *
mbed_official 76:aeb1df146756 67 * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 68 *
mbed_official 76:aeb1df146756 69 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 70 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 71 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 72 *
mbed_official 76:aeb1df146756 73 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 74 *
mbed_official 76:aeb1df146756 75 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 76 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 77 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 78 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 79 * limitations under the License.
mbed_official 76:aeb1df146756 80 *
mbed_official 76:aeb1df146756 81 ******************************************************************************
mbed_official 76:aeb1df146756 82 */
mbed_official 76:aeb1df146756 83
mbed_official 76:aeb1df146756 84 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 85 #include "stm32l1xx_iwdg.h"
mbed_official 76:aeb1df146756 86
mbed_official 76:aeb1df146756 87 /** @addtogroup STM32L1xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 88 * @{
mbed_official 76:aeb1df146756 89 */
mbed_official 76:aeb1df146756 90
mbed_official 76:aeb1df146756 91 /** @defgroup IWDG
mbed_official 76:aeb1df146756 92 * @brief IWDG driver modules
mbed_official 76:aeb1df146756 93 * @{
mbed_official 76:aeb1df146756 94 */
mbed_official 76:aeb1df146756 95
mbed_official 76:aeb1df146756 96 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 97 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 98 /* ---------------------- IWDG registers bit mask ----------------------------*/
mbed_official 76:aeb1df146756 99 /* KR register bit mask */
mbed_official 76:aeb1df146756 100 #define KR_KEY_RELOAD ((uint16_t)0xAAAA)
mbed_official 76:aeb1df146756 101 #define KR_KEY_ENABLE ((uint16_t)0xCCCC)
mbed_official 76:aeb1df146756 102
mbed_official 76:aeb1df146756 103 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 104 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 105 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 106 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 107
mbed_official 76:aeb1df146756 108 /** @defgroup IWDG_Private_Functions
mbed_official 76:aeb1df146756 109 * @{
mbed_official 76:aeb1df146756 110 */
mbed_official 76:aeb1df146756 111
mbed_official 76:aeb1df146756 112 /** @defgroup IWDG_Group1 Prescaler and Counter configuration functions
mbed_official 76:aeb1df146756 113 * @brief Prescaler and Counter configuration functions
mbed_official 76:aeb1df146756 114 *
mbed_official 76:aeb1df146756 115 @verbatim
mbed_official 76:aeb1df146756 116 ==============================================================================
mbed_official 76:aeb1df146756 117 ##### Prescaler and Counter configuration functions #####
mbed_official 76:aeb1df146756 118 ==============================================================================
mbed_official 76:aeb1df146756 119
mbed_official 76:aeb1df146756 120 @endverbatim
mbed_official 76:aeb1df146756 121 * @{
mbed_official 76:aeb1df146756 122 */
mbed_official 76:aeb1df146756 123
mbed_official 76:aeb1df146756 124 /**
mbed_official 76:aeb1df146756 125 * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
mbed_official 76:aeb1df146756 126 * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
mbed_official 76:aeb1df146756 127 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 128 * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
mbed_official 76:aeb1df146756 129 * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
mbed_official 76:aeb1df146756 130 * @retval None
mbed_official 76:aeb1df146756 131 */
mbed_official 76:aeb1df146756 132 void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
mbed_official 76:aeb1df146756 133 {
mbed_official 76:aeb1df146756 134 /* Check the parameters */
mbed_official 76:aeb1df146756 135 assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
mbed_official 76:aeb1df146756 136 IWDG->KR = IWDG_WriteAccess;
mbed_official 76:aeb1df146756 137 }
mbed_official 76:aeb1df146756 138
mbed_official 76:aeb1df146756 139 /**
mbed_official 76:aeb1df146756 140 * @brief Sets IWDG Prescaler value.
mbed_official 76:aeb1df146756 141 * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
mbed_official 76:aeb1df146756 142 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 143 * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
mbed_official 76:aeb1df146756 144 * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
mbed_official 76:aeb1df146756 145 * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
mbed_official 76:aeb1df146756 146 * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
mbed_official 76:aeb1df146756 147 * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
mbed_official 76:aeb1df146756 148 * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
mbed_official 76:aeb1df146756 149 * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
mbed_official 76:aeb1df146756 150 * @retval None
mbed_official 76:aeb1df146756 151 */
mbed_official 76:aeb1df146756 152 void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
mbed_official 76:aeb1df146756 153 {
mbed_official 76:aeb1df146756 154 /* Check the parameters */
mbed_official 76:aeb1df146756 155 assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
mbed_official 76:aeb1df146756 156 IWDG->PR = IWDG_Prescaler;
mbed_official 76:aeb1df146756 157 }
mbed_official 76:aeb1df146756 158
mbed_official 76:aeb1df146756 159 /**
mbed_official 76:aeb1df146756 160 * @brief Sets IWDG Reload value.
mbed_official 76:aeb1df146756 161 * @param Reload: specifies the IWDG Reload value.
mbed_official 76:aeb1df146756 162 * This parameter must be a number between 0 and 0x0FFF.
mbed_official 76:aeb1df146756 163 * @retval None
mbed_official 76:aeb1df146756 164 */
mbed_official 76:aeb1df146756 165 void IWDG_SetReload(uint16_t Reload)
mbed_official 76:aeb1df146756 166 {
mbed_official 76:aeb1df146756 167 /* Check the parameters */
mbed_official 76:aeb1df146756 168 assert_param(IS_IWDG_RELOAD(Reload));
mbed_official 76:aeb1df146756 169 IWDG->RLR = Reload;
mbed_official 76:aeb1df146756 170 }
mbed_official 76:aeb1df146756 171
mbed_official 76:aeb1df146756 172 /**
mbed_official 76:aeb1df146756 173 * @brief Reloads IWDG counter with value defined in the reload register
mbed_official 76:aeb1df146756 174 * (write access to IWDG_PR and IWDG_RLR registers disabled).
mbed_official 76:aeb1df146756 175 * @param None
mbed_official 76:aeb1df146756 176 * @retval None
mbed_official 76:aeb1df146756 177 */
mbed_official 76:aeb1df146756 178 void IWDG_ReloadCounter(void)
mbed_official 76:aeb1df146756 179 {
mbed_official 76:aeb1df146756 180 IWDG->KR = KR_KEY_RELOAD;
mbed_official 76:aeb1df146756 181 }
mbed_official 76:aeb1df146756 182
mbed_official 76:aeb1df146756 183 /**
mbed_official 76:aeb1df146756 184 * @}
mbed_official 76:aeb1df146756 185 */
mbed_official 76:aeb1df146756 186
mbed_official 76:aeb1df146756 187 /** @defgroup IWDG_Group2 IWDG activation function
mbed_official 76:aeb1df146756 188 * @brief IWDG activation function
mbed_official 76:aeb1df146756 189 *
mbed_official 76:aeb1df146756 190 @verbatim
mbed_official 76:aeb1df146756 191 ==============================================================================
mbed_official 76:aeb1df146756 192 ##### IWDG activation function #####
mbed_official 76:aeb1df146756 193 ==============================================================================
mbed_official 76:aeb1df146756 194
mbed_official 76:aeb1df146756 195 @endverbatim
mbed_official 76:aeb1df146756 196 * @{
mbed_official 76:aeb1df146756 197 */
mbed_official 76:aeb1df146756 198
mbed_official 76:aeb1df146756 199 /**
mbed_official 76:aeb1df146756 200 * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
mbed_official 76:aeb1df146756 201 * @param None.
mbed_official 76:aeb1df146756 202 * @retval None.
mbed_official 76:aeb1df146756 203 */
mbed_official 76:aeb1df146756 204 void IWDG_Enable(void)
mbed_official 76:aeb1df146756 205 {
mbed_official 76:aeb1df146756 206 IWDG->KR = KR_KEY_ENABLE;
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 */
mbed_official 76:aeb1df146756 212
mbed_official 76:aeb1df146756 213 /** @defgroup IWDG_Group3 Flag management function
mbed_official 76:aeb1df146756 214 * @brief Flag management function
mbed_official 76:aeb1df146756 215 *
mbed_official 76:aeb1df146756 216 @verbatim
mbed_official 76:aeb1df146756 217 ===============================================================================
mbed_official 76:aeb1df146756 218 ##### Flag management function #####
mbed_official 76:aeb1df146756 219 ===============================================================================
mbed_official 76:aeb1df146756 220
mbed_official 76:aeb1df146756 221 @endverbatim
mbed_official 76:aeb1df146756 222 * @{
mbed_official 76:aeb1df146756 223 */
mbed_official 76:aeb1df146756 224
mbed_official 76:aeb1df146756 225 /**
mbed_official 76:aeb1df146756 226 * @brief Checks whether the specified IWDG flag is set or not.
mbed_official 76:aeb1df146756 227 * @param IWDG_FLAG: specifies the flag to check.
mbed_official 76:aeb1df146756 228 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 229 * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
mbed_official 76:aeb1df146756 230 * @arg IWDG_FLAG_RVU: Reload Value Update on going
mbed_official 76:aeb1df146756 231 * @retval The new state of IWDG_FLAG (SET or RESET).
mbed_official 76:aeb1df146756 232 */
mbed_official 76:aeb1df146756 233 FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
mbed_official 76:aeb1df146756 234 {
mbed_official 76:aeb1df146756 235 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 236 /* Check the parameters */
mbed_official 76:aeb1df146756 237 assert_param(IS_IWDG_FLAG(IWDG_FLAG));
mbed_official 76:aeb1df146756 238 if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 239 {
mbed_official 76:aeb1df146756 240 bitstatus = SET;
mbed_official 76:aeb1df146756 241 }
mbed_official 76:aeb1df146756 242 else
mbed_official 76:aeb1df146756 243 {
mbed_official 76:aeb1df146756 244 bitstatus = RESET;
mbed_official 76:aeb1df146756 245 }
mbed_official 76:aeb1df146756 246 /* Return the flag status */
mbed_official 76:aeb1df146756 247 return bitstatus;
mbed_official 76:aeb1df146756 248 }
mbed_official 76:aeb1df146756 249
mbed_official 76:aeb1df146756 250 /**
mbed_official 76:aeb1df146756 251 * @}
mbed_official 76:aeb1df146756 252 */
mbed_official 76:aeb1df146756 253
mbed_official 76:aeb1df146756 254 /**
mbed_official 76:aeb1df146756 255 * @}
mbed_official 76:aeb1df146756 256 */
mbed_official 76:aeb1df146756 257
mbed_official 76:aeb1df146756 258 /**
mbed_official 76:aeb1df146756 259 * @}
mbed_official 76:aeb1df146756 260 */
mbed_official 76:aeb1df146756 261
mbed_official 76:aeb1df146756 262 /**
mbed_official 76:aeb1df146756 263 * @}
mbed_official 76:aeb1df146756 264 */
mbed_official 76:aeb1df146756 265
mbed_official 76:aeb1df146756 266 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/