-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9da0acf
commit e73502c
Showing
20 changed files
with
1,085 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
License Agreement | ||
(3-clause BSD License) | ||
Janelia Research Campus Software Copyright 1.1 | ||
|
||
Copyright (c) 2021, Howard Hughes Medical Institute | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the Howard Hughes Medical Institute nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written | ||
permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#+TITLE: Watchdog | ||
#+AUTHOR: Peter Polidoro | ||
#+EMAIL: [email protected] | ||
|
||
* Library Information | ||
- Name :: Watchdog | ||
- Version :: 3.0.2 | ||
- License :: BSD | ||
- URL :: https://github.com/janelia-arduino/Watchdog | ||
- Author :: Peter Polidoro, Antonio Brewer, Steve Sawtelle | ||
- Email :: [email protected] | ||
|
||
The watchdog monitors the operation of the system by expecting periodic | ||
communication from the software, generally known as servicing or refreshing the | ||
watchdog. If this periodic refreshing does not occur, the watchdog resets the | ||
system. Works with avr, megaavr, and teensy processors. | ||
|
||
When the watchdog timer is enabled, a call to the reset instruction is | ||
required before the timer expires after the timeout duration, otherwise a | ||
watchdog-initiated device reset will occur. | ||
|
||
** Timeout Durations | ||
|
||
Possible timeout durations are 15ms, 30ms, 60ms, 120ms, 250ms, 500ms, 1s, 2s, 4s, and 8s. | ||
|
||
Not all devices allow timeout durations. | ||
- Teensy 4.x does not allow timeout durations below 1s. | ||
- Other processors do not allow timeout durations of 4s or 8s. | ||
|
||
** Teensy 4 | ||
|
||
The watchdog code for the Teensy 4 was written by Antonio Brewer: | ||
|
||
https://github.com/tonton81/WDT_T4 | ||
|
||
** Tripped Method | ||
|
||
The tripped method was written by Steve Sawtelle. | ||
|
||
Unfortunately this method does not work with certain microprocessors and | ||
boards, such as the Arduino Mega 2560, Teensy 2.0, and Teensy++ 2.0. |
97 changes: 97 additions & 0 deletions
97
vendor/librares/Watchdog/examples/WatchdogTester/WatchdogTester.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// ---------------------------------------------------------------------------- | ||
// WatchdogTester.ino | ||
// | ||
// Authors: | ||
// Peter Polidoro [email protected] | ||
// ---------------------------------------------------------------------------- | ||
|
||
// This sample program shows how to use the watchdog timer. | ||
|
||
// When the device first powers on, it turns the LED off for 1 seconds. It then | ||
// turns the LED on, and pauses for 4 seconds letting you know it is ready to | ||
// start. Watchdog is initialized and the loop starts. It will flash the LED and | ||
// reset watchdog for the first 6 secs. After that, it stops resetting watchdog. | ||
// This causes the watchdog to reboot the device. When the device powers on | ||
// after a watchdog device reset, it blinks the LED twice for 1.5 seconds before | ||
// flashing the LED to let you know the watchdog had been previously tripped. | ||
|
||
#include <Watchdog.h> | ||
|
||
|
||
const unsigned long SETUP_LED_OFF_DURATION = 1000; | ||
const unsigned long SETUP_LED_ON_IF_NOT_TRIPPED_DURATION = 4000; | ||
const unsigned long SETUP_LED_ON_IF_TRIPPED_DURATION = 1500; | ||
const unsigned long TIMEOUT_DURATION = 6000; | ||
const unsigned long BLINK_HALF_PERIOD = 100; | ||
const unsigned long RESET_DURATION = 500; | ||
|
||
Watchdog watchdog; | ||
unsigned long enabled_time; | ||
unsigned long blink_time; | ||
unsigned long reset_time; | ||
|
||
void setLedOff() | ||
{ | ||
digitalWrite(LED_BUILTIN,LOW); | ||
delay(SETUP_LED_OFF_DURATION); | ||
} | ||
|
||
void setLedOn(unsigned long duration) | ||
{ | ||
digitalWrite(LED_BUILTIN,HIGH); | ||
delay(duration); | ||
} | ||
|
||
void toggleLed() | ||
{ | ||
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN)); | ||
} | ||
|
||
void setup() | ||
{ | ||
pinMode(LED_BUILTIN,OUTPUT); | ||
|
||
// Indicate we are starting over by holding led off | ||
setLedOff(); | ||
|
||
// Indicate we are in setup by holding LED on | ||
if (!watchdog.tripped()) | ||
{ | ||
// blink once to indicate power cycle reset | ||
setLedOn(SETUP_LED_ON_IF_NOT_TRIPPED_DURATION); | ||
} | ||
else | ||
{ | ||
// blink twice to indicate watchdog tripped reset | ||
setLedOn(SETUP_LED_ON_IF_TRIPPED_DURATION); | ||
setLedOff(); | ||
setLedOn(SETUP_LED_ON_IF_TRIPPED_DURATION); | ||
} | ||
|
||
// Setup watchdog | ||
watchdog.enable(Watchdog::TIMEOUT_1S); | ||
|
||
enabled_time = millis(); | ||
blink_time = enabled_time; | ||
reset_time = enabled_time; | ||
} | ||
|
||
void loop() | ||
{ | ||
const unsigned long time = millis(); | ||
|
||
// Toggle led | ||
if ((time - blink_time) >= BLINK_HALF_PERIOD) | ||
{ | ||
blink_time = time; | ||
toggleLed(); | ||
} | ||
|
||
// Stop resetting watchdog after timeout | ||
if (((time - enabled_time) <= TIMEOUT_DURATION) && | ||
((time - reset_time) >= RESET_DURATION)) | ||
{ | ||
reset_time = time; | ||
watchdog.reset(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=Watchdog | ||
version=3.0.2 | ||
author=Peter Polidoro <[email protected]>, Antonio Brewer, Steve Sawtelle | ||
maintainer=Peter Polidoro <[email protected]> | ||
sentence=Watchdog resets the device if the timer expires before the watchdog is reset. | ||
paragraph=Like this project? Please star it on GitHub! | ||
category=Device Control | ||
url=https://github.com/janelia-arduino/Watchdog.git | ||
architectures=avr,megaavr,teensy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// ---------------------------------------------------------------------------- | ||
// Watchdog.h | ||
// | ||
// Authors: | ||
// Peter Polidoro [email protected] | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef WATCHDOG_H | ||
#define WATCHDOG_H | ||
|
||
#include <Arduino.h> | ||
|
||
#if defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB1286__) | ||
|
||
#include "Watchdog/WatchdogBaseTeensy2.h" | ||
|
||
#elif defined(__AVR__) && defined(MCUSR) && !defined(__AVR_ATmega32U4__) && !defined(__AVR_AT90USB1286__) | ||
|
||
#include "Watchdog/WatchdogBaseAvr.h" | ||
|
||
#elif defined(__AVR__) && defined(RSTCTRL_RSTFR) | ||
|
||
#include "Watchdog/WatchdogBaseMegaavr.h" | ||
|
||
#elif defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) | ||
|
||
#include "Watchdog/WatchdogBaseTeensy3.h" | ||
|
||
#elif defined(__IMXRT1062__) | ||
|
||
#include "Watchdog/WatchdogBaseTeensy4.h" | ||
|
||
#endif | ||
|
||
|
||
class Watchdog : public WatchdogBase | ||
{ | ||
public: | ||
enum Timeout { | ||
TIMEOUT_15MS=15, | ||
TIMEOUT_30MS=30, | ||
TIMEOUT_60MS=60, | ||
TIMEOUT_120MS=120, | ||
TIMEOUT_250MS=250, | ||
TIMEOUT_500MS=500, | ||
TIMEOUT_1S=1000, | ||
TIMEOUT_2S=2000, | ||
TIMEOUT_4S=4000, | ||
TIMEOUT_8S=8000 | ||
}; | ||
Watchdog(); | ||
void enable(Timeout timeout=TIMEOUT_1S); | ||
bool enabled(); | ||
void reset(); | ||
bool tripped(); | ||
private: | ||
bool enabled_; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// ---------------------------------------------------------------------------- | ||
// Watchdog.cpp | ||
// | ||
// Authors: | ||
// Peter Polidoro [email protected] | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include "../Watchdog.h" | ||
|
||
|
||
Watchdog::Watchdog() | ||
: enabled_{false} | ||
{ | ||
} | ||
|
||
void Watchdog::enable(Timeout timeout) | ||
{ | ||
WatchdogBase::enable(timeout); | ||
enabled_ = true; | ||
} | ||
|
||
bool Watchdog::enabled() | ||
{ | ||
return enabled_; | ||
} | ||
|
||
void Watchdog::reset() | ||
{ | ||
WatchdogBase::reset(); | ||
} | ||
|
||
bool Watchdog::tripped() | ||
{ | ||
return WatchdogBase::tripped(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// ---------------------------------------------------------------------------- | ||
// WatchdogBaseAvr.cpp | ||
// | ||
// Authors: | ||
// Peter Polidoro [email protected] | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include "WatchdogBaseAvr.h" | ||
|
||
#if defined(__AVR__) && defined(MCUSR) && !defined(__AVR_ATmega32U4__) && !defined(__AVR_AT90USB1286__) | ||
|
||
|
||
bool WatchdogBase::tripped() | ||
{ | ||
return ( (MCUSR & (1<<WDRF)) != 0 ); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// ---------------------------------------------------------------------------- | ||
// WatchdogBaseAvr.h | ||
// | ||
// Authors: | ||
// Peter Polidoro [email protected] | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef WATCHDOG_BASE_AVR_H | ||
#define WATCHDOG_BASE_AVR_H | ||
|
||
#include <Arduino.h> | ||
|
||
#if defined(__AVR__) && defined(MCUSR) && !defined(__AVR_ATmega32U4__) && !defined(__AVR_AT90USB1286__) | ||
|
||
#include "WdtAvr.h" | ||
|
||
|
||
class WatchdogBase : public WdtAvr | ||
{ | ||
public: | ||
bool tripped(); | ||
}; | ||
|
||
#endif | ||
#endif |
18 changes: 18 additions & 0 deletions
18
vendor/librares/Watchdog/src/Watchdog/WatchdogBaseMegaavr.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// ---------------------------------------------------------------------------- | ||
// WatchdogBaseMegaavr.cpp | ||
// | ||
// Authors: | ||
// Peter Polidoro [email protected] | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include "WatchdogBaseMegaavr.h" | ||
|
||
#if defined(__AVR__) && defined(RSTCTRL_RSTFR) | ||
|
||
|
||
bool WatchdogBase::tripped() | ||
{ | ||
return ( (RSTCTRL_RSTFR & (1<<RSTCTRL_WDRF_bp)) != 0 ); | ||
} | ||
|
||
#endif |
25 changes: 25 additions & 0 deletions
25
vendor/librares/Watchdog/src/Watchdog/WatchdogBaseMegaavr.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// ---------------------------------------------------------------------------- | ||
// WatchdogBaseMegaavr.h | ||
// | ||
// Authors: | ||
// Peter Polidoro [email protected] | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef WATCHDOG_BASE_MEGAAVR_H | ||
#define WATCHDOG_BASE_MEGAAVR_H | ||
|
||
#include <Arduino.h> | ||
|
||
#if defined(__AVR__) && defined(RSTCTRL_RSTFR) | ||
|
||
#include "WdtAvr.h" | ||
|
||
|
||
class WatchdogBase : public WdtAvr | ||
{ | ||
public: | ||
bool tripped(); | ||
}; | ||
|
||
#endif | ||
#endif |
Oops, something went wrong.