-
Notifications
You must be signed in to change notification settings - Fork 39
Add WDT Library #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add WDT Library #242
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2ca5c57
Create keywords.txt
nseidle 9072743
Correct typo in HAL
nseidle ddda09e
Add checking of RTS/CTS pins to enable flow control. Fix typo in _beg…
nseidle 16894c2
Merge pull request #230 from sparkfun/addFlowControl
33bd2d9
Merge pull request #191 from sparkfun/addKeywords
1287ee0
Merge pull request #232 from sparkfun/release-candidate
2cc5ab4
Merge pull request #234 from sparkfun/release-candidate
0af5eb0
Merge pull request #1 from sparkfun/master
stephenf7072 ece522d
Removed code using <time.h> non-core library (ie. Epoch stuff)
stephenf7072 847eb3d
Create Example8_ResetsAndWatchdog.ino
stephenf7072 38d783d
Create WDT.h
adamgarbo d913933
Create WDT.cpp
adamgarbo f8d1fb9
Create library.properties
adamgarbo fd8e357
Create keywords.txt
adamgarbo 57c81bd
Revert "Removed code using <time.h> non-core library (ie. Epoch stuff)"
stephenf7072 66b6e6e
Update WDT.h
adamgarbo 331b8d7
Update WDT.cpp
adamgarbo 453196d
rename example
oclyke 03ae640
rename the actual file
oclyke d9b3290
Merge pull request #241 from stephenf7072/master
e1a7d9b
Add examples
adamgarbo 73a813b
Add WDT configuration
adamgarbo 6bda297
Merge remote-tracking branch 'upstream/master' into wdt
adamgarbo 38a241b
Minor updates
adamgarbo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,39 @@ | ||
####################################### | ||
# Syntax Coloring Map For Wire | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
enableBurstMode KEYWORD2 | ||
disableBurstMode KEYWORD2 | ||
getCpuFreqMHz KEYWORD2 | ||
|
||
getInternalTemp KEYWORD2 | ||
|
||
analogWriteResolution KEYWORD2 | ||
analogWriteFrameWidth KEYWORD2 | ||
analogWriteFrequency KEYWORD2 | ||
servoWrite KEYWORD2 | ||
|
||
enableFastShift KEYWORD2 | ||
fastShiftOut KEYWORD2 | ||
fastShiftIn KEYWORD2 | ||
|
||
secs KEYWORD2 | ||
systicks KEYWORD2 | ||
sysoverflows KEYWORD2 | ||
|
||
####################################### | ||
# Instances (KEYWORD2) | ||
####################################### | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### | ||
|
82 changes: 82 additions & 0 deletions
82
libraries/WDT/examples/Example1_WDT_Basic/Example1_WDT_Basic.ino
This file contains hidden or 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,82 @@ | ||
/* | ||
Author: Adam Garbo | ||
Created: August 1st, 2020 | ||
License: MIT. See SparkFun Arduino Apollo3 Project for more information | ||
|
||
This example demonstrates a simple configuration of the Artemis Watchdog Timer. | ||
|
||
The code will configure the watchdog for both interrupt and reset generation, | ||
and immediately start the watchdog timer. | ||
|
||
The watchdog ISR provided will 'pet' the watchdog four times. On the fifth | ||
interrupt, the watchdog will not be pet, so the 'reset' action can occur. | ||
On the sixth timeout event, the WDT will issue a system reset, and the | ||
program will start over from the beginning. | ||
|
||
The watchdogCounter will show the number of ticks before the watchdog | ||
reset occurs. | ||
|
||
This example is based on the Ambiq SDK 2.4.2 watchdog.c example. | ||
|
||
Tested with SparkFun Artemis Redboard. | ||
*/ | ||
|
||
#include <WDT.h> | ||
|
||
APM3_WDT wdt; | ||
|
||
volatile bool watchdogFlag = false; // Watchdog Timer ISR flag | ||
volatile int watchdogInterrupt = 0; // Watchdog interrupt counter | ||
unsigned long currentMillis = 0, | ||
previousMillis = 0; | ||
|
||
void setup() { | ||
|
||
Serial.begin(115200); | ||
|
||
Serial.println("Artemis Watchdog Timer Example"); | ||
|
||
// Start the watchdog | ||
wdt.start(); | ||
} | ||
|
||
void loop() | ||
{ | ||
// Check for watchdog interrupts | ||
if (watchdogFlag) | ||
{ | ||
// Calculate duration between watchdog interrupts | ||
currentMillis = millis() - previousMillis; | ||
previousMillis = millis(); | ||
|
||
Serial.print("Interrupt: "); Serial.print(watchdogInterrupt); | ||
Serial.print(" Period: "); Serial.print(currentMillis); Serial.println(" ms "); | ||
|
||
if (watchdogInterrupt == 5) | ||
{ | ||
Serial.println("Warning: Watchdog has triggered a system reset"); | ||
} | ||
} | ||
|
||
watchdogFlag = false; // Clear watchdog flag | ||
delay(1); | ||
} | ||
|
||
// Interrupt handler for the watchdog | ||
extern "C" void am_watchdog_isr(void) | ||
{ | ||
// Clear the watchdog interrupt | ||
wdt.clear(); | ||
|
||
// Catch the first four watchdog interrupts, but let the fifth through untouched | ||
if ( watchdogInterrupt < 4 ) | ||
{ | ||
wdt.restart(); // "Pet" the dog | ||
} | ||
else { | ||
digitalWrite(LED_BUILTIN, HIGH); // Visual indication of system reset trigger | ||
} | ||
|
||
watchdogFlag = true; // Set watchdog flag | ||
watchdogInterrupt++; // Increment watchdog interrupt counter | ||
} |
103 changes: 103 additions & 0 deletions
103
libraries/WDT/examples/Example2_WDT_Config/Example2_WDT_Config.ino
This file contains hidden or 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,103 @@ | ||
/* | ||
Author: Adam Garbo | ||
Created: August 1st, 2020 | ||
License: MIT. See SparkFun Arduino Apollo3 Project for more information | ||
|
||
This example demonstrates how to modify the configuration of the Artemis | ||
Watchdog Timer (WDT). | ||
|
||
The watchdog timer is controlled by a clock divider, interrupt ticks and | ||
reset ticks. To achieve desired watchdog timing, a simple calculation can be made: | ||
|
||
period = # ticks / clock divider frequency | ||
|
||
Examples: | ||
128 interrupt ticks / 128 Hz clock = 1 second | ||
64 interrupt ticks / 16 Hz clock = 4 seconds | ||
32 interrupt ticks / 1 Hz clock = 32 seconds | ||
16 interrupt ticks / 1/16 Hz clock = 256 seconds | ||
|
||
The following code will configure the watchdog for both interrupt and reset | ||
generation, and immediately start the watchdog timer. | ||
The watchdog ISR provided will 'pet' the watchdog four times. On the fifth | ||
interrupt, the watchdog will not be pet, so the 'reset' action can occur. | ||
On the sixth timeout event, the WDT will issue a system reset, and the | ||
program will start over from the beginning. | ||
|
||
This example is based on the Ambiq SDK 2.4.2 watchdog.c example. | ||
|
||
Tested with SparkFun Artemis Redboard. | ||
*/ | ||
|
||
#include <WDT.h> | ||
|
||
APM3_WDT wdt; | ||
|
||
volatile bool watchdogFlag = false; // Watchdog Timer ISR flag | ||
volatile int watchdogInterrupt = 0; // Watchdog interrupt counter | ||
|
||
unsigned long currentMillis = 0, | ||
previousMillis = 0; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
Serial.println("Artemis Watchdog Timer Example"); | ||
|
||
// Configure the watchdog | ||
/* | ||
Available watchdog timer clock dividers: | ||
0 = Low Power Mode. This setting disables the watch dog timer | ||
adamgarbo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1 = 128 Hz | ||
2 = 16 Hz | ||
3 = 1 Hz | ||
4 = 1/16th Hz | ||
*/ | ||
// Set watchdog timer clock to 128 Hz | ||
// Set watchdog interrupt to 1 seconds (128 ticks / 128 Hz = 1 second) | ||
// Set watchdog reset ~2 seconds (255 ticks / 128 Hz = 1.99 seconds) | ||
wdt.configure(1, 128, 255); // Note: Ticks are limited to 255 (8-bit) | ||
adamgarbo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wdt.start(); // Start the watchdog | ||
} | ||
|
||
void loop() | ||
{ | ||
// Check for watchdog interrupts | ||
if (watchdogFlag) | ||
{ | ||
// Calculate duration between watchdog interrupts | ||
currentMillis = millis() - previousMillis; | ||
previousMillis = millis(); | ||
|
||
Serial.print("Interrupt: "); Serial.print(watchdogInterrupt); | ||
Serial.print(" Period: "); Serial.print(currentMillis); Serial.println(" ms"); | ||
|
||
// The watchdog configurations can also be set individually | ||
wdt.setClock(2); // Set watchdog timer clock to 16 Hz | ||
adamgarbo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wdt.setInterrupt(64); // Set watchdog interrupt to 4 second (64 ticks / 16 Hz = 4 seconds) | ||
wdt.setReset(96); // Set watchdog reset to 8 seconds (96 ticks / 16 Hz = 8 seconds) | ||
} | ||
watchdogFlag = false; // Clear watchdog flag | ||
delay(1); | ||
} | ||
|
||
// Interrupt handler for the watchdog | ||
extern "C" void am_watchdog_isr(void) | ||
{ | ||
// Clear the watchdog interrupt | ||
wdt.clear(); | ||
|
||
// Catch the first eight watchdog interrupts, but let the ninth through untouched | ||
if ( watchdogInterrupt < 8 ) | ||
{ | ||
wdt.restart(); // "Pet" the dog | ||
} | ||
else | ||
{ | ||
digitalWrite(LED_BUILTIN, HIGH); // Visual indication of system reset trigger | ||
} | ||
|
||
watchdogFlag = true; // Set watchdog flag | ||
watchdogInterrupt++; // Increment watchdog interrupt counter | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.