├── jupyter_notebook ├── MnistProt │ ├── __init__.py │ ├── Mode.py │ ├── Command.py │ ├── Stats.py │ ├── GetStats.py │ ├── InferenceInput.py │ ├── InferenceOutput.py │ └── Commands.py ├── MnistDigitDraw │ ├── __init__.py │ ├── digit_draw_1.png │ ├── digit_draw_2.png │ └── MnistDigitDraw.py ├── FbComm │ ├── fb_comm_test │ │ └── make.sh │ └── FbComm.py └── export-to-tflite.py ├── source ├── libs │ ├── flatbuffers │ │ ├── .gitattributes │ │ ├── src │ │ │ ├── clang-format.sh │ │ │ ├── flathash.cpp │ │ │ └── flatc_main.cpp │ │ ├── .editorconfig │ │ ├── .bazelci │ │ │ └── presubmit.yml │ │ ├── .clang-format │ │ ├── .travis │ │ │ ├── deploy-python.sh │ │ │ ├── check-sources.sh │ │ │ ├── check-sources.sh.py │ │ │ ├── check-generate-code.sh │ │ │ └── build-and-run-docker-test-containers.sh │ │ ├── .github │ │ │ ├── ISSUE_TEMPLATE.md │ │ │ └── PULL_REQUEST_TEMPLATE.md │ │ ├── .appveyor │ │ │ └── check-generate-code.bat │ │ ├── .gitignore │ │ └── include │ │ │ └── flatbuffers │ │ │ ├── flatc.h │ │ │ ├── hash.h │ │ │ └── registry.h │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F7xx │ │ │ │ └── Include │ │ │ │ ├── stm32f7xx.h │ │ │ │ ├── stm32f746xx.h │ │ │ │ └── system_stm32f7xx.h │ │ ├── Include │ │ │ ├── cmsis_version.h │ │ │ └── tz_context.h │ │ └── DSP │ │ │ └── Source │ │ │ ├── MatrixFunctions │ │ │ └── arm_mat_init_f32.c │ │ │ ├── SupportFunctions │ │ │ ├── arm_q7_to_float.c │ │ │ ├── arm_q15_to_float.c │ │ │ ├── arm_q7_to_q15.c │ │ │ └── arm_q15_to_q7.c │ │ │ └── BasicMathFunctions │ │ │ └── arm_dot_prod_f32.c │ ├── noarch_c_lib │ │ ├── README.md │ │ ├── various_defs.h │ │ ├── LICENSE.h │ │ ├── timer_sched_main.c │ │ ├── debug_trace.h │ │ ├── mod_led_main.c │ │ ├── .gitignore │ │ ├── states.h │ │ ├── states_main.c │ │ ├── mod_led.h │ │ └── timer_sched.h │ └── AI │ │ └── Inc │ │ ├── ai_common_config.h │ │ ├── datatypes_network.h │ │ ├── core_datatypes.h │ │ ├── layers_dense.h │ │ ├── formats_list.h │ │ ├── layers.h │ │ ├── layers_sm.h │ │ ├── core_convert.h │ │ ├── core_net_inspect.h │ │ ├── layers_list.h │ │ ├── ai_log.h │ │ ├── layers_rnn.h │ │ ├── core_log.h │ │ └── core_net_inspect_interface.h ├── cmake │ ├── flatbuffers_lib.cmake │ ├── noarch_c_lib.cmake │ ├── stm_ai_lib.cmake │ ├── stm32f7_hal_driver.cmake │ ├── cmsis_dsp_lib.cmake │ ├── TOOLCHAIN_arm_none_eabi_cortex_m7.cmake │ └── language_provider.cmake ├── schema │ ├── create-header.sh │ └── schema.fbs ├── src │ ├── inc │ │ ├── stm32f7_helper_func.h │ │ ├── mnistkeras_data.h │ │ ├── RTE_Components.h │ │ ├── stm32f7xx_it.h │ │ ├── main.h │ │ ├── comm_buffer.h │ │ ├── constants_ai.h │ │ ├── app_x-cube-ai.h │ │ └── digit.h │ ├── CMakeLists.txt │ └── syscalls.c └── CMakeLists.txt ├── flash.sh ├── format.sh ├── LICENSE ├── .gitignore └── extras └── digit.csv /jupyter_notebook/MnistProt/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /jupyter_notebook/MnistDigitDraw/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | -------------------------------------------------------------------------------- /flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | STM32_BIN=build-stm32/src/stm32f7-mnist-x_cube_ai.bin 3 | OFFSET=0x8000000 4 | st-flash --reset write "${STM32_BIN}" "${OFFSET}" 5 | -------------------------------------------------------------------------------- /jupyter_notebook/MnistDigitDraw/digit_draw_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimtass/stm32f746-x-cube-ai-mnist/HEAD/jupyter_notebook/MnistDigitDraw/digit_draw_1.png -------------------------------------------------------------------------------- /jupyter_notebook/MnistDigitDraw/digit_draw_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimtass/stm32f746-x-cube-ai-mnist/HEAD/jupyter_notebook/MnistDigitDraw/digit_draw_2.png -------------------------------------------------------------------------------- /source/libs/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimtass/stm32f746-x-cube-ai-mnist/HEAD/source/libs/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h -------------------------------------------------------------------------------- /source/libs/CMSIS/Device/ST/STM32F7xx/Include/stm32f746xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimtass/stm32f746-x-cube-ai-mnist/HEAD/source/libs/CMSIS/Device/ST/STM32F7xx/Include/stm32f746xx.h -------------------------------------------------------------------------------- /jupyter_notebook/MnistProt/Mode.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: MnistProt 4 | 5 | class Mode(object): 6 | ACCELERATION_NONE = 0 7 | ACCELERATION_CMSIS_NN = 1 8 | 9 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/src/clang-format.sh: -------------------------------------------------------------------------------- 1 | clang-format -i -style=file include/flatbuffers/* src/*.cpp tests/test.cpp samples/*.cpp grpc/src/compiler/schema_interface.h grpc/tests/*.cpp 2 | git checkout include/flatbuffers/reflection_generated.h 3 | -------------------------------------------------------------------------------- /jupyter_notebook/MnistProt/Command.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: MnistProt 4 | 5 | class Command(object): 6 | CMD_GET_STATS = 0 7 | CMD_INFERENCE_INPUT = 1 8 | CMD_INFERENCE_OUTPUT = 2 9 | 10 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | # Don't set line endings to avoid conflict with core.autocrlf flag. 3 | # Line endings on checkout/checkin are controlled by .gitattributes file. 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | insert_final_newline = true 8 | -------------------------------------------------------------------------------- /jupyter_notebook/FbComm/fb_comm_test/make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # You don't need a makefile for a one-liner... 4 | 5 | echo "Build FbComm test tool..." 6 | g++ -o fb_comm_test fb_comm_test.cpp -I../../../source/libs/flatbuffers/include/flatbuffers/ -I../../../source/src/inc 7 | echo "Done. Now you can run ./fb_comm_test" 8 | -------------------------------------------------------------------------------- /format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # Format file 4 | echo "Formating $1..." 5 | clang-format -i -style="{BasedOnStyle: llvm, ColumnLimit: 120, IndentWidth: 4, Standard: Cpp11, PointerBindsToType: false, BreakBeforeBraces: Linux, BreakConstructorInitializersBeforeComma: true, AccessModifierOffset: -4, BreakBeforeBinaryOperators: true}" $1 6 | -------------------------------------------------------------------------------- /source/cmake/flatbuffers_lib.cmake: -------------------------------------------------------------------------------- 1 | set(FLATBUFFERS_LIB_DIR ${CMAKE_SOURCE_DIR}/libs/flatbuffers) 2 | 3 | # Make sure that git submodule is initialized and updated 4 | if (NOT EXISTS "${FLATBUFFERS_LIB_DIR}") 5 | message(FATAL_ERROR "FLATBUFFERS_LIB_DIR not found.") 6 | endif() 7 | 8 | include_directories( 9 | ${FLATBUFFERS_LIB_DIR}/include 10 | ) 11 | -------------------------------------------------------------------------------- /source/schema/create-header.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | OUTPUT_H="mnist_schema_generated.h" 4 | OUTPUT_F="./source/src/inc/" 5 | 6 | echo "Creating framebuffer C++ header..." 7 | flatc -o ./source/schema/ --cpp ./source/schema/schema.fbs 8 | 9 | echo "Copying ${OUTPUT_H} to ${OUTPUT_F}..." 10 | mv ./source/schema/schema_generated.h ./${OUTPUT_F}/${OUTPUT_H} 11 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.bazelci/presubmit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | buildifier: latest 3 | platforms: 4 | ubuntu1604: 5 | build_targets: 6 | - "..." 7 | test_targets: 8 | - "..." 9 | ubuntu1804: 10 | build_targets: 11 | - "..." 12 | test_targets: 13 | - "..." 14 | macos: 15 | build_targets: 16 | - "..." 17 | test_targets: 18 | - "..." 19 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Google 4 | DerivePointerAlignment: false 5 | PointerAlignment: Right 6 | IndentPPDirectives: AfterHash 7 | Cpp11BracedListStyle: false 8 | AlwaysBreakTemplateDeclarations: false 9 | AllowShortCaseLabelsOnASingleLine: true 10 | SpaceAfterTemplateKeyword: false 11 | AllowShortBlocksOnASingleLine: true 12 | ... 13 | 14 | -------------------------------------------------------------------------------- /source/cmake/noarch_c_lib.cmake: -------------------------------------------------------------------------------- 1 | set(NOARCH_LIB_DIR ${CMAKE_SOURCE_DIR}/libs/noarch_c_lib) 2 | 3 | # Make sure that git submodule is initialized and updated 4 | if (NOT EXISTS "${NOARCH_LIB_DIR}") 5 | message(FATAL_ERROR "noarch_c_lib submodule not found. Initialize with 'git submodule update --init' in the source directory") 6 | endif() 7 | 8 | include_directories( 9 | ${NOARCH_LIB_DIR}/ 10 | ) 11 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.travis/deploy-python.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 4 | PROD_REPOSITORY="https://upload.pypi.org/legacy/" 5 | TEST_REPOSITORY="https://test.pypi.org/legacy/" 6 | 7 | twine upload \ 8 | --username "$PYPI_USERNAME" \ 9 | --password "$PYPI_PASSWORD" \ 10 | --repository-url "$PROD_REPOSITORY" \ 11 | "$DIR/../python/dist/"* 12 | 13 | -------------------------------------------------------------------------------- /source/cmake/stm_ai_lib.cmake: -------------------------------------------------------------------------------- 1 | set(STM_AI_LIB_DIR ${CMAKE_SOURCE_DIR}/libs/AI) 2 | 3 | # Make sure the lib is there 4 | if (NOT EXISTS "${STM_AI_LIB_DIR}") 5 | message(FATAL_ERROR "STM_AI_LIB_DIR not found.") 6 | endif() 7 | 8 | include_directories( 9 | ${STM_AI_LIB_DIR}/Inc 10 | ${CMAKE_SOURCE_DIR}libs/CMSIS/DSP/Source/MatrixFunctions/ 11 | ) 12 | 13 | find_library(ST_AI_Lib NetworkRuntime400_CM7_GCC ${CMAKE_SOURCE_DIR}/libs/AI/Lib/) 14 | 15 | set(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${ST_AI_Lib}) -------------------------------------------------------------------------------- /source/libs/flatbuffers/.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for submitting an issue! 2 | 3 | Please make sure you include the names of the affected language(s), compiler version(s), operating system version(s), and FlatBuffers version(s) in your issue title. 4 | 5 | This helps us get the correct maintainers to look at your issue. Here are examples of good titles: 6 | 7 | - Crash when accessing FlatBuffer [C++, gcc 4.8, OS X, master] 8 | - Flatc converts a protobuf 'bytes' field to 'string' in fbs schema file [all languages, FlatBuffers 1.4] 9 | 10 | Include other details as appropriate. 11 | 12 | Thanks! 13 | -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/README.md: -------------------------------------------------------------------------------- 1 | Universal C Library 2 | ---- 3 | 4 | This repo contains several MIT libraries that can be used universally 5 | and they aren't BSP dependant. These are quite useful for embedded 6 | projects as they are more lightweight. 7 | 8 | ## List of libs 9 | * `list.h`: This is the Linux kernel list lib 10 | * `trace.h`: Simple trace lib that needs printf 11 | * `various_defs.h`: Various useful defines 12 | * `states.h`: A state machine library 13 | * `time_sched.h`: A timer/scheduler library 14 | * `mod_led.h`: A generic cross-platform module for LEDS 15 | 16 | ## Author 17 | Dimitris Tassopoulos -------------------------------------------------------------------------------- /source/schema/schema.fbs: -------------------------------------------------------------------------------- 1 | namespace MnistProt; 2 | 3 | enum Command : byte { 4 | CMD_GET_STATS, 5 | CMD_INFERENCE_INPUT, 6 | CMD_INFERENCE_OUTPUT 7 | } 8 | 9 | enum Mode : byte { 10 | ACCELERATION_NONE, 11 | ACCELERATION_CMSIS_NN 12 | } 13 | 14 | table Stats { 15 | version:ubyte; 16 | freq:uint; 17 | mode:Mode; 18 | } 19 | 20 | table InferenceInput { 21 | digit:[float]; 22 | } 23 | 24 | table InferenceOutput { 25 | output_f:[float]; 26 | output_n:ubyte; 27 | timer_ms:float; 28 | } 29 | 30 | table Commands { 31 | cmd:Command; 32 | stats:Stats; 33 | input:InferenceInput; 34 | ouput:InferenceOutput; 35 | } 36 | 37 | root_type Commands; -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/various_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * various_defs.h 3 | * 4 | * This header file contains various useful defines., You can either include the 5 | * file to your project of just copy-paste parts that you need. Most of these stuff 6 | * are not mine, so the license might be GPL and not MIT 7 | */ 8 | 9 | #ifndef __VARIOUS_DEFS_H_ 10 | #define __VARIOUS_DEFS_H_ 11 | 12 | /** 13 | * @brief: Get the size of any array 14 | */ 15 | #define ARRAY_SIZE(X) (sizeof(X)/sizeof(X[0])) 16 | 17 | #define container_of(ptr, type, member) ({ \ 18 | const typeof(((type *)0)->member) * __mptr = (ptr); \ 19 | (type *)((char *)__mptr - offsetof(type, member)); \ 20 | }) 21 | 22 | #endif /* __VARIOUS_DEFS_H_ */ 23 | -------------------------------------------------------------------------------- /source/src/inc/stm32f7_helper_func.h: -------------------------------------------------------------------------------- 1 | #ifndef __STM32F7_HELPER_H__ 2 | #define __STM32F7_HELPER_H__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | struct dwtTime { 9 | uint32_t fcpu; 10 | int s; 11 | int ms; 12 | int us; 13 | }; 14 | 15 | uint32_t disableInts(void); 16 | void restoreInts(uint32_t state); 17 | 18 | void dwtIpInit(void); 19 | void dwtReset(void); 20 | uint32_t dwtGetCycles(void); 21 | uint32_t systemCoreClock(void); 22 | float dwtCyclesToFloatMs(uint64_t clks); 23 | 24 | const char *devIdToStr(uint16_t dev_id); 25 | void logDeviceConf(void); 26 | 27 | uint32_t systemCoreClock(void); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif // __STM32F7_HELPER_H__ -------------------------------------------------------------------------------- /source/libs/flatbuffers/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for submitting a PR! 2 | 3 | Please make sure you include the names of the affected language(s) in your PR title. 4 | This helps us get the correct maintainers to look at your issue. 5 | 6 | If you make changes to any of the code generators, be sure to run 7 | `cd tests && sh generate_code.sh` (or equivalent .bat) and include the generated 8 | code changes in the PR. This allows us to better see the effect of the PR. 9 | 10 | If your PR includes C++ code, please adhere to the Google C++ Style Guide, 11 | and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3), 12 | so only some C++11 support is available. 13 | 14 | Include other details as appropriate. 15 | 16 | Thanks! 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Dimitris Tassopoulos 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 12 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 13 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 14 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 15 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 16 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/LICENSE.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Dimitris Tassopoulos 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | * of the Software, and to permit persons to whom the Software is furnished to do 9 | * so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 15 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 16 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 17 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 19 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/ai_common_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ai_common_config.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 18-May-2018 6 | * @brief header file of AI platform common compile configuration defines 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | #ifndef __AI_COMMON_CONFIG_H_ 21 | #define __AI_COMMON_CONFIG_H_ 22 | #pragma once 23 | 24 | /*! 25 | * @defgroup layers Layers Compilation Config Definitions 26 | * @brief definition 27 | * 28 | */ 29 | 30 | #define HAS_PROFILE_FLOAT 31 | #define HAS_PROFILE_FIXED 32 | 33 | 34 | #endif /*__AI_COMMON_CONFIG_H_*/ 35 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.travis/check-sources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2018 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | set -e 17 | 18 | if [ -n "$1" ]; then 19 | scan_dir="$1" 20 | else 21 | scan_dir="$( pwd )" 22 | fi 23 | 24 | py_checker="$0.py" 25 | 26 | echo "scan root directory = '$scan_dir'" 27 | python3 --version 28 | # Scan recursively and search all *.cpp and *.h files using regex patterns. 29 | # Assume that script running from a root of Flatbuffers working dir. 30 | python3 $py_checker "ascii" "$scan_dir/include" "\.h$" 31 | python3 $py_checker "ascii" "$scan_dir/src" "\.cpp$" 32 | python3 $py_checker "ascii" "$scan_dir/tests" "\.h$" 33 | python3 $py_checker "utf-8" "$scan_dir/tests" "\.cpp$" 34 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.travis/check-sources.sh.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import sys 4 | 5 | def check_encoding(encoding, scan_dir, regex_pattern): 6 | fname = None 7 | try: 8 | assert encoding in ['ascii', 'utf-8'], "unexpected encoding" 9 | cmp = re.compile(regex_pattern) 10 | for root, dirs, files in os.walk(scan_dir): 11 | fname = root 12 | cmp_list = [f for f in files if cmp.search(f) is not None] 13 | for f in cmp_list: 14 | fname = os.path.join(root, f) 15 | with open(fname, mode='rb') as test_file: 16 | btext = test_file.read() 17 | # check encoding 18 | btext.decode(encoding=encoding, errors="strict") 19 | if encoding == "utf-8" and btext.startswith(b'\xEF\xBB\xBF'): 20 | raise ValueError("unexpected BOM in file") 21 | # check LF line endings 22 | LF = btext.count(b'\n') 23 | CR = btext.count(b'\r') 24 | if CR!=0: 25 | raise ValueError("invalid line endings: LF({})/CR({})".format(LF, CR)) 26 | except Exception as err: 27 | print("ERROR with [{}]: {}".format(fname, err)) 28 | return -1 29 | else: 30 | return 0 31 | 32 | if __name__ == "__main__": 33 | # python check-sources.sh.py 'ascii' '.' '.*\.(cpp|h)$' 34 | res = check_encoding(sys.argv[1], sys.argv[2], sys.argv[3]) 35 | sys.exit(0 if res == 0 else -1) 36 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.travis/check-generate-code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2018 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | set -e 17 | 18 | cd tests 19 | ./generate_code.sh 20 | cd .. 21 | 22 | # TODO: Linux and macos builds produce differences here for some reason. 23 | git checkout HEAD -- tests/monster_test.bfbs 24 | 25 | if ! git diff --quiet; then 26 | echo >&2 27 | echo "ERROR: ********************************************************" >&2 28 | echo "ERROR: The following differences were found after running the" >&2 29 | echo "ERROR: tests/generate_code.sh script. Maybe you forgot to run" >&2 30 | echo "ERROR: it after making changes in a generator or schema?" >&2 31 | echo "ERROR: ********************************************************" >&2 32 | echo >&2 33 | git diff --binary --exit-code 34 | fi 35 | -------------------------------------------------------------------------------- /source/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.6) 2 | 3 | include_directories( 4 | ${EXTERNAL_INCLUDES} 5 | inc 6 | ) 7 | 8 | aux_source_directory (./ DIR_USER_SRCS) 9 | 10 | file(GLOB C_SOURCE 11 | ${OTHER_SRC_FILES} 12 | #Add the local and project specific files 13 | ${DIR_USER_SRCS} 14 | ../config/system_stm32f7xx.c 15 | ) 16 | 17 | set_source_files_properties(${C_SOURCE} 18 | PROPERTIES COMPILE_FLAGS ${STM32F7_DEFINES} 19 | ) 20 | 21 | add_executable(${PROJECT_NAME}.elf 22 | ${C_SOURCE} 23 | ${EXTERNAL_EXECUTABLES} 24 | ) 25 | 26 | if (EXTERNAL_DEPENDENCIES) 27 | add_dependencies(${PROJECT_NAME}.elf 28 | ${EXTERNAL_DEPENDENCIES} 29 | ) 30 | endif() 31 | 32 | if (EXTERNAL_LIBS) 33 | target_link_libraries(${PROJECT_NAME}.elf 34 | ${EXTERNAL_LIBS} 35 | ) 36 | endif() 37 | 38 | 39 | add_custom_target ( ${PROJECT_NAME}.hex ALL 40 | DEPENDS ${PROJECT_NAME}.elf 41 | COMMAND ${CMAKE_OBJCOPY} -O ihex ${PROJECT_NAME}.elf ${PROJECT_NAME}.hex 42 | COMMENT "Generating ${PROJECT_NAME}.hex" 43 | ) 44 | add_custom_target ( ${PROJECT_NAME}.bin ALL 45 | DEPENDS ${PROJECT_NAME}.elf 46 | COMMAND ${CMAKE_OBJCOPY} -O binary ${PROJECT_NAME}.elf ${PROJECT_NAME}.bin 47 | COMMENT "Generating ${PROJECT_NAME}.bin" 48 | ) 49 | 50 | add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD 51 | COMMAND ${CMAKE_SIZE} --format=berkeley "${PROJECT_NAME}.elf") 52 | -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/timer_sched_main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This is an example test project for the timer_sched.h (timer/scheduler library) 3 | * 4 | * @author: Dimitris Tassopoulos 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "LICENSE.h" 12 | #include "various_defs.h" 13 | #include "debug_trace.h" 14 | #include "timer_sched.h" 15 | 16 | /* Set trace levels */ 17 | uint32_t trace_levels = \ 18 | TRACE_LEVEL_DEFAULT | 19 | 0; 20 | 21 | static LIST_HEAD(obj_timer_list); 22 | 23 | struct a_random_obj { 24 | char name[20]; 25 | }; 26 | 27 | void random_obj_cb(struct a_random_obj * obj) 28 | { 29 | TRACE(("random_obj_cb: %s\n", obj->name)); 30 | } 31 | 32 | int main() 33 | { 34 | /* create an object */ 35 | struct a_random_obj obj1 = {.name = "RANDOM OBJ1"}; 36 | /* add the object to the scheduler */ 37 | mod_timer_add((void*) &obj1, 1000, (void*) &random_obj_cb, &obj_timer_list); 38 | 39 | 40 | /* create another object */ 41 | struct a_random_obj obj2 = {.name = "RANDOM OBJ2"}; 42 | /* add the object to the scheduler */ 43 | mod_timer_add((void*) &obj2, 500, (void*) &random_obj_cb, &obj_timer_list); 44 | 45 | 46 | /* run the loop. In the ouput you should see the OBJ2 2 times/sec and OBJ1 1 time/sec */ 47 | while(1) { 48 | usleep(1 * 1000); //every 1msec 49 | mod_timer_polling(&obj_timer_list); 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /source/cmake/stm32f7_hal_driver.cmake: -------------------------------------------------------------------------------- 1 | set(STM32F7_HAL_DRIVER_DIR ${CMAKE_SOURCE_DIR}/libs/STM32F7xx_HAL_Driver) 2 | set(CMSIS_DIR ${CMAKE_SOURCE_DIR}/libs/CMSIS) 3 | 4 | # Make sure that git submodule is initialized and updated 5 | if (NOT EXISTS "${STM32F7_HAL_DRIVER_DIR}") 6 | message(FATAL_ERROR "STM32F7 HAL Driver submodule not found. Initialize with 'git submodule update --init' in the source directory") 7 | endif() 8 | 9 | # Make sure that git submodule is initialized and updated 10 | if (NOT EXISTS "${CMSIS_DIR}") 11 | message(FATAL_ERROR "cmsis submodule not found. Initialize with 'git submodule update --init' in the source directory") 12 | endif() 13 | 14 | include_directories( 15 | ${CMSIS_DIR}/Include 16 | ${CMSIS_DIR}/Device/ST/STM32F7xx/Include 17 | ${STM32F7_HAL_DRIVER_DIR}/Inc 18 | ${SRC}/inc 19 | ) 20 | 21 | 22 | # Get all source files from the Src directory 23 | aux_source_directory(${STM32F7_HAL_DRIVER_DIR}/Src STM32F7_HAL_DRIVER_SRC) 24 | 25 | set(STM32F7_DEFINES "${STM32F7_DEFINES} -DUSE_HAL_DRIVER") 26 | 27 | set_source_files_properties(${STM32F7_HAL_DRIVER_SRC} 28 | PROPERTIES COMPILE_FLAGS ${STM32F7_DEFINES} 29 | ) 30 | 31 | add_library(STM32F7xx_HAL_Driver STATIC ${STM32F7_HAL_DRIVER_SRC}) 32 | set_target_properties(STM32F7xx_HAL_Driver PROPERTIES LINKER_LANGUAGE C) 33 | 34 | set(EXTERNAL_EXECUTABLES ${EXTERNAL_EXECUTABLES} ${STARTUP_ASM_FILE}) 35 | 36 | set(EXTERNAL_LIBS ${EXTERNAL_LIBS} STM32F7xx_HAL_Driver) -------------------------------------------------------------------------------- /source/cmake/cmsis_dsp_lib.cmake: -------------------------------------------------------------------------------- 1 | set(STM32F7_DSP_LIB_DIR ${CMAKE_SOURCE_DIR}/libs/CMSIS/DSP) 2 | 3 | # Make sure the lib is there 4 | if (NOT EXISTS "${STM32F7_DSP_LIB_DIR}") 5 | message(FATAL_ERROR "STM32F7_DSP_LIB_DIR not found.") 6 | endif() 7 | 8 | include_directories( 9 | ${STM32F7_DSP_LIB_DIR}/Source/MatrixFunctions/ 10 | ) 11 | 12 | # Get all source files from the Source directory 13 | set(STM32F7_DSP_LIB_SRC 14 | ${STM32F7_DSP_LIB_DIR}/Source/MatrixFunctions/arm_mat_init_f32.c 15 | ${STM32F7_DSP_LIB_DIR}/Source/SupportFunctions/arm_q15_to_float.c 16 | ${STM32F7_DSP_LIB_DIR}/Source/SupportFunctions/arm_q15_to_q7.c 17 | ${STM32F7_DSP_LIB_DIR}/Source/SupportFunctions/arm_float_to_q15.c 18 | ${STM32F7_DSP_LIB_DIR}/Source/SupportFunctions/arm_q7_to_q15.c 19 | ${STM32F7_DSP_LIB_DIR}/Source/SupportFunctions/arm_float_to_q7.c 20 | ${STM32F7_DSP_LIB_DIR}/Source/SupportFunctions/arm_q7_to_float.c 21 | ${STM32F7_DSP_LIB_DIR}/Source/BasicMathFunctions/arm_dot_prod_f32.c 22 | ${STM32F7_DSP_LIB_DIR}/Source/BasicMathFunctions/arm_shift_q7.c 23 | ${STM32F7_DSP_LIB_DIR}/Source/BasicMathFunctions/arm_shift_q15.c 24 | ) 25 | 26 | set_source_files_properties(${STM32F7_DSP_LIB_SRC} 27 | PROPERTIES COMPILE_FLAGS ${STM32F7_DEFINES} 28 | ) 29 | 30 | add_library(STM32F7_DSP_Lib STATIC ${STM32F7_DSP_LIB_SRC}) 31 | set_target_properties(STM32F7_DSP_Lib PROPERTIES LINKER_LANGUAGE C) 32 | 33 | set(EXTERNAL_EXECUTABLES ${EXTERNAL_EXECUTABLES} ${STARTUP_ASM_FILE}) 34 | 35 | set(EXTERNAL_LIBS ${EXTERNAL_LIBS} STM32F7_DSP_Lib) -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/debug_trace.h: -------------------------------------------------------------------------------- 1 | /** 2 | * debug_trace.h 3 | * 4 | * LICENSE: MIT 5 | * 6 | * This header lib can be used to print trace messages using printf. It supports multiple\ 7 | * levels that can be enabledand disabled in run-time. The default trace level is the: 8 | * TRACE_LEVEL_DEFAULT and this is defined in this header. You can define more trace levels 9 | * but prefer to do that in your code and not in the header file, so the code is re-usable. 10 | * 11 | * Finally, you also need to define the trace_levels in you code file. 12 | * 13 | * Dimitris Tassopoulos 14 | */ 15 | 16 | #ifndef __DEBUG_TRACE_H_ 17 | #define __DEBUG_TRACE_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include "LICENSE.h" 25 | 26 | #define DEBUG_TRACE 27 | 28 | #define TRACE_LEVEL_DEFAULT (1 << 0) 29 | /** You can define more in your code, e.g. 30 | #define TRACE_LEVEL_USB (1 << 1) 31 | #define TRACE_LEVEL_GPIO (1 << 2) 32 | */ 33 | 34 | #ifdef DEBUG_TRACE 35 | #define TRACE(X) TRACEL(TRACE_LEVEL_DEFAULT, X) 36 | #define TRACEL(TRACE_LEVEL, X) do { if (trace_levels & TRACE_LEVEL) printf X;} while(0) 37 | #else 38 | #define TRACE(X) 39 | #define TRACEL(X,Y) 40 | #endif 41 | 42 | extern uint32_t trace_levels; 43 | 44 | static inline void trace_levels_set(uint32_t level, uint8_t enable) 45 | { 46 | if (enable) { 47 | trace_levels |= level; 48 | } 49 | else { 50 | trace_levels &= ~level; 51 | } 52 | } 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif //__DEBUG_TRACE_H_ 59 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.appveyor/check-generate-code.bat: -------------------------------------------------------------------------------- 1 | :: Copyright 2018 Google Inc. All rights reserved. 2 | :: 3 | :: Licensed under the Apache License, Version 2.0 (the "License"); 4 | :: you may not use this file except in compliance with the License. 5 | :: You may obtain a copy of the License at 6 | :: 7 | :: http://www.apache.org/licenses/LICENSE-2.0 8 | :: 9 | :: Unless required by applicable law or agreed to in writing, software 10 | :: distributed under the License is distributed on an "AS IS" BASIS, 11 | :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | :: See the License for the specific language governing permissions and 13 | :: limitations under the License. 14 | set buildtype=Release 15 | if "%1"=="-b" set buildtype=%2 16 | 17 | cd tests 18 | call generate_code.bat -b %buildtype% || goto FAIL 19 | 20 | :: TODO: Release and Debug builds produce differences here for some reason. 21 | git checkout HEAD -- monster_test.bfbs 22 | 23 | git -c core.autocrlf=true diff --exit-code --quiet || goto :DIFFFOUND 24 | goto SUCCESS 25 | 26 | :DIFFFOUND 27 | @echo "" >&2 28 | @echo "ERROR: ********************************************************" >&2 29 | @echo "ERROR: The following differences were found after running the" >&2 30 | @echo "ERROR: tests/generate_code.sh script. Maybe you forgot to run" >&2 31 | @echo "ERROR: it after making changes in a generator or schema?" >&2 32 | @echo "ERROR: ********************************************************" >&2 33 | @echo "" >&2 34 | @git -c core.autocrlf=true --no-pager diff --binary 35 | 36 | :FAIL 37 | set EXITCODE=1 38 | :SUCCESS 39 | cd .. 40 | EXIT /B %EXITCODE% -------------------------------------------------------------------------------- /jupyter_notebook/MnistProt/Stats.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: MnistProt 4 | 5 | import flatbuffers 6 | 7 | class Stats(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsStats(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = Stats() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # Stats 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # Stats 22 | def Version(self): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) 26 | return 0 27 | 28 | # Stats 29 | def Freq(self): 30 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) 31 | if o != 0: 32 | return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) 33 | return 0 34 | 35 | # Stats 36 | def Mode(self): 37 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) 38 | if o != 0: 39 | return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) 40 | return 0 41 | 42 | def StatsStart(builder): builder.StartObject(3) 43 | def StatsAddVersion(builder, version): builder.PrependUint8Slot(0, version, 0) 44 | def StatsAddFreq(builder, freq): builder.PrependUint32Slot(1, freq, 0) 45 | def StatsAddMode(builder, mode): builder.PrependInt8Slot(2, mode, 0) 46 | def StatsEnd(builder): return builder.EndObject() 47 | -------------------------------------------------------------------------------- /jupyter_notebook/export-to-tflite.py: -------------------------------------------------------------------------------- 1 | # Usage: 2 | # $ export-to-tflite.py model.h5 3 | # $ export-to-tflite.py model.h5 uint8 4 | # $ export-to-tflite.py model.h5 size 5 | 6 | 7 | import tensorflow as tf 8 | import os, sys 9 | 10 | def export(model_name, mode): 11 | converter = tf.lite.TFLiteConverter.from_keras_model_file(model_name) 12 | if 'uint8' in mode: 13 | print('Optimizing for QUANTIZED_UINT8') 14 | converter.inference_type = tf.uint8 15 | input_arrays = converter.get_input_arrays() 16 | converter.quantized_input_stats = {input_arrays[0] : (0., 1.)} # mean, std_dev 17 | converter.default_ranges_stats = [-1, 1] 18 | elif 'size' in mode: 19 | print('Optimizing for OPTIMIZE_FOR_SIZE') 20 | converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE] 21 | tflite_model = converter.convert() 22 | new_fname = os.path.splitext(model_name)[0] + '.tflite' 23 | open(new_fname, 'wb').write(tflite_model) 24 | print('---------------------------------------') 25 | # Get size of input file 26 | stat_inp = os.stat(model_name) 27 | print('Input model size: %d bytes' % stat_inp.st_size) 28 | # Get size of exported file 29 | stat_out = os.stat(new_fname) 30 | print('Output model size: %d bytes' % stat_out.st_size) 31 | print('Compress ratio: %f' % (stat_inp.st_size/stat_out.st_size)) 32 | print('Space savings: %f' % ( 100 - (stat_out.st_size*100.0/stat_inp.st_size))) 33 | 34 | if __name__=="__main__": 35 | model_name = sys.argv[1] 36 | mode = sys.argv[2] 37 | 38 | if 'h5' not in model_name: 39 | print('Can only convert HDF5 (*.h5) models') 40 | quit(1) 41 | 42 | export(model_name, mode) -------------------------------------------------------------------------------- /source/libs/flatbuffers/.travis/build-and-run-docker-test-containers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2018 Google Inc. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | set -e 17 | 18 | # build flatc on debian once to speed up the test loop below 19 | docker build -t build_flatc_debian_stretch -f tests/docker/Dockerfile.testing.build_flatc_debian_stretch . 20 | BUILD_CONTAINER_ID=$(docker create --read-only build_flatc_debian_stretch) 21 | docker cp ${BUILD_CONTAINER_ID}:/code/flatc flatc_debian_stretch 22 | 23 | for f in $(ls tests/docker/languages | sort) 24 | do 25 | # docker pull sometimes fails for unknown reasons, probably travisci-related. this retries the pull we need a few times. 26 | REQUIRED_BASE_IMAGE=$(cat tests/docker/languages/${f} | head -n 1 | awk ' { print $2 } ') 27 | 28 | set +e 29 | n=0 30 | until [ $n -ge 5 ] 31 | do 32 | docker pull $REQUIRED_BASE_IMAGE && break 33 | n=$[$n+1] 34 | sleep 1 35 | done 36 | set -e 37 | 38 | docker build -t $(echo ${f} | cut -f 3- -d .) -f tests/docker/languages/${f} . 39 | echo "TEST OK: ${f}" 40 | done 41 | -------------------------------------------------------------------------------- /jupyter_notebook/MnistProt/GetStats.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: MnistProt 4 | 5 | import flatbuffers 6 | 7 | class GetStats(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsGetStats(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = GetStats() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # GetStats 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # GetStats 22 | def Version(self): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) 26 | return 0 27 | 28 | # GetStats 29 | def Freq(self): 30 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) 31 | if o != 0: 32 | return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) 33 | return 0 34 | 35 | # GetStats 36 | def Mode(self): 37 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) 38 | if o != 0: 39 | return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) 40 | return 0 41 | 42 | def GetStatsStart(builder): builder.StartObject(3) 43 | def GetStatsAddVersion(builder, version): builder.PrependUint8Slot(0, version, 0) 44 | def GetStatsAddFreq(builder, freq): builder.PrependUint32Slot(1, freq, 0) 45 | def GetStatsAddMode(builder, mode): builder.PrependInt8Slot(2, mode, 0) 46 | def GetStatsEnd(builder): return builder.EndObject() 47 | -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/mod_led_main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This is an example test project for the mod_led.h (timer/scheduler library) 3 | * 4 | * @author: Dimitris Tassopoulos 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "LICENSE.h" 12 | #include "various_defs.h" 13 | #include "debug_trace.h" 14 | #include "mod_led.h" 15 | 16 | /* Set trace levels */ 17 | uint32_t trace_levels = \ 18 | TRACE_LEVEL_DEFAULT | 19 | 0; 20 | 21 | struct bsp_led { 22 | char port[20]; 23 | uint8_t pin; 24 | }; 25 | 26 | int port_init(void* bsp_data) 27 | { 28 | struct bsp_led * bsp = bsp_data; 29 | TRACE(("port_init: %s.%d\n", bsp->port, bsp->pin)); 30 | return bsp->pin; 31 | } 32 | 33 | int port_pin_low(void* bsp_data) 34 | { 35 | struct bsp_led * bsp = bsp_data; 36 | TRACE(("port_pin_low: %s.%d\n", bsp->port, bsp->pin)); 37 | return bsp->pin; 38 | } 39 | 40 | int port_pin_high(void* bsp_data) 41 | { 42 | struct bsp_led * bsp = bsp_data; 43 | TRACE(("port_pin_high: %s.%d\n", bsp->port, bsp->pin)); 44 | return bsp->pin; 45 | } 46 | 47 | 48 | int main() 49 | { 50 | DECLARE_MODULE_LED(led_module,8,1000); 51 | mod_led_init(&led_module); 52 | 53 | struct bsp_led led_data = {.port = "PORTA", .pin = 12}; 54 | 55 | DECLARE_DEV_LED(test_led, &led_module, 1, &led_data, &port_init, &port_pin_low, &port_pin_high); 56 | led_pattern_t blink = 0b11001010; 57 | dev_led_add(&test_led); 58 | dev_led_set_pattern(&test_led, blink); 59 | 60 | 61 | /* run the loop. In the ouput you should see the OBJ2 2 times/sec and OBJ1 1 time/sec */ 62 | while(1) { 63 | usleep(1000 * 1000); //every 1msec 64 | mod_led_update(&led_module); 65 | } 66 | 67 | return 0; 68 | } 69 | 70 | 71 | -------------------------------------------------------------------------------- /jupyter_notebook/MnistProt/InferenceInput.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: MnistProt 4 | 5 | import flatbuffers 6 | 7 | class InferenceInput(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsInferenceInput(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = InferenceInput() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # InferenceInput 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # InferenceInput 22 | def Digit(self, j): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | a = self._tab.Vector(o) 26 | return self._tab.Get(flatbuffers.number_types.Float32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) 27 | return 0 28 | 29 | # InferenceInput 30 | def DigitAsNumpy(self): 31 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 32 | if o != 0: 33 | return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float32Flags, o) 34 | return 0 35 | 36 | # InferenceInput 37 | def DigitLength(self): 38 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 39 | if o != 0: 40 | return self._tab.VectorLen(o) 41 | return 0 42 | 43 | def InferenceInputStart(builder): builder.StartObject(1) 44 | def InferenceInputAddDigit(builder, digit): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(digit), 0) 45 | def InferenceInputStartDigitVector(builder, numElems): return builder.StartVector(4, numElems, 4) 46 | def InferenceInputEnd(builder): return builder.EndObject() 47 | -------------------------------------------------------------------------------- /source/libs/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/datatypes_network.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file datatypes_network.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 30-Aug-2017 6 | * @brief Definitions of code generated network types 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2017 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | #ifndef __DATATYPES_NETWORK_H__ 22 | #define __DATATYPES_NETWORK_H__ 23 | #pragma once 24 | 25 | /* 26 | * Header to be overriden by the generated version 27 | * by including with <> the include directories are searched in the order 28 | * specified in the compiler 29 | * To enable the override, put the generated path before the API path 30 | */ 31 | 32 | #include "ai_platform.h" 33 | 34 | AI_API_DECLARE_BEGIN 35 | 36 | #ifdef AI_OVERRIDE_CUSTOM_TYPES 37 | #warning "Warning: Custom Types have been already defined!\n" 38 | #endif 39 | 40 | #define AI_CUSTOM_TYPES_COUNT (3) 41 | 42 | #define AI_CUSTOM_TYPES_SIGNATURE_DECLARE(name) \ 43 | const ai_custom_type_signature name[AI_CUSTOM_TYPES_COUNT+1] = { \ 44 | AI_CUSTOM_TYPES_COUNT, \ 45 | AI_CUSTOM_SIZE(ai_shape_dimension), \ 46 | AI_CUSTOM_SIZE(ai_stride_dimension), \ 47 | AI_CUSTOM_SIZE(ai_array_size), \ 48 | }; 49 | 50 | 51 | typedef ai_u32 ai_shape_dimension; 52 | typedef ai_i32 ai_stride_dimension; 53 | typedef ai_u32 ai_array_size; 54 | 55 | 56 | AI_API_DECLARE_END 57 | 58 | #endif /*__DATATYPES_NETWORK_H__*/ 59 | -------------------------------------------------------------------------------- /source/src/inc/mnistkeras_data.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file mnistkeras_data.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date Wed Jul 24 15:39:42 2019 6 | * @brief AI Tool Automatic Code Generator for Embedded NN computing 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | #ifndef __MNISTKERAS_DATA_H_ 22 | #define __MNISTKERAS_DATA_H_ 23 | #pragma once 24 | 25 | #include "ai_platform.h" 26 | 27 | #define AI_MNISTKERAS_DATA_CONFIG AI_HANDLE_NULL 28 | 29 | #define AI_MNISTKERAS_DATA_ACTIVATIONS_SIZE (33664) 30 | 31 | #define AI_MNISTKERAS_DATA_WEIGHTS_SIZE (263720) 32 | 33 | #define AI_MNISTKERAS_DATA_ACTIVATIONS(ptr_) \ 34 | AI_BUFFER_OBJ_INIT( \ 35 | AI_BUFFER_FORMAT_U8, \ 36 | 1, 1, AI_MNISTKERAS_DATA_ACTIVATIONS_SIZE, 1, \ 37 | AI_HANDLE_PTR(ptr_) ) 38 | 39 | #define AI_MNISTKERAS_DATA_WEIGHTS(ptr_) \ 40 | AI_BUFFER_OBJ_INIT( \ 41 | AI_BUFFER_FORMAT_U8|AI_BUFFER_FMT_FLAG_CONST, \ 42 | 1, 1, AI_MNISTKERAS_DATA_WEIGHTS_SIZE, 1, \ 43 | AI_HANDLE_PTR(ptr_) ) 44 | 45 | 46 | AI_API_DECLARE_BEGIN 47 | 48 | /*! 49 | * @brief Get network weights array pointer as a handle ptr. 50 | * @ingroup mnistkeras_data 51 | * @return a ai_handle pointer to the weights array 52 | */ 53 | AI_API_ENTRY 54 | ai_handle ai_mnistkeras_data_weights_get(void); 55 | 56 | 57 | AI_API_DECLARE_END 58 | 59 | #endif /* __MNISTKERAS_DATA_H_ */ 60 | 61 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/core_datatypes.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_datatypes.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 22-Aug-2018 6 | * @brief header file of core module private defines and datatypes 7 | * to public nor codegen tool 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© Copyright (c) 2018 STMicroelectronics. 12 | * All rights reserved.

