mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32620C/mxc/wdt.c@186:707f6e361f3e, 2018-06-22 (annotated)
- Committer:
- Anna Bridge
- Date:
- Fri Jun 22 16:45:37 2018 +0100
- Revision:
- 186:707f6e361f3e
mbed-dev library. Release version 162
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
186:707f6e361f3e | 1 | /** |
Anna Bridge |
186:707f6e361f3e | 2 | * @file |
Anna Bridge |
186:707f6e361f3e | 3 | * @brief Watchdog driver source. |
Anna Bridge |
186:707f6e361f3e | 4 | */ |
Anna Bridge |
186:707f6e361f3e | 5 | /* ***************************************************************************** |
Anna Bridge |
186:707f6e361f3e | 6 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
Anna Bridge |
186:707f6e361f3e | 7 | * |
Anna Bridge |
186:707f6e361f3e | 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
Anna Bridge |
186:707f6e361f3e | 9 | * copy of this software and associated documentation files (the "Software"), |
Anna Bridge |
186:707f6e361f3e | 10 | * to deal in the Software without restriction, including without limitation |
Anna Bridge |
186:707f6e361f3e | 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Anna Bridge |
186:707f6e361f3e | 12 | * and/or sell copies of the Software, and to permit persons to whom the |
Anna Bridge |
186:707f6e361f3e | 13 | * Software is furnished to do so, subject to the following conditions: |
Anna Bridge |
186:707f6e361f3e | 14 | * |
Anna Bridge |
186:707f6e361f3e | 15 | * The above copyright notice and this permission notice shall be included |
Anna Bridge |
186:707f6e361f3e | 16 | * in all copies or substantial portions of the Software. |
Anna Bridge |
186:707f6e361f3e | 17 | * |
Anna Bridge |
186:707f6e361f3e | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Anna Bridge |
186:707f6e361f3e | 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Anna Bridge |
186:707f6e361f3e | 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Anna Bridge |
186:707f6e361f3e | 21 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Anna Bridge |
186:707f6e361f3e | 22 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Anna Bridge |
186:707f6e361f3e | 23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Anna Bridge |
186:707f6e361f3e | 24 | * OTHER DEALINGS IN THE SOFTWARE. |
Anna Bridge |
186:707f6e361f3e | 25 | * |
Anna Bridge |
186:707f6e361f3e | 26 | * Except as contained in this notice, the name of Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 27 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 28 | * Products, Inc. Branding Policy. |
Anna Bridge |
186:707f6e361f3e | 29 | * |
Anna Bridge |
186:707f6e361f3e | 30 | * The mere transfer of this software does not imply any licenses |
Anna Bridge |
186:707f6e361f3e | 31 | * of trade secrets, proprietary technology, copyrights, patents, |
Anna Bridge |
186:707f6e361f3e | 32 | * trademarks, maskwork rights, or any other form of intellectual |
Anna Bridge |
186:707f6e361f3e | 33 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Anna Bridge |
186:707f6e361f3e | 34 | * ownership rights. |
Anna Bridge |
186:707f6e361f3e | 35 | * |
Anna Bridge |
186:707f6e361f3e | 36 | * $Date: 2016-09-08 17:27:05 -0500 (Thu, 08 Sep 2016) $ |
Anna Bridge |
186:707f6e361f3e | 37 | * $Revision: 24321 $ |
Anna Bridge |
186:707f6e361f3e | 38 | * |
Anna Bridge |
186:707f6e361f3e | 39 | **************************************************************************** */ |
Anna Bridge |
186:707f6e361f3e | 40 | |
Anna Bridge |
186:707f6e361f3e | 41 | /* **** Includes **** */ |
Anna Bridge |
186:707f6e361f3e | 42 | #include <stddef.h> |
Anna Bridge |
186:707f6e361f3e | 43 | #include "wdt.h" |
Anna Bridge |
186:707f6e361f3e | 44 | /** |
Anna Bridge |
186:707f6e361f3e | 45 | * @ingroup wdt |
Anna Bridge |
186:707f6e361f3e | 46 | * @{ |
Anna Bridge |
186:707f6e361f3e | 47 | */ |
Anna Bridge |
186:707f6e361f3e | 48 | static uint32_t interruptEnable = 0; //keeps track to interrupts to enable in start function |
Anna Bridge |
186:707f6e361f3e | 49 | |
Anna Bridge |
186:707f6e361f3e | 50 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 51 | int WDT_Init(mxc_wdt_regs_t *wdt, const sys_cfg_wdt_t *cfg, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 52 | { |
Anna Bridge |
186:707f6e361f3e | 53 | if ((wdt == NULL) || (cfg == NULL)) |
Anna Bridge |
186:707f6e361f3e | 54 | return E_NULL_PTR; |
Anna Bridge |
186:707f6e361f3e | 55 | |
Anna Bridge |
186:707f6e361f3e | 56 | //setup watchdog clock |
Anna Bridge |
186:707f6e361f3e | 57 | SYS_WDT_Init(wdt, cfg); |
Anna Bridge |
186:707f6e361f3e | 58 | |
Anna Bridge |
186:707f6e361f3e | 59 | //unlock ctrl to be writable |
Anna Bridge |
186:707f6e361f3e | 60 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 61 | |
Anna Bridge |
186:707f6e361f3e | 62 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 63 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 64 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 65 | |
Anna Bridge |
186:707f6e361f3e | 66 | //disable all interrupts |
Anna Bridge |
186:707f6e361f3e | 67 | interruptEnable = 0; |
Anna Bridge |
186:707f6e361f3e | 68 | wdt->enable = interruptEnable; |
Anna Bridge |
186:707f6e361f3e | 69 | |
Anna Bridge |
186:707f6e361f3e | 70 | //enable the watchdog clock and clear all other settings |
Anna Bridge |
186:707f6e361f3e | 71 | wdt->ctrl = MXC_F_WDT_CTRL_EN_CLOCK; |
Anna Bridge |
186:707f6e361f3e | 72 | |
Anna Bridge |
186:707f6e361f3e | 73 | //clear all interrupt flags |
Anna Bridge |
186:707f6e361f3e | 74 | wdt->flags = WDT_FLAGS_CLEAR_ALL; |
Anna Bridge |
186:707f6e361f3e | 75 | |
Anna Bridge |
186:707f6e361f3e | 76 | //lock ctrl to read-only |
Anna Bridge |
186:707f6e361f3e | 77 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 78 | |
Anna Bridge |
186:707f6e361f3e | 79 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 80 | } |
Anna Bridge |
186:707f6e361f3e | 81 | |
Anna Bridge |
186:707f6e361f3e | 82 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 83 | int WDT_EnableInt(mxc_wdt_regs_t *wdt, wdt_period_t int_period, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 84 | { |
Anna Bridge |
186:707f6e361f3e | 85 | //unlock ctrl to be writable |
Anna Bridge |
186:707f6e361f3e | 86 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 87 | |
Anna Bridge |
186:707f6e361f3e | 88 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 89 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 90 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 91 | |
Anna Bridge |
186:707f6e361f3e | 92 | //stop timer and clear interval period |
Anna Bridge |
186:707f6e361f3e | 93 | wdt->ctrl &= ~(MXC_F_WDT_CTRL_INT_PERIOD | MXC_F_WDT_CTRL_EN_TIMER); |
Anna Bridge |
186:707f6e361f3e | 94 | |
Anna Bridge |
186:707f6e361f3e | 95 | //set interval period |
Anna Bridge |
186:707f6e361f3e | 96 | wdt->ctrl |= (int_period << MXC_F_WDT_CTRL_INT_PERIOD_POS); |
Anna Bridge |
186:707f6e361f3e | 97 | |
Anna Bridge |
186:707f6e361f3e | 98 | //enable timeout interrupt |
Anna Bridge |
186:707f6e361f3e | 99 | interruptEnable |= MXC_F_WDT_ENABLE_TIMEOUT; |
Anna Bridge |
186:707f6e361f3e | 100 | |
Anna Bridge |
186:707f6e361f3e | 101 | //lock ctrl to read-only |
Anna Bridge |
186:707f6e361f3e | 102 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 103 | |
Anna Bridge |
186:707f6e361f3e | 104 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 105 | } |
Anna Bridge |
186:707f6e361f3e | 106 | |
Anna Bridge |
186:707f6e361f3e | 107 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 108 | int WDT_DisableInt(mxc_wdt_regs_t *wdt, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 109 | { |
Anna Bridge |
186:707f6e361f3e | 110 | //unlock register to be writable |
Anna Bridge |
186:707f6e361f3e | 111 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 112 | |
Anna Bridge |
186:707f6e361f3e | 113 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 114 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 115 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 116 | |
Anna Bridge |
186:707f6e361f3e | 117 | //disable timeout interrupt |
Anna Bridge |
186:707f6e361f3e | 118 | interruptEnable &= ~MXC_F_WDT_ENABLE_TIMEOUT; |
Anna Bridge |
186:707f6e361f3e | 119 | wdt->enable = interruptEnable; |
Anna Bridge |
186:707f6e361f3e | 120 | |
Anna Bridge |
186:707f6e361f3e | 121 | //lock register to read-only |
Anna Bridge |
186:707f6e361f3e | 122 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 123 | |
Anna Bridge |
186:707f6e361f3e | 124 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 125 | } |
Anna Bridge |
186:707f6e361f3e | 126 | |
Anna Bridge |
186:707f6e361f3e | 127 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 128 | int WDT_EnableWait(mxc_wdt_regs_t *wdt, wdt_period_t wait_period, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 129 | { |
Anna Bridge |
186:707f6e361f3e | 130 | // Make sure wait_period is valid |
Anna Bridge |
186:707f6e361f3e | 131 | if (wait_period >= WDT_PERIOD_MAX) |
Anna Bridge |
186:707f6e361f3e | 132 | return E_INVALID; |
Anna Bridge |
186:707f6e361f3e | 133 | |
Anna Bridge |
186:707f6e361f3e | 134 | //unlock ctrl to be writable |
Anna Bridge |
186:707f6e361f3e | 135 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 136 | |
Anna Bridge |
186:707f6e361f3e | 137 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 138 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 139 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 140 | |
Anna Bridge |
186:707f6e361f3e | 141 | //stop timer and clear wait period |
Anna Bridge |
186:707f6e361f3e | 142 | wdt->ctrl &= ~(MXC_F_WDT_CTRL_WAIT_PERIOD | MXC_F_WDT_CTRL_EN_TIMER); |
Anna Bridge |
186:707f6e361f3e | 143 | |
Anna Bridge |
186:707f6e361f3e | 144 | //set wait period |
Anna Bridge |
186:707f6e361f3e | 145 | wdt->ctrl |= (wait_period << MXC_F_WDT_CTRL_WAIT_PERIOD_POS); |
Anna Bridge |
186:707f6e361f3e | 146 | |
Anna Bridge |
186:707f6e361f3e | 147 | //enable wait interrupt |
Anna Bridge |
186:707f6e361f3e | 148 | interruptEnable |= MXC_F_WDT_ENABLE_PRE_WIN; |
Anna Bridge |
186:707f6e361f3e | 149 | |
Anna Bridge |
186:707f6e361f3e | 150 | //lock ctrl to read-only |
Anna Bridge |
186:707f6e361f3e | 151 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 152 | |
Anna Bridge |
186:707f6e361f3e | 153 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 154 | } |
Anna Bridge |
186:707f6e361f3e | 155 | |
Anna Bridge |
186:707f6e361f3e | 156 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 157 | int WDT_DisableWait(mxc_wdt_regs_t *wdt, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 158 | { |
Anna Bridge |
186:707f6e361f3e | 159 | //unlock register to be writable |
Anna Bridge |
186:707f6e361f3e | 160 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 161 | |
Anna Bridge |
186:707f6e361f3e | 162 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 163 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 164 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 165 | |
Anna Bridge |
186:707f6e361f3e | 166 | //disable wait interrupt |
Anna Bridge |
186:707f6e361f3e | 167 | interruptEnable &= ~MXC_F_WDT_ENABLE_PRE_WIN; |
Anna Bridge |
186:707f6e361f3e | 168 | wdt->enable = interruptEnable; |
Anna Bridge |
186:707f6e361f3e | 169 | |
Anna Bridge |
186:707f6e361f3e | 170 | //lock register to read-only |
Anna Bridge |
186:707f6e361f3e | 171 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 172 | |
Anna Bridge |
186:707f6e361f3e | 173 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 174 | } |
Anna Bridge |
186:707f6e361f3e | 175 | |
Anna Bridge |
186:707f6e361f3e | 176 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 177 | int WDT_EnableReset(mxc_wdt_regs_t *wdt, wdt_period_t rst_period, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 178 | { |
Anna Bridge |
186:707f6e361f3e | 179 | // Make sure wait_period is valid |
Anna Bridge |
186:707f6e361f3e | 180 | if (rst_period >= WDT_PERIOD_MAX) |
Anna Bridge |
186:707f6e361f3e | 181 | return E_INVALID; |
Anna Bridge |
186:707f6e361f3e | 182 | |
Anna Bridge |
186:707f6e361f3e | 183 | //unlock ctrl to be writable |
Anna Bridge |
186:707f6e361f3e | 184 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 185 | |
Anna Bridge |
186:707f6e361f3e | 186 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 187 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 188 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 189 | |
Anna Bridge |
186:707f6e361f3e | 190 | //stop timer and clear reset period |
Anna Bridge |
186:707f6e361f3e | 191 | wdt->ctrl &= ~(MXC_F_WDT_CTRL_RST_PERIOD | MXC_F_WDT_CTRL_EN_TIMER); |
Anna Bridge |
186:707f6e361f3e | 192 | |
Anna Bridge |
186:707f6e361f3e | 193 | //set reset period |
Anna Bridge |
186:707f6e361f3e | 194 | wdt->ctrl |= (rst_period << MXC_F_WDT_CTRL_RST_PERIOD_POS); |
Anna Bridge |
186:707f6e361f3e | 195 | |
Anna Bridge |
186:707f6e361f3e | 196 | //enable reset0 |
Anna Bridge |
186:707f6e361f3e | 197 | interruptEnable |= MXC_F_WDT_ENABLE_RESET_OUT; |
Anna Bridge |
186:707f6e361f3e | 198 | |
Anna Bridge |
186:707f6e361f3e | 199 | //lock ctrl to read-only |
Anna Bridge |
186:707f6e361f3e | 200 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 201 | |
Anna Bridge |
186:707f6e361f3e | 202 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 203 | } |
Anna Bridge |
186:707f6e361f3e | 204 | |
Anna Bridge |
186:707f6e361f3e | 205 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 206 | int WDT_DisableReset(mxc_wdt_regs_t *wdt, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 207 | { |
Anna Bridge |
186:707f6e361f3e | 208 | //unlock register to be writable |
Anna Bridge |
186:707f6e361f3e | 209 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 210 | |
Anna Bridge |
186:707f6e361f3e | 211 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 212 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 213 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 214 | |
Anna Bridge |
186:707f6e361f3e | 215 | //disable reset0 |
Anna Bridge |
186:707f6e361f3e | 216 | interruptEnable &= ~MXC_F_WDT_ENABLE_RESET_OUT; |
Anna Bridge |
186:707f6e361f3e | 217 | wdt->enable = interruptEnable; |
Anna Bridge |
186:707f6e361f3e | 218 | |
Anna Bridge |
186:707f6e361f3e | 219 | //lock register to read-only |
Anna Bridge |
186:707f6e361f3e | 220 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 221 | |
Anna Bridge |
186:707f6e361f3e | 222 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 223 | } |
Anna Bridge |
186:707f6e361f3e | 224 | |
Anna Bridge |
186:707f6e361f3e | 225 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 226 | int WDT_Start(mxc_wdt_regs_t *wdt, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 227 | { |
Anna Bridge |
186:707f6e361f3e | 228 | //check if watchdog is already running |
Anna Bridge |
186:707f6e361f3e | 229 | if(WDT_IsActive(wdt)) |
Anna Bridge |
186:707f6e361f3e | 230 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 231 | |
Anna Bridge |
186:707f6e361f3e | 232 | //unlock ctrl to be writable |
Anna Bridge |
186:707f6e361f3e | 233 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 234 | |
Anna Bridge |
186:707f6e361f3e | 235 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 236 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 237 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 238 | |
Anna Bridge |
186:707f6e361f3e | 239 | WDT_Reset(wdt); |
Anna Bridge |
186:707f6e361f3e | 240 | |
Anna Bridge |
186:707f6e361f3e | 241 | //enable interrupts |
Anna Bridge |
186:707f6e361f3e | 242 | wdt->enable = interruptEnable; |
Anna Bridge |
186:707f6e361f3e | 243 | |
Anna Bridge |
186:707f6e361f3e | 244 | //start timer |
Anna Bridge |
186:707f6e361f3e | 245 | wdt->ctrl |= MXC_F_WDT_CTRL_EN_TIMER; |
Anna Bridge |
186:707f6e361f3e | 246 | |
Anna Bridge |
186:707f6e361f3e | 247 | //lock ctrl to read-only |
Anna Bridge |
186:707f6e361f3e | 248 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 249 | |
Anna Bridge |
186:707f6e361f3e | 250 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 251 | } |
Anna Bridge |
186:707f6e361f3e | 252 | |
Anna Bridge |
186:707f6e361f3e | 253 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 254 | void WDT_Reset(mxc_wdt_regs_t *wdt) |
Anna Bridge |
186:707f6e361f3e | 255 | { |
Anna Bridge |
186:707f6e361f3e | 256 | //reset the watchdog counter |
Anna Bridge |
186:707f6e361f3e | 257 | wdt->clear = MXC_V_WDT_RESET_KEY_0; |
Anna Bridge |
186:707f6e361f3e | 258 | wdt->clear = MXC_V_WDT_RESET_KEY_1; |
Anna Bridge |
186:707f6e361f3e | 259 | |
Anna Bridge |
186:707f6e361f3e | 260 | //clear all interrupt flags |
Anna Bridge |
186:707f6e361f3e | 261 | wdt->flags = WDT_FLAGS_CLEAR_ALL; |
Anna Bridge |
186:707f6e361f3e | 262 | |
Anna Bridge |
186:707f6e361f3e | 263 | //wait for all interrupts to clear |
Anna Bridge |
186:707f6e361f3e | 264 | while(wdt->flags != 0) { |
Anna Bridge |
186:707f6e361f3e | 265 | wdt->flags = WDT_FLAGS_CLEAR_ALL; |
Anna Bridge |
186:707f6e361f3e | 266 | } |
Anna Bridge |
186:707f6e361f3e | 267 | |
Anna Bridge |
186:707f6e361f3e | 268 | return; |
Anna Bridge |
186:707f6e361f3e | 269 | } |
Anna Bridge |
186:707f6e361f3e | 270 | |
Anna Bridge |
186:707f6e361f3e | 271 | /* ************************************************************************* */ |
Anna Bridge |
186:707f6e361f3e | 272 | int WDT_Stop(mxc_wdt_regs_t *wdt, uint8_t unlock_key) |
Anna Bridge |
186:707f6e361f3e | 273 | { |
Anna Bridge |
186:707f6e361f3e | 274 | //unlock ctrl to be writable |
Anna Bridge |
186:707f6e361f3e | 275 | wdt->lock_ctrl = unlock_key; |
Anna Bridge |
186:707f6e361f3e | 276 | |
Anna Bridge |
186:707f6e361f3e | 277 | //check to make sure it unlocked |
Anna Bridge |
186:707f6e361f3e | 278 | if (wdt->lock_ctrl & 0x01) |
Anna Bridge |
186:707f6e361f3e | 279 | return E_BAD_STATE; |
Anna Bridge |
186:707f6e361f3e | 280 | |
Anna Bridge |
186:707f6e361f3e | 281 | //disabled the timer and interrupts |
Anna Bridge |
186:707f6e361f3e | 282 | wdt->enable = 0; |
Anna Bridge |
186:707f6e361f3e | 283 | wdt->ctrl &= ~(MXC_F_WDT_CTRL_EN_TIMER); |
Anna Bridge |
186:707f6e361f3e | 284 | |
Anna Bridge |
186:707f6e361f3e | 285 | //lock ctrl to read-only |
Anna Bridge |
186:707f6e361f3e | 286 | wdt->lock_ctrl = MXC_V_WDT_LOCK_KEY; |
Anna Bridge |
186:707f6e361f3e | 287 | |
Anna Bridge |
186:707f6e361f3e | 288 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 289 | } |
Anna Bridge |
186:707f6e361f3e | 290 | /**@} end of ingroup wdt */ |