From 086326efa4859a2c3e5aaf8f21a57800acfc8808 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 27 Nov 2023 15:10:38 +0100 Subject: [PATCH] Portenta H7: allow watchdog feed during CAT.M1 connection process --- src/ArduinoIoTCloudTCP.cpp | 6 ++-- src/utility/watchdog/Watchdog.cpp | 46 +++++++++++++++---------------- src/utility/watchdog/Watchdog.h | 8 +++++- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 9e018d60..c0e4a5c6 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -233,9 +233,11 @@ 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)*/ + Serial.println(" TCP:watchdog_enable_network_feed"); + watchdog_enable_network_feed(_connection->getInterface()); } #endif diff --git a/src/utility/watchdog/Watchdog.cpp b/src/utility/watchdog/Watchdog.cpp index aeb27abd..1a32fdef 100644 --- a/src/utility/watchdog/Watchdog.cpp +++ b/src/utility/watchdog/Watchdog.cpp @@ -39,8 +39,6 @@ # define EDGE_CONTROL_WATCHDOG_MAX_TIMEOUT_ms (65536) #endif /* ARDUINO_ARCH_MBED */ -#include - /****************************************************************************** * GLOBAL VARIABLES ******************************************************************************/ @@ -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(); @@ -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() { @@ -167,15 +167,15 @@ void watchdog_reset() #endif } -void watchdog_enable_network_feed(const bool use_ethernet) +void watchdog_enable_network_feed(NetworkAdapter ni) { + /* Setup WiFi NINA watchdog feed callback function */ #ifdef WIFI_HAS_FEED_WATCHDOG_FUNC - (void)use_ethernet; + (void)ni; WiFi.setFeedWatchdogFunc(watchdog_reset); #endif -#ifdef ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC - mbed_watchdog_enable_network_feed(use_ethernet); -#endif + /* Setup mbed sockets watchdog feed callback function */ + mbed_watchdog_enable_network_feed(ni); } #endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */ diff --git a/src/utility/watchdog/Watchdog.h b/src/utility/watchdog/Watchdog.h index dbaf2abd..3bfd3545 100644 --- a/src/utility/watchdog/Watchdog.h +++ b/src/utility/watchdog/Watchdog.h @@ -18,6 +18,12 @@ #ifndef ARDUINO_AIOTC_UTILITY_WATCHDOG_H_ #define ARDUINO_AIOTC_UTILITY_WATCHDOG_H_ +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + /****************************************************************************** * FUNCTION DECLARATION ******************************************************************************/ @@ -25,7 +31,7 @@ #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