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
Anna Bridge 169:a7c7b631e539 1 /*******************************************************************************
Anna Bridge 169:a7c7b631e539 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
Anna Bridge 169:a7c7b631e539 3 *
Anna Bridge 169:a7c7b631e539 4 * Permission is hereby granted, free of charge, to any person obtaining a
Anna Bridge 169:a7c7b631e539 5 * copy of this software and associated documentation files (the "Software"),
Anna Bridge 169:a7c7b631e539 6 * to deal in the Software without restriction, including without limitation
Anna Bridge 169:a7c7b631e539 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Anna Bridge 169:a7c7b631e539 8 * and/or sell copies of the Software, and to permit persons to whom the
Anna Bridge 169:a7c7b631e539 9 * Software is furnished to do so, subject to the following conditions:
Anna Bridge 169:a7c7b631e539 10 *
Anna Bridge 169:a7c7b631e539 11 * The above copyright notice and this permission notice shall be included
Anna Bridge 169:a7c7b631e539 12 * in all copies or substantial portions of the Software.
Anna Bridge 169:a7c7b631e539 13 *
Anna Bridge 169:a7c7b631e539 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Anna Bridge 169:a7c7b631e539 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Anna Bridge 169:a7c7b631e539 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Anna Bridge 169:a7c7b631e539 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
Anna Bridge 169:a7c7b631e539 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Anna Bridge 169:a7c7b631e539 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Anna Bridge 169:a7c7b631e539 20 * OTHER DEALINGS IN THE SOFTWARE.
Anna Bridge 169:a7c7b631e539 21 *
Anna Bridge 169:a7c7b631e539 22 * Except as contained in this notice, the name of Maxim Integrated
Anna Bridge 169:a7c7b631e539 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
Anna Bridge 169:a7c7b631e539 24 * Products, Inc. Branding Policy.
Anna Bridge 169:a7c7b631e539 25 *
Anna Bridge 169:a7c7b631e539 26 * The mere transfer of this software does not imply any licenses
Anna Bridge 169:a7c7b631e539 27 * of trade secrets, proprietary technology, copyrights, patents,
Anna Bridge 169:a7c7b631e539 28 * trademarks, maskwork rights, or any other form of intellectual
Anna Bridge 169:a7c7b631e539 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
Anna Bridge 169:a7c7b631e539 30 * ownership rights.
Anna Bridge 169:a7c7b631e539 31 *
Anna Bridge 169:a7c7b631e539 32 * $Date: 2016-03-21 15:44:11 -0500 (Mon, 21 Mar 2016) $
Anna Bridge 169:a7c7b631e539 33 * $Revision: 22024 $
Anna Bridge 169:a7c7b631e539 34 *
Anna Bridge 169:a7c7b631e539 35 ******************************************************************************/
Anna Bridge 169:a7c7b631e539 36
Anna Bridge 169:a7c7b631e539 37 /**
Anna Bridge 169:a7c7b631e539 38 * @file wdt.h
Anna Bridge 169:a7c7b631e539 39 * @addtogroup wdt WDT
Anna Bridge 169:a7c7b631e539 40 * @{
Anna Bridge 169:a7c7b631e539 41 * @brief This is the high level API for the watchdog timer interface module
Anna Bridge 169:a7c7b631e539 42 *
Anna Bridge 169:a7c7b631e539 43 */
Anna Bridge 169:a7c7b631e539 44
Anna Bridge 169:a7c7b631e539 45 #ifndef _WDT_H
Anna Bridge 169:a7c7b631e539 46 #define _WDT_H
Anna Bridge 169:a7c7b631e539 47
Anna Bridge 169:a7c7b631e539 48 #include "mxc_config.h"
Anna Bridge 169:a7c7b631e539 49 #include "wdt_regs.h"
Anna Bridge 169:a7c7b631e539 50 #include "mxc_assert.h"
Anna Bridge 169:a7c7b631e539 51 #include "mxc_sys.h"
Anna Bridge 169:a7c7b631e539 52
Anna Bridge 169:a7c7b631e539 53 #ifdef __cplusplus
Anna Bridge 169:a7c7b631e539 54 extern "C" {
Anna Bridge 169:a7c7b631e539 55 #endif
Anna Bridge 169:a7c7b631e539 56
Anna Bridge 169:a7c7b631e539 57 #define WDT_FLAGS_CLEAR_ALL (MXC_F_WDT_FLAGS_TIMEOUT| \
Anna Bridge 169:a7c7b631e539 58 MXC_F_WDT_FLAGS_PRE_WIN | \
Anna Bridge 169:a7c7b631e539 59 MXC_F_WDT_FLAGS_RESET_OUT)
Anna Bridge 169:a7c7b631e539 60 /** @enum wdt_period_t */
Anna Bridge 169:a7c7b631e539 61 /** @brief Enumeration for the Watchdog Timer Period */
Anna Bridge 169:a7c7b631e539 62 typedef enum {
Anna Bridge 169:a7c7b631e539 63 WDT_PERIOD_2_31_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_31_CLKS, /**< 2^31 WDT clocks. */
Anna Bridge 169:a7c7b631e539 64 WDT_PERIOD_2_30_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_30_CLKS, /**< 2^30 WDT clocks. */
Anna Bridge 169:a7c7b631e539 65 WDT_PERIOD_2_29_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_29_CLKS, /**< 2^29 WDT clocks. */
Anna Bridge 169:a7c7b631e539 66 WDT_PERIOD_2_28_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_28_CLKS, /**< 2^28 WDT clocks. */
Anna Bridge 169:a7c7b631e539 67 WDT_PERIOD_2_27_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_27_CLKS, /**< 2^27 WDT clocks. */
Anna Bridge 169:a7c7b631e539 68 WDT_PERIOD_2_26_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_26_CLKS, /**< 2^26 WDT clocks. */
Anna Bridge 169:a7c7b631e539 69 WDT_PERIOD_2_25_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_25_CLKS, /**< 2^25 WDT clocks. */
Anna Bridge 169:a7c7b631e539 70 WDT_PERIOD_2_24_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_24_CLKS, /**< 2^24 WDT clocks. */
Anna Bridge 169:a7c7b631e539 71 WDT_PERIOD_2_23_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_23_CLKS, /**< 2^23 WDT clocks. */
Anna Bridge 169:a7c7b631e539 72 WDT_PERIOD_2_22_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_22_CLKS, /**< 2^22 WDT clocks. */
Anna Bridge 169:a7c7b631e539 73 WDT_PERIOD_2_21_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_21_CLKS, /**< 2^21 WDT clocks. */
Anna Bridge 169:a7c7b631e539 74 WDT_PERIOD_2_20_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_20_CLKS, /**< 2^20 WDT clocks. */
Anna Bridge 169:a7c7b631e539 75 WDT_PERIOD_2_19_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_19_CLKS, /**< 2^19 WDT clocks. */
Anna Bridge 169:a7c7b631e539 76 WDT_PERIOD_2_18_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_18_CLKS, /**< 2^18 WDT clocks. */
Anna Bridge 169:a7c7b631e539 77 WDT_PERIOD_2_17_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_17_CLKS, /**< 2^17 WDT clocks. */
Anna Bridge 169:a7c7b631e539 78 WDT_PERIOD_2_16_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_16_CLKS, /**< 2^16 WDT clocks. */
Anna Bridge 169:a7c7b631e539 79 WDT_PERIOD_MAX /**< Maximum Period is Max - 1 */
Anna Bridge 169:a7c7b631e539 80 } wdt_period_t;
Anna Bridge 169:a7c7b631e539 81
Anna Bridge 169:a7c7b631e539 82 /**
Anna Bridge 169:a7c7b631e539 83 * @brief Initializes system level clocks and sets watchdog in a known disabled state
Anna Bridge 169:a7c7b631e539 84 * @note The clk_scale in cfg is only used if the system clock is selected for clk.
Anna Bridge 169:a7c7b631e539 85 *
Anna Bridge 169:a7c7b631e539 86 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 87 * @param cfg Watchdog system configuration, see sys_cfg_wdt_t.
Anna Bridge 169:a7c7b631e539 88 * @param unlock_key Watchdog unlock key
Anna Bridge 169:a7c7b631e539 89 *
Anna Bridge 169:a7c7b631e539 90 * @retval E_NO_ERROR Watchdog Timer initialized as requested
Anna Bridge 169:a7c7b631e539 91 * @retval E_NULL_PTR NULL pointer for Watchdog Timer Instance or Configuration parameters.
Anna Bridge 169:a7c7b631e539 92 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
Anna Bridge 169:a7c7b631e539 93 */
Anna Bridge 169:a7c7b631e539 94 int WDT_Init(mxc_wdt_regs_t *wdt, const sys_cfg_wdt_t *cfg, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 95
Anna Bridge 169:a7c7b631e539 96 /**
Anna Bridge 169:a7c7b631e539 97 * @brief Configures and enables the interrupt timeout for the watchdog specified.
Anna Bridge 169:a7c7b631e539 98 *
Anna Bridge 169:a7c7b631e539 99 * @param wdt Watchdog module to operate on
Anna Bridge 169:a7c7b631e539 100 * @param int_period Interrupt period as defined by wdt_period_t.
Anna Bridge 169:a7c7b631e539 101 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
Anna Bridge 169:a7c7b631e539 102 *
Anna Bridge 169:a7c7b631e539 103 * @retval E_NO_ERROR Interrupt enabled
Anna Bridge 169:a7c7b631e539 104 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
Anna Bridge 169:a7c7b631e539 105 */
Anna Bridge 169:a7c7b631e539 106 int WDT_EnableInt(mxc_wdt_regs_t *wdt, wdt_period_t int_period, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 107
Anna Bridge 169:a7c7b631e539 108 /**
Anna Bridge 169:a7c7b631e539 109 * @brief Disables the interrupt timeout for the watchdog specified.
Anna Bridge 169:a7c7b631e539 110 *
Anna Bridge 169:a7c7b631e539 111 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 112 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
Anna Bridge 169:a7c7b631e539 113 *
Anna Bridge 169:a7c7b631e539 114 * @retval E_NO_ERROR Interrupt disabled.
Anna Bridge 169:a7c7b631e539 115 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
Anna Bridge 169:a7c7b631e539 116 */
Anna Bridge 169:a7c7b631e539 117 int WDT_DisableInt(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 118
Anna Bridge 169:a7c7b631e539 119 /**
Anna Bridge 169:a7c7b631e539 120 * @brief Configures and enables the pre-window timeout for the watchdog specified.
Anna Bridge 169:a7c7b631e539 121 *
Anna Bridge 169:a7c7b631e539 122 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 123 * @param wait_period Pre-window period, see wdt_period_t for accepted values.
Anna Bridge 169:a7c7b631e539 124 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
Anna Bridge 169:a7c7b631e539 125 *
Anna Bridge 169:a7c7b631e539 126 * @retval E_NO_ERROR Pre-window timeout set to wait_period
Anna Bridge 169:a7c7b631e539 127 * @retval E_BAD_STATE WDT unable to be unlocked
Anna Bridge 169:a7c7b631e539 128 * @retval E_INVALID Requested Period is greater than the maximum supported
Anna Bridge 169:a7c7b631e539 129 */
Anna Bridge 169:a7c7b631e539 130 int WDT_EnableWait(mxc_wdt_regs_t *wdt, wdt_period_t wait_period, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 131
Anna Bridge 169:a7c7b631e539 132 /**
Anna Bridge 169:a7c7b631e539 133 * @brief Disables the pre-window timeout for the watchdog specified.
Anna Bridge 169:a7c7b631e539 134 *
Anna Bridge 169:a7c7b631e539 135 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 136 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
Anna Bridge 169:a7c7b631e539 137 *
Anna Bridge 169:a7c7b631e539 138 * @retval E_NO_ERROR Wait disabled.
Anna Bridge 169:a7c7b631e539 139 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
Anna Bridge 169:a7c7b631e539 140 */
Anna Bridge 169:a7c7b631e539 141 int WDT_DisableWait(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 142
Anna Bridge 169:a7c7b631e539 143 /**
Anna Bridge 169:a7c7b631e539 144 * @brief Configures and enables the reset timeout for the watchdog specified.
Anna Bridge 169:a7c7b631e539 145 *
Anna Bridge 169:a7c7b631e539 146 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 147 * @param rst_period Reset period, see wdt_period_t for accepted values.
Anna Bridge 169:a7c7b631e539 148 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
Anna Bridge 169:a7c7b631e539 149 *
Anna Bridge 169:a7c7b631e539 150 * @retval E_NO_ERROR Watchdog Timer Reset enabled with the rst_period time.
Anna Bridge 169:a7c7b631e539 151 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
Anna Bridge 169:a7c7b631e539 152 * @retval E_INVALID Requested Period is greater than the maximum supported
Anna Bridge 169:a7c7b631e539 153 */
Anna Bridge 169:a7c7b631e539 154 int WDT_EnableReset(mxc_wdt_regs_t *wdt, wdt_period_t rst_period, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 155
Anna Bridge 169:a7c7b631e539 156 /**
Anna Bridge 169:a7c7b631e539 157 * @brief Disables the reset timeout for the watchdog specified.
Anna Bridge 169:a7c7b631e539 158 *
Anna Bridge 169:a7c7b631e539 159 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 160 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
Anna Bridge 169:a7c7b631e539 161 *
Anna Bridge 169:a7c7b631e539 162 * @retval E_NO_ERROR Reset disabled.
Anna Bridge 169:a7c7b631e539 163 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
Anna Bridge 169:a7c7b631e539 164 */
Anna Bridge 169:a7c7b631e539 165 int WDT_DisableReset(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 166
Anna Bridge 169:a7c7b631e539 167 /**
Anna Bridge 169:a7c7b631e539 168 * @brief Gets the watchdog interrupt flags
Anna Bridge 169:a7c7b631e539 169 *
Anna Bridge 169:a7c7b631e539 170 * @param wdt Pointer to the Watchdog Timer Instance.
Anna Bridge 169:a7c7b631e539 171 *
Anna Bridge 169:a7c7b631e539 172 * @retval uint32_t Value of the Watchdog Timer Flags.
Anna Bridge 169:a7c7b631e539 173 *
Anna Bridge 169:a7c7b631e539 174 */
Anna Bridge 169:a7c7b631e539 175 __STATIC_INLINE uint32_t WDT_GetFlags(mxc_wdt_regs_t *wdt)
Anna Bridge 169:a7c7b631e539 176 {
Anna Bridge 169:a7c7b631e539 177 return (wdt->flags);
Anna Bridge 169:a7c7b631e539 178 }
Anna Bridge 169:a7c7b631e539 179
Anna Bridge 169:a7c7b631e539 180 /**
Anna Bridge 169:a7c7b631e539 181 * @brief Clears the watchdog interrupt flags based on the mask
Anna Bridge 169:a7c7b631e539 182 *
Anna Bridge 169:a7c7b631e539 183 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 184 * @param mask Watchdog Flags to clear
Anna Bridge 169:a7c7b631e539 185 *
Anna Bridge 169:a7c7b631e539 186 */
Anna Bridge 169:a7c7b631e539 187 __STATIC_INLINE void WDT_ClearFlags(mxc_wdt_regs_t *wdt, uint32_t mask)
Anna Bridge 169:a7c7b631e539 188 {
Anna Bridge 169:a7c7b631e539 189 wdt->flags = mask;
Anna Bridge 169:a7c7b631e539 190 }
Anna Bridge 169:a7c7b631e539 191
Anna Bridge 169:a7c7b631e539 192 /**
Anna Bridge 169:a7c7b631e539 193 * @brief Starts the specified Watchdog Timer instance.
Anna Bridge 169:a7c7b631e539 194 *
Anna Bridge 169:a7c7b631e539 195 * @param wdt Pointer to the Watchdog Timer instance
Anna Bridge 169:a7c7b631e539 196 * @param unlock_key Key to unlock watchdog.
Anna Bridge 169:a7c7b631e539 197 *
Anna Bridge 169:a7c7b631e539 198 * @retval E_NO_ERROR Interrupt enabled.
Anna Bridge 169:a7c7b631e539 199 * @retval E_BAD_STATE WDT2 Already Running
Anna Bridge 169:a7c7b631e539 200 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
Anna Bridge 169:a7c7b631e539 201 *
Anna Bridge 169:a7c7b631e539 202 */
Anna Bridge 169:a7c7b631e539 203 int WDT_Start(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 204
Anna Bridge 169:a7c7b631e539 205 /**
Anna Bridge 169:a7c7b631e539 206 * @brief Feeds the watchdog specified.
Anna Bridge 169:a7c7b631e539 207 *
Anna Bridge 169:a7c7b631e539 208 * @param wdt Watchdog module to operate on
Anna Bridge 169:a7c7b631e539 209 *
Anna Bridge 169:a7c7b631e539 210 */
Anna Bridge 169:a7c7b631e539 211 void WDT_Reset(mxc_wdt_regs_t *wdt);
Anna Bridge 169:a7c7b631e539 212
Anna Bridge 169:a7c7b631e539 213 /**
Anna Bridge 169:a7c7b631e539 214 * @brief Stops the watchdog specified.
Anna Bridge 169:a7c7b631e539 215 *
Anna Bridge 169:a7c7b631e539 216 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 217 * @param unlock_key Key to unlock watchdog.
Anna Bridge 169:a7c7b631e539 218 *
Anna Bridge 169:a7c7b631e539 219 * @retval E_NO_ERROR Interrupt enabled.
Anna Bridge 169:a7c7b631e539 220 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
Anna Bridge 169:a7c7b631e539 221 */
Anna Bridge 169:a7c7b631e539 222 int WDT_Stop(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
Anna Bridge 169:a7c7b631e539 223
Anna Bridge 169:a7c7b631e539 224 /**
Anna Bridge 169:a7c7b631e539 225 * @brief Determines if the watchdog is running
Anna Bridge 169:a7c7b631e539 226 *
Anna Bridge 169:a7c7b631e539 227 * @param wdt Pointer to the Watchdog Timer Instance
Anna Bridge 169:a7c7b631e539 228 *
Anna Bridge 169:a7c7b631e539 229 * @retval 0 Watchdog timer is Disabled.
Anna Bridge 169:a7c7b631e539 230 * @retval non-zero Watchdog timer is Active
Anna Bridge 169:a7c7b631e539 231 */
Anna Bridge 169:a7c7b631e539 232 __STATIC_INLINE int WDT_IsActive(mxc_wdt_regs_t *wdt)
Anna Bridge 169:a7c7b631e539 233 {
Anna Bridge 169:a7c7b631e539 234 return (!!(wdt->ctrl & MXC_F_WDT_CTRL_EN_TIMER));
Anna Bridge 169:a7c7b631e539 235 }
Anna Bridge 169:a7c7b631e539 236
Anna Bridge 169:a7c7b631e539 237 /**
Anna Bridge 169:a7c7b631e539 238 * @}
Anna Bridge 169:a7c7b631e539 239 */
Anna Bridge 169:a7c7b631e539 240
Anna Bridge 169:a7c7b631e539 241 #ifdef __cplusplus
Anna Bridge 169:a7c7b631e539 242 }
Anna Bridge 169:a7c7b631e539 243 #endif
Anna Bridge 169:a7c7b631e539 244
Anna Bridge 169:a7c7b631e539 245 #endif /* _WDT_H */