diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6f66c92a..bbc35ca7 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -13,7 +13,7 @@ We therefore release foxBMS with permissive licenses: **Creative Commons Attribution 4.0 International License (SPDX short identifier: CC-BY-4.0)** - Software: **BSD 3-Clause License (SPDX short identifier: BSD-3-Clause)** -For details see the [LICENSE](../LICENSE) file and the +For details see the [LICENSE.md](../LICENSE.md) file and the [license documentation](https://iisb-foxbms.iisb.fraunhofer.de/foxbms/gen2/docs/html/latest/general/licenses.html). However foxBMS is not openly developed on GitHub (or any other platform). The diff --git a/.gitignore b/.gitignore index 832eea9a..98c98fae 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,6 @@ tools/waf-sig* *.bz2 *.gz *.zip -# do not ignore zip in hardware -!/hardware/*.zip *.7z __pycache__ diff --git a/conf/env/paths_win32.txt b/conf/env/paths_win32.txt index e94eccab..9e2c6caf 100644 --- a/conf/env/paths_win32.txt +++ b/conf/env/paths_win32.txt @@ -8,4 +8,4 @@ C:\Program Files\Cppcheck\Cppcheck-2.2-x64 C:\Program Files\LLVM\11.0.1\bin C:\Ruby\Ruby272-x64\bin C:\MinGW64\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\mingw64\bin -C:\Bauhaus\7.2.0\bin +C:\Bauhaus\7.2.3\bin diff --git a/conf/fmt/pyproject.toml b/conf/fmt/pyproject.toml index 69b3292c..b554b7f8 100644 --- a/conf/fmt/pyproject.toml +++ b/conf/fmt/pyproject.toml @@ -21,7 +21,6 @@ exclude = ''' | tools/waf3-2.0.22-1241519b19b496207abef1f72bbf61c2 )/ | docs/conf.py - | tests/axivion | tools/vendor | tools/waf-tools/why.py ) diff --git a/conf/guidelines/rules.json b/conf/guidelines/rules.json index 2d48e6bd..38f2e9c9 100644 --- a/conf/guidelines/rules.json +++ b/conf/guidelines/rules.json @@ -18,6 +18,7 @@ ".vscode/**", ".mypy_cache/**", "build/**", + "libbuild/**", "build-tools-tests/**", "conf/hcg/include/*", "conf/hcg/source/*", @@ -45,7 +46,6 @@ "tools/vendor/**", "tools/waf", "tools/waf-verify-sig.py", - "tests/axivion/**", "tests/scripts/waf-tools/f_guidelines/tests/**", "tests/scripts/waf-core/general/**", "tests/scripts/waf-core/init/**", @@ -70,7 +70,8 @@ "conf/hcg/**/*.c", "conf/hcg/**/*.h", "src/app/driver/mic/nxp/common/MC33775A.h", - "src/os/freertos/README.ti-halcogen.md" + "src/os/freertos/README.ti-halcogen.md", + "tests/axivion/cafeCC.config" ] }, "unique_filenames": { diff --git a/conf/spa/.pylintrc b/conf/spa/.pylintrc index 56ad6a2f..0b7bbbb0 100644 --- a/conf/spa/.pylintrc +++ b/conf/spa/.pylintrc @@ -250,6 +250,7 @@ good-names=p, i, j, k, + m, ex, Run, f, diff --git a/docs/conf.py b/docs/conf.py index cd45c823..7e041eab 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -129,6 +129,10 @@ "https://gitlab.com/ita1024/waf/-/blob/3536dfecf8061c6d99bac338837997c4862ee89b/waflib/TaskGen.py#L495-527", "https://gitlab.com/ita1024/waf/-/blob/3f8bb163290eb8fbfc3b26d61dd04aa5a6a29d4a/waf-light#L6-30", "https://www.misra.org.uk/", + "../_images/battery-system-setup.png", + "../_images/battery-system-setup-pack.png", + "../_images/battery-system-setup-bjb.png", + "../_images/battery-system-setup-single-string.png", ] html_theme_options = { diff --git a/docs/developer-manual/software/software-tools.rst b/docs/developer-manual/software/software-tools.rst index e404dd44..a27edae5 100644 --- a/docs/developer-manual/software/software-tools.rst +++ b/docs/developer-manual/software/software-tools.rst @@ -57,9 +57,12 @@ The following tools are shown in :numref:`mapping-of-third-party-tools`. | waf | build automation system | T3 | controls build process; generates | | | | | version dependent code | +-----------------+-------------------------+-------------+----------------------------------------+ - | Cppcheck | static program | T1 | just a helper for the static analysis; | + | Axivion Suite | static program | T2 | | | | analysis tools | | | +-----------------+-------------------------+-------------+----------------------------------------+ + | Cppcheck | static program | T1 | just a helper for the static analysis; | + | | analysis tools | | Axivion is used as the main tool | + +-----------------+-------------------------+-------------+----------------------------------------+ | sphinx | documentation tools | T1 | just a rendering tool for | | | | | the documentation text files | +-----------------+-------------------------+-------------+----------------------------------------+ diff --git a/docs/developer-manual/software/software-verification.rst b/docs/developer-manual/software/software-verification.rst index 7e5f144d..d07af16d 100644 --- a/docs/developer-manual/software/software-verification.rst +++ b/docs/developer-manual/software/software-verification.rst @@ -21,4 +21,8 @@ Software Analysis ----------------- The source code is subject to a static program analysis. These tests are -performed by Cppcheck (see :numref:`CPPCHECK`). +performed by Axivion Suite and Cppcheck (see :numref:`AXIVION_BAUHAUS_SUITE` +and :numref:`CPPCHECK`). + +The architecture is verified by the Axivion Suite (see +:numref:`AXIVION_BAUHAUS_SUITE`) diff --git a/docs/developer-manual/style-guide/examples/c-011.c b/docs/developer-manual/style-guide/examples/c-011.c index cae77f43..7ee1c482 100644 --- a/docs/developer-manual/style-guide/examples/c-011.c +++ b/docs/developer-manual/style-guide/examples/c-011.c @@ -46,9 +46,9 @@ * @details Detailed description of this function * @return some uint8_t which describes xyz */ -static uint8_t ABC_Another_Function(void); +static uint8_t ABC_AnotherFunction(void); -static uint8_t ABC_Another_Function(void) { +static uint8_t ABC_AnotherFunction(void) { /* code */ return 0; } diff --git a/docs/developer-manual/style-guide/examples/c-019.c b/docs/developer-manual/style-guide/examples/c-019.c index b6b82ba9..559a6f06 100644 --- a/docs/developer-manual/style-guide/examples/c-019.c +++ b/docs/developer-manual/style-guide/examples/c-019.c @@ -51,7 +51,7 @@ typedef struct POINT { typedef struct PATH { POINT_s point; uint32_t timestamp; - uint32_t prevTimestamp; + uint32_t previousTimestamp; uint8_t name[16]; } PATH_s; @@ -63,7 +63,7 @@ uint64_t myVar3 = 10uLL; int8_t myVar4 = -10; int16_t myVar5 = -10; int32_t myVar6 = -10; -int32_t myVar7 = -10LL; +int64_t myVar7 = -10LL; /* Initialization example for arrays */ uint8_t myArrayA[] = {1, 2, 3}; /* Array has type uint8_t[3] and holds 1,2,3 */ diff --git a/docs/developer-manual/style-guide/guidelines_c.rst b/docs/developer-manual/style-guide/guidelines_c.rst index 421e3730..4b17de12 100644 --- a/docs/developer-manual/style-guide/guidelines_c.rst +++ b/docs/developer-manual/style-guide/guidelines_c.rst @@ -27,8 +27,8 @@ installed (see :ref:`software_prerequisites`) using :kbd:`Ctrl-S`. .. warning:: The style of third party sources (generated HAL sources in - ``build/bin/src/hal/**`` and ``src/os``) should not be changed. To save - without reformatting use :kbd:`Ctrl-K + Ctrl-Shift-S`. + ``build/bin/src/hal/**`` and ``src/os``) should not be changed. + To save without reformatting use :kbd:`Ctrl-K + Ctrl-Shift-S`. The following list shows more detailed rules for |foxbms|. Every rule has some context and/or rationale and notes that clearly state the rules, followed by a diff --git a/docs/general/changelog.rst b/docs/general/changelog.rst index 13327b96..afe0732a 100644 --- a/docs/general/changelog.rst +++ b/docs/general/changelog.rst @@ -33,6 +33,61 @@ Versioning follows then these rules: - increasing ``MINOR`` adds functionality in a backwards compatible manner - increasing ``PATCH`` fixes bugs in a backwards compatible manner +******************** +[1.1.2] - 2021-09-03 +******************** + +Added +===== + +- A basic block diagram and description of a battery system and the voltages + and the currents that need to be measured have been included in the + documentation. +- Add helper script to run the library test build + (``tests/variants/lib-build/lib-build.bat``). +- Updated the Axivion configuration to use version 7.2.3. +- Added minimal documentation for Axivion setup. +- Improved the Axivion configuration: + + * use ``FAS_ASSERT`` as assert macro in order to be compliant with the style + guide + * fix some includes (library-inclusions and unnecessary inclusions) + * adds the Axivion example for race condition analysis and a minimal + configuration of entry points + * updates .axivion.preinc with missing symbols + * makes cafeCC point to the right compiler library + * excludes vendored code from analysis + * disables all naming conventions (as they are currently not configured and + thus horribly noisy) + * disables the NoImplicitTypeConversion check as it is very noisy and better + done with appropriate MISRA rules + * detect unsafe variable access by defining task priorities + * make Axivion less noisy, by disabling unused style-checks. + * Made rules for loop-counter variables more strict. + * enabling more detailed computation of findings (Abstract Interpretation in + Static Semantic Analysis). + +Changed +======= + +- Improved the code quality of the module ``foxmath`` so that it is + MISRA-compliant (:numref:`FOXMATH`). +- Refactored ``cc-options`` parsing to separate tool to simplify the TI ARM CGT + compiler tool. + +Deprecated +========== + +Removed +======= + +Fixed +===== + +- When HALCoGen was not available, the waf tool nevertheless tried to set the + respective include path, which lead to exception in Python. This has been + fixed by not trying to set the include path when HALCoGen is not available. + ******************** [1.1.1] - 2021-08-06 ******************** @@ -528,6 +583,7 @@ Removed - Removed the deprecated Anaconda extension from the list of recommended Visual Studio Code plugins that is shipped with the project. +- Suppressed the (uncovered) ADI-driver from the unit-test-report. Fixed ===== diff --git a/docs/general/releases.csv b/docs/general/releases.csv index a0ee1f99..1650fb68 100644 --- a/docs/general/releases.csv +++ b/docs/general/releases.csv @@ -1,4 +1,5 @@ foxBMS 2; Release Date; Permanent link to documentation +v1.1.2; 2021-09-03; https://iisb-foxbms.iisb.fraunhofer.de/foxbms/gen2/docs/html/v1.1.2/ v1.1.1; 2021-08-06; https://iisb-foxbms.iisb.fraunhofer.de/foxbms/gen2/docs/html/v1.1.1/ v1.1.0; 2021-07-29; https://iisb-foxbms.iisb.fraunhofer.de/foxbms/gen2/docs/html/v1.1.0/ v1.0.2; 2021-04-30; https://iisb-foxbms.iisb.fraunhofer.de/foxbms/gen2/docs/html/v1.0.2/ diff --git a/docs/getting-started/repository-structure.rst b/docs/getting-started/repository-structure.rst index 6b443f1d..3f137f98 100644 --- a/docs/getting-started/repository-structure.rst +++ b/docs/getting-started/repository-structure.rst @@ -131,6 +131,12 @@ The ``tests`` directory is structured into the following parts (see +--------------------+--------------------------+--------------------------------------+ | directory | long name | content description | +====================+==========================+======================================+ + | ``tests/axivion`` | Axivion | configuration files to describe the | + | | | architecture of |foxbms|. Additional | + | | | static program analysis | + | | | configurations are stored here | + | | | (e.g., MISRA-C) | + +--------------------+--------------------------+--------------------------------------+ | ``tests/scripts`` | scripts | unit test of scripts (e.g., Python, | | | | shell) | +--------------------+--------------------------+--------------------------------------+ diff --git a/docs/getting-started/software-installation.rst b/docs/getting-started/software-installation.rst index 52a5d9e9..6bb921ea 100644 --- a/docs/getting-started/software-installation.rst +++ b/docs/getting-started/software-installation.rst @@ -70,9 +70,9 @@ later steps of this manual. :caption: Downloading a release :name: download-foxbms-2 - C:\Users\vulpes\Documents>curl -Ss -L -o foxbms-2-v1.1.1.zip https://github.com/foxBMS/foxbms-2/archive/v1.1.1.zip - C:\Users\vulpes\Documents>tar -x -f foxbms-2-v1.1.1.zip - C:\Users\vulpes\Documents>ren foxbms-2-1.1.1 foxbms-2 + C:\Users\vulpes\Documents>curl -Ss -L -o foxbms-2-v1.1.2.zip https://github.com/foxBMS/foxbms-2/archive/v1.1.2.zip + C:\Users\vulpes\Documents>tar -x -f foxbms-2-v1.1.2.zip + C:\Users\vulpes\Documents>ren foxbms-2-1.1.2 foxbms-2 C:\Users\vulpes\Documents>cd foxbms-2 .. note:: diff --git a/docs/index.rst b/docs/index.rst index 069c8afd..3c64598d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,6 +36,7 @@ The documentation is divided in the following parts: #. :ref:`GETTING_STARTED_OVERVIEW` #. :ref:`SOFTWARE_DOCUMENTATION_OVERVIEW` #. :ref:`HARDWARE_DOCUMENTATION_OVERVIEW` +#. :ref:`SYSTEM_DOCUMENTATION_OVERVIEW` #. :ref:`TOOLS_DOCUMENTATION_OVERVIEW` #. :ref:`DEVELOPER_MANUAL` @@ -70,6 +71,9 @@ in the |doxygen| documentation. Next, the :ref:`HARDWARE_DOCUMENTATION_OVERVIEW` gives the details needed to understand the hardware platform developed for |foxbms|. +The :ref:`SYSTEM_DOCUMENTATION_OVERVIEW` provides information on the +integration of |foxbms| in an application. + Numerous tools have been developed or adapted to support developing with the |foxbms| platform. These tools and their usage are described in :ref:`TOOLS_DOCUMENTATION_OVERVIEW`. @@ -152,6 +156,17 @@ All sections are listed here: ./hardware/design-resources.rst ./hardware/connectors.rst +.. _SYSTEM_DOCUMENTATION_OVERVIEW: + +.. toctree:: + :titlesonly: + :numbered: + :maxdepth: 1 + :caption: System Documentation + + ./system/system-introduction.rst + ./system/system-voltage-and-current-monitoring.rst + .. _TOOLS_DOCUMENTATION_OVERVIEW: .. toctree:: @@ -165,6 +180,7 @@ All sections are listed here: ./tools/waf-tools/waf-tools.rst ./tools/debugger/debug-application.rst ./tools/halcogen/halcogen.rst + ./tools/static-analysis/axivion.rst ./tools/static-analysis/cppcheck.rst .. _DEVELOPER_MANUAL: diff --git a/docs/macros.txt b/docs/macros.txt index d0f8fa7d..6cad2608 100644 --- a/docs/macros.txt +++ b/docs/macros.txt @@ -3,7 +3,7 @@ .. |timestamp| date:: %Y-%m-%d %H:%M:%S .. |foxbms| replace:: foxBMS 2 -.. |version_foxbms| replace:: ``1.1.1`` +.. |version_foxbms| replace:: ``1.1.2`` .. |github_foxbms| replace:: https://github.com/foxBMS/ .. |foxbms_repository| replace:: https://github.com/foxBMS/foxbms-2 .. _Fraunhofer IISB: https://www.iisb.fraunhofer.de diff --git a/docs/software/overview/sw-overview.rst b/docs/software/overview/sw-overview.rst index bd901235..4c94fbb4 100644 --- a/docs/software/overview/sw-overview.rst +++ b/docs/software/overview/sw-overview.rst @@ -14,35 +14,37 @@ Startup ******* The startup code begins in the function ``_c_int00()`` in -``app/main/fstartup.c``. After initialization of the main -microcontroller registers, memory, system clock and interrupts, -the C function ``main()`` is called. +``app/main/fstartup.c``. +After initialization of the main microcontroller registers, memory, system +clock and interrupts, the C function ``main()`` is called. In ``general/main.c``, interrupts are enabled and the initializations of the microcontroller unit, peripherals and software modules are done (e.g., -hardware modules like SPI and DMA). The OS is than started.The steps are -indicated by the global variable -``os_boot``. At the end of the main function, the operating system resources -(tasks, events, queues, mutex) are configured in -``OS_InitializeOperatingSystem()`` (``os/os.c``) and the scheduler is started. +hardware modules like SPI and DMA). +The OS is then started. +The steps are indicated by the global variable ``os_boot``. +At the end of the main function, the operating system resources (tasks, queues) +are configured in ``OS_InitializeOperatingSystem()`` (``src/app/task/os/os.c``) +and the scheduler is started. All configured tasks (FreeRTOS threads) are then started depending on -their priority. The successful activation of the tasks is indicated by +their priority. +The successful activation of the tasks is indicated by ``os_boot = OS_RUNNING``. -The OS-scheduler first calls the highest priority task. All other cyclic tasks -are blocked in a while-loop until the initialization of this -task finishes. At the beginning of the task, -``FTSK_InitializeUserCodeEngine()`` is called. -In this function, the database is initialized. Once finished, this is indicated -by ``os_boot = OS_ENGINE_RUNNING``. +The OS-scheduler first calls the highest priority task. +All other cyclic tasks are blocked in a while-loop until the initialization of +this task finishes. +At the beginning of the task, ``FTSK_InitializeUserCodeEngine()`` is called. +In this function, the database is initialized. +Once finished, this is indicated by ``os_boot = OS_ENGINE_RUNNING``. The function ``FTSK_RunUserCodeEngine()`` is then called, where the diagnostic module and the database are managed. -Once ``os_boot = OS_ENGINE_RUNNING``, the 1ms cyclic task is unblocked. The -function ``FTSK_InitializeUserCodePreCyclicTasks()`` is called once first. +Once ``os_boot = OS_ENGINE_RUNNING``, the 1ms cyclic task is unblocked. +The function ``FTSK_InitializeUserCodePreCyclicTasks()`` is called once first. This function is called when the OS and the database are running but before -the cyclic tasks run. Once ``FTSK_InitializeUserCodePreCyclicTasks()`` has -finished, all cyclic tasks are unblocked from there while-loop and run -periodically. +the cyclic tasks run. +Once ``FTSK_InitializeUserCodePreCyclicTasks()`` has finished, all cyclic tasks +are unblocked from there while-loop and run periodically. **************** Operating System diff --git a/docs/system/bjb-measurements.csv b/docs/system/bjb-measurements.csv new file mode 100644 index 00000000..3c2655b4 --- /dev/null +++ b/docs/system/bjb-measurements.csv @@ -0,0 +1,6 @@ +Symbol ; Description +V\ :sub:`P` ; Pack voltage +V\ :sub:`FP` ; Pack voltage after main fuse +V\ :sub:`SV` ; System voltage +V\ :sub:`SV2` ; System voltage: second power path +I\ :sub:`P` ; Pack current diff --git a/docs/system/img/battery-system-setup-bjb.png b/docs/system/img/battery-system-setup-bjb.png new file mode 100644 index 00000000..ac24838f Binary files /dev/null and b/docs/system/img/battery-system-setup-bjb.png differ diff --git a/docs/system/img/battery-system-setup-pack.png b/docs/system/img/battery-system-setup-pack.png new file mode 100644 index 00000000..b2038c16 Binary files /dev/null and b/docs/system/img/battery-system-setup-pack.png differ diff --git a/docs/system/img/battery-system-setup-single-string.png b/docs/system/img/battery-system-setup-single-string.png new file mode 100644 index 00000000..149dad74 Binary files /dev/null and b/docs/system/img/battery-system-setup-single-string.png differ diff --git a/docs/system/img/battery-system-setup.png b/docs/system/img/battery-system-setup.png new file mode 100644 index 00000000..999f5dbf Binary files /dev/null and b/docs/system/img/battery-system-setup.png differ diff --git a/docs/system/img/battery-system-setup.vsdx b/docs/system/img/battery-system-setup.vsdx new file mode 100644 index 00000000..dbb7b962 Binary files /dev/null and b/docs/system/img/battery-system-setup.vsdx differ diff --git a/docs/system/img/blue.png b/docs/system/img/blue.png new file mode 100644 index 00000000..5c97c52e Binary files /dev/null and b/docs/system/img/blue.png differ diff --git a/docs/system/img/contactor.png b/docs/system/img/contactor.png new file mode 100644 index 00000000..476d566c Binary files /dev/null and b/docs/system/img/contactor.png differ diff --git a/docs/system/img/current-sensor.png b/docs/system/img/current-sensor.png new file mode 100644 index 00000000..11e822f9 Binary files /dev/null and b/docs/system/img/current-sensor.png differ diff --git a/docs/system/img/dark-blue.png b/docs/system/img/dark-blue.png new file mode 100644 index 00000000..0d3ae2dc Binary files /dev/null and b/docs/system/img/dark-blue.png differ diff --git a/docs/system/img/dark-yellow.png b/docs/system/img/dark-yellow.png new file mode 100644 index 00000000..54de4af1 Binary files /dev/null and b/docs/system/img/dark-yellow.png differ diff --git a/docs/system/img/dotted-red.png b/docs/system/img/dotted-red.png new file mode 100644 index 00000000..b287b168 Binary files /dev/null and b/docs/system/img/dotted-red.png differ diff --git a/docs/system/img/fuse.png b/docs/system/img/fuse.png new file mode 100644 index 00000000..b7198d51 Binary files /dev/null and b/docs/system/img/fuse.png differ diff --git a/docs/system/img/imd.png b/docs/system/img/imd.png new file mode 100644 index 00000000..adbdbb8b Binary files /dev/null and b/docs/system/img/imd.png differ diff --git a/docs/system/img/inverter.png b/docs/system/img/inverter.png new file mode 100644 index 00000000..905bff66 Binary files /dev/null and b/docs/system/img/inverter.png differ diff --git a/docs/system/img/msd.png b/docs/system/img/msd.png new file mode 100644 index 00000000..5d645585 Binary files /dev/null and b/docs/system/img/msd.png differ diff --git a/docs/system/img/purple.png b/docs/system/img/purple.png new file mode 100644 index 00000000..ffe93b12 Binary files /dev/null and b/docs/system/img/purple.png differ diff --git a/docs/system/img/red.png b/docs/system/img/red.png new file mode 100644 index 00000000..01fa9d6e Binary files /dev/null and b/docs/system/img/red.png differ diff --git a/docs/system/img/resistor.png b/docs/system/img/resistor.png new file mode 100644 index 00000000..b6a43dc1 Binary files /dev/null and b/docs/system/img/resistor.png differ diff --git a/docs/system/system-introduction.rst b/docs/system/system-introduction.rst new file mode 100644 index 00000000..6c3abaac --- /dev/null +++ b/docs/system/system-introduction.rst @@ -0,0 +1,7 @@ +.. include:: ./../macros.txt +.. include:: ./../units.txt + +.. _SYSTEM_INTRODUCTION: + +System Introduction +=================== diff --git a/docs/system/system-voltage-and-current-monitoring.rst b/docs/system/system-voltage-and-current-monitoring.rst new file mode 100644 index 00000000..c6be30c6 --- /dev/null +++ b/docs/system/system-voltage-and-current-monitoring.rst @@ -0,0 +1,198 @@ +.. include:: ./../macros.txt +.. include:: ./../units.txt + +.. _SYSTEM_VOLTAGE_AND_CURRENT_MONITORING: + +##################################### +System Voltage And Current Monitoring +##################################### + +Several different voltages inside a battery system need to be measured. +The exact number of voltages is dependent on the system topology and the +configuration of the battery system. + +:numref:`start-high-level` shows the voltages that need to measured in a +multi-string system, here for example for a 3-string system. +The symbols are explained in :numref:`symbols-in-system-block-diagram`. +The colors are explained in :numref:`colors-in-system-block-diagram`. + +The left side of the image shows the *Battery Pack*. +The *Battery Junction Box* is depicted in the center of the figure with an +indicated connected application shown on the right side the of the picture. + +.. figure:: img/battery-system-setup.png + :alt: Voltages to be measured in a multi-string system + :name: voltages-in-multi-string-system + :align: center + :target: ../_images/battery-system-setup.png + + Voltages of interest in a multi-string system (click to enlarge) + + +.. |contactor| image:: img/contactor.png +.. |current-sensor| image:: img/current-sensor.png +.. |fuse| image:: img/fuse.png +.. |imd| image:: img/imd.png +.. |inverter| image:: img/inverter.png +.. |msd| image:: img/msd.png +.. |resistor| image:: img/resistor.png + + +.. table:: Symbol description + :name: symbols-in-system-block-diagram + :widths: grid + + +-------------------+-------------------------------+ + | Symbol | Meaning | + +===================+===============================+ + | |contactor| | Contactor | + +-------------------+-------------------------------+ + | |current-sensor| | Current sensor | + +-------------------+-------------------------------+ + | |fuse| | Fuse | + +-------------------+-------------------------------+ + | |imd| | Insulation Measurement Device | + +-------------------+-------------------------------+ + | |inverter| | Inverter | + +-------------------+-------------------------------+ + | |msd| | Manual Service Disconnect | + +-------------------+-------------------------------+ + | |resistor| | Resistor | + +-------------------+-------------------------------+ + + +.. |red| image:: img/red.png +.. |dotted-red| image:: img/dotted-red.png +.. |purple| image:: img/purple.png +.. |dark-yellow| image:: img/dark-yellow.png +.. |dark-blue| image:: img/dark-blue.png +.. |blue| image:: img/blue.png + +.. table:: Color description + :name: colors-in-system-block-diagram + :widths: grid + + +-------------------+-----------------------------------+ + | Symbol | Meaning | + +===================+===================================+ + | |red| | Power path | + +-------------------+-----------------------------------+ + | |dotted-red| | Second power path (optional) | + +-------------------+-----------------------------------+ + | |purple| | CAN | + +-------------------+-----------------------------------+ + | |dark-yellow| | Contactor control and feedback | + +-------------------+-----------------------------------+ + | |dark-blue| | Insulation measurement line | + +-------------------+-----------------------------------+ + | |blue| | Daisy-chain | + +-------------------+-----------------------------------+ + +******************* +Multi-String System +******************* + +The following section describes important parameters within a multi-string +battery pack. + +Measurements Inside the Battery Pack +==================================== + +.. figure:: img/battery-system-setup-pack.png + :alt: Voltages to be measured in a multi-string system in the pack + :name: voltages-in-multi-string-system-in-pack + :align: center + :target: ../_images/battery-system-setup-pack.png + + Voltages to be measured in a multi-string system inside the battery pack + (click to enlarge) + +The strings are depicted in ascending order from right to left starting with +string 1 (``S1``) until left-most string m (``Sm``). +Each string consists of ``n`` modules, where every module has its own |slave|. +Each string features a current sensor, a string fuse and one or two string +contactors. +Thus, the following voltages need to be measured in each string: + +- *String voltage*, short V\ :sub:`Sm`, where ``m`` indicates the number of + the string. +- *Fused string voltage*, short V\ :sub:`FSm`, where ``m`` indicates the number + of the string. + It is measured between the lowest module and after the string fuse. +- *Pack voltage*, short V\ :sub:`Pm`, where ``m`` indicates the number + of the string. + It is measured between the negative pole of the lowest module and behind the + positive string contactor. + This voltage is identical for all connected strings and enables measurement + validation. + +The current sensor additional measures each string current. + +Comprehension of measured voltages and current in the pack: + ++---------------+---------------------------------------+ +| Symbol | Description | ++===============+=======================================+ +| V\ :sub:`Sm` | Voltage of string m | ++---------------+---------------------------------------+ +| V\ :sub:`FSm` | Voltage after string fuse of string m | ++---------------+---------------------------------------+ +| V\ :sub:`Pm` | Pack voltage | ++---------------+---------------------------------------+ +| I\ :sub:`Sm` | Current in string m | ++---------------+---------------------------------------+ + +******************** +Single-String System +******************** + +A single-string system reduces the amount of required voltage and current +measurements. +:numref:`measurements-in-single-string-system` shows the single-string +topology. + +.. figure:: img/battery-system-setup-single-string.png + :alt: Voltages and current to be measured in a single-string system + :name: measurements-in-single-string-system + :align: center + :target: ../_images/battery-system-setup-single-string.png + + Voltages and current to be measured in a single-string system (click to + enlarge) + +The list of measurements is therefore reduced to +:numref:`pack-measurements-single-string-system` and no further measurements +inside the string are required. + +.. csv-table:: List of measurements in single-string system + :name: pack-measurements-single-string-system + :header-rows: 1 + :delim: ; + :file: ./bjb-measurements.csv + +******************************************** +Measurements Inside the Battery Junction Box +******************************************** + +.. figure:: img/battery-system-setup-bjb.png + :alt: Voltages to be measured in a multi string system in the BJB + :name: voltages-in-multi-string-system-in-bjb + :align: center + :target: ../_images/battery-system-setup-bjb.png + + Voltages to be measured in a multi-string system in the BJB (click to + enlarge) + +- The pack voltage is measured before the main fuse. +- The fused pack voltage is measured after the main fuse. +- The system voltage is measured after the contactors. +- **optional**: If the system uses a second power path, the second power path + voltage is measured after the contactors of the second power path. + +Comprehension of measured voltages and current in the battery junction box: + +.. csv-table:: List of measurements in multi-string system + :name: pack-measurements-multi-string-system + :header-rows: 1 + :delim: ; + :file: ./bjb-measurements.csv diff --git a/docs/tools/static-analysis/axivion.rst b/docs/tools/static-analysis/axivion.rst new file mode 100644 index 00000000..e0dd9445 --- /dev/null +++ b/docs/tools/static-analysis/axivion.rst @@ -0,0 +1,115 @@ +.. include:: ./../../macros.txt +.. include:: ./../../units.txt + +.. _AXIVION_BAUHAUS_SUITE: + +Axivion Bauhaus Suite +===================== + +.. + Comments: + Axivion is the company that builds the Axivion Bauhaus suite + cafeCC is the Axivion compiler + dashserver is the command to run the Axivion Bauhaus Suite dashserver + +.. spelling:: + Axivion + cafeCC + dashserver + +Static Analysis tries to uncover potential errors in software by analyzing the +source code. In this project one of the tools that are used is the +Axivion Bauhaus Suite. + +Setup +----- + +- Install OpenJDK and make it available in PATH. +- Install Python3.8 from https://www.python.org/downloads/windows/. Use the + user installer and make sure to install the Python launcher. Leave all other + options as they are selected. +- Install Axivion Bauhaus Suite from the zip-file in a versioned directory + e.g., ``C:\Bauhaus\x.y.z`` and add ``C:\Bauhaus\x.y.z\bin`` to the user PATH + environment variable. +- Copy the license file into ``%USERPROFILE%\.bauhaus``. +- Copy the certificate of the dashboard server to + ``%USERPROFILE%\.bauhaus\auto.cert``. +- **Optional:** If there is an Axivion Dashboard server running: Set the user + environment variable ``AXIVION_PASSWORD=xyz`` to the user token obtained from + the dashboard. + +To verify that the install can successfully build run the following commands in +a terminal inside the project root (please make sure that the terminal is +freshly spawned so that it inherits the new environment variables): + +.. code-block:: console + + C:\Users\vulpes\Documents\foxbms-2>waf build_axivion clean_axivion + +Local Builds And Results +------------------------ + +- Run the analysis step + + .. code-block:: console + + C:\Users\vulpes\Documents\foxbms-2>tests\axivion\start_local_analysis.bat + +- Run the following command in to start a local dashserver and **do not** close + the terminal afterwards: + + .. code-block:: console + + dashserver start --local --noauth --install_file=%USERPROFILE%\.bauhaus\localbuild\projects\foxbms-2.db + +- Follow the instructions printed on the terminal to see the results. + +VS Code Setup +------------- + +Usage ++++++ + +Running the Tests +^^^^^^^^^^^^^^^^^ + +Press :kbd:`Ctrl + Shift + B` and run the task *axivion analysis*. This task +runs the Axivion analysis script ``tests/axivion/start_analysis.bat``. + +Issues +^^^^^^ + +Open command palette by pressing :kbd:`Ctrl + Shift + P` and search for +*axivion*. + +Local Builds +++++++++++++ + +If VS Code is installed the VS Code's ``settings.json`` is automatically +correctly configured for Axivion usage. + +CI Builds ++++++++++ + +To get CI build results in VS Code add the following configuration to the +VS Code User settings: + +.. code-block:: json + + "axivion.dashboards": [ + { + "id": "user friendly Dashboard name", + "url": "", + "username": "" + } + ] + +Advanced Usage +++++++++++++++ + +Race Condition Analysis +^^^^^^^^^^^^^^^^^^^^^^^ + +Go into the directory `racepdfs` and execute the wrapper batch file. This +should generate a directory with call graphs to variables that are accessed in +a potential unsafe manner. These can be used for closer investigation. diff --git a/docs/tools/waf-tools/compiler-tool/f_ti_arm_cgt_cc_options.rst b/docs/tools/waf-tools/compiler-tool/f_ti_arm_cgt_cc_options.rst new file mode 100644 index 00000000..c8bd88bb --- /dev/null +++ b/docs/tools/waf-tools/compiler-tool/f_ti_arm_cgt_cc_options.rst @@ -0,0 +1,16 @@ +.. include:: ./../../../macros.txt +.. include:: ./../../../units.txt + +.. _TI_ARM_CGT_COMPILER_CONFIGURATION_TOOL: + +TI ARM CGT Compiler Configuration Tool +====================================== + +The tool is located in ``tools/waf-tools``. + +Tool Documentation +------------------ + +.. automodule:: f_ti_arm_cgt_cc_options + :members: + :show-inheritance: diff --git a/docs/tools/waf-tools/f_axivion.rst b/docs/tools/waf-tools/f_axivion.rst new file mode 100644 index 00000000..87dc63b9 --- /dev/null +++ b/docs/tools/waf-tools/f_axivion.rst @@ -0,0 +1,25 @@ +.. include:: ./../../macros.txt +.. include:: ./../../units.txt + +.. _WAF_TOOL_AXIVION: + +Axivion +======= + +.. + Comments: + Axivion is the company that builds the Axivion + bld is the waf object + cafeCC is the Axivion compiler + +.. spelling:: + Axivion + axivion + bld + cafeCC + +The tool is located in ``tools/waf-tools``. + +.. automodule:: f_axivion + :members: + :show-inheritance: diff --git a/docs/tools/waf-tools/ti-arm-compiler-tools.rst b/docs/tools/waf-tools/ti-arm-compiler-tools.rst index c1751308..fe4ebfaf 100644 --- a/docs/tools/waf-tools/ti-arm-compiler-tools.rst +++ b/docs/tools/waf-tools/ti-arm-compiler-tools.rst @@ -23,6 +23,7 @@ The implementation documentation is found hereafter: :caption: Compiler Tool Implementations ./compiler-tool/f_ti_arm_cgt + ./compiler-tool/f_ti_arm_cgt_cc_options ./compiler-tool/f_ti_arm_helper ./compiler-tool/f_ti_arm_tools ./compiler-tool/f_ti_color_arm_cgt diff --git a/docs/tools/waf-tools/waf-tools.rst b/docs/tools/waf-tools/waf-tools.rst index ec727ca8..6386bc10 100644 --- a/docs/tools/waf-tools/waf-tools.rst +++ b/docs/tools/waf-tools/waf-tools.rst @@ -20,6 +20,7 @@ Waf Tools Implementation Documentation :maxdepth: 1 ./ti-arm-compiler-tools + ./f_axivion.rst ./f_black.rst ./f_bootstrap_library_project.rst ./f_check_db_vars.rst diff --git a/src/app/application/algorithm/state_estimation/soc/counting/soc_counting.c b/src/app/application/algorithm/state_estimation/soc/counting/soc_counting.c index 937045f3..b8f16677 100644 --- a/src/app/application/algorithm/state_estimation/soc/counting/soc_counting.c +++ b/src/app/application/algorithm/state_estimation/soc/counting/soc_counting.c @@ -43,7 +43,7 @@ * @file soc_counting.c * @author foxBMS Team * @date 2020-10-07 (date of creation) - * @updated 2021-05-20 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup APPLICATION * @prefix SOC * @@ -383,7 +383,7 @@ float SOC_GetFromVoltage(int16_t voltage_mV) { /* Interpolate between LUT values, but do not extrapolate LUT! */ if (!(((0u == between_high) && (0u == between_low)) || /* cell voltage > maximum LUT voltage */ (between_low >= bc_stateOfChargeLookupTableLength))) { /* cell voltage < minimum LUT voltage */ - soc_perc = MATH_linearInterpolation( + soc_perc = MATH_LinearInterpolation( (float)bc_stateOfChargeLookupTable[between_low].voltage_mV, bc_stateOfChargeLookupTable[between_low].value, (float)bc_stateOfChargeLookupTable[between_high].voltage_mV, diff --git a/src/app/application/algorithm/state_estimation/soe/counting/soe_counting.c b/src/app/application/algorithm/state_estimation/soe/counting/soe_counting.c index 3d865792..1c94c556 100644 --- a/src/app/application/algorithm/state_estimation/soe/counting/soe_counting.c +++ b/src/app/application/algorithm/state_estimation/soe/counting/soe_counting.c @@ -43,7 +43,7 @@ * @file soe_counting.c * @author foxBMS Team * @date 2020-10-07 (date of creation) - * @updated 2021-05-20 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup APPLICATION * @prefix SOE * @@ -222,7 +222,7 @@ static float SOE_GetFromVoltage(int16_t voltage_mV) { /* Interpolate between LUT values, but do not extrapolate LUT! */ if (!(((0u == between_high) && (0u == between_low)) || /* cell voltage > maximum LUT voltage */ (between_low >= bc_stateOfEnergyLookupTableLength))) { /* cell voltage < minimum LUT voltage */ - soe_perc = MATH_linearInterpolation( + soe_perc = MATH_LinearInterpolation( (float)bc_stateOfEnergyLookupTable[between_low].voltage_mV, bc_stateOfEnergyLookupTable[between_low].value, (float)bc_stateOfEnergyLookupTable[between_high].voltage_mV, diff --git a/src/app/application/bal/bal.h b/src/app/application/bal/bal.h index 3afbdd05..38e06f28 100644 --- a/src/app/application/bal/bal.h +++ b/src/app/application/bal/bal.h @@ -134,7 +134,7 @@ typedef struct BAL_STATE { uint8_t lastSubstate; /*!< previous substate of the state machine */ uint8_t triggerEntry; /*!< counter for re-entrance protection (function running flag) */ uint32_t errorRequestCounter; /*!< counts the number of illegal requests to the BAL state machine */ - STD_RETURN_TYPE_e initializationFinished; /*!< E_OK if statemachine initialized, otherwise E_NOT_OK */ + STD_RETURN_TYPE_e initializationFinished; /*!< #STD_OK if statemachine initialized, otherwise #STD_NOT_OK */ bool active; /*!< indicate if balancing active or not */ int32_t balancingThreshold; /*!< effective balancing threshold */ bool balancingAllowed; /*!< flag to disable balancing */ diff --git a/src/app/application/bms/bms.c b/src/app/application/bms/bms.c index 89b3a2bd..b7592603 100644 --- a/src/app/application/bms/bms.c +++ b/src/app/application/bms/bms.c @@ -43,7 +43,7 @@ * @file bms.c * @author foxBMS Team * @date 2020-02-24 (date of creation) - * @updated 2021-07-29 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup ENGINE * @prefix BMS * @@ -372,8 +372,8 @@ static STD_RETURN_TYPE_e BMS_CheckPrecharge(uint8_t stringNumber, const DATA_BLO if ((0u == pPackValues->invalidStringCurrent[stringNumber]) && (0u == pPackValues->invalidStringVoltage[stringNumber]) && (0u == pPackValues->invalidHvBusVoltage)) { /* Only current not current direction is checked */ - const int32_t current_mA = MATH_AbsInt32(pPackValues->stringCurrent_mA[stringNumber]); - const int64_t cont_prechargeVoltDiff_mV = MATH_AbsInt64( + const int32_t current_mA = MATH_AbsInt32_t(pPackValues->stringCurrent_mA[stringNumber]); + const int64_t cont_prechargeVoltDiff_mV = MATH_AbsInt64_t( (int64_t)pPackValues->stringVoltage_mV[stringNumber] - (int64_t)pPackValues->highVoltageBusVoltage_mV); if ((cont_prechargeVoltDiff_mV < BMS_PRECHARGE_VOLTAGE_THRESHOLD_mV) && @@ -551,12 +551,12 @@ static int32_t BMS_GetStringVoltageDifference(uint8_t string, const DATA_BLOCK_P if ((0u == pPackValues->invalidStringVoltage[string]) && (0u == pPackValues->invalidStringVoltage[bms_state.firstClosedString])) { /* Calculate difference between string voltages */ - voltageDifference_mV = MATH_AbsInt32( + voltageDifference_mV = MATH_AbsInt32_t( pPackValues->stringVoltage_mV[string] - pPackValues->stringVoltage_mV[bms_state.firstClosedString]); } else if ((0u == pPackValues->invalidStringVoltage[string]) && (0u == pPackValues->invalidHvBusVoltage)) { /* Calculate difference between string and high voltage bus voltage */ voltageDifference_mV = - MATH_AbsInt32(pPackValues->stringVoltage_mV[string] - pPackValues->highVoltageBusVoltage_mV); + MATH_AbsInt32_t(pPackValues->stringVoltage_mV[string] - pPackValues->highVoltageBusVoltage_mV); } else { /* No valid voltages for comparison -> do not calculate difference and return INT32_MAX */ voltageDifference_mV = INT32_MAX; diff --git a/src/app/driver/foxmath/foxmath.c b/src/app/driver/foxmath/foxmath.c index 6d0ce171..9f4a149b 100644 --- a/src/app/driver/foxmath/foxmath.c +++ b/src/app/driver/foxmath/foxmath.c @@ -43,7 +43,7 @@ * @file foxmath.c * @author foxBMS Team * @date 2018-01-18 (date of creation) - * @updated 2021-07-15 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup DRIVERS * @prefix MATH * @@ -55,6 +55,14 @@ #include "foxmath.h" /*========== Macros and Definitions =========================================*/ +/** shift one byte (8 positions) */ +#define SHIFT_ONE_BYTE (8u) + +/** shift two bytes (16 positions) */ +#define SHIFT_TWO_BYTES (16u) + +/** shift four bytes (32 positions) */ +#define SHIFT_FOUR_BYTES (32u) /*========== Static Constant and Variable Definitions =======================*/ @@ -66,47 +74,74 @@ /*========== Extern Function Implementations ================================*/ -extern float MATH_linearInterpolation(float x1, float y1, float x2, float y2, float x_interpolate) { - float y_interpolate = 0.0f; - float slope = 0.0f; +/* AXIVION Disable Style Generic-MissingParameterAssert: If not specified otherwise, functions in this lib are designed to take full range input. No assert needed. */ + +extern void MATH_StartupSelfTest(void) { + FAS_ASSERT(MATH_AbsInt64_t(INT64_MIN) == INT64_MAX); + FAS_ASSERT(MATH_AbsInt32_t(INT32_MIN) == INT32_MAX); +} + +extern float MATH_LinearInterpolation( + const float x1, + const float y1, + const float x2, + const float y2, + const float x_interpolate) { + float slope = 0.0f; - if (x1 != x2) { + if (fabsf(x1 - x2) >= FLT_EPSILON) { /* Calculate slope */ slope = (y2 - y1) / (x2 - x1); - } else { - /* x values are identical -> no interpolation possible: return y1 value */ - slope = 0; } + /* In the case that the if clause is not entered (x values are identical) + * -> no interpolation possible: return y1 value + * -> slope takes initialization value of 0.0f + */ + /* Interpolate starting from x1/y1 */ - y_interpolate = y1 + (slope * (x_interpolate - x1)); + float y_interpolate = y1 + (slope * (x_interpolate - x1)); return y_interpolate; } -extern uint16_t MATH_swapBytes_uint16_t(uint16_t val) { - return (val << 8) | (val >> 8); +extern uint16_t MATH_SwapBytesUint16_t(const uint16_t val) { + return (val << SHIFT_ONE_BYTE) | (val >> SHIFT_ONE_BYTE); } -extern uint32_t MATH_swapBytes_uint32_t(uint32_t val) { - val = ((val << 8) & 0xFF00FF00u) | ((val >> 8) & 0xFF00FFu); - return (val << 16) | (val >> 16); +extern uint32_t MATH_SwapBytesUint32_t(const uint32_t val) { + const uint32_t alternating2PatternStartFF = 0xFF00FF00u; + const uint32_t alternating2PatternStart00 = 0x00FF00FFu; + const uint32_t intermediate = ((val << SHIFT_ONE_BYTE) & alternating2PatternStartFF) | + ((val >> SHIFT_ONE_BYTE) & alternating2PatternStart00); + return (intermediate << SHIFT_TWO_BYTES) | (intermediate >> SHIFT_TWO_BYTES); } -extern uint64_t MATH_swapBytes_uint64_t(uint64_t val) { - val = ((val << 8) & 0xFF00FF00FF00FF00ull) | ((val >> 8) & 0x00FF00FF00FF00FFull); - val = ((val << 16) & 0xFFFF0000FFFF0000ull) | ((val >> 16) & 0x0000FFFF0000FFFFull); - return (val << 32) | (val >> 32); +extern uint64_t MATH_SwapBytesUint64_t(const uint64_t val) { + const uint64_t alternating2PatternStartFF = 0xFF00FF00FF00FF00uLL; + const uint64_t alternating2PatternStart00 = 0x00FF00FF00FF00FFuLL; + const uint64_t alternating4PatternStartFFFF = 0xFFFF0000FFFF0000uLL; + const uint64_t alternating4PatternStart0000 = 0x0000FFFF0000FFFFuLL; + + uint64_t intermediate = ((val << SHIFT_ONE_BYTE) & alternating2PatternStartFF) | + ((val >> SHIFT_ONE_BYTE) & alternating2PatternStart00); + intermediate = ((intermediate << SHIFT_TWO_BYTES) & alternating4PatternStartFFFF) | + ((intermediate >> SHIFT_TWO_BYTES) & alternating4PatternStart0000); + return (intermediate << SHIFT_FOUR_BYTES) | (intermediate >> SHIFT_FOUR_BYTES); } -extern float MATH_MinimumOfTwoFloats(float value1, float value2) { +extern float MATH_MinimumOfTwoFloats(const float value1, const float value2) { return fminf(value1, value2); } -extern uint8_t MATH_MinimumOfTwoUint8_t(uint8_t value1, uint8_t value2) { - return ((value1 < value2) ? value1 : value2); +extern uint8_t MATH_MinimumOfTwoUint8_t(const uint8_t value1, const uint8_t value2) { + uint8_t returnvalue = value1; + if (returnvalue > value2) { + returnvalue = value2; + } + return returnvalue; } -extern uint16_t MATH_MinimumOfTwoUint16_t(uint16_t value1, uint16_t value2) { +extern uint16_t MATH_MinimumOfTwoUint16_t(const uint16_t value1, const uint16_t value2) { uint16_t returnvalue = value1; if (returnvalue > value2) { returnvalue = value2; @@ -114,7 +149,7 @@ extern uint16_t MATH_MinimumOfTwoUint16_t(uint16_t value1, uint16_t value2) { return returnvalue; } -extern int32_t MATH_AbsInt32(int32_t value) { +extern int32_t MATH_AbsInt32_t(const int32_t value) { int32_t absValue = INT32_MAX; if (value != INT32_MIN) { absValue = labs(value); @@ -122,7 +157,7 @@ extern int32_t MATH_AbsInt32(int32_t value) { return absValue; } -extern int64_t MATH_AbsInt64(int64_t value) { +extern int64_t MATH_AbsInt64_t(const int64_t value) { int64_t absValue = INT64_MAX; if (value != INT64_MIN) { absValue = llabs(value); @@ -130,4 +165,6 @@ extern int64_t MATH_AbsInt64(int64_t value) { return absValue; } +/* AXIVION Enable Style Generic-MissingParameterAssert: */ + /*========== Externalized Static Function Implementations (Unit Test) =======*/ diff --git a/src/app/driver/foxmath/foxmath.h b/src/app/driver/foxmath/foxmath.h index c15696ad..8e9b0f7a 100644 --- a/src/app/driver/foxmath/foxmath.h +++ b/src/app/driver/foxmath/foxmath.h @@ -43,7 +43,7 @@ * @file foxmath.h * @author foxBMS Team * @date 2018-01-18 (date of creation) - * @updated 2021-07-15 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup DRIVERS * @prefix MATH * @@ -62,9 +62,11 @@ /*========== Includes =======================================================*/ #include "general.h" +/* AXIVION Disable Style Generic-LocalInclude: foxmath is intended as a library and therefore includes all useful libraries */ #include #include #include +/* AXIVION Enable Style Generic-LocalInclude: */ /*========== Macros and Definitions =========================================*/ @@ -77,6 +79,15 @@ /*========== Extern Constant and Variable Declarations ======================*/ /*========== Extern Function Prototypes =====================================*/ +/** + * @brief: self test for math functions that can be called at startup + * + *@details: This self test is intended to be called at startup. It will assert + * if one of the assumptions is violated. This function can be used + * to make sure that features of foxmath that are currently not used + * by the code are working nevertheless as expected. + */ +extern void MATH_StartupSelfTest(void); /** * @brief Linear inter-/extrapolates a third point according to two given points @@ -89,25 +100,30 @@ * * @return interpolated value (float) */ -extern float MATH_linearInterpolation(float x1, float y1, float x2, float y2, float x_interpolate); +extern float MATH_LinearInterpolation( + const float x1, + const float y1, + const float x2, + const float y2, + const float x_interpolate); /** * @brief Swap bytes of uint16_t value * @param val: value to swap bytes: 0x1234 -> 0x3412 */ -extern uint16_t MATH_swapBytes_uint16_t(uint16_t val); +extern uint16_t MATH_SwapBytesUint16_t(const uint16_t val); /** * @brief Swap bytes of uint32_t value * @param val: value to swap bytes: 0x12345678 -> 0x78563412 */ -extern uint32_t MATH_swapBytes_uint32_t(uint32_t val); +extern uint32_t MATH_SwapBytesUint32_t(const uint32_t val); /** * @brief Swap bytes of uint64_t value * @param val: value to swap bytes: 0x1122334455667788 -> 0x8877665544332211 */ -extern uint64_t MATH_swapBytes_uint64_t(uint64_t val); +extern uint64_t MATH_SwapBytesUint64_t(const uint64_t val); /** * @brief Returns the minimum of the passed float values @@ -115,7 +131,7 @@ extern uint64_t MATH_swapBytes_uint64_t(uint64_t val); * @param[in] value2 value 2 * @return minimum value */ -extern float MATH_MinimumOfTwoFloats(float value1, float value2); +extern float MATH_MinimumOfTwoFloats(const float value1, const float value2); /** * @brief Returns the minimum of the passed uint8_t values @@ -123,7 +139,7 @@ extern float MATH_MinimumOfTwoFloats(float value1, float value2); * @param[in] value2 value 2 * @return minimum value */ -extern uint8_t MATH_MinimumOfTwoUint8_t(uint8_t value1, uint8_t value2); +extern uint8_t MATH_MinimumOfTwoUint8_t(const uint8_t value1, const uint8_t value2); /** * @brief Returns the minimum of the passed uint16_t values @@ -131,21 +147,21 @@ extern uint8_t MATH_MinimumOfTwoUint8_t(uint8_t value1, uint8_t value2); * @param[in] value2 value 2 * @return minimum value */ -extern uint16_t MATH_MinimumOfTwoUint16_t(uint16_t value1, uint16_t value2); +extern uint16_t MATH_MinimumOfTwoUint16_t(const uint16_t value1, const uint16_t value2); /** * @brief Returns the absolute value of passed int32_t value * @param[in] value integer value * @return absolute value or INT32_MAX if INT32_MIN is passed */ -extern int32_t MATH_AbsInt32(int32_t value); +extern int32_t MATH_AbsInt32_t(const int32_t value); /** * @brief Returns the absolute value of passed int64_t value * @param[in] value integer value * @return absolute value or INT64_MAX if INT64_MIN is passed */ -extern int64_t MATH_AbsInt64(int64_t value); +extern int64_t MATH_AbsInt64_t(const int64_t value); /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/ diff --git a/src/app/driver/ts/epcos/b57251v5103j060/epcos_b57251v5103j060.c b/src/app/driver/ts/epcos/b57251v5103j060/epcos_b57251v5103j060.c index 9cc44a39..373817a2 100644 --- a/src/app/driver/ts/epcos/b57251v5103j060/epcos_b57251v5103j060.c +++ b/src/app/driver/ts/epcos/b57251v5103j060/epcos_b57251v5103j060.c @@ -43,7 +43,7 @@ * @file epcos_b57251v5103j060.c * @author foxBMS Team * @date 2018-10-30 (date of creation) - * @updated 2021-03-22 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup TEMPERATURE_SENSORS * @prefix TS * @@ -179,7 +179,7 @@ extern int16_t TS_Epc00GetTemperatureFromLut(uint16_t adcVoltage_mV) { /* Interpolate between LUT values, but do not extrapolate LUT! */ if (!(((between_high == 0u) && (between_low == 0u)) || /* measured resistance > maximum LUT resistance */ (between_low > b57251v5103j060LutSize))) { /* measured resistance < minimum LUT resistance */ - temperature_ddegC = (int16_t)MATH_linearInterpolation( + temperature_ddegC = (int16_t)MATH_LinearInterpolation( ts_b57251v5103j060Lut[between_low].resistance_Ohm, ts_b57251v5103j060Lut[between_low].temperature_ddegC, ts_b57251v5103j060Lut[between_high].resistance_Ohm, diff --git a/src/app/driver/ts/epcos/b57861s0103f045/epcos_b57861s0103f045.c b/src/app/driver/ts/epcos/b57861s0103f045/epcos_b57861s0103f045.c index c3ba0d80..5857dbd6 100644 --- a/src/app/driver/ts/epcos/b57861s0103f045/epcos_b57861s0103f045.c +++ b/src/app/driver/ts/epcos/b57861s0103f045/epcos_b57861s0103f045.c @@ -43,7 +43,7 @@ * @file epcos_b57861s0103f045.c * @author foxBMS Team * @date 2018-10-30 (date of creation) - * @updated 2018-10-30 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup TEMPERATURE_SENSORS * @prefix TS * @@ -180,7 +180,7 @@ extern int16_t TS_Epc01GetTemperatureFromLut(uint16_t adcVoltage_mV) { /* Interpolate between LUT values, but do not extrapolate LUT! */ if (!(((between_high == 0u) && (between_low == 0u)) || /* measured resistance > maximum LUT resistance */ (between_low > ts_b57861s0103f045LutSize))) { /* measured resistance < minimum LUT resistance */ - temperature_ddegC = (int16_t)MATH_linearInterpolation( + temperature_ddegC = (int16_t)MATH_LinearInterpolation( ts_b57861s0103f045Lut[between_low].resistance_Ohm, ts_b57861s0103f045Lut[between_low].temperature_ddegC, ts_b57861s0103f045Lut[between_high].resistance_Ohm, diff --git a/src/app/driver/ts/vishay/ntcalug01a103g/vishay_ntcalug01a103g.c b/src/app/driver/ts/vishay/ntcalug01a103g/vishay_ntcalug01a103g.c index 047f6f15..f5a1c711 100644 --- a/src/app/driver/ts/vishay/ntcalug01a103g/vishay_ntcalug01a103g.c +++ b/src/app/driver/ts/vishay/ntcalug01a103g/vishay_ntcalug01a103g.c @@ -43,7 +43,7 @@ * @file vishay_ntcalug01a103g.c * @author foxBMS Team * @date 2018-10-30 (date of creation) - * @updated 2021-03-22 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup TEMPERATURE_SENSORS * @prefix TS * @@ -283,7 +283,7 @@ extern int16_t TS_Vis00GetTemperatureFromLut(uint16_t adcVoltage_mV) { /* Interpolate between LUT values, but do not extrapolate LUT! */ if (!(((between_high == 0u) && (between_low == 0u)) || /* measured resistance > maximum LUT resistance */ (between_low > ts_ntcalug01a103gLutSize))) { /* measured resistance < minimum LUT resistance */ - temperature_ddegC = (int16_t)MATH_linearInterpolation( + temperature_ddegC = (int16_t)MATH_LinearInterpolation( ts_ntcalug01a103gLut[between_low].resistance_Ohm, ts_ntcalug01a103gLut[between_low].temperature_ddegC, ts_ntcalug01a103gLut[between_high].resistance_Ohm, diff --git a/src/app/engine/config/database_cfg.h b/src/app/engine/config/database_cfg.h index dad05a53..547676b8 100644 --- a/src/app/engine/config/database_cfg.h +++ b/src/app/engine/config/database_cfg.h @@ -43,7 +43,7 @@ * @file database_cfg.h * @author foxBMS Team * @date 2015-08-18 (date of creation) - * @updated 2021-06-09 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup ENGINE_CONFIGURATION * @prefix DATA * @@ -290,9 +290,9 @@ typedef struct DATA_BLOCK_USER_MUX { /* This struct needs to be at the beginning of every database entry. During * the initialization of a database struct, uniqueId must be set to the * respective database entry representation in enum DATA_BLOCK_ID_e. */ - DATA_BLOCK_HEADER_s header; /*!< Data block header */ - uint8_t state; /*!< for future use */ - uint16_t value[BS_NR_OF_STRINGS][8 * 2 * BS_NR_OF_MODULES]; /*!< unit: mV (mux voltage input) */ + DATA_BLOCK_HEADER_s header; /*!< Data block header */ + uint8_t state; /*!< for future use */ + uint16_t value[BS_NR_OF_STRINGS][8u * 2u * BS_NR_OF_MODULES]; /*!< unit: mV (mux voltage input) */ } DATA_BLOCK_USER_MUX_s; /** data block struct of cell open wire */ @@ -304,7 +304,7 @@ typedef struct DATA_BLOCK_OPENWIRE { uint8_t state; /*!< for future use */ uint16_t nrOpenWires[BS_NR_OF_STRINGS]; /*!< number of open wires */ uint8_t openwire[BS_NR_OF_STRINGS] - [BS_NR_OF_MODULES * (BS_NR_OF_CELLS_PER_MODULE + 1)]; /*!< 1 -> open wire, 0 -> everything ok */ + [BS_NR_OF_MODULES * (BS_NR_OF_CELLS_PER_MODULE + 1u)]; /*!< 1 -> open wire, 0 -> everything ok */ } DATA_BLOCK_OPEN_WIRE_s; /** data block struct of GPIO voltage */ diff --git a/src/app/main/main.c b/src/app/main/main.c index 9b35d347..9986a2c7 100644 --- a/src/app/main/main.c +++ b/src/app/main/main.c @@ -43,7 +43,7 @@ * @file main.c * @author foxBMS Team * @date 2019-08-27 (date of creation) - * @updated 2021-07-23 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup GENERAL * @prefix TODO * @@ -66,6 +66,7 @@ #include "contactor.h" #include "diag.h" #include "dma.h" +#include "foxmath.h" #include "masterinfo.h" #include "meas.h" #include "os.h" @@ -94,6 +95,7 @@ int main(void) { DMA_Initialize(); DIAG_Initialize(&diag_device); CAN_Initialize(); + MATH_StartupSelfTest(); OS_InitializeOperatingSystem(); if (OS_INIT_PRE_OS != os_boot) { diff --git a/src/app/main/wscript b/src/app/main/wscript index bcc4fc4a..bb8dfb51 100644 --- a/src/app/main/wscript +++ b/src/app/main/wscript @@ -65,6 +65,7 @@ def build(bld): os.path.join("..", "driver", "config"), os.path.join("..", "driver", "contactor"), os.path.join("..", "driver", "dma"), + os.path.join("..", "driver", "foxmath"), os.path.join("..", "driver", "io"), os.path.join("..", "driver", "meas"), os.path.join("..", "driver", "spi"), diff --git a/tests/axivion/.axivion.preinc b/tests/axivion/.axivion.preinc new file mode 100644 index 00000000..63349a2f --- /dev/null +++ b/tests/axivion/.axivion.preinc @@ -0,0 +1,330 @@ +/** + * + * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * We kindly request you to use one or more of the following phrases to refer to + * foxBMS in your hardware, software, documentation or advertising materials: + * + * - ″This product uses parts of foxBMS®″ + * - ″This product includes parts of foxBMS®″ + * - ″This product is derived from foxBMS®″ + * + */ + +/* Required by Axivion */ + +#pragma diag_suppress unrecognized_pragma, unrecognized_attribute, invalid_error_tag, invalid_error_number, 69, 951 + +/* We use GNU mode to emulate extensions such as __attribute__, + but we can't define __GNUC__ or the system headers go down the wrong code path. */ +#undef __GNUC__ +#undef __GNUG__ + +/* foxBMS 2 specific adapations */ +/* SPNU151V-January1998-RevisedFebruary2020 */ +/* 5.14 ARM Instruction Intrinsics */ +/* Table 5-3. ARM Intrinsic Support by Target */ +/* entries for ARM V7R (Cortex-R4) */ + +/* Cortex-R4 has: __clz */ +/* Cortex-R4 has: __delay_cycle */ +/* Cortex-R4 has: __ldrex */ +/* Cortex-R4 has: __ldrexb */ +/* Cortex-R4 has: __ldrexd */ +/* Cortex-R4 has: __ldrexh */ +/* Cortex-R4 has: __MCR */ +/* Cortex-R4 has: __MRC */ +/* Cortex-R4 has: __nop */ +/* Cortex-R4 has: _norm */ +/* Cortex-R4 has: __rev */ +/* Cortex-R4 has: __rev16 */ +/* Cortex-R4 has: __revsh */ +/* Cortex-R4 has: __rbit */ +/* Cortex-R4 has: __ror */ +/* Cortex-R4 has: _pkhbt */ +/* Cortex-R4 has: _pkhtb */ +/* Cortex-R4 has: _qadd16 */ +/* Cortex-R4 has: _qadd8 */ +/* Cortex-R4 has: _qaddsubx */ +/* Cortex-R4 has: _qsub16 */ +/* Cortex-R4 has: qsub8 */ +/* Cortex-R4 has: _qsubaddx */ +/* Cortex-R4 has: _sadd */ +/* Cortex-R4 has: _sadd16 */ +/* Cortex-R4 has: _sadd8 */ +/* Cortex-R4 has: _saddsubx */ +/* Cortex-R4 has: _sdadd */ +/* Cortex-R4 has: _sdsub */ +/* Cortex-R4 has: _sel */ +/* Cortex-R4 has: _shadd16 */ +/* Cortex-R4 has: _shadd8 */ +/* Cortex-R4 has: _shsub16 */ +/* Cortex-R4 has: _shsub8 */ +/* Cortex-R4 has: _smac */ +/* Cortex-R4 has: _smlabb */ +/* Cortex-R4 has: _smlabt */ +/* Cortex-R4 has: _smlad */ +/* Cortex-R4 has: _smladx */ +/* Cortex-R4 has: _smlalbb */ +/* Cortex-R4 has: _smlalbt */ +/* Cortex-R4 has: _smlald */ +/* Cortex-R4 has: _smlaldx */ +/* Cortex-R4 has: _smlaltb */ +/* Cortex-R4 has: _smlaltt */ +/* Cortex-R4 has: _smlatb */ +/* Cortex-R4 has: _smlatt */ +/* Cortex-R4 has: _smlawb */ +/* Cortex-R4 has: _smlawt */ +/* Cortex-R4 has: _smlsd */ +/* Cortex-R4 has: _smlsdx */ +/* Cortex-R4 has: _smlsld */ +/* Cortex-R4 has: _smlsldx */ +/* Cortex-R4 has: _smmla */ +/* Cortex-R4 has: _smmlar */ +/* Cortex-R4 has: _smmls */ +/* Cortex-R4 has: _smmlsr */ +/* Cortex-R4 has: _smmul */ +/* Cortex-R4 has: _smmulr */ +/* Cortex-R4 has: _smuad */ +/* Cortex-R4 has: _smuadx */ +/* Cortex-R4 has: _smusd */ +/* Cortex-R4 has: _smusdx */ +/* Cortex-R4 has: _smpy */ +/* Cortex-R4 has: _smsub */ +/* Cortex-R4 has: _smulbb */ +/* Cortex-R4 has: _smulbt */ +/* Cortex-R4 has: _smultb */ +/* Cortex-R4 has: _smultt */ +/* Cortex-R4 has: _smulwb */ +/* Cortex-R4 has: _smulwt */ +/* Cortex-R4 has: __sqrt */ +/* Cortex-R4 has: __sqrtf */ +/* Cortex-R4 has: _ssat16 */ +/* Cortex-R4 has: _ssata */ +/* Cortex-R4 has: _ssatl */ +/* Cortex-R4 has: _ssub */ +/* Cortex-R4 has: _ssub16 */ +/* Cortex-R4 has: _ssub8 */ +/* Cortex-R4 has: _ssubaddx */ +/* Cortex-R4 has: __strex */ +/* Cortex-R4 has: __strexb */ +/* Cortex-R4 has: __strexd */ +/* Cortex-R4 has: __strexh */ +/* Cortex-R4 has: _subc */ +/* Cortex-R4 has: _sxtab */ +/* Cortex-R4 has: _sxtab16 */ +/* Cortex-R4 has: _sxtah */ +/* Cortex-R4 has: _sxtb */ +/* Cortex-R4 has: _sxtb16 */ +/* Cortex-R4 has: _sxth */ +/* Cortex-R4 has: _uadd16 */ +/* Cortex-R4 has: _uadd8 */ +/* Cortex-R4 has: _uaddsubx */ +/* Cortex-R4 has: _uhadd16 */ +/* Cortex-R4 has: _uhadd8 */ +/* Cortex-R4 has: _uhsub16 */ +/* Cortex-R4 has: _uhsub8 */ +/* Cortex-R4 has: _umaal */ +/* Cortex-R4 has: _uqadd16 */ +/* Cortex-R4 has: _uqadd8 */ +/* Cortex-R4 has: _uqaddsubx */ +/* Cortex-R4 has: _uqsub16 */ +/* Cortex-R4 has: _uqsub8 */ +/* Cortex-R4 has: _uqsubaddx */ +/* Cortex-R4 has: _usad8 */ +/* Cortex-R4 has: _usat16 */ +/* Cortex-R4 has: _usata */ +/* Cortex-R4 has: _usatl */ +/* Cortex-R4 has: _usub16 */ +/* Cortex-R4 has: _usub8 */ +/* Cortex-R4 has: _usubaddx */ +/* Cortex-R4 has: _uxtab */ +/* Cortex-R4 has: _uxtab16 */ +/* Cortex-R4 has: _uxtah */ +/* Cortex-R4 has: _uxtb */ +/* Cortex-R4 has: _uxtb16 */ +/* Cortex-R4 has: _uxth */ +/* Cortex-R4 has: __wfe */ +/* Cortex-R4 has: __wfi */ + +/* foxBMS 2 specific adapations */ +/* SPNU151V-January1998-RevisedFebruary2020 */ +/* 5.14 ARM Instruction Intrinsics */ +/* Table 5-4. ARM Compiler Intrinsics */ + +int _clz(int src) __attribute__((const)); +void __delay_cycles(unsigned int cycles) __attribute__((const)); +unsigned int __get_MSP(void) __attribute__((const)); +unsigned int __get_PRIMASK(void) __attribute__((const)); +unsigned int __ldrex(void *src) __attribute__((const)); +unsigned int __ldrexb(void *src) __attribute__((const)); +unsigned long long __ldrexd(void *src) __attribute__((const)); +unsigned int __ldrexh(void *src) __attribute__((const)); +void __MCR(unsigned int coproc, unsigned int opc1, unsigned int src, unsigned int coproc_reg1, unsigned int coproc_reg2, unsigned int opc2) __attribute__((const)); +unsigned int __MRC(unsigned int coproc, unsigned int opc1, unsigned int coproc_reg1, unsigned int coproc_reg2, unsigned int opc2) __attribute__((const)); +void __nop(void) __attribute__((const)); +int _norm(int src) __attribute__((const)); +int _pkhbt(int src1, int src2, int shift) __attribute__((const)); +int _pkhtb(int src1, int src2, int shift) __attribute__((const)); +int _qadd16(int src1, int src2) __attribute__((const)); +int _qadd8(int src1, int src2) __attribute__((const)); +int _qaddsubx(int src1, int src2) __attribute__((const)); +int _qsub16(int src1, int src2) __attribute__((const)); +int _qsub8(int src1, int src2) __attribute__((const)); +int _qsubaddx(int src1, int src2) __attribute__((const)); +int __rbit(int src) __attribute__((const)); +int __rev(int src) __attribute__((const)); +int __rev16(int src) __attribute__((const)); +int __revsh(int src) __attribute__((const)); +int __ror(int src, int shift) __attribute__((const)); +int _sadd(int src1, int src2) __attribute__((const)); +int _sadd16(int src1, int src2) __attribute__((const)); +int _sadd8(int src1, int src2) __attribute__((const)); +int _saddsubx(int src1, int src2) __attribute__((const)); +int _sdadd(int src1, int src2) __attribute__((const)); +int _sdsub(int src1, int src2) __attribute__((const)); +int _sel(int src1, int src2) __attribute__((const)); +void __set_MSP(unsigned int src) __attribute__((const)); +unsigned int __set_PRIMASK(unsigned int src) __attribute__((const)); +int _shadd16(int src1, int src2) __attribute__((const)); +int _shadd8(int src1, int src2) __attribute__((const)); +int _shsub16(int src1, int src2) __attribute__((const)); +int _shsub8(int src1, int src2) __attribute__((const)); +int _smac(int dst, int src1, int src2) __attribute__((const)); +int _smlabb(int dst, short src1, short src2) __attribute__((const)); +int _smlabt(int dst, short src1, int src2) __attribute__((const)); +int _smlad(int src1, int src2, int acc) __attribute__((const)); +int _smladx(int src1, int src2, int acc) __attribute__((const)); +long long _smlalbb(long long dst, short src1, short src2) __attribute__((const)); +long long _smlalbt(long long dst, short src1, int src2) __attribute__((const)); +long long _smlald(long long acc, int src1, int src2) __attribute__((const)); +long long _smlaldx(long long acc, int src1, int src2) __attribute__((const)); +long long _smlaltb(long long dst, int src1, short src2) __attribute__((const)); +long long _smlaltt(long long dst, int src1, int src2) __attribute__((const)); +int _smlatb(int dst, int src1, short src2) __attribute__((const)); +int _smlatt(int dst, int src1, int src2) __attribute__((const)); +int _smlawb(int src1, short src2, int acc) __attribute__((const)); +int _smlawt(int src1, short src2, int acc) __attribute__((const)); +int _smlsd(int src1, int src2, int acc) __attribute__((const)); +int _smlsdx(int src1, int src2, int acc) __attribute__((const)); +long long _smlsld(long long acc, int src1, int src2) __attribute__((const)); +long long _smlsldx(long long acc, int src1, int src2) __attribute__((const)); +int _smmla(int src1, int src2, int acc) __attribute__((const)); +int _smmlar(int src1, int src2, int acc) __attribute__((const)); +int _smmls(int src1, int src2, int acc) __attribute__((const)); +int _smmlsr(int src1, int src2, int acc) __attribute__((const)); +int _smmul(int src1, int src2, int acc) __attribute__((const)); +int _smmulr(int src1, int src2, int acc) __attribute__((const)); +int _smpy(int src1, int src2) __attribute__((const)); +int _smsub(int src1, int src2) __attribute__((const)); +int _smuad(int src1, int src2) __attribute__((const)); +int _smuadx(int src1, int src2) __attribute__((const)); +int _smulbb(int src1, int src2) __attribute__((const)); +int _smulbt(int src1, int src2) __attribute__((const)); +int _smultb(int src1, int src2) __attribute__((const)); +int _smultt(int src1, int src2) __attribute__((const)); +int _smulwb(int src1, short src2, int acc) __attribute__((const)); +int _smulwt(int src1, short src2, int acc) __attribute__((const)); +int _smusd(int src1, int src2) __attribute__((const)); +int _smusdx(int src1, int src2) __attribute__((const)); +double __sqrt(double) __attribute__((const)); +float __sqrtf(float) __attribute__((const)); +int _ssat16(int src, int bitpos) __attribute__((const)); +int _ssata(int src, int shift, int bitpos) __attribute__((const)); +int _ssatl(int src, int shift, int bitpos) __attribute__((const)); +int _ssub(int src1, int src2) __attribute__((const)); +int _ssub16(int src1, int src2) __attribute__((const)); +int _ssub8(int src1, int src2) __attribute__((const)); +int _ssubaddx(int src1, int src2) __attribute__((const)); +int __strex(unsigned int src, void *dst) __attribute__((const)); +int __strexb(unsigned char src, void *dst) __attribute__((const)); +int __strexd(unsigned long long src, void *dst) __attribute__((const)); +int __strexh(unsigned short src, void *dst) __attribute__((const)); +int _subc(int src1, int src2) __attribute__((const)); +int _sxtab(int src1, int src2, int rotamt) __attribute__((const)); +int _sxtab16(int src1, int src2, int rotamt) __attribute__((const)); +int _sxtah(int src1, int src2, int rotamt) __attribute__((const)); +int _sxtb(int src1, int rotamt) __attribute__((const)); +int _sxtb16(int src1, int rotamt) __attribute__((const)); +int _sxth(int src1, int rotamt) __attribute__((const)); +int _uadd16(int src1, int src2) __attribute__((const)); +int _uadd8(int src1, int src2) __attribute__((const)); +int _uaddsubx(int src1, int src2) __attribute__((const)); +int _uhadd16(int src1, int src2) __attribute__((const)); +int _uhadd8(int src1, int src2) __attribute__((const)); +int _uhsub16(int src1, int src2) __attribute__((const)); +int _uhsub8(int src1, int src2) __attribute__((const)); +int _umaal(long long acc, int src1, int src2) __attribute__((const)); +int _uqadd16(int src1, int src2) __attribute__((const)); +int _uqadd8(int src1, int src2) __attribute__((const)); +int _uqaddsubx(int src1, int src2) __attribute__((const)); +int _uqsub16(int src1, int src2) __attribute__((const)); +int _uqsub8(int src1, int src2) __attribute__((const)); +int _uqsubaddx(int src1, int src2) __attribute__((const)); +int _usad8(int src1, int src2) __attribute__((const)); +int _usat16(int src, int bitpos) __attribute__((const)); +int _sxtab(int src1, int src2, int rotamt) __attribute__((const)); +int _sxtab16(int src1, int src2, int rotamt) __attribute__((const)); +int _sxtah(int src1, int src2, int rotamt) __attribute__((const)); +int _sxtb(int src1, int rotamt) __attribute__((const)); +int _sxtb16(int src1, int rotamt) __attribute__((const)); +int _sxth(int src1, int rotamt) __attribute__((const)); +int _uadd16(int src1, int src2) __attribute__((const)); +int _uadd8(int src1, int src2) __attribute__((const)); +int _uaddsubx(int src1, int src2) __attribute__((const)); +int _uhadd16(int src1, int src2) __attribute__((const)); +int _uhadd8(int src1, int src2) __attribute__((const)); +int _uhsub16(int src1, int src2) __attribute__((const)); +int _uhsub8(int src1, int src2) __attribute__((const)); +int _umaal(long long acc, int src1, int src2) __attribute__((const)); +int _uqadd16(int src1, int src2) __attribute__((const)); +int _uqadd8(int src1, int src2) __attribute__((const)); +int _uqaddsubx(int src1, int src2) __attribute__((const)); +int _uqsub16(int src1, int src2) __attribute__((const)); +int _uqsub8(int src1, int src2) __attribute__((const)); +int _uqsubaddx(int src1, int src2) __attribute__((const)); +int _usad8(int src1, int src2) __attribute__((const)); +int _usat16(int src, int bitpos) __attribute__((const)); + +/* foxBMS 2 specific adapations */ +/* SPNU151V-January1998-RevisedFebruary2020 */ +/* 6.9 Built-In Functions */ + +void *__curpc(void); +int __run_address_check(void); + +/* foxBMS 2 specific adapations */ +/* source: https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/666101/compiler-tms570ls3137-need-definition-for-the-_hi-f-_lo-f-used-in-the-xxdftype-h-file*/ +unsigned long _hi(long double); +unsigned long _lo(long double); + +/* foxBMS 2 specific adapations */ +unsigned _ftoi (float src); diff --git a/tests/axivion/.clang-format b/tests/axivion/.clang-format new file mode 100644 index 00000000..9d159247 --- /dev/null +++ b/tests/axivion/.clang-format @@ -0,0 +1,2 @@ +DisableFormat: true +SortIncludes: false diff --git a/tests/axivion/.gitignore b/tests/axivion/.gitignore new file mode 100644 index 00000000..fb4311b1 --- /dev/null +++ b/tests/axivion/.gitignore @@ -0,0 +1,3 @@ +enable_id_output.json +races.txt +pdfs/ diff --git a/tests/axivion/README.md b/tests/axivion/README.md new file mode 100644 index 00000000..08054e44 --- /dev/null +++ b/tests/axivion/README.md @@ -0,0 +1,43 @@ +# Axivion Bauhaus Suite Configuration for foxBMS 2 + +## Directory Description + + +- ``.axivion.preinc``, ``predefined_macros.txt`` and ``predefined_sizes.txt`` + describe compiler built-ins for the TI ARM CGT compiler for TMS570LC4357. +- ``architecture.gxl``, ``architecture.json`` and ``mapping.gxl`` describe the + software architecture of foxBMS 2. +- ``axivion_config.json``, ``cafeCC.config``, ``ci_config.json``, + ``rule_config_c.json``, ``rule_config_c.py`` provide project specific + settings. +- ``start_analysis.bat``, ``start_local_analysis.bat``, + ``start_local_analysis.sh``, ``start_local_dashserver.bat`` are helper + scripts to run axivion. Files here might need to be updated to your local + Axivion setup. +- ``wrapper_make_race_pdfs.bat`` wrapper script to simplify creating the + report. + +``` +(repository-root) +└── tests + └── axivion + ├── .axivion.preinc + ├── .clang-format + ├── .gitignore + ├── architecture.gxl + ├── architecture.json + ├── axivion_config.json + ├── cafeCC.config + ├── ci_config.json + ├── mapping.gxl + ├── predefined_macros.txt + ├── predefined_sizes.txt + ├── README.md + ├── rule_config_c.json + ├── rule_config_c.py + ├── start_analysis.bat + ├── start_local_analysis.bat + ├── start_local_analysis.sh + ├── start_local_dashserver.bat + └── wrapper_make_race_pdfs.bat +``` diff --git a/tests/axivion/architecture.gxl b/tests/axivion/architecture.gxl new file mode 100644 index 00000000..c7627247 --- /dev/null +++ b/tests/axivion/architecture.gxl @@ -0,0 +1,567 @@ + + + + + + + + HAL + + + ce57c8ae-5258-43b6-9961-b8eab70b4233 + + + + + + Driver + + + 7834bbf9-71da-4cea-9104-67ecd2558f56 + + + + + + OS + + + 73570489-fadd-4b30-b7a7-4640f5f844f8 + + + + + + Application + + + 806c54d7-9be9-4760-afd3-8a0d8b62a609 + + + + + + Balancing + + + 27d7a7c4-00ca-48b0-b107-688cdcaf71ef + + + + + + BMS + + + 1d321303-9120-4897-a5a0-2397c1e7293a + + + + + + Plausibility + + + f6e881ac-babd-463c-b6ec-348d990d4e76 + + + + + + SOX + + + e7e42410-6388-46c2-807f-5ee60a251396 + + + + + + Engine + + + 999b8969-10b6-4739-bd2c-f8e269f113a0 + + + + + + Main + + + a3e03d08-3b41-4a56-9f03-103a52c90548 + + + + + + Database + + + 3b5c26dc-b3a5-4423-a961-3f39dc0a5ed9 + + + + + + Diagnosis + + + f19bedfe-54a4-4f01-a486-c94e529ced58 + + + + + + System + + + 75fe3254-d162-432e-ae16-eaa70619f50f + + + + + + System Monitoring + + + 3eff9945-c2ad-4073-bd82-dc7d5405452a + + + + + + CAN + + + df9e1298-e967-4ee3-a903-55f1632284fc + + + + + + Measurement IC + + + 515b9069-5530-4897-9777-6af92794f278 + + + + + + Measurement + + + 027cc519-176f-4c70-960c-6505ea5ddd1c + + + + + + Contactor + + + 69d80159-eb51-4788-ad91-72171eef7461 + + + + + + ADC + + + 8c5c9da5-b98b-4f3d-abc2-3c8d12fd96bc + + + + + + DMA + + + 051a17d1-7a79-41f5-83a4-588da5d9eff2 + + + + + + FRAM + + + 3823ea61-02b8-457c-b028-b1d5fbb9256e + + + + + + Interlock + + + 2f24952b-2688-46c5-b9db-6b0b400f9312 + + + + + + IO + + + ec782c10-d1d9-4c3a-966a-a6e755cc611d + + + + + + MCU + + + b1a1861d-1d0e-4b8b-855e-d500c5fde734 + + + + + + SPI + + + 01ccfcfe-7c45-4177-9508-f423ae8a5cd0 + + + + + + Temperature Sensors + + + 3bf2fe9c-629b-41b6-a544-1afe67eb9daa + + + + + + Task Configuration + + + 130d48ab-422a-42cf-a6a5-517ed0d81e12 + + + + + + OS Interface + + + 608c1594-8d27-4812-89d8-8f0954583fd6 + + + + + + Task Setup + + + 6d62c3ee-039e-4ad7-a231-4fce2b23a145 + + + + + + Common + + + 57d0dee1-8103-40c2-9dc6-e4e6feb88b9e + + + + + + main + + + 2f136d68-9615-4fe5-a2ac-b24e727d4452 + + + + + + core components + + + 0b546284-b270-48d4-ba42-12b5921159ef + + + + + + version information + + + f6f89ed6-60cb-46ee-9623-bbb2bf8182cd + + + + + + fassert + + + 85311c57-46cb-4255-91aa-4cfb1b9d98fb + + + + + + Power Supply + + + ee3eb6b6-d536-4c33-887b-e5130795c242 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/axivion/architecture.json b/tests/axivion/architecture.json new file mode 100644 index 00000000..bd6f7660 --- /dev/null +++ b/tests/axivion/architecture.json @@ -0,0 +1,28 @@ +{ + "Analysis": { + "Architecture": { + "child_order": [ + "Architecture-ImportGXLArchitecture", + "Architecture-ImportGXLMapping", + "Architecture-ArchitectureCheck" + ] + }, + "Architecture-ArchitectureCheck": { + "_active": true + }, + "Architecture-ImportGXLArchitecture": { + "_active": true, + "_copy_from": "Architecture-GXLImport", + "gxl_file": "architecture.gxl", + "view_name": "Architecture" + }, + "Architecture-ImportGXLMapping": { + "_active": true, + "_copy_from": "Architecture-GXLImport", + "gxl_file": "mapping.gxl", + "view_name": "Mapping" + } + }, + "_Format": "1.0", + "_Version": "trunk-r3870" +} diff --git a/tests/axivion/axivion_config.json b/tests/axivion/axivion_config.json new file mode 100644 index 00000000..8aaac129 --- /dev/null +++ b/tests/axivion/axivion_config.json @@ -0,0 +1,10 @@ +{ + "_Layers": [ + "ci_config.json", + "architecture.json", + "rule_config_c.py", + "rule_config_c.json", + "rule_config_names.py", + "rule_config_names.json" + ] +} diff --git a/tests/axivion/cafeCC.config b/tests/axivion/cafeCC.config new file mode 100644 index 00000000..3e18865c --- /dev/null +++ b/tests/axivion/cafeCC.config @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/axivion/ci_config.json b/tests/axivion/ci_config.json new file mode 100644 index 00000000..f1469695 --- /dev/null +++ b/tests/axivion/ci_config.json @@ -0,0 +1,62 @@ +{ + "Analysis": { + "Analysis-GlobalOptions": { + "global_excludes": [ + "C:/ti/*", + "*src/app/driver/mic/ltc/common/ltc_pec.*", + "*src/app/driver/sbc/fs8x_driver/*", + "*src/hal/*", + "*src/os/*" + ] + }, + "SaveRFG": { + "_active": true, + "rfg_file": "../../build/axivion/foxbms.elf.rfg" + } + }, + "Project": { + "BuildSystemIntegration": { + "child_order": [ + "Command" + ] + }, + "Command": { + "_active": true, + "build_command": "$(builtin:AXIVION_CONFDIR)/../../waf.bat configure build_axivion -v -c yes", + "clean_command": "$(builtin:AXIVION_CONFDIR)/../../waf.bat configure clean_axivion -v -c yes", + "cwd": "." + }, + "Git": { + "_active": true, + "sourceserver_gitdir": "$(env:sourceServerGitDir=)" + }, + "Project-GlobalOptions": { + "ci_mode": { + "clean_after": false, + "clean_before": "!$(env:SKIP_PREBUILD_CLEAN=false)" + }, + "directory": "../..", + "ir": "build/axivion/foxbms.elf", + "name": "$(env:analysisProjectName=foxbms-2)" + } + }, + "Results": { + "Dashboard": { + "dashboard_url": "$(env:AXIVION_DASHBOARD_URL=https://axivion-dash.iisb.fraunhofer.de/axivion)" + }, + "Database": { + "ci_mode": { + "directory": "", + "filename": "$(env:databaseFileRemote=)" + } + } + }, + "_Format": "1.0", + "_Version": "7.1.1", + "_VersionNum": [ + 7, + 1, + 1, + 5996 + ] +} diff --git a/tests/axivion/mapping.gxl b/tests/axivion/mapping.gxl new file mode 100644 index 00000000..312f5691 --- /dev/null +++ b/tests/axivion/mapping.gxl @@ -0,0 +1,1140 @@ + + + + + + + + hal + + + D build/axivion/src/hal + + + + + + interlock + + + D src/app/driver/interlock + + + + + + mic + + + D src/app/driver/mic + + + + + + sbc + + + D src/app/driver/sbc + + + + + + bal + + + D src/app/application/bal + + + + + + bms + + + D src/app/application/bms + + + + + + can + + + D src/app/driver/can + + + + + + database + + + D src/app/engine/database + + + + + + diag + + + D src/app/engine/diag + + + + + + os + + + D src/os + + + + + + redundancy + + + D src/app/application/redundancy + + + + + + os + + + D src/app/task/os + + + + + + state_estimation + + + D src/app/application/algorithm/state_estimation + + + + + + sys_mon + + + D src/app/engine/sys_mon + + + + + + sys + + + D src/app/engine/sys + + + + + + ts + + + D src/app/driver/ts + + + + + + contactor + + + D src/app/driver/contactor + + + + + + adc + + + D src/app/driver/adc + + + + + + sps + + + D src/app/driver/sps + + + + + + ftask + + + D src/app/task/ftask + + + + + + checksum + + + D src/app/driver/checksum + + + + + + fram + + + D src/app/driver/fram + + + + + + io + + + D src/app/driver/io + + + + + + foxmath + + + D src/app/driver/foxmath + + + + + + mcu + + + D src/app/driver/mcu + + + + + + meas + + + D src/app/driver/meas + + + + + + plausibility + + + D src/app/application/plausibility + + + + + + soa + + + D src/app/application/soa + + + + + + spi + + + D src/app/driver/spi + + + + + + bal_cfg.h + + + f src/app/application/config/bal_cfg.h + + + + + + bms_cfg.h + + + f src/app/application/config/bms_cfg.h + + + + + + plausibility_cfg.h + + + f src/app/application/config/plausibility_cfg.h + + + + + + soa_cfg.h + + + f src/app/application/config/soa_cfg.h + + + + + + can_cfg.h + + + f src/app/driver/config/can_cfg.h + + + + + + contactor_cfg.h + + + f src/app/driver/config/contactor_cfg.h + + + + + + dma_cfg.h + + + f src/app/driver/config/dma_cfg.h + + + + + + fram_cfg.h + + + f src/app/driver/config/fram_cfg.h + + + + + + interlock_cfg.h + + + f src/app/driver/config/interlock_cfg.h + + + + + + nxpfs85xx_cfg.h + + + f src/app/driver/config/nxpfs85xx_cfg.h + + + + + + spi_cfg.h + + + f src/app/driver/config/spi_cfg.h + + + + + + sps_cfg.h + + + f src/app/driver/config/sps_cfg.h + + + + + + tsi_plausibility_cfg.h + + + f src/app/driver/config/tsi_plausibility_cfg.h + + + + + + dma.h + + + f src/app/driver/dma/dma.h + + + + + + database_cfg.h + + + f src/app/engine/config/database_cfg.h + + + + + + diag_cfg.h + + + f src/app/engine/config/diag_cfg.h + + + + + + sys_cfg.h + + + f src/app/engine/config/sys_cfg.h + + + + + + sys_mon_cfg.h + + + f src/app/engine/config/sys_mon_cfg.h + + + + + + version_cfg.h + + + f src/app/main/include/config/version_cfg.h + + + + + + fassert.h + + + f src/app/main/include/fassert.h + + + + + + fstd_types.h + + + f src/app/main/include/fstd_types.h + + + + + + fsystem.h + + + f src/app/main/include/fsystem.h + + + + + + general.h + + + f src/app/main/include/general.h + + + + + + main.h + + + f src/app/main/include/main.h + + + + + + ftask_cfg.h + + + f src/app/task/config/ftask_cfg.h + + + + + + version_cfg.c + + + f build/axivion/src/app/main/version_cfg.c + + + + + + soa_cfg.c + + + f src/app/application/config/soa_cfg.c + + + + + + can_cfg.c + + + f src/app/driver/config/can_cfg.c + + + + + + contactor_cfg.c + + + f src/app/driver/config/contactor_cfg.c + + + + + + dma_cfg.c + + + f src/app/driver/config/dma_cfg.c + + + + + + fram_cfg.c + + + f src/app/driver/config/fram_cfg.c + + + + + + interlock_cfg.c + + + f src/app/driver/config/interlock_cfg.c + + + + + + spi_cfg.c + + + f src/app/driver/config/spi_cfg.c + + + + + + sps_cfg.c + + + f src/app/driver/config/sps_cfg.c + + + + + + dma.c + + + f src/app/driver/dma/dma.c + + + + + + database_cfg.c + + + f src/app/engine/config/database_cfg.c + + + + + + diag_cfg.c + + + f src/app/engine/config/diag_cfg.c + + + + + + sys_cfg.c + + + f src/app/engine/config/sys_cfg.c + + + + + + sys_mon_cfg.c + + + f src/app/engine/config/sys_mon_cfg.c + + + + + + fassert.c + + + f src/app/main/fassert.c + + + + + + fstartup.c + + + f src/app/main/fstartup.c + + + + + + main.c + + + f src/app/main/main.c + + + + + + ftask_cfg.c + + + f src/app/task/config/ftask_cfg.c + + + + + + HAL + + + ce57c8ae-5258-43b6-9961-b8eab70b4233 + + + + + + OS + + + 73570489-fadd-4b30-b7a7-4640f5f844f8 + + + + + + Balancing + + + 27d7a7c4-00ca-48b0-b107-688cdcaf71ef + + + + + + BMS + + + 1d321303-9120-4897-a5a0-2397c1e7293a + + + + + + Plausibility + + + f6e881ac-babd-463c-b6ec-348d990d4e76 + + + + + + SOX + + + e7e42410-6388-46c2-807f-5ee60a251396 + + + + + + Database + + + 3b5c26dc-b3a5-4423-a961-3f39dc0a5ed9 + + + + + + Diagnosis + + + f19bedfe-54a4-4f01-a486-c94e529ced58 + + + + + + System + + + 75fe3254-d162-432e-ae16-eaa70619f50f + + + + + + System Monitoring + + + 3eff9945-c2ad-4073-bd82-dc7d5405452a + + + + + + CAN + + + df9e1298-e967-4ee3-a903-55f1632284fc + + + + + + Measurement IC + + + 515b9069-5530-4897-9777-6af92794f278 + + + + + + Measurement + + + 027cc519-176f-4c70-960c-6505ea5ddd1c + + + + + + Contactor + + + 69d80159-eb51-4788-ad91-72171eef7461 + + + + + + ADC + + + 8c5c9da5-b98b-4f3d-abc2-3c8d12fd96bc + + + + + + DMA + + + 051a17d1-7a79-41f5-83a4-588da5d9eff2 + + + + + + FRAM + + + 3823ea61-02b8-457c-b028-b1d5fbb9256e + + + + + + Interlock + + + 2f24952b-2688-46c5-b9db-6b0b400f9312 + + + + + + IO + + + ec782c10-d1d9-4c3a-966a-a6e755cc611d + + + + + + MCU + + + b1a1861d-1d0e-4b8b-855e-d500c5fde734 + + + + + + SPI + + + 01ccfcfe-7c45-4177-9508-f423ae8a5cd0 + + + + + + Temperature Sensors + + + 3bf2fe9c-629b-41b6-a544-1afe67eb9daa + + + + + + OS Interface + + + 608c1594-8d27-4812-89d8-8f0954583fd6 + + + + + + Task Setup + + + 6d62c3ee-039e-4ad7-a231-4fce2b23a145 + + + + + + Common + + + 57d0dee1-8103-40c2-9dc6-e4e6feb88b9e + + + + + + main + + + 2f136d68-9615-4fe5-a2ac-b24e727d4452 + + + + + + core components + + + 0b546284-b270-48d4-ba42-12b5921159ef + + + + + + version information + + + f6f89ed6-60cb-46ee-9623-bbb2bf8182cd + + + + + + fassert + + + 85311c57-46cb-4255-91aa-4cfb1b9d98fb + + + + + + Power Supply + + + ee3eb6b6-d536-4c33-887b-e5130795c242 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/axivion/predefined_macros.txt b/tests/axivion/predefined_macros.txt new file mode 100644 index 00000000..bea0c811 --- /dev/null +++ b/tests/axivion/predefined_macros.txt @@ -0,0 +1,137 @@ +# EDG C/C++ predefined macro definition file. +# +# based on ti-cgt-arm_20.2.4.LTS +# generated by copying the content from "predefined defines" step when +# configuring the project +# +# C compiler information +# command: C:\ti\ccs1031\ccs\tools\compiler\ti-cgt-arm_20.2.4.LTS\bin\armcl.exe -version +# out: TI ARM C/C++ Compiler v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# +# TI ARM EABI C/C++ Parser v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM C/C++ File Merge v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM C/C++ Optimizer v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM G3 C/C++ Codegen v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Assembler v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Embed Utility v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM C Source Interlister v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Linker v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Absolute Lister v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Strip Utility v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM XREF Utility v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM C++ Demangler v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Hex Converter v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Name Utility v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Object File Display v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D +# TI ARM Archiver v20.2.4.LTS +# Build Number 1UM9J-2LI-RZASS-TAQ-C08D + +# Build information +# predefined_defines.c file content: +# int main() { +# return 0; +# } +# command: C:\ti\ccs1031\ccs\tools\compiler\ti-cgt-arm_20.2.4.LTS\bin\armcl.exe +# --silicon_version=7R5 +# --code_state=32 +# --float_support=VFPv3D16 -g +# --diag_wrap=off +# --display_error_number +# --enum_type=packed +# --abi=eabi +# --c99 +# --preproc_macros +# --compile_only +# --obj_directory=. +# --output_file=predefined_defines.obj +# predefined_defines.c + +all no __32bis__ 1 +all no __ARM_32BIT_STATE 1 +all no __ARM_ACLE 200 +all no __ARM_ARCH 7 +all no __ARM_ARCH_ISA_ARM 1 +all no __ARM_ARCH_ISA_THUMB 2 +all no __ARM_ARCH_PROFILE 82 +all no __ARM_BIG_ENDIAN 1 +all no __ARM_FEATURE_CLZ 1 +all no __ARM_FEATURE_DSP 1 +all no __ARM_FEATURE_LDREX 15 +all no __ARM_FEATURE_SAT 1 +all no __ARM_FEATURE_SIMD32 1 +all no __ARM_FEATURE_UNALIGNED 1 +all no __ARM_FP 12 +all no __ARM_FP16_ARGS 1 +all no __ARM_FP16_FORMAT_IEEE 1 +all no __ARM_PCS 1 +all no __ARM_PCS_VFP 1 +all no __ARM_SIZEOF_MINIMAL_ENUM 1 +all no __ARM_SIZEOF_WCHAR_T 2 +all no __big_endian__ 1 +all no __BIG_ENDIAN__ 1 +all no __CHAR_BIT__ 8 +all no __COMPILER_VERSION__ 20002004 +all no __eabi__ 1 +all no __edg_front_end__ 1 +all no __EDG_VERSION__ 413 +all no __ELF__ 1 +all no __INT_MAX__ 2147483647 +all no __LONG_LONG_MAX__ 9223372036854775807 +all no __LONG_MAX__ 2147483647 +all no __PRAGMA_REDEFINE_EXTNAME 1 +all no __PTRDIFF_T_TYPE__ int +all no __SCHAR_MAX__ 127 +all no __SHRT_MAX__ 32767 +all no __SIZE_T_TYPE__ unsigned +all no __SIZEOF_DOUBLE__ 8 +all no __SIZEOF_FLOAT__ 4 +all no __SIZEOF_INT__ 4 +all no __SIZEOF_LONG__ 4 +all no __SIZEOF_LONG_DOUBLE__ 8 +all no __SIZEOF_LONG_LONG__ 8 +all no __SIZEOF_PTRDIFF_T__ 4 +all no __SIZEOF_SHORT__ 2 +all no __SIZEOF_SIZE_T__ 4 +all no __SIZEOF_WCHAR_T__ 2 +all no __SIZEOF_WINT_T__ 2 +all no __STDC_NO_THREADS__ 1 +all no __TI_ARM__ 1 +all no __TI_ARM_V7__ 1 +all no __TI_ARM_V7R4__ 1 +all no __TI_ARM_V7R5__ 1 +all no __TI_C99_COMPLEX_ENABLED__ 1 +all no __TI_COMPILER_VERSION__ 20002004 +all no __TI_COMPILER_VERSION_QUAL__ QUAL_LETTER +all no __TI_COMPILER_VERSION_QUAL_ID__ 20344 +all no __TI_EABI__ 1 +all no __TI_EABI_SUPPORT__ 1 +all no __TI_GNU_ATTRIBUTE_SUPPORT__ 1 +all no __TI_STRICT_ANSI_MODE__ 0 +all no __TI_STRICT_FP_MODE__ 1 +all no __TI_TMS470_V7__ 1 +all no __TI_TMS470_V7R4__ 1 +all no __TI_TMS470_V7R5__ 1 +all no __TI_VFP_SUPPORT__ 1 +all no __TI_VFPV3D16_SUPPORT__ 1 +all no __TI_WCHAR_T_BITS__ 16 +all no __TMS470__ 1 +all no __unsigned_chars__ 1 +all no __WCHAR_T_TYPE__ unsigned short +all no _OPTIMIZE_FOR_SPACE 1 +all no _INLINE 1 diff --git a/tests/axivion/predefined_sizes.txt b/tests/axivion/predefined_sizes.txt new file mode 100644 index 00000000..3dc3238a --- /dev/null +++ b/tests/axivion/predefined_sizes.txt @@ -0,0 +1,21 @@ +[ti] +sizeof(char) = 1 +sizeof(short) = 2 +sizeof(int) = 4 +sizeof(long) = 4 +sizeof(long long) = 8 +sizeof(float) = 4 +sizeof(double) = 8 +sizeof(long double) = 8 + +alignof(short) = 2 +alignof(int) = 4 +alignof(long) = 4 +alignof(long long) = 8 +alignof(float) = 4 +alignof(double) = 8 +alignof(long double) = 8 + +wchar_t = unsigned short int +size_t = unsigned int +ptrdiff_t = int diff --git a/tests/axivion/rule_config_c.json b/tests/axivion/rule_config_c.json new file mode 100644 index 00000000..b046b9c5 --- /dev/null +++ b/tests/axivion/rule_config_c.json @@ -0,0 +1,1231 @@ +{ + "Analysis": { + "Analysis-GlobalOptions": { + "scanner": { + "additional_basic_characters": "\\$@" + }, + "side_effects": { + "effect_free_functions": [ + "__curpc", + "MPU_xTaskGetTickCount", + "xPortRaisePrivilege" + ], + "local_effect_functions": [ + "FAS_ASSERT", + "fas_storeAssertLoc" + ], + "side_effect_functions": [ + "FAS_DisableInterrupts", + "fclose", + "fopen", + "fprintf", + "fputs", + "freopen", + "printf", + "tmpfile" + ] + }, + "types": { + "allow_single_bitfield_as_bool": true, + "user_bool_types": [ + "bool", + "Bool", + "BOOL", + "bool_t", + "BOOLEAN", + "boolean_t", + "STD_BOOLEAN_TYPE_e", + "tBool" + ] + } + }, + "Architecture": { + "child_order": [ + "Architecture-CyclesView", + "Architecture-DeadCodeView", + "Architecture-ActivateMembers", + "Architecture-ComputeDependencyProperties", + "Architecture-CSharpRFGTransformations", + "Architecture-XAMLAnalysis", + "Architecture-AddDynamicVariableAccesses", + "Architecture-CopyIntoEntriesView", + "Architecture-GXLImport", + "Architecture-RhapsodyImporter", + "Architecture-ARXMLImport", + "Architecture-CopyAndProjectView", + "Architecture-CreateTypes", + "Architecture-CustomRFGFunction", + "Architecture-InsertSystemNode", + "Architecture-ObfuscateNames", + "Architecture-ProjectView", + "Architecture-RemoveView", + "Architecture-StripBasepath", + "Architecture-TransitiveClosure", + "Architecture-CopyView", + "Architecture-CheckRFGEquality", + "Architecture-MatchGraphs", + "Architecture-EAImporter", + "Architecture-EdgeInterpretation", + "Architecture-GravisRoleAttributes", + "Architecture-HierarchicalMapping", + "Architecture-TaggedValuesMapping", + "Architecture-ScriptedArchitecture", + "Architecture-ArchitectureCheck", + "Architecture-ProcessLine", + "Architecture-CycleDetection", + "Architecture-GXLExport", + "Architecture-SaveRFG" + ] + }, + "Architecture-CyclesView": { + "_active": true + }, + "Architecture-DeadCodeView": { + "_active": true + }, + "Architecture-GXLExport": { + "_active": true + }, + "Architecture-SaveRFG": { + "_active": true + }, + "AutosarC++17_03-A15.4.1": { + "_active": true + }, + "CWE-Pointer-Issues-467": { + "_active": true + }, + "CWE-Pointer-Issues-476": { + "_active": true + }, + "CertC-DCL00": { + "_active": false, + "exclude_in_macros": [ + "FAS_ASSERT" + ] + }, + "CloneDetection": { + "_active": true, + "no_sequences": true, + "pre_excludes": [ + "/*", + "C:/*" + ] + }, + "CodeAnnotations": { + "show_debug_output": false + }, + "CodingStyle-AllmanBraces": { + "_active": false + }, + "CodingStyle-FileExtensionNaming": { + "languages": [ + "C++", + "C++/CLI" + ] + }, + "CodingStyle-MaxOneStmtPerLine": { + "_active": true, + "ignore_stmts": [ + "Exit_Switch", + "Statement_Sequence", + "Switch_Case_Label" + ] + }, + "CodingStyle-Naming.Enum": { + "_active": false, + "naming_convention": "^[A-Z][A-Z0-9]*_e$" + }, + "CodingStyle-Naming.Enumerator": { + "_active": false + }, + "CodingStyle-Naming.Function": { + "_active": false + }, + "CodingStyle-Naming.GlobalVariable": { + "_active": false + }, + "CodingStyle-Naming.Label": { + "_active": false + }, + "CodingStyle-Naming.LocalVariable": { + "_active": false + }, + "CodingStyle-Naming.Macro": { + "_active": false + }, + "CodingStyle-Naming.Parameter": { + "_active": false + }, + "CodingStyle-Naming.Struct": { + "_active": false, + "naming_convention": "^[A-Z][A-Z0-9]*_s$" + }, + "CodingStyle-Naming.StructField": { + "_active": false + }, + "CodingStyle-Naming.Union": { + "_active": false + }, + "CodingStyle-Naming.UserType": { + "_active": false + }, + "CodingStyle-NoBlankLinesAtBraces": { + "_active": false + }, + "CodingStyle-NoSingleCharIdentifier": { + "_active": true, + "exclude_loop_counter": true, + "whitelist": [] + }, + "CodingStyle-NoTabs": { + "_active": true + }, + "CodingStyle-NoTrailingWhitespace": { + "_active": true + }, + "CodingStyle-NoWhitespaceMemberSelection": { + "_active": true + }, + "CodingStyle-NoWhitespacePointerReference": { + "_active": false + }, + "CodingStyle-TooManyIncludes": { + "_active": true + }, + "CycleDetection-CallgraphCycles": { + "_active": true + }, + "CycleDetection-IncludeCycles": { + "_active": true + }, + "DeadCodeDetection": { + "_active": true + }, + "EnableDisable": { + "_active": true + }, + "EnableDisableSingleRule": { + "_active": false + }, + "EntryPoints-EntriesByName": { + "_active": true, + "names": [ + "*Notification", + "FTSK_TaskCreator*" + ] + }, + "FaultDetection-BadEnumValue": { + "_active": true + }, + "FaultDetection-DeadBranches": { + "_active": true, + "exclude_in_macros": [ + "FAS_ASSERT" + ] + }, + "FaultDetection-DivisionByZero": { + "_active": true, + "abstract_interpretation_div_by_zero": true + }, + "FaultDetection-EscapingLocalAddress": { + "_active": true + }, + "FaultDetection-IntegerOverflow": { + "_active": true, + "abstract_interpretation_overflow": true + }, + "FaultDetection-MemoryLeak": { + "_active": true + }, + "FaultDetection-NullPointerDereference": { + "_active": true + }, + "FaultDetection-OutOfBounds": { + "_active": true + }, + "FaultDetection-RemovableStatements": { + "_active": true + }, + "FaultDetection-UninitializedVariable": { + "_active": true + }, + "FaultDetection-UnrelatedPointerComparison": { + "_active": true + }, + "FaultDetection-UnrelatedPointerSubtraction": { + "_active": true + }, + "FaultDetection-UnusedAssignments": { + "_active": true + }, + "FaultDetection-UseAfterFree": { + "_active": true + }, + "Generic-CComments": { + "_active": true + }, + "Generic-DoxygenCommentAtDefinition": { + "_active": false + }, + "Generic-DoxygenCommentInHeader": { + "_active": true + }, + "Generic-DuplicateIncludeGuard": { + "_active": true + }, + "Generic-ForbiddenFunctions": { + "_active": true + }, + "Generic-IncludeKind": { + "_active": true + }, + "Generic-InitializeAllVariables": { + "_active": true + }, + "Generic-LocalInclude": { + "_active": true, + "enums_can_be_redeclared": true, + "excludes": [], + "interface_headers": [ + "*/*_api.h", + "*/Python.h", + "*/*_fwd.h", + "Q*" + ], + "routines_can_be_redeclared": true, + "typedefs_can_be_redeclared": true + }, + "Generic-LocalScope": { + "_active": true, + "move_global_const_into_function": false, + "treat_initialization_as_use": true + }, + "Generic-MaxComplexity": { + "_active": true, + "maxcomplexity": 20 + }, + "Generic-MaxConditions": { + "_active": true, + "maxconditions": 5 + }, + "Generic-MaxNesting": { + "_active": true, + "maxnesting": 5 + }, + "Generic-MaxOneStmtPerLine": { + "_active": true + }, + "Generic-MaxParams": { + "_active": true + }, + "Generic-MissingIncludeGuard": { + "_active": true + }, + "Generic-MissingOverride": { + "_active": true + }, + "Generic-MissingParameterAssert": { + "_active": true, + "macro_names": [ + "assert", + "FAS_ASSERT" + ] + }, + "Generic-MissingSelfHeaderInclude": { + "_active": true + }, + "Generic-NoAbsoluteInclude": { + "_active": true + }, + "Generic-NoCompilerWarnings": { + "_active": true + }, + "Generic-NoConditionalOperator": { + "_active": true + }, + "Generic-NoConstCasts": { + "_active": true + }, + "Generic-NoConstOnRHS": { + "_active": false + }, + "Generic-NoDiscardedReturnCode": { + "_active": true + }, + "Generic-NoEllipsis": { + "_active": true + }, + "Generic-NoEmptyStructs": { + "_active": true + }, + "Generic-NoExternInImpl": { + "_active": true + }, + "Generic-NoFunctionDefinitionInHeader": { + "_active": true + }, + "Generic-NoImplicitTypeConversion": { + "_active": false + }, + "Generic-NoIncludePaths": { + "_active": true, + "allow_downward_paths": true + }, + "Generic-NoIrregularInclude": { + "_active": true + }, + "Generic-NoLeakingReferenceToLocal": { + "_active": true + }, + "Generic-NoLinkerWarnings": { + "_active": true + }, + "Generic-NoMagicNumbers": { + "_active": true, + "exclude_single_uses": false + }, + "Generic-NoMalloc": { + "_active": true + }, + "Generic-NoPrecisionLoss": { + "_active": true + }, + "Generic-NoReferenceToLocalVariable": { + "_active": true + }, + "Generic-NoSemicolonAtEndOfMacro": { + "_active": true + }, + "Generic-NoSingleCharIdentifier": { + "_active": true, + "exclude_loop_counter": true, + "excludes": [], + "whitelist": [] + }, + "Generic-NoStaticInHeader": { + "_active": true + }, + "Generic-NoTabs": { + "_active": true + }, + "Generic-NoTrailingWhitespace": { + "_active": true + }, + "Generic-NoTypeConversionToBool": { + "_active": true + }, + "Generic-NoUncheckedPointerParamDereference": { + "_active": true + }, + "Generic-NoUnsafeMacro": { + "_active": true + }, + "Generic-NoWhitespaceMemberSelection": { + "_active": true + }, + "Generic-TooManyIncludes": { + "_active": true + }, + "Generic-TypedefCheck": { + "_active": true, + "report_identical_redefinitions": false + }, + "Generic-WrongIncludeCasing": { + "_active": true + }, + "Metric-CloneRatio": { + "_active": true + }, + "Metric-ExtendedMcCabe": { + "_active": true + }, + "Metric-Includes.DirectIncluders": { + "_active": true + }, + "Metric-Includes.DirectIncludes": { + "_active": true + }, + "Metric-Includes.IncludeBurden": { + "_active": true + }, + "Metric-Includes.MaximumIncludeDepth": { + "_active": true + }, + "Metric-Includes.MaximumIncluderDepth": { + "_active": true + }, + "Metric-Includes.TransitiveIncluders": { + "_active": true + }, + "Metric-Includes.TransitiveIncludes": { + "_active": true + }, + "Metric-IssueCount.Architecture": { + "_active": true + }, + "Metric-IssueCount.Clone": { + "_active": true + }, + "Metric-IssueCount.Cycle": { + "_active": true + }, + "Metric-IssueCount.DeadEntity": { + "_active": true + }, + "Metric-IssueCount.Metric": { + "_active": true + }, + "Metric-IssueCount.Style": { + "_active": true + }, + "Metric-Lines.Class.LOC": { + "_active": true + }, + "Metric-Lines.Comment": { + "_active": true + }, + "Metric-Lines.File.Comment": { + "_active": true + }, + "Metric-Lines.File.LOC": { + "_active": true + }, + "Metric-Lines.LOC": { + "_active": true + }, + "Metric-Lines.PP.Define": { + "_active": true + }, + "Metric-Lines.PP.Elif": { + "_active": true + }, + "Metric-Lines.PP.Else": { + "_active": true + }, + "Metric-Lines.PP.Endif": { + "_active": true + }, + "Metric-Lines.PP.Error": { + "_active": true + }, + "Metric-Lines.PP.Ident": { + "_active": true + }, + "Metric-Lines.PP.If": { + "_active": true + }, + "Metric-Lines.PP.Ifdef": { + "_active": true + }, + "Metric-Lines.PP.Ifndef": { + "_active": true + }, + "Metric-Lines.PP.Include": { + "_active": true + }, + "Metric-Lines.PP.Line": { + "_active": true + }, + "Metric-Lines.PP.Pragma": { + "_active": true + }, + "Metric-Lines.PP.Undef": { + "_active": true + }, + "Metric-Lines.PP.Warning": { + "_active": true + }, + "Metric-Lines.Routine.LOC": { + "_active": true + }, + "Metric-LogNPathCeiling": { + "_active": true + }, + "Metric-LogNPathFloor": { + "_active": true + }, + "Metric-McCabeComplexity": { + "_active": true + }, + "Metric-NumberOfCalledRoutines": { + "_active": true, + "max_value": 20 + }, + "Metric-NumberOfCallingRoutines": { + "_active": true, + "max_value": 20 + }, + "Metric-NumberOfGotos": { + "_active": true + }, + "Metric-NumberOfInvocations": { + "_active": true + }, + "Metric-NumberOfParameters": { + "_active": true + }, + "Metric-NumberOfReturns": { + "_active": true + }, + "Metric-NumberOfSCCs": { + "_active": true + }, + "Metric-NumberOfStatements": { + "_active": true + }, + "Metric-SwitchComplexity": { + "_active": true + }, + "Metric-TokenFileMetric.Check": { + "_active": false + }, + "Metric-TokenFileMetric.Debug": { + "_active": false + }, + "Metric-TokenFileMetric.Fixme": { + "_active": false + }, + "Metric-TokenFileMetric.Hack": { + "_active": false + }, + "Metric-TokenFileMetric.Todo": { + "_active": false + }, + "Metric-TokenFileMetric.XXX": { + "_active": false + }, + "Metric-TokenMetric.Check": { + "_active": false + }, + "Metric-TokenMetric.Debug": { + "_active": true + }, + "Metric-TokenMetric.Fixme": { + "_active": true + }, + "Metric-TokenMetric.Hack": { + "_active": true + }, + "Metric-TokenMetric.Todo": { + "_active": true + }, + "Metric-TokenMetric.XXX": { + "_active": true + }, + "MisraC-13.3": { + "_active": true + }, + "MisraC-13.6": { + "_active": true + }, + "MisraC2012-1.1": { + "_active": true + }, + "MisraC2012-1.2": { + "_active": true, + "exclude_in_macros": [ + "must_check_return" + ] + }, + "MisraC2012-1.3": { + "_active": true + }, + "MisraC2012-1.4": { + "_active": true + }, + "MisraC2012-10.1": { + "_active": true + }, + "MisraC2012-10.2": { + "_active": true + }, + "MisraC2012-10.3": { + "_active": true + }, + "MisraC2012-10.4": { + "_active": true + }, + "MisraC2012-10.5": { + "_active": true + }, + "MisraC2012-10.6": { + "_active": true + }, + "MisraC2012-10.7": { + "_active": true + }, + "MisraC2012-10.8": { + "_active": true + }, + "MisraC2012-11.1": { + "_active": true + }, + "MisraC2012-11.2": { + "_active": true + }, + "MisraC2012-11.3": { + "_active": true + }, + "MisraC2012-11.4": { + "_active": true + }, + "MisraC2012-11.5": { + "_active": true + }, + "MisraC2012-11.6": { + "_active": true + }, + "MisraC2012-11.7": { + "_active": true + }, + "MisraC2012-11.8": { + "_active": true + }, + "MisraC2012-11.9": { + "_active": true + }, + "MisraC2012-12.1": { + "_active": true + }, + "MisraC2012-12.2": { + "_active": true + }, + "MisraC2012-12.3": { + "_active": true + }, + "MisraC2012-12.4": { + "_active": true + }, + "MisraC2012-12.5": { + "_active": true + }, + "MisraC2012-13": { + "exclude_in_macros": [ + "FAS_ASSERT" + ] + }, + "MisraC2012-13.1": { + "_active": true + }, + "MisraC2012-13.2": { + "_active": true + }, + "MisraC2012-13.3": { + "_active": true + }, + "MisraC2012-13.4": { + "_active": true + }, + "MisraC2012-13.5": { + "_active": true + }, + "MisraC2012-13.6": { + "_active": true + }, + "MisraC2012-14.1": { + "_active": true + }, + "MisraC2012-14.2": { + "_active": true + }, + "MisraC2012-14.3": { + "_active": true, + "exclude_in_macros": [ + "FAS_ASSERT" + ] + }, + "MisraC2012-14.4": { + "_active": true + }, + "MisraC2012-15.1": { + "_active": true + }, + "MisraC2012-15.2": { + "_active": true + }, + "MisraC2012-15.3": { + "_active": true + }, + "MisraC2012-15.4": { + "_active": true + }, + "MisraC2012-15.5": { + "_active": true + }, + "MisraC2012-15.6": { + "_active": true + }, + "MisraC2012-15.7": { + "_active": true + }, + "MisraC2012-16.1": { + "_active": true, + "acceptable_end_items": [ + "Exit_Switch", + "Return_Statement" + ], + "acceptable_middle_items": [ + "Exit_Switch", + "Return_Statement", + "Switch_Case_Label" + ], + "allow_if": true + }, + "MisraC2012-16.2": { + "_active": true + }, + "MisraC2012-16.3": { + "_active": true + }, + "MisraC2012-16.4": { + "_active": true + }, + "MisraC2012-16.5": { + "_active": true + }, + "MisraC2012-16.6": { + "_active": true + }, + "MisraC2012-16.7": { + "_active": true + }, + "MisraC2012-17.1": { + "_active": true + }, + "MisraC2012-17.2": { + "_active": true + }, + "MisraC2012-17.3": { + "_active": true + }, + "MisraC2012-17.4": { + "_active": true + }, + "MisraC2012-17.5": { + "_active": true + }, + "MisraC2012-17.6": { + "_active": true + }, + "MisraC2012-17.7": { + "_active": true + }, + "MisraC2012-17.8": { + "_active": true + }, + "MisraC2012-18.1": { + "_active": true + }, + "MisraC2012-18.2": { + "_active": true + }, + "MisraC2012-18.3": { + "_active": true + }, + "MisraC2012-18.4": { + "_active": true + }, + "MisraC2012-18.5": { + "_active": true + }, + "MisraC2012-18.6": { + "_active": true + }, + "MisraC2012-18.7": { + "_active": true + }, + "MisraC2012-18.8": { + "_active": true + }, + "MisraC2012-19.1": { + "_active": true + }, + "MisraC2012-19.2": { + "_active": true + }, + "MisraC2012-2.1": { + "_active": true + }, + "MisraC2012-2.2": { + "_active": true, + "exclude_in_macros": [ + "FAS_ASSERT" + ] + }, + "MisraC2012-2.3": { + "_active": true + }, + "MisraC2012-2.4": { + "_active": true + }, + "MisraC2012-2.5": { + "_active": true + }, + "MisraC2012-2.6": { + "_active": true + }, + "MisraC2012-2.7": { + "_active": true + }, + "MisraC2012-20.1": { + "_active": true + }, + "MisraC2012-20.10": { + "_active": true + }, + "MisraC2012-20.11": { + "_active": true + }, + "MisraC2012-20.12": { + "_active": true + }, + "MisraC2012-20.13": { + "_active": true + }, + "MisraC2012-20.14": { + "_active": true + }, + "MisraC2012-20.2": { + "_active": true + }, + "MisraC2012-20.3": { + "_active": true + }, + "MisraC2012-20.4": { + "_active": true + }, + "MisraC2012-20.5": { + "_active": true + }, + "MisraC2012-20.6": { + "_active": true + }, + "MisraC2012-20.7": { + "_active": true + }, + "MisraC2012-20.8": { + "_active": true + }, + "MisraC2012-20.9": { + "_active": true + }, + "MisraC2012-21.1": { + "_active": true + }, + "MisraC2012-21.10": { + "_active": true + }, + "MisraC2012-21.11": { + "_active": true + }, + "MisraC2012-21.12": { + "_active": true + }, + "MisraC2012-21.13": { + "_active": true + }, + "MisraC2012-21.14": { + "_active": true + }, + "MisraC2012-21.15": { + "_active": true + }, + "MisraC2012-21.16": { + "_active": true + }, + "MisraC2012-21.17": { + "_active": true + }, + "MisraC2012-21.18": { + "_active": true + }, + "MisraC2012-21.19": { + "_active": true + }, + "MisraC2012-21.2": { + "_active": true + }, + "MisraC2012-21.20": { + "_active": true + }, + "MisraC2012-21.21": { + "_active": true + }, + "MisraC2012-21.3": { + "_active": true + }, + "MisraC2012-21.4": { + "_active": true + }, + "MisraC2012-21.5": { + "_active": true + }, + "MisraC2012-21.6": { + "_active": true + }, + "MisraC2012-21.7": { + "_active": true + }, + "MisraC2012-21.8": { + "_active": true + }, + "MisraC2012-21.9": { + "_active": true + }, + "MisraC2012-22.1": { + "_active": true + }, + "MisraC2012-22.10": { + "_active": true + }, + "MisraC2012-22.2": { + "_active": true + }, + "MisraC2012-22.3": { + "_active": true + }, + "MisraC2012-22.4": { + "_active": true + }, + "MisraC2012-22.5": { + "_active": true + }, + "MisraC2012-22.6": { + "_active": true + }, + "MisraC2012-22.7": { + "_active": true + }, + "MisraC2012-22.8": { + "_active": true + }, + "MisraC2012-22.9": { + "_active": true + }, + "MisraC2012-3.1": { + "_active": true + }, + "MisraC2012-3.2": { + "_active": true + }, + "MisraC2012-4.1": { + "_active": true + }, + "MisraC2012-4.2": { + "_active": true + }, + "MisraC2012-5.1": { + "_active": true + }, + "MisraC2012-5.2": { + "_active": true + }, + "MisraC2012-5.3": { + "_active": true + }, + "MisraC2012-5.4": { + "_active": true + }, + "MisraC2012-5.5": { + "_active": true + }, + "MisraC2012-5.6": { + "_active": true + }, + "MisraC2012-5.7": { + "_active": true + }, + "MisraC2012-5.8": { + "_active": true + }, + "MisraC2012-5.9": { + "_active": true + }, + "MisraC2012-6.1": { + "_active": true + }, + "MisraC2012-6.2": { + "_active": true + }, + "MisraC2012-7.1": { + "_active": true + }, + "MisraC2012-7.2": { + "_active": true + }, + "MisraC2012-7.3": { + "_active": true + }, + "MisraC2012-7.4": { + "_active": true + }, + "MisraC2012-8.1": { + "_active": true + }, + "MisraC2012-8.10": { + "_active": true + }, + "MisraC2012-8.11": { + "_active": true + }, + "MisraC2012-8.12": { + "_active": true + }, + "MisraC2012-8.13": { + "_active": true + }, + "MisraC2012-8.14": { + "_active": true + }, + "MisraC2012-8.2": { + "_active": true + }, + "MisraC2012-8.3": { + "_active": true + }, + "MisraC2012-8.4": { + "_active": true + }, + "MisraC2012-8.5": { + "_active": true + }, + "MisraC2012-8.6": { + "_active": true + }, + "MisraC2012-8.7": { + "_active": true + }, + "MisraC2012-8.8": { + "_active": true + }, + "MisraC2012-8.9": { + "_active": true + }, + "MisraC2012-9.1": { + "_active": true + }, + "MisraC2012-9.2": { + "_active": true + }, + "MisraC2012-9.3": { + "_active": true + }, + "MisraC2012-9.4": { + "_active": true + }, + "MisraC2012-9.5": { + "_active": true + }, + "MisraC2012Directive-1.1": { + "_active": true + }, + "MisraC2012Directive-2.1": { + "_active": true + }, + "MisraC2012Directive-4.1": { + "_active": true, + "abstract_interpretation_div_by_zero": true, + "abstract_interpretation_overflow": true + }, + "MisraC2012Directive-4.10": { + "_active": true + }, + "MisraC2012Directive-4.11": { + "_active": true + }, + "MisraC2012Directive-4.12": { + "_active": true + }, + "MisraC2012Directive-4.13": { + "_active": true + }, + "MisraC2012Directive-4.14": { + "_active": true, + "external_sources": { + "return_values_of": { + "excluded": { + "$(delta:+)": [ + "__curpc", + "abs", + "labs", + "llabs", + "fminf", + "fabsf" + ] + } + } + } + }, + "MisraC2012Directive-4.2": { + "_active": true + }, + "MisraC2012Directive-4.3": { + "_active": true + }, + "MisraC2012Directive-4.4": { + "_active": true + }, + "MisraC2012Directive-4.5": { + "_active": true + }, + "MisraC2012Directive-4.6": { + "_active": true, + "allow_floating_point": true + }, + "MisraC2012Directive-4.7": { + "_active": true + }, + "MisraC2012Directive-4.8": { + "_active": true, + "excludes": { + "$(delta:+)": [ + "src/app/engine/config/database_cfg.h" + ] + } + }, + "MisraC2012Directive-4.9": { + "_active": true + }, + "Parallelism-IncorrectCriticalRegion": { + "_active": true, + "enter_critical_functions": [ + "OS_EnterTaskCritical" + ], + "exit_critical_functions": [ + "OS_ExitTaskCritical" + ] + }, + "Parallelism-UnsafeVarAccess": { + "_active": true, + "enter_critical_functions": [ + "OS_EnterTaskCritical" + ], + "exit_critical_functions": [ + "OS_ExitTaskCritical" + ], + "inspect_pointers": true, + "strict_priorities": true + }, + "SaveRFG": { + "_active": true + }, + "StaticSemanticAnalysis": { + "_active": true, + "callgraph_options": { + "use_full_pointer_analysis": true + }, + "global_classic_options": { + "abstract_interpretation": true + } + } + }, + "_Format": "1.0", + "_Version": "7.2.0", + "_VersionNum": [ + 7, + 2, + 0, + 7204 + ] +} diff --git a/tests/axivion/rule_config_c.py b/tests/axivion/rule_config_c.py new file mode 100644 index 00000000..0abb9102 --- /dev/null +++ b/tests/axivion/rule_config_c.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# We kindly request you to use one or more of the following phrases to refer to +# foxBMS in your hardware, software, documentation or advertising materials: +# +# - "This product uses parts of foxBMS®" +# - "This product includes parts of foxBMS®" +# - "This product is derived from foxBMS®" + +"""Axivion rules configured for the foxBMS 2 project.""" + +import axivion.config # pylint: disable=import-error + +analysis = axivion.config.get_analysis() + +analysis["Generic-LocalInclude"].msg["add_include"].disabled = True +analysis["Generic-LocalInclude"].msg["add_symbol_declaration"].disabled = True +analysis["Generic-LocalInclude"].msg["bad_pch_use"].disabled = True +analysis["Generic-LocalInclude"].msg["circular_include"].disabled = False +analysis["Generic-LocalInclude"].msg["contents_covered_include"].disabled = True +analysis["Generic-LocalInclude"].msg["covered_include"].disabled = True +analysis["Generic-LocalInclude"].msg["local_decl_instead_of_include"].disabled = True +analysis["Generic-LocalInclude"].msg["local_def_instead_of_include"].disabled = True +analysis["Generic-LocalInclude"].msg["more_precise_include"].disabled = True +analysis["Generic-LocalInclude"].msg["move_include"].disabled = True +analysis["Generic-LocalInclude"].msg["move_include_with_many_clients"].disabled = True +analysis["Generic-LocalInclude"].msg["unused_include"].disabled = False + +analysis["Generic-ForbiddenFunctions"].blacklist = { + "stdlib.h": ["malloc", "free", "calloc", "realloc"], + "stdio.h": ["*printf*"], + "string.h": ["str[!n]*"], +} + +analysis["Parallelism-UnsafeVarAccess"].partitions = { + "TaskEngine": { + "entries": ["FTSK_CreateTaskEngine"], + "priority": 9, + }, + "Task1ms": { + "entries": ["FTSK_CreateTaskCyclic1ms"], + "priority": 6, + }, + "Task10ms": { + "entries": ["FTSK_CreateTaskCyclic10ms"], + "priority": 5, + }, + "Task100ms": { + "entries": ["FTSK_CreateTaskCyclic100ms"], + "priority": 4, + }, + "Task_100ms_Algorithm": { + "entries": ["FTSK_CreateTaskCyclicAlgorithm100ms"], + "priority": 3, + }, +} diff --git a/tests/axivion/rule_config_names.json b/tests/axivion/rule_config_names.json new file mode 100644 index 00000000..a6de8896 --- /dev/null +++ b/tests/axivion/rule_config_names.json @@ -0,0 +1,67 @@ +{ + "Analysis": { + "CodingStyle-Naming.Function": { + "_active": true, + "msg": { + "non_compliant_name": { + "text": "Function names shall use the naming convention (prefix.upper())_PascalCase." + } + }, + "naming_convention": "^[A-Z][A-Z0-9]{1,4}_([A-Z][a-z0-9]+)*[A-Z][a-z0-9]*$" + }, + "CodingStyle-Naming.GlobalVariable": { + "_active": true, + "msg": { + "non_compliant_name": { + "text": "Names of global variables shall use the naming convention (prefix.lower())_camelCase." + } + }, + "naming_convention": "[a-z]+_[a-z0-9]([a-z0-9]*[A-Z0-9]*[a-z0-9]+)*(_[umd]?([AKVs]|perc|degC))?" + }, + "CodingStyle-Naming.LocalVariable": { + "_active": true, + "msg": { + "non_compliant_name": { + "text": "Names of local variables shall use the naming convention (prefix.lower())_camelCase." + } + }, + "naming_convention": "[a-z0-9]([a-z0-9]*[A-Z0-9]*[a-z0-9]+)*(_[umd]?([AKVs]|perc|degC))?" + }, + "CodingStyle-Naming.Macro": { + "_active": true, + "msg": { + "non_compliant_name": { + "text": "Macro names shall use the naming convention (prefix.upper())_ALL_CAPS." + } + }, + "naming_convention": "[A-Z][A-Z0-9]{1,4}_[A-Z0-9]([A-Z0-9_]*)[A-Z0-9](_[umd]?([AKVs]|perc|degC))?" + }, + "CodingStyle-Naming.TypedefedEnum": { + "_active": true, + "_copy_from": "CodingStyle-Naming.UserType", + "apply_to_renaming_of_classes": false, + "apply_to_renaming_of_structs": false, + "apply_to_renaming_of_unions": false, + "msg": { + "non_compliant_name": { + "text": "Names of user-defined enum types shall use the naming convention (prefix.upper())_ALL_CAPS_e." + } + }, + "naming_convention": "^[A-Z][A-Z0-9]{1,4}_([A-Z0-9_]*)_e" + }, + "CodingStyle-Naming.TypedefedStruct": { + "_active": true, + "_copy_from": "CodingStyle-Naming.UserType", + "apply_to_renaming_of_classes": false, + "apply_to_renaming_of_enums": false, + "apply_to_renaming_of_unions": false, + "msg": { + "non_compliant_name": { + "text": "Names of user-defined struct types shall use the naming convention (prefix.upper())_ALL_CAPS_s." + } + }, + "naming_convention": "^[A-Z][A-Z0-9]{1,4}_([A-Z0-9_]*)_s" + } + }, + "_Format": "1.0" +} diff --git a/tests/axivion/rule_config_names.py b/tests/axivion/rule_config_names.py new file mode 100644 index 00000000..e0a81b9b --- /dev/null +++ b/tests/axivion/rule_config_names.py @@ -0,0 +1,176 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# We kindly request you to use one or more of the following phrases to refer to +# foxBMS in your hardware, software, documentation or advertising materials: +# +# - "This product uses parts of foxBMS®" +# - "This product includes parts of foxBMS®" +# - "This product is derived from foxBMS®" + +"""foxBMS specific rules settings for Axivion analysis.""" + +import pathlib +import re + +import axivion.config # pylint: disable=import-error + +from bauhaus import ir # pylint: disable=import-error +from bauhaus import style # pylint: disable=import-error +from bauhaus.ir.common.scanner import comments # pylint: disable=import-error + + +ANALYSIS = axivion.config.get_analysis() + + +def get_rule_type_from_name(rule_name: str) -> str: + """returns the rule in a nicer human readable format.""" + cs_type_name = re.sub( + r"([A-Z])", r" \1", rule_name.rsplit(".", maxsplit=1)[-1] + ).split() + return " ".join([i.lower() for i in cs_type_name]) + + +@style.workitem(inputs=(ir.Graph, comments.scan_and_cache_comments), repeat=True) +class ModulePrefixLookup(style.WorkItem): + """Fetches the module prefix based on a regex from the provided source file + + hint: check that this regex is consistent with + 'conf/guidelines/rules.json:languages:C:doxygen:regex:{xy}' + setting + """ + + prefix_re = re.compile(r"@prefix\s+(\S+)(?:\s|\n|$)", flags=re.MULTILINE) + + # pylint: disable=too-many-nested-blocks + def __init__(self, ir_graph, cached_comments): + self._map = dict() + for file_node in ir_graph.nodes_of_type(ir.Physical, "Primary_File"): + for comment in cached_comments.get(file_node, ()): + if not comment.at_beginning: + break + match = self.prefix_re.search(comment.Value) + if match: + self._map[file_node] = match[1] + break + header_mapping = [] + for user_file, prefix in self._map.items(): + user_stem = pathlib.Path(user_file.Full_Name).stem + for user_contents in user_file.Versions: + for include in user_contents.Sorted_Includes: + if include.is_of_type("Include_Declaration"): + # filter out irregular includes + included_file = include.Contents.enclosing_of_type( + "User_Include_File" + ) + if included_file: + # filter out all except user include files + if pathlib.Path(included_file.Full_Name).stem == user_stem: + header_mapping.append((included_file, prefix)) + self._map.update(header_mapping) + + def __contains__(self, item): + return item in self._map + + def __getitem__(self, item): + return self._map[item] + + +def containing_modules(node): + """yields the file""" + nodes = node.Definitions + # if no definitions available, go for the declartions + if len(node.Definitions) == 0: + # use declarations if aviable, otherwise fallback + if len(node.Declarations): + nodes = node.Declarations + else: + nodes = (node.Physical,) + + for pir_node in nodes: + if pir_node: + file = pir_node.enclosing_of_type("File") + if file: + yield file + + +def check_lowercase_prefix(node: ir.Node, module_prefixes: ModulePrefixLookup) -> bool: + """check that node starts with the lower-case module prefixed followed by + an underscore.""" + if node.Name: + for file in containing_modules(node): + if file in module_prefixes: + if not node.Name.startswith(module_prefixes[file].lower() + "_"): + return False + return True + + +def check_uppercase_prefix(node: ir.Node, module_prefixes: ModulePrefixLookup) -> bool: + """check that node starts with the upper-case module prefixed followed by + an underscore.""" + if node.Name: + for file in containing_modules(node): + if file in module_prefixes: + if not node.Name.startswith(module_prefixes[file].upper() + "_"): + return False + return True + + +#: list: List of things that MUST start with the upper-case module prefix +upper_case = ( + "CodingStyle-Naming.Function", + "CodingStyle-Naming.Macro", + "CodingStyle-Naming.TypedefedEnum", + "CodingStyle-Naming.TypedefedStruct", +) + +for name in upper_case: + ANALYSIS[name].additional_checks.append( + ( + check_uppercase_prefix, + f"Please use upper-case module prefix for {get_rule_type_from_name(name)}.", + ) + ) + +#: list: List of things that MUST start with the lower-case module prefix +lower_case = ( + "CodingStyle-Naming.GlobalVariable", + "CodingStyle-Naming.LocalVariable", +) +for name in lower_case: + ANALYSIS[name].additional_checks.append( + ( + check_lowercase_prefix, + f"Please use lower-case module prefix for {get_rule_type_from_name(name)}.", + ) + ) diff --git a/tests/axivion/start_analysis.bat b/tests/axivion/start_analysis.bat new file mode 100644 index 00000000..262667d0 --- /dev/null +++ b/tests/axivion/start_analysis.bat @@ -0,0 +1,52 @@ +@REM Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +@REM All rights reserved. +@REM +@REM SPDX-License-Identifier: BSD-3-Clause +@REM +@REM Redistribution and use in source and binary forms, with or without +@REM modification, are permitted provided that the following conditions are met: +@REM +@REM 1. Redistributions of source code must retain the above copyright notice, this +@REM list of conditions and the following disclaimer. +@REM +@REM 2. Redistributions in binary form must reproduce the above copyright notice, +@REM this list of conditions and the following disclaimer in the documentation +@REM and/or other materials provided with the distribution. +@REM +@REM 3. Neither the name of the copyright holder nor the names of its +@REM contributors may be used to endorse or promote products derived from +@REM this software without specific prior written permission. +@REM +@REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +@REM AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +@REM IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +@REM DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +@REM FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +@REM DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +@REM SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +@REM CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +@REM OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +@REM OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +@REM +@REM We kindly request you to use one or more of the following phrases to refer to +@REM foxBMS in your hardware, software, documentation or advertising materials: +@REM +@REM - "This product uses parts of foxBMS®" +@REM - "This product includes parts of foxBMS®" +@REM - "This product is derived from foxBMS®" + +@SETLOCAL EnableExtensions EnableDelayedExpansion + +@IF DEFINED AXIVION_LOCAL_BUILD ( + set SKIP_PREBUILD_CLEAN=%AXIVION_LOCAL_BUILD% +) +@IF DEFINED AXIVION_INCREMENTAL_BUILD ( + set SKIP_POSTBUILD_CLEAN=%AXIVION_INCREMENTAL_BUILD% +) + +@if NOT DEFINED REQUESTS_CA_BUNDLE ( + @SET REQUESTS_CA_BUNDLE=\\axivion-dash\Axivion_share\dashboard\config\cert\auto.crt +) + +@SET BAUHAUS_CONFIG=%~dp0 +@axivion_ci diff --git a/tests/axivion/start_local_analysis.bat b/tests/axivion/start_local_analysis.bat new file mode 100644 index 00000000..a495853c --- /dev/null +++ b/tests/axivion/start_local_analysis.bat @@ -0,0 +1,43 @@ +@REM Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +@REM All rights reserved. +@REM +@REM SPDX-License-Identifier: BSD-3-Clause +@REM +@REM Redistribution and use in source and binary forms, with or without +@REM modification, are permitted provided that the following conditions are met: +@REM +@REM 1. Redistributions of source code must retain the above copyright notice, this +@REM list of conditions and the following disclaimer. +@REM +@REM 2. Redistributions in binary form must reproduce the above copyright notice, +@REM this list of conditions and the following disclaimer in the documentation +@REM and/or other materials provided with the distribution. +@REM +@REM 3. Neither the name of the copyright holder nor the names of its +@REM contributors may be used to endorse or promote products derived from +@REM this software without specific prior written permission. +@REM +@REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +@REM AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +@REM IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +@REM DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +@REM FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +@REM DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +@REM SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +@REM CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +@REM OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +@REM OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +@REM +@REM We kindly request you to use one or more of the following phrases to refer to +@REM foxBMS in your hardware, software, documentation or advertising materials: +@REM +@REM - "This product uses parts of foxBMS®" +@REM - "This product includes parts of foxBMS®" +@REM - "This product is derived from foxBMS®" + +@SETLOCAL EnableExtensions EnableDelayedExpansion + +@set AXIVION=TRUE +@set AXIVION_LOCAL_BUILD=TRUE +@set REQUESTS_CA_BUNDLE=%USERPROFILE%\.bauhaus\auto.crt +@call %~dp0start_analysis.bat diff --git a/tests/axivion/start_local_analysis.sh b/tests/axivion/start_local_analysis.sh new file mode 100644 index 00000000..2113f6c1 --- /dev/null +++ b/tests/axivion/start_local_analysis.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# We kindly request you to use one or more of the following phrases to refer to +# foxBMS in your hardware, software, documentation or advertising materials: +# +# - "This product uses parts of foxBMS®" +# - "This product includes parts of foxBMS®" +# - "This product is derived from foxBMS®" + +set -e + +echo "Axivion currently only supported through cmd.exe." diff --git a/tests/axivion/start_local_dashserver.bat b/tests/axivion/start_local_dashserver.bat new file mode 100644 index 00000000..dad78921 --- /dev/null +++ b/tests/axivion/start_local_dashserver.bat @@ -0,0 +1,40 @@ +@REM Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +@REM All rights reserved. +@REM +@REM SPDX-License-Identifier: BSD-3-Clause +@REM +@REM Redistribution and use in source and binary forms, with or without +@REM modification, are permitted provided that the following conditions are met: +@REM +@REM 1. Redistributions of source code must retain the above copyright notice, this +@REM list of conditions and the following disclaimer. +@REM +@REM 2. Redistributions in binary form must reproduce the above copyright notice, +@REM this list of conditions and the following disclaimer in the documentation +@REM and/or other materials provided with the distribution. +@REM +@REM 3. Neither the name of the copyright holder nor the names of its +@REM contributors may be used to endorse or promote products derived from +@REM this software without specific prior written permission. +@REM +@REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +@REM AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +@REM IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +@REM DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +@REM FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +@REM DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +@REM SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +@REM CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +@REM OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +@REM OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +@REM +@REM We kindly request you to use one or more of the following phrases to refer to +@REM foxBMS in your hardware, software, documentation or advertising materials: +@REM +@REM - "This product uses parts of foxBMS®" +@REM - "This product includes parts of foxBMS®" +@REM - "This product is derived from foxBMS®" + +@SETLOCAL EnableExtensions EnableDelayedExpansion + +dashserver start --local --noauth --install_file=%USERPROFILE%\.bauhaus\localbuild\projects\foxbms-2.db diff --git a/tests/axivion/wrapper_make_race_pdfs.bat b/tests/axivion/wrapper_make_race_pdfs.bat new file mode 100644 index 00000000..02e922e3 --- /dev/null +++ b/tests/axivion/wrapper_make_race_pdfs.bat @@ -0,0 +1,42 @@ +@REM Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +@REM All rights reserved. +@REM +@REM SPDX-License-Identifier: BSD-3-Clause +@REM +@REM Redistribution and use in source and binary forms, with or without +@REM modification, are permitted provided that the following conditions are met: +@REM +@REM 1. Redistributions of source code must retain the above copyright notice, this +@REM list of conditions and the following disclaimer. +@REM +@REM 2. Redistributions in binary form must reproduce the above copyright notice, +@REM this list of conditions and the following disclaimer in the documentation +@REM and/or other materials provided with the distribution. +@REM +@REM 3. Neither the name of the copyright holder nor the names of its +@REM contributors may be used to endorse or promote products derived from +@REM this software without specific prior written permission. +@REM +@REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +@REM AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +@REM IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +@REM DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +@REM FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +@REM DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +@REM SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +@REM CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +@REM OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +@REM OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +@REM +@REM We kindly request you to use one or more of the following phrases to refer to +@REM foxBMS in your hardware, software, documentation or advertising materials: +@REM +@REM - "This product uses parts of foxBMS®" +@REM - "This product includes parts of foxBMS®" +@REM - "This product is derived from foxBMS®" + +@SETLOCAL EnableExtensions EnableDelayedExpansion + +@SET BAUHAUS_CONFIG=%~dp0 +@SET PATH=%PATH%;C:\Bauhaus\7.2.0\doc\html\_downloads\309ace4c1e28cca5a965200324624eec +@call make_race_pdfs.bat %USERPROFILE%\.bauhaus\localbuild\projects\foxbms-2.ir %USERPROFILE%\.bauhaus\localbuild\projects\foxbms-2.rfg diff --git a/tests/re-names/README.md b/tests/re-names/README.md new file mode 100644 index 00000000..ae000526 --- /dev/null +++ b/tests/re-names/README.md @@ -0,0 +1,16 @@ +# Unit Tests for Guidelines + +Tests to verify that the regular expressions that are used to check function +names etc. are indeed correct. + +## Running the Test + +``` +C:\Users\vulpes\Documents\foxbms-2>tools\utils\cmd\run-python-script.bat .\tests\re-names\test_names_regex.py +``` + +## Adding Tests + +If a function, variable etc. is found in code by manual review, that did not +get mentioned in the Axivion report, then the regex for that case needs to to +fixed and this name should be added to the test case of the respective case. diff --git a/tests/re-names/function.json b/tests/re-names/function.json new file mode 100644 index 00000000..256d9144 --- /dev/null +++ b/tests/re-names/function.json @@ -0,0 +1,37 @@ +{ + "valid": [ + "ABC_A", + "ABC_Az", + "ABC_A1", + "ABC_Function", + "ABC_Function0", + "ABC_MyFunction", + "ABC_MyOtherFunction", + "ABC_MyOther0Function", + "ABC_MyOtherFunction0" + ], + "invalid": [ + "_", + "_01", + "_ab", + "a", + "ABC", + "ABC_", + "PREFIXONLY", + "PREFIXBUTNOUNDERSCORE", + "noprefix", + "lowercaseprefix_function", + "abc_function", + "abc_function0", + "abc_myfunction", + "abc_myotherfunction", + "abc_myother0function", + "abc_myotherfunction0", + "abc_function_s", + "abc_function_perc", + "abc_myfunction_perc", + "abc_myotherfunction_perc", + "abc_my0otherfunction_perc", + "abc_my0otherfunction1_perc" + ] +} diff --git a/tests/re-names/global-variable.json b/tests/re-names/global-variable.json new file mode 100644 index 00000000..0728c6d9 --- /dev/null +++ b/tests/re-names/global-variable.json @@ -0,0 +1,47 @@ +{ + "valid": [ + "abc_my", + "abc_my_ddegC", + "abc_myVar", + "abc_myVar1", + "abc_my1Var1", + "abc_myVar1Var", + "abc_myVar1Var1", + "abc_myVar1_mA", + "abc_myVar1_K", + "abc_myVar1_perc", + "abc_myVar1_degC", + "abc_myVar1_ddegC", + "abc_myVar1_uV" + ], + "invalid": [ + "_", + "myVar_", + "myVar", + "myVar1", + "my1Var1", + "myVar1Var", + "myVar1Var1", + "MyVar", + "MyVar1", + "My1Var1", + "MyVar1Var", + "MyVar1Var1", + "ABC_myVar", + "ABC_myVar1", + "ABC_my1Var1", + "ABC_myVar1Var", + "ABC_myVar1Var1", + "Abc_myVar", + "Abc_myVar1", + "Abc_my1Var1", + "Abc_myVar1Var", + "Abc_myVar1Var1", + "aBc_myVar", + "aBc_myVar1", + "aBc_my1Var1", + "aBc_myVar1Var", + "aBc_myVar1Var1", + "abc_myVar_" + ] +} diff --git a/tests/re-names/local-variable.json b/tests/re-names/local-variable.json new file mode 100644 index 00000000..40b4fce9 --- /dev/null +++ b/tests/re-names/local-variable.json @@ -0,0 +1,28 @@ +{ + "valid": [ + "my", + "my_ddegC", + "myVar", + "myVar1", + "my1Var1", + "myVar1Var", + "myVar1Var1", + "myVar1_mA", + "myVar1_K", + "myVar1_s", + "myVar1_ms", + "myVar1_perc", + "myVar1_degC", + "myVar1_ddegC", + "myVar1_uV" + ], + "invalid": [ + "_", + "myVar_", + "MyVar", + "MyVar1", + "My1Var1", + "MyVar1Var", + "MyVar1Var1" + ] +} diff --git a/tests/re-names/macro.json b/tests/re-names/macro.json new file mode 100644 index 00000000..af50c2f3 --- /dev/null +++ b/tests/re-names/macro.json @@ -0,0 +1,22 @@ +{ + "valid": [ + "ABC_ABC", + "ABC_A123", + "ABC_123", + "ABC_123_12", + "ABC_123_AB", + "ABC_123_AB_mV", + "ABC_123_AB_perc" + ], + "invalid": [ + "_ABC", + "_ABC_", + "_abc", + "_abc_", + "abc", + "abc_", + "ABC_", + "ABC_abc", + "ABC_ABC_123_" + ] +} diff --git a/tests/re-names/test_names_regex.py b/tests/re-names/test_names_regex.py new file mode 100644 index 00000000..b5a49da4 --- /dev/null +++ b/tests/re-names/test_names_regex.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# We kindly request you to use one or more of the following phrases to refer to +# foxBMS in your hardware, software, documentation or advertising materials: +# +# - "This product uses parts of foxBMS®" +# - "This product includes parts of foxBMS®" +# - "This product is derived from foxBMS®" + +"""Test regular expressions that are used to validate function, variable etc. +names in the Axivion analysis.""" + +import json +import os +import re +import sys +import unittest +from pathlib import Path + + +class TestNamingConventionRegularExpressions(unittest.TestCase): + """Unit tests for foxBMS regular expressions for names in the embedded code""" + + test_files_to_rules = { + "function": "CodingStyle-Naming.Function", + "global-variable": "CodingStyle-Naming.GlobalVariable", + "local-variable": "CodingStyle-Naming.LocalVariable", + "macro": "CodingStyle-Naming.Macro", + "typedefed-enum": "CodingStyle-Naming.TypedefedEnum", + "typedefed-struct": "CodingStyle-Naming.TypedefedStruct", + } + + def __init__(self, *args, **kwargs) -> None: + super().__init__(*args, **kwargs) + self.script_root = Path(os.path.abspath(os.path.dirname(__file__))) + self.axivion_dir = ( + Path(os.path.abspath(os.path.dirname(__file__))).parent / "axivion" + ) + self.axivion_config = self._load_ax_config() + + def _load_ax_config(self) -> dict: + """validates and returns the Axivion configuration as dict.""" + try: + ax_config = (self.axivion_dir / "rule_config_names.json").read_text() + except FileNotFoundError: + sys.exit("Could not find Axivion configuration.") + try: + tmp = json.loads(ax_config) + except json.decoder.JSONDecodeError: + sys.exit("Provided Axivion configuration is not a valid json file.") + assert tmp["_Format"] == "1.0", "Expected format version '1.0'." + + if not tmp.get("Analysis", None): + sys.exit("Could not find 'Analysis section'.") + + return tmp["Analysis"] + + def _load_test(self, test_name: str) -> dict: + """returns the test as dict.""" + test_config = (self.script_root / test_name).read_text() + return json.loads(test_config) + + def _run_test(self, test, test_config, test_re): + """Checks the regex against the machting and not-matching test cases.""" + # Axivion uses 'fullmatch', therefore we need to test it the same way + msg = ( + f"Checking that '{self.test_files_to_rules[test.stem]}: " + f"'{test_re.pattern}' DOES %s match '%s'." + ) + for i in test_config["valid"]: + m = test_re.fullmatch(i) + found = False + if m: + found = True + with self.subTest(msg=" ".join((msg % ("", i)).split())): + self.assertEqual(found, True) + for i in test_config["invalid"]: + m = test_re.fullmatch(i) + found = False + if m: + found = True + with self.subTest(msg=msg % ("NOT", i)): + self.assertEqual(found, False) + + def test_naming_regexes(self): + """Tests for the naming rules regular expressions.""" + for i in self.script_root.glob("*.json"): + test_config = self._load_test(i.resolve()) + rule = self.test_files_to_rules[i.stem] + test_re = re.compile(self.axivion_config[rule]["naming_convention"]) + self._run_test(i, test_config, test_re) + + +def main(): + """Gets the test and runs them through python's unit test module.""" + unittest.main() + + +if __name__ == "__main__": + main() diff --git a/tests/re-names/typedefed-enum.json b/tests/re-names/typedefed-enum.json new file mode 100644 index 00000000..7ddbc0c1 --- /dev/null +++ b/tests/re-names/typedefed-enum.json @@ -0,0 +1,24 @@ +{ + "valid": [ + "ABC_ABC_e", + "ABC_A123_e", + "ABC_123_e", + "ABC_123_12_e", + "ABC_123_AB_e" + ], + "invalid": [ + "_ABC", + "_ABC_", + "_abc", + "_abc_", + "abc", + "abc_", + "ABC_", + "ABC_abc", + "ABC_ABC_123_", + "ABC_E", + "ABC_Ge", + "ABC_ABC_s", + "ABC_e" + ] +} diff --git a/tests/re-names/typedefed-struct.json b/tests/re-names/typedefed-struct.json new file mode 100644 index 00000000..3c482f41 --- /dev/null +++ b/tests/re-names/typedefed-struct.json @@ -0,0 +1,24 @@ +{ + "valid": [ + "ABC_ABC_s", + "ABC_A123_s", + "ABC_123_s", + "ABC_123_12_s", + "ABC_123_AB_s" + ], + "invalid": [ + "_ABC", + "_ABC_", + "_abc", + "_abc_", + "abc", + "abc_", + "ABC_", + "ABC_abc", + "ABC_ABC_123_", + "ABC_S", + "ABC_ms", + "ABC_ABC_e", + "ABC_s" + ] +} diff --git a/tests/unit/app/driver/foxmath/test_foxmath.c b/tests/unit/app/driver/foxmath/test_foxmath.c index ebd561dd..c1a1af48 100644 --- a/tests/unit/app/driver/foxmath/test_foxmath.c +++ b/tests/unit/app/driver/foxmath/test_foxmath.c @@ -43,7 +43,7 @@ * @file test_foxmath.c * @author foxBMS Team * @date 2020-04-01 (date of creation) - * @updated 2020-07-15 (date of last update) + * @updated 2021-08-06 (date of last update) * @ingroup UNIT_TEST_IMPLEMENTATION * @prefix TEST * @@ -84,61 +84,61 @@ void tearDown(void) { /*========== Test Cases =====================================================*/ void test_linearInterpolation_X1EqualsX2() { coord_x1 = coord_x2; - TEST_ASSERT_EQUAL(coord_y1, MATH_linearInterpolation(coord_x1, coord_y1, coord_x2, coord_y2, coord_x_interpolate)); + TEST_ASSERT_EQUAL(coord_y1, MATH_LinearInterpolation(coord_x1, coord_y1, coord_x2, coord_y2, coord_x_interpolate)); } void test_linearInterpolation_interpolateBetweenX1AndX2() { - TEST_ASSERT_EQUAL(75.0f, MATH_linearInterpolation(10.f, 50.f, 20.f, 100.f, 15.f)); - TEST_ASSERT_EQUAL(87.0f, MATH_linearInterpolation(10.f, 50.f, 20.f, 100.f, 17.5f)); - TEST_ASSERT_EQUAL(50.0f, MATH_linearInterpolation(10.f, 50.f, 20.f, 100.f, 10.0001f)); + TEST_ASSERT_EQUAL(75.0f, MATH_LinearInterpolation(10.f, 50.f, 20.f, 100.f, 15.f)); + TEST_ASSERT_EQUAL(87.0f, MATH_LinearInterpolation(10.f, 50.f, 20.f, 100.f, 17.5f)); + TEST_ASSERT_EQUAL(50.0f, MATH_LinearInterpolation(10.f, 50.f, 20.f, 100.f, 10.0001f)); } void test_linearInterpolation_extrapolateFromX1AndX2() { - TEST_ASSERT_EQUAL(100.0f, MATH_linearInterpolation(10.f, 50.f, 20.f, 100.f, 20.1f)); - TEST_ASSERT_EQUAL(-100.0f, MATH_linearInterpolation(10.f, 50.f, 20.f, 100.f, -20.f)); - TEST_ASSERT_EQUAL(16739465.0f, MATH_linearInterpolation(10.f, 50.f, 20.f, 100.f, 3347893.0f)); + TEST_ASSERT_EQUAL(100.0f, MATH_LinearInterpolation(10.f, 50.f, 20.f, 100.f, 20.1f)); + TEST_ASSERT_EQUAL(-100.0f, MATH_LinearInterpolation(10.f, 50.f, 20.f, 100.f, -20.f)); + TEST_ASSERT_EQUAL(16739465.0f, MATH_LinearInterpolation(10.f, 50.f, 20.f, 100.f, 3347893.0f)); } void test_allZeros_swap16(void) { - TEST_ASSERT_EQUAL(0u, MATH_swapBytes_uint16_t(val16)); + TEST_ASSERT_EQUAL(0u, MATH_SwapBytesUint16_t(val16)); } void test_allZeros_swap32(void) { - TEST_ASSERT_EQUAL(0u, MATH_swapBytes_uint32_t(val32)); + TEST_ASSERT_EQUAL(0u, MATH_SwapBytesUint32_t(val32)); } void test_allZeros_swap64(void) { - TEST_ASSERT_EQUAL(0u, MATH_swapBytes_uint64_t(val64)); + TEST_ASSERT_EQUAL(0u, MATH_SwapBytesUint64_t(val64)); } void test_swap16(void) { val16 = 786u; /* any random value */ - TEST_ASSERT_EQUAL(4611u, MATH_swapBytes_uint16_t(val16)); + TEST_ASSERT_EQUAL(4611u, MATH_SwapBytesUint16_t(val16)); } void test_swap32(void) { val32 = 0xFFFF0000u; /* any random value */ - TEST_ASSERT_EQUAL(0x0000FFFFu, MATH_swapBytes_uint32_t(val32)); + TEST_ASSERT_EQUAL(0x0000FFFFu, MATH_SwapBytesUint32_t(val32)); } void test_swap64(void) { val64 = 123u; /* 0x007B */ - TEST_ASSERT_EQUAL(0x7B00000000000000u, MATH_swapBytes_uint64_t(val64)); + TEST_ASSERT_EQUAL(0x7B00000000000000u, MATH_SwapBytesUint64_t(val64)); } void test_swap16_MAX(void) { val16 = UINT16_MAX; - TEST_ASSERT_EQUAL(UINT16_MAX, MATH_swapBytes_uint16_t(val16)); + TEST_ASSERT_EQUAL(UINT16_MAX, MATH_SwapBytesUint16_t(val16)); } void test_swap32_MAX(void) { val32 = UINT32_MAX; - TEST_ASSERT_EQUAL(UINT32_MAX, MATH_swapBytes_uint32_t(val32)); + TEST_ASSERT_EQUAL(UINT32_MAX, MATH_SwapBytesUint32_t(val32)); } void test_swap64_MAX(void) { val64 = UINT64_MAX; - TEST_ASSERT_EQUAL(UINT64_MAX, MATH_swapBytes_uint64_t(val64)); + TEST_ASSERT_EQUAL(UINT64_MAX, MATH_SwapBytesUint64_t(val64)); } void test_minimumOfTwoFloats(void) { diff --git a/tests/variants/lib-build/README.md b/tests/variants/lib-build/README.md new file mode 100644 index 00000000..f43e0ddf --- /dev/null +++ b/tests/variants/lib-build/README.md @@ -0,0 +1,7 @@ +# Library Test Build + +To run the library build test helper script ``lib-build.bat``, ``PowerShell`` +and ``tar`` need to be available in PATH. +PowerShell should be available by default and ``tar`` is available e.g., in +*Git for Windows* at ``GIT_INSTALL_DIR/usr/bin`` +(prepend to PATH if not available). diff --git a/tests/variants/lib-build/lib-build.bat b/tests/variants/lib-build/lib-build.bat new file mode 100644 index 00000000..473d0c05 --- /dev/null +++ b/tests/variants/lib-build/lib-build.bat @@ -0,0 +1,101 @@ +@REM Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +@REM All rights reserved. +@REM +@REM SPDX-License-Identifier: BSD-3-Clause +@REM +@REM Redistribution and use in source and binary forms, with or without +@REM modification, are permitted provided that the following conditions are met: +@REM +@REM 1. Redistributions of source code must retain the above copyright notice, this +@REM list of conditions and the following disclaimer. +@REM +@REM 2. Redistributions in binary form must reproduce the above copyright notice, +@REM this list of conditions and the following disclaimer in the documentation +@REM and/or other materials provided with the distribution. +@REM +@REM 3. Neither the name of the copyright holder nor the names of its +@REM contributors may be used to endorse or promote products derived from +@REM this software without specific prior written permission. +@REM +@REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +@REM AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +@REM IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +@REM DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +@REM FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +@REM DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +@REM SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +@REM CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +@REM OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +@REM OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +@REM +@REM We kindly request you to use one or more of the following phrases to refer to +@REM foxBMS in your hardware, software, documentation or advertising materials: +@REM +@REM - "This product uses parts of foxBMS®" +@REM - "This product includes parts of foxBMS®" +@REM - "This product is derived from foxBMS®" + +@SETLOCAL EnableExtensions EnableDelayedExpansion + +@REM This scripts works only when foxBMS 2 is developed inside a git repository + + +@FOR /F "tokens=* USEBACKQ" %%F IN (`git rev-parse --show-toplevel`) DO @( + @SET REPO_ROOT=%%F +) + +@REM go the repository root +@cd %REPO_ROOT% + +@call waf.bat bootstrap_library_project -v -c yes +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) + +@mkdir libbuild + +@tar -jxf library-project.tar.bz2 --directory libbuild +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) + +@REM Build the library +@cd libbuild +@CALL waf.bat configure build -v -c yes +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) +@cd .. + +@REM Copy file that includes the library header and uses a function from it +@copy /y tests\variants\lib-build\lib-build_cc-options.yaml conf\cc\cc-options.yaml +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) +@copy /y tests\variants\lib-build\lib-build_main.c src\app\main\main.c +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) + +@REM Fix doxygen comment +@Powershell.exe -Command "((Get-Content -path .\src\app\main\main.c -Raw) -replace '@file lib-build_main.c','@file main.c') | Set-Content -NoNewline -Path .\src\app\main\main.c" +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) + +@REM Fix library and header path +@Powershell.exe -Command "((Get-Content -path .\conf\cc\cc-options.yaml -Raw) -replace 'REPO_ROOT', $env:REPO_ROOT) | Set-Content -NoNewline -Path .\conf\cc\cc-options.yaml" +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) + +@REM Build the library +@CALL waf.bat configure -v -c yes +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) + +@CALL waf.bat build_bin -v -c yes +@IF %ERRORLEVEL% NEQ 0 ( + @EXIT /b %ERRORLEVEL% +) diff --git a/tests/variants/lib-build/lib-build_cc-options.yaml b/tests/variants/lib-build/lib-build_cc-options.yaml index 282fe08e..347fd95d 100644 --- a/tests/variants/lib-build/lib-build_cc-options.yaml +++ b/tests/variants/lib-build/lib-build_cc-options.yaml @@ -35,14 +35,21 @@ # - "This product includes parts of foxBMS®" # - "This product is derived from foxBMS®" +# REPO_ROOT will be correctly set when using the batch script for that test: +# tests/variants/lib-build/lib-build.bat +# This batch script requires +# - PowerShell available in Path. +# - tar available in Path. Tar is shipped in git for Windows at +# GIT_INSTALL_DIR/usr/bin + INCLUDE_PATHS: win32: - - C:\GitLab-Runner\builds\foxbms-on-tms570\libbuild\src + - REPO_ROOT\libbuild\src linux: LIBRARY_PATHS: win32: - - C:\GitLab-Runner\builds\foxbms-on-tms570\libbuild\build + - REPO_ROOT\libbuild\build linux: LIBRARIES: diff --git a/tools/deploy/deploy_internal_server.sh b/tools/deploy/deploy_internal_server.sh index 8f4ff01d..a439d5f1 100644 --- a/tools/deploy/deploy_internal_server.sh +++ b/tools/deploy/deploy_internal_server.sh @@ -49,9 +49,9 @@ COV_ARTIFACT='build/unit_test/artifacts/gcov/.' NAME_COV_SCRIPT_DEPLOY_JOB='cov_script_report_deployment' DIR_COV_SCRIPT_DEPLOY='cov_script' COV_SCRIPT_ARTIFACT='build/unit_test_scripts/.' -REMOTE_HOSTNAME='devel-foxbms' -REMOTE="foxbms@$REMOTE_HOSTNAME" -REMOTE_WEB_DIR='/srv/www/vhosts/devel-foxbms/htdocs' +REMOTE="$REMOTE_USER@$REMOTE_HOSTNAME" +echo "Value of variable REMOTE_HOSTNAME: $REMOTE_HOSTNAME" +echo "Value of variable REMOTE_USER: $REMOTE_USER" echo 'This is the deployment-script for local reports and documentation.' echo 'I will try to detect the current CI-job:' diff --git a/tools/gui/fgui/__init__.py b/tools/gui/fgui/__init__.py index a8c56b99..bf01534d 100644 --- a/tools/gui/fgui/__init__.py +++ b/tools/gui/fgui/__init__.py @@ -40,7 +40,7 @@ """sets the version package etc.""" -__version__ = "1.1.1" +__version__ = "1.1.2" __appname__ = "foxBMS 2" __author__ = "The foxBMS Team" __copyright__ = "(c) 2010 - 2021 foxBMS" diff --git a/tools/ide/vscode/cspell.json.jinja2 b/tools/ide/vscode/cspell.json.jinja2 index 212d16fc..dd6a85f7 100644 --- a/tools/ide/vscode/cspell.json.jinja2 +++ b/tools/ide/vscode/cspell.json.jinja2 @@ -25,6 +25,7 @@ "parens", "phosphane", "precharged", + "prepend", "prepending", "recurse", "readmes", @@ -36,6 +37,7 @@ "substates", "supercapacitor", "supercapacitors", + "Typedefed", "throughs", "toolchain", "toolchains", @@ -591,8 +593,10 @@ "src/app/driver/sbc/fs8x_driver/**", "src/app/driver/mic/ltc/common/ltc_pec.*", "src/os/**", - "tests/axivion/*.preinc", + "tests/axivion/.axivion.preinc", + "tests/axivion/rule_config_c.json", "tests/axivion/ci_config.json", + "tests/re-names/*.json", "tools/dbc/*.dbc", "tools/dbc/*.sym", "tools/debugger/lauterbach/*.in", diff --git a/tools/ide/vscode/settings.json.jinja2 b/tools/ide/vscode/settings.json.jinja2 index 7d79985e..2e6c1f60 100644 --- a/tools/ide/vscode/settings.json.jinja2 +++ b/tools/ide/vscode/settings.json.jinja2 @@ -25,7 +25,6 @@ "restructuredtext.linter.disabled": true, "restructuredtext.preview.sphinx.disabled": true, "restructuredtext.preview.docutil.disabled": true, - "gitlab.instanceUrl": "https://iisb-gitlab.iisb.fraunhofer.de/", "extensions.ignoreRecommendations": true, "C_Cpp.autoAddFileAssociations": true, "C_Cpp.clang_format_path": "{{ CLANG_FORMAT_EXECUTABLE }}", @@ -52,6 +51,7 @@ "python.analysis.extraPaths": [ "{{ WAF_DIR }}", "{{ WAF_TOOLS_DIR }}", + "{{ AXIVION_MODULES }}" ], "python.condaPath": "{{ CONDA_PATH }}", "python.formatting.provider": "black", @@ -116,6 +116,15 @@ "*.ppr": "c", "*.pprs": "c", "*.cppcheck": "xml", - "*.conf.in": "properties" - } + "tests/axivion/cafeCC.config": "xml", + "tests/axivion/architecture.gxl": "xml", + "tests/axivion/mapping.gxl": "xml" + }, + "axivion.pathMappings": [ + { + "analysisProject": "{{ AXIVION_VS_CONFIG['analysisProject'] }}", + "localPath": "{{ AXIVION_VS_CONFIG['localPath'] }}", + "analysisPath": "{{ AXIVION_VS_CONFIG['analysisPath'] }}" + } + ] } diff --git a/tools/ide/vscode/tasks.json.jinja2 b/tools/ide/vscode/tasks.json.jinja2 index 2f19711d..aacc6303 100644 --- a/tools/ide/vscode/tasks.json.jinja2 +++ b/tools/ide/vscode/tasks.json.jinja2 @@ -235,6 +235,13 @@ ], "problemMatcher": [] }, + { + "label": "Run:Axivion Analysis", + "type": "process", + "group": "build", + "command": "{{ AXIVION_START_ANALYSIS }}", + "problemMatcher": [] + }, { "label": "Run:Guidelines and style guide check", "type": "process", diff --git a/tools/waf-tools/f_axivion.py b/tools/waf-tools/f_axivion.py new file mode 100644 index 00000000..8afb7f4c --- /dev/null +++ b/tools/waf-tools/f_axivion.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# We kindly request you to use one or more of the following phrases to refer to +# foxBMS in your hardware, software, documentation or advertising materials: +# +# - "This product uses parts of foxBMS®" +# - "This product includes parts of foxBMS®" +# - "This product is derived from foxBMS®" + +"""Implements a waf tool to use Axivion cafeCC compiler + +For information on Axivion see https://www.axivion.com/. +""" + +import os +from waflib import Logs +from waflib.Tools.ccroot import link_task +from waflib import TaskGen +from waflib.TaskGen import taskgen_method +from waflib.Configure import conf + +import f_ti_arm_helper # pylint: disable=unused-import +import f_ti_arm_tools # pylint: disable=unused-import +import f_ti_color_arm_cgt # pylint: disable=unused-import + + +def configure(configure_context): + """Searches the Axivion cafeCC compiler""" + if os.getenv("AXIVION", None): + configure_context.find_program("cafecc", var="AXIVION_CC") + + +@conf +def patch_for_axivion_build(self, bld): # pylint: disable=unused-argument + """Patches the Axivion build (i.e. remove tasks that do not apply).""" + if not bld.env.AXIVION_CC: + Logs.warn("Axivion tools not available.") + return + + os.environ["BAUHAUS_CONFIG"] = os.path.join(bld.path.abspath(), "tests", "axivion") + bld.env.CC = bld.env.AXIVION_CC + bld.env.LINK_CC = bld.env.AXIVION_CC + bld.env.append_unique("LINKFLAGS", ["-echo"]) # show real linker call + bld.env.LINKFLAGS.extend(["-larg", "--show_plan"]) + bld.env.append_unique("CFLAGS", ["-B", self.path.abspath()]) + + @TaskGen.extension(".c") + def c_hook(self, node): + return self.create_compiled_task_c("c", node) + + @taskgen_method + def create_compiled_task_c(self, t_name, node): + if self.idx > 1: + Logs.warn( + "Consistency of .aux, .crl and .rl output files can not be guaranteed." + ) + out_obj = "%s.%d.obj" % (node.name, self.idx) + task = self.create_task( + t_name, + src=node, + tgt=[ + node.parent.find_or_declare(out_obj), + ], + ) + try: + self.compiled_tasks.append(task) + except AttributeError: + self.compiled_tasks = [task] + return task + + class cprogram(link_task): # pylint: disable=invalid-name,unused-variable + """class to run the Axivion CC compiler in linker mode""" + + run_str = ( + "${LINK_CC} ${CFLAGS} ${RUN_LINKER} ${LINKFLAGS} " + "${CCLINK_TGT_F}${TGT[0].abspath()} ${SRC} ${LINKER_SCRIPT} " + "${LIBPATH_ST:LIBPATH} ${STLIBPATH_ST:STLIBPATH} " + "-Wl,--start-group ${LIB_ST:LIB} ${STLIB_ST:STLIB} " + "-Wl,--end-group ${LDFLAGS}" + ) + ext_out = [".elf"] + vars = ["LINKDEPS"] + + def keyword(self): + return "Linking" + + @conf + def tiprogram(bld, *k, **kw): # pylint: disable=unused-variable + if "linker_script" not in kw: + bld.fatal("linker script missing") + bld.env.LINKER_SCRIPT = kw["linker_script"].abspath() + kw["features"] = "c cprogram" + tgt_elf = bld.path.find_or_declare( + "%s.%s" % (kw["target"], bld.env.DEST_BIN_FMT) + ) + kw["target"] = [tgt_elf] + bld.add_manual_dependency(tgt_elf, kw["linker_script"]) + return bld(*k, **kw) + + @TaskGen.feature("cprogram") + def add_bingen_task(self): # pylint: disable=unused-argument,unused-variable + return + + @TaskGen.feature("c", "cprogram") + def process_sizes(self): # pylint: disable=unused-argument,unused-variable + return + + @TaskGen.feature("c", "cprogram") + def process_nm(self): # pylint: disable=unused-argument,unused-variable + return + + @TaskGen.feature("c") + @TaskGen.after("c_pp") + def remove_stuff_from_pp(self): # pylint: disable=unused-argument,unused-variable + return + + @TaskGen.feature("c", "db_check") + @TaskGen.after_method("process_source") + def check_data_base_init(self): # pylint: disable=unused-argument,unused-variable + return diff --git a/tools/waf-tools/f_hcg.py b/tools/waf-tools/f_hcg.py index 17f3a423..93bdb3ee 100644 --- a/tools/waf-tools/f_hcg.py +++ b/tools/waf-tools/f_hcg.py @@ -184,6 +184,13 @@ def process_hcg(self, node): self.create_task( "hcg_compiler", src=[node, dil_file], tgt=tgt, remove_files=hcg.removes ) + no_clang_node = self.path.find_resource(".clang-format") + if not no_clang_node: + no_clang_node = self.path.find_or_declare(".clang-format") + no_clang_node.write( + f"DisableFormat: true{os.linesep}SortIncludes: false{os.linesep}" + ) + if not hasattr(self, "unit_test"): self.source.extend(gen_sources) try: @@ -327,9 +334,15 @@ def configure(conf): """ conf.start_msg("Checking for TI Code Generator (HALCoGen)") if not Utils.is_win32: - conf.end_msg(0) + conf.end_msg(False) return + conf.find_program("HALCOGEN", var="HALCOGEN", mandatory=False) + + if not conf.env.HALCOGEN: + conf.end_msg(False) + return + incpath_halcogen = os.path.join( pathlib.Path(conf.env.HALCOGEN[0]).parent.parent.parent, "F021 Flash API", diff --git a/tools/waf-tools/f_node_helper.py b/tools/waf-tools/f_node_helper.py index 02163745..005f183f 100644 --- a/tools/waf-tools/f_node_helper.py +++ b/tools/waf-tools/f_node_helper.py @@ -41,7 +41,7 @@ """Helper methods to work with waf node objects""" -from waflib import Errors, Node, Utils, TaskGen +from waflib import Errors, Node, TaskGen, Utils @TaskGen.taskgen_method diff --git a/tools/waf-tools/f_ti_arm_cgt.py b/tools/waf-tools/f_ti_arm_cgt.py index 12bec20e..ff9f33b8 100644 --- a/tools/waf-tools/f_ti_arm_cgt.py +++ b/tools/waf-tools/f_ti_arm_cgt.py @@ -41,14 +41,13 @@ """Implements a waf tool to use TI ARM CGT (https://www.ti.com/tool/ARM-CGT). """ +import binascii +import json import os -import sys import pathlib import re import shutil -import binascii -import json -import yaml +import sys import waflib.Tools.asm from waflib import Context, Logs, Task, TaskGen, Utils, Errors @@ -57,11 +56,11 @@ from waflib.Tools import c_preproc from waflib.Tools.ccroot import link_task +import f_ti_arm_cgt_cc_options # pylint: disable=unused-import import f_ti_arm_helper # pylint: disable=unused-import import f_ti_arm_tools # pylint: disable=unused-import import f_ti_color_arm_cgt - HAVE_GIT = False try: from git import Repo @@ -71,6 +70,8 @@ except ImportError: pass +TOOL_DIR = os.path.dirname(os.path.realpath(__file__)) + def remove_targets(task): """General helper function to remove targets""" @@ -80,23 +81,14 @@ def remove_targets(task): def options(opt): - """Configurable options of the :py:mod:`f_ti_arm_cgt` tool. The options are - - - ``--cc-options=conf/cc/cc-options.yaml`` + """Configurable options of the :py:mod:`f_ti_arm_cgt` tool. Furthermore the default formatter gets replaced by :py:class:`f_ti_arm_cgt.armclFormatter`. """ - #: option to overwrite the default location of the cc-options file - opt.add_option( - "--cc-options", - action="store", - default=os.path.join("conf", "cc", "cc-options.yaml"), - dest="CC_OPTIONS", - help="Path to cc options specification file", - ) - opt.load("f_ti_color_arm_cgt", tooldir=os.path.dirname(os.path.realpath(__file__))) - opt.load("f_hcg", tooldir=os.path.dirname(os.path.realpath(__file__))) + opt.load("f_ti_arm_cgt_cc_options", tooldir=TOOL_DIR) + opt.load("f_ti_color_arm_cgt", tooldir=TOOL_DIR) + opt.load("f_hcg", tooldir=TOOL_DIR) @TaskGen.extension(".asm") @@ -275,11 +267,6 @@ class c(Task.Task): # pylint: disable-msg=invalid-name,too-few-public-methods file), a crl files (cross-reference listing file) and a rl file (output preprocessor listing) are generated. - These additional files are generated as in ``conf/cc/cc-options.yaml`` - the options ``--gen_cross_reference_listing``, ``--gen_func_info_listing`` - and ``--gen_preprocessor_listing`` are passed in the compile step. See - :ref:`CONFIGURATION_CFLAGS`. - .. graphviz:: :caption: Input-output relation for assembler source files :name: c-to-obj @@ -1442,67 +1429,9 @@ def cgt_flags(conf): # pylint: disable-msg=redefined-outer-name def configure(conf): # pylint: disable-msg=redefined-outer-name """configuration step of the TI ARM CGT compiler tool""" - cc_spec_file = conf.path.find_node(conf.options.CC_OPTIONS) - with open(cc_spec_file.abspath(), "r") as stream: - try: - conf.env.cc_options = yaml.load(stream, Loader=yaml.Loader) - except yaml.YAMLError as exc: - conf.fatal(exc) conf.load_special_tools("c_*.py") - include_paths = conf.env.cc_options["INCLUDE_PATHS"][ - Utils.unversioned_sys_platform() - ] - library_paths = conf.env.cc_options["LIBRARY_PATHS"][ - Utils.unversioned_sys_platform() - ] - libraries_st = conf.env.cc_options["LIBRARIES"]["ST"] - libraries_target = conf.env.cc_options["LIBRARIES"]["TARGET"] - cflags_common = conf.env.cc_options["CFLAGS"]["common"] - cflags_common_compile_only = conf.env.cc_options["CFLAGS"]["common_compile_only"] - cflags_foxbms = conf.env.cc_options["CFLAGS"]["foxbms"] - cflags_hal = conf.env.cc_options["CFLAGS"]["hal"] - cflags_os = conf.env.cc_options["CFLAGS"]["operating_system"] - linkflags = conf.env.cc_options["LINKFLAGS"] - hexgenflags = conf.env.cc_options["HEXGENFLAGS"] - nmflags = conf.env.cc_options["NMFLAGS"] - - if linkflags: - conf.env.append_unique("LINKFLAGS", linkflags) - if hexgenflags: - conf.env.append_unique("HEXGENFLAGS", hexgenflags) - if nmflags: - conf.env.append_unique("NMFLAGS", nmflags) - - if include_paths: - conf.env.append_unique("INCLUDES", include_paths) - if library_paths: - conf.env.append_unique("STLIBPATH", library_paths) - if libraries_st: - conf.env.append_unique("STLIB", libraries_st) - if libraries_target: - conf.env.append_unique("TARGETLIB", libraries_target) - if cflags_common: - conf.env.append_unique("CFLAGS", cflags_common) - - if cflags_common_compile_only: - conf.env.append_unique("CFLAGS_COMPILE_ONLY", cflags_common_compile_only) - conf.env.append_unique( - "CFLAGS_COMPILE_ONLY", - [ - "--gen_cross_reference_listing", - "--gen_func_info_listing", - "--gen_preprocessor_listing", - ], - ) - - if cflags_foxbms: - conf.env.append_unique("CFLAGS_FOXBMS", cflags_foxbms) - if cflags_hal: - conf.env.append_unique("CFLAGS_HAL", cflags_hal) - if cflags_os: - conf.env.append_unique("CFLAGS_OS", cflags_os) - conf.start_msg("Checking for TI ARM CGT compiler and tools") + conf.load_cc_options() conf.find_armcl() conf.find_armar() conf.find_arm_tools() @@ -1514,4 +1443,4 @@ def configure(conf): # pylint: disable-msg=redefined-outer-name conf.env.DEST_OS = ["EMBEDDED"] conf.env.COMPILER_CC = "ti_arm_cgt" conf.end_msg(conf.env.get_flat("CC")) - conf.load("f_hcg", tooldir=os.path.dirname(os.path.realpath(__file__))) + conf.load("f_hcg", tooldir=TOOL_DIR) diff --git a/tools/waf-tools/f_ti_arm_cgt_cc_options.py b/tools/waf-tools/f_ti_arm_cgt_cc_options.py new file mode 100644 index 00000000..823e1f3a --- /dev/null +++ b/tools/waf-tools/f_ti_arm_cgt_cc_options.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (c) 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# We kindly request you to use one or more of the following phrases to refer to +# foxBMS in your hardware, software, documentation or advertising materials: +# +# - "This product uses parts of foxBMS®" +# - "This product includes parts of foxBMS®" +# - "This product is derived from foxBMS®" + +"""Implements the compiler options for the TI ARM CGT +(https://www.ti.com/tool/ARM-CGT) Tool. +""" + +import os + +import yaml +from waflib import Utils +from waflib.Configure import conf + + +def options(opt): + """Configurable options of the :py:mod:`f_ti_arm_cgt` tool. The options are + + - ``--cc-options=conf/cc/cc-options.yaml`` + + """ + #: option to overwrite the default location of the cc-options file + opt.add_option( + "--cc-options", + action="store", + default=os.path.join("conf", "cc", "cc-options.yaml"), + dest="CC_OPTIONS", + help="Path to cc options specification file", + ) + + +@conf +def load_cc_options(conf): # pylint: disable-msg=redefined-outer-name + """configuration step of the TI ARM CGT compiler tool""" + cc_spec_file = conf.path.find_node(conf.options.CC_OPTIONS) + if not cc_spec_file: + conf.fatal(f"'{cc_spec_file}' does not exist.") + cc_spec_txt = cc_spec_file.read(encoding="utf-8") + try: + conf.env.cc_options = yaml.load(cc_spec_txt, Loader=yaml.Loader) + except yaml.YAMLError as exc: + conf.fatal(exc) + + include_paths = conf.env.cc_options["INCLUDE_PATHS"][ + Utils.unversioned_sys_platform() + ] + library_paths = conf.env.cc_options["LIBRARY_PATHS"][ + Utils.unversioned_sys_platform() + ] + libraries_st = conf.env.cc_options["LIBRARIES"]["ST"] + libraries_target = conf.env.cc_options["LIBRARIES"]["TARGET"] + cflags_common = conf.env.cc_options["CFLAGS"]["common"] + cflags_common_compile_only = conf.env.cc_options["CFLAGS"]["common_compile_only"] + cflags_foxbms = conf.env.cc_options["CFLAGS"]["foxbms"] + cflags_hal = conf.env.cc_options["CFLAGS"]["hal"] + cflags_os = conf.env.cc_options["CFLAGS"]["operating_system"] + linkflags = conf.env.cc_options["LINKFLAGS"] + hexgenflags = conf.env.cc_options["HEXGENFLAGS"] + nmflags = conf.env.cc_options["NMFLAGS"] + + if linkflags: + conf.env.append_unique("LINKFLAGS", linkflags) + if hexgenflags: + conf.env.append_unique("HEXGENFLAGS", hexgenflags) + if nmflags: + conf.env.append_unique("NMFLAGS", nmflags) + + if include_paths: + conf.env.append_unique("INCLUDES", include_paths) + if library_paths: + conf.env.append_unique("STLIBPATH", library_paths) + if libraries_st: + conf.env.append_unique("STLIB", libraries_st) + if libraries_target: + conf.env.append_unique("TARGETLIB", libraries_target) + if cflags_common: + conf.env.append_unique("CFLAGS", cflags_common) + + if cflags_common_compile_only: + conf.env.append_unique("CFLAGS_COMPILE_ONLY", cflags_common_compile_only) + conf.env.append_unique( + "CFLAGS_COMPILE_ONLY", + [ + "--gen_cross_reference_listing", + "--gen_func_info_listing", + "--gen_preprocessor_listing", + ], + ) + + if cflags_foxbms: + conf.env.append_unique("CFLAGS_FOXBMS", cflags_foxbms) + if cflags_hal: + conf.env.append_unique("CFLAGS_HAL", cflags_hal) + if cflags_os: + conf.env.append_unique("CFLAGS_OS", cflags_os) diff --git a/tools/waf-tools/f_ti_arm_helper.py b/tools/waf-tools/f_ti_arm_helper.py index ee457c69..14432148 100644 --- a/tools/waf-tools/f_ti_arm_helper.py +++ b/tools/waf-tools/f_ti_arm_helper.py @@ -44,7 +44,7 @@ import os import traceback -from waflib import Context, Logs, Utils, Errors +from waflib import Context, Errors, Logs, Utils from waflib.Configure import conf @@ -144,7 +144,7 @@ def get_defines(self, *k, **kw): testfile_basename = "predefined_defines" kw["features"] = "c" kw["idx"] = 0 - kw["fragment"] = "#include \n\nint main() {\n return 0;\n}\n" + kw["fragment"] = "int main() {\n return 0;\n}\n" kw["out_name"] = testfile_basename kw["compile_filename"] = f"{testfile_basename}.c" kw["msg"] = "Getting predefined compiler defines" diff --git a/tools/waf-tools/f_vscode.py b/tools/waf-tools/f_vscode.py index 3d5da590..6f91e791 100644 --- a/tools/waf-tools/f_vscode.py +++ b/tools/waf-tools/f_vscode.py @@ -104,10 +104,18 @@ def configure(conf): # pylint: disable=too-many-statements,too-many-branches waf_wrapper_script = pathlib.Path(conf.path.abspath()).as_posix() + "/waf.bat" else: waf_wrapper_script = pathlib.Path(conf.path.abspath()) + "/waf.sh" + axivion_base_path = pathlib.Path( + os.path.join(conf.path.abspath(), "tests", "axivion") + ).as_posix() + if Utils.is_win32: + axivion_start_analysis = axivion_base_path + "/start_local_analysis.bat" + else: + axivion_start_analysis = axivion_base_path + "/start_local_analysis.sh" template = template_env.get_template("tasks.json.jinja2") tasks = template.render( WAF_WRAPPER_SCRIPT=waf_wrapper_script, + AXIVION_START_ANALYSIS=axivion_start_analysis, ) vsc_tasks_file = os.path.join(vscode_dir.relpath(), "tasks.json") conf.path.make_node(vsc_tasks_file).write(fix_jinja(tasks)) @@ -157,16 +165,50 @@ def configure(conf): # pylint: disable=too-many-statements,too-many-branches else: clang_format_executable = pathlib.Path(conf.env.CLANG_FORMAT[0]).as_posix() + ax_modules_rel = pathlib.Path(os.path.join("lib", "scripts")) + + if Utils.is_win32: + axivion_modules = ( + pathlib.Path(os.environ.get("ProgramFiles(x86)", "C:\\Program Files(x86)")) + / "Bauhaus" + / ax_modules_rel + ).as_posix() + userprofile = os.environ.get( + "USERPROFILE", os.environ.get("HOMEDRIVE", "C:") + os.sep + ) + else: + axivion_modules = ( + pathlib.Path(os.environ.get("HOME", "/")) / "bauhaus-suite" / ax_modules_rel + ) + userprofile = os.environ.get("HOME", "~") + + axivion_vs_config = { + "analysisProject": "foxbms-2", + "localPath": pathlib.Path(conf.path.abspath()).as_posix(), + "analysisPath": pathlib.Path(userprofile).as_posix(), + } + if conf.env.AXIVION_CC: + projects_path = os.path.join(userprofile, ".bauhaus", "localbuild", "projects") + axivion_vs_config["analysisPath"] = pathlib.Path(projects_path).as_posix() + + try: + axivion_modules = ( + pathlib.Path(conf.env.AXIVION_CC[0]).parent.parent / ax_modules_rel + ).as_posix() + except IndexError: + pass settings = template.render( PYTHONPATH=py_exe, WAF_DIR=waf_dir, WAF_TOOLS_DIR=waf_tools_dir, + AXIVION_MODULES=axivion_modules, CONDA_PATH=conda_exe, PYLINT_PATH=pylint_exe, PYLINT_CONFIG=pylint_cfg, BLACKPATH=black_exe, BLACK_CONFIG=black_cfg, CLANG_FORMAT_EXECUTABLE=clang_format_executable, + AXIVION_VS_CONFIG=axivion_vs_config, ) vsc_settings_file = os.path.join(vscode_dir.relpath(), "settings.json") diff --git a/wscript b/wscript index 38b9d077..93e64035 100644 --- a/wscript +++ b/wscript @@ -53,20 +53,10 @@ import tarfile import shlex import pathlib import json -import collections import jsonschema import tabulate -from waflib import ( - Build, - Configure, - Context, - Errors, - Logs, - Options, - Utils, - Scripting, -) +from waflib import Build, Configure, Context, Errors, Logs, Options, Utils, Scripting from waflib.Build import ( BuildContext, CleanContext, @@ -86,12 +76,12 @@ top = "." # pylint:disable=invalid-name APPNAME = "foxBMS" """name of the application. This is used in various waf functions""" -VERSION = "1.1.1" +VERSION = "1.1.2" """version of the application. This is used in various waf functions. This version must match the version number defined in ``macros.txt``. Otherwise a configuration error is thrown.""" -BIN_VARIANTS = ["bin"] +BIN_VARIANTS = ["bin", "axivion"] """Binary build command variations that are supported. The commands are then generated by concatenating the command + the variant, e.g., ``build_bin``""" @@ -201,6 +191,7 @@ def options(opt): action="store_true", help="Builds a coverage report based on the unit test", ) + opt.load("f_axivion", tooldir=TOOLDIR) opt.load("f_sphinx_build", tooldir=TOOLDIR) opt.load("doxygen", tooldir=TOOLDIR) opt.load("f_cppcheck", tooldir=TOOLDIR) @@ -393,9 +384,13 @@ def configure(conf): # pylint: disable=too-many-statements,too-many-branches os.path.join(out, "bin", "src", "hal", "include"), os.path.join(out, "bin", "src", "hal", "source"), ] - conf.load("f_vscode", tooldir=TOOLDIR) conf.load("f_ozone", tooldir=TOOLDIR) conf.load("f_lauterbach", tooldir=TOOLDIR) + conf.load("f_axivion", tooldir=TOOLDIR) + # load VS Code setup as last foxBMS specific tool to ensure that all + # variables have a meaningful value + conf.load("f_vscode", tooldir=TOOLDIR) + # the project has been successfully configured, now we can set the # application name and version conf.env.APPNAME = APPNAME @@ -561,6 +556,14 @@ def build(bld): # pylint: disable=too-many-branches,too-many-statements print(info) bld.recurse("src") + if bld.variant == "axivion": + if not bld.env.AXIVION_CC: + Logs.warn("Axivion tools not available.") + return + bld.patch_for_axivion_build(bld) + + bld.recurse("src") + if bld.variant == "unit_test": Options.commands = ["check_testfiles"] + Options.commands if bld.cmd.startswith("clean"): @@ -842,7 +845,9 @@ def build(bld): # pylint: disable=too-many-branches,too-many-statements os.path.join(doc_dir, "software", "unit-tests", "unit-tests.rst"), os.path.join(doc_dir, "software", "unit-tests", "unit-tests_how-to.rst"), os.path.join(doc_dir, "tools", "halcogen", "halcogen.rst"), + os.path.join(doc_dir, "tools", "static-analysis", "axivion.rst"), os.path.join(doc_dir, "tools", "static-analysis", "cppcheck.rst"), + os.path.join(doc_dir, "tools", "waf-tools", "f_axivion.rst"), os.path.join(doc_dir, "tools", "waf-tools", "f_black.rst"), os.path.join(doc_dir, "tools", "waf-tools", "f_bootstrap_library_project.rst"), os.path.join(doc_dir, "tools", "waf-tools", "f_check_db_vars.rst"), @@ -988,31 +993,6 @@ def distcheck_bin(conf): conf.excl = DIST_EXCLUDE -def check_filenames(ctx): - """Checks if duplicate file names are in the source directory.""" - sources = ctx.path.ant_glob( - "src/**/*.c src/**/*.h tests/unit/**/*.c tests/unit/**/*.h" - ) - source_names = [pathlib.Path(i.abspath()).name for i in sources] - duplicates = [ - i for i, count in collections.Counter(source_names).items() if count > 1 - ] - if duplicates: - duplicate_locations = {} - err_msg = "--\n" - for i in duplicates: - duplicate_locations[i] = ctx.path.ant_glob( - f"src/**/{i} tests/unit/**/{i}", excl="src/hal/** src/os/**" - ) - for i, dup in duplicate_locations.items(): - err_msg += ( - f"File name:\n {i}\nDuplicates:\n " - + "\n ".join([x.abspath() for x in dup]) - + "\n--\n" - ) - ctx.fatal(f"There are duplicate file names:\n{err_msg}") - - def check_testfiles(ctx): """Check if test files to corresponding source files exist.""" prefix = os.path.join(ctx.path.abspath(), "src") + os.pathsep @@ -1020,9 +1000,12 @@ def check_testfiles(ctx): i.abspath()[len(prefix) :] for i in ctx.path.ant_glob( "src/app/**/*.c src/opt/**/*.c", - excl="src/app/driver/sbc/fs8x_driver/** " - "src/app/driver/mic/ltc/common/ltc_pec.* " - "src/hal/** src/os/**", + excl=[ + "src/app/driver/sbc/fs8x_driver/**", + "src/app/driver/mic/ltc/common/ltc_pec.*", + "src/hal/**", + "src/os/**", + ], ) ]