MRF24J40 based drivers

This module contains drivers for radio devices in Microchip MRF24J40 series. More...

Detailed Description

The driver is aimed to work with all devices of this series.

Files

file  mrf24j40.h
 Interface definition for MRF24J40 based drivers.
 
file  mrf24j40_internal.h
 Internal interfaces for MRF24J40 drivers.
 
file  mrf24j40_netdev.h
 Netdev interface to MRF24J40 drivers.
 
file  mrf24j40_registers.h
 Register and command definitions for MRF24J40 devices.
 

Data Structures

struct  mrf24j40_params
 struct holding all params needed for device initialization More...
 
struct  mrf24j40_t
 Device descriptor for MRF24J40 radio devices. More...
 

Macros

#define RSSI_BASE_VAL   (-91)
 Default TX power (0dBm) 0 -> -36dB 1 -> -35dB 2 -> -34dB 3 -> -33dB 4 -> -32dB 5 -> -31dB 6 -> -30dB 7 -> -30dB 8 -> -26dB 9 -> -25dB 10 -> -24dB 11 -> -23dB 12 -> -22dB 13 -> -21dB 14 -> -20dB 15 -> -20dB 16 -> -16dB 17 -> -15dB 18 -> -14dB 19 -> -13dB 20 -> -12dB 21 -> -11dB 22 -> -10dB 23 -> -10dB 24 -> -6dB 25 -> -5dB 26 -> -4dB 27 -> -3dB 28 -> -2dB 29 -> -1dB 30 -> -0dB 31 -> -0dB. More...
 
#define MRF24J40_TASK_TX_DONE   (0x01)
 TX operation is done.
 
#define MRF24J40_TASK_TX_READY   (0x02)
 TX operation results ready for processing.
 
#define MRF24J40_TASK_RX_READY   (0x04)
 RX processing needed.
 
#define MRF24J40_MAX_FRAME_RETRIES   (3U)
 Number of frame retries (fixed)
 

Typedefs

typedef struct mrf24j40_params mrf24j40_params_t
 struct holding all params needed for device initialization
 

Functions

void mrf24j40_setup (mrf24j40_t *dev, const mrf24j40_params_t *params)
 Setup an MRF24J40 based device state. More...
 
void mrf24j40_reset (mrf24j40_t *dev)
 Trigger a hardware reset and configure radio with default values. More...
 
bool mrf24j40_cca (mrf24j40_t *dev)
 Trigger a clear channel assessment. More...
 
uint16_t mrf24j40_get_addr_short (mrf24j40_t *dev)
 Get the short address of the given device. More...
 
void mrf24j40_set_addr_short (mrf24j40_t *dev, uint16_t addr)
 Set the short address of the given device. More...
 
uint64_t mrf24j40_get_addr_long (mrf24j40_t *dev)
 Get the configured long address of the given device. More...
 
void mrf24j40_set_addr_long (mrf24j40_t *dev, uint64_t addr)
 Set the long address of the given device. More...
 
uint8_t mrf24j40_get_chan (mrf24j40_t *dev)
 Get the configured channel number of the given device. More...
 
void mrf24j40_set_chan (mrf24j40_t *dev, uint8_t chan)
 Set the channel number of the given device. More...
 
uint16_t mrf24j40_get_pan (mrf24j40_t *dev)
 Get the configured PAN ID of the given device. More...
 
void mrf24j40_set_pan (mrf24j40_t *dev, uint16_t pan)
 Set the PAN ID of the given device. More...
 
int16_t mrf24j40_get_txpower (mrf24j40_t *dev)
 Get the configured transmission power of the given device [in dBm]. More...
 
void mrf24j40_set_txpower (mrf24j40_t *dev, int16_t txpower)
 Set the transmission power of the given device [in dBm]. More...
 
uint8_t mrf24j40_get_csma_max_retries (mrf24j40_t *dev)
 Get the maximum number of channel access attempts per frame (CSMA) More...
 
void mrf24j40_set_csma_max_retries (mrf24j40_t *dev, int8_t retries)
 Set the maximum number of channel access attempts per frame (CSMA) More...
 
void mrf24j40_set_csma_backoff_exp (mrf24j40_t *dev, uint8_t min, uint8_t max)
 Set the min and max backoff exponent for CSMA/CA. More...
 
int8_t mrf24j40_get_cca_threshold (mrf24j40_t *dev)
 Get the CCA threshold value. More...
 
void mrf24j40_set_cca_threshold (mrf24j40_t *dev, int8_t value)
 Set the CCA threshold value. More...
 
void mrf24j40_set_option (mrf24j40_t *dev, uint16_t option, bool state)
 Enable or disable driver specific options. More...
 
void mrf24j40_set_state (mrf24j40_t *dev, uint8_t state)
 Set the state of the given device (trigger a state change) More...
 
void mrf24j40_sleep (mrf24j40_t *dev)
 Put in sleep mode. More...
 
void mrf24j40_assert_sleep (mrf24j40_t *dev)
 Put in sleep mode if idle_state is sleep. More...
 
void mrf24j40_assert_awake (mrf24j40_t *dev)
 Wake up from sleep mode. More...
 
void mrf24j40_reset_state_machine (mrf24j40_t *dev)
 Reset the internal state machine to TRX_OFF mode. More...
 
void mrf24j40_software_reset (mrf24j40_t *dev)
 Software Reset. More...
 
void mrf24j40_tx_prepare (mrf24j40_t *dev)
 Prepare for sending of data. More...
 
size_t mrf24j40_tx_load (mrf24j40_t *dev, uint8_t *data, size_t len, size_t offset)
 Load chunks of data into the transmit buffer of the given device. More...
 
void mrf24j40_tx_exec (mrf24j40_t *dev)
 Trigger sending of data previously loaded into transmit buffer. More...
 
#define MRF24J40_PSEUDO_STATE_IDLE   (0x01)
 Flags for PSEUDO DEVICE INTERNAL STATES. More...
 
#define MRF24J40_PSEUDO_STATE_SLEEP   (0x02)
 sleep mode, registers functional, but no RF
 
#define MRF24J40_PSEUDO_STATE_RESET   (0x04)
 Reset device, next state is idle.
 
#define MRF24J40_OPT_CSMA   (0x0100)
 Internal device option flags. More...
 
#define MRF24J40_OPT_PROMISCUOUS   (0x0200)
 promiscuous mode active
 
#define MRF24J40_OPT_PRELOADING   (0x0400)
 preloading enabled
 
#define MRF24J40_OPT_TELL_TX_START   (0x0800)
 notify MAC layer on TX start
 
#define MRF24J40_OPT_TELL_TX_END   (0x1000)
 notify MAC layer on TX finished
 
#define MRF24J40_OPT_TELL_RX_START   (0x2000)
 notify MAC layer on RX start
 
#define MRF24J40_OPT_TELL_RX_END   (0x4000)
 notify MAC layer on RX finished
 
#define MRF24J40_OPT_REQ_AUTO_ACK   (0x8000)
 notify MAC layer on RX finished
 

Macro Definition Documentation

#define MRF24J40_OPT_CSMA   (0x0100)

0x00ff is reserved for general IEEE 802.15.4 flags (see netdev_ieee802154_t)CSMA active

Definition at line 100 of file mrf24j40.h.

#define MRF24J40_PSEUDO_STATE_IDLE   (0x01)

Idle, ready to transmit or receive

Definition at line 87 of file mrf24j40.h.

#define RSSI_BASE_VAL   (-91)

Base (minimal) RSSI value in dBm

Definition at line 81 of file mrf24j40.h.

Function Documentation

void mrf24j40_assert_awake ( mrf24j40_t dev)
Parameters
[in]devdevice to eventually wake up
void mrf24j40_assert_sleep ( mrf24j40_t dev)
Parameters
[in]devdevice to put to sleep
bool mrf24j40_cca ( mrf24j40_t dev)
Parameters
[in]devdevice to use
Returns
true if channel is clear
false if channel is busy
uint64_t mrf24j40_get_addr_long ( mrf24j40_t dev)
Parameters
[in]devdevice to read from
Returns
the currently set (8-byte) long address
uint16_t mrf24j40_get_addr_short ( mrf24j40_t dev)
Parameters
[in]devdevice to read from
Returns
the currently set (2-byte) short address
int8_t mrf24j40_get_cca_threshold ( mrf24j40_t dev)
Parameters
[in]devdevice to read value from
Returns
the current CCA threshold value
uint8_t mrf24j40_get_chan ( mrf24j40_t dev)
Parameters
[in]devdevice to read from
Returns
the currently set channel number
uint8_t mrf24j40_get_csma_max_retries ( mrf24j40_t dev)
Parameters
[in]devdevice to read from
Returns
configured number of retries
uint16_t mrf24j40_get_pan ( mrf24j40_t dev)
Parameters
[in]devdevice to read from
Returns
the currently set PAN ID
int16_t mrf24j40_get_txpower ( mrf24j40_t dev)
Parameters
[in]devdevice to read from
Returns
configured transmission power in dBm
void mrf24j40_reset ( mrf24j40_t dev)
Parameters
[in]devdevice to reset
void mrf24j40_reset_state_machine ( mrf24j40_t dev)

