Skip to content

Commit

Permalink
[ext] Split up CMSIS-DSP into submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Jul 11, 2019
1 parent afbd533 commit 7f94500
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ext/arm/cmsis
Submodule cmsis updated from 1f1f7c to 22d8dd
2 changes: 1 addition & 1 deletion ext/arm/cmsis.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ We use only use these parts of CMSIS:
via CMSIS-DSP.

[cmsis]: https://developer.arm.com/embedded/cmsis
[overview]: https://developer.arm.com/-/media/developer/Block%20Diagrams/CMSIS%20Diagram%20v2.png
[overview]: https://developer.arm.com/-/media/Arm%20Developer%20Community/Images/Block%20Diagrams/Cortex%20Microcontroller%20Software%20Interface%20Standard%20-%20CMSIS/CMSIS%20Diagram%20v2.png
96 changes: 71 additions & 25 deletions ext/arm/dsp.lb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,72 @@
# -----------------------------------------------------------------------------

from collections import defaultdict

from pathlib import Path

class CmsisDspModule(Module):

def __init__(self, path):
self.path = str(path.name)
self.name = self.path.replace("Functions", "").replace("Common", "") \
.replace("Math", "_math").lower()

def init(self, module):
module.name = ":cmsis:dsp:{}".format(self.name)
module.description = "DSP {}".format(" ".join(s.capitalize()
for s in self.name.split("_")))

def prepare(self, module, options):
dependencies = {
"basic_math": [],
"complex_math": [":cmsis:dsp:fast_math"],
"controller": [":cmsis:dsp:tables"],
"fast_math": [":cmsis:dsp:tables"],
"filtering": [":cmsis:dsp:tables", ":cmsis:dsp:support"],
"matrix": [],
"statistics": [":cmsis:dsp:fast_math"],
"support": [],
"tables": [],
"transform": [":cmsis:dsp:tables"],
}
module.depends(*dependencies[self.name])
return True

def build(self, env):
metadata = defaultdict(list)
metadata[":build:cflags"].append("-fno-strict-aliasing")
metadata[":build:cflags"].append("-Wno-nested-externs")
metadata[":build:ccflags"].append("-Wno-sign-compare")
metadata[":build:ccflags"].append("-Wno-double-promotion")

core = env[":target"].get_driver("core")["type"]
if "f" in core:
metadata[":build:cppdefines"].append("__FPU_PRESENT=1")

if env[":cmsis:dsp:check_matrix_sizes"]:
metadata[":build:cppdefines"].append("ARM_MATH_MATRIX_CHECK")
else:
metadata[":build:cppdefines.debug"].append("ARM_MATH_MATRIX_CHECK")

if env[":cmsis:dsp:round_float_inputs"]:
metadata[":build:cppdefines"].append("ARM_MATH_ROUNDING")

if not env.get(":cmsis:dsp:unaligned_data", False):
metadata[":build:cppdefines"].append("UNALIGNED_SUPPORT_DISABLE")

env.outbasepath = "modm/ext/cmsis/dsp"
if "tables" in self.name:
env.copy("cmsis/CMSIS/DSP/Include/arm_common_tables.h", "arm_common_tables.h")
env.copy("cmsis/CMSIS/DSP/Include/arm_const_structs.h", "arm_const_structs.h")
operations = env.copy("cmsis/CMSIS/DSP/Source/{}".format(self.path), "{}".format(self.path),
ignore=env.ignore_files("arm_bitreversal2.c", "CMakeLists.txt",
"*Functions.c", "*Tables.c"))

# For all sources add these compile flags
for key, values in metadata.items():
env.collect(key, *values, operations=operations)


# =============================================================================
def init(module):
module.name = ":cmsis:dsp"
module.description = FileReader("dsp.md")
Expand All @@ -39,39 +104,20 @@ def prepare(module, options):
description=descr_round_floats,
default=True))

for path in Path(localpath("cmsis/CMSIS/DSP/Source")).iterdir():
if path.is_dir():
module.add_submodule(CmsisDspModule(path))

return True

def build(env):
metadata = defaultdict(list)
metadata[":build:cflags"].append("-fno-strict-aliasing")

core = env[":target"].get_driver("core")["type"]
if "f" in core:
metadata[":build:cppdefines"].append("__FPU_PRESENT=1")

core = core.replace("cortex-m", "CM").replace("+", "PLUS").replace("f", "").replace("d", "")
env.collect(":build:cppdefines", "ARM_MATH_{}".format(core))

if env["check_matrix_sizes"]:
metadata[":build:cppdefines"].append("ARM_MATH_MATRIX_CHECK")
else:
metadata[":build:cppdefines.debug"].append("ARM_MATH_MATRIX_CHECK")

if env["round_float_inputs"]:
metadata[":build:cppdefines"].append("ARM_MATH_ROUNDING")

if not env.get("unaligned_data", False):
metadata[":build:cppdefines"].append("UNALIGNED_SUPPORT_DISABLE")

env.collect(":build:path.include", "modm/ext/cmsis/dsp")

env.outbasepath = "modm/ext/cmsis/dsp"
env.copy("cmsis/CMSIS/DSP/Include", ".")
operations = env.copy("cmsis/CMSIS/DSP/Source", ".")

# For all sources add these compile flags
for key, values in metadata.items():
env.collect(key, *values, operations=operations)
env.copy("cmsis/CMSIS/DSP/Include/arm_math.h", "arm_math.h")


# ============================ Option Descriptions ============================
Expand Down
2 changes: 1 addition & 1 deletion repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ except Exception as e:
exit(1)

import lbuild
min_lbuild_version = "1.11.6"
min_lbuild_version = "1.12.1"
if StrictVersion(getattr(lbuild, "__version__", "0.1.0")) < StrictVersion(min_lbuild_version):
print("modm requires at least lbuild v{}, please upgrade!\n"
" pip3 install -U lbuild".format(min_lbuild_version))
Expand Down

0 comments on commit 7f94500

Please sign in to comment.