mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
106:ced8cbb51063
test with CLOCK_SETUP = 0

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 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 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 106:ced8cbb51063 67 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 68 *
mbed_official 106:ced8cbb51063 69 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 106:ced8cbb51063 70 * are permitted provided that the following conditions are met:
mbed_official 106:ced8cbb51063 71 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 106:ced8cbb51063 72 * this list of conditions and the following disclaimer.
mbed_official 106:ced8cbb51063 73 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 106:ced8cbb51063 74 * this list of conditions and the following disclaimer in the documentation
mbed_official 106:ced8cbb51063 75 * and/or other materials provided with the distribution.
mbed_official 106:ced8cbb51063 76 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 106:ced8cbb51063 77 * may be used to endorse or promote products derived from this software
mbed_official 106:ced8cbb51063 78 * without specific prior written permission.
mbed_official 76:aeb1df146756 79 *
mbed_official 106:ced8cbb51063 80 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 106:ced8cbb51063 81 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 106:ced8cbb51063 82 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 106:ced8cbb51063 83 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 106:ced8cbb51063 84 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 106:ced8cbb51063 85 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 106:ced8cbb51063 86 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 106:ced8cbb51063 87 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 106:ced8cbb51063 88 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 106:ced8cbb51063 89 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 76:aeb1df146756 90 *
mbed_official 76:aeb1df146756 91 ******************************************************************************
mbed_official 76:aeb1df146756 92 */
mbed_official 76:aeb1df146756 93
mbed_official 76:aeb1df146756 94 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 95 #include "stm32l1xx_iwdg.h"
mbed_official 76:aeb1df146756 96
mbed_official 76:aeb1df146756 97 /** @addtogroup STM32L1xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 98 * @{
mbed_official 76:aeb1df146756 99 */
mbed_official 76:aeb1df146756 100
mbed_official 76:aeb1df146756 101 /** @defgroup IWDG
mbed_official 76:aeb1df146756 102 * @brief IWDG driver modules
mbed_official 76:aeb1df146756 103 * @{
mbed_official 76:aeb1df146756 104 */
mbed_official 76:aeb1df146756 105
mbed_official 76:aeb1df146756 106 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 107 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 108 /* ---------------------- IWDG registers bit mask ----------------------------*/
mbed_official 76:aeb1df146756 109 /* KR register bit mask */
mbed_official 76:aeb1df146756 110 #define KR_KEY_RELOAD ((uint16_t)0xAAAA)
mbed_official 76:aeb1df146756 111 #define KR_KEY_ENABLE ((uint16_t)0xCCCC)
mbed_official 76:aeb1df146756 112
mbed_official 76:aeb1df146756 113 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 114 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 115 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 116 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 117
mbed_official 76:aeb1df146756 118 /** @defgroup IWDG_Private_Functions
mbed_official 76:aeb1df146756 119 * @{
mbed_official 76:aeb1df146756 120 */
mbed_official 76:aeb1df146756 121
mbed_official 76:aeb1df146756 122 /** @defgroup IWDG_Group1 Prescaler and Counter configuration functions
mbed_official 76:aeb1df146756 123 * @brief Prescaler and Counter configuration functions
mbed_official 76:aeb1df146756 124 *
mbed_official 76:aeb1df146756 125 @verbatim
mbed_official 76:aeb1df146756 126 ==============================================================================
mbed_official 76:aeb1df146756 127 ##### Prescaler and Counter configuration functions #####
mbed_official 76:aeb1df146756 128 ==============================================================================
mbed_official 76:aeb1df146756 129
mbed_official 76:aeb1df146756 130 @endverbatim
mbed_official 76:aeb1df146756 131 * @{
mbed_official 76:aeb1df146756 132 */
mbed_official 76:aeb1df146756 133
mbed_official 76:aeb1df146756 134 /**
mbed_official 76:aeb1df146756 135 * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
mbed_official 76:aeb1df146756 136 * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
mbed_official 76:aeb1df146756 137 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 138 * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
mbed_official 76:aeb1df146756 139 * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
mbed_official 76:aeb1df146756 140 * @retval None
mbed_official 76:aeb1df146756 141 */
mbed_official 76:aeb1df146756 142 void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
mbed_official 76:aeb1df146756 143 {
mbed_official 76:aeb1df146756 144 /* Check the parameters */
mbed_official 76:aeb1df146756 145 assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
mbed_official 76:aeb1df146756 146 IWDG->KR = IWDG_WriteAccess;
mbed_official 76:aeb1df146756 147 }
mbed_official 76:aeb1df146756 148
mbed_official 76:aeb1df146756 149 /**
mbed_official 76:aeb1df146756 150 * @brief Sets IWDG Prescaler value.
mbed_official 76:aeb1df146756 151 * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
mbed_official 76:aeb1df146756 152 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 153 * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
mbed_official 76:aeb1df146756 154 * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
mbed_official 76:aeb1df146756 155 * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
mbed_official 76:aeb1df146756 156 * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
mbed_official 76:aeb1df146756 157 * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
mbed_official 76:aeb1df146756 158 * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
mbed_official 76:aeb1df146756 159 * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
mbed_official 76:aeb1df146756 160 * @retval None
mbed_official 76:aeb1df146756 161 */
mbed_official 76:aeb1df146756 162 void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
mbed_official 76:aeb1df146756 163 {
mbed_official 76:aeb1df146756 164 /* Check the parameters */
mbed_official 76:aeb1df146756 165 assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
mbed_official 76:aeb1df146756 166 IWDG->PR = IWDG_Prescaler;
mbed_official 76:aeb1df146756 167 }
mbed_official 76:aeb1df146756 168
mbed_official 76:aeb1df146756 169 /**
mbed_official 76:aeb1df146756 170 * @brief Sets IWDG Reload value.
mbed_official 76:aeb1df146756 171 * @param Reload: specifies the IWDG Reload value.
mbed_official 76:aeb1df146756 172 * This parameter must be a number between 0 and 0x0FFF.
mbed_official 76:aeb1df146756 173 * @retval None
mbed_official 76:aeb1df146756 174 */
mbed_official 76:aeb1df146756 175 void IWDG_SetReload(uint16_t Reload)
mbed_official 76:aeb1df146756 176 {
mbed_official 76:aeb1df146756 177 /* Check the parameters */
mbed_official 76:aeb1df146756 178 assert_param(IS_IWDG_RELOAD(Reload));
mbed_official 76:aeb1df146756 179 IWDG->RLR = Reload;
mbed_official 76:aeb1df146756 180 }
mbed_official 76:aeb1df146756 181
mbed_official 76:aeb1df146756 182 /**
mbed_official 76:aeb1df146756 183 * @brief Reloads IWDG counter with value defined in the reload register
mbed_official 76:aeb1df146756 184 * (write access to IWDG_PR and IWDG_RLR registers disabled).
mbed_official 76:aeb1df146756 185 * @param None
mbed_official 76:aeb1df146756 186 * @retval None
mbed_official 76:aeb1df146756 187 */
mbed_official 76:aeb1df146756 188 void IWDG_ReloadCounter(void)
mbed_official 76:aeb1df146756 189 {
mbed_official 76:aeb1df146756 190 IWDG->KR = KR_KEY_RELOAD;
mbed_official 76:aeb1df146756 191 }
mbed_official 76:aeb1df146756 192
mbed_official 76:aeb1df146756 193 /**
mbed_official 76:aeb1df146756 194 * @}
mbed_official 76:aeb1df146756 195 */
mbed_official 76:aeb1df146756 196
mbed_official 76:aeb1df146756 197 /** @defgroup IWDG_Group2 IWDG activation function
mbed_official 76:aeb1df146756 198 * @brief IWDG activation function
mbed_official 76:aeb1df146756 199 *
mbed_official 76:aeb1df146756 200 @verbatim
mbed_official 76:aeb1df146756 201 ==============================================================================
mbed_official 76:aeb1df146756 202 ##### IWDG activation function #####
mbed_official 76:aeb1df146756 203 ==============================================================================
mbed_official 76:aeb1df146756 204
mbed_official 76:aeb1df146756 205 @endverbatim
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 * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
mbed_official 76:aeb1df146756 211 * @param None.
mbed_official 76:aeb1df146756 212 * @retval None.
mbed_official 76:aeb1df146756 213 */
mbed_official 76:aeb1df146756 214 void IWDG_Enable(void)
mbed_official 76:aeb1df146756 215 {
mbed_official 76:aeb1df146756 216 IWDG->KR = KR_KEY_ENABLE;
mbed_official 76:aeb1df146756 217 }
mbed_official 76:aeb1df146756 218
mbed_official 76:aeb1df146756 219 /**
mbed_official 76:aeb1df146756 220 * @}
mbed_official 76:aeb1df146756 221 */
mbed_official 76:aeb1df146756 222
mbed_official 76:aeb1df146756 223 /** @defgroup IWDG_Group3 Flag management function
mbed_official 76:aeb1df146756 224 * @brief Flag management function
mbed_official 76:aeb1df146756 225 *
mbed_official 76:aeb1df146756 226 @verbatim
mbed_official 76:aeb1df146756 227 ===============================================================================
mbed_official 76:aeb1df146756 228 ##### Flag management function #####
mbed_official 76:aeb1df146756 229 ===============================================================================
mbed_official 76:aeb1df146756 230
mbed_official 76:aeb1df146756 231 @endverbatim
mbed_official 76:aeb1df146756 232 * @{
mbed_official 76:aeb1df146756 233 */
mbed_official 76:aeb1df146756 234
mbed_official 76:aeb1df146756 235 /**
mbed_official 76:aeb1df146756 236 * @brief Checks whether the specified IWDG flag is set or not.
mbed_official 76:aeb1df146756 237 * @param IWDG_FLAG: specifies the flag to check.
mbed_official 76:aeb1df146756 238 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 239 * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
mbed_official 76:aeb1df146756 240 * @arg IWDG_FLAG_RVU: Reload Value Update on going
mbed_official 76:aeb1df146756 241 * @retval The new state of IWDG_FLAG (SET or RESET).
mbed_official 76:aeb1df146756 242 */
mbed_official 76:aeb1df146756 243 FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
mbed_official 76:aeb1df146756 244 {
mbed_official 76:aeb1df146756 245 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 246 /* Check the parameters */
mbed_official 76:aeb1df146756 247 assert_param(IS_IWDG_FLAG(IWDG_FLAG));
mbed_official 76:aeb1df146756 248 if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 249 {
mbed_official 76:aeb1df146756 250 bitstatus = SET;
mbed_official 76:aeb1df146756 251 }
mbed_official 76:aeb1df146756 252 else
mbed_official 76:aeb1df146756 253 {
mbed_official 76:aeb1df146756 254 bitstatus = RESET;
mbed_official 76:aeb1df146756 255 }
mbed_official 76:aeb1df146756 256 /* Return the flag status */
mbed_official 76:aeb1df146756 257 return bitstatus;
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 */
mbed_official 76:aeb1df146756 267
mbed_official 76:aeb1df146756 268 /**
mbed_official 76:aeb1df146756 269 * @}
mbed_official 76:aeb1df146756 270 */
mbed_official 76:aeb1df146756 271
mbed_official 76:aeb1df146756 272 /**
mbed_official 76:aeb1df146756 273 * @}
mbed_official 76:aeb1df146756 274 */
mbed_official 76:aeb1df146756 275
mbed_official 76:aeb1df146756 276 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/