Skip to content

Correct network status callbacks with ethernet and nanostack #8817

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 @@ -7,6 +7,7 @@
#include "nsdynmemLIB.h"
#include "arm_hal_phy.h"
#include "EMAC.h"
#include "enet_tasklet.h"

class EMACPhy : public NanostackEthernetPhy {
public:
Expand Down Expand Up @@ -137,6 +138,7 @@ int8_t EMACPhy::phy_register()

emac.set_memory_manager(memory_manager);
emac.set_link_input_cb(mbed::callback(this, &EMACPhy::emac_phy_rx));
emac.set_link_state_cb(enet_tasklet_link_state_changed);

if (!emac.power_up()) {
return -1;
Expand Down
31 changes: 31 additions & 0 deletions features/nanostack/mbed-mesh-api/source/ethernet_tasklet.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ void enet_tasklet_main(arm_event_s *event)
case APPLICATION_EVENT:
if (event->event_id == APPL_EVENT_CONNECT) {
enet_tasklet_configure_and_connect_to_network();
} else if (event->event_id == APPL_BACKHAUL_INTERFACE_PHY_UP) {
// Ethernet cable has been plugged in
arm_nwk_interface_configure_ipv6_bootstrap_set(
tasklet_data_ptr->network_interface_id, NET_IPV6_BOOTSTRAP_AUTONOMOUS, NULL);
enet_tasklet_configure_and_connect_to_network();

if (tasklet_data_ptr->poll_network_status_timeout != NULL) {
// Restart poll timer
eventOS_timeout_cancel(tasklet_data_ptr->poll_network_status_timeout);
}
tasklet_data_ptr->poll_network_status_timeout =
eventOS_timeout_every_ms(enet_tasklet_poll_network_status, 2000, NULL);
} else if (event->event_id == APPL_BACKHAUL_INTERFACE_PHY_DOWN) {
// Ethernet cable has been removed
arm_nwk_interface_down(tasklet_data_ptr->network_interface_id);
eventOS_timeout_cancel(tasklet_data_ptr->poll_network_status_timeout);
tasklet_data_ptr->poll_network_status_timeout = NULL;
memset(tasklet_data_ptr->ip, 0x0, 16);
enet_tasklet_network_state_changed(MESH_BOOTSTRAP_STARTED);
}
break;

Expand Down Expand Up @@ -300,3 +319,15 @@ int8_t enet_tasklet_network_init(int8_t device_id)
tasklet_data_ptr->network_interface_id, NET_IPV6_BOOTSTRAP_AUTONOMOUS, NULL);
return tasklet_data_ptr->network_interface_id;
}

void enet_tasklet_link_state_changed(bool up)
{
arm_event_s event = {
.receiver = tasklet_data_ptr->tasklet,
.sender = tasklet_data_ptr->tasklet,
.event_type = APPLICATION_EVENT,
.priority = ARM_LIB_LOW_PRIORITY_EVENT,
.event_id = up ? APPL_BACKHAUL_INTERFACE_PHY_UP : APPL_BACKHAUL_INTERFACE_PHY_DOWN,
};
eventOS_event_send(&event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void enet_tasklet_init(void);
uint8_t enet_tasklet_network_init(int8_t);
int8_t enet_tasklet_connect(void (*)(mesh_connection_status_t mesh_status), int8_t nwk_interface_id);
void enet_tasklet_disconnect();
void enet_tasklet_link_state_changed(bool up);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ extern "C" {
/*
* Event type for connecting
*/
#define APPL_EVENT_CONNECT 0x01
enum {
APPL_EVENT_CONNECT = 0x01,
APPL_BACKHAUL_INTERFACE_PHY_DOWN,
APPL_BACKHAUL_INTERFACE_PHY_UP
};

/*
* \brief Send application connect event to receiver tasklet to
Expand Down