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 #else
61 #define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN)
62 #define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX)
63 #define AT86RF2XX_DEFAULT_CHANNEL (IEEE802154_DEFAULT_CHANNEL)
64 #endif
65 
72 #define AT86RF2XX_DEFAULT_PANID (IEEE802154_DEFAULT_PANID)
73 
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 #else
91 # define RSSI_BASE_VAL (-91)
92 #endif
93 
94 #if defined(DOXYGEN) || defined(MODULE_AT86RF232) || defined(MODULE_AT86RF233)
95 
103 #define AT86RF2XX_HAVE_RETRIES (1)
104 #else
105 #define AT86RF2XX_HAVE_RETRIES (0)
106 #endif
107 
112 #define AT86RF2XX_STATE_P_ON (0x00)
113 #define AT86RF2XX_STATE_BUSY_RX (0x01)
114 #define AT86RF2XX_STATE_BUSY_TX (0x02)
115 #define AT86RF2XX_STATE_FORCE_TRX_OFF (0x03)
116 #define AT86RF2XX_STATE_RX_ON (0x06)
117 #define AT86RF2XX_STATE_TRX_OFF (0x08)
118 #define AT86RF2XX_STATE_PLL_ON (0x09)
119 #define AT86RF2XX_STATE_SLEEP (0x0f)
120 #define AT86RF2XX_STATE_BUSY_RX_AACK (0x11)
121 #define AT86RF2XX_STATE_BUSY_TX_ARET (0x12)
122 #define AT86RF2XX_STATE_RX_AACK_ON (0x16)
123 #define AT86RF2XX_STATE_TX_ARET_ON (0x19)
124 #define AT86RF2XX_STATE_IN_PROGRESS (0x1f)
135 #define AT86RF2XX_OPT_SRC_ADDR_LONG (NETDEV_IEEE802154_SRC_MODE_LONG)
136 #define AT86RF2XX_OPT_RAWDUMP (NETDEV_IEEE802154_RAW)
137 #define AT86RF2XX_OPT_AUTOACK (NETDEV_IEEE802154_ACK_REQ)
139 #define AT86RF2XX_OPT_CSMA (0x0100)
140 #define AT86RF2XX_OPT_PROMISCUOUS (0x0200)
142 #define AT86RF2XX_OPT_PRELOADING (0x0400)
143 #define AT86RF2XX_OPT_TELL_TX_START (0x0800)
145 #define AT86RF2XX_OPT_TELL_TX_END (0x1000)
147 #define AT86RF2XX_OPT_TELL_RX_START (0x2000)
149 #define AT86RF2XX_OPT_TELL_RX_END (0x4000)
156 typedef struct at86rf2xx_params {
157  spi_t spi;
158  spi_clk_t spi_clk;
159  spi_cs_t cs_pin;
160  gpio_t int_pin;
161  gpio_t sleep_pin;
162  gpio_t reset_pin;
170 typedef struct {
172  /* device specific fields */
173  at86rf2xx_params_t params;
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.
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.
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.
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.
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