mbed official / mbed-dev

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Tue Mar 20 16:56:18 2018 +0000
Revision:
182:a56a73fd2a6f
Parent:
175:af195413fb11
mbed-dev library. Release version 160

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 170:19eb464bc2be 1 /*
AnnaBridge 182:a56a73fd2a6f 2 * The Clear BSD License
Kojto 170:19eb464bc2be 3 * Copyright (c) 2016, Freescale Semiconductor, Inc.
Kojto 170:19eb464bc2be 4 * Copyright 2016-2017 NXP
AnnaBridge 182:a56a73fd2a6f 5 * All rights reserved.
Kojto 170:19eb464bc2be 6 *
Kojto 170:19eb464bc2be 7 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 182:a56a73fd2a6f 8 * are permitted (subject to the limitations in the disclaimer below) provided
AnnaBridge 182:a56a73fd2a6f 9 * that the following conditions are met:
Kojto 170:19eb464bc2be 10 *
Kojto 170:19eb464bc2be 11 * o Redistributions of source code must retain the above copyright notice, this list
Kojto 170:19eb464bc2be 12 * of conditions and the following disclaimer.
Kojto 170:19eb464bc2be 13 *
Kojto 170:19eb464bc2be 14 * o Redistributions in binary form must reproduce the above copyright notice, this
Kojto 170:19eb464bc2be 15 * list of conditions and the following disclaimer in the documentation and/or
Kojto 170:19eb464bc2be 16 * other materials provided with the distribution.
Kojto 170:19eb464bc2be 17 *
Kojto 170:19eb464bc2be 18 * o Neither the name of the copyright holder nor the names of its
Kojto 170:19eb464bc2be 19 * contributors may be used to endorse or promote products derived from this
Kojto 170:19eb464bc2be 20 * software without specific prior written permission.
Kojto 170:19eb464bc2be 21 *
AnnaBridge 182:a56a73fd2a6f 22 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
Kojto 170:19eb464bc2be 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Kojto 170:19eb464bc2be 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Kojto 170:19eb464bc2be 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 170:19eb464bc2be 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Kojto 170:19eb464bc2be 27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Kojto 170:19eb464bc2be 28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Kojto 170:19eb464bc2be 29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Kojto 170:19eb464bc2be 30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 170:19eb464bc2be 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Kojto 170:19eb464bc2be 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 170:19eb464bc2be 33 */
Kojto 170:19eb464bc2be 34 #ifndef _FSL_WWDT_H_
Kojto 170:19eb464bc2be 35 #define _FSL_WWDT_H_
Kojto 170:19eb464bc2be 36
Kojto 170:19eb464bc2be 37 #include "fsl_common.h"
Kojto 170:19eb464bc2be 38
Kojto 170:19eb464bc2be 39 /*!
Kojto 170:19eb464bc2be 40 * @addtogroup wwdt
Kojto 170:19eb464bc2be 41 * @{
Kojto 170:19eb464bc2be 42 */
Kojto 170:19eb464bc2be 43
Kojto 170:19eb464bc2be 44 /*! @file */
Kojto 170:19eb464bc2be 45
Kojto 170:19eb464bc2be 46 /*******************************************************************************
Kojto 170:19eb464bc2be 47 * Definitions
Kojto 170:19eb464bc2be 48 *******************************************************************************/
Kojto 170:19eb464bc2be 49
Kojto 170:19eb464bc2be 50 /*! @name Driver version */
Kojto 170:19eb464bc2be 51 /*@{*/
Kojto 170:19eb464bc2be 52 /*! @brief Defines WWDT driver version 2.0.0. */
Kojto 170:19eb464bc2be 53 #define FSL_WWDT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
Kojto 170:19eb464bc2be 54 /*@}*/
Kojto 170:19eb464bc2be 55
Kojto 170:19eb464bc2be 56 /*! @name Refresh sequence */
Kojto 170:19eb464bc2be 57 /*@{*/
Kojto 170:19eb464bc2be 58 #define WWDT_FIRST_WORD_OF_REFRESH (0xAAU) /*!< First word of refresh sequence */
Kojto 170:19eb464bc2be 59 #define WWDT_SECOND_WORD_OF_REFRESH (0x55U) /*!< Second word of refresh sequence */
Kojto 170:19eb464bc2be 60 /*@}*/
Kojto 170:19eb464bc2be 61
Kojto 170:19eb464bc2be 62 /*! @brief Describes WWDT configuration structure. */
Kojto 170:19eb464bc2be 63 typedef struct _wwdt_config
Kojto 170:19eb464bc2be 64 {
Kojto 170:19eb464bc2be 65 bool enableWwdt; /*!< Enables or disables WWDT */
Kojto 170:19eb464bc2be 66 bool enableWatchdogReset; /*!< true: Watchdog timeout will cause a chip reset
Kojto 170:19eb464bc2be 67 false: Watchdog timeout will not cause a chip reset */
Kojto 170:19eb464bc2be 68 bool enableWatchdogProtect; /*!< true: Enable watchdog protect i.e timeout value can only be
Kojto 170:19eb464bc2be 69 changed after counter is below warning & window values
Kojto 170:19eb464bc2be 70 false: Disable watchdog protect; timeout value can be changed
Kojto 170:19eb464bc2be 71 at any time */
Kojto 170:19eb464bc2be 72 bool enableLockOscillator; /*!< true: Disabling or powering down the watchdog oscillator is prevented
Kojto 170:19eb464bc2be 73 Once set, this bit can only be cleared by a reset
Kojto 170:19eb464bc2be 74 false: Do not lock oscillator */
Kojto 170:19eb464bc2be 75 uint32_t windowValue; /*!< Window value, set this to 0xFFFFFF if windowing is not in effect */
Kojto 170:19eb464bc2be 76 uint32_t timeoutValue; /*!< Timeout value */
Kojto 170:19eb464bc2be 77 uint32_t warningValue; /*!< Watchdog time counter value that will generate a
Kojto 170:19eb464bc2be 78 warning interrupt. Set this to 0 for no warning */
Kojto 170:19eb464bc2be 79
Kojto 170:19eb464bc2be 80 } wwdt_config_t;
Kojto 170:19eb464bc2be 81
Kojto 170:19eb464bc2be 82 /*!
Kojto 170:19eb464bc2be 83 * @brief WWDT status flags.
Kojto 170:19eb464bc2be 84 *
Kojto 170:19eb464bc2be 85 * This structure contains the WWDT status flags for use in the WWDT functions.
Kojto 170:19eb464bc2be 86 */
Kojto 170:19eb464bc2be 87 enum _wwdt_status_flags_t
Kojto 170:19eb464bc2be 88 {
Kojto 170:19eb464bc2be 89 kWWDT_TimeoutFlag = WWDT_MOD_WDTOF_MASK, /*!< Time-out flag, set when the timer times out */
Kojto 170:19eb464bc2be 90 kWWDT_WarningFlag = WWDT_MOD_WDINT_MASK /*!< Warning interrupt flag, set when timer is below the value WDWARNINT */
Kojto 170:19eb464bc2be 91 };
Kojto 170:19eb464bc2be 92
Kojto 170:19eb464bc2be 93 /*******************************************************************************
Kojto 170:19eb464bc2be 94 * API
Kojto 170:19eb464bc2be 95 *******************************************************************************/
Kojto 170:19eb464bc2be 96
Kojto 170:19eb464bc2be 97 #if defined(__cplusplus)
Kojto 170:19eb464bc2be 98 extern "C" {
Kojto 170:19eb464bc2be 99 #endif /* __cplusplus */
Kojto 170:19eb464bc2be 100
Kojto 170:19eb464bc2be 101 /*!
Kojto 170:19eb464bc2be 102 * @name WWDT Initialization and De-initialization
Kojto 170:19eb464bc2be 103 * @{
Kojto 170:19eb464bc2be 104 */
Kojto 170:19eb464bc2be 105
Kojto 170:19eb464bc2be 106 /*!
Kojto 170:19eb464bc2be 107 * @brief Initializes WWDT configure sturcture.
Kojto 170:19eb464bc2be 108 *
Kojto 170:19eb464bc2be 109 * This function initializes the WWDT configure structure to default value. The default
Kojto 170:19eb464bc2be 110 * value are:
Kojto 170:19eb464bc2be 111 * @code
Kojto 170:19eb464bc2be 112 * config->enableWwdt = true;
Kojto 170:19eb464bc2be 113 * config->enableWatchdogReset = false;
Kojto 170:19eb464bc2be 114 * config->enableWatchdogProtect = false;
Kojto 170:19eb464bc2be 115 * config->enableLockOscillator = false;
Kojto 170:19eb464bc2be 116 * config->windowValue = 0xFFFFFFU;
Kojto 170:19eb464bc2be 117 * config->timeoutValue = 0xFFFFFFU;
Kojto 170:19eb464bc2be 118 * config->warningValue = 0;
Kojto 170:19eb464bc2be 119 * @endcode
Kojto 170:19eb464bc2be 120 *
Kojto 170:19eb464bc2be 121 * @param config Pointer to WWDT config structure.
Kojto 170:19eb464bc2be 122 * @see wwdt_config_t
Kojto 170:19eb464bc2be 123 */
Kojto 170:19eb464bc2be 124 void WWDT_GetDefaultConfig(wwdt_config_t *config);
Kojto 170:19eb464bc2be 125
Kojto 170:19eb464bc2be 126 /*!
Kojto 170:19eb464bc2be 127 * @brief Initializes the WWDT.
Kojto 170:19eb464bc2be 128 *
Kojto 170:19eb464bc2be 129 * This function initializes the WWDT. When called, the WWDT runs according to the configuration.
Kojto 170:19eb464bc2be 130 *
Kojto 170:19eb464bc2be 131 * Example:
Kojto 170:19eb464bc2be 132 * @code
Kojto 170:19eb464bc2be 133 * wwdt_config_t config;
Kojto 170:19eb464bc2be 134 * WWDT_GetDefaultConfig(&config);
Kojto 170:19eb464bc2be 135 * config.timeoutValue = 0x7ffU;
Kojto 170:19eb464bc2be 136 * WWDT_Init(wwdt_base,&config);
Kojto 170:19eb464bc2be 137 * @endcode
Kojto 170:19eb464bc2be 138 *
Kojto 170:19eb464bc2be 139 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 140 * @param config The configuration of WWDT
Kojto 170:19eb464bc2be 141 */
Kojto 170:19eb464bc2be 142 void WWDT_Init(WWDT_Type *base, const wwdt_config_t *config);
Kojto 170:19eb464bc2be 143
Kojto 170:19eb464bc2be 144 /*!
Kojto 170:19eb464bc2be 145 * @brief Shuts down the WWDT.
Kojto 170:19eb464bc2be 146 *
Kojto 170:19eb464bc2be 147 * This function shuts down the WWDT.
Kojto 170:19eb464bc2be 148 *
Kojto 170:19eb464bc2be 149 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 150 */
Kojto 170:19eb464bc2be 151 void WWDT_Deinit(WWDT_Type *base);
Kojto 170:19eb464bc2be 152
Kojto 170:19eb464bc2be 153 /* @} */
Kojto 170:19eb464bc2be 154
Kojto 170:19eb464bc2be 155 /*!
Kojto 170:19eb464bc2be 156 * @name WWDT Functional Operation
Kojto 170:19eb464bc2be 157 * @{
Kojto 170:19eb464bc2be 158 */
Kojto 170:19eb464bc2be 159
Kojto 170:19eb464bc2be 160 /*!
Kojto 170:19eb464bc2be 161 * @brief Enables the WWDT module.
Kojto 170:19eb464bc2be 162 *
Kojto 170:19eb464bc2be 163 * This function write value into WWDT_MOD register to enable the WWDT, it is a write-once bit;
Kojto 170:19eb464bc2be 164 * once this bit is set to one and a watchdog feed is performed, the watchdog timer will run
Kojto 170:19eb464bc2be 165 * permanently.
Kojto 170:19eb464bc2be 166 *
Kojto 170:19eb464bc2be 167 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 168 */
Kojto 170:19eb464bc2be 169 static inline void WWDT_Enable(WWDT_Type *base)
Kojto 170:19eb464bc2be 170 {
Kojto 170:19eb464bc2be 171 base->MOD |= WWDT_MOD_WDEN_MASK;
Kojto 170:19eb464bc2be 172 }
Kojto 170:19eb464bc2be 173
Kojto 170:19eb464bc2be 174 /*!
Kojto 170:19eb464bc2be 175 * @brief Disables the WWDT module.
Kojto 170:19eb464bc2be 176 *
Kojto 170:19eb464bc2be 177 * This function write value into WWDT_MOD register to disable the WWDT.
Kojto 170:19eb464bc2be 178 *
Kojto 170:19eb464bc2be 179 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 180 */
Kojto 170:19eb464bc2be 181 static inline void WWDT_Disable(WWDT_Type *base)
Kojto 170:19eb464bc2be 182 {
Kojto 170:19eb464bc2be 183 base->MOD &= ~WWDT_MOD_WDEN_MASK;
Kojto 170:19eb464bc2be 184 }
Kojto 170:19eb464bc2be 185
Kojto 170:19eb464bc2be 186 /*!
Kojto 170:19eb464bc2be 187 * @brief Gets all WWDT status flags.
Kojto 170:19eb464bc2be 188 *
Kojto 170:19eb464bc2be 189 * This function gets all status flags.
Kojto 170:19eb464bc2be 190 *
Kojto 170:19eb464bc2be 191 * Example for getting Timeout Flag:
Kojto 170:19eb464bc2be 192 * @code
Kojto 170:19eb464bc2be 193 * uint32_t status;
Kojto 170:19eb464bc2be 194 * status = WWDT_GetStatusFlags(wwdt_base) & kWWDT_TimeoutFlag;
Kojto 170:19eb464bc2be 195 * @endcode
Kojto 170:19eb464bc2be 196 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 197 * @return The status flags. This is the logical OR of members of the
Kojto 170:19eb464bc2be 198 * enumeration ::_wwdt_status_flags_t
Kojto 170:19eb464bc2be 199 */
Kojto 170:19eb464bc2be 200 static inline uint32_t WWDT_GetStatusFlags(WWDT_Type *base)
Kojto 170:19eb464bc2be 201 {
Kojto 170:19eb464bc2be 202 return (base->MOD & (WWDT_MOD_WDTOF_MASK | WWDT_MOD_WDINT_MASK));
Kojto 170:19eb464bc2be 203 }
Kojto 170:19eb464bc2be 204
Kojto 170:19eb464bc2be 205 /*!
Kojto 170:19eb464bc2be 206 * @brief Clear WWDT flag.
Kojto 170:19eb464bc2be 207 *
Kojto 170:19eb464bc2be 208 * This function clears WWDT status flag.
Kojto 170:19eb464bc2be 209 *
Kojto 170:19eb464bc2be 210 * Example for clearing warning flag:
Kojto 170:19eb464bc2be 211 * @code
Kojto 170:19eb464bc2be 212 * WWDT_ClearStatusFlags(wwdt_base, kWWDT_WarningFlag);
Kojto 170:19eb464bc2be 213 * @endcode
Kojto 170:19eb464bc2be 214 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 215 * @param mask The status flags to clear. This is a logical OR of members of the
Kojto 170:19eb464bc2be 216 * enumeration ::_wwdt_status_flags_t
Kojto 170:19eb464bc2be 217 */
Kojto 170:19eb464bc2be 218 void WWDT_ClearStatusFlags(WWDT_Type *base, uint32_t mask);
Kojto 170:19eb464bc2be 219
Kojto 170:19eb464bc2be 220 /*!
Kojto 170:19eb464bc2be 221 * @brief Set the WWDT warning value.
Kojto 170:19eb464bc2be 222 *
Kojto 170:19eb464bc2be 223 * The WDWARNINT register determines the watchdog timer counter value that will generate a watchdog
Kojto 170:19eb464bc2be 224 * interrupt. When the watchdog timer counter is no longer greater than the value defined by
Kojto 170:19eb464bc2be 225 * WARNINT, an interrupt will be generated after the subsequent WDCLK.
Kojto 170:19eb464bc2be 226 *
Kojto 170:19eb464bc2be 227 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 228 * @param warningValue WWDT warning value.
Kojto 170:19eb464bc2be 229 */
Kojto 170:19eb464bc2be 230 static inline void WWDT_SetWarningValue(WWDT_Type *base, uint32_t warningValue)
Kojto 170:19eb464bc2be 231 {
Kojto 170:19eb464bc2be 232 base->WARNINT = WWDT_WARNINT_WARNINT(warningValue);
Kojto 170:19eb464bc2be 233 }
Kojto 170:19eb464bc2be 234
Kojto 170:19eb464bc2be 235 /*!
Kojto 170:19eb464bc2be 236 * @brief Set the WWDT timeout value.
Kojto 170:19eb464bc2be 237 *
Kojto 170:19eb464bc2be 238 * This function sets the timeout value. Every time a feed sequence occurs the value in the TC
Kojto 170:19eb464bc2be 239 * register is loaded into the Watchdog timer. Writing a value below 0xFF will cause 0xFF to be
Kojto 170:19eb464bc2be 240 * loaded into the TC register. Thus the minimum time-out interval is TWDCLK*256*4.
Kojto 170:19eb464bc2be 241 * If enableWatchdogProtect flag is true in wwdt_config_t config structure, any attempt to change
Kojto 170:19eb464bc2be 242 * the timeout value before the watchdog counter is below the warning and window values
Kojto 170:19eb464bc2be 243 * will cause a watchdog reset and set the WDTOF flag.
Kojto 170:19eb464bc2be 244 *
Kojto 170:19eb464bc2be 245 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 246 * @param timeoutCount WWDT timeout value, count of WWDT clock tick.
Kojto 170:19eb464bc2be 247 */
Kojto 170:19eb464bc2be 248 static inline void WWDT_SetTimeoutValue(WWDT_Type *base, uint32_t timeoutCount)
Kojto 170:19eb464bc2be 249 {
Kojto 170:19eb464bc2be 250 base->TC = WWDT_TC_COUNT(timeoutCount);
Kojto 170:19eb464bc2be 251 }
Kojto 170:19eb464bc2be 252
Kojto 170:19eb464bc2be 253 /*!
Kojto 170:19eb464bc2be 254 * @brief Sets the WWDT window value.
Kojto 170:19eb464bc2be 255 *
Kojto 170:19eb464bc2be 256 * The WINDOW register determines the highest TV value allowed when a watchdog feed is performed.
Kojto 170:19eb464bc2be 257 * If a feed sequence occurs when timer value is greater than the value in WINDOW, a watchdog
Kojto 170:19eb464bc2be 258 * event will occur. To disable windowing, set windowValue to 0xFFFFFF (maximum possible timer
Kojto 170:19eb464bc2be 259 * value) so windowing is not in effect.
Kojto 170:19eb464bc2be 260 *
Kojto 170:19eb464bc2be 261 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 262 * @param windowValue WWDT window value.
Kojto 170:19eb464bc2be 263 */
Kojto 170:19eb464bc2be 264 static inline void WWDT_SetWindowValue(WWDT_Type *base, uint32_t windowValue)
Kojto 170:19eb464bc2be 265 {
Kojto 170:19eb464bc2be 266 base->WINDOW = WWDT_WINDOW_WINDOW(windowValue);
Kojto 170:19eb464bc2be 267 }
Kojto 170:19eb464bc2be 268
Kojto 170:19eb464bc2be 269 /*!
Kojto 170:19eb464bc2be 270 * @brief Refreshes the WWDT timer.
Kojto 170:19eb464bc2be 271 *
Kojto 170:19eb464bc2be 272 * This function feeds the WWDT.
Kojto 170:19eb464bc2be 273 * This function should be called before WWDT timer is in timeout. Otherwise, a reset is asserted.
Kojto 170:19eb464bc2be 274 *
Kojto 170:19eb464bc2be 275 * @param base WWDT peripheral base address
Kojto 170:19eb464bc2be 276 */
Kojto 170:19eb464bc2be 277 void WWDT_Refresh(WWDT_Type *base);
Kojto 170:19eb464bc2be 278
Kojto 170:19eb464bc2be 279 /*@}*/
Kojto 170:19eb464bc2be 280
Kojto 170:19eb464bc2be 281 #if defined(__cplusplus)
Kojto 170:19eb464bc2be 282 }
Kojto 170:19eb464bc2be 283 #endif /* __cplusplus */
Kojto 170:19eb464bc2be 284
Kojto 170:19eb464bc2be 285 /*! @}*/
Kojto 170:19eb464bc2be 286
Kojto 170:19eb464bc2be 287 #endif /* _FSL_WWDT_H_ */