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)
121 typedef struct mrf24j40_params {
122  spi_t spi;
123  spi_clk_t spi_clk;
124  spi_cs_t cs_pin;
125  gpio_t int_pin;
126  gpio_t reset_pin;
132 typedef struct {
134  /* device specific fields */
135  mrf24j40_params_t params;
136  uint8_t state;
137  uint8_t idle_state;
138  uint8_t tx_frame_len;
139  uint8_t header_len;
140  uint8_t pending;
141  uint8_t irq_flag;
142  uint8_t tx_retries;
151 void mrf24j40_setup(mrf24j40_t *dev, const mrf24j40_params_t *params);
152 
158 void mrf24j40_reset(mrf24j40_t *dev);
159 
168 bool mrf24j40_cca(mrf24j40_t *dev);
169 
177 uint16_t mrf24j40_get_addr_short(mrf24j40_t *dev);
178 
185 void mrf24j40_set_addr_short(mrf24j40_t *dev, uint16_t addr);
186 
194 uint64_t mrf24j40_get_addr_long(mrf24j40_t *dev);
195 
202 void mrf24j40_set_addr_long(mrf24j40_t *dev, uint64_t addr);
203 
211 uint8_t mrf24j40_get_chan(mrf24j40_t *dev);
212 
219 void mrf24j40_set_chan(mrf24j40_t *dev, uint8_t chan);
220 
228 uint16_t mrf24j40_get_pan(mrf24j40_t *dev);
229 
236 void mrf24j40_set_pan(mrf24j40_t *dev, uint16_t pan);
237 
245 int16_t mrf24j40_get_txpower(mrf24j40_t *dev);
246 
258 void mrf24j40_set_txpower(mrf24j40_t *dev, int16_t txpower);
259 
268 
280 void mrf24j40_set_csma_max_retries(mrf24j40_t *dev, int8_t retries);
281 
292 void mrf24j40_set_csma_backoff_exp(mrf24j40_t *dev, uint8_t min, uint8_t max);
293 
302 
309 void mrf24j40_set_cca_threshold(mrf24j40_t *dev, int8_t value);
310 
318 void mrf24j40_set_option(mrf24j40_t *dev, uint16_t option, bool state);
319 
326 void mrf24j40_set_state(mrf24j40_t *dev, uint8_t state);
327 
333 void mrf24j40_sleep(mrf24j40_t *dev);
334 
341 
348 
359 
369 
379 
390 size_t mrf24j40_tx_load(mrf24j40_t *dev, uint8_t *data, size_t len,
391  size_t offset);
392 
398 void mrf24j40_tx_exec(mrf24j40_t *dev);
399 
400 #ifdef __cplusplus
401 }
402 #endif
403 
404 #endif /* MRF24J40_H */
405 
void mrf24j40_reset(mrf24j40_t *dev)
Trigger a hardware reset and configure radio with default values.
void mrf24j40_tx_prepare(mrf24j40_t *dev)
Prepare for sending of data.
void mrf24j40_set_option(mrf24j40_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
void mrf24j40_reset_state_machine(mrf24j40_t *dev)
Reset the internal state machine to TRX_OFF mode.
Low-level GPIO peripheral driver interface definitions.
void mrf24j40_sleep(mrf24j40_t *dev)
Put in sleep mode.
Definitions low-level network driver interface.
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.
void mrf24j40_tx_exec(mrf24j40_t *dev)
Trigger sending of data previously loaded into transmit buffer.
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_csma_max_retries(mrf24j40_t *dev, int8_t retries)
Set the maximum number of channel access attempts per frame (CSMA)
int16_t mrf24j40_get_txpower(mrf24j40_t *dev)
Get the configured transmission power of the given device [in dBm].
Device descriptor for MRF24J40 radio devices.
Definition: mrf24j40.h:138
Low-level SPI peripheral driver interface definition.
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition: spi.h:113
void mrf24j40_set_state(mrf24j40_t *dev, uint8_t state)
Set the state of the given device (trigger a state change)
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.
uint8_t mrf24j40_get_csma_max_retries(mrf24j40_t *dev)
Get the maximum number of channel access attempts per frame (CSMA)
struct mrf24j40_params mrf24j40_params_t
struct holding all params needed for device initialization
Structure to hold driver state.
uint8_t mrf24j40_get_chan(mrf24j40_t *dev)
Get the configured channel number of the given device.
void mrf24j40_assert_awake(mrf24j40_t *dev)
Wake up from sleep mode.
Definitions for netdev common IEEE 802.15.4 code.
bool mrf24j40_cca(mrf24j40_t *dev)
Trigger a clear channel assessment.
uint64_t mrf24j40_get_addr_long(mrf24j40_t *dev)
Get the configured long address of the given device.
int8_t mrf24j40_get_cca_threshold(mrf24j40_t *dev)
Get the CCA threshold value.
Extended structure to hold IEEE 802.15.4 driver state.
uint16_t mrf24j40_get_pan(mrf24j40_t *dev)
Get the configured PAN ID of the given device.
void mrf24j40_set_cca_threshold(mrf24j40_t *dev, int8_t value)
Set the CCA threshold value.
void mrf24j40_set_pan(mrf24j40_t *dev, uint16_t pan)
Set the PAN ID of the given device.
void mrf24j40_assert_sleep(mrf24j40_t *dev)
Put in sleep mode if idle_state is sleep.
uint16_t mrf24j40_get_addr_short(mrf24j40_t *dev)
Get the short address of the given device.
void mrf24j40_software_reset(mrf24j40_t *dev)
Software Reset.
void mrf24j40_setup(mrf24j40_t *dev, const mrf24j40_params_t *params)
Setup an MRF24J40 based device state.
struct holding all params needed for device initialization
Definition: mrf24j40.h:127
Protocol type definitions.
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:105
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, uint64_t addr)
Set the long address of the given device.