mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
Add Due watchdog functions; modified according to feedback supplied
This commit is contained in:
parent
4725d75054
commit
d2c510d166
@ -194,6 +194,8 @@ extern const PinDescription g_APinDescription[] ;
|
|||||||
#include "wiring_shift.h"
|
#include "wiring_shift.h"
|
||||||
#include "WInterrupts.h"
|
#include "WInterrupts.h"
|
||||||
|
|
||||||
|
#include "watchdog.h"
|
||||||
|
|
||||||
// USB Device
|
// USB Device
|
||||||
#define USB_VID 0x2341 // arduino LLC vid
|
#define USB_VID 0x2341 // arduino LLC vid
|
||||||
#define USB_PID_LEONARDO 0x0034
|
#define USB_PID_LEONARDO 0x0034
|
||||||
|
@ -41,6 +41,9 @@ void initVariant() { }
|
|||||||
*/
|
*/
|
||||||
int main( void )
|
int main( void )
|
||||||
{
|
{
|
||||||
|
// Initialize watchdog
|
||||||
|
watchdogSetup();
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
initVariant();
|
initVariant();
|
||||||
|
55
hardware/arduino/sam/cores/arduino/watchdog.cpp
Normal file
55
hardware/arduino/sam/cores/arduino/watchdog.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <chip.h>
|
||||||
|
|
||||||
|
#include "watchdog.h"
|
||||||
|
|
||||||
|
|
||||||
|
void watchdogEnable (uint32_t timeout)
|
||||||
|
{
|
||||||
|
/* this assumes the slow clock is running at 32.768 kHz
|
||||||
|
watchdog frequency is therefore 32768 / 128 = 256 Hz */
|
||||||
|
timeout = timeout * 256 / 1000;
|
||||||
|
if (timeout == 0)
|
||||||
|
timeout = 1;
|
||||||
|
else if (timeout > 0xFFF)
|
||||||
|
timeout = 0xFFF;
|
||||||
|
timeout = WDT_MR_WDRSTEN | WDT_MR_WDRPROC | WDT_MR_WDV(timeout) | WDT_MR_WDD(timeout);
|
||||||
|
WDT_Enable (WDT, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void watchdogDisable(void)
|
||||||
|
{
|
||||||
|
WDT_Disable (WDT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void watchdogReset(void)
|
||||||
|
{
|
||||||
|
WDT_Restart (WDT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
void _watchdogDefaultSetup (void)
|
||||||
|
{
|
||||||
|
WDT_Disable (WDT);
|
||||||
|
}
|
||||||
|
void watchdogSetup (void) __attribute__ ((weak, alias("_watchdogDefaultSetup")));
|
||||||
|
|
||||||
|
|
52
hardware/arduino/sam/cores/arduino/watchdog.h
Normal file
52
hardware/arduino/sam/cores/arduino/watchdog.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2014 Arduino. All right reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _WATCHDOG_
|
||||||
|
#define _WATCHDOG_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// Watchdog functions
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Enable the watchdog with the specified timeout. Should only be called once.
|
||||||
|
*
|
||||||
|
* \param timeount in milliseconds.
|
||||||
|
*/
|
||||||
|
void watchdogEnable (uint32_t timeout);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Disable the watchdog timer. Should only be called once.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void watchdogDisable (void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Reset the watchdog counter.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void watchdogReset (void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* \brief Watchdog initialize hook. This function is called from init(). If the user does not provide
|
||||||
|
* this function, then the default action is to disable watchdog.
|
||||||
|
*/
|
||||||
|
void watchdogSetup (void);
|
||||||
|
|
||||||
|
#endif /* _WATCHDOG_ */
|
||||||
|
|
@ -358,52 +358,6 @@ void serialEventRun(void)
|
|||||||
if (Serial3.available()) serialEvent3();
|
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
|
#ifdef __cplusplus
|
||||||
@ -423,9 +377,6 @@ void init( void )
|
|||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize watchdog
|
|
||||||
wdt_initialize();
|
|
||||||
|
|
||||||
// Initialize C library
|
// Initialize C library
|
||||||
__libc_init_array();
|
__libc_init_array();
|
||||||
|
|
||||||
|
@ -232,25 +232,6 @@ static const uint8_t CAN1TX = 89;
|
|||||||
#define TC_MIN_DUTY_CYCLE 0
|
#define TC_MIN_DUTY_CYCLE 0
|
||||||
#define TC_RESOLUTION 8
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -293,6 +274,5 @@ extern USARTClass Serial3;
|
|||||||
#define SERIAL_PORT_HARDWARE2 Serial2
|
#define SERIAL_PORT_HARDWARE2 Serial2
|
||||||
#define SERIAL_PORT_HARDWARE3 Serial3
|
#define SERIAL_PORT_HARDWARE3 Serial3
|
||||||
|
|
||||||
|
|
||||||
#endif /* _VARIANT_ARDUINO_DUE_X_ */
|
#endif /* _VARIANT_ARDUINO_DUE_X_ */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user