at86rf215_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 ML!PA Consulting GmbH
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef AT86RF215_INTERNAL_H
20 #define AT86RF215_INTERNAL_H
21 
22 #include <stdint.h>
23 #include "at86rf215.h"
24 #include "at86rf215_registers.h"
25 #include "board.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
34 #ifndef CONFIG_AT86RF215_RESET_PULSE_WIDTH_US
35 #define CONFIG_AT86RF215_RESET_PULSE_WIDTH_US (16U)
36 #endif
37 
41 #define AT86RF215_RESET_DELAY_US (16U)
42 
44 #define AT86RF215_EDT_DEFAULT (-84) /* dBm */
45 
50 #define AT86RF215_RETRIES_MAX_DEFAULT (3)
51 #define AT86RF215_CSMA_RETRIES_MAX_DEFAULT (4)
52 #define AT86RF215_CSMA_MIN_BE_DEFAULT (3)
53 #define AT86RF215_CSMA_MAX_BE_DEFAULT (5)
54 
57 #define AT86RF215_ACK_PSDU_BYTES (5)
58 
63 #define AT86RF215_ACK_PERIOD_IN_SYMBOLS (54U)
64 
65 #define AT86RF215_OQPSK_MODE_LEGACY (0x1)
66 #define AT86RF215_OQPSK_MODE_LEGACY_HDR (0x3)
67 #define AT86RF215_MR_OQPSK_MODE(n) ((n) << OQPSKPHRTX_MOD_SHIFT)
75 int at86rf215_hardware_reset(at86rf215_t *dev);
76 
84 void at86rf215_reg_write(const at86rf215_t *dev, uint16_t reg, uint8_t val);
85 
94 void at86rf215_reg_write_bytes(const at86rf215_t *dev, uint16_t reg, const void *data, size_t len);
95 
104 uint8_t at86rf215_reg_read(const at86rf215_t *dev, uint16_t reg);
105 
114 void at86rf215_reg_read_bytes(const at86rf215_t *dev, uint16_t reg, void *data, size_t len);
115 
123 void at86rf215_filter_ack(at86rf215_t *dev, bool on);
124 
134 void at86rf215_get_random(at86rf215_t *dev, void *data, size_t len);
135 
145 extern const uint8_t _at86rf215_fsk_srate_10kHz[];
146 
150 extern const uint8_t _at86rf215_fsk_channel_spacing_25kHz[];
151 
164 int at86rf215_configure_FSK(at86rf215_t *dev, uint8_t srate, uint8_t mod_idx, uint8_t mod_order, uint8_t fec);
165 
172 int at86rf215_FSK_set_srate(at86rf215_t *dev, uint8_t srate);
173 
182 
196 int at86rf215_FSK_set_mod_idx(at86rf215_t *dev, uint8_t mod_idx);
197 
208 
222 int at86rf215_FSK_set_fec(at86rf215_t *dev, uint8_t mode);
223 
236 uint8_t at86rf215_FSK_get_fec(at86rf215_t *dev);
237 
246 int at86rf215_FSK_set_channel_spacing(at86rf215_t *dev, uint8_t ch_space);
247 
256 
266 int at86rf215_FSK_set_mod_order(at86rf215_t *dev, uint8_t mod_order);
267 
277 
285 
312 int at86rf215_configure_OFDM(at86rf215_t *dev, uint8_t option, uint8_t mcs);
313 
322 int at86rf215_OFDM_set_scheme(at86rf215_t *dev, uint8_t mcs);
323 
332 
341 int at86rf215_OFDM_set_option(at86rf215_t *dev, uint8_t option);
342 
351 
371 int at86rf215_configure_legacy_OQPSK(at86rf215_t *dev, bool high_rate);
372 
388 int at86rf215_configure_OQPSK(at86rf215_t *dev, uint8_t chips, uint8_t rate);
389 
398 
407 int at86rf215_OQPSK_set_chips(at86rf215_t *dev, uint8_t chips);
408 
417 
426 int at86rf215_OQPSK_set_mode(at86rf215_t *dev, uint8_t mode);
427 
436 
445 int at86rf215_OQPSK_set_mode_legacy(at86rf215_t *dev, bool high_rate);
446 
454 static inline bool at86rf215_OQPSK_is_legacy(at86rf215_t *dev) {
456 }
457 
470 uint8_t at86rf215_get_phy_mode(at86rf215_t *dev);
471 
488 uint16_t at86rf215_chan_valid(at86rf215_t *dev, uint16_t chan);
489 
497 const char* at86rf215_hw_state2a(uint8_t state);
498 
506 const char* at86rf215_sw_state2a(at86rf215_state_t state);
507 
516 static inline void at86rf215_reg_and(const at86rf215_t *dev, uint16_t reg, uint8_t val)
517 {
518  val &= at86rf215_reg_read(dev, reg);
519  at86rf215_reg_write(dev, reg, val);
520 }
521 
530 static inline void at86rf215_reg_or(const at86rf215_t *dev, uint16_t reg, uint8_t val)
531 {
532  val |= at86rf215_reg_read(dev, reg);
533  at86rf215_reg_write(dev, reg, val);
534 }
535 
543 static inline void at86rf215_reg_write16(const at86rf215_t *dev, uint16_t reg, uint16_t val)
544 {
545  at86rf215_reg_write_bytes(dev, reg, &val, sizeof(val));
546 }
547 
556 static inline uint16_t at86rf215_reg_read16(const at86rf215_t *dev, uint16_t reg)
557 {
558  uint16_t value;
559  at86rf215_reg_read_bytes(dev, reg, &value, sizeof(value));
560  return value;
561 }
562 
569 static inline void at86rf215_rf_cmd(const at86rf215_t *dev, uint8_t rf_cmd)
570 {
571  at86rf215_reg_write(dev, dev->RF->RG_CMD, rf_cmd);
572 }
573 
581 static inline uint8_t at86rf215_get_rf_state(const at86rf215_t *dev)
582 {
583  return at86rf215_reg_read(dev, dev->RF->RG_STATE) & STATE_STATE_MASK;
584 }
585 
592 static inline void at86rf215_await_state(const at86rf215_t *dev, uint8_t state)
593 {
594  while (at86rf215_get_rf_state(dev) != state) {}
595 }
596 
603 static inline void at86rf215_await_state_end(const at86rf215_t *dev, uint8_t state)
604 {
605  while (at86rf215_get_rf_state(dev) == state) {}
606 }
607 
616 bool at86rf215_set_rx_from_idle(at86rf215_t *dev, uint8_t *old_state);
617 
626 bool at86rf215_set_idle_from_rx(at86rf215_t *dev, uint8_t state);
627 
633 static inline void at86rf215_enable_baseband(const at86rf215_t *dev)
634 {
635  at86rf215_reg_or(dev, dev->BBC->RG_PC, PC_BBEN_MASK);
636 }
637 
643 static inline void at86rf215_disable_baseband(const at86rf215_t *dev) {
644  at86rf215_reg_and(dev, dev->BBC->RG_PC, ~PC_BBEN_MASK);
645 }
646 
653 static inline void at86rf215_enable_radio(at86rf215_t *dev, uint8_t modulation)
654 {
655  /* 16 bit frame-checksum, baseband enabled, checksum calculated by chip,
656  frames with invalid cs are dropped */
657  at86rf215_reg_write(dev, dev->BBC->RG_PC, modulation | PC_BBEN_MASK
658  | PC_FCST_MASK | PC_TXAFCS_MASK
659  | PC_FCSFE_MASK);
660 }
661 
669 
677 
686 static inline bool is_subGHz(const at86rf215_t *dev)
687 {
688  return dev->RF->RG_IRQS == RG_RF09_IRQS;
689 }
690 
691 #ifdef __cplusplus
692 }
693 #endif
694 
695 #endif /* AT86RF215_INTERNAL_H */
696 
at86rf215_RF_regs::RG_STATE
uint16_t RG_STATE
see datasheet
Definition: at86rf215_registers.h:38
at86rf215_FSK_set_mod_order
int at86rf215_FSK_set_mod_order(at86rf215_t *dev, uint8_t mod_order)
Configure the FSK modulation order.
at86rf215_get_random
void at86rf215_get_random(at86rf215_t *dev, void *data, size_t len)
Read random data from the RNG.
at86rf215_reg_write16
static void at86rf215_reg_write16(const at86rf215_t *dev, uint16_t reg, uint16_t val)
Write a 16-bit word to a register at address addr from device dev.
Definition: at86rf215_internal.h:543
at86rf215_OFDM_get_option
uint8_t at86rf215_OFDM_get_option(at86rf215_t *dev)
Get the current OFDM option.
at86rf215_reg_read16
static uint16_t at86rf215_reg_read16(const at86rf215_t *dev, uint16_t reg)
Read a 16-bit word from a register at address addr from device dev.
Definition: at86rf215_internal.h:556
at86rf215_enable_baseband
static void at86rf215_enable_baseband(const at86rf215_t *dev)
Enable the baseband processor of the device.
Definition: at86rf215_internal.h:633
at86rf215_FSK_get_fec
uint8_t at86rf215_FSK_get_fec(at86rf215_t *dev)
Get the Forward Error Correction (coding) scheme for FSK modulation.
at86rf215_hw_state2a
const char * at86rf215_hw_state2a(uint8_t state)
Converts radio state into human readable string.
at86rf215_get_rf_state
static uint8_t at86rf215_get_rf_state(const at86rf215_t *dev)
Get the radio state of the device.
Definition: at86rf215_internal.h:581
at86rf215_state_t
at86rf215_state_t
Definition: at86rf215.h:248
at86rf215_FSK_prepare_tx
void at86rf215_FSK_prepare_tx(at86rf215_t *dev)
The FSK premable length needs to be switched between RX and TX This function takes care of putting FS...
at86rf215_BBC_regs::RG_PC
uint16_t RG_PC
see datasheet
Definition: at86rf215_registers.h:78
at86rf215_FSK_prepare_rx
void at86rf215_FSK_prepare_rx(at86rf215_t *dev)
The FSK premable length needs to be switched between RX and TX This function takes care of putting FS...
at86rf215_OFDM_set_scheme
int at86rf215_OFDM_set_scheme(at86rf215_t *dev, uint8_t mcs)
Set the current modulation and coding scheme (MCS)
at86rf215::RF
const at86rf215_RF_regs_t * RF
Radio Frontend Registers.
Definition: at86rf215.h:314
at86rf215_get_phy_mode
uint8_t at86rf215_get_phy_mode(at86rf215_t *dev)
Get the current PHY modulation.
at86rf215_OQPSK_is_legacy
static bool at86rf215_OQPSK_is_legacy(at86rf215_t *dev)
Test if O-QPSK PHY operates in legacy mode.
Definition: at86rf215_internal.h:454
at86rf215_OQPSK_get_chips
uint8_t at86rf215_OQPSK_get_chips(at86rf215_t *dev)
Get the current O-QPSK chip rate.
at86rf215_FSK_set_srate
int at86rf215_FSK_set_srate(at86rf215_t *dev, uint8_t srate)
Configure the symbol rate of the FSK modulation.
at86rf215_OFDM_set_option
int at86rf215_OFDM_set_option(at86rf215_t *dev, uint8_t option)
Set the current OFDM option.
_at86rf215_fsk_channel_spacing_25kHz
const uint8_t _at86rf215_fsk_channel_spacing_25kHz[]
Channel Spacing for register values, in 25kHz.
at86rf215_BBC_regs::RG_OQPSKPHRTX
uint16_t RG_OQPSKPHRTX
see datasheet
Definition: at86rf215_registers.h:96
at86rf215_configure_FSK
int at86rf215_configure_FSK(at86rf215_t *dev, uint8_t srate, uint8_t mod_idx, uint8_t mod_order, uint8_t fec)
Configure the radio to make use of FSK modulation.
at86rf215_get_channel_spacing
uint16_t at86rf215_get_channel_spacing(at86rf215_t *dev)
Get the configured channel spacing.
at86rf215_OQPSK_get_mode
uint8_t at86rf215_OQPSK_get_mode(at86rf215_t *dev)
Get the current O-QPSK rate mode.
at86rf215_RF_regs::RG_IRQS
uint16_t RG_IRQS
see datasheet
Definition: at86rf215_registers.h:35
at86rf215_reg_read_bytes
void at86rf215_reg_read_bytes(const at86rf215_t *dev, uint16_t reg, void *data, size_t len)
Read a chunk of data from the memory of the given device.
at86rf215_OQPSK_set_mode
int at86rf215_OQPSK_set_mode(at86rf215_t *dev, uint8_t mode)
Set the current O-QPSK rate mode.
at86rf215_configure_legacy_OQPSK
int at86rf215_configure_legacy_OQPSK(at86rf215_t *dev, bool high_rate)
Configure the radio to make use of O-QPSK modulation.
at86rf215_configure_OQPSK
int at86rf215_configure_OQPSK(at86rf215_t *dev, uint8_t chips, uint8_t rate)
Configure the radio to make use of O-QPSK modulation.
at86rf215_reg_or
static void at86rf215_reg_or(const at86rf215_t *dev, uint16_t reg, uint8_t val)
Reads the contents of reg, apply val with a bitwise OR and then writes the result back to reg.
Definition: at86rf215_internal.h:530
at86rf215_configure_OFDM
int at86rf215_configure_OFDM(at86rf215_t *dev, uint8_t option, uint8_t mcs)
Configure the radio to make use of OFDM modulation.
at86rf215_reg_write
void at86rf215_reg_write(const at86rf215_t *dev, uint16_t reg, uint8_t val)
Write to a register at address addr from device dev.
at86rf215_chan_valid
uint16_t at86rf215_chan_valid(at86rf215_t *dev, uint16_t chan)
Check if a channel number is valid.
at86rf215_registers.h
Register Definitions for the AT86RF215 chip.
at86rf215_sw_state2a
const char * at86rf215_sw_state2a(at86rf215_state_t state)
Converts state machine state into human readable string.
at86rf215_set_rx_from_idle
bool at86rf215_set_rx_from_idle(at86rf215_t *dev, uint8_t *old_state)
Switch device back to IDLE-RX from non-RX idle.
at86rf215_disable_rpc
void at86rf215_disable_rpc(at86rf215_t *dev)
Internal convenience function to disable reduced power consumption (RPC) for energy detection.
at86rf215_OFDM_get_scheme
uint8_t at86rf215_OFDM_get_scheme(at86rf215_t *dev)
Get the current modulation and coding scheme (MCS)
at86rf215_enable_radio
static void at86rf215_enable_radio(at86rf215_t *dev, uint8_t modulation)
Enable the radio hardware with a given modulation.
Definition: at86rf215_internal.h:653
at86rf215_disable_baseband
static void at86rf215_disable_baseband(const at86rf215_t *dev)
Disable the baseband processor of the device.
Definition: at86rf215_internal.h:643
at86rf215_await_state_end
static void at86rf215_await_state_end(const at86rf215_t *dev, uint8_t state)
Blocks until the device has reached the given state.
Definition: at86rf215_internal.h:603
at86rf215_rf_cmd
static void at86rf215_rf_cmd(const at86rf215_t *dev, uint8_t rf_cmd)
Issue a radio command to the device.
Definition: at86rf215_internal.h:569
at86rf215
Device descriptor for AT86RF215 radio devices.
Definition: at86rf215.h:309
at86rf215_OQPSK_set_chips
int at86rf215_OQPSK_set_chips(at86rf215_t *dev, uint8_t chips)
Set the current O-QPSK chip rate.
at86rf215_await_state
static void at86rf215_await_state(const at86rf215_t *dev, uint8_t state)
Blocks until the device has reached the given state.
Definition: at86rf215_internal.h:592
at86rf215_FSK_get_mod_order
uint8_t at86rf215_FSK_get_mod_order(at86rf215_t *dev)
Get the current FSK modulation order.
at86rf215.h
Interface definition for AT86RF215 based drivers.
at86rf215_RF_regs::RG_CMD
uint16_t RG_CMD
see datasheet
Definition: at86rf215_registers.h:39
_at86rf215_fsk_srate_10kHz
const uint8_t _at86rf215_fsk_srate_10kHz[]
Symbol Rates for register values, in 10kHz.
at86rf215_OQPSK_get_mode_legacy
uint8_t at86rf215_OQPSK_get_mode_legacy(at86rf215_t *dev)
Get the current legacy O-QPSK mode.
at86rf215::BBC
const at86rf215_BBC_regs_t * BBC
Baseband Registers.
Definition: at86rf215.h:315
at86rf215_FSK_set_channel_spacing
int at86rf215_FSK_set_channel_spacing(at86rf215_t *dev, uint8_t ch_space)
Configure the channel spacing for the FSK modulation.
at86rf215_set_idle_from_rx
bool at86rf215_set_idle_from_rx(at86rf215_t *dev, uint8_t state)
Switch device to non-RX idle state from RX.
at86rf215_enable_rpc
void at86rf215_enable_rpc(at86rf215_t *dev)
Internal convenience function to re-enable reduced power consumption (RPC) after energy detection.
at86rf215_OQPSK_set_mode_legacy
int at86rf215_OQPSK_set_mode_legacy(at86rf215_t *dev, bool high_rate)
Set the current legacy O-QPSK rate mode.
is_subGHz
static bool is_subGHz(const at86rf215_t *dev)
Checks whether the device operates in the sub-GHz band.
Definition: at86rf215_internal.h:686
at86rf215_reg_and
static void at86rf215_reg_and(const at86rf215_t *dev, uint16_t reg, uint8_t val)
Reads the contents of reg, apply val with a bitwise AND and then writes the result back to reg.
Definition: at86rf215_internal.h:516
at86rf215_FSK_get_srate
uint8_t at86rf215_FSK_get_srate(at86rf215_t *dev)
Get the symbol rate of the FSK modulation.
at86rf215_FSK_set_mod_idx
int at86rf215_FSK_set_mod_idx(at86rf215_t *dev, uint8_t mod_idx)
Configure the modulation index of the FSK modulation The modulation index is a fractional value,...
at86rf215_FSK_set_fec
int at86rf215_FSK_set_fec(at86rf215_t *dev, uint8_t mode)
Configure the Forward Error Correction (coding) scheme for FSK modulation.
at86rf215_reg_read
uint8_t at86rf215_reg_read(const at86rf215_t *dev, uint16_t reg)
Read from a register at address addr from device dev.
at86rf215_filter_ack
void at86rf215_filter_ack(at86rf215_t *dev, bool on)
Enable / Disable the ACK filter.
AT86RF215_OQPSK_MODE_LEGACY
#define AT86RF215_OQPSK_MODE_LEGACY
legacy mode, 250 kbit/s
Definition: at86rf215_internal.h:65
at86rf215_reg_write_bytes
void at86rf215_reg_write_bytes(const at86rf215_t *dev, uint16_t reg, const void *data, size_t len)
Write a chunk of data into the memory of the given device.
at86rf215_FSK_get_mod_idx
uint8_t at86rf215_FSK_get_mod_idx(at86rf215_t *dev)
Get the current modulation index of the FSK modulation The modulation index is a fractional value,...