13 | * 14 | * This software component is licensed by ST under Ultimate Liberty license 15 | * SLA0044, the "License"; You may not use this file except in compliance with 16 | * the License. You may obtain a copy of the License at: 17 | * www.st.com/SLA0044 18 | * 19 | ****************************************************************************** 20 | */ 21 | 22 | #ifndef __AI_CORE_DATATYPES_H_ 23 | #define __AI_CORE_DATATYPES_H_ 24 | #pragma once 25 | #include 26 | 27 | /*! 28 | * @defgroup Core Module Datatypes 29 | * @brief Data structures and defines used by core module 30 | */ 31 | 32 | /*! 33 | * @brief platform runtime core library version 34 | */ 35 | #define AI_PLATFORM_RUNTIME_MAJOR 4 36 | #define AI_PLATFORM_RUNTIME_MINOR 0 37 | #define AI_PLATFORM_RUNTIME_MICRO 0 38 | 39 | #define AI_MAGIC_CONTEXT_TOKEN (0xA1C00100) /*!< AI Cool! Magic Token */ 40 | 41 | #define AI_MAGIC_INSPECTOR_TOKEN (0xA1C00101) /*!< AI Cool! Magic Token */ 42 | 43 | 44 | #define AI_ID_OBJ(id) \ 45 | ((ai_id_obj)(id)) 46 | 47 | #define AI_C_ARRAY_COUNT(array_) \ 48 | ( sizeof(array_) / sizeof((array_)[0]) ) 49 | 50 | /*! 51 | * @typedef ai_id_obj 52 | * @ingroup core_datatypes 53 | * @brief numeric identifier for generic object instances (e.g. layers, 54 | * operators, etc.) It is used by codegen tool to keep tracks of specific 55 | * instances created 56 | */ 57 | typedef uint16_t ai_id_obj; 58 | 59 | #endif /*__AI_CORE_DATATYPES_H_*/ 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | # Prerequisites 50 | *.d 51 | 52 | # Compiled Object files 53 | *.slo 54 | *.lo 55 | *.o 56 | *.obj 57 | 58 | # Object files 59 | *.o 60 | *.ko 61 | *.obj 62 | *.elf 63 | 64 | # Linker output 65 | *.ilk 66 | *.map 67 | *.exp 68 | 69 | # Precompiled Headers 70 | *.gch 71 | *.pch 72 | 73 | # Libraries 74 | *.lib 75 | *.a 76 | *.la 77 | *.lo 78 | 79 | # Shared objects (inc. Windows DLLs) 80 | *.dll 81 | *.so 82 | *.so.* 83 | *.dylib 84 | 85 | # Executables 86 | *.exe 87 | *.out 88 | *.app 89 | *.i*86 90 | *.x86_64 91 | *.hex 92 | 93 | # Firmwares/Binaries 94 | *.bin 95 | 96 | # Debug files 97 | *.dSYM/ 98 | *.su 99 | *.idb 100 | *.pdb 101 | 102 | # Kernel Module Compile Results 103 | *.mod* 104 | *.cmd 105 | .tmp_versions/ 106 | modules.order 107 | Module.symvers 108 | Mkfile.old 109 | dkms.conf 110 | 111 | # eclipse project files 112 | *.cproject 113 | *.pydevproject 114 | *.project 115 | *.settings 116 | 117 | # sublime project files 118 | *.sublime-project 119 | *.sublime-workspace 120 | 121 | # visual studio project files 122 | *.vcxproj* 123 | 124 | # Visual Studio Code project file 125 | *.vscode 126 | 127 | # Keil μVision 128 | *.uvgui.* 129 | *.uvopt 130 | *.dep 131 | 132 | # Project specific 133 | build-stm32/ 134 | .ipynb_checkpoints/ 135 | __pycache__/ 136 | 137 | -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | # Prerequisites 50 | *.d 51 | 52 | # Compiled Object files 53 | *.slo 54 | *.lo 55 | *.o 56 | *.obj 57 | 58 | # Object files 59 | *.o 60 | *.ko 61 | *.obj 62 | *.elf 63 | 64 | # Linker output 65 | *.ilk 66 | *.map 67 | *.exp 68 | 69 | # Precompiled Headers 70 | *.gch 71 | *.pch 72 | 73 | # Libraries 74 | *.lib 75 | *.a 76 | *.la 77 | *.lo 78 | 79 | # Shared objects (inc. Windows DLLs) 80 | *.dll 81 | *.so 82 | *.so.* 83 | *.dylib 84 | 85 | # Executables 86 | *.exe 87 | *.out 88 | *.app 89 | *.i*86 90 | *.x86_64 91 | *.hex 92 | 93 | # Firmwares/Binaries 94 | *.bin 95 | 96 | # Debug files 97 | *.dSYM/ 98 | *.su 99 | *.idb 100 | *.pdb 101 | 102 | # Kernel Module Compile Results 103 | *.mod* 104 | *.cmd 105 | .tmp_versions/ 106 | modules.order 107 | Module.symvers 108 | Mkfile.old 109 | dkms.conf 110 | 111 | # eclipse project files 112 | *.cproject 113 | *.pydevproject 114 | *.project 115 | *.settings 116 | 117 | # sublime project files 118 | *.sublime-project 119 | *.sublime-workspace 120 | 121 | # visual studio project files 122 | *.vcxproj* 123 | 124 | # Visual Studio Code project file 125 | *.vscode 126 | vscode-bitbake-build/ 127 | 128 | # Keil μVision 129 | *.uvgui.* 130 | *.uvopt 131 | *.dep 132 | 133 | # Project specific 134 | build-stm32/ 135 | /Debug/ 136 | /Release/ 137 | -------------------------------------------------------------------------------- /source/src/inc/RTE_Components.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file 4 | * @author MCD Application Team 5 | * @version V2.0.0 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * COPYRIGHT(c) 2019 STMicroelectronics 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | */ 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __RTE_COMPONENTS_H__ 36 | #define __RTE_COMPONENTS_H__ 37 | 38 | /* Defines ------------------------------------------------------------------*/ 39 | #define AI_ApplicationTemplate 40 | 41 | #endif /* __RTE_COMPONENTS_H__ */ 42 | -------------------------------------------------------------------------------- /source/src/inc/stm32f7xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f7xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2019 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F7xx_IT_H 23 | #define __STM32F7xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void SVC_Handler(void); 56 | void DebugMon_Handler(void); 57 | void PendSV_Handler(void); 58 | void SysTick_Handler(void); 59 | void USART6_IRQHandler(void); 60 | void UART7_IRQHandler(void); 61 | /* USER CODE BEGIN EFP */ 62 | 63 | /* USER CODE END EFP */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __STM32F7xx_IT_H */ 70 | 71 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 72 | -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/states.h: -------------------------------------------------------------------------------- 1 | /** 2 | * states.h 3 | * 4 | * LICENSE: MIT 5 | * 6 | * This header lib can be used to create state machines. You can use 7 | * this lib for multiple state machines at the same time. Basic usage: 8 | * 9 | * 1. Create an enum the states 10 | * 2. Create a struct tp_state[] list with the above states 11 | * 3. Use DECLARE_STATE_OBJ to declare a new state machine. 12 | * 13 | * Dimitris Tassopoulos 14 | */ 15 | 16 | #ifndef __STATES_H_ 17 | #define __STATES_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include "LICENSE.h" 25 | 26 | typedef uint16_t state_t; 27 | 28 | struct tp_state { 29 | state_t state; 30 | void (*enter)(state_t prev, void * data); 31 | void (*run)(void * data); 32 | void (*exit)(state_t next, void * data); 33 | }; 34 | 35 | #define DECLARE_STATE(STATE,ENTER,RUN,EXIT) { \ 36 | .state = (state_t) STATE, \ 37 | .enter = ENTER, \ 38 | .run = RUN, \ 39 | .exit = EXIT, \ 40 | } 41 | 42 | struct obj_state_t { 43 | void *data; 44 | struct tp_state *state_list; 45 | uint16_t state_list_size; 46 | struct tp_state *state_curr; 47 | struct tp_state *state_next; 48 | }; 49 | 50 | #define DECLARE_STATE_OBJ(NAME,DATA,LIST,LIST_SIZE,CURR,NEXT) \ 51 | struct obj_state_t NAME = { \ 52 | .data = DATA, \ 53 | .state_list = LIST, \ 54 | .state_list_size = LIST_SIZE, \ 55 | .state_curr = CURR, \ 56 | .state_next = NEXT, \ 57 | } 58 | 59 | 60 | inline void __attribute__((always_inline)) 61 | state_change(struct obj_state_t * obj, state_t next) 62 | { 63 | if (next < obj->state_list_size) 64 | obj->state_next = &obj->state_list[next]; 65 | } 66 | 67 | inline void __attribute__((always_inline)) 68 | state_handler(struct obj_state_t * obj) 69 | { 70 | if (obj->state_curr != obj->state_next) { 71 | if (obj->state_curr->exit) 72 | obj->state_curr->exit(obj->state_next->state, obj->data); 73 | if (obj->state_next->enter) 74 | obj->state_next->enter(obj->state_curr->state, obj->data); 75 | obj->state_curr = obj->state_next; 76 | 77 | #ifdef TRACE 78 | TRACE(("state: %d -> %d\n", obj->state_curr->state, obj->state_next->state)); 79 | #endif 80 | } 81 | if (obj->state_curr->run) 82 | obj->state_curr->run(obj->data); 83 | } 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif // __STATES_H_ 90 | -------------------------------------------------------------------------------- /source/libs/CMSIS/DSP/Source/MatrixFunctions/arm_mat_init_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_mat_init_f32.c 4 | * Description: Floating-point matrix initialization 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "arm_math.h" 30 | 31 | /** 32 | * @ingroup groupMatrix 33 | */ 34 | 35 | /** 36 | * @defgroup MatrixInit Matrix Initialization 37 | * 38 | * Initializes the underlying matrix data structure. 39 | * The functions set the numRows, 40 | * numCols, and pData fields 41 | * of the matrix data structure. 42 | */ 43 | 44 | /** 45 | * @addtogroup MatrixInit 46 | * @{ 47 | */ 48 | 49 | /** 50 | * @brief Floating-point matrix initialization. 51 | * @param[in,out] *S points to an instance of the floating-point matrix structure. 52 | * @param[in] nRows number of rows in the matrix. 53 | * @param[in] nColumns number of columns in the matrix. 54 | * @param[in] *pData points to the matrix data array. 55 | * @return none 56 | */ 57 | 58 | void arm_mat_init_f32( 59 | arm_matrix_instance_f32 * S, 60 | uint16_t nRows, 61 | uint16_t nColumns, 62 | float32_t * pData) 63 | { 64 | /* Assign Number of Rows */ 65 | S->numRows = nRows; 66 | 67 | /* Assign Number of Columns */ 68 | S->numCols = nColumns; 69 | 70 | /* Assign Data pointer */ 71 | S->pData = pData; 72 | } 73 | 74 | /** 75 | * @} end of MatrixInit group 76 | */ 77 | -------------------------------------------------------------------------------- /source/src/inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f7xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | extern __IO uint32_t glb_tmr_1ms; 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | void MX_USART6_UART_Init(void); 62 | /* USER CODE BEGIN Private defines */ 63 | 64 | /* USER CODE END Private defines */ 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* __MAIN_H */ 71 | 72 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 73 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/.gitignore: -------------------------------------------------------------------------------- 1 | *_wire.txt 2 | *_wire.bin 3 | .DS_Store 4 | *.o 5 | *.o.d 6 | *.class 7 | *.a 8 | *.swp 9 | *~ 10 | *.vcxproj 11 | *.vcxproj.filters 12 | *.vcxproj.user 13 | *.sln 14 | *.suo 15 | *.opendb 16 | *.keystore 17 | **/.vs/** 18 | **/bin/** 19 | !tests/rust_usage_test/bin/** 20 | **/gen/** 21 | **/libs/** 22 | **/obj/** 23 | **/*.dir/** 24 | **/CMakeFiles/** 25 | **/cmake_install.cmake 26 | **/install_manifest.txt 27 | **/CMakeCache.txt 28 | **/CMakeTestfile.cmake 29 | **/CPackConfig.cmake 30 | **/CPackSourceConfig.cmake 31 | **/compile_commands.json 32 | **/Debug/** 33 | **/Release/** 34 | **/RelWithDebInfo/** 35 | **/x64/ #build artifacts from VS 36 | build.xml 37 | local.properties 38 | project.properties 39 | proguard-project.txt 40 | linklint_results 41 | Makefile 42 | flatc 43 | flatc.exe 44 | flathash 45 | flathash.exe 46 | flattests 47 | flattests.exe 48 | flatsamplebinary 49 | flatsamplebinary.exe 50 | flatsampletext 51 | flatsampletext.exe 52 | flatsamplebfbs 53 | flatsamplebfbs.exe 54 | grpctest 55 | grpctest.exe 56 | snapshot.sh 57 | tags 58 | tests/dart_gen 59 | tests/go_gen 60 | tests/monsterdata_java_wire.mon 61 | tests/monsterdata_java_wire_sp.mon 62 | tests/monsterdata_go_wire.mon 63 | tests/monsterdata_javascript_wire.mon 64 | tests/monsterdata_lobster_wire.mon 65 | tests/monsterdata_rust_wire.mon 66 | tests/unicode_test.mon 67 | tests/ts/ 68 | tests/php/ 69 | CMakeLists.txt.user 70 | CMakeScripts/** 71 | CTestTestfile.cmake 72 | FlatbuffersConfigVersion.cmake 73 | FlatBuffers.cbp 74 | build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/** 75 | build/Xcode/FlatBuffers.xcodeproj/xcuserdata/** 76 | FlatBuffers.xcodeproj/ 77 | java/.idea 78 | java/*.iml 79 | .idea 80 | *.iml 81 | target 82 | **/*.pyc 83 | build/VS2010/FlatBuffers.sdf 84 | build/VS2010/FlatBuffers.opensdf 85 | build/VS2010/ipch/**/*.ipch 86 | *.so 87 | Testing/Temporary 88 | .cproject 89 | .settings/ 90 | .project 91 | net/**/obj 92 | node_modules/ 93 | android/.externalNativeBuild/ 94 | android/.gradle/ 95 | android/build/ 96 | samples/android/.externalNativeBuild/ 97 | samples/android/.gradle/ 98 | samples/android/build/ 99 | js/flatbuffers.mjs 100 | /bazel-bin 101 | /bazel-flatbuffers 102 | /bazel-genfiles 103 | /bazel-out 104 | /bazel-testlogs 105 | .ninja_deps 106 | .ninja_log 107 | build.ninja 108 | rules.ninja 109 | .vscode 110 | dart/.pub/ 111 | dart/.packages 112 | dart/pubspec.lock 113 | dart/.dart_tool/ 114 | dart/build/ 115 | dart/doc/api/ 116 | Cargo.lock 117 | .corpus** 118 | .seed** 119 | -------------------------------------------------------------------------------- /jupyter_notebook/MnistProt/InferenceOutput.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: MnistProt 4 | 5 | import flatbuffers 6 | 7 | class InferenceOutput(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsInferenceOutput(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = InferenceOutput() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # InferenceOutput 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # InferenceOutput 22 | def OutputF(self, j): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | a = self._tab.Vector(o) 26 | return self._tab.Get(flatbuffers.number_types.Float32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) 27 | return 0 28 | 29 | # InferenceOutput 30 | def OutputFAsNumpy(self): 31 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 32 | if o != 0: 33 | return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float32Flags, o) 34 | return 0 35 | 36 | # InferenceOutput 37 | def OutputFLength(self): 38 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 39 | if o != 0: 40 | return self._tab.VectorLen(o) 41 | return 0 42 | 43 | # InferenceOutput 44 | def OutputN(self): 45 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) 46 | if o != 0: 47 | return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) 48 | return 0 49 | 50 | # InferenceOutput 51 | def TimerMs(self): 52 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) 53 | if o != 0: 54 | return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) 55 | return 0.0 56 | 57 | def InferenceOutputStart(builder): builder.StartObject(3) 58 | def InferenceOutputAddOutputF(builder, outputF): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(outputF), 0) 59 | def InferenceOutputStartOutputFVector(builder, numElems): return builder.StartVector(4, numElems, 4) 60 | def InferenceOutputAddOutputN(builder, outputN): builder.PrependUint8Slot(1, outputN, 0) 61 | def InferenceOutputAddTimerMs(builder, timerMs): builder.PrependFloat32Slot(2, timerMs, 0.0) 62 | def InferenceOutputEnd(builder): return builder.EndObject() 63 | -------------------------------------------------------------------------------- /jupyter_notebook/MnistProt/Commands.py: -------------------------------------------------------------------------------- 1 | # automatically generated by the FlatBuffers compiler, do not modify 2 | 3 | # namespace: MnistProt 4 | 5 | import flatbuffers 6 | 7 | class Commands(object): 8 | __slots__ = ['_tab'] 9 | 10 | @classmethod 11 | def GetRootAsCommands(cls, buf, offset): 12 | n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) 13 | x = Commands() 14 | x.Init(buf, n + offset) 15 | return x 16 | 17 | # Commands 18 | def Init(self, buf, pos): 19 | self._tab = flatbuffers.table.Table(buf, pos) 20 | 21 | # Commands 22 | def Cmd(self): 23 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) 24 | if o != 0: 25 | return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) 26 | return 0 27 | 28 | # Commands 29 | def Stats(self): 30 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) 31 | if o != 0: 32 | x = self._tab.Indirect(o + self._tab.Pos) 33 | from .Stats import Stats 34 | obj = Stats() 35 | obj.Init(self._tab.Bytes, x) 36 | return obj 37 | return None 38 | 39 | # Commands 40 | def Input(self): 41 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) 42 | if o != 0: 43 | x = self._tab.Indirect(o + self._tab.Pos) 44 | from .InferenceInput import InferenceInput 45 | obj = InferenceInput() 46 | obj.Init(self._tab.Bytes, x) 47 | return obj 48 | return None 49 | 50 | # Commands 51 | def Ouput(self): 52 | o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) 53 | if o != 0: 54 | x = self._tab.Indirect(o + self._tab.Pos) 55 | from .InferenceOutput import InferenceOutput 56 | obj = InferenceOutput() 57 | obj.Init(self._tab.Bytes, x) 58 | return obj 59 | return None 60 | 61 | def CommandsStart(builder): builder.StartObject(4) 62 | def CommandsAddCmd(builder, cmd): builder.PrependInt8Slot(0, cmd, 0) 63 | def CommandsAddStats(builder, stats): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(stats), 0) 64 | def CommandsAddInput(builder, input): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(input), 0) 65 | def CommandsAddOuput(builder, ouput): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(ouput), 0) 66 | def CommandsEnd(builder): return builder.EndObject() 67 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/layers_dense.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_dense.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 18-Apr-2018 6 | * @brief header file of AI platform dense layers datatypes 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© COPYRIGHT(c) 2018 STMicroelectronics

