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 
98 #define AT86RF2XX_STATE_FORCE_TRX_OFF (0x03)
99 #define AT86RF2XX_STATE_TRX_OFF (0x08)
100 #define AT86RF2XX_STATE_PLL_ON (0x09)
101 #define AT86RF2XX_STATE_SLEEP (0x0f)
102 #define AT86RF2XX_STATE_BUSY_RX_AACK (0x11)
103 #define AT86RF2XX_STATE_BUSY_TX_ARET (0x12)
104 #define AT86RF2XX_STATE_RX_AACK_ON (0x16)
105 #define AT86RF2XX_STATE_TX_ARET_ON (0x19)
106 #define AT86RF2XX_STATE_IN_PROGRESS (0x1f)
117 #define AT86RF2XX_OPT_SRC_ADDR_LONG (NETDEV_IEEE802154_SRC_MODE_LONG)
118 #define AT86RF2XX_OPT_RAWDUMP (NETDEV_IEEE802154_RAW)
119 #define AT86RF2XX_OPT_AUTOACK (NETDEV_IEEE802154_ACK_REQ)
121 #define AT86RF2XX_OPT_CSMA (0x0100)
122 #define AT86RF2XX_OPT_PROMISCUOUS (0x0200)
124 #define AT86RF2XX_OPT_PRELOADING (0x0400)
125 #define AT86RF2XX_OPT_TELL_TX_START (0x0800)
127 #define AT86RF2XX_OPT_TELL_TX_END (0x1000)
129 #define AT86RF2XX_OPT_TELL_RX_START (0x2000)
131 #define AT86RF2XX_OPT_TELL_RX_END (0x4000)
138 typedef struct at86rf2xx_params {
139  spi_t spi;
140  spi_clk_t spi_clk;
141  spi_cs_t cs_pin;
142  gpio_t int_pin;
143  gpio_t sleep_pin;
144  gpio_t reset_pin;
152 typedef struct {
159  uint8_t state;
160  uint8_t tx_frame_len;
161 #ifdef MODULE_AT86RF212B
162  /* Only AT86RF212B supports multiple pages (PHY modes) */
163  uint8_t page;
164 #endif
165  uint8_t idle_state;
166  uint8_t pending_tx;
178 void at86rf2xx_setup(at86rf2xx_t *dev, const at86rf2xx_params_t *params);
179 
185 void at86rf2xx_reset(at86rf2xx_t *dev);
186 
195 
202 void at86rf2xx_set_addr_short(at86rf2xx_t *dev, uint16_t addr);
203 
211 uint64_t at86rf2xx_get_addr_long(at86rf2xx_t *dev);
212 
219 void at86rf2xx_set_addr_long(at86rf2xx_t *dev, uint64_t addr);
220 
228 uint8_t at86rf2xx_get_chan(at86rf2xx_t *dev);
229 
236 void at86rf2xx_set_chan(at86rf2xx_t *dev, uint8_t chan);
237 
245 uint8_t at86rf2xx_get_page(at86rf2xx_t *dev);
246 
253 void at86rf2xx_set_page(at86rf2xx_t *dev, uint8_t page);
254 
262 uint16_t at86rf2xx_get_pan(at86rf2xx_t *dev);
263 
270 void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
271 
279 int16_t at86rf2xx_get_txpower(at86rf2xx_t *dev);
280 
292 void at86rf2xx_set_txpower(at86rf2xx_t *dev, int16_t txpower);
293 
302 
313 void at86rf2xx_set_max_retries(at86rf2xx_t *dev, uint8_t max);
314 
323 
335 void at86rf2xx_set_csma_max_retries(at86rf2xx_t *dev, int8_t retries);
336 
347 void at86rf2xx_set_csma_backoff_exp(at86rf2xx_t *dev, uint8_t min, uint8_t max);
348 
355 void at86rf2xx_set_csma_seed(at86rf2xx_t *dev, uint8_t entropy[2]);
356 
365 
372 void at86rf2xx_set_cca_threshold(at86rf2xx_t *dev, int8_t value);
373 
381 void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state);
382 
389 void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state);
390 
401 
414 size_t at86rf2xx_send(at86rf2xx_t *dev, uint8_t *data, size_t len);
415 
425 
436 size_t at86rf2xx_tx_load(at86rf2xx_t *dev, uint8_t *data, size_t len,
437  size_t offset);
438 
444 void at86rf2xx_tx_exec(at86rf2xx_t *dev);
445 
446 #ifdef __cplusplus
447 }
448 #endif
449 
450 #endif /* AT86RF2XX_H */
451 
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_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
uint8_t at86rf2xx_get_page(at86rf2xx_t *dev)
Get the configured channel page of the given device.
int8_t at86rf2xx_get_cca_threshold(at86rf2xx_t *dev)
Get the CCA threshold value.
Low-level GPIO peripheral driver interface definitions.
uint16_t at86rf2xx_get_pan(at86rf2xx_t *dev)
Get the configured PAN ID of the given device.
Definitions low-level network driver interface.
void at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
Set the state of the given device (trigger a state change)
void at86rf2xx_set_cca_threshold(at86rf2xx_t *dev, int8_t value)
Set the CCA threshold value.
uint8_t at86rf2xx_get_chan(at86rf2xx_t *dev)
Get the configured channel number of the given device.
void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan)
Set the PAN ID of the given device.
void at86rf2xx_set_csma_backoff_exp(at86rf2xx_t *dev, uint8_t min, uint8_t max)
Set the min and max backoff exponent for CSMA/CA.
void at86rf2xx_set_txpower(at86rf2xx_t *dev, int16_t txpower)
Set the transmission power of the given device [in dBm].
Low-level SPI peripheral driver interface definition.
void at86rf2xx_set_csma_max_retries(at86rf2xx_t *dev, int8_t retries)
Set the maximum number of channel access attempts per frame (CSMA)
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_addr_short(at86rf2xx_t *dev, uint16_t addr)
Set the short address of the given device.
uint64_t at86rf2xx_get_addr_long(at86rf2xx_t *dev)
Get the configured long address of the given device.
void at86rf2xx_set_max_retries(at86rf2xx_t *dev, uint8_t max)
Set the maximum number of retransmissions.
Structure to hold driver state.
uint8_t at86rf2xx_get_csma_max_retries(at86rf2xx_t *dev)
Get the maximum number of channel access attempts per frame (CSMA)
Definitions for netdev common IEEE 802.15.4 code.
Device descriptor for AT86RF2XX radio devices.
Definition: at86rf2xx.h:157
uint8_t at86rf2xx_get_max_retries(at86rf2xx_t *dev)
Get the maximum number of retransmissions.
uint16_t at86rf2xx_get_addr_short(at86rf2xx_t *dev)
Get the short address of the given device.
void at86rf2xx_reset(at86rf2xx_t *dev)
Trigger a hardware reset and configure radio with default values.
void at86rf2xx_set_csma_seed(at86rf2xx_t *dev, uint8_t entropy[2])
Set seed for CSMA random backoff.
void at86rf2xx_tx_exec(at86rf2xx_t *dev)
Trigger sending of data previously loaded into transmit buffer.
Extended structure to hold IEEE 802.15.4 driver state.
size_t at86rf2xx_tx_load(at86rf2xx_t *dev, uint8_t *data, size_t len, size_t offset)
Load chunks of data into the transmit buffer of the given device.
size_t at86rf2xx_send(at86rf2xx_t *dev, uint8_t *data, size_t len)
Convenience function for simply sending data.
int16_t at86rf2xx_get_txpower(at86rf2xx_t *dev)
Get the configured transmission power of the given device [in dBm].
void at86rf2xx_reset_state_machine(at86rf2xx_t *dev)
Reset the internal state machine to TRX_OFF mode.
Protocol type definitions.
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:105
struct holding all params needed for device initialization
Definition: at86rf2xx.h:143