Skip to content

Commit

Permalink
Merge pull request #6074 from zhuoshuguo/gnrc_add_internal_mac_types
Browse files Browse the repository at this point in the history
gnrc_mac: add mac tx and rx internal types.
  • Loading branch information
miri64 committed Jan 4, 2017
2 parents 84b2910 + 6a0ac75 commit e30989a
Show file tree
Hide file tree
Showing 12 changed files with 890 additions and 15 deletions.
80 changes: 80 additions & 0 deletions sys/include/net/gnrc/mac/internal.h
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2015 Daniel Krebs
* 2016 INRIA
*
* 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.
*/

/**
* @ingroup net_gnrc_mac
* @{
*
* @file
* @brief Definitions of internal functions of GNRC_MAC module
* @internal
* @author Daniel Krebs <github@daniel-krebs.net>
* @author Shuguo Zhuo <shuguo.zhuo@inria.fr>
*/

#ifndef GNRC_MAC_INTERNAL_H_
#define GNRC_MAC_INTERNAL_H_

#include <stdint.h>
#include <net/ieee802154.h>
#include <net/gnrc/mac/types.h>

#ifdef __cplusplus
extern "C" {
#endif

#if (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN)
/**
* @brief Queues the packet into the related transmission packet queue in netdev2_t::tx.
* Note that, in case the `gnrc_mac_tx_neighbor_t` structure is in used (indicated
* by `GNRC_MAC_NEIGHBOR_COUNT != 0`), this function queues the packet to
* the queue associated to the pkt's destination neighbor, including a
* `broadcast-neighbor` (neighbor id is `0` in netdev2_t::tx::neighbors) which
* specifically stores broadcasting packets.
* On the other hand, if `gnrc_mac_tx_neighbor_t` structure is not in used (indicated
* by `GNRC_MAC_NEIGHBOR_COUNT == 0`), this function queues the packet into the single
* priority TX queue defined in in netdev2_t::tx.
*
* @param[in,out] tx gnrc_mac transmission management object
* @param[in] priority the priority of @p pkt
* @param[in] pkt gnrc packet that will be queued
*
* @return true if queued successfully, otherwise false.
*/
bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t* tx, uint32_t priority, gnrc_pktsnip_t* pkt);
#endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */

#if (GNRC_MAC_RX_QUEUE_SIZE != 0) || defined(DOXYGEN)
/**
* @brief Queues the packet into the reception packet queue in netdev2_t::rx.
*
* @param[in,out] rx gnrc_mac reception management object
* @param[in] priority the priority of @p pkt
* @param[in] pkt gnrc packet that will be queued
*
* @return true if queued successfully, otherwise false.
*/
bool gnrc_mac_queue_rx_packet(gnrc_mac_rx_t* rx, uint32_t priority, gnrc_pktsnip_t* pkt);
#endif /* (GNRC_MAC_RX_QUEUE_SIZE != 0) || defined(DOXYGEN) */

#if (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN)
/**
* @brief Dispatch all the packets stored in netdev2_t::rx:dispatch_buffer to upper layer.
*
* @param[in,out] rx gnrc_mac reception management object
*/
void gnrc_mac_dispatch(gnrc_mac_rx_t* rx);
#endif /* (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN) */

#ifdef __cplusplus
}
#endif

#endif /* GNRC_MAC_INTERNAL_H_ */
/** @} */
64 changes: 64 additions & 0 deletions sys/include/net/gnrc/mac/mac.h
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2015 Daniel Krebs
* 2016 INRIA
*
* 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 Common MAC module
* @ingroup net_gnrc
* @brief A MAC module for providing common MAC parameters and helper functions.
*
* @{
*
* @file
* @brief Definitions of GNRC_MAC
*
* @author Daniel Krebs <github@daniel-krebs.net>
* @author Shuguo Zhuo <shuguo.zhuo@inria.fr>
*/

#ifndef GNRC_MAC_H
#define GNRC_MAC_H

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief The default rx queue size for incoming packets
*/
#ifndef GNRC_MAC_RX_QUEUE_SIZE
#define GNRC_MAC_RX_QUEUE_SIZE (8U)
#endif

/**
* @brief The default buffer size for storing dispatching packets
*/
#ifndef GNRC_MAC_DISPATCH_BUFFER_SIZE
#define GNRC_MAC_DISPATCH_BUFFER_SIZE (8U)
#endif

/**
* @brief Count of neighbor nodes in one-hop distance
*/
#ifndef GNRC_MAC_NEIGHBOR_COUNT
#define GNRC_MAC_NEIGHBOR_COUNT (8U)
#endif

/**
* @brief The default queue size for transmission packets coming from higher layers
*/
#ifndef GNRC_MAC_TX_QUEUE_SIZE
#define GNRC_MAC_TX_QUEUE_SIZE (8U)
#endif

#ifdef __cplusplus
}
#endif

