Skip to content

Commit

Permalink
[ext] Add modm:etl module
Browse files Browse the repository at this point in the history
Co-authored-by: Niklas Hauser <[email protected]>
  • Loading branch information
rleh and salkinium committed Oct 12, 2021
1 parent f4c7492 commit 1f58472
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
[submodule "ext/lvgl/lvgl"]
path = ext/lvgl/lvgl
url = https://github.com/modm-ext/lvgl-partial.git
[submodule "ext/etlcpp/etl"]
path = ext/etlcpp/etl
url = https://github.com/modm-ext/etl-partial.git
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ git clone --recurse-submodules --jobs 8 https://github.com/modm-io/modm.git
- Integration of useful third-party software:
- [FreeRTOS][] and [FreeRTOS+TCP][].
- [CMSIS][] and [CMSIS-DSP][].
- [ETL][].
- [TinyUSB][].
- [FatFS][].
- [ROSserial][].
Expand Down Expand Up @@ -766,6 +767,7 @@ and [many more contributors][contributors].
[CMSIS]: https://www.keil.com/pack/doc/CMSIS/General/html/index.html
[CMSIS-DSP]: https://www.keil.com/pack/doc/CMSIS/DSP/html/index.html
[TinyUSB]: https://github.com/hathach/tinyusb
[ETL]: https://www.etlcpp.com
[FatFS]: http://elm-chan.org/fsw/ff/00index_e.html
[ROSserial]: https://wiki.ros.org/rosserial
[CrashCatcher]: https://github.com/adamgreen/CrashCatcher
Expand Down
68 changes: 68 additions & 0 deletions ext/etlcpp/error_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2021 Niklas Hauser
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/

#ifndef ETL_ERROR_HANDLER_EXTERNAL_INCLUDED
#define ETL_ERROR_HANDLER_EXTERNAL_INCLUDED

/* Include the original header from ETL */
#include "error_handler_internal.h"

/* Only redefine errors if necessary */
#if !defined(ETL_NO_CHECKS) && !defined(ETL_THROW_EXCEPTIONS) && !defined(ETL_LOG_ERRORS)

/* Undefine the error handlers */
#undef ETL_ASSERT
#undef ETL_ASSERT_AND_RETURN
#undef ETL_ASSERT_AND_RETURN_VALUE
#undef ETL_ALWAYS_ASSERT
#undef ETL_ALWAYS_ASSERT_AND_RETURN
#undef ETL_ALWAYS_ASSERT_AND_RETURN_VALUE
#undef ETL_ERROR

/* Define the error handlers to use modm_assert */
#include <modm/architecture/interface/assert.h>

#define ETL_ASSERT(b, e) { modm_assert((b), "etl", (e)); }
#define ETL_ASSERT_AND_RETURN(b, e) { if (not modm_assert_continue_ignore((b), "etl", (e))) return; }
#define ETL_ASSERT_AND_RETURN_VALUE(b, e, v) { if (not modm_assert_continue_ignore((b), "etl", (e))) return (v); }

#define ETL_ALWAYS_ASSERT(e) ETL_ASSERT(false, e)
#define ETL_ALWAYS_ASSERT_AND_RETURN(e) ETL_ASSERT_AND_RETURN(false, e)
#define ETL_ALWAYS_ASSERT_AND_RETURN_VALUE(e, v) ETL_ASSERT_AND_RETURN_VALUE(false, e, v)

#include <modm/architecture/utils.hpp>

#if defined(ETL_VERBOSE_ERRORS)
#define ETL_ERROR(e) (__FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" MODM_STRINGIFY(e) "\"")
#else
#define ETL_ERROR(e) (MODM_STRINGIFY(__LINE__) " -> \"" MODM_STRINGIFY(e) "\"")
#endif

#endif /* ETL_NO_CHECKS */

#endif /* ETL_ERROR_HANDLER_EXTERNAL_INCLUDED */
1 change: 1 addition & 0 deletions ext/etlcpp/etl
Submodule etl added at 7fc4a6
82 changes: 82 additions & 0 deletions ext/etlcpp/module.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021, Raphael Lehmann
# Copyright (c) 2021, 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/.
# -----------------------------------------------------------------------------

def init(module):
module.name = ":etl"
module.description = """
# Embedded Template Library (ETL)
ETL is a MIT licensed template library which augments the STL with embedded
friendly containers and algorithms.
- https://www.etlcpp.com/
- https://github.com/ETLCPP/etl
## Configuration
This module pre-configures ETL by adding these macros:
- `ETL_TARGET_OS_FREERTOS`: if built together with the `modm:freertos` module.
To add your own configuration you can [create a `<etl_profile.h>` file][config]
which will automatically be included by ETL.
## Debugging ETL
This module reroutes ETLs assertions to `modm_assert` but only for the default
configuration. Defining any of `ETL_NO_CHECKS`, `ETL_THROW_EXCEPTIONS` or
`ETL_LOG_ERRORS` will use original ETL mechanism.
Make sure you have implemented the `modm_abandon` handler! See the
`modm:architecture:assert` module for details.
An ETL assertion failure in release mode is fairly cryptic:
```
Assertion 'etl' failed!
Abandoning...
```
If you run this again in debug mode, you'll note a much more detailed assertion
description:
```
Assertion 'etl' failed!
modm/ext/etl/etl/ipool.h:369 -> "pool_no_allocation"
Abandoning...
```
[config]: https://www.etlcpp.com/setup.html
"""

def prepare(module, options):
module.depends(":architecture:assert")
return True

def build(env):
env.collect(":build:path.include", "modm/ext/etl")
env.outbasepath = "modm/ext/etl"
env.substitutions = {"with_freertos": env.has_module(":freertos")}

# Ignore the preconfigured profiles (but keep determine_ headers)
env.copy("etl/include/etl/", dest="etl/", ignore=env.ignore_paths(
"*/etl/include/etl/profiles/[a-ce-z]*", "*/doxygen.h",
"*/error_handler.h", "*/platform.h"))
# Rename the original header files
env.copy("etl/include/etl/error_handler.h", dest="etl/error_handler_internal.h")
env.copy("etl/include/etl/platform.h", dest="etl/platform_internal.h")
# So that we can replace them with ours but not need to reproduce them
env.copy("error_handler.h", dest="etl/error_handler.h")
env.template("platform.h.in", dest="etl/platform.h")
45 changes: 45 additions & 0 deletions ext/etlcpp/platform.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/******************************************************************************
The MIT License(MIT)

Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com

Copyright(c) 2021 Niklas Hauser

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/

#ifndef ETL_PLATFORM_EXTERNAL_INCLUDED
#define ETL_PLATFORM_EXTERNAL_INCLUDED

/* Map modm's debug macro to ETL's debug macro */
#ifdef MODM_DEBUG_BUILD
#define ETL_DEBUG
#define ETL_VERBOSE_ERRORS
#endif

/* Default modm settings */
%% if with_freertos
#define ETL_TARGET_OS_FREERTOS
%% endif

#include "platform_internal.h"

#endif /* ETL_PLATFORM_EXTERNAL_INCLUDED */

0 comments on commit 1f58472

Please sign in to comment.