1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #18299 from fabian18/preprocessor_successor

sys: preprocessor successor module
This commit is contained in:
benpicco 2022-10-17 22:42:27 +02:00 committed by GitHub
commit 0b2fbce906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 108 additions and 3 deletions

View File

@ -0,0 +1,4 @@
# Usage
Do `./generate_pp_successor_header.sh N`,
where `N` is the maximum number for which the successor is defined.

View File

@ -0,0 +1,36 @@
#!/bin/sh
set -e
RIOT_PP_SUCCESSOR_MAX=$1
echo "/* DO NOT edit this file, your changes will be overwritten and won't take any effect! */"
cat << EOF
#ifndef RIOT_PP_SUCCESSOR_H
#define RIOT_PP_SUCCESSOR_H
#ifdef __cplusplus
extern "C" {
#endif
#define RIOT_PP_SUCCESSOR_MAX ${RIOT_PP_SUCCESSOR_MAX}
EOF
gen_successors() {
for n in $(seq 0 "${RIOT_PP_SUCCESSOR_MAX}")
do
echo "#define RIOT_PP_SUCCESSOR_${n} $(( n + 1 ))"
done
}
gen_successors
cat << EOF
#define RIOT_PP_SUCCESSOR(n) RIOT_PP_SUCCESSOR_ ## n
#ifdef __cplusplus
}
#endif
#endif
EOF

View File

@ -2,6 +2,10 @@
# end of the dependency loop. They MAY inlcude new modules, but this modules
# MUST NOT have dependencies themselfs.
ifneq (,$(filter auto_init%,$(USEMODULE)))
USEMODULE += preprocessor preprocessor_successor
endif
ifneq (,$(filter auto_init_ztimer,$(USEMODULE)))
USEMODULE += ztimer_init
endif

View File

@ -85,6 +85,7 @@ rsource "oneway-malloc/Kconfig"
rsource "phydat/Kconfig"
rsource "pm_layered/Kconfig"
rsource "posix/Kconfig"
rsource "preprocessor/Kconfig"
rsource "progress_bar/Kconfig"
rsource "ps/Kconfig"
rsource "random/Kconfig"

View File

@ -173,6 +173,9 @@ endif
ifneq (,$(filter pthread,$(USEMODULE)))
DIRS += posix/pthread
endif
ifneq (,$(filter preprocessor_%,$(USEMODULE)))
DIRS += preprocessor
endif
ifneq (,$(filter routing,$(USEMODULE)))
DIRS += net/routing
endif

View File

@ -994,4 +994,8 @@ ifneq (,$(filter rust_riotmodules,$(USEMODULE)))
include $(RIOTBASE)/sys/rust_riotmodules/Makefile.dep
endif
ifneq (,$(filter auto_init%,$(USEMODULE)))
USEMODULE += preprocessor_successor
endif
include $(RIOTBASE)/sys/test_utils/Makefile.dep

View File

@ -56,6 +56,10 @@ ifneq (,$(filter app_metadata,$(USEMODULE)))
endif
endif
ifneq (,$(filter auto_init,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/auto_init/include
endif
ifneq (,$(filter cpp11-compat,$(USEMODULE)))
USEMODULE_INCLUDES += $(RIOTBASE)/sys/cpp11-compat/include
endif
@ -181,3 +185,7 @@ endif
ifneq (,$(filter tiny_strerror,$(USEMODULE)))
include $(RIOTBASE)/sys/tiny_strerror/Makefile.include
endif
ifneq (,$(filter preprocessor_%,$(USEMODULE)))
include $(RIOTBASE)/sys/preprocessor/Makefile.include
endif

View File

@ -9,6 +9,7 @@ menuconfig MODULE_AUTO_INIT
bool "Auto-initialization system"
default y
depends on TEST_KCONFIG
select MODULE_PREPROCESSOR_SUCCESSOR
help
Auto-initialization module. Can be used to initialize modules (such as
drivers, or network interfaces) on start-up automatically. Disable if a

View File

@ -30,6 +30,4 @@ ifneq (,$(filter auto_init_screen,$(USEMODULE)))
DIRS += screen
endif
INCLUDES += -I$(RIOTBASE)/sys/auto_init/include
include $(RIOTBASE)/Makefile.base

View File

@ -31,6 +31,9 @@
#include "xfa.h"
#include "macros/xtstr.h"
#include "kernel_defines.h"
#if IS_USED(MODULE_PREPROCESSOR_SUCCESSOR)
#include "preprocessor_successor.h"
#endif
#ifdef __cplusplus
extern "C" {
@ -84,6 +87,12 @@ typedef struct {
= { .init = (auto_init_fn_t)function }
#endif
/**
* @brief Construct a priority value equal to @p priority + 1,
* to be used with @ref AUTO_INIT
*/
#define AUTO_INIT_PRIORITY_AFTER(priority) RIOT_PP_SUCCESSOR(priority)
#ifdef __cplusplus
}
#endif

15
sys/preprocessor/Kconfig Normal file
View File

@ -0,0 +1,15 @@
# Copyright (c) 2022 Otto-von-Guericke-Universität Magdeburg
#
# 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.
#
config MODULE_PREPROCESSOR
bool "Preprocessor utilities"
depends on TEST_KCONFIG
config MODULE_PREPROCESSOR_SUCCESSOR
bool "Generate preprocessor_successor.h to do preprocessor based successor arithmetic"
depends on TEST_KCONFIG
select MODULE_PREPROCESSOR

View File

@ -0,0 +1,3 @@
MODULE := preprocessor
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,18 @@
RIOT_PP_SUCCESSOR_MAX ?= 9999
PSEUDOMODULES += preprocessor_successor
USEMODULE_INCLUDES_preprocessor := $(BINDIR)/preprocessor
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_preprocessor)
RIOT_GENERATE_PP_HEADERS :=
ifneq (,$(filter preprocessor_successor,$(USEMODULE)))
RIOT_GENERATE_PP_HEADERS += $(BINDIR)/preprocessor/preprocessor_successor.h
endif
BUILDDEPS += $(RIOT_GENERATE_PP_HEADERS)
$(BINDIR)/preprocessor/preprocessor_successor.h:
@mkdir -p '$(dir $@)'
$(Q)'$(RIOTTOOLS)/generate_pp_successor_header/generate_pp_successor_header.sh' $(RIOT_PP_SUCCESSOR_MAX) > $@

View File

@ -20,9 +20,10 @@
*/
#include "external_module.h"
#include "auto_init_priorities.h"
#include "auto_init_utils.h"
#define PRIO 1111
#define PRIO AUTO_INIT_PRIORITY_AFTER(AUTO_INIT_PRIO_MOD_RANDOM)
AUTO_INIT(auto_init_external_module, PRIO);