11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of STMicroelectronics nor the names of its 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | #ifndef __LAYERS_DENSE_H_ 39 | #define __LAYERS_DENSE_H_ 40 | #pragma once 41 | 42 | 43 | #include "layers_common.h" 44 | 45 | 46 | /*! 47 | * @defgroup layers Normalization Layers Definitions 48 | * @brief definition 49 | * 50 | */ 51 | 52 | AI_API_DECLARE_BEGIN 53 | 54 | /*! 55 | * @brief Computes the activations of a fixed point dense (fully connected) layer. 56 | * @ingroup layers_dense 57 | * @param layer the dense layer 58 | */ 59 | AI_INTERNAL_API 60 | void forward_dense_fixed(ai_layer *pLayer); 61 | 62 | AI_API_DECLARE_END 63 | 64 | #endif /*__LAYERS_DENSE_H_*/ 65 | 66 | -------------------------------------------------------------------------------- /source/src/inc/comm_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * comm_buffer.h 3 | * 4 | * Copyright 2018 Dimitris Tassopoulos 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | * of the Software, and to permit persons to whom the Software is furnished to do 11 | * so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 17 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef COMM_BUFFER_H_ 26 | #define COMM_BUFFER_H_ 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | /** 36 | * @brief This is a struct that is used for UART comms 37 | */ 38 | struct tp_comm_buffer { 39 | /* tx vars */ 40 | uint8_t *tx_buffer; 41 | size_t tx_buffer_size; 42 | uint8_t tx_ready; 43 | uint16_t tx_ptr_in; 44 | uint16_t tx_ptr_out; 45 | uint16_t tx_length; 46 | uint8_t tx_int_en; 47 | /* rx vars */ 48 | uint8_t *rx_buffer; 49 | size_t rx_buffer_size; 50 | uint8_t rx_ready; 51 | uint8_t rx_ready_tmr; 52 | uint16_t rx_ptr_in; 53 | uint16_t rx_ptr_out; 54 | uint16_t rx_length; 55 | volatile uint8_t rx_tmp; 56 | }; 57 | 58 | #define DECLARE_COMM_BUFFER(NAME, TX_SIZE, RX_SIZE) \ 59 | uint8_t comm_tx_buffer_##NAME[TX_SIZE]; \ 60 | uint8_t comm_rx_buffer_##NAME[RX_SIZE]; \ 61 | volatile struct tp_comm_buffer NAME = {.tx_buffer = comm_tx_buffer_##NAME, \ 62 | .tx_buffer_size = TX_SIZE, \ 63 | .rx_buffer = comm_rx_buffer_##NAME, \ 64 | .rx_buffer_size = RX_SIZE} 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* COMM_BUFFER_H_ */ 71 | -------------------------------------------------------------------------------- /source/cmake/TOOLCHAIN_arm_none_eabi_cortex_m7.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE toolchain for the gcc arm-none-eabi 2 | # 3 | set(CMAKE_SYSTEM_NAME Generic) 4 | set(CMAKE_SYSTEM_VERSION 1) 5 | set(CMAKE_SYSTEM_PROCESSOR arm-none-eabi) 6 | 7 | # set arm-none-eabi toolchain paths 8 | if (NOT TOOLCHAIN_DIR) 9 | set(TOOLCHAIN_DIR /path/to/toolchain) 10 | endif() 11 | 12 | set(TOOL_CHAIN_PREFIX arm-none-eabi) 13 | set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_DIR}/bin) 14 | set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_DIR}/lib) 15 | 16 | if(WIN32) 17 | set(EXE .exe) 18 | endif(WIN32) 19 | 20 | # which compilers to use for C and C++ 21 | # 22 | SET(CMAKE_AR ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-gcc-ar${EXE}) 23 | SET(CMAKE_RANLIB ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-gcc-ranlib${EXE}) 24 | SET(CMAKE_LD ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-ld${EXE}) 25 | set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-gcc${EXE}) 26 | set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-g++${EXE}) 27 | set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-as${EXE}) 28 | set(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-objcopy${EXE} CACHE INTERNAL "objcopy command") 29 | set(CMAKE_OBJDUMP ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-objdump${EXE} CACHE INTERNAL "objdump command") 30 | set(CMAKE_GDB ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-gdb${EXE}) 31 | set(CMAKE_SIZE ${TOOLCHAIN_BIN_DIR}/${TOOL_CHAIN_PREFIX}-size${EXE}) 32 | 33 | # set(CMAKE_C_ARCHIVE_CREATE " qc ") 34 | set(CMAKE_C_ARCHIVE_CREATE "${CMAKE_AR} qc ") 35 | set(CMAKE_C_ARCHIVE_FINISH " ") 36 | 37 | set(COMPILER_OPTIONS "-g -mthumb -fno-builtin -mcpu=cortex-m7 -mfpu=fpv5-sp-d16 -mfloat-abi=softfp ") 38 | set(COMMON_FLAGS "-Wall -std=gnu99 -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize") 39 | set(LIB_FLAGS "-lm -lc -lnosys --specs=nosys.specs") 40 | SET(CMAKE_C_FLAGS "${COMPILER_OPTIONS} ${COMMON_FLAGS} ${LIB_FLAGS} " CACHE INTERNAL "c compiler flags") 41 | SET(CMAKE_CXX_FLAGS "${COMPILER_OPTIONS} ${COMMON_FLAGS} ${LIB_FLAGS} " CACHE INTERNAL "cxx compiler flags") 42 | SET(CMAKE_ASM_FLAGS "-g -mthumb -mcpu=cortex-m7 -mfpu=fpv5-sp-d16 -mfloat-abi=softfp " CACHE INTERNAL "asm compiler flags") 43 | 44 | SET(CMAKE_EXE_LINKER_FLAGS "${COMPILER_OPTIONS} -mabi=aapcs -Wl,-Map=linker.map -Wl,-cref -Wl,--gc-sections" CACHE INTERNAL "exe link flags") 45 | 46 | # adjust the default behaviour of the FIND_XXX() commands: 47 | # search headers and libraries in the target environment, 48 | # search programs in the host environment 49 | # 50 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) 51 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 52 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 53 | 54 | SET(CMAKE_ASM_COMPILE_OBJECT " -o ") 55 | -------------------------------------------------------------------------------- /source/libs/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /extras/digit.csv: -------------------------------------------------------------------------------- 1 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.003921568627451,0.011764705882353,0.027450980392157,0.019607843137255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.019607843137255,0.019607843137255,0,0,0,0,0,0.015686274509804,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.023529411764706,0,0,0,0,0,0.254901960784314,0.062745098039216,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.047058823529412,0.607843137254902,1,1,1,1,0.898039215686275,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.188235294117647,1,1,1,1,1,1,1,1,1,0.341176470588235,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.596078431372549,1,1,0.792156862745098,0.4,0.164705882352941,0.549019607843137,1,1,1,1,1,0,0,0.011764705882353,0,0,0,0,0,0,0,0,0,0,0,0,0.749019607843137,1,0.419607843137255,0,0,0,0,0,0,0.737254901960784,1,1,1,0.956862745098039,0,0.015686274509804,0,0,0,0,0,0,0,0,0,0.015686274509804,0,0.305882352941176,0.603921568627451,0,0,0,0.007843137254902,0.027450980392157,0.019607843137255,0.011764705882353,0,0,0.737254901960784,1,1,1,0,0,0.003921568627451,0,0,0,0,0,0,0,0,0,0,0,0,0,0.031372549019608,0.011764705882353,0,0,0,0,0.019607843137255,0,0,1,1,1,0,0,0.003921568627451,0,0,0,0,0,0,0,0,0,0,0,0.015686274509804,0.003921568627451,0,0,0,0,0,0,0,0.003921568627451,0,0.862745098039216,1,0.564705882352941,0,0.027450980392157,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0.003921568627451,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.019607843137255,0,0,1,0.027450980392157,0,0.007843137254902,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.003921568627451,0,0,1,0.372549019607843,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.003921568627451,0,0,0.803921568627451,0.443137254901961,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.003921568627451,0,0,0.870588235294118,0.505882352941176,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.003921568627451,0,0,0.862745098039216,0.501960784313726,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.015686274509804,0,0,0.815686274509804,0.47843137254902,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0.505882352941176,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.192156862745098,1,0.443137254901961,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.305882352941176,1,0.16078431372549,0,0.007843137254902,0.023529411764706,0.019607843137255,0.015686274509804,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.168627450980392,1,0,0,0,0,0,0,0,0,0.027450980392157,0.027450980392157,0.027450980392157,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.086274509803922,1,1,1,1,0.792156862745098,0.643137254901961,0.435294117647059,0.098039215686275,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.011764705882353,0,0.058823529411765,1,1,1,1,1,1,1,1,1,1,1,0.603921568627451,0.584313725490196,0.643137254901961,0,0,0,0,0,0,0,0,0,0,0,0.003921568627451,0,0,0.549019607843137,0.67843137254902,0.972549019607843,1,1,1,1,1,1,1,1,1,1,0.929411764705882,0,0.007843137254902,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.235294117647059,0.686274509803922,1,1,1,1,0.619607843137255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.003921568627451,0.027450980392157,0.027450980392157,0,0,0,0,0,0,0,0,0,0.07843137254902,0,0,0.007843137254902,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.003921568627451,0.003921568627451,0.007843137254902,0.015686274509804,0.015686274509804,0,0,0,0,0.003921568627451,0,0,0,0,0,0,0,0,0 2 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/formats_list.h: -------------------------------------------------------------------------------- 1 | 2 | /* FMT_ENTRY( exp_(0/1 only), name_, type_id_, 3 | * sign_bit_, float_bit_, pbits_, bits_, fbits_, ldiv_bits_) 4 | * Specifications (in order of the bit fields, little endian): 5 | - name_ : it is the enum used to define both the ai_array_format and 6 | ai_buffer_format. 7 | - exp_ (1bit) : it is a boolean flag (0 or 1) indicating whether the format 8 | is available as a public APIs ai_buffer format. in this case the field 9 | exp_name_ indicates the enum name of the ai_buffer format 10 | - (7 bits): reserved for flags 11 | - sign_bit_ (1bit) : codes whether or not the format is of a signed type 12 | - float_bit_ (1bit) : codes if the format is float 13 | - ldiv_bits (2 bits) : right shift value for computing the byte size of the 14 | format 15 | - type_id_ (4bits) : it is used to define the "family" of the format: 16 | see @ref AI_FMT_Q as an example. Currently supported types are: 17 | AI_FMT_Q (fixed point types), AI_FMT_FLOAT (floating point values), 18 | AI_FMT_LUT4 or AI_FMT_LUT8 (compressed formats) 19 | - pbits_ (3bits) : number of padding bits for the format 20 | - bits_ (7bits) : size in bits of the format (NB: integer+fractional bits) 21 | - fbits_ (7bits) : number of fractional bits for the format (for AI_FMT_Q only) 22 | 23 | */ 24 | 25 | /* Macro tricks are here: 26 | * https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms 27 | */ 28 | 29 | /* Format none entry */ 30 | FMT_ENTRY(1, NONE, AI_FMT_NONE, 0, 0, 0, 0, 0, 0) 31 | 32 | /* Floating point formats */ 33 | FMT_ENTRY(1, FLOAT, AI_FMT_FLOAT, 1, 1, 0, 32, 0, 0) 34 | FMT_ENTRY(0, FLOAT64, AI_FMT_FLOAT, 1, 1, 0, 64, 0, 0) 35 | FMT_ENTRY(0, FLOAT16, AI_FMT_FLOAT, 1, 1, 0, 16, 0, 0) 36 | 37 | /* Integer formats (i.e. fractional bits = 0!) */ 38 | FMT_ENTRY(1, U8, AI_FMT_Q, 0, 0, 0, 8, 0, 0) 39 | FMT_ENTRY(1, U16, AI_FMT_Q, 0, 0, 0, 16, 0, 0) 40 | FMT_ENTRY(0, U32, AI_FMT_Q, 0, 0, 0, 32, 0, 0) 41 | FMT_ENTRY(0, U64, AI_FMT_Q, 0, 0, 0, 64, 0, 0) 42 | FMT_ENTRY(0, U4, AI_FMT_Q, 0, 0, 0, 4, 0, 0) 43 | 44 | FMT_ENTRY(1, S8, AI_FMT_Q, 1, 0, 0, 8, 0, 0) 45 | FMT_ENTRY(1, S16, AI_FMT_Q, 1, 0, 0, 16, 0, 0) 46 | FMT_ENTRY(0, S32, AI_FMT_Q, 1, 0, 0, 32, 0, 0) 47 | FMT_ENTRY(0, S64, AI_FMT_Q, 1, 0, 0, 64, 0, 0) 48 | FMT_ENTRY(0, S4, AI_FMT_Q, 1, 0, 0, 4, 0, 0) 49 | 50 | /* Fixed-point formats including ARM CMSIS Q7, Q15, Q31 ones */ 51 | FMT_ENTRY(1, Q, AI_FMT_Q, 1, 0, 0, 0, 0, 0) 52 | FMT_ENTRY(1, Q7, AI_FMT_Q, 1, 0, 0, 8, 7, 0) 53 | FMT_ENTRY(1, Q15, AI_FMT_Q, 1, 0, 0, 16, 15, 0) 54 | FMT_ENTRY(0, Q31, AI_FMT_Q, 1, 0, 0, 32, 31, 0) 55 | 56 | FMT_ENTRY(1, UQ, AI_FMT_Q, 0, 0, 0, 0, 0, 0) 57 | FMT_ENTRY(1, UQ7, AI_FMT_Q, 0, 0, 0, 8, 7, 0) 58 | FMT_ENTRY(1, UQ15, AI_FMT_Q, 0, 0, 0, 16, 15, 0) 59 | FMT_ENTRY(0, UQ31, AI_FMT_Q, 0, 0, 0, 32, 31, 0) 60 | 61 | /* Compressed formats */ 62 | FMT_ENTRY(0, LUT4_FLOAT, AI_FMT_LUT4, 1, 1, 0, 32, 0, 3) 63 | FMT_ENTRY(0, LUT8_FLOAT, AI_FMT_LUT8, 1, 1, 0, 32, 0, 2) 64 | FMT_ENTRY(0, LUT4_Q15, AI_FMT_LUT4, 1, 0, 0, 16, 15, 2) 65 | FMT_ENTRY(0, LUT8_Q15, AI_FMT_LUT8, 1, 0, 0, 16, 15, 1) 66 | FMT_ENTRY(0, LUT4_UQ15, AI_FMT_LUT4, 0, 0, 0, 16, 15, 2) 67 | FMT_ENTRY(0, LUT8_UQ15, AI_FMT_LUT8, 0, 0, 0, 16, 15, 1) 68 | 69 | #undef FMT_ENTRY 70 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/layers.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 01-May-2017 6 | * @brief header file of AI platform layers datatypes 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2017 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | #ifndef __LAYERS_H_ 22 | #define __LAYERS_H_ 23 | #pragma once 24 | 25 | #include "layers_common.h" 26 | #include "layers_conv2d.h" 27 | #include "layers_generic.h" 28 | #include "layers_nl.h" 29 | #include "layers_norm.h" 30 | #include "layers_pool.h" 31 | #include "layers_rnn.h" 32 | #include "layers_dense.h" 33 | #include "layers_sm.h" 34 | 35 | #ifdef USE_OPERATORS 36 | #include "layers_lambda.h" 37 | #endif /* USE_OPERATORS */ 38 | 39 | 40 | AI_API_DECLARE_BEGIN 41 | 42 | /*! 43 | * @defgroup layers Layers 44 | * @brief Definition of the forward functions for the layers and the general 45 | * ai_layer datastructure used to abstract specific layer implementation in the 46 | * generic forward function definition 47 | * 48 | * The forward function for a layer computes the layer activations given the 49 | * activations of the previous layer. They are added to the layer as function 50 | * pointer and called implicitly by the @ref ai_layers_forward_all function. 51 | * The input activations are read from layer → in and the computed 52 | * activations stored in layer → out. The layer type needs to be compatible 53 | * with the forward function, but layers with the same layout (e.g. `mp` and 54 | * `ap`) can share the same structure. 55 | */ 56 | 57 | /******************************************************************************/ 58 | /* Forward Functions Section */ 59 | /******************************************************************************/ 60 | 61 | /*! 62 | * @brief Executes a single layer in the network. 63 | * @ingroup layers 64 | * @param layer the layer to process 65 | * @return pointer to the next layer 66 | */ 67 | AI_INTERNAL_API 68 | ai_layer* ai_layers_forward_layer(ai_layer* layer); 69 | 70 | 71 | /*! 72 | * @brief Computes the ouptut of the network given the input. 73 | * @ingroup layers 74 | * 75 | * Given a network with the input pre-loaded in the net → in tensor, 76 | * computes the output by calling the forward functions of each layer and 77 | * selecting the next layer. When the layer has no successor or it's in a 78 | * loop-back configuration (layer → next is again layer), the function 79 | * stops. The result is stored in net → out. 80 | * 81 | * @param net the network to evaluate 82 | */ 83 | AI_INTERNAL_API 84 | void ai_layers_forward_all(ai_network* net); 85 | 86 | AI_API_DECLARE_END 87 | 88 | #endif /* __LAYERS_H_ */ 89 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/include/flatbuffers/flatc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include "flatbuffers.h" 21 | #include "idl.h" 22 | #include "util.h" 23 | 24 | #ifndef FLATC_H_ 25 | # define FLATC_H_ 26 | 27 | namespace flatbuffers { 28 | 29 | class FlatCompiler { 30 | public: 31 | // Output generator for the various programming languages and formats we 32 | // support. 33 | struct Generator { 34 | typedef bool (*GenerateFn)(const flatbuffers::Parser &parser, 35 | const std::string &path, 36 | const std::string &file_name); 37 | typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser, 38 | const std::string &path, 39 | const std::string &file_name); 40 | 41 | GenerateFn generate; 42 | const char *generator_opt_short; 43 | const char *generator_opt_long; 44 | const char *lang_name; 45 | bool schema_only; 46 | GenerateFn generateGRPC; 47 | flatbuffers::IDLOptions::Language lang; 48 | const char *generator_help; 49 | MakeRuleFn make_rule; 50 | }; 51 | 52 | typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn, 53 | bool show_exe_name); 54 | 55 | typedef void (*ErrorFn)(const FlatCompiler *flatc, const std::string &err, 56 | bool usage, bool show_exe_name); 57 | 58 | // Parameters required to initialize the FlatCompiler. 59 | struct InitParams { 60 | InitParams() 61 | : generators(nullptr), 62 | num_generators(0), 63 | warn_fn(nullptr), 64 | error_fn(nullptr) {} 65 | 66 | const Generator *generators; 67 | size_t num_generators; 68 | WarnFn warn_fn; 69 | ErrorFn error_fn; 70 | }; 71 | 72 | explicit FlatCompiler(const InitParams ¶ms) : params_(params) {} 73 | 74 | int Compile(int argc, const char **argv); 75 | 76 | std::string GetUsageString(const char *program_name) const; 77 | 78 | private: 79 | void ParseFile(flatbuffers::Parser &parser, const std::string &filename, 80 | const std::string &contents, 81 | std::vector &include_directories) const; 82 | 83 | void LoadBinarySchema(Parser &parser, const std::string &filename, 84 | const std::string &contents); 85 | 86 | void Warn(const std::string &warn, bool show_exe_name = true) const; 87 | 88 | void Error(const std::string &err, bool usage = true, 89 | bool show_exe_name = true) const; 90 | 91 | InitParams params_; 92 | }; 93 | 94 | } // namespace flatbuffers 95 | 96 | #endif // FLATC_H_ 97 | -------------------------------------------------------------------------------- /source/src/inc/constants_ai.h: -------------------------------------------------------------------------------- 1 | /* Define to prevent recursive inclusion -------------------------------------*/ 2 | #ifndef __CONSTANTS_H 3 | #define __CONSTANTS_H 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | /** 8 | ****************************************************************************** 9 | * @file : constants.h 10 | * @brief : AI constants definitions 11 | ****************************************************************************** 12 | * This notice applies to any and all portions of this file 13 | * that are not between comment pairs USER CODE BEGIN and 14 | * USER CODE END. Other portions of this file, whether 15 | * inserted by the user or by software development tools 16 | * are owned by their respective copyright owners. 17 | * 18 | * Copyright (c) 2018 STMicroelectronics International N.V. 19 | * All rights reserved. 20 | * 21 | * Redistribution and use in source and binary forms, with or without 22 | * modification, are permitted, provided that the following conditions are met: 23 | * 24 | * 1. Redistribution of source code must retain the above copyright notice, 25 | * this list of conditions and the following disclaimer. 26 | * 2. Redistributions in binary form must reproduce the above copyright notice, 27 | * this list of conditions and the following disclaimer in the documentation 28 | * and/or other materials provided with the distribution. 29 | * 3. Neither the name of STMicroelectronics nor the names of other 30 | * contributors to this software may be used to endorse or promote products 31 | * derived from this software without specific written permission. 32 | * 4. This software, including modifications and/or derivative works of this 33 | * software, must execute solely and exclusively on microcontroller or 34 | * microprocessor devices manufactured by or for STMicroelectronics. 35 | * 5. Redistribution and use of this software other than as permitted under 36 | * this license is void and will automatically terminate your rights under 37 | * this license. 38 | * 39 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 40 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 41 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 42 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 43 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 44 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 45 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 47 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 48 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 49 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 50 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 | * 52 | ****************************************************************************** 53 | */ 54 | /* Constants definitions ------------------------------------------------------------------*/ 55 | #define MIN_HEAP_SIZE 56 | #define MIN_STACK_SIZE 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /*__constants_ai_h_H */ 62 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/layers_sm.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_sm.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 18-Apr-2018 6 | * @brief header file of AI platform non softmax layer datatype 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© COPYRIGHT(c) 2018 STMicroelectronics

11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of STMicroelectronics nor the names of its 20 | * contributors may be used to endorse or promote products derived from 21 | * this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 | * POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | #ifndef __LAYERS_SM_H_ 39 | #define __LAYERS_SM_H_ 40 | #pragma once 41 | 42 | #include "layers_common.h" 43 | 44 | /*! 45 | * @defgroup layers SoftMax Layer Definitions 46 | * @brief definition 47 | * 48 | */ 49 | 50 | AI_API_DECLARE_BEGIN 51 | 52 | /*! 53 | * @brief Softmax normalization computed on an array of fixed point channels 54 | * @ingroup layers_sm 55 | * @param out opaque handler to output channel array 56 | * @param in opaque handler to input channel array 57 | * @param in_size total size (number of elements) to process on the input 58 | * @param channel_size number of elements of the input channel 59 | * @param in_channel_step number of elements to move to next input element 60 | * @param out_channel_step number of elements to move to next output element 61 | */ 62 | AI_INTERNAL_API 63 | void sm_func_sm_array_fixed(ai_handle out, const ai_handle in, 64 | const ai_size in_size, 65 | const ai_size channel_size, 66 | const ai_size in_channel_step, 67 | const ai_size out_channel_step); 68 | 69 | /*! 70 | * @brief Computes the activations of a fixed point softmax nonlinear layer. 71 | * @ingroup layers_sm 72 | * @param layer the softmax (sm) layer 73 | */ 74 | AI_INTERNAL_API 75 | void forward_sm_fixed(ai_layer *pLayer); 76 | 77 | AI_API_DECLARE_END 78 | 79 | #endif /*__LAYERS_SM_H_*/ 80 | 81 | -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/states_main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * This is an example test project for the state.h (state machine library) 3 | * 4 | * @author: Dimitris Tassopoulos 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "LICENSE.h" 13 | #include "various_defs.h" 14 | #include "states.h" 15 | #include "debug_trace.h" 16 | 17 | /* Set trace levels */ 18 | uint32_t trace_levels = \ 19 | TRACE_LEVEL_DEFAULT | 20 | 0; 21 | 22 | /* STATE_1 data and functions */ 23 | struct tp_state_1_data { 24 | char name[20]; 25 | }; 26 | 27 | void state_1_enter_cb(state_t prev, void * data) 28 | { 29 | struct tp_state_1_data * state_data = (struct tp_state_1_data*) data; 30 | TRACE(("state_1_enter_cb: %s\n", state_data->name)); 31 | } 32 | 33 | void state_1_run_cb(void * data) 34 | { 35 | struct tp_state_1_data * state_data = (struct tp_state_1_data*) data; 36 | TRACE(("state_1_run_cb: %s\n", state_data->name)); 37 | } 38 | 39 | void state_1_exit_cb(state_t next, void * data) 40 | { 41 | struct tp_state_1_data * state_data = (struct tp_state_1_data*) data; 42 | TRACE(("state_1_exit_cb: %s\n", state_data->name)); 43 | } 44 | 45 | 46 | /* STATE_2 data and functions */ 47 | struct tp_state_2_data { 48 | char name[20]; 49 | }; 50 | 51 | void state_2_enter_cb(state_t prev, void * data) 52 | { 53 | struct tp_state_2_data * state_data = (struct tp_state_2_data*) data; 54 | TRACE(("state_2_enter_cb: %s\n", state_data->name)); 55 | } 56 | 57 | void state_2_run_cb(void * data) 58 | { 59 | struct tp_state_2_data * state_data = (struct tp_state_2_data*) data; 60 | TRACE(("state_2_run_cb: %s\n", state_data->name)); 61 | } 62 | 63 | void state_2_exit_cb(state_t next, void * data) 64 | { 65 | struct tp_state_2_data * state_data = (struct tp_state_2_data*) data; 66 | TRACE(("state_2_exit_cb: %s\n", state_data->name)); 67 | } 68 | 69 | 70 | int main(void) 71 | { 72 | struct tp_state_1_data data_1 = { 73 | .name = "DATA_1", 74 | }; 75 | /* enumerator with states */ 76 | enum en_state_1 { 77 | eNONE_1 = 0, 78 | eSTATE_1_1, 79 | eSTATE_1_2, 80 | eEND_STATE_1, 81 | }; 82 | /* a list with states */ 83 | struct tp_state sys_states_list[] = { 84 | [eNONE_1] = DECLARE_STATE(eNONE_1, &state_1_enter_cb, &state_1_run_cb, &state_1_exit_cb), 85 | [eSTATE_1_1] = DECLARE_STATE(eSTATE_1_1, &state_1_enter_cb, &state_1_run_cb, &state_1_exit_cb), 86 | [eSTATE_1_2] = DECLARE_STATE(eSTATE_1_2, &state_1_enter_cb, &state_1_run_cb, &state_1_exit_cb), 87 | }; 88 | /* declare the state object */ 89 | DECLARE_STATE_OBJ(sys_states, (void*) &data_1, sys_states_list, ARRAY_SIZE(sys_states_list), &sys_states_list[eNONE_1], &sys_states_list[eSTATE_1_1]); 90 | 91 | 92 | struct tp_state_2_data data_2 = { 93 | .name = "DATA_2", 94 | }; 95 | /* enumerator with states */ 96 | enum en_state_module { 97 | eNONE_2 = 0, 98 | eSTATE_2_1, 99 | eSTATE_2_2, 100 | 101 | eEND_STATE_2, 102 | }; 103 | /* a list with states */ 104 | struct tp_state module_states_list[] = { 105 | [eNONE_2] = DECLARE_STATE(eNONE_2, &state_2_enter_cb, &state_2_run_cb, &state_2_exit_cb), 106 | [eSTATE_2_1] = DECLARE_STATE(eSTATE_2_1, &state_2_enter_cb, &state_2_run_cb, &state_2_exit_cb), 107 | [eSTATE_2_2] = DECLARE_STATE(eSTATE_2_2, &state_2_enter_cb, &state_2_run_cb, &state_2_exit_cb), 108 | }; 109 | /* declare the state object */ 110 | DECLARE_STATE_OBJ(module_states, (void*) &data_2, module_states_list, ARRAY_SIZE(module_states_list), &module_states_list[eNONE_2], &module_states_list[eSTATE_2_1]); 111 | 112 | 113 | while(1) { 114 | usleep(500 * 1000); 115 | state_handler(&sys_states); 116 | state_handler(&module_states); 117 | } 118 | 119 | return EXIT_SUCCESS; 120 | } 121 | -------------------------------------------------------------------------------- /source/libs/CMSIS/DSP/Source/SupportFunctions/arm_q7_to_float.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_q7_to_float.c 4 | * Description: Converts the elements of the Q7 vector to floating-point vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "arm_math.h" 30 | 31 | /** 32 | * @ingroup groupSupport 33 | */ 34 | 35 | /** 36 | * @defgroup q7_to_x Convert 8-bit Integer value 37 | */ 38 | 39 | /** 40 | * @addtogroup q7_to_x 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Converts the elements of the Q7 vector to floating-point vector. 46 | * @param[in] *pSrc points to the Q7 input vector 47 | * @param[out] *pDst points to the floating-point output vector 48 | * @param[in] blockSize length of the input vector 49 | * @return none. 50 | * 51 | * \par Description: 52 | * 53 | * The equation used for the conversion process is: 54 | * 55 | *
 56 |  * 	pDst[n] = (float32_t) pSrc[n] / 128;   0 <= n < blockSize.
 57 |  * 
