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 
70 #ifndef MRF24J40_H
71 #define MRF24J40_H
72 
73 #include <stdint.h>
74 
75 #include "board.h"
76 #include "periph/spi.h"
77 #include "periph/gpio.h"
78 #include "net/netdev.h"
79 #include "net/netdev/ieee802154.h"
80 #include "net/gnrc/nettype.h"
81 #include "net/ieee802154/radio.h"
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
91 #define MRF24J40_PSEUDO_STATE_IDLE (0x01)
92 #define MRF24J40_PSEUDO_STATE_SLEEP (0x02)
93 #define MRF24J40_PSEUDO_STATE_RESET (0x04)
104 #define MRF24J40_OPT_CSMA (0x0100)
105 #define MRF24J40_OPT_PROMISCUOUS (0x0200)
107 #define MRF24J40_OPT_PRELOADING (0x0400)
110 #define MRF24J40_TASK_TX_DONE (0x01)
111 #define MRF24J40_TASK_TX_READY (0x02)
112 #define MRF24J40_TASK_RX_READY (0x04)
114 #define MRF24J40_MAX_FRAME_RETRIES (3U)
116 #define MRF24J40_MAX_MINBE (3U)
118 #define MRF24J40_MIN_TXPOWER (-36)
119 #define MRF24J40_MAX_TXPOWER (0)
135 #if defined(DOXYGEN)
136 #define CONFIG_MRF24J40_USE_EXT_PA_LNA
137 #endif
138 
147 #if defined(DOXYGEN)
148 #define CONFIG_MRF24J40_TEST_SPI_CONNECTION
149 #endif
155 typedef struct mrf24j40_params {
156  spi_t spi;
159  gpio_t int_pin;
160  gpio_t reset_pin;
162 
166 typedef struct {
167  /* device specific fields */
169  uint8_t fcf_low;
170  uint8_t pending;
171  bool tx_pending;
172 } mrf24j40_t;
173 
182 
189 void mrf24j40_set_addr_short(mrf24j40_t *dev, uint16_t addr);
190 
197 void mrf24j40_set_addr_long(mrf24j40_t *dev, const uint8_t *addr);
198 
207 
214 void mrf24j40_set_chan(mrf24j40_t *dev, uint8_t chan);
215 
224 
231 void mrf24j40_set_pan(mrf24j40_t *dev, uint16_t pan);
232 
244 void mrf24j40_set_txpower(mrf24j40_t *dev, int16_t txpower);
245 
257 void mrf24j40_set_csma_max_retries(mrf24j40_t *dev, int8_t retries);
258 
269 void mrf24j40_set_csma_backoff_exp(mrf24j40_t *dev, uint8_t min, uint8_t max);
270 
277 void mrf24j40_set_cca_threshold(mrf24j40_t *dev, int8_t value);
278 
286 void mrf24j40_set_option(mrf24j40_t *dev, uint16_t option, bool state);
287 
294 void mrf24j40_set_state(mrf24j40_t *dev, uint8_t state);
295 
307 void mrf24j40_set_turbo(mrf24j40_t *dev, bool enable);
308 
315 
322 
333 
343 
350 int8_t mrf24j40_dbm_from_reg(uint8_t value);
351 
361 
372 size_t mrf24j40_tx_load(mrf24j40_t *dev, uint8_t *data, size_t len,
373  size_t offset);
374 
381 
388 
401  gpio_cb_t cb, void *ctx);
402 
403 #ifdef __cplusplus
404 }
405 #endif
406 
407 #endif /* MRF24J40_H */
spi_clk_t
Definition: periph_cpu.h:352
Definitions for netdev common IEEE 802.15.4 code.
Definitions low-level network driver interface.
Low-level GPIO peripheral driver interface definitions.
void mrf24j40_set_option(mrf24j40_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
void mrf24j40_set_csma_max_retries(mrf24j40_t *dev, int8_t retries)
Set the maximum number of channel access attempts per frame (CSMA)
int mrf24j40_init(mrf24j40_t *dev, const mrf24j40_params_t *params, ieee802154_dev_t *hal, gpio_cb_t cb, void *ctx)
Initialize the given MRF24J40 device.
void mrf24j40_sleep(mrf24j40_t *dev)
Put in sleep mode.
uint16_t mrf24j40_get_pan(mrf24j40_t *dev)
Get the configured PAN ID of the given device.
void mrf24j40_set_txpower(mrf24j40_t *dev, int16_t txpower)
Set the transmission power of the given device [in dBm].
void mrf24j40_set_addr_long(mrf24j40_t *dev, const uint8_t *addr)
Set the long address of the given device.
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.
uint8_t mrf24j40_get_chan(mrf24j40_t *dev)
Get the configured channel number of the given device.
int8_t mrf24j40_dbm_from_reg(uint8_t value)
Convert scalar from mrf24j40 RSSI to dBm.
void mrf24j40_tx_prepare(mrf24j40_t *dev)
Prepare for sending of data.
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.
void mrf24j40_set_cca_threshold(mrf24j40_t *dev, int8_t value)
Set the CCA threshold value.
struct mrf24j40_params mrf24j40_params_t
struct holding all params needed for device initialization
void mrf24j40_radio_irq_handler(void *dev)
IRQ Handler for the MRF24J40 device.
void mrf24j40_software_reset(mrf24j40_t *dev)
Software Reset.
void mrf24j40_reset_state_machine(mrf24j40_t *dev)
Reset the internal state machine to TRX_OFF mode.
int mrf24j40_reset(mrf24j40_t *dev)
Trigger a hardware reset and configure radio with default values.
void mrf24j40_tx_exec(mrf24j40_t *dev)
Trigger sending of data previously loaded into transmit buffer.
void mrf24j40_set_state(mrf24j40_t *dev, uint8_t state)
Set the state of the given device (trigger a state change)
void mrf24j40_set_pan(mrf24j40_t *dev, uint16_t pan)
Set the PAN ID of the given device.
void mrf24j40_wake_up(mrf24j40_t *dev)
Wake up from sleep mode.
void mrf24j40_set_turbo(mrf24j40_t *dev, bool enable)
Enable or disable proprietary Turbo Mode.
void mrf24j40_set_chan(mrf24j40_t *dev, uint8_t chan)
Set the channel number of the given device.
void mrf24j40_set_addr_short(mrf24j40_t *dev, uint16_t addr)
Set the short address of the given device.
void(* gpio_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: gpio.h:147
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition: spi.h:136
Protocol type definitions.
Low-level SPI peripheral driver interface definition.
the IEEE802.15.4 device descriptor
Definition: radio.h:415
struct holding all params needed for device initialization
Definition: mrf24j40.h:155
spi_t spi
SPI bus the device is connected to.
Definition: mrf24j40.h:156
spi_cs_t cs_pin
GPIO pin connected to chip select.
Definition: mrf24j40.h:158
spi_clk_t spi_clk
SPI speed to use.
Definition: mrf24j40.h:157
gpio_t int_pin
GPIO pin connected to the interrupt pin.
Definition: mrf24j40.h:159
gpio_t reset_pin
GPIO pin connected to the reset pin.
Definition: mrf24j40.h:160
Device descriptor for MRF24J40 radio devices.
Definition: mrf24j40.h:166
const mrf24j40_params_t * params
parameters for initialization
Definition: mrf24j40.h:168
bool tx_pending
Whether a transmission is pending or not.
Definition: mrf24j40.h:171
uint8_t fcf_low
Low 8 FCF bits of the current TX frame.
Definition: mrf24j40.h:169
uint8_t pending
Flags for pending tasks.
Definition: mrf24j40.h:170