diff --git a/sys/Makefile.include b/sys/Makefile.include index 280e0851db..80d51b4f12 100644 --- a/sys/Makefile.include +++ b/sys/Makefile.include @@ -212,3 +212,7 @@ endif ifneq (,$(filter unicoap,$(USEMODULE))) include $(RIOTBASE)/sys/net/application_layer/unicoap/Makefile.include endif + +ifneq (,$(filter event,$(USEMODULE))) + include $(RIOTBASE)/sys/event/Makefile.include +endif diff --git a/sys/event/Makefile.include b/sys/event/Makefile.include new file mode 100644 index 0000000000..c986438e5a --- /dev/null +++ b/sys/event/Makefile.include @@ -0,0 +1,35 @@ +include $(RIOTMAKE)/utils/strings.mk + +# This applies to all thread stacks +ifneq (, $(EVENT_THREAD_STACKSIZE_MIN)) + EVENT_THREAD_STACKSIZE_MIN := $(call max_number,$(EVENT_THREAD_STACKSIZE_MIN)) +endif + +ifeq (,$(filter event_thread_highest, $(USEMODULE))) + # No highest priority event thread, so the highest prio queue is handled by + # the same thread handling the medium priority queue. So we "trickle down" + # the requirements here + EVENT_THREAD_MEDIUM_STACKSIZE_MIN += $(EVENT_THREAD_HIGHEST_STACKSIZE_MIN) +else + ifneq (, $(EVENT_THREAD_HIGHEST_STACKSIZE_MIN)) + EVENT_THREAD_HIGHEST_STACKSIZE_MIN := $(call max_number,$(EVENT_THREAD_HIGHEST_STACKSIZE_MIN) $(EVENT_THREAD_STACKSIZE_MIN)) + CFLAGS += -DEVENT_THREAD_HIGHEST_STACKSIZE=$(EVENT_THREAD_HIGHEST_STACKSIZE_MIN) + endif +endif + +ifeq (,$(filter event_thread_medium, $(USEMODULE))) + # No medium priority event thread, so the medium prio queue is handled by + # the same thread handling the lowest priority queue. So we "trickle down" + # the requirements here + EVENT_THREAD_LOWEST_STACKSIZE_MIN += $(EVENT_THREAD_MEDIUM_STACKSIZE_MIN) +else + ifneq (, $(EVENT_THREAD_MEDIUM_STACKSIZE_MIN)) + EVENT_THREAD_MEDIUM_STACKSIZE_MIN := $(call max_number,$(EVENT_THREAD_MEDIUM_STACKSIZE_MIN) $(EVENT_THREAD_STACKSIZE_MIN)) + CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE=$(EVENT_THREAD_MEDIUM_STACKSIZE_MIN) + endif +endif + +ifneq (, $(EVENT_THREAD_LOWEST_STACKSIZE_MIN)) + EVENT_THREAD_LOWEST_STACKSIZE_MIN := $(call max_number,$(EVENT_THREAD_LOWEST_STACKSIZE_MIN) $(EVENT_THREAD_STACKSIZE_MIN)) + CFLAGS += -DEVENT_THREAD_LOWEST_STACKSIZE=$(EVENT_THREAD_LOWEST_STACKSIZE_MIN) +endif diff --git a/sys/include/event/thread.h b/sys/include/event/thread.h index 1e277bee40..f76c0852aa 100644 --- a/sys/include/event/thread.h +++ b/sys/include/event/thread.h @@ -44,6 +44,32 @@ * event queue gets its own thread. So higher priority events will always * preempt events of lower priority in this case. * + * Managing Stack Size Requirements + * -------------------------------- + * + * A module using the medium priority event queue might require a certain + * minimum stack size, say 1024, to operate correctly. Instead of just adding + * `CFLAGS += -DDEVENT_THREAD_MEDIUM_STACKSIZE=1024`, it can instead add the + * following to its `Makefile.dep`: + * + * ```Makefile + * EVENT_THREAD_MEDIUM_STACKSIZE_MIN += 1024 + * ``` + * + * In the `Makefile.include` of `sys/event` the highest value of the minimum + * requirements declared by any module will be picked and added to the + * `CFLAGS`. + * + * @note `EVENT_THREAD_MEDIUM_STACKSIZE_MIN` and + * `EVENT_THREAD_HIGHEST_STACKSIZE_MIN` always apply to the thread + * managing the medium priority queue. + * @details E.g. without the module `event_thread_medium` the lowest priority + * and medium priority queues are both handled by the lowest priority + * even thread. In that case, `EVENT_THREAD_MEDIUM_STACKSIZE_MIN` would + * ensure a minimum thread statck size on the lowest priority even + * thread. With `event_thread_medium` in use, it would instead apply + * to the stack of the dedicated medium event queue thread. + * * @{ * * @file