-
Notifications
You must be signed in to change notification settings - Fork 178
Add ResetReason and Watchdog driver docs #1099
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
AnotherButler
merged 9 commits into
ARMmbed:development
from
fkjagodzinski:docs_update-watchdog
Jul 11, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4094e0
Add Watchdog driver docs
fkjagodzinski 0b57150
Add ResetReason driver docs
fkjagodzinski 5f7929f
Fix example code astyle for the ResetReason
fkjagodzinski 5b4be96
Address review comments on Watchdog & ResetReason
fkjagodzinski 9968db4
Edit ResetReason.md
bd14c80
Edit Watchdog.md
62a296c
Fix link in Watchdog.md
fb305da
Add link to ResetReason.md
e483f76
Replace API link in ResetReason.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
## ResetReason | ||
|
||
When the system restarts, the system registers contain the reason for the restart at boot time in a platform specific manner. This API provides a generic method of fetching the reason for the restart. | ||
|
||
You can use the ResetReason interface to determine the cause of the last system reset in a portable fashion. | ||
|
||
### ResetReason class reference | ||
|
||
[](https://os.mbed.com/docs/mbed-os/development/mbed-os-api-doxy/classmbed_1_1_reset_reason.html) | ||
|
||
### ResetReason example | ||
|
||
Check the cause of the last system reset: | ||
|
||
```c++ | ||
#include "mbed.h" | ||
#include "ResetReason.h" | ||
|
||
#include <string> | ||
|
||
std::string reset_reason_to_string(const reset_reason_t reason) | ||
{ | ||
switch (reason) { | ||
case RESET_REASON_POWER_ON: | ||
return "Power On"; | ||
case RESET_REASON_PIN_RESET: | ||
return "Hardware Pin"; | ||
case RESET_REASON_SOFTWARE: | ||
return "Software Reset"; | ||
case RESET_REASON_WATCHDOG: | ||
return "Watchdog"; | ||
default: | ||
return "Other Reason"; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
const reset_reason_t reason = ResetReason::get(); | ||
|
||
printf("Last system reset reason: %s\r\n", reset_reason_to_string(reason).c_str()); | ||
} | ||
``` |
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 |
---|---|---|
@@ -1,11 +1,51 @@ | ||
# Watchdog | ||
|
||
[Add description here.] | ||
You can use the Watchdog interface to set up a hardware watchdog timer that resets the system in the case of system failures or malfunctions. | ||
|
||
## Watchdog class reference | ||
<span class="notes">**Note:** There is only one instance in the system. Use `Watchdog::get_instance()` to obtain a reference. </span> | ||
|
||
[Add class reference here. Ask your editor for help if you've never done this before.] | ||
If you fail to refresh the watchdog periodically, it resets the system after a set period of time. | ||
|
||
## Watchdog example | ||
<span class="notes">**Note:** The maximum amount of time you can set as the Watchdog timeout varies depending on the target hardware. You can check the maximum value by calling `Watchdog::get_instance().get_max_timeout()`.</span> | ||
|
||
[Add example here.] | ||
### Watchdog class reference | ||
|
||
[](https://os.mbed.com/docs/mbed-os/development/mbed-os-api-doxy/classmbed_1_1_watchdog.html) | ||
|
||
### Watchdog example | ||
|
||
This example creates a watchdog timer that expires after five seconds and that you can refresh by pushing BUTTON1 on the target board: | ||
|
||
```c++ | ||
#include "mbed.h" | ||
|
||
const uint32_t TIMEOUT_MS = 5000; | ||
InterruptIn button(BUTTON1); | ||
volatile int countdown = 9; | ||
|
||
void trigger() | ||
{ | ||
Watchdog::get_instance().kick(); | ||
countdown = 9; | ||
} | ||
|
||
int main() | ||
{ | ||
printf("\r\nTarget started.\r\n"); | ||
|
||
Watchdog &watchdog = Watchdog::get_instance(); | ||
watchdog.start(TIMEOUT_MS); | ||
button.rise(&trigger); | ||
|
||
uint32_t watchdog_timeout = watchdog.get_timeout(); | ||
printf("Watchdog initialized to %lu ms.\r\n", watchdog_timeout); | ||
printf("Press BUTTON1 at least once every %lu ms to kick the " | ||
"watchdog and prevent system reset.\r\n", watchdog_timeout); | ||
|
||
while (1) { | ||
printf("\r%3i", countdown--); | ||
fflush(stdout); | ||
wait(TIMEOUT_MS / 1000.0 / 10); | ||
} | ||
} | ||
``` |
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.