Skip to content

Commit

Permalink
Merge pull request #10243 from michalpasztamobica/nanostack_bringdown…
Browse files Browse the repository at this point in the history
…_blocking

Nanostack::EthernetInterface::bringdown() can handle blocking mode
  • Loading branch information
Cruz Monrreal authored Mar 29, 2019
2 parents 0a088a6 + ccc83f7 commit 9c381f2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}

0 comments on commit 9c381f2

Please sign in to comment.