Skip to content

Commit 4725d75

Browse files
bobcfacchinm
authored andcommitted
Add watchdog routines for Due.
1 parent f17cc83 commit 4725d75

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

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

+48-2
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,52 @@ void serialEventRun(void)
358358
if (Serial3.available()) serialEvent3();
359359
}
360360

361+
// ----------------------------------------------------------------------------
362+
extern "C" {
363+
364+
/**
365+
* Watchdog enable
366+
*
367+
* Enable the watchdog timer with the specified settings.
368+
* WDTO_xxx macros provide standard settings.
369+
* Should only be called once.
370+
*/
371+
void wdt_enable (uint32_t mode)
372+
{
373+
WDT_Enable (WDT, mode);
374+
}
375+
376+
/**
377+
* Watchdog disable
378+
*
379+
* Disable the watchdog timer.
380+
* Should only be called once.
381+
*/
382+
void wdt_disable(void)
383+
{
384+
WDT_Disable (WDT);
385+
}
386+
387+
/**
388+
* Watchdog reset
389+
*
390+
* Resets the watchdog counter
391+
*/
392+
void wdt_reset(void)
393+
{
394+
WDT_Restart (WDT);
395+
}
396+
397+
} // extern "C"
398+
399+
/**
400+
* Watchdog initialize hook
401+
*
402+
* This function is called from init().
403+
* Default action is to disable watchdog.
404+
*/
405+
void wdt_initialize(void) __attribute__ ((weak, alias("wdt_disable")));
406+
361407
// ----------------------------------------------------------------------------
362408

363409
#ifdef __cplusplus
@@ -377,8 +423,8 @@ void init( void )
377423
while (true);
378424
}
379425

380-
// Disable watchdog
381-
WDT_Disable(WDT);
426+
// Initialize watchdog
427+
wdt_initialize();
382428

383429
// Initialize C library
384430
__libc_init_array();

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

+20
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,25 @@ static const uint8_t CAN1TX = 89;
232232
#define TC_MIN_DUTY_CYCLE 0
233233
#define TC_RESOLUTION 8
234234

235+
// Watchdog routines
236+
237+
#define WDTO_15MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(4) | WDT_MR_WDD(4)
238+
#define WDTO_30MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(8) | WDT_MR_WDD(8)
239+
#define WDTO_60MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(15) | WDT_MR_WDD(15)
240+
#define WDTO_120MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(31) | WDT_MR_WDD(31)
241+
#define WDTO_250MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(64) | WDT_MR_WDD(64)
242+
#define WDTO_500MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(128) | WDT_MR_WDD(128)
243+
#define WDTO_1S WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(256) | WDT_MR_WDD(256)
244+
#define WDTO_2S WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(512) | WDT_MR_WDD(512)
245+
#define WDTO_4S WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(1024) | WDT_MR_WDD(1024)
246+
#define WDTO_8S WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(2048) | WDT_MR_WDD(2048)
247+
248+
void wdt_enable (uint32_t mode);
249+
250+
void wdt_disable(void);
251+
252+
void wdt_reset(void);
253+
235254
#ifdef __cplusplus
236255
}
237256
#endif
@@ -274,5 +293,6 @@ extern USARTClass Serial3;
274293
#define SERIAL_PORT_HARDWARE2 Serial2
275294
#define SERIAL_PORT_HARDWARE3 Serial3
276295

296+
277297
#endif /* _VARIANT_ARDUINO_DUE_X_ */
278298

0 commit comments

Comments
 (0)