Loading...
Searching...
No Matches
cc2420.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Freie Universität Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
19
20#include <stdint.h>
21
22#include "periph/spi.h"
23#include "periph/gpio.h"
24
25#include "net/netdev.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
35#define CC2420_PKT_MAXLEN (IEEE802154_FRAME_LEN_MAX)
36
41#define CC2420_CHAN_MIN (IEEE802154_CHANNEL_MIN)
42#define CC2420_CHAN_MAX (IEEE802154_CHANNEL_MAX)
43#define CC2420_CHAN_DEFAULT (CONFIG_IEEE802154_DEFAULT_CHANNEL)
45
50#define CC2420_TXPOWER_MIN (-25)
51#define CC2420_TXPOWER_MAX (0)
52#define CC2420_TXPOWER_DEFAULT (CONFIG_IEEE802154_DEFAULT_TXPOWER)
54
58#define CC2420_RSSI_OFFSET (-45)
59
63enum {
64 CC2420_RET_CHAN_OK = 2,
65};
66
70typedef struct cc2420_params {
71 spi_t spi;
73 gpio_t pin_cs;
74 gpio_t pin_fifo;
75 gpio_t pin_fifop;
76 gpio_t pin_cca;
77 gpio_t pin_sfd;
78 gpio_t pin_vrefen;
79 gpio_t pin_reset;
81
85typedef struct {
86 /* netdev fields */
88 /* device specific fields */
90 /* device state fields */
91 uint8_t state;
92 uint16_t options;
93} cc2420_t;
94
103void cc2420_setup(cc2420_t *dev, const cc2420_params_t *params, uint8_t index);
104
114
123
133
140void cc2420_get_addr_short(cc2420_t *dev, uint8_t *addr);
141
148void cc2420_set_addr_short(cc2420_t *dev, const uint8_t *addr);
149
156void cc2420_get_addr_long(cc2420_t *dev, uint8_t *addr_long);
157
164void cc2420_set_addr_long(cc2420_t *dev, const uint8_t *addr_long);
165
174
181void cc2420_set_pan(cc2420_t *dev, uint16_t pan);
182
191
198int cc2420_set_chan(cc2420_t *dev, uint16_t chan);
199
208
220void cc2420_set_txpower(cc2420_t *dev, int16_t txpower);
221
229int cc2420_set_option(cc2420_t *dev, uint16_t option, bool state);
230
238
247
259size_t cc2420_send(cc2420_t *dev, const iolist_t *iolist);
260
271
278
290int cc2420_rx(cc2420_t *dev, uint8_t *buf, size_t max_len, void *info);
291
292#ifdef __cplusplus
293}
294#endif
295
spi_clk_t
Definition periph_cpu.h:348
Definitions for netdev common IEEE 802.15.4 code.
Definitions low-level network driver interface.
Low-level GPIO peripheral driver interface definitions.
void cc2420_get_addr_short(cc2420_t *dev, uint8_t *addr)
Get the short address of the given device.
void cc2420_set_pan(cc2420_t *dev, uint16_t pan)
Set the PAN ID of the given device.
int16_t cc2420_get_txpower(cc2420_t *dev)
Get the configured transmission power of the given device [in dBm].
void cc2420_set_txpower(cc2420_t *dev, int16_t txpower)
Set the transmission power of the given device [in dBm].
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.
int cc2420_set_option(cc2420_t *dev, uint16_t option, bool state)
Enable or disable driver specific options.
void cc2420_set_addr_long(cc2420_t *dev, const uint8_t *addr_long)
Set the long address of the given device.
void cc2420_setup(cc2420_t *dev, const cc2420_params_t *params, uint8_t index)
Setup the device descriptor for the given device.
uint16_t cc2420_get_chan(cc2420_t *dev)
Get the configured channel of the given device.
struct cc2420_params cc2420_params_t
Struct holding all parameters needed for device initialization.
bool cc2420_cca(cc2420_t *dev)
Trigger a clear channel assessment.
size_t cc2420_tx_prepare(cc2420_t *dev, const iolist_t *iolist)
Prepare for sending of data.
int cc2420_init(cc2420_t *dev)
Initialize a given CC2420 device.
void cc2420_tx_exec(cc2420_t *dev)
Trigger sending of data previously loaded into transmit buffer.
netopt_state_t cc2420_get_state(cc2420_t *dev)
Get the state 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.
uint16_t cc2420_get_pan(cc2420_t *dev)
Get the configured PAN ID of the given device.
void cc2420_set_addr_short(cc2420_t *dev, const uint8_t *addr)
Set the short address of the given device.
int cc2420_reset(cc2420_t *dev)
Trigger a hardware reset and configure radio with default values.
int cc2420_set_chan(cc2420_t *dev, uint16_t chan)
Set the channel of the given device.
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_send(cc2420_t *dev, const iolist_t *iolist)
Convenience function for simply sending data.
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:900
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:33
Low-level SPI peripheral driver interface definition.
Struct holding all parameters needed for device initialization.
Definition cc2420.h:70
gpio_t pin_cca
pin connected to CCA
Definition cc2420.h:76
gpio_t pin_reset
pin connected to the reset pin
Definition cc2420.h:79
spi_clk_t spi_clk
SPI speed to use.
Definition cc2420.h:72
gpio_t pin_fifo
pin connected to the FIFO interrupt pin
Definition cc2420.h:74
gpio_t pin_cs
pin connected to chip select
Definition cc2420.h:73
gpio_t pin_vrefen
pin connected to the Vref enable pin
Definition cc2420.h:78
gpio_t pin_fifop
pin connected to the FIFOP interrupt pin
Definition cc2420.h:75
spi_t spi
SPI bus the device is connected to.
Definition cc2420.h:71
gpio_t pin_sfd
pin connected to 'start of frame delimiter'
Definition cc2420.h:77
Device descriptor for CC2420 radio devices.
Definition cc2420.h:85
uint16_t options
state of used options
Definition cc2420.h:92
cc2420_params_t params
hardware interface configuration
Definition cc2420.h:89
uint8_t state
current state of the radio
Definition cc2420.h:91
netdev_ieee802154_t netdev
netdev parent struct
Definition cc2420.h:87
iolist structure definition
Definition iolist.h:38
Extended structure to hold IEEE 802.15.4 driver state.
Definition ieee802154.h:97