cc2420.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
21 #ifndef CC2420_H
22 #define CC2420_H
23 
24 #include <stdint.h>
25 
26 #include "periph/spi.h"
27 #include "periph/gpio.h"
28 
29 #include "net/netdev.h"
30 #include "net/netdev/ieee802154.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
39 #define CC2420_PKT_MAXLEN (IEEE802154_FRAME_LEN_MAX)
40 
45 #define CC2420_CHAN_MIN (IEEE802154_CHANNEL_MIN)
46 #define CC2420_CHAN_MAX (IEEE802154_CHANNEL_MAX)
47 #define CC2420_CHAN_DEFAULT (CONFIG_IEEE802154_DEFAULT_CHANNEL)
48 
54 #define CC2420_TXPOWER_MIN (-25)
55 #define CC2420_TXPOWER_MAX (0)
56 #define CC2420_TXPOWER_DEFAULT (CONFIG_IEEE802154_DEFAULT_TXPOWER)
57 
62 #define CC2420_RSSI_OFFSET (-45)
63 
67 enum {
68  CC2420_RET_CHAN_OK = 2,
69 };
70 
74 typedef struct cc2420_params {
77  gpio_t pin_cs;
78  gpio_t pin_fifo;
79  gpio_t pin_fifop;
80  gpio_t pin_cca;
81  gpio_t pin_sfd;
82  gpio_t pin_vrefen;
83  gpio_t pin_reset;
85 
89 typedef struct {
90  /* netdev fields */
92  /* device specific fields */
94  /* device state fields */
95  uint8_t state;
96  uint16_t options;
97 } cc2420_t;
98 
108 void cc2420_setup(cc2420_t *dev, const cc2420_params_t *params);
109 
118 int cc2420_init(cc2420_t *dev);
119 
127 int cc2420_reset(cc2420_t *dev);
128 
137 bool cc2420_cca(cc2420_t *dev);
138 
145 void cc2420_get_addr_short(cc2420_t *dev, uint8_t *addr);
146 
153 void cc2420_set_addr_short(cc2420_t *dev, const uint8_t *addr);
154 
163 void cc2420_get_addr_long(cc2420_t *dev, uint8_t *addr_long);
164 
171 void cc2420_set_addr_long(cc2420_t *dev, const uint8_t *addr_long);
172 
180 uint16_t cc2420_get_pan(cc2420_t *dev);
181 
188 void cc2420_set_pan(cc2420_t *dev, uint16_t pan);
189 
197 uint16_t cc2420_get_chan(cc2420_t *dev);
198 
205 int cc2420_set_chan(cc2420_t *dev, uint16_t chan);
206 
214 int16_t cc2420_get_txpower(cc2420_t *dev);
215 
227 void cc2420_set_txpower(cc2420_t *dev, int16_t txpower);
228 
236 int cc2420_set_option(cc2420_t *dev, uint16_t option, bool state);
237 
244 int cc2420_set_state(cc2420_t *dev, netopt_state_t state);
245 
254 
266 size_t cc2420_send(cc2420_t *dev, const iolist_t *iolist);
267 
277 size_t cc2420_tx_prepare(cc2420_t *dev, const iolist_t *iolist);
278 
284 void cc2420_tx_exec(cc2420_t *dev);
285 
297 int cc2420_rx(cc2420_t *dev, uint8_t *buf, size_t max_len, void *info);
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 
303 #endif /* CC2420_H */
304 
cc2420_get_chan
uint16_t cc2420_get_chan(cc2420_t *dev)
Get the configured channel of the given device.
cc2420_params::spi
spi_t spi
SPI bus the device is connected to.
Definition: cc2420.h:75
cc2420_rx
int cc2420_rx(cc2420_t *dev, uint8_t *buf, size_t max_len, void *info)
Read a chunk of data from the receive buffer of the given device.
cc2420_get_addr_long
void cc2420_get_addr_long(cc2420_t *dev, uint8_t *addr_long)
Get the configured long address of the given device.
cc2420_set_chan
int cc2420_set_chan(cc2420_t *dev, uint16_t chan)
Set the channel of the given device.
cc2420_params::pin_reset
gpio_t pin_reset
pin connected to the reset pin
Definition: cc2420.h:83
cc2420_tx_exec
void cc2420_tx_exec(cc2420_t *dev)
Trigger sending of data previously loaded into transmit buffer.
cc2420_set_txpower
void cc2420_set_txpower(cc2420_t *dev, int16_t txpower)
Set the transmission power of the given device [in dBm].
cc2420_params::pin_vrefen
gpio_t pin_vrefen
pin connected to the Vref enable pin
Definition: cc2420.h:82
ieee802154.h
Definitions for netdev common IEEE 802.15.4 code.
cc2420_set_addr_short
void cc2420_set_addr_short(cc2420_t *dev, const uint8_t *addr)
Set the short address of the given device.
spi.h
Low-level SPI peripheral driver interface definition.
cc2420_init
int cc2420_init(cc2420_t *dev)
Initialize a given CC2420 device.
cc2420_t
Device descriptor for CC2420 radio devices.
Definition: cc2420.h:89
cc2420_set_state
int cc2420_set_state(cc2420_t *dev, netopt_state_t state)
Set the state of the given device (trigger a state change)
cc2420_reset
int cc2420_reset(cc2420_t *dev)
Trigger a hardware reset and configure radio with default values.
cc2420_get_addr_short
void cc2420_get_addr_short(cc2420_t *dev, uint8_t *addr)
Get the short address of the given device.
cc2420_get_pan
uint16_t cc2420_get_pan(cc2420_t *dev)
Get the configured PAN ID of the given device.
cc2420_params::pin_fifop
gpio_t pin_fifop
pin connected to the FIFOP interrupt pin
Definition: cc2420.h:79
cc2420_t::netdev
netdev_ieee802154_t netdev
netdev parent struct
Definition: cc2420.h:91
cc2420_t::options
uint16_t options
state of used options
Definition: cc2420.h:96
cc2420_t::state
uint8_t state
current state of the radio
Definition: cc2420.h:95
cc2420_params::pin_cs
gpio_t pin_cs
pin connected to chip select
Definition: cc2420.h:77
netopt_state_t
netopt_state_t
Option parameter to be used with NETOPT_STATE to set or get the state of a network device or protocol...
Definition: netopt.h:805
cc2420_get_state
netopt_state_t cc2420_get_state(cc2420_t *dev)
Get the state of the given device.
cc2420_tx_prepare
size_t cc2420_tx_prepare(cc2420_t *dev, const iolist_t *iolist)
Prepare for sending of data.
cc2420_get_txpower
int16_t cc2420_get_txpower(cc2420_t *dev)
Get the configured transmission power of the given device [in dBm].
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
netdev.h
Definitions low-level network driver interface.
iolist
iolist structure definition
Definition: iolist.h:39
cc2420_set_addr_long
void cc2420_set_addr_long(cc2420_t *dev, const uint8_t *addr_long)
Set the long address of the given device.
cc2420_set_pan
void cc2420_set_pan(cc2420_t *dev, uint16_t pan)
Set the PAN ID of the given device.
netdev_ieee802154_t
Extended structure to hold IEEE 802.15.4 driver state.
Definition: ieee802154.h:90
cc2420_params
Struct holding all parameters needed for device initialization.
Definition: cc2420.h:74
cc2420_params::pin_sfd
gpio_t pin_sfd
pin connected to 'start of frame delimiter'
Definition: cc2420.h:81
cc2420_set_option
int cc2420_set_option(cc2420_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
gpio.h
Low-level GPIO peripheral driver interface definitions.
cc2420_cca
bool cc2420_cca(cc2420_t *dev)
Trigger a clear channel assessment.
cc2420_t::params
cc2420_params_t params
hardware interface configuration
Definition: cc2420.h:93
cc2420_params_t
struct cc2420_params cc2420_params_t
Struct holding all parameters needed for device initialization.
cc2420_params::pin_fifo
gpio_t pin_fifo
pin connected to the FIFO interrupt pin
Definition: cc2420.h:78
cc2420_setup
void cc2420_setup(cc2420_t *dev, const cc2420_params_t *params)
Setup the device descriptor for the given device.
cc2420_params::spi_clk
spi_clk_t spi_clk
SPI speed to use.
Definition: cc2420.h:76
cc2420_params::pin_cca
gpio_t pin_cca
pin connected to CCA
Definition: cc2420.h:80
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
cc2420_send
size_t cc2420_send(cc2420_t *dev, const iolist_t *iolist)
Convenience function for simply sending data.