t

Fork of mbed-dev by mbed official

Committer:
amithy
Date:
Thu Nov 09 22:14:37 2017 +0000
Revision:
178:c26431f84b0d
Parent:
150:02e0a0aed4ec
test export

Who changed what in which revision?

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