diff --git a/drivers/ieee802154/Kconfig b/drivers/ieee802154/Kconfig index a4e4e6d307d..af405551f63 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 613c913868b..a74606edf44 100644 --- a/drivers/ieee802154/ieee802154_nrf5.c +++ b/drivers/ieee802154/ieee802154_nrf5.c @@ -720,7 +720,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); @@ -737,6 +737,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) @@ -1244,15 +1261,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 f9a557beba0..e2ab96ffac4 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 dd4e0a0859b..f29b77e120e 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 ccdd3236d38..514b9b85745 100644 --- a/modules/openthread/Kconfig.features +++ b/modules/openthread/Kconfig.features @@ -136,6 +136,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 a55368bb10f..b92e34209b8 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 8e2d91bd5ef..94fd04d7057 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 7e2943e734f..33fc7b42bbf 100644 --- a/modules/openthread/platform/radio.c +++ b/modules/openthread/platform/radio.c @@ -809,6 +809,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) { @@ -831,6 +832,7 @@ otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable) return OT_ERROR_NONE; } +#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */ otRadioState otPlatRadioGetState(otInstance *aInstance) {