|
| 1 | +/* |
| 2 | + Copyright (c) 2014 Arduino. All right reserved. |
| 3 | +
|
| 4 | + This library is free software; you can redistribute it and/or |
| 5 | + modify it under the terms of the GNU Lesser General Public |
| 6 | + License as published by the Free Software Foundation; either |
| 7 | + version 2.1 of the License, or (at your option) any later version. |
| 8 | +
|
| 9 | + This library is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | + See the GNU Lesser General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU Lesser General Public |
| 15 | + License along with this library; if not, write to the Free Software |
| 16 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | +*/ |
| 18 | + |
| 19 | +#include <chip.h> |
| 20 | + |
| 21 | +#include "watchdog.h" |
| 22 | + |
| 23 | + |
| 24 | +void watchdogEnable (uint32_t timeout) |
| 25 | +{ |
| 26 | + /* this assumes the slow clock is running at 32.768 kHz |
| 27 | + watchdog frequency is therefore 32768 / 128 = 256 Hz */ |
| 28 | + timeout = timeout * 256 / 1000; |
| 29 | + if (timeout == 0) |
| 30 | + timeout = 1; |
| 31 | + else if (timeout > 0xFFF) |
| 32 | + timeout = 0xFFF; |
| 33 | + timeout = WDT_MR_WDRSTEN | WDT_MR_WDV(timeout) | WDT_MR_WDD(timeout); |
| 34 | + WDT_Enable (WDT, timeout); |
| 35 | +} |
| 36 | + |
| 37 | +void watchdogDisable(void) |
| 38 | +{ |
| 39 | + WDT_Disable (WDT); |
| 40 | +} |
| 41 | + |
| 42 | +void watchdogReset(void) |
| 43 | +{ |
| 44 | + WDT_Restart (WDT); |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +extern "C" |
| 49 | +void _watchdogDefaultSetup (void) |
| 50 | +{ |
| 51 | + WDT_Disable (WDT); |
| 52 | +} |
| 53 | +void watchdogSetup (void) __attribute__ ((weak, alias("_watchdogDefaultSetup"))); |
| 54 | + |
| 55 | + |
0 commit comments