Add watchdog routines for Due.

This commit is contained in:
Bob Cousins 2014-07-27 13:01:40 +01:00 committed by Martino Facchin
parent f17cc834cf
commit 4725d75054
2 changed files with 68 additions and 2 deletions

View File

@ -358,6 +358,52 @@ void serialEventRun(void)
if (Serial3.available()) serialEvent3();
}
// ----------------------------------------------------------------------------
extern "C" {
/**
* Watchdog enable
*
* Enable the watchdog timer with the specified settings.
* WDTO_xxx macros provide standard settings.
* Should only be called once.
*/
void wdt_enable (uint32_t mode)
{
WDT_Enable (WDT, mode);
}
/**
* Watchdog disable
*
* Disable the watchdog timer.
* Should only be called once.
*/
void wdt_disable(void)
{
WDT_Disable (WDT);
}
/**
* Watchdog reset
*
* Resets the watchdog counter
*/
void wdt_reset(void)
{
WDT_Restart (WDT);
}
} // extern "C"
/**
* Watchdog initialize hook
*
* This function is called from init().
* Default action is to disable watchdog.
*/
void wdt_initialize(void) __attribute__ ((weak, alias("wdt_disable")));
// ----------------------------------------------------------------------------
#ifdef __cplusplus
@ -377,8 +423,8 @@ void init( void )
while (true);
}
// Disable watchdog
WDT_Disable(WDT);
// Initialize watchdog
wdt_initialize();
// Initialize C library
__libc_init_array();

View File

@ -232,6 +232,25 @@ static const uint8_t CAN1TX = 89;
#define TC_MIN_DUTY_CYCLE 0
#define TC_RESOLUTION 8
// Watchdog routines
#define WDTO_15MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(4) | WDT_MR_WDD(4)
#define WDTO_30MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(8) | WDT_MR_WDD(8)
#define WDTO_60MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(15) | WDT_MR_WDD(15)
#define WDTO_120MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(31) | WDT_MR_WDD(31)
#define WDTO_250MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(64) | WDT_MR_WDD(64)
#define WDTO_500MS WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(128) | WDT_MR_WDD(128)
#define WDTO_1S WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(256) | WDT_MR_WDD(256)
#define WDTO_2S WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(512) | WDT_MR_WDD(512)
#define WDTO_4S WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(1024) | WDT_MR_WDD(1024)
#define WDTO_8S WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(2048) | WDT_MR_WDD(2048)
void wdt_enable (uint32_t mode);
void wdt_disable(void);
void wdt_reset(void);
#ifdef __cplusplus
}
#endif
@ -274,5 +293,6 @@ extern USARTClass Serial3;
#define SERIAL_PORT_HARDWARE2 Serial2
#define SERIAL_PORT_HARDWARE3 Serial3
#endif /* _VARIANT_ARDUINO_DUE_X_ */