2015-03-12 14:20:27 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 INRIA
|
|
|
|
* Copyright (C) 2015 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup drivers_xbee XBee driver
|
2015-09-25 21:06:17 +02:00
|
|
|
* @ingroup drivers_netdev
|
2015-03-12 14:20:27 +01:00
|
|
|
* @brief High-level driver for the XBee S1 802.15.4 modem
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief High-level driver for the XBee S1 802.15.4 modem
|
|
|
|
*
|
|
|
|
* @author Kévin Roussel <kevin.roussel@inria.fr>
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef XBEE_H_
|
|
|
|
#define XBEE_H_
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "mutex.h"
|
|
|
|
#include "periph/uart.h"
|
|
|
|
#include "periph/gpio.h"
|
2015-08-10 02:41:08 +02:00
|
|
|
#include "net/gnrc.h"
|
2015-08-07 14:36:04 +02:00
|
|
|
#include "net/ieee802154.h"
|
2015-03-12 14:20:27 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
2015-08-07 14:37:19 +02:00
|
|
|
extern "C" {
|
2015-03-12 14:20:27 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Maximum payload length that can be send
|
|
|
|
*/
|
|
|
|
#define XBEE_MAX_PAYLOAD_LENGTH (100U)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Maximum packet length, including XBee API frame overhead
|
|
|
|
*/
|
|
|
|
#define XBEE_MAX_PKT_LENGTH (115U)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Maximum length of a command response
|
|
|
|
*/
|
|
|
|
#define XBEE_MAX_RESP_LENGTH (16U)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Default protocol for data that is coming in
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
#ifdef MODULE_GNRC_SIXLOWPAN
|
|
|
|
#define XBEE_DEFAULT_PROTOCOL (GNRC_NETTYPE_SIXLOWPAN)
|
2015-03-12 14:20:27 +01:00
|
|
|
#else
|
2015-08-17 15:41:29 +02:00
|
|
|
#define XBEE_DEFAULT_PROTOCOL (GNRC_NETTYPE_UNDEF)
|
2015-03-12 14:20:27 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Default PAN ID used after initialization
|
|
|
|
*/
|
2015-04-20 18:12:40 +02:00
|
|
|
#define XBEE_DEFAULT_PANID (0x0023)
|
2015-03-12 14:20:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Default channel used after initialization
|
|
|
|
*/
|
2016-02-16 13:07:17 +01:00
|
|
|
#ifndef XBEE_DEFAULT_CHANNEL
|
2015-08-04 18:02:27 +02:00
|
|
|
#define XBEE_DEFAULT_CHANNEL (26U)
|
2016-02-16 13:07:17 +01:00
|
|
|
#endif
|
2015-03-12 14:20:27 +01:00
|
|
|
|
2015-06-03 17:11:20 +02:00
|
|
|
/**
|
|
|
|
* @name Address flags
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Use long addresses if not otherwise defined when set, use short
|
|
|
|
* addresses when unset.
|
|
|
|
*/
|
|
|
|
#define XBEE_ADDR_FLAGS_LONG (0x80)
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2015-03-12 14:20:27 +01:00
|
|
|
/**
|
|
|
|
* @brief States of the internal FSM for handling incoming UART frames
|
|
|
|
*
|
|
|
|
* Incoming data frames on the UART interfaces are handled using a finite state
|
|
|
|
* machine (FSM) in the UARTs RX interrupt handler. The FSM is needed to extract
|
|
|
|
* frame specific data as the frame size, frame type, and checksums.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
XBEE_INT_STATE_IDLE, /**< waiting for the beginning of a new frame */
|
|
|
|
XBEE_INT_STATE_SIZE1, /**< waiting for the first byte (MSB) of the
|
|
|
|
* frame size field */
|
|
|
|
XBEE_INT_STATE_SIZE2, /**< waiting for the second byte (LSB) of the
|
|
|
|
* frame size field */
|
|
|
|
XBEE_INT_STATE_TYPE, /**< waiting for the frame type field */
|
|
|
|
XBEE_INT_STATE_RESP, /**< handling incoming data for AT command
|
|
|
|
* responses */
|
|
|
|
XBEE_INT_STATE_RX, /**< handling incoming data when receiving radio
|
|
|
|
* packets */
|
|
|
|
} xbee_rx_state_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief XBee device descriptor
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/* netdev fields */
|
2015-08-17 15:41:29 +02:00
|
|
|
gnrc_netdev_driver_t const *driver; /**< pointer to the devices interface */
|
|
|
|
gnrc_netdev_event_cb_t event_cb; /**< netdev event callback */
|
2015-03-12 14:20:27 +01:00
|
|
|
kernel_pid_t mac_pid; /**< the driver's thread's PID */
|
|
|
|
/* device driver specific fields */
|
|
|
|
uart_t uart; /**< UART interfaced used */
|
|
|
|
gpio_t reset_pin; /**< GPIO pin connected to RESET */
|
|
|
|
gpio_t sleep_pin; /**< GPIO pin connected to SLEEP */
|
2015-08-17 15:41:29 +02:00
|
|
|
gnrc_nettype_t proto; /**< protocol the interface speaks */
|
2015-03-12 14:20:27 +01:00
|
|
|
uint8_t options; /**< options field */
|
2015-06-03 17:11:20 +02:00
|
|
|
uint8_t addr_flags; /**< address flags as defined above */
|
2015-03-12 14:20:27 +01:00
|
|
|
uint8_t addr_short[2]; /**< onw 802.15.4 short address */
|
2015-05-11 11:29:28 +02:00
|
|
|
eui64_t addr_long; /**< own 802.15.4 long address */
|
2015-03-12 14:20:27 +01:00
|
|
|
/* general variables for the UART RX state machine */
|
|
|
|
xbee_rx_state_t int_state; /**< current state if the UART RX FSM */
|
|
|
|
uint16_t int_size; /**< temporary space for parsing the
|
|
|
|
* frame size */
|
|
|
|
/* values for the UART TX state machine */
|
|
|
|
mutex_t tx_lock; /**< mutex to allow only one
|
|
|
|
* transmission at a time */
|
|
|
|
uint8_t tx_buf[XBEE_MAX_PKT_LENGTH];/**< transmit data buffer */
|
|
|
|
/* buffer and synchronization for command responses */
|
|
|
|
mutex_t resp_lock; /**< mutex for waiting for AT command
|
|
|
|
* response frames */
|
|
|
|
uint8_t resp_buf[XBEE_MAX_RESP_LENGTH]; /**< AT response data buffer */
|
|
|
|
uint16_t resp_count; /**< counter for ongoing transmission */
|
|
|
|
uint16_t resp_limit; /**< size RESP frame in transferred */
|
|
|
|
/* buffer and synchronization for incoming network packets */
|
|
|
|
uint8_t rx_buf[XBEE_MAX_PKT_LENGTH];/**< receiving data buffer */
|
|
|
|
uint16_t rx_count; /**< counter for ongoing transmission */
|
|
|
|
uint16_t rx_limit; /**< size RX frame transferred */
|
|
|
|
} xbee_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reference to the XBee driver interface
|
|
|
|
*/
|
2015-08-17 15:41:29 +02:00
|
|
|
extern const gnrc_netdev_driver_t xbee_driver;
|
2015-03-12 14:20:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize the given Xbee device
|
|
|
|
*
|
|
|
|
* @param[out] dev Xbee device to initialize
|
|
|
|
* @param[in] uart UART interfaced the device is connected to
|
|
|
|
* @param[in] baudrate baudrate to use
|
|
|
|
* @param[in] sleep_pin GPIO pin that is connected to the SLEEP pin, set to
|
2015-06-14 16:12:47 +02:00
|
|
|
* GPIO_UNDEF if not used
|
2016-03-28 19:59:37 +02:00
|
|
|
* @param[in] reset_pin GPIO pin that is connected to the STATUS pin, set to
|
2015-06-14 16:12:47 +02:00
|
|
|
* GPIO_UNDEF if not used
|
2015-03-12 14:20:27 +01:00
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return -ENODEV on invalid device descriptor
|
|
|
|
* @return -ENXIO on invalid UART or GPIO pins
|
|
|
|
*/
|
|
|
|
int xbee_init(xbee_t *dev, uart_t uart, uint32_t baudrate,
|
2016-03-28 19:59:37 +02:00
|
|
|
gpio_t sleep_pin, gpio_t reset_pin);
|
2015-03-12 14:20:27 +01:00
|
|
|
|
2015-05-08 15:51:26 +02:00
|
|
|
/**
|
|
|
|
* @brief auto_init struct holding Xbee device initalization params
|
|
|
|
*/
|
|
|
|
typedef struct xbee_params {
|
|
|
|
uart_t uart; /**< UART interfaced the device is connected to */
|
|
|
|
uint32_t baudrate; /**< baudrate to use */
|
|
|
|
gpio_t sleep_pin; /**< GPIO pin that is connected to the SLEEP pin
|
2015-06-14 16:12:47 +02:00
|
|
|
set to GPIO_UNDEF if not used */
|
2016-03-28 19:59:37 +02:00
|
|
|
gpio_t reset_pin; /**< GPIO pin that is connected to the STATUS pin
|
2015-06-14 16:12:47 +02:00
|
|
|
set to GPIO_UNDEF if not used */
|
2015-05-08 15:51:26 +02:00
|
|
|
} xbee_params_t;
|
|
|
|
|
2015-03-12 14:20:27 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* XBEE_H_ */
|
|
|
|
/** @} */
|