Skip to content

Provide clean API for passing watchdog function. #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern "C" {
#include "utility/debug.h"
}

WiFiClass::WiFiClass() : _timeout(50000)
WiFiClass::WiFiClass() : _timeout(50000), _feed_watchdog_func(0)
{
}

Expand All @@ -49,6 +49,7 @@ int WiFiClass::begin(const char* ssid)
{
for (unsigned long start = millis(); (millis() - start) < _timeout;)
{
feedWatchdog();
delay(WL_DELAY_START_CONNECTION);
status = WiFiDrv::getConnectionStatus();
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
Expand All @@ -71,6 +72,7 @@ int WiFiClass::begin(const char* ssid, uint8_t key_idx, const char *key)
{
for (unsigned long start = millis(); (millis() - start) < _timeout;)
{
feedWatchdog();
delay(WL_DELAY_START_CONNECTION);
status = WiFiDrv::getConnectionStatus();
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
Expand All @@ -92,6 +94,7 @@ int WiFiClass::begin(const char* ssid, const char *passphrase)
{
for (unsigned long start = millis(); (millis() - start) < _timeout;)
{
feedWatchdog();
delay(WL_DELAY_START_CONNECTION);
status = WiFiDrv::getConnectionStatus();
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
Expand Down Expand Up @@ -382,4 +385,16 @@ void WiFiClass::setTimeout(unsigned long timeout)
{
_timeout = timeout;
}

void WiFiClass::setFeedWatchdogFunc(FeedHostProcessorWatchdogFuncPointer func)
{
_feed_watchdog_func = func;
}

void WiFiClass::feedWatchdog()
{
if (_feed_watchdog_func)
_feed_watchdog_func();
}

WiFiClass WiFi;
6 changes: 6 additions & 0 deletions src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ extern "C" {
#include "WiFiServer.h"
#include "WiFiStorage.h"

typedef void(*FeedHostProcessorWatchdogFuncPointer)();

class WiFiClass
{
private:

static void init();
unsigned long _timeout;
FeedHostProcessorWatchdogFuncPointer _feed_watchdog_func;
public:
WiFiClass();

Expand Down Expand Up @@ -274,6 +277,9 @@ class WiFiClass
int ping(IPAddress host, uint8_t ttl = 128);

void setTimeout(unsigned long timeout);

void setFeedWatchdogFunc(FeedHostProcessorWatchdogFuncPointer func);
void feedWatchdog();
};

extern WiFiClass WiFi;
Expand Down
11 changes: 3 additions & 8 deletions src/utility/spi_drv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <SPI.h>
#include "utility/spi_drv.h"
#include "pins_arduino.h"
#include "WiFi.h"

#ifdef ARDUINO_SAMD_MKRVIDOR4000

Expand Down Expand Up @@ -67,13 +68,7 @@ static bool inverted_reset = false;

bool SpiDrv::initialized = false;

__attribute__((weak)) void wifi_nina_feed_watchdog()
{
/* This function can be overwritten by a "strong" implementation
* in a higher level application, such as the ArduinoIoTCloud
* firmware stack.
*/
}
extern WiFiClass WiFi;

void SpiDrv::begin()
{
Expand Down Expand Up @@ -227,7 +222,7 @@ void SpiDrv::waitForSlaveReady(bool const feed_watchdog)
{
if (feed_watchdog) {
if ((millis() - start) < 10000) {
wifi_nina_feed_watchdog();
WiFi.feedWatchdog();
}
}
}
Expand Down