From bcf2ba6653d159270e2da81c52d5af65aaa3880f Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Wed, 27 Nov 2024 14:00:25 +0100 Subject: [PATCH] drivers: ieee802154: New API for modulated carrier wave transmission. Added new API function to start modulated carrier wave transmission Signed-off-by: Przemyslaw Bida --- drivers/ieee802154/Kconfig | 5 ++++ drivers/ieee802154/ieee802154_nrf5.c | 24 +++++++++++++++--- include/zephyr/net/ieee802154_radio.h | 25 +++++++++++++++++++ modules/hal_nordic/Kconfig | 2 +- modules/openthread/Kconfig.features | 1 + modules/openthread/platform/diag.c | 2 ++ modules/openthread/platform/platform-zephyr.h | 2 ++ modules/openthread/platform/radio.c | 2 ++ 8 files changed, 59 insertions(+), 4 deletions(-) diff --git a/drivers/ieee802154/Kconfig b/drivers/ieee802154/Kconfig index a4e4e6d307dbec..af405551f63251 100644 --- a/drivers/ieee802154/Kconfig +++ b/drivers/ieee802154/Kconfig @@ -100,6 +100,11 @@ config IEEE802154_SELECTIVE_TXCHANNEL this Kconfig option is enabled. If the Kconfig option is disabled the drivers MUST NOT have the capability. +config IEEE802154_CARRIER_FUNCTIONS + bool "Support for carrier functions" + help + Enable support for functions such as modulated carrier and continuous carrier. + module = IEEE802154_DRIVER module-str = IEEE 802.15.4 driver module-help = Sets log level for IEEE 802.15.4 Device Drivers. diff --git a/drivers/ieee802154/ieee802154_nrf5.c b/drivers/ieee802154/ieee802154_nrf5.c index e9a0433d3b5915..556ae9e0a36aa6 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -730,7 +730,7 @@ static int nrf5_stop(const struct device *dev) return 0; } -#if defined(CONFIG_NRF_802154_CARRIER_FUNCTIONS) +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) static int nrf5_continuous_carrier(const struct device *dev) { ARG_UNUSED(dev); @@ -747,6 +747,23 @@ static int nrf5_continuous_carrier(const struct device *dev) return 0; } + +static int nrf_modulated_carrier(const struct device *dev, const uint8_t *data) +{ + ARG_UNUSED(dev); + + nrf_802154_tx_power_set(nrf5_data.txpwr); + + if (!nrf_802154_modulated_carrier(data)) { + LOG_ERR("Failed to enter modulated carrier state"); + return -EIO; + } + + LOG_DBG("Modulated carrier wave transmission started (channel: %d)", + nrf_802154_channel_get()); + + return 0; +} #endif #if !defined(CONFIG_IEEE802154_NRF5_EXT_IRQ_MGMT) @@ -1271,15 +1288,16 @@ static const struct ieee802154_radio_api nrf5_radio_api = { .set_txpower = nrf5_set_txpower, .start = nrf5_start, .stop = nrf5_stop, -#if defined(CONFIG_NRF_802154_CARRIER_FUNCTIONS) +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) .continuous_carrier = nrf5_continuous_carrier, + .modulated_carrier = nrf_modulated_carrier, #endif .tx = nrf5_tx, .ed_scan = nrf5_energy_scan_start, .get_time = nrf5_get_time, .get_sch_acc = nrf5_get_acc, .configure = nrf5_configure, - .attr_get = nrf5_attr_get + .attr_get = nrf5_attr_get, }; #if defined(CONFIG_NET_L2_IEEE802154) diff --git a/include/zephyr/net/ieee802154_radio.h b/include/zephyr/net/ieee802154_radio.h index f9a557beba0dbf..e2ab96ffac47db 100644 --- a/include/zephyr/net/ieee802154_radio.h +++ b/include/zephyr/net/ieee802154_radio.h @@ -1765,6 +1765,7 @@ struct ieee802154_radio_api { */ int (*stop)(const struct device *dev); +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) /** * @brief Start continuous carrier wave transmission. * @@ -1786,6 +1787,30 @@ struct ieee802154_radio_api { */ int (*continuous_carrier)(const struct device *dev); + /** + * @brief Start modulated carrier wave transmission. + * + * @details When the radio is emitting modulated carrier signals, it + * blocks all transmissions on the selected channel. + * This function is to be called only during radio + * tests. Do not use it during normal device operation. + * + * @note Implementations MAY **sleep** and will usually NOT be + * **isr-ok**. MAY be called in any interface state once the driver is + * fully initialized ("ready"). + * + * @param dev pointer to IEEE 802.15.4 driver device + * @param data Pointer to a buffer to modulate the carrier with. + * The first byte is the data length. + * + * @retval 0 modulated carrier wave transmission started + * @retval -EALREADY The driver was already in "TESTING" state and + * emitting a modulated carrier. + * @retval -EIO not started + */ + int (*modulated_carrier)(const struct device *dev, const uint8_t *data); +#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */ + /** * @brief Set or update driver configuration. * diff --git a/modules/hal_nordic/Kconfig b/modules/hal_nordic/Kconfig index dd4e0a0859b1f3..f29b77e120e50d 100644 --- a/modules/hal_nordic/Kconfig +++ b/modules/hal_nordic/Kconfig @@ -204,7 +204,7 @@ config NRF_802154_SECURITY_KEY_STORAGE_SIZE config NRF_802154_CARRIER_FUNCTIONS bool "nRF 802.15.4 carrier functions" - default y if OPENTHREAD_DIAG + default y if (OPENTHREAD_DIAG || IEEE802154_CARRIER_FUNCTIONS) help This option enables functions such as modulated carrier and continuous carrier. If this option is modified on a multicore SoC, its remote counterpart must be set to the exact same value. diff --git a/modules/openthread/Kconfig.features b/modules/openthread/Kconfig.features index 17031467b7c556..4c84a698c24c8f 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -144,6 +144,7 @@ config OPENTHREAD_DHCP6_SERVER config OPENTHREAD_DIAG bool "Diagnostic functions support" + depends on IEEE802154_CARRIER_FUNCTIONS help Enable OpenThread CLI diagnostic commands diff --git a/modules/openthread/platform/diag.c b/modules/openthread/platform/diag.c index a55368bb10fbed..b92e34209b80cb 100644 --- a/modules/openthread/platform/diag.c +++ b/modules/openthread/platform/diag.c @@ -86,6 +86,7 @@ void otPlatDiagRadioReceived(otInstance *aInstance, ARG_UNUSED(aError); } +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable) { if (!otPlatDiagModeGet()) { @@ -94,6 +95,7 @@ otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable) return platformRadioTransmitCarrier(aInstance, aEnable); } +#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */ void otPlatDiagAlarmCallback(otInstance *aInstance) { diff --git a/modules/openthread/platform/platform-zephyr.h b/modules/openthread/platform/platform-zephyr.h index 8e2d91bd5ef77b..94fd04d70579ac 100644 --- a/modules/openthread/platform/platform-zephyr.h +++ b/modules/openthread/platform/platform-zephyr.h @@ -70,10 +70,12 @@ void platformUartPanic(void); */ uint16_t platformRadioChannelGet(otInstance *aInstance); +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) /** * Start/stop continuous carrier wave transmission. */ otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable); +#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */ /** * This function initializes the random number service used by OpenThread. diff --git a/modules/openthread/platform/radio.c b/modules/openthread/platform/radio.c index 72f25eedc1d723..008dab009930f5 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -823,6 +823,7 @@ otError otPlatRadioReceiveAt(otInstance *aInstance, uint8_t aChannel, } #endif +#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS) otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable) { if (radio_api->continuous_carrier == NULL) { @@ -845,6 +846,7 @@ otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable) return OT_ERROR_NONE; } +#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */ otRadioState otPlatRadioGetState(otInstance *aInstance) {