Skip to content

Commit c940d0e

Browse files
authored
Merge pull request #2551 from ARMmbed/runtime_configuration
Remove IPv6 link time dependency on an RF phy
2 parents e4c8d76 + 126c8be commit c940d0e

File tree

4 files changed

+109
-15
lines changed

4 files changed

+109
-15
lines changed

features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/arm_hal_random.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#include "ns_types.h"
1717
#include "arm_hal_random.h"
1818

19-
#ifdef MBED_CONF_NANOSTACK_CONFIGURATION
20-
#include "driverRFPhy.h"
21-
#endif
2219
#include "mbedtls/entropy_poll.h"
2320

2421
void arm_random_module_init(void)
@@ -32,14 +29,6 @@ uint32_t arm_random_seed_get(void)
3229
/* Grab a seed from a function we provide for mbedtls */
3330
size_t len;
3431
mbedtls_hardware_poll(NULL, (uint8_t *) &result, sizeof result, &len);
35-
#endif
36-
#ifdef MBED_CONF_NANOSTACK_CONFIGURATION
37-
uint8_t mac[8];
38-
rf_read_mac_address(mac);
39-
for (int i = 0; i <= 7; i++) {
40-
result ^= (uint32_t) mac[i] << ((i % 4) * 8);
41-
}
42-
result ^= rf_read_random();
4332
#endif
4433
return result;
4534
}

features/net/FEATURE_IPV6/nanostack-interface/NanostackInterface.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include "mesh_system.h" // from inside mbed-mesh-api
2929
#include "socket_api.h"
30-
#include "driverRFPhy.h"
3130
#include "net_interface.h"
3231
#include "ip6string.h"
3332
// Uncomment to enable trace
@@ -453,6 +452,28 @@ void NanostackSocket::event_connnect_closed(socket_callback_t *sock_cb)
453452
close();
454453
}
455454