58 | * 59 | */ 60 | 61 | 62 | void arm_q7_to_float( 63 | q7_t * pSrc, 64 | float32_t * pDst, 65 | uint32_t blockSize) 66 | { 67 | q7_t *pIn = pSrc; /* Src pointer */ 68 | uint32_t blkCnt; /* loop counter */ 69 | 70 | 71 | #if defined (ARM_MATH_DSP) 72 | 73 | /* Run the below code for Cortex-M4 and Cortex-M3 */ 74 | 75 | /*loop Unrolling */ 76 | blkCnt = blockSize >> 2U; 77 | 78 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 79 | ** a second loop below computes the remaining 1 to 3 samples. */ 80 | while (blkCnt > 0U) 81 | { 82 | /* C = (float32_t) A / 128 */ 83 | /* convert from q7 to float and then store the results in the destination buffer */ 84 | *pDst++ = ((float32_t) * pIn++ / 128.0f); 85 | *pDst++ = ((float32_t) * pIn++ / 128.0f); 86 | *pDst++ = ((float32_t) * pIn++ / 128.0f); 87 | *pDst++ = ((float32_t) * pIn++ / 128.0f); 88 | 89 | /* Decrement the loop counter */ 90 | blkCnt--; 91 | } 92 | 93 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 94 | ** No loop unrolling is used. */ 95 | blkCnt = blockSize % 0x4U; 96 | 97 | #else 98 | 99 | /* Run the below code for Cortex-M0 */ 100 | 101 | /* Loop over blockSize number of values */ 102 | blkCnt = blockSize; 103 | 104 | #endif /* #if defined (ARM_MATH_DSP) */ 105 | 106 | while (blkCnt > 0U) 107 | { 108 | /* C = (float32_t) A / 128 */ 109 | /* convert from q7 to float and then store the results in the destination buffer */ 110 | *pDst++ = ((float32_t) * pIn++ / 128.0f); 111 | 112 | /* Decrement the loop counter */ 113 | blkCnt--; 114 | } 115 | } 116 | 117 | /** 118 | * @} end of q7_to_x group 119 | */ 120 | -------------------------------------------------------------------------------- /source/libs/CMSIS/DSP/Source/SupportFunctions/arm_q15_to_float.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_q15_to_float.c 4 | * Description: Converts the elements of the Q15 vector to floating-point vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "arm_math.h" 30 | 31 | /** 32 | * @ingroup groupSupport 33 | */ 34 | 35 | /** 36 | * @defgroup q15_to_x Convert 16-bit Integer value 37 | */ 38 | 39 | /** 40 | * @addtogroup q15_to_x 41 | * @{ 42 | */ 43 | 44 | 45 | 46 | 47 | /** 48 | * @brief Converts the elements of the Q15 vector to floating-point vector. 49 | * @param[in] *pSrc points to the Q15 input vector 50 | * @param[out] *pDst points to the floating-point output vector 51 | * @param[in] blockSize length of the input vector 52 | * @return none. 53 | * 54 | * \par Description: 55 | * 56 | * The equation used for the conversion process is: 57 | * 58 | *
 59 |  * 	pDst[n] = (float32_t) pSrc[n] / 32768;   0 <= n < blockSize.
 60 |  * 
61 | * 62 | */ 63 | 64 | 65 | void arm_q15_to_float( 66 | q15_t * pSrc, 67 | float32_t * pDst, 68 | uint32_t blockSize) 69 | { 70 | q15_t *pIn = pSrc; /* Src pointer */ 71 | uint32_t blkCnt; /* loop counter */ 72 | 73 | 74 | #if defined (ARM_MATH_DSP) 75 | 76 | /* Run the below code for Cortex-M4 and Cortex-M3 */ 77 | 78 | /*loop Unrolling */ 79 | blkCnt = blockSize >> 2U; 80 | 81 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 82 | ** a second loop below computes the remaining 1 to 3 samples. */ 83 | while (blkCnt > 0U) 84 | { 85 | /* C = (float32_t) A / 32768 */ 86 | /* convert from q15 to float and then store the results in the destination buffer */ 87 | *pDst++ = ((float32_t) * pIn++ / 32768.0f); 88 | *pDst++ = ((float32_t) * pIn++ / 32768.0f); 89 | *pDst++ = ((float32_t) * pIn++ / 32768.0f); 90 | *pDst++ = ((float32_t) * pIn++ / 32768.0f); 91 | 92 | /* Decrement the loop counter */ 93 | blkCnt--; 94 | } 95 | 96 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 97 | ** No loop unrolling is used. */ 98 | blkCnt = blockSize % 0x4U; 99 | 100 | #else 101 | 102 | /* Run the below code for Cortex-M0 */ 103 | 104 | /* Loop over blockSize number of values */ 105 | blkCnt = blockSize; 106 | 107 | #endif /* #if defined (ARM_MATH_DSP) */ 108 | 109 | while (blkCnt > 0U) 110 | { 111 | /* C = (float32_t) A / 32768 */ 112 | /* convert from q15 to float and then store the results in the destination buffer */ 113 | *pDst++ = ((float32_t) * pIn++ / 32768.0f); 114 | 115 | /* Decrement the loop counter */ 116 | blkCnt--; 117 | } 118 | } 119 | 120 | /** 121 | * @} end of q15_to_x group 122 | */ 123 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/core_convert.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_utils.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 16-Aug-2018 6 | * @brief header file of core utils routines 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© COPYRIGHT(c) 2018 STMicroelectronics

11 | * 12 | * Redistribution and use in source and binary forms, with or without modification, 13 | * are permitted provided that the following conditions are met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | ****************************************************************************** 35 | */ 36 | 37 | #ifndef __CORE_CONVERT_H_ 38 | #define __CORE_CONVERT_H_ 39 | #pragma once 40 | 41 | #include "ai_platform.h" 42 | #include "ai_platform_interface.h" 43 | 44 | #include "core_common.h" 45 | 46 | AI_API_DECLARE_BEGIN 47 | 48 | /*! 49 | * @defgroup core_convert Core Convert Routines 50 | * @brief Implementation of core node format convertion routines (Q7 to float, ... etc.) 51 | */ 52 | 53 | 54 | /*! 55 | * @brief Convert input tensor array from input format to output format 56 | * @ingroup core_convert 57 | * @param[in] pNode in a handler to node (layer or operators) with tensor informations 58 | */ 59 | AI_INTERNAL_API 60 | void node_convert(ai_node *pNode); 61 | 62 | /*! 63 | * @brief Convert a shape struct into a stride struct 64 | * @ingroup core_convert 65 | * @param[in] in a pointer to a shape to convert 66 | * @return a condverted stride datastruct 67 | */ 68 | AI_INTERNAL_API 69 | ai_stride core_shape_to_stride(const ai_shape* in); 70 | 71 | /*! 72 | * @brief Convert a shape 2D struct into a stride struct 73 | * @ingroup core_convert 74 | * @param[in] in a pointer to a shape to convert 75 | * @return a condverted stride datastruct 76 | */ 77 | AI_INTERNAL_API 78 | ai_stride core_shape_2d_to_stride(const ai_shape_2d* in); 79 | 80 | /*! 81 | * @brief Convert a shape struct into a ND stride struct (multi dimensional) 82 | * @ingroup core_convert 83 | * @param[in] in a pointer to a shape to convert 84 | * @return a condverted ND stride datastruct 85 | */ 86 | AI_INTERNAL_API 87 | ai_stride_nd core_shape_to_stride_nd(const ai_shape* in); 88 | 89 | /*! 90 | * @brief Convert a shape 2D struct into a ND stride struct (multi dimensional) 91 | * @ingroup core_convert 92 | * @param[in] in a pointer to a shape 2D to convert 93 | * @return a condverted ND stride datastruct 94 | */ 95 | AI_INTERNAL_API 96 | ai_stride_nd core_shape_2d_to_stride_nd(const ai_shape_2d* in); 97 | 98 | #endif /*__CORE_CONVERT_H_*/ 99 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/core_net_inspect.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_net_inspect.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 20-Lug-2018 6 | * @brief header file of core network inspection APIs 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | #ifndef __CORE_NET_INSPECT_H_ 22 | #define __CORE_NET_INSPECT_H_ 23 | #pragma once 24 | 25 | #include "core_net_inspect_interface.h" 26 | 27 | #include "core_common.h" 28 | #include "layers_common.h" 29 | 30 | /*! 31 | * @defgroup core_net_inspect Core Network Inspection routines 32 | * @brief Implementation of core network inspection routines that allows to 33 | * inspect on a node basis a generated network model 34 | * @details A network context @ref ai_network basically contains a chained list 35 | * of nodes @ref ai_node that have an associated forward function. 36 | * Each ai)network context and ai_node datastructs have as a required member 37 | * field an opaque handler (i.e. a void pointer) to a klass object. 38 | * This handler is intended to be used as a platform specific node context 39 | * that implements specific target platform routines. 40 | * The inspector module basically acts as a plugin that exploiting these features 41 | * by temporary creating an hidden inspection context (see 42 | * @ref ai_core_inspect_net_klass) associated to the network and 43 | * linking it by re-routing the klass field to this inspection context. The 44 | * inspection context saves as part of its state (by a stack push operation), the 45 | * internal state of the network (all node / network klass pointers and actual 46 | * forward functions). 47 | * Thus, for each node it re-routes all node's forward functions to a dedicated 48 | * inspection forward function (see @ref _forward_inspect_validate() routine) 49 | * This routine is the core of the mechanism and it allows to inspect a network 50 | * node by node. Some additional inspection could thus be done inside the 51 | * _forward_inspect_validate() routine before and after the actual node 52 | * forward function is called; 53 | * 54 | */ 55 | 56 | AI_API_DECLARE_BEGIN 57 | 58 | /*! 59 | * @defgroup core_net_inspect Network Inspection Core 60 | * @brief Implementation of the validation network routines 61 | */ 62 | 63 | /*! 64 | * @brief Initialize the network inspection context on a given network 65 | * @ingroup core net inspect 66 | * @param network opaque handler to the network instance 67 | * @param cfg a pointer to the inspector configuration we want to use 68 | * @return true if execution of the API is fine, false otherwise 69 | */ 70 | AI_API_ENTRY 71 | ai_bool ai_network_inspect_init( 72 | ai_handle network, const ai_inspect_config* cfg); 73 | 74 | /*! 75 | * @brief Get a summary report from the inspected network 76 | * @ingroup core net inspect 77 | * @param network opaque handler to the network instance 78 | * @param report a pointer to the report provided back by the inspection 79 | * @return true if execution of the API is fine, false otherwise 80 | */ 81 | AI_API_ENTRY 82 | ai_bool ai_network_inspect_get_report( 83 | ai_handle network, ai_inspect_net_report* report); 84 | 85 | /*! 86 | * @brief Destroy the network inspection context on a given network 87 | * @ingroup core net inspect 88 | * @param network opaque handler to the network instance 89 | * @return true if execution of the API is fine, false otherwise 90 | */ 91 | AI_API_ENTRY 92 | ai_bool ai_network_inspect_destroy(ai_handle network); 93 | 94 | AI_API_DECLARE_END 95 | 96 | #endif /*__CORE_NET_INSPECT_H_*/ 97 | -------------------------------------------------------------------------------- /source/libs/CMSIS/DSP/Source/BasicMathFunctions/arm_dot_prod_f32.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_dot_prod_f32.c 4 | * Description: Floating-point dot product 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "arm_math.h" 30 | 31 | /** 32 | * @ingroup groupMath 33 | */ 34 | 35 | /** 36 | * @defgroup dot_prod Vector Dot Product 37 | * 38 | * Computes the dot product of two vectors. 39 | * The vectors are multiplied element-by-element and then summed. 40 | * 41 | *
 42 |  *     sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... + pSrcA[blockSize-1]*pSrcB[blockSize-1]
 43 |  * 
44 | * 45 | * There are separate functions for floating-point, Q7, Q15, and Q31 data types. 46 | */ 47 | 48 | /** 49 | * @addtogroup dot_prod 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @brief Dot product of floating-point vectors. 55 | * @param[in] *pSrcA points to the first input vector 56 | * @param[in] *pSrcB points to the second input vector 57 | * @param[in] blockSize number of samples in each vector 58 | * @param[out] *result output result returned here 59 | * @return none. 60 | */ 61 | 62 | 63 | void arm_dot_prod_f32( 64 | float32_t * pSrcA, 65 | float32_t * pSrcB, 66 | uint32_t blockSize, 67 | float32_t * result) 68 | { 69 | float32_t sum = 0.0f; /* Temporary result storage */ 70 | uint32_t blkCnt; /* loop counter */ 71 | 72 | 73 | #if defined (ARM_MATH_DSP) 74 | 75 | /* Run the below code for Cortex-M4 and Cortex-M3 */ 76 | /*loop Unrolling */ 77 | blkCnt = blockSize >> 2U; 78 | 79 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 80 | ** a second loop below computes the remaining 1 to 3 samples. */ 81 | while (blkCnt > 0U) 82 | { 83 | /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */ 84 | /* Calculate dot product and then store the result in a temporary buffer */ 85 | sum += (*pSrcA++) * (*pSrcB++); 86 | sum += (*pSrcA++) * (*pSrcB++); 87 | sum += (*pSrcA++) * (*pSrcB++); 88 | sum += (*pSrcA++) * (*pSrcB++); 89 | 90 | /* Decrement the loop counter */ 91 | blkCnt--; 92 | } 93 | 94 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 95 | ** No loop unrolling is used. */ 96 | blkCnt = blockSize % 0x4U; 97 | 98 | #else 99 | 100 | /* Run the below code for Cortex-M0 */ 101 | 102 | /* Initialize blkCnt with number of samples */ 103 | blkCnt = blockSize; 104 | 105 | #endif /* #if defined (ARM_MATH_DSP) */ 106 | 107 | 108 | while (blkCnt > 0U) 109 | { 110 | /* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */ 111 | /* Calculate dot product and then store the result in a temporary buffer. */ 112 | sum += (*pSrcA++) * (*pSrcB++); 113 | 114 | /* Decrement the loop counter */ 115 | blkCnt--; 116 | } 117 | /* Store the result back in the destination buffer */ 118 | *result = sum; 119 | } 120 | 121 | /** 122 | * @} end of dot_prod group 123 | */ 124 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/layers_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_list.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 20-Jul-2018 6 | * @brief header file of AI platform layers datatypes 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | 22 | /* No sentry. This is deliberate!! */ 23 | /* Template: LAYER_ENTRY(type_, id_, struct_, forward_func_) 24 | * Where: 25 | * - type_ is the (enum) type name of the layer. to have the complete enum 26 | * value you should use the macro @ref AI_LAYER_TYPE_ENTRY(type_) that adds 27 | * the specific prefix and postfix tokens to the type_ 28 | * - id_ is the numeric id of the layer 29 | * - struct_ is the name of the datastruct of the layer 30 | * - forward_func_ is the forward function name of the routine implementing 31 | * actual layer processing 32 | */ 33 | 34 | /*!< Elementwise addition layer */ 35 | LAYER_ENTRY(ADD, 10001, ai_layer_add, forward_add) 36 | /*!< Batch normalization layer */ 37 | LAYER_ENTRY(BN, 10002, ai_layer_bn, forward_bn) 38 | /*!< 2D Convolutional layer */ 39 | LAYER_ENTRY(CONV2D, 10004, ai_layer_conv2d, forward_conv2d) 40 | /*!< Dense layer */ 41 | LAYER_ENTRY(DENSE, 10005, ai_layer_dense, forward_dense) 42 | /*!< Gated Recurrent Unit layer */ 43 | LAYER_ENTRY(GRU, 10006, ai_layer_gru, forward_gru) 44 | /*!< Local Response Normalization layer */ 45 | LAYER_ENTRY(LRN, 10007, ai_layer_lrn, forward_lrn) 46 | /*!< Long Short Time Memory layer */ 47 | LAYER_ENTRY(LSTM, 10008, ai_layer_lstm, forward_lstm) 48 | /*!< Nonlinearity layer */ 49 | LAYER_ENTRY(NL, 10009, ai_layer_nl, NULL) 50 | /*!< Normalization layer */ 51 | LAYER_ENTRY(NORM, 10010, ai_layer_norm, forward_norm) 52 | /*!< Merged Conv2d / Pool layer */ 53 | LAYER_ENTRY(OPTIMIZED_CONV2D, 10011, ai_layer_conv2d_nl_pool, forward_conv2d_nl_pool) 54 | /*!< Permute Tensor layer */ 55 | LAYER_ENTRY(PERMUTE, 10012, ai_layer_permute, forward_permute) 56 | /*!< Pooling layer */ 57 | LAYER_ENTRY(POOL, 10013, ai_layer_pool, forward_pool) 58 | /*!< Softmax layer */ 59 | LAYER_ENTRY(SM, 10014, ai_layer_nl, forward_sm) 60 | /*!< Split layer */ 61 | LAYER_ENTRY(SPLIT, 10015, ai_layer_split, forward_split) 62 | /*!< TimeDelay layer */ 63 | LAYER_ENTRY(TIME_DELAY, 10016, ai_layer_time_delay, forward_time_delay) 64 | /*!< TimeDistributed layer */ 65 | LAYER_ENTRY(TIME_DISTRIBUTED, 10017, ai_layer_time_distributed, forward_time_distributed) 66 | /*!< Concat Tensor layer */ 67 | LAYER_ENTRY(CONCAT, 10019, ai_layer_concat, forward_concat) 68 | /*!< GEMM layer */ 69 | LAYER_ENTRY(GEMM, 10020, ai_layer_gemm, forward_gemm) 70 | /*!< Upsample layer */ 71 | LAYER_ENTRY(UPSAMPLE, 10021, ai_layer_upsample, forward_upsample) 72 | /*!< Container layer for eltwise operations */ 73 | LAYER_ENTRY(ELTWISE, 10022, ai_layer_eltwise, forward_eltwise) 74 | /*!< Generic layer */ 75 | LAYER_ENTRY(GENERIC, 10023, ai_layer, NULL) 76 | /*!< InstanceNormalization layer */ 77 | LAYER_ENTRY(INSTANCENORMALIZATION, 10024, ai_layer_instanceNormalization, forward_instanceNormalization) 78 | /*!< Pad layer */ 79 | LAYER_ENTRY(PAD, 10025, ai_layer_pad, forward_pad) 80 | /*!< Slice layer */ 81 | LAYER_ENTRY(SLICE, 10026, ai_layer_slice, forward_slice) 82 | /*!< Tile layer */ 83 | LAYER_ENTRY(TILE, 10027, ai_layer_tile, forward_tile) 84 | /*!< Container layer for reduce operations */ 85 | LAYER_ENTRY(REDUCE, 10028, ai_layer_reduce, forward_reduce) 86 | #ifdef USE_OPERATORS 87 | /*!< Container layer for operators */ 88 | LAYER_ENTRY(CONTAINER, 10003, ai_layer_container, forward_container) 89 | /*!< Container layer for operators */ 90 | LAYER_ENTRY(LAMBDA, 10018, ai_layer_lambda, forward_lambda) 91 | #endif 92 | #undef LAYER_ENTRY 93 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/include/flatbuffers/hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_HASH_H_ 18 | #define FLATBUFFERS_HASH_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "flatbuffers.h" 24 | 25 | namespace flatbuffers { 26 | 27 | template struct FnvTraits { 28 | static const T kFnvPrime; 29 | static const T kOffsetBasis; 30 | }; 31 | 32 | template<> struct FnvTraits { 33 | static const uint32_t kFnvPrime = 0x01000193; 34 | static const uint32_t kOffsetBasis = 0x811C9DC5; 35 | }; 36 | 37 | template<> struct FnvTraits { 38 | static const uint64_t kFnvPrime = 0x00000100000001b3ULL; 39 | static const uint64_t kOffsetBasis = 0xcbf29ce484222645ULL; 40 | }; 41 | 42 | template T HashFnv1(const char *input) { 43 | T hash = FnvTraits::kOffsetBasis; 44 | for (const char *c = input; *c; ++c) { 45 | hash *= FnvTraits::kFnvPrime; 46 | hash ^= static_cast(*c); 47 | } 48 | return hash; 49 | } 50 | 51 | template T HashFnv1a(const char *input) { 52 | T hash = FnvTraits::kOffsetBasis; 53 | for (const char *c = input; *c; ++c) { 54 | hash ^= static_cast(*c); 55 | hash *= FnvTraits::kFnvPrime; 56 | } 57 | return hash; 58 | } 59 | 60 | template <> inline uint16_t HashFnv1(const char *input) { 61 | uint32_t hash = HashFnv1(input); 62 | return (hash >> 16) ^ (hash & 0xffff); 63 | } 64 | 65 | template <> inline uint16_t HashFnv1a(const char *input) { 66 | uint32_t hash = HashFnv1a(input); 67 | return (hash >> 16) ^ (hash & 0xffff); 68 | } 69 | 70 | template struct NamedHashFunction { 71 | const char *name; 72 | 73 | typedef T (*HashFunction)(const char *); 74 | HashFunction function; 75 | }; 76 | 77 | const NamedHashFunction kHashFunctions16[] = { 78 | { "fnv1_16", HashFnv1 }, 79 | { "fnv1a_16", HashFnv1a }, 80 | }; 81 | 82 | const NamedHashFunction kHashFunctions32[] = { 83 | { "fnv1_32", HashFnv1 }, 84 | { "fnv1a_32", HashFnv1a }, 85 | }; 86 | 87 | const NamedHashFunction kHashFunctions64[] = { 88 | { "fnv1_64", HashFnv1 }, 89 | { "fnv1a_64", HashFnv1a }, 90 | }; 91 | 92 | inline NamedHashFunction::HashFunction FindHashFunction16( 93 | const char *name) { 94 | std::size_t size = sizeof(kHashFunctions16) / sizeof(kHashFunctions16[0]); 95 | for (std::size_t i = 0; i < size; ++i) { 96 | if (std::strcmp(name, kHashFunctions16[i].name) == 0) { 97 | return kHashFunctions16[i].function; 98 | } 99 | } 100 | return nullptr; 101 | } 102 | 103 | inline NamedHashFunction::HashFunction FindHashFunction32( 104 | const char *name) { 105 | std::size_t size = sizeof(kHashFunctions32) / sizeof(kHashFunctions32[0]); 106 | for (std::size_t i = 0; i < size; ++i) { 107 | if (std::strcmp(name, kHashFunctions32[i].name) == 0) { 108 | return kHashFunctions32[i].function; 109 | } 110 | } 111 | return nullptr; 112 | } 113 | 114 | inline NamedHashFunction::HashFunction FindHashFunction64( 115 | const char *name) { 116 | std::size_t size = sizeof(kHashFunctions64) / sizeof(kHashFunctions64[0]); 117 | for (std::size_t i = 0; i < size; ++i) { 118 | if (std::strcmp(name, kHashFunctions64[i].name) == 0) { 119 | return kHashFunctions64[i].function; 120 | } 121 | } 122 | return nullptr; 123 | } 124 | 125 | } // namespace flatbuffers 126 | 127 | #endif // FLATBUFFERS_HASH_H_ 128 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/ai_log.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 rxi 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the MIT license. See `log.c` for details. 6 | */ 7 | 8 | #ifndef AI_LOG_H_ 9 | #define AI_LOG_H_ 10 | #pragma once 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | /*! 18 | * @defgroup log Core logger class definition and implementation 19 | * @brief Data structures and defines used to implementlogger module 20 | * functionalities 21 | */ 22 | 23 | #define LOG_VERSION "0.3.0" 24 | #define LOG_CR "\r\n" 25 | 26 | /***** Compilation options: define/undef as required **************************/ 27 | #define LOG_USE_COLOR 28 | /* #define LOG_INFO_SOURCE_CODE */ 29 | 30 | #ifndef HAS_STM32 31 | #define LOG_USE_FILE 32 | #define LOG_INFO_TIME 33 | #define LOG_INFO_SOURCE_CODE_STRIP_FILE_PATHS '/' 34 | #else 35 | #define LOG_INFO_SOURCE_CODE_STRIP_FILE_PATHS '\\' 36 | #endif 37 | 38 | /******************************************************************************/ 39 | #define LOG_SUDO (0x0) 40 | #define LOG_FATAL (0x1) 41 | #define LOG_ERROR (0x2) 42 | #define LOG_WARN (0x3) 43 | #define LOG_INFO (0x4) 44 | #define LOG_DEBUG (0x5) 45 | #define LOG_TRACE (0x6) 46 | 47 | /*! 48 | * @typedef log_LockFn 49 | * @ingroup ai_log 50 | * @brief callback function for locking implementation (e.g. mutexes, etc.) 51 | */ 52 | typedef void (*log_LockFn)(const void *udata, const bool lock); 53 | 54 | /*! 55 | * @typedef log_MsgFn 56 | * @ingroup ai_log 57 | * @brief callback for listening at logged channels 58 | */ 59 | typedef void (*log_MsgFn)( 60 | const void *udata, const uint8_t level, 61 | const char* msg, const uint32_t len); 62 | 63 | /*! 64 | * @brief Get gloabal log context handle 65 | * @ingroup ai_log 66 | */ 67 | void* ai_log_acquire(void); 68 | 69 | /*! 70 | * @brief Set global log level 71 | * @ingroup ai_log 72 | */ 73 | void ai_log_set_level(const uint8_t level); 74 | 75 | /*! 76 | * @brief Set global log quiet mode (no messages are emitted) 77 | * @ingroup ai_log 78 | */ 79 | void ai_log_set_quiet(const bool enable); 80 | 81 | /*! 82 | * @brief Set callback for log messages locking 83 | * @ingroup ai_log 84 | */ 85 | void ai_log_set_lock(log_LockFn fn, const void *udata); 86 | 87 | /*! 88 | * @brief Push on log stack a new listener with given log level 89 | * @ingroup ai_log 90 | * @param[in] level the log level for this channel 91 | * @param[out] the callback function to emit when a message is available 92 | * @param[in] udata a pointer to the caller environment that is provided back 93 | * when the callback is called 94 | * @return 0 if OK, value>0 that indicates the current size of the stack 95 | */ 96 | uint8_t ai_log_channel_push(const uint8_t level, log_MsgFn fn, const void *udata); 97 | 98 | /*! 99 | * @brief Pop from log stack a pushed listener 100 | * @ingroup ai_log 101 | * @param[in] the callback function registered during @ref log_channel_push 102 | * @param[in] udata a pointer to the caller environment registered during @ref 103 | * log_channel_push 104 | * @return 0 if OK, value>0 that indicates the max size of the callback stack 105 | */ 106 | uint8_t ai_log_channel_pop(log_MsgFn fn, const void *udata); 107 | 108 | #ifdef LOG_USE_FILE 109 | /*! 110 | * @brief Enable file dumping of all logged messages to a file as well. 111 | * @details NB: the quiet option does not apply to file logging. file log 112 | * messages are recorded also when the log is in quiet mode. 113 | * @ingroup ai_log 114 | * @param[out] fp the file pointer of the file used to log the massages 115 | */ 116 | void ai_log_set_fp(FILE *fp); 117 | #endif 118 | 119 | /*! 120 | * @brief Main Routine: PLEASE invoke always by using defined macros 121 | * @ingroup ai_log 122 | * @param[in] level the log level of the input message 123 | * @param[in] file the string containing the __FILE__ info about the source file 124 | * generating the message to log 125 | * @param[in] fmt the varargs format of the string to print 126 | */ 127 | void ai_log_log(const uint8_t level, const char *file, 128 | const int line, const char *fmt, ...); 129 | 130 | #endif /*AI_LOG_H_*/ 131 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/src/flathash.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "hash.h" 22 | 23 | enum OutputFormat { kDecimal, kHexadecimal, kHexadecimal0x }; 24 | 25 | int main(int argc, char *argv[]) { 26 | const char *name = argv[0]; 27 | if (argc <= 1) { 28 | printf("%s HASH [OPTION]... [--] STRING...\n", name); 29 | printf("Available hashing algorithms:\n"); 30 | printf(" 16 bit:\n"); 31 | size_t size = sizeof(flatbuffers::kHashFunctions16) / 32 | sizeof(flatbuffers::kHashFunctions16[0]); 33 | for (size_t i = 0; i < size; ++i) { 34 | printf(" * %s\n", flatbuffers::kHashFunctions16[i].name); 35 | } 36 | printf(" 32 bit:\n"); 37 | size = sizeof(flatbuffers::kHashFunctions32) / 38 | sizeof(flatbuffers::kHashFunctions32[0]); 39 | for (size_t i = 0; i < size; ++i) { 40 | printf(" * %s\n", flatbuffers::kHashFunctions32[i].name); 41 | } 42 | printf(" 64 bit:\n"); 43 | size = sizeof(flatbuffers::kHashFunctions64) / 44 | sizeof(flatbuffers::kHashFunctions64[0]); 45 | for (size_t i = 0; i < size; ++i) { 46 | printf(" * %s\n", flatbuffers::kHashFunctions64[i].name); 47 | } 48 | printf( 49 | " -d Output hash in decimal.\n" 50 | " -x Output hash in hexadecimal.\n" 51 | " -0x Output hash in hexadecimal and prefix with 0x.\n" 52 | " -c Append the string to the output in a c-style comment.\n"); 53 | return 1; 54 | } 55 | 56 | const char *hash_algorithm = argv[1]; 57 | 58 | flatbuffers::NamedHashFunction::HashFunction hash_function16 = 59 | flatbuffers::FindHashFunction16(hash_algorithm); 60 | flatbuffers::NamedHashFunction::HashFunction hash_function32 = 61 | flatbuffers::FindHashFunction32(hash_algorithm); 62 | flatbuffers::NamedHashFunction::HashFunction hash_function64 = 63 | flatbuffers::FindHashFunction64(hash_algorithm); 64 | 65 | if (!hash_function16 && !hash_function32 && !hash_function64) { 66 | printf("\"%s\" is not a known hash algorithm.\n", hash_algorithm); 67 | return 1; 68 | } 69 | 70 | OutputFormat output_format = kHexadecimal; 71 | bool annotate = false; 72 | bool escape_dash = false; 73 | for (int i = 2; i < argc; i++) { 74 | const char *arg = argv[i]; 75 | if (!escape_dash && arg[0] == '-') { 76 | std::string opt = arg; 77 | if (opt == "-d") 78 | output_format = kDecimal; 79 | else if (opt == "-x") 80 | output_format = kHexadecimal; 81 | else if (opt == "-0x") 82 | output_format = kHexadecimal0x; 83 | else if (opt == "-c") 84 | annotate = true; 85 | else if (opt == "--") 86 | escape_dash = true; 87 | else 88 | printf("Unrecognized argument: \"%s\"\n", arg); 89 | } else { 90 | std::stringstream ss; 91 | if (output_format == kDecimal) { 92 | ss << std::dec; 93 | } else if (output_format == kHexadecimal) { 94 | ss << std::hex; 95 | } else if (output_format == kHexadecimal0x) { 96 | ss << std::hex; 97 | ss << "0x"; 98 | } 99 | if (hash_function16) 100 | ss << hash_function16(arg); 101 | else if (hash_function32) 102 | ss << hash_function32(arg); 103 | else if (hash_function64) 104 | ss << hash_function64(arg); 105 | 106 | if (annotate) ss << " /* \"" << arg << "\" */"; 107 | 108 | ss << "\n"; 109 | 110 | std::cout << ss.str(); 111 | } 112 | } 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /source/libs/CMSIS/DSP/Source/SupportFunctions/arm_q7_to_q15.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_q7_to_q15.c 4 | * Description: Converts the elements of the Q7 vector to Q15 vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "arm_math.h" 30 | 31 | /** 32 | * @ingroup groupSupport 33 | */ 34 | 35 | /** 36 | * @addtogroup q7_to_x 37 | * @{ 38 | */ 39 | 40 | 41 | 42 | 43 | /** 44 | * @brief Converts the elements of the Q7 vector to Q15 vector. 45 | * @param[in] *pSrc points to the Q7 input vector 46 | * @param[out] *pDst points to the Q15 output vector 47 | * @param[in] blockSize length of the input vector 48 | * @return none. 49 | * 50 | * \par Description: 51 | * 52 | * The equation used for the conversion process is: 53 | * 54 | *
 55 |  * 	pDst[n] = (q15_t) pSrc[n] << 8;   0 <= n < blockSize.
 56 |  * 
57 | * 58 | */ 59 | 60 | 61 | void arm_q7_to_q15( 62 | q7_t * pSrc, 63 | q15_t * pDst, 64 | uint32_t blockSize) 65 | { 66 | q7_t *pIn = pSrc; /* Src pointer */ 67 | uint32_t blkCnt; /* loop counter */ 68 | 69 | #if defined (ARM_MATH_DSP) 70 | q31_t in; 71 | q31_t in1, in2; 72 | q31_t out1, out2; 73 | 74 | /* Run the below code for Cortex-M4 and Cortex-M3 */ 75 | 76 | /*loop Unrolling */ 77 | blkCnt = blockSize >> 2U; 78 | 79 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 80 | ** a second loop below computes the remaining 1 to 3 samples. */ 81 | while (blkCnt > 0U) 82 | { 83 | /* C = (q15_t) A << 8 */ 84 | /* convert from q7 to q15 and then store the results in the destination buffer */ 85 | in = *__SIMD32(pIn)++; 86 | 87 | /* rotatate in by 8 and extend two q7_t values to q15_t values */ 88 | in1 = __SXTB16(__ROR(in, 8)); 89 | 90 | /* extend remainig two q7_t values to q15_t values */ 91 | in2 = __SXTB16(in); 92 | 93 | in1 = in1 << 8U; 94 | in2 = in2 << 8U; 95 | 96 | in1 = in1 & 0xFF00FF00; 97 | in2 = in2 & 0xFF00FF00; 98 | 99 | #ifndef ARM_MATH_BIG_ENDIAN 100 | 101 | out2 = __PKHTB(in1, in2, 16); 102 | out1 = __PKHBT(in2, in1, 16); 103 | 104 | #else 105 | 106 | out1 = __PKHTB(in1, in2, 16); 107 | out2 = __PKHBT(in2, in1, 16); 108 | 109 | #endif 110 | 111 | *__SIMD32(pDst)++ = out1; 112 | *__SIMD32(pDst)++ = out2; 113 | 114 | /* Decrement the loop counter */ 115 | blkCnt--; 116 | } 117 | 118 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 119 | ** No loop unrolling is used. */ 120 | blkCnt = blockSize % 0x4U; 121 | 122 | #else 123 | 124 | /* Run the below code for Cortex-M0 */ 125 | 126 | /* Loop over blockSize number of values */ 127 | blkCnt = blockSize; 128 | 129 | #endif /* #if defined (ARM_MATH_DSP) */ 130 | 131 | while (blkCnt > 0U) 132 | { 133 | /* C = (q15_t) A << 8 */ 134 | /* convert from q7 to q15 and then store the results in the destination buffer */ 135 | *pDst++ = (q15_t) * pIn++ << 8; 136 | 137 | /* Decrement the loop counter */ 138 | blkCnt--; 139 | } 140 | 141 | } 142 | 143 | /** 144 | * @} end of q7_to_x group 145 | */ 146 | -------------------------------------------------------------------------------- /source/libs/CMSIS/Device/ST/STM32F7xx/Include/system_stm32f7xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f7xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M7 Device System Source File for STM32F7xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2016 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f7xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32F7XX_H 48 | #define __SYSTEM_STM32F7XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32F7xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32F7xx_System_Exported_Variables 64 | * @{ 65 | */ 66 | /* The SystemCoreClock variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @addtogroup STM32F7xx_System_Exported_Constants 85 | * @{ 86 | */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @addtogroup STM32F7xx_System_Exported_Macros 93 | * @{ 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** @addtogroup STM32F7xx_System_Exported_Functions 101 | * @{ 102 | */ 103 | 104 | extern void SystemInit(void); 105 | extern void SystemCoreClockUpdate(void); 106 | /** 107 | * @} 108 | */ 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /*__SYSTEM_STM32F7XX_H */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 124 | -------------------------------------------------------------------------------- /source/libs/CMSIS/DSP/Source/SupportFunctions/arm_q15_to_q7.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_q15_to_q7.c 4 | * Description: Converts the elements of the Q15 vector to Q7 vector 5 | * 6 | * $Date: 27. January 2017 7 | * $Revision: V.1.5.1 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "arm_math.h" 30 | 31 | /** 32 | * @ingroup groupSupport 33 | */ 34 | 35 | /** 36 | * @addtogroup q15_to_x 37 | * @{ 38 | */ 39 | 40 | 41 | /** 42 | * @brief Converts the elements of the Q15 vector to Q7 vector. 43 | * @param[in] *pSrc points to the Q15 input vector 44 | * @param[out] *pDst points to the Q7 output vector 45 | * @param[in] blockSize length of the input vector 46 | * @return none. 47 | * 48 | * \par Description: 49 | * 50 | * The equation used for the conversion process is: 51 | * 52 | *
 53 |  * 	pDst[n] = (q7_t) pSrc[n] >> 8;   0 <= n < blockSize.
 54 |  * 
55 | * 56 | */ 57 | 58 | 59 | void arm_q15_to_q7( 60 | q15_t * pSrc, 61 | q7_t * pDst, 62 | uint32_t blockSize) 63 | { 64 | q15_t *pIn = pSrc; /* Src pointer */ 65 | uint32_t blkCnt; /* loop counter */ 66 | 67 | #if defined (ARM_MATH_DSP) 68 | 69 | /* Run the below code for Cortex-M4 and Cortex-M3 */ 70 | q31_t in1, in2; 71 | q31_t out1, out2; 72 | 73 | /*loop Unrolling */ 74 | blkCnt = blockSize >> 2U; 75 | 76 | /* First part of the processing with loop unrolling. Compute 4 outputs at a time. 77 | ** a second loop below computes the remaining 1 to 3 samples. */ 78 | while (blkCnt > 0U) 79 | { 80 | /* C = (q7_t) A >> 8 */ 81 | /* convert from q15 to q7 and then store the results in the destination buffer */ 82 | in1 = *__SIMD32(pIn)++; 83 | in2 = *__SIMD32(pIn)++; 84 | 85 | #ifndef ARM_MATH_BIG_ENDIAN 86 | 87 | out1 = __PKHTB(in2, in1, 16); 88 | out2 = __PKHBT(in2, in1, 16); 89 | 90 | #else 91 | 92 | out1 = __PKHTB(in1, in2, 16); 93 | out2 = __PKHBT(in1, in2, 16); 94 | 95 | #endif // #ifndef ARM_MATH_BIG_ENDIAN 96 | 97 | /* rotate packed value by 24 */ 98 | out2 = ((uint32_t) out2 << 8) | ((uint32_t) out2 >> 24); 99 | 100 | /* anding with 0xff00ff00 to get two 8 bit values */ 101 | out1 = out1 & 0xFF00FF00; 102 | /* anding with 0x00ff00ff to get two 8 bit values */ 103 | out2 = out2 & 0x00FF00FF; 104 | 105 | /* oring two values(contains two 8 bit values) to get four packed 8 bit values */ 106 | out1 = out1 | out2; 107 | 108 | /* store 4 samples at a time to destiantion buffer */ 109 | *__SIMD32(pDst)++ = out1; 110 | 111 | /* Decrement the loop counter */ 112 | blkCnt--; 113 | } 114 | 115 | /* If the blockSize is not a multiple of 4, compute any remaining output samples here. 116 | ** No loop unrolling is used. */ 117 | blkCnt = blockSize % 0x4U; 118 | 119 | #else 120 | 121 | /* Run the below code for Cortex-M0 */ 122 | 123 | /* Loop over blockSize number of values */ 124 | blkCnt = blockSize; 125 | 126 | #endif /* #if defined (ARM_MATH_DSP) */ 127 | 128 | while (blkCnt > 0U) 129 | { 130 | /* C = (q7_t) A >> 8 */ 131 | /* convert from q15 to q7 and then store the results in the destination buffer */ 132 | *pDst++ = (q7_t) (*pIn++ >> 8); 133 | 134 | /* Decrement the loop counter */ 135 | blkCnt--; 136 | } 137 | 138 | } 139 | 140 | /** 141 | * @} end of q15_to_x group 142 | */ 143 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/layers_rnn.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file layers_rnn.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 18-May-2018 6 | * @brief header file of RNN layers 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | #ifndef __LAYERS_RNN_H_ 21 | #define __LAYERS_RNN_H_ 22 | #pragma once 23 | 24 | #include "layers_common.h" 25 | 26 | AI_API_DECLARE_BEGIN 27 | 28 | /*! 29 | * @struct ai_layer_lstm 30 | * @ingroup layers 31 | * @brief LSTM layer with generic nonlinearities and peephole connections 32 | */ 33 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_lstm_ { 34 | AI_LAYER_COMMON_FIELDS_DECLARE 35 | ai_size n_units; /**< size of the hidden RNN state */ 36 | func_nl_el activation_nl; /**< activation nonlinearity (input to cell) */ 37 | func_nl_el recurrent_nl; /**< recurrent nonlinearity (hidden to cell) */ 38 | func_nl_el out_nl; /**< output nonlinearity (cell to hidden) */ 39 | ai_bool go_backwards; /**< process reversed input */ 40 | ai_bool reverse_seq; /**< reverse output sequence */ 41 | } ai_layer_lstm; 42 | 43 | 44 | /*! 45 | * @struct ai_layer_gru 46 | * @ingroup layers 47 | * @brief Gated Recurrent Unit (GRU) layer with generic nonlinearities 48 | */ 49 | typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_gru_ { 50 | AI_LAYER_COMMON_FIELDS_DECLARE 51 | ai_size n_units; /**< size of the hidden RNN state */ 52 | func_nl_el activation_nl; /**< activation nonlinearity (input to cell) */ 53 | func_nl_el recurrent_nl; /**< recurrent nonlinearity (hidden to cell) */ 54 | ai_bool reset_after; 55 | ai_bool go_backwards; /**< process reversed input */ 56 | ai_bool reverse_seq; /**< reverse output sequence */ 57 | } ai_layer_gru; 58 | 59 | /*! 60 | * @brief Computes the activations of a Long-Short Term Memory (LSTM) layer. 61 | * @ingroup layers 62 | * 63 | * Implements a Long-Short Term Layer with peephole connections: 64 | * \f{eqnarray*}{ 65 | * i_t &=& \sigma_a(x_t W_{xi} + h_{t-1} W_{hi} 66 | * + w_{ci} \odot c_{t-1} + b_i)\\ 67 | * f_t &=& \sigma_a(x_t W_{xf} + h_{t-1} W_{hf} 68 | * + w_{cf} \odot c_{t-1} + b_f)\\ 69 | * c_t &=& f_t \odot c_{t - 1} 70 | * + i_t \odot \sigma_r(x_t W_{xc} + h_{t-1} W_{hc} + b_c)\\ 71 | * o_t &=& \sigma_a(x_t W_{xo} + h_{t-1} W_{ho} + w_{co} \odot c_t + b_o)\\ 72 | * h_t &=& o_t \odot \sigma_o(c_t) 73 | * \f} 74 | * where \f$\sigma_a\f$ is the activation nonlinearity, \f$\sigma_r\f$ is the 75 | * recurrent nonlinearity and \f$\sigma_o\f$ is the out nonlinearity. The 76 | * \f$W_x\f$, \f$W_h\f$ and \f$W_c\f$ weights are sliced from the kernel, 77 | * recurrent and peephole weights. 78 | * 79 | * @param layer the LSTM layer 80 | */ 81 | AI_INTERNAL_API 82 | void forward_lstm(ai_layer * layer); 83 | 84 | /*! 85 | * @brief Computes the activations of a Gated Recurrent Unit (GRU) layer. 86 | * @ingroup layers 87 | * 88 | * Implements a Gated Recurrent Unit with the formula: 89 | * \f{eqnarray*}{ 90 | * r_t &=& \sigma_a(x_t W_{xr} + h_{t - 1} W_{hr} + b_r) \\ 91 | * z_t &=& \sigma_a(x_t W_{xz} + h_{t - 1} W_{hz} + b_z) \\ 92 | * c_t &=& \sigma_r(x_t W_{xc} + r_t \odot (h_{t - 1} W_{hc} + b_{hc}) + b_c) 93 | * \qquad \textnormal{when reset after is true} \\ 94 | * c_t &=& \sigma_r(x_t W_{xc} + (r_t \odot h_{t - 1}) W_{hc} + b_{hc} + b_c) 95 | * \qquad \textnormal{when reset after is false (default)} \\ 96 | * h_t &=& (1 - z_t) \odot h_{t - 1} + z_t \odot c_t 97 | * \f} 98 | * where \f$\sigma_a\f$ is the activation nonlinearity and \f$\sigma_r\f$ is 99 | * the recurrent nonlinearity. The weights are sliced from the kernel and 100 | * recurrent weights. 101 | * 102 | * @param layer the GRU layer 103 | */ 104 | AI_INTERNAL_API 105 | void forward_gru(ai_layer * layer); 106 | 107 | 108 | AI_API_DECLARE_END 109 | 110 | #endif /* __LAYERS_RNN_H_ */ 111 | -------------------------------------------------------------------------------- /source/src/inc/app_x-cube-ai.h: -------------------------------------------------------------------------------- 1 | 2 | /* Define to prevent recursive inclusion -------------------------------------*/ 3 | #ifndef __APP_AI_H 4 | #define __APP_AI_H 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | /** 9 | ****************************************************************************** 10 | * @file : app_x-cube-ai.h 11 | * @brief : AI entry function definitions 12 | ****************************************************************************** 13 | * This notice applies to any and all portions of this file 14 | * that are not between comment pairs USER CODE BEGIN and 15 | * USER CODE END. Other portions of this file, whether 16 | * inserted by the user or by software development tools 17 | * are owned by their respective copyright owners. 18 | * 19 | * Copyright (c) 2018 STMicroelectronics International N.V. 20 | * All rights reserved. 21 | * 22 | * Redistribution and use in source and binary forms, with or without 23 | * modification, are permitted, provided that the following conditions are met: 24 | * 25 | * 1. Redistribution of source code must retain the above copyright notice, 26 | * this list of conditions and the following disclaimer. 27 | * 2. Redistributions in binary form must reproduce the above copyright notice, 28 | * this list of conditions and the following disclaimer in the documentation 29 | * and/or other materials provided with the distribution. 30 | * 3. Neither the name of STMicroelectronics nor the names of other 31 | * contributors to this software may be used to endorse or promote products 32 | * derived from this software without specific written permission. 33 | * 4. This software, including modifications and/or derivative works of this 34 | * software, must execute solely and exclusively on microcontroller or 35 | * microprocessor devices manufactured by or for STMicroelectronics. 36 | * 5. Redistribution and use of this software other than as permitted under 37 | * this license is void and will automatically terminate your rights under 38 | * this license. 39 | * 40 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 41 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 42 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 43 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 44 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 45 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 46 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 47 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 48 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 49 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 50 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 51 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 52 | * 53 | ****************************************************************************** 54 | */ 55 | /* Includes ------------------------------------------------------------------*/ 56 | #include "ai_platform.h" 57 | #include "mnistkeras.h" 58 | #include "mnistkeras_data.h" 59 | 60 | void MX_X_CUBE_AI_Init(void); 61 | void MX_X_CUBE_AI_Process(void); 62 | int aiInit(const ai_u8* activations); 63 | int aiRun(const void *in_data, void *out_data); 64 | 65 | /* Helper macro */ 66 | #define AI_MIN(x_, y_) \ 67 | ( ((x_)<(y_)) ? (x_) : (y_) ) 68 | 69 | #define AI_MAX(x_, y_) \ 70 | ( ((x_)>(y_)) ? (x_) : (y_) ) 71 | 72 | #define AI_CLAMP(x_, min_, max_, type_) \ 73 | (type_) (AI_MIN(AI_MAX(x_, min_), max_)) 74 | 75 | #define AI_ROUND(v_, type_) \ 76 | (type_) ( ((v_)<0) ? ((v_)-0.5f) : ((v_)+0.5f) ) 77 | 78 | /* USER CODE BEGIN includes */ 79 | /* USER CODE END includes */ 80 | #define AI_MMETWORK_IN AI_MNISTKERAS_IN 81 | #define AI_MNETWORK_OUT AI_MNISTKERAS_OUT 82 | 83 | #define AI_MNETWORK_NUMBER (1) 84 | #define AI_MNETWORK_DATA_ACTIVATIONS_SIZE AI_MNISTKERAS_DATA_ACTIVATIONS_SIZE 85 | #define AI_MNETWORK_IN_1_SIZE AI_MNISTKERAS_IN_1_SIZE 86 | #define AI_MNETWORK_IN_1_SIZE_BYTES AI_MNISTKERAS_IN_1_SIZE_BYTES 87 | #define AI_MNETWORK_OUT_1_SIZE AI_MNISTKERAS_OUT_1_SIZE 88 | #define AI_MNETWORK_OUT_1_SIZE_BYTES AI_MNISTKERAS_OUT_1_SIZE_BYTES 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif /*__STMicroelectronics_X-CUBE-AI_4_0_0_H */ 94 | -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/mod_led.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mod_led.h 3 | * 4 | * Usage: 5 | * // Declare LED module and initialize it 6 | * DECLARE_MODULE_LED(led_module, 8, 250); 7 | * mod_led_init(&led_module); 8 | * mod_timer_add((void*) &led_module, led_module.tick_ms, (void*) &mod_led_update, &obj_timer_list); 9 | * // Declare LED 10 | * DECLARE_DEV_LED(def_led, &led_module, 1, NULL, &led_init, &led_on, &led_off); 11 | * dev_led_add(&def_led); 12 | * dev_led_set_pattern(&def_led, 0b11001100); 13 | */ 14 | 15 | #ifndef __MOD_LED_H_ 16 | #define __MOD_LED_H_ 17 | 18 | #include 19 | #include "LICENSE.h" 20 | #include "list.h" 21 | 22 | /* This defines the size/bit-length of the pattern */ 23 | typedef uint16_t led_pattern_t; 24 | 25 | #define DECLARE_MODULE_LED(NAME,SIZE,TICK_MS) \ 26 | struct mod_led NAME = { \ 27 | .pattern_size = SIZE, \ 28 | .tick_ms = TICK_MS, \ 29 | .pattern_index = 0, \ 30 | } 31 | 32 | 33 | struct mod_led { 34 | volatile uint8_t pattern_index; 35 | uint8_t pattern_size; 36 | uint16_t tick_ms; 37 | struct list_head led_list; 38 | }; 39 | 40 | 41 | #define DECLARE_DEV_LED(NAME,OWNER,ID,BSP_DATA,INIT_FUNC,ON_FUNC,OFF_FUNC) \ 42 | struct dev_led NAME = { \ 43 | .owner = OWNER, \ 44 | .id = ID, \ 45 | .bsp_data =BSP_DATA, \ 46 | .led_init = INIT_FUNC, \ 47 | .led_on = ON_FUNC, \ 48 | .led_off = OFF_FUNC, \ 49 | .pattern = 0, \ 50 | } 51 | 52 | 53 | struct dev_led { 54 | struct mod_led * owner; 55 | uint16_t id; 56 | led_pattern_t pattern; 57 | void *bsp_data; 58 | void (*led_init)(void*); 59 | void (*led_on)(void*); 60 | void (*led_off)(void*); 61 | struct list_head list; 62 | }; 63 | 64 | 65 | #define LED_EXISTS(LED, ITTERATOR) (LED->id == ITTERATOR->id) 66 | 67 | /** 68 | * @brief Initialize LED 69 | * @param[in] dev_led A pointer to the LED dev 70 | */ 71 | static inline void __attribute__((always_inline)) 72 | mod_led_init(struct mod_led * mod) 73 | { 74 | INIT_LIST_HEAD(&mod->led_list); 75 | } 76 | 77 | 78 | static inline struct __attribute__((always_inline)) 79 | dev_led * dev_led_find(struct mod_led * mod, struct dev_led * led) 80 | { 81 | if (!mod || !led) return NULL; 82 | if (!list_empty(&mod->led_list)) { 83 | struct dev_led * led_it = NULL; 84 | list_for_each_entry(led_it, &mod->led_list, list) { 85 | if LED_EXISTS(led, led_it) { 86 | /* found */ 87 | return(led_it); 88 | } 89 | } 90 | } 91 | return NULL; 92 | } 93 | 94 | 95 | /** 96 | * @brief Set the active pattern 97 | * @param[in] dev_led A pointer to the LED dev struct 98 | * @param[in] pattern The pattern to set as active.This is truncated to uint8_t internally 99 | */ 100 | static inline void __attribute__((always_inline)) 101 | dev_led_set_pattern(struct dev_led * led, led_pattern_t pattern) 102 | { 103 | struct mod_led * mod = led->owner; 104 | struct dev_led * found_led = dev_led_find(mod, led); 105 | if (found_led) { 106 | found_led->pattern = pattern; 107 | } 108 | } 109 | 110 | 111 | static inline void __attribute__((always_inline)) 112 | dev_led_add(struct dev_led * led) 113 | { 114 | struct mod_led * mod = led->owner; 115 | 116 | /* do not allow duplicates */ 117 | if (dev_led_find(mod, led)) { 118 | return; 119 | } 120 | 121 | /* init dev head list */ 122 | INIT_LIST_HEAD(&led->list); 123 | 124 | /* Add to led_list */ 125 | list_add(&led->list, &mod->led_list); 126 | 127 | /* initialize the port/pin. This is a BSP depended call and must be implemented elsewhere */ 128 | led->led_init(led->bsp_data); 129 | 130 | dev_led_set_pattern(led, led->pattern); 131 | return; 132 | } 133 | 134 | 135 | static inline void __attribute__((always_inline)) 136 | dev_led_remove(struct dev_led * led) 137 | { 138 | struct mod_led * dev = led->owner; 139 | struct dev_led * found_led = dev_led_find(dev, led); 140 | if (found_led) { 141 | led->led_off(led->bsp_data); 142 | list_del(&found_led->list); 143 | } 144 | } 145 | 146 | 147 | /** 148 | * @brief Update the LED pattern 149 | */ 150 | static inline void __attribute__((always_inline)) 151 | mod_led_update(struct mod_led * mod) 152 | { 153 | if (!list_empty(&mod->led_list)) { 154 | struct dev_led * led_it; 155 | list_for_each_entry(led_it, &mod->led_list, list) { 156 | if (led_it->pattern & (1 << mod->pattern_index) ) 157 | led_it->led_on(led_it->bsp_data); 158 | else 159 | led_it->led_off(led_it->bsp_data); 160 | if ((++mod->pattern_index) == mod->pattern_size) 161 | mod->pattern_index = 0; 162 | } 163 | } 164 | } 165 | 166 | #endif /* __MOD_LED_H_ */ 167 | -------------------------------------------------------------------------------- /source/src/inc/digit.h: -------------------------------------------------------------------------------- 1 | const float digit[] = { 2 | 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.011764705882352941,0.027450980392156862,0.0196078431372549,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0196078431372549,0.0196078431372549,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.023529411764705882,0.0,0.0,0.0,0.0,0.0,0.2549019607843137,0.06274509803921569,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.047058823529411764,0.6078431372549019,1.0,1.0,1.0,1.0,0.8980392156862745,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.18823529411764706,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.3411764705882353,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.596078431372549,1.0,1.0,0.792156862745098,0.4,0.16470588235294117,0.5490196078431373,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.011764705882352941,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.7490196078431373,1.0,0.4196078431372549,0.0,0.0,0.0,0.0,0.0,0.0,0.7372549019607844,1.0,1.0,1.0,0.9568627450980393,0.0,0.01568627450980392,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.3058823529411765,0.6039215686274509,0.0,0.0,0.0,0.00784313725490196,0.027450980392156862,0.0196078431372549,0.011764705882352941,0.0,0.0,0.7372549019607844,1.0,1.0,1.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.03137254901960784,0.011764705882352941,0.0,0.0,0.0,0.0,0.0196078431372549,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.8627450980392157,1.0,0.5647058823529412,0.0,0.027450980392156862,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0196078431372549,0.0,0.0,1.0,0.027450980392156862,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,1.0,0.37254901960784315,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.803921568627451,0.44313725490196076,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.8705882352941177,0.5058823529411764,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.8627450980392157,0.5019607843137255,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.01568627450980392,0.0,0.0,0.8156862745098039,0.47843137254901963,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.5058823529411764,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.19215686274509805,1.0,0.44313725490196076,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.3058823529411765,1.0,0.1607843137254902,0.0,0.00784313725490196,0.023529411764705882,0.0196078431372549,0.01568627450980392,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.16862745098039217,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.027450980392156862,0.027450980392156862,0.027450980392156862,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.08627450980392157,1.0,1.0,1.0,1.0,0.792156862745098,0.6431372549019608,0.43529411764705883,0.09803921568627451,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.011764705882352941,0.0,0.058823529411764705,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.6039215686274509,0.5843137254901961,0.6431372549019608,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.5490196078431373,0.6784313725490196,0.9725490196078431,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.9294117647058824,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.23529411764705882,0.6862745098039216,1.0,1.0,1.0,1.0,0.6196078431372549,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.027450980392156862,0.027450980392156862,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0784313725490196,0.0,0.0,0.00784313725490196,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.00392156862745098,0.00392156862745098,0.00784313725490196,0.01568627450980392,0.01568627450980392,0.0,0.0,0.0,0.0,0.00392156862745098,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 3 | }; -------------------------------------------------------------------------------- /jupyter_notebook/MnistDigitDraw/MnistDigitDraw.py: -------------------------------------------------------------------------------- 1 | from PIL import ImageTk, Image, ImageDraw, ImageFilter 2 | import PIL 3 | from tkinter import * 4 | import numpy as np 5 | 6 | class MnistDigitDraw: 7 | def __init__(self, master, width, height): 8 | self._master = master 9 | self._width = width 10 | self._height = height 11 | self._mnist_width = 28 12 | self._mnist_height = 28 13 | self._output_image = PIL.Image.new('L', (self._mnist_width, self._mnist_height), (255)) 14 | self._export_fname = 'digit.txt' 15 | 16 | def start(self): 17 | # Create a frame that will host the canvas and buttons 18 | self._frame = Frame(self._master) 19 | # Canvas for drawing 20 | self._canvas = Canvas(self._frame, width=self._width, height=self._height, bg='white') 21 | # create an empty PIL image and draw object to draw on 22 | self._input_image = PIL.Image.new('L', (self._width, self._height), (255)) 23 | self._draw = ImageDraw.Draw(self._input_image) 24 | self._canvas.pack(expand=YES, fill=BOTH, side=LEFT) 25 | self._canvas.bind("", self._paint) 26 | 27 | # Canvas for displaying the result image 28 | self._img_canvas = Canvas(self._frame, width=self._width, height=self._height, bg='white') 29 | self._img_canvas.pack(expand=YES, fill=BOTH, side=RIGHT) 30 | # self._img_canvas.create_image(self._width/2, self._height/2, image=self._output_image) 31 | 32 | # Inference button 33 | self._btn_inference = Button(self._frame, text="Inference", command = self._btn_inference) 34 | self._btn_inference.pack(side=BOTTOM) 35 | # Inference button 36 | self._btn_export = Button(self._frame, text="Export", command = self._btn_export) 37 | self._btn_export.pack(side=BOTTOM) 38 | # Clear button 39 | self._btn_clear = Button(self._frame, text="Clear", command = self._btn_clear) 40 | self._btn_clear.pack(side=BOTTOM) 41 | # Add controls 42 | self._frame.pack() 43 | 44 | def _paint(self,event): 45 | x1, y1 = (event.x - 1), (event.y - 1) 46 | x2, y2 = (event.x + 1), (event.y + 1) 47 | self._canvas.create_oval(x1, y1, x2, y2, fill="black",width=30) 48 | self._draw.line([x1, y1, x2, y2],fill="black",width=30) 49 | 50 | def _convert_image(self): 51 | # First down-scale the image at mnist size 52 | img = self._input_image.resize((self._mnist_width,self._mnist_height), PIL.Image.ANTIALIAS).filter(ImageFilter.SHARPEN) 53 | # Then up-scale again to width/height 54 | self._output_image = ImageTk.PhotoImage(img.resize((self._width, self._height), PIL.Image.NONE)) 55 | # Display the image in the right windows 56 | self._img_canvas.create_image(self._width/2, self._height/2, image=self._output_image) 57 | arr = self._image_to_array(img) 58 | return arr 59 | 60 | def _btn_export(self): 61 | """ 62 | Exports the digit to a text file in order to import it in the jupyter notebook 63 | """ 64 | # Convert the image to the MNIST format 65 | arr = self._convert_image() 66 | # Convert the image to a numpy array 67 | # Debug save array to file 68 | np.savetxt(self._export_fname, arr) 69 | print("Exported image to %s" % (self._export_fname)) 70 | 71 | def _btn_inference(self): 72 | """ 73 | Send the data to the stm32f746 for processing 74 | """ 75 | # Convert the image to the MNIST format 76 | arr = self._convert_image() 77 | # Send the array to the MCU via serial 78 | print("Not implemented yet...") 79 | 80 | def _btn_clear(self): 81 | """ 82 | Clear the image in order to re-draw 83 | """ 84 | # Clear canvas 85 | self._canvas.delete(ALL) 86 | self._img_canvas.delete(ALL) 87 | # Clear left image 88 | del self._input_image 89 | self._input_image = PIL.Image.new('L', (self._width, self._height), (255)) 90 | self._draw = ImageDraw.Draw(self._input_image) 91 | 92 | def _image_to_array(self, im): 93 | """ 94 | This function returns the pixel values. 95 | The imput is a png file location. 96 | """ 97 | tv = list(im.getdata()) # get pixel values 98 | # normalize pixels to 0 and 1. 0 is pure white, 1 is pure black. 99 | tva = [(255 - x) * 1.0 / 255.0 for x in tv] 100 | return tva 101 | 102 | 103 | if __name__=="__main__": 104 | var = Tk() 105 | dd = DigitDraw(var, 250, 250) 106 | dd.start() 107 | var.mainloop() -------------------------------------------------------------------------------- /source/cmake/language_provider.cmake: -------------------------------------------------------------------------------- 1 | # This will sort the Eclipse indexer issue with mixed C/C++ source code projects 2 | # by Wolfgang Schmieder 3 | # (https://www.eclipse.org/forums/index.php/t/1066506/?) 4 | 5 | # Create language specific (C/C++) compiler built in macros and include paths 6 | message("${MESSAGE_TABS}language_provider.cmake ...") 7 | SET(MESSAGE_TABS "${MESSAGE_TABS}\t") 8 | 9 | #Try replacing in function create_language_provider the text: 10 | # 'org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector' by 11 | # 'org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorCygwin' if you use Cygwin toolchain, respectively by 12 | # 'org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW' if you use MinGW toolchain. 13 | # Note: The above settings for Cygwin / MinGW have not been tested yet. 14 | 15 | function(create_language_provider OUTPUT_DIR COMMAND_PREFIX) 16 | set(OUTPUT_FILE ${OUTPUT_DIR}/language.settings.xml) 17 | file(WRITE ${OUTPUT_FILE} "\n") 18 | file(APPEND ${OUTPUT_FILE} "\n") 19 | file(APPEND ${OUTPUT_FILE} "\t\n") 20 | file(APPEND ${OUTPUT_FILE} "\t\t\n") 21 | file(APPEND ${OUTPUT_FILE} "\t\t\t\n") 22 | file(APPEND ${OUTPUT_FILE} "\t\t\t\n") 23 | file(APPEND ${OUTPUT_FILE} "\t\t\t\n") 24 | file(APPEND ${OUTPUT_FILE} "\t\t\t\t\n") 25 | file(APPEND ${OUTPUT_FILE} "\t\t\t\t\n") 26 | file(APPEND ${OUTPUT_FILE} "\t\t\t\n") 27 | file(APPEND ${OUTPUT_FILE} "\t\t\t\n") 28 | file(APPEND ${OUTPUT_FILE} "\t\t\n") 29 | file(APPEND ${OUTPUT_FILE} "\t\n") 30 | file(APPEND ${OUTPUT_FILE} "\n") 31 | endfunction(create_language_provider) 32 | 33 | 34 | macro(remove_from_SYSTEM_ITEM LANGUAGE ITEM_TYPE CACHE_DOC_STRING) 35 | # message("${MESSAGE_TABS}CMAKE_EXTRA_GENERATOR_${LANGUAGE}${ITEM_TYPE} = ${CMAKE_EXTRA_GENERATOR_${LANGUAGE}${ITEM_TYPE}}") 36 | set(TEMP_VAR) 37 | if(${ARGC} LESS 4) 38 | # There is no regular expression, so remove everything 39 | message("${MESSAGE_TABS}wiping ${CACHE_DOC_STRING}") 40 | else(${ARGC} LESS 4) 41 | # The extra argument ist treated as an regular expression. Every match will be removed. 42 | message("${MESSAGE_TABS}Removing ${ARGN} from ${CACHE_DOC_STRING}") 43 | 44 | set(TEMP_VAR "${CMAKE_EXTRA_GENERATOR_${LANGUAGE}${ITEM_TYPE}}") 45 | STRING(REGEX REPLACE "${ARGN}" "" TEMP_VAR "${TEMP_VAR}") 46 | endif(${ARGC} LESS 4) 47 | set(CMAKE_EXTRA_GENERATOR_${LANGUAGE}${ITEM_TYPE} "${TEMP_VAR}" CACHE INTERNAL "${CACHE_DOC_STRING}") 48 | # message("${MESSAGE_TABS}CMAKE_EXTRA_GENERATOR_${LANGUAGE}${ITEM_TYPE} = ${CMAKE_EXTRA_GENERATOR_${LANGUAGE}${ITEM_TYPE}}") 49 | endmacro(remove_from_SYSTEM_ITEM ITEM_TYPE) 50 | 51 | # Remove a string from C or CXX system include directories. 52 | # The string to be removed is passed as a regular expression within the optional the last argument 53 | # If there is no regular expression, ALL system include directories will be removed. 54 | macro(remove_from_SYSTEM_INCLUDE_DIRS LANGUAGE) 55 | set(system_DOC_STRING "${LANGUAGE} compiler system include directories") 56 | remove_from_SYSTEM_ITEM(${LANGUAGE} _SYSTEM_INCLUDE_DIRS "${system_DOC_STRING}" ${ARGN}) 57 | endmacro(remove_from_SYSTEM_INCLUDE_DIRS) 58 | 59 | # Remove a string from C or CXX system defined macros. 60 | # The string to be removed is passed as a regular expression within the optional the last argument 61 | # If there is no regular expression, ALL system defined macros will be removed. 62 | macro(remove_from_SYSTEM_MACROS LANGUAGE) 63 | set(system_DOC_STRING "${LANGUAGE} compiler system defined macros") 64 | remove_from_SYSTEM_ITEM(${LANGUAGE} _SYSTEM_DEFINED_MACROS "${system_DOC_STRING}" ${ARGN}) 65 | endmacro(remove_from_SYSTEM_MACROS) 66 | 67 | if(NOT ${MESSAGE_TABS} STREQUAL "") 68 | STRING(SUBSTRING ${MESSAGE_TABS} 1 -1 MESSAGE_TABS) 69 | endif(NOT ${MESSAGE_TABS} STREQUAL "") 70 | message("${MESSAGE_TABS}language_provider.cmake done.\n") -------------------------------------------------------------------------------- /source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Author: Dimitris Tassopoulos 2 | 3 | cmake_minimum_required(VERSION 3.6) 4 | 5 | project(stm32f7-mnist-x_cube_ai LANGUAGES C CXX) 6 | 7 | option(USE_CORTEX_NN "Use Cortex-M7 DSP/NN lib" ON) 8 | option(USE_STM_AI "Use STM AI library" ON) 9 | option(USE_HAL_DRIVER "Use HAL Driver library" ON) 10 | option(USE_OVERCLOCK "Overclock the STM7" OFF) 11 | 12 | set(DEVICE_CONFIG_DIR ${CMAKE_SOURCE_DIR}/libs/CMSIS/Device/ST/STM32F7xx) 13 | 14 | # Include toolchain (toolchain path ) 15 | include(cmake/TOOLCHAIN_arm_none_eabi_cortex_m7.cmake) 16 | # If the toolchain path is not set in the build scsript then add it here${DEVICE_CONFIG_DIR} 17 | # or in the toolchain cmake file 18 | # set(TOOLCHAIN_DIR "/opt/toolchains/gcc-arm-none-eabi-8-2018-q4-major") 19 | 20 | # Define the hardware 21 | set(OTHER_SRC_FILES "${DEVICE_CONFIG_DIR}/system_stm32f7xx.c") 22 | 23 | # Set STM32 SoC specific variables 24 | set(STM32F7_DEFINES " \ 25 | -DIVECT_TAB_OFFSET=0x0 \ 26 | -DSTM32F746xx \ 27 | -DARM_MATH_CM7 \ 28 | '-D__FPU_PRESENT=1' \ 29 | ") 30 | 31 | # set compiler optimisations 32 | set(COMPILER_OPTIMISATION "-Og -g3") 33 | 34 | # Enable CPU overclock 35 | if (USE_OVERCLOCK) 36 | set(STM32F7_DEFINES "${STM32F7_DEFINES} -DOVERCLOCK") 37 | endif() 38 | 39 | # add startup and linker file 40 | set(STARTUP_ASM_FILE "${CMAKE_SOURCE_DIR}/config/startup/startup_stm32f746xx.s") 41 | set_property(SOURCE ${STARTUP_ASM_FILE} PROPERTY LANGUAGE ASM) 42 | set(LINKER_FILE "${CMAKE_SOURCE_DIR}/STM32F746NGHx_FLASH.ld") 43 | 44 | # Only build for arm-none-eabi 45 | if (NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm-none-eabi") 46 | message(FATAL_ERROR "Invalid CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") 47 | endif() 48 | 49 | if (USE_STM_AI) 50 | include(cmake/stm_ai_lib.cmake) 51 | endif() 52 | 53 | if (USE_CORTEX_NN) 54 | include(cmake/cmsis_dsp_lib.cmake) 55 | endif() 56 | 57 | # HAL Driver shared library 58 | if (USE_HAL_DRIVER) 59 | include(cmake/stm32f7_hal_driver.cmake) 60 | endif() 61 | 62 | # Add the arch independent C lib 63 | include (cmake/noarch_c_lib.cmake) 64 | include (cmake/flatbuffers_lib.cmake) 65 | 66 | # force stm builds to debug. This is a hack as when release is set, it automatically 67 | # sets the invalid -O3 flag on the assembler. 68 | set(CMAKE_BUILD_TYPE Debug) 69 | 70 | # Resolve the issue with Eclipse's indexer and C/C++ mixed source files 71 | include(cmake/language_provider.cmake) 72 | remove_from_SYSTEM_MACROS(CXX "__cplusplus;.*;") 73 | create_language_provider("${CMAKE_BINARY_DIR}/.settings" "${GCC_PREFIX}-" "${CXX_STANDARD_FLAG}") 74 | 75 | # enable asm for stm startup.s file 76 | enable_language(ASM) 77 | 78 | ## Override toolchain flags ## 79 | # CFLAGS 80 | set (STM32F7_ARCH "-mthumb -mcpu=cortex-m7 -mfpu=fpv5-sp-d16 -mfloat-abi=hard") 81 | set (CMAKE_C_FLAGS "${COMPILER_OPTIMISATION} ${STM32F7_DEFINES} \ 82 | ${STM32F7_ARCH} \ 83 | -fmessage-length=0 -ffunction-sections -fmessage-length=0 -std=c11 \ 84 | -Wall -lm -specs=nosys.specs -specs=nano.specs -u _printf_float \ 85 | -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize") 86 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} " CACHE INTERNAL "c compiler flags") 87 | # CXXFLAGS 88 | set (CMAKE_CXX_FLAGS "${COMPILER_OPTIMISATION} ${STM32F7_DEFINES} \ 89 | ${STM32F7_ARCH} \ 90 | -fmessage-length=0 -ffunction-sections -fmessage-length=0 \ 91 | -Wall -lm -specs=nosys.specs -specs=nano.specs -u _printf_float") 92 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -s") 93 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE INTERNAL "cxx compiler flags") 94 | 95 | # ASMFLAGS 96 | set (CMAKE_ASM_FLAGS "-g ${STM32F7_ARCH}" CACHE INTERNAL "asm compiler flags") 97 | # LDFLAGS 98 | # -L${CMAKE_SOURCE_DIR}/libs/AI/Lib -l:NetworkRuntime400_CM7_GCC.a \ 99 | set (CMAKE_EXE_LINKER_FLAGS "${STM32F7_ARCH} -Wl,--gc-sections -lm -T${LINKER_FILE} \ 100 | -L\"${CMAKE_SOURCE_DIR}/libs/AI/Lib\" -lNetworkRuntime400_CM7_GCC \ 101 | ") 102 | set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" CACHE INTERNAL "executable linker flags") 103 | 104 | message(STATUS "System Processor : ${CMAKE_SYSTEM_PROCESSOR}") 105 | message(STATUS 106 | "BUILD FLAGS:\n" 107 | " c flags : ${CMAKE_C_FLAGS}\n" 108 | " c++ flags : ${CMAKE_CXX_FLAGS}\n" 109 | " asm flags : ${CMAKE_ASM_FLAGS}\n" 110 | " ld flags : ${CMAKE_EXE_LINKER_FLAGS}\n" 111 | " optimizations : ${COMPILER_OPTIMISATION}\n" 112 | " CMSIS : ${CMSIS_DIR}\n" 113 | " HAL library : ${STDPERIPHSTM32F7_HAL_DRIVER_DIR_DIR}\n" 114 | " FreeRTOS : ${FREERTOS_INC_DIR}\n" 115 | ) 116 | 117 | 118 | # add the source code directory 119 | add_subdirectory(${SRC}) 120 | -------------------------------------------------------------------------------- /source/libs/noarch_c_lib/timer_sched.h: -------------------------------------------------------------------------------- 1 | /* 2 | * timer_sched.h 3 | * 4 | * LICENSE: MIT 5 | * 6 | * The following example creates two different timers that each one can host different 7 | * timer objects. To create a new timer object use this in your main code: 8 | * 9 | * // Example led structure 10 | * struct led_t { 11 | * uint16_t tick_ms; 12 | * uint8_ pattern; 13 | * }; 14 | * 15 | * // Instances of leds 16 | * struct led_t led2 = {100, 0b00110011}; 17 | * struct led_t led3 = {500, 0b00110011}; 18 | * struct led_t led4 = {1000, 0b00110011}; 19 | * struct led_t led5 = {2000, 0b00110011}; 20 | * 21 | * // Callback function that handles all leds in this case (it could be different) 22 | * void led_update(truct led_t * led) 23 | * { 24 | * // Handle led 25 | * } 26 | * 27 | * // In your main 28 | * mod_timer_add((void*) &led1, led1.tick_ms, (void*) &led_update, &timer1_list); 29 | * mod_timer_add((void*) &led2, led2.tick_ms, (void*) &led_update, &timer1_list); 30 | * mod_timer_add((void*) &led3, led3.tick_ms, (void*) &led_update, &timer2_list); 31 | * mod_timer_add((void*) &led4, led4.tick_ms, (void*) &led_update, &timer2_list); 32 | * 33 | * The above code will add two led objects in each timer and the callback function 34 | * will be triggered for each one. 35 | * 36 | * Last and most important is that you need a read hw timer to run the timer's 37 | * internal clock. Therefore, for your platform you can setup a HW timer to triggered 38 | * every 1ms and in this timer routine you just need to run these two functions. 39 | * 40 | * mod_timer_polling(timer1_list); 41 | * mod_timer_polling(timer2_list); 42 | * 43 | * It's just simple as that. 44 | */ 45 | 46 | 47 | #ifndef __TIMER_SCHED_H_ 48 | #define __TIMER_SCHED_H_ 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | #include 55 | #include 56 | #include 57 | #include "LICENSE.h" 58 | #include "list.h" 59 | 60 | typedef void (*fp_timeout_cb)(void *); 61 | 62 | /** 63 | * @brief: Basic timer object. 64 | * @parent void* This is a pointer to the object that will use the timer 65 | * @timeout uint16_t This is the number or the main clock ticks for the timer to be triggered 66 | * @counter uint16_t The count up value that is compared with the timeout_ticks 67 | * @fp_timeout_cb void(*)(void*) The callback function to call when the timer triggers 68 | * @list list_head The timer list 69 | */ 70 | struct obj_timer_t { 71 | void *parent; 72 | uint16_t timeout_ticks; 73 | volatile uint16_t counter; 74 | fp_timeout_cb cbk; 75 | struct list_head list; 76 | }; 77 | 78 | #define TIMER_EXISTS(TMR, ITTERATOR) ( (TMR->cbk == ITTERATOR->cbk) && (TMR->timeout_ticks == ITTERATOR->timeout_ticks) ) 79 | 80 | static inline struct obj_timer_t * __attribute__((always_inline)) 81 | mod_timer_find_timer(struct obj_timer_t * tmr, struct list_head * timer_list) 82 | { 83 | if (!list_empty(timer_list)) { 84 | struct obj_timer_t * tmr_it = NULL; 85 | list_for_each_entry(tmr_it, timer_list, list) { 86 | if TIMER_EXISTS(tmr, tmr_it) { 87 | /* found */ 88 | return(tmr_it); 89 | } 90 | } 91 | } 92 | return NULL; 93 | } 94 | 95 | static inline void __attribute__((always_inline)) 96 | mod_timer_add(void * object, uint16_t timeout, fp_timeout_cb obj_callback, struct list_head * timer_list) 97 | { 98 | struct obj_timer_t timer = { 99 | .parent = object, 100 | .timeout_ticks = timeout, 101 | .counter = 0, 102 | .cbk = obj_callback 103 | }; 104 | /* Check if already exists */ 105 | if (!timer_list) return; 106 | if (!mod_timer_find_timer(&timer, timer_list)) { 107 | struct obj_timer_t * new_timer = (struct obj_timer_t *) malloc(sizeof(struct obj_timer_t)); 108 | memcpy(new_timer, &timer, sizeof(struct obj_timer_t)); 109 | // TRACE(("Timer add: %d/%d\n", new_timer->timeout_ticks, new_timer->counter)); 110 | INIT_LIST_HEAD(&new_timer->list); 111 | list_add(&new_timer->list, timer_list); 112 | } 113 | } 114 | 115 | static inline void __attribute__((always_inline)) 116 | mod_timer_del(struct obj_timer_t * timer, struct list_head * timer_list) 117 | { 118 | struct obj_timer_t * found_timer = mod_timer_find_timer(timer, timer_list); 119 | if (found_timer) { 120 | /* remove */ 121 | list_del(&found_timer->list); 122 | free(found_timer); 123 | } 124 | } 125 | 126 | static inline void __attribute__((always_inline)) 127 | mod_timer_polling(struct list_head * timer_list) 128 | { 129 | if (!list_empty(timer_list)) { 130 | struct obj_timer_t * tmr_it = NULL; 131 | list_for_each_entry(tmr_it, timer_list, list) { 132 | if ((++tmr_it->counter) >= tmr_it->timeout_ticks) { 133 | tmr_it->counter = 0; 134 | tmr_it->cbk(tmr_it->parent); 135 | } 136 | } 137 | } 138 | } 139 | 140 | #ifdef __cplusplus 141 | } 142 | #endif 143 | 144 | #endif /* __TIMER_SCHED_H_ */ 145 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/core_log.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_log.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 14-Aug-2018 6 | * @brief header file of core log interfaces 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | #ifndef __CORE_LOG_H_ 22 | #define __CORE_LOG_H_ 23 | #pragma once 24 | 25 | #include "ai_platform.h" 26 | 27 | /*! 28 | * @defgroup core_log Logger core routines wrapper interface 29 | * @brief Common macros, datatypes and routines of ai logger module 30 | * @details This header defines the wrapping macros interfaces to handle the 31 | * global logger module. These macro are defined when the macro HAS_LOG is 32 | * defined, otherwise they are all set to NOP routines and no logger code is 33 | * compiled at all. When the macro HAS_LOG is defined, only the log messages 34 | * having an enum id >= the value of the macro are compiled. Thus to include in 35 | * compilation only log messages up to the error level the value of HAS_LOG must 36 | * be equal the the enum value of LOG_ERROR macro (i.e. 3). a value of 6 means 37 | * to include all log messages up to the lower LOG_TRACE level. 38 | */ 39 | 40 | #if defined HAS_LOG && (HAS_LOG>=0) 41 | #include "ai_log.h" 42 | #define AI_LOG_SECTION(...) { __VA_ARGS__ } 43 | 44 | #define AI_LOG_ACQUIRE() \ 45 | ai_log_acquire() 46 | #define AI_LOG_SET_LEVEL(level_) \ 47 | AI_WRAP_FUNC(ai_log_set_level(level_);) 48 | #define AI_LOG_SET_QUIET(onoff_) \ 49 | AI_WRAP_FUNC(ai_log_set_quiet(onoff_);) 50 | #define AI_LOG_SET_LOCK_FN(fn_, udata_) \ 51 | AI_WRAP_FUNC(ai_log_set_lock(fn_, udata_);) 52 | #define AI_LOG_CHANNEL_PUSH(level_, fn_, udata_) \ 53 | AI_WRAP_FUNC(ai_log_channel_push(level_, fn_, udata_);) 54 | #define AI_LOG_CHANNEL_POP(fn_, udata_) \ 55 | AI_WRAP_FUNC(ai_log_channel_pop(fn_, udata_);) 56 | #ifdef LOG_USE_FILE 57 | #define AI_LOG_SET_FILE_POINTER(fp_) \ 58 | AI_WRAP_FUNC(ai_log_set_fp(fp_);) 59 | #else 60 | #define AI_LOG_SET_FILE_POINTER(fp_) \ 61 | /*AI_LOG_SET_FILE_POINTER()*/ 62 | #endif 63 | #else 64 | #define AI_LOG_SECTION(...) /*AI_LOG_SECTION()*/ 65 | 66 | #define AI_LOG_ACQUIRE() (NULL) 67 | #define AI_LOG_SET_LEVEL(level_) /*AI_LOG_SET_LEVEL()*/ 68 | #define AI_LOG_SET_QUIET(onoff_) /*AI_LOG_SET_QUIET()*/ 69 | #define AI_LOG_SET_LOCK_FN(fn_, udata_) /*AI_LOG_SET_LOCK_FN()*/ 70 | #define AI_LOG_CHANNEL_PUSH(level_, fn_, udata_) /*AI_LOG_CHANNEL_PUSH()*/ 71 | #define AI_LOG_CHANNEL_POP(fn_, udata_) /*AI_LOG_CHANNEL_POP()*/ 72 | #define AI_LOG_SET_FILE_POINTER(fp_) /*AI_LOG_SET_FILE_POINTER()*/ 73 | #endif 74 | 75 | #if defined HAS_LOG && (HAS_LOG>=LOG_SUDO) 76 | #define AI_LOG_SUDO(...) AI_WRAP_FUNC(ai_log_log(LOG_SUDO, __FILE__, __LINE__, __VA_ARGS__);) 77 | #else 78 | #define AI_LOG_SUDO(...) /*AI_LOG_SUDO()*/ 79 | #endif 80 | 81 | #if defined HAS_LOG && (HAS_LOG>=LOG_TRACE) 82 | #define AI_LOG_TRACE(...) AI_WRAP_FUNC(ai_log_log(LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__);) 83 | #else 84 | #define AI_LOG_TRACE(...) /*AI_LOG_TRACE()*/ 85 | #endif 86 | 87 | #if defined HAS_LOG && (HAS_LOG>=LOG_DEBUG) 88 | #define AI_LOG_DEBUG(...) AI_WRAP_FUNC(ai_log_log(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__);) 89 | #else 90 | #define AI_LOG_DEBUG(...) /*AI_LOG_DEBUG()*/ 91 | #endif 92 | 93 | #if defined HAS_LOG && (HAS_LOG>=LOG_INFO) 94 | #define AI_LOG_INFO(...) AI_WRAP_FUNC(ai_log_log(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__);) 95 | #else 96 | #define AI_LOG_INFO(...) /*AI_LOG_INFO()*/ 97 | #endif 98 | 99 | #if defined HAS_LOG && (HAS_LOG>=LOG_WARN) 100 | #define AI_LOG_WARN(...) AI_WRAP_FUNC(ai_log_log(LOG_WARN, __FILE__, __LINE__, __VA_ARGS__);) 101 | #else 102 | #define AI_LOG_WARN(...) /*AI_LOG_WARN()*/ 103 | #endif 104 | 105 | #if defined HAS_LOG && (HAS_LOG>=LOG_ERROR) 106 | #define AI_LOG_ERROR(...) AI_WRAP_FUNC(ai_log_log(LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__);) 107 | #else 108 | #define AI_LOG_ERROR(...) /*AI_LOG_ERROR()*/ 109 | #endif 110 | 111 | #if defined HAS_LOG && (HAS_LOG>=LOG_FATAL) 112 | #define AI_LOG_FATAL(...) AI_WRAP_FUNC(ai_log_log(LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__);) 113 | #else 114 | #define AI_LOG_FATAL(...) /*AI_LOG_FATAL()*/ 115 | #endif 116 | 117 | #endif /*__CORE_LOG_H_*/ 118 | -------------------------------------------------------------------------------- /source/src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ***************************************************************************** 3 | ** 4 | ** File : syscalls.c 5 | ** 6 | ** Author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : STM32CubeIDE Minimal System calls file 9 | ** 10 | ** For more information about which c-functions 11 | ** need which of these lowlevel functions 12 | ** please consult the Newlib libc-manual 13 | ** 14 | ** Environment : STM32CubeIDE MCU 15 | ** 16 | ** Distribution: The file is distributed as is, without any warranty 17 | ** of any kind. 18 | ** 19 | ***************************************************************************** 20 | ** 21 | **

© COPYRIGHT(c) 2018 STMicroelectronics

22 | ** 23 | ** Redistribution and use in source and binary forms, with or without modification, 24 | ** are permitted provided that the following conditions are met: 25 | ** 1. Redistributions of source code must retain the above copyright notice, 26 | ** this list of conditions and the following disclaimer. 27 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 28 | ** this list of conditions and the following disclaimer in the documentation 29 | ** and/or other materials provided with the distribution. 30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | ** may be used to endorse or promote products derived from this software 32 | ** without specific prior written permission. 33 | ** 34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | ** 45 | ** 46 | ***************************************************************************** 47 | */ 48 | 49 | /* Includes */ 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | extern int errno; 60 | extern int __io_putchar(int ch) __attribute__((weak)); 61 | extern int __io_getchar(void) __attribute__((weak)); 62 | 63 | register char *stack_ptr __asm("sp"); 64 | 65 | char *__env[1] = {0}; 66 | char **environ = __env; 67 | 68 | /* Functions */ 69 | void initialise_monitor_handles() {} 70 | 71 | int _getpid(void) { return 1; } 72 | 73 | int _kill(int pid, int sig) 74 | { 75 | errno = EINVAL; 76 | return -1; 77 | } 78 | 79 | void _exit(int status) 80 | { 81 | _kill(status, -1); 82 | while (1) { 83 | } /* Make sure we hang here */ 84 | } 85 | 86 | __attribute__((weak)) int _read(int file, char *ptr, int len) 87 | { 88 | int DataIdx; 89 | 90 | for (DataIdx = 0; DataIdx < len; DataIdx++) { 91 | *ptr++ = __io_getchar(); 92 | } 93 | 94 | return len; 95 | } 96 | 97 | __attribute__((weak)) int _write(int file, char *ptr, int len) 98 | { 99 | int DataIdx; 100 | 101 | for (DataIdx = 0; DataIdx < len; DataIdx++) { 102 | __io_putchar(*ptr++); 103 | } 104 | return len; 105 | } 106 | 107 | int _close(int file) { return -1; } 108 | 109 | int _fstat(int file, struct stat *st) 110 | { 111 | st->st_mode = S_IFCHR; 112 | return 0; 113 | } 114 | 115 | int _isatty(int file) { return 1; } 116 | 117 | int _lseek(int file, int ptr, int dir) { return 0; } 118 | 119 | int _open(char *path, int flags, ...) 120 | { 121 | /* Pretend like we always fail */ 122 | return -1; 123 | } 124 | 125 | int _wait(int *status) 126 | { 127 | errno = ECHILD; 128 | return -1; 129 | } 130 | 131 | int _unlink(char *name) 132 | { 133 | errno = ENOENT; 134 | return -1; 135 | } 136 | 137 | int _times(struct tms *buf) { return -1; } 138 | 139 | int _stat(char *file, struct stat *st) 140 | { 141 | st->st_mode = S_IFCHR; 142 | return 0; 143 | } 144 | 145 | int _link(char *old, char *new) 146 | { 147 | errno = EMLINK; 148 | return -1; 149 | } 150 | 151 | int _fork(void) 152 | { 153 | errno = EAGAIN; 154 | return -1; 155 | } 156 | 157 | int _execve(char *name, char **argv, char **env) 158 | { 159 | errno = ENOMEM; 160 | return -1; 161 | } 162 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/include/flatbuffers/registry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_REGISTRY_H_ 18 | #define FLATBUFFERS_REGISTRY_H_ 19 | 20 | #include "idl.h" 21 | 22 | namespace flatbuffers { 23 | 24 | // Convenience class to easily parse or generate text for arbitrary FlatBuffers. 25 | // Simply pre-populate it with all schema filenames that may be in use, and 26 | // This class will look them up using the file_identifier declared in the 27 | // schema. 28 | class Registry { 29 | public: 30 | // Call this for all schemas that may be in use. The identifier has 31 | // a function in the generated code, e.g. MonsterIdentifier(). 32 | void Register(const char *file_identifier, const char *schema_path) { 33 | Schema schema; 34 | schema.path_ = schema_path; 35 | schemas_[file_identifier] = schema; 36 | } 37 | 38 | // Generate text from an arbitrary FlatBuffer by looking up its 39 | // file_identifier in the registry. 40 | bool FlatBufferToText(const uint8_t *flatbuf, size_t len, std::string *dest) { 41 | // Get the identifier out of the buffer. 42 | // If the buffer is truncated, exit. 43 | if (len < sizeof(uoffset_t) + FlatBufferBuilder::kFileIdentifierLength) { 44 | lasterror_ = "buffer truncated"; 45 | return false; 46 | } 47 | std::string ident( 48 | reinterpret_cast(flatbuf) + sizeof(uoffset_t), 49 | FlatBufferBuilder::kFileIdentifierLength); 50 | // Load and parse the schema. 51 | Parser parser; 52 | if (!LoadSchema(ident, &parser)) return false; 53 | // Now we're ready to generate text. 54 | if (!GenerateText(parser, flatbuf, dest)) { 55 | lasterror_ = "unable to generate text for FlatBuffer binary"; 56 | return false; 57 | } 58 | return true; 59 | } 60 | 61 | // Converts a binary buffer to text using one of the schemas in the registry, 62 | // use the file_identifier to indicate which. 63 | // If DetachedBuffer::data() is null then parsing failed. 64 | DetachedBuffer TextToFlatBuffer(const char *text, 65 | const char *file_identifier) { 66 | // Load and parse the schema. 67 | Parser parser; 68 | if (!LoadSchema(file_identifier, &parser)) return DetachedBuffer(); 69 | // Parse the text. 70 | if (!parser.Parse(text)) { 71 | lasterror_ = parser.error_; 72 | return DetachedBuffer(); 73 | } 74 | // We have a valid FlatBuffer. Detach it from the builder and return. 75 | return parser.builder_.Release(); 76 | } 77 | 78 | // Modify any parsing / output options used by the other functions. 79 | void SetOptions(const IDLOptions &opts) { opts_ = opts; } 80 | 81 | // If schemas used contain include statements, call this function for every 82 | // directory the parser should search them for. 83 | void AddIncludeDirectory(const char *path) { include_paths_.push_back(path); } 84 | 85 | // Returns a human readable error if any of the above functions fail. 86 | const std::string &GetLastError() { return lasterror_; } 87 | 88 | private: 89 | bool LoadSchema(const std::string &ident, Parser *parser) { 90 | // Find the schema, if not, exit. 91 | auto it = schemas_.find(ident); 92 | if (it == schemas_.end()) { 93 | // Don't attach the identifier, since it may not be human readable. 94 | lasterror_ = "identifier for this buffer not in the registry"; 95 | return false; 96 | } 97 | auto &schema = it->second; 98 | // Load the schema from disk. If not, exit. 99 | std::string schematext; 100 | if (!LoadFile(schema.path_.c_str(), false, &schematext)) { 101 | lasterror_ = "could not load schema: " + schema.path_; 102 | return false; 103 | } 104 | // Parse schema. 105 | parser->opts = opts_; 106 | if (!parser->Parse(schematext.c_str(), vector_data(include_paths_), 107 | schema.path_.c_str())) { 108 | lasterror_ = parser->error_; 109 | return false; 110 | } 111 | return true; 112 | } 113 | 114 | struct Schema { 115 | std::string path_; 116 | // TODO(wvo) optionally cache schema file or parsed schema here. 117 | }; 118 | 119 | std::string lasterror_; 120 | IDLOptions opts_; 121 | std::vector include_paths_; 122 | std::map schemas_; 123 | }; 124 | 125 | } // namespace flatbuffers 126 | 127 | #endif // FLATBUFFERS_REGISTRY_H_ 128 | -------------------------------------------------------------------------------- /source/libs/flatbuffers/src/flatc_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "flatc.h" 18 | 19 | static const char *g_program_name = nullptr; 20 | 21 | static void Warn(const flatbuffers::FlatCompiler *flatc, 22 | const std::string &warn, bool show_exe_name) { 23 | (void)flatc; 24 | if (show_exe_name) { printf("%s: ", g_program_name); } 25 | printf("warning: %s\n", warn.c_str()); 26 | } 27 | 28 | static void Error(const flatbuffers::FlatCompiler *flatc, 29 | const std::string &err, bool usage, bool show_exe_name) { 30 | if (show_exe_name) { printf("%s: ", g_program_name); } 31 | printf("error: %s\n", err.c_str()); 32 | if (usage) { printf("%s", flatc->GetUsageString(g_program_name).c_str()); } 33 | exit(1); 34 | } 35 | 36 | int main(int argc, const char *argv[]) { 37 | g_program_name = argv[0]; 38 | 39 | const flatbuffers::FlatCompiler::Generator generators[] = { 40 | { flatbuffers::GenerateBinary, "-b", "--binary", "binary", false, nullptr, 41 | flatbuffers::IDLOptions::kBinary, 42 | "Generate wire format binaries for any data definitions", 43 | flatbuffers::BinaryMakeRule }, 44 | { flatbuffers::GenerateTextFile, "-t", "--json", "text", false, nullptr, 45 | flatbuffers::IDLOptions::kJson, 46 | "Generate text output for any data definitions", 47 | flatbuffers::TextMakeRule }, 48 | { flatbuffers::GenerateCPP, "-c", "--cpp", "C++", true, 49 | flatbuffers::GenerateCppGRPC, flatbuffers::IDLOptions::kCpp, 50 | "Generate C++ headers for tables/structs", flatbuffers::CPPMakeRule }, 51 | { flatbuffers::GenerateGo, "-g", "--go", "Go", true, 52 | flatbuffers::GenerateGoGRPC, flatbuffers::IDLOptions::kGo, 53 | "Generate Go files for tables/structs", flatbuffers::GeneralMakeRule }, 54 | { flatbuffers::GenerateGeneral, "-j", "--java", "Java", true, 55 | flatbuffers::GenerateJavaGRPC, flatbuffers::IDLOptions::kJava, 56 | "Generate Java classes for tables/structs", 57 | flatbuffers::GeneralMakeRule }, 58 | { flatbuffers::GenerateJSTS, "-s", "--js", "JavaScript", true, nullptr, 59 | flatbuffers::IDLOptions::kJs, 60 | "Generate JavaScript code for tables/structs", flatbuffers::JSTSMakeRule }, 61 | { flatbuffers::GenerateDart, "-d", "--dart", "Dart", true, nullptr, 62 | flatbuffers::IDLOptions::kDart, 63 | "Generate Dart classes for tables/structs", flatbuffers::DartMakeRule }, 64 | { flatbuffers::GenerateJSTS, "-T", "--ts", "TypeScript", true, nullptr, 65 | flatbuffers::IDLOptions::kTs, 66 | "Generate TypeScript code for tables/structs", flatbuffers::JSTSMakeRule }, 67 | { flatbuffers::GenerateGeneral, "-n", "--csharp", "C#", true, nullptr, 68 | flatbuffers::IDLOptions::kCSharp, 69 | "Generate C# classes for tables/structs", flatbuffers::GeneralMakeRule }, 70 | { flatbuffers::GeneratePython, "-p", "--python", "Python", true, nullptr, 71 | flatbuffers::IDLOptions::kPython, 72 | "Generate Python files for tables/structs", 73 | flatbuffers::GeneralMakeRule }, 74 | { flatbuffers::GenerateLobster, nullptr, "--lobster", "Lobster", true, nullptr, 75 | flatbuffers::IDLOptions::kLobster, 76 | "Generate Lobster files for tables/structs", 77 | flatbuffers::GeneralMakeRule }, 78 | { flatbuffers::GenerateLua, "-l", "--lua", "Lua", true, nullptr, 79 | flatbuffers::IDLOptions::kLua, 80 | "Generate Lua files for tables/structs", 81 | flatbuffers::GeneralMakeRule }, 82 | { flatbuffers::GenerateRust, "-r", "--rust", "Rust", true, nullptr, 83 | flatbuffers::IDLOptions::kRust, 84 | "Generate Rust files for tables/structs", 85 | flatbuffers::RustMakeRule }, 86 | { flatbuffers::GeneratePhp, nullptr, "--php", "PHP", true, nullptr, 87 | flatbuffers::IDLOptions::kPhp, "Generate PHP files for tables/structs", 88 | flatbuffers::GeneralMakeRule }, 89 | { flatbuffers::GenerateJsonSchema, nullptr, "--jsonschema", "JsonSchema", 90 | true, nullptr, flatbuffers::IDLOptions::kJsonSchema, 91 | "Generate Json schema", flatbuffers::GeneralMakeRule }, 92 | }; 93 | 94 | flatbuffers::FlatCompiler::InitParams params; 95 | params.generators = generators; 96 | params.num_generators = sizeof(generators) / sizeof(generators[0]); 97 | params.warn_fn = Warn; 98 | params.error_fn = Error; 99 | 100 | flatbuffers::FlatCompiler flatc(params); 101 | return flatc.Compile(argc - 1, argv + 1); 102 | } 103 | -------------------------------------------------------------------------------- /source/libs/AI/Inc/core_net_inspect_interface.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file core_net_inspect_interface.h 4 | * @author AST Embedded Analytics Research Platform 5 | * @date 20-Lug-2018 6 | * @brief header file of core network inspection interface APIs 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2018 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | #ifndef __CORE_NET_INSPECT_INTERFACE_H_ 22 | #define __CORE_NET_INSPECT_INTERFACE_H_ 23 | #pragma once 24 | 25 | #include "ai_platform.h" 26 | 27 | AI_API_DECLARE_BEGIN 28 | 29 | /*! 30 | * @defgroup core_validation Validation Core 31 | * @brief Implementation of the validation network interface headers 32 | */ 33 | 34 | 35 | /*! 36 | * @struct ai_inspect_node_info 37 | * @brief network node inspection context: there is one of this datastruct 38 | * for each node of the network 39 | */ 40 | typedef struct ai_inspect_node_info_s { 41 | ai_u16 type; /*!< node type info @see ai_node datastruct */ 42 | ai_u16 id; /*!< node id assigned by codegen tool to identify 43 | the specific node instance */ 44 | ai_u16 batch_id; /*!< current node batch processed */ 45 | ai_u16 n_batches; /*!< total number of node batches to process */ 46 | ai_float elapsed_ms; /*!< node performance analysys: time in 47 | milliseconds to execute the node forward 48 | function */ 49 | ai_u16 in_size; /*!< number of node's input activation buffers */ 50 | ai_u16 out_size; /*!< number of node's output activation buffers */ 51 | ai_buffer* in; /*!< input node activation buffer see @ref ai_buffer */ 52 | ai_buffer* out; /*!< output node activation buffer see @ref ai_buffer */ 53 | } ai_inspect_node_info; 54 | 55 | /*! 56 | * @struct ai_inspect_net_report 57 | * @brief network inspection report context 58 | */ 59 | typedef struct ai_inspect_net_report_s { 60 | ai_u32 id; /*!< id of the report */ 61 | ai_signature signature; /*!< network identification checksum */ 62 | ai_u32 num_inferences; /*!< total number of inferences processed 63 | during the inspection */ 64 | ai_u32 n_nodes; /*!< number of nodes in the network */ 65 | ai_float elapsed_ms; /*!< network total time (in ms) for processing 66 | num_inferences inferences */ 67 | ai_inspect_node_info* node; /*!< pointer to the array of size n_nodes where 68 | a single node report is reported. see @ref 69 | ai_inspect_node_info datastruct */ 70 | } ai_inspect_net_report; 71 | 72 | /*! 73 | * @enum net inspector inspection mode 74 | * @brief configuration flags to set net inspection mode 75 | */ 76 | typedef enum { 77 | VALIDATION_INSPECT = (0x1<<0), /**< Network validation inspection mode */ 78 | STORE_ALL_IO_ACTIVATIONS = (0x1<<7), /**< Store all I/O activations on snapshot datastruct */ 79 | } ai_inspect_mode; 80 | 81 | typedef enum { 82 | AI_NODE_EXEC_PRE_FORWARD_STAGE = 0x0, 83 | AI_NODE_EXEC_POST_FORWARD_STAGE = 0x1, 84 | } ai_node_exec_stage; 85 | 86 | /*! 87 | * @brief function pointer to callback report 88 | */ 89 | typedef void (*ai_inspect_report_cb_func)( 90 | const ai_handle cookie, 91 | const ai_inspect_net_report* report); 92 | 93 | /*! 94 | * @brief function pointer to node execute 95 | */ 96 | typedef void (*ai_inspect_exec_node_cb_func)( 97 | const ai_handle cookie, 98 | const ai_inspect_node_info* node_info, 99 | const ai_node_exec_stage stage); 100 | 101 | /*! 102 | * @struct ai_inspect_config 103 | * @brief inspection config datastruct 104 | */ 105 | typedef struct ai_inspect_config_s { 106 | ai_u8 validation_mode; /*!< validation mode flags 107 | see @ref ai_inspect_mode */ 108 | ai_u8 log_level; /*!< log class level see @ref LOG_SUDO */ 109 | ai_bool log_quiet; /*!< log class quiet mode */ 110 | ai_inspect_report_cb_func on_report_destroy; /*!< callback function 111 | called when a report datastruct 112 | is released from memory */ 113 | ai_inspect_exec_node_cb_func on_exec_node; /*!< callback function 114 | called when a node is executed (pre & post) */ 115 | ai_handle cookie; 116 | } ai_inspect_config; 117 | 118 | 119 | AI_API_DECLARE_END 120 | 121 | #endif /*__CORE_NET_INSPECT_INTERFACE_H_*/ 122 | -------------------------------------------------------------------------------- /jupyter_notebook/FbComm/FbComm.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.insert(0, './') 3 | sys.path.insert(1, '../') 4 | import flatbuffers 5 | import MnistProt.Mode 6 | import MnistProt.Command 7 | import MnistProt.Commands 8 | import MnistProt.Stats 9 | import MnistProt.InferenceInput 10 | import MnistProt.InferenceOutput 11 | import socket 12 | import serial 13 | import numpy as np 14 | 15 | class FbComm: 16 | def __init__(self, *args, **kwargs): 17 | self._version = 100 18 | self._server_ip = kwargs['ip'] if 'ip' in kwargs else None 19 | self._server_port = kwargs['port'] if 'port' in kwargs else None 20 | self._uart = kwargs['uart'] if 'uart' in kwargs else None 21 | # Create serial port 22 | self._serial = None 23 | if self._uart: 24 | self._serial = serial.Serial( 25 | port=self._uart, 26 | baudrate=115200, 27 | parity=serial.PARITY_NONE, 28 | stopbits=serial.STOPBITS_ONE, 29 | bytesize=serial.EIGHTBITS, 30 | timeout=0.3, # IMPORTANT, can be lower or higher 31 | inter_byte_timeout=0.1 # Alternative 32 | ) 33 | self._serial.isOpen() 34 | # Create and connect to socket 35 | self._tcp_client = None 36 | if self._server_ip: 37 | self._tcp_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 38 | self._tcp_client.connect((self._server_ip, self._server_port)) 39 | print('Comm initialized') 40 | 41 | def __del__(self): 42 | if self._serial: 43 | self._serial.close() 44 | if self._tcp_client: 45 | self._tcp_client.close() 46 | 47 | def reqStats(self): 48 | print('Requesting stats...') 49 | self._builder = flatbuffers.Builder(1024) 50 | MnistProt.Commands.CommandsStart(self._builder) 51 | MnistProt.Commands.CommandsAddCmd(self._builder, MnistProt.Command.Command.CMD_GET_STATS) 52 | req = MnistProt.Commands.CommandsEnd(self._builder) 53 | self._builder.Finish(req) 54 | buf = self._builder.Output() 55 | # Send data 56 | if self._serial: 57 | self.sendDataUart(buf) 58 | if self._tcp_client: 59 | self.sendDataTcp(buf) 60 | # Receive data 61 | print('Receiving stats...') 62 | inp_buf = bytearray 63 | if self._serial: 64 | inp_buf = self._serial.read(100) 65 | if self._tcp_client: 66 | inp_buf = self.recvDataTcp() 67 | resp = MnistProt.Commands.Commands.GetRootAsCommands(inp_buf, 0) 68 | # Print responce 69 | print('Command: %d' % resp.Cmd()) 70 | print('Version: %d' % resp.Stats().Version()) 71 | print('Freq: %d' % resp.Stats().Freq()) 72 | 73 | def reqInference(self, digit): 74 | # Create the image vector 75 | numElems = len(digit) 76 | print('Num of elements: %d' % numElems) 77 | builder = flatbuffers.Builder(4096) 78 | 79 | # Build digit 80 | MnistProt.InferenceInput.InferenceInputStartDigitVector(builder, numElems) 81 | for i in reversed(range(0, numElems)): 82 | builder.PrependFloat32(digit[i]) 83 | digit_vect = builder.EndVector(numElems) 84 | MnistProt.InferenceInput.InferenceInputStart(builder) 85 | MnistProt.InferenceInput.InferenceInputAddDigit(builder, digit_vect) 86 | digit_elem = MnistProt.InferenceInput.InferenceInputEnd(builder) 87 | # Send image data 88 | print('Sending image data') 89 | MnistProt.Commands.CommandsStart(builder) 90 | MnistProt.Commands.CommandsAddCmd(builder, MnistProt.Command.Command.CMD_INFERENCE_INPUT) 91 | MnistProt.Commands.CommandsAddInput(builder, digit_elem) 92 | req = MnistProt.Commands.CommandsEnd(builder) 93 | builder.Finish(req) 94 | buf = builder.Output() 95 | if self._serial: 96 | self.sendDataUart(buf) 97 | if self._tcp_client: 98 | self.sendDataTcp(buf) 99 | # Receive results 100 | print('Receive results...') 101 | inp_buf = bytearray 102 | if self._serial: 103 | self._serial.timeout = 2 104 | inp_buf = self._serial.read(92) 105 | if self._tcp_client: 106 | inp_buf = self.recvDataTcp() 107 | resp = MnistProt.Commands.Commands.GetRootAsCommands(inp_buf, 0) 108 | print('Command: %d'% resp.Cmd()) 109 | print('Execution time: %f msec' % resp.Ouput().TimerMs()) 110 | for i in reversed(range(0, resp.Ouput().OutputFLength())): 111 | print('Out[%d]: %f' % (i, resp.Ouput().OutputF(i))) 112 | 113 | def sendDataUart(self, data): 114 | self._serial.write(data) 115 | 116 | def sendDataTcp(self, data): 117 | # Establish connection to TCP server and exchange data 118 | self._tcp_client.sendall(data) 119 | 120 | def recvDataTcp(self): 121 | received = self._tcp_client.recv(1024) 122 | return received 123 | 124 | 125 | if __name__=="__main__": 126 | # com = FbComm(ip='127.0.0.1', port=32001) 127 | com = FbComm(uart='/dev/ttyUSB1') 128 | com.reqStats() 129 | 130 | # digit = np.load('../digit.txt.npy') 131 | # com.reqInference(digit) 132 | --------------------------------------------------------------------------------