Skip to content
Snippets Groups Projects
Commit 3225aaa3 authored by Gunar Schorcht's avatar Gunar Schorcht Committed by Schorcht
Browse files

cpu/esp8266: different conn states in esp_wifi

Different connection states defined to be able to realize a better connect/reconnect handling
parent 88f6beec
No related branches found
No related tags found
No related merge requests found
...@@ -197,14 +197,14 @@ static void _esp_wifi_handle_event_cb(System_Event_t *evt) ...@@ -197,14 +197,14 @@ static void _esp_wifi_handle_event_cb(System_Event_t *evt)
ESP_WIFI_LOG_INFO("connected to ssid %s, channel %d", ESP_WIFI_LOG_INFO("connected to ssid %s, channel %d",
evt->event_info.connected.ssid, evt->event_info.connected.ssid,
evt->event_info.connected.channel); evt->event_info.connected.channel);
_esp_wifi_dev.connected = true; _esp_wifi_dev.state = ESP_WIFI_CONNECTED;
break; break;
case EVENT_STAMODE_DISCONNECTED: case EVENT_STAMODE_DISCONNECTED:
ESP_WIFI_LOG_INFO("disconnected from ssid %s, reason %d", ESP_WIFI_LOG_INFO("disconnected from ssid %s, reason %d",
evt->event_info.disconnected.ssid, evt->event_info.disconnected.ssid,
evt->event_info.disconnected.reason); evt->event_info.disconnected.reason);
_esp_wifi_dev.connected = false; _esp_wifi_dev.state = ESP_WIFI_DISCONNECTED;
/* call disconnect to reset internal state */ /* call disconnect to reset internal state */
if (!wifi_station_disconnect()) { if (!wifi_station_disconnect()) {
...@@ -263,7 +263,7 @@ static int _send(netdev_t *netdev, const iolist_t *iolist) ...@@ -263,7 +263,7 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
esp_wifi_netdev_t *dev = (esp_wifi_netdev_t*)netdev; esp_wifi_netdev_t *dev = (esp_wifi_netdev_t*)netdev;
critical_enter(); critical_enter();
if (!dev->connected) { if (dev->state != ESP_WIFI_CONNECTED) {
ESP_WIFI_DEBUG("WiFi is still not connected to AP, cannot send"); ESP_WIFI_DEBUG("WiFi is still not connected to AP, cannot send");
_in_send = false; _in_send = false;
critical_exit(); critical_exit();
...@@ -459,7 +459,7 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len) ...@@ -459,7 +459,7 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
case NETOPT_LINK_CONNECTED: case NETOPT_LINK_CONNECTED:
assert(max_len == 1); assert(max_len == 1);
if (dev->connected) { if (dev->state == ESP_WIFI_CONNECTED) {
*((netopt_enable_t *)val) = NETOPT_ENABLE; *((netopt_enable_t *)val) = NETOPT_ENABLE;
} }
else { else {
...@@ -544,7 +544,7 @@ static void _esp_wifi_setup(void) ...@@ -544,7 +544,7 @@ static void _esp_wifi_setup(void)
/* initialize netdev data structure */ /* initialize netdev data structure */
dev->rx_len = 0; dev->rx_len = 0;
dev->connected = false; dev->state = ESP_WIFI_DISCONNECTED;
mutex_init(&dev->dev_lock); mutex_init(&dev->dev_lock);
......
...@@ -20,12 +20,22 @@ ...@@ -20,12 +20,22 @@
#define ESP_WIFI_NETDEV_H #define ESP_WIFI_NETDEV_H
#include "net/netdev.h" #include "net/netdev.h"
#include "lwip/udp.h" #include "ringbuffer.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/**
* @brief State of the WiFi interface
*/
typedef enum {
ESP_WIFI_NOT_WORKING, /**< interface is not working correctly */
ESP_WIFI_DISCONNECTED, /**< interface is not associated to the AP */
ESP_WIFI_CONNECTING, /**< interface is trying an association to the AP */
ESP_WIFI_CONNECTED /**< interface is not associated to the AP */
} esp_wifi_state_t;
/** /**
* @brief Device descriptor for ESP infrastructure mode WIFI device * @brief Device descriptor for ESP infrastructure mode WIFI device
*/ */
...@@ -34,15 +44,14 @@ typedef struct ...@@ -34,15 +44,14 @@ typedef struct
netdev_t netdev; /**< netdev parent struct */ netdev_t netdev; /**< netdev parent struct */
uint8_t mac[ETHERNET_ADDR_LEN]; /**< MAC address of the device */ uint8_t mac[ETHERNET_ADDR_LEN]; /**< MAC address of the device */
ip_addr_t ip; /**< IPv4 address of the device */
uint8_t rx_buf[ETHERNET_MAX_LEN]; /**< receive buffer */ uint8_t rx_buf[ETHERNET_MAX_LEN]; /**< receive buffer */
uint16_t rx_len; /**< number of bytes received from lwIP */ uint16_t rx_len; /**< number of bytes received from lwIP */
bool connected; /**< indicates the connection state to the AP */ esp_wifi_state_t state; /**< indicates the interface state */
mutex_t dev_lock; /**< for exclusive access to buffer in receive functions */
mutex_t dev_lock; /**< for exclusive access to buffer in
receive functions */
} esp_wifi_netdev_t; } esp_wifi_netdev_t;
#ifdef __cplusplus #ifdef __cplusplus
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment