From 2c1aa8618b94a4cf9c1eb65979eb839ac258f030 Mon Sep 17 00:00:00 2001 From: Akshai M Date: Sun, 24 May 2020 15:18:20 +0530 Subject: [PATCH 1/8] gnrc/mac : Configure GNRC_MAC_RX_QUEUE_SIZE with exponent --- sys/include/net/gnrc/mac/mac.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/include/net/gnrc/mac/mac.h b/sys/include/net/gnrc/mac/mac.h index 983e1dd59bab..39bd499c0009 100644 --- a/sys/include/net/gnrc/mac/mac.h +++ b/sys/include/net/gnrc/mac/mac.h @@ -28,11 +28,22 @@ extern "C" { #endif +/** + * @brief Default message queue size to use for the incoming packets (as + * exponent of 2^n). + * + * As the queue size ALWAYS needs to be power of two, this option represents the + * exponent of 2^n, which will be used as the size of the queue. + */ +#ifndef CONFIG_GNRC_MAC_RX_QUEUE_SIZE_EXP +#define CONFIG_GNRC_MAC_RX_QUEUE_SIZE_EXP (3U) +#endif + /** * @brief The default rx queue size for incoming packets */ #ifndef GNRC_MAC_RX_QUEUE_SIZE -#define GNRC_MAC_RX_QUEUE_SIZE (8U) +#define GNRC_MAC_RX_QUEUE_SIZE (1 << CONFIG_GNRC_MAC_RX_QUEUE_SIZE_EXP) #endif /** From b2550451a167014a4f6506ab454d5e4124f84714 Mon Sep 17 00:00:00 2001 From: Akshai M Date: Sun, 24 May 2020 15:53:49 +0530 Subject: [PATCH 2/8] gnrc/mac : Configure GNRC_MAC_DISPATCH_BUFFER_SIZE with exponent --- sys/include/net/gnrc/mac/mac.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/include/net/gnrc/mac/mac.h b/sys/include/net/gnrc/mac/mac.h index 39bd499c0009..49a213d55ec4 100644 --- a/sys/include/net/gnrc/mac/mac.h +++ b/sys/include/net/gnrc/mac/mac.h @@ -46,11 +46,22 @@ extern "C" { #define GNRC_MAC_RX_QUEUE_SIZE (1 << CONFIG_GNRC_MAC_RX_QUEUE_SIZE_EXP) #endif +/** + * @brief Default buffer size to use for storing dispatching packets (as + * exponent of 2^n). + * + * As the buffer size ALWAYS needs to be power of two, this option represents + * the exponent of 2^n, which will be used as the size of the buffer. + */ +#ifndef CONFIG_GNRC_MAC_DISPATCH_BUFFER_SIZE_EXP +#define CONFIG_GNRC_MAC_DISPATCH_BUFFER_SIZE_EXP (3U) +#endif + /** * @brief The default buffer size for storing dispatching packets */ #ifndef GNRC_MAC_DISPATCH_BUFFER_SIZE -#define GNRC_MAC_DISPATCH_BUFFER_SIZE (8U) +#define GNRC_MAC_DISPATCH_BUFFER_SIZE (1 << CONFIG_GNRC_MAC_DISPATCH_BUFFER_SIZE_EXP) #endif /** From 9ddc9e063381a4f5d6412f46df674758b1dec63c Mon Sep 17 00:00:00 2001 From: Akshai M Date: Sun, 24 May 2020 16:04:09 +0530 Subject: [PATCH 3/8] gnrc/mac : Move GNRC_MAC_NEIGHBOR_COUNT to 'CONFIG_' --- sys/include/net/gnrc/mac/internal.h | 4 +-- sys/include/net/gnrc/mac/mac.h | 6 ++--- sys/include/net/gnrc/mac/types.h | 26 +++++++++---------- sys/include/net/gnrc/netif/mac.h | 6 ++--- .../gnrc/link_layer/gomach/gomach_internal.c | 10 +++---- sys/net/gnrc/link_layer/lwmac/lwmac.c | 2 +- sys/net/gnrc/link_layer/mac/internal.c | 16 ++++++------ .../tests-gnrc_mac_internal.c | 8 +++--- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/sys/include/net/gnrc/mac/internal.h b/sys/include/net/gnrc/mac/internal.h index 3527b99c167f..30176105b93d 100644 --- a/sys/include/net/gnrc/mac/internal.h +++ b/sys/include/net/gnrc/mac/internal.h @@ -98,12 +98,12 @@ static inline void gnrc_netif_set_tx_feedback(gnrc_netif_t *netif, /** * @brief Queues the packet into the related transmission packet queue in netdev_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 + * by `CONFIG_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 netdev_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 + * by `CONFIG_GNRC_MAC_NEIGHBOR_COUNT == 0`), this function queues the packet into the single * priority TX queue defined in in netdev_t::tx. * * @param[in,out] tx gnrc_mac transmission management object diff --git a/sys/include/net/gnrc/mac/mac.h b/sys/include/net/gnrc/mac/mac.h index 49a213d55ec4..d8de2c8dd7f0 100644 --- a/sys/include/net/gnrc/mac/mac.h +++ b/sys/include/net/gnrc/mac/mac.h @@ -65,10 +65,10 @@ extern "C" { #endif /** - * @brief Count of neighbor nodes in one-hop distance + * @brief Count of neighbor nodes in one-hop distance. */ -#ifndef GNRC_MAC_NEIGHBOR_COUNT -#define GNRC_MAC_NEIGHBOR_COUNT (8U) +#ifndef CONFIG_GNRC_MAC_NEIGHBOR_COUNT +#define CONFIG_GNRC_MAC_NEIGHBOR_COUNT (8U) #endif /** diff --git a/sys/include/net/gnrc/mac/types.h b/sys/include/net/gnrc/mac/types.h index 0f77810770fd..433d85b1977f 100644 --- a/sys/include/net/gnrc/mac/types.h +++ b/sys/include/net/gnrc/mac/types.h @@ -115,7 +115,7 @@ typedef struct { #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) +#if (CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) /** * @brief type for storing states of TX neighbor node. */ @@ -162,9 +162,9 @@ typedef struct { GNRC_MAC_PHASE_UNINITIALIZED, \ } #endif /* (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) */ -#endif /* (GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) */ +#endif /* (CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) */ -#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) +#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) /** * @brief MAC internal type for storing transmission state parameters and * state machines. @@ -173,18 +173,18 @@ typedef struct { * \#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. +#if (CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) + gnrc_mac_tx_neighbor_t neighbors[CONFIG_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) */ +#endif /* (CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0) || defined(DOXYGEN) */ #if (GNRC_MAC_TX_QUEUE_SIZE != 0) || defined(DOXYGEN) -#if (GNRC_MAC_NEIGHBOR_COUNT == 0) || defined(DOXYGEN) +#if (CONFIG_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) */ +#endif /* (CONFIG_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 */ @@ -219,26 +219,26 @@ typedef struct { /** * @brief Static initializer for gnrc_mac_tx_t. */ -#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) +#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (CONFIG_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) +#elif ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (CONFIG_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) +#elif ((GNRC_MAC_TX_QUEUE_SIZE == 0) && (CONFIG_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) */ +#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) && (CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) */ +#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0)) || defined(DOXYGEN) */ #ifdef __cplusplus } diff --git a/sys/include/net/gnrc/netif/mac.h b/sys/include/net/gnrc/netif/mac.h index 76dac3019b9a..97429329d436 100644 --- a/sys/include/net/gnrc/netif/mac.h +++ b/sys/include/net/gnrc/netif/mac.h @@ -90,16 +90,16 @@ typedef struct { */ gnrc_mac_rx_t rx; #endif /* ((GNRC_MAC_RX_QUEUE_SIZE != 0) || (GNRC_MAC_DISPATCH_BUFFER_SIZE != 0)) || DOXYGEN */ -#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT != 0)) || DOXYGEN +#if ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0)) || DOXYGEN /** * @brief MAC internal object which stores transmission parameters, queues, and * state machines. * * @note Only available if @ref GNRC_MAC_TX_QUEUE_SIZE or - * @ref GNRC_MAC_NEIGHBOR_COUNT is greater than 0. + * @ref CONFIG_GNRC_MAC_NEIGHBOR_COUNT is greater than 0. */ gnrc_mac_tx_t tx; -#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_NEIGHBOR_COUNT == 0)) || DOXYGEN */ +#endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (CONFIG_GNRC_MAC_NEIGHBOR_COUNT == 0)) || DOXYGEN */ #if defined(MODULE_GNRC_LWMAC) || defined(MODULE_GNRC_GOMACH) gnrc_mac_prot_t prot; diff --git a/sys/net/gnrc/link_layer/gomach/gomach_internal.c b/sys/net/gnrc/link_layer/gomach/gomach_internal.c index 78f325d91b78..0ca67a1cbf09 100644 --- a/sys/net/gnrc/link_layer/gomach/gomach_internal.c +++ b/sys/net/gnrc/link_layer/gomach/gomach_internal.c @@ -1166,11 +1166,11 @@ bool gnrc_gomach_find_next_tx_neighbor(gnrc_netif_t *netif) * thus to be more fair. */ uint8_t j = netif->mac.tx.last_tx_neighbor_id + 1; - if (j >= GNRC_MAC_NEIGHBOR_COUNT) { + if (j >= CONFIG_GNRC_MAC_NEIGHBOR_COUNT) { j = 1; } - for (uint8_t i = 1; i < GNRC_MAC_NEIGHBOR_COUNT; i++) { + for (uint8_t i = 1; i < CONFIG_GNRC_MAC_NEIGHBOR_COUNT; i++) { if (gnrc_priority_pktqueue_length(&netif->mac.tx.neighbors[j].queue) > 0) { netif->mac.tx.last_tx_neighbor_id = j; next = (int) j; @@ -1178,7 +1178,7 @@ bool gnrc_gomach_find_next_tx_neighbor(gnrc_netif_t *netif) } else { j++; - if (j >= GNRC_MAC_NEIGHBOR_COUNT) { + if (j >= CONFIG_GNRC_MAC_NEIGHBOR_COUNT) { j = 1; } } @@ -1388,7 +1388,7 @@ void gnrc_gomach_update_neighbor_phase(gnrc_netif_t *netif) { assert(netif != NULL); - for (uint8_t i = 1; i < GNRC_MAC_NEIGHBOR_COUNT; i++) { + for (uint8_t i = 1; i < CONFIG_GNRC_MAC_NEIGHBOR_COUNT; i++) { if (netif->mac.tx.neighbors[i].mac_type == GNRC_GOMACH_TYPE_KNOWN) { long int tmp = netif->mac.tx.neighbors[i].cp_phase - netif->mac.prot.gomach.backoff_phase_us; @@ -1422,7 +1422,7 @@ void gnrc_gomach_update_neighbor_pubchan(gnrc_netif_t *netif) } /* Toggle TX neighbors' current channel. */ - for (uint8_t i = 1; i < GNRC_MAC_NEIGHBOR_COUNT; i++) { + for (uint8_t i = 1; i < CONFIG_GNRC_MAC_NEIGHBOR_COUNT; i++) { if (netif->mac.tx.neighbors[i].mac_type == GNRC_GOMACH_TYPE_KNOWN) { if (netif->mac.tx.neighbors[i].pub_chanseq == netif->mac.prot.gomach.pub_channel_1) { netif->mac.tx.neighbors[i].pub_chanseq = netif->mac.prot.gomach.pub_channel_2; diff --git a/sys/net/gnrc/link_layer/lwmac/lwmac.c b/sys/net/gnrc/link_layer/lwmac/lwmac.c index 2c08f4921731..d5019ee28b8d 100644 --- a/sys/net/gnrc/link_layer/lwmac/lwmac.c +++ b/sys/net/gnrc/link_layer/lwmac/lwmac.c @@ -201,7 +201,7 @@ static gnrc_mac_tx_neighbor_t *_next_tx_neighbor(gnrc_netif_t *netif) gnrc_mac_tx_neighbor_t *next = NULL; uint32_t phase_nearest = GNRC_LWMAC_PHASE_MAX; - for (unsigned i = 0; i < GNRC_MAC_NEIGHBOR_COUNT; i++) { + for (unsigned i = 0; i < CONFIG_GNRC_MAC_NEIGHBOR_COUNT; i++) { if (gnrc_priority_pktqueue_length(&netif->mac.tx.neighbors[i].queue) > 0) { /* Unknown destinations are initialized with their phase at the end * of the local interval, so known destinations that still wakeup diff --git a/sys/net/gnrc/link_layer/mac/internal.c b/sys/net/gnrc/link_layer/mac/internal.c index 0bb66f8a9c06..6bf43f3c313f 100644 --- a/sys/net/gnrc/link_layer/mac/internal.c +++ b/sys/net/gnrc/link_layer/mac/internal.c @@ -47,7 +47,7 @@ gnrc_priority_pktqueue_node_t *_alloc_pktqueue_node(gnrc_priority_pktqueue_node_ #endif /* ((GNRC_MAC_TX_QUEUE_SIZE != 0) || (GNRC_MAC_RX_QUEUE_SIZE != 0)) */ #if GNRC_MAC_TX_QUEUE_SIZE != 0 -#if GNRC_MAC_NEIGHBOR_COUNT != 0 +#if CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0 /* Find the neighbor's id based on the given address */ int _gnrc_mac_find_neighbor(gnrc_mac_tx_t *tx, const uint8_t *dst_addr, int addr_len) { @@ -59,7 +59,7 @@ int _gnrc_mac_find_neighbor(gnrc_mac_tx_t *tx, const uint8_t *dst_addr, int addr neighbors = tx->neighbors; /* Don't attempt to find broadcast neighbor, so start at index 1 */ - for (int i = 1; i <= (signed)GNRC_MAC_NEIGHBOR_COUNT; i++) { + for (int i = 1; i <= (signed)CONFIG_GNRC_MAC_NEIGHBOR_COUNT; i++) { if (neighbors[i].l2_addr_len == addr_len) { if (memcmp(&(neighbors[i].l2_addr), dst_addr, addr_len) == 0) { return i; @@ -78,7 +78,7 @@ int _gnrc_mac_free_neighbor(gnrc_mac_tx_t *tx) neighbors = tx->neighbors; /* Don't attempt to free broadcast neighbor, so start at index 1 */ - for (int i = 1; i <= (signed)GNRC_MAC_NEIGHBOR_COUNT; i++) { + for (int i = 1; i <= (signed)CONFIG_GNRC_MAC_NEIGHBOR_COUNT; i++) { if ((gnrc_priority_pktqueue_length(&(neighbors[i].queue)) == 0) && (&neighbors[i] != tx->current_neighbor)) { /* Mark as free */ @@ -98,7 +98,7 @@ int _gnrc_mac_alloc_neighbor(gnrc_mac_tx_t *tx) neighbors = tx->neighbors; /* Don't attempt to allocate broadcast neighbor, so start at index 1 */ - for (int i = 1; i <= (signed)GNRC_MAC_NEIGHBOR_COUNT; i++) { + for (int i = 1; i <= (signed)CONFIG_GNRC_MAC_NEIGHBOR_COUNT; i++) { if (neighbors[i].l2_addr_len == 0) { gnrc_priority_pktqueue_init(&(neighbors[i].queue)); return i; @@ -118,14 +118,14 @@ void _gnrc_mac_init_neighbor(gnrc_mac_tx_neighbor_t *neighbor, const uint8_t *ad neighbor->phase = GNRC_MAC_PHASE_MAX; memcpy(&(neighbor->l2_addr), addr, len); } -#endif /* GNRC_MAC_NEIGHBOR_COUNT != 0 */ +#endif /* CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0 */ bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t *tx, uint32_t priority, gnrc_pktsnip_t *pkt) { assert(tx != NULL); assert(pkt != NULL); -#if GNRC_MAC_NEIGHBOR_COUNT == 0 +#if CONFIG_GNRC_MAC_NEIGHBOR_COUNT == 0 gnrc_priority_pktqueue_node_t *node; node = _alloc_pktqueue_node(tx->_queue_nodes, GNRC_MAC_TX_QUEUE_SIZE); @@ -177,7 +177,7 @@ bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t *tx, uint32_t priority, gnrc_pktsnip /* No neighbor entries left */ if (neighbor_id < 0) { DEBUG("[gnrc_mac-int] No neighbor entries left, maybe increase " - "GNRC_MAC_NEIGHBOR_COUNT for better performance\n"); + "CONFIG_GNRC_MAC_NEIGHBOR_COUNT for better performance\n"); /* Try to free an unused queue */ neighbor_id = _gnrc_mac_free_neighbor(tx); @@ -210,7 +210,7 @@ bool gnrc_mac_queue_tx_packet(gnrc_mac_tx_t *tx, uint32_t priority, gnrc_pktsnip neighbor_id); return false; -#endif /* GNRC_MAC_NEIGHBOR_COUNT == 0 */ +#endif /* CONFIG_GNRC_MAC_NEIGHBOR_COUNT == 0 */ } #endif /* GNRC_MAC_TX_QUEUE_SIZE != 0 */ diff --git a/tests/unittests/tests-gnrc_mac_internal/tests-gnrc_mac_internal.c b/tests/unittests/tests-gnrc_mac_internal/tests-gnrc_mac_internal.c index 12edf0f79631..15fa7aea21f7 100644 --- a/tests/unittests/tests-gnrc_mac_internal/tests-gnrc_mac_internal.c +++ b/tests/unittests/tests-gnrc_mac_internal/tests-gnrc_mac_internal.c @@ -33,7 +33,7 @@ static void set_up(void) * correctly queue the packet to the corresponded priority packet queue. * * In case when the `gnrc_mac_tx_neighbor_t` structure is in used (indicated by - * by `GNRC_MAC_NEIGHBOR_COUNT != 0`), `test_gnrc_mac_queue_tx_packet()` successively + * by `CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0`), `test_gnrc_mac_queue_tx_packet()` successively * queues 4 packets, which are pkt1, pkt2, pkt3 and pkt_bcast, into a defined `tx` * (type of `gnrc_mac_tx_t`). Pkt1, pkt2 have the same destination address of "0x76b6", * , pkt3 is heading for "0x447e", while pkt_bcast is for broadcasting. @@ -42,7 +42,7 @@ static void set_up(void) * queued to `tx::neighbors[0]::queue`. * * In case when the `gnrc_mac_tx_neighbor_t` structure is not in used (indicated by - * by `GNRC_MAC_NEIGHBOR_COUNT == 0`), `test_gnrc_mac_queue_tx_packet()` successively + * by `CONFIG_GNRC_MAC_NEIGHBOR_COUNT == 0`), `test_gnrc_mac_queue_tx_packet()` successively * queues 4 packets, which are pkt1, pkt2, pkt3 and pkt_bcast, into a defined `tx` * (type of `gnrc_mac_tx_t`). Pkt1, pkt2 have the same destination address of "0x76b6", * , pkt3 is heading for "0x447e", while pkt_bcast is for broadcasting. @@ -90,7 +90,7 @@ static void test_gnrc_mac_queue_tx_packet(void) LL_APPEND(hdr, pkt3); pkt3 = hdr; -#if GNRC_MAC_NEIGHBOR_COUNT != 0 +#if CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0 gnrc_pktsnip_t *pkt_head; TEST_ASSERT(gnrc_mac_queue_tx_packet(&tx,1,pkt1)); @@ -172,7 +172,7 @@ static void test_gnrc_mac_queue_tx_packet(void) TEST_ASSERT(0 == gnrc_priority_pktqueue_length(&tx.queue)); TEST_ASSERT_EQUAL_STRING(TEST_STRING8, pkt_head->next->data); -#endif /* GNRC_MAC_NEIGHBOR_COUNT != 0 */ +#endif /* CONFIG_GNRC_MAC_NEIGHBOR_COUNT != 0 */ } #endif /* GNRC_MAC_TX_QUEUE_SIZE != 0 */ From 75e0632caf46a8d3e6f44eefb6a9a55964d3d23b Mon Sep 17 00:00:00 2001 From: Akshai M Date: Sun, 24 May 2020 16:10:23 +0530 Subject: [PATCH 4/8] gnrc/mac : Configure GNRC_MAC_TX_QUEUE_SIZE with exponent --- sys/include/net/gnrc/mac/mac.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sys/include/net/gnrc/mac/mac.h b/sys/include/net/gnrc/mac/mac.h index d8de2c8dd7f0..cf6684f2cd49 100644 --- a/sys/include/net/gnrc/mac/mac.h +++ b/sys/include/net/gnrc/mac/mac.h @@ -72,10 +72,22 @@ extern "C" { #endif /** - * @brief The default queue size for transmission packets coming from higher layers + * @brief Default queue size for transmission packets coming from higher + * layers (as exponent of 2^n). + * + * As the queue size ALWAYS needs to be power of two, this option represents + * the exponent of 2^n, which will be used as the size of the buffer. + */ +#ifndef CONFIG_GNRC_MAC_TX_QUEUE_SIZE_EXP +#define CONFIG_GNRC_MAC_TX_QUEUE_SIZE_EXP (3U) +#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) +#define GNRC_MAC_TX_QUEUE_SIZE (1 << CONFIG_GNRC_MAC_TX_QUEUE_SIZE_EXP) #endif /** From ba3368694957832fec042dc435b55009f89c9d19 Mon Sep 17 00:00:00 2001 From: Akshai M Date: Sun, 24 May 2020 16:21:28 +0530 Subject: [PATCH 5/8] gnrc/mac : Model as bool GNRC_MAC_ENABLE_DUTYCYCLE_RECORD Modelled GNRC_MAC_ENABLE_DUTYCYCLE_RECORD as bool. Introduced CONFIG_GNRC_MAC_DISABLE_DUTYCYCLE_RECORD to invert the logic. Tagged GNRC_MAC_ENABLE_DUTYCYCLE_RECORD for deprecation. --- sys/include/net/gnrc/mac/mac.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sys/include/net/gnrc/mac/mac.h b/sys/include/net/gnrc/mac/mac.h index cf6684f2cd49..2905c067c110 100644 --- a/sys/include/net/gnrc/mac/mac.h +++ b/sys/include/net/gnrc/mac/mac.h @@ -21,6 +21,8 @@ * @author Shuguo Zhuo */ +#include "kernel_defines.h" + #ifndef NET_GNRC_MAC_MAC_H #define NET_GNRC_MAC_MAC_H @@ -90,14 +92,27 @@ extern "C" { #define GNRC_MAC_TX_QUEUE_SIZE (1 << CONFIG_GNRC_MAC_TX_QUEUE_SIZE_EXP) #endif +/** + * @brief Disable MAC radio duty-cycle recording and displaying. + */ +#ifdef DOXYGEN +#define CONFIG_GNRC_MAC_DISABLE_DUTYCYCLE_RECORD +#endif + /** * @brief Enable/disable MAC radio duty-cycle recording and displaying. * * Set "1" to enable, set "0" to disable. + * @deprecated Use inverse @ref CONFIG_GNRC_MAC_DISABLE_DUTYCYCLE_RECORD + * instead. Will be removed after 2021.01 release. */ #ifndef GNRC_MAC_ENABLE_DUTYCYCLE_RECORD +#if IS_ACTIVE(CONFIG_GNRC_MAC_DISABLE_DUTYCYCLE_RECORD) +#define GNRC_MAC_ENABLE_DUTYCYCLE_RECORD (0) +#else #define GNRC_MAC_ENABLE_DUTYCYCLE_RECORD (1U) #endif +#endif #ifdef __cplusplus } From 25f778b5527fc175002980f13849f7393126a05c Mon Sep 17 00:00:00 2001 From: Akshai M Date: Sun, 24 May 2020 18:11:45 +0530 Subject: [PATCH 6/8] gnrc/mac : Expose to Kconfig Expose configurations to Kconfig Co-authored-by: Leandro Lanzieri --- sys/net/gnrc/Kconfig | 1 + sys/net/gnrc/link_layer/mac/Kconfig | 46 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 sys/net/gnrc/link_layer/mac/Kconfig diff --git a/sys/net/gnrc/Kconfig b/sys/net/gnrc/Kconfig index 18e9c239d25e..f27b486e3e2e 100644 --- a/sys/net/gnrc/Kconfig +++ b/sys/net/gnrc/Kconfig @@ -9,6 +9,7 @@ menu "GNRC Network stack" rsource "application_layer/dhcpv6/Kconfig" rsource "link_layer/lorawan/Kconfig" +rsource "link_layer/mac/Kconfig" rsource "netif/Kconfig" rsource "network_layer/ipv6/Kconfig" rsource "network_layer/sixlowpan/Kconfig" diff --git a/sys/net/gnrc/link_layer/mac/Kconfig b/sys/net/gnrc/link_layer/mac/Kconfig new file mode 100644 index 000000000000..d43a32b13b45 --- /dev/null +++ b/sys/net/gnrc/link_layer/mac/Kconfig @@ -0,0 +1,46 @@ +# Copyright (c) 2020 Freie Universitaet Berlin +# +# 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. +# +menuconfig KCONFIG_MODULE_GNRC_MAC + bool "Configure GNRC MAC" + depends on MODULE_GNRC_MAC + help + Configure the GNRC MAC using Kconfig. + +if KCONFIG_MODULE_GNRC_MAC + +config GNRC_MAC_RX_QUEUE_SIZE_EXP + int "Exponent for the RX queue size (resulting in the queue size 2^n)" + default 3 + help + As the queue size ALWAYS needs to be power of two, this option + represents the exponent of 2^n, which will be used as the size of the RX + queue for incoming packets. + +config GNRC_MAC_DISPATCH_BUFFER_SIZE_EXP + int "Exponent for the dispatch buffer size (resulting in the buffer size 2^n)" + default 3 + help + As the buffer size ALWAYS needs to be power of two, this option + represents the exponent of 2^n, which will be used as the size of the + dispatch buffer for storing dispatching packets. + +config GNRC_MAC_NEIGHBOR_COUNT + int "Count of neighbor nodes in one-hop distance" + default 8 + +config GNRC_MAC_TX_QUEUE_SIZE_EXP + int "Exponent for the TX queue size (resulting in the queue size 2^n)" + default 3 + help + As the queue size ALWAYS needs to be power of two, this option + represents the exponent of 2^n, which will be used as the size of the TX + queue for transmission packets coming from higher layers. + +config GNRC_MAC_DISABLE_DUTYCYCLE_RECORD + bool "Disable MAC radio duty-cycle recording and displaying" + +endif # KCONFIG_MODULE_GNRC_MAC From 414a0b0fa5f26454cc979b20860b7187ef997d51 Mon Sep 17 00:00:00 2001 From: Akshai M Date: Sun, 24 May 2020 18:21:13 +0530 Subject: [PATCH 7/8] tests/unittests/mac : Added check for macro if set via Kconfig --- tests/unittests/tests-gnrc_mac_internal/Makefile.include | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unittests/tests-gnrc_mac_internal/Makefile.include b/tests/unittests/tests-gnrc_mac_internal/Makefile.include index 29394f309669..49f45a1f5c9e 100644 --- a/tests/unittests/tests-gnrc_mac_internal/Makefile.include +++ b/tests/unittests/tests-gnrc_mac_internal/Makefile.include @@ -1,3 +1,5 @@ USEMODULE += gnrc_priority_pktqueue USEMODULE += gnrc_mac -CFLAGS += -DGNRC_MAC_TX_QUEUE_SIZE=4 -DGNRC_MAC_NEIGHBOR_COUNT=4 + +# Set CFLAGS if not being set via Kconfig +CFLAGS += $(if $(CONFIG_KCONFIG_MODULE_GNRC_MAC),,-DGNRC_MAC_TX_QUEUE_SIZE=4 -DCONFIG_GNRC_MAC_NEIGHBOR_COUNT=4) From 383555c3deb41263e5a0cbb7f220527afde19a64 Mon Sep 17 00:00:00 2001 From: Akshai M Date: Mon, 25 May 2020 21:26:31 +0530 Subject: [PATCH 8/8] gnrc/mac : Update documentation Move non 'CONFIG_' macros away from 'net_gnrc_mac_conf' group --- sys/include/net/gnrc/mac/mac.h | 50 +++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/sys/include/net/gnrc/mac/mac.h b/sys/include/net/gnrc/mac/mac.h index 2905c067c110..cef40e317e08 100644 --- a/sys/include/net/gnrc/mac/mac.h +++ b/sys/include/net/gnrc/mac/mac.h @@ -30,6 +30,11 @@ extern "C" { #endif +/** + * @defgroup net_gnrc_mac_conf GNRC MAC compile configurations + * @ingroup net_gnrc_conf + * @{ + */ /** * @brief Default message queue size to use for the incoming packets (as * exponent of 2^n). @@ -41,13 +46,6 @@ extern "C" { #define CONFIG_GNRC_MAC_RX_QUEUE_SIZE_EXP (3U) #endif -/** - * @brief The default rx queue size for incoming packets - */ -#ifndef GNRC_MAC_RX_QUEUE_SIZE -#define GNRC_MAC_RX_QUEUE_SIZE (1 << CONFIG_GNRC_MAC_RX_QUEUE_SIZE_EXP) -#endif - /** * @brief Default buffer size to use for storing dispatching packets (as * exponent of 2^n). @@ -59,13 +57,6 @@ extern "C" { #define CONFIG_GNRC_MAC_DISPATCH_BUFFER_SIZE_EXP (3U) #endif -/** - * @brief The default buffer size for storing dispatching packets - */ -#ifndef GNRC_MAC_DISPATCH_BUFFER_SIZE -#define GNRC_MAC_DISPATCH_BUFFER_SIZE (1 << CONFIG_GNRC_MAC_DISPATCH_BUFFER_SIZE_EXP) -#endif - /** * @brief Count of neighbor nodes in one-hop distance. */ @@ -84,14 +75,6 @@ extern "C" { #define CONFIG_GNRC_MAC_TX_QUEUE_SIZE_EXP (3U) #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 (1 << CONFIG_GNRC_MAC_TX_QUEUE_SIZE_EXP) -#endif - /** * @brief Disable MAC radio duty-cycle recording and displaying. */ @@ -113,6 +96,29 @@ extern "C" { #define GNRC_MAC_ENABLE_DUTYCYCLE_RECORD (1U) #endif #endif +/** @} */ + +/** + * @brief The default rx queue size for incoming packets + */ +#ifndef GNRC_MAC_RX_QUEUE_SIZE +#define GNRC_MAC_RX_QUEUE_SIZE (1 << CONFIG_GNRC_MAC_RX_QUEUE_SIZE_EXP) +#endif + +/** + * @brief The default buffer size for storing dispatching packets + */ +#ifndef GNRC_MAC_DISPATCH_BUFFER_SIZE +#define GNRC_MAC_DISPATCH_BUFFER_SIZE (1 << CONFIG_GNRC_MAC_DISPATCH_BUFFER_SIZE_EXP) +#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 (1 << CONFIG_GNRC_MAC_TX_QUEUE_SIZE_EXP) +#endif #ifdef __cplusplus }