mirror of https://github.com/ARMmbed/mbed-os.git
Nanostack::EthernetInterface::bringdown() can handle blocking mode
This let the tests-network-interface test pass for nanostack.pull/10243/head
parent
7e7f4f561b
commit
ccc83f7e3b
|
|
@ -63,6 +63,7 @@ protected:
|
|||
int8_t interface_id;
|
||||
int8_t _device_id;
|
||||
rtos::Semaphore connect_semaphore;
|
||||
rtos::Semaphore disconnect_semaphore;
|
||||
|
||||
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
|
||||
nsapi_connection_status_t _connect_status;
|
||||
|
|
|
|||
|
|
@ -119,9 +119,13 @@ nsapi_error_t MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
|
|||
|
||||
void Nanostack::Interface::network_handler(mesh_connection_status_t status)
|
||||
{
|
||||
if ((status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL ||
|
||||
status == MESH_CONNECTED_GLOBAL) && _blocking) {
|
||||
connect_semaphore.release();
|
||||
if (_blocking) {
|
||||
if (status == MESH_CONNECTED || status == MESH_CONNECTED_LOCAL ||
|
||||
status == MESH_CONNECTED_GLOBAL) {
|
||||
connect_semaphore.release();
|
||||
} else if (status == MESH_DISCONNECTED) {
|
||||
disconnect_semaphore.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ nsapi_error_t Nanostack::EthernetInterface::bringup(bool dhcp, const char *ip,
|
|||
return NSAPI_ERROR_DHCP_FAILURE; // sort of...
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t NanostackEthernetInterface::do_initialize()
|
||||
|
|
@ -97,8 +97,26 @@ nsapi_error_t NanostackEthernetInterface::do_initialize()
|
|||
|
||||
nsapi_error_t Nanostack::EthernetInterface::bringdown()
|
||||
{
|
||||
if (enet_tasklet_disconnect(true)) {
|
||||
nanostack_lock();
|
||||
int8_t status = enet_tasklet_disconnect(true);
|
||||
nanostack_unlock();
|
||||
|
||||
if (status == -1) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
} else if (status == -2) {
|
||||
return NSAPI_ERROR_NO_MEMORY;
|
||||
} else if (status == -3) {
|
||||
return NSAPI_ERROR_ALREADY;
|
||||
} else if (status != 0) {
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (_blocking) {
|
||||
int32_t count = disconnect_semaphore.wait(30000);
|
||||
|
||||
if (count <= 0) {
|
||||
return NSAPI_ERROR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue