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)
138 #define AT86RF2XX_OPT_ACK_PENDING (NETDEV_IEEE802154_FRAME_PEND)
140 #define AT86RF2XX_OPT_CSMA (0x0100)
141 #define AT86RF2XX_OPT_PROMISCUOUS (0x0200)
143 #define AT86RF2XX_OPT_PRELOADING (0x0400)
144 #define AT86RF2XX_OPT_TELL_TX_START (0x0800)
146 #define AT86RF2XX_OPT_TELL_TX_END (0x1000)
148 #define AT86RF2XX_OPT_TELL_RX_START (0x2000)
150 #define AT86RF2XX_OPT_TELL_RX_END (0x4000)
157 typedef struct at86rf2xx_params {
158  spi_t spi;
159  spi_clk_t spi_clk;
160  spi_cs_t cs_pin;
161  gpio_t int_pin;
162  gpio_t sleep_pin;
163  gpio_t reset_pin;
171 typedef struct {
173  /* device specific fields */
174  at86rf2xx_params_t params;
175  uint8_t state;
176  uint8_t tx_frame_len;
177 #ifdef MODULE_AT86RF212B
178  /* Only AT86RF212B supports multiple pages (PHY modes) */
179  uint8_t page;
180 #endif
181  uint8_t idle_state;
182  uint8_t pending_tx;
185 #if AT86RF2XX_HAVE_RETRIES
186  /* Only radios with the XAH_CTRL_2 register support frame retry reporting */
187  uint8_t tx_retries;
188 #endif
189 
190 } at86rf2xx_t;
191 
198 void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params);
199 
205 void at86rf2xx_reset(at86rf2xx_t *dev);
206 
214 uint16_t at86rf2xx_get_addr_short(const at86rf2xx_t *dev);
215 
222 void at86rf2xx_set_addr_short(at86rf2xx_t *dev, uint16_t addr);
223 
231 uint64_t at86rf2xx_get_addr_long(const at86rf2xx_t *dev);
232 
239 void at86rf2xx_set_addr_long(at86rf2xx_t *dev, uint64_t addr);
240 
248 uint8_t at86rf2xx_get_chan(const at86rf2xx_t *dev);
249 
256 void at86rf2xx_set_chan(at86rf2xx_t *dev, uint8_t chan);
257 
265 uint8_t at86rf2xx_get_page(const at86rf2xx_t *dev);
266 
273 void at86rf2xx_set_page(at86rf2xx_t *dev, uint8_t page);
274 
282 uint16_t at86rf2xx_get_pan(const at86rf2xx_t *dev);
283 
290 void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
291 
299 int16_t at86rf2xx_get_txpower(const at86rf2xx_t *dev);
300 
312 void at86rf2xx_set_txpower(const at86rf2xx_t *dev, int16_t txpower);
313 
321 uint8_t at86rf2xx_get_max_retries(const at86rf2xx_t *dev);
322 
333 void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max);
334 
342 uint8_t at86rf2xx_get_csma_max_retries(const at86rf2xx_t *dev);
343 
355 void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries);
356 
368  uint8_t min, uint8_t max);
369 
376 void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2]);
377 
385 int8_t at86rf2xx_get_cca_threshold(const at86rf2xx_t *dev);
386 
393 void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value);
394 
403 
411 void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state);
412 
421 uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state);
422 
435 size_t at86rf2xx_send(at86rf2xx_t *dev, const uint8_t *data, size_t len);
436 
446 
457 size_t at86rf2xx_tx_load(at86rf2xx_t *dev, const uint8_t *data,
458  size_t len, size_t offset);
459 
465 void at86rf2xx_tx_exec(const at86rf2xx_t *dev);
466 
477 bool at86rf2xx_cca(at86rf2xx_t *dev);
478 
479 #ifdef __cplusplus
480 }
481 #endif
482 
483 #endif /* AT86RF2XX_H */
484 
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:176
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:162