at86rf215.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 2019 ML!PA Consulting GmbH
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 
23 #ifndef AT86RF215_H
24 #define AT86RF215_H
25 
26 #include <stdint.h>
27 #include <stdbool.h>
28 
29 #include "board.h"
30 #include "periph/spi.h"
31 #include "periph/gpio.h"
32 #include "net/netdev.h"
33 #include "net/netdev/ieee802154.h"
34 #include "net/gnrc/nettype.h"
35 #include "xtimer.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
45 
50 
57 typedef void (*at86rf215_batmon_cb_t)(void *arg);
58 
62 enum {
63  AT86RF215_FCHIP_100,
64  AT86RF215_FCHIP_200,
65  AT86RF215_FCHIP_1000,
66  AT86RF215_FCHIP_2000,
67 };
68 
72 #define AT86RF215_MAX_PKT_LENGTH (2047)
73 
84 #ifdef DOXYGEN
85 #define CONFIG_AT86RF215_USE_CLOCK_OUTPUT
86 #endif
87 
88 #if defined(DOXYGEN) && !defined(CONFIG_AT86RF215_TRIM_VAL)
89 
101 #define CONFIG_AT86RF215_TRIM_VAL (0)
102 #endif
103 
108 #ifndef CONFIG_AT86RF215_DEFAULT_CHANNEL
109 #define CONFIG_AT86RF215_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_CHANNEL)
110 #endif
111 
112 #ifndef CONFIG_AT86RF215_DEFAULT_SUBGHZ_CHANNEL
113 #define CONFIG_AT86RF215_DEFAULT_SUBGHZ_CHANNEL (CONFIG_IEEE802154_DEFAULT_SUBGHZ_CHANNEL)
114 #endif
115 
121 #ifndef CONFIG_AT86RF215_RPC_EN
122 #define CONFIG_AT86RF215_RPC_EN (0)
123 #endif
124 
130 #if IS_ACTIVE(CONFIG_AT86RF215_DEFAULT_LEGACY_OQPSK)
131 #define CONFIG_AT86RF215_DEFAULT_PHY_MODE (IEEE802154_PHY_OQPSK)
132 #elif IS_ACTIVE(CONFIG_AT86RF215_DEFAULT_MR_OQPSK)
133 #define CONFIG_AT86RF215_DEFAULT_PHY_MODE (IEEE802154_PHY_MR_OQPSK)
134 #elif IS_ACTIVE(CONFIG_AT86RF215_DEFAULT_MR_OFDM)
135 #define CONFIG_AT86RF215_DEFAULT_PHY_MODE (IEEE802154_PHY_MR_OFDM)
136 #endif
137 
138 #ifndef CONFIG_AT86RF215_DEFAULT_PHY_MODE
139 #define CONFIG_AT86RF215_DEFAULT_PHY_MODE (IEEE802154_PHY_OQPSK)
140 #endif
141 
148 #ifndef CONFIG_AT86RF215_DEFAULT_OQPSK_RATE
149 #define CONFIG_AT86RF215_DEFAULT_OQPSK_RATE (0)
150 #endif
151 
157 #if IS_ACTIVE(CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS_100)
158 #define CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS (AT86RF215_FCHIP_100)
159 #elif IS_ACTIVE(CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS_200)
160 #define CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS (AT86RF215_FCHIP_200)
161 #elif IS_ACTIVE(CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS_1000)
162 #define CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS (AT86RF215_FCHIP_1000)
163 #elif IS_ACTIVE(CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS_2000)
164 #define CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS (AT86RF215_FCHIP_2000)
165 #endif
166 
167 #ifndef CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS
168 #define CONFIG_AT86RF215_DEFAULT_MR_OQPSK_CHIPS (AT86RF215_FCHIP_1000)
169 #endif
170 
176 #ifndef CONFIG_AT86RF215_DEFAULT_MR_OQPSK_RATE
177 #define CONFIG_AT86RF215_DEFAULT_MR_OQPSK_RATE (2)
178 #endif
179 
185 #ifndef CONFIG_AT86RF215_DEFAULT_MR_OFDM_OPT
186 #define CONFIG_AT86RF215_DEFAULT_MR_OFDM_OPT (2)
187 #endif
188 
194 #ifndef CONFIG_AT86RF215_DEFAULT_MR_OFDM_MCS
195 #define CONFIG_AT86RF215_DEFAULT_MR_OFDM_MCS (2)
196 #endif
197 
203 #ifndef CONFIG_AT86RF215_DEFAULT_MR_FSK_SRATE
204 #define CONFIG_AT86RF215_DEFAULT_MR_FSK_SRATE FSK_SRATE_200K
205 #endif
206 
212 #ifndef CONFIG_AT86RF215_DEFAULT_MR_FSK_MOD_IDX
213 #define CONFIG_AT86RF215_DEFAULT_MR_FSK_MOD_IDX (64)
214 #endif
215 
221 #ifndef CONFIG_AT86RF215_DEFAULT_MR_FSK_MORD
222 #define CONFIG_AT86RF215_DEFAULT_MR_FSK_MORD FSK_MORD_4SFK
223 #endif
224 
230 #ifndef CONFIG_AT86RF215_DEFAULT_MR_FSK_FEC
231 #define CONFIG_AT86RF215_DEFAULT_MR_FSK_FEC IEEE802154_FEC_NONE
232 #endif
233 
238 #ifndef CONFIG_AT86RF215_DEFAULT_TXPOWER
239 #define CONFIG_AT86RF215_DEFAULT_TXPOWER (CONFIG_IEEE802154_DEFAULT_TXPOWER)
240 #endif
241 
248 typedef enum {
258 enum {
259  AT86RF215_MODE_LEGACY_OQPSK,
260  AT86RF215_MODE_MR_OQPSK,
261  AT86RF215_MODE_MR_OFDM,
262  AT86RF215_MODE_MR_FSK
263 };
264 
269 #define AT86RF215_OPT_TELL_TX_START (0x0001)
270 #define AT86RF215_OPT_TELL_TX_END (0x0002)
271 #define AT86RF215_OPT_TELL_RX_START (0x0004)
272 #define AT86RF215_OPT_TELL_RX_END (0x0008)
273 #define AT86RF215_OPT_CSMA (0x0010)
274 #define AT86RF215_OPT_PROMISCUOUS (0x0020)
275 #define AT86RF215_OPT_PRELOADING (0x0040)
276 #define AT86RF215_OPT_AUTOACK (0x0080)
277 #define AT86RF215_OPT_ACK_REQUESTED (0x0100)
278 #define AT86RF215_OPT_AGCH (0x0200)
279 #define AT86RF215_OPT_TX_PENDING (0x0400)
280 #define AT86RF215_OPT_CCA_PENDING (0x0800)
281 #define AT86RF215_OPT_RPC (0x1000)
282 #define AT86RF215_OPT_CCATX (0x2000)
289 #define AT86RF215_TIMEOUT_ACK (0x0001)
290 #define AT86RF215_TIMEOUT_CSMA (0x0002)
296 typedef struct at86rf215_params {
300  gpio_t int_pin;
301  gpio_t reset_pin;
303 
309 typedef struct at86rf215 {
311  /* device specific fields */
313  struct at86rf215 *sibling;
318  uint32_t ack_timeout_usec;
320  uint16_t flags;
321  uint16_t num_chans;
322  uint16_t tx_frame_len;
323  uint8_t timeout;
324  uint8_t state;
325  uint8_t retries_max;
326  uint8_t retries;
328  uint8_t csma_retries;
329 #ifdef MODULE_NETDEV_IEEE802154_MR_FSK
330  uint8_t fsk_pl;
331 #endif
332  uint8_t csma_minbe;
333  uint8_t csma_maxbe;
334  int8_t csma_ed;
335 } at86rf215_t;
336 
346 void at86rf215_setup(at86rf215_t *dev_09, at86rf215_t *dev_24, const at86rf215_params_t *params, uint8_t index);
347 
354 
360 void at86rf215_reset(at86rf215_t *dev);
361 
370 uint16_t at86rf215_get_addr_short(const at86rf215_t *dev, uint8_t filter);
371 
379 void at86rf215_set_addr_short(at86rf215_t *dev, uint8_t filter, uint16_t addr);
380 
389 bool at86rf215_get_framefilter_enabled(at86rf215_t *dev, uint8_t filter);
390 
398  void at86rf215_disable_framefilter(at86rf215_t *dev, uint8_t filter);
399 
407 void at86rf215_enable_framefilter(at86rf215_t *dev, uint8_t filter);
408 
416 uint64_t at86rf215_get_addr_long(const at86rf215_t *dev);
417 
424 void at86rf215_set_addr_long(at86rf215_t *dev, uint64_t addr);
425 
433 uint8_t at86rf215_get_chan(const at86rf215_t *dev);
434 
441 void at86rf215_set_chan(at86rf215_t *dev, uint16_t chan);
442 
451 uint16_t at86rf215_get_pan(const at86rf215_t *dev, uint8_t filter);
452 
460 void at86rf215_set_pan(at86rf215_t *dev, uint8_t filter, uint16_t pan);
461 
469 int16_t at86rf215_get_txpower(const at86rf215_t *dev);
470 
482 void at86rf215_set_txpower(const at86rf215_t *dev, int16_t txpower);
483 
491 int8_t at86rf215_get_cca_threshold(const at86rf215_t *dev);
492 
499 void at86rf215_set_cca_threshold(at86rf215_t *dev, int8_t value);
500 
509 
517 void at86rf215_set_option(at86rf215_t *dev, uint16_t option, bool state);
518 
531 ssize_t at86rf215_send(at86rf215_t *dev, const void *data, size_t len);
532 
544 
555 size_t at86rf215_tx_load(at86rf215_t *dev, const uint8_t *data,
556  size_t len, size_t offset);
557 
566 
573 
580 void at86rf215_tx_done(at86rf215_t *dev);
581 
592 bool at86rf215_cca(at86rf215_t *dev);
593 
594 #ifdef __cplusplus
595 }
596 #endif
597 
598 #endif /* AT86RF215_H */
599 
at86rf215::csma_retries_max
uint8_t csma_retries_max
number of retries until channel is clear
Definition: at86rf215.h:327
AT86RF215_STATE_TX_WAIT_ACK
@ AT86RF215_STATE_TX_WAIT_ACK
sending frame, wait for ACK
Definition: at86rf215.h:253
xtimer
xtimer timer structure
Definition: xtimer.h:81
at86rf215_get_ed_level
int8_t at86rf215_get_ed_level(at86rf215_t *dev)
Get the latest ED level measurement.
at86rf215_get_addr_short
uint16_t at86rf215_get_addr_short(const at86rf215_t *dev, uint8_t filter)
Get the short address of the given device form multi address filter.
at86rf215_send
ssize_t at86rf215_send(at86rf215_t *dev, const void *data, size_t len)
Convenience function for simply sending data.
at86rf215::timer_msg
msg_t timer_msg
message for timeout timer
Definition: at86rf215.h:317
at86rf215_disable_framefilter
void at86rf215_disable_framefilter(at86rf215_t *dev, uint8_t filter)
Enables a frame filter.
at86rf215::csma_maxbe
uint8_t csma_maxbe
CSMA maximum backoff exponent.
Definition: at86rf215.h:333
at86rf215_state_t
at86rf215_state_t
Definition: at86rf215.h:248
at86rf215::sibling
struct at86rf215 * sibling
The other radio.
Definition: at86rf215.h:313
ieee802154.h
Definitions for netdev common IEEE 802.15.4 code.
at86rf215_params
struct holding all params needed for device initialization
Definition: at86rf215.h:296
spi.h
Low-level SPI peripheral driver interface definition.
at86rf215_batmon_cb_t
void(* at86rf215_batmon_cb_t)(void *arg)
Signature for the Battery monitor callback.
Definition: at86rf215.h:57
at86rf215_params_t
struct at86rf215_params at86rf215_params_t
struct holding all params needed for device initialization
at86rf215::ack_timeout_usec
uint32_t ack_timeout_usec
time to wait before retransmission in µs
Definition: at86rf215.h:318
netdev_ieee802154_t::pan
uint16_t pan
IEEE 802.15.4 specific fields.
Definition: ieee802154.h:103
at86rf215_params::spi_clk
spi_clk_t spi_clk
SPI clock speed to use.
Definition: at86rf215.h:298
at86rf215::RF
const at86rf215_RF_regs_t * RF
Radio Frontend Registers.
Definition: at86rf215.h:314
at86rf215_get_chan
uint8_t at86rf215_get_chan(const at86rf215_t *dev)
Get the configured channel number of the given device.
at86rf215_set_txpower
void at86rf215_set_txpower(const at86rf215_t *dev, int16_t txpower)
Set the transmission power of the given device [in dBm].
at86rf215::params
at86rf215_params_t params
parameters for initialization
Definition: at86rf215.h:312
at86rf215_reset
void at86rf215_reset(at86rf215_t *dev)
Trigger a hardware reset, configuration is retained.
at86rf215_t
struct at86rf215 at86rf215_t
Device descriptor for AT86RF215 radio devices.
at86rf215_tx_done
void at86rf215_tx_done(at86rf215_t *dev)
Signal that the transfer of the frame (and optional ACK reception) has finished.
at86rf215_setup
void at86rf215_setup(at86rf215_t *dev_09, at86rf215_t *dev_24, const at86rf215_params_t *params, uint8_t index)
Setup an AT86RF215 based device state.
at86rf215_params::cs_pin
spi_cs_t cs_pin
GPIO pin connected to chip select.
Definition: at86rf215.h:299
at86rf215::retries
uint8_t retries
retries left
Definition: at86rf215.h:326
at86rf215::csma_minbe
uint8_t csma_minbe
CSMA minimum backoff exponent.
Definition: at86rf215.h:332
at86rf215_BBC_regs
Base Band Controller registers.
Definition: at86rf215_registers.h:71
spi_cs_t
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition: spi.h:126
at86rf215_set_chan
void at86rf215_set_chan(at86rf215_t *dev, uint16_t chan)
Set the channel number of the given device.
at86rf215::num_chans
uint16_t num_chans
Number of legal channel at current modulation.
Definition: at86rf215.h:321
at86rf215::timeout
uint8_t timeout
indicates which timeout was reached
Definition: at86rf215.h:323
at86rf215_set_addr_short
void at86rf215_set_addr_short(at86rf215_t *dev, uint8_t filter, uint16_t addr)
Set the short address of the given device to multi address filter.
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
AT86RF215_STATE_OFF
@ AT86RF215_STATE_OFF
radio not configured
Definition: at86rf215.h:249
netdev.h
Definitions low-level network driver interface.
AT86RF215_STATE_IDLE
@ AT86RF215_STATE_IDLE
idle state, listening
Definition: at86rf215.h:250
at86rf215_tx_exec
int at86rf215_tx_exec(at86rf215_t *dev)
Trigger sending of data previously loaded into transmit buffer.
at86rf215_tx_prepare
int at86rf215_tx_prepare(at86rf215_t *dev)
Prepare for sending of data.
nettype.h
Protocol type definitions.
at86rf215_get_txpower
int16_t at86rf215_get_txpower(const at86rf215_t *dev)
Get the configured transmission power of the given device [in dBm].
at86rf215_get_framefilter_enabled
bool at86rf215_get_framefilter_enabled(at86rf215_t *dev, uint8_t filter)
Get whether a frame filter is enabled or not.
AT86RF215_STATE_RX_SEND_ACK
@ AT86RF215_STATE_RX_SEND_ACK
receiving frame, sending ACK
Definition: at86rf215.h:251
at86rf215_params::spi
spi_t spi
SPI bus the device is connected to.
Definition: at86rf215.h:297
at86rf215_set_pan
void at86rf215_set_pan(at86rf215_t *dev, uint8_t filter, uint16_t pan)
Set the PAN ID of the given address filter.
at86rf215_reset_and_cfg
void at86rf215_reset_and_cfg(at86rf215_t *dev)
Trigger a hardware reset and configure radio with default values.
at86rf215
Device descriptor for AT86RF215 radio devices.
Definition: at86rf215.h:309
at86rf215_params::int_pin
gpio_t int_pin
GPIO pin connected to the interrupt pin.
Definition: at86rf215.h:300
at86rf215_tx_load
size_t at86rf215_tx_load(at86rf215_t *dev, const uint8_t *data, size_t len, size_t offset)
Load chunks of data into the transmit buffer of the given device.
AT86RF215_STATE_SLEEP
@ AT86RF215_STATE_SLEEP
sleep mode, not listening
Definition: at86rf215.h:254
at86rf215::csma_ed
int8_t csma_ed
CSMA energy detect threshold.
Definition: at86rf215.h:334
netdev_ieee802154_t
Extended structure to hold IEEE 802.15.4 driver state.
Definition: ieee802154.h:90
gpio.h
Low-level GPIO peripheral driver interface definitions.
at86rf215::tx_frame_len
uint16_t tx_frame_len
length of the current TX frame
Definition: at86rf215.h:322
AT86RF215_STATE_TX
@ AT86RF215_STATE_TX
sending frame
Definition: at86rf215.h:252
at86rf215::BBC
const at86rf215_BBC_regs_t * BBC
Baseband Registers.
Definition: at86rf215.h:315
at86rf215::netdev
netdev_ieee802154_t netdev
netdev parent struct
Definition: at86rf215.h:310
at86rf215_params::reset_pin
gpio_t reset_pin
GPIO pin connected to the reset pin.
Definition: at86rf215.h:301
at86rf215_set_option
void at86rf215_set_option(at86rf215_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
at86rf215_set_addr_long
void at86rf215_set_addr_long(at86rf215_t *dev, uint64_t addr)
Set the long address of the given device.
at86rf215_get_addr_long
uint64_t at86rf215_get_addr_long(const at86rf215_t *dev)
Get the configured long address of the given device.
at86rf215_get_pan
uint16_t at86rf215_get_pan(const at86rf215_t *dev, uint8_t filter)
Get the configured PAN ID of the given device from multi address filter.
at86rf215::timer
xtimer_t timer
timer for ACK & CSMA timeout
Definition: at86rf215.h:316
at86rf215_RF_regs
Radio Frontend registers.
Definition: at86rf215_registers.h:34
at86rf215_set_cca_threshold
void at86rf215_set_cca_threshold(at86rf215_t *dev, int8_t value)
Set the CCA threshold value.
msg_t
Describes a message object which can be sent between threads.
Definition: msg.h:185
at86rf215_tx_abort
void at86rf215_tx_abort(at86rf215_t *dev)
Abort sending of data previously loaded into transmit buffer.
netdev_ieee802154_t::chan
uint8_t chan
channel
Definition: ieee802154.h:115
at86rf215_cca
bool at86rf215_cca(at86rf215_t *dev)
Perform one manual channel clear assessment (CCA)
at86rf215::flags
uint16_t flags
Device specific flags.
Definition: at86rf215.h:320
netdev_ieee802154_t::txpower
int16_t txpower
tx power in dBm
Definition: ieee802154.h:118
at86rf215::csma_backoff_period
uint32_t csma_backoff_period
CSMA Backoff period.
Definition: at86rf215.h:319
at86rf215_enable_framefilter
void at86rf215_enable_framefilter(at86rf215_t *dev, uint8_t filter)
Disables a frame filter.
xtimer.h
xtimer interface definitions
at86rf215::retries_max
uint8_t retries_max
number of retries until ACK is received
Definition: at86rf215.h:325
at86rf215::state
uint8_t state
current state of the radio
Definition: at86rf215.h:324
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
at86rf215::csma_retries
uint8_t csma_retries
CSMA retries left.
Definition: at86rf215.h:328
at86rf215_get_cca_threshold
int8_t at86rf215_get_cca_threshold(const at86rf215_t *dev)
Get the CCA threshold value.