#endif /* GNRC_MAC_H */
/** @} */
162 changes: 149 additions & 13 deletions sys/include/net/gnrc/mac/types.h
@@ -1,20 +1,18 @@
/*
* Copyright (C) 2015 Daniel Krebs
*
* 2016 INRIA
*
* 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.
* @ingroup net_gnrc_mac
* @{
*
* @file
* @brief Internal types used by the GNRC_MAC entities
* @brief Internal data types used by GNRC_MAC
*
* @author Daniel Krebs <github@daniel-krebs.net>
* @author Shuguo Zhuo <shuguo.zhuo@inria.fr>
Expand All @@ -26,11 +24,10 @@
#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>

#include <net/gnrc/priority_pktqueue.h>
#include <net/ieee802154.h>
#include <net/gnrc/mac/mac.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -40,12 +37,151 @@ extern "C" {
* @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 */
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;

/**
* @brief Static initializer for gnrc_mac_tx_feedback_t.
*/
#define GNRC_MAC_TX_FEEDBACK_INIT { TX_FEEDBACK_UNDEF }

#if ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN)
/**
* @brief MAC internal type for storing reception state parameters and
* state machines.
* This structure can be extended to contain more needed
* states and parameters. Please guard them by appropriate
* #ifdef directives when applicable.
*/
typedef struct {
#if (GNRC_MAC_RX_QUEUE_SIZE != 0) || defined(DOXYGEN)
gnrc_priority_pktqueue_t queue; /**< RX packet queue */
gnrc_priority_pktqueue_node_t _queue_nodes[GNRC_MAC_RX_QUEUE_SIZE]; /**< RX queue nodes */
#endif /* (GNRC_MAC_RX_QUEUE_SIZE != 0) || defined(DOXYGEN) */

#if (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN)
gnrc_pktsnip_t* dispatch_buffer[GNRC_MAC_DISPATCH_BUFFER_SIZE]; /**< dispatch packet buffer */
#endif /* (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN) */
} gnrc_mac_rx_t;

/**
* @brief Static initializer for gnrc_mac_rx_t.
*/
#if ((GNRC_MAC_RX_QUEUE_SIZE != 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN)
#define GNRC_MAC_RX_INIT { \
PRIORITY_PKTQUEUE_INIT, \
{ PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \
{ NULL }, \
}
#elif (GNRC_MAC_RX_QUEUE_SIZE != 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE == 0) || defined(DOXYGEN)
#define GNRC_MAC_RX_INIT { \
PRIORITY_PKTQUEUE_INIT, \
{ PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \
}
#elif (GNRC_MAC_RX_QUEUE_SIZE == 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0) || defined(DOXYGEN)
#define GNRC_MAC_RX_INIT { \
{ NULL }, \
}
#endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) && (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */
#endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */

#if (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN)
/**
* @brief type for storing states of TX neighbor node.
*/
typedef struct {
uint8_t l2_addr[IEEE802154_LONG_ADDRESS_LEN]; /**< Address of neighbor node */
uint8_t l2_addr_len; /**< Neighbor address length */
uint32_t phase; /**< Neighbor's wake-up Phase */

#if (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN)
gnrc_priority_pktqueue_t queue; /**< TX queue for this particular Neighbor */
#endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */
} gnrc_mac_tx_neighbor_t;

/**
* @brief Uninitialized phase value.
*/
#define GNRC_MAC_PHASE_UNINITIALIZED (0)

/**
* @brief Maximum phase value.
*/
#define GNRC_MAC_PHASE_MAX (-1)

