mirror of https://github.com/ARMmbed/mbed-os.git
ESP8266: reduces SIGIO signaled to the upper layers
parent
a4ed473afc
commit
7d3621dae4
|
@ -28,7 +28,6 @@
|
||||||
#include "platform/Callback.h"
|
#include "platform/Callback.h"
|
||||||
#include "platform/mbed_debug.h"
|
#include "platform/mbed_debug.h"
|
||||||
#include "platform/mbed_wait_api.h"
|
#include "platform/mbed_wait_api.h"
|
||||||
#include "Kernel.h"
|
|
||||||
|
|
||||||
#ifndef MBED_CONF_ESP8266_DEBUG
|
#ifndef MBED_CONF_ESP8266_DEBUG
|
||||||
#define MBED_CONF_ESP8266_DEBUG false
|
#define MBED_CONF_ESP8266_DEBUG false
|
||||||
|
@ -495,6 +494,10 @@ int ESP8266Interface::socket_close(void *handle)
|
||||||
err = NSAPI_ERROR_DEVICE_ERROR;
|
err = NSAPI_ERROR_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cbs[socket->id].callback = NULL;
|
||||||
|
_cbs[socket->id].data = NULL;
|
||||||
|
_cbs[socket->id].deferred = false;
|
||||||
|
|
||||||
socket->connected = false;
|
socket->connected = false;
|
||||||
_sock_i[socket->id].open = false;
|
_sock_i[socket->id].open = false;
|
||||||
_sock_i[socket->id].sport = 0;
|
_sock_i[socket->id].sport = 0;
|
||||||
|
@ -573,15 +576,12 @@ int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size)
|
||||||
return socket->proto == NSAPI_TCP ? 0 : NSAPI_ERROR_UNSUPPORTED;
|
return socket->proto == NSAPI_TCP ? 0 : NSAPI_ERROR_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long int sendStartTime = rtos::Kernel::get_ms_count();
|
|
||||||
do {
|
|
||||||
status = _esp.send(socket->id, data, size);
|
status = _esp.send(socket->id, data, size);
|
||||||
} while ((sendStartTime - rtos::Kernel::get_ms_count() < 50)
|
|
||||||
&& (status != NSAPI_ERROR_OK));
|
|
||||||
|
|
||||||
if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_TCP) {
|
if (status == NSAPI_ERROR_WOULD_BLOCK && !_cbs[socket->id].deferred && socket->proto == NSAPI_TCP) {
|
||||||
tr_debug("ESP8266Interface::socket_send(): enqueuing the event call");
|
tr_debug("Postponing SIGIO from the device");
|
||||||
_global_event_queue->call_in(100, callback(this, &ESP8266Interface::event));
|
_cbs[socket->id].deferred = true;
|
||||||
|
_global_event_queue->call_in(50, callback(this, &ESP8266Interface::event_deferred));
|
||||||
} else if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_UDP) {
|
} else if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_UDP) {
|
||||||
status = NSAPI_ERROR_DEVICE_ERROR;
|
status = NSAPI_ERROR_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -731,6 +731,16 @@ void ESP8266Interface::event()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ESP8266Interface::event_deferred()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) {
|
||||||
|
if (_cbs[i].deferred && _cbs[i].callback) {
|
||||||
|
_cbs[i].deferred = false;
|
||||||
|
_cbs[i].callback(_cbs[i].data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ESP8266Interface::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
|
void ESP8266Interface::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
|
||||||
{
|
{
|
||||||
_conn_stat_cb = status_cb;
|
_conn_stat_cb = status_cb;
|
||||||
|
|
|
@ -373,8 +373,10 @@ private:
|
||||||
struct {
|
struct {
|
||||||
void (*callback)(void *);
|
void (*callback)(void *);
|
||||||
void *data;
|
void *data;
|
||||||
|
bool deferred;
|
||||||
} _cbs[ESP8266_SOCKET_COUNT];
|
} _cbs[ESP8266_SOCKET_COUNT];
|
||||||
void event();
|
void event();
|
||||||
|
void event_deferred();
|
||||||
|
|
||||||
// Connection state reporting to application
|
// Connection state reporting to application
|
||||||
nsapi_connection_status_t _conn_stat;
|
nsapi_connection_status_t _conn_stat;
|
||||||
|
|
Loading…
Reference in New Issue