Loading...
Searching...
No Matches
xbee.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 INRIA
3 * SPDX-FileCopyrightText: 2015-2016 Freie Universität Berlin
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
21
22#include <stdint.h>
23
24#include "mutex.h"
25#include "periph/uart.h"
26#include "periph/gpio.h"
27#include "net/netdev.h"
28#include "net/ieee802154.h"
29#include "net/gnrc/nettype.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
38#ifdef MODULE_XBEE_ENCRYPTION
39#define XBEE_MAX_PAYLOAD_LENGTH (95U)
40#else
41#define XBEE_MAX_PAYLOAD_LENGTH (100U)
42#endif
43
47#define XBEE_MAX_PKT_LENGTH (115U)
48
52#define XBEE_MAX_RESP_LENGTH (16U)
53
57#define XBEE_MAX_TXHDR_LENGTH (14U)
58
62#ifdef MODULE_GNRC_SIXLOWPAN
63#define XBEE_DEFAULT_PROTOCOL (GNRC_NETTYPE_SIXLOWPAN)
64#else
65#define XBEE_DEFAULT_PROTOCOL (GNRC_NETTYPE_UNDEF)
66#endif
67
71#define XBEE_DEFAULT_PANID (CONFIG_IEEE802154_DEFAULT_PANID)
72
76#define XBEE_DEFAULT_CHANNEL (CONFIG_IEEE802154_DEFAULT_CHANNEL)
77
86#define XBEE_ADDR_FLAGS_LONG (0x80)
88
108
112typedef struct {
114 uint32_t br;
115 gpio_t pin_sleep;
117 gpio_t pin_reset;
120
124typedef struct {
125 /* netdev fields */
126 const struct netdev_driver *driver;
128 void* context;
129 /* device driver specific fields */
131 uint8_t options;
132 uint8_t addr_flags;
133 uint8_t addr_short[2];
135 /* general variables for the UART RX state machine */
137 uint16_t int_size;
139 /* values for the UART TX state machine */
143 uint8_t tx_fid;
144 /* buffer and synchronization for command responses */
148 uint16_t resp_count;
149 uint16_t resp_limit;
150 /* buffer and synchronization for incoming network packets */
152 uint16_t rx_count;
153 uint16_t rx_limit;
154} xbee_t;
155
159typedef struct {
160 uint8_t addr_len;
161 uint8_t bcast;
162 uint8_t rssi;
163 uint8_t src_addr[8];
164 uint8_t dst_addr[8];
166
170extern const netdev_driver_t xbee_driver;
171
178void xbee_setup(xbee_t *dev, const xbee_params_t *params);
179
194int xbee_build_hdr(xbee_t *dev, uint8_t *xhdr, size_t payload_len,
195 void *dst_addr, size_t addr_len);
196
207int xbee_parse_hdr(xbee_t *dev, const uint8_t *xhdr, xbee_l2hdr_t *l2hdr);
208
209#ifdef __cplusplus
210}
211#endif
212
Definitions low-level network driver interface.
Low-level GPIO peripheral driver interface definitions.
struct netdev_driver netdev_driver_t
Structure to hold driver interface -> function mapping.
void(* netdev_event_cb_t)(netdev_t *dev, netdev_event_t event)
Event callback for signaling event to upper layers.
Definition netdev.h:293
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:109
int xbee_parse_hdr(xbee_t *dev, const uint8_t *xhdr, xbee_l2hdr_t *l2hdr)
Extract IEEE802.15.4 L2 header information from the XBee header.
#define XBEE_MAX_RESP_LENGTH
Maximum length of a command response.
Definition xbee.h:52
#define XBEE_MAX_PKT_LENGTH
Maximum packet length, including XBee API frame overhead.
Definition xbee.h:47
xbee_rx_state_t
States of the internal FSM for handling incoming UART frames.
Definition xbee.h:96
int xbee_build_hdr(xbee_t *dev, uint8_t *xhdr, size_t payload_len, void *dst_addr, size_t addr_len)
Put together the internal proprietary XBee header.
const netdev_driver_t xbee_driver
Reference to the XBee driver interface.
void xbee_setup(xbee_t *dev, const xbee_params_t *params)
Prepare the given Xbee device.
@ XBEE_INT_STATE_SIZE1
waiting for the first byte (MSB) of the frame size field
Definition xbee.h:98
@ XBEE_INT_STATE_TYPE
waiting for the frame type field
Definition xbee.h:102
@ XBEE_INT_STATE_SIZE2
waiting for the second byte (LSB) of the frame size field
Definition xbee.h:100
@ XBEE_INT_STATE_RX
handling incoming data when receiving radio packets
Definition xbee.h:105
@ XBEE_INT_STATE_RESP
handling incoming data for AT command responses
Definition xbee.h:103
@ XBEE_INT_STATE_IDLE
waiting for the beginning of a new frame
Definition xbee.h:97
Mutex for thread synchronization.
Protocol type definitions.
Mutex structure.
Definition mutex.h:36
Structure to hold driver interface -> function mapping.
Definition netdev.h:423
Data structure for extraction L2 information of received packets.
Definition xbee.h:159
uint8_t src_addr[8]
L2 source address.
Definition xbee.h:163
uint8_t rssi
RSSI value.
Definition xbee.h:162
uint8_t bcast
0 := unicast, 1:=broadcast
Definition xbee.h:161
uint8_t dst_addr[8]
L2 dst address.
Definition xbee.h:164
uint8_t addr_len
L2 address length (SRC and DST)
Definition xbee.h:160
Configuration parameters for XBee devices.
Definition xbee.h:112
gpio_t pin_sleep
GPIO pin that is connected to the SLEEP pin set to GPIO_UNDEF if not used.
Definition xbee.h:115
uint32_t br
baudrate to use
Definition xbee.h:114
uart_t uart
UART interfaced the device is connected to.
Definition xbee.h:113
gpio_t pin_reset
GPIO pin that is connected to the STATUS pin set to GPIO_UNDEF if not used.
Definition xbee.h:117
XBee device descriptor.
Definition xbee.h:124
uint16_t resp_limit
size RESP frame in transferred
Definition xbee.h:149
uint8_t options
options field
Definition xbee.h:131
xbee_params_t p
configuration parameters
Definition xbee.h:130
uint8_t tx_fid
TX frame ID.
Definition xbee.h:143
uint8_t resp_buf[XBEE_MAX_RESP_LENGTH]
AT response data buffer.
Definition xbee.h:147
netdev_event_cb_t event_callback
callback for device events
Definition xbee.h:127
mutex_t resp_lock
mutex for waiting for AT command response frames
Definition xbee.h:145
xbee_rx_state_t int_state
current state if the UART RX FSM
Definition xbee.h:136
void * context
ptr to network stack context
Definition xbee.h:128
uint8_t cmd_buf[XBEE_MAX_RESP_LENGTH]
command data buffer
Definition xbee.h:142
uint8_t rx_buf[XBEE_MAX_PKT_LENGTH]
receiving data buffer
Definition xbee.h:151
const struct netdev_driver * driver
ptr to that driver's interface.
Definition xbee.h:126
uint16_t resp_count
counter for ongoing transmission
Definition xbee.h:148
eui64_t addr_long
own 802.15.4 long address
Definition xbee.h:134
mutex_t tx_lock
mutex to allow only one transmission at a time
Definition xbee.h:140
uint8_t addr_short[2]
own 802.15.4 short address
Definition xbee.h:133
uint8_t addr_flags
address flags as defined above
Definition xbee.h:132
uint16_t rx_count
counter for ongoing transmission
Definition xbee.h:152
uint16_t rx_limit
size RX frame transferred
Definition xbee.h:153
uint16_t int_size
temporary space for parsing the frame size
Definition xbee.h:137
IEEE 802.15.4 header definitions.
Low-level UART peripheral driver interface definition.
Data type to represent an EUI-64.
Definition eui64.h:55