lwmac_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Daniel Krebs
3  * 2016 INRIA
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
21 #ifndef LWMAC_INTERNAL_H
22 #define LWMAC_INTERNAL_H
23 
24 #include <stdint.h>
25 
26 #include "periph/rtt.h"
27 #include "net/gnrc/netif.h"
28 #include "net/gnrc/mac/types.h"
29 #include "net/gnrc/lwmac/types.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
44 #define GNRC_LWMAC_TX_CONTINUE (0x0008U)
45 
56 #define GNRC_LWMAC_QUIT_TX (0x0010U)
57 
68 #define GNRC_LWMAC_PHASE_BACKOFF (0x0020U)
69 
81 #define GNRC_LWMAC_QUIT_RX (0x0040U)
82 
86 typedef struct {
91 
98 #define GNRC_LWMAC_RTT_EVENT_MARGIN_TICKS (RTT_MS_TO_TICKS(2))
99 
107 static inline void gnrc_lwmac_set_tx_continue(gnrc_netif_t *netif, bool tx_continue)
108 {
109  if (tx_continue) {
111  }
112  else {
114  }
115 }
116 
125 static inline bool gnrc_lwmac_get_tx_continue(gnrc_netif_t *netif)
126 {
127  return (netif->mac.mac_info & GNRC_LWMAC_TX_CONTINUE);
128 }
129 
137 static inline void gnrc_lwmac_set_quit_tx(gnrc_netif_t *netif, bool quit_tx)
138 {
139  if (quit_tx) {
140  netif->mac.mac_info |= GNRC_LWMAC_QUIT_TX;
141  }
142  else {
143  netif->mac.mac_info &= ~GNRC_LWMAC_QUIT_TX;
144  }
145 }
146 
155 static inline bool gnrc_lwmac_get_quit_tx(gnrc_netif_t *netif)
156 {
157  return (netif->mac.mac_info & GNRC_LWMAC_QUIT_TX);
158 }
159 
167 static inline void gnrc_lwmac_set_phase_backoff(gnrc_netif_t *netif, bool backoff)
168 {
169  if (backoff) {
171  }
172  else {
174  }
175 }
176 
185 static inline bool gnrc_lwmac_get_phase_backoff(gnrc_netif_t *netif)
186 {
187  return (netif->mac.mac_info & GNRC_LWMAC_PHASE_BACKOFF);
188 }
189 
197 static inline void gnrc_lwmac_set_quit_rx(gnrc_netif_t *netif, bool quit_rx)
198 {
199  if (quit_rx) {
200  netif->mac.mac_info |= GNRC_LWMAC_QUIT_RX;
201  }
202  else {
203  netif->mac.mac_info &= ~GNRC_LWMAC_QUIT_RX;
204  }
205 }
206 
215 static inline bool gnrc_lwmac_get_quit_rx(gnrc_netif_t *netif)
216 {
217  return (netif->mac.mac_info & GNRC_LWMAC_QUIT_RX);
218 }
219 
227 static inline void gnrc_lwmac_set_dutycycle_active(gnrc_netif_t *netif, bool active)
228 {
229  if (active) {
230  netif->mac.prot.lwmac.lwmac_info |= GNRC_LWMAC_DUTYCYCLE_ACTIVE;
231  }
232  else {
233  netif->mac.prot.lwmac.lwmac_info &= ~GNRC_LWMAC_DUTYCYCLE_ACTIVE;
234  }
235 }
236 
246 {
247  return (netif->mac.prot.lwmac.lwmac_info & GNRC_LWMAC_DUTYCYCLE_ACTIVE);
248 }
249 
257 static inline void gnrc_lwmac_set_reschedule(gnrc_netif_t *netif, bool reschedule)
258 {
259  if (reschedule) {
260  netif->mac.prot.lwmac.lwmac_info |= GNRC_LWMAC_NEEDS_RESCHEDULE;
261  }
262  else {
263  netif->mac.prot.lwmac.lwmac_info &= ~GNRC_LWMAC_NEEDS_RESCHEDULE;
264  }
265 }
266 
275 static inline bool gnrc_lwmac_get_reschedule(gnrc_netif_t *netif)
276 {
277  return (netif->mac.prot.lwmac.lwmac_info & GNRC_LWMAC_NEEDS_RESCHEDULE);
278 }
279 
303 
316 
325 
333 
341 static inline uint32_t _gnrc_lwmac_ticks_to_phase(uint32_t ticks)
342 {
344 
346 }
347 
353 static inline uint32_t _gnrc_lwmac_phase_now(void)
354 {
356 }
357 
365 static inline uint32_t _gnrc_lwmac_ticks_until_phase(uint32_t phase)
366 {
367  long int tmp = phase - _gnrc_lwmac_phase_now();
368 
369  if (tmp < 0) {
370  /* Phase in next interval */
372  }
373 
374  return (uint32_t)tmp;
375 }
376 
388 
389 #ifdef __cplusplus
390 }
391 #endif
392 
393 #endif /* LWMAC_INTERNAL_H */
394 
_gnrc_lwmac_dispatch_defer
int _gnrc_lwmac_dispatch_defer(gnrc_pktsnip_t *buffer[], gnrc_pktsnip_t *pkt)
Store the received packet to the dispatch buffer and remove possible duplicate packets.
gnrc_lwmac_set_reschedule
static void gnrc_lwmac_set_reschedule(gnrc_netif_t *netif, bool reschedule)
set the GNRC_LWMAC_NEEDS_RESCHEDULE flag of LWMAC
Definition: lwmac_internal.h:257
gnrc_lwmac_set_quit_rx
static void gnrc_lwmac_set_quit_rx(gnrc_netif_t *netif, bool quit_rx)
set the GNRC_LWMAC_QUIT_RX flag of the device
Definition: lwmac_internal.h:197
gnrc_netif_t::mac
gnrc_netif_mac_t mac
Common MAC module component
Definition: netif.h:130
gnrc_lwmac_get_quit_tx
static bool gnrc_lwmac_get_quit_tx(gnrc_netif_t *netif)
get the GNRC_LWMAC_QUIT_TX flag of the device
Definition: lwmac_internal.h:155
assert
#define assert(cond)
abort the program if assertion is false
Definition: assert.h:104
gnrc_lwmac_set_dutycycle_active
static void gnrc_lwmac_set_dutycycle_active(gnrc_netif_t *netif, bool active)
set the GNRC_LWMAC_DUTYCYCLE_ACTIVE flag of LWMAC
Definition: lwmac_internal.h:227
_gnrc_lwmac_transmit
int _gnrc_lwmac_transmit(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
send a packet over the network interface in LWMAC
gnrc_lwmac_get_quit_rx
static bool gnrc_lwmac_get_quit_rx(gnrc_netif_t *netif)
get the GNRC_LWMAC_QUIT_RX flag of the device
Definition: lwmac_internal.h:215
gnrc_lwmac_packet_info_t::header
gnrc_lwmac_hdr_t * header
LWMAC header of packet.
Definition: lwmac_internal.h:87
gnrc_lwmac_packet_info_t
Type to pass information about parsing.
Definition: lwmac_internal.h:86
GNRC_LWMAC_DUTYCYCLE_ACTIVE
#define GNRC_LWMAC_DUTYCYCLE_ACTIVE
LWMAC duty-cycle active flag.
Definition: types.h:78
rtt.h
Low-level RTT (Real Time Timer) peripheral driver interface definitions.
types.h
Internal data types used by GNRC_MAC.
GNRC_LWMAC_PHASE_BACKOFF
#define GNRC_LWMAC_PHASE_BACKOFF
Flag to track if the device need to reselect a new wake-up phase.
Definition: lwmac_internal.h:68
gnrc_lwmac_hdr_t
LWMAC header.
Definition: hdr.h:74
_gnrc_lwmac_ticks_to_phase
static uint32_t _gnrc_lwmac_ticks_to_phase(uint32_t ticks)
Convert RTT ticks to device phase.
Definition: lwmac_internal.h:341
netopt_state_t
netopt_state_t
Option parameter to be used with NETOPT_STATE to set or get the state of a network device or protocol...
Definition: netopt.h:805
gnrc_lwmac_get_dutycycle_active
static bool gnrc_lwmac_get_dutycycle_active(gnrc_netif_t *netif)
get the GNRC_LWMAC_DUTYCYCLE_ACTIVE flag of LWMAC
Definition: lwmac_internal.h:245
GNRC_LWMAC_QUIT_RX
#define GNRC_LWMAC_QUIT_RX
Flag to track if the device needs to quit the wake-up (listening) procedure.
Definition: lwmac_internal.h:81
gnrc_netif_t
Representation of a network interface.
Definition: netif.h:115
_gnrc_lwmac_set_netdev_state
void _gnrc_lwmac_set_netdev_state(gnrc_netif_t *netif, netopt_state_t devstate)
Shortcut to set the state of netdev.
gnrc_lwmac_set_quit_tx
static void gnrc_lwmac_set_quit_tx(gnrc_netif_t *netif, bool quit_tx)
set the GNRC_LWMAC_QUIT_TX flag of the device
Definition: lwmac_internal.h:137
gnrc_lwmac_set_phase_backoff
static void gnrc_lwmac_set_phase_backoff(gnrc_netif_t *netif, bool backoff)
set the GNRC_LWMAC_PHASE_BACKOFF flag of the device
Definition: lwmac_internal.h:167
RTT_US_TO_TICKS
#define RTT_US_TO_TICKS(us)
Convert microseconds to rtt ticks.
Definition: rtt.h:109
gnrc_lwmac_l2_addr_t
LWMAC internal L2 address structure.
Definition: hdr.h:61
gnrc_lwmac_get_reschedule
static bool gnrc_lwmac_get_reschedule(gnrc_netif_t *netif)
get the GNRC_LWMAC_NEEDS_RESCHEDULE flag of LWMAC
Definition: lwmac_internal.h:275
gnrc_netif_mac_t::mac_info
uint16_t mac_info
general information for the MAC protocol
Definition: mac.h:76
gnrc_lwmac_packet_info_t::dst_addr
gnrc_lwmac_l2_addr_t dst_addr
copied destination address of packet
Definition: lwmac_internal.h:89
gnrc_lwmac_get_tx_continue
static bool gnrc_lwmac_get_tx_continue(gnrc_netif_t *netif)
get the GNRC_LWMAC_TX_CONTINUE flag of the device
Definition: lwmac_internal.h:125
rtt_get_counter
uint32_t rtt_get_counter(void)
Get the current RTT counter.
GNRC_LWMAC_NEEDS_RESCHEDULE
#define GNRC_LWMAC_NEEDS_RESCHEDULE
LWMAC needs reschedule flag.
Definition: types.h:86
netif.h
Definition for GNRC's network interfaces.
GNRC_LWMAC_TX_CONTINUE
#define GNRC_LWMAC_TX_CONTINUE
Flag to track if the sender can continue to transmit packet to the receiver in its TX procedure.
Definition: lwmac_internal.h:44
gnrc_lwmac_set_tx_continue
static void gnrc_lwmac_set_tx_continue(gnrc_netif_t *netif, bool tx_continue)
set the GNRC_LWMAC_TX_CONTINUE flag of the device
Definition: lwmac_internal.h:107
CONFIG_GNRC_LWMAC_WAKEUP_INTERVAL_US
#define CONFIG_GNRC_LWMAC_WAKEUP_INTERVAL_US
Time between consecutive wake-ups.
Definition: lwmac.h:104
_gnrc_lwmac_parse_packet
int _gnrc_lwmac_parse_packet(gnrc_pktsnip_t *pkt, gnrc_lwmac_packet_info_t *info)
Parse an incoming packet and extract important information.
_gnrc_lwmac_phase_now
static uint32_t _gnrc_lwmac_phase_now(void)
Get device's current phase.
Definition: lwmac_internal.h:353
gnrc_lwmac_get_phase_backoff
static bool gnrc_lwmac_get_phase_backoff(gnrc_netif_t *netif)
get the GNRC_LWMAC_PHASE_BACKOFF flag of the device
Definition: lwmac_internal.h:185
GNRC_LWMAC_QUIT_TX
#define GNRC_LWMAC_QUIT_TX
Flag to track if the sender should quit Tx in current cycle.
Definition: lwmac_internal.h:56
gnrc_pktsnip
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:108
types.h
Definition of internal types used by LWMAC.
gnrc_lwmac_packet_info_t::src_addr
gnrc_lwmac_l2_addr_t src_addr
copied source address of packet
Definition: lwmac_internal.h:88
_gnrc_lwmac_ticks_until_phase
static uint32_t _gnrc_lwmac_ticks_until_phase(uint32_t phase)
Calculate how many ticks remaining to the targeted phase in the future.
Definition: lwmac_internal.h:365
_gnrc_lwmac_get_netdev_state
netopt_state_t _gnrc_lwmac_get_netdev_state(gnrc_netif_t *netif)
Shortcut to get the state of netdev.