Skip to content

Commit 51d3fc0

Browse files
committed
Adjust Nanostack startup
Fix locking - can't lock until the system is initialised. So initialise on first entry to connect(). Run randLIB initialisation after starting the radio driver - means you get MAC and RF noise out.
1 parent 8dc9b0b commit 51d3fc0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

net/nanostack-interface/NanostackInterface.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
#include "ns_address.h"
2222
#include "nsdynmemLIB.h"
2323
#include "eventOS_scheduler.h"
24+
#include "randLIB.h"
2425

2526
#include "mbed-mesh-api/MeshInterfaceFactory.h"
2627

28+
#include "mesh_system.h" // from inside mbed-mesh-api
2729
#include "socket_api.h"
2830
#include "driverRFPhy.h"
2931
#include "net_interface.h"
@@ -482,8 +484,6 @@ int NanostackInterface::register_rf()
482484

483485
int NanostackInterface::actual_connect()
484486
{
485-
nanostack_lock();
486-
487487
mesh_error_t status = get_mesh_api()->connect();
488488
if (status != MESH_ERROR_NONE) {
489489
nanostack_unlock();
@@ -513,6 +513,8 @@ int NanostackInterface::disconnect()
513513

514514
int ThreadInterface::connect()
515515
{
516+
// initialize mesh networking resources, memory, timers, etc...
517+
mesh_system_init();
516518
nanostack_lock();
517519

518520
mesh_api = MeshInterfaceFactory::createInterface(MESH_TYPE_THREAD);
@@ -524,6 +526,10 @@ int ThreadInterface::connect()
524526
nanostack_unlock();
525527
return NSAPI_ERROR_DEVICE_ERROR;
526528
}
529+
530+
// After the RF is up, we can seed the random from it.
531+
randLIB_seed_random();
532+
527533
mesh_error_t status = ((MeshThread *)mesh_api)->init(rf_device_id, AbstractMesh::mesh_network_handler_t(static_cast<NanostackInterface *>(this), &ThreadInterface::mesh_network_handler), eui64, NULL);
528534
if (status != MESH_ERROR_NONE) {
529535
nanostack_unlock();
@@ -538,6 +544,8 @@ int ThreadInterface::connect()
538544

539545
int LoWPANNDInterface::connect()
540546
{
547+
// initialize mesh networking resources, memory, timers, etc...
548+
mesh_system_init();
541549
nanostack_lock();
542550

543551
mesh_api = MeshInterfaceFactory::createInterface(MESH_TYPE_6LOWPAN_ND);
@@ -549,6 +557,10 @@ int LoWPANNDInterface::connect()
549557
nanostack_unlock();
550558
return NSAPI_ERROR_DEVICE_ERROR;
551559
}
560+
561+
// After the RF is up, we can seed the random from it.
562+
randLIB_seed_random();
563+
552564
mesh_error_t status = ((Mesh6LoWPAN_ND *)mesh_api)->init(rf_device_id, AbstractMesh::mesh_network_handler_t(static_cast<NanostackInterface *>(this), &LoWPANNDInterface::mesh_network_handler));
553565
if (status != MESH_ERROR_NONE) {
554566
nanostack_unlock();

0 commit comments

Comments
 (0)