Skip to content

Commit ad2cb91

Browse files
authored
Merge pull request #9503 from VeijoPesonen/feature-esp8266_oob_handling_by_sigio
ESP8266: OOB handling done based on arrival of SIGIOs
2 parents f4e6db2 + d6701c3 commit ad2cb91

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ESP8266Interface::ESP8266Interface()
6161
_connect_retval(NSAPI_ERROR_OK),
6262
_conn_stat(NSAPI_STATUS_DISCONNECTED),
6363
_conn_stat_cb(NULL),
64-
_global_event_queue(NULL),
64+
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
6565
_oob_event_id(0),
6666
_connect_event_id(0)
6767
{
@@ -77,8 +77,6 @@ ESP8266Interface::ESP8266Interface()
7777
_sock_i[i].open = false;
7878
_sock_i[i].sport = 0;
7979
}
80-
81-
_oob2global_event_queue();
8280
}
8381
#endif
8482

@@ -92,7 +90,7 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
9290
_initialized(false),
9391
_conn_stat(NSAPI_STATUS_DISCONNECTED),
9492
_conn_stat_cb(NULL),
95-
_global_event_queue(NULL),
93+
_global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
9694
_oob_event_id(0),
9795
_connect_event_id(0)
9896
{
@@ -108,8 +106,6 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
108106
_sock_i[i].open = false;
109107
_sock_i[i].sport = 0;
110108
}
111-
112-
_oob2global_event_queue();
113109
}
114110

115111
ESP8266Interface::~ESP8266Interface()
@@ -169,17 +165,6 @@ int ESP8266Interface::connect(const char *ssid, const char *pass, nsapi_security
169165
return connect();
170166
}
171167

172-
void ESP8266Interface::_oob2global_event_queue()
173-
{
174-
_global_event_queue = mbed_event_queue();
175-
_oob_event_id = _global_event_queue->call_every(ESP8266_RECV_TIMEOUT, callback(this, &ESP8266Interface::proc_oob_evnt));
176-
177-
if (!_oob_event_id) {
178-
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
179-
"ESP8266::_oob2geq: unable to allocate OOB event");
180-
}
181-
}
182-
183168
void ESP8266Interface::_connect_async()
184169
{
185170
_cmutex.lock();
@@ -748,6 +733,11 @@ nsapi_error_t ESP8266Interface::getsockopt(nsapi_socket_t handle, int level, int
748733

749734
void ESP8266Interface::event()
750735
{
736+
if (!_oob_event_id) {
737+
// Throttles event creation by using arbitrary small delay
738+
_oob_event_id = _global_event_queue->call_in(50, callback(this, &ESP8266Interface::proc_oob_evnt));
739+
}
740+
751741
for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) {
752742
if (_cbs[i].callback) {
753743
_cbs[i].callback(_cbs[i].data);
@@ -824,6 +814,7 @@ void ESP8266Interface::refresh_conn_state_cb()
824814

825815
void ESP8266Interface::proc_oob_evnt()
826816
{
817+
_oob_event_id = 0; // Allows creation of a new event
827818
_esp.bg_process_oob(ESP8266_RECV_TIMEOUT, true);
828819
}
829820

components/wifi/esp8266-driver/ESP8266Interface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
389389
int _oob_event_id;
390390
int _connect_event_id;
391391
void proc_oob_evnt();
392-
void _oob2global_event_queue();
393392
void _connect_async();
394393
rtos::Mutex _cmutex; // Protect asynchronous connection logic
395394

0 commit comments

Comments
 (0)