Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: ieee802154: New API for modulated carrier wave transmission. #82134

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions drivers/ieee802154/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 21 additions & 3 deletions drivers/ieee802154/ieee802154_nrf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions include/zephyr/net/ieee802154_radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -1786,6 +1787,30 @@ struct ieee802154_radio_api {
*/
int (*continuous_carrier)(const struct device *dev);

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to surround this with a Kconfig, if it is not normally available during regular device operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cfriedt Both continuous_carrier and modulated_carrier on the nRF platform driver require extra Kconfig CONFIG_NRF_802154_CARRIER_FUNCTIONS but I don't see why other platforms would have to follow the same logic. So I would prefer to leave it as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply have a generic carrier Kconfig option here and apply the same one in the Nordic driver (or both?)

Additional reasons:

why expose a NULL function pointer to API consumers?

If a device isn't built for test and is never intended to transmit CW, then code won't accidentally compile or call it, or worse, make that functionality available in the field, possibly jamming other devices?

Zephyr should be minimal by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at updated version.

* @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.
*
Expand Down
2 changes: 1 addition & 1 deletion modules/hal_nordic/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as OPENTHREAD_DIAG now depends on IEEE802154_CARRIER_FUNCTIONS isn't this or statement redundant? We will never have a situation when diag is enabled but carrier functions is disabled. so maybe just default y if IEEE802154_CARRIER_FUNCTIONS would be enough?

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.
Expand Down
1 change: 1 addition & 0 deletions modules/openthread/Kconfig.features
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions modules/openthread/platform/diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -94,6 +95,7 @@ otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable)

return platformRadioTransmitCarrier(aInstance, aEnable);
}
#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */

void otPlatDiagAlarmCallback(otInstance *aInstance)
{
Expand Down
2 changes: 2 additions & 0 deletions modules/openthread/platform/platform-zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions modules/openthread/platform/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -845,6 +846,7 @@ otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable)

return OT_ERROR_NONE;
}
#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */

otRadioState otPlatRadioGetState(otInstance *aInstance)
{
Expand Down
Loading