Skip to content

Commit ecf964e

Browse files
committed
[resumable] Deprecate resumable functions
1 parent de1fc6f commit ecf964e

File tree

17 files changed

+87
-61
lines changed

17 files changed

+87
-61
lines changed

src/modm/platform/spi/at90_tiny_mega/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def get_properties(env):
1515
device = env[":target"]
1616
driver = device.get_driver("spi:avr")
1717
properties = {}
18-
properties["use_fiber"] = env.query(":processing:fiber:__enabled", False)
18+
properties["use_fiber"] = env.get(":processing:use_fiber_shim", True)
1919
properties["target"] = device.identifier
2020
properties["partname"] = device.partname
2121
properties["driver"] = driver

src/modm/platform/spi/rp/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Instance(Module):
2525
def build(self, env):
2626
env.substitutions = {
2727
"id": self.instance,
28-
"use_fiber": env.query(":processing:fiber:__enabled", False)
28+
"use_fiber": env.get(":processing:use_fiber_shim", True)
2929
}
3030
env.outbasepath = "modm/src/modm/platform/spi"
3131

src/modm/platform/spi/sam/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_properties(env):
1414
device = env[":target"]
1515
driver = device.get_driver("spi")
1616
properties = {}
17-
properties["use_fiber"] = env.query(":processing:fiber:__enabled", False)
17+
properties["use_fiber"] = env.get(":processing:use_fiber_shim", True)
1818
properties["target"] = device.identifier
1919
properties["features"] = driver["feature"] if "feature" in driver else []
2020
return properties

src/modm/platform/spi/sam_x7x/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def get_properties(env):
1616
device = env[":target"]
1717
properties = {}
18-
properties["use_fiber"] = env.query(":processing:fiber:__enabled", False)
18+
properties["use_fiber"] = env.get(":processing:use_fiber_shim", True)
1919
properties["target"] = device.identifier
2020
return properties
2121

src/modm/platform/spi/stm32/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_properties(env):
1616
device = env[":target"]
1717
driver = device.get_driver("spi")
1818
properties = {}
19-
properties["use_fiber"] = env.query(":processing:fiber:__enabled", False)
19+
properties["use_fiber"] = env.get(":processing:use_fiber_shim", True)
2020
properties["target"] = device.identifier
2121
properties["features"] = driver["feature"] if "feature" in driver else []
2222
return properties

src/modm/platform/spi/stm32_uart/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_properties(env):
1717
"target": device.identifier,
1818
"driver": driver,
1919
"over8_sampling": ("feature" in driver) and ("over8" in driver["feature"]),
20-
"use_fiber": env.query(":processing:fiber:__enabled", False)
20+
"use_fiber": env.get(":processing:use_fiber_shim", True)
2121
}
2222
return properties
2323

src/modm/platform/spi/stm32h7/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_properties(env):
1616
device = env[":target"]
1717
driver = device.get_driver("spi")
1818
properties = {}
19-
properties["use_fiber"] = env.query(":processing:fiber:__enabled", False)
19+
properties["use_fiber"] = env.get(":processing:use_fiber_shim", True)
2020
properties["target"] = device.identifier
2121

2222
return properties

src/modm/processing/fiber.hpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/modm/processing/fiber.hpp.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2024, Niklas Hauser
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
12+
%% if with_functions
13+
// includes the functions related to time
14+
#include "fiber/functions.hpp"
15+
%% endif
16+
%% if with_task
17+
// pulls in the fiber and scheduler implementation
18+
#include "fiber/task.hpp"
19+
%% else
20+
// polyfill implementation of an empty yield
21+
#include "fiber/no_yield.hpp"
22+
%% endif

src/modm/processing/fiber/module.lb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@ def init(module):
1616
module.name = ":processing:fiber"
1717
module.description = FileReader("module.md")
1818

19-
def is_enabled(env):
20-
return env.get(":processing:protothread:use_fiber", False) or \
21-
not env.has_module(":processing:protothread")
22-
2319
def prepare(module, options):
24-
module.depends(":architecture:clock", ":architecture:atomic", ":architecture:assert")
25-
26-
module.add_query(
27-
EnvironmentQuery(name="__enabled", factory=is_enabled))
20+
module.depends(":architecture:clock", ":architecture:atomic",
21+
":architecture:assert", ":stdc++")
2822

2923
core = options[":target"].get_driver("core")["type"]
3024
if core.startswith("cortex-m"): module.depends(":cmsis:device")
@@ -34,7 +28,11 @@ def prepare(module, options):
3428

3529
def build(env):
3630
env.outbasepath = "modm/src/modm/processing/fiber"
37-
env.copy("../fiber.hpp")
31+
env.substitutions = {
32+
"with_functions": True,
33+
"with_task": True,
34+
}
35+
env.template("../fiber.hpp.in")
3836

3937
core = env[":target"].get_driver("core")["type"]
4038
with_fpu = env.get(":platform:cortex-m:float-abi", "soft") != "soft"

src/modm/processing/module.lb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
1212
# -----------------------------------------------------------------------------
1313

14+
import os
15+
1416
def init(module):
1517
module.name = ":processing"
1618
module.description = """\
@@ -21,18 +23,34 @@ and delegation.
2123
"""
2224

