Skip to content

Commit 2e6c4f1

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 7eafb41 commit 2e6c4f1

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-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

+34
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,13 @@ static void samd_watchdog_reset()
6366
}
6467
}
6568

69+
#if defined (WIFI_HAS_FEED_WATCHDOG_FUNC)
70+
static void samd_watchdog_enable_network_feed()
71+
{
72+
WiFi.setFeedWatchdogFunc(watchdog_reset);
73+
}
74+
#endif
75+
6676
/* This function is called within the WiFiNINA library when invoking
6777
* the method 'connectBearSSL' in order to prevent a premature bite
6878
* of the watchdog (max timeout on SAMD is 16 s). wifi_nina_feed...
@@ -114,6 +124,19 @@ static void mbed_watchdog_reset()
114124
}
115125
}
116126

127+
#if defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
128+
static void mbed_watchdog_enable_network_feed(const bool use_ethernet)
129+
{
130+
if(use_ethernet) {
131+
#if defined(ARDUINO_PORTENTA_H7_M7)
132+
Ethernet.setFeedWatchdogFunc(watchdog_reset);
133+
#endif
134+
} else {
135+
WiFi.setFeedWatchdogFunc(watchdog_reset);
136+
}
137+
}
138+
#endif
139+
117140
void mbed_watchdog_trigger_reset()
118141
{
119142
watchdog_config_t cfg;
@@ -154,4 +177,15 @@ void watchdog_reset()
154177
mbed_watchdog_reset();
155178
#endif
156179
}
180+
181+
#if defined (WIFI_HAS_FEED_WATCHDOG_FUNC) || defined (ARDUINO_PORTENTA_H7_WIFI_HAS_FEED_WATCHDOG_FUNC)
182+
void watchdog_enable_network_feed(const bool use_ethernet)
183+
{
184+
#ifdef ARDUINO_ARCH_SAMD
185+
samd_watchdog_enable_network_feed();
186+
#else
187+
mbed_watchdog_enable_network_feed(use_ethernet);
188+
#endif
189+
}
190+
#endif
157191
#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)