mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 10:12:45 +01:00
gnrc_pktbuf_static: expose _align() function to be used for tests
This commit is contained in:
parent
de67719b59
commit
ecba5fa1d0
@ -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
|
||||
|
2
sys/net/gnrc/pktbuf_static/Makefile.include
Normal file
2
sys/net/gnrc/pktbuf_static/Makefile.include
Normal file
@ -0,0 +1,2 @@
|
||||
USEMODULE_INCLUDES_gnrc_pktbuf_static := $(LAST_MAKEFILEDIR)/include
|
||||
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_gnrc_pktbuf_static)
|
@ -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)
|
||||
{
|
||||
|
58
sys/net/gnrc/pktbuf_static/include/pktbuf_static.h
Normal file
58
sys/net/gnrc/pktbuf_static/include/pktbuf_static.h
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2014-2015 Martine S. Lenders <m.lenders@fu-berlin.de>
|
||||
* 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 <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
#ifndef PKTBUF_STATIC_H
|
||||
#define PKTBUF_STATIC_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#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 */
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user