2325
def prepare(module, options):
26+
module.depends(":architecture:clock", ":architecture:atomic")
27+
module.add_option(
28+
BooleanOption(
29+
name="use_fiber_shim",
30+
default=True,
31+
description="Implement Protothreads and Resumable Functions via Fibers"))
2432
return True
2533

2634
def build(env):
2735
env.outbasepath = "modm/src/modm/processing"
2836
env.copy("task.hpp")
37+
has_protothread = env.has_module(":processing:protothread")
38+
has_resumable = env.has_module(":processing:resumable")
39+
has_timer = env.has_module(":processing:timer")
40+
has_fiber = env.has_module(":processing:fiber")
2941

30-
if not env.has_module(":processing:fiber"):
42+
if (has_protothread or has_resumable or has_timer) and not has_fiber:
3143
env.outbasepath = "modm/src/modm/processing/"
44+
env.substitutions = {
45+
"with_functions": env.has_module(":architecture:clock"),
46+
"with_task": False,
47+
}
3248
env.copy("fiber/functions.hpp")
3349
env.copy("fiber/no_yield.hpp")
34-
env.copy("fiber.hpp")
50+
env.template("fiber.hpp.in")
51+
if has_resumable:
52+
env.copy("fiber/mutex.hpp")
3553

3654
env.outbasepath = "modm/src/modm"
37-
headers = env.generated_local_files(filterfunc=lambda path: ".h" in path and not "_impl.h" in path)
55+
headers = env.generated_local_files(filterfunc=lambda path: ".hpp" in path and path.count(os.path.sep) == 1)
3856
env.template("processing.hpp.in", substitutions={"headers": sorted(headers)})

src/modm/processing/processing.hpp.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@
1818
#include "{{ header | modm.posixify }}"
1919
%% endfor
2020

21-
#include "processing/task.hpp"
22-
2321
#endif // MODM_PROCESSING_HPP

src/modm/processing/protothread/module.lb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ def init(module):
1717

1818
def prepare(module, options):
1919
module.depends(":architecture")
20-
module.add_option(
21-
BooleanOption(
20+
module.add_alias(
21+
Alias(
2222
name="use_fiber",
23-
default=False,
24-
description="Implement via Fibers",
25-
dependencies=lambda v: ":processing:fiber" if v else None))
23+
destination=":processing:use_fiber_shim",
24+
description="Moved for better dependency management"))
2625

2726
return True
2827

2928
def build(env):
3029
env.outbasepath = "modm/src/modm/processing/protothread"
31-
if env["use_fiber"]:
30+
if env[":processing:use_fiber_shim"]:
3231
env.copy("macros_fiber.hpp", "macros.hpp")
3332
env.copy("protothread_fiber.hpp", "protothread.hpp")
3433
else:

src/modm/processing/resumable/module.lb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ def prepare(module, options):
2727

2828
return True
2929

30+
def validate(env):
31+
if not env[":processing:use_fiber_shim"]:
32+
env.log.warning(descr_deprecated)
33+
3034
def build(env):
3135
env.outbasepath = "modm/src/modm/processing/resumable"
32-
if env.query(":processing:fiber:__enabled", False):
36+
if env[":processing:use_fiber_shim"]:
3337
env.copy("macros_fiber.hpp", "macros.hpp")
3438
env.copy("resumable_fiber.hpp", "resumable.hpp")
3539
else:
@@ -57,3 +61,14 @@ function polling and just continuing program execution.
5761
on function entry and not during every polling call, so the performance
5862
penalty is relatively small.
5963
"""
64+
65+
descr_deprecated = """
66+
67+
#### Resumable Functions are deprecated! ####
68+
69+
Unfortunately GCC12 is the last version that supported the way we implemented
70+
Resumables. Since GCC13 the implementation does not compile anymore and cannot
71+
be fixed without significant breaking changes.
72+
73+
Please port your code to use `modm:processing:fiber` instead.
74+
"""

src/modm/processing/resumable/module.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Resumable Functions
22

3+
!!! warning "Resumable Functions are deprecated!"
4+
Unfortunately GCC12 is the last version that supported the way we implemented
5+
Resumables. Since GCC13 the implementation does not compile anymore and cannot
6+
be fixed without significant breaking changes.
7+
Please port your code to use `modm:processing:fiber` instead.
8+
9+
310
An implementation of lightweight resumable functions which allow for nested
411
calling.
512

@@ -159,7 +166,7 @@ The given example is in `modm/examples/generic/resumable`.
159166
## Using Fibers
160167
161168
Resumable functions can be implemented using stackful fibers by setting the
162-
`modm:processing:protothreads:use_fiber` option, which replaces the
169+
`modm:processing:use_fiber_shim` option, which replaces the
163170
preprocessor macros and C++ implementations of this and the
164171
`modm:processing:protothreads` module with a fiber version.
165172

src/modm/processing/resumable/resumable_fiber.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#pragma once
1313

1414
#include "macros.hpp"
15-
#include <modm/processing/fiber.hpp>
16-
#include <modm/processing/fiber/mutex.hpp>
1715
#include <stdint.h>
1816

1917
#define MODM_RESUMABLE_IS_FIBER

src/modm/processing/timer/module.lb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def prepare(module, options):
1919
module.depends(
2020
":architecture:clock",
2121
":architecture:assert",
22+
# ":processing:fiber", managed manually in ../module.lb
2223
":math:utils")
2324
return True
2425

0 commit comments

Comments
 (0)