Skip to content

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
merged 9 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/api/drivers/ResetReason.md
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

[![View code](https://www.mbed.com/embed/?type=library)](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());
}
```
50 changes: 45 additions & 5 deletions docs/api/drivers/Watchdog.md
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

[![View code](https://www.mbed.com/embed/?type=library)](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);
}
}
```