455+
MeshInterfaceNanostack::MeshInterfaceNanostack()
456+
: phy(NULL), mesh_api(NULL), rf_device_id(-1), eui64(),
457+
ip_addr_str(), mac_addr_str(), connect_semaphore(0)
458+
{
459+
// Nothing to do
460+
}
461+
462+
MeshInterfaceNanostack::MeshInterfaceNanostack(NanostackRfPhy *phy)
463+
: phy(phy), mesh_api(NULL), rf_device_id(-1), connect_semaphore(0)
464+
{
465+
// Nothing to do
466+
}
467+
468+
int MeshInterfaceNanostack::initialize(NanostackRfPhy *phy)
469+
{
470+
if (this->phy != NULL) {
471+
error("Phy already set");
472+
}
473+
this->phy = phy;
474+
return 0;
475+
}
476+
456477
void MeshInterfaceNanostack::mesh_network_handler(mesh_connection_status_t status)
457478
{
458479
nanostack_lock();
@@ -468,13 +489,13 @@ int MeshInterfaceNanostack::register_rf()
468489
{
469490
nanostack_lock();
470491

471-
rf_device_id = rf_device_register();
492+
rf_device_id = phy->rf_register();
472493
if (rf_device_id < 0) {
473494
nanostack_unlock();
474495
return -1;
475496
}
476497
// Read mac address after registering the device.
477-
rf_read_mac_address(eui64);
498+
phy->get_mac_address(eui64);
478499
sprintf(mac_addr_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", eui64[0], eui64[1], eui64[2], eui64[3], eui64[4], eui64[5], eui64[6], eui64[7]);
479500

480501
nanostack_unlock();

features/net/FEATURE_IPV6/nanostack-interface/NanostackInterface.h

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "NetworkStack.h"
99
#include "MeshInterface.h"
10+
#include "NanostackRfPhy.h"
1011

1112
#include "mbed-mesh-api/Mesh6LoWPAN_ND.h"
1213
#include "mbed-mesh-api/MeshThread.h"
@@ -220,6 +221,15 @@ class NanostackInterface : public NetworkStack {
220221
class MeshInterfaceNanostack : public MeshInterface {
221222
public:
222223

224+
/** Attach phy and initialize the mesh
225+
*
226+
* Initializes a mesh interface on the given phy. Not needed if
227+
* the phy is passed to the mesh's constructor.
228+
*
229+
* @return 0 on success, negative on failure
230+
*/
231+
virtual int initialize(NanostackRfPhy *phy);
232+
223233
/** Start the interface
224234
*
225235
* @return 0 on success, negative on failure
@@ -243,12 +253,14 @@ class MeshInterfaceNanostack : public MeshInterface {
243253
virtual const char *get_mac_address();
244254

245255
protected:
246-
MeshInterfaceNanostack() : connect_semaphore(0) { }
256+
MeshInterfaceNanostack();
257+
MeshInterfaceNanostack(NanostackRfPhy *phy);
247258
int register_rf();
248259
int actual_connect();
249260
virtual NetworkStack * get_stack(void);
250261

251262
void mesh_network_handler(mesh_connection_status_t status);
263+
NanostackRfPhy *phy;
252264
AbstractMesh *mesh_api;
253265
int8_t rf_device_id;
254266
uint8_t eui64[8];
@@ -259,6 +271,22 @@ class MeshInterfaceNanostack : public MeshInterface {
259271

260272
class LoWPANNDInterface : public MeshInterfaceNanostack {
261273
public:
274+
275+
/** Create an uninitialized LoWPANNDInterface
276+
*
277+
* Must initialize to initialize the mesh on a phy.
278+
*/
279+
LoWPANNDInterface() : MeshInterfaceNanostack() {
280+
281+
}
282+
283+
/** Create an initialized MeshInterface
284+
*
285+
*/
286+
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) {
287+
288+
}
289+
262290
int connect();
263291
protected:
264292
Mesh6LoWPAN_ND *get_mesh_api() const { return static_cast<Mesh6LoWPAN_ND *>(mesh_api); }
@@ -268,6 +296,22 @@ class LoWPANNDInterface : public MeshInterfaceNanostack {
268296

269297
class ThreadInterface : public MeshInterfaceNanostack {
270298
public:
299+
300+
/** Create an uninitialized LoWPANNDInterface
301+
*
302+
* Must initialize to initialize the mesh on a phy.
303+
*/
304+
ThreadInterface() : MeshInterfaceNanostack() {
305+
306+
}
307+
308+
/** Create an initialized MeshInterface
309+
*
310+
*/
311+
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) {
312+
313+
}
314+
271315
int connect();
272316
protected:
273317
MeshThread *get_mesh_api() const { return static_cast<MeshThread *>(mesh_api); }
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2016 ARM Limited. All rights reserved.
3+
*/
4+
5+
#ifndef NANOSTACK_RF_PHY_H_
6+
#define NANOSTACK_RF_PHY_H_
7+
8+
class NanostackRfPhy {
9+
public:
10+
11+
/** Register this physical interface with Nanostack
12+
*
13+
* @return Device driver ID or a negative error
14+
* code on failure
15+
*/
16+
virtual int8_t rf_register() = 0;
17+
18+
/** Unregister this physical interface
19+
*
20+
*/
21+
virtual void rf_unregister() = 0;
22+
23+
/** Read the mac address of this physical interface
24+
*
25+
* Note - some devices do not have a mac address
26+
* in hardware.
27+
*/
28+
virtual void get_mac_address(uint8_t *mac) = 0;
29+
30+
/** Set the mac address of this physical interface
31+
*
32+
*/
33+
virtual void set_mac_address(uint8_t *mac) = 0;
34+
35+
protected:
36+
NanostackRfPhy() {}
37+
virtual ~NanostackRfPhy() {}
38+
};
39+
40+
#endif /* NANOSTACK_INTERFACE_H_ */

0 commit comments

Comments
 (0)