Merge pull request #5941 from zhuoshuguo/gnrc_mac_type
gnrc: create the basic "gnrc_mac" type for providing common MAC functionalities
This commit is contained in:
commit
e6ad438a0b
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2015 Daniel Krebs
|
||||
*
|
||||
*
|
||||
* 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 net_gnrc_mac A common MAC type for providing key MAC parameters and helper functions
|
||||
* @ingroup net
|
||||
* @brief A common MAC type for providing key MAC parameters and helper functions.
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Internal types used by the GNRC_MAC entities
|
||||
*
|
||||
* @author Daniel Krebs <github@daniel-krebs.net>
|
||||
* @author Shuguo Zhuo <shuguo.zhuo@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef GNRC_MAC_TYPES_H_
|
||||
#define GNRC_MAC_TYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <kernel_types.h>
|
||||
#include <xtimer.h>
|
||||
#include <net/netdev2.h>
|
||||
#include <net/gnrc/netdev2.h>
|
||||
#include <net/gnrc.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief definition for device transmission feedback types
|
||||
*/
|
||||
typedef enum {
|
||||
TX_FEEDBACK_UNDEF = 0, /* Transmission just start, no Tx feedback yet */
|
||||
TX_FEEDBACK_SUCCESS, /* Transmission succeeded */
|
||||
TX_FEEDBACK_NOACK, /* No ACK for the transmitted packet */
|
||||
TX_FEEDBACK_BUSY /* found medium busy when doing transmission */
|
||||
} gnrc_mac_tx_feedback_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GNRC_MAC_TYPES_H_ */
|
||||
/** @} */
|
|
@ -29,9 +29,13 @@
|
|||
#ifndef GNRC_NETDEV2_H
|
||||
#define GNRC_NETDEV2_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "kernel_types.h"
|
||||
#include "net/netdev2.h"
|
||||
#include "net/gnrc.h"
|
||||
#include "net/gnrc/mac/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -46,6 +50,17 @@ extern "C" {
|
|||
*/
|
||||
#define NETDEV2_MSG_TYPE_EVENT 0x1234
|
||||
|
||||
/**
|
||||
* @brief Mask for @ref gnrc_mac_tx_feedback_t
|
||||
*/
|
||||
#define GNRC_NETDEV2_MAC_INFO_TX_FEEDBACK_MASK (0x0003U)
|
||||
|
||||
/**
|
||||
* @brief Flag to track if a transmission might have corrupted a received
|
||||
* packet
|
||||
*/
|
||||
#define GNRC_NETDEV2_MAC_INFO_RX_STARTED (0x0004U)
|
||||
|
||||
/**
|
||||
* @brief Structure holding GNRC netdev2 adapter state
|
||||
*
|
||||
|
@ -81,8 +96,82 @@ typedef struct gnrc_netdev2 {
|
|||
* @brief PID of this adapter for netapi messages
|
||||
*/
|
||||
kernel_pid_t pid;
|
||||
|
||||
#ifdef MODULE_GNRC_MAC
|
||||
/**
|
||||
* @brief general information for the MAC protocol
|
||||
*/
|
||||
uint16_t mac_info;
|
||||
#endif
|
||||
} gnrc_netdev2_t;
|
||||
|
||||
#ifdef MODULE_GNRC_MAC
|
||||
|
||||
/**
|
||||
* @brief get the 'rx_started' state of the device
|
||||
*
|
||||
* This function checks whether the device has started receiving a packet.
|
||||
*
|
||||
* @param[in] dev ptr to netdev2 device
|
||||
*
|
||||
* @return the rx_started state
|
||||
*/
|
||||
static inline bool gnrc_netdev2_get_rx_started(gnrc_netdev2_t *dev)
|
||||
{
|
||||
return (dev->mac_info & GNRC_NETDEV2_MAC_INFO_RX_STARTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the rx_started state of the device
|
||||
*
|
||||
* This function is intended to be called only in netdev2_t::event_callback().
|
||||
*
|
||||
* @param[in] dev ptr to netdev2 device
|
||||
*
|
||||
*/
|
||||
static inline void gnrc_netdev2_set_rx_started(gnrc_netdev2_t *dev, bool rx_started)
|
||||
{
|
||||
if (rx_started) {
|
||||
dev->mac_info |= GNRC_NETDEV2_MAC_INFO_RX_STARTED;
|
||||
}
|
||||
else {
|
||||
dev->mac_info &= ~GNRC_NETDEV2_MAC_INFO_RX_STARTED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the transmission feedback of the device
|
||||
*
|
||||
* @param[in] dev ptr to netdev2 device
|
||||
*
|
||||
* @return the transmission feedback
|
||||
*/
|
||||
static inline gnrc_mac_tx_feedback_t gnrc_netdev2_get_tx_feedback(gnrc_netdev2_t *dev)
|
||||
{
|
||||
return (gnrc_mac_tx_feedback_t)(dev->mac_info &
|
||||
GNRC_NETDEV2_MAC_INFO_TX_FEEDBACK_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the transmission feedback of the device
|
||||
*
|
||||
* This function is intended to be called only in netdev2_t::event_callback().
|
||||
*
|
||||
* @param[in] dev ptr to netdev2 device
|
||||
*
|
||||
*/
|
||||
static inline void gnrc_netdev2_set_tx_feedback(gnrc_netdev2_t *dev,
|
||||
gnrc_mac_tx_feedback_t txf)
|
||||
{
|
||||
/* check if gnrc_mac_tx_feedback does not collide with
|
||||
* GNRC_NETDEV2_MAC_INFO_RX_STARTED */
|
||||
assert(txf & GNRC_NETDEV2_MAC_INFO_RX_STARTED);
|
||||
/* unset previous value */
|
||||
dev->mac_info &= ~GNRC_NETDEV2_MAC_INFO_TX_FEEDBACK_MASK;
|
||||
dev->mac_info |= (uint16_t)(txf & GNRC_NETDEV2_MAC_INFO_TX_FEEDBACK_MASK);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize GNRC netdev2 handler thread
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue