Skip to content

Commit 4688a7a

Browse files
committed
Merge pull request #3111 from facchinm/test-watchdog-sam-2
Add watchdog routines for Due
2 parents fe52e7f + 7f8cba6 commit 4688a7a

File tree

5 files changed

+112
-3
lines changed

5 files changed

+112
-3
lines changed

hardware/arduino/sam/cores/arduino/Arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ extern const PinDescription g_APinDescription[] ;
194194
#include "wiring_shift.h"
195195
#include "WInterrupts.h"
196196

197+
#include "watchdog.h"
198+
197199
// USB Device
198200
#define USB_VID 0x2341 // arduino LLC vid
199201
#define USB_PID_LEONARDO 0x0034

hardware/arduino/sam/cores/arduino/main.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ void initVariant() { }
4141
*/
4242
int main( void )
4343
{
44+
// Initialize watchdog
45+
watchdogSetup();
46+
4447
init();
4548

4649
initVariant();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
#ifndef _WATCHDOG_
20+
#define _WATCHDOG_
21+
22+
#include <stdint.h>
23+
24+
// Watchdog functions
25+
26+
/*
27+
* \brief Enable the watchdog with the specified timeout. Should only be called once.
28+
*
29+
* \param timeount in milliseconds.
30+
*/
31+
void watchdogEnable (uint32_t timeout);
32+
33+
/*
34+
* \brief Disable the watchdog timer. Should only be called once.
35+
*
36+
*/
37+
void watchdogDisable (void);
38+
39+
/*
40+
* \brief Reset the watchdog counter.
41+
*
42+
*/
43+
void watchdogReset (void);
44+
45+
/*
46+
* \brief Watchdog initialize hook. This function is called from init(). If the user does not provide
47+
* this function, then the default action is to disable watchdog.
48+
*/
49+
void watchdogSetup (void);
50+
51+
#endif /* _WATCHDOG_ */
52+

hardware/arduino/sam/variants/arduino_due_x/variant.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,6 @@ void init( void )
377377
while (true);
378378
}
379379

380-
// Disable watchdog
381-
WDT_Disable(WDT);
382-
383380
// Initialize C library
384381
__libc_init_array();
385382

0 commit comments

Comments
 (0)