test

Committer:
elijahsj
Date:
Mon Nov 09 00:33:19 2020 -0500
Revision:
2:4364577b5ad8
Parent:
1:8a094db1347f
copied mbed library

Who changed what in which revision?

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