Line | |
---|
1 | /*
|
---|
2 | Copyright (c) 2012 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 <Arduino.h>
|
---|
20 | #include "Reset.h"
|
---|
21 |
|
---|
22 | #ifdef __cplusplus
|
---|
23 | extern "C" {
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | __attribute__ ((long_call, section (".ramfunc")))
|
---|
27 | static void banzai() {
|
---|
28 | // Disable all interrupts
|
---|
29 | __disable_irq();
|
---|
30 |
|
---|
31 | WDT->CONFIG.bit.PER = 0x0; //8 clock cycles period for WDT
|
---|
32 | WDT->CTRL.reg |= WDT_CTRL_ENABLE; //enable watchdog
|
---|
33 | while(1)
|
---|
34 | {
|
---|
35 | //wait for WDT
|
---|
36 | }
|
---|
37 | while (true);
|
---|
38 | }
|
---|
39 |
|
---|
40 | static int ticks = -1;
|
---|
41 |
|
---|
42 | void initiateReset(int _ticks) {
|
---|
43 | ticks = _ticks;
|
---|
44 | banzai();
|
---|
45 | }
|
---|
46 |
|
---|
47 | void cancelReset() {
|
---|
48 | ticks = -1;
|
---|
49 | }
|
---|
50 |
|
---|
51 | void tickReset() {
|
---|
52 | if (ticks == -1)
|
---|
53 | return;
|
---|
54 | ticks--;
|
---|
55 | if (ticks == 0)
|
---|
56 | banzai();
|
---|
57 | }
|
---|
58 |
|
---|
59 | #ifdef __cplusplus
|
---|
60 | }
|
---|
61 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.