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 
44 #define CC2420_PANID_DEFAULT (IEEE802154_DEFAULT_PANID)
45 
50 #define CC2420_CHAN_MIN (IEEE802154_CHANNEL_MIN)
51 #define CC2420_CHAN_MAX (IEEE802154_CHANNEL_MAX)
52 #define CC2420_CHAN_DEFAULT (IEEE802154_DEFAULT_CHANNEL)
53 
59 #define CC2420_TXPOWER_MIN (-25)
60 #define CC2420_TXPOWER_MAX (0)
61 #define CC2420_TXPOWER_DEFAULT (IEEE802154_DEFAULT_TXPOWER)
62 
67 #define CC2420_RSSI_OFFSET (-45)
68 
72 enum {
73  CC2420_RET_CHAN_OK = 2,
74 };
75 
79 typedef struct cc2420_params {
82  gpio_t pin_cs;
83  gpio_t pin_fifo;
84  gpio_t pin_fifop;
85  gpio_t pin_cca;
86  gpio_t pin_sfd;
87  gpio_t pin_vrefen;
88  gpio_t pin_reset;
90 
94 typedef struct {
95  /* netdev fields */
97  /* device specific fields */
99  /* device state fields */
100  uint8_t state;
101  uint16_t options;
102 } cc2420_t;
103 
113 void cc2420_setup(cc2420_t *dev, const cc2420_params_t *params);
114 
123 int cc2420_init(cc2420_t *dev);
124 
132 int cc2420_reset(cc2420_t *dev);
133 
142 bool cc2420_cca(cc2420_t *dev);
143 
150 void cc2420_get_addr_short(cc2420_t *dev, uint8_t *addr);
151 
158 void cc2420_set_addr_short(cc2420_t *dev, const uint8_t *addr);
159 
168 void cc2420_get_addr_long(cc2420_t *dev, uint8_t *addr_long);
169 
176 void cc2420_set_addr_long(cc2420_t *dev, const uint8_t *addr_long);
177 
185 uint16_t cc2420_get_pan(cc2420_t *dev);
186 
193 void cc2420_set_pan(cc2420_t *dev, uint16_t pan);
194 
202 uint16_t cc2420_get_chan(cc2420_t *dev);
203 
210 int cc2420_set_chan(cc2420_t *dev, uint16_t chan);
211 
219 int16_t cc2420_get_txpower(cc2420_t *dev);
220 
232 void cc2420_set_txpower(cc2420_t *dev, int16_t txpower);
233 
241 int cc2420_set_option(cc2420_t *dev, uint16_t option, bool state);
242 
249 int cc2420_set_state(cc2420_t *dev, netopt_state_t state);
250 
259 
271 size_t cc2420_send(cc2420_t *dev, const iolist_t *iolist);
272 
282 size_t cc2420_tx_prepare(cc2420_t *dev, const iolist_t *iolist);
283 
289 void cc2420_tx_exec(cc2420_t *dev);
290 
302 int cc2420_rx(cc2420_t *dev, uint8_t *buf, size_t max_len, void *info);
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 
308 #endif /* CC2420_H */
309 
int cc2420_set_chan(cc2420_t *dev, uint16_t chan)
Set the channel of the given device.
void cc2420_get_addr_long(cc2420_t *dev, uint8_t *addr_long)
Get the configured long address of the given device.
gpio_t pin_reset
pin connected to the reset pin
Definition: cc2420.h:88
Definitions low-level network driver interface.
void cc2420_setup(cc2420_t *dev, const cc2420_params_t *params)
Setup the device descriptor for the given device.
gpio_t pin_vrefen
pin connected to the Vref enable pin
Definition: cc2420.h:87
void cc2420_tx_exec(cc2420_t *dev)
Trigger sending of data previously loaded into transmit buffer.
uint8_t state
current state of the radio
Definition: cc2420.h:100
Low-level GPIO peripheral driver interface definitions.
uint16_t options
state of used options
Definition: cc2420.h:101
gpio_t pin_cs
pin connected to chip select
Definition: cc2420.h:82
spi_clk_t spi_clk
SPI speed to use.
Definition: cc2420.h:81
size_t cc2420_send(cc2420_t *dev, const iolist_t *iolist)
Convenience function for simply sending data.
void cc2420_get_addr_short(cc2420_t *dev, uint8_t *addr)
Get the short address of the given device.
Low-level SPI peripheral driver interface definition.
int cc2420_init(cc2420_t *dev)
Initialize a given CC2420 device.
void cc2420_set_txpower(cc2420_t *dev, int16_t txpower)
Set the transmission power of the given device [in dBm].
gpio_t pin_cca
pin connected to CCA
Definition: cc2420.h:85
uint16_t cc2420_get_pan(cc2420_t *dev)
Get the configured PAN ID of the given device.
gpio_t pin_sfd
pin connected to &#39;start of frame delimiter&#39;
Definition: cc2420.h:86
void cc2420_set_pan(cc2420_t *dev, uint16_t pan)
Set the PAN ID of the given device.
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:564
netdev_ieee802154_t netdev
netdev parent struct
Definition: cc2420.h:96
int cc2420_set_state(cc2420_t *dev, netopt_state_t state)
Set the state of the given device (trigger a state change)
size_t cc2420_tx_prepare(cc2420_t *dev, const iolist_t *iolist)
Prepare for sending of data.
gpio_t pin_fifop
pin connected to the FIFOP interrupt pin
Definition: cc2420.h:84
Definitions for netdev common IEEE 802.15.4 code.
int16_t cc2420_get_txpower(cc2420_t *dev)
Get the configured transmission power of the given device [in dBm].
bool cc2420_cca(cc2420_t *dev)
Trigger a clear channel assessment.
cc2420_params_t params
hardware interface configuration
Definition: cc2420.h:98
uint16_t cc2420_get_chan(cc2420_t *dev)
Get the configured channel of the given device.
int cc2420_reset(cc2420_t *dev)
Trigger a hardware reset and configure radio with default values.
spi_t spi
SPI bus the device is connected to.
Definition: cc2420.h:80
netopt_state_t cc2420_get_state(cc2420_t *dev)
Get the state of the given device.
int cc2420_set_option(cc2420_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
iolist structure definition
Definition: iolist.h:37
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.
Device descriptor for CC2420 radio devices.
Definition: cc2420.h:94
struct cc2420_params cc2420_params_t
Struct holding all parameters needed for device initialization.
Struct holding all parameters needed for device initialization.
Definition: cc2420.h:79
void cc2420_set_addr_short(cc2420_t *dev, const uint8_t *addr)
Set the short address of the given device.
Extended structure to hold IEEE 802.15.4 driver state.
void cc2420_set_addr_long(cc2420_t *dev, const uint8_t *addr_long)
Set the long address of the given device.
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:105
gpio_t pin_fifo
pin connected to the FIFO interrupt pin
Definition: cc2420.h:83