This will force a transition to TRX_OFF regardless of whether the transceiver is currently busy sending or receiving. This function is used to get back to a known state during driver initialization.

Parameters
[in]devdevice to operate on
void mrf24j40_set_addr_long ( mrf24j40_t dev,
uint64_t  addr 
)
Parameters
[in]devdevice to write to
[in]addr(8-byte) long address to set
void mrf24j40_set_addr_short ( mrf24j40_t dev,
uint16_t  addr 
)
Parameters
[in]devdevice to write to
[in]addr(2-byte) short address to set
void mrf24j40_set_cca_threshold ( mrf24j40_t dev,
int8_t  value 
)
Parameters
[in]devdevice to write to
[in]valuethe new CCA threshold value
void mrf24j40_set_chan ( mrf24j40_t dev,
uint8_t  chan 
)
Parameters
[in]devdevice to write to
[in]chanchannel number to set
void mrf24j40_set_csma_backoff_exp ( mrf24j40_t dev,
uint8_t  min,
uint8_t  max 
)
  • Maximum BE: 0 - 8
  • Minimum BE: 0 - [max]
Parameters
[in]devdevice to write to
[in]minthe minimum BE
[in]maxthe maximum BE
void mrf24j40_set_csma_max_retries ( mrf24j40_t dev,
int8_t  retries 
)

This setting specifies the number of attempts to access the channel to transmit a frame. If the channel is busy retries times, then frame transmission fails. Valid values: 0 to 5, -1 means CSMA disabled

Parameters
[in]devdevice to write to
[in]retriesthe maximum number of retries
void mrf24j40_set_option ( mrf24j40_t dev,
uint16_t  option,
bool  state 
)
Parameters
[in]devdevice to set/clear option flag for
[in]optionoption to enable/disable
[in]statetrue for enable, false for disable
void mrf24j40_set_pan ( mrf24j40_t dev,
uint16_t  pan 
)
Parameters
[in]devdevice to write to
[in]panPAN ID to set
void mrf24j40_set_state ( mrf24j40_t dev,
uint8_t  state 
)
Parameters
[in]devdevice to change state of
[in]statethe targeted new state
void mrf24j40_set_txpower ( mrf24j40_t dev,
int16_t  txpower 
)

If the device does not support the exact dBm value given, it will set a value as close as possible to the given value. If the given value is larger or lower then the maximal or minimal possible value, the min or max value is set, respectively.

Parameters
[in]devdevice to write to
[in]txpowertransmission power in dBm
void mrf24j40_setup ( mrf24j40_t dev,
const mrf24j40_params_t params 
)
Parameters
[out]devdevice descriptor
[in]paramsparameters for device initialization
void mrf24j40_sleep ( mrf24j40_t dev)
Parameters
[in]devdevice to put to sleep
void mrf24j40_software_reset ( mrf24j40_t dev)

This will force the power management circuitry, the baseband circuitry and the MAC circuitry to be reset

Parameters
[in]devdevice to operate on
void mrf24j40_tx_exec ( mrf24j40_t dev)
Parameters
[in]devdevice to trigger
size_t mrf24j40_tx_load ( mrf24j40_t dev,
uint8_t *  data,
size_t  len,
size_t  offset 
)
Parameters
[in]devdevice to write data to
[in]databuffer containing the data to load
[in]lennumber of bytes in buffer
[in]offsetoffset used when writing data to internal buffer
Returns
offset + number of bytes written
void mrf24j40_tx_prepare ( mrf24j40_t dev)

This function puts the given device into the TX state, so no receiving of data is possible after it was called.

Parameters
[in]devdevice to prepare for sending