Skip to content

Commit 095d454

Browse files
committed
Portenta H7: allow watchdog feed during CAT.M1 connection process
1 parent 98a6bdd commit 095d454

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

Diff for: src/ArduinoIoTCloudTCP.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
233233
*/
234234
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
235235
if (enable_watchdog) {
236+
/* Initialize watchdog hardware */
236237
watchdog_enable();
237-
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
238-
watchdog_enable_network_feed(use_ethernet);
238+
/* Setup callbacks to feed the watchdog during offloaded network operations (connection/download)*/
239+
watchdog_enable_network_feed(_connection->getInterface());
239240
}
240241
#endif
241242

Diff for: src/utility/watchdog/Watchdog.cpp

+25-23
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
# define EDGE_CONTROL_WATCHDOG_MAX_TIMEOUT_ms (65536)
4040
#endif /* ARDUINO_ARCH_MBED */
4141

42-
#include <Arduino_ConnectionHandler.h>
43-
4442
/******************************************************************************
4543
* GLOBAL VARIABLES
4644
******************************************************************************/
@@ -66,24 +64,18 @@ static void samd_watchdog_reset()
6664
}
6765
}
6866

69-
/* This function is called within the WiFiNINA library when invoking
70-
* the method 'connectBearSSL' in order to prevent a premature bite
71-
* of the watchdog (max timeout on SAMD is 16 s). wifi_nina_feed...
67+
/* This function is called within the GSMConnectionHandler. mkr_gsm_feed...
7268
* is defined a weak function there and overwritten by this "strong"
7369
* function here.
7470
*/
75-
#ifndef WIFI_HAS_FEED_WATCHDOG_FUNC
76-
void wifi_nina_feed_watchdog()
77-
{
78-
samd_watchdog_reset();
79-
}
80-
#endif
81-
8271
void mkr_gsm_feed_watchdog()
8372
{
8473
samd_watchdog_reset();
8574
}
86-
75+
/* This function is called within the GSMConnectionHandler. mkr_nb_feed...
76+
* is defined a weak function there and overwritten by this "strong"
77+
* function here.
78+
*/
8779
void mkr_nb_feed_watchdog()
8880
{
8981
samd_watchdog_reset();
@@ -119,18 +111,26 @@ static void mbed_watchdog_reset()
119111
}
120112
}
121113

122-
#if defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
123-
static void mbed_watchdog_enable_network_feed(const bool use_ethernet)
114+
static void mbed_watchdog_enable_network_feed(NetworkAdapter ni)
124115
{
116+
if (ni == NetworkAdapter::ETHERNET) {
125117
#if defined(BOARD_HAS_ETHERNET)
126-
if(use_ethernet) {
127118
Ethernet.setFeedWatchdogFunc(watchdog_reset);
128-
} else
129119
#endif
120+
}
121+
122+
if (ni == NetworkAdapter::WIFI) {
123+
#if defined(ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC) && defined(BOARD_HAS_WIFI)
130124
WiFi.setFeedWatchdogFunc(watchdog_reset);
125+
#endif
126+
}
131127

132-
}
128+
if (ni == NetworkAdapter::CATM1) {
129+
#if defined(BOARD_HAS_CATM1_NBIOT)
130+
GSM.setFeedWatchdogFunc(watchdog_reset);
133131
#endif
132+
}
133+
}
134134

135135
void mbed_watchdog_trigger_reset()
136136
{
@@ -167,15 +167,17 @@ void watchdog_reset()
167167
#endif
168168
}
169169

170-
void watchdog_enable_network_feed(const bool use_ethernet)
170+
void watchdog_enable_network_feed(NetworkAdapter ni)
171171
{
172-
#ifdef WIFI_HAS_FEED_WATCHDOG_FUNC
173-
(void)use_ethernet;
172+
/* Setup WiFi NINA watchdog feed callback function */
173+
#if defined(ARDUINO_ARCH_SAMD) && defined(WIFI_HAS_FEED_WATCHDOG_FUNC)
174+
(void)ni;
174175
WiFi.setFeedWatchdogFunc(watchdog_reset);
175176
#endif
176177

177-
#ifdef ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC
178-
mbed_watchdog_enable_network_feed(use_ethernet);
178+
/* Setup mbed sockets watchdog feed callback function */
179+
#if defined(ARDUINO_ARCH_MBED)
180+
mbed_watchdog_enable_network_feed(ni);
179181
#endif
180182
}
181183
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */

Diff for: src/utility/watchdog/Watchdog.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
#ifndef ARDUINO_AIOTC_UTILITY_WATCHDOG_H_
1919
#define ARDUINO_AIOTC_UTILITY_WATCHDOG_H_
2020

21+
/******************************************************************************
22+
* INCLUDE
23+
******************************************************************************/
24+
25+
#include <Arduino_ConnectionHandler.h>
26+
2127
/******************************************************************************
2228
* FUNCTION DECLARATION
2329
******************************************************************************/
2430

2531
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
2632
void watchdog_enable();
2733
void watchdog_reset();
28-
void watchdog_enable_network_feed(const bool use_ethernet);
34+
void watchdog_enable_network_feed(NetworkAdapter ni);
2935
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */
3036

3137
#ifdef ARDUINO_ARCH_MBED

0 commit comments

Comments
 (0)