at86rf215_internal.h File Reference

Low-Level functions for the AT86RF215 driver. More...

Detailed Description

Low-Level functions for the AT86RF215 driver.

Author
Benjamin Valentin benja.nosp@m.min..nosp@m.valen.nosp@m.tin@.nosp@m.ml-pa.nosp@m..com

Definition in file at86rf215_internal.h.

#include <stdint.h>
#include "at86rf215.h"
#include "at86rf215_registers.h"
+ Include dependency graph for at86rf215_internal.h:

Go to the source code of this file.

Macros

#define AT86RF215_RESET_PULSE_WIDTH_US   (16U)
 Minimum reset pulse width (tRST) in µs.
 
#define AT86RF215_RESET_DELAY_US   (16U)
 The typical transition time to TRX_OFF after reset (tPOWERON) in µs.
 
#define AT86RF215_EDT_DEFAULT   (-84) /* dBm */
 Default energy detect threshold for CSMA (reset value)
 
#define AT86RF215_BACKOFF_PERIOD_IN_SYMBOLS   (20U)
 This is used to calculate the csma backoff based on the bitrate. More...
 
#define AT86RF215_ACK_PSDU_BYTES   (5)
 An ACK consists of 5 payload bytes.
 
#define AT86RF215_ACK_PERIOD_IN_SYMBOLS   (54U)
 This is used to calculate the ACK timeout based on the bitrate. More...
 
#define AT86RF215_OQPSK_MODE_LEGACY   (0x1)
 legacy mode, 250 kbit/s
 
#define AT86RF215_OQPSK_MODE_LEGACY_HDR   (0x3)
 legacy mode, high data rate
 
#define AT86RF215_MR_OQPSK_MODE(n)   ((n) << OQPSKPHRTX_MOD_SHIFT)
 MR-QPSK.
 

Functions

int at86rf215_hardware_reset (at86rf215_t *dev)
 Perform a reset of the entire chip. More...
 
void at86rf215_reg_write (const at86rf215_t *dev, uint16_t reg, uint8_t val)
 Write to a register at address addr from device dev. More...
 
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. More...
 
uint8_t at86rf215_reg_read (const at86rf215_t *dev, uint16_t reg)
 Read from a register at address addr from device dev. More...
 
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. More...
 
void at86rf215_filter_ack (at86rf215_t *dev, bool on)
 Enable / Disable the ACK filter. More...
 
void at86rf215_get_random (at86rf215_t *dev, void *data, size_t len)
 Read random data from the RNG. More...
 
int at86rf215_configure_legacy_OQPSK (at86rf215_t *dev, bool high_rate)
 Configure the radio to make use of O-QPSK modulation. More...
 
int at86rf215_configure_OQPSK (at86rf215_t *dev, uint8_t chips, uint8_t rate)
 Configure the radio to make use of O-QPSK modulation. More...
 
uint8_t at86rf215_OQPSK_get_chips (at86rf215_t *dev)
 Get the current O-QPSK chip rate. More...
 
int at86rf215_OQPSK_set_chips (at86rf215_t *dev, uint8_t chips)
 Set the current O-QPSK chip rate. More...
 
uint8_t at86rf215_OQPSK_get_mode (at86rf215_t *dev)
 Get the current O-QPSK rate mode. More...
 
int at86rf215_OQPSK_set_mode (at86rf215_t *dev, uint8_t mode)
 Set the current O-QPSK rate mode. More...
 
uint8_t at86rf215_OQPSK_get_mode_legacy (at86rf215_t *dev)
 Get the current legacy O-QPSK mode. More...
 
int at86rf215_OQPSK_set_mode_legacy (at86rf215_t *dev, bool high_rate)
 Set the current legacy O-QPSK rate mode. More...
 
static bool at86rf215_OQPSK_is_legacy (at86rf215_t *dev)
 Test if O-QPSK PHY operates in legacy mode. More...
 
uint8_t at86rf215_get_phy_mode (at86rf215_t *dev)
 Get the current PHY modulation. More...
 
uint16_t at86rf215_chan_valid (at86rf215_t *dev, uint16_t chan)
 Check if a channel number is valid. More...
 
const char * at86rf215_hw_state2a (uint8_t state)
 Converts radio state into human readable string. More...
 
const char * at86rf215_sw_state2a (at86rf215_state_t state)
 Converts state machine state into human readable string. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static void at86rf215_rf_cmd (const at86rf215_t *dev, uint8_t rf_cmd)
 Issue a radio command to the device. More...
 
