Skip to content

Commit 26beb98

Browse files
Correct network status callbacks with Nanostack.
Ethernet-tasklet needs to be registered for emac link state changes. Ethernet-tasklet will then handle ethernet cable connection/disconnection events.
1 parent 9aef9d3 commit 26beb98

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

features/nanostack/mbed-mesh-api/source/NanostackEMACInterface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "nsdynmemLIB.h"
88
#include "arm_hal_phy.h"
99
#include "EMAC.h"
10+
#include "enet_tasklet.h"
1011

1112
class EMACPhy : public NanostackEthernetPhy {
1213
public:
@@ -137,6 +138,7 @@ int8_t EMACPhy::phy_register()
137138

138139
emac.set_memory_manager(memory_manager);
139140
emac.set_link_input_cb(mbed::callback(this, &EMACPhy::emac_phy_rx));
141+
emac.set_link_state_cb(enet_tasklet_link_state_changed);
140142

141143
if (!emac.power_up()) {
142144
return -1;

features/nanostack/mbed-mesh-api/source/ethernet_tasklet.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ void enet_tasklet_main(arm_event_s *event)
119119
case APPLICATION_EVENT:
120120
if (event->event_id == APPL_EVENT_CONNECT) {
121121
enet_tasklet_configure_and_connect_to_network();
122+
} else if (event->event_id == APPL_BACKHAUL_INTERFACE_PHY_UP) {
123+
// Ethernet cable has been plugged in
124+
arm_nwk_interface_configure_ipv6_bootstrap_set(
125+
tasklet_data_ptr->network_interface_id, NET_IPV6_BOOTSTRAP_AUTONOMOUS, NULL);
126+
enet_tasklet_configure_and_connect_to_network();
127+
128+
if (tasklet_data_ptr->poll_network_status_timeout != NULL) {
129+
// Restart poll timer
130+
eventOS_timeout_cancel(tasklet_data_ptr->poll_network_status_timeout);
131+
}
132+
tasklet_data_ptr->poll_network_status_timeout =
133+
eventOS_timeout_every_ms(enet_tasklet_poll_network_status, 2000, NULL);
134+
} else if (event->event_id == APPL_BACKHAUL_INTERFACE_PHY_DOWN) {
135+
// Ethernet cable has been removed
136+
arm_nwk_interface_down(tasklet_data_ptr->network_interface_id);
137+
eventOS_timeout_cancel(tasklet_data_ptr->poll_network_status_timeout);
138+
tasklet_data_ptr->poll_network_status_timeout = NULL;
139+
memset(tasklet_data_ptr->ip, 0x0, 16);
140+
enet_tasklet_network_state_changed(MESH_BOOTSTRAP_STARTED);
122141
}
123142
break;
124143

@@ -300,3 +319,15 @@ int8_t enet_tasklet_network_init(int8_t device_id)
300319
tasklet_data_ptr->network_interface_id, NET_IPV6_BOOTSTRAP_AUTONOMOUS, NULL);
301320
return tasklet_data_ptr->network_interface_id;
302321
}
322+
323+
void enet_tasklet_link_state_changed(bool up)
324+
{
325+
arm_event_s event = {
326+
.receiver = tasklet_data_ptr->tasklet,
327+
.sender = tasklet_data_ptr->tasklet,
328+
.event_type = APPLICATION_EVENT,
329+
.priority = ARM_LIB_LOW_PRIORITY_EVENT,
330+
.event_id = up ? APPL_BACKHAUL_INTERFACE_PHY_UP : APPL_BACKHAUL_INTERFACE_PHY_DOWN,
331+
};
332+
eventOS_event_send(&event);
333+
}

features/nanostack/mbed-mesh-api/source/include/enet_tasklet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void enet_tasklet_init(void);
2626
uint8_t enet_tasklet_network_init(int8_t);
2727
int8_t enet_tasklet_connect(void (*)(mesh_connection_status_t mesh_status), int8_t nwk_interface_id);
2828
void enet_tasklet_disconnect();
29+
void enet_tasklet_link_state_changed(bool up);
2930

3031
#ifdef __cplusplus
3132
}

features/nanostack/mbed-mesh-api/source/include/mesh_system.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ extern "C" {
2525
/*
2626
* Event type for connecting
2727
*/
28-
#define APPL_EVENT_CONNECT 0x01
28+
enum {
29+
APPL_EVENT_CONNECT = 0x01,
30+
APPL_BACKHAUL_INTERFACE_PHY_DOWN,
31+
APPL_BACKHAUL_INTERFACE_PHY_UP
32+
};
2933

3034
/*
3135
* \brief Send application connect event to receiver tasklet to

0 commit comments

Comments
 (0)