From 71bfc3a1ca3320d6a488a75f796a9cf43b9a2ee2 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 30 Mar 2022 19:06:31 +0200 Subject: [PATCH 1/3] drivers/atwinc15x0: disconnect when sleeping Don't try to re-connect when the interface is in SLEEP state. Also disconnect before entering sleep. --- drivers/atwinc15x0/atwinc15x0_netdev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/atwinc15x0/atwinc15x0_netdev.c b/drivers/atwinc15x0/atwinc15x0_netdev.c index 1fcf3da46d..348d7ccce9 100644 --- a/drivers/atwinc15x0/atwinc15x0_netdev.c +++ b/drivers/atwinc15x0/atwinc15x0_netdev.c @@ -193,6 +193,11 @@ static void _atwinc15x0_wifi_cb(uint8_t type, void *msg) atwinc15x0->connected = false; atwinc15x0->netdev.event_callback(&atwinc15x0->netdev, NETDEV_EVENT_LINK_DOWN); + /* do not reconnect on standby or sleep */ + if (atwinc15x0->state == NETOPT_STATE_STANDBY || + atwinc15x0->state == NETOPT_STATE_SLEEP) { + break; + } /* wait and try to reconnect */ ztimer_sleep(ZTIMER_MSEC, ATWINC15X0_WAIT_RECONNECT_MS); _atwinc15x0_connect(); @@ -434,13 +439,15 @@ static int _set_state(atwinc15x0_t *dev, netopt_state_t state) switch (state) { case NETOPT_STATE_SLEEP: case NETOPT_STATE_STANDBY: + dev->state = state; + m2m_wifi_disconnect(); m2m_wifi_set_sleep_mode(M2M_PS_MANUAL, CONFIG_ATWINC15X0_RECV_BCAST); m2m_wifi_request_sleep(UINT32_MAX); - dev->state = state; return sizeof(netopt_state_t); case NETOPT_STATE_IDLE: m2m_wifi_set_sleep_mode(M2M_PS_DEEP_AUTOMATIC, CONFIG_ATWINC15X0_RECV_BCAST); dev->state = state; + _atwinc15x0_connect(); return sizeof(netopt_state_t); default: break; From 14121a529824e6333e583bf1140b05ab7b28b70a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 31 Mar 2022 16:49:41 +0200 Subject: [PATCH 2/3] drivers/atwinc15x0: fix DEBUG() macro --- drivers/atwinc15x0/atwinc15x0_netdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/atwinc15x0/atwinc15x0_netdev.c b/drivers/atwinc15x0/atwinc15x0_netdev.c index 348d7ccce9..b7c91b4bac 100644 --- a/drivers/atwinc15x0/atwinc15x0_netdev.c +++ b/drivers/atwinc15x0/atwinc15x0_netdev.c @@ -252,13 +252,13 @@ static int _atwinc15x0_send(netdev_t *netdev, const iolist_t *iolist) assert(iolist); if (!dev->connected) { - DEBUG("%s WiFi is still not connected to AP, cannot send", __func__); + DEBUG("%s WiFi is still not connected to AP, cannot send\n", __func__); return -ENODEV; } /* send wakes from standby but not from sleep */ if (dev->state == NETOPT_STATE_SLEEP) { - DEBUG("%s WiFi is in SLEEP state, cannot send", __func__); + DEBUG("%s WiFi is in SLEEP state, cannot send\n", __func__); return -ENODEV; } if (dev->state == NETOPT_STATE_STANDBY) { From 37159fe4d9b518f05f3cf7df71e5532edd79ff05 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 31 Mar 2022 16:52:40 +0200 Subject: [PATCH 3/3] drivers/atwinc15x0: make use of wake pin --- drivers/atwinc15x0/atwinc15x0_netdev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/atwinc15x0/atwinc15x0_netdev.c b/drivers/atwinc15x0/atwinc15x0_netdev.c index b7c91b4bac..4287a3cad8 100644 --- a/drivers/atwinc15x0/atwinc15x0_netdev.c +++ b/drivers/atwinc15x0/atwinc15x0_netdev.c @@ -443,8 +443,14 @@ static int _set_state(atwinc15x0_t *dev, netopt_state_t state) m2m_wifi_disconnect(); m2m_wifi_set_sleep_mode(M2M_PS_MANUAL, CONFIG_ATWINC15X0_RECV_BCAST); m2m_wifi_request_sleep(UINT32_MAX); + if (gpio_is_valid(atwinc15x0->params.wake_pin)) { + gpio_clear(atwinc15x0->params.wake_pin); + } return sizeof(netopt_state_t); case NETOPT_STATE_IDLE: + if (gpio_is_valid(atwinc15x0->params.wake_pin)) { + gpio_set(atwinc15x0->params.wake_pin); + } m2m_wifi_set_sleep_mode(M2M_PS_DEEP_AUTOMATIC, CONFIG_ATWINC15X0_RECV_BCAST); dev->state = state; _atwinc15x0_connect();