static uint8_t at86rf215_get_rf_state (const at86rf215_t *dev)
 Get the radio state of the device. More...
 
static void at86rf215_await_state (const at86rf215_t *dev, uint8_t state)
 Blocks until the device has reached the given state. More...
 
static void at86rf215_await_state_end (const at86rf215_t *dev, uint8_t state)
 Blocks until the device has reached the given state. More...
 
bool at86rf215_set_rx_from_idle (at86rf215_t *dev, uint8_t *old_state)
 Switch device back to IDLE-RX from non-RX idle. More...
 
bool at86rf215_set_idle_from_rx (at86rf215_t *dev, uint8_t state)
 Switch device to non-RX idle state from RX. More...
 
static void at86rf215_enable_baseband (const at86rf215_t *dev)
 Enable the baseband processor of the device. More...
 
static void at86rf215_disable_baseband (const at86rf215_t *dev)
 Disable the baseband processor of the device. More...
 
static void at86rf215_enable_radio (at86rf215_t *dev, uint8_t modulation)
 Enable the radio hardware with a given modulation. More...
 
void at86rf215_disable_rpc (at86rf215_t *dev)
 Internal convenience function to disable reduced power consumption (RPC) for energy detection. More...
 
void at86rf215_enable_rpc (at86rf215_t *dev)
 Internal convenience function to re-enable reduced power consumption (RPC) after energy detection. More...
 
bool at86rf215_switch_mode (at86rf215_t *dev, uint8_t new_mode)
 Notify the driver and stack about a change in transmission mode which may result in a change of PDU. More...
 
static bool is_subGHz (const at86rf215_t *dev)
 Checks whether the device operates in the sub-GHz band. More...
 
#define AT86RF215_RETRIES_MAX_DEFAULT   (3)
 Default Parameters for 802.15.4 retransmissions & CSMA.
 
#define AT86RF215_CSMA_RETRIES_MAX_DEFAULT   (4)
 
#define AT86RF215_CSMA_MIN_BE_DEFAULT   (3)
 
#define AT86RF215_CSMA_MAX_BE_DEFAULT   (5)
 

Macro Definition Documentation

◆ AT86RF215_ACK_PERIOD_IN_SYMBOLS

#define AT86RF215_ACK_PERIOD_IN_SYMBOLS   (54U)

This is used to calculate the ACK timeout based on the bitrate.

AT86RF233 uses an ACK timeout of 54 symbol periods, or 864 µs @ 250 kbit/s -> 864µs * 250kbit/s = 216 bit

Definition at line 67 of file at86rf215_internal.h.

◆ AT86RF215_BACKOFF_PERIOD_IN_SYMBOLS

#define AT86RF215_BACKOFF_PERIOD_IN_SYMBOLS   (20U)

This is used to calculate the csma backoff based on the bitrate.

20 symbols is the std period length

Definition at line 48 of file at86rf215_internal.h.

Function Documentation

◆ at86rf215_await_state()

static void at86rf215_await_state ( const at86rf215_t dev,
uint8_t  state 
)
inlinestatic

Blocks until the device has reached the given state.

Parameters
[in]devdevice to poll
[in]statethe expected state

Definition at line 372 of file at86rf215_internal.h.

◆ at86rf215_await_state_end()

static void at86rf215_await_state_end ( const at86rf215_t dev,
uint8_t  state 
)
inlinestatic

Blocks until the device has reached the given state.

Parameters
[in]devdevice to poll
[in]statethe expected state

Definition at line 383 of file at86rf215_internal.h.

◆ at86rf215_chan_valid()

uint16_t at86rf215_chan_valid ( at86rf215_t dev,
uint16_t  chan 
)

Check if a channel number is valid.

The function takes the current frequency band and modulation into account to determine if chan would be a legal channel number. If so, it is returned unmodified. Otherwise the next closest legal channel number is returned.

Note
This function does not change the configuration.
Parameters
[in]devdevice to check against
[in]chanthe channel number to check
Returns
If the channel number is legal, chan is returned. Otherwise the next closest legal channel number is returned.

◆ 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.

The rate mode may be

  • 0 for compatibility with first-gen 802.15.4 devices (250 kbit/s)
  • 1 for compatibility with the proprietary high-data rate modes of at86rf2xx
Parameters
[in]devdevice to configure
[in]high_rateuse proprietary high data rate compatible with at86rf2xx
Returns
0 on success, error otherwise

◆ 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.

The chip rate is the number of bits per second (chips per second) used in the spreading signal. The rate mode may be