/**
* @brief Static initializer for gnrc_mac_tx_neighbor_t.
*/
#if (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN)
#define GNRC_MAC_TX_NEIGHBOR_INIT { \
{ 0 }, \
0, \
GNRC_MAC_PHASE_UNINITIALIZED, \
PRIORITY_PKTQUEUE_INIT, \
}
#else
#define GNRC_MAC_TX_NEIGHBOR_INIT { \
{ 0 }, \
0, \
GNRC_MAC_PHASE_UNINITIALIZED, \
}
#endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */
#endif /* (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) */

#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN)
/**
* @brief MAC internal type for storing transmission state parameters and
* state machines.
* This structure can be extended to contain more needed
* states and parameters. Please guard them by appropriate
* #ifdef directives when applicable.
*/
typedef struct {
#if (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN)
gnrc_mac_tx_neighbor_t neighbors[GNRC_MAC_NEIGHBOR_COUNT + 1]; /**< Neighbor information units for one-hop neighbors.
First unit is for broadcast (+1) */
gnrc_mac_tx_neighbor_t* current_neighbor; /**< Neighbor information unit of destination node to which
the current packet will be sent */
#endif /* (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) */

#if (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN)
#if (GNRC_MAC_NEIGHBOR_COUNT == 0) || defined(DOXYGEN)
gnrc_priority_pktqueue_t queue; /**< If neighbor queues is not used, define
a single queue for managing TX packets. */
#endif /* (GNRC_MAC_NEIGHBOR_COUNT == 0) || defined(DOXYGEN) */

gnrc_priority_pktqueue_node_t _queue_nodes[GNRC_MAC_TX_QUEUE_SIZE]; /**< Shared buffer for TX queue nodes */
gnrc_pktsnip_t* packet; /**< currently scheduled packet for sending */
#endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */
} gnrc_mac_tx_t;

/**
* @brief Static initializer for gnrc_mac_tx_t.
*/
#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN)
#define GNRC_MAC_TX_INIT { \
{ GNRC_MAC_TX_NEIGHBOR_INIT }, \
NULL, \
{ PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \
NULL, \
}
#elif ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (GNRC_MAC_NEIGHBOR_COUNT == 0)) || defined(DOXYGEN)
#define GNRC_MAC_TX_INIT { \
PRIORITY_PKTQUEUE_INIT, \
{ PRIORITY_PKTQUEUE_NODE_INIT(0, NULL) }, \
NULL, \
}
#elif ((GNRC_MAC_TX_QUEUE_SIZE == 0) && (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN)
#define GNRC_MAC_TX_INIT { \
{ GNRC_MAC_TX_NEIGHBOR_INIT }, \
NULL, \
}
#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) */
#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) */

#ifdef __cplusplus
}
#endif
Expand Down
19 changes: 18 additions & 1 deletion sys/include/net/gnrc/netdev2.h
Expand Up @@ -37,6 +37,7 @@
#include "net/gnrc.h"
#include "net/gnrc/mac/types.h"
#include "net/ieee802154.h"
#include "net/gnrc/mac/mac.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -113,7 +114,23 @@ typedef struct gnrc_netdev2 {
* @brief device's l2 address length
*/
uint8_t l2_addr_len;
#endif

#if ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN)
/**
* @brief MAC internal object which stores reception parameters, queues, and
* state machines.
*/
gnrc_mac_rx_t rx;
#endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */

#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN)
/**
* @brief MAC internal object which stores transmission parameters, queues, and
* state machines.
*/
gnrc_mac_tx_t tx;
#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT == 0)) || defined(DOXYGEN) */
#endif /* MODULE_GNRC_MAC */
} gnrc_netdev2_t;

#ifdef MODULE_GNRC_MAC
Expand Down
3 changes: 3 additions & 0 deletions sys/net/gnrc/Makefile
Expand Up @@ -70,6 +70,9 @@ endif
ifneq (,$(filter gnrc_nomac,$(USEMODULE)))
DIRS += link_layer/nomac
endif
ifneq (,$(filter gnrc_mac,$(USEMODULE)))
DIRS += link_layer/gnrc_mac
endif
ifneq (,$(filter gnrc_pkt,$(USEMODULE)))
DIRS += pkt
endif
Expand Down
3 changes: 3 additions & 0 deletions sys/net/gnrc/link_layer/gnrc_mac/Makefile
@@ -0,0 +1,3 @@
MODULE = gnrc_mac

include $(RIOTBASE)/Makefile.base

0 comments on commit e30989a

Please sign in to comment.