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 "periph/spi.h"
37 #include "periph/gpio.h"
38 #include "net/netdev.h"
39 #include "net/netdev/ieee802154.h"
40 #include "net/gnrc/nettype.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
49 #define AT86RF2XX_MAX_PKT_LENGTH (IEEE802154_FRAME_LEN_MAX)
50 
55 #ifdef MODULE_AT86RF212B
56 /* the AT86RF212B has a sub-1GHz radio */
57 #define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN_SUBGHZ)
58 #define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX_SUBGHZ)
59 #define AT86RF2XX_DEFAULT_CHANNEL (IEEE802154_DEFAULT_SUBGHZ_CHANNEL)
60 /* Page 2 is O-QPSK 100 kbit/s (channel 0), or 250 kbit/s (channels 1-10) */
61 #define AT86RF2XX_DEFAULT_PAGE (IEEE802154_DEFAULT_SUBGHZ_PAGE)
62 #else
63 #define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN)
64 #define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX)
65 #define AT86RF2XX_DEFAULT_CHANNEL (IEEE802154_DEFAULT_CHANNEL)
66 /* Only page 0 is supported in the 2.4 GHz band */
67 #endif
68 
75 #define AT86RF2XX_DEFAULT_PANID (IEEE802154_DEFAULT_PANID)
76 
80 #define AT86RF2XX_DEFAULT_TXPOWER (IEEE802154_DEFAULT_TXPOWER)
81 
85 #if MODULE_AT86RF233
86 # define RSSI_BASE_VAL (-94)
87 #elif MODULE_AT86RF212B
88 
92 # define RSSI_BASE_VAL (-98)
93 #else
94 # define RSSI_BASE_VAL (-91)
95 #endif
96 
97 #if defined(DOXYGEN) || defined(MODULE_AT86RF232) || defined(MODULE_AT86RF233)
98 
106 #define AT86RF2XX_HAVE_RETRIES (1)
107 #else
108 #define AT86RF2XX_HAVE_RETRIES (0)
109 #endif
110 
115 #define AT86RF2XX_STATE_P_ON (0x00)
116 #define AT86RF2XX_STATE_BUSY_RX (0x01)
117 #define AT86RF2XX_STATE_BUSY_TX (0x02)
118 #define AT86RF2XX_STATE_FORCE_TRX_OFF (0x03)
119 #define AT86RF2XX_STATE_RX_ON (0x06)
120 #define AT86RF2XX_STATE_TRX_OFF (0x08)
121 #define AT86RF2XX_STATE_PLL_ON (0x09)
122 #define AT86RF2XX_STATE_SLEEP (0x0f)
123 #define AT86RF2XX_STATE_BUSY_RX_AACK (0x11)
124 #define AT86RF2XX_STATE_BUSY_TX_ARET (0x12)
125 #define AT86RF2XX_STATE_RX_AACK_ON (0x16)
126 #define AT86RF2XX_STATE_TX_ARET_ON (0x19)
127 #define AT86RF2XX_STATE_IN_PROGRESS (0x1f)
134 #define AT86RF2XX_OPT_TELL_TX_START (0x0001)
136 #define AT86RF2XX_OPT_TELL_TX_END (0x0002)
138 #define AT86RF2XX_OPT_TELL_RX_START (0x0004)
140 #define AT86RF2XX_OPT_TELL_RX_END (0x0008)
142 #define AT86RF2XX_OPT_CSMA (0x0010)
143 #define AT86RF2XX_OPT_PROMISCUOUS (0x0020)
145 #define AT86RF2XX_OPT_PRELOADING (0x0040)
146 #define AT86RF2XX_OPT_AUTOACK (0x0080)
147 #define AT86RF2XX_OPT_ACK_PENDING (0x0100)
155 typedef struct at86rf2xx_params {
156  spi_t spi;
157  spi_clk_t spi_clk;
158  spi_cs_t cs_pin;
159  gpio_t int_pin;
160  gpio_t sleep_pin;
161  gpio_t reset_pin;
169 typedef struct {
171  /* device specific fields */
172  at86rf2xx_params_t params;
173  uint16_t flags;
174  uint8_t state;
175  uint8_t tx_frame_len;
176 #ifdef MODULE_AT86RF212B
177  /* Only AT86RF212B supports multiple pages (PHY modes) */
178  uint8_t page;
179 #endif
180  uint8_t idle_state;
181  uint8_t pending_tx;
184 #if AT86RF2XX_HAVE_RETRIES
185  /* Only radios with the XAH_CTRL_2 register support frame retry reporting */
186  uint8_t tx_retries;
187 #endif
188 
189 } at86rf2xx_t;
190 
197 void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params);
198 
204 void at86rf2xx_reset(at86rf2xx_t *dev);
205 
213 uint16_t at86rf2xx_get_addr_short(const at86rf2xx_t *dev);
214 
221 void at86rf2xx_set_addr_short(at86rf2xx_t *dev, uint16_t addr);
222 
230 uint64_t at86rf2xx_get_addr_long(const at86rf2xx_t *dev);
231 
238 void at86rf2xx_set_addr_long(at86rf2xx_t *dev, uint64_t addr);
239 
247 uint8_t at86rf2xx_get_chan(const at86rf2xx_t *dev);
248 
255 void at86rf2xx_set_chan(at86rf2xx_t *dev, uint8_t chan);
256 
264 uint8_t at86rf2xx_get_page(const at86rf2xx_t *dev);
265 
272 void at86rf2xx_set_page(at86rf2xx_t *dev, uint8_t page);
273 
281 uint16_t at86rf2xx_get_pan(const at86rf2xx_t *dev);
282 
289 void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
290 
298 int16_t at86rf2xx_get_txpower(const at86rf2xx_t *dev);
299 
311 void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower);
312 
320 uint8_t at86rf2xx_get_max_retries(const at86rf2xx_t *dev);
321 
332 void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max);
333 
341 uint8_t at86rf2xx_get_csma_max_retries(const at86rf2xx_t *dev);
342 
354 void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries);
355 
367  uint8_t min, uint8_t max);
368 
375 void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2]);
376 
384 int8_t at86rf2xx_get_cca_threshold(const at86rf2xx_t *dev);
385 
392 void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value);
393 
402 
410 void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state);
411 
420 uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state);
421 
434 size_t at86rf2xx_send(at86rf2xx_t *dev, const uint8_t *data, size_t len);
435 
445 
456 size_t at86rf2xx_tx_load(at86rf2xx_t *dev, const uint8_t *data,
457  size_t len, size_t offset);
458 
464 void at86rf2xx_tx_exec(const at86rf2xx_t *dev);
465 
476 bool at86rf2xx_cca(at86rf2xx_t *dev);
477 
478 #ifdef __cplusplus
479 }
480 #endif
481 
482 #endif /* AT86RF2XX_H */
483 
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.
Definitions low-level network driver interface.
void at86rf2xx_set_addr_long(at86rf2xx_t *dev, uint64_t addr)
Set the long address of the given device.
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
Low-level GPIO peripheral driver interface definitions.
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.
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.
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:113
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)
void at86rf2xx_set_addr_short(at86rf2xx_t *dev, uint16_t addr)
Set the short 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.
uint16_t at86rf2xx_get_addr_short(const at86rf2xx_t *dev)
Get the short address of the given device.
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:275
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.
uint64_t at86rf2xx_get_addr_long(const at86rf2xx_t *dev)
Get the configured long address of the given device.
int8_t at86rf2xx_get_ed_level(at86rf2xx_t *dev)
Get the latest ED level measurement.
Definitions for netdev common IEEE 802.15.4 code.
Device descriptor for AT86RF2XX radio devices.
Definition: at86rf2xx.h:175
void at86rf2xx_reset(at86rf2xx_t *dev)
Trigger a hardware reset and configure radio with default values.
uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
Set the state of the given device (trigger a state change)
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.
Protocol type definitions.
uint8_t at86rf2xx_get_chan(const at86rf2xx_t *dev)
Get the configured channel number of the given device.
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:105
struct holding all params needed for device initialization
Definition: at86rf2xx.h:161