Loading...
Searching...
No Matches
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
10#pragma once
11
22
23#include <stdint.h>
24
25#include "periph/rtt.h"
26#include "net/gnrc/netif.h"
27#include "net/gnrc/mac/types.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
43#define GNRC_LWMAC_TX_CONTINUE (0x0008U)
44
55#define GNRC_LWMAC_QUIT_TX (0x0010U)
56
67#define GNRC_LWMAC_PHASE_BACKOFF (0x0020U)
68
80#define GNRC_LWMAC_QUIT_RX (0x0040U)
81
90
97#define GNRC_LWMAC_RTT_EVENT_MARGIN_TICKS (RTT_MS_TO_TICKS(2))
98
106static inline void gnrc_lwmac_set_tx_continue(gnrc_netif_t *netif, bool tx_continue)
107{
108 if (tx_continue) {
110 }
111 else {
113 }
114}
115
124static inline bool gnrc_lwmac_get_tx_continue(gnrc_netif_t *netif)
125{
126 return (netif->mac.mac_info & GNRC_LWMAC_TX_CONTINUE);
127}
128
136static inline void gnrc_lwmac_set_quit_tx(gnrc_netif_t *netif, bool quit_tx)
137{
138 if (quit_tx) {
140 }
141 else {
143 }
144}
145
154static inline bool gnrc_lwmac_get_quit_tx(gnrc_netif_t *netif)
155{
156 return (netif->mac.mac_info & GNRC_LWMAC_QUIT_TX);
157}
158
166static inline void gnrc_lwmac_set_phase_backoff(gnrc_netif_t *netif, bool backoff)
167{
168 if (backoff) {
170 }
171 else {
173 }
174}
175
185{
186 return (netif->mac.mac_info & GNRC_LWMAC_PHASE_BACKOFF);
187}
188
196static inline void gnrc_lwmac_set_quit_rx(gnrc_netif_t *netif, bool quit_rx)
197{
198 if (quit_rx) {
200 }
201 else {
203 }
204}
205
214static inline bool gnrc_lwmac_get_quit_rx(gnrc_netif_t *netif)
215{
216 return (netif->mac.mac_info & GNRC_LWMAC_QUIT_RX);
217}
218
226static inline void gnrc_lwmac_set_dutycycle_active(gnrc_netif_t *netif, bool active)
227{
228 if (active) {
229 netif->mac.prot.lwmac.lwmac_info |= GNRC_LWMAC_DUTYCYCLE_ACTIVE;
230 }
231 else {
232 netif->mac.prot.lwmac.lwmac_info &= ~GNRC_LWMAC_DUTYCYCLE_ACTIVE;
233 }
234}
235
245{
246 return (netif->mac.prot.lwmac.lwmac_info & GNRC_LWMAC_DUTYCYCLE_ACTIVE);
247}
248
256static inline void gnrc_lwmac_set_reschedule(gnrc_netif_t *netif, bool reschedule)
257{
258 if (reschedule) {
259 netif->mac.prot.lwmac.lwmac_info |= GNRC_LWMAC_NEEDS_RESCHEDULE;
260 }
261 else {
262 netif->mac.prot.lwmac.lwmac_info &= ~GNRC_LWMAC_NEEDS_RESCHEDULE;
263 }
264}
265
274static inline bool gnrc_lwmac_get_reschedule(gnrc_netif_t *netif)
275{
276 return (netif->mac.prot.lwmac.lwmac_info & GNRC_LWMAC_NEEDS_RESCHEDULE);
277}
278
302
315
324
332
340static inline uint32_t _gnrc_lwmac_ticks_to_phase(uint32_t ticks)
341{
343
345}
346
352static inline uint32_t _gnrc_lwmac_phase_now(void)
353{
355}
356
364static inline uint32_t _gnrc_lwmac_ticks_until_phase(uint32_t phase)
365{
366 long int tmp = phase - _gnrc_lwmac_phase_now();
367
368 if (tmp < 0) {
369 /* Phase in next interval */
371 }
372
373 return (uint32_t)tmp;
374}
375
387
388#ifdef __cplusplus
389}
390#endif
391
#define assert(cond)
abort the program if assertion is false
Definition assert.h:135
Definition for GNRC's network interfaces.
uint32_t rtt_get_counter(void)
Get the current RTT counter.
#define RTT_US_TO_TICKS(us)
Convert microseconds to rtt ticks.
Definition rtt.h:112
#define CONFIG_GNRC_LWMAC_WAKEUP_INTERVAL_US
Time between consecutive wake-ups.
Definition lwmac.h:104
struct gnrc_pktsnip gnrc_pktsnip_t
Type to represent parts (either headers or payload) of a packet, called snips.
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:893
#define GNRC_LWMAC_QUIT_RX
Flag to track if the device needs to quit the wake-up (listening) procedure.
#define GNRC_LWMAC_TX_CONTINUE
Flag to track if the sender can continue to transmit packet to the receiver in its TX procedure.
static void gnrc_lwmac_set_quit_tx(gnrc_netif_t *netif, bool quit_tx)
set the GNRC_LWMAC_QUIT_TX flag of the device
static void gnrc_lwmac_set_reschedule(gnrc_netif_t *netif, bool reschedule)
set the GNRC_LWMAC_NEEDS_RESCHEDULE flag of LWMAC
#define GNRC_LWMAC_PHASE_BACKOFF
Flag to track if the device need to reselect a new wake-up phase.
static bool gnrc_lwmac_get_quit_rx(gnrc_netif_t *netif)
get the GNRC_LWMAC_QUIT_RX flag of the device
static bool gnrc_lwmac_get_quit_tx(gnrc_netif_t *netif)
get the GNRC_LWMAC_QUIT_TX flag of the device
void _gnrc_lwmac_set_netdev_state(gnrc_netif_t *netif, netopt_state_t devstate)
Shortcut to set the state of netdev.
static bool gnrc_lwmac_get_reschedule(gnrc_netif_t *netif)
get the GNRC_LWMAC_NEEDS_RESCHEDULE flag of LWMAC
static bool gnrc_lwmac_get_phase_backoff(gnrc_netif_t *netif)
get the GNRC_LWMAC_PHASE_BACKOFF flag of the device
static void gnrc_lwmac_set_quit_rx(gnrc_netif_t *netif, bool quit_rx)
set the GNRC_LWMAC_QUIT_RX flag of the device
static void gnrc_lwmac_set_phase_backoff(gnrc_netif_t *netif, bool backoff)
set the GNRC_LWMAC_PHASE_BACKOFF flag of the device
int _gnrc_lwmac_transmit(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
send a packet over the network interface in LWMAC
netopt_state_t _gnrc_lwmac_get_netdev_state(gnrc_netif_t *netif)
Shortcut to get the state of netdev.
int _gnrc_lwmac_parse_packet(gnrc_pktsnip_t *pkt, gnrc_lwmac_packet_info_t *info)
Parse an incoming packet and extract important information.
static uint32_t _gnrc_lwmac_phase_now(void)
Get device's current phase.
#define GNRC_LWMAC_QUIT_TX
Flag to track if the sender should quit Tx in current cycle.
static bool gnrc_lwmac_get_tx_continue(gnrc_netif_t *netif)
get the GNRC_LWMAC_TX_CONTINUE flag of the device
static uint32_t _gnrc_lwmac_ticks_to_phase(uint32_t ticks)
Convert RTT ticks to device phase.
static uint32_t _gnrc_lwmac_ticks_until_phase(uint32_t phase)
Calculate how many ticks remaining to the targeted phase in the future.
static void gnrc_lwmac_set_dutycycle_active(gnrc_netif_t *netif, bool active)
set the GNRC_LWMAC_DUTYCYCLE_ACTIVE flag of LWMAC
static bool gnrc_lwmac_get_dutycycle_active(gnrc_netif_t *netif)
get the GNRC_LWMAC_DUTYCYCLE_ACTIVE flag of LWMAC
static void gnrc_lwmac_set_tx_continue(gnrc_netif_t *netif, bool tx_continue)
set the GNRC_LWMAC_TX_CONTINUE flag of the device
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.
Low-level RTT (Real Time Timer) peripheral driver interface definitions.
LWMAC header.
Definition hdr.h:73
LWMAC internal L2 address structure.
Definition hdr.h:60
Type to pass information about parsing.
gnrc_lwmac_l2_addr_t dst_addr
copied destination address of packet
gnrc_lwmac_l2_addr_t src_addr
copied source address of packet
gnrc_lwmac_hdr_t * header
LWMAC header of packet.
uint16_t mac_info
general information for the MAC protocol
Definition mac.h:76
Representation of a network interface.
Definition netif.h:135
gnrc_netif_mac_t mac
Common MAC module component
Definition netif.h:150
Definition of internal types used by LWMAC.
#define GNRC_LWMAC_DUTYCYCLE_ACTIVE
LWMAC duty-cycle active flag.
Definition types.h:77
#define GNRC_LWMAC_NEEDS_RESCHEDULE
LWMAC needs reschedule flag.
Definition types.h:85
Internal data types used by GNRC_MAC.