Skip to content

Nanostack::EthernetInterface::bringdown() can handle blocking mode #10243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30s timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took it from the bringup procedure... Is there a specified timeout that you'd suggest?


if (count <= 0) {
return NSAPI_ERROR_TIMEOUT;
}
}
return NSAPI_ERROR_OK;
}