From 1fd4d41d760dcafc69fe14c7d71f13a5d68fc619 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 22 Apr 2022 14:24:42 +0200 Subject: [PATCH] driver/netdev_ieee802154: Make timestamp optional Also remove duplicate struct member. --- drivers/Makefile.dep | 6 +++ drivers/at86rf215/Makefile.dep | 4 -- drivers/at86rf215/Makefile.include | 1 - drivers/at86rf215/at86rf215_netdev.c | 7 ++-- drivers/include/net/netdev/ieee802154.h | 49 ++++++++++++++++++++++++- drivers/netdev/Kconfig | 10 ++++- makefiles/pseudomodules.inc.mk | 1 + tests/driver_at86rf215/Makefile | 2 +- 8 files changed, 68 insertions(+), 12 deletions(-) diff --git a/drivers/Makefile.dep b/drivers/Makefile.dep index 84dc17307d..398bdc36fd 100644 --- a/drivers/Makefile.dep +++ b/drivers/Makefile.dep @@ -244,3 +244,9 @@ ifneq (,$(filter-out netdev_default, $(filter netdev_%,$(USEMODULE)))) USEMODULE += netdev_register endif endif + +ifneq (,$(filter gnrc_netif_timestamp,$(USEMODULE))) + ifneq (,$(filter netdev_ieee802154,$(USEMODULE))) + USEMODULE += netdev_ieee802154_rx_timestamp + endif +endif diff --git a/drivers/at86rf215/Makefile.dep b/drivers/at86rf215/Makefile.dep index d079dfb38f..2810697566 100644 --- a/drivers/at86rf215/Makefile.dep +++ b/drivers/at86rf215/Makefile.dep @@ -33,7 +33,3 @@ endif USEMODULE += xtimer USEMODULE += ieee802154 USEMODULE += netdev_ieee802154 - -ifneq (,$(filter gnrc_netif_timestamp,$(USEMODULE))) - USEMODULE += at86rf215_timestamp -endif diff --git a/drivers/at86rf215/Makefile.include b/drivers/at86rf215/Makefile.include index 4b3b15ad81..0373011237 100644 --- a/drivers/at86rf215/Makefile.include +++ b/drivers/at86rf215/Makefile.include @@ -1,5 +1,4 @@ PSEUDOMODULES += at86rf215_batmon -PSEUDOMODULES += at86rf215_timestamp PSEUDOMODULES += at86rf215_subghz PSEUDOMODULES += at86rf215_24ghz PSEUDOMODULES += at86rf215_blocking_send diff --git a/drivers/at86rf215/at86rf215_netdev.c b/drivers/at86rf215/at86rf215_netdev.c index dce59bbc8b..fca5dbdef4 100644 --- a/drivers/at86rf215/at86rf215_netdev.c +++ b/drivers/at86rf215/at86rf215_netdev.c @@ -22,6 +22,7 @@ #include #include +#include "byteorder.h" #include "iolist.h" #include "net/eui64.h" @@ -204,14 +205,14 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info) netdev_ieee802154_rx_info_t *radio_info = info; radio_info->rssi = (int8_t) at86rf215_reg_read(dev, dev->RF->RG_EDV); - if (IS_USED(MODULE_AT86RF215_TIMESTAMP)) { + if (IS_USED(MODULE_NETDEV_IEEE802154_RX_TIMESTAMP)) { uint32_t rx_timestamp; at86rf215_reg_read_bytes(dev, dev->BBC->RG_CNT0, &rx_timestamp, sizeof(rx_timestamp)); /* convert counter value to ns */ - radio_info->timestamp = rx_timestamp * 1000ULL / 32; - radio_info->flags |= NETDEV_RX_IEEE802154_INFO_FLAG_TIMESTAMP; + uint64_t res = rx_timestamp * 1000ULL / 32; + netdev_ieee802154_rx_info_set_timestamp(radio_info, res); } } diff --git a/drivers/include/net/netdev/ieee802154.h b/drivers/include/net/netdev/ieee802154.h index 80409e041c..83c9789fa7 100644 --- a/drivers/include/net/netdev/ieee802154.h +++ b/drivers/include/net/netdev/ieee802154.h @@ -136,15 +136,60 @@ typedef struct { * @brief Received packet status information for IEEE 802.15.4 radios */ typedef struct netdev_ieee802154_rx_info { - uint64_t timestamp; /**< Timestamp value of a received frame in ns */ int16_t rssi; /**< RSSI of a received frame in dBm */ uint8_t lqi; /**< LQI of a received frame */ uint8_t flags; /**< Flags e.g. used to mark other fields as valid */ -#if IS_USED(MODULE_SOCK_AUX_TIMESTAP) +#if IS_USED(MODULE_NETDEV_IEEE802154_RX_TIMESTAMP) uint64_t timestamp; /**< Timestamp value of a received frame in ns */ #endif } netdev_ieee802154_rx_info_t; +/** + * @brief Write the given timestamp to the given RX info struct. + * + * @details This function is safe to call even when module + * `netdev_ieee802154_rx_timestamp` is not used. It will become a + * no-op then. + */ +static inline void netdev_ieee802154_rx_info_set_timestamp( + netdev_ieee802154_rx_info_t *dest, + uint64_t timestamp) +{ + (void)dest; + (void)timestamp; +#if IS_USED(MODULE_NETDEV_IEEE802154_RX_TIMESTAMP) + dest->timestamp = timestamp; + dest->flags |= NETDEV_RX_IEEE802154_INFO_FLAG_TIMESTAMP; +#endif +} + +/** + * @brief Get the timestamp to from the RX info. + * + * @details This function is safe to call even when module + * `netdev_ieee802154_rx_timestamp` is not used. It will become a + * no-op then. + * + * @retval 0 Success + * @retval -1 No timestamp present or module `netdev_ieee802154_rx_timestamp` + * not used + */ +static inline int netdev_ieee802154_rx_info_get_timestamp( + const netdev_ieee802154_rx_info_t *info, + uint64_t *dest) +{ + (void)info; + (void)dest; +#if IS_USED(MODULE_NETDEV_IEEE802154_RX_TIMESTAMP) + if (info->flags & NETDEV_RX_IEEE802154_INFO_FLAG_TIMESTAMP) { + *dest = info->timestamp; + return 0; + } +#endif + + return -1; +} + /** * @brief Reset function for ieee802154 common fields * diff --git a/drivers/netdev/Kconfig b/drivers/netdev/Kconfig index 8ea0bd35fa..5807707c68 100644 --- a/drivers/netdev/Kconfig +++ b/drivers/netdev/Kconfig @@ -1,4 +1,4 @@ -# Copyright (c) 2020 HAW Hamburg +# Copyright (c) 2022 Otto-von-Guericke-Universität Magdeburg # # This file is subject to the terms and conditions of the GNU Lesser # General Public License v2.1. See the file LICENSE in the top level @@ -9,4 +9,12 @@ menu "Network Device Drivers" config MODULE_NETDEV_DEFAULT bool "Enable default network devices on the platform" +menu "IEEE 802.15.4 Device Drivers" + visible if MODULE_NETDEV_IEEE802154 + +config MODULE_NETDEV_IEEE802154_RX_TIMESTAMP + bool "Timestamp received frames" + +endmenu # IEEE 802.15.4 Device Drivers + endmenu # Network Device Drivers diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index cc64d28a9a..4211bc240c 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -144,6 +144,7 @@ PSEUDOMODULES += mtd_write_page PSEUDOMODULES += nanocoap_% PSEUDOMODULES += netdev_default PSEUDOMODULES += netdev_ieee802154_% +PSEUDOMODULES += netdev_ieee802154_rx_timestamp PSEUDOMODULES += netdev_ieee802154 PSEUDOMODULES += netdev_eth PSEUDOMODULES += netdev_layer diff --git a/tests/driver_at86rf215/Makefile b/tests/driver_at86rf215/Makefile index b9ae2606aa..1681dfce5a 100644 --- a/tests/driver_at86rf215/Makefile +++ b/tests/driver_at86rf215/Makefile @@ -3,7 +3,7 @@ BOARD ?= openmote-b # the radio driver to test USEMODULE += at86rf215 USEMODULE += at86rf215_batmon -USEMODULE += at86rf215_timestamp +USEMODULE += netdev_ieee802154_rx_timestamp CFLAGS += -DCONFIG_NETDEV_REGISTER_SIGNAL