Skip to content

Commit f8789ad

Browse files
committed
zephyr: metrics: Replace bt_conn_le_info.interval with interval_us
Interval has been deprecated in zephyr. Interval_us replaces it in units of microseconds. Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no>
1 parent 67244e0 commit f8789ad

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

ports/zephyr/common/metrics/memfault_platform_bluetooth_metrics.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424
#include "memfault/metrics/platform/timer.h"
2525
#include "memfault/ports/zephyr/version.h"
2626

27+
#define BT_LE_INTERVAL_UNIT_US (1250U)
28+
2729
static struct bt_conn *s_mflt_bt_current_conn = NULL;
28-
static uint16_t s_mflt_bt_connection_interval = 0;
30+
static uint32_t s_mflt_bt_connection_interval_us = 0;
2931
struct k_work_delayable s_mflt_bt_delayed_metrics_work;
3032

3133
static void prv_record_gatt_mtu(struct bt_conn *conn) {
3234
uint16_t mtu = bt_gatt_get_mtu(conn);
3335
MEMFAULT_METRIC_SET_UNSIGNED(bt_gatt_mtu_size, mtu);
3436
}
3537

36-
static void prv_count_connection_events(uint16_t interval, bool reset_time) {
38+
static void prv_count_connection_events(uint32_t interval_us, bool reset_time) {
3739
// to accumulate data correctly on:
3840
// - connection interval change
3941
// - connection up/down
@@ -47,10 +49,9 @@ static void prv_count_connection_events(uint16_t interval, bool reset_time) {
4749
return;
4850
}
4951

50-
if (interval) {
51-
// connection interval is in units of 1.25ms
52-
// calculate events per second: 1000ms / (interval * 1.25ms)
53-
int32_t events_per_second = 800 / interval; // 1000 / 1.25 = 800
52+
if (interval_us) {
53+
// calculate events per second: 1000000us / interval_us
54+
int32_t events_per_second = 1000000 / interval_us;
5455

5556
// compute connection events accumulated
5657
const uint64_t current_time_ms = memfault_platform_get_time_since_boot_ms();
@@ -138,13 +139,18 @@ static void prv_delayed_metrics_work_handler(struct k_work *work) {
138139
static void prv_record_connection_params(struct bt_conn *conn) {
139140
struct bt_conn_info info;
140141
if (bt_conn_get_info(conn, &info) == 0) {
141-
MEMFAULT_METRIC_SET_UNSIGNED(bt_connection_interval, info.le.interval);
142+
MEMFAULT_METRIC_SET_UNSIGNED(bt_connection_interval_us, info.le.interval_us);
142143
MEMFAULT_METRIC_SET_UNSIGNED(bt_connection_latency, info.le.latency);
143144
MEMFAULT_METRIC_SET_UNSIGNED(bt_connection_timeout, info.le.timeout);
144-
s_mflt_bt_connection_interval = info.le.interval;
145+
#if (defined(MEMFAULT_ZEPHYR_VERSION_GT) && MEMFAULT_ZEPHYR_VERSION_GT(4, 3)) || \
146+
(defined(MEMFAULT_NCS_VERSION_GT) && MEMFAULT_NCS_VERSION_GT(3, 1))
147+
s_mflt_bt_connection_interval_us = info.le.interval_us;
148+
#else
149+
s_mflt_bt_connection_interval_us = info.le.interval * BT_LE_INTERVAL_UNIT_US;
150+
#endif
145151
} else {
146152
MEMFAULT_LOG_ERROR("Failed to get connection info");
147-
s_mflt_bt_connection_interval = 0;
153+
s_mflt_bt_connection_interval_us = 0;
148154
}
149155
}
150156

@@ -172,8 +178,8 @@ static void prv_bt_connected_cb(struct bt_conn *conn, uint8_t err) {
172178

173179
static void prv_bt_disconnected_cb(struct bt_conn *conn, uint8_t reason) {
174180
// tally connection events
175-
prv_count_connection_events(s_mflt_bt_connection_interval, false);
176-
s_mflt_bt_connection_interval = 0;
181+
prv_count_connection_events(s_mflt_bt_connection_interval_us, false);
182+
s_mflt_bt_connection_interval_us = 0;
177183

178184
if (s_mflt_bt_current_conn == conn) {
179185
bt_conn_unref(s_mflt_bt_current_conn);
@@ -203,16 +209,18 @@ static void prv_record_remote_info_cb(struct bt_conn *conn,
203209

204210
static void prv_bt_le_param_updated_cb(struct bt_conn *conn, uint16_t interval, uint16_t latency,
205211
uint16_t timeout) {
212+
uint32_t interval_us = interval * BT_LE_INTERVAL_UNIT_US;
213+
206214
// Record LE connection parameters
207-
MEMFAULT_METRIC_SET_UNSIGNED(bt_connection_interval, interval);
215+
MEMFAULT_METRIC_SET_UNSIGNED(bt_connection_interval_us, interval_us);
208216
MEMFAULT_METRIC_SET_UNSIGNED(bt_connection_latency, latency);
209217
MEMFAULT_METRIC_SET_UNSIGNED(bt_connection_timeout, timeout);
210218

211219
// Tally connection event counts received with the previous interval setting
212-
prv_count_connection_events(s_mflt_bt_connection_interval, false);
220+
prv_count_connection_events(s_mflt_bt_connection_interval_us, false);
213221

214222
// Update connection interval for computing connection event count
215-
s_mflt_bt_connection_interval = interval;
223+
s_mflt_bt_connection_interval_us = interval_us;
216224
}
217225

218226
BT_CONN_CB_DEFINE(bt_metrics_conn_callbacks) = {
@@ -238,7 +246,7 @@ static struct bt_gatt_cb prv_gatt_callbacks = {
238246
void memfault_bluetooth_metrics_heartbeat_update(void) {
239247
if (s_mflt_bt_current_conn != NULL) {
240248
// Update connection event count estimate
241-
prv_count_connection_events(s_mflt_bt_connection_interval, false);
249+
prv_count_connection_events(s_mflt_bt_connection_interval_us, false);
242250

243251
// Record current RSSI (if available)
244252
prv_record_connection_rssi(s_mflt_bt_current_conn);

ports/zephyr/config/memfault_metrics_heartbeat_zephyr_port_config.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ MEMFAULT_METRICS_KEY_DEFINE(bt_gatt_mtu_size, kMemfaultMetricType_Unsigned)
6868
MEMFAULT_METRICS_STRING_KEY_DEFINE(bt_connection_remote_info, sizeof("ff:ffff.ffff") - 1)
6969
#endif // defined(CONFIG_BT_REMOTE_VERSION)
7070
MEMFAULT_METRICS_KEY_DEFINE(bt_connection_event_count, kMemfaultMetricType_Unsigned)
71-
MEMFAULT_METRICS_KEY_DEFINE(bt_connection_interval, kMemfaultMetricType_Unsigned)
71+
MEMFAULT_METRICS_KEY_DEFINE(bt_connection_interval_us, kMemfaultMetricType_Unsigned)
7272
MEMFAULT_METRICS_KEY_DEFINE(bt_connection_latency, kMemfaultMetricType_Unsigned)
7373
MEMFAULT_METRICS_KEY_DEFINE(bt_connection_timeout, kMemfaultMetricType_Unsigned)
7474
#if defined(CONFIG_BT_CTLR_CONN_RSSI)

0 commit comments

Comments
 (0)