Skip to content

Commit

Permalink
Portenta H7: allow watchdog feed during CAT.M1 connection process
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Nov 27, 2023
1 parent 98a6bdd commit 1b94ef6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
46 changes: 23 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,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) */
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

0 comments on commit 1b94ef6

Please sign in to comment.