net/ieee802154/radio: use bitflags for capabilities

Signed-off-by: Jean Pierre Dudey <me@jeandudey.tech>
This commit is contained in:
Jean Pierre Dudey 2021-02-13 12:16:20 +01:00
parent 4bacc4f9b1
commit 243de6e501
3 changed files with 65 additions and 87 deletions

View File

@ -400,23 +400,6 @@ static int _off(ieee802154_dev_t *dev)
return -ENOTSUP; return -ENOTSUP;
} }
static bool _get_cap(ieee802154_dev_t *dev, ieee802154_rf_caps_t cap)
{
(void) dev;
switch (cap) {
case IEEE802154_CAP_24_GHZ:
case IEEE802154_CAP_AUTO_CSMA:
case IEEE802154_CAP_IRQ_CRC_ERROR:
case IEEE802154_CAP_IRQ_TX_DONE:
case IEEE802154_CAP_IRQ_CCA_DONE:
case IEEE802154_CAP_IRQ_RX_START:
case IEEE802154_CAP_IRQ_TX_START:
return true;
default:
return false;
}
}
static int _set_hw_addr_filter(ieee802154_dev_t *dev, const network_uint16_t *short_addr, static int _set_hw_addr_filter(ieee802154_dev_t *dev, const network_uint16_t *short_addr,
const eui64_t *ext_addr, const uint16_t *pan_id) const eui64_t *ext_addr, const uint16_t *pan_id)
{ {
@ -536,6 +519,14 @@ static int _set_csma_params(ieee802154_dev_t *dev, const ieee802154_csma_be_t *b
} }
static const ieee802154_radio_ops_t cc2538_rf_ops = { static const ieee802154_radio_ops_t cc2538_rf_ops = {
.caps = IEEE802154_CAP_24_GHZ
| IEEE802154_CAP_AUTO_CSMA
| IEEE802154_CAP_IRQ_CRC_ERROR
| IEEE802154_CAP_IRQ_TX_DONE
| IEEE802154_CAP_IRQ_CCA_DONE
| IEEE802154_CAP_IRQ_RX_START
| IEEE802154_CAP_IRQ_TX_START,
.write = _write, .write = _write,
.read = _read, .read = _read,
.request_transmit = _request_transmit, .request_transmit = _request_transmit,
@ -548,7 +539,6 @@ static const ieee802154_radio_ops_t cc2538_rf_ops = {
.confirm_set_trx_state = _confirm_set_trx_state, .confirm_set_trx_state = _confirm_set_trx_state,
.request_cca = _request_cca, .request_cca = _request_cca,
.confirm_cca = _confirm_cca, .confirm_cca = _confirm_cca,
.get_cap = _get_cap,
.set_cca_threshold = _set_cca_threshold, .set_cca_threshold = _set_cca_threshold,
.set_cca_mode = _set_cca_mode, .set_cca_mode = _set_cca_mode,
.config_phy = _config_phy, .config_phy = _config_phy,

View File

@ -661,22 +661,6 @@ static int _off(ieee802154_dev_t *dev)
return 0; return 0;
} }
static bool _get_cap(ieee802154_dev_t *dev, ieee802154_rf_caps_t cap)
{
(void) dev;
switch (cap) {
case IEEE802154_CAP_24_GHZ:
case IEEE802154_CAP_IRQ_CRC_ERROR:
case IEEE802154_CAP_IRQ_RX_START:
case IEEE802154_CAP_IRQ_TX_START:
case IEEE802154_CAP_IRQ_TX_DONE:
case IEEE802154_CAP_IRQ_CCA_DONE:
return true;
default:
return false;
}
}
int _len(ieee802154_dev_t *dev) int _len(ieee802154_dev_t *dev)
{ {
(void) dev; (void) dev;
@ -793,6 +777,13 @@ void nrf802154_setup(nrf802154_t *dev)
} }
static const ieee802154_radio_ops_t nrf802154_ops = { static const ieee802154_radio_ops_t nrf802154_ops = {
.caps = IEEE802154_CAP_24_GHZ
| IEEE802154_CAP_IRQ_CRC_ERROR
| IEEE802154_CAP_IRQ_RX_START
| IEEE802154_CAP_IRQ_TX_START
| IEEE802154_CAP_IRQ_TX_DONE
| IEEE802154_CAP_IRQ_CCA_DONE,
.write = _write, .write = _write,
.read = _read, .read = _read,
.request_transmit = _request_transmit, .request_transmit = _request_transmit,
@ -805,7 +796,6 @@ static const ieee802154_radio_ops_t nrf802154_ops = {
.confirm_set_trx_state = _confirm_set_trx_state, .confirm_set_trx_state = _confirm_set_trx_state,
.request_cca = _request_cca, .request_cca = _request_cca,
.confirm_cca = _confirm_cca, .confirm_cca = _confirm_cca,
.get_cap = _get_cap,
.set_cca_threshold = set_cca_threshold, .set_cca_threshold = set_cca_threshold,
.set_cca_mode = _set_cca_mode, .set_cca_mode = _set_cca_mode,
.config_phy = _config_phy, .config_phy = _config_phy,

View File

@ -29,6 +29,7 @@ extern "C" {
#include <stdbool.h> #include <stdbool.h>
#include "iolist.h" #include "iolist.h"
#include "sys/uio.h" #include "sys/uio.h"
#include "bitarithm.h"
#include "byteorder.h" #include "byteorder.h"
#include "net/eui64.h" #include "net/eui64.h"
@ -59,7 +60,7 @@ typedef enum {
* @note it's implicit that a radio supports @ref * @note it's implicit that a radio supports @ref
* IEEE802154_CAP_AUTO_CSMA if this cap is available * IEEE802154_CAP_AUTO_CSMA if this cap is available
*/ */
IEEE802154_CAP_FRAME_RETRANS, IEEE802154_CAP_FRAME_RETRANS = BIT0,
/** /**
* @brief the device supports Auto CSMA-CA * @brief the device supports Auto CSMA-CA
* *
@ -69,7 +70,7 @@ typedef enum {
* ieee802154_radio_ops::confirm_transmit. If it fails, the device reports * ieee802154_radio_ops::confirm_transmit. If it fails, the device reports
* @ref TX_STATUS_MEDIUM_BUSY. * @ref TX_STATUS_MEDIUM_BUSY.
*/ */
IEEE802154_CAP_AUTO_CSMA, IEEE802154_CAP_AUTO_CSMA = BIT1,
/** /**
* @brief the device support ACK timeout interrupt * @brief the device support ACK timeout interrupt
* *
@ -81,47 +82,47 @@ typedef enum {
* *
* The ACK frame is not indicated to the upper layer. * The ACK frame is not indicated to the upper layer.
*/ */
IEEE802154_CAP_IRQ_ACK_TIMEOUT, IEEE802154_CAP_IRQ_ACK_TIMEOUT = BIT2,
/** /**
* @brief the device supports the IEEE802.15.4 2.4 GHz band * @brief the device supports the IEEE802.15.4 2.4 GHz band
* *
* It's assumed that @ref IEEE802154_CAP_IRQ_TX_DONE is present. * It's assumed that @ref IEEE802154_CAP_IRQ_TX_DONE is present.
*/ */
IEEE802154_CAP_24_GHZ, IEEE802154_CAP_24_GHZ = BIT3,
/** /**
* @brief the device support the IEEE802.15.4 Sub GHz band * @brief the device support the IEEE802.15.4 Sub GHz band
*/ */
IEEE802154_CAP_SUB_GHZ, IEEE802154_CAP_SUB_GHZ = BIT4,
/** /**
* @brief the device reports reception off frames with invalid CRC. * @brief the device reports reception off frames with invalid CRC.
*/ */
IEEE802154_CAP_IRQ_CRC_ERROR, IEEE802154_CAP_IRQ_CRC_ERROR = BIT5,
/** /**
* @brief the device reports when the transmission is done * @brief the device reports when the transmission is done
*/ */
IEEE802154_CAP_IRQ_TX_DONE, IEEE802154_CAP_IRQ_TX_DONE = BIT6,
/** /**
* @brief the device reports the start of a frame (SFD) when received. * @brief the device reports the start of a frame (SFD) when received.
*/ */
IEEE802154_CAP_IRQ_RX_START, IEEE802154_CAP_IRQ_RX_START = BIT7,
/** /**
* @brief the device reports the start of a frame (SFD) was sent. * @brief the device reports the start of a frame (SFD) was sent.
*/ */
IEEE802154_CAP_IRQ_TX_START, IEEE802154_CAP_IRQ_TX_START = BIT8,
/** /**
* @brief the device reports the end of the CCA procedure * @brief the device reports the end of the CCA procedure
*/ */
IEEE802154_CAP_IRQ_CCA_DONE, IEEE802154_CAP_IRQ_CCA_DONE = BIT9,
/** /**
* @brief the device provides the number of retransmissions * @brief the device provides the number of retransmissions
* *
* It's assumed that @ref IEEE802154_CAP_FRAME_RETRANS is present. * It's assumed that @ref IEEE802154_CAP_FRAME_RETRANS is present.
*/ */
IEEE802154_CAP_FRAME_RETRANS_INFO, IEEE802154_CAP_FRAME_RETRANS_INFO = BIT10,
/** /**
* @brief the device retains all register values when off. * @brief the device retains all register values when off.
*/ */
IEEE802154_CAP_REG_RETENTION, IEEE802154_CAP_REG_RETENTION = BIT11,
} ieee802154_rf_caps_t; } ieee802154_rf_caps_t;
/** /**
@ -382,6 +383,14 @@ typedef struct {
* @brief Radio ops struct declaration * @brief Radio ops struct declaration
*/ */
struct ieee802154_radio_ops { struct ieee802154_radio_ops {
/**
* @brief Radio device capabilities
*
* This field contains bitflags of supported capabilities
* (@ref ieee802154_rf_caps_t) by the device.
*/
const uint16_t caps;
/** /**
* @brief Write a frame into the framebuffer. * @brief Write a frame into the framebuffer.
* *
@ -602,17 +611,6 @@ struct ieee802154_radio_ops {
*/ */
int (*confirm_cca)(ieee802154_dev_t *dev); int (*confirm_cca)(ieee802154_dev_t *dev);
/**
* @brief Get a cap from the radio
*
* @param[in] dev IEEE802.15.4 device descriptor
* @param cap cap to be checked
*
* @return true if the radio supports the cap
* @return false otherwise
*/
bool (*get_cap)(ieee802154_dev_t *dev, ieee802154_rf_caps_t cap);
/** /**
* @brief Set the threshold for the Energy Detection (first mode of CCA) * @brief Set the threshold for the Energy Detection (first mode of CCA)
* *
@ -998,8 +996,8 @@ static inline int ieee802154_radio_confirm_cca(ieee802154_dev_t *dev)
/** /**
* @brief Check if the device supports ACK timeout * @brief Check if the device supports ACK timeout
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_IRQ_ACK_TIMEOUT. * @ref IEEE802154_CAP_IRQ_ACK_TIMEOUT.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1008,14 +1006,14 @@ static inline int ieee802154_radio_confirm_cca(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_irq_ack_timeout(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_irq_ack_timeout(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_IRQ_ACK_TIMEOUT); return (dev->driver->caps & IEEE802154_CAP_IRQ_ACK_TIMEOUT);
} }
/** /**
* @brief Check if the device supports frame retransmissions (with CSMA-CA). * @brief Check if the device supports frame retransmissions (with CSMA-CA).
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_FRAME_RETRANS. * @ref IEEE802154_CAP_FRAME_RETRANS.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1024,14 +1022,14 @@ static inline bool ieee802154_radio_has_irq_ack_timeout(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_frame_retrans(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_frame_retrans(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_FRAME_RETRANS); return (dev->driver->caps & IEEE802154_CAP_FRAME_RETRANS);
} }
/** /**
* @brief Check if the device supports Auto CSMA-CA for transmissions. * @brief Check if the device supports Auto CSMA-CA for transmissions.
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_AUTO_CSMA. * @ref IEEE802154_CAP_AUTO_CSMA.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1040,14 +1038,14 @@ static inline bool ieee802154_radio_has_frame_retrans(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_auto_csma(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_auto_csma(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_AUTO_CSMA); return (dev->driver->caps & IEEE802154_CAP_AUTO_CSMA);
} }
/** /**
* @brief Check if the device supports the IEEE802.15.4 Sub-GHz band * @brief Check if the device supports the IEEE802.15.4 Sub-GHz band
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_SUB_GHZ. * @ref IEEE802154_CAP_SUB_GHZ.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1056,14 +1054,14 @@ static inline bool ieee802154_radio_has_auto_csma(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_sub_ghz(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_sub_ghz(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_SUB_GHZ); return (dev->driver->caps & IEEE802154_CAP_SUB_GHZ);
} }
/** /**
* @brief Check if the device supports the IEEE802.15.4 2.4 GHz band * @brief Check if the device supports the IEEE802.15.4 2.4 GHz band
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_24_GHZ. * @ref IEEE802154_CAP_24_GHZ.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1072,14 +1070,14 @@ static inline bool ieee802154_radio_has_sub_ghz(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_24_ghz(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_24_ghz(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_24_GHZ); return (dev->driver->caps & IEEE802154_CAP_24_GHZ);
} }
/** /**
* @brief Check if the device supports TX done interrupt * @brief Check if the device supports TX done interrupt
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_IRQ_TX_DONE. * @ref IEEE802154_CAP_IRQ_TX_DONE.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1088,14 +1086,14 @@ static inline bool ieee802154_radio_has_24_ghz(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_irq_tx_done(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_irq_tx_done(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_IRQ_TX_DONE); return (dev->driver->caps & IEEE802154_CAP_IRQ_TX_DONE);
} }
/** /**
* @brief Check if the device supports RX start interrupt * @brief Check if the device supports RX start interrupt
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_IRQ_RX_START. * @ref IEEE802154_CAP_IRQ_RX_START.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1104,14 +1102,14 @@ static inline bool ieee802154_radio_has_irq_tx_done(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_irq_rx_start(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_irq_rx_start(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_IRQ_RX_START); return (dev->driver->caps & IEEE802154_CAP_IRQ_RX_START);
} }
/** /**
* @brief Check if the device supports TX start interrupt * @brief Check if the device supports TX start interrupt
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_IRQ_TX_START. * @ref IEEE802154_CAP_IRQ_TX_START.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1120,13 +1118,13 @@ static inline bool ieee802154_radio_has_irq_rx_start(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_irq_tx_start(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_irq_tx_start(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_IRQ_TX_START); return (dev->driver->caps & IEEE802154_CAP_IRQ_TX_START);
} }
/** /**
* @brief Check if the device supports CCA done interrupt * @brief Check if the device supports CCA done interrupt
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps with @ref
* IEEE802154_CAP_IRQ_CCA_DONE. * IEEE802154_CAP_IRQ_CCA_DONE.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
@ -1136,15 +1134,15 @@ static inline bool ieee802154_radio_has_irq_tx_start(ieee802154_dev_t *dev)
*/ */
static inline bool ieee802154_radio_has_irq_cca_done(ieee802154_dev_t *dev) static inline bool ieee802154_radio_has_irq_cca_done(ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_IRQ_CCA_DONE); return (dev->driver->caps & IEEE802154_CAP_IRQ_CCA_DONE);
} }
/** /**
* @brief Check if the device reports the number of retransmissions of the last * @brief Check if the device reports the number of retransmissions of the last
* TX procedure. * TX procedure.
* *
* Internally this function calls ieee802154_radio_ops::get_cap with @ref * Internally this function reads ieee802154_radio_ops::caps and checks for
* IEEE802154_CAP_FRAME_RETRANS_INFO. * @ref IEEE802154_CAP_FRAME_RETRANS_INFO.
* *
* @param[in] dev IEEE802.15.4 device descriptor * @param[in] dev IEEE802.15.4 device descriptor
* *
@ -1154,7 +1152,7 @@ static inline bool ieee802154_radio_has_irq_cca_done(ieee802154_dev_t *dev)
static inline bool ieee802154_radio_has_frame_retrans_info( static inline bool ieee802154_radio_has_frame_retrans_info(
ieee802154_dev_t *dev) ieee802154_dev_t *dev)
{ {
return dev->driver->get_cap(dev, IEEE802154_CAP_FRAME_RETRANS_INFO); return (dev->driver->caps & IEEE802154_CAP_FRAME_RETRANS_INFO);
} }
/** /**