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 
29 #ifndef AT86RF2XX_H
30 #define AT86RF2XX_H
31 
32 #include <stdint.h>
33 #include <stdbool.h>
34 
35 #include "board.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 (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 (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 (IEEE802154_DEFAULT_CHANNEL)
70 /* Only page 0 is supported in the 2.4 GHz band */
71 #endif
72 
77 #define AT86RF2XX_DEFAULT_TXPOWER (IEEE802154_DEFAULT_TXPOWER)
78 
82 #if MODULE_AT86RF233
83 # define RSSI_BASE_VAL (-94)
84 #elif MODULE_AT86RF212B
85 
89 # define RSSI_BASE_VAL (-98)
90 #elif MODULE_AT86RFA1 || MODULE_AT86RFR2
91 # define RSSI_BASE_VAL (-90)
92 #else
93 # define RSSI_BASE_VAL (-91)
94 #endif
95 
99 #if MODULE_AT86RF233
100 # define MAX_RX_SENSITIVITY (-52)
101 #elif MODULE_AT86RF212B
102 # define MAX_RX_SENSITIVITY (-54)
103 #elif MODULE_AT86RFA1 || MODULE_AT86RFR2
104 # define MAX_RX_SENSITIVITY (-48)
105 #else
106 # define MAX_RX_SENSITIVITY (-49)
107 #endif
108 
112 #if MODULE_AT86RF233
113 # define MIN_RX_SENSITIVITY (-101)
114 #elif MODULE_AT86RF212B
115 # define MIN_RX_SENSITIVITY (-110)
116 #elif MODULE_AT86RFA1 || MODULE_AT86RFR2
117 # define MIN_RX_SENSITIVITY (-100)
118 #else
119 # define MIN_RX_SENSITIVITY (-101)
120 #endif
121 
122 #if defined(DOXYGEN) || defined(MODULE_AT86RF232) || defined(MODULE_AT86RF233)
123 
131 #define AT86RF2XX_HAVE_RETRIES (1)
132 #else
133 #define AT86RF2XX_HAVE_RETRIES (0)
134 #endif
135 
143 #if defined(MODULE_AT86RF233) || defined(MODULE_AT86RF231) || defined(MODULE_AT86RFA1) || defined(MODULE_AT86RFR2)
144 #ifndef AT86RF2XX_RANDOM_NUMBER_GENERATOR
145 #define AT86RF2XX_RANDOM_NUMBER_GENERATOR (1)
146 #endif
147 #else
148 #ifndef AT86RF2XX_RANDOM_NUMBER_GENERATOR
149 #define AT86RF2XX_RANDOM_NUMBER_GENERATOR (0)
150 #endif
151 #endif
152 
161 #if defined(MODULE_AT86RF233) || defined(MODULE_AT86RFR2)
162 #ifndef AT86RF2XX_SMART_IDLE_LISTENING
163 #define AT86RF2XX_SMART_IDLE_LISTENING (1)
164 #endif
165 #else
166 #define AT86RF2XX_SMART_IDLE_LISTENING (0)
167 #endif
168 
173 #define AT86RF2XX_STATE_P_ON (0x00)
174 #define AT86RF2XX_STATE_BUSY_RX (0x01)
175 #define AT86RF2XX_STATE_BUSY_TX (0x02)
176 #define AT86RF2XX_STATE_FORCE_TRX_OFF (0x03)
177 #define AT86RF2XX_STATE_RX_ON (0x06)
178 #define AT86RF2XX_STATE_TRX_OFF (0x08)
179 #define AT86RF2XX_STATE_PLL_ON (0x09)
180 #define AT86RF2XX_STATE_SLEEP (0x0f)
181 #define AT86RF2XX_STATE_BUSY_RX_AACK (0x11)
182 #define AT86RF2XX_STATE_BUSY_TX_ARET (0x12)
183 #define AT86RF2XX_STATE_RX_AACK_ON (0x16)
184 #define AT86RF2XX_STATE_TX_ARET_ON (0x19)
185 #define AT86RF2XX_STATE_IN_PROGRESS (0x1f)
192 #define AT86RF2XX_OPT_TELL_TX_START (0x0001)
194 #define AT86RF2XX_OPT_TELL_TX_END (0x0002)
196 #define AT86RF2XX_OPT_TELL_RX_START (0x0004)
198 #define AT86RF2XX_OPT_TELL_RX_END (0x0008)
200 #define AT86RF2XX_OPT_CSMA (0x0010)
201 #define AT86RF2XX_OPT_PROMISCUOUS (0x0020)
203 #define AT86RF2XX_OPT_PRELOADING (0x0040)
204 #define AT86RF2XX_OPT_AUTOACK (0x0080)
205 #define AT86RF2XX_OPT_ACK_PENDING (0x0100)
210 #if defined(MODULE_AT86RFA1) || defined(MODULE_AT86RFR2)
211 
214 typedef void at86rf2xx_params_t;
215 #else
216 
219 typedef struct at86rf2xx_params {
220  spi_t spi;
222  spi_cs_t cs_pin;
223  gpio_t int_pin;
224  gpio_t sleep_pin;
225  gpio_t reset_pin;
227 #endif
234 typedef struct {
236 #if defined(MODULE_AT86RFA1) || defined(MODULE_AT86RFR2)
237  /* ATmega256rfr2 signals transceiver events with different interrupts
238  * they have to be stored to mimic the same flow as external transceiver
239  * Use irq_status to map saved interrupts of SOC transceiver,
240  * as they clear after IRQ callback.
241  *
242  * irq_status = IRQ_STATUS
243  */
244  uint8_t irq_status;
245 #else
246  /* device specific fields */
247  at86rf2xx_params_t params;
248 #endif
249  uint16_t flags;
250  uint8_t state;
251  uint8_t tx_frame_len;
252 #ifdef MODULE_AT86RF212B
253  /* Only AT86RF212B supports multiple pages (PHY modes) */
254  uint8_t page;
255 #endif
256  uint8_t idle_state;
257  uint8_t pending_tx;
260 #if AT86RF2XX_HAVE_RETRIES
261  /* Only radios with the XAH_CTRL_2 register support frame retry reporting */
262  uint8_t tx_retries;
263 #endif
264 
265 } at86rf2xx_t;
266 
273 void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params);
274 
280 void at86rf2xx_reset(at86rf2xx_t *dev);
281 
291 
299 
308 void at86rf2xx_get_addr_long(const at86rf2xx_t *dev, eui64_t *addr);
309 
316 void at86rf2xx_set_addr_long(at86rf2xx_t *dev, const eui64_t *addr);
317 
325 uint8_t at86rf2xx_get_chan(const at86rf2xx_t *dev);
326 
333 void at86rf2xx_set_chan(at86rf2xx_t *dev, uint8_t chan);
334 
342 uint8_t at86rf2xx_get_page(const at86rf2xx_t *dev);
343 
350 void at86rf2xx_set_page(at86rf2xx_t *dev, uint8_t page);
351 
359 uint16_t at86rf2xx_get_pan(const at86rf2xx_t *dev);
360 
367 void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
368 
376 int16_t at86rf2xx_get_txpower(const at86rf2xx_t *dev);
377 
389 void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower);
390 
398 int16_t at86rf2xx_get_rxsensitivity(const at86rf2xx_t *dev);
399 
411 void at86rf2xx_set_rxsensitivity(const at86rf2xx_t *dev, int16_t rxsens);
412 
420 uint8_t at86rf2xx_get_max_retries(const at86rf2xx_t *dev);
421 
432 void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max);
433 
441 uint8_t at86rf2xx_get_csma_max_retries(const at86rf2xx_t *dev);
442 
454 void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries);
455 
467  uint8_t min, uint8_t max);
468 
475 void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2]);
476 
484 int8_t at86rf2xx_get_cca_threshold(const at86rf2xx_t *dev);
485 
492 void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value);
493 
502 
510 void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state);
511 
520 uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state);
521 
534 size_t at86rf2xx_send(at86rf2xx_t *dev, const uint8_t *data, size_t len);
535 
545 
556 size_t at86rf2xx_tx_load(at86rf2xx_t *dev, const uint8_t *data,
557  size_t len, size_t offset);
558 
564 void at86rf2xx_tx_exec(const at86rf2xx_t *dev);
565 
576 bool at86rf2xx_cca(at86rf2xx_t *dev);
577 
578 #ifdef __cplusplus
579 }
580 #endif
581 
582 #endif /* AT86RF2XX_H */
583 
void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower)
Set the transmission power of the given device [in dBm].
void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params)
Setup an AT86RF2xx based device state.
void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value)
Set the CCA threshold value.
void at86rf2xx_set_page(at86rf2xx_t *dev, uint8_t page)
Set the channel page of the given device.
void at86rf2xx_set_chan(at86rf2xx_t *dev, uint8_t chan)
Set the channel number of the given device.
struct at86rf2xx_params at86rf2xx_params_t
struct holding all params needed for device initialization
spi_clk_t spi_clk
SPI clock speed to use.
Definition: at86rf2xx.h:227
void at86rf2xx_set_addr_short(at86rf2xx_t *dev, const network_uint16_t *addr)
Set the short address of the given device.
Low-level GPIO peripheral driver interface definitions.
gpio_t int_pin
GPIO pin connected to the interrupt pin.
Definition: at86rf2xx.h:229
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:76
uint8_t at86rf2xx_get_csma_max_retries(const at86rf2xx_t *dev)
Get the maximum number of channel access attempts per frame (CSMA)
void at86rf2xx_tx_exec(const at86rf2xx_t *dev)
Trigger sending of data previously loaded into transmit buffer.
void at86rf2xx_get_addr_long(const at86rf2xx_t *dev, eui64_t *addr)
Get the configured long address of the given device.
Definitions low-level network driver interface.
bool at86rf2xx_cca(at86rf2xx_t *dev)
Perform one manual channel clear assessment (CCA)
size_t at86rf2xx_send(at86rf2xx_t *dev, const uint8_t *data, size_t len)
Convenience function for simply sending data.
void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max)
Set the maximum number of retransmissions.
void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan)
Set the PAN ID of the given device.
gpio_t reset_pin
GPIO pin connected to the reset pin.
Definition: at86rf2xx.h:231
Low-level SPI peripheral driver interface definition.
uint16_t at86rf2xx_get_pan(const at86rf2xx_t *dev)
Get the configured PAN ID of the given device.
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition: spi.h:126
spi_t spi
SPI bus the device is connected to.
Definition: at86rf2xx.h:226
void at86rf2xx_tx_prepare(at86rf2xx_t *dev)
Prepare for sending of data.
void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries)
Set the maximum number of channel access attempts per frame (CSMA)
int16_t at86rf2xx_get_rxsensitivity(const at86rf2xx_t *dev)
Get the configured receiver sensitivity of the given device [in dBm].
void at86rf2xx_set_addr_long(at86rf2xx_t *dev, const eui64_t *addr)
Set the long address of the given device.
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.
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
uint8_t at86rf2xx_get_page(const at86rf2xx_t *dev)
Get the configured channel page of the given device.
int16_t at86rf2xx_get_txpower(const at86rf2xx_t *dev)
Get the configured transmission power of the given device [in dBm].
int8_t at86rf2xx_get_cca_threshold(const at86rf2xx_t *dev)
Get the CCA threshold value.
Structure to hold driver state.
Definition: netdev.h:283
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_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2])
Set seed for CSMA random backoff.
int8_t at86rf2xx_get_ed_level(at86rf2xx_t *dev)
Get the latest ED level measurement.
Definitions for netdev common IEEE 802.15.4 code.
spi_cs_t cs_pin
GPIO pin connected to chip select.
Definition: at86rf2xx.h:228
Device descriptor for AT86RF2XX radio devices.
Definition: at86rf2xx.h:240
void at86rf2xx_reset(at86rf2xx_t *dev)
Trigger a hardware reset and configure radio with default values.
void at86rf2xx_get_addr_short(const at86rf2xx_t *dev, network_uint16_t *addr)
Get the short address 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)
Data type to represent an EUI-64.
Definition: eui64.h:55
uint8_t at86rf2xx_get_max_retries(const at86rf2xx_t *dev)
Get the maximum number of retransmissions.
Extended structure to hold IEEE 802.15.4 driver state.
Definition: ieee802154.h:89
Protocol type definitions.
uint8_t at86rf2xx_get_chan(const at86rf2xx_t *dev)
Get the configured channel number of the given device.
void at86rf2xx_set_rxsensitivity(const at86rf2xx_t *dev, int16_t rxsens)
Set the receiver sensitivity of the given device [in dBm].
gpio_t sleep_pin
GPIO pin connected to the sleep pin.
Definition: at86rf2xx.h:230
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
struct holding all params needed for device initialization
Definition: at86rf2xx.h:225