Skip to content

Commit 1849bb5

Browse files
authored
Merge pull request #14817 from artokin/add_nanostack_system_time_callbacks_to_master
Add system time read/write callbacks to mbed-mesh-api
2 parents 1d5d3b0 + 2856a88 commit 1849bb5

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

connectivity/nanostack/mbed-mesh-api/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"help": "Definition of heap statistics `mem_stat_t` storage.",
2525
"value": null
2626
},
27+
"system-time-update-from-nanostack": {
28+
"help": "Allow nanostack to read and write device system time to synchronise time in the network. Feature enabled when set to true, false otherwise.",
29+
"value": true
30+
},
2731
"6lowpan-nd-channel-mask": {
2832
"help": "Channel mask, bit-mask of channels to use. [0-0x07fff800]",
2933
"value": "0x7fff800"

connectivity/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@
2222
#include "thread_management_if.h"
2323
#include "ip6string.h"
2424
#include "mbed_error.h"
25+
#include "mbed_rtc_time.h"
26+
27+
#if (MBED_CONF_MBED_MESH_API_SYSTEM_TIME_UPDATE_FROM_NANOSTACK == true)
28+
static uint64_t time_read_callback(void)
29+
{
30+
time_t seconds = time(NULL);
31+
32+
return (uint64_t)seconds;
33+
}
34+
35+
static void time_write_callback(uint64_t time_write)
36+
{
37+
set_time((time_t)time_write);
38+
}
39+
#endif /* MBED_CONF_MBED_MESH_API_SYSTEM_TIME_UPDATE_FROM_NANOSTACK */
2540

2641
nsapi_error_t Nanostack::Interface::get_ip_address(SocketAddress *address)
2742
{
@@ -110,6 +125,10 @@ int InterfaceNanostack::connect()
110125
return error;
111126
}
112127

128+
#if (MBED_CONF_MBED_MESH_API_SYSTEM_TIME_UPDATE_FROM_NANOSTACK == true)
129+
mesh_system_time_callback_set(time_read_callback, time_write_callback);
130+
#endif /* MBED_CONF_MBED_MESH_API_SYSTEM_TIME_UPDATE_FROM_NANOSTACK */
131+
113132
return _interface->bringup(false, NULL, NULL, NULL, IPV6_STACK, _blocking);
114133
}
115134

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ enum {
3232
APPL_BACKHAUL_LINK_UP
3333
};
3434

35+
36+
typedef uint64_t ns_time_read_cb(void);
37+
typedef void ns_time_write_cb(uint64_t);
38+
39+
3540
/*
3641
* \brief Send application connect event to receiver tasklet to
3742
* ensure that connection is made in right tasklet.
@@ -40,6 +45,8 @@ void mesh_system_send_connect_event(uint8_t receiver);
4045

4146
int mesh_system_set_file_system_root_path(const char *root_path);
4247

48+
void mesh_system_time_callback_set(ns_time_read_cb, ns_time_write_cb);
49+
4350
/*
4451
* \brief Initialize mesh system.
4552
* Memory pool, timers, traces and support are initialized.

connectivity/nanostack/mbed-mesh-api/source/mesh_system.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "mbed_assert.h"
2727
#include "mbed_error.h"
2828
#include "ns_file_system.h"
29+
#include "ns_time_api.h"
2930
// For tracing we need to define flag, have include and define group
3031
#define HAVE_DEBUG 1
3132
#include "ns_trace.h"
@@ -83,3 +84,9 @@ int mesh_system_set_file_system_root_path(const char *root_path)
8384
{
8485
return ns_file_system_set_root_path(root_path);
8586
}
87+
88+
void mesh_system_time_callback_set(ns_time_read_cb read_cb, ns_time_write_cb write_cb)
89+
{
90+
ns_time_api_system_time_callback_set(read_cb);
91+
ns_time_api_system_time_write_callback_set(write_cb);
92+
}

0 commit comments

Comments
 (0)