at86rf2xx.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
9 #pragma once
10 
31 #include <stdint.h>
32 #include <stdbool.h>
33 
34 #include "board.h"
35 #include "kernel_defines.h"
36 #include "net/netdev.h"
37 #include "net/netdev/ieee802154.h"
38 #include "net/gnrc/nettype.h"
39 
40 /* we need no peripherals for memory mapped radios */
41 #if !defined(MODULE_AT86RFA1) && !defined(MODULE_AT86RFR2)
42 #include "periph/spi.h"
43 #include "periph/gpio.h"
44 #endif
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
53 #define AT86RF2XX_MAX_PKT_LENGTH (IEEE802154_FRAME_LEN_MAX)
54 
59 #ifdef MODULE_AT86RF212B
60 /* the AT86RF212B has a sub-1GHz radio */
61 #define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN_SUBGHZ)
62 #define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX_SUBGHZ)
63 #define AT86RF2XX_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_SUBGHZ_CHANNEL)
64 /* Page 2 is O-QPSK 100 kbit/s (channel 0), or 250 kbit/s (channels 1-10) */
65 #define AT86RF2XX_DEFAULT_PAGE (CONFIG_IEEE802154_DEFAULT_SUBGHZ_PAGE)
66 #else
67 #define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN)
68 #define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX)
69 #define AT86RF2XX_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_CHANNEL)
70 #define AT86RF2XX_DEFAULT_PAGE (0)
71 /* Only page 0 is supported in the 2.4 GHz band */
72 #endif
78 #define AT86RF2XX_DEFAULT_TXPOWER (CONFIG_IEEE802154_DEFAULT_TXPOWER)
79 
83 #if MODULE_AT86RF233
84 # define RSSI_BASE_VAL (-94)
85 #elif MODULE_AT86RF212B
90 # define RSSI_BASE_VAL (-98)
91 #elif MODULE_AT86RFA1 || MODULE_AT86RFR2
92 # define RSSI_BASE_VAL (-90)
93 #else
94 # define RSSI_BASE_VAL (-91)
95 #endif
96 
100 #if MODULE_AT86RF233
101 # define MIN_RX_SENSITIVITY (-101)
102 #elif MODULE_AT86RF212B
103 # define MIN_RX_SENSITIVITY (-110)
104 #elif MODULE_AT86RFA1 || MODULE_AT86RFR2
105 # define MIN_RX_SENSITIVITY (-100)
106 #else
107 # define MIN_RX_SENSITIVITY (-101)
108 #endif
109 
113 #if IS_USED(MODULE_AT86RFA1) || IS_USED(MODULE_AT86RFR2)
114 #define AT86RF2XX_IS_PERIPH (1)
115 #else
116 #define AT86RF2XX_IS_PERIPH (0)
117 #endif
118 
122 #if defined(MODULE_AT86RF231) || IS_ACTIVE(AT86RF2XX_PERIPH)
123 #define AT86RF2XX_HAVE_ED_REGISTER (1)
124 #else
125 #define AT86RF2XX_HAVE_ED_REGISTER (0)
126 #endif
127 
131 #ifdef MODULE_AT86RF212B
132 #define AT86RF2XX_HAVE_SUBGHZ (1)
133 #else
134 #define AT86RF2XX_HAVE_SUBGHZ (0)
135 #endif
136 
137 #if defined(DOXYGEN) || defined(MODULE_AT86RF232) || defined(MODULE_AT86RF233) || defined(MODULE_AT86RFR2)
144 #define AT86RF2XX_HAVE_RETRIES (1)
145 #else
146 #define AT86RF2XX_HAVE_RETRIES (0)
147 #endif
148 
155 #if AT86RF2XX_HAVE_RETRIES && defined(AT86RF2XX_REG__XAH_CTRL_2)
156 #define AT86RF2XX_HAVE_RETRIES_REG (1)
157 #else
158 #define AT86RF2XX_HAVE_RETRIES_REG (0)
159 #endif
160 
164 #ifdef AT86RF2XX_REG__IRQ_MASK1
165 #define AT86RF2XX_HAVE_TX_START_IRQ (1)
166 #else
167 #define AT86RF2XX_HAVE_TX_START_IRQ (0)
168 #endif
169 
177 #if defined(MODULE_AT86RF233) || defined(MODULE_AT86RF231) || defined(MODULE_AT86RFA1) || defined(MODULE_AT86RFR2)
178 #ifndef AT86RF2XX_RANDOM_NUMBER_GENERATOR
179 #define AT86RF2XX_RANDOM_NUMBER_GENERATOR (1)
180 #endif
181 #else
182 #ifndef AT86RF2XX_RANDOM_NUMBER_GENERATOR
183 #define AT86RF2XX_RANDOM_NUMBER_GENERATOR (0)
184 #endif
185 #endif
186 
195 #if defined(MODULE_AT86RF233) || defined(MODULE_AT86RFR2)
196 #ifndef AT86RF2XX_SMART_IDLE_LISTENING
197 #define AT86RF2XX_SMART_IDLE_LISTENING (1)
198 #endif
199 #else
200 #define AT86RF2XX_SMART_IDLE_LISTENING (0)
201 #endif
202 
207 #define AT86RF2XX_STATE_P_ON (0x00)
208 #define AT86RF2XX_STATE_BUSY_RX (0x01)
209 #define AT86RF2XX_STATE_BUSY_TX (0x02)
210 #define AT86RF2XX_STATE_FORCE_TRX_OFF (0x03)
211 #define AT86RF2XX_STATE_RX_ON (0x06)
212 #define AT86RF2XX_STATE_TRX_OFF (0x08)
213 #define AT86RF2XX_STATE_PLL_ON (0x09)
214 #define AT86RF2XX_STATE_SLEEP (0x0f)
215 #define AT86RF2XX_STATE_BUSY_RX_AACK (0x11)
216 #define AT86RF2XX_STATE_BUSY_TX_ARET (0x12)
217 #define AT86RF2XX_STATE_RX_AACK_ON (0x16)
218 #define AT86RF2XX_STATE_TX_ARET_ON (0x19)
219 #define AT86RF2XX_STATE_IN_PROGRESS (0x1f)
226 #define AT86RF2XX_OPT_CSMA (0x0010)
227 #define AT86RF2XX_OPT_PROMISCUOUS (0x0020)
228 #define AT86RF2XX_OPT_PRELOADING (0x0040)
229 #define AT86RF2XX_OPT_AUTOACK (0x0080)
230 #define AT86RF2XX_OPT_ACK_PENDING (0x0100)
234 #if IS_ACTIVE(AT86RF2XX_BASIC_MODE) || defined(DOXYGEN)
238 #define AT86RF2XX_PHY_STATE_RX AT86RF2XX_STATE_RX_ON
242 #define AT86RF2XX_PHY_STATE_RX_BUSY AT86RF2XX_STATE_BUSY_RX
246 #define AT86RF2XX_PHY_STATE_TX AT86RF2XX_STATE_PLL_ON
250 #define AT86RF2XX_PHY_STATE_TX_BUSY AT86RF2XX_STATE_BUSY_TX
251 #else
252 #define AT86RF2XX_PHY_STATE_RX AT86RF2XX_STATE_RX_AACK_ON
253 #define AT86RF2XX_PHY_STATE_RX_BUSY AT86RF2XX_STATE_BUSY_RX_AACK
254 #define AT86RF2XX_PHY_STATE_TX AT86RF2XX_STATE_TX_ARET_ON
255 #define AT86RF2XX_PHY_STATE_TX_BUSY AT86RF2XX_STATE_BUSY_TX_ARET
256 #endif /* IS_ACTIVE(AT86RF2XX_BASIC_MODE) */
257 
258 #if AT86RF2XX_IS_PERIPH
262 typedef void at86rf2xx_params_t;
263 #else
267 typedef struct at86rf2xx_params {
268  spi_t spi;
271  gpio_t int_pin;
272  gpio_t sleep_pin;
273  gpio_t reset_pin;
275 #endif
276 
282 typedef struct {
284 #if AT86RF2XX_IS_PERIPH
285  /* ATmega256rfr2 signals transceiver events with different interrupts
286  * they have to be stored to mimic the same flow as external transceiver
287  * Use irq_status to map saved interrupts of SOC transceiver,
288  * as they clear after IRQ callback.
289  *
290  * irq_status = IRQ_STATUS
291  */
292  uint8_t irq_status;
293 #else
294  /* device specific fields */
296 #endif
297  uint16_t flags;
298  uint8_t state;
299  uint8_t tx_frame_len;
300 #ifdef MODULE_AT86RF212B
301  /* Only AT86RF212B supports multiple pages (PHY modes) */
302  uint8_t page;
303 #endif
304  uint8_t idle_state;
305  uint8_t pending_tx;
308 #if AT86RF2XX_HAVE_RETRIES
309  /* Only radios with the XAH_CTRL_2 register support frame retry reporting */
310  int8_t tx_retries;
311 #endif
312 } at86rf2xx_t;
313 
322 void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params, uint8_t index);
323 
330 
338 
346 
354 
363 
378 int at86rf2xx_set_rate(at86rf2xx_t *dev, uint8_t rate);
379 
386 void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
387 
400 void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower, uint8_t channel);
401 
410 
422 void at86rf2xx_set_rxsensitivity(const at86rf2xx_t *dev, int8_t rxsens);
423 
432 
443 void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max);
444 
453 
465 void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries);
466 
478  uint8_t min, uint8_t max);
479 
486 void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2]);
487 
496 
503 void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value);
504 
513 
521 void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state);
522 
531 uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state);
532 
542 
553 size_t at86rf2xx_tx_load(at86rf2xx_t *dev, const uint8_t *data,
554  size_t len, size_t offset);
555 
562 
574 
584 
592 
593 #ifdef __cplusplus
594 }
595 #endif
596 
spi_clk_t
Definition: periph_cpu.h:351
Definitions for netdev common IEEE 802.15.4 code.
Definitions low-level network driver interface.
Low-level GPIO peripheral driver interface definitions.
int at86rf2xx_set_rate(at86rf2xx_t *dev, uint8_t rate)
Set the current O-QPSK rate mode of the PHY rate modes > 0 are proprietary.
void at86rf2xx_reset(at86rf2xx_t *dev)
Trigger a hardware reset and configure radio with default values.
int8_t at86rf2xx_get_cca_threshold(const at86rf2xx_t *dev)
Get the CCA threshold value.
void at86rf2xx_disable_smart_idle(at86rf2xx_t *dev)
Disable the smart receive technology (SRT)
void at86rf2xx_tx_prepare(at86rf2xx_t *dev)
Prepare for sending of data.
void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan)
Set the PAN ID of the given device.
bool at86rf2xx_cca(at86rf2xx_t *dev)
Perform one manual channel clear assessment (CCA)
size_t at86rf2xx_tx_load(at86rf2xx_t *dev, const uint8_t *data, size_t len, size_t offset)
Load chunks of data into the transmit buffer of the given device.
void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value)
Set the CCA threshold value.
void at86rf2xx_tx_exec(at86rf2xx_t *dev)
Trigger sending of data previously loaded into transmit buffer.
void at86rf2xx_set_addr_long(at86rf2xx_t *dev, const eui64_t *addr)
Set the long address of the given device.
void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries)
Set the maximum number of channel access attempts per frame (CSMA)
uint8_t at86rf2xx_get_rate(at86rf2xx_t *dev)
Get the current O-QPSK rate mode of the PHY.
void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2])
Set seed for CSMA random backoff.
uint8_t at86rf2xx_get_phy_mode(at86rf2xx_t *dev)
Get the PHY mode of the given device.
uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
Set the state of the given device (trigger a state change)
void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params, uint8_t index)
Setup an AT86RF2xx based device state.
int8_t at86rf2xx_get_rxsensitivity(const at86rf2xx_t *dev)
Get the configured receiver sensitivity of the given device [in dBm].
uint8_t at86rf2xx_get_csma_max_retries(const at86rf2xx_t *dev)
Get the maximum number of channel access attempts per frame (CSMA)
struct at86rf2xx_params at86rf2xx_params_t
struct holding all params needed for device initialization
void at86rf2xx_enable_smart_idle(at86rf2xx_t *dev)
Enable the smart receive technology (SRT)
void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max)
Set the maximum number of retransmissions.
void at86rf2xx_set_csma_backoff_exp(const at86rf2xx_t *dev, uint8_t min, uint8_t max)
Set the min and max backoff exponent for CSMA/CA.
void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
uint8_t at86rf2xx_get_max_retries(const at86rf2xx_t *dev)
Get the maximum number of retransmissions.
void at86rf2xx_set_addr_short(at86rf2xx_t *dev, const network_uint16_t *addr)
Set the short address of the given device.
void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower, uint8_t channel)
Set the transmission power of the given device [in dBm].
void at86rf2xx_set_rxsensitivity(const at86rf2xx_t *dev, int8_t rxsens)
Set the receiver sensitivity of the given device [in dBm].
int8_t at86rf2xx_get_ed_level(at86rf2xx_t *dev)
Get the latest ED level measurement.
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition: spi.h:135
Common macros and compiler attributes/pragmas configuration.
Protocol type definitions.
Low-level SPI peripheral driver interface definition.
struct holding all params needed for device initialization
Definition: at86rf2xx.h:267
spi_t spi
SPI bus the device is connected to.
Definition: at86rf2xx.h:268
spi_cs_t cs_pin
GPIO pin connected to chip select.
Definition: at86rf2xx.h:270
gpio_t reset_pin
GPIO pin connected to the reset pin.
Definition: at86rf2xx.h:273
gpio_t sleep_pin
GPIO pin connected to the sleep pin.
Definition: at86rf2xx.h:272
gpio_t int_pin
GPIO pin connected to the interrupt pin.
Definition: at86rf2xx.h:271
spi_clk_t spi_clk
SPI clock speed to use.
Definition: at86rf2xx.h:269
Device descriptor for AT86RF2XX radio devices.
Definition: at86rf2xx.h:282
int8_t tx_retries
Number of NOACK retransmissions.
Definition: at86rf2xx.h:310
uint8_t pending_tx
keep track of pending TX calls this is required to know when to return to at86rf2xx_t::idle_state
Definition: at86rf2xx.h:305
uint8_t tx_frame_len
length of the current TX frame
Definition: at86rf2xx.h:299
netdev_ieee802154_t netdev
netdev parent struct
Definition: at86rf2xx.h:283
uint8_t idle_state
state to return to after sending
Definition: at86rf2xx.h:304
uint8_t state
current state of the radio
Definition: at86rf2xx.h:298
at86rf2xx_params_t params
parameters for initialization
Definition: at86rf2xx.h:295
uint16_t flags
Device specific flags.
Definition: at86rf2xx.h:297
Extended structure to hold IEEE 802.15.4 driver state.
Definition: ieee802154.h:100
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:73
Data type to represent an EUI-64.
Definition: eui64.h:55