Skip to content

Commit 6a10215

Browse files
committed
Watchdog: Enable feed function for Ethernet
The implementation is done as for WiFi so we can reuse the same define ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC Move watchdog network feed configuration into Watchdog module
1 parent 1191d85 commit 6a10215

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/ArduinoIoTCloudTCP.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
308308
if (enable_watchdog) {
309309
watchdog_enable();
310310
#if defined (WIFI_HAS_FEED_WATCHDOG_FUNC) || defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
311-
WiFi.setFeedWatchdogFunc(watchdog_reset);
311+
bool const use_ethernet = _connection->getInterface() == NetworkAdapter::ETHERNET ? true : false;
312+
watchdog_enable_network_feed(use_ethernet);
312313
#endif
313314
}
314315
#endif

src/utility/watchdog/Watchdog.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@
2929

3030
#ifdef ARDUINO_ARCH_SAMD
3131
# include <Adafruit_SleepyDog.h>
32+
# include <WiFi.h>
3233
# define SAMD_WATCHDOG_MAX_TIME_ms (16 * 1000)
3334
#endif /* ARDUINO_ARCH_SAMD */
3435

3536
#ifdef ARDUINO_ARCH_MBED
3637
# include <watchdog_api.h>
38+
# include <WiFi.h>
39+
# include <Ethernet.h>
3740
# define PORTENTA_H7_WATCHDOG_MAX_TIMEOUT_ms (32760)
3841
# define NANO_RP2040_WATCHDOG_MAX_TIMEOUT_ms (8389)
3942
#endif /* ARDUINO_ARCH_MBED */
@@ -63,6 +66,11 @@ static void samd_watchdog_reset()
6366
}
6467
}
6568

69+
static void samd_watchdog_enable_network_feed()
70+
{
71+
WiFi.setFeedWatchdogFunc(watchdog_reset);
72+
}
73+
6674
/* This function is called within the WiFiNINA library when invoking
6775
* the method 'connectBearSSL' in order to prevent a premature bite
6876
* of the watchdog (max timeout on SAMD is 16 s). wifi_nina_feed...
@@ -114,6 +122,17 @@ static void mbed_watchdog_reset()
114122
}
115123
}
116124

125+
static void mbed_watchdog_enable_network_feed(bool use_ethernet)
126+
{
127+
if(use_ethernet) {
128+
#if defined(ARDUINO_PORTENTA_H7_M7)
129+
Ethernet.setFeedWatchdogFunc(watchdog_reset);
130+
#endif
131+
} else {
132+
WiFi.setFeedWatchdogFunc(watchdog_reset);
133+
}
134+
}
135+
117136
void mbed_watchdog_trigger_reset()
118137
{
119138
watchdog_config_t cfg;
@@ -154,4 +173,13 @@ void watchdog_reset()
154173
mbed_watchdog_reset();
155174
#endif
156175
}
176+
177+
void watchdog_enable_network_feed(bool use_ethernet)
178+
{
179+
#ifdef ARDUINO_ARCH_SAMD
180+
samd_watchdog_enable_network_feed();
181+
#else
182+
mbed_watchdog_enable_network_feed(use_ethernet);
183+
#endif
184+
}
157185
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */

src/utility/watchdog/Watchdog.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED)
2626
void watchdog_enable();
2727
void watchdog_reset();
28+
void watchdog_enable_network_feed(bool use_ethernet);
2829
#endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */
2930

3031
#ifdef ARDUINO_ARCH_MBED

0 commit comments

Comments
 (0)