Skip to content

Commit 66b2e47

Browse files
committed
Replace compile-time configuration of watchdog (compiled in/out) with parameter in 'begin' function.
The watchdog is now always compiled in, but can be disabled when setting the parameter 'enable_watchdog' too false. The parameter is set to true by default.
1 parent 2ce0578 commit 66b2e47

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

src/AIoTC_Config.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@
8787
* AUTOMATICALLY CONFIGURED DEFINES
8888
******************************************************************************/
8989

90-
#ifdef ARDUINO_ARCH_SAMD
91-
# define WATCHDOG_ENABLED (1)
92-
#else
93-
# define WATCHDOG_ENABLED (0)
94-
#endif
95-
9690
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \
9791
defined(ARDUINO_AVR_UNO_WIFI_REV2)
9892
#define OTA_STORAGE_SNU (1)

src/ArduinoIoTCloudTCP.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
104104
* PUBLIC MEMBER FUNCTIONS
105105
******************************************************************************/
106106

107-
int ArduinoIoTCloudTCP::begin(ConnectionHandler & connection, String brokerAddress, uint16_t brokerPort)
107+
int ArduinoIoTCloudTCP::begin(ConnectionHandler & connection, bool const enable_watchdog, String brokerAddress, uint16_t brokerPort)
108108
{
109109
_connection = &connection;
110110
_brokerAddress = brokerAddress;
111111
_brokerPort = brokerPort;
112112
_time_service.begin(&connection);
113-
return begin(_brokerAddress, _brokerPort);
113+
return begin(enable_watchdog, _brokerAddress, _brokerPort);
114114
}
115115

116-
int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
116+
int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress, uint16_t brokerPort)
117117
{
118118
_brokerAddress = brokerAddress;
119119
_brokerPort = brokerPort;
@@ -275,7 +275,9 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort)
275275
* call to ArduinoIoTCloudTCP::update() it is wise to
276276
* set a rather large timeout at first.
277277
*/
278-
Watchdog.enable(SAMD_WATCHDOG_MAX_TIME_ms);
278+
if (enable_watchdog) {
279+
samd_watchdog_enable();
280+
}
279281
#endif /* ARDUINO_ARCH_SAMD */
280282

281283
return 1;
@@ -287,7 +289,7 @@ void ArduinoIoTCloudTCP::update()
287289
/* Feed the watchdog. If any of the functions called below
288290
* get stuck than we can at least reset and recover.
289291
*/
290-
Watchdog.reset();
292+
samd_watchdog_reset();
291293
#endif /* ARDUINO_ARCH_SAMD */
292294

293295
/* Run through the state machine. */
@@ -546,7 +548,7 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
546548
void ArduinoIoTCloudTCP::onOTARequest()
547549
{
548550
#ifdef ARDUINO_ARCH_SAMD
549-
Watchdog.reset();
551+
samd_watchdog_reset();
550552
#endif /* ARDUINO_ARCH_SAMD */
551553

552554
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s _ota_url = %s", __FUNCTION__, _ota_url.c_str());
@@ -557,7 +559,7 @@ void ArduinoIoTCloudTCP::onOTARequest()
557559
WiFiStorage.remove("/fs/UPDATE.BIN.LZSS.TMP");
558560

559561
#ifdef ARDUINO_ARCH_SAMD
560-
Watchdog.reset();
562+
samd_watchdog_reset();
561563
#endif /* ARDUINO_ARCH_SAMD */
562564

563565
/* Trigger direct download to nina module. */

src/ArduinoIoTCloudTCP.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
6666
virtual void printDebugInfo() override;
6767

6868
#if defined(BOARD_HAS_ECCX08) || defined(BOARD_HAS_OFFLOADED_ECCX08)
69-
int begin(ConnectionHandler & connection, String brokerAddress = DEFAULT_BROKER_ADDRESS_SECURE_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_SECURE_AUTH);
69+
int begin(ConnectionHandler & connection, bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS_SECURE_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_SECURE_AUTH);
7070
#else
71-
int begin(ConnectionHandler & connection, String brokerAddress = DEFAULT_BROKER_ADDRESS_USER_PASS_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_USER_PASS_AUTH);
71+
int begin(ConnectionHandler & connection, bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS_USER_PASS_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_USER_PASS_AUTH);
7272
#endif
73-
int begin(String brokerAddress = DEFAULT_BROKER_ADDRESS_SECURE_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_SECURE_AUTH);
73+
int begin(bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS_SECURE_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_SECURE_AUTH);
7474

7575
#ifdef BOARD_ESP
7676
inline void setBoardId (String const device_id) { setDeviceId(device_id); }

src/utility/watchdog/Watchdog.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,30 @@
2121

2222
#include "Watchdog.h"
2323

24+
/******************************************************************************
25+
* GLOBAL VARIABLES
26+
******************************************************************************/
27+
28+
static bool is_watchdog_enabled = false;
29+
2430
/******************************************************************************
2531
* FUNCTION DEFINITION
2632
******************************************************************************/
2733

28-
#if WATCHDOG_ENABLED
29-
# ifdef ARDUINO_ARCH_SAMD
34+
#ifdef ARDUINO_ARCH_SAMD
35+
void samd_watchdog_enable()
36+
{
37+
is_watchdog_enabled = true;
38+
Watchdog.enable(SAMD_WATCHDOG_MAX_TIME_ms);
39+
}
40+
41+
void samd_watchdog_reset()
42+
{
43+
if (is_watchdog_enabled) {
44+
Watchdog.reset();
45+
}
46+
}
47+
3048
/* This function is called within the WiFiNINA library when invoking
3149
* the method 'connectBearSSL' in order to prevent a premature bite
3250
* of the watchdog (max timeout on SAMD is 16 s). wifi_nina_feed...
@@ -35,7 +53,6 @@
3553
*/
3654
void wifi_nina_feed_watchdog()
3755
{
38-
Watchdog.reset();
56+
samd_watchdog_reset();
3957
}
40-
# endif /* ARDUINO_ARCH_SAMD */
41-
#endif /* WATCHDOG_ENABLED */
58+
#endif /* ARDUINO_ARCH_SAMD */

src/utility/watchdog/Watchdog.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@
2424

2525
#include <AIoTC_Config.h>
2626

27-
#if WATCHDOG_ENABLED
28-
# ifdef ARDUINO_ARCH_SAMD
29-
# include <Adafruit_SleepyDog.h>
30-
# define SAMD_WATCHDOG_MAX_TIME_ms (16 * 1000)
31-
# endif /* ARDUINO_ARCH_SAMD */
32-
#endif /* WATCHDOG_ENABLED */
27+
/******************************************************************************
28+
* PREPROCESSOR SECTION
29+
******************************************************************************/
30+
31+
#ifdef ARDUINO_ARCH_SAMD
32+
# include <Adafruit_SleepyDog.h>
33+
# define SAMD_WATCHDOG_MAX_TIME_ms (16 * 1000)
34+
#endif /* ARDUINO_ARCH_SAMD */
35+
36+
/******************************************************************************
37+
* FUNCTION DECLARATION
38+
******************************************************************************/
39+
40+
#ifdef ARDUINO_ARCH_SAMD
41+
void samd_watchdog_enable();
42+
void samd_watchdog_reset();
43+
#endif /* ARDUINO_ARCH_SAMD */
3344

3445
#endif /* ARDUINO_AIOTC_UTILITY_WATCHDOG_H_ */

0 commit comments

Comments
 (0)