Skip to content

Commit

Permalink
Merge pull request #472 from pennam/wdg-mbed
Browse files Browse the repository at this point in the history
Watchdog: use mbed API
  • Loading branch information
pennam authored Jun 4, 2024
2 parents 00a6466 + 03b69d3 commit d4ae0a3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
2 changes: 0 additions & 2 deletions src/ota/implementation/OTANanoRP2040.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ OTACloudProcessInterface::State NANO_RP2040OTACloudProcess::flashOTA() {
}

OTACloudProcessInterface::State NANO_RP2040OTACloudProcess::reboot() {
mbed_watchdog_trigger_reset();
/* If watchdog is enabled we should not reach this point */
NVIC_SystemReset();

return Resume; // This won't ever be reached
Expand Down
28 changes: 5 additions & 23 deletions src/utility/watchdog/Watchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#endif /* ARDUINO_ARCH_SAMD */

#ifdef ARDUINO_ARCH_MBED
# include <watchdog_api.h>
# include <drivers/Watchdog.h>
# define PORTENTA_H7_WATCHDOG_MAX_TIMEOUT_ms (32760)
# define NANO_RP2040_WATCHDOG_MAX_TIMEOUT_ms (8389)
# define EDGE_CONTROL_WATCHDOG_MAX_TIMEOUT_ms (65536)
Expand All @@ -42,7 +42,7 @@
/******************************************************************************
* GLOBAL VARIABLES
******************************************************************************/
#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_MBED)
#if defined(ARDUINO_ARCH_SAMD)
static bool is_watchdog_enabled = false;
#endif

Expand Down Expand Up @@ -96,18 +96,15 @@ static void mbed_watchdog_enable()
# error "You need to define the maximum possible timeout for this architecture."
#endif

if (hal_watchdog_init(&cfg) == WATCHDOG_STATUS_OK) {
is_watchdog_enabled = true;
}
else {
if (!mbed::Watchdog::get_instance().start(cfg.timeout_ms)) {
DEBUG_WARNING("%s: watchdog could not be enabled", __FUNCTION__);
}
}

static void mbed_watchdog_reset()
{
if (is_watchdog_enabled) {
hal_watchdog_kick();
if (mbed::Watchdog::get_instance().is_running()) {
mbed::Watchdog::get_instance().kick();
}
}

Expand All @@ -131,21 +128,6 @@ static void mbed_watchdog_enable_network_feed(NetworkAdapter ni)
#endif
}
}

void mbed_watchdog_trigger_reset()
{
watchdog_config_t cfg;
cfg.timeout_ms = 1;

if (hal_watchdog_init(&cfg) == WATCHDOG_STATUS_OK) {
is_watchdog_enabled = true;
while(1){}
}
else {
DEBUG_WARNING("%s: watchdog could not be reconfigured", __FUNCTION__);
}

}
#endif /* ARDUINO_ARCH_MBED */

#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
Expand Down
4 changes: 0 additions & 4 deletions src/utility/watchdog/Watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,4 @@ void watchdog_reset();
void watchdog_enable_network_feed(NetworkAdapter ni);
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */

#ifdef ARDUINO_ARCH_MBED
void mbed_watchdog_trigger_reset();
#endif /* ARDUINO_ARCH_MBED */

#endif /* ARDUINO_AIOTC_UTILITY_WATCHDOG_H_ */

0 comments on commit d4ae0a3

Please sign in to comment.