Parameters
[in]devdevice to configure
[in]chipschip rate, BB_FCHIP100BB_FCHIP2000
[in]raterate mode, may be AT86RF215_OQPSK_MODE_LEGACY or AT86RF215_MR_OQPSK_MODE
Returns
0 on success, error otherwise

◆ at86rf215_disable_baseband()

static void at86rf215_disable_baseband ( const at86rf215_t dev)
inlinestatic

Disable the baseband processor of the device.

Parameters
[in]devdevice to disable the baseband on

Definition at line 423 of file at86rf215_internal.h.

◆ at86rf215_disable_rpc()

void at86rf215_disable_rpc ( at86rf215_t dev)

Internal convenience function to disable reduced power consumption (RPC) for energy detection.

Parameters
[in]devdevice to configure

◆ at86rf215_enable_baseband()

static void at86rf215_enable_baseband ( const at86rf215_t dev)
inlinestatic

Enable the baseband processor of the device.

Parameters
[in]devdevice to enable the baseband on

Definition at line 413 of file at86rf215_internal.h.

◆ at86rf215_enable_radio()

static void at86rf215_enable_radio ( at86rf215_t dev,
uint8_t  modulation 
)
inlinestatic

Enable the radio hardware with a given modulation.

Parameters
[in]devdevice to enable
[in]modulationmodulation to configure on the radio

Definition at line 433 of file at86rf215_internal.h.

◆ at86rf215_enable_rpc()

void at86rf215_enable_rpc ( at86rf215_t dev)

Internal convenience function to re-enable reduced power consumption (RPC) after energy detection.

Parameters
[in]devdevice to configure

◆ at86rf215_filter_ack()

void at86rf215_filter_ack ( at86rf215_t dev,
bool  on 
)

Enable / Disable the ACK filter.

Parameters
[in]devdevice to configure
[in]onif true, only ACK frames are received if false, only non-ACK frames are received

◆ at86rf215_get_phy_mode()

uint8_t at86rf215_get_phy_mode ( at86rf215_t dev)

Get the current PHY modulation.

May be IEEE802154_PHY_MR_FSK, IEEE802154_PHY_MR_OFDM, IEEE802154_PHY_MR_OQPSK, IEEE802154_PHY_OQPSK or IEEE802154_PHY_DISABLED.

Parameters
[in]devdevice to read from
Returns
the current PHY mode the device is operating with

◆ at86rf215_get_random()

void at86rf215_get_random ( at86rf215_t dev,
void *  data,
size_t  len 
)

Read random data from the RNG.

Precondition
The device has to be in state RX with PLL locked.
Parameters
[in]devdevice to configure
[out]databuffer to copy the random data to
[in]lennumber of random bytes to store in data

◆ at86rf215_get_rf_state()

static uint8_t at86rf215_get_rf_state ( const at86rf215_t dev)
inlinestatic

Get the radio state of the device.

Parameters
[in]devdevice to read from
Returns
the current radio state

Definition at line 361 of file at86rf215_internal.h.

◆ at86rf215_hardware_reset()

int at86rf215_hardware_reset ( at86rf215_t dev)

Perform a reset of the entire chip.

Parameters
devdevice to reset, will also reset sibling device
Returns
0 on success, error if device is not available

◆ at86rf215_hw_state2a()

const char* at86rf215_hw_state2a ( uint8_t  state)

Converts radio state into human readable string.

Parameters
[in]stateradio state
Returns
fixed string representation of the radio state

◆ at86rf215_OQPSK_get_chips()

uint8_t at86rf215_OQPSK_get_chips ( at86rf215_t dev)

Get the current O-QPSK chip rate.

Parameters
[in]devdevice to read from
Returns
the current chip rate

◆ at86rf215_OQPSK_get_mode()

uint8_t at86rf215_OQPSK_get_mode ( at86rf215_t dev)

Get the current O-QPSK rate mode.

Parameters
[in]devdevice to read from
Returns
the current rate mode

◆ at86rf215_OQPSK_get_mode_legacy()

uint8_t at86rf215_OQPSK_get_mode_legacy ( at86rf215_t dev)

Get the current legacy O-QPSK mode.

Parameters
[in]devdevice to read from
Returns
0 for IEEE 802.15.4 mode, 1 for high data rate

◆ at86rf215_OQPSK_is_legacy()

static bool at86rf215_OQPSK_is_legacy ( at86rf215_t dev)
inlinestatic

Test if O-QPSK PHY operates in legacy mode.

Parameters
[in]devdevice to test
Returns
true if device operates in legacy mode

Definition at line 234 of file at86rf215_internal.h.

