Skip to content

Portenta H7 Watchdog: allow watchdog feeding using CATM1 #397

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 1 commit into from
Feb 19, 2024
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
5 changes: 3 additions & 2 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
*/
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
if (enable_watchdog) {
/* Initialize watchdog hardware */
watchdog_enable();
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
watchdog_enable_network_feed(use_ethernet);
/* Setup callbacks to feed the watchdog during offloaded network operations (connection/download)*/
watchdog_enable_network_feed(_connection->getInterface());
}
#endif

Expand Down
48 changes: 25 additions & 23 deletions src/utility/watchdog/Watchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
# define EDGE_CONTROL_WATCHDOG_MAX_TIMEOUT_ms (65536)
#endif /* ARDUINO_ARCH_MBED */

#include <Arduino_ConnectionHandler.h>

/******************************************************************************
* GLOBAL VARIABLES
******************************************************************************/
Expand All @@ -66,24 +64,18 @@ static void samd_watchdog_reset()
}
}

/* This function is called within the WiFiNINA library when invoking
* the method 'connectBearSSL' in order to prevent a premature bite
* of the watchdog (max timeout on SAMD is 16 s). wifi_nina_feed...
/* This function is called within the GSMConnectionHandler. mkr_gsm_feed...
* is defined a weak function there and overwritten by this "strong"
* function here.
*/
#ifndef WIFI_HAS_FEED_WATCHDOG_FUNC
void wifi_nina_feed_watchdog()
{
samd_watchdog_reset();
}
#endif

void mkr_gsm_feed_watchdog()
{
samd_watchdog_reset();
}

/* This function is called within the GSMConnectionHandler. mkr_nb_feed...
* is defined a weak function there and overwritten by this "strong"
* function here.
*/
void mkr_nb_feed_watchdog()
{
samd_watchdog_reset();
Expand Down Expand Up @@ -119,18 +111,26 @@ static void mbed_watchdog_reset()
}
}

#if defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
static void mbed_watchdog_enable_network_feed(const bool use_ethernet)
static void mbed_watchdog_enable_network_feed(NetworkAdapter ni)
{
if (ni == NetworkAdapter::ETHERNET) {
#if defined(BOARD_HAS_ETHERNET)
if(use_ethernet) {
Ethernet.setFeedWatchdogFunc(watchdog_reset);
} else
#endif
}

if (ni == NetworkAdapter::WIFI) {
#if defined(ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC) && defined(BOARD_HAS_WIFI)
WiFi.setFeedWatchdogFunc(watchdog_reset);
#endif
}

}
if (ni == NetworkAdapter::CATM1) {
#if defined(BOARD_HAS_CATM1_NBIOT)
GSM.setFeedWatchdogFunc(watchdog_reset);
#endif
}
}

void mbed_watchdog_trigger_reset()
{
Expand Down Expand Up @@ -167,15 +167,17 @@ void watchdog_reset()
#endif
}

void watchdog_enable_network_feed(const bool use_ethernet)
void watchdog_enable_network_feed(NetworkAdapter ni)
{
#ifdef WIFI_HAS_FEED_WATCHDOG_FUNC
(void)use_ethernet;
/* Setup WiFi NINA watchdog feed callback function */
#if defined(ARDUINO_ARCH_SAMD) && defined(WIFI_HAS_FEED_WATCHDOG_FUNC)
(void)ni;
WiFi.setFeedWatchdogFunc(watchdog_reset);
#endif

#ifdef ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC
mbed_watchdog_enable_network_feed(use_ethernet);
/* Setup mbed sockets watchdog feed callback function */
#if defined(ARDUINO_ARCH_MBED)
mbed_watchdog_enable_network_feed(ni);
#endif
}
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */
8 changes: 7 additions & 1 deletion src/utility/watchdog/Watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
#ifndef ARDUINO_AIOTC_UTILITY_WATCHDOG_H_
#define ARDUINO_AIOTC_UTILITY_WATCHDOG_H_

/******************************************************************************
* INCLUDE
******************************************************************************/

#include <Arduino_ConnectionHandler.h>

/******************************************************************************
* FUNCTION DECLARATION
******************************************************************************/

#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
void watchdog_enable();
void watchdog_reset();
void watchdog_enable_network_feed(const bool use_ethernet);
void watchdog_enable_network_feed(NetworkAdapter ni);
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */

#ifdef ARDUINO_ARCH_MBED
Expand Down