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)
138 #define AT86RF2XX_OPT_SRC_ADDR_LONG (NETDEV_IEEE802154_SRC_MODE_LONG)
139 #define AT86RF2XX_OPT_RAWDUMP (NETDEV_IEEE802154_RAW)
140 #define AT86RF2XX_OPT_AUTOACK (NETDEV_IEEE802154_ACK_REQ)
141 #define AT86RF2XX_OPT_ACK_PENDING (NETDEV_IEEE802154_FRAME_PEND)
143 #define AT86RF2XX_OPT_CSMA (0x0100)
144 #define AT86RF2XX_OPT_PROMISCUOUS (0x0200)
146 #define AT86RF2XX_OPT_PRELOADING (0x0400)
147 #define AT86RF2XX_OPT_TELL_TX_START (0x0800)
149 #define AT86RF2XX_OPT_TELL_TX_END (0x1000)
151 #define AT86RF2XX_OPT_TELL_RX_START (0x2000)
153 #define AT86RF2XX_OPT_TELL_RX_END (0x4000)
160 typedef struct at86rf2xx_params {
161  spi_t spi;
162  spi_clk_t spi_clk;
163  spi_cs_t cs_pin;
164  gpio_t int_pin;
165  gpio_t sleep_pin;
166  gpio_t reset_pin;
174 typedef struct {
176  /* device specific fields */
177  at86rf2xx_params_t params;
178  uint8_t state;
179  uint8_t tx_frame_len;
180 #ifdef MODULE_AT86RF212B
181  /* Only AT86RF212B supports multiple pages (PHY modes) */
182  uint8_t page;
183 #endif
184  uint8_t idle_state;
185  uint8_t pending_tx;
188 #if AT86RF2XX_HAVE_RETRIES
189  /* Only radios with the XAH_CTRL_2 register support frame retry reporting */
190  uint8_t tx_retries;
191 #endif
192 
193 } at86rf2xx_t;
194 
201 void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params);
202 
208 void at86rf2xx_reset(at86rf2xx_t *dev);
209 
217 uint16_t at86rf2xx_get_addr_short(const at86rf2xx_t *dev);
218 
225 void at86rf2xx_set_addr_short(at86rf2xx_t *dev, uint16_t addr);
226 
234 uint64_t at86rf2xx_get_addr_long(const at86rf2xx_t *dev);
235 
242 void at86rf2xx_set_addr_long(at86rf2xx_t *dev, uint64_t addr);
243 
251 uint8_t at86rf2xx_get_chan(const at86rf2xx_t *dev);
252 
259 void at86rf2xx_set_chan(at86rf2xx_t *dev, uint8_t chan);
260 
268 uint8_t at86rf2xx_get_page(const at86rf2xx_t *dev);
269 
276 void at86rf2xx_set_page(at86rf2xx_t *dev, uint8_t page);
277 
285 uint16_t at86rf2xx_get_pan(const at86rf2xx_t *dev);
286 
293 void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
294 
302 int16_t at86rf2xx_get_txpower(const at86rf2xx_t *dev);
303 
315 void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower);
316 
324 uint8_t at86rf2xx_get_max_retries(const at86rf2xx_t *dev);
325 
336 void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max);
337 
345 uint8_t at86rf2xx_get_csma_max_retries(const at86rf2xx_t *dev);
346 
358 void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries);
359 
371  uint8_t min, uint8_t max);
372 
379 void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2]);
380 
388 int8_t at86rf2xx_get_cca_threshold(const at86rf2xx_t *dev);
389 
396 void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value);
397 
406 
414 void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state);
415 
424 uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state);
425 
438 size_t at86rf2xx_send(at86rf2xx_t *dev, const uint8_t *data, size_t len);
439 
449 
460 size_t at86rf2xx_tx_load(at86rf2xx_t *dev, const uint8_t *data,
461  size_t len, size_t offset);
462 
468 void at86rf2xx_tx_exec(const at86rf2xx_t *dev);
469 
480 bool at86rf2xx_cca(at86rf2xx_t *dev);
481 
482 #ifdef __cplusplus
483 }
484 #endif
485 
486 #endif /* AT86RF2XX_H */
487 
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:179
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:165