◆ at86rf215_OQPSK_set_chips()

int at86rf215_OQPSK_set_chips ( at86rf215_t dev,
uint8_t  chips 
)

Set the current O-QPSK chip rate.

Parameters
[in]devdevice to configure
[in]chipschip rate in chip/s
Returns
0 on success, error otherwise

◆ at86rf215_OQPSK_set_mode()

int at86rf215_OQPSK_set_mode ( at86rf215_t dev,
uint8_t  mode 
)

Set the current O-QPSK rate mode.

Parameters
[in]devdevice to configure
[in]moderate mode
Returns
0 on success, error otherwise

◆ 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.

Parameters
[in]devdevice to configure
[in]high_rateset to use proprietary high data rate
Returns
0 on success, error otherwise

◆ at86rf215_reg_and()

static void at86rf215_reg_and ( const at86rf215_t dev,
uint16_t  reg,
uint8_t  val 
)
inlinestatic

Reads the contents of reg, apply val with a bitwise AND and then writes the result back to reg.

Parameters
[in]devdevice to write to
[in]regregister to write to
[in]valvalue to bitwise AND with the register content

Definition at line 296 of file at86rf215_internal.h.

◆ at86rf215_reg_or()

static void at86rf215_reg_or ( const at86rf215_t dev,
uint16_t  reg,
uint8_t  val 
)
inlinestatic

Reads the contents of reg, apply val with a bitwise OR and then writes the result back to reg.

Parameters
[in]devdevice to write to
[in]regregister to write to
[in]valvalue to bitwise OR with the register content

Definition at line 310 of file at86rf215_internal.h.

◆ 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.

Parameters
[in]devdevice to read from
[in]regaddress of the register to read
Returns
the value of the specified register

◆ at86rf215_reg_read16()

static uint16_t at86rf215_reg_read16 ( const at86rf215_t dev,
uint16_t  reg 
)
inlinestatic

Read a 16-bit word from a register at address addr from device dev.

Parameters
[in]devdevice to read from
[in]regaddress of the register to read
Returns
the value of the specified register

Definition at line 336 of file at86rf215_internal.h.

◆ 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.

Parameters
[in]devdevice to read from
[in]regstarting address to read from
[out]databuffer to read data into
[in]lennumber of bytes to read

◆ 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.

Parameters
[in]devdevice to write to
[in]regaddress of the register to write
[in]valvalue to write to the given register

◆ at86rf215_reg_write16()

static void at86rf215_reg_write16 ( const at86rf215_t dev,
uint16_t  reg,
uint16_t  val 
)
inlinestatic

Write a 16-bit word to a register at address addr from device dev.

Parameters
[in]devdevice to write to
[in]regaddress of the register to write
[in]valvalue to write to the given register

Definition at line 323 of file at86rf215_internal.h.

◆ 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.

Parameters
[in]devdevice to write to
[in]regaddress in the device to write to
[in]datadata to copy into the device
[in]lennumber of bytes to write into the device

◆ at86rf215_rf_cmd()

static void at86rf215_rf_cmd ( const at86rf215_t dev,
uint8_t  rf_cmd 
)
inlinestatic

Issue a radio command to the device.

Parameters
[in]devdevice to configure
[in]rf_cmdcommand to send

Definition at line 349 of file at86rf215_internal.h.

◆ 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.

Parameters
[in]devdevice to update
[out]statethe new state (may be CMD_RF_TRXOFF or CMD_RF_SLEEP)
Returns
true if the operation was possible

◆ 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.

Parameters
[in]devdevice to update
[out]old_statepointer to store the previous state, may be NULL
Returns
true if the operation was possible

◆ at86rf215_sw_state2a()

const char* at86rf215_sw_state2a ( at86rf215_state_t  state)

Converts state machine state into human readable string.

Parameters
[in]statestate of the driver's state machine
Returns
fixed string representation of the state machine state

◆ at86rf215_switch_mode()

bool at86rf215_switch_mode ( at86rf215_t dev,
uint8_t  new_mode 
)

Notify the driver and stack about a change in transmission mode which may result in a change of PDU.

Parameters
[in]devdevice that changed it's mode
[in]new_modethe new transmission mode

◆ is_subGHz()

static bool is_subGHz ( const at86rf215_t dev)
inlinestatic

Checks whether the device operates in the sub-GHz band.

Parameters
[in]devdevice to read from
Returns
true if the device operates in the sub-GHz band false if the device operates in the 2.4-GHz band

Definition at line 475 of file at86rf215_internal.h.