mrf24j40.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Neo Nenaco <neo@nenaco.de>
3  * Copyright (C) 2017 Koen Zandberg <koen@bergzand.net>
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser General
6  * Public License v2.1. See the file LICENSE in the top level directory for more
7  * details.
8  */
9 
62 #ifndef MRF24J40_H
63 #define MRF24J40_H
64 
65 #include <stdint.h>
66 
67 #include "board.h"
68 #include "periph/spi.h"
69 #include "periph/gpio.h"
70 #include "net/netdev.h"
71 #include "net/netdev/ieee802154.h"
72 #include "net/gnrc/nettype.h"
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
82 #define MRF24J40_PSEUDO_STATE_IDLE (0x01)
83 #define MRF24J40_PSEUDO_STATE_SLEEP (0x02)
84 #define MRF24J40_PSEUDO_STATE_RESET (0x04)
95 #define MRF24J40_OPT_CSMA (0x0100)
96 #define MRF24J40_OPT_PROMISCUOUS (0x0200)
98 #define MRF24J40_OPT_PRELOADING (0x0400)
99 #define MRF24J40_OPT_TELL_TX_START (0x0800)
101 #define MRF24J40_OPT_TELL_TX_END (0x1000)
103 #define MRF24J40_OPT_TELL_RX_START (0x2000)
105 #define MRF24J40_OPT_TELL_RX_END (0x4000)
107 #define MRF24J40_OPT_REQ_AUTO_ACK (0x8000)
112 #define MRF24J40_TASK_TX_DONE (0x01)
113 #define MRF24J40_TASK_TX_READY (0x02)
114 #define MRF24J40_TASK_RX_READY (0x04)
116 #define MRF24J40_MAX_FRAME_RETRIES (3U)
132 #if defined(DOXYGEN)
133 #define CONFIG_MRF24J40_USE_EXT_PA_LNA
134 #endif
135 
144 #if defined(DOXYGEN)
145 #define CONFIG_MRF24J40_TEST_SPI_CONNECTION
146 #endif
147 
152 typedef struct mrf24j40_params {
156  gpio_t int_pin;
157  gpio_t reset_pin;
159 
163 typedef struct {
165  /* device specific fields */
167  uint8_t state;
168  uint8_t idle_state;
169  uint8_t tx_frame_len;
170  uint8_t header_len;
171  uint8_t fcf_low;
172  uint8_t pending;
173  uint8_t irq_flag;
174  uint8_t tx_retries;
175 } mrf24j40_t;
176 
185 void mrf24j40_setup(mrf24j40_t *dev, const mrf24j40_params_t *params, uint8_t index);
186 
194 int mrf24j40_reset(mrf24j40_t *dev);
195 
205 bool mrf24j40_cca(mrf24j40_t *dev, int8_t *rssi);
206 
214 uint16_t mrf24j40_get_addr_short(mrf24j40_t *dev);
215 
222 void mrf24j40_set_addr_short(mrf24j40_t *dev, uint16_t addr);
223 
230 void mrf24j40_get_addr_long(mrf24j40_t *dev, uint8_t *addr);
231 
238 void mrf24j40_set_addr_long(mrf24j40_t *dev, const uint8_t *addr);
239 
247 uint8_t mrf24j40_get_chan(mrf24j40_t *dev);
248 
255 void mrf24j40_set_chan(mrf24j40_t *dev, uint8_t chan);
256 
264 uint16_t mrf24j40_get_pan(mrf24j40_t *dev);
265 
272 void mrf24j40_set_pan(mrf24j40_t *dev, uint16_t pan);
273 
281 int16_t mrf24j40_get_txpower(mrf24j40_t *dev);
282 
294 void mrf24j40_set_txpower(mrf24j40_t *dev, int16_t txpower);
295 
304 
316 void mrf24j40_set_csma_max_retries(mrf24j40_t *dev, int8_t retries);
317 
328 void mrf24j40_set_csma_backoff_exp(mrf24j40_t *dev, uint8_t min, uint8_t max);
329 
338 
345 void mrf24j40_set_cca_threshold(mrf24j40_t *dev, int8_t value);
346 
354 void mrf24j40_set_option(mrf24j40_t *dev, uint16_t option, bool state);
355 
362 void mrf24j40_set_state(mrf24j40_t *dev, uint8_t state);
363 
375 void mrf24j40_set_turbo(mrf24j40_t *dev, bool enable);
376 
383 bool mrf24j40_get_turbo(mrf24j40_t *dev);
384 
390 void mrf24j40_sleep(mrf24j40_t *dev);
391 
398 
405 
416 
426 
433 int8_t mrf24j40_dbm_from_reg(uint8_t value);
434 
444 
455 size_t mrf24j40_tx_load(mrf24j40_t *dev, uint8_t *data, size_t len,
456  size_t offset);
457 
463 void mrf24j40_tx_exec(mrf24j40_t *dev);
464 
465 #ifdef __cplusplus
466 }
467 #endif
468 
469 #endif /* MRF24J40_H */
470 
mrf24j40_set_csma_max_retries
void mrf24j40_set_csma_max_retries(mrf24j40_t *dev, int8_t retries)
Set the maximum number of channel access attempts per frame (CSMA)
mrf24j40_setup
void mrf24j40_setup(mrf24j40_t *dev, const mrf24j40_params_t *params, uint8_t index)
Setup an MRF24J40 based device state.
mrf24j40_assert_sleep
void mrf24j40_assert_sleep(mrf24j40_t *dev)
Put in sleep mode if idle_state is sleep.
mrf24j40_set_txpower
void mrf24j40_set_txpower(mrf24j40_t *dev, int16_t txpower)
Set the transmission power of the given device [in dBm].
mrf24j40_t::tx_frame_len
uint8_t tx_frame_len
length of the current TX frame
Definition: mrf24j40.h:169
mrf24j40_params
struct holding all params needed for device initialization
Definition: mrf24j40.h:152
mrf24j40_t::header_len
uint8_t header_len
length of the header
Definition: mrf24j40.h:170
mrf24j40_t::netdev
netdev_ieee802154_t netdev
netdev parent struct
Definition: mrf24j40.h:164
ieee802154.h
Definitions for netdev common IEEE 802.15.4 code.
mrf24j40_set_csma_backoff_exp
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.
mrf24j40_get_txpower
int16_t mrf24j40_get_txpower(mrf24j40_t *dev)
Get the configured transmission power of the given device [in dBm].
spi.h
Low-level SPI peripheral driver interface definition.
mrf24j40_t::tx_retries
uint8_t tx_retries
Number of retries needed for last transmission.
Definition: mrf24j40.h:174
mrf24j40_set_pan
void mrf24j40_set_pan(mrf24j40_t *dev, uint16_t pan)
Set the PAN ID of the given device.
mrf24j40_t::pending
uint8_t pending
Flags for pending tasks.
Definition: mrf24j40.h:172
mrf24j40_reset_state_machine
void mrf24j40_reset_state_machine(mrf24j40_t *dev)
Reset the internal state machine to TRX_OFF mode.
mrf24j40_reset
int mrf24j40_reset(mrf24j40_t *dev)
Trigger a hardware reset and configure radio with default values.
mrf24j40_params::reset_pin
gpio_t reset_pin
GPIO pin connected to the reset pin.
Definition: mrf24j40.h:157
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
mrf24j40_tx_prepare
void mrf24j40_tx_prepare(mrf24j40_t *dev)
Prepare for sending of data.
mrf24j40_t::irq_flag
uint8_t irq_flag
Flags for IRQs.
Definition: mrf24j40.h:173
mrf24j40_params_t
struct mrf24j40_params mrf24j40_params_t
struct holding all params needed for device initialization
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
mrf24j40_get_turbo
bool mrf24j40_get_turbo(mrf24j40_t *dev)
Query the state of the turbo mode.
mrf24j40_set_chan
void mrf24j40_set_chan(mrf24j40_t *dev, uint8_t chan)
Set the channel number of the given device.
netdev.h
Definitions low-level network driver interface.
mrf24j40_sleep
void mrf24j40_sleep(mrf24j40_t *dev)
Put in sleep mode.
mrf24j40_get_cca_threshold
int8_t mrf24j40_get_cca_threshold(mrf24j40_t *dev)
Get the CCA threshold value.
mrf24j40_set_addr_short
void mrf24j40_set_addr_short(mrf24j40_t *dev, uint16_t addr)
Set the short address of the given device.
mrf24j40_params::cs_pin
spi_cs_t cs_pin
GPIO pin connected to chip select.
Definition: mrf24j40.h:155
mrf24j40_get_pan
uint16_t mrf24j40_get_pan(mrf24j40_t *dev)
Get the configured PAN ID of the given device.
mrf24j40_params::spi
spi_t spi
SPI bus the device is connected to.
Definition: mrf24j40.h:153
nettype.h
Protocol type definitions.
mrf24j40_params::int_pin
gpio_t int_pin
GPIO pin connected to the interrupt pin.
Definition: mrf24j40.h:156
mrf24j40_set_state
void mrf24j40_set_state(mrf24j40_t *dev, uint8_t state)
Set the state of the given device (trigger a state change)
mrf24j40_t::params
mrf24j40_params_t params
parameters for initialization
Definition: mrf24j40.h:166
mrf24j40_tx_exec
void mrf24j40_tx_exec(mrf24j40_t *dev)
Trigger sending of data previously loaded into transmit buffer.
mrf24j40_tx_load
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.
mrf24j40_get_addr_long
void mrf24j40_get_addr_long(mrf24j40_t *dev, uint8_t *addr)
Get the configured long address of the given device.
mrf24j40_set_addr_long
void mrf24j40_set_addr_long(mrf24j40_t *dev, const uint8_t *addr)
Set the long address of the given device.
mrf24j40_t::fcf_low
uint8_t fcf_low
Low 8 FCF bits of the current TX frame.
Definition: mrf24j40.h:171
mrf24j40_set_turbo
void mrf24j40_set_turbo(mrf24j40_t *dev, bool enable)
Enable or disable proprietary Turbo Mode.
mrf24j40_set_cca_threshold
void mrf24j40_set_cca_threshold(mrf24j40_t *dev, int8_t value)
Set the CCA threshold value.
netdev_ieee802154_t
Extended structure to hold IEEE 802.15.4 driver state.
Definition: ieee802154.h:90
mrf24j40_t::state
uint8_t state
current state of the radio
Definition: mrf24j40.h:167
gpio.h
Low-level GPIO peripheral driver interface definitions.
mrf24j40_cca
bool mrf24j40_cca(mrf24j40_t *dev, int8_t *rssi)
Trigger a clear channel assessment & retrieve RSSI.
mrf24j40_get_chan
uint8_t mrf24j40_get_chan(mrf24j40_t *dev)
Get the configured channel number of the given device.
mrf24j40_get_csma_max_retries
uint8_t mrf24j40_get_csma_max_retries(mrf24j40_t *dev)
Get the maximum number of channel access attempts per frame (CSMA)
mrf24j40_t
Device descriptor for MRF24J40 radio devices.
Definition: mrf24j40.h:163
mrf24j40_get_addr_short
uint16_t mrf24j40_get_addr_short(mrf24j40_t *dev)
Get the short address of the given device.
mrf24j40_dbm_from_reg
int8_t mrf24j40_dbm_from_reg(uint8_t value)
Convert scalar from mrf24j40 RSSI to dBm.
mrf24j40_assert_awake
void mrf24j40_assert_awake(mrf24j40_t *dev)
Wake up from sleep mode.
mrf24j40_set_option
void mrf24j40_set_option(mrf24j40_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
mrf24j40_t::idle_state
uint8_t idle_state
state to return to after sending
Definition: mrf24j40.h:168
mrf24j40_params::spi_clk
spi_clk_t spi_clk
SPI speed to use.
Definition: mrf24j40.h:154
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
mrf24j40_software_reset
void mrf24j40_software_reset(mrf24j40_t *dev)
Software Reset.