The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

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