Skip to content

Commit

Permalink
[resumable] Deprecate resumable functions
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Nov 24, 2024
1 parent deffd07 commit 9b8c69c
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/modm/platform/spi/at90_tiny_mega/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/spi/rp/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/spi/sam/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/spi/sam_x7x/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/spi/stm32/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/spi/stm32_uart/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/spi/stm32h7/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 0 additions & 30 deletions src/modm/processing/fiber.hpp

This file was deleted.

22 changes: 22 additions & 0 deletions src/modm/processing/fiber.hpp.in
Original file line number Diff line number Diff line change
@@ -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
13 changes: 5 additions & 8 deletions src/modm/processing/fiber/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
13 changes: 11 additions & 2 deletions src/modm/processing/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/modm/processing/protothread/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
17 changes: 16 additions & 1 deletion src/modm/processing/resumable/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
"""
7 changes: 7 additions & 0 deletions src/modm/processing/resumable/module.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 0 additions & 2 deletions src/modm/processing/resumable/resumable_fiber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#pragma once

#include "macros.hpp"
#include <modm/processing/fiber.hpp>
#include <modm/processing/fiber/mutex.hpp>
#include <stdint.h>

#define MODM_RESUMABLE_IS_FIBER
Expand Down

0 comments on commit 9b8c69c

Please sign in to comment.