sys/include/net/gnrc/netdev.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
29 #ifndef GNRC_NETDEV_H
30 #define GNRC_NETDEV_H
31 
32 #include <assert.h>
33 #include <stdint.h>
34 
35 #include "kernel_types.h"
36 #include "net/netdev.h"
37 #include "net/gnrc.h"
38 #include "net/gnrc/mac/types.h"
39 #include "net/ieee802154.h"
40 #include "net/gnrc/mac/mac.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
49 #ifndef GNRC_NETDEV_MAC_PRIO
50 #define GNRC_NETDEV_MAC_PRIO (THREAD_PRIORITY_MAIN - 5)
51 #endif
52 
56 #define NETDEV_MSG_TYPE_EVENT 0x1234
57 
61 #define GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK (0x0003U)
62 
67 #define GNRC_NETDEV_MAC_INFO_RX_STARTED (0x0004U)
68 
77 typedef struct gnrc_netdev {
84  int (*send)(struct gnrc_netdev *dev, gnrc_pktsnip_t *snip);
85 
93  gnrc_pktsnip_t * (*recv)(struct gnrc_netdev *dev);
94 
99 
104 
105 #ifdef MODULE_GNRC_MAC
106 
109  uint16_t mac_info;
110 
114  uint8_t l2_addr[IEEE802154_LONG_ADDRESS_LEN];
115 
119  uint8_t l2_addr_len;
120 
121 #if ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN)
122 
126  gnrc_mac_rx_t rx;
127 #endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || defined(DOXYGEN) */
128 
129 #if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN)
130 
134  gnrc_mac_tx_t tx;
135 #endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT == 0)) || defined(DOXYGEN) */
136 #endif /* MODULE_GNRC_MAC */
137 } gnrc_netdev_t;
138 
139 #ifdef MODULE_GNRC_MAC
140 
150 static inline bool gnrc_netdev_get_rx_started(gnrc_netdev_t *dev)
151 {
152  return (dev->mac_info & GNRC_NETDEV_MAC_INFO_RX_STARTED);
153 }
154 
163 static inline void gnrc_netdev_set_rx_started(gnrc_netdev_t *dev, bool rx_started)
164 {
165  if (rx_started) {
166  dev->mac_info |= GNRC_NETDEV_MAC_INFO_RX_STARTED;
167  }
168  else {
169  dev->mac_info &= ~GNRC_NETDEV_MAC_INFO_RX_STARTED;
170  }
171 }
172 
180 static inline gnrc_mac_tx_feedback_t gnrc_netdev_get_tx_feedback(gnrc_netdev_t *dev)
181 {
182  return (gnrc_mac_tx_feedback_t)(dev->mac_info &
184 }
185 
194 static inline void gnrc_netdev_set_tx_feedback(gnrc_netdev_t *dev,
196 {
197  /* check if gnrc_mac_tx_feedback does not collide with
198  * GNRC_NETDEV_MAC_INFO_RX_STARTED */
200  /* unset previous value */
201  dev->mac_info &= ~GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK;
202  dev->mac_info |= (uint16_t)(txf & GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK);
203 }
204 #endif
205 
218 kernel_pid_t gnrc_netdev_init(char *stack, int stacksize, char priority,
219  const char *name, gnrc_netdev_t *gnrc_netdev);
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 
225 #endif /* GNRC_NETDEV_H */
226 
Types used by the kernel.
Internal data types used by GNRC_MAC.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
struct gnrc_netdev gnrc_netdev_t
Structure holding GNRC netdev adapter state.
Definitions low-level network driver interface.
kernel_pid_t pid
PID of this adapter for netapi messages.
netdev_t * dev
netdev handle this adapter is working with
Structure holding GNRC netdev adapter state.
IEEE 802.15.4 header definitions.
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
kernel_pid_t gnrc_netdev_init(char *stack, int stacksize, char priority, const char *name, gnrc_netdev_t *gnrc_netdev)
Initialize GNRC netdev handler thread.
Includes all essential GNRC network stack base modules.
int(* send)(struct gnrc_netdev *dev, gnrc_pktsnip_t *snip)
Send a pktsnip using this device.
Structure to hold driver state.
gnrc_mac_tx_feedback_t
definition for device transmission feedback types
Definition: types.h:39
#define GNRC_NETDEV_MAC_INFO_RX_STARTED
Flag to track if a transmission might have corrupted a received packet.
MAC internal type for storing reception state parameters and state machines.
Definition: types.h:59
#define GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK
Mask for gnrc_mac_tx_feedback_t.
Type to represent parts (either headers or payload) of a packet, called snips.
MAC internal type for storing transmission state parameters and state machines.
Definition: types.h:142
#define IEEE802154_LONG_ADDRESS_LEN
long address (EUI-64)
Definitions of GNRC_MAC.