drivers: ieee802154: rf2xx: Add tx mode direct

The current RF2XX driver only support IEEE802154_TX_MODE_CSMA_CA.  Add
IEEE802154_TX_MODE_DIRECT to allow transmit packets immediately without
performing random backoff, CCA and retransmission process.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
This commit is contained in:
Gerson Fernando Budke 2020-11-21 19:02:34 -03:00 committed by Carles Cufí
commit 195800145e
3 changed files with 26 additions and 3 deletions

View file

@ -537,9 +537,27 @@ static int rf2xx_tx(const struct device *dev,
struct rf2xx_context *ctx = dev->data;
int response = 0;
if (mode != IEEE802154_TX_MODE_CSMA_CA) {
NET_ERR("TX mode %d not supported", mode);
return -ENOTSUP;
if (ctx->tx_mode != mode) {
switch (mode) {
case IEEE802154_TX_MODE_DIRECT:
/* skip retries & csma/ca algorithm */
rf2xx_iface_reg_write(dev, RF2XX_XAH_CTRL_0_REG, 0x0E);
break;
case IEEE802154_TX_MODE_CSMA_CA:
/* backoff maxBE = 5, minBE = 3 */
rf2xx_iface_reg_write(dev, RF2XX_CSMA_BE_REG, 0x53);
/* max frame retries = 3, csma/ca retries = 4 */
rf2xx_iface_reg_write(dev, RF2XX_XAH_CTRL_0_REG, 0x38);
break;
case IEEE802154_TX_MODE_CCA:
case IEEE802154_TX_MODE_TXTIME:
case IEEE802154_TX_MODE_TXTIME_CCA:
default:
NET_ERR("TX mode %d not supported", mode);
return -ENOTSUP;
}
ctx->tx_mode = mode;
}
rf2xx_trx_set_tx_state(dev);
@ -681,6 +699,8 @@ static int power_on_and_setup(const struct device *dev)
}
rf2xx_iface_reg_write(dev, RF2XX_TRX_CTRL_2_REG, config);
ctx->tx_mode = IEEE802154_TX_MODE_CSMA_CA;
/* Configure INT behaviour */
config = (1 << RF2XX_RX_START) |
(1 << RF2XX_TRX_END);

View file

@ -126,6 +126,7 @@ struct rf2xx_context {
enum rf2xx_trx_model_t trx_model;
enum rf2xx_trx_state_trac_t trx_trac;
enum ieee802154_tx_mode tx_mode;
uint8_t mac_addr[8];
uint8_t pkt_lqi;
uint8_t pkt_ed;

View file

@ -18,6 +18,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <drivers/spi.h>
#include <drivers/gpio.h>
#include <net/ieee802154_radio.h>
#include "ieee802154_rf2xx.h"
#include "ieee802154_rf2xx_regs.h"
#include "ieee802154_rf2xx_iface.h"