mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

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?

UserRevisionLine numberNew contents of line
mbed_official 155:8435094ec241 1 /**
mbed_official 155:8435094ec241 2 ******************************************************************************
mbed_official 155:8435094ec241 3 * @file stm32f30x_wwdg.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 firmware functions to manage the following
mbed_official 155:8435094ec241 8 * functionalities of the Window watchdog (WWDG) peripheral:
mbed_official 155:8435094ec241 9 * + Prescaler, Refresh window and Counter configuration
mbed_official 155:8435094ec241 10 * + WWDG activation
mbed_official 155:8435094ec241 11 * + Interrupts and flags management
mbed_official 155:8435094ec241 12 *
mbed_official 155:8435094ec241 13 * @verbatim
mbed_official 155:8435094ec241 14 *
mbed_official 155:8435094ec241 15 ==============================================================================
mbed_official 155:8435094ec241 16 ##### WWDG features #####
mbed_official 155:8435094ec241 17 ==============================================================================
mbed_official 155:8435094ec241 18
mbed_official 155:8435094ec241 19 [..] Once enabled the WWDG generates a system reset on expiry of a programmed
mbed_official 155:8435094ec241 20 time period, unless the program refreshes the counter (downcounter)
mbed_official 155:8435094ec241 21 before to reach 0x3F value (i.e. a reset is generated when the counter
mbed_official 155:8435094ec241 22 value rolls over from 0x40 to 0x3F).
mbed_official 155:8435094ec241 23 [..] An MCU reset is also generated if the counter value is refreshed
mbed_official 155:8435094ec241 24 before the counter has reached the refresh window value. This
mbed_official 155:8435094ec241 25 implies that the counter must be refreshed in a limited window.
mbed_official 155:8435094ec241 26
mbed_official 155:8435094ec241 27 [..] Once enabled the WWDG cannot be disabled except by a system reset.
mbed_official 155:8435094ec241 28
mbed_official 155:8435094ec241 29 [..] WWDGRST flag in RCC_CSR register can be used to inform when a WWDG
mbed_official 155:8435094ec241 30 reset occurs.
mbed_official 155:8435094ec241 31
mbed_official 155:8435094ec241 32 [..] The WWDG counter input clock is derived from the APB clock divided
mbed_official 155:8435094ec241 33 by a programmable prescaler.
mbed_official 155:8435094ec241 34
mbed_official 155:8435094ec241 35 [..] WWDG counter clock = PCLK1 / Prescaler.
mbed_official 155:8435094ec241 36 [..] WWDG timeout = (WWDG counter clock) * (counter value).
mbed_official 155:8435094ec241 37
mbed_official 155:8435094ec241 38 [..] Min-max timeout value @36MHz (PCLK1): ~114us / ~58.3ms.
mbed_official 155:8435094ec241 39
mbed_official 155:8435094ec241 40 ##### How to use this driver #####
mbed_official 155:8435094ec241 41 ==============================================================================
mbed_official 155:8435094ec241 42 [..]
mbed_official 155:8435094ec241 43 (#) Enable WWDG clock using RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE)
mbed_official 155:8435094ec241 44 function.
mbed_official 155:8435094ec241 45
mbed_official 155:8435094ec241 46 (#) Configure the WWDG prescaler using WWDG_SetPrescaler() function.
mbed_official 155:8435094ec241 47
mbed_official 155:8435094ec241 48 (#) Configure the WWDG refresh window using WWDG_SetWindowValue() function.
mbed_official 155:8435094ec241 49
mbed_official 155:8435094ec241 50 (#) Set the WWDG counter value and start it using WWDG_Enable() function.
mbed_official 155:8435094ec241 51 When the WWDG is enabled the counter value should be configured to
mbed_official 155:8435094ec241 52 a value greater than 0x40 to prevent generating an immediate reset.
mbed_official 155:8435094ec241 53
mbed_official 155:8435094ec241 54 (#) Optionally you can enable the Early wakeup interrupt which is
mbed_official 155:8435094ec241 55 generated when the counter reach 0x40.
mbed_official 155:8435094ec241 56 Once enabled this interrupt cannot be disabled except by a system reset.
mbed_official 155:8435094ec241 57
mbed_official 155:8435094ec241 58 (#) Then the application program must refresh the WWDG counter at regular
mbed_official 155:8435094ec241 59 intervals during normal operation to prevent an MCU reset, using
mbed_official 155:8435094ec241 60 WWDG_SetCounter() function. This operation must occur only when
mbed_official 155:8435094ec241 61 the counter value is lower than the refresh window value,
mbed_official 155:8435094ec241 62 programmed using WWDG_SetWindowValue().
mbed_official 155:8435094ec241 63
mbed_official 155:8435094ec241 64 @endverbatim
mbed_official 155:8435094ec241 65
mbed_official 155:8435094ec241 66 ******************************************************************************
mbed_official 155:8435094ec241 67 * @attention
mbed_official 155:8435094ec241 68 *
mbed_official 155:8435094ec241 69 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 155:8435094ec241 70 *
mbed_official 155:8435094ec241 71 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 155:8435094ec241 72 * are permitted provided that the following conditions are met:
mbed_official 155:8435094ec241 73 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 155:8435094ec241 74 * this list of conditions and the following disclaimer.
mbed_official 155:8435094ec241 75 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 155:8435094ec241 76 * this list of conditions and the following disclaimer in the documentation
mbed_official 155:8435094ec241 77 * and/or other materials provided with the distribution.
mbed_official 155:8435094ec241 78 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 155:8435094ec241 79 * may be used to endorse or promote products derived from this software
mbed_official 155:8435094ec241 80 * without specific prior written permission.
mbed_official 155:8435094ec241 81 *
mbed_official 155:8435094ec241 82 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 155:8435094ec241 83 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 155:8435094ec241 84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 155:8435094ec241 85 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 155:8435094ec241 86 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 155:8435094ec241 87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 155:8435094ec241 88 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 155:8435094ec241 89 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 155:8435094ec241 90 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 155:8435094ec241 91 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 155:8435094ec241 92 *
mbed_official 155:8435094ec241 93 ******************************************************************************
mbed_official 155:8435094ec241 94 */
mbed_official 155:8435094ec241 95
mbed_official 155:8435094ec241 96 /* Includes ------------------------------------------------------------------*/
mbed_official 155:8435094ec241 97 #include "stm32f30x_wwdg.h"
mbed_official 155:8435094ec241 98 #include "stm32f30x_rcc.h"
mbed_official 155:8435094ec241 99
mbed_official 155:8435094ec241 100 /** @addtogroup STM32F30x_StdPeriph_Driver
mbed_official 155:8435094ec241 101 * @{
mbed_official 155:8435094ec241 102 */
mbed_official 155:8435094ec241 103
mbed_official 155:8435094ec241 104 /** @defgroup WWDG
mbed_official 155:8435094ec241 105 * @brief WWDG driver modules
mbed_official 155:8435094ec241 106 * @{
mbed_official 155:8435094ec241 107 */
mbed_official 155:8435094ec241 108
mbed_official 155:8435094ec241 109 /* Private typedef -----------------------------------------------------------*/
mbed_official 155:8435094ec241 110 /* Private define ------------------------------------------------------------*/
mbed_official 155:8435094ec241 111 /* --------------------- WWDG registers bit mask ---------------------------- */
mbed_official 155:8435094ec241 112 /* CFR register bit mask */
mbed_official 155:8435094ec241 113 #define CFR_WDGTB_MASK ((uint32_t)0xFFFFFE7F)
mbed_official 155:8435094ec241 114 #define CFR_W_MASK ((uint32_t)0xFFFFFF80)
mbed_official 155:8435094ec241 115 #define BIT_MASK ((uint8_t)0x7F)
mbed_official 155:8435094ec241 116
mbed_official 155:8435094ec241 117 /* Private macro -------------------------------------------------------------*/
mbed_official 155:8435094ec241 118 /* Private variables ---------------------------------------------------------*/
mbed_official 155:8435094ec241 119 /* Private function prototypes -----------------------------------------------*/
mbed_official 155:8435094ec241 120 /* Private functions ---------------------------------------------------------*/
mbed_official 155:8435094ec241 121
mbed_official 155:8435094ec241 122 /** @defgroup WWDG_Private_Functions
mbed_official 155:8435094ec241 123 * @{
mbed_official 155:8435094ec241 124 */
mbed_official 155:8435094ec241 125
mbed_official 155:8435094ec241 126 /** @defgroup WWDG_Group1 Prescaler, Refresh window and Counter configuration functions
mbed_official 155:8435094ec241 127 * @brief Prescaler, Refresh window and Counter configuration functions
mbed_official 155:8435094ec241 128 *
mbed_official 155:8435094ec241 129 @verbatim
mbed_official 155:8435094ec241 130 ==============================================================================
mbed_official 155:8435094ec241 131 ##### Prescaler, Refresh window and Counter configuration functions #####
mbed_official 155:8435094ec241 132 ==============================================================================
mbed_official 155:8435094ec241 133
mbed_official 155:8435094ec241 134 @endverbatim
mbed_official 155:8435094ec241 135 * @{
mbed_official 155:8435094ec241 136 */
mbed_official 155:8435094ec241 137
mbed_official 155:8435094ec241 138 /**
mbed_official 155:8435094ec241 139 * @brief Deinitializes the WWDG peripheral registers to their default reset values.
mbed_official 155:8435094ec241 140 * @param None
mbed_official 155:8435094ec241 141 * @retval None
mbed_official 155:8435094ec241 142 */
mbed_official 155:8435094ec241 143 void WWDG_DeInit(void)
mbed_official 155:8435094ec241 144 {
mbed_official 155:8435094ec241 145 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
mbed_official 155:8435094ec241 146 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
mbed_official 155:8435094ec241 147 }
mbed_official 155:8435094ec241 148
mbed_official 155:8435094ec241 149 /**
mbed_official 155:8435094ec241 150 * @brief Sets the WWDG Prescaler.
mbed_official 155:8435094ec241 151 * @param WWDG_Prescaler: specifies the WWDG Prescaler.
mbed_official 155:8435094ec241 152 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 153 * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
mbed_official 155:8435094ec241 154 * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
mbed_official 155:8435094ec241 155 * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
mbed_official 155:8435094ec241 156 * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
mbed_official 155:8435094ec241 157 * @retval None
mbed_official 155:8435094ec241 158 */
mbed_official 155:8435094ec241 159 void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
mbed_official 155:8435094ec241 160 {
mbed_official 155:8435094ec241 161 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 162 /* Check the parameters */
mbed_official 155:8435094ec241 163 assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
mbed_official 155:8435094ec241 164 /* Clear WDGTB[1:0] bits */
mbed_official 155:8435094ec241 165 tmpreg = WWDG->CFR & CFR_WDGTB_MASK;
mbed_official 155:8435094ec241 166 /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
mbed_official 155:8435094ec241 167 tmpreg |= WWDG_Prescaler;
mbed_official 155:8435094ec241 168 /* Store the new value */
mbed_official 155:8435094ec241 169 WWDG->CFR = tmpreg;
mbed_official 155:8435094ec241 170 }
mbed_official 155:8435094ec241 171
mbed_official 155:8435094ec241 172 /**
mbed_official 155:8435094ec241 173 * @brief Sets the WWDG window value.
mbed_official 155:8435094ec241 174 * @param WindowValue: specifies the window value to be compared to the downcounter.
mbed_official 155:8435094ec241 175 * This parameter value must be lower than 0x80.
mbed_official 155:8435094ec241 176 * @retval None
mbed_official 155:8435094ec241 177 */
mbed_official 155:8435094ec241 178 void WWDG_SetWindowValue(uint8_t WindowValue)
mbed_official 155:8435094ec241 179 {
mbed_official 155:8435094ec241 180 __IO uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 181
mbed_official 155:8435094ec241 182 /* Check the parameters */
mbed_official 155:8435094ec241 183 assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
mbed_official 155:8435094ec241 184 /* Clear W[6:0] bits */
mbed_official 155:8435094ec241 185
mbed_official 155:8435094ec241 186 tmpreg = WWDG->CFR & CFR_W_MASK;
mbed_official 155:8435094ec241 187
mbed_official 155:8435094ec241 188 /* Set W[6:0] bits according to WindowValue value */
mbed_official 155:8435094ec241 189 tmpreg |= WindowValue & (uint32_t) BIT_MASK;
mbed_official 155:8435094ec241 190
mbed_official 155:8435094ec241 191 /* Store the new value */
mbed_official 155:8435094ec241 192 WWDG->CFR = tmpreg;
mbed_official 155:8435094ec241 193 }
mbed_official 155:8435094ec241 194
mbed_official 155:8435094ec241 195 /**
mbed_official 155:8435094ec241 196 * @brief Enables the WWDG Early Wakeup interrupt(EWI).
mbed_official 155:8435094ec241 197 * @note Once enabled this interrupt cannot be disabled except by a system reset.
mbed_official 155:8435094ec241 198 * @param None
mbed_official 155:8435094ec241 199 * @retval None
mbed_official 155:8435094ec241 200 */
mbed_official 155:8435094ec241 201 void WWDG_EnableIT(void)
mbed_official 155:8435094ec241 202 {
mbed_official 155:8435094ec241 203 WWDG->CFR |= WWDG_CFR_EWI;
mbed_official 155:8435094ec241 204 }
mbed_official 155:8435094ec241 205
mbed_official 155:8435094ec241 206 /**
mbed_official 155:8435094ec241 207 * @brief Sets the WWDG counter value.
mbed_official 155:8435094ec241 208 * @param Counter: specifies the watchdog counter value.
mbed_official 155:8435094ec241 209 * This parameter must be a number between 0x40 and 0x7F (to prevent generating
mbed_official 155:8435094ec241 210 * an immediate reset).
mbed_official 155:8435094ec241 211 * @retval None
mbed_official 155:8435094ec241 212 */
mbed_official 155:8435094ec241 213 void WWDG_SetCounter(uint8_t Counter)
mbed_official 155:8435094ec241 214 {
mbed_official 155:8435094ec241 215 /* Check the parameters */
mbed_official 155:8435094ec241 216 assert_param(IS_WWDG_COUNTER(Counter));
mbed_official 155:8435094ec241 217 /* Write to T[6:0] bits to configure the counter value, no need to do
mbed_official 155:8435094ec241 218 a read-modify-write; writing a 0 to WDGA bit does nothing */
mbed_official 155:8435094ec241 219 WWDG->CR = Counter & BIT_MASK;
mbed_official 155:8435094ec241 220 }
mbed_official 155:8435094ec241 221
mbed_official 155:8435094ec241 222 /**
mbed_official 155:8435094ec241 223 * @}
mbed_official 155:8435094ec241 224 */
mbed_official 155:8435094ec241 225
mbed_official 155:8435094ec241 226 /** @defgroup WWDG_Group2 WWDG activation functions
mbed_official 155:8435094ec241 227 * @brief WWDG activation functions
mbed_official 155:8435094ec241 228 *
mbed_official 155:8435094ec241 229 @verbatim
mbed_official 155:8435094ec241 230 ==============================================================================
mbed_official 155:8435094ec241 231 ##### WWDG activation function #####
mbed_official 155:8435094ec241 232 ==============================================================================
mbed_official 155:8435094ec241 233
mbed_official 155:8435094ec241 234 @endverbatim
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 * @brief Enables WWDG and load the counter value.
mbed_official 155:8435094ec241 240 * @param Counter: specifies the watchdog counter value.
mbed_official 155:8435094ec241 241 * This parameter must be a number between 0x40 and 0x7F (to prevent generating
mbed_official 155:8435094ec241 242 * an immediate reset).
mbed_official 155:8435094ec241 243 * @retval None
mbed_official 155:8435094ec241 244 */
mbed_official 155:8435094ec241 245 void WWDG_Enable(uint8_t Counter)
mbed_official 155:8435094ec241 246 {
mbed_official 155:8435094ec241 247 /* Check the parameters */
mbed_official 155:8435094ec241 248 assert_param(IS_WWDG_COUNTER(Counter));
mbed_official 155:8435094ec241 249 WWDG->CR = WWDG_CR_WDGA | Counter;
mbed_official 155:8435094ec241 250 }
mbed_official 155:8435094ec241 251
mbed_official 155:8435094ec241 252 /**
mbed_official 155:8435094ec241 253 * @}
mbed_official 155:8435094ec241 254 */
mbed_official 155:8435094ec241 255
mbed_official 155:8435094ec241 256 /** @defgroup WWDG_Group3 Interrupts and flags management functions
mbed_official 155:8435094ec241 257 * @brief Interrupts and flags management functions
mbed_official 155:8435094ec241 258 *
mbed_official 155:8435094ec241 259 @verbatim
mbed_official 155:8435094ec241 260 ==============================================================================
mbed_official 155:8435094ec241 261 ##### Interrupts and flags management functions #####
mbed_official 155:8435094ec241 262 ==============================================================================
mbed_official 155:8435094ec241 263
mbed_official 155:8435094ec241 264 @endverbatim
mbed_official 155:8435094ec241 265 * @{
mbed_official 155:8435094ec241 266 */
mbed_official 155:8435094ec241 267
mbed_official 155:8435094ec241 268 /**
mbed_official 155:8435094ec241 269 * @brief Checks whether the Early Wakeup interrupt flag is set or not.
mbed_official 155:8435094ec241 270 * @param None
mbed_official 155:8435094ec241 271 * @retval The new state of the Early Wakeup interrupt flag (SET or RESET).
mbed_official 155:8435094ec241 272 */
mbed_official 155:8435094ec241 273 FlagStatus WWDG_GetFlagStatus(void)
mbed_official 155:8435094ec241 274 {
mbed_official 155:8435094ec241 275 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 276
mbed_official 155:8435094ec241 277 if ((WWDG->SR) != (uint32_t)RESET)
mbed_official 155:8435094ec241 278 {
mbed_official 155:8435094ec241 279 bitstatus = SET;
mbed_official 155:8435094ec241 280 }
mbed_official 155:8435094ec241 281 else
mbed_official 155:8435094ec241 282 {
mbed_official 155:8435094ec241 283 bitstatus = RESET;
mbed_official 155:8435094ec241 284 }
mbed_official 155:8435094ec241 285 return bitstatus;
mbed_official 155:8435094ec241 286 }
mbed_official 155:8435094ec241 287
mbed_official 155:8435094ec241 288 /**
mbed_official 155:8435094ec241 289 * @brief Clears Early Wakeup interrupt flag.
mbed_official 155:8435094ec241 290 * @param None
mbed_official 155:8435094ec241 291 * @retval None
mbed_official 155:8435094ec241 292 */
mbed_official 155:8435094ec241 293 void WWDG_ClearFlag(void)
mbed_official 155:8435094ec241 294 {
mbed_official 155:8435094ec241 295 WWDG->SR = (uint32_t)RESET;
mbed_official 155:8435094ec241 296 }
mbed_official 155:8435094ec241 297
mbed_official 155:8435094ec241 298 /**
mbed_official 155:8435094ec241 299 * @}
mbed_official 155:8435094ec241 300 */
mbed_official 155:8435094ec241 301
mbed_official 155:8435094ec241 302 /**
mbed_official 155:8435094ec241 303 * @}
mbed_official 155:8435094ec241 304 */
mbed_official 155:8435094ec241 305
mbed_official 155:8435094ec241 306 /**
mbed_official 155:8435094ec241 307 * @}
mbed_official 155:8435094ec241 308 */
mbed_official 155:8435094ec241 309
mbed_official 155:8435094ec241 310 /**
mbed_official 155:8435094ec241 311 * @}
mbed_official 155:8435094ec241 312 */
mbed_official 155:8435094ec241 313
mbed_official 155:8435094ec241 314 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/