Skip to content

Commit

Permalink
drivers: ieee802154: introduce network uptime API
Browse files Browse the repository at this point in the history
Optionally introduces the network uptime API into the IEEE 802.15.4
driver API.

Signed-off-by: Florian Grandel <[email protected]>
  • Loading branch information
fgrandel committed Oct 20, 2023
1 parent ccb8204 commit 86d8ab7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/zephyr/net/ieee802154_radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,10 @@ struct ieee802154_radio_api {
*
* See @ref net_time_t for semantic details.
*
* @note This is an alias for `radio_api->get_time_reference()
* ->get_time()` for drivers that support the network uptime
* reference API.
*
* @note requires IEEE802154_HW_TXTIME and/or IEEE802154_HW_RXTIME
* capabilities. Implementations SHALL be **isr-ok** and MUST NOT
* **sleep**. MAY be called in any interface state once the driver is
Expand All @@ -1763,6 +1767,21 @@ struct ieee802154_radio_api {
*/
net_time_t (*get_time)(const struct device *dev);

/**
* @brief Provides access to the full API of the underlying network
* uptime reference of the driver.
*
* @note Implementations SHALL be **isr-ok** and MUST NOT **sleep**. MAY
* be called in any interface state once the driver is fully initialized
* ("ready").
*
* @param dev pointer to IEEE 802.15.4 driver device
*
* @returns a pointer to the driver's underlying network uptime
* reference or NULL if not supported.
*/
const struct net_time_reference_api *(*get_time_reference)(const struct device *dev);

/**
* @brief Get the current estimated worst case accuracy (maximum ±
* deviation from the nominal frequency) of the network subsystem's
Expand Down
7 changes: 7 additions & 0 deletions subsys/net/l2/ieee802154/ieee802154_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ static inline void ieee802154_radio_remove_pan_id(struct net_if *iface, uint16_t
}
}

static inline const struct net_time_reference_api *
ieee802154_radio_get_time_reference(struct net_if *iface)
{
const struct ieee802154_radio_api *radio = net_if_get_device(iface)->api;

return radio->get_time_reference(net_if_get_device(iface));
}

/**
* MAC utilities
Expand Down
10 changes: 10 additions & 0 deletions tests/net/ieee802154/l2/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2023, Florian Grandel, Zephyr Project
#
# SPDX-License-Identifier: Apache-2.0

config IEEE802154_FAKE_DRIVER
bool "A fake driver for IEEE 802.15.4 L2 tests"
select NET_TIME_REFERENCE_CLOCK
default y

source "Kconfig.zephyr"
1 change: 1 addition & 0 deletions tests/net/ieee802154/l2/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CONFIG_NET_LOG=y
CONFIG_NET_L2_IEEE802154=y
CONFIG_NET_L2_IEEE802154_SECURITY=y
CONFIG_NET_L2_IEEE802154_SECURITY_CRYPTO_DEV_NAME="CRYPTO_MTLS"
CONFIG_IEEE802154_FAKE_DRIVER=y

CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_PACKET=y
Expand Down
7 changes: 7 additions & 0 deletions tests/net/ieee802154/l2/src/ieee802154_fake_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LOG_MODULE_REGISTER(net_ieee802154_fake_driver, LOG_LEVEL_DBG);
#include <zephyr/net/net_core.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_pkt.h>
#include <zephyr/net/net_time.h>

/** FAKE ieee802.15.4 driver **/
#include <zephyr/net/ieee802154_radio.h>
Expand Down Expand Up @@ -133,6 +134,11 @@ static int fake_attr_get(const struct device *dev, enum ieee802154_attr attr,
&drv_attr.phy_supported_channels, value);
}

static net_time_t fake_get_time(const struct device *dev)
{
return 0;
}

static void fake_iface_init(struct net_if *iface)
{
struct ieee802154_context *ctx = net_if_l2_data(iface);
Expand Down Expand Up @@ -167,6 +173,7 @@ static struct ieee802154_radio_api fake_radio_api = {
.stop = fake_stop,
.tx = fake_tx,
.attr_get = fake_attr_get,
.get_time = fake_get_time,
};

NET_DEVICE_INIT(fake, "fake_ieee802154",
Expand Down

0 comments on commit 86d8ab7

Please sign in to comment.