Skip to content

Commit 6e34acc

Browse files
alexapostolukartben
authored andcommitted
Bluetooth: Host: Use macro for nanoseconds per second
Use the macro NSEC_PER_SEC defined in sys_clock.h for nanoseconds per second when updating write stats. Signed-off-by: Alex Apostolu <[email protected]>
1 parent fe7f71b commit 6e34acc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

subsys/bluetooth/host/shell/gatt.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <zephyr/sys/__assert.h>
2828
#include <zephyr/sys/byteorder.h>
2929
#include <zephyr/sys/time_units.h>
30+
#include <zephyr/sys_clock.h>
3031
#include <zephyr/sys/util.h>
3132
#include <sys/types.h>
3233

@@ -61,14 +62,14 @@ static void update_write_stats(uint16_t len)
6162
/* if last data rx-ed was greater than 1 second in the past,
6263
* reset the metrics.
6364
*/
64-
if (delta > 1000000000) {
65+
if (delta > NSEC_PER_SEC) {
6566
write_stats.len = 0U;
6667
write_stats.rate = 0U;
6768
cycle_stamp = k_cycle_get_32();
6869
} else {
6970
write_stats.len += len;
7071
write_stats.rate = ((uint64_t)write_stats.len << 3) *
71-
1000000000U / delta;
72+
NSEC_PER_SEC / delta;
7273
}
7374
}
7475

subsys/bluetooth/host/shell/l2cap.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <zephyr/shell/shell_string_conv.h>
3030
#include <zephyr/sys/atomic_types.h>
3131
#include <zephyr/sys/byteorder.h>
32+
#include <zephyr/sys_clock.h>
3233
#include <zephyr/kernel.h>
3334
#include <zephyr/sys/time_units.h>
3435
#include <zephyr/sys/util.h>
@@ -76,13 +77,13 @@ static int l2cap_recv_metrics(struct bt_l2cap_chan *chan, struct net_buf *buf)
7677
/* if last data rx-ed was greater than 1 second in the past,
7778
* reset the metrics.
7879
*/
79-
if (delta > 1000000000) {
80+
if (delta > NSEC_PER_SEC) {
8081
len = 0U;
8182
l2cap_rate = 0U;
8283
cycle_stamp = k_cycle_get_32();
8384
} else {
8485
len += buf->len;
85-
l2cap_rate = ((uint64_t)len << 3) * 1000000000U / delta;
86+
l2cap_rate = ((uint64_t)len << 3) * NSEC_PER_SEC / delta;
8687
}
8788

8889
return 0;

0 commit comments

Comments
 (0)