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#else
64# define AT86RF2XX_MIN_CHANNEL (IEEE802154_CHANNEL_MIN)
65# define AT86RF2XX_MAX_CHANNEL (IEEE802154_CHANNEL_MAX)
66# define AT86RF2XX_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_CHANNEL)
67#endif
69
73#define AT86RF2XX_DEFAULT_TXPOWER (CONFIG_IEEE802154_DEFAULT_TXPOWER)
74
78#if MODULE_AT86RF233
79# define RSSI_BASE_VAL (-94)
80#elif MODULE_AT86RF212B
85# define RSSI_BASE_VAL (-98)
86#elif MODULE_AT86RFA1 || MODULE_AT86RFR2
87# define RSSI_BASE_VAL (-90)
88#else
89# define RSSI_BASE_VAL (-91)
90#endif
91
95#if MODULE_AT86RF233
96# define MIN_RX_SENSITIVITY (-101)
97#elif MODULE_AT86RF212B
98# define MIN_RX_SENSITIVITY (-110)
99#elif MODULE_AT86RFA1 || MODULE_AT86RFR2
100# define MIN_RX_SENSITIVITY (-100)
101#else
102# define MIN_RX_SENSITIVITY (-101)
103#endif
104
108#if IS_USED(MODULE_AT86RFA1) || IS_USED(MODULE_AT86RFR2)
109# define AT86RF2XX_IS_PERIPH (1)
110#else
111# define AT86RF2XX_IS_PERIPH (0)
112#endif
113
117#if defined(MODULE_AT86RF231) || IS_ACTIVE(AT86RF2XX_PERIPH)
118# define AT86RF2XX_HAVE_ED_REGISTER (1)
119#else
120# define AT86RF2XX_HAVE_ED_REGISTER (0)
121#endif
122
126#ifdef MODULE_AT86RF212B
127# define AT86RF2XX_HAVE_SUBGHZ (1)
128#else
129# define AT86RF2XX_HAVE_SUBGHZ (0)
130#endif
131
132#if defined(DOXYGEN) || defined(MODULE_AT86RF232) || defined(MODULE_AT86RF233) || defined(MODULE_AT86RFR2)
139# define AT86RF2XX_HAVE_RETRIES (1)
140#else
141# define AT86RF2XX_HAVE_RETRIES (0)
142#endif
143
150#if AT86RF2XX_HAVE_RETRIES && defined(AT86RF2XX_REG__XAH_CTRL_2)
151# define AT86RF2XX_HAVE_RETRIES_REG (1)
152#else
153# define AT86RF2XX_HAVE_RETRIES_REG (0)
154#endif
155
159#ifdef AT86RF2XX_REG__IRQ_MASK1
160# define AT86RF2XX_HAVE_TX_START_IRQ (1)
161#else
162# define AT86RF2XX_HAVE_TX_START_IRQ (0)
163#endif
164
172#if defined(MODULE_AT86RF233) || defined(MODULE_AT86RF231) || defined(MODULE_AT86RFA1) || defined(MODULE_AT86RFR2)
173# ifndef AT86RF2XX_RANDOM_NUMBER_GENERATOR
174# define AT86RF2XX_RANDOM_NUMBER_GENERATOR (1)
175# endif
176#else
177# ifndef AT86RF2XX_RANDOM_NUMBER_GENERATOR
178# define AT86RF2XX_RANDOM_NUMBER_GENERATOR (0)
179# endif
180#endif
181
190#if defined(MODULE_AT86RF233) || defined(MODULE_AT86RFR2)
191# ifndef AT86RF2XX_SMART_IDLE_LISTENING
192# define AT86RF2XX_SMART_IDLE_LISTENING (1)
193# endif
194#else
195# define AT86RF2XX_SMART_IDLE_LISTENING (0)
196#endif
197
202#define AT86RF2XX_STATE_P_ON (0x00)
203#define AT86RF2XX_STATE_BUSY_RX (0x01)
204#define AT86RF2XX_STATE_BUSY_TX (0x02)
205#define AT86RF2XX_STATE_FORCE_TRX_OFF (0x03)
206#define AT86RF2XX_STATE_RX_ON (0x06)
207#define AT86RF2XX_STATE_TRX_OFF (0x08)
208#define AT86RF2XX_STATE_PLL_ON (0x09)
209#define AT86RF2XX_STATE_SLEEP (0x0f)
210#define AT86RF2XX_STATE_BUSY_RX_AACK (0x11)
211#define AT86RF2XX_STATE_BUSY_TX_ARET (0x12)
212#define AT86RF2XX_STATE_RX_AACK_ON (0x16)
213#define AT86RF2XX_STATE_TX_ARET_ON (0x19)
214#define AT86RF2XX_STATE_IN_PROGRESS (0x1f)
216
221#define AT86RF2XX_OPT_CSMA (0x0010)
222#define AT86RF2XX_OPT_PROMISCUOUS (0x0020)
223#define AT86RF2XX_OPT_PRELOADING (0x0040)
224#define AT86RF2XX_OPT_AUTOACK (0x0080)
225#define AT86RF2XX_OPT_ACK_PENDING (0x0100)
226
228
229#if IS_ACTIVE(AT86RF2XX_BASIC_MODE) || defined(DOXYGEN)
233# define AT86RF2XX_PHY_STATE_RX AT86RF2XX_STATE_RX_ON
237# define AT86RF2XX_PHY_STATE_RX_BUSY AT86RF2XX_STATE_BUSY_RX
241# define AT86RF2XX_PHY_STATE_TX AT86RF2XX_STATE_PLL_ON
245# define AT86RF2XX_PHY_STATE_TX_BUSY AT86RF2XX_STATE_BUSY_TX
246#else
247# define AT86RF2XX_PHY_STATE_RX AT86RF2XX_STATE_RX_AACK_ON
248# define AT86RF2XX_PHY_STATE_RX_BUSY AT86RF2XX_STATE_BUSY_RX_AACK
249# define AT86RF2XX_PHY_STATE_TX AT86RF2XX_STATE_TX_ARET_ON
250# define AT86RF2XX_PHY_STATE_TX_BUSY AT86RF2XX_STATE_BUSY_TX_ARET
251#endif /* IS_ACTIVE(AT86RF2XX_BASIC_MODE) */
252
253#if AT86RF2XX_IS_PERIPH
257typedef void at86rf2xx_params_t;
258#else
270#endif
271
277typedef struct {
278#if !AT86RF2XX_IS_PERIPH
279 /* device specific fields */
281#endif
282#if AT86RF2XX_HAVE_RETRIES && AT86RF2XX_IS_PERIPH
283 /* Only radios with the XAH_CTRL_2 register support frame retry reporting */
284 int8_t tx_retries;
285#endif
286 bool sleep;
289
299
307
315
323
332
347int at86rf2xx_set_rate(at86rf2xx_t *dev, uint8_t rate);
348
355void at86rf2xx_set_pan(at86rf2xx_t *dev, uint16_t pan);
356
365
377void at86rf2xx_set_rxsensitivity(const at86rf2xx_t *dev, int8_t rxsens);
378
387
398void at86rf2xx_set_max_retries(const at86rf2xx_t *dev, uint8_t max);
399
408
420void at86rf2xx_set_csma_max_retries(const at86rf2xx_t *dev, int8_t retries);
421
433 uint8_t min, uint8_t max);
434
441void at86rf2xx_set_csma_seed(const at86rf2xx_t *dev, const uint8_t entropy[2]);
442
451
458void at86rf2xx_set_cca_threshold(const at86rf2xx_t *dev, int8_t value);
459
468
476void at86rf2xx_set_option(at86rf2xx_t *dev, uint16_t option, bool state);
477
486uint8_t at86rf2xx_set_state(at86rf2xx_t *dev, uint8_t state);
487
499
509
517
526
537
551int at86rf2xx_init(at86rf2xx_t *dev, const at86rf2xx_params_t *params, ieee802154_dev_t *hal, void (*cb)(void*), void *ctx);
552
566
567#ifdef __cplusplus
568}
569#endif
570
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:415
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:293
event_queue_t * evq
Pointer to the event queue.
Definition at86rf2xx.h:296
event_t ev
ISR offload event.
Definition at86rf2xx.h:297
at86rf2xx_t dev
Device descriptor.
Definition at86rf2xx.h:294
ieee802154_dev_t * hal
Pointer to the Radio HAL descriptor.
Definition at86rf2xx.h:295
struct holding all params needed for device initialization
Definition at86rf2xx.h:262
spi_t spi
SPI bus the device is connected to.
Definition at86rf2xx.h:263
spi_cs_t cs_pin
GPIO pin connected to chip select.
Definition at86rf2xx.h:265
gpio_t reset_pin
GPIO pin connected to the reset pin.
Definition at86rf2xx.h:268
gpio_t sleep_pin
GPIO pin connected to the sleep pin.
Definition at86rf2xx.h:267
gpio_t int_pin
GPIO pin connected to the interrupt pin.
Definition at86rf2xx.h:266
spi_clk_t spi_clk
SPI clock speed to use.
Definition at86rf2xx.h:264
Device descriptor for AT86RF2XX radio devices.
Definition at86rf2xx.h:277
bool sleep
whether the device is sleeping or not
Definition at86rf2xx.h:286
mutex_t lock
device lock
Definition at86rf2xx.h:287
at86rf2xx_params_t params
parameters for initialization
Definition at86rf2xx.h:280
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