Loading...
Searching...
No Matches
at86rf2xx.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Freie Universität Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
27
28#include <stdint.h>
29#include <stdbool.h>
30
31#include "board.h"
32#include "kernel_defines.h"
33#include "net/netdev.h"
35#include "net/gnrc/nettype.h"
36#include "net/ieee802154/radio.h"
37#include "event.h"
38
39/* we need no peripherals for memory mapped radios */
40#if !defined(MODULE_AT86RFA1) && !defined(MODULE_AT86RFR2)
41# include "periph/spi.h"
42# include "periph/gpio.h"
43#endif
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
52#define AT86RF2XX_MAX_PKT_LENGTH (IEEE802154_FRAME_LEN_MAX)
53
58#ifdef MODULE_AT86RF212B
59/* the AT86RF212B has a sub-1GHz radio */
60# define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN_SUBGHZ)
61# define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX_SUBGHZ)
62# define AT86RF2XX_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_SUBGHZ_CHANNEL)
63/* Page 2 is O-QPSK 100 kbit/s (channel 0), or 250 kbit/s (channels 1-10) */
64# define AT86RF2XX_DEFAULT_PAGE (CONFIG_IEEE802154_DEFAULT_SUBGHZ_PAGE)
65#else
66# define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN)
67# define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX)
68# define AT86RF2XX_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_CHANNEL)
69# define AT86RF2XX_DEFAULT_PAGE (0)
70/* Only page 0 is supported in the 2.4 GHz band */
71#endif
73
77#define AT86RF2XX_DEFAULT_TXPOWER (CONFIG_IEEE802154_DEFAULT_TXPOWER)
78
82#if MODULE_AT86RF233
83# define RSSI_BASE_VAL (-94)
84#elif MODULE_AT86RF212B
89# define RSSI_BASE_VAL (-98)
90#elif MODULE_AT86RFA1 || MODULE_AT86RFR2
91# define RSSI_BASE_VAL (-90)
92#else
93# define RSSI_BASE_VAL (-91)
94#endif
95
99#if MODULE_AT86RF233
100# define MIN_RX_SENSITIVITY (-101)
101#elif MODULE_AT86RF212B
102# define MIN_RX_SENSITIVITY (-110)
103#elif MODULE_AT86RFA1 || MODULE_AT86RFR2
104# define MIN_RX_SENSITIVITY (-100)
105#else
106# define MIN_RX_SENSITIVITY (-101)
107#endif
108
112#if IS_USED(MODULE_AT86RFA1) || IS_USED(MODULE_AT86RFR2)
113# define AT86RF2XX_IS_PERIPH (1)
114#else
115# define AT86RF2XX_IS_PERIPH (0)
116#endif
117
121#if defined(MODULE_AT86RF231) || IS_ACTIVE(AT86RF2XX_PERIPH)
122# define AT86RF2XX_HAVE_ED_REGISTER (1)
123#else
124# define AT86RF2XX_HAVE_ED_REGISTER (0)
125#endif
126
130#ifdef MODULE_AT86RF212B
131# define AT86RF2XX_HAVE_SUBGHZ (1)
132#else
133# define AT86RF2XX_HAVE_SUBGHZ (0)
134#endif
135
136#if defined(DOXYGEN) || defined(MODULE_AT86RF232) || defined(MODULE_AT86RF233) || defined(MODULE_AT86RFR2)
143# define AT86RF2XX_HAVE_RETRIES (1)
144#else
145# define AT86RF2XX_HAVE_RETRIES (0)
146#endif
147
154#if AT86RF2XX_HAVE_RETRIES && defined(AT86RF2XX_REG__XAH_CTRL_2)
155# define AT86RF2XX_HAVE_RETRIES_REG (1)
156#else
157# define AT86RF2XX_HAVE_RETRIES_REG (0)
158#endif
159
163#ifdef AT86RF2XX_REG__IRQ_MASK1
164# define AT86RF2XX_HAVE_TX_START_IRQ (1)
165#else
166# define AT86RF2XX_HAVE_TX_START_IRQ (0)
167#endif
168
176#if defined(MODULE_AT86RF233) || defined(MODULE_AT86RF231) || defined(MODULE_AT86RFA1) || defined(MODULE_AT86RFR2)
177# ifndef AT86RF2XX_RANDOM_NUMBER_GENERATOR
178# define AT86RF2XX_RANDOM_NUMBER_GENERATOR (1)
179# endif
180#else
181# ifndef AT86RF2XX_RANDOM_NUMBER_GENERATOR
182# define AT86RF2XX_RANDOM_NUMBER_GENERATOR (0)
183# endif
184#endif
185
194#if defined(MODULE_AT86RF233) || defined(MODULE_AT86RFR2)
195# ifndef AT86RF2XX_SMART_IDLE_LISTENING
196# define AT86RF2XX_SMART_IDLE_LISTENING (1)
197# endif
198#else
199# define AT86RF2XX_SMART_IDLE_LISTENING (0)
200#endif
201
206#define AT86RF2XX_STATE_P_ON (0x00)
207#define AT86RF2XX_STATE_BUSY_RX (0x01)
208#define AT86RF2XX_STATE_BUSY_TX (0x02)
209#define AT86RF2XX_STATE_FORCE_TRX_OFF (0x03)
210#define AT86RF2XX_STATE_RX_ON (0x06)
211#define AT86RF2XX_STATE_TRX_OFF (0x08)
212#define AT86RF2XX_STATE_PLL_ON (0x09)
213#define AT86RF2XX_STATE_SLEEP (0x0f)
214#define AT86RF2XX_STATE_BUSY_RX_AACK (0x11)
215#define AT86RF2XX_STATE_BUSY_TX_ARET (0x12)
216#define AT86RF2XX_STATE_RX_AACK_ON (0x16)
217#define AT86RF2XX_STATE_TX_ARET_ON (0x19)
218#define AT86RF2XX_STATE_IN_PROGRESS (0x1f)
220
225#define AT86RF2XX_OPT_CSMA (0x0010)
226#define AT86RF2XX_OPT_PROMISCUOUS (0x0020)
227#define AT86RF2XX_OPT_PRELOADING (0x0040)
228#define AT86RF2XX_OPT_AUTOACK (0x0080)
229#define AT86RF2XX_OPT_ACK_PENDING (0x0100)
230
232
233#if IS_ACTIVE(AT86RF2XX_BASIC_MODE) || defined(DOXYGEN)
237# define AT86RF2XX_PHY_STATE_RX AT86RF2XX_STATE_RX_ON
241# define AT86RF2XX_PHY_STATE_RX_BUSY AT86RF2XX_STATE_BUSY_RX
245# define AT86RF2XX_PHY_STATE_TX AT86RF2XX_STATE_PLL_ON
249# define AT86RF2XX_PHY_STATE_TX_BUSY AT86RF2XX_STATE_BUSY_TX
250#else
251# define AT86RF2XX_PHY_STATE_RX AT86RF2XX_STATE_RX_AACK_ON
252# define AT86RF2XX_PHY_STATE_RX_BUSY AT86RF2XX_STATE_BUSY_RX_AACK
253# define AT86RF2XX_PHY_STATE_TX AT86RF2XX_STATE_TX_ARET_ON
254# define AT86RF2XX_PHY_STATE_TX_BUSY AT86RF2XX_STATE_BUSY_TX_ARET
255#endif /* IS_ACTIVE(AT86RF2XX_BASIC_MODE) */
256
257#if AT86RF2XX_IS_PERIPH
261typedef void at86rf2xx_params_t;
262#else
274#endif
275
281typedef struct {
282#if !AT86RF2XX_IS_PERIPH
283 /* device specific fields */
285#endif
286#if AT86RF2XX_HAVE_RETRIES && AT86RF2XX_IS_PERIPH
287 /* Only radios with the XAH_CTRL_2 register support frame retry reporting */
288 int8_t tx_retries;
289#endif
290 bool sleep;
293
303
311
319
327
336
351int at86rf2xx_set_rate(at86rf2xx_t *dev, uint8_t rate);
352
359void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
360
369
381void at86rf2xx_set_rxsensitivity(const at86rf2xx_t *dev, int8_t rxsens);
382
391
402void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max);
403
412
424void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries);
425
437 uint8_t min, uint8_t max);
438
445void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2]);
446
455
462void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value);
463
472
480void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state);
481
490uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state);
491
503
513
521
530
541
555int at86rf2xx_init(at86rf2xx_t *dev, const at86rf2xx_params_t *params, ieee802154_dev_t *hal, void (*cb)(void*), void *ctx);
556
570
571#ifdef __cplusplus
572}
573#endif
574
spi_clk_t
Definition periph_cpu.h:348
be_uint16_t network_uint16_t
A 16 bit integer in network byte order.
Definition byteorder.h:92
Definitions for netdev common IEEE 802.15.4 code.
Definitions low-level network driver interface.
Low-level GPIO peripheral driver interface definitions.
int at86rf2xx_set_rate(at86rf2xx_t *dev, uint8_t rate)
Set the current O-QPSK rate mode of the PHY rate modes > 0 are proprietary.
int8_t at86rf2xx_get_cca_threshold(const at86rf2xx_t *dev)
Get the CCA threshold value.
void at86rf2xx_disable_smart_idle(at86rf2xx_t *dev)
Disable the smart receive technology (SRT)
void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan)
Set the PAN ID of the given device.
bool at86rf2xx_cca(at86rf2xx_t *dev)
Perform one manual channel clear assessment (CCA)
void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value)
Set the CCA threshold value.
int at86rf2xx_init_event(at86rf2xx_bhp_ev_t *bhp, const at86rf2xx_params_t *params, ieee802154_dev_t *hal, event_queue_t *evq)
Init an AT86RF2XX device with an event based Bottom Half Processor.
void at86rf2xx_set_addr_long(at86rf2xx_t *dev, const eui64_t *addr)
Set the long address of the given device.
void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries)
Set the maximum number of channel access attempts per frame (CSMA)
uint8_t at86rf2xx_get_rate(at86rf2xx_t *dev)
Get the current O-QPSK rate mode of the PHY.
void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2])
Set seed for CSMA random backoff.
uint8_t at86rf2xx_get_phy_mode(at86rf2xx_t *dev)
Get the PHY mode of the given device.
uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state)
Set the state of the given device (trigger a state change)
int8_t at86rf2xx_get_rxsensitivity(const at86rf2xx_t *dev)
Get the configured receiver sensitivity of the given device [in dBm].
uint8_t at86rf2xx_get_csma_max_retries(const at86rf2xx_t *dev)
Get the maximum number of channel access attempts per frame (CSMA)
struct at86rf2xx_params at86rf2xx_params_t
struct holding all params needed for device initialization
void at86rf2xx_enable_smart_idle(at86rf2xx_t *dev)
Enable the smart receive technology (SRT)
void at86rf2xx_disable_clock_output(at86rf2xx_t *dev)
Disable AT86RF2XX clock output.
void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max)
Set the maximum number of retransmissions.
void at86rf2xx_irq_handler(ieee802154_dev_t *hal)
Offload pending IRQ.
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.
int at86rf2xx_init(at86rf2xx_t *dev, const at86rf2xx_params_t *params, ieee802154_dev_t *hal, void(*cb)(void *), void *ctx)
Init an AT86RF2XX device.
void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
uint8_t at86rf2xx_get_max_retries(const at86rf2xx_t *dev)
Get the maximum number of retransmissions.
void at86rf2xx_set_addr_short(at86rf2xx_t *dev, const network_uint16_t *addr)
Set the short address of the given device.
void at86rf2xx_set_rxsensitivity(const at86rf2xx_t *dev, int8_t rxsens)
Set the receiver sensitivity of the given device [in dBm].
int8_t at86rf2xx_get_ed_level(at86rf2xx_t *dev)
Get the latest ED level measurement.
struct ieee802154_dev ieee802154_dev_t
Forward declaration of the IEEE802.15.4 device descriptor.
Definition radio.h:414
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition spi.h:157
struct PTRTAG event_queue_t
event queue structure
struct event event_t
event structure forward declaration
Definition event.h:132
Common macros and compiler attributes/pragmas configuration.
Protocol type definitions.
Low-level SPI peripheral driver interface definition.
Event Bottom Half Processor descriptor for AT86RF2XX transceivers.
Definition at86rf2xx.h:297
event_queue_t * evq
Pointer to the event queue.
Definition at86rf2xx.h:300
event_t ev
ISR offload event.
Definition at86rf2xx.h:301
at86rf2xx_t dev
Device descriptor.
Definition at86rf2xx.h:298
ieee802154_dev_t * hal
Pointer to the Radio HAL descriptor.
Definition at86rf2xx.h:299
struct holding all params needed for device initialization
Definition at86rf2xx.h:266
spi_t spi
SPI bus the device is connected to.
Definition at86rf2xx.h:267
spi_cs_t cs_pin
GPIO pin connected to chip select.
Definition at86rf2xx.h:269
gpio_t reset_pin
GPIO pin connected to the reset pin.
Definition at86rf2xx.h:272
gpio_t sleep_pin
GPIO pin connected to the sleep pin.
Definition at86rf2xx.h:271
gpio_t int_pin
GPIO pin connected to the interrupt pin.
Definition at86rf2xx.h:270
spi_clk_t spi_clk
SPI clock speed to use.
Definition at86rf2xx.h:268
Device descriptor for AT86RF2XX radio devices.
Definition at86rf2xx.h:281
bool sleep
whether the device is sleeping or not
Definition at86rf2xx.h:290
mutex_t lock
device lock
Definition at86rf2xx.h:291
at86rf2xx_params_t params
parameters for initialization
Definition at86rf2xx.h:284
Bottom Half Processor descriptor.
Definition bhp.h:47
Mutex structure.
Definition mutex.h:36
Data type to represent an EUI-64.
Definition eui64.h:52