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.
pull/8817/head
Kari Haapalehto 2018-11-20 11:17:30 +02:00
parent 9aef9d3661
commit 26beb983d4
4 changed files with 39 additions and 1 deletions

View File

@ -7,6 +7,7 @@
#include "nsdynmemLIB.h"
#include "arm_hal_phy.h"
#include "EMAC.h"
#include "enet_tasklet.h"
class EMACPhy : public NanostackEthernetPhy {
public:
@ -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;

View File

@ -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;
@ -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);
}

View File

@ -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
}

View File

@ -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