From ecba5fa1d0c178dd4b5043cc6fc3973304ffe470 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Fri, 19 Feb 2021 11:28:01 +0100 Subject: [PATCH] gnrc_pktbuf_static: expose _align() function to be used for tests --- sys/Makefile.include | 4 ++ sys/net/gnrc/pktbuf_static/Makefile.include | 2 + .../gnrc/pktbuf_static/gnrc_pktbuf_static.c | 14 +---- .../pktbuf_static/include/pktbuf_static.h | 58 +++++++++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 sys/net/gnrc/pktbuf_static/Makefile.include create mode 100644 sys/net/gnrc/pktbuf_static/include/pktbuf_static.h diff --git a/sys/Makefile.include b/sys/Makefile.include index 875f9c6bcd..058ed847e2 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -21,6 +21,10 @@ ifneq (,$(filter gnrc_pktbuf,$(USEMODULE))) include $(RIOTBASE)/sys/net/gnrc/pktbuf/Makefile.include endif +ifneq (,$(filter gnrc_pktbuf_static,$(USEMODULE))) + include $(RIOTBASE)/sys/net/gnrc/pktbuf_static/Makefile.include +endif + ifneq (,$(filter malloc_thread_safe,$(USEMODULE))) include $(RIOTBASE)/sys/malloc_thread_safe/Makefile.include endif diff --git a/sys/net/gnrc/pktbuf_static/Makefile.include b/sys/net/gnrc/pktbuf_static/Makefile.include new file mode 100644 index 0000000000..6509bb8e78 --- /dev/null +++ b/sys/net/gnrc/pktbuf_static/Makefile.include @@ -0,0 +1,2 @@ +USEMODULE_INCLUDES_gnrc_pktbuf_static := $(LAST_MAKEFILEDIR)/include +USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_gnrc_pktbuf_static) diff --git a/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c b/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c index 3124b6d557..30fc9f2050 100644 --- a/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c +++ b/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c @@ -31,17 +31,11 @@ #include "net/gnrc/pkt.h" #include "pktbuf_internal.h" +#include "pktbuf_static.h" #define ENABLE_DEBUG 0 #include "debug.h" -#define _ALIGNMENT_MASK (sizeof(_unused_t) - 1) - -typedef struct _unused { - struct _unused *next; - unsigned int size; -} _unused_t; - /* The static buffer needs to be aligned to word size, so that its start * address can be casted to `_unused_t *` safely. Just allocating an array of * (word sized) uintptr_t is a trivial way to do this */ @@ -59,12 +53,6 @@ static gnrc_pktsnip_t *_create_snip(gnrc_pktsnip_t *next, const void *data, size gnrc_nettype_t type); static void *_pktbuf_alloc(size_t size); -/* fits size to byte alignment */ -static inline size_t _align(size_t size) -{ - return (size + _ALIGNMENT_MASK) & ~(_ALIGNMENT_MASK); -} - static inline void _set_pktsnip(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *next, void *data, size_t size, gnrc_nettype_t type) { diff --git a/sys/net/gnrc/pktbuf_static/include/pktbuf_static.h b/sys/net/gnrc/pktbuf_static/include/pktbuf_static.h new file mode 100644 index 0000000000..dce6f8736e --- /dev/null +++ b/sys/net/gnrc/pktbuf_static/include/pktbuf_static.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2014-2015 Martine S. Lenders + * Copyright (C) 2014-2021 Freie Universität 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. + */ + +/** + * @ingroup net_gnrc_pktbuf + * @brief Internal definitions of the static implementation of + * @ref net_gnrc_pktbuf + * @{ + * + * @file + * @brief Definitions of types and their alignment for usage in tests + * + * @author Martine Lenders + */ +#ifndef PKTBUF_STATIC_H +#define PKTBUF_STATIC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Mask to align packet buffer allocations with size of @ref _unused_t + */ +#define GNRC_PKTBUF_STATIC_ALIGN_MASK (sizeof(_unused_t) - 1) + +/** + * @brief Marks an unused section of the packet buffer arena array + */ +typedef struct _unused { + struct _unused *next; /**< the next unused section */ + unsigned int size; /**< the size of the unused section */ +} _unused_t; + +/** + * @brief Calculates the required space of a number of bytes including + * alignment to the size of @ref _unused_t + */ +static inline size_t _align(size_t size) +{ + return (size + GNRC_PKTBUF_STATIC_ALIGN_MASK) & + ~(GNRC_PKTBUF_STATIC_ALIGN_MASK); +} + +#ifdef __cplusplus +} +#endif + +#endif /* PKTBUF_STATIC_H */ +/** @} */