diff --git a/src/modm/platform/spi/at90_tiny_mega/module.lb b/src/modm/platform/spi/at90_tiny_mega/module.lb index 60a006e169..4e3c87d805 100644 --- a/src/modm/platform/spi/at90_tiny_mega/module.lb +++ b/src/modm/platform/spi/at90_tiny_mega/module.lb @@ -15,7 +15,7 @@ def get_properties(env): device = env[":target"] driver = device.get_driver("spi:avr") properties = {} - properties["use_fiber"] = env.query(":processing:fiber:__enabled", False) + properties["use_fiber"] = env.get(":processing:protothread:use_fiber", True) properties["target"] = device.identifier properties["partname"] = device.partname properties["driver"] = driver diff --git a/src/modm/platform/spi/rp/module.lb b/src/modm/platform/spi/rp/module.lb index 6f2d5a5e46..cff1b1e8df 100644 --- a/src/modm/platform/spi/rp/module.lb +++ b/src/modm/platform/spi/rp/module.lb @@ -25,7 +25,7 @@ class Instance(Module): def build(self, env): env.substitutions = { "id": self.instance, - "use_fiber": env.query(":processing:fiber:__enabled", False) + "use_fiber": env.get(":processing:protothread:use_fiber", True) } env.outbasepath = "modm/src/modm/platform/spi" diff --git a/src/modm/platform/spi/sam/module.lb b/src/modm/platform/spi/sam/module.lb index 4c0e7818f4..82bc97f3b6 100644 --- a/src/modm/platform/spi/sam/module.lb +++ b/src/modm/platform/spi/sam/module.lb @@ -14,7 +14,7 @@ def get_properties(env): device = env[":target"] driver = device.get_driver("spi") properties = {} - properties["use_fiber"] = env.query(":processing:fiber:__enabled", False) + properties["use_fiber"] = env.get(":processing:protothread:use_fiber", True) properties["target"] = device.identifier properties["features"] = driver["feature"] if "feature" in driver else [] return properties diff --git a/src/modm/platform/spi/sam_x7x/module.lb b/src/modm/platform/spi/sam_x7x/module.lb index 459b51e5e9..f10473fe97 100644 --- a/src/modm/platform/spi/sam_x7x/module.lb +++ b/src/modm/platform/spi/sam_x7x/module.lb @@ -15,7 +15,7 @@ def get_properties(env): device = env[":target"] properties = {} - properties["use_fiber"] = env.query(":processing:fiber:__enabled", False) + properties["use_fiber"] = env.get(":processing:protothread:use_fiber", True) properties["target"] = device.identifier return properties diff --git a/src/modm/platform/spi/stm32/module.lb b/src/modm/platform/spi/stm32/module.lb index 7d4ee68e92..a3a1278613 100644 --- a/src/modm/platform/spi/stm32/module.lb +++ b/src/modm/platform/spi/stm32/module.lb @@ -16,7 +16,7 @@ def get_properties(env): device = env[":target"] driver = device.get_driver("spi") properties = {} - properties["use_fiber"] = env.query(":processing:fiber:__enabled", False) + properties["use_fiber"] = env.get(":processing:protothread:use_fiber", True) properties["target"] = device.identifier properties["features"] = driver["feature"] if "feature" in driver else [] return properties diff --git a/src/modm/platform/spi/stm32_uart/module.lb b/src/modm/platform/spi/stm32_uart/module.lb index ee10191197..67fe3ba014 100644 --- a/src/modm/platform/spi/stm32_uart/module.lb +++ b/src/modm/platform/spi/stm32_uart/module.lb @@ -17,7 +17,7 @@ def get_properties(env): "target": device.identifier, "driver": driver, "over8_sampling": ("feature" in driver) and ("over8" in driver["feature"]), - "use_fiber": env.query(":processing:fiber:__enabled", False) + "use_fiber": env.get(":processing:protothread:use_fiber", True) } return properties diff --git a/src/modm/platform/spi/stm32h7/module.lb b/src/modm/platform/spi/stm32h7/module.lb index 6056bc2c83..5ec9b91010 100644 --- a/src/modm/platform/spi/stm32h7/module.lb +++ b/src/modm/platform/spi/stm32h7/module.lb @@ -16,7 +16,7 @@ def get_properties(env): device = env[":target"] driver = device.get_driver("spi") properties = {} - properties["use_fiber"] = env.query(":processing:fiber:__enabled", False) + properties["use_fiber"] = env.get(":processing:protothread:use_fiber", True) properties["target"] = device.identifier return properties diff --git a/src/modm/processing/fiber.hpp b/src/modm/processing/fiber.hpp deleted file mode 100644 index fe923760df..0000000000 --- a/src/modm/processing/fiber.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2024, Niklas Hauser - * - * This file is part of the modm project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ -// ---------------------------------------------------------------------------- - -/* -We use __has_include guards here to support the case when fibers are not in use -but we still need to provide the interface to the rest of the library. -Then only the functionality that is enabled is supported and the fiber yield() -function returns immediately, thus blocks in-place. -*/ - -// includes the functions related to time -#if __has_include() -# include "fiber/functions.hpp" -#endif -// polyfill implementation of an empty yield -#if __has_include("fiber/no_yield.hpp") -# include "fiber/no_yield.hpp" -#endif -// pulls in the fiber and scheduler implementation -#if __has_include("fiber/task.hpp") -# include "fiber/task.hpp" -#endif diff --git a/src/modm/processing/fiber.hpp.in b/src/modm/processing/fiber.hpp.in new file mode 100644 index 0000000000..9430e24181 --- /dev/null +++ b/src/modm/processing/fiber.hpp.in @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, Niklas Hauser + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +// ---------------------------------------------------------------------------- + +%% if with_functions +// includes the functions related to time +#include "fiber/functions.hpp" +%% endif +%% if with_task +// pulls in the fiber and scheduler implementation +#include "fiber/task.hpp" +%% else +// polyfill implementation of an empty yield +#include "fiber/no_yield.hpp" +%% endif diff --git a/src/modm/processing/fiber/module.lb b/src/modm/processing/fiber/module.lb index 22b527c5db..66315b3ea4 100644 --- a/src/modm/processing/fiber/module.lb +++ b/src/modm/processing/fiber/module.lb @@ -16,16 +16,9 @@ def init(module): module.name = ":processing:fiber" module.description = FileReader("module.md") -def is_enabled(env): - return env.get(":processing:protothread:use_fiber", False) or \ - not env.has_module(":processing:protothread") - def prepare(module, options): module.depends(":architecture:clock", ":architecture:atomic", ":architecture:assert") - module.add_query( - EnvironmentQuery(name="__enabled", factory=is_enabled)) - core = options[":target"].get_driver("core")["type"] if core.startswith("cortex-m"): module.depends(":cmsis:device") return (core.startswith("cortex-m") or core.startswith("avr") or @@ -34,7 +27,11 @@ def prepare(module, options): def build(env): env.outbasepath = "modm/src/modm/processing/fiber" - env.copy("../fiber.hpp") + env.substitutions = { + "with_functions": True, + "with_task": True, + } + env.template("../fiber.hpp.in") core = env[":target"].get_driver("core")["type"] with_fpu = env.get(":platform:cortex-m:float-abi", "soft") != "soft" diff --git a/src/modm/processing/module.lb b/src/modm/processing/module.lb index 183fa93176..0b18a8e09c 100644 --- a/src/modm/processing/module.lb +++ b/src/modm/processing/module.lb @@ -26,12 +26,21 @@ def prepare(module, options): def build(env): env.outbasepath = "modm/src/modm/processing" env.copy("task.hpp") + has_protothread = env.has_module(":processing:protothread") + has_resumable = env.has_module(":processing:resumable") + has_fiber = env.has_module(":processing:fiber") - if not env.has_module(":processing:fiber"): + if (has_protothread or has_resumable) and not has_fiber: env.outbasepath = "modm/src/modm/processing/" + env.substitutions = { + "with_functions": env.has_module(":architecture:clock"), + "with_task": False, + } env.copy("fiber/functions.hpp") env.copy("fiber/no_yield.hpp") - env.copy("fiber.hpp") + env.template("fiber.hpp.in") + if has_resumable: + env.copy("fiber/mutex.hpp") env.outbasepath = "modm/src/modm" headers = env.generated_local_files(filterfunc=lambda path: ".h" in path and not "_impl.h" in path) diff --git a/src/modm/processing/protothread/module.lb b/src/modm/processing/protothread/module.lb index 504bd7294e..c48babe663 100644 --- a/src/modm/processing/protothread/module.lb +++ b/src/modm/processing/protothread/module.lb @@ -20,7 +20,7 @@ def prepare(module, options): module.add_option( BooleanOption( name="use_fiber", - default=False, + default=True, description="Implement via Fibers", dependencies=lambda v: ":processing:fiber" if v else None)) diff --git a/src/modm/processing/resumable/module.lb b/src/modm/processing/resumable/module.lb index b68e2bee09..b260a7abbb 100644 --- a/src/modm/processing/resumable/module.lb +++ b/src/modm/processing/resumable/module.lb @@ -27,9 +27,13 @@ def prepare(module, options): return True +def validate(env): + if not env.get(":processing:protothread:use_fiber", True): + env.log.warning(descr_deprecated) + def build(env): env.outbasepath = "modm/src/modm/processing/resumable" - if env.query(":processing:fiber:__enabled", False): + if env.get(":processing:protothread:use_fiber", True): env.copy("macros_fiber.hpp", "macros.hpp") env.copy("resumable_fiber.hpp", "resumable.hpp") else: @@ -57,3 +61,14 @@ function polling and just continuing program execution. on function entry and not during every polling call, so the performance penalty is relatively small. """ + +descr_deprecated = """ + + #### Resumable Functions are deprecated! #### + +Unfortunately GCC12 is the last version that supported the way we implemented +Resumables. Since GCC13 the implementation does not compile anymore and cannot +be fixed without significant breaking changes. + +Please port your code to use `modm:processing:fiber` instead. +""" diff --git a/src/modm/processing/resumable/module.md b/src/modm/processing/resumable/module.md index f3a3cdba71..fe50fa6d16 100644 --- a/src/modm/processing/resumable/module.md +++ b/src/modm/processing/resumable/module.md @@ -1,5 +1,12 @@ # Resumable Functions +!!! warning "Resumable Functions are deprecated!" + Unfortunately GCC12 is the last version that supported the way we implemented + Resumables. Since GCC13 the implementation does not compile anymore and cannot + be fixed without significant breaking changes. + Please port your code to use `modm:processing:fiber` instead. + + An implementation of lightweight resumable functions which allow for nested calling. diff --git a/src/modm/processing/resumable/resumable_fiber.hpp b/src/modm/processing/resumable/resumable_fiber.hpp index ad900091e0..840166e626 100644 --- a/src/modm/processing/resumable/resumable_fiber.hpp +++ b/src/modm/processing/resumable/resumable_fiber.hpp @@ -12,8 +12,6 @@ #pragma once #include "macros.hpp" -#include -#include #include #define MODM_RESUMABLE_IS_FIBER