From 3db7c1150a13b81be362bc3221fad83cb5e3028b Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 22 Oct 2020 13:37:31 +0200 Subject: [PATCH 1/6] core: split out library code This commit splits core into it's scheduler/IPC part and into other code that is either used or uses the scheduler, through defined APIs. --- Makefile.include | 5 ++++- boards/native/Makefile.include | 1 + core/Makefile | 2 +- core/lib/Makefile | 12 ++++++++++++ core/{ => lib}/assert.c | 0 core/{ => lib}/atomic_c11.c | 0 core/{ => lib}/atomic_sync.c | 0 core/{ => lib}/bitarithm.c | 0 core/{ => lib}/clist.c | 0 core/{ => lib}/include/assert.h | 0 core/{ => lib}/include/bitarithm.h | 0 core/{ => lib}/include/cib.h | 0 core/{ => lib}/include/clist.h | 0 core/{ => lib}/include/debug.h | 0 core/{ => lib}/include/irq.h | 0 core/{ => lib}/include/kernel_defines.h | 0 core/{ => lib}/include/kernel_init.h | 0 core/{ => lib}/include/list.h | 0 core/{ => lib}/include/log.h | 0 core/{ => lib}/include/macros/units.h | 0 core/{ => lib}/include/macros/xtstr.h | 0 core/{ => lib}/include/panic.h | 0 core/{ => lib}/include/priority_queue.h | 0 core/{ => lib}/include/ringbuffer.h | 0 core/{ => lib}/include/rmutex.h | 0 core/{ => lib}/include/thread_config.h | 0 core/{ => lib}/include/xfa.h | 0 core/{ => lib}/init.c | 0 core/{ => lib}/panic.c | 0 core/{ => lib}/priority_queue.c | 0 core/{ => lib}/ringbuffer.c | 0 core/{ => lib}/rmutex.c | 0 makefiles/application.inc.mk | 2 +- makefiles/defaultmodules.inc.mk | 5 ++++- makefiles/pseudomodules.inc.mk | 3 +++ 35 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 core/lib/Makefile rename core/{ => lib}/assert.c (100%) rename core/{ => lib}/atomic_c11.c (100%) rename core/{ => lib}/atomic_sync.c (100%) rename core/{ => lib}/bitarithm.c (100%) rename core/{ => lib}/clist.c (100%) rename core/{ => lib}/include/assert.h (100%) rename core/{ => lib}/include/bitarithm.h (100%) rename core/{ => lib}/include/cib.h (100%) rename core/{ => lib}/include/clist.h (100%) rename core/{ => lib}/include/debug.h (100%) rename core/{ => lib}/include/irq.h (100%) rename core/{ => lib}/include/kernel_defines.h (100%) rename core/{ => lib}/include/kernel_init.h (100%) rename core/{ => lib}/include/list.h (100%) rename core/{ => lib}/include/log.h (100%) rename core/{ => lib}/include/macros/units.h (100%) rename core/{ => lib}/include/macros/xtstr.h (100%) rename core/{ => lib}/include/panic.h (100%) rename core/{ => lib}/include/priority_queue.h (100%) rename core/{ => lib}/include/ringbuffer.h (100%) rename core/{ => lib}/include/rmutex.h (100%) rename core/{ => lib}/include/thread_config.h (100%) rename core/{ => lib}/include/xfa.h (100%) rename core/{ => lib}/init.c (100%) rename core/{ => lib}/panic.c (100%) rename core/{ => lib}/priority_queue.c (100%) rename core/{ => lib}/ringbuffer.c (100%) rename core/{ => lib}/rmutex.c (100%) diff --git a/Makefile.include b/Makefile.include index 462c3ab82e..cd65dba748 100644 --- a/Makefile.include +++ b/Makefile.include @@ -407,7 +407,10 @@ ifneq (,$(IOTLAB_NODE)) endif # Add standard include directories -INCLUDES += -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/include +INCLUDES += -I$(RIOTBASE)/core/lib/include +INCLUDES += -I$(RIOTBASE)/core/include +INCLUDES += -I$(RIOTBASE)/drivers/include +INCLUDES += -I$(RIOTBASE)/sys/include # process provided features include $(RIOTBASE)/Makefile.features diff --git a/boards/native/Makefile.include b/boards/native/Makefile.include index 3ba0c19aae..118eb8a4b4 100644 --- a/boards/native/Makefile.include +++ b/boards/native/Makefile.include @@ -1,5 +1,6 @@ NATIVEINCLUDES += -DNATIVE_INCLUDES NATIVEINCLUDES += -I$(RIOTBOARD)/native/include/ +NATIVEINCLUDES += -I$(RIOTBASE)/core/lib/include/ NATIVEINCLUDES += -I$(RIOTBASE)/core/include/ NATIVEINCLUDES += -I$(RIOTBASE)/drivers/include/ diff --git a/core/Makefile b/core/Makefile index f387da65ef..50308607e3 100644 --- a/core/Makefile +++ b/core/Makefile @@ -1,5 +1,5 @@ # exclude submodule sources from *.c wildcard source selection -SRC := $(filter-out init.c mbox.c msg.c msg_bus.c panic.c thread_flags.c,$(wildcard *.c)) +SRC := $(filter-out mbox.c msg.c msg_bus.c thread_flags.c,$(wildcard *.c)) # enable submodules SUBMODULES := 1 diff --git a/core/lib/Makefile b/core/lib/Makefile new file mode 100644 index 0000000000..43b65f5209 --- /dev/null +++ b/core/lib/Makefile @@ -0,0 +1,12 @@ +MODULE = core_lib + +# enable submodules +SUBMODULES := 1 +# set this so the panic and init code is available as "core_panic" and "core_init" +# instead of "core_lib_..." +BASE_MODULE = core + +# exclude submodule sources from *.c wildcard source selection +SRC := $(filter-out panic.c init.c,$(wildcard *.c)) + +include $(RIOTBASE)/Makefile.base diff --git a/core/assert.c b/core/lib/assert.c similarity index 100% rename from core/assert.c rename to core/lib/assert.c diff --git a/core/atomic_c11.c b/core/lib/atomic_c11.c similarity index 100% rename from core/atomic_c11.c rename to core/lib/atomic_c11.c diff --git a/core/atomic_sync.c b/core/lib/atomic_sync.c similarity index 100% rename from core/atomic_sync.c rename to core/lib/atomic_sync.c diff --git a/core/bitarithm.c b/core/lib/bitarithm.c similarity index 100% rename from core/bitarithm.c rename to core/lib/bitarithm.c diff --git a/core/clist.c b/core/lib/clist.c similarity index 100% rename from core/clist.c rename to core/lib/clist.c diff --git a/core/include/assert.h b/core/lib/include/assert.h similarity index 100% rename from core/include/assert.h rename to core/lib/include/assert.h diff --git a/core/include/bitarithm.h b/core/lib/include/bitarithm.h similarity index 100% rename from core/include/bitarithm.h rename to core/lib/include/bitarithm.h diff --git a/core/include/cib.h b/core/lib/include/cib.h similarity index 100% rename from core/include/cib.h rename to core/lib/include/cib.h diff --git a/core/include/clist.h b/core/lib/include/clist.h similarity index 100% rename from core/include/clist.h rename to core/lib/include/clist.h diff --git a/core/include/debug.h b/core/lib/include/debug.h similarity index 100% rename from core/include/debug.h rename to core/lib/include/debug.h diff --git a/core/include/irq.h b/core/lib/include/irq.h similarity index 100% rename from core/include/irq.h rename to core/lib/include/irq.h diff --git a/core/include/kernel_defines.h b/core/lib/include/kernel_defines.h similarity index 100% rename from core/include/kernel_defines.h rename to core/lib/include/kernel_defines.h diff --git a/core/include/kernel_init.h b/core/lib/include/kernel_init.h similarity index 100% rename from core/include/kernel_init.h rename to core/lib/include/kernel_init.h diff --git a/core/include/list.h b/core/lib/include/list.h similarity index 100% rename from core/include/list.h rename to core/lib/include/list.h diff --git a/core/include/log.h b/core/lib/include/log.h similarity index 100% rename from core/include/log.h rename to core/lib/include/log.h diff --git a/core/include/macros/units.h b/core/lib/include/macros/units.h similarity index 100% rename from core/include/macros/units.h rename to core/lib/include/macros/units.h diff --git a/core/include/macros/xtstr.h b/core/lib/include/macros/xtstr.h similarity index 100% rename from core/include/macros/xtstr.h rename to core/lib/include/macros/xtstr.h diff --git a/core/include/panic.h b/core/lib/include/panic.h similarity index 100% rename from core/include/panic.h rename to core/lib/include/panic.h diff --git a/core/include/priority_queue.h b/core/lib/include/priority_queue.h similarity index 100% rename from core/include/priority_queue.h rename to core/lib/include/priority_queue.h diff --git a/core/include/ringbuffer.h b/core/lib/include/ringbuffer.h similarity index 100% rename from core/include/ringbuffer.h rename to core/lib/include/ringbuffer.h diff --git a/core/include/rmutex.h b/core/lib/include/rmutex.h similarity index 100% rename from core/include/rmutex.h rename to core/lib/include/rmutex.h diff --git a/core/include/thread_config.h b/core/lib/include/thread_config.h similarity index 100% rename from core/include/thread_config.h rename to core/lib/include/thread_config.h diff --git a/core/include/xfa.h b/core/lib/include/xfa.h similarity index 100% rename from core/include/xfa.h rename to core/lib/include/xfa.h diff --git a/core/init.c b/core/lib/init.c similarity index 100% rename from core/init.c rename to core/lib/init.c diff --git a/core/panic.c b/core/lib/panic.c similarity index 100% rename from core/panic.c rename to core/lib/panic.c diff --git a/core/priority_queue.c b/core/lib/priority_queue.c similarity index 100% rename from core/priority_queue.c rename to core/lib/priority_queue.c diff --git a/core/ringbuffer.c b/core/lib/ringbuffer.c similarity index 100% rename from core/ringbuffer.c rename to core/lib/ringbuffer.c diff --git a/core/rmutex.c b/core/lib/rmutex.c similarity index 100% rename from core/rmutex.c rename to core/lib/rmutex.c diff --git a/makefiles/application.inc.mk b/makefiles/application.inc.mk index 68e867f268..0460b057c1 100644 --- a/makefiles/application.inc.mk +++ b/makefiles/application.inc.mk @@ -1,7 +1,7 @@ MODULE = $(APPLICATION_MODULE) DIRS += $(RIOTCPU)/$(CPU) $(BOARDDIR) -DIRS += $(RIOTBASE)/core $(RIOTBASE)/drivers $(RIOTBASE)/sys +DIRS += $(RIOTBASE)/core $(RIOTBASE)/core/lib $(RIOTBASE)/drivers $(RIOTBASE)/sys # For regular modules, adding files to BLOBS to their Makefile is sufficient to # create the corresponding headers. diff --git a/makefiles/defaultmodules.inc.mk b/makefiles/defaultmodules.inc.mk index 74849bbbab..8e3f6b21df 100644 --- a/makefiles/defaultmodules.inc.mk +++ b/makefiles/defaultmodules.inc.mk @@ -1,4 +1,7 @@ -DEFAULT_MODULE += board board_common_init cpu core core_init core_msg core_panic sys +DEFAULT_MODULE += board board_common_init \ + cpu \ + core core_init core_lib core_msg core_panic \ + sys # Include potentially added default modules by the board -include $(BOARDDIR)/Makefile.default diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 2531e39681..94ce28ad20 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -274,6 +274,9 @@ PSEUDOMODULES += ztimer64_% ## configuration header board.h. These can be found out by running tests/ztimer_overhead PSEUDOMODULES += ztimer_auto_adjust +# core_lib is not a submodule +NO_PSEUDOMODULES += core_lib + # ztimer's main module is called "ztimer_core" NO_PSEUDOMODULES += ztimer_core NO_PSEUDOMODULES += netdev_ieee802154_submac From f94d72b7feedf5944700221eddfba016bf60a458 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Tue, 15 Feb 2022 11:23:58 +0100 Subject: [PATCH 2/6] core: add core_lib to Kconfig --- core/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/Kconfig b/core/Kconfig index d29176d257..fa4724c802 100644 --- a/core/Kconfig +++ b/core/Kconfig @@ -9,10 +9,17 @@ menuconfig MODULE_CORE bool "RIOT Core" default y depends on TEST_KCONFIG + depends on MODULE_CORE_LIB help RIOT's core module. Only change this if you know what you are doing. If unsure, say Y. +config MODULE_CORE_LIB + bool + default y + help + Select y to to include core libs + if MODULE_CORE config MODULE_CORE_IDLE_THREAD From 36eaf6f6ea3f8d7c15708d91d98add0bec7f3a26 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 10 Mar 2022 09:54:11 +0100 Subject: [PATCH 3/6] tools/zep_dispatch: fixup core -> core/lib include path --- dist/tools/zep_dispatch/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/tools/zep_dispatch/Makefile b/dist/tools/zep_dispatch/Makefile index 95f5a3fef3..b21925f403 100644 --- a/dist/tools/zep_dispatch/Makefile +++ b/dist/tools/zep_dispatch/Makefile @@ -15,7 +15,7 @@ ZEP_PORT_BASE ?= 17754 TOPOLOGY ?= network.topo GV_OUT ?= $(TOPOLOGY).gv -RIOT_INCLUDE += -I$(RIOTBASE)/core/include +RIOT_INCLUDE += -I$(RIOTBASE)/core/lib/include RIOT_INCLUDE += -I$(RIOTBASE)/cpu/native/include RIOT_INCLUDE += -I$(RIOTBASE)/drivers/include RIOT_INCLUDE += -I$(RIOTBASE)/sys/include From ca4f1ec05b5064b9fd8ee17751f93549e53d9e65 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 10 Mar 2022 10:03:14 +0100 Subject: [PATCH 4/6] core/lib: add doxygen for `BIT0` - `BIT31` --- core/lib/include/bitarithm.h | 64 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/core/lib/include/bitarithm.h b/core/lib/include/bitarithm.h index 8655b4d3d2..41e9460141 100644 --- a/core/lib/include/bitarithm.h +++ b/core/lib/include/bitarithm.h @@ -56,40 +56,40 @@ extern "C" { * @{ */ #ifndef BIT0 -#define BIT0 0x00000001 -#define BIT1 0x00000002 -#define BIT2 0x00000004 -#define BIT3 0x00000008 -#define BIT4 0x00000010 -#define BIT5 0x00000020 -#define BIT6 0x00000040 -#define BIT7 0x00000080 -#define BIT8 0x00000100 -#define BIT9 0x00000200 -#define BIT10 0x00000400 -#define BIT11 0x00000800 -#define BIT12 0x00001000 -#define BIT13 0x00002000 -#define BIT14 0x00004000 -#define BIT15 0x00008000 +#define BIT0 0x00000001 /**< Bit 0 set define */ +#define BIT1 0x00000002 /**< Bit 1 set define */ +#define BIT2 0x00000004 /**< Bit 2 set define */ +#define BIT3 0x00000008 /**< Bit 3 set define */ +#define BIT4 0x00000010 /**< Bit 4 set define */ +#define BIT5 0x00000020 /**< Bit 5 set define */ +#define BIT6 0x00000040 /**< Bit 6 set define */ +#define BIT7 0x00000080 /**< Bit 7 set define */ +#define BIT8 0x00000100 /**< Bit 8 set define */ +#define BIT9 0x00000200 /**< Bit 9 set define */ +#define BIT10 0x00000400 /**< Bit 10 set define */ +#define BIT11 0x00000800 /**< Bit 11 set define */ +#define BIT12 0x00001000 /**< Bit 12 set define */ +#define BIT13 0x00002000 /**< Bit 13 set define */ +#define BIT14 0x00004000 /**< Bit 14 set define */ +#define BIT15 0x00008000 /**< Bit 15 set define */ #endif #ifndef BIT16 -#define BIT16 0x00010000 -#define BIT17 0x00020000 -#define BIT18 0x00040000 -#define BIT19 0x00080000 -#define BIT20 0x00100000 -#define BIT21 0x00200000 -#define BIT22 0x00400000 -#define BIT23 0x00800000 -#define BIT24 0x01000000 -#define BIT25 0x02000000 -#define BIT26 0x04000000 -#define BIT27 0x08000000 -#define BIT28 0x10000000 -#define BIT29 0x20000000 -#define BIT30 0x40000000 -#define BIT31 0x80000000 +#define BIT16 0x00010000 /**< Bit 16 set define */ +#define BIT17 0x00020000 /**< Bit 17 set define */ +#define BIT18 0x00040000 /**< Bit 18 set define */ +#define BIT19 0x00080000 /**< Bit 19 set define */ +#define BIT20 0x00100000 /**< Bit 20 set define */ +#define BIT21 0x00200000 /**< Bit 21 set define */ +#define BIT22 0x00400000 /**< Bit 22 set define */ +#define BIT23 0x00800000 /**< Bit 23 set define */ +#define BIT24 0x01000000 /**< Bit 24 set define */ +#define BIT25 0x02000000 /**< Bit 25 set define */ +#define BIT26 0x04000000 /**< Bit 26 set define */ +#define BIT27 0x08000000 /**< Bit 27 set define */ +#define BIT28 0x10000000 /**< Bit 28 set define */ +#define BIT29 0x20000000 /**< Bit 29 set define */ +#define BIT30 0x40000000 /**< Bit 30 set define */ +#define BIT31 0x80000000 /**< Bit 31 set define */ #endif /** @} */ From 003d64dd6cf056a24fb92303171d1516d235810e Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 10 Mar 2022 10:08:16 +0100 Subject: [PATCH 5/6] core/lib: add doxygen for `LOG_*` macros --- core/lib/include/log.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/lib/include/log.h b/core/lib/include/log.h index d656f4ab21..a9aa1ea949 100644 --- a/core/lib/include/log.h +++ b/core/lib/include/log.h @@ -89,10 +89,10 @@ enum { * @name Logging convenience defines * @{ */ -#define LOG_ERROR(...) LOG(LOG_ERROR, __VA_ARGS__) -#define LOG_WARNING(...) LOG(LOG_WARNING, __VA_ARGS__) -#define LOG_INFO(...) LOG(LOG_INFO, __VA_ARGS__) -#define LOG_DEBUG(...) LOG(LOG_DEBUG, __VA_ARGS__) +#define LOG_ERROR(...) LOG(LOG_ERROR, __VA_ARGS__) /**< log an error */ +#define LOG_WARNING(...) LOG(LOG_WARNING, __VA_ARGS__) /**< log a warning */ +#define LOG_INFO(...) LOG(LOG_INFO, __VA_ARGS__) /**< for the curious */ +#define LOG_DEBUG(...) LOG(LOG_DEBUG, __VA_ARGS__) /**< teach some ignorance */ /** @} */ #ifdef MODULE_LOG From d248b2d78555a5420952d9c6d4acfd36adb5effc Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Thu, 10 Mar 2022 10:12:44 +0100 Subject: [PATCH 6/6] core/lib: hide `_XTSTR()` from doxygen --- core/lib/include/macros/xtstr.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/lib/include/macros/xtstr.h b/core/lib/include/macros/xtstr.h index b0ab140ad9..0f22135ea8 100644 --- a/core/lib/include/macros/xtstr.h +++ b/core/lib/include/macros/xtstr.h @@ -31,8 +31,10 @@ extern "C" { * @brief A macro to return the string respresentation of x */ #ifndef XTSTR -#define _XTSTR(x) # x -#define XTSTR(x) _XTSTR(x) +# ifndef DOXYGEN +# define _XTSTR(x) # x +# endif /* DOXYGEN */ +# define XTSTR(x) _XTSTR(x) #endif /* XTSTR */ #ifdef __cplusplus