From: @zoloft Reviewed-by: @wangchengyuan,@hangangqiang Signed-off-by: @wangchengyuanpull/13780/MERGE
| @@ -0,0 +1,71 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file : main.h | |||
| * @brief : Header for main.c file. | |||
| * This file contains the common defines of the application. | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * <h2><center>© Copyright (c) 2021 STMicroelectronics. | |||
| * All rights reserved.</center></h2> | |||
| * | |||
| * This software component is licensed by ST under BSD 3-Clause license, | |||
| * the "License"; You may not use this file except in compliance with the | |||
| * License. You may obtain a copy of the License at: | |||
| * opensource.org/licenses/BSD-3-Clause | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Define to prevent recursive inclusion -------------------------------------*/ | |||
| #ifndef __MAIN_H | |||
| #define __MAIN_H | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "stm32f7xx_hal.h" | |||
| /* Private includes ----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| /* Exported types ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN ET */ | |||
| /* USER CODE END ET */ | |||
| /* Exported constants --------------------------------------------------------*/ | |||
| /* USER CODE BEGIN EC */ | |||
| /* USER CODE END EC */ | |||
| /* Exported macro ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN EM */ | |||
| /* USER CODE END EM */ | |||
| /* Exported functions prototypes ---------------------------------------------*/ | |||
| void Error_Handler(void); | |||
| /* USER CODE BEGIN EFP */ | |||
| /* USER CODE END EFP */ | |||
| /* Private defines -----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Private defines */ | |||
| /* USER CODE END Private defines */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __MAIN_H */ | |||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||
| @@ -0,0 +1,214 @@ | |||
| /* USER CODE BEGIN Header */ | |||
| /** | |||
| ****************************************************************************** | |||
| * @file : main.c | |||
| * @brief : Main program body | |||
| ****************************************************************************** | |||
| * @attention | |||
| * | |||
| * <h2><center>© Copyright (c) 2021 STMicroelectronics. | |||
| * All rights reserved.</center></h2> | |||
| * | |||
| * This software component is licensed by ST under BSD 3-Clause license, | |||
| * the "License"; You may not use this file except in compliance with the | |||
| * License. You may obtain a copy of the License at: | |||
| * opensource.org/licenses/BSD-3-Clause | |||
| * | |||
| ****************************************************************************** | |||
| */ | |||
| /* USER CODE END Header */ | |||
| /* Includes ------------------------------------------------------------------*/ | |||
| #include "main.h" | |||
| #include "SEGGER_RTT.h" | |||
| #include "include/errorcode.h" | |||
| #include "include/lite_session.h" | |||
| #include "include/ms_tensor.h" | |||
| #include "mnist_input_data.h" | |||
| // #include <stdio.h> | |||
| using namespace mindspore; | |||
| /* Private includes ----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN Includes */ | |||
| /* USER CODE END Includes */ | |||
| /* Private typedef -----------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PTD */ | |||
| /* USER CODE END PTD */ | |||
| /* Private define ------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PD */ | |||
| /* USER CODE END PD */ | |||
| /* Private macro -------------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PM */ | |||
| /* USER CODE END PM */ | |||
| /* Private variables ---------------------------------------------------------*/ | |||
| /* USER CODE BEGIN PV */ | |||
| /* USER CODE END PV */ | |||
| /* Private function prototypes -----------------------------------------------*/ | |||
| void SystemClock_Config(void); | |||
| /* USER CODE BEGIN PFP */ | |||
| /* USER CODE END PFP */ | |||
| /* Private user code ---------------------------------------------------------*/ | |||
| /* USER CODE BEGIN 0 */ | |||
| /* USER CODE END 0 */ | |||
| /** | |||
| * @brief The application entry point. | |||
| * @retval int | |||
| */ | |||
| int main(void) { | |||
| /* USER CODE BEGIN 1 */ | |||
| /* USER CODE END 1 */ | |||
| /* MCU Configuration--------------------------------------------------------*/ | |||
| /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ | |||
| HAL_Init(); | |||
| /* USER CODE BEGIN Init */ | |||
| /* USER CODE END Init */ | |||
| /* Configure the system clock */ | |||
| SystemClock_Config(); | |||
| /* USER CODE BEGIN SysInit */ | |||
| /* USER CODE END SysInit */ | |||
| /* Initialize all configured peripherals */ | |||
| /* USER CODE BEGIN 2 */ | |||
| /* USER CODE END 2 */ | |||
| /* Infinite loop */ | |||
| /* USER CODE BEGIN WHILE */ | |||
| // float inputs_binbuf[784] = {0}; | |||
| while (1) { | |||
| /* USER CODE END WHILE */ | |||
| SEGGER_RTT_printf(0, "***********mnist test start***********\n"); | |||
| const char *model_buffer = nullptr; | |||
| int model_size = 0; | |||
| session::LiteSession *session = mindspore::session::LiteSession::CreateSession(model_buffer, model_size, nullptr); | |||
| Vector<tensor::MSTensor *> inputs = session->GetInputs(); | |||
| size_t inputs_num = inputs.size(); | |||
| void *inputs_binbuf[inputs_num]; | |||
| int inputs_size[inputs_num]; | |||
| for (size_t i = 0; i < inputs_num; ++i) { | |||
| inputs_size[i] = inputs[i]->Size(); | |||
| } | |||
| // here mnist only have one input data,just hard code to it's array; | |||
| inputs_binbuf[0] = mnist_inputs_data; | |||
| for (size_t i = 0; i < inputs_num; ++i) { | |||
| void *input_data = inputs[i]->MutableData(); | |||
| memcpy(input_data, inputs_binbuf[i], inputs_size[i]); | |||
| } | |||
| int ret = session->RunGraph(); | |||
| if (ret != lite::RET_OK) { | |||
| return lite::RET_ERROR; | |||
| } | |||
| Vector<String> outputs_name = session->GetOutputTensorNames(); | |||
| for (int i = 0; i < outputs_name.size(); ++i) { | |||
| tensor::MSTensor *output_tensor = session->GetOutputByTensorName(outputs_name[i]); | |||
| if (output_tensor == nullptr) { | |||
| return -1; | |||
| } | |||
| SEGGER_RTT_printf(0, "***********mnist test start5.2***********\n"); | |||
| float *casted_data = static_cast<float *>(output_tensor->MutableData()); | |||
| if (casted_data == nullptr) { | |||
| return -1; | |||
| } | |||
| SEGGER_RTT_printf(0, "***********mnist test start5.3***********\n"); | |||
| for (size_t j = 0; j < 10 && j < output_tensor->ElementsNum(); j++) { | |||
| SEGGER_RTT_printf(0, "output: [%d] is : [%d]/100\n", i, casted_data[i] * 100); | |||
| } | |||
| } | |||
| delete session; | |||
| SEGGER_RTT_printf(0, "***********mnist test end***********\n"); | |||
| /* USER CODE BEGIN 3 */ | |||
| } | |||
| /* USER CODE END 3 */ | |||
| } | |||
| /** | |||
| * @brief System Clock Configuration | |||
| * @retval None | |||
| */ | |||
| void SystemClock_Config(void) { | |||
| RCC_OscInitTypeDef RCC_OscInitStruct = {0}; | |||
| RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; | |||
| /** Configure the main internal regulator output voltage | |||
| */ | |||
| __HAL_RCC_PWR_CLK_ENABLE(); | |||
| __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3); | |||
| /** Initializes the RCC Oscillators according to the specified parameters | |||
| * in the RCC_OscInitTypeDef structure. | |||
| */ | |||
| RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | |||
| RCC_OscInitStruct.HSIState = RCC_HSI_ON; | |||
| RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; | |||
| RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; | |||
| if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { | |||
| Error_Handler(); | |||
| } | |||
| /** Initializes the CPU, AHB and APB buses clocks | |||
| */ | |||
| RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | |||
| | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | |||
| RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; | |||
| RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |||
| RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; | |||
| RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | |||
| if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { | |||
| Error_Handler(); | |||
| } | |||
| } | |||
| /* USER CODE BEGIN 4 */ | |||
| /* USER CODE END 4 */ | |||
| /** | |||
| * @brief This function is executed in case of error occurrence. | |||
| * @retval None | |||
| */ | |||
| void Error_Handler(void) { | |||
| /* USER CODE BEGIN Error_Handler_Debug */ | |||
| /* User can add his own implementation to report the HAL error return state */ | |||
| __disable_irq(); | |||
| while (1) { | |||
| } | |||
| /* USER CODE END Error_Handler_Debug */ | |||
| } | |||
| #ifdef USE_FULL_ASSERT | |||
| /** | |||
| * @brief Reports the name of the source file and the source line number | |||
| * where the assert_param error has occurred. | |||
| * @param file: pointer to the source file name | |||
| * @param line: assert_param error line source number | |||
| * @retval None | |||
| */ | |||
| void assert_failed(uint8_t *file, uint32_t line) { | |||
| /* USER CODE BEGIN 6 */ | |||
| /* User can add his own implementation to report the file name and line number, | |||
| ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |||
| /* USER CODE END 6 */ | |||
| } | |||
| #endif /* USE_FULL_ASSERT */ | |||
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |||
| @@ -0,0 +1,174 @@ | |||
| # Arm Cortex-M编译部署 | |||
| `Linux` `Cortex-M` `IOT` `C/C++` `全流程` `模型编译` `模型代码生成` `模型部署` `推理应用` `初级` `中级` `高级` | |||
| <!-- TOC --> | |||
| - Arm Cortex-M编译部署 | |||
| - [STM32F746编译依赖](#STM32F746编译依赖) | |||
| - [STM32F746构建](#STM32F746构建) | |||
| - [STM32F746工程部署](#STM32F746工程部署) | |||
| - [更多详情](#更多详情) | |||
| - [Linux x86_64平台编译部署](#Linux x86_64平台编译部署) | |||
| - [Android平台编译部署](#STM32746平台编译部署) | |||
| <!-- /TOC --> | |||
| ## Arm Cortex-M编译部署 | |||
| 本教程以在STM32F746单板上编译部署生成模型代码为例,演示了codegen编译模型在Cortex-M平台的使用。更多关于Arm Cortex-M的详情可参见其[官网](https://developer.arm.com/ip-products/processors/cortex-m)。 | |||
| ### STM32F746编译依赖 | |||
| 模型推理代码的编译部署需要在windows上安装[Jlink]((https://www.segger.com/))、[STM32CubeMX](https://www.st.com/content/st_com/en.html)、[gcc-arm-none-ebai](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm)等工具来进行交叉编译。 | |||
| - [STM32CubeMX-Win](https://www.st.com/content/ccc/resource/technical/software/sw_development_suite/group0/0b/05/f0/25/c7/2b/42/9d/stm32cubemx_v6-1-1/files/stm32cubemx_v6-1-1.zip/jcr:content/translations/en.stm32cubemx_v6-1-1.zip) >= 6.0.1 | |||
| - [gcc-arm-none-eabi](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) >= 9-2019-q4-major-win32 | |||
| - [JLink-windows](https://www.segger.com/downloads/jlink/) >= 6.56 | |||
| - [GCC](https://gcc.gnu.org/releases.html) >= 7.3.0 | |||
| - [CMake](https://cmake.org/download/) >= 3.18.3 | |||
| ### STM32F746构建与运行 | |||
| 首先使用codegen编译LeNet模型,生成对应的STM32F46推理代码。具体命令如下: | |||
| ```bash | |||
| ./codegen --codePath=. --modelPath=LeNet.ms --moduleName=LeNet --target=ARM32M | |||
| ``` | |||
| #### 代码工程说明 | |||
| ```bash | |||
| ├── LeNet | |||
| └── operator_library | |||
| ``` | |||
| ##### 算子静态库目录说明 | |||
| 在编译此工程之前需要预先获取Cortex-M 平台对应的[算子库]()。 | |||
| 预置算子静态库的目录如下: | |||
| ```bash | |||
| ├── operator_library # 对应平台算子库目录 | |||
| ├── include # 对应平台算子库头文件目录 | |||
| └── lib # 对应平台算子库静态库目录 | |||
| ``` | |||
| 生成代码工程目录如下: | |||
| ```bash | |||
| ├── LeNet # 生成代码的根目录 | |||
| ├── benchmark # 生成代码的benchmark目录 | |||
| ├── include # 模型推理代码对外暴露头文件目录 | |||
| └── src # 模型推理代码目录 | |||
| ``` | |||
| #### 代码工程编译 | |||
| ##### 环境测试 | |||
| 安装好交叉编译所需环境后,需要在windows环境中依次将其加入到环境变量中 | |||
| ```bash | |||
| gcc -v # 查看GCC版本 | |||
| arm-none-eabi-gdb -v # 查看交叉编译环境 | |||
| jlink -v # 查看jlink版本 | |||
| make -v # 查看make版本 | |||
| ``` | |||
| 以上的命令均有成功返回值时,表明环境准备ok,可以继续进入下一步,否则先安装上述环境!!! | |||
| ##### 生成STM32F746单板初始化代码([详情示例代码]()) | |||
| 1. 启动 STM32CubeMX,新建project,选择单板STM32F746IG | |||
| 2. 成功以后,选择`Makefile` ,`generator code` | |||
| 3. 在生成的工程目录下打开`cmd`,执行`make`,测试初始代码是否成功编译。 | |||
| ```bash | |||
| # make成功结果 | |||
| arm-none-eabi-size build/test_stm32f746.elf | |||
| text data bss dec hex filename | |||
| 3660 20 1572 5252 1484 build/test_stm32f746.elf | |||
| arm-none-eabi-objcopy -O ihex build/test_stm32f746.elf build/test_stm32f746.hex | |||
| arm-none-eabi-objcopy -O binary -S build/test_stm32f746.elf build/test_stm32f746.bin | |||
| ``` | |||
| ##### 编译生成模型静态库 | |||
| 1. 拷贝mindspore团队提供的cortex-m7的算子静态库以及对应头文件到STM32CubeMX生成的工程目录中。 | |||
| 2. 拷贝codegen生成模型推理代码到 STM32CubeMX生成的代码工程目录中 | |||
| ```bash | |||
| ├── .mxproject | |||
| └── build # 工程编译目录最终的elf文件存在于此 | |||
| └── Core | |||
| └── Drivers | |||
| └── LeNet # codegen生成的cortex-m7 模型推理代码 | |||
| └── Makefile # 组织工程makefile文件需要用户自己修改组织lenet && operator_library到工程目录中 | |||
| └── operator_library # mindspore团队提供的对应平台算子库 | |||
| └── startup_stm32f746xx.s | |||
| └── STM32F746IGKx_FLASH.ld | |||
| └── test_stm32f746.ioc | |||
| ``` | |||
| 3. 修改makefile文件,组织算子静态库以及模型推理代码 | |||
| ```bash | |||
| # C includes | |||
| C_INCLUDES = \ | |||
| -ICore/Inc \ | |||
| -IDrivers/STM32F7xx_HAL_Driver/Inc \ | |||
| -IDrivers/STM32F7xx_HAL_Driver/Inc/Legacy \ | |||
| -IDrivers/CMSIS/Device/ST/STM32F7xx/Include \ | |||
| -Ioperator_library/include \ # 新增,指定算子库头文件目录 | |||
| -ILeNet/include \ # 新增,指定模型推理代码头文件 | |||
| -ILeNet/src # 新增,指定模型推理代码头文件 | |||
| # libraries | |||
| LIBS = -lc -lm -lnosys -lops # 修改,导入mindspore团队提供算子库 | |||
| LIBDIR = -Ioperator_library/lib/arm32m # 新增,指定算子库所在路径 | |||
| ``` | |||
| 4. 在工程目录的Core/Src的main.c编写模型调用代码,具体代码新增如下: | |||
| ```cpp | |||
| ``` | |||
| 5. 在工程跟目中目录使用管理员权限打开`cmd` 执行 `make`进行编译 | |||
| ```bash | |||
| make | |||
| ``` | |||
| ### STM32F746工程部署 | |||
| 使用jlink 将可执行文件拷贝到单板上并做推理 | |||
| ```bash | |||
| jlinkgdbserver # 启动jlinkgdbserver 选定target device为STM32F746IG | |||
| jlinkRTTViewer # 启动jlinkRTTViewer 选定target devices为STM32F746IG | |||
| arm-none-eabi-gdb # 启动arm-gcc gdb服务 | |||
| file build/target.elf # 打开调测文件 | |||
| target remote 127.0.0.1 # 连接jlink服务器 | |||
| monitor reset # 重置单板 | |||
| monitor halt # 挂起单板 | |||
| load # 加载可执行文件到单板 | |||
| c # 执行模型推理 | |||
| ``` | |||
| #### 执行结果 | |||
| ```bash | |||
| ``` | |||
| ## 更多详情 | |||
| ### [Linux x86_64平台编译部署]() | |||
| ### [Android平台编译部署]() | |||
| @@ -0,0 +1,59 @@ | |||
| cmake_minimum_required(VERSION 3.14) | |||
| project(benchmark) | |||
| if(NOT DEFINED PKG_PATH) | |||
| message(FATAL_ERROR "PKG_PATH not set") | |||
| endif() | |||
| get_filename_component(PKG_PATH ${PKG_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) | |||
| set(HEADER_PATH ${PKG_PATH}/inference) | |||
| option(MICRO_BUILD_ARM64 "build android arm64" OFF) | |||
| option(MICRO_BUILD_ARM32A "build android arm32" OFF) | |||
| add_compile_definitions(NOT_USE_STL) | |||
| if(MICRO_BUILD_ARM64 OR MICRO_BUILD_ARM32A) | |||
| add_compile_definitions(ENABLE_NEON) | |||
| add_compile_definitions(ENABLE_ARM) | |||
| endif() | |||
| if(MICRO_BUILD_ARM64) | |||
| add_compile_definitions(ENABLE_ARM64) | |||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+dotprod") | |||
| endif() | |||
| if(MICRO_BUILD_ARM32A) | |||
| add_compile_definitions(ENABLE_ARM32) | |||
| add_definitions(-mfloat-abi=softfp -mfpu=neon) | |||
| endif() | |||
| set(CMAKE_C_FLAGS "${CMAKE_ENABLE_C99} ${CMAKE_C_FLAGS}") | |||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") | |||
| if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") | |||
| message(STATUS "build benchmark with debug info") | |||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDebug -g") | |||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDebug -g") | |||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default") | |||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default") | |||
| else() | |||
| set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \ | |||
| -Wno-deprecated-declarations -Wno-missing-braces ${CMAKE_C_FLAGS}") | |||
| set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror -fstack-protector-strong -Wno-attributes \ | |||
| -Wno-deprecated-declarations -Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}") | |||
| endif() | |||
| add_subdirectory(src) | |||
| include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | |||
| include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/) | |||
| include_directories(${HEADER_PATH}) | |||
| set(SRC_FILES | |||
| benchmark/benchmark.cc | |||
| benchmark/load_input.c | |||
| ) | |||
| add_executable(benchmark ${SRC_FILES}) | |||
| target_link_libraries(benchmark net -lm -pthread) | |||
| @@ -0,0 +1,65 @@ | |||
| cmake_minimum_required(VERSION 3.14) | |||
| project(benchmark) | |||
| if(NOT DEFINED MODEL_LIB) | |||
| message(FATAL_ERROR "MODEL_LIB not set") | |||
| endif() | |||
| if(NOT DEFINED HEADER_PATH) | |||
| message(FATAL_ERROR "HEADER_PATH not set") | |||
| endif() | |||
| get_filename_component(MODEL_LIB ${MODEL_LIB} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) | |||
| get_filename_component(HEADER_PATH ${HEADER_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}) | |||
| function(parse_lib_info lib_full_path lib_name lib_path) | |||
| string(FIND "${lib_full_path}" "/" POS REVERSE) | |||
| math(EXPR POS "${POS} + 1") | |||
| string(SUBSTRING ${lib_full_path} 0 ${POS} path) | |||
| set(${lib_path} ${path} PARENT_SCOPE) | |||
| string(SUBSTRING ${lib_full_path} "${POS}" "-1" name) | |||
| set(${lib_name} ${name} PARENT_SCOPE) | |||
| endfunction(parse_lib_info) | |||
| parse_lib_info(${MODEL_LIB} MODEL_LIB_NAME MODEL_LIB_PATH) | |||
| message("project name: ${MODEL_LIB_NAME}") | |||
| option(MICRO_BUILD_ARM64 "build android arm64" OFF) | |||
| option(MICRO_BUILD_ARM32A "build android arm32" OFF) | |||
| if(MICRO_BUILD_ARM64 OR MICRO_BUILD_ARM32A) | |||
| add_compile_definitions(ENABLE_NEON) | |||
| add_compile_definitions(ENABLE_ARM) | |||
| endif() | |||
| if(MICRO_BUILD_ARM64) | |||
| add_compile_definitions(ENABLE_ARM64) | |||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+dotprod") | |||
| endif() | |||
| if(MICRO_BUILD_ARM32A) | |||
| add_compile_definitions(ENABLE_ARM32) | |||
| add_definitions(-mfloat-abi=softfp -mfpu=neon) | |||
| endif() | |||
| set(CMAKE_C_FLAGS "${CMAKE_ENABLE_C99} ${CMAKE_C_FLAGS}") | |||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") | |||
| if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") | |||
| message(STATUS "build benchmark with debug info") | |||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDebug -g") | |||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDebug -g") | |||
| set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default") | |||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default") | |||
| else() | |||
| set(CMAKE_C_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O3 -Wall -Werror -fstack-protector-strong -Wno-attributes \ | |||
| -Wno-deprecated-declarations -Wno-missing-braces ${CMAKE_C_FLAGS}") | |||
| set(CMAKE_CXX_FLAGS "-fPIC -fPIE -D_FORTIFY_SOURCE=2 -O3 -Wall -Werror -fstack-protector-strong -Wno-attributes \ | |||
| -Wno-deprecated-declarations -Wno-missing-braces -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}") | |||
| endif() | |||
| link_directories(${MODEL_LIB_PATH}) | |||
| include(benchmark.cmake) | |||
| add_executable(benchmark ${SRC_FILES}) | |||
| target_link_libraries(benchmark ${MODEL_LIB_NAME} -lm -pthread) | |||
| @@ -0,0 +1,136 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include <iostream> | |||
| #include <string> | |||
| #include <cstring> | |||
| #include "include/lite_session.h" | |||
| #include "include/ms_tensor.h" | |||
| #include "include/errorcode.h" | |||
| #include "load_input.h" | |||
| using namespace mindspore; | |||
| void usage() { | |||
| printf( | |||
| "-- mindspore benchmark params usage:\n" | |||
| "args[0]: executable file\n" | |||
| "args[1]: inputs binary file\n" | |||
| "args[2]: model weight binary file\n" | |||
| "args[3]: loop count for performance test\n" | |||
| "args[4]: runtime thread num\n" | |||
| "args[5]: runtime thread bind mode\n\n"); | |||
| } | |||
| template <typename T> | |||
| void PrintData(void *data, size_t data_number) { | |||
| if (data == nullptr) { | |||
| return; | |||
| } | |||
| auto casted_data = static_cast<T *>(data); | |||
| for (size_t i = 0; i < 10 && i < data_number; i++) { | |||
| std::cout << std::to_string(casted_data[i]) << ", "; | |||
| } | |||
| std::cout << std::endl; | |||
| } | |||
| void TensorToString(tensor::MSTensor *tensor) { | |||
| std::cout << ", DataType: " << tensor->data_type(); | |||
| std::cout << ", Size: " << tensor->Size(); | |||
| std::cout << ", Shape:"; | |||
| for (auto &dim : tensor->shape()) { | |||
| std::cout << " " << dim; | |||
| } | |||
| std::cout << ", Data:" << std::endl; | |||
| switch (tensor->data_type()) { | |||
| case kNumberTypeFloat32: { | |||
| PrintData<float>(tensor->MutableData(), tensor->ElementsNum()); | |||
| } break; | |||
| case kNumberTypeFloat16: { | |||
| PrintData<int16_t>(tensor->MutableData(), tensor->ElementsNum()); | |||
| } break; | |||
| case kNumberTypeInt32: { | |||
| PrintData<int32_t>(tensor->MutableData(), tensor->ElementsNum()); | |||
| } break; | |||
| case kNumberTypeInt16: { | |||
| PrintData<int16_t>(tensor->MutableData(), tensor->ElementsNum()); | |||
| } break; | |||
| case kNumberTypeInt8: { | |||
| PrintData<int8_t>(tensor->MutableData(), tensor->ElementsNum()); | |||
| } break; | |||
| case kNumberTypeUInt8: { | |||
| PrintData<uint8_t>(tensor->MutableData(), tensor->ElementsNum()); | |||
| } break; | |||
| default: | |||
| std::cout << "Unsupported data type to print" << std::endl; | |||
| break; | |||
| } | |||
| } | |||
| int main(int argc, const char **argv) { | |||
| if (argc < 2) { | |||
| std::cout << "input command is invalid\n" << std::endl; | |||
| usage(); | |||
| return lite::RET_ERROR; | |||
| } | |||
| std::cout << "start run benchmark" << std::endl; | |||
| const char *model_buffer = nullptr; | |||
| int model_size = 0; | |||
| // read .bin file by ReadBinaryFile; | |||
| if (argc >= 3) { | |||
| model_buffer = static_cast<const char *>(ReadInputData(argv[2], &model_size)); | |||
| } | |||
| session::LiteSession *session = mindspore::session::LiteSession::CreateSession(model_buffer, model_size, nullptr); | |||
| if (session == nullptr) { | |||
| std::cerr << "create lite session failed" << std::endl; | |||
| return lite::RET_ERROR; | |||
| } | |||
| // set model inputs tensor data | |||
| Vector<tensor::MSTensor *> inputs = session->GetInputs(); | |||
| size_t inputs_num = inputs.size(); | |||
| void *inputs_binbuf[inputs_num]; | |||
| int inputs_size[inputs_num]; | |||
| for (size_t i = 0; i < inputs_num; ++i) { | |||
| inputs_size[i] = inputs[i]->Size(); | |||
| } | |||
| int ret = ReadInputsFile(const_cast<char *>(argv[1]), inputs_binbuf, inputs_size, inputs_num); | |||
| if (ret != lite::RET_OK) { | |||
| return lite::RET_ERROR; | |||
| } | |||
| for (size_t i = 0; i < inputs_num; ++i) { | |||
| void *input_data = inputs[i]->MutableData(); | |||
| memcpy(input_data, inputs_binbuf[i], inputs_size[i]); | |||
| } | |||
| ret = session->RunGraph(); | |||
| if (ret != lite::RET_OK) { | |||
| return lite::RET_ERROR; | |||
| } | |||
| std::cout << "run benchmark success" << std::endl; | |||
| delete session; | |||
| for (size_t i = 0; i < inputs_num; ++i) { | |||
| free(inputs_binbuf[i]); | |||
| } | |||
| return lite::RET_OK; | |||
| } | |||
| @@ -0,0 +1,7 @@ | |||
| include_directories(${CMAKE_CURRENT_SOURCE_DIR}) | |||
| include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/) | |||
| include_directories(${HEADER_PATH}) | |||
| set(SRC_FILES | |||
| benchmark.cc | |||
| load_input.c | |||
| ) | |||
| @@ -0,0 +1,95 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "load_input.h" | |||
| #include <stdlib.h> | |||
| #include <stdio.h> | |||
| #include <string.h> | |||
| void *ReadInputData(const char *real_input_path, int *size) { | |||
| if (real_input_path == NULL) { | |||
| return NULL; | |||
| } | |||
| if (strstr(real_input_path, ".bin") || strstr(real_input_path, ".net")) { | |||
| FILE *file; | |||
| file = fopen(real_input_path, "rb+"); | |||
| if (!file) { | |||
| printf("Can't find %s\n", real_input_path); | |||
| return NULL; | |||
| } | |||
| int curr_file_posi = ftell(file); | |||
| fseek(file, 0, SEEK_END); | |||
| *size = ftell(file); | |||
| unsigned char *buf = malloc((*size)); | |||
| (void)memset(buf, 0, (*size)); | |||
| fseek(file, curr_file_posi, SEEK_SET); | |||
| int read_size = (int)(fread(buf, 1, *size, file)); | |||
| if (read_size != (*size)) { | |||
| printf("read file failed, total file size: %d, read_size: %d\n", (*size), read_size); | |||
| fclose(file); | |||
| free(buf); | |||
| return NULL; | |||
| } | |||
| fclose(file); | |||
| return (void *)buf; | |||
| } else { | |||
| printf("input data file should be .bin , .net"); | |||
| return NULL; | |||
| } | |||
| } | |||
| void SaveOutputData(char *final_name, unsigned char *output_data, unsigned int out_size) { | |||
| FILE *output_file; | |||
| output_file = fopen(final_name, "w"); | |||
| if (output_file == NULL) { | |||
| printf("fopen output file: %s failed\n", final_name); | |||
| return; | |||
| } | |||
| unsigned char str[out_size]; | |||
| for (unsigned int i = 0; i < out_size; ++i) { | |||
| str[i] = output_data[i]; | |||
| fprintf(output_file, "%d\t", str[i]); | |||
| } | |||
| fclose(output_file); | |||
| } | |||
| int ReadInputsFile(char *path, void **buffers, const int *inputs_size, int inputs_num) { | |||
| char *inputs_path[inputs_num]; | |||
| char *delim = ","; | |||
| char *token; | |||
| int i = 0; | |||
| while ((token = strtok_r(path, delim, &path))) { | |||
| if (i >= inputs_num) { | |||
| printf("inputs num is error, need: %d\n", inputs_num); | |||
| return -1; | |||
| } | |||
| inputs_path[i] = token; | |||
| printf("input %d: %s\n", i, inputs_path[i]); | |||
| i++; | |||
| } | |||
| for (i = 0; i < inputs_num; ++i) { | |||
| int size = 0; | |||
| buffers[i] = ReadInputData(inputs_path[i], &size); | |||
| if (size != inputs_size[i] || buffers[i] == NULL) { | |||
| printf("size mismatch, %s, input: %d, needed: %d\n", inputs_path[i], size, inputs_size[i]); | |||
| return -1; | |||
| } | |||
| } | |||
| return 0; | |||
| } | |||
| @@ -0,0 +1,36 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_ | |||
| #define MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_ | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void *ReadInputData(const char *real_input_path, int *size); | |||
| void SaveOutputData(char *final_name, unsigned char *output_data, unsigned int out_size); | |||
| int ReadInputsFile(char *path, void **buffers, const int *inputs_size, int inputs_num); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MICRO_EXAMPLE_LOAD_INPUT_LOAD_INPUT_H_ | |||
| @@ -0,0 +1,133 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_CELL_H | |||
| #define MINDSPORE_INCLUDE_API_CELL_H | |||
| #include <string> | |||
| #include <vector> | |||
| #include <map> | |||
| #include <memory> | |||
| #include "include/api/status.h" | |||
| #include "include/api/types.h" | |||
| #include "include/api/graph.h" | |||
| namespace mindspore { | |||
| class InputAndOutput; | |||
| using Input = InputAndOutput; | |||
| using Output = InputAndOutput; | |||
| class MS_API CellBase { | |||
| public: | |||
| CellBase() = default; | |||
| virtual ~CellBase() = default; | |||
| virtual std::vector<Output> Construct(const std::vector<Input> &inputs) { return {}; } | |||
| virtual std::shared_ptr<CellBase> Clone() const = 0; | |||
| virtual Status Run(const std::vector<MSTensor> &inputs, std::vector<MSTensor> *outputs) { return kSuccess; } | |||
| std::vector<Output> operator()(const std::vector<Input> &inputs) const; | |||
| }; | |||
| template <class T> | |||
| class MS_API Cell : public CellBase { | |||
| public: | |||
| virtual ~Cell() = default; | |||
| std::shared_ptr<CellBase> Clone() const override { return std::make_shared<T>(static_cast<const T &>(*this)); } | |||
| }; | |||
| class MS_API ParameterCell final : public Cell<ParameterCell> { | |||
| public: | |||
| ParameterCell() = default; | |||
| ~ParameterCell() override = default; | |||
| ParameterCell(const ParameterCell &); | |||
| ParameterCell &operator=(const ParameterCell &); | |||
| ParameterCell(ParameterCell &&); | |||
| ParameterCell &operator=(ParameterCell &&); | |||
| explicit ParameterCell(const MSTensor &); | |||
| ParameterCell &operator=(const MSTensor &); | |||
| explicit ParameterCell(MSTensor &&); | |||
| ParameterCell &operator=(MSTensor &&); | |||
| MSTensor GetTensor() const { return tensor_; } | |||
| private: | |||
| MSTensor tensor_; | |||
| }; | |||
| class MS_API OpCellBase : public CellBase { | |||
| public: | |||
| explicit OpCellBase(const std::string &name) : name_(name) {} | |||
| ~OpCellBase() override = default; | |||
| const std::string &GetOpType() const { return name_; } | |||
| protected: | |||
| std::string name_; | |||
| }; | |||
| template <class T> | |||
| class MS_API OpCell : public OpCellBase, public std::enable_shared_from_this<T> { | |||
| public: | |||
| explicit OpCell(const std::string &name) : OpCellBase(name) {} | |||
| ~OpCell() override = default; | |||
| std::shared_ptr<CellBase> Clone() const override { return std::make_shared<T>(static_cast<const T &>(*this)); } | |||
| }; | |||
| class MS_API GraphCell final : public Cell<GraphCell> { | |||
| public: | |||
| class GraphImpl; | |||
| GraphCell() = default; | |||
| ~GraphCell() override = default; | |||
| explicit GraphCell(const Graph &); | |||
| explicit GraphCell(Graph &&); | |||
| explicit GraphCell(const std::shared_ptr<Graph> &); | |||
| const std::shared_ptr<Graph> &GetGraph() const { return graph_; } | |||
| Status Run(const std::vector<MSTensor> &inputs, std::vector<MSTensor> *outputs) override; | |||
| std::vector<MSTensor> GetInputs(); | |||
| std::vector<MSTensor> GetOutputs(); | |||
| private: | |||
| friend class ModelImpl; | |||
| Status Load(); | |||
| std::shared_ptr<Graph> graph_; | |||
| std::shared_ptr<GraphImpl> executor_; | |||
| }; | |||
| class MS_API InputAndOutput { | |||
| public: | |||
| InputAndOutput(); | |||
| ~InputAndOutput() = default; | |||
| // no explicit | |||
| InputAndOutput(const MSTensor &); // NOLINT(runtime/explicit) | |||
| InputAndOutput(MSTensor &&); // NOLINT(runtime/explicit) | |||
| InputAndOutput(const std::shared_ptr<CellBase> &, const std::vector<InputAndOutput> &, int32_t index); | |||
| int32_t GetIndex() const { return index_; } | |||
| void SetIndex(int32_t index) { index_ = index; } | |||
| private: | |||
| std::shared_ptr<CellBase> cell_; | |||
| std::vector<InputAndOutput> prev_; | |||
| int32_t index_; | |||
| }; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_CELL_H | |||
| @@ -0,0 +1,185 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_CONTEXT_H | |||
| #define MINDSPORE_INCLUDE_API_CONTEXT_H | |||
| #include <string> | |||
| #include <memory> | |||
| #include <vector> | |||
| #include <map> | |||
| #include "include/api/types.h" | |||
| #include "include/api/dual_abi_helper.h" | |||
| namespace mindspore { | |||
| constexpr auto kDeviceTypeAscend310 = "Ascend310"; | |||
| constexpr auto kDeviceTypeAscend910 = "Ascend910"; | |||
| constexpr auto kDeviceTypeGPU = "GPU"; | |||
| struct MS_API Context { | |||
| public: | |||
| Context(); | |||
| virtual ~Context() = default; | |||
| struct Data; | |||
| std::shared_ptr<Data> data; | |||
| }; | |||
| struct MS_API GlobalContext : public Context { | |||
| public: | |||
| static std::shared_ptr<Context> GetGlobalContext(); | |||
| static inline void SetGlobalDeviceTarget(const std::string &device_target); | |||
| static inline std::string GetGlobalDeviceTarget(); | |||
| static void SetGlobalDeviceID(const uint32_t &device_id); | |||
| static uint32_t GetGlobalDeviceID(); | |||
| static inline void SetGlobalDumpConfigPath(const std::string &cfg_path); | |||
| static inline std::string GetGlobalDumpConfigPath(); | |||
| private: | |||
| // api without std::string | |||
| static void SetGlobalDeviceTarget(const std::vector<char> &device_target); | |||
| static std::vector<char> GetGlobalDeviceTargetChar(); | |||
| static void SetGlobalDumpConfigPath(const std::vector<char> &cfg_path); | |||
| static std::vector<char> GetGlobalDumpConfigPathChar(); | |||
| }; | |||
| struct MS_API ModelContext : public Context { | |||
| public: | |||
| static inline void SetInsertOpConfigPath(const std::shared_ptr<Context> &context, const std::string &cfg_path); | |||
| static inline std::string GetInsertOpConfigPath(const std::shared_ptr<Context> &context); | |||
| static inline void SetInputFormat(const std::shared_ptr<Context> &context, const std::string &format); | |||
| static inline std::string GetInputFormat(const std::shared_ptr<Context> &context); | |||
| static inline void SetInputShape(const std::shared_ptr<Context> &context, const std::string &shape); | |||
| static inline std::string GetInputShape(const std::shared_ptr<Context> &context); | |||
| static void SetInputShapeMap(const std::shared_ptr<Context> &context, const std::map<int, std::vector<int>> &shape); | |||
| static std::map<int, std::vector<int>> GetInputShapeMap(const std::shared_ptr<Context> &context); | |||
| static void SetDynamicBatchSize(const std::shared_ptr<Context> &context, | |||
| const std::vector<size_t> &dynamic_batch_size); | |||
| static inline std::string GetDynamicBatchSize(const std::shared_ptr<Context> &context); | |||
| static void SetOutputType(const std::shared_ptr<Context> &context, enum DataType output_type); | |||
| static enum DataType GetOutputType(const std::shared_ptr<Context> &context); | |||
| static inline void SetPrecisionMode(const std::shared_ptr<Context> &context, const std::string &precision_mode); | |||
| static inline std::string GetPrecisionMode(const std::shared_ptr<Context> &context); | |||
| static inline void SetOpSelectImplMode(const std::shared_ptr<Context> &context, | |||
| const std::string &op_select_impl_mode); | |||
| static inline std::string GetOpSelectImplMode(const std::shared_ptr<Context> &context); | |||
| static inline void SetFusionSwitchConfigPath(const std::shared_ptr<Context> &context, const std::string &cfg_path); | |||
| static inline std::string GetFusionSwitchConfigPath(const std::shared_ptr<Context> &context); | |||
| static inline void SetGpuTrtInferMode(const std::shared_ptr<Context> &context, const std::string &gpu_trt_infer_mode); | |||
| static inline std::string GetGpuTrtInferMode(const std::shared_ptr<Context> &context); | |||
| private: | |||
| // api without std::string | |||
| static void SetInsertOpConfigPath(const std::shared_ptr<Context> &context, const std::vector<char> &cfg_path); | |||
| static std::vector<char> GetInsertOpConfigPathChar(const std::shared_ptr<Context> &context); | |||
| static void SetInputFormat(const std::shared_ptr<Context> &context, const std::vector<char> &format); | |||
| static std::vector<char> GetInputFormatChar(const std::shared_ptr<Context> &context); | |||
| static void SetInputShape(const std::shared_ptr<Context> &context, const std::vector<char> &shape); | |||
| static std::vector<char> GetInputShapeChar(const std::shared_ptr<Context> &context); | |||
| static void SetPrecisionMode(const std::shared_ptr<Context> &context, const std::vector<char> &precision_mode); | |||
| static std::vector<char> GetPrecisionModeChar(const std::shared_ptr<Context> &context); | |||
| static void SetOpSelectImplMode(const std::shared_ptr<Context> &context, | |||
| const std::vector<char> &op_select_impl_mode); | |||
| static std::vector<char> GetOpSelectImplModeChar(const std::shared_ptr<Context> &context); | |||
| static void SetFusionSwitchConfigPath(const std::shared_ptr<Context> &context, const std::vector<char> &cfg_path); | |||
| static std::vector<char> GetFusionSwitchConfigPathChar(const std::shared_ptr<Context> &context); | |||
| static void SetGpuTrtInferMode(const std::shared_ptr<Context> &context, const std::vector<char> &gpu_trt_infer_mode); | |||
| static std::vector<char> GetGpuTrtInferModeChar(const std::shared_ptr<Context> &context); | |||
| static std::vector<char> GetDynamicBatchSizeChar(const std::shared_ptr<Context> &context); | |||
| }; | |||
| void GlobalContext::SetGlobalDeviceTarget(const std::string &device_target) { | |||
| SetGlobalDeviceTarget(StringToChar(device_target)); | |||
| } | |||
| std::string GlobalContext::GetGlobalDeviceTarget() { return CharToString(GetGlobalDeviceTargetChar()); } | |||
| void GlobalContext::SetGlobalDumpConfigPath(const std::string &cfg_path) { | |||
| SetGlobalDumpConfigPath(StringToChar(cfg_path)); | |||
| } | |||
| std::string GlobalContext::GetGlobalDumpConfigPath() { return CharToString(GetGlobalDumpConfigPathChar()); } | |||
| void ModelContext::SetInsertOpConfigPath(const std::shared_ptr<Context> &context, const std::string &cfg_path) { | |||
| SetInsertOpConfigPath(context, StringToChar(cfg_path)); | |||
| } | |||
| std::string ModelContext::GetInsertOpConfigPath(const std::shared_ptr<Context> &context) { | |||
| return CharToString(GetInsertOpConfigPathChar(context)); | |||
| } | |||
| void ModelContext::SetInputFormat(const std::shared_ptr<Context> &context, const std::string &format) { | |||
| SetInputFormat(context, StringToChar(format)); | |||
| } | |||
| std::string ModelContext::GetInputFormat(const std::shared_ptr<Context> &context) { | |||
| return CharToString(GetInputFormatChar(context)); | |||
| } | |||
| void ModelContext::SetInputShape(const std::shared_ptr<Context> &context, const std::string &shape) { | |||
| SetInputShape(context, StringToChar(shape)); | |||
| } | |||
| std::string ModelContext::GetInputShape(const std::shared_ptr<Context> &context) { | |||
| return CharToString(GetInputShapeChar(context)); | |||
| } | |||
| void ModelContext::SetPrecisionMode(const std::shared_ptr<Context> &context, const std::string &precision_mode) { | |||
| SetPrecisionMode(context, StringToChar(precision_mode)); | |||
| } | |||
| std::string ModelContext::GetPrecisionMode(const std::shared_ptr<Context> &context) { | |||
| return CharToString(GetPrecisionModeChar(context)); | |||
| } | |||
| void ModelContext::SetOpSelectImplMode(const std::shared_ptr<Context> &context, | |||
| const std::string &op_select_impl_mode) { | |||
| SetOpSelectImplMode(context, StringToChar(op_select_impl_mode)); | |||
| } | |||
| std::string ModelContext::GetOpSelectImplMode(const std::shared_ptr<Context> &context) { | |||
| return CharToString(GetOpSelectImplModeChar(context)); | |||
| } | |||
| void ModelContext::SetFusionSwitchConfigPath(const std::shared_ptr<Context> &context, const std::string &cfg_path) { | |||
| SetFusionSwitchConfigPath(context, StringToChar(cfg_path)); | |||
| } | |||
| std::string ModelContext::GetFusionSwitchConfigPath(const std::shared_ptr<Context> &context) { | |||
| return CharToString(GetFusionSwitchConfigPathChar(context)); | |||
| } | |||
| std::string ModelContext::GetDynamicBatchSize(const std::shared_ptr<Context> &context) { | |||
| return CharToString(GetDynamicBatchSizeChar(context)); | |||
| } | |||
| void ModelContext::SetGpuTrtInferMode(const std::shared_ptr<Context> &context, const std::string &gpu_trt_infer_mode) { | |||
| SetGpuTrtInferMode(context, StringToChar(gpu_trt_infer_mode)); | |||
| } | |||
| std::string ModelContext::GetGpuTrtInferMode(const std::shared_ptr<Context> &context) { | |||
| return CharToString(GetGpuTrtInferModeChar(context)); | |||
| } | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_CONTEXT_H | |||
| @@ -0,0 +1,43 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_DATA_TYPE_H_ | |||
| #define MINDSPORE_INCLUDE_API_DATA_TYPE_H_ | |||
| namespace mindspore { | |||
| enum class DataType : int { | |||
| kTypeUnknown = 0, | |||
| kObjectTypeString = 12, | |||
| kObjectTypeList = 13, | |||
| kObjectTypeTuple = 14, | |||
| kObjectTypeTensorType = 17, | |||
| kNumberTypeBool = 30, | |||
| kNumberTypeInt8 = 32, | |||
| kNumberTypeInt16 = 33, | |||
| kNumberTypeInt32 = 34, | |||
| kNumberTypeInt64 = 35, | |||
| kNumberTypeUInt8 = 37, | |||
| kNumberTypeUInt16 = 38, | |||
| kNumberTypeUInt32 = 39, | |||
| kNumberTypeUInt64 = 40, | |||
| kNumberTypeFloat16 = 42, | |||
| kNumberTypeFloat32 = 43, | |||
| kNumberTypeFloat64 = 44, | |||
| kNumberTypeEnd = 46, | |||
| // add new enum here | |||
| kInvalidType = INT32_MAX, | |||
| }; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_DATA_TYPE_H_ | |||
| @@ -0,0 +1,164 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_DUAL_ABI_HELPER_H_ | |||
| #define MINDSPORE_INCLUDE_API_DUAL_ABI_HELPER_H_ | |||
| #include <algorithm> | |||
| #include <map> | |||
| #include <memory> | |||
| #include <optional> | |||
| #include <string> | |||
| #include <set> | |||
| #include <unordered_map> | |||
| #include <utility> | |||
| #include <vector> | |||
| namespace mindspore { | |||
| inline std::vector<char> StringToChar(const std::string &s) { return std::vector<char>(s.begin(), s.end()); } | |||
| inline std::string CharToString(const std::vector<char> &c) { return std::string(c.begin(), c.end()); } | |||
| inline std::optional<std::vector<char>> OptionalStringToChar(const std::optional<std::string> &s) { | |||
| if (s == std::nullopt) return std::nullopt; | |||
| std::optional<std::vector<char>> ret = std::vector<char>(s->begin(), s->end()); | |||
| return ret; | |||
| } | |||
| inline std::optional<std::string> OptionalCharToString(const std::optional<std::vector<char>> &c) { | |||
| if (c == std::nullopt) return std::nullopt; | |||
| std::optional<std::string> ret = std::string(c->begin(), c->end()); | |||
| return ret; | |||
| } | |||
| inline std::pair<std::vector<char>, int32_t> PairStringToChar(const std::pair<std::string, int32_t> &s) { | |||
| return std::pair<std::vector<char>, int32_t>(std::vector<char>(s.first.begin(), s.first.end()), s.second); | |||
| } | |||
| inline std::pair<std::string, int32_t> PairCharToString(const std::pair<std::vector<char>, int32_t> &c) { | |||
| return std::pair<std::string, int32_t>(std::string(c.first.begin(), c.first.end()), c.second); | |||
| } | |||
| inline std::vector<std::vector<char>> VectorStringToChar(const std::vector<std::string> &s) { | |||
| std::vector<std::vector<char>> ret; | |||
| std::transform(s.begin(), s.end(), std::back_inserter(ret), | |||
| [](auto str) { return std::vector<char>(str.begin(), str.end()); }); | |||
| return ret; | |||
| } | |||
| inline std::vector<std::string> VectorCharToString(const std::vector<std::vector<char>> &c) { | |||
| std::vector<std::string> ret; | |||
| std::transform(c.begin(), c.end(), std::back_inserter(ret), | |||
| [](auto ch) { return std::string(ch.begin(), ch.end()); }); | |||
| return ret; | |||
| } | |||
| inline std::set<std::vector<char>> SetStringToChar(const std::set<std::string> &s) { | |||
| std::set<std::vector<char>> ret; | |||
| std::transform(s.begin(), s.end(), std::inserter(ret, ret.begin()), | |||
| [](auto str) { return std::vector<char>(str.begin(), str.end()); }); | |||
| return ret; | |||
| } | |||
| inline std::set<std::string> SetCharToString(const std::set<std::vector<char>> &c) { | |||
| std::set<std::string> ret; | |||
| std::transform(c.begin(), c.end(), std::inserter(ret, ret.begin()), | |||
| [](auto ch) { return std::string(ch.begin(), ch.end()); }); | |||
| return ret; | |||
| } | |||
| inline std::map<std::vector<char>, int32_t> MapStringToChar(const std::map<std::string, int32_t> &s) { | |||
| std::map<std::vector<char>, int32_t> ret; | |||
| std::transform(s.begin(), s.end(), std::inserter(ret, ret.begin()), [](auto str) { | |||
| return std::pair<std::vector<char>, int32_t>(std::vector<char>(str.first.begin(), str.first.end()), str.second); | |||
| }); | |||
| return ret; | |||
| } | |||
| inline std::map<std::string, int32_t> MapCharToString(const std::map<std::vector<char>, int32_t> &c) { | |||
| std::map<std::string, int32_t> ret; | |||
| std::transform(c.begin(), c.end(), std::inserter(ret, ret.begin()), [](auto ch) { | |||
| return std::pair<std::string, int32_t>(std::string(ch.first.begin(), ch.first.end()), ch.second); | |||
| }); | |||
| return ret; | |||
| } | |||
| inline std::map<std::vector<char>, std::vector<char>> UnorderedMapStringToChar( | |||
| const std::unordered_map<std::string, std::string> &s) { | |||
| std::map<std::vector<char>, std::vector<char>> ret; | |||
| std::transform(s.begin(), s.end(), std::inserter(ret, ret.begin()), [](auto str) { | |||
| return std::pair<std::vector<char>, std::vector<char>>(std::vector<char>(str.first.begin(), str.first.end()), | |||
| std::vector<char>(str.second.begin(), str.second.end())); | |||
| }); | |||
| return ret; | |||
| } | |||
| inline std::unordered_map<std::string, std::string> UnorderedMapCharToString( | |||
| const std::map<std::vector<char>, std::vector<char>> &c) { | |||
| std::unordered_map<std::string, std::string> ret; | |||
| std::transform(c.begin(), c.end(), std::inserter(ret, ret.begin()), [](auto ch) { | |||
| return std::pair<std::string, std::string>(std::string(ch.first.begin(), ch.first.end()), | |||
| std::string(ch.second.begin(), ch.second.end())); | |||
| }); | |||
| return ret; | |||
| } | |||
| inline std::vector<std::pair<std::vector<char>, std::vector<int32_t>>> ClassIndexStringToChar( | |||
| const std::vector<std::pair<std::string, std::vector<int32_t>>> &s) { | |||
| std::vector<std::pair<std::vector<char>, std::vector<int32_t>>> ret; | |||
| std::transform(s.begin(), s.end(), std::back_inserter(ret), [](auto str) { | |||
| return std::pair<std::vector<char>, std::vector<int32_t>>(std::vector<char>(str.first.begin(), str.first.end()), | |||
| str.second); | |||
| }); | |||
| return ret; | |||
| } | |||
| inline std::vector<std::pair<std::string, std::vector<int32_t>>> ClassIndexCharToString( | |||
| const std::vector<std::pair<std::vector<char>, std::vector<int32_t>>> &c) { | |||
| std::vector<std::pair<std::string, std::vector<int32_t>>> ret; | |||
| std::transform(c.begin(), c.end(), std::back_inserter(ret), [](auto ch) { | |||
| return std::pair<std::string, std::vector<int32_t>>(std::string(ch.first.begin(), ch.first.end()), ch.second); | |||
| }); | |||
| return ret; | |||
| } | |||
| template <class T> | |||
| inline std::map<std::vector<char>, T> PadInfoStringToChar(const std::map<std::string, T> &s_pad_info) { | |||
| std::map<std::vector<char>, T> ret; | |||
| std::transform(s_pad_info.begin(), s_pad_info.end(), std::inserter(ret, ret.begin()), [](auto str) { | |||
| return std::pair<std::vector<char>, T>(std::vector<char>(str.first.begin(), str.first.end()), str.second); | |||
| }); | |||
| return ret; | |||
| } | |||
| template <class T> | |||
| inline std::map<std::string, T> PadInfoCharToString(const std::map<std::vector<char>, T> &c_pad_info) { | |||
| std::map<std::string, T> ret; | |||
| std::transform(c_pad_info.begin(), c_pad_info.end(), std::inserter(ret, ret.begin()), [](auto ch) { | |||
| return std::pair<std::string, T>(std::string(ch.first.begin(), ch.first.end()), ch.second); | |||
| }); | |||
| return ret; | |||
| } | |||
| template <class T> | |||
| inline void TensorMapCharToString(const std::map<std::vector<char>, T> *c, std::unordered_map<std::string, T> *s) { | |||
| for (auto ch : *c) { | |||
| auto key = std::string(ch.first.begin(), ch.first.end()); | |||
| auto val = ch.second; | |||
| s->insert(std::pair<std::string, T>(key, val)); | |||
| } | |||
| } | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_DUAL_ABI_HELPER_H_ | |||
| @@ -0,0 +1,44 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_GRAPH_H | |||
| #define MINDSPORE_INCLUDE_API_GRAPH_H | |||
| #include <cstddef> | |||
| #include <vector> | |||
| #include <map> | |||
| #include <memory> | |||
| #include "include/api/status.h" | |||
| #include "include/api/types.h" | |||
| namespace mindspore { | |||
| class MS_API Graph { | |||
| public: | |||
| class GraphData; | |||
| explicit Graph(const std::shared_ptr<GraphData> &graph_data); | |||
| explicit Graph(std::shared_ptr<GraphData> &&graph_data); | |||
| explicit Graph(std::nullptr_t); | |||
| ~Graph(); | |||
| enum ModelType ModelType() const; | |||
| bool operator==(std::nullptr_t) const; | |||
| private: | |||
| friend class GraphCell; | |||
| friend class ModelImpl; | |||
| std::shared_ptr<GraphData> graph_data_; | |||
| }; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_GRAPH_H | |||
| @@ -0,0 +1,71 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_LITE_CONTEXT_H | |||
| #define MINDSPORE_INCLUDE_API_LITE_CONTEXT_H | |||
| #include <string> | |||
| #include <memory> | |||
| #include <map> | |||
| #include <any> | |||
| #include "include/api/types.h" | |||
| #include "include/lite_types.h" | |||
| namespace mindspore { | |||
| namespace lite { | |||
| class Allocator; | |||
| } // namespace lite | |||
| struct MS_API Context { | |||
| public: | |||
| static void Clear(const std::shared_ptr<Context> &context); | |||
| static void SetAsDefault(const std::shared_ptr<Context> &context); | |||
| static void SetVendorName(const std::shared_ptr<Context> &context, const std::string &name); | |||
| static std::string GetVendorName(const std::shared_ptr<Context> &context); | |||
| static void SetThreadNum(const std::shared_ptr<Context> &context, int num); | |||
| static int GetThreadNum(const std::shared_ptr<Context> &context); | |||
| static void SetAllocator(const std::shared_ptr<Context> &context, std::shared_ptr<lite::Allocator> alloc); | |||
| static std::shared_ptr<lite::Allocator> GetAllocator(const std::shared_ptr<Context> &context); | |||
| static void ConfigCPU(const std::shared_ptr<Context> &context, bool config); | |||
| static bool IfCPUEnabled(const std::shared_ptr<Context> &context); | |||
| static void ConfigCPUFp16(const std::shared_ptr<Context> &context, bool config); | |||
| static bool IfCPUFp16Enabled(const std::shared_ptr<Context> &context); | |||
| static void SetCPUBindMode(const std::shared_ptr<Context> &context, lite::CpuBindMode mode); | |||
| static lite::CpuBindMode GetCPUBindMode(const std::shared_ptr<Context> &context); | |||
| static void ConfigGPU(const std::shared_ptr<Context> &context, bool config); | |||
| static bool IfGPUEnabled(const std::shared_ptr<Context> &context); | |||
| static void ConfigGPUFp16(const std::shared_ptr<Context> &context, bool config); | |||
| static bool IfGPUFp16Enabled(const std::shared_ptr<Context> &context); | |||
| static void ConfigNPU(const std::shared_ptr<Context> &context, bool config); | |||
| static bool IfNPUEnabled(const std::shared_ptr<Context> &context); | |||
| static void SetNPUFrequency(const std::shared_ptr<Context> &context, int freq); | |||
| static int GetNPUFrequency(const std::shared_ptr<Context> &context); | |||
| private: | |||
| std::map<std::string, std::any> context_; | |||
| }; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_LITE_CONTEXT_H | |||
| @@ -0,0 +1,62 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_MODEL_H | |||
| #define MINDSPORE_INCLUDE_API_MODEL_H | |||
| #include <string> | |||
| #include <vector> | |||
| #include <map> | |||
| #include <memory> | |||
| #include <utility> | |||
| #include "include/api/status.h" | |||
| #include "include/api/types.h" | |||
| #include "include/api/graph.h" | |||
| #include "include/api/cell.h" | |||
| #include "include/api/dual_abi_helper.h" | |||
| namespace mindspore { | |||
| class ModelImpl; | |||
| struct Context; | |||
| class MS_API Model { | |||
| public: | |||
| explicit Model(const std::vector<Output> &network, const std::shared_ptr<Context> &model_context = nullptr); | |||
| explicit Model(const GraphCell &graph, const std::shared_ptr<Context> &model_context = nullptr); | |||
| ~Model(); | |||
| Model(const Model &) = delete; | |||
| void operator=(const Model &) = delete; | |||
| Status Build(); | |||
| Status Resize(const std::vector<MSTensor> &inputs, const std::vector<std::vector<int64_t>> &dims); | |||
| Status Predict(const std::vector<MSTensor> &inputs, std::vector<MSTensor> *outputs); | |||
| std::vector<MSTensor> GetInputs(); | |||
| std::vector<MSTensor> GetOutputs(); | |||
| static inline bool CheckModelSupport(const std::string &device_type, ModelType model_type); | |||
| private: | |||
| // api without std::string | |||
| static bool CheckModelSupport(const std::vector<char> &device_type, ModelType model_type); | |||
| std::shared_ptr<ModelImpl> impl_; | |||
| }; | |||
| bool Model::CheckModelSupport(const std::string &device_type, ModelType model_type) { | |||
| return CheckModelSupport(StringToChar(device_type), model_type); | |||
| } | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_MODEL_H | |||
| @@ -0,0 +1,48 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_OPS_OPS_H | |||
| #define MINDSPORE_INCLUDE_API_OPS_OPS_H | |||
| #include <string> | |||
| #include <vector> | |||
| #include <map> | |||
| #include <memory> | |||
| #include "include/api/status.h" | |||
| #include "include/api/types.h" | |||
| #include "include/api/cell.h" | |||
| namespace mindspore { | |||
| struct MS_API Conv2D : public OpCell<Conv2D> { | |||
| Conv2D() : OpCell("Conv2D") {} | |||
| ~Conv2D() override = default; | |||
| std::vector<Output> Construct(const std::vector<Input> &inputs) override; | |||
| Conv2D(int out_channel, const std::vector<int> &kernel_size, int mode = 1, const std::string &pad_mode = "valid", | |||
| const std::vector<int> &pad = {0, 0, 0, 0}, const std::vector<int> &stride = {1, 1, 1, 1}, | |||
| const std::vector<int> &dilation = {1, 1, 1, 1}, int group = 1); | |||
| Output operator()(const Input &, const Input &) const; | |||
| int out_channel; | |||
| std::vector<int> kernel_size; | |||
| int mode = 1; | |||
| std::string pad_mode = "valid"; | |||
| std::vector<int> pad = {0, 0, 0, 0}; | |||
| std::vector<int> stride = {1, 1, 1, 1}; | |||
| std::vector<int> dilation = {1, 1, 1, 1}; | |||
| int group = 1; | |||
| }; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_OPS_OPS_H | |||
| @@ -0,0 +1,47 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_SERIALIZATION_H | |||
| #define MINDSPORE_INCLUDE_API_SERIALIZATION_H | |||
| #include <string> | |||
| #include <vector> | |||
| #include <map> | |||
| #include <memory> | |||
| #include "include/api/status.h" | |||
| #include "include/api/types.h" | |||
| #include "include/api/model.h" | |||
| #include "include/api/graph.h" | |||
| #include "include/api/dual_abi_helper.h" | |||
| namespace mindspore { | |||
| class MS_API Serialization { | |||
| public: | |||
| static Graph LoadModel(const void *model_data, size_t data_size, ModelType model_type); | |||
| inline static Graph LoadModel(const std::string &file, ModelType model_type); | |||
| static Status LoadCheckPoint(const std::string &ckpt_file, std::map<std::string, Buffer> *parameters); | |||
| static Status SetParameters(const std::map<std::string, Buffer> ¶meters, Model *model); | |||
| static Status ExportModel(const Model &model, ModelType model_type, Buffer *model_data); | |||
| static Status ExportModel(const Model &model, ModelType model_type, const std::string &model_file); | |||
| private: | |||
| static Graph LoadModel(const std::vector<char> &file, ModelType model_type); | |||
| }; | |||
| Graph Serialization::LoadModel(const std::string &file, ModelType model_type) { | |||
| return LoadModel(StringToChar(file), model_type); | |||
| } | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_SERIALIZATION_H | |||
| @@ -0,0 +1,164 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_STATUS_H | |||
| #define MINDSPORE_INCLUDE_API_STATUS_H | |||
| #include <memory> | |||
| #include <string> | |||
| #include <vector> | |||
| #include <ostream> | |||
| #include <climits> | |||
| #include "include/api/dual_abi_helper.h" | |||
| #include "include/api/types.h" | |||
| namespace mindspore { | |||
| enum CompCode : uint32_t { | |||
| kCore = 0x00000000u, | |||
| kMD = 0x10000000u, | |||
| kME = 0x20000000u, | |||
| kMC = 0x30000000u, | |||
| kLite = 0xF0000000u, | |||
| }; | |||
| enum StatusCode : uint32_t { | |||
| kSuccess = 0, | |||
| // Core | |||
| kCoreFailed = kCore | 0x1, | |||
| // MD | |||
| kMDOutOfMemory = kMD | 1, | |||
| kMDShapeMisMatch = kMD | 2, | |||
| kMDInterrupted = kMD | 3, | |||
| kMDNoSpace = kMD | 4, | |||
| kMDPyFuncException = kMD | 5, | |||
| kMDDuplicateKey = kMD | 6, | |||
| kMDPythonInterpreterFailure = kMD | 7, | |||
| kMDTDTPushFailure = kMD | 8, | |||
| kMDFileNotExist = kMD | 9, | |||
| kMDProfilingError = kMD | 10, | |||
| kMDBoundingBoxOutOfBounds = kMD | 11, | |||
| kMDBoundingBoxInvalidShape = kMD | 12, | |||
| kMDSyntaxError = kMD | 13, | |||
| kMDTimeOut = kMD | 14, | |||
| kMDBuddySpaceFull = kMD | 15, | |||
| kMDNetWorkError = kMD | 16, | |||
| kMDNotImplementedYet = kMD | 17, | |||
| // Make this error code the last one. Add new error code above it. | |||
| kMDUnexpectedError = kMD | 127, | |||
| // ME | |||
| kMEFailed = kME | 0x1, | |||
| kMEInvalidInput = kME | 0x2, | |||
| // MC | |||
| kMCFailed = kMC | 0x1, | |||
| kMCDeviceError = kMC | 0x2, | |||
| kMCInvalidInput = kMC | 0x3, | |||
| kMCInvalidArgs = kMC | 0x4, | |||
| // Lite // Common error code, range: [-1, -100) | |||
| kLiteError = kLite | (0x0FFFFFFF & -1), /**< Common error code. */ | |||
| kLiteNullptr = kLite | (0x0FFFFFFF & -2), /**< NULL pointer returned.*/ | |||
| kLiteParamInvalid = kLite | (0x0FFFFFFF & -3), /**< Invalid parameter.*/ | |||
| kLiteNoChange = kLite | (0x0FFFFFFF & -4), /**< No change. */ | |||
| kLiteSuccessExit = kLite | (0x0FFFFFFF & -5), /**< No error but exit. */ | |||
| kLiteMemoryFailed = kLite | (0x0FFFFFFF & -6), /**< Fail to create memory. */ | |||
| kLiteNotSupport = kLite | (0x0FFFFFFF & -7), /**< Fail to support. */ | |||
| kLiteThreadPoolError = kLite | (0x0FFFFFFF & -8), /**< Error occur in thread pool. */ | |||
| // Executor error code, range: [-100,-200) | |||
| kLiteOutOfTensorRange = kLite | (0x0FFFFFFF & -100), /**< Failed to check range. */ | |||
| kLiteInputTensorError = kLite | (0x0FFFFFFF & -101), /**< Failed to check input tensor. */ | |||
| kLiteReentrantError = kLite | (0x0FFFFFFF & -102), /**< Exist executor running. */ | |||
| // Graph error code, range: [-200,-300) | |||
| kLiteGraphFileError = kLite | (0x0FFFFFFF & -200), /**< Failed to verify graph file. */ | |||
| // Node error code, range: [-300,-400) | |||
| kLiteNotFindOp = kLite | (0x0FFFFFFF & -300), /**< Failed to find operator. */ | |||
| kLiteInvalidOpName = kLite | (0x0FFFFFFF & -301), /**< Invalid operator name. */ | |||
| kLiteInvalidOpAttr = kLite | (0x0FFFFFFF & -302), /**< Invalid operator attr. */ | |||
| kLiteOpExecuteFailure = kLite | (0x0FFFFFFF & -303), /**< Failed to execution operator. */ | |||
| // Tensor error code, range: [-400,-500) | |||
| kLiteFormatError = kLite | (0x0FFFFFFF & -400), /**< Failed to checking tensor format. */ | |||
| // InferShape error code, range: [-500,-600) | |||
| kLiteInferError = kLite | (0x0FFFFFFF & -500), /**< Failed to infer shape. */ | |||
| kLiteInferInvalid = kLite | (0x0FFFFFFF & -501), /**< Invalid infer shape before runtime. */ | |||
| // User input param error code, range: [-600, 700) | |||
| kLiteInputParamInvalid = kLite | (0x0FFFFFFF & -600), /**< Invalid input param by user. */ | |||
| }; | |||
| class MS_API Status { | |||
| public: | |||
| Status(); | |||
| inline Status(enum StatusCode status_code, const std::string &status_msg = ""); // NOLINT(runtime/explicit) | |||
| inline Status(const StatusCode code, int line_of_code, const char *file_name, const std::string &extra = ""); | |||
| ~Status() = default; | |||
| enum StatusCode StatusCode() const; | |||
| inline std::string ToString() const; | |||
| int GetLineOfCode() const; | |||
| inline std::string GetErrDescription() const; | |||
| inline std::string SetErrDescription(const std::string &err_description); | |||
| friend std::ostream &operator<<(std::ostream &os, const Status &s); | |||
| bool operator==(const Status &other) const; | |||
| bool operator==(enum StatusCode other_code) const; | |||
| bool operator!=(const Status &other) const; | |||
| bool operator!=(enum StatusCode other_code) const; | |||
| explicit operator bool() const; | |||
| explicit operator int() const; | |||
| static Status OK(); | |||
| bool IsOk() const; | |||
| bool IsError() const; | |||
| static inline std::string CodeAsString(enum StatusCode c); | |||
| private: | |||
| // api without std::string | |||
| explicit Status(enum StatusCode status_code, const std::vector<char> &status_msg); | |||
| Status(const enum StatusCode code, int line_of_code, const char *file_name, const std::vector<char> &extra); | |||
| std::vector<char> ToCString() const; | |||
| std::vector<char> GetErrDescriptionChar() const; | |||
| std::vector<char> SetErrDescription(const std::vector<char> &err_description); | |||
| static std::vector<char> CodeAsCString(enum StatusCode c); | |||
| struct Data; | |||
| std::shared_ptr<Data> data_; | |||
| }; | |||
| Status::Status(enum StatusCode status_code, const std::string &status_msg) | |||
| : Status(status_code, StringToChar(status_msg)) {} | |||
| Status::Status(const enum StatusCode code, int line_of_code, const char *file_name, const std::string &extra) | |||
| : Status(code, line_of_code, file_name, StringToChar(extra)) {} | |||
| std::string Status::ToString() const { return CharToString(ToCString()); } | |||
| std::string Status::GetErrDescription() const { return CharToString(GetErrDescriptionChar()); } | |||
| std::string Status::SetErrDescription(const std::string &err_description) { | |||
| return CharToString(SetErrDescription(StringToChar(err_description))); | |||
| } | |||
| std::string Status::CodeAsString(enum StatusCode c) { return CharToString(CodeAsCString(c)); } | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_STATUS_H | |||
| @@ -0,0 +1,122 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_INCLUDE_API_TYPES_H | |||
| #define MINDSPORE_INCLUDE_API_TYPES_H | |||
| #include <cstddef> | |||
| #include <string> | |||
| #include <vector> | |||
| #include <memory> | |||
| #include "include/api/data_type.h" | |||
| #include "include/api/dual_abi_helper.h" | |||
| #ifdef _WIN32 | |||
| #define MS_API __declspec(dllexport) | |||
| #else | |||
| #define MS_API __attribute__((visibility("default"))) | |||
| #endif | |||
| namespace mindspore { | |||
| enum ModelType : uint32_t { | |||
| kMindIR = 0, | |||
| kAIR = 1, | |||
| kOM = 2, | |||
| kONNX = 3, | |||
| // insert new data type here | |||
| kUnknownType = 0xFFFFFFFF | |||
| }; | |||
| class MS_API MSTensor { | |||
| public: | |||
| class Impl; | |||
| static inline MSTensor CreateTensor(const std::string &name, DataType type, const std::vector<int64_t> &shape, | |||
| const void *data, size_t data_len) noexcept; | |||
| static inline MSTensor CreateRefTensor(const std::string &name, DataType type, const std::vector<int64_t> &shape, | |||
| const void *data, size_t data_len) noexcept; | |||
| MSTensor(); | |||
| explicit MSTensor(const std::shared_ptr<Impl> &impl); | |||
| inline MSTensor(const std::string &name, DataType type, const std::vector<int64_t> &shape, const void *data, | |||
| size_t data_len); | |||
| ~MSTensor(); | |||
| inline std::string Name() const; | |||
| enum DataType DataType() const; | |||
| const std::vector<int64_t> &Shape() const; | |||
| int64_t ElementNum() const; | |||
| std::shared_ptr<const void> Data() const; | |||
| void *MutableData(); | |||
| size_t DataSize() const; | |||
| bool IsDevice() const; | |||
| MSTensor Clone() const; | |||
| bool operator==(std::nullptr_t) const; | |||
| private: | |||
| // api without std::string | |||
| static MSTensor CreateTensor(const std::vector<char> &name, enum DataType type, const std::vector<int64_t> &shape, | |||
| const void *data, size_t data_len) noexcept; | |||
| static MSTensor CreateRefTensor(const std::vector<char> &name, enum DataType type, const std::vector<int64_t> &shape, | |||
| const void *data, size_t data_len) noexcept; | |||
| MSTensor(const std::vector<char> &name, enum DataType type, const std::vector<int64_t> &shape, const void *data, | |||
| size_t data_len); | |||
| std::vector<char> CharName() const; | |||
| friend class ModelImpl; | |||
| explicit MSTensor(std::nullptr_t); | |||
| std::shared_ptr<Impl> impl_; | |||
| }; | |||
| class MS_API Buffer { | |||
| public: | |||
| Buffer(); | |||
| Buffer(const void *data, size_t data_len); | |||
| ~Buffer(); | |||
| const void *Data() const; | |||
| void *MutableData(); | |||
| size_t DataSize() const; | |||
| bool ResizeData(size_t data_len); | |||
| bool SetData(const void *data, size_t data_len); | |||
| Buffer Clone() const; | |||
| private: | |||
| class Impl; | |||
| std::shared_ptr<Impl> impl_; | |||
| }; | |||
| MSTensor MSTensor::CreateTensor(const std::string &name, enum DataType type, const std::vector<int64_t> &shape, | |||
| const void *data, size_t data_len) noexcept { | |||
| return CreateTensor(StringToChar(name), type, shape, data, data_len); | |||
| } | |||
| MSTensor MSTensor::CreateRefTensor(const std::string &name, enum DataType type, const std::vector<int64_t> &shape, | |||
| const void *data, size_t data_len) noexcept { | |||
| return CreateRefTensor(StringToChar(name), type, shape, data, data_len); | |||
| } | |||
| MSTensor::MSTensor(const std::string &name, enum DataType type, const std::vector<int64_t> &shape, const void *data, | |||
| size_t data_len) | |||
| : MSTensor(StringToChar(name), type, shape, data, data_len) {} | |||
| std::string MSTensor::Name() const { return CharToString(CharName()); } | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_INCLUDE_API_TYPES_H | |||
| @@ -0,0 +1,66 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_INCLUDE_CONTEXT_H_ | |||
| #define MINDSPORE_LITE_INCLUDE_CONTEXT_H_ | |||
| #include "include/ms_tensor.h" | |||
| #include "include/lite_utils.h" | |||
| #include "include/lite_types.h" | |||
| namespace mindspore::lite { | |||
| /// \brief CpuDeviceInfo defined for CPU's configuration information. | |||
| typedef struct { | |||
| bool enable_float16_ = false; /**< prior enable float16 inference */ | |||
| CpuBindMode cpu_bind_mode_ = MID_CPU; | |||
| } CpuDeviceInfo; | |||
| /// \brief GpuDeviceInfo defined for GPU's configuration information. | |||
| typedef struct { | |||
| bool enable_float16_ = false; /**< prior enable float16 inference */ | |||
| } GpuDeviceInfo; | |||
| /// \brief NpuDeviceInfo defined for NPU's configuration information. | |||
| typedef struct { | |||
| int frequency_ = 3; /**< npu frequency inference */ | |||
| } NpuDeviceInfo; | |||
| /// \brief DeviceInfo defined for backend's configuration information. | |||
| union DeviceInfo { | |||
| CpuDeviceInfo cpu_device_info_; | |||
| GpuDeviceInfo gpu_device_info_; | |||
| NpuDeviceInfo npu_device_info_; | |||
| }; | |||
| /// \brief DeviceContext defined for holding backend's configuration information. | |||
| struct DeviceContext { | |||
| DeviceType device_type_ = DT_CPU; | |||
| DeviceInfo device_info_; | |||
| }; | |||
| /// \brief Context defined for holding environment variables during runtime. | |||
| struct Context { | |||
| String vendor_name_; | |||
| int thread_num_ = 2; /**< thread number config for thread pool */ | |||
| AllocatorPtr allocator = nullptr; | |||
| #ifndef NOT_USE_STL | |||
| DeviceContextVector device_list_ = {{DT_CPU, {false, MID_CPU}}}; | |||
| #else | |||
| DeviceContextVector device_list_; | |||
| #endif // NOT_USE_STL | |||
| }; | |||
| } // namespace mindspore::lite | |||
| #endif // MINDSPORE_LITE_INCLUDE_CONTEXT_H_ | |||
| @@ -0,0 +1,74 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_INCLUDE_ERRORCODE_H_ | |||
| #define MINDSPORE_LITE_INCLUDE_ERRORCODE_H_ | |||
| #include "include/lite_utils.h" | |||
| namespace mindspore { | |||
| namespace lite { | |||
| /// \brief STATUS defined for holding error code in MindSpore Lite. | |||
| using STATUS = int; | |||
| /* Success */ | |||
| constexpr int RET_OK = 0; /**< No error occurs. */ | |||
| /* Common error code, range: [-1, -100)*/ | |||
| constexpr int RET_ERROR = -1; /**< Common error code. */ | |||
| constexpr int RET_NULL_PTR = -2; /**< NULL pointer returned.*/ | |||
| constexpr int RET_PARAM_INVALID = -3; /**< Invalid parameter.*/ | |||
| constexpr int RET_NO_CHANGE = -4; /**< No change. */ | |||
| constexpr int RET_SUCCESS_EXIT = -5; /**< No error but exit. */ | |||
| constexpr int RET_MEMORY_FAILED = -6; /**< Fail to create memory. */ | |||
| constexpr int RET_NOT_SUPPORT = -7; /**< Fail to support. */ | |||
| constexpr int RET_THREAD_POOL_ERROR = -8; /**< Error occur in thread pool. */ | |||
| /* Executor error code, range: [-100,-200) */ | |||
| constexpr int RET_OUT_OF_TENSOR_RANGE = -100; /**< Failed to check range. */ | |||
| constexpr int RET_INPUT_TENSOR_ERROR = -101; /**< Failed to check input tensor. */ | |||
| constexpr int RET_REENTRANT_ERROR = -102; /**< Exist executor running. */ | |||
| /* Graph error code, range: [-200,-300) */ | |||
| constexpr int RET_GRAPH_FILE_ERR = -200; /**< Failed to verify graph file. */ | |||
| /* Node error code, range: [-300,-400) */ | |||
| constexpr int RET_NOT_FIND_OP = -300; /**< Failed to find operator. */ | |||
| constexpr int RET_INVALID_OP_NAME = -301; /**< Invalid operator name. */ | |||
| constexpr int RET_INVALID_OP_ATTR = -302; /**< Invalid operator attr. */ | |||
| constexpr int RET_OP_EXECUTE_FAILURE = -303; /**< Failed to execution operator. */ | |||
| /* Tensor error code, range: [-400,-500) */ | |||
| constexpr int RET_FORMAT_ERR = -400; /**< Failed to checking tensor format. */ | |||
| /* InferShape error code, range: [-500,-600) */ | |||
| constexpr int RET_INFER_ERR = -500; /**< Failed to infer shape. */ | |||
| constexpr int RET_INFER_INVALID = -501; /**< Invalid infer shape before runtime. */ | |||
| /* User input param error code, range: [-600, 700)*/ | |||
| constexpr int RET_INPUT_PARAM_INVALID = -600; /**< Invalid input param by user. */ | |||
| /// \brief Print description of errorcode. | |||
| /// | |||
| /// \param[in] error_code define return status of procedure. | |||
| /// | |||
| /// \return String of errorcode info. | |||
| String GetErrorInfo(STATUS error_code); | |||
| } // namespace lite | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_LITE_INCLUDE_ERRORCODE_H_ | |||
| @@ -0,0 +1,95 @@ | |||
| /** | |||
| * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). | |||
| * | |||
| * Copyright 2019-2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_CORE_IR_DTYPE_TYPE_ID_H_ | |||
| #define MINDSPORE_CORE_IR_DTYPE_TYPE_ID_H_ | |||
| namespace mindspore { | |||
| // | |||
| // Supported meta type | |||
| // | |||
| enum TypeId : int { | |||
| kTypeUnknown = 0, | |||
| kMetaTypeBegin = kTypeUnknown, | |||
| kMetaTypeType, // Type | |||
| kMetaTypeAnything, | |||
| kMetaTypeObject, | |||
| kMetaTypeTypeType, // TypeType | |||
| kMetaTypeProblem, | |||
| kMetaTypeExternal, | |||
| kMetaTypeNone, | |||
| kMetaTypeNull, | |||
| kMetaTypeEllipsis, | |||
| kMetaTypeEnd, | |||
| // | |||
| // Object types | |||
| // | |||
| kObjectTypeBegin = kMetaTypeEnd, | |||
| kObjectTypeNumber, | |||
| kObjectTypeString, | |||
| kObjectTypeList, | |||
| kObjectTypeTuple, | |||
| kObjectTypeSlice, | |||
| kObjectTypeKeyword, | |||
| kObjectTypeTensorType, | |||
| kObjectTypeRowTensorType, | |||
| kObjectTypeSparseTensorType, | |||
| kObjectTypeUndeterminedType, | |||
| kObjectTypeClass, | |||
| kObjectTypeDictionary, | |||
| kObjectTypeFunction, | |||
| kObjectTypeJTagged, | |||
| kObjectTypeSymbolicKeyType, | |||
| kObjectTypeEnvType, | |||
| kObjectTypeRefKey, | |||
| kObjectTypeRef, | |||
| kObjectTypeEnd, | |||
| // | |||
| // Number Types | |||
| // | |||
| kNumberTypeBegin = kObjectTypeEnd, | |||
| kNumberTypeBool, | |||
| kNumberTypeInt, | |||
| kNumberTypeInt8, | |||
| kNumberTypeInt16, | |||
| kNumberTypeInt32, | |||
| kNumberTypeInt64, | |||
| kNumberTypeUInt, | |||
| kNumberTypeUInt8, | |||
| kNumberTypeUInt16, | |||
| kNumberTypeUInt32, | |||
| kNumberTypeUInt64, | |||
| kNumberTypeFloat, | |||
| kNumberTypeFloat16, | |||
| kNumberTypeFloat32, | |||
| kNumberTypeFloat64, | |||
| kNumberTypeComplex64, | |||
| kNumberTypeEnd, | |||
| // | |||
| // Monad Types | |||
| // | |||
| // Monad types is placed at the end of enum, | |||
| // in order to keep fit with the type of existing model on the lite side. | |||
| kMonadTypeBegin = kNumberTypeEnd, | |||
| kObjectTypeMonad, | |||
| kObjectTypeUMonad, | |||
| kObjectTypeIOMonad, | |||
| kMonadTypeEnd | |||
| }; | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_CORE_IR_DTYPE_TYPE_ID_H_ | |||
| @@ -0,0 +1,125 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_INCLUDE_LITE_SESSION_H | |||
| #define MINDSPORE_LITE_INCLUDE_LITE_SESSION_H | |||
| #ifndef NOT_USE_STL | |||
| #include <unordered_map> | |||
| #endif // NOT_USE_STL | |||
| #include "include/ms_tensor.h" | |||
| #include "include/model.h" | |||
| #include "include/context.h" | |||
| namespace mindspore { | |||
| namespace session { | |||
| /// \brief LiteSession defined session in MindSpore Lite for compiling Model and forwarding model. | |||
| class MS_API LiteSession { | |||
| public: | |||
| /// \brief Static method to create a LiteSession pointer. | |||
| /// | |||
| /// \param[in] context Define the context of session to be created. | |||
| /// | |||
| /// \return Pointer of MindSpore Lite LiteSession. | |||
| static LiteSession *CreateSession(const lite::Context *context); | |||
| /// \brief Static method to create a LiteSession pointer which has already compiled a model. | |||
| /// | |||
| /// \param[in] model_buf Define the buffer read from a model file. | |||
| /// \param[in] size Define bytes number of model buffer. | |||
| /// \param[in] context Define the context of session to be created. | |||
| /// | |||
| /// \return Pointer of MindSpore Lite LiteSession. | |||
| static LiteSession *CreateSession(const char *model_buf, size_t size, const lite::Context *context); | |||
| /// \brief Destructor of MindSpore Lite LiteSession. | |||
| virtual ~LiteSession() = default; | |||
| /// \brief Attempt to bind or unbind threads in the thread pool to or from the specified cpu core. | |||
| /// | |||
| /// \param[in] if_bind Define whether to bind or unbind threads. | |||
| virtual void BindThread(bool if_bind) = 0; | |||
| /// \brief Compile MindSpore Lite model. | |||
| /// | |||
| /// \note CompileGraph should be called before RunGraph. | |||
| /// | |||
| /// \param[in] model Define the model to be compiled. | |||
| /// | |||
| /// \return STATUS as an error code of compiling graph, STATUS is defined in errorcode.h. | |||
| virtual int CompileGraph(lite::Model *model) = 0; | |||
| /// \brief Get input MindSpore Lite MSTensors of model. | |||
| /// | |||
| /// \return The vector of MindSpore Lite MSTensor. | |||
| virtual Vector<tensor::MSTensor *> GetInputs() const = 0; | |||
| /// \brief Get input MindSpore Lite MSTensors of model by tensor name. | |||
| /// | |||
| /// \param[in] node_name Define tensor name. | |||
| /// | |||
| /// \return The vector of MindSpore Lite MSTensor. | |||
| virtual mindspore::tensor::MSTensor *GetInputsByTensorName(const String &tensor_name) const = 0; | |||
| /// \brief Run session with callback. | |||
| /// | |||
| /// \param[in] before Define a call_back_function to be called before running each node. | |||
| /// \param[in] after Define a call_back_function called after running each node. | |||
| /// | |||
| /// \note RunGraph should be called after CompileGraph. | |||
| /// | |||
| /// \return STATUS as an error code of running graph, STATUS is defined in errorcode.h. | |||
| virtual int RunGraph(const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr) = 0; | |||
| /// \brief Get output MindSpore Lite MSTensors of model by node name. | |||
| /// | |||
| /// \param[in] node_name Define node name. | |||
| /// | |||
| /// \note Deprecated, replace with GetOutputByTensorName | |||
| /// | |||
| /// \return The vector of MindSpore Lite MSTensor. | |||
| virtual Vector<tensor::MSTensor *> GetOutputsByNodeName(const String &node_name) const = 0; | |||
| #ifndef NOT_USE_STL | |||
| /// \brief Get output MindSpore Lite MSTensors of model mapped by tensor name. | |||
| /// | |||
| /// \return The map of output tensor name and MindSpore Lite MSTensor. | |||
| virtual std::unordered_map<String, mindspore::tensor::MSTensor *> GetOutputs() const = 0; | |||
| #endif | |||
| /// \brief Get name of output tensors of model compiled by this session. | |||
| /// | |||
| /// \return The vector of string as output tensor names in order. | |||
| virtual Vector<String> GetOutputTensorNames() const = 0; | |||
| /// \brief Get output MindSpore Lite MSTensors of model by tensor name. | |||
| /// | |||
| /// \param[in] tensor_name Define tensor name. | |||
| /// | |||
| /// \return Pointer of MindSpore Lite MSTensor. | |||
| virtual mindspore::tensor::MSTensor *GetOutputByTensorName(const String &tensor_name) const = 0; | |||
| /// \brief Resize inputs shape. | |||
| /// | |||
| /// \param[in] inputs Define the inputs of the model. | |||
| /// \param[in] dims Define the inputs new shape. | |||
| /// | |||
| /// \return STATUS as an error code of resize inputs, STATUS is defined in errorcode.h. | |||
| virtual int Resize(const Vector<tensor::MSTensor *> &inputs, const Vector<Vector<int>> &dims) = 0; | |||
| }; | |||
| } // namespace session | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_LITE_INCLUDE_LITE_SESSION_H | |||
| @@ -0,0 +1,36 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_INCLUDE_LITE_TYPES_H_ | |||
| #define MINDSPORE_LITE_INCLUDE_LITE_TYPES_H_ | |||
| namespace mindspore::lite { | |||
| /// \brief CpuBindMode defined for holding bind cpu strategy argument. | |||
| typedef enum { | |||
| NO_BIND, /**< no bind */ | |||
| HIGHER_CPU, /**< bind higher cpu first */ | |||
| MID_CPU /**< bind middle cpu first */ | |||
| } CpuBindMode; | |||
| /// \brief DeviceType defined for holding user's preferred backend. | |||
| typedef enum { | |||
| DT_CPU, /**< CPU device type */ | |||
| DT_GPU, /**< GPU device type */ | |||
| DT_NPU /**< NPU device type */ | |||
| } DeviceType; | |||
| } // namespace mindspore::lite | |||
| #endif // MINDSPORE_LITE_INCLUDE_LITE_TYPES_H_ | |||
| @@ -0,0 +1,412 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_INCLUDE_LITE_UTILS_H_ | |||
| #define MINDSPORE_LITE_INCLUDE_LITE_UTILS_H_ | |||
| #ifndef NOT_USE_STL | |||
| #include <vector> | |||
| #include <string> | |||
| #include <memory> | |||
| #include <functional> | |||
| #else | |||
| #include <stdint.h> | |||
| #include <stdlib.h> | |||
| #include <string.h> | |||
| #include <stddef.h> | |||
| #endif // NOT_USE_STL | |||
| #ifndef MS_API | |||
| #ifdef _WIN32 | |||
| #define MS_API __declspec(dllexport) | |||
| #else | |||
| #define MS_API __attribute__((visibility("default"))) | |||
| #endif | |||
| #endif | |||
| namespace mindspore { | |||
| namespace schema { | |||
| struct Tensor; | |||
| } // namespace schema | |||
| namespace tensor { | |||
| class MSTensor; | |||
| } // namespace tensor | |||
| namespace lite { | |||
| struct DeviceContext; | |||
| } // namespace lite | |||
| #ifdef NOT_USE_STL | |||
| class String { | |||
| public: | |||
| String(); | |||
| String(size_t count, char ch); | |||
| String(const char *s, size_t count); | |||
| explicit String(const char *s); | |||
| String(const String &other); | |||
| String(const String &other, size_t pos, size_t count = npos); | |||
| ~String(); | |||
| String &operator=(const String &str); | |||
| String &operator=(const char *str); | |||
| char &at(size_t pos); | |||
| const char &at(size_t pos) const; | |||
| inline char &operator[](size_t pos); | |||
| inline const char &operator[](size_t pos) const; | |||
| char *data() noexcept; | |||
| const char *data() const noexcept; | |||
| const char *c_str() const noexcept; | |||
| // capacity | |||
| bool empty() const noexcept; | |||
| size_t size() const noexcept; | |||
| size_t length() const noexcept; | |||
| // operations | |||
| void clear() noexcept; | |||
| String &append(size_t count, const char ch); | |||
| String &append(const String &str); | |||
| String &append(const char *s); | |||
| String &operator+(const String &str); | |||
| String &operator+=(const String &str); | |||
| String &operator+=(const char *str); | |||
| String &operator+=(const char ch); | |||
| int compare(const String &str) const; | |||
| int compare(const char *str) const; | |||
| String substr(size_t pos = 0, size_t count = npos) const; | |||
| static const size_t npos = -1; | |||
| private: | |||
| size_t size_; | |||
| char *buffer_; | |||
| }; | |||
| String operator+(const String &str1, const char *str2); | |||
| String operator+(const char *str1, const String &str2); | |||
| String to_string(int32_t value); | |||
| String to_string(float value); | |||
| #define DEFAULT_CAPACITY 4 | |||
| #define MS_C_EXCEPTION(...) exit(1) | |||
| #define MIN(x, y) ((x < y) ? (x) : (y)) | |||
| template <typename T> | |||
| class Vector { | |||
| public: | |||
| Vector() { | |||
| size_ = 0; | |||
| capacity_ = DEFAULT_CAPACITY; | |||
| elem_size_ = sizeof(T); | |||
| data_ = nullptr; | |||
| } | |||
| explicit Vector(size_t size) { | |||
| size_ = size; | |||
| elem_size_ = sizeof(T); | |||
| capacity_ = (size == 0 ? DEFAULT_CAPACITY : size); | |||
| data_ = reinterpret_cast<T *>(malloc(capacity_ * elem_size_)); | |||
| if (data_ == nullptr) { | |||
| MS_C_EXCEPTION("malloc data failed"); | |||
| } | |||
| memset(data_, 0, capacity_ * elem_size_); | |||
| } | |||
| Vector(size_t size, const T &value) { | |||
| size_ = size; | |||
| elem_size_ = sizeof(T); | |||
| capacity_ = (size == 0 ? DEFAULT_CAPACITY : size); | |||
| data_ = reinterpret_cast<T *>(malloc(capacity_ * elem_size_)); | |||
| if (data_ == nullptr) { | |||
| MS_C_EXCEPTION("malloc data failed"); | |||
| } | |||
| for (int i = 0; i < size; ++i) { | |||
| data_[i] = value; | |||
| } | |||
| } | |||
| Vector(const Vector<T> &vec) { | |||
| size_ = vec.size_; | |||
| elem_size_ = sizeof(T); | |||
| capacity_ = vec.capacity_; | |||
| data_ = reinterpret_cast<T *>(malloc(capacity_ * elem_size_)); | |||
| if (data_ == nullptr) { | |||
| MS_C_EXCEPTION("malloc data failed"); | |||
| } | |||
| memcpy(data_, vec.data_, size_ * elem_size_); | |||
| } | |||
| ~Vector() { | |||
| if (data_ != nullptr) { | |||
| free(data_); | |||
| } | |||
| } | |||
| void clear() { | |||
| size_ = 0; | |||
| if (data_ != nullptr) { | |||
| free(data_); | |||
| data_ = nullptr; | |||
| } | |||
| } | |||
| void push_back(const T &elem) { | |||
| if (data_ == nullptr) { | |||
| data_ = reinterpret_cast<T *>(malloc(capacity_ * elem_size_)); | |||
| if (data_ == nullptr) { | |||
| MS_C_EXCEPTION("malloc data failed"); | |||
| } | |||
| } else if (size_ == capacity_) { | |||
| resize(size_ + 1); | |||
| --size_; | |||
| } | |||
| data_[size_] = elem; | |||
| ++size_; | |||
| } | |||
| void push_back(T &&elem) { | |||
| if (data_ == nullptr) { | |||
| data_ = reinterpret_cast<T *>(malloc(capacity_ * elem_size_)); | |||
| if (data_ == nullptr) { | |||
| MS_C_EXCEPTION("malloc data failed"); | |||
| } | |||
| } else if (size_ == capacity_) { | |||
| resize(size_ + 1); | |||
| --size_; | |||
| } | |||
| data_[size_] = elem; | |||
| ++size_; | |||
| } | |||
| void pop_back() { | |||
| if (size_ > 0) { | |||
| --size_; | |||
| } else { | |||
| MS_C_EXCEPTION("Index is out of range!"); | |||
| } | |||
| } | |||
| void insert(const T &elem, size_t index) { | |||
| if (index <= size_) { | |||
| ++size_; | |||
| if (size_ > capacity_) { | |||
| resize(size_); | |||
| } | |||
| if (index == size_ - 1) { | |||
| push_back(elem); | |||
| } else { | |||
| memmove(data_ + index + 1, data_ + index, (size_ - index - 1) * elem_size_); | |||
| data_[index] = elem; | |||
| } | |||
| } else { | |||
| MS_C_EXCEPTION("Input index is out of range!"); | |||
| } | |||
| } | |||
| T *begin() { return data_; } | |||
| const T *begin() const { return data_; } | |||
| T *end() { return data_ + size_; } | |||
| const T *end() const { return data_ + size_; } | |||
| T &front() { | |||
| if (size_ > 0) { | |||
| return data_[0]; | |||
| } | |||
| MS_C_EXCEPTION("Index is out of range!"); | |||
| } | |||
| const T &front() const { | |||
| if (size_ > 0) { | |||
| return data_[0]; | |||
| } | |||
| MS_C_EXCEPTION("Index is out of range!"); | |||
| } | |||
| T &back() { | |||
| if (size_ > 0) { | |||
| return data_[size_ - 1]; | |||
| } | |||
| MS_C_EXCEPTION("Index is out of range!"); | |||
| } | |||
| const T &back() const { | |||
| if (size_ > 0) { | |||
| return data_[size_ - 1]; | |||
| } | |||
| MS_C_EXCEPTION("Index is out of range!"); | |||
| } | |||
| T &at(size_t index) { | |||
| if (index < size_) { | |||
| return data_[index]; | |||
| } | |||
| MS_C_EXCEPTION("Input index is out of range!"); | |||
| } | |||
| const T &at(size_t index) const { | |||
| if (index < size_) { | |||
| return data_[index]; | |||
| } | |||
| MS_C_EXCEPTION("Input index is out of range!"); | |||
| } | |||
| T &operator[](size_t index) { | |||
| if (index < size_) { | |||
| return data_[index]; | |||
| } | |||
| MS_C_EXCEPTION("Input index is out of range!"); | |||
| } | |||
| const T &operator[](size_t index) const { | |||
| if (index < size_) { | |||
| return data_[index]; | |||
| } | |||
| MS_C_EXCEPTION("Input index is out of range!"); | |||
| } | |||
| T *data() { return data_; } | |||
| const T *data() const { return data_; } | |||
| size_t size() const { return size_; } | |||
| size_t capacity() const { return capacity_; } | |||
| bool empty() const { return size_ == 0; } | |||
| void erase(size_t index) { | |||
| if (index == size_ - 1) { | |||
| --size_; | |||
| } else if (index < size_) { | |||
| memmove(data_ + index, data_ + index + 1, (size_ - index - 1) * elem_size_); | |||
| --size_; | |||
| } else { | |||
| MS_C_EXCEPTION("Input index is out of range!"); | |||
| } | |||
| } | |||
| void resize(size_t size) { | |||
| while (size > capacity_) { | |||
| capacity_ *= 2; | |||
| } | |||
| T *tmp = data_; | |||
| data_ = reinterpret_cast<T *>(malloc(capacity_ * elem_size_)); | |||
| if (data_ == nullptr) { | |||
| MS_C_EXCEPTION("malloc data failed"); | |||
| } | |||
| memcpy(data_, tmp, MIN(size, size_) * elem_size_); | |||
| size_ = size; | |||
| free(tmp); | |||
| } | |||
| void reserve(size_t capacity) { | |||
| if (capacity > capacity_) { | |||
| capacity_ = capacity; | |||
| } | |||
| } | |||
| Vector<T> &operator=(const Vector<T> &vec) { | |||
| if (this == &vec) { | |||
| return *this; | |||
| } | |||
| size_ = vec.size_; | |||
| elem_size_ = sizeof(T); | |||
| capacity_ = vec.capacity_; | |||
| data_ = reinterpret_cast<T *>(malloc(capacity_ * elem_size_)); | |||
| if (data_ == nullptr) { | |||
| MS_C_EXCEPTION("malloc data failed"); | |||
| } | |||
| memcpy(data_, vec.data_, size_ * elem_size_); | |||
| return *this; | |||
| } | |||
| private: | |||
| size_t size_; | |||
| size_t elem_size_; | |||
| size_t capacity_; | |||
| T *data_; | |||
| }; | |||
| using TensorPtrVector = Vector<mindspore::schema::Tensor *>; | |||
| using Uint32Vector = Vector<uint32_t>; | |||
| using AllocatorPtr = void *; | |||
| using DeviceContextVector = Vector<lite::DeviceContext>; | |||
| using KernelCallBack = void (*)(void *, void *); | |||
| #else | |||
| /// \brief Allocator defined a memory pool for malloc memory and free memory dynamically. | |||
| /// | |||
| /// \note List public class and interface for reference. | |||
| class Allocator; | |||
| using AllocatorPtr = std::shared_ptr<Allocator>; | |||
| using TensorPtrVector = std::vector<mindspore::schema::Tensor *>; | |||
| using Uint32Vector = std::vector<uint32_t>; | |||
| template <typename T> | |||
| using Vector = std::vector<T>; | |||
| template <typename T> | |||
| inline std::string to_string(T t) { | |||
| return std::to_string(t); | |||
| } | |||
| namespace tensor { | |||
| using String = std::string; | |||
| } // namespace tensor | |||
| namespace session { | |||
| using String = std::string; | |||
| } // namespace session | |||
| /// \brief CallBackParam defined input arguments for callBack function. | |||
| struct CallBackParam { | |||
| session::String node_name; /**< node name argument */ | |||
| session::String node_type; /**< node type argument */ | |||
| }; | |||
| struct GPUCallBackParam : CallBackParam { | |||
| double execute_time{-1.f}; | |||
| }; | |||
| /// \brief KernelCallBack defined the function pointer for callBack. | |||
| using KernelCallBack = std::function<bool(Vector<tensor::MSTensor *> inputs, Vector<tensor::MSTensor *> outputs, | |||
| const CallBackParam &opInfo)>; | |||
| namespace lite { | |||
| using String = std::string; | |||
| using DeviceContextVector = std::vector<DeviceContext>; | |||
| /// \brief Set data of MSTensor from string vector. | |||
| /// | |||
| /// \param[in] input string vector. | |||
| /// \param[out] MSTensor. | |||
| /// | |||
| /// \return STATUS as an error code of this interface, STATUS is defined in errorcode.h. | |||
| int MS_API StringsToMSTensor(const Vector<String> &inputs, tensor::MSTensor *tensor); | |||
| /// \brief Get string vector from MSTensor. | |||
| /// \param[in] MSTensor. | |||
| /// \return string vector. | |||
| Vector<String> MS_API MSTensorToStrings(const tensor::MSTensor *tensor); | |||
| } // namespace lite | |||
| #endif // NOT_USE_STL | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_LITE_INCLUDE_LITE_UTILS_H_ | |||
| @@ -0,0 +1,66 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_INCLUDE_MODEL_H_ | |||
| #define MINDSPORE_LITE_INCLUDE_MODEL_H_ | |||
| #include "include/lite_utils.h" | |||
| namespace mindspore::lite { | |||
| struct MS_API Model { | |||
| struct Node { | |||
| String name_; | |||
| int node_type_; | |||
| const void *primitive_; | |||
| Uint32Vector input_indices_; | |||
| Uint32Vector output_indices_; | |||
| int quant_type_; | |||
| }; | |||
| using NodePtrVector = Vector<Node *>; | |||
| struct SubGraph { | |||
| String name_; | |||
| Uint32Vector input_indices_; | |||
| Uint32Vector output_indices_; | |||
| Uint32Vector node_indices_; | |||
| Uint32Vector tensor_indices_; | |||
| }; | |||
| using SubGraphPtrVector = Vector<SubGraph *>; | |||
| String name_; | |||
| String version_; | |||
| TensorPtrVector all_tensors_; | |||
| NodePtrVector all_nodes_; | |||
| char *buf; | |||
| SubGraphPtrVector sub_graphs_; | |||
| /// \brief Static method to create a Model pointer. | |||
| /// | |||
| /// \param[in] model_buf Define the buffer read from a model file. | |||
| /// \param[in] size Define bytes number of model buffer. | |||
| /// | |||
| /// \return Pointer of MindSpore Lite Model. | |||
| static Model *Import(const char *model_buf, size_t size); | |||
| /// \brief Free meta graph temporary buffer | |||
| virtual void Free() = 0; | |||
| /// \brief Free all temporary buffer.EG: nodes in the model. | |||
| virtual void Destroy() = 0; | |||
| /// \brief Model destruct, free all memory | |||
| virtual ~Model() = default; | |||
| }; | |||
| } // namespace mindspore::lite | |||
| #endif // MINDSPORE_LITE_INCLUDE_MODEL_H_ | |||
| @@ -0,0 +1,97 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_ | |||
| #define MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_ | |||
| #include "include/lite_utils.h" | |||
| #include "ir/dtype/type_id.h" | |||
| namespace mindspore { | |||
| namespace tensor { | |||
| /// \brief MSTensor defined tensor in MindSpore Lite. | |||
| class MS_API MSTensor { | |||
| public: | |||
| /// \brief Constructor of MindSpore Lite MSTensor. | |||
| /// | |||
| /// \return Instance of MindSpore Lite MSTensor. | |||
| MSTensor() = default; | |||
| /// \brief Destructor of MindSpore Lite Model. | |||
| virtual ~MSTensor() = default; | |||
| /// \brief Create a MSTensor. | |||
| /// | |||
| /// \return Pointer to an instance of MindSpore Lite MSTensor. | |||
| static MSTensor *CreateTensor(const String &name, TypeId type, const Vector<int> &shape, const void *data, | |||
| size_t data_len); | |||
| /// \brief Get data type of the MindSpore Lite MSTensor. | |||
| /// | |||
| /// \note TypeId is defined in mindspore/mindspore/include/api/type_id.h. Only number types in TypeId enum are | |||
| /// suitable for MSTensor. | |||
| /// | |||
| /// \return MindSpore Lite TypeId of the MindSpore Lite MSTensor. | |||
| virtual TypeId data_type() const = 0; | |||
| /// \brief Get shape of the MindSpore Lite MSTensor. | |||
| /// | |||
| /// \return A vector of int as the shape of the MindSpore Lite MSTensor. | |||
| virtual Vector<int> shape() const = 0; | |||
| /// \brief Set the shape of MSTensor. | |||
| virtual void set_shape(const Vector<int> &name) = 0; | |||
| /// \brief Get number of element in MSTensor. | |||
| /// | |||
| /// \return Number of element in MSTensor. | |||
| virtual int ElementsNum() const = 0; | |||
| /// \brief Get byte size of data in MSTensor. | |||
| /// | |||
| /// \return Byte size of data in MSTensor. | |||
| virtual size_t Size() const = 0; | |||
| /// \brief Get the name of MSTensor. | |||
| /// | |||
| /// \return the name of MSTensor. | |||
| virtual String tensor_name() const = 0; | |||
| /// \brief Set the name of MSTensor. | |||
| virtual void set_tensor_name(const String name) = 0; | |||
| /// \brief Get the pointer of data in MSTensor. | |||
| /// | |||
| /// \note The data pointer can be used to both write and read data in MSTensor. The memory buffer will be | |||
| /// automatically allocated. | |||
| /// | |||
| /// \return the pointer points to data in MSTensor. | |||
| virtual void *MutableData() = 0; | |||
| /// \brief Get the pointer of data in MSTensor. | |||
| /// | |||
| /// \note The data pointer can be used to both write and read data in MSTensor. No memory buffer will be | |||
| /// allocated. | |||
| /// | |||
| /// \return the pointer points to data in MSTensor. | |||
| virtual void *data() = 0; | |||
| /// \brief Set the data of MSTensor. | |||
| virtual void set_data(void *data) = 0; | |||
| }; | |||
| } // namespace tensor | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_LITE_INCLUDE_MS_TENSOR_H_ | |||
| @@ -0,0 +1,38 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_INCLUDE_VERSION_H_ | |||
| #define MINDSPORE_LITE_INCLUDE_VERSION_H_ | |||
| #include "include/lite_utils.h" | |||
| namespace mindspore { | |||
| namespace lite { | |||
| const int ms_version_major = 1; | |||
| const int ms_version_minor = 2; | |||
| const int ms_version_revision = 0; | |||
| /// \brief Global method to get a version string. | |||
| /// | |||
| /// \return The version string of MindSpore Lite. | |||
| inline String Version() { | |||
| return "MindSpore Lite " + to_string(ms_version_major) + "." + to_string(ms_version_revision) + "." + | |||
| to_string(ms_version_revision); | |||
| } | |||
| } // namespace lite | |||
| } // namespace mindspore | |||
| #endif // MINDSPORE_LITE_INCLUDE_VERSION_H_ | |||
| @@ -0,0 +1,411 @@ | |||
| /****************************************************************************** | |||
| * @file cachel1_armv7.h | |||
| * @brief CMSIS Level 1 Cache API for Armv7-M and later | |||
| * @version V1.0.0 | |||
| * @date 03. March 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef ARM_CACHEL1_ARMV7_H | |||
| #define ARM_CACHEL1_ARMV7_H | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_CacheFunctions Cache Functions | |||
| \brief Functions that configure Instruction and Data cache. | |||
| @{ | |||
| */ | |||
| /* Cache Size ID Register Macros */ | |||
| #define CCSIDR_WAYS(x) (((x) & SCB_CCSIDR_ASSOCIATIVITY_Msk) >> SCB_CCSIDR_ASSOCIATIVITY_Pos) | |||
| #define CCSIDR_SETS(x) (((x) & SCB_CCSIDR_NUMSETS_Msk ) >> SCB_CCSIDR_NUMSETS_Pos ) | |||
| #ifndef __SCB_DCACHE_LINE_SIZE | |||
| #define __SCB_DCACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ | |||
| #endif | |||
| #ifndef __SCB_ICACHE_LINE_SIZE | |||
| #define __SCB_ICACHE_LINE_SIZE 32U /*!< Cortex-M7 cache line size is fixed to 32 bytes (8 words). See also register SCB_CCSIDR */ | |||
| #endif | |||
| /** | |||
| \brief Enable I-Cache | |||
| \details Turns on I-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_EnableICache (void) | |||
| { | |||
| #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) | |||
| if (SCB->CCR & SCB_CCR_IC_Msk) return; /* return if ICache is already enabled */ | |||
| __DSB(); | |||
| __ISB(); | |||
| SCB->ICIALLU = 0UL; /* invalidate I-Cache */ | |||
| __DSB(); | |||
| __ISB(); | |||
| SCB->CCR |= (uint32_t)SCB_CCR_IC_Msk; /* enable I-Cache */ | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Disable I-Cache | |||
| \details Turns off I-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_DisableICache (void) | |||
| { | |||
| #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) | |||
| __DSB(); | |||
| __ISB(); | |||
| SCB->CCR &= ~(uint32_t)SCB_CCR_IC_Msk; /* disable I-Cache */ | |||
| SCB->ICIALLU = 0UL; /* invalidate I-Cache */ | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Invalidate I-Cache | |||
| \details Invalidates I-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_InvalidateICache (void) | |||
| { | |||
| #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) | |||
| __DSB(); | |||
| __ISB(); | |||
| SCB->ICIALLU = 0UL; | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief I-Cache Invalidate by address | |||
| \details Invalidates I-Cache for the given address. | |||
| I-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. | |||
| I-Cache memory blocks which are part of given address + given size are invalidated. | |||
| \param[in] addr address | |||
| \param[in] isize size of memory block (in number of bytes) | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_InvalidateICache_by_Addr (void *addr, int32_t isize) | |||
| { | |||
| #if defined (__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1U) | |||
| if ( isize > 0 ) { | |||
| int32_t op_size = isize + (((uint32_t)addr) & (__SCB_ICACHE_LINE_SIZE - 1U)); | |||
| uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_ICACHE_LINE_SIZE - 1U) */; | |||
| __DSB(); | |||
| do { | |||
| SCB->ICIMVAU = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ | |||
| op_addr += __SCB_ICACHE_LINE_SIZE; | |||
| op_size -= __SCB_ICACHE_LINE_SIZE; | |||
| } while ( op_size > 0 ); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Enable D-Cache | |||
| \details Turns on D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_EnableDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| if (SCB->CCR & SCB_CCR_DC_Msk) return; /* return if DCache is already enabled */ | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* invalidate D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | | |||
| ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| SCB->CCR |= (uint32_t)SCB_CCR_DC_Msk; /* enable D-Cache */ | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Disable D-Cache | |||
| \details Turns off D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_DisableDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| SCB->CCR &= ~(uint32_t)SCB_CCR_DC_Msk; /* disable D-Cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* clean & invalidate D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | | |||
| ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Invalidate D-Cache | |||
| \details Invalidates D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_InvalidateDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* invalidate D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCISW = (((sets << SCB_DCISW_SET_Pos) & SCB_DCISW_SET_Msk) | | |||
| ((ways << SCB_DCISW_WAY_Pos) & SCB_DCISW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Clean D-Cache | |||
| \details Cleans D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_CleanDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* clean D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCCSW = (((sets << SCB_DCCSW_SET_Pos) & SCB_DCCSW_SET_Msk) | | |||
| ((ways << SCB_DCCSW_WAY_Pos) & SCB_DCCSW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Clean & Invalidate D-Cache | |||
| \details Cleans and Invalidates D-Cache | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_CleanInvalidateDCache (void) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| uint32_t ccsidr; | |||
| uint32_t sets; | |||
| uint32_t ways; | |||
| SCB->CSSELR = 0U; /* select Level 1 data cache */ | |||
| __DSB(); | |||
| ccsidr = SCB->CCSIDR; | |||
| /* clean & invalidate D-Cache */ | |||
| sets = (uint32_t)(CCSIDR_SETS(ccsidr)); | |||
| do { | |||
| ways = (uint32_t)(CCSIDR_WAYS(ccsidr)); | |||
| do { | |||
| SCB->DCCISW = (((sets << SCB_DCCISW_SET_Pos) & SCB_DCCISW_SET_Msk) | | |||
| ((ways << SCB_DCCISW_WAY_Pos) & SCB_DCCISW_WAY_Msk) ); | |||
| #if defined ( __CC_ARM ) | |||
| __schedule_barrier(); | |||
| #endif | |||
| } while (ways-- != 0U); | |||
| } while(sets-- != 0U); | |||
| __DSB(); | |||
| __ISB(); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief D-Cache Invalidate by address | |||
| \details Invalidates D-Cache for the given address. | |||
| D-Cache is invalidated starting from a 32 byte aligned address in 32 byte granularity. | |||
| D-Cache memory blocks which are part of given address + given size are invalidated. | |||
| \param[in] addr address | |||
| \param[in] dsize size of memory block (in number of bytes) | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_InvalidateDCache_by_Addr (void *addr, int32_t dsize) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| if ( dsize > 0 ) { | |||
| int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); | |||
| uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; | |||
| __DSB(); | |||
| do { | |||
| SCB->DCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ | |||
| op_addr += __SCB_DCACHE_LINE_SIZE; | |||
| op_size -= __SCB_DCACHE_LINE_SIZE; | |||
| } while ( op_size > 0 ); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| } | |||
| /** | |||
| \brief D-Cache Clean by address | |||
| \details Cleans D-Cache for the given address | |||
| D-Cache is cleaned starting from a 32 byte aligned address in 32 byte granularity. | |||
| D-Cache memory blocks which are part of given address + given size are cleaned. | |||
| \param[in] addr address | |||
| \param[in] dsize size of memory block (in number of bytes) | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_CleanDCache_by_Addr (uint32_t *addr, int32_t dsize) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| if ( dsize > 0 ) { | |||
| int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); | |||
| uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; | |||
| __DSB(); | |||
| do { | |||
| SCB->DCCMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ | |||
| op_addr += __SCB_DCACHE_LINE_SIZE; | |||
| op_size -= __SCB_DCACHE_LINE_SIZE; | |||
| } while ( op_size > 0 ); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| } | |||
| /** | |||
| \brief D-Cache Clean and Invalidate by address | |||
| \details Cleans and invalidates D_Cache for the given address | |||
| D-Cache is cleaned and invalidated starting from a 32 byte aligned address in 32 byte granularity. | |||
| D-Cache memory blocks which are part of given address + given size are cleaned and invalidated. | |||
| \param[in] addr address (aligned to 32-byte boundary) | |||
| \param[in] dsize size of memory block (in number of bytes) | |||
| */ | |||
| __STATIC_FORCEINLINE void SCB_CleanInvalidateDCache_by_Addr (uint32_t *addr, int32_t dsize) | |||
| { | |||
| #if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) | |||
| if ( dsize > 0 ) { | |||
| int32_t op_size = dsize + (((uint32_t)addr) & (__SCB_DCACHE_LINE_SIZE - 1U)); | |||
| uint32_t op_addr = (uint32_t)addr /* & ~(__SCB_DCACHE_LINE_SIZE - 1U) */; | |||
| __DSB(); | |||
| do { | |||
| SCB->DCCIMVAC = op_addr; /* register accepts only 32byte aligned values, only bits 31..5 are valid */ | |||
| op_addr += __SCB_DCACHE_LINE_SIZE; | |||
| op_size -= __SCB_DCACHE_LINE_SIZE; | |||
| } while ( op_size > 0 ); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| } | |||
| /*@} end of CMSIS_Core_CacheFunctions */ | |||
| #endif /* ARM_CACHEL1_ARMV7_H */ | |||
| @@ -0,0 +1,885 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_armcc.h | |||
| * @brief CMSIS compiler ARMCC (Arm Compiler 5) header file | |||
| * @version V5.2.1 | |||
| * @date 26. March 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef __CMSIS_ARMCC_H | |||
| #define __CMSIS_ARMCC_H | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677) | |||
| #error "Please use Arm Compiler Toolchain V4.0.677 or later!" | |||
| #endif | |||
| /* CMSIS compiler control architecture macros */ | |||
| #if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \ | |||
| (defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) ) | |||
| #define __ARM_ARCH_6M__ 1 | |||
| #endif | |||
| #if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) | |||
| #define __ARM_ARCH_7M__ 1 | |||
| #endif | |||
| #if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) | |||
| #define __ARM_ARCH_7EM__ 1 | |||
| #endif | |||
| /* __ARM_ARCH_8M_BASE__ not applicable */ | |||
| /* __ARM_ARCH_8M_MAIN__ not applicable */ | |||
| /* __ARM_ARCH_8_1M_MAIN__ not applicable */ | |||
| /* CMSIS compiler control DSP macros */ | |||
| #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| #define __ARM_FEATURE_DSP 1 | |||
| #endif | |||
| /* CMSIS compiler specific defines */ | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE __inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static __inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE static __forceinline | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __declspec(noreturn) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed)) | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT __packed struct | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #define __PACKED_UNION __packed union | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x))) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| #define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr))) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| #define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr))) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #define __RESTRICT __restrict | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #define __COMPILER_BARRIER() __memory_changed() | |||
| #endif | |||
| /* ######################### Startup and Lowlevel Init ######################## */ | |||
| #ifndef __PROGRAM_START | |||
| #define __PROGRAM_START __main | |||
| #endif | |||
| #ifndef __INITIAL_SP | |||
| #define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit | |||
| #endif | |||
| #ifndef __STACK_LIMIT | |||
| #define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base | |||
| #endif | |||
| #ifndef __VECTOR_TABLE | |||
| #define __VECTOR_TABLE __Vectors | |||
| #endif | |||
| #ifndef __VECTOR_TABLE_ATTRIBUTE | |||
| #define __VECTOR_TABLE_ATTRIBUTE __attribute__((used, section("RESET"))) | |||
| #endif | |||
| /* ########################### Core Function Access ########################### */ | |||
| /** \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Enable IRQ Interrupts | |||
| \details Enables IRQ interrupts by clearing the I-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| /* intrinsic void __enable_irq(); */ | |||
| /** | |||
| \brief Disable IRQ Interrupts | |||
| \details Disables IRQ interrupts by setting the I-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| /* intrinsic void __disable_irq(); */ | |||
| /** | |||
| \brief Get Control Register | |||
| \details Returns the content of the Control Register. | |||
| \return Control Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_CONTROL(void) | |||
| { | |||
| register uint32_t __regControl __ASM("control"); | |||
| return(__regControl); | |||
| } | |||
| /** | |||
| \brief Set Control Register | |||
| \details Writes the given value to the Control Register. | |||
| \param [in] control Control Register value to set | |||
| */ | |||
| __STATIC_INLINE void __set_CONTROL(uint32_t control) | |||
| { | |||
| register uint32_t __regControl __ASM("control"); | |||
| __regControl = control; | |||
| } | |||
| /** | |||
| \brief Get IPSR Register | |||
| \details Returns the content of the IPSR Register. | |||
| \return IPSR Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_IPSR(void) | |||
| { | |||
| register uint32_t __regIPSR __ASM("ipsr"); | |||
| return(__regIPSR); | |||
| } | |||
| /** | |||
| \brief Get APSR Register | |||
| \details Returns the content of the APSR Register. | |||
| \return APSR Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_APSR(void) | |||
| { | |||
| register uint32_t __regAPSR __ASM("apsr"); | |||
| return(__regAPSR); | |||
| } | |||
| /** | |||
| \brief Get xPSR Register | |||
| \details Returns the content of the xPSR Register. | |||
| \return xPSR Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_xPSR(void) | |||
| { | |||
| register uint32_t __regXPSR __ASM("xpsr"); | |||
| return(__regXPSR); | |||
| } | |||
| /** | |||
| \brief Get Process Stack Pointer | |||
| \details Returns the current value of the Process Stack Pointer (PSP). | |||
| \return PSP Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_PSP(void) | |||
| { | |||
| register uint32_t __regProcessStackPointer __ASM("psp"); | |||
| return(__regProcessStackPointer); | |||
| } | |||
| /** | |||
| \brief Set Process Stack Pointer | |||
| \details Assigns the given value to the Process Stack Pointer (PSP). | |||
| \param [in] topOfProcStack Process Stack Pointer value to set | |||
| */ | |||
| __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) | |||
| { | |||
| register uint32_t __regProcessStackPointer __ASM("psp"); | |||
| __regProcessStackPointer = topOfProcStack; | |||
| } | |||
| /** | |||
| \brief Get Main Stack Pointer | |||
| \details Returns the current value of the Main Stack Pointer (MSP). | |||
| \return MSP Register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_MSP(void) | |||
| { | |||
| register uint32_t __regMainStackPointer __ASM("msp"); | |||
| return(__regMainStackPointer); | |||
| } | |||
| /** | |||
| \brief Set Main Stack Pointer | |||
| \details Assigns the given value to the Main Stack Pointer (MSP). | |||
| \param [in] topOfMainStack Main Stack Pointer value to set | |||
| */ | |||
| __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) | |||
| { | |||
| register uint32_t __regMainStackPointer __ASM("msp"); | |||
| __regMainStackPointer = topOfMainStack; | |||
| } | |||
| /** | |||
| \brief Get Priority Mask | |||
| \details Returns the current state of the priority mask bit from the Priority Mask Register. | |||
| \return Priority Mask value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_PRIMASK(void) | |||
| { | |||
| register uint32_t __regPriMask __ASM("primask"); | |||
| return(__regPriMask); | |||
| } | |||
| /** | |||
| \brief Set Priority Mask | |||
| \details Assigns the given value to the Priority Mask Register. | |||
| \param [in] priMask Priority Mask | |||
| */ | |||
| __STATIC_INLINE void __set_PRIMASK(uint32_t priMask) | |||
| { | |||
| register uint32_t __regPriMask __ASM("primask"); | |||
| __regPriMask = (priMask); | |||
| } | |||
| #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| /** | |||
| \brief Enable FIQ | |||
| \details Enables FIQ interrupts by clearing the F-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| #define __enable_fault_irq __enable_fiq | |||
| /** | |||
| \brief Disable FIQ | |||
| \details Disables FIQ interrupts by setting the F-bit in the CPSR. | |||
| Can only be executed in Privileged modes. | |||
| */ | |||
| #define __disable_fault_irq __disable_fiq | |||
| /** | |||
| \brief Get Base Priority | |||
| \details Returns the current value of the Base Priority register. | |||
| \return Base Priority register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_BASEPRI(void) | |||
| { | |||
| register uint32_t __regBasePri __ASM("basepri"); | |||
| return(__regBasePri); | |||
| } | |||
| /** | |||
| \brief Set Base Priority | |||
| \details Assigns the given value to the Base Priority register. | |||
| \param [in] basePri Base Priority value to set | |||
| */ | |||
| __STATIC_INLINE void __set_BASEPRI(uint32_t basePri) | |||
| { | |||
| register uint32_t __regBasePri __ASM("basepri"); | |||
| __regBasePri = (basePri & 0xFFU); | |||
| } | |||
| /** | |||
| \brief Set Base Priority with condition | |||
| \details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled, | |||
| or the new value increases the BASEPRI priority level. | |||
| \param [in] basePri Base Priority value to set | |||
| */ | |||
| __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) | |||
| { | |||
| register uint32_t __regBasePriMax __ASM("basepri_max"); | |||
| __regBasePriMax = (basePri & 0xFFU); | |||
| } | |||
| /** | |||
| \brief Get Fault Mask | |||
| \details Returns the current value of the Fault Mask register. | |||
| \return Fault Mask register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_FAULTMASK(void) | |||
| { | |||
| register uint32_t __regFaultMask __ASM("faultmask"); | |||
| return(__regFaultMask); | |||
| } | |||
| /** | |||
| \brief Set Fault Mask | |||
| \details Assigns the given value to the Fault Mask register. | |||
| \param [in] faultMask Fault Mask value to set | |||
| */ | |||
| __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) | |||
| { | |||
| register uint32_t __regFaultMask __ASM("faultmask"); | |||
| __regFaultMask = (faultMask & (uint32_t)1U); | |||
| } | |||
| #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ | |||
| /** | |||
| \brief Get FPSCR | |||
| \details Returns the current value of the Floating Point Status/Control register. | |||
| \return Floating Point Status/Control register value | |||
| */ | |||
| __STATIC_INLINE uint32_t __get_FPSCR(void) | |||
| { | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| register uint32_t __regfpscr __ASM("fpscr"); | |||
| return(__regfpscr); | |||
| #else | |||
| return(0U); | |||
| #endif | |||
| } | |||
| /** | |||
| \brief Set FPSCR | |||
| \details Assigns the given value to the Floating Point Status/Control register. | |||
| \param [in] fpscr Floating Point Status/Control value to set | |||
| */ | |||
| __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) | |||
| { | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| register uint32_t __regfpscr __ASM("fpscr"); | |||
| __regfpscr = (fpscr); | |||
| #else | |||
| (void)fpscr; | |||
| #endif | |||
| } | |||
| /*@} end of CMSIS_Core_RegAccFunctions */ | |||
| /* ########################## Core Instruction Access ######################### */ | |||
| /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface | |||
| Access to dedicated instructions | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief No Operation | |||
| \details No Operation does nothing. This instruction can be used for code alignment purposes. | |||
| */ | |||
| #define __NOP __nop | |||
| /** | |||
| \brief Wait For Interrupt | |||
| \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. | |||
| */ | |||
| #define __WFI __wfi | |||
| /** | |||
| \brief Wait For Event | |||
| \details Wait For Event is a hint instruction that permits the processor to enter | |||
| a low-power state until one of a number of events occurs. | |||
| */ | |||
| #define __WFE __wfe | |||
| /** | |||
| \brief Send Event | |||
| \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. | |||
| */ | |||
| #define __SEV __sev | |||
| /** | |||
| \brief Instruction Synchronization Barrier | |||
| \details Instruction Synchronization Barrier flushes the pipeline in the processor, | |||
| so that all instructions following the ISB are fetched from cache or memory, | |||
| after the instruction has been completed. | |||
| */ | |||
| #define __ISB() __isb(0xF) | |||
| /** | |||
| \brief Data Synchronization Barrier | |||
| \details Acts as a special kind of Data Memory Barrier. | |||
| It completes when all explicit memory accesses before this instruction complete. | |||
| */ | |||
| #define __DSB() __dsb(0xF) | |||
| /** | |||
| \brief Data Memory Barrier | |||
| \details Ensures the apparent order of the explicit memory operations before | |||
| and after the instruction, without ensuring their completion. | |||
| */ | |||
| #define __DMB() __dmb(0xF) | |||
| /** | |||
| \brief Reverse byte order (32 bit) | |||
| \details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #define __REV __rev | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #ifndef __NO_EMBEDDED_ASM | |||
| __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) | |||
| { | |||
| rev16 r0, r0 | |||
| bx lr | |||
| } | |||
| #endif | |||
| /** | |||
| \brief Reverse byte order (16 bit) | |||
| \details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #ifndef __NO_EMBEDDED_ASM | |||
| __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value) | |||
| { | |||
| revsh r0, r0 | |||
| bx lr | |||
| } | |||
| #endif | |||
| /** | |||
| \brief Rotate Right in unsigned value (32 bit) | |||
| \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. | |||
| \param [in] op1 Value to rotate | |||
| \param [in] op2 Number of Bits to rotate | |||
| \return Rotated value | |||
| */ | |||
| #define __ROR __ror | |||
| /** | |||
| \brief Breakpoint | |||
| \details Causes the processor to enter Debug state. | |||
| Debug tools can use this to investigate system state when the instruction at a particular address is reached. | |||
| \param [in] value is ignored by the processor. | |||
| If required, a debugger can use it to store additional information about the breakpoint. | |||
| */ | |||
| #define __BKPT(value) __breakpoint(value) | |||
| /** | |||
| \brief Reverse bit order of value | |||
| \details Reverses the bit order of the given value. | |||
| \param [in] value Value to reverse | |||
| \return Reversed value | |||
| */ | |||
| #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| #define __RBIT __rbit | |||
| #else | |||
| __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) | |||
| { | |||
| uint32_t result; | |||
| uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ | |||
| result = value; /* r will be reversed bits of v; first get LSB of v */ | |||
| for (value >>= 1U; value != 0U; value >>= 1U) | |||
| { | |||
| result <<= 1U; | |||
| result |= value & 1U; | |||
| s--; | |||
| } | |||
| result <<= s; /* shift when v's highest bits are zero */ | |||
| return result; | |||
| } | |||
| #endif | |||
| /** | |||
| \brief Count leading zeros | |||
| \details Counts the number of leading zeros of a data value. | |||
| \param [in] value Value to count the leading zeros | |||
| \return number of leading zeros in value | |||
| */ | |||
| #define __CLZ __clz | |||
| #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| /** | |||
| \brief LDR Exclusive (8 bit) | |||
| \details Executes a exclusive LDR instruction for 8 bit value. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint8_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief LDR Exclusive (16 bit) | |||
| \details Executes a exclusive LDR instruction for 16 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint16_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief LDR Exclusive (32 bit) | |||
| \details Executes a exclusive LDR instruction for 32 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint32_t at (*ptr) | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) | |||
| #else | |||
| #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (8 bit) | |||
| \details Executes a exclusive STR instruction for 8 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXB(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (16 bit) | |||
| \details Executes a exclusive STR instruction for 16 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXH(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief STR Exclusive (32 bit) | |||
| \details Executes a exclusive STR instruction for 32 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| \return 0 Function succeeded | |||
| \return 1 Function failed | |||
| */ | |||
| #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) | |||
| #define __STREXW(value, ptr) __strex(value, ptr) | |||
| #else | |||
| #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") | |||
| #endif | |||
| /** | |||
| \brief Remove the exclusive lock | |||
| \details Removes the exclusive lock which is created by LDREX. | |||
| */ | |||
| #define __CLREX __clrex | |||
| /** | |||
| \brief Signed Saturate | |||
| \details Saturates a signed value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (1..32) | |||
| \return Saturated value | |||
| */ | |||
| #define __SSAT __ssat | |||
| /** | |||
| \brief Unsigned Saturate | |||
| \details Saturates an unsigned value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (0..31) | |||
| \return Saturated value | |||
| */ | |||
| #define __USAT __usat | |||
| /** | |||
| \brief Rotate Right with Extend (32 bit) | |||
| \details Moves each bit of a bitstring right by one bit. | |||
| The carry input is shifted in at the left end of the bitstring. | |||
| \param [in] value Value to rotate | |||
| \return Rotated value | |||
| */ | |||
| #ifndef __NO_EMBEDDED_ASM | |||
| __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) | |||
| { | |||
| rrx r0, r0 | |||
| bx lr | |||
| } | |||
| #endif | |||
| /** | |||
| \brief LDRT Unprivileged (8 bit) | |||
| \details Executes a Unprivileged LDRT instruction for 8 bit value. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint8_t at (*ptr) | |||
| */ | |||
| #define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr)) | |||
| /** | |||
| \brief LDRT Unprivileged (16 bit) | |||
| \details Executes a Unprivileged LDRT instruction for 16 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint16_t at (*ptr) | |||
| */ | |||
| #define __LDRHT(ptr) ((uint16_t) __ldrt(ptr)) | |||
| /** | |||
| \brief LDRT Unprivileged (32 bit) | |||
| \details Executes a Unprivileged LDRT instruction for 32 bit values. | |||
| \param [in] ptr Pointer to data | |||
| \return value of type uint32_t at (*ptr) | |||
| */ | |||
| #define __LDRT(ptr) ((uint32_t ) __ldrt(ptr)) | |||
| /** | |||
| \brief STRT Unprivileged (8 bit) | |||
| \details Executes a Unprivileged STRT instruction for 8 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| */ | |||
| #define __STRBT(value, ptr) __strt(value, ptr) | |||
| /** | |||
| \brief STRT Unprivileged (16 bit) | |||
| \details Executes a Unprivileged STRT instruction for 16 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| */ | |||
| #define __STRHT(value, ptr) __strt(value, ptr) | |||
| /** | |||
| \brief STRT Unprivileged (32 bit) | |||
| \details Executes a Unprivileged STRT instruction for 32 bit values. | |||
| \param [in] value Value to store | |||
| \param [in] ptr Pointer to location | |||
| */ | |||
| #define __STRT(value, ptr) __strt(value, ptr) | |||
| #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ | |||
| /** | |||
| \brief Signed Saturate | |||
| \details Saturates a signed value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (1..32) | |||
| \return Saturated value | |||
| */ | |||
| __attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) | |||
| { | |||
| if ((sat >= 1U) && (sat <= 32U)) | |||
| { | |||
| const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); | |||
| const int32_t min = -1 - max ; | |||
| if (val > max) | |||
| { | |||
| return max; | |||
| } | |||
| else if (val < min) | |||
| { | |||
| return min; | |||
| } | |||
| } | |||
| return val; | |||
| } | |||
| /** | |||
| \brief Unsigned Saturate | |||
| \details Saturates an unsigned value. | |||
| \param [in] value Value to be saturated | |||
| \param [in] sat Bit position to saturate to (0..31) | |||
| \return Saturated value | |||
| */ | |||
| __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) | |||
| { | |||
| if (sat <= 31U) | |||
| { | |||
| const uint32_t max = ((1U << sat) - 1U); | |||
| if (val > (int32_t)max) | |||
| { | |||
| return max; | |||
| } | |||
| else if (val < 0) | |||
| { | |||
| return 0U; | |||
| } | |||
| } | |||
| return (uint32_t)val; | |||
| } | |||
| #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ | |||
| (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ | |||
| /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ | |||
| /* ################### Compiler specific Intrinsics ########################### */ | |||
| /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics | |||
| Access to dedicated SIMD instructions | |||
| @{ | |||
| */ | |||
| #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) | |||
| #define __SADD8 __sadd8 | |||
| #define __QADD8 __qadd8 | |||
| #define __SHADD8 __shadd8 | |||
| #define __UADD8 __uadd8 | |||
| #define __UQADD8 __uqadd8 | |||
| #define __UHADD8 __uhadd8 | |||
| #define __SSUB8 __ssub8 | |||
| #define __QSUB8 __qsub8 | |||
| #define __SHSUB8 __shsub8 | |||
| #define __USUB8 __usub8 | |||
| #define __UQSUB8 __uqsub8 | |||
| #define __UHSUB8 __uhsub8 | |||
| #define __SADD16 __sadd16 | |||
| #define __QADD16 __qadd16 | |||
| #define __SHADD16 __shadd16 | |||
| #define __UADD16 __uadd16 | |||
| #define __UQADD16 __uqadd16 | |||
| #define __UHADD16 __uhadd16 | |||
| #define __SSUB16 __ssub16 | |||
| #define __QSUB16 __qsub16 | |||
| #define __SHSUB16 __shsub16 | |||
| #define __USUB16 __usub16 | |||
| #define __UQSUB16 __uqsub16 | |||
| #define __UHSUB16 __uhsub16 | |||
| #define __SASX __sasx | |||
| #define __QASX __qasx | |||
| #define __SHASX __shasx | |||
| #define __UASX __uasx | |||
| #define __UQASX __uqasx | |||
| #define __UHASX __uhasx | |||
| #define __SSAX __ssax | |||
| #define __QSAX __qsax | |||
| #define __SHSAX __shsax | |||
| #define __USAX __usax | |||
| #define __UQSAX __uqsax | |||
| #define __UHSAX __uhsax | |||
| #define __USAD8 __usad8 | |||
| #define __USADA8 __usada8 | |||
| #define __SSAT16 __ssat16 | |||
| #define __USAT16 __usat16 | |||
| #define __UXTB16 __uxtb16 | |||
| #define __UXTAB16 __uxtab16 | |||
| #define __SXTB16 __sxtb16 | |||
| #define __SXTAB16 __sxtab16 | |||
| #define __SMUAD __smuad | |||
| #define __SMUADX __smuadx | |||
| #define __SMLAD __smlad | |||
| #define __SMLADX __smladx | |||
| #define __SMLALD __smlald | |||
| #define __SMLALDX __smlaldx | |||
| #define __SMUSD __smusd | |||
| #define __SMUSDX __smusdx | |||
| #define __SMLSD __smlsd | |||
| #define __SMLSDX __smlsdx | |||
| #define __SMLSLD __smlsld | |||
| #define __SMLSLDX __smlsldx | |||
| #define __SEL __sel | |||
| #define __QADD __qadd | |||
| #define __QSUB __qsub | |||
| #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ | |||
| ((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) ) | |||
| #define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \ | |||
| ((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) ) | |||
| #define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \ | |||
| ((int64_t)(ARG3) << 32U) ) >> 32U)) | |||
| #define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2)) | |||
| #endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */ | |||
| /*@} end of group CMSIS_SIMD_intrinsics */ | |||
| #endif /* __CMSIS_ARMCC_H */ | |||
| @@ -0,0 +1,283 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_compiler.h | |||
| * @brief CMSIS compiler generic header file | |||
| * @version V5.1.0 | |||
| * @date 09. October 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef __CMSIS_COMPILER_H | |||
| #define __CMSIS_COMPILER_H | |||
| #include <stdint.h> | |||
| /* | |||
| * Arm Compiler 4/5 | |||
| */ | |||
| #if defined ( __CC_ARM ) | |||
| #include "cmsis_armcc.h" | |||
| /* | |||
| * Arm Compiler 6.6 LTM (armclang) | |||
| */ | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100) | |||
| #include "cmsis_armclang_ltm.h" | |||
| /* | |||
| * Arm Compiler above 6.10.1 (armclang) | |||
| */ | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) | |||
| #include "cmsis_armclang.h" | |||
| /* | |||
| * GNU Compiler | |||
| */ | |||
| #elif defined ( __GNUC__ ) | |||
| #include "cmsis_gcc.h" | |||
| /* | |||
| * IAR Compiler | |||
| */ | |||
| #elif defined ( __ICCARM__ ) | |||
| #include <cmsis_iccarm.h> | |||
| /* | |||
| * TI Arm Compiler | |||
| */ | |||
| #elif defined ( __TI_ARM__ ) | |||
| #include <cmsis_ccs.h> | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __attribute__((noreturn)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __attribute__((packed)) | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT struct __attribute__((packed)) | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #define __PACKED_UNION union __attribute__((packed)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| struct __attribute__((packed)) T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #define __RESTRICT __restrict | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| /* | |||
| * TASKING Compiler | |||
| */ | |||
| #elif defined ( __TASKING__ ) | |||
| /* | |||
| * The CMSIS functions have been implemented as intrinsics in the compiler. | |||
| * Please use "carm -?i" to get an up to date list of all intrinsics, | |||
| * Including the CMSIS ones. | |||
| */ | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #define __NO_RETURN __attribute__((noreturn)) | |||
| #endif | |||
| #ifndef __USED | |||
| #define __USED __attribute__((used)) | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __attribute__((weak)) | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED __packed__ | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT struct __packed__ | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #define __PACKED_UNION union __packed__ | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| struct __packed__ T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #define __ALIGNED(x) __align(x) | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. | |||
| #define __RESTRICT | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| /* | |||
| * COSMIC Compiler | |||
| */ | |||
| #elif defined ( __CSMC__ ) | |||
| #include <cmsis_csm.h> | |||
| #ifndef __ASM | |||
| #define __ASM _asm | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| // NO RETURN is automatically detected hence no warning here | |||
| #define __NO_RETURN | |||
| #endif | |||
| #ifndef __USED | |||
| #warning No compiler specific solution for __USED. __USED is ignored. | |||
| #define __USED | |||
| #endif | |||
| #ifndef __WEAK | |||
| #define __WEAK __weak | |||
| #endif | |||
| #ifndef __PACKED | |||
| #define __PACKED @packed | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #define __PACKED_STRUCT @packed struct | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #define __PACKED_UNION @packed union | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| @packed struct T_UINT32 { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; | |||
| #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; | |||
| #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. | |||
| #define __ALIGNED(x) | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. | |||
| #define __RESTRICT | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. | |||
| #define __COMPILER_BARRIER() (void)0 | |||
| #endif | |||
| #else | |||
| #error Unknown compiler. | |||
| #endif | |||
| #endif /* __CMSIS_COMPILER_H */ | |||
| @@ -0,0 +1,968 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_iccarm.h | |||
| * @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file | |||
| * @version V5.2.0 | |||
| * @date 28. January 2020 | |||
| ******************************************************************************/ | |||
| //------------------------------------------------------------------------------ | |||
| // | |||
| // Copyright (c) 2017-2019 IAR Systems | |||
| // Copyright (c) 2017-2019 Arm Limited. All rights reserved. | |||
| // | |||
| // SPDX-License-Identifier: Apache-2.0 | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License") | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| // | |||
| //------------------------------------------------------------------------------ | |||
| #ifndef __CMSIS_ICCARM_H__ | |||
| #define __CMSIS_ICCARM_H__ | |||
| #ifndef __ICCARM__ | |||
| #error This file should only be compiled by ICCARM | |||
| #endif | |||
| #pragma system_include | |||
| #define __IAR_FT _Pragma("inline=forced") __intrinsic | |||
| #if (__VER__ >= 8000000) | |||
| #define __ICCARM_V8 1 | |||
| #else | |||
| #define __ICCARM_V8 0 | |||
| #endif | |||
| #ifndef __ALIGNED | |||
| #if __ICCARM_V8 | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #elif (__VER__ >= 7080000) | |||
| /* Needs IAR language extensions */ | |||
| #define __ALIGNED(x) __attribute__((aligned(x))) | |||
| #else | |||
| #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored. | |||
| #define __ALIGNED(x) | |||
| #endif | |||
| #endif | |||
| /* Define compiler macros for CPU architecture, used in CMSIS 5. | |||
| */ | |||
| #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__ | |||
| /* Macros already defined */ | |||
| #else | |||
| #if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__) | |||
| #define __ARM_ARCH_8M_MAIN__ 1 | |||
| #elif defined(__ARM8M_BASELINE__) | |||
| #define __ARM_ARCH_8M_BASE__ 1 | |||
| #elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' | |||
| #if __ARM_ARCH == 6 | |||
| #define __ARM_ARCH_6M__ 1 | |||
| #elif __ARM_ARCH == 7 | |||
| #if __ARM_FEATURE_DSP | |||
| #define __ARM_ARCH_7EM__ 1 | |||
| #else | |||
| #define __ARM_ARCH_7M__ 1 | |||
| #endif | |||
| #endif /* __ARM_ARCH */ | |||
| #endif /* __ARM_ARCH_PROFILE == 'M' */ | |||
| #endif | |||
| /* Alternativ core deduction for older ICCARM's */ | |||
| #if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \ | |||
| !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__) | |||
| #if defined(__ARM6M__) && (__CORE__ == __ARM6M__) | |||
| #define __ARM_ARCH_6M__ 1 | |||
| #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__) | |||
| #define __ARM_ARCH_7M__ 1 | |||
| #elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__) | |||
| #define __ARM_ARCH_7EM__ 1 | |||
| #elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__) | |||
| #define __ARM_ARCH_8M_BASE__ 1 | |||
| #elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__) | |||
| #define __ARM_ARCH_8M_MAIN__ 1 | |||
| #elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__) | |||
| #define __ARM_ARCH_8M_MAIN__ 1 | |||
| #else | |||
| #error "Unknown target." | |||
| #endif | |||
| #endif | |||
| #if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1 | |||
| #define __IAR_M0_FAMILY 1 | |||
| #elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1 | |||
| #define __IAR_M0_FAMILY 1 | |||
| #else | |||
| #define __IAR_M0_FAMILY 0 | |||
| #endif | |||
| #ifndef __ASM | |||
| #define __ASM __asm | |||
| #endif | |||
| #ifndef __COMPILER_BARRIER | |||
| #define __COMPILER_BARRIER() __ASM volatile("":::"memory") | |||
| #endif | |||
| #ifndef __INLINE | |||
| #define __INLINE inline | |||
| #endif | |||
| #ifndef __NO_RETURN | |||
| #if __ICCARM_V8 | |||
| #define __NO_RETURN __attribute__((__noreturn__)) | |||
| #else | |||
| #define __NO_RETURN _Pragma("object_attribute=__noreturn") | |||
| #endif | |||
| #endif | |||
| #ifndef __PACKED | |||
| #if __ICCARM_V8 | |||
| #define __PACKED __attribute__((packed, aligned(1))) | |||
| #else | |||
| /* Needs IAR language extensions */ | |||
| #define __PACKED __packed | |||
| #endif | |||
| #endif | |||
| #ifndef __PACKED_STRUCT | |||
| #if __ICCARM_V8 | |||
| #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) | |||
| #else | |||
| /* Needs IAR language extensions */ | |||
| #define __PACKED_STRUCT __packed struct | |||
| #endif | |||
| #endif | |||
| #ifndef __PACKED_UNION | |||
| #if __ICCARM_V8 | |||
| #define __PACKED_UNION union __attribute__((packed, aligned(1))) | |||
| #else | |||
| /* Needs IAR language extensions */ | |||
| #define __PACKED_UNION __packed union | |||
| #endif | |||
| #endif | |||
| #ifndef __RESTRICT | |||
| #if __ICCARM_V8 | |||
| #define __RESTRICT __restrict | |||
| #else | |||
| /* Needs IAR language extensions */ | |||
| #define __RESTRICT restrict | |||
| #endif | |||
| #endif | |||
| #ifndef __STATIC_INLINE | |||
| #define __STATIC_INLINE static inline | |||
| #endif | |||
| #ifndef __FORCEINLINE | |||
| #define __FORCEINLINE _Pragma("inline=forced") | |||
| #endif | |||
| #ifndef __STATIC_FORCEINLINE | |||
| #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_READ | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __IAR_FT uint16_t __iar_uint16_read(void const *ptr) | |||
| { | |||
| return *(__packed uint16_t*)(ptr); | |||
| } | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT16_WRITE | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val) | |||
| { | |||
| *(__packed uint16_t*)(ptr) = val;; | |||
| } | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_READ | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __IAR_FT uint32_t __iar_uint32_read(void const *ptr) | |||
| { | |||
| return *(__packed uint32_t*)(ptr); | |||
| } | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32_WRITE | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val) | |||
| { | |||
| *(__packed uint32_t*)(ptr) = val;; | |||
| } | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL) | |||
| #endif | |||
| #ifndef __UNALIGNED_UINT32 /* deprecated */ | |||
| #pragma language=save | |||
| #pragma language=extended | |||
| __packed struct __iar_u32 { uint32_t v; }; | |||
| #pragma language=restore | |||
| #define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v) | |||
| #endif | |||
| #ifndef __USED | |||
| #if __ICCARM_V8 | |||
| #define __USED __attribute__((used)) | |||
| #else | |||
| #define __USED _Pragma("__root") | |||
| #endif | |||
| #endif | |||
| #ifndef __WEAK | |||
| #if __ICCARM_V8 | |||
| #define __WEAK __attribute__((weak)) | |||
| #else | |||
| #define __WEAK _Pragma("__weak") | |||
| #endif | |||
| #endif | |||
| #ifndef __PROGRAM_START | |||
| #define __PROGRAM_START __iar_program_start | |||
| #endif | |||
| #ifndef __INITIAL_SP | |||
| #define __INITIAL_SP CSTACK$$Limit | |||
| #endif | |||
| #ifndef __STACK_LIMIT | |||
| #define __STACK_LIMIT CSTACK$$Base | |||
| #endif | |||
| #ifndef __VECTOR_TABLE | |||
| #define __VECTOR_TABLE __vector_table | |||
| #endif | |||
| #ifndef __VECTOR_TABLE_ATTRIBUTE | |||
| #define __VECTOR_TABLE_ATTRIBUTE @".intvec" | |||
| #endif | |||
| #ifndef __ICCARM_INTRINSICS_VERSION__ | |||
| #define __ICCARM_INTRINSICS_VERSION__ 0 | |||
| #endif | |||
| #if __ICCARM_INTRINSICS_VERSION__ == 2 | |||
| #if defined(__CLZ) | |||
| #undef __CLZ | |||
| #endif | |||
| #if defined(__REVSH) | |||
| #undef __REVSH | |||
| #endif | |||
| #if defined(__RBIT) | |||
| #undef __RBIT | |||
| #endif | |||
| #if defined(__SSAT) | |||
| #undef __SSAT | |||
| #endif | |||
| #if defined(__USAT) | |||
| #undef __USAT | |||
| #endif | |||
| #include "iccarm_builtin.h" | |||
| #define __disable_fault_irq __iar_builtin_disable_fiq | |||
| #define __disable_irq __iar_builtin_disable_interrupt | |||
| #define __enable_fault_irq __iar_builtin_enable_fiq | |||
| #define __enable_irq __iar_builtin_enable_interrupt | |||
| #define __arm_rsr __iar_builtin_rsr | |||
| #define __arm_wsr __iar_builtin_wsr | |||
| #define __get_APSR() (__arm_rsr("APSR")) | |||
| #define __get_BASEPRI() (__arm_rsr("BASEPRI")) | |||
| #define __get_CONTROL() (__arm_rsr("CONTROL")) | |||
| #define __get_FAULTMASK() (__arm_rsr("FAULTMASK")) | |||
| #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) | |||
| #define __get_FPSCR() (__arm_rsr("FPSCR")) | |||
| #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE))) | |||
| #else | |||
| #define __get_FPSCR() ( 0 ) | |||
| #define __set_FPSCR(VALUE) ((void)VALUE) | |||
| #endif | |||
| #define __get_IPSR() (__arm_rsr("IPSR")) | |||
| #define __get_MSP() (__arm_rsr("MSP")) | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure MSPLIM is RAZ/WI | |||
| #define __get_MSPLIM() (0U) | |||
| #else | |||
| #define __get_MSPLIM() (__arm_rsr("MSPLIM")) | |||
| #endif | |||
| #define __get_PRIMASK() (__arm_rsr("PRIMASK")) | |||
| #define __get_PSP() (__arm_rsr("PSP")) | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure PSPLIM is RAZ/WI | |||
| #define __get_PSPLIM() (0U) | |||
| #else | |||
| #define __get_PSPLIM() (__arm_rsr("PSPLIM")) | |||
| #endif | |||
| #define __get_xPSR() (__arm_rsr("xPSR")) | |||
| #define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE))) | |||
| #define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE))) | |||
| #define __set_CONTROL(VALUE) (__arm_wsr("CONTROL", (VALUE))) | |||
| #define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE))) | |||
| #define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE))) | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure MSPLIM is RAZ/WI | |||
| #define __set_MSPLIM(VALUE) ((void)(VALUE)) | |||
| #else | |||
| #define __set_MSPLIM(VALUE) (__arm_wsr("MSPLIM", (VALUE))) | |||
| #endif | |||
| #define __set_PRIMASK(VALUE) (__arm_wsr("PRIMASK", (VALUE))) | |||
| #define __set_PSP(VALUE) (__arm_wsr("PSP", (VALUE))) | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure PSPLIM is RAZ/WI | |||
| #define __set_PSPLIM(VALUE) ((void)(VALUE)) | |||
| #else | |||
| #define __set_PSPLIM(VALUE) (__arm_wsr("PSPLIM", (VALUE))) | |||
| #endif | |||
| #define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS")) | |||
| #define __TZ_set_CONTROL_NS(VALUE) (__arm_wsr("CONTROL_NS", (VALUE))) | |||
| #define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS")) | |||
| #define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE))) | |||
| #define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS")) | |||
| #define __TZ_set_MSP_NS(VALUE) (__arm_wsr("MSP_NS", (VALUE))) | |||
| #define __TZ_get_SP_NS() (__arm_rsr("SP_NS")) | |||
| #define __TZ_set_SP_NS(VALUE) (__arm_wsr("SP_NS", (VALUE))) | |||
| #define __TZ_get_PRIMASK_NS() (__arm_rsr("PRIMASK_NS")) | |||
| #define __TZ_set_PRIMASK_NS(VALUE) (__arm_wsr("PRIMASK_NS", (VALUE))) | |||
| #define __TZ_get_BASEPRI_NS() (__arm_rsr("BASEPRI_NS")) | |||
| #define __TZ_set_BASEPRI_NS(VALUE) (__arm_wsr("BASEPRI_NS", (VALUE))) | |||
| #define __TZ_get_FAULTMASK_NS() (__arm_rsr("FAULTMASK_NS")) | |||
| #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE))) | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure PSPLIM is RAZ/WI | |||
| #define __TZ_get_PSPLIM_NS() (0U) | |||
| #define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE)) | |||
| #else | |||
| #define __TZ_get_PSPLIM_NS() (__arm_rsr("PSPLIM_NS")) | |||
| #define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE))) | |||
| #endif | |||
| #define __TZ_get_MSPLIM_NS() (__arm_rsr("MSPLIM_NS")) | |||
| #define __TZ_set_MSPLIM_NS(VALUE) (__arm_wsr("MSPLIM_NS", (VALUE))) | |||
| #define __NOP __iar_builtin_no_operation | |||
| #define __CLZ __iar_builtin_CLZ | |||
| #define __CLREX __iar_builtin_CLREX | |||
| #define __DMB __iar_builtin_DMB | |||
| #define __DSB __iar_builtin_DSB | |||
| #define __ISB __iar_builtin_ISB | |||
| #define __LDREXB __iar_builtin_LDREXB | |||
| #define __LDREXH __iar_builtin_LDREXH | |||
| #define __LDREXW __iar_builtin_LDREX | |||
| #define __RBIT __iar_builtin_RBIT | |||
| #define __REV __iar_builtin_REV | |||
| #define __REV16 __iar_builtin_REV16 | |||
| __IAR_FT int16_t __REVSH(int16_t val) | |||
| { | |||
| return (int16_t) __iar_builtin_REVSH(val); | |||
| } | |||
| #define __ROR __iar_builtin_ROR | |||
| #define __RRX __iar_builtin_RRX | |||
| #define __SEV __iar_builtin_SEV | |||
| #if !__IAR_M0_FAMILY | |||
| #define __SSAT __iar_builtin_SSAT | |||
| #endif | |||
| #define __STREXB __iar_builtin_STREXB | |||
| #define __STREXH __iar_builtin_STREXH | |||
| #define __STREXW __iar_builtin_STREX | |||
| #if !__IAR_M0_FAMILY | |||
| #define __USAT __iar_builtin_USAT | |||
| #endif | |||
| #define __WFE __iar_builtin_WFE | |||
| #define __WFI __iar_builtin_WFI | |||
| #if __ARM_MEDIA__ | |||
| #define __SADD8 __iar_builtin_SADD8 | |||
| #define __QADD8 __iar_builtin_QADD8 | |||
| #define __SHADD8 __iar_builtin_SHADD8 | |||
| #define __UADD8 __iar_builtin_UADD8 | |||
| #define __UQADD8 __iar_builtin_UQADD8 | |||
| #define __UHADD8 __iar_builtin_UHADD8 | |||
| #define __SSUB8 __iar_builtin_SSUB8 | |||
| #define __QSUB8 __iar_builtin_QSUB8 | |||
| #define __SHSUB8 __iar_builtin_SHSUB8 | |||
| #define __USUB8 __iar_builtin_USUB8 | |||
| #define __UQSUB8 __iar_builtin_UQSUB8 | |||
| #define __UHSUB8 __iar_builtin_UHSUB8 | |||
| #define __SADD16 __iar_builtin_SADD16 | |||
| #define __QADD16 __iar_builtin_QADD16 | |||
| #define __SHADD16 __iar_builtin_SHADD16 | |||
| #define __UADD16 __iar_builtin_UADD16 | |||
| #define __UQADD16 __iar_builtin_UQADD16 | |||
| #define __UHADD16 __iar_builtin_UHADD16 | |||
| #define __SSUB16 __iar_builtin_SSUB16 | |||
| #define __QSUB16 __iar_builtin_QSUB16 | |||
| #define __SHSUB16 __iar_builtin_SHSUB16 | |||
| #define __USUB16 __iar_builtin_USUB16 | |||
| #define __UQSUB16 __iar_builtin_UQSUB16 | |||
| #define __UHSUB16 __iar_builtin_UHSUB16 | |||
| #define __SASX __iar_builtin_SASX | |||
| #define __QASX __iar_builtin_QASX | |||
| #define __SHASX __iar_builtin_SHASX | |||
| #define __UASX __iar_builtin_UASX | |||
| #define __UQASX __iar_builtin_UQASX | |||
| #define __UHASX __iar_builtin_UHASX | |||
| #define __SSAX __iar_builtin_SSAX | |||
| #define __QSAX __iar_builtin_QSAX | |||
| #define __SHSAX __iar_builtin_SHSAX | |||
| #define __USAX __iar_builtin_USAX | |||
| #define __UQSAX __iar_builtin_UQSAX | |||
| #define __UHSAX __iar_builtin_UHSAX | |||
| #define __USAD8 __iar_builtin_USAD8 | |||
| #define __USADA8 __iar_builtin_USADA8 | |||
| #define __SSAT16 __iar_builtin_SSAT16 | |||
| #define __USAT16 __iar_builtin_USAT16 | |||
| #define __UXTB16 __iar_builtin_UXTB16 | |||
| #define __UXTAB16 __iar_builtin_UXTAB16 | |||
| #define __SXTB16 __iar_builtin_SXTB16 | |||
| #define __SXTAB16 __iar_builtin_SXTAB16 | |||
| #define __SMUAD __iar_builtin_SMUAD | |||
| #define __SMUADX __iar_builtin_SMUADX | |||
| #define __SMMLA __iar_builtin_SMMLA | |||
| #define __SMLAD __iar_builtin_SMLAD | |||
| #define __SMLADX __iar_builtin_SMLADX | |||
| #define __SMLALD __iar_builtin_SMLALD | |||
| #define __SMLALDX __iar_builtin_SMLALDX | |||
| #define __SMUSD __iar_builtin_SMUSD | |||
| #define __SMUSDX __iar_builtin_SMUSDX | |||
| #define __SMLSD __iar_builtin_SMLSD | |||
| #define __SMLSDX __iar_builtin_SMLSDX | |||
| #define __SMLSLD __iar_builtin_SMLSLD | |||
| #define __SMLSLDX __iar_builtin_SMLSLDX | |||
| #define __SEL __iar_builtin_SEL | |||
| #define __QADD __iar_builtin_QADD | |||
| #define __QSUB __iar_builtin_QSUB | |||
| #define __PKHBT __iar_builtin_PKHBT | |||
| #define __PKHTB __iar_builtin_PKHTB | |||
| #endif | |||
| #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */ | |||
| #if __IAR_M0_FAMILY | |||
| /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */ | |||
| #define __CLZ __cmsis_iar_clz_not_active | |||
| #define __SSAT __cmsis_iar_ssat_not_active | |||
| #define __USAT __cmsis_iar_usat_not_active | |||
| #define __RBIT __cmsis_iar_rbit_not_active | |||
| #define __get_APSR __cmsis_iar_get_APSR_not_active | |||
| #endif | |||
| #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) )) | |||
| #define __get_FPSCR __cmsis_iar_get_FPSR_not_active | |||
| #define __set_FPSCR __cmsis_iar_set_FPSR_not_active | |||
| #endif | |||
| #ifdef __INTRINSICS_INCLUDED | |||
| #error intrinsics.h is already included previously! | |||
| #endif | |||
| #include <intrinsics.h> | |||
| #if __IAR_M0_FAMILY | |||
| /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */ | |||
| #undef __CLZ | |||
| #undef __SSAT | |||
| #undef __USAT | |||
| #undef __RBIT | |||
| #undef __get_APSR | |||
| __STATIC_INLINE uint8_t __CLZ(uint32_t data) | |||
| { | |||
| if (data == 0U) { return 32U; } | |||
| uint32_t count = 0U; | |||
| uint32_t mask = 0x80000000U; | |||
| while ((data & mask) == 0U) | |||
| { | |||
| count += 1U; | |||
| mask = mask >> 1U; | |||
| } | |||
| return count; | |||
| } | |||
| __STATIC_INLINE uint32_t __RBIT(uint32_t v) | |||
| { | |||
| uint8_t sc = 31U; | |||
| uint32_t r = v; | |||
| for (v >>= 1U; v; v >>= 1U) | |||
| { | |||
| r <<= 1U; | |||
| r |= v & 1U; | |||
| sc--; | |||
| } | |||
| return (r << sc); | |||
| } | |||
| __STATIC_INLINE uint32_t __get_APSR(void) | |||
| { | |||
| uint32_t res; | |||
| __asm("MRS %0,APSR" : "=r" (res)); | |||
| return res; | |||
| } | |||
| #endif | |||
| #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ | |||
| (defined (__FPU_USED ) && (__FPU_USED == 1U)) )) | |||
| #undef __get_FPSCR | |||
| #undef __set_FPSCR | |||
| #define __get_FPSCR() (0) | |||
| #define __set_FPSCR(VALUE) ((void)VALUE) | |||
| #endif | |||
| #pragma diag_suppress=Pe940 | |||
| #pragma diag_suppress=Pe177 | |||
| #define __enable_irq __enable_interrupt | |||
| #define __disable_irq __disable_interrupt | |||
| #define __NOP __no_operation | |||
| #define __get_xPSR __get_PSR | |||
| #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0) | |||
| __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr) | |||
| { | |||
| return __LDREX((unsigned long *)ptr); | |||
| } | |||
| __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr) | |||
| { | |||
| return __STREX(value, (unsigned long *)ptr); | |||
| } | |||
| #endif | |||
| /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */ | |||
| #if (__CORTEX_M >= 0x03) | |||
| __IAR_FT uint32_t __RRX(uint32_t value) | |||
| { | |||
| uint32_t result; | |||
| __ASM volatile("RRX %0, %1" : "=r"(result) : "r" (value)); | |||
| return(result); | |||
| } | |||
| __IAR_FT void __set_BASEPRI_MAX(uint32_t value) | |||
| { | |||
| __asm volatile("MSR BASEPRI_MAX,%0"::"r" (value)); | |||
| } | |||
| #define __enable_fault_irq __enable_fiq | |||
| #define __disable_fault_irq __disable_fiq | |||
| #endif /* (__CORTEX_M >= 0x03) */ | |||
| __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2) | |||
| { | |||
| return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2)); | |||
| } | |||
| #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ | |||
| (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) | |||
| __IAR_FT uint32_t __get_MSPLIM(void) | |||
| { | |||
| uint32_t res; | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure MSPLIM is RAZ/WI | |||
| res = 0U; | |||
| #else | |||
| __asm volatile("MRS %0,MSPLIM" : "=r" (res)); | |||
| #endif | |||
| return res; | |||
| } | |||
| __IAR_FT void __set_MSPLIM(uint32_t value) | |||
| { | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure MSPLIM is RAZ/WI | |||
| (void)value; | |||
| #else | |||
| __asm volatile("MSR MSPLIM,%0" :: "r" (value)); | |||
| #endif | |||
| } | |||
| __IAR_FT uint32_t __get_PSPLIM(void) | |||
| { | |||
| uint32_t res; | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure PSPLIM is RAZ/WI | |||
| res = 0U; | |||
| #else | |||
| __asm volatile("MRS %0,PSPLIM" : "=r" (res)); | |||
| #endif | |||
| return res; | |||
| } | |||
| __IAR_FT void __set_PSPLIM(uint32_t value) | |||
| { | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure PSPLIM is RAZ/WI | |||
| (void)value; | |||
| #else | |||
| __asm volatile("MSR PSPLIM,%0" :: "r" (value)); | |||
| #endif | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_CONTROL_NS(void) | |||
| { | |||
| uint32_t res; | |||
| __asm volatile("MRS %0,CONTROL_NS" : "=r" (res)); | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_CONTROL_NS(uint32_t value) | |||
| { | |||
| __asm volatile("MSR CONTROL_NS,%0" :: "r" (value)); | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_PSP_NS(void) | |||
| { | |||
| uint32_t res; | |||
| __asm volatile("MRS %0,PSP_NS" : "=r" (res)); | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_PSP_NS(uint32_t value) | |||
| { | |||
| __asm volatile("MSR PSP_NS,%0" :: "r" (value)); | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_MSP_NS(void) | |||
| { | |||
| uint32_t res; | |||
| __asm volatile("MRS %0,MSP_NS" : "=r" (res)); | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_MSP_NS(uint32_t value) | |||
| { | |||
| __asm volatile("MSR MSP_NS,%0" :: "r" (value)); | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_SP_NS(void) | |||
| { | |||
| uint32_t res; | |||
| __asm volatile("MRS %0,SP_NS" : "=r" (res)); | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_SP_NS(uint32_t value) | |||
| { | |||
| __asm volatile("MSR SP_NS,%0" :: "r" (value)); | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_PRIMASK_NS(void) | |||
| { | |||
| uint32_t res; | |||
| __asm volatile("MRS %0,PRIMASK_NS" : "=r" (res)); | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_PRIMASK_NS(uint32_t value) | |||
| { | |||
| __asm volatile("MSR PRIMASK_NS,%0" :: "r" (value)); | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_BASEPRI_NS(void) | |||
| { | |||
| uint32_t res; | |||
| __asm volatile("MRS %0,BASEPRI_NS" : "=r" (res)); | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_BASEPRI_NS(uint32_t value) | |||
| { | |||
| __asm volatile("MSR BASEPRI_NS,%0" :: "r" (value)); | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_FAULTMASK_NS(void) | |||
| { | |||
| uint32_t res; | |||
| __asm volatile("MRS %0,FAULTMASK_NS" : "=r" (res)); | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_FAULTMASK_NS(uint32_t value) | |||
| { | |||
| __asm volatile("MSR FAULTMASK_NS,%0" :: "r" (value)); | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_PSPLIM_NS(void) | |||
| { | |||
| uint32_t res; | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure PSPLIM is RAZ/WI | |||
| res = 0U; | |||
| #else | |||
| __asm volatile("MRS %0,PSPLIM_NS" : "=r" (res)); | |||
| #endif | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_PSPLIM_NS(uint32_t value) | |||
| { | |||
| #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ | |||
| (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) | |||
| // without main extensions, the non-secure PSPLIM is RAZ/WI | |||
| (void)value; | |||
| #else | |||
| __asm volatile("MSR PSPLIM_NS,%0" :: "r" (value)); | |||
| #endif | |||
| } | |||
| __IAR_FT uint32_t __TZ_get_MSPLIM_NS(void) | |||
| { | |||
| uint32_t res; | |||
| __asm volatile("MRS %0,MSPLIM_NS" : "=r" (res)); | |||
| return res; | |||
| } | |||
| __IAR_FT void __TZ_set_MSPLIM_NS(uint32_t value) | |||
| { | |||
| __asm volatile("MSR MSPLIM_NS,%0" :: "r" (value)); | |||
| } | |||
| #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */ | |||
| #endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */ | |||
| #define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value)) | |||
| #if __IAR_M0_FAMILY | |||
| __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) | |||
| { | |||
| if ((sat >= 1U) && (sat <= 32U)) | |||
| { | |||
| const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); | |||
| const int32_t min = -1 - max ; | |||
| if (val > max) | |||
| { | |||
| return max; | |||
| } | |||
| else if (val < min) | |||
| { | |||
| return min; | |||
| } | |||
| } | |||
| return val; | |||
| } | |||
| __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) | |||
| { | |||
| if (sat <= 31U) | |||
| { | |||
| const uint32_t max = ((1U << sat) - 1U); | |||
| if (val > (int32_t)max) | |||
| { | |||
| return max; | |||
| } | |||
| else if (val < 0) | |||
| { | |||
| return 0U; | |||
| } | |||
| } | |||
| return (uint32_t)val; | |||
| } | |||
| #endif | |||
| #if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */ | |||
| __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); | |||
| return ((uint8_t)res); | |||
| } | |||
| __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); | |||
| return ((uint16_t)res); | |||
| } | |||
| __IAR_FT uint32_t __LDRT(volatile uint32_t *addr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); | |||
| return res; | |||
| } | |||
| __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr) | |||
| { | |||
| __ASM volatile ("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); | |||
| } | |||
| __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr) | |||
| { | |||
| __ASM volatile ("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); | |||
| } | |||
| __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr) | |||
| { | |||
| __ASM volatile ("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory"); | |||
| } | |||
| #endif /* (__CORTEX_M >= 0x03) */ | |||
| #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ | |||
| (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) | |||
| __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); | |||
| return ((uint8_t)res); | |||
| } | |||
| __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); | |||
| return ((uint16_t)res); | |||
| } | |||
| __IAR_FT uint32_t __LDA(volatile uint32_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); | |||
| return res; | |||
| } | |||
| __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr) | |||
| { | |||
| __ASM volatile ("STLB %1, [%0]" :: "r" (ptr), "r" (value) : "memory"); | |||
| } | |||
| __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr) | |||
| { | |||
| __ASM volatile ("STLH %1, [%0]" :: "r" (ptr), "r" (value) : "memory"); | |||
| } | |||
| __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr) | |||
| { | |||
| __ASM volatile ("STL %1, [%0]" :: "r" (ptr), "r" (value) : "memory"); | |||
| } | |||
| __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); | |||
| return ((uint8_t)res); | |||
| } | |||
| __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); | |||
| return ((uint16_t)res); | |||
| } | |||
| __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); | |||
| return res; | |||
| } | |||
| __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory"); | |||
| return res; | |||
| } | |||
| __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory"); | |||
| return res; | |||
| } | |||
| __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) | |||
| { | |||
| uint32_t res; | |||
| __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory"); | |||
| return res; | |||
| } | |||
| #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */ | |||
| #undef __IAR_FT | |||
| #undef __IAR_M0_FAMILY | |||
| #undef __ICCARM_V8 | |||
| #pragma diag_default=Pe940 | |||
| #pragma diag_default=Pe177 | |||
| #define __SXTB16_RORn(ARG1, ARG2) __SXTB16(__ROR(ARG1, ARG2)) | |||
| #endif /* __CMSIS_ICCARM_H__ */ | |||
| @@ -0,0 +1,39 @@ | |||
| /**************************************************************************//** | |||
| * @file cmsis_version.h | |||
| * @brief CMSIS Core(M) Version definitions | |||
| * @version V5.0.4 | |||
| * @date 23. July 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 ARM Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef __CMSIS_VERSION_H | |||
| #define __CMSIS_VERSION_H | |||
| /* CMSIS Version definitions */ | |||
| #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ | |||
| #define __CM_CMSIS_VERSION_SUB ( 4U) /*!< [15:0] CMSIS Core(M) sub version */ | |||
| #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ | |||
| __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ | |||
| #endif | |||
| @@ -0,0 +1,952 @@ | |||
| /**************************************************************************//** | |||
| * @file core_cm0.h | |||
| * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File | |||
| * @version V5.0.8 | |||
| * @date 21. August 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2019 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef __CORE_CM0_H_GENERIC | |||
| #define __CORE_CM0_H_GENERIC | |||
| #include <stdint.h> | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /** | |||
| \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions | |||
| CMSIS violates the following MISRA-C:2004 rules: | |||
| \li Required Rule 8.5, object/function definition in header file.<br> | |||
| Function definitions in header files are used to allow 'inlining'. | |||
| \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br> | |||
| Unions are used for effective representation of core registers. | |||
| \li Advisory Rule 19.7, Function-like macro defined.<br> | |||
| Function-like macros are used to allow more efficient code. | |||
| */ | |||
| /******************************************************************************* | |||
| * CMSIS definitions | |||
| ******************************************************************************/ | |||
| /** | |||
| \ingroup Cortex_M0 | |||
| @{ | |||
| */ | |||
| #include "cmsis_version.h" | |||
| /* CMSIS CM0 definitions */ | |||
| #define __CM0_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ | |||
| #define __CM0_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ | |||
| #define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16U) | \ | |||
| __CM0_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ | |||
| #define __CORTEX_M (0U) /*!< Cortex-M Core */ | |||
| /** __FPU_USED indicates whether an FPU is used or not. | |||
| This core does not support an FPU at all | |||
| */ | |||
| #define __FPU_USED 0U | |||
| #if defined ( __CC_ARM ) | |||
| #if defined __TARGET_FPU_VFP | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) | |||
| #if defined __ARM_FP | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __GNUC__ ) | |||
| #if defined (__VFP_FP__) && !defined(__SOFTFP__) | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __ICCARM__ ) | |||
| #if defined __ARMVFP__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __TI_ARM__ ) | |||
| #if defined __TI_VFP_SUPPORT__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __TASKING__ ) | |||
| #if defined __FPU_VFP__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __CSMC__ ) | |||
| #if ( __CSMC__ & 0x400U) | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #endif | |||
| #include "cmsis_compiler.h" /* CMSIS compiler specific defines */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __CORE_CM0_H_GENERIC */ | |||
| #ifndef __CMSIS_GENERIC | |||
| #ifndef __CORE_CM0_H_DEPENDANT | |||
| #define __CORE_CM0_H_DEPENDANT | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* check device defines and use defaults */ | |||
| #if defined __CHECK_DEVICE_DEFINES | |||
| #ifndef __CM0_REV | |||
| #define __CM0_REV 0x0000U | |||
| #warning "__CM0_REV not defined in device header file; using default!" | |||
| #endif | |||
| #ifndef __NVIC_PRIO_BITS | |||
| #define __NVIC_PRIO_BITS 2U | |||
| #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" | |||
| #endif | |||
| #ifndef __Vendor_SysTickConfig | |||
| #define __Vendor_SysTickConfig 0U | |||
| #warning "__Vendor_SysTickConfig not defined in device header file; using default!" | |||
| #endif | |||
| #endif | |||
| /* IO definitions (access restrictions to peripheral registers) */ | |||
| /** | |||
| \defgroup CMSIS_glob_defs CMSIS Global Defines | |||
| <strong>IO Type Qualifiers</strong> are used | |||
| \li to specify the access to peripheral variables. | |||
| \li for automatic generation of peripheral register debug information. | |||
| */ | |||
| #ifdef __cplusplus | |||
| #define __I volatile /*!< Defines 'read only' permissions */ | |||
| #else | |||
| #define __I volatile const /*!< Defines 'read only' permissions */ | |||
| #endif | |||
| #define __O volatile /*!< Defines 'write only' permissions */ | |||
| #define __IO volatile /*!< Defines 'read / write' permissions */ | |||
| /* following defines should be used for structure members */ | |||
| #define __IM volatile const /*! Defines 'read only' structure member permissions */ | |||
| #define __OM volatile /*! Defines 'write only' structure member permissions */ | |||
| #define __IOM volatile /*! Defines 'read / write' structure member permissions */ | |||
| /*@} end of group Cortex_M0 */ | |||
| /******************************************************************************* | |||
| * Register Abstraction | |||
| Core Register contain: | |||
| - Core Register | |||
| - Core NVIC Register | |||
| - Core SCB Register | |||
| - Core SysTick Register | |||
| ******************************************************************************/ | |||
| /** | |||
| \defgroup CMSIS_core_register Defines and Type Definitions | |||
| \brief Type definitions and defines for Cortex-M processor based devices. | |||
| */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_CORE Status and Control Registers | |||
| \brief Core Register type definitions. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Union type to access the Application Program Status Register (APSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */ | |||
| uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ | |||
| uint32_t C:1; /*!< bit: 29 Carry condition code flag */ | |||
| uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ | |||
| uint32_t N:1; /*!< bit: 31 Negative condition code flag */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } APSR_Type; | |||
| /* APSR Register Definitions */ | |||
| #define APSR_N_Pos 31U /*!< APSR: N Position */ | |||
| #define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */ | |||
| #define APSR_Z_Pos 30U /*!< APSR: Z Position */ | |||
| #define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */ | |||
| #define APSR_C_Pos 29U /*!< APSR: C Position */ | |||
| #define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */ | |||
| #define APSR_V_Pos 28U /*!< APSR: V Position */ | |||
| #define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */ | |||
| /** | |||
| \brief Union type to access the Interrupt Program Status Register (IPSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ | |||
| uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } IPSR_Type; | |||
| /* IPSR Register Definitions */ | |||
| #define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */ | |||
| #define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */ | |||
| /** | |||
| \brief Union type to access the Special-Purpose Program Status Registers (xPSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ | |||
| uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ | |||
| uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ | |||
| uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */ | |||
| uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ | |||
| uint32_t C:1; /*!< bit: 29 Carry condition code flag */ | |||
| uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ | |||
| uint32_t N:1; /*!< bit: 31 Negative condition code flag */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } xPSR_Type; | |||
| /* xPSR Register Definitions */ | |||
| #define xPSR_N_Pos 31U /*!< xPSR: N Position */ | |||
| #define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */ | |||
| #define xPSR_Z_Pos 30U /*!< xPSR: Z Position */ | |||
| #define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */ | |||
| #define xPSR_C_Pos 29U /*!< xPSR: C Position */ | |||
| #define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */ | |||
| #define xPSR_V_Pos 28U /*!< xPSR: V Position */ | |||
| #define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */ | |||
| #define xPSR_T_Pos 24U /*!< xPSR: T Position */ | |||
| #define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ | |||
| #define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ | |||
| #define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ | |||
| /** | |||
| \brief Union type to access the Control Registers (CONTROL). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t _reserved0:1; /*!< bit: 0 Reserved */ | |||
| uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ | |||
| uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } CONTROL_Type; | |||
| /* CONTROL Register Definitions */ | |||
| #define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ | |||
| #define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ | |||
| /*@} end of group CMSIS_CORE */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) | |||
| \brief Type definitions for the NVIC Registers | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ | |||
| uint32_t RESERVED0[31U]; | |||
| __IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ | |||
| uint32_t RESERVED1[31U]; | |||
| __IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ | |||
| uint32_t RESERVED2[31U]; | |||
| __IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ | |||
| uint32_t RESERVED3[31U]; | |||
| uint32_t RESERVED4[64U]; | |||
| __IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */ | |||
| } NVIC_Type; | |||
| /*@} end of group CMSIS_NVIC */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SCB System Control Block (SCB) | |||
| \brief Type definitions for the System Control Block Registers | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Control Block (SCB). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ | |||
| __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ | |||
| uint32_t RESERVED0; | |||
| __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ | |||
| __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ | |||
| __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ | |||
| uint32_t RESERVED1; | |||
| __IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ | |||
| __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ | |||
| } SCB_Type; | |||
| /* SCB CPUID Register Definitions */ | |||
| #define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */ | |||
| #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ | |||
| #define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */ | |||
| #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ | |||
| #define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */ | |||
| #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ | |||
| #define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */ | |||
| #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ | |||
| #define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */ | |||
| #define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */ | |||
| /* SCB Interrupt Control State Register Definitions */ | |||
| #define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */ | |||
| #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ | |||
| #define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */ | |||
| #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ | |||
| #define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */ | |||
| #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ | |||
| #define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */ | |||
| #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ | |||
| #define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */ | |||
| #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ | |||
| #define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */ | |||
| #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ | |||
| #define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */ | |||
| #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ | |||
| #define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */ | |||
| #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ | |||
| #define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */ | |||
| #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ | |||
| /* SCB Application Interrupt and Reset Control Register Definitions */ | |||
| #define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */ | |||
| #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ | |||
| #define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */ | |||
| #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ | |||
| #define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */ | |||
| #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ | |||
| #define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */ | |||
| #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ | |||
| #define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */ | |||
| #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ | |||
| /* SCB System Control Register Definitions */ | |||
| #define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */ | |||
| #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ | |||
| #define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */ | |||
| #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ | |||
| #define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */ | |||
| #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ | |||
| /* SCB Configuration Control Register Definitions */ | |||
| #define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */ | |||
| #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ | |||
| #define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */ | |||
| #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ | |||
| /* SCB System Handler Control and State Register Definitions */ | |||
| #define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ | |||
| #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ | |||
| /*@} end of group CMSIS_SCB */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SysTick System Tick Timer (SysTick) | |||
| \brief Type definitions for the System Timer Registers. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Timer (SysTick). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ | |||
| __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ | |||
| __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ | |||
| __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ | |||
| } SysTick_Type; | |||
| /* SysTick Control / Status Register Definitions */ | |||
| #define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */ | |||
| #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ | |||
| #define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */ | |||
| #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ | |||
| #define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */ | |||
| #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ | |||
| #define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */ | |||
| #define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */ | |||
| /* SysTick Reload Register Definitions */ | |||
| #define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */ | |||
| #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */ | |||
| /* SysTick Current Register Definitions */ | |||
| #define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */ | |||
| #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */ | |||
| /* SysTick Calibration Register Definitions */ | |||
| #define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */ | |||
| #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ | |||
| #define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */ | |||
| #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ | |||
| #define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */ | |||
| #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */ | |||
| /*@} end of group CMSIS_SysTick */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) | |||
| \brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor. | |||
| Therefore they are not covered by the Cortex-M0 header file. | |||
| @{ | |||
| */ | |||
| /*@} end of group CMSIS_CoreDebug */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_core_bitfield Core register bit field macros | |||
| \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk). | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Mask and shift a bit field value for use in a register bit range. | |||
| \param[in] field Name of the register bit field. | |||
| \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. | |||
| \return Masked and shifted value. | |||
| */ | |||
| #define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) | |||
| /** | |||
| \brief Mask and shift a register value to extract a bit filed value. | |||
| \param[in] field Name of the register bit field. | |||
| \param[in] value Value of register. This parameter is interpreted as an uint32_t type. | |||
| \return Masked and shifted bit field value. | |||
| */ | |||
| #define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) | |||
| /*@} end of group CMSIS_core_bitfield */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_core_base Core Definitions | |||
| \brief Definitions for base addresses, unions, and structures. | |||
| @{ | |||
| */ | |||
| /* Memory mapping of Core Hardware */ | |||
| #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ | |||
| #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ | |||
| #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ | |||
| #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ | |||
| #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ | |||
| #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ | |||
| #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ | |||
| /*@} */ | |||
| /******************************************************************************* | |||
| * Hardware Abstraction Layer | |||
| Core Function Interface contains: | |||
| - Core NVIC Functions | |||
| - Core SysTick Functions | |||
| - Core Register Access Functions | |||
| ******************************************************************************/ | |||
| /** | |||
| \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference | |||
| */ | |||
| /* ########################## NVIC functions #################################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_NVICFunctions NVIC Functions | |||
| \brief Functions that manage interrupts and exceptions via the NVIC. | |||
| @{ | |||
| */ | |||
| #ifdef CMSIS_NVIC_VIRTUAL | |||
| #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE | |||
| #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" | |||
| #endif | |||
| #include CMSIS_NVIC_VIRTUAL_HEADER_FILE | |||
| #else | |||
| #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping | |||
| #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping | |||
| #define NVIC_EnableIRQ __NVIC_EnableIRQ | |||
| #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ | |||
| #define NVIC_DisableIRQ __NVIC_DisableIRQ | |||
| #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ | |||
| #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ | |||
| #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ | |||
| /*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M0 */ | |||
| #define NVIC_SetPriority __NVIC_SetPriority | |||
| #define NVIC_GetPriority __NVIC_GetPriority | |||
| #define NVIC_SystemReset __NVIC_SystemReset | |||
| #endif /* CMSIS_NVIC_VIRTUAL */ | |||
| #ifdef CMSIS_VECTAB_VIRTUAL | |||
| #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE | |||
| #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" | |||
| #endif | |||
| #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE | |||
| #else | |||
| #define NVIC_SetVector __NVIC_SetVector | |||
| #define NVIC_GetVector __NVIC_GetVector | |||
| #endif /* (CMSIS_VECTAB_VIRTUAL) */ | |||
| #define NVIC_USER_IRQ_OFFSET 16 | |||
| /* The following EXC_RETURN values are saved the LR on exception entry */ | |||
| #define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */ | |||
| #define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */ | |||
| #define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */ | |||
| /* Interrupt Priorities are WORD accessible only under Armv6-M */ | |||
| /* The following MACROS handle generation of the register offset and byte masks */ | |||
| #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL) | |||
| #define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) ) | |||
| #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) ) | |||
| #define __NVIC_SetPriorityGrouping(X) (void)(X) | |||
| #define __NVIC_GetPriorityGrouping() (0U) | |||
| /** | |||
| \brief Enable Interrupt | |||
| \details Enables a device specific interrupt in the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| __COMPILER_BARRIER(); | |||
| NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| __COMPILER_BARRIER(); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Interrupt Enable status | |||
| \details Returns a device specific interrupt enable status from the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \return 0 Interrupt is not enabled. | |||
| \return 1 Interrupt is enabled. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); | |||
| } | |||
| else | |||
| { | |||
| return(0U); | |||
| } | |||
| } | |||
| /** | |||
| \brief Disable Interrupt | |||
| \details Disables a device specific interrupt in the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Pending Interrupt | |||
| \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \return 0 Interrupt status is not pending. | |||
| \return 1 Interrupt status is pending. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); | |||
| } | |||
| else | |||
| { | |||
| return(0U); | |||
| } | |||
| } | |||
| /** | |||
| \brief Set Pending Interrupt | |||
| \details Sets the pending bit of a device specific interrupt in the NVIC pending register. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| } | |||
| } | |||
| /** | |||
| \brief Clear Pending Interrupt | |||
| \details Clears the pending bit of a device specific interrupt in the NVIC pending register. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| } | |||
| } | |||
| /** | |||
| \brief Set Interrupt Priority | |||
| \details Sets the priority of a device specific interrupt or a processor exception. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \param [in] priority Priority to set. | |||
| \note The priority cannot be set for every processor exception. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | | |||
| (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); | |||
| } | |||
| else | |||
| { | |||
| SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | | |||
| (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Interrupt Priority | |||
| \details Reads the priority of a device specific interrupt or a processor exception. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \return Interrupt Priority. | |||
| Value is aligned automatically to the implemented priority bits of the microcontroller. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); | |||
| } | |||
| else | |||
| { | |||
| return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); | |||
| } | |||
| } | |||
| /** | |||
| \brief Encode Priority | |||
| \details Encodes the priority for an interrupt with the given priority group, | |||
| preemptive priority value, and subpriority value. | |||
| In case of a conflict between priority grouping and available | |||
| priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. | |||
| \param [in] PriorityGroup Used priority group. | |||
| \param [in] PreemptPriority Preemptive priority value (starting from 0). | |||
| \param [in] SubPriority Subpriority value (starting from 0). | |||
| \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority(). | |||
| */ | |||
| __STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) | |||
| { | |||
| uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ | |||
| uint32_t PreemptPriorityBits; | |||
| uint32_t SubPriorityBits; | |||
| PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); | |||
| SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); | |||
| return ( | |||
| ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | | |||
| ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) | |||
| ); | |||
| } | |||
| /** | |||
| \brief Decode Priority | |||
| \details Decodes an interrupt priority value with a given priority group to | |||
| preemptive priority value and subpriority value. | |||
| In case of a conflict between priority grouping and available | |||
| priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. | |||
| \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority(). | |||
| \param [in] PriorityGroup Used priority group. | |||
| \param [out] pPreemptPriority Preemptive priority value (starting from 0). | |||
| \param [out] pSubPriority Subpriority value (starting from 0). | |||
| */ | |||
| __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority) | |||
| { | |||
| uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ | |||
| uint32_t PreemptPriorityBits; | |||
| uint32_t SubPriorityBits; | |||
| PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); | |||
| SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); | |||
| *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); | |||
| *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL); | |||
| } | |||
| /** | |||
| \brief Set Interrupt Vector | |||
| \details Sets an interrupt vector in SRAM based interrupt vector table. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| Address 0 must be mapped to SRAM. | |||
| \param [in] IRQn Interrupt number | |||
| \param [in] vector Address of interrupt handler function | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) | |||
| { | |||
| uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */ | |||
| *(vectors + (int32_t)IRQn) = vector; /* use pointer arithmetic to access vector */ | |||
| /* ARM Application Note 321 states that the M0 does not require the architectural barrier */ | |||
| } | |||
| /** | |||
| \brief Get Interrupt Vector | |||
| \details Reads an interrupt vector from interrupt vector table. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \return Address of interrupt handler function | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) | |||
| { | |||
| uint32_t *vectors = (uint32_t *)(NVIC_USER_IRQ_OFFSET << 2); /* point to 1st user interrupt */ | |||
| return *(vectors + (int32_t)IRQn); /* use pointer arithmetic to access vector */ | |||
| } | |||
| /** | |||
| \brief System Reset | |||
| \details Initiates a system reset request to reset the MCU. | |||
| */ | |||
| __NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) | |||
| { | |||
| __DSB(); /* Ensure all outstanding memory accesses included | |||
| buffered write are completed before reset */ | |||
| SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | | |||
| SCB_AIRCR_SYSRESETREQ_Msk); | |||
| __DSB(); /* Ensure completion of memory access */ | |||
| for(;;) /* wait until reset */ | |||
| { | |||
| __NOP(); | |||
| } | |||
| } | |||
| /*@} end of CMSIS_Core_NVICFunctions */ | |||
| /* ########################## FPU functions #################################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_FpuFunctions FPU Functions | |||
| \brief Function that provides FPU type. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief get FPU type | |||
| \details returns the FPU type | |||
| \returns | |||
| - \b 0: No FPU | |||
| - \b 1: Single precision FPU | |||
| - \b 2: Double + Single precision FPU | |||
| */ | |||
| __STATIC_INLINE uint32_t SCB_GetFPUType(void) | |||
| { | |||
| return 0U; /* No FPU */ | |||
| } | |||
| /*@} end of CMSIS_Core_FpuFunctions */ | |||
| /* ################################## SysTick function ############################################ */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_SysTickFunctions SysTick Functions | |||
| \brief Functions that configure the System. | |||
| @{ | |||
| */ | |||
| #if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) | |||
| /** | |||
| \brief System Tick Configuration | |||
| \details Initializes the System Timer and its interrupt, and starts the System Tick Timer. | |||
| Counter is in free running mode to generate periodic interrupts. | |||
| \param [in] ticks Number of ticks between two interrupts. | |||
| \return 0 Function succeeded. | |||
| \return 1 Function failed. | |||
| \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the | |||
| function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b> | |||
| must contain a vendor-specific implementation of this function. | |||
| */ | |||
| __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) | |||
| { | |||
| if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) | |||
| { | |||
| return (1UL); /* Reload value impossible */ | |||
| } | |||
| SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ | |||
| NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ | |||
| SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ | |||
| SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | | |||
| SysTick_CTRL_TICKINT_Msk | | |||
| SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ | |||
| return (0UL); /* Function successful */ | |||
| } | |||
| #endif | |||
| /*@} end of CMSIS_Core_SysTickFunctions */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __CORE_CM0_H_DEPENDANT */ | |||
| #endif /* __CMSIS_GENERIC */ | |||
| @@ -0,0 +1,979 @@ | |||
| /**************************************************************************//** | |||
| * @file core_cm1.h | |||
| * @brief CMSIS Cortex-M1 Core Peripheral Access Layer Header File | |||
| * @version V1.0.1 | |||
| * @date 12. November 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2009-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef __CORE_CM1_H_GENERIC | |||
| #define __CORE_CM1_H_GENERIC | |||
| #include <stdint.h> | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /** | |||
| \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions | |||
| CMSIS violates the following MISRA-C:2004 rules: | |||
| \li Required Rule 8.5, object/function definition in header file.<br> | |||
| Function definitions in header files are used to allow 'inlining'. | |||
| \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br> | |||
| Unions are used for effective representation of core registers. | |||
| \li Advisory Rule 19.7, Function-like macro defined.<br> | |||
| Function-like macros are used to allow more efficient code. | |||
| */ | |||
| /******************************************************************************* | |||
| * CMSIS definitions | |||
| ******************************************************************************/ | |||
| /** | |||
| \ingroup Cortex_M1 | |||
| @{ | |||
| */ | |||
| #include "cmsis_version.h" | |||
| /* CMSIS CM1 definitions */ | |||
| #define __CM1_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */ | |||
| #define __CM1_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */ | |||
| #define __CM1_CMSIS_VERSION ((__CM1_CMSIS_VERSION_MAIN << 16U) | \ | |||
| __CM1_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */ | |||
| #define __CORTEX_M (1U) /*!< Cortex-M Core */ | |||
| /** __FPU_USED indicates whether an FPU is used or not. | |||
| This core does not support an FPU at all | |||
| */ | |||
| #define __FPU_USED 0U | |||
| #if defined ( __CC_ARM ) | |||
| #if defined __TARGET_FPU_VFP | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) | |||
| #if defined __ARM_FP | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __GNUC__ ) | |||
| #if defined (__VFP_FP__) && !defined(__SOFTFP__) | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __ICCARM__ ) | |||
| #if defined __ARMVFP__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __TI_ARM__ ) | |||
| #if defined __TI_VFP_SUPPORT__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __TASKING__ ) | |||
| #if defined __FPU_VFP__ | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #elif defined ( __CSMC__ ) | |||
| #if ( __CSMC__ & 0x400U) | |||
| #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" | |||
| #endif | |||
| #endif | |||
| #include "cmsis_compiler.h" /* CMSIS compiler specific defines */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __CORE_CM1_H_GENERIC */ | |||
| #ifndef __CMSIS_GENERIC | |||
| #ifndef __CORE_CM1_H_DEPENDANT | |||
| #define __CORE_CM1_H_DEPENDANT | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| /* check device defines and use defaults */ | |||
| #if defined __CHECK_DEVICE_DEFINES | |||
| #ifndef __CM1_REV | |||
| #define __CM1_REV 0x0100U | |||
| #warning "__CM1_REV not defined in device header file; using default!" | |||
| #endif | |||
| #ifndef __NVIC_PRIO_BITS | |||
| #define __NVIC_PRIO_BITS 2U | |||
| #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" | |||
| #endif | |||
| #ifndef __Vendor_SysTickConfig | |||
| #define __Vendor_SysTickConfig 0U | |||
| #warning "__Vendor_SysTickConfig not defined in device header file; using default!" | |||
| #endif | |||
| #endif | |||
| /* IO definitions (access restrictions to peripheral registers) */ | |||
| /** | |||
| \defgroup CMSIS_glob_defs CMSIS Global Defines | |||
| <strong>IO Type Qualifiers</strong> are used | |||
| \li to specify the access to peripheral variables. | |||
| \li for automatic generation of peripheral register debug information. | |||
| */ | |||
| #ifdef __cplusplus | |||
| #define __I volatile /*!< Defines 'read only' permissions */ | |||
| #else | |||
| #define __I volatile const /*!< Defines 'read only' permissions */ | |||
| #endif | |||
| #define __O volatile /*!< Defines 'write only' permissions */ | |||
| #define __IO volatile /*!< Defines 'read / write' permissions */ | |||
| /* following defines should be used for structure members */ | |||
| #define __IM volatile const /*! Defines 'read only' structure member permissions */ | |||
| #define __OM volatile /*! Defines 'write only' structure member permissions */ | |||
| #define __IOM volatile /*! Defines 'read / write' structure member permissions */ | |||
| /*@} end of group Cortex_M1 */ | |||
| /******************************************************************************* | |||
| * Register Abstraction | |||
| Core Register contain: | |||
| - Core Register | |||
| - Core NVIC Register | |||
| - Core SCB Register | |||
| - Core SysTick Register | |||
| ******************************************************************************/ | |||
| /** | |||
| \defgroup CMSIS_core_register Defines and Type Definitions | |||
| \brief Type definitions and defines for Cortex-M processor based devices. | |||
| */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_CORE Status and Control Registers | |||
| \brief Core Register type definitions. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Union type to access the Application Program Status Register (APSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */ | |||
| uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ | |||
| uint32_t C:1; /*!< bit: 29 Carry condition code flag */ | |||
| uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ | |||
| uint32_t N:1; /*!< bit: 31 Negative condition code flag */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } APSR_Type; | |||
| /* APSR Register Definitions */ | |||
| #define APSR_N_Pos 31U /*!< APSR: N Position */ | |||
| #define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */ | |||
| #define APSR_Z_Pos 30U /*!< APSR: Z Position */ | |||
| #define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */ | |||
| #define APSR_C_Pos 29U /*!< APSR: C Position */ | |||
| #define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */ | |||
| #define APSR_V_Pos 28U /*!< APSR: V Position */ | |||
| #define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */ | |||
| /** | |||
| \brief Union type to access the Interrupt Program Status Register (IPSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ | |||
| uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } IPSR_Type; | |||
| /* IPSR Register Definitions */ | |||
| #define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */ | |||
| #define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */ | |||
| /** | |||
| \brief Union type to access the Special-Purpose Program Status Registers (xPSR). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ | |||
| uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ | |||
| uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ | |||
| uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */ | |||
| uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ | |||
| uint32_t C:1; /*!< bit: 29 Carry condition code flag */ | |||
| uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ | |||
| uint32_t N:1; /*!< bit: 31 Negative condition code flag */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } xPSR_Type; | |||
| /* xPSR Register Definitions */ | |||
| #define xPSR_N_Pos 31U /*!< xPSR: N Position */ | |||
| #define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */ | |||
| #define xPSR_Z_Pos 30U /*!< xPSR: Z Position */ | |||
| #define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */ | |||
| #define xPSR_C_Pos 29U /*!< xPSR: C Position */ | |||
| #define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */ | |||
| #define xPSR_V_Pos 28U /*!< xPSR: V Position */ | |||
| #define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */ | |||
| #define xPSR_T_Pos 24U /*!< xPSR: T Position */ | |||
| #define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ | |||
| #define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */ | |||
| #define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */ | |||
| /** | |||
| \brief Union type to access the Control Registers (CONTROL). | |||
| */ | |||
| typedef union | |||
| { | |||
| struct | |||
| { | |||
| uint32_t _reserved0:1; /*!< bit: 0 Reserved */ | |||
| uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ | |||
| uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */ | |||
| } b; /*!< Structure used for bit access */ | |||
| uint32_t w; /*!< Type used for word access */ | |||
| } CONTROL_Type; | |||
| /* CONTROL Register Definitions */ | |||
| #define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ | |||
| #define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ | |||
| /*@} end of group CMSIS_CORE */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) | |||
| \brief Type definitions for the NVIC Registers | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ | |||
| uint32_t RESERVED0[31U]; | |||
| __IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ | |||
| uint32_t RSERVED1[31U]; | |||
| __IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ | |||
| uint32_t RESERVED2[31U]; | |||
| __IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ | |||
| uint32_t RESERVED3[31U]; | |||
| uint32_t RESERVED4[64U]; | |||
| __IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */ | |||
| } NVIC_Type; | |||
| /*@} end of group CMSIS_NVIC */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SCB System Control Block (SCB) | |||
| \brief Type definitions for the System Control Block Registers | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Control Block (SCB). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ | |||
| __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ | |||
| uint32_t RESERVED0; | |||
| __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ | |||
| __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ | |||
| __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ | |||
| uint32_t RESERVED1; | |||
| __IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ | |||
| __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ | |||
| } SCB_Type; | |||
| /* SCB CPUID Register Definitions */ | |||
| #define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */ | |||
| #define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ | |||
| #define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */ | |||
| #define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ | |||
| #define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */ | |||
| #define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ | |||
| #define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */ | |||
| #define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ | |||
| #define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */ | |||
| #define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */ | |||
| /* SCB Interrupt Control State Register Definitions */ | |||
| #define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */ | |||
| #define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ | |||
| #define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */ | |||
| #define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ | |||
| #define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */ | |||
| #define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ | |||
| #define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */ | |||
| #define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ | |||
| #define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */ | |||
| #define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ | |||
| #define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */ | |||
| #define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ | |||
| #define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */ | |||
| #define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ | |||
| #define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */ | |||
| #define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ | |||
| #define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */ | |||
| #define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */ | |||
| /* SCB Application Interrupt and Reset Control Register Definitions */ | |||
| #define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */ | |||
| #define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ | |||
| #define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */ | |||
| #define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ | |||
| #define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */ | |||
| #define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ | |||
| #define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */ | |||
| #define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ | |||
| #define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */ | |||
| #define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ | |||
| /* SCB System Control Register Definitions */ | |||
| #define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */ | |||
| #define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ | |||
| #define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */ | |||
| #define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ | |||
| #define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */ | |||
| #define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ | |||
| /* SCB Configuration Control Register Definitions */ | |||
| #define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */ | |||
| #define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ | |||
| #define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */ | |||
| #define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ | |||
| /* SCB System Handler Control and State Register Definitions */ | |||
| #define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ | |||
| #define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ | |||
| /*@} end of group CMSIS_SCB */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB) | |||
| \brief Type definitions for the System Control and ID Register not in the SCB | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Control and ID Register not in the SCB. | |||
| */ | |||
| typedef struct | |||
| { | |||
| uint32_t RESERVED0[2U]; | |||
| __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ | |||
| } SCnSCB_Type; | |||
| /* Auxiliary Control Register Definitions */ | |||
| #define SCnSCB_ACTLR_ITCMUAEN_Pos 4U /*!< ACTLR: Instruction TCM Upper Alias Enable Position */ | |||
| #define SCnSCB_ACTLR_ITCMUAEN_Msk (1UL << SCnSCB_ACTLR_ITCMUAEN_Pos) /*!< ACTLR: Instruction TCM Upper Alias Enable Mask */ | |||
| #define SCnSCB_ACTLR_ITCMLAEN_Pos 3U /*!< ACTLR: Instruction TCM Lower Alias Enable Position */ | |||
| #define SCnSCB_ACTLR_ITCMLAEN_Msk (1UL << SCnSCB_ACTLR_ITCMLAEN_Pos) /*!< ACTLR: Instruction TCM Lower Alias Enable Mask */ | |||
| /*@} end of group CMSIS_SCnotSCB */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_SysTick System Tick Timer (SysTick) | |||
| \brief Type definitions for the System Timer Registers. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Structure type to access the System Timer (SysTick). | |||
| */ | |||
| typedef struct | |||
| { | |||
| __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ | |||
| __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ | |||
| __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ | |||
| __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ | |||
| } SysTick_Type; | |||
| /* SysTick Control / Status Register Definitions */ | |||
| #define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */ | |||
| #define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ | |||
| #define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */ | |||
| #define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ | |||
| #define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */ | |||
| #define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ | |||
| #define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */ | |||
| #define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */ | |||
| /* SysTick Reload Register Definitions */ | |||
| #define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */ | |||
| #define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */ | |||
| /* SysTick Current Register Definitions */ | |||
| #define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */ | |||
| #define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */ | |||
| /* SysTick Calibration Register Definitions */ | |||
| #define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */ | |||
| #define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ | |||
| #define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */ | |||
| #define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ | |||
| #define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */ | |||
| #define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */ | |||
| /*@} end of group CMSIS_SysTick */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) | |||
| \brief Cortex-M1 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor. | |||
| Therefore they are not covered by the Cortex-M1 header file. | |||
| @{ | |||
| */ | |||
| /*@} end of group CMSIS_CoreDebug */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_core_bitfield Core register bit field macros | |||
| \brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk). | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief Mask and shift a bit field value for use in a register bit range. | |||
| \param[in] field Name of the register bit field. | |||
| \param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type. | |||
| \return Masked and shifted value. | |||
| */ | |||
| #define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk) | |||
| /** | |||
| \brief Mask and shift a register value to extract a bit filed value. | |||
| \param[in] field Name of the register bit field. | |||
| \param[in] value Value of register. This parameter is interpreted as an uint32_t type. | |||
| \return Masked and shifted bit field value. | |||
| */ | |||
| #define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos) | |||
| /*@} end of group CMSIS_core_bitfield */ | |||
| /** | |||
| \ingroup CMSIS_core_register | |||
| \defgroup CMSIS_core_base Core Definitions | |||
| \brief Definitions for base addresses, unions, and structures. | |||
| @{ | |||
| */ | |||
| /* Memory mapping of Core Hardware */ | |||
| #define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ | |||
| #define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ | |||
| #define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ | |||
| #define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ | |||
| #define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */ | |||
| #define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ | |||
| #define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ | |||
| #define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ | |||
| /*@} */ | |||
| /******************************************************************************* | |||
| * Hardware Abstraction Layer | |||
| Core Function Interface contains: | |||
| - Core NVIC Functions | |||
| - Core SysTick Functions | |||
| - Core Register Access Functions | |||
| ******************************************************************************/ | |||
| /** | |||
| \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference | |||
| */ | |||
| /* ########################## NVIC functions #################################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_NVICFunctions NVIC Functions | |||
| \brief Functions that manage interrupts and exceptions via the NVIC. | |||
| @{ | |||
| */ | |||
| #ifdef CMSIS_NVIC_VIRTUAL | |||
| #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE | |||
| #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" | |||
| #endif | |||
| #include CMSIS_NVIC_VIRTUAL_HEADER_FILE | |||
| #else | |||
| #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping | |||
| #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping | |||
| #define NVIC_EnableIRQ __NVIC_EnableIRQ | |||
| #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ | |||
| #define NVIC_DisableIRQ __NVIC_DisableIRQ | |||
| #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ | |||
| #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ | |||
| #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ | |||
| /*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M1 */ | |||
| #define NVIC_SetPriority __NVIC_SetPriority | |||
| #define NVIC_GetPriority __NVIC_GetPriority | |||
| #define NVIC_SystemReset __NVIC_SystemReset | |||
| #endif /* CMSIS_NVIC_VIRTUAL */ | |||
| #ifdef CMSIS_VECTAB_VIRTUAL | |||
| #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE | |||
| #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" | |||
| #endif | |||
| #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE | |||
| #else | |||
| #define NVIC_SetVector __NVIC_SetVector | |||
| #define NVIC_GetVector __NVIC_GetVector | |||
| #endif /* (CMSIS_VECTAB_VIRTUAL) */ | |||
| #define NVIC_USER_IRQ_OFFSET 16 | |||
| /* The following EXC_RETURN values are saved the LR on exception entry */ | |||
| #define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */ | |||
| #define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */ | |||
| #define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */ | |||
| /* Interrupt Priorities are WORD accessible only under Armv6-M */ | |||
| /* The following MACROS handle generation of the register offset and byte masks */ | |||
| #define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL) | |||
| #define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) ) | |||
| #define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) ) | |||
| #define __NVIC_SetPriorityGrouping(X) (void)(X) | |||
| #define __NVIC_GetPriorityGrouping() (0U) | |||
| /** | |||
| \brief Enable Interrupt | |||
| \details Enables a device specific interrupt in the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| __COMPILER_BARRIER(); | |||
| NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| __COMPILER_BARRIER(); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Interrupt Enable status | |||
| \details Returns a device specific interrupt enable status from the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \return 0 Interrupt is not enabled. | |||
| \return 1 Interrupt is enabled. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); | |||
| } | |||
| else | |||
| { | |||
| return(0U); | |||
| } | |||
| } | |||
| /** | |||
| \brief Disable Interrupt | |||
| \details Disables a device specific interrupt in the NVIC interrupt controller. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Pending Interrupt | |||
| \details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \return 0 Interrupt status is not pending. | |||
| \return 1 Interrupt status is pending. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); | |||
| } | |||
| else | |||
| { | |||
| return(0U); | |||
| } | |||
| } | |||
| /** | |||
| \brief Set Pending Interrupt | |||
| \details Sets the pending bit of a device specific interrupt in the NVIC pending register. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| } | |||
| } | |||
| /** | |||
| \brief Clear Pending Interrupt | |||
| \details Clears the pending bit of a device specific interrupt in the NVIC pending register. | |||
| \param [in] IRQn Device specific interrupt number. | |||
| \note IRQn must not be negative. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); | |||
| } | |||
| } | |||
| /** | |||
| \brief Set Interrupt Priority | |||
| \details Sets the priority of a device specific interrupt or a processor exception. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \param [in] priority Priority to set. | |||
| \note The priority cannot be set for every processor exception. | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | | |||
| (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); | |||
| } | |||
| else | |||
| { | |||
| SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) | | |||
| (((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn))); | |||
| } | |||
| } | |||
| /** | |||
| \brief Get Interrupt Priority | |||
| \details Reads the priority of a device specific interrupt or a processor exception. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \return Interrupt Priority. | |||
| Value is aligned automatically to the implemented priority bits of the microcontroller. | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) | |||
| { | |||
| if ((int32_t)(IRQn) >= 0) | |||
| { | |||
| return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); | |||
| } | |||
| else | |||
| { | |||
| return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); | |||
| } | |||
| } | |||
| /** | |||
| \brief Encode Priority | |||
| \details Encodes the priority for an interrupt with the given priority group, | |||
| preemptive priority value, and subpriority value. | |||
| In case of a conflict between priority grouping and available | |||
| priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. | |||
| \param [in] PriorityGroup Used priority group. | |||
| \param [in] PreemptPriority Preemptive priority value (starting from 0). | |||
| \param [in] SubPriority Subpriority value (starting from 0). | |||
| \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority(). | |||
| */ | |||
| __STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) | |||
| { | |||
| uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ | |||
| uint32_t PreemptPriorityBits; | |||
| uint32_t SubPriorityBits; | |||
| PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); | |||
| SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); | |||
| return ( | |||
| ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | | |||
| ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) | |||
| ); | |||
| } | |||
| /** | |||
| \brief Decode Priority | |||
| \details Decodes an interrupt priority value with a given priority group to | |||
| preemptive priority value and subpriority value. | |||
| In case of a conflict between priority grouping and available | |||
| priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. | |||
| \param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority(). | |||
| \param [in] PriorityGroup Used priority group. | |||
| \param [out] pPreemptPriority Preemptive priority value (starting from 0). | |||
| \param [out] pSubPriority Subpriority value (starting from 0). | |||
| */ | |||
| __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority) | |||
| { | |||
| uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ | |||
| uint32_t PreemptPriorityBits; | |||
| uint32_t SubPriorityBits; | |||
| PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); | |||
| SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); | |||
| *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); | |||
| *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL); | |||
| } | |||
| /** | |||
| \brief Set Interrupt Vector | |||
| \details Sets an interrupt vector in SRAM based interrupt vector table. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| Address 0 must be mapped to SRAM. | |||
| \param [in] IRQn Interrupt number | |||
| \param [in] vector Address of interrupt handler function | |||
| */ | |||
| __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) | |||
| { | |||
| uint32_t *vectors = (uint32_t *)0x0U; | |||
| vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; | |||
| /* ARM Application Note 321 states that the M1 does not require the architectural barrier */ | |||
| } | |||
| /** | |||
| \brief Get Interrupt Vector | |||
| \details Reads an interrupt vector from interrupt vector table. | |||
| The interrupt number can be positive to specify a device specific interrupt, | |||
| or negative to specify a processor exception. | |||
| \param [in] IRQn Interrupt number. | |||
| \return Address of interrupt handler function | |||
| */ | |||
| __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) | |||
| { | |||
| uint32_t *vectors = (uint32_t *)0x0U; | |||
| return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; | |||
| } | |||
| /** | |||
| \brief System Reset | |||
| \details Initiates a system reset request to reset the MCU. | |||
| */ | |||
| __NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) | |||
| { | |||
| __DSB(); /* Ensure all outstanding memory accesses included | |||
| buffered write are completed before reset */ | |||
| SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | | |||
| SCB_AIRCR_SYSRESETREQ_Msk); | |||
| __DSB(); /* Ensure completion of memory access */ | |||
| for(;;) /* wait until reset */ | |||
| { | |||
| __NOP(); | |||
| } | |||
| } | |||
| /*@} end of CMSIS_Core_NVICFunctions */ | |||
| /* ########################## FPU functions #################################### */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_FpuFunctions FPU Functions | |||
| \brief Function that provides FPU type. | |||
| @{ | |||
| */ | |||
| /** | |||
| \brief get FPU type | |||
| \details returns the FPU type | |||
| \returns | |||
| - \b 0: No FPU | |||
| - \b 1: Single precision FPU | |||
| - \b 2: Double + Single precision FPU | |||
| */ | |||
| __STATIC_INLINE uint32_t SCB_GetFPUType(void) | |||
| { | |||
| return 0U; /* No FPU */ | |||
| } | |||
| /*@} end of CMSIS_Core_FpuFunctions */ | |||
| /* ################################## SysTick function ############################################ */ | |||
| /** | |||
| \ingroup CMSIS_Core_FunctionInterface | |||
| \defgroup CMSIS_Core_SysTickFunctions SysTick Functions | |||
| \brief Functions that configure the System. | |||
| @{ | |||
| */ | |||
| #if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) | |||
| /** | |||
| \brief System Tick Configuration | |||
| \details Initializes the System Timer and its interrupt, and starts the System Tick Timer. | |||
| Counter is in free running mode to generate periodic interrupts. | |||
| \param [in] ticks Number of ticks between two interrupts. | |||
| \return 0 Function succeeded. | |||
| \return 1 Function failed. | |||
| \note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the | |||
| function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b> | |||
| must contain a vendor-specific implementation of this function. | |||
| */ | |||
| __STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) | |||
| { | |||
| if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) | |||
| { | |||
| return (1UL); /* Reload value impossible */ | |||
| } | |||
| SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ | |||
| NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ | |||
| SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ | |||
| SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | | |||
| SysTick_CTRL_TICKINT_Msk | | |||
| SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ | |||
| return (0UL); /* Function successful */ | |||
| } | |||
| #endif | |||
| /*@} end of CMSIS_Core_SysTickFunctions */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* __CORE_CM1_H_DEPENDANT */ | |||
| #endif /* __CMSIS_GENERIC */ | |||
| @@ -0,0 +1,275 @@ | |||
| /****************************************************************************** | |||
| * @file mpu_armv7.h | |||
| * @brief CMSIS MPU API for Armv7-M MPU | |||
| * @version V5.1.1 | |||
| * @date 10. February 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2017-2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef ARM_MPU_ARMV7_H | |||
| #define ARM_MPU_ARMV7_H | |||
| #define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes | |||
| #define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes | |||
| #define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes | |||
| #define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes | |||
| #define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes | |||
| #define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte | |||
| #define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes | |||
| #define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes | |||
| #define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes | |||
| #define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes | |||
| #define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes | |||
| #define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes | |||
| #define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes | |||
| #define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes | |||
| #define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes | |||
| #define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte | |||
| #define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes | |||
| #define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes | |||
| #define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes | |||
| #define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes | |||
| #define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes | |||
| #define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes | |||
| #define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes | |||
| #define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes | |||
| #define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes | |||
| #define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte | |||
| #define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes | |||
| #define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes | |||
| #define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access | |||
| #define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only | |||
| #define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only | |||
| #define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access | |||
| #define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only | |||
| #define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access | |||
| /** MPU Region Base Address Register Value | |||
| * | |||
| * \param Region The region to be configured, number 0 to 15. | |||
| * \param BaseAddress The base address for the region. | |||
| */ | |||
| #define ARM_MPU_RBAR(Region, BaseAddress) \ | |||
| (((BaseAddress) & MPU_RBAR_ADDR_Msk) | \ | |||
| ((Region) & MPU_RBAR_REGION_Msk) | \ | |||
| (MPU_RBAR_VALID_Msk)) | |||
| /** | |||
| * MPU Memory Access Attributes | |||
| * | |||
| * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. | |||
| * \param IsShareable Region is shareable between multiple bus masters. | |||
| * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. | |||
| * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. | |||
| */ | |||
| #define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \ | |||
| ((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \ | |||
| (((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \ | |||
| (((IsCacheable) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \ | |||
| (((IsBufferable) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk)) | |||
| /** | |||
| * MPU Region Attribute and Size Register Value | |||
| * | |||
| * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. | |||
| * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. | |||
| * \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_. | |||
| * \param SubRegionDisable Sub-region disable field. | |||
| * \param Size Region size of the region to be configured, for example 4K, 8K. | |||
| */ | |||
| #define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \ | |||
| ((((DisableExec) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \ | |||
| (((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \ | |||
| (((AccessAttributes) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk))) | \ | |||
| (((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \ | |||
| (((Size) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \ | |||
| (((MPU_RASR_ENABLE_Msk)))) | |||
| /** | |||
| * MPU Region Attribute and Size Register Value | |||
| * | |||
| * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. | |||
| * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. | |||
| * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. | |||
| * \param IsShareable Region is shareable between multiple bus masters. | |||
| * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. | |||
| * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. | |||
| * \param SubRegionDisable Sub-region disable field. | |||
| * \param Size Region size of the region to be configured, for example 4K, 8K. | |||
| */ | |||
| #define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \ | |||
| ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size) | |||
| /** | |||
| * MPU Memory Access Attribute for strongly ordered memory. | |||
| * - TEX: 000b | |||
| * - Shareable | |||
| * - Non-cacheable | |||
| * - Non-bufferable | |||
| */ | |||
| #define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U) | |||
| /** | |||
| * MPU Memory Access Attribute for device memory. | |||
| * - TEX: 000b (if shareable) or 010b (if non-shareable) | |||
| * - Shareable or non-shareable | |||
| * - Non-cacheable | |||
| * - Bufferable (if shareable) or non-bufferable (if non-shareable) | |||
| * | |||
| * \param IsShareable Configures the device memory as shareable or non-shareable. | |||
| */ | |||
| #define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U)) | |||
| /** | |||
| * MPU Memory Access Attribute for normal memory. | |||
| * - TEX: 1BBb (reflecting outer cacheability rules) | |||
| * - Shareable or non-shareable | |||
| * - Cacheable or non-cacheable (reflecting inner cacheability rules) | |||
| * - Bufferable or non-bufferable (reflecting inner cacheability rules) | |||
| * | |||
| * \param OuterCp Configures the outer cache policy. | |||
| * \param InnerCp Configures the inner cache policy. | |||
| * \param IsShareable Configures the memory as shareable or non-shareable. | |||
| */ | |||
| #define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) >> 1U), ((InnerCp) & 1U)) | |||
| /** | |||
| * MPU Memory Access Attribute non-cacheable policy. | |||
| */ | |||
| #define ARM_MPU_CACHEP_NOCACHE 0U | |||
| /** | |||
| * MPU Memory Access Attribute write-back, write and read allocate policy. | |||
| */ | |||
| #define ARM_MPU_CACHEP_WB_WRA 1U | |||
| /** | |||
| * MPU Memory Access Attribute write-through, no write allocate policy. | |||
| */ | |||
| #define ARM_MPU_CACHEP_WT_NWA 2U | |||
| /** | |||
| * MPU Memory Access Attribute write-back, no write allocate policy. | |||
| */ | |||
| #define ARM_MPU_CACHEP_WB_NWA 3U | |||
| /** | |||
| * Struct for a single MPU Region | |||
| */ | |||
| typedef struct { | |||
| uint32_t RBAR; //!< The region base address register value (RBAR) | |||
| uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR | |||
| } ARM_MPU_Region_t; | |||
| /** Enable the MPU. | |||
| * \param MPU_Control Default access permissions for unconfigured regions. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) | |||
| { | |||
| __DMB(); | |||
| MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| /** Disable the MPU. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Disable(void) | |||
| { | |||
| __DMB(); | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| /** Clear and disable the given MPU region. | |||
| * \param rnr Region number to be cleared. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) | |||
| { | |||
| MPU->RNR = rnr; | |||
| MPU->RASR = 0U; | |||
| } | |||
| /** Configure an MPU region. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rsar Value for RSAR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) | |||
| { | |||
| MPU->RBAR = rbar; | |||
| MPU->RASR = rasr; | |||
| } | |||
| /** Configure the given MPU region. | |||
| * \param rnr Region number to be configured. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rsar Value for RSAR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) | |||
| { | |||
| MPU->RNR = rnr; | |||
| MPU->RBAR = rbar; | |||
| MPU->RASR = rasr; | |||
| } | |||
| /** Memcopy with strictly ordered memory access, e.g. for register targets. | |||
| * \param dst Destination data is copied to. | |||
| * \param src Source data is copied from. | |||
| * \param len Amount of data words to be copied. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) | |||
| { | |||
| uint32_t i; | |||
| for (i = 0U; i < len; ++i) | |||
| { | |||
| dst[i] = src[i]; | |||
| } | |||
| } | |||
| /** Load the given number of MPU regions from a table. | |||
| * \param table Pointer to the MPU configuration table. | |||
| * \param cnt Amount of regions to be configured. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt) | |||
| { | |||
| const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; | |||
| while (cnt > MPU_TYPE_RALIASES) { | |||
| ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize); | |||
| table += MPU_TYPE_RALIASES; | |||
| cnt -= MPU_TYPE_RALIASES; | |||
| } | |||
| ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize); | |||
| } | |||
| #endif | |||
| @@ -0,0 +1,352 @@ | |||
| /****************************************************************************** | |||
| * @file mpu_armv8.h | |||
| * @brief CMSIS MPU API for Armv8-M and Armv8.1-M MPU | |||
| * @version V5.1.2 | |||
| * @date 10. February 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2017-2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef ARM_MPU_ARMV8_H | |||
| #define ARM_MPU_ARMV8_H | |||
| /** \brief Attribute for device memory (outer only) */ | |||
| #define ARM_MPU_ATTR_DEVICE ( 0U ) | |||
| /** \brief Attribute for non-cacheable, normal memory */ | |||
| #define ARM_MPU_ATTR_NON_CACHEABLE ( 4U ) | |||
| /** \brief Attribute for normal memory (outer and inner) | |||
| * \param NT Non-Transient: Set to 1 for non-transient data. | |||
| * \param WB Write-Back: Set to 1 to use write-back update policy. | |||
| * \param RA Read Allocation: Set to 1 to use cache allocation on read miss. | |||
| * \param WA Write Allocation: Set to 1 to use cache allocation on write miss. | |||
| */ | |||
| #define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \ | |||
| ((((NT) & 1U) << 3U) | (((WB) & 1U) << 2U) | (((RA) & 1U) << 1U) | ((WA) & 1U)) | |||
| /** \brief Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement */ | |||
| #define ARM_MPU_ATTR_DEVICE_nGnRnE (0U) | |||
| /** \brief Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement */ | |||
| #define ARM_MPU_ATTR_DEVICE_nGnRE (1U) | |||
| /** \brief Device memory type non Gathering, Re-ordering, Early Write Acknowledgement */ | |||
| #define ARM_MPU_ATTR_DEVICE_nGRE (2U) | |||
| /** \brief Device memory type Gathering, Re-ordering, Early Write Acknowledgement */ | |||
| #define ARM_MPU_ATTR_DEVICE_GRE (3U) | |||
| /** \brief Memory Attribute | |||
| * \param O Outer memory attributes | |||
| * \param I O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes | |||
| */ | |||
| #define ARM_MPU_ATTR(O, I) ((((O) & 0xFU) << 4U) | ((((O) & 0xFU) != 0U) ? ((I) & 0xFU) : (((I) & 0x3U) << 2U))) | |||
| /** \brief Normal memory non-shareable */ | |||
| #define ARM_MPU_SH_NON (0U) | |||
| /** \brief Normal memory outer shareable */ | |||
| #define ARM_MPU_SH_OUTER (2U) | |||
| /** \brief Normal memory inner shareable */ | |||
| #define ARM_MPU_SH_INNER (3U) | |||
| /** \brief Memory access permissions | |||
| * \param RO Read-Only: Set to 1 for read-only memory. | |||
| * \param NP Non-Privileged: Set to 1 for non-privileged memory. | |||
| */ | |||
| #define ARM_MPU_AP_(RO, NP) ((((RO) & 1U) << 1U) | ((NP) & 1U)) | |||
| /** \brief Region Base Address Register value | |||
| * \param BASE The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned. | |||
| * \param SH Defines the Shareability domain for this memory region. | |||
| * \param RO Read-Only: Set to 1 for a read-only memory region. | |||
| * \param NP Non-Privileged: Set to 1 for a non-privileged memory region. | |||
| * \oaram XN eXecute Never: Set to 1 for a non-executable memory region. | |||
| */ | |||
| #define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \ | |||
| (((BASE) & MPU_RBAR_BASE_Msk) | \ | |||
| (((SH) << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \ | |||
| ((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \ | |||
| (((XN) << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk)) | |||
| /** \brief Region Limit Address Register value | |||
| * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended. | |||
| * \param IDX The attribute index to be associated with this memory region. | |||
| */ | |||
| #define ARM_MPU_RLAR(LIMIT, IDX) \ | |||
| (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \ | |||
| (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ | |||
| (MPU_RLAR_EN_Msk)) | |||
| #if defined(MPU_RLAR_PXN_Pos) | |||
| /** \brief Region Limit Address Register with PXN value | |||
| * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended. | |||
| * \param PXN Privileged execute never. Defines whether code can be executed from this privileged region. | |||
| * \param IDX The attribute index to be associated with this memory region. | |||
| */ | |||
| #define ARM_MPU_RLAR_PXN(LIMIT, PXN, IDX) \ | |||
| (((LIMIT) & MPU_RLAR_LIMIT_Msk) | \ | |||
| (((PXN) << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \ | |||
| (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ | |||
| (MPU_RLAR_EN_Msk)) | |||
| #endif | |||
| /** | |||
| * Struct for a single MPU Region | |||
| */ | |||
| typedef struct { | |||
| uint32_t RBAR; /*!< Region Base Address Register value */ | |||
| uint32_t RLAR; /*!< Region Limit Address Register value */ | |||
| } ARM_MPU_Region_t; | |||
| /** Enable the MPU. | |||
| * \param MPU_Control Default access permissions for unconfigured regions. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) | |||
| { | |||
| __DMB(); | |||
| MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| /** Disable the MPU. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Disable(void) | |||
| { | |||
| __DMB(); | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Enable the Non-secure MPU. | |||
| * \param MPU_Control Default access permissions for unconfigured regions. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control) | |||
| { | |||
| __DMB(); | |||
| MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| /** Disable the Non-secure MPU. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Disable_NS(void) | |||
| { | |||
| __DMB(); | |||
| #ifdef SCB_SHCSR_MEMFAULTENA_Msk | |||
| SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; | |||
| #endif | |||
| MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk; | |||
| __DSB(); | |||
| __ISB(); | |||
| } | |||
| #endif | |||
| /** Set the memory attribute encoding to the given MPU. | |||
| * \param mpu Pointer to the MPU to be configured. | |||
| * \param idx The attribute index to be set [0-7] | |||
| * \param attr The attribute value to be set. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr) | |||
| { | |||
| const uint8_t reg = idx / 4U; | |||
| const uint32_t pos = ((idx % 4U) * 8U); | |||
| const uint32_t mask = 0xFFU << pos; | |||
| if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) { | |||
| return; // invalid index | |||
| } | |||
| mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask)); | |||
| } | |||
| /** Set the memory attribute encoding. | |||
| * \param idx The attribute index to be set [0-7] | |||
| * \param attr The attribute value to be set. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr) | |||
| { | |||
| ARM_MPU_SetMemAttrEx(MPU, idx, attr); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Set the memory attribute encoding to the Non-secure MPU. | |||
| * \param idx The attribute index to be set [0-7] | |||
| * \param attr The attribute value to be set. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr) | |||
| { | |||
| ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr); | |||
| } | |||
| #endif | |||
| /** Clear and disable the given MPU region of the given MPU. | |||
| * \param mpu Pointer to MPU to be used. | |||
| * \param rnr Region number to be cleared. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr) | |||
| { | |||
| mpu->RNR = rnr; | |||
| mpu->RLAR = 0U; | |||
| } | |||
| /** Clear and disable the given MPU region. | |||
| * \param rnr Region number to be cleared. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) | |||
| { | |||
| ARM_MPU_ClrRegionEx(MPU, rnr); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Clear and disable the given Non-secure MPU region. | |||
| * \param rnr Region number to be cleared. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr) | |||
| { | |||
| ARM_MPU_ClrRegionEx(MPU_NS, rnr); | |||
| } | |||
| #endif | |||
| /** Configure the given MPU region of the given MPU. | |||
| * \param mpu Pointer to MPU to be used. | |||
| * \param rnr Region number to be configured. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rlar Value for RLAR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar) | |||
| { | |||
| mpu->RNR = rnr; | |||
| mpu->RBAR = rbar; | |||
| mpu->RLAR = rlar; | |||
| } | |||
| /** Configure the given MPU region. | |||
| * \param rnr Region number to be configured. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rlar Value for RLAR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar) | |||
| { | |||
| ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Configure the given Non-secure MPU region. | |||
| * \param rnr Region number to be configured. | |||
| * \param rbar Value for RBAR register. | |||
| * \param rlar Value for RLAR register. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar) | |||
| { | |||
| ARM_MPU_SetRegionEx(MPU_NS, rnr, rbar, rlar); | |||
| } | |||
| #endif | |||
| /** Memcopy with strictly ordered memory access, e.g. for register targets. | |||
| * \param dst Destination data is copied to. | |||
| * \param src Source data is copied from. | |||
| * \param len Amount of data words to be copied. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) | |||
| { | |||
| uint32_t i; | |||
| for (i = 0U; i < len; ++i) | |||
| { | |||
| dst[i] = src[i]; | |||
| } | |||
| } | |||
| /** Load the given number of MPU regions from a table to the given MPU. | |||
| * \param mpu Pointer to the MPU registers to be used. | |||
| * \param rnr First region number to be configured. | |||
| * \param table Pointer to the MPU configuration table. | |||
| * \param cnt Amount of regions to be configured. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) | |||
| { | |||
| const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; | |||
| if (cnt == 1U) { | |||
| mpu->RNR = rnr; | |||
| ARM_MPU_OrderedMemcpy(&(mpu->RBAR), &(table->RBAR), rowWordSize); | |||
| } else { | |||
| uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U); | |||
| uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES; | |||
| mpu->RNR = rnrBase; | |||
| while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) { | |||
| uint32_t c = MPU_TYPE_RALIASES - rnrOffset; | |||
| ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), c*rowWordSize); | |||
| table += c; | |||
| cnt -= c; | |||
| rnrOffset = 0U; | |||
| rnrBase += MPU_TYPE_RALIASES; | |||
| mpu->RNR = rnrBase; | |||
| } | |||
| ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), cnt*rowWordSize); | |||
| } | |||
| } | |||
| /** Load the given number of MPU regions from a table. | |||
| * \param rnr First region number to be configured. | |||
| * \param table Pointer to the MPU configuration table. | |||
| * \param cnt Amount of regions to be configured. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) | |||
| { | |||
| ARM_MPU_LoadEx(MPU, rnr, table, cnt); | |||
| } | |||
| #ifdef MPU_NS | |||
| /** Load the given number of MPU regions from a table to the Non-secure MPU. | |||
| * \param rnr First region number to be configured. | |||
| * \param table Pointer to the MPU configuration table. | |||
| * \param cnt Amount of regions to be configured. | |||
| */ | |||
| __STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) | |||
| { | |||
| ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt); | |||
| } | |||
| #endif | |||
| #endif | |||
| @@ -0,0 +1,337 @@ | |||
| /****************************************************************************** | |||
| * @file pmu_armv8.h | |||
| * @brief CMSIS PMU API for Armv8.1-M PMU | |||
| * @version V1.0.0 | |||
| * @date 24. March 2020 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2020 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef ARM_PMU_ARMV8_H | |||
| #define ARM_PMU_ARMV8_H | |||
| /** | |||
| * \brief PMU Events | |||
| * \note See the Armv8.1-M Architecture Reference Manual for full details on these PMU events. | |||
| * */ | |||
| #define ARM_PMU_SW_INCR 0x0000 /*!< Software update to the PMU_SWINC register, architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_L1I_CACHE_REFILL 0x0001 /*!< L1 I-Cache refill */ | |||
| #define ARM_PMU_L1D_CACHE_REFILL 0x0003 /*!< L1 D-Cache refill */ | |||
| #define ARM_PMU_L1D_CACHE 0x0004 /*!< L1 D-Cache access */ | |||
| #define ARM_PMU_LD_RETIRED 0x0006 /*!< Memory-reading instruction architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_ST_RETIRED 0x0007 /*!< Memory-writing instruction architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_INST_RETIRED 0x0008 /*!< Instruction architecturally executed */ | |||
| #define ARM_PMU_EXC_TAKEN 0x0009 /*!< Exception entry */ | |||
| #define ARM_PMU_EXC_RETURN 0x000A /*!< Exception return instruction architecturally executed and the condition code check pass */ | |||
| #define ARM_PMU_PC_WRITE_RETIRED 0x000C /*!< Software change to the Program Counter (PC). Instruction is architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_BR_IMMED_RETIRED 0x000D /*!< Immediate branch architecturally executed */ | |||
| #define ARM_PMU_BR_RETURN_RETIRED 0x000E /*!< Function return instruction architecturally executed and the condition code check pass */ | |||
| #define ARM_PMU_UNALIGNED_LDST_RETIRED 0x000F /*!< Unaligned memory memory-reading or memory-writing instruction architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_BR_MIS_PRED 0x0010 /*!< Mispredicted or not predicted branch speculatively executed */ | |||
| #define ARM_PMU_CPU_CYCLES 0x0011 /*!< Cycle */ | |||
| #define ARM_PMU_BR_PRED 0x0012 /*!< Predictable branch speculatively executed */ | |||
| #define ARM_PMU_MEM_ACCESS 0x0013 /*!< Data memory access */ | |||
| #define ARM_PMU_L1I_CACHE 0x0014 /*!< Level 1 instruction cache access */ | |||
| #define ARM_PMU_L1D_CACHE_WB 0x0015 /*!< Level 1 data cache write-back */ | |||
| #define ARM_PMU_L2D_CACHE 0x0016 /*!< Level 2 data cache access */ | |||
| #define ARM_PMU_L2D_CACHE_REFILL 0x0017 /*!< Level 2 data cache refill */ | |||
| #define ARM_PMU_L2D_CACHE_WB 0x0018 /*!< Level 2 data cache write-back */ | |||
| #define ARM_PMU_BUS_ACCESS 0x0019 /*!< Bus access */ | |||
| #define ARM_PMU_MEMORY_ERROR 0x001A /*!< Local memory error */ | |||
| #define ARM_PMU_INST_SPEC 0x001B /*!< Instruction speculatively executed */ | |||
| #define ARM_PMU_BUS_CYCLES 0x001D /*!< Bus cycles */ | |||
| #define ARM_PMU_CHAIN 0x001E /*!< For an odd numbered counter, increment when an overflow occurs on the preceding even-numbered counter on the same PE */ | |||
| #define ARM_PMU_L1D_CACHE_ALLOCATE 0x001F /*!< Level 1 data cache allocation without refill */ | |||
| #define ARM_PMU_L2D_CACHE_ALLOCATE 0x0020 /*!< Level 2 data cache allocation without refill */ | |||
| #define ARM_PMU_BR_RETIRED 0x0021 /*!< Branch instruction architecturally executed */ | |||
| #define ARM_PMU_BR_MIS_PRED_RETIRED 0x0022 /*!< Mispredicted branch instruction architecturally executed */ | |||
| #define ARM_PMU_STALL_FRONTEND 0x0023 /*!< No operation issued because of the frontend */ | |||
| #define ARM_PMU_STALL_BACKEND 0x0024 /*!< No operation issued because of the backend */ | |||
| #define ARM_PMU_L2I_CACHE 0x0027 /*!< Level 2 instruction cache access */ | |||
| #define ARM_PMU_L2I_CACHE_REFILL 0x0028 /*!< Level 2 instruction cache refill */ | |||
| #define ARM_PMU_L3D_CACHE_ALLOCATE 0x0029 /*!< Level 3 data cache allocation without refill */ | |||
| #define ARM_PMU_L3D_CACHE_REFILL 0x002A /*!< Level 3 data cache refill */ | |||
| #define ARM_PMU_L3D_CACHE 0x002B /*!< Level 3 data cache access */ | |||
| #define ARM_PMU_L3D_CACHE_WB 0x002C /*!< Level 3 data cache write-back */ | |||
| #define ARM_PMU_LL_CACHE_RD 0x0036 /*!< Last level data cache read */ | |||
| #define ARM_PMU_LL_CACHE_MISS_RD 0x0037 /*!< Last level data cache read miss */ | |||
| #define ARM_PMU_L1D_CACHE_MISS_RD 0x0039 /*!< Level 1 data cache read miss */ | |||
| #define ARM_PMU_OP_COMPLETE 0x003A /*!< Operation retired */ | |||
| #define ARM_PMU_OP_SPEC 0x003B /*!< Operation speculatively executed */ | |||
| #define ARM_PMU_STALL 0x003C /*!< Stall cycle for instruction or operation not sent for execution */ | |||
| #define ARM_PMU_STALL_OP_BACKEND 0x003D /*!< Stall cycle for instruction or operation not sent for execution due to pipeline backend */ | |||
| #define ARM_PMU_STALL_OP_FRONTEND 0x003E /*!< Stall cycle for instruction or operation not sent for execution due to pipeline frontend */ | |||
| #define ARM_PMU_STALL_OP 0x003F /*!< Instruction or operation slots not occupied each cycle */ | |||
| #define ARM_PMU_L1D_CACHE_RD 0x0040 /*!< Level 1 data cache read */ | |||
| #define ARM_PMU_LE_RETIRED 0x0100 /*!< Loop end instruction executed */ | |||
| #define ARM_PMU_LE_SPEC 0x0101 /*!< Loop end instruction speculatively executed */ | |||
| #define ARM_PMU_BF_RETIRED 0x0104 /*!< Branch future instruction architecturally executed and condition code check pass */ | |||
| #define ARM_PMU_BF_SPEC 0x0105 /*!< Branch future instruction speculatively executed and condition code check pass */ | |||
| #define ARM_PMU_LE_CANCEL 0x0108 /*!< Loop end instruction not taken */ | |||
| #define ARM_PMU_BF_CANCEL 0x0109 /*!< Branch future instruction not taken */ | |||
| #define ARM_PMU_SE_CALL_S 0x0114 /*!< Call to secure function, resulting in Security state change */ | |||
| #define ARM_PMU_SE_CALL_NS 0x0115 /*!< Call to non-secure function, resulting in Security state change */ | |||
| #define ARM_PMU_DWT_CMPMATCH0 0x0118 /*!< DWT comparator 0 match */ | |||
| #define ARM_PMU_DWT_CMPMATCH1 0x0119 /*!< DWT comparator 1 match */ | |||
| #define ARM_PMU_DWT_CMPMATCH2 0x011A /*!< DWT comparator 2 match */ | |||
| #define ARM_PMU_DWT_CMPMATCH3 0x011B /*!< DWT comparator 3 match */ | |||
| #define ARM_PMU_MVE_INST_RETIRED 0x0200 /*!< MVE instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_INST_SPEC 0x0201 /*!< MVE instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_FP_RETIRED 0x0204 /*!< MVE floating-point instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_FP_SPEC 0x0205 /*!< MVE floating-point instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_FP_HP_RETIRED 0x0208 /*!< MVE half-precision floating-point instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_FP_HP_SPEC 0x0209 /*!< MVE half-precision floating-point instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_FP_SP_RETIRED 0x020C /*!< MVE single-precision floating-point instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_FP_SP_SPEC 0x020D /*!< MVE single-precision floating-point instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_FP_MAC_RETIRED 0x0214 /*!< MVE floating-point multiply or multiply-accumulate instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_FP_MAC_SPEC 0x0215 /*!< MVE floating-point multiply or multiply-accumulate instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_INT_RETIRED 0x0224 /*!< MVE integer instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_INT_SPEC 0x0225 /*!< MVE integer instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_INT_MAC_RETIRED 0x0228 /*!< MVE multiply or multiply-accumulate instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_INT_MAC_SPEC 0x0229 /*!< MVE multiply or multiply-accumulate instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_RETIRED 0x0238 /*!< MVE load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_SPEC 0x0239 /*!< MVE load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_RETIRED 0x023C /*!< MVE load instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_SPEC 0x023D /*!< MVE load instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_RETIRED 0x0240 /*!< MVE store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_SPEC 0x0241 /*!< MVE store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_CONTIG_RETIRED 0x0244 /*!< MVE contiguous load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_CONTIG_SPEC 0x0245 /*!< MVE contiguous load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_CONTIG_RETIRED 0x0248 /*!< MVE contiguous load instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_CONTIG_SPEC 0x0249 /*!< MVE contiguous load instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_CONTIG_RETIRED 0x024C /*!< MVE contiguous store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_CONTIG_SPEC 0x024D /*!< MVE contiguous store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_NONCONTIG_RETIRED 0x0250 /*!< MVE non-contiguous load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_NONCONTIG_SPEC 0x0251 /*!< MVE non-contiguous load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_NONCONTIG_RETIRED 0x0254 /*!< MVE non-contiguous load instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_NONCONTIG_SPEC 0x0255 /*!< MVE non-contiguous load instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_NONCONTIG_RETIRED 0x0258 /*!< MVE non-contiguous store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_NONCONTIG_SPEC 0x0259 /*!< MVE non-contiguous store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_MULTI_RETIRED 0x025C /*!< MVE memory instruction targeting multiple registers architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_MULTI_SPEC 0x025D /*!< MVE memory instruction targeting multiple registers speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_MULTI_RETIRED 0x0260 /*!< MVE memory load instruction targeting multiple registers architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_MULTI_SPEC 0x0261 /*!< MVE memory load instruction targeting multiple registers speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_MULTI_RETIRED 0x0261 /*!< MVE memory store instruction targeting multiple registers architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_MULTI_SPEC 0x0265 /*!< MVE memory store instruction targeting multiple registers speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_UNALIGNED_RETIRED 0x028C /*!< MVE unaligned memory load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_UNALIGNED_SPEC 0x028D /*!< MVE unaligned memory load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LD_UNALIGNED_RETIRED 0x0290 /*!< MVE unaligned load instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LD_UNALIGNED_SPEC 0x0291 /*!< MVE unaligned load instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_ST_UNALIGNED_RETIRED 0x0294 /*!< MVE unaligned store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_ST_UNALIGNED_SPEC 0x0295 /*!< MVE unaligned store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_LDST_UNALIGNED_NONCONTIG_RETIRED 0x0298 /*!< MVE unaligned noncontiguous load or store instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_LDST_UNALIGNED_NONCONTIG_SPEC 0x0299 /*!< MVE unaligned noncontiguous load or store instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_RETIRED 0x02A0 /*!< MVE vector reduction instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_SPEC 0x02A1 /*!< MVE vector reduction instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_FP_RETIRED 0x02A4 /*!< MVE floating-point vector reduction instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_FP_SPEC 0x02A5 /*!< MVE floating-point vector reduction instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_INT_RETIRED 0x02A8 /*!< MVE integer vector reduction instruction architecturally executed */ | |||
| #define ARM_PMU_MVE_VREDUCE_INT_SPEC 0x02A9 /*!< MVE integer vector reduction instruction speculatively executed */ | |||
| #define ARM_PMU_MVE_PRED 0x02B8 /*!< Cycles where one or more predicated beats architecturally executed */ | |||
| #define ARM_PMU_MVE_STALL 0x02CC /*!< Stall cycles caused by an MVE instruction */ | |||
| #define ARM_PMU_MVE_STALL_RESOURCE 0x02CD /*!< Stall cycles caused by an MVE instruction because of resource conflicts */ | |||
| #define ARM_PMU_MVE_STALL_RESOURCE_MEM 0x02CE /*!< Stall cycles caused by an MVE instruction because of memory resource conflicts */ | |||
| #define ARM_PMU_MVE_STALL_RESOURCE_FP 0x02CF /*!< Stall cycles caused by an MVE instruction because of floating-point resource conflicts */ | |||
| #define ARM_PMU_MVE_STALL_RESOURCE_INT 0x02D0 /*!< Stall cycles caused by an MVE instruction because of integer resource conflicts */ | |||
| #define ARM_PMU_MVE_STALL_BREAK 0x02D3 /*!< Stall cycles caused by an MVE chain break */ | |||
| #define ARM_PMU_MVE_STALL_DEPENDENCY 0x02D4 /*!< Stall cycles caused by MVE register dependency */ | |||
| #define ARM_PMU_ITCM_ACCESS 0x4007 /*!< Instruction TCM access */ | |||
| #define ARM_PMU_DTCM_ACCESS 0x4008 /*!< Data TCM access */ | |||
| #define ARM_PMU_TRCEXTOUT0 0x4010 /*!< ETM external output 0 */ | |||
| #define ARM_PMU_TRCEXTOUT1 0x4011 /*!< ETM external output 1 */ | |||
| #define ARM_PMU_TRCEXTOUT2 0x4012 /*!< ETM external output 2 */ | |||
| #define ARM_PMU_TRCEXTOUT3 0x4013 /*!< ETM external output 3 */ | |||
| #define ARM_PMU_CTI_TRIGOUT4 0x4018 /*!< Cross-trigger Interface output trigger 4 */ | |||
| #define ARM_PMU_CTI_TRIGOUT5 0x4019 /*!< Cross-trigger Interface output trigger 5 */ | |||
| #define ARM_PMU_CTI_TRIGOUT6 0x401A /*!< Cross-trigger Interface output trigger 6 */ | |||
| #define ARM_PMU_CTI_TRIGOUT7 0x401B /*!< Cross-trigger Interface output trigger 7 */ | |||
| /** \brief PMU Functions */ | |||
| __STATIC_INLINE void ARM_PMU_Enable(void); | |||
| __STATIC_INLINE void ARM_PMU_Disable(void); | |||
| __STATIC_INLINE void ARM_PMU_Set_EVTYPER(uint32_t num, uint32_t type); | |||
| __STATIC_INLINE void ARM_PMU_CYCCNT_Reset(void); | |||
| __STATIC_INLINE void ARM_PMU_EVCNTR_ALL_Reset(void); | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Enable(uint32_t mask); | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Disable(uint32_t mask); | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_CCNTR(void); | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_EVCNTR(uint32_t num); | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_CNTR_OVS(void); | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_OVS(uint32_t mask); | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Enable(uint32_t mask); | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask); | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask); | |||
| /** | |||
| \brief Enable the PMU | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Enable(void) | |||
| { | |||
| PMU->CTRL |= PMU_CTRL_ENABLE_Msk; | |||
| } | |||
| /** | |||
| \brief Disable the PMU | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Disable(void) | |||
| { | |||
| PMU->CTRL &= ~PMU_CTRL_ENABLE_Msk; | |||
| } | |||
| /** | |||
| \brief Set event to count for PMU eventer counter | |||
| \param [in] num Event counter (0-30) to configure | |||
| \param [in] type Event to count | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Set_EVTYPER(uint32_t num, uint32_t type) | |||
| { | |||
| PMU->EVTYPER[num] = type; | |||
| } | |||
| /** | |||
| \brief Reset cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_CYCCNT_Reset(void) | |||
| { | |||
| PMU->CTRL |= PMU_CTRL_CYCCNT_RESET_Msk; | |||
| } | |||
| /** | |||
| \brief Reset all event counters | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_EVCNTR_ALL_Reset(void) | |||
| { | |||
| PMU->CTRL |= PMU_CTRL_EVENTCNT_RESET_Msk; | |||
| } | |||
| /** | |||
| \brief Enable counters | |||
| \param [in] mask Counters to enable | |||
| \note Enables one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Enable(uint32_t mask) | |||
| { | |||
| PMU->CNTENSET = mask; | |||
| } | |||
| /** | |||
| \brief Disable counters | |||
| \param [in] mask Counters to enable | |||
| \note Disables one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Disable(uint32_t mask) | |||
| { | |||
| PMU->CNTENCLR = mask; | |||
| } | |||
| /** | |||
| \brief Read cycle counter | |||
| \return Cycle count | |||
| */ | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_CCNTR(void) | |||
| { | |||
| return PMU->CCNTR; | |||
| } | |||
| /** | |||
| \brief Read event counter | |||
| \param [in] num Event counter (0-30) to read | |||
| \return Event count | |||
| */ | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_EVCNTR(uint32_t num) | |||
| { | |||
| return PMU->EVCNTR[num]; | |||
| } | |||
| /** | |||
| \brief Read counter overflow status | |||
| \return Counter overflow status bits for the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE uint32_t ARM_PMU_Get_CNTR_OVS(void) | |||
| { | |||
| return PMU->OVSSET; | |||
| } | |||
| /** | |||
| \brief Clear counter overflow status | |||
| \param [in] mask Counter overflow status bits to clear | |||
| \note Clears overflow status bits for one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_OVS(uint32_t mask) | |||
| { | |||
| PMU->OVSCLR = mask; | |||
| } | |||
| /** | |||
| \brief Enable counter overflow interrupt request | |||
| \param [in] mask Counter overflow interrupt request bits to set | |||
| \note Sets overflow interrupt request bits for one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Enable(uint32_t mask) | |||
| { | |||
| PMU->INTENSET = mask; | |||
| } | |||
| /** | |||
| \brief Disable counter overflow interrupt request | |||
| \param [in] mask Counter overflow interrupt request bits to clear | |||
| \note Clears overflow interrupt request bits for one or more of the following: | |||
| - event counters (0-30) | |||
| - cycle counter | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask) | |||
| { | |||
| PMU->INTENCLR = mask; | |||
| } | |||
| /** | |||
| \brief Software increment event counter | |||
| \param [in] mask Counters to increment | |||
| \note Software increment bits for one or more event counters (0-30) | |||
| */ | |||
| __STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask) | |||
| { | |||
| PMU->SWINC = mask; | |||
| } | |||
| #endif | |||
| @@ -0,0 +1,70 @@ | |||
| /****************************************************************************** | |||
| * @file tz_context.h | |||
| * @brief Context Management for Armv8-M TrustZone | |||
| * @version V1.0.1 | |||
| * @date 10. January 2018 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2017-2018 Arm Limited. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #if defined ( __ICCARM__ ) | |||
| #pragma system_include /* treat file as system include file for MISRA check */ | |||
| #elif defined (__clang__) | |||
| #pragma clang system_header /* treat file as system include file */ | |||
| #endif | |||
| #ifndef TZ_CONTEXT_H | |||
| #define TZ_CONTEXT_H | |||
| #include <stdint.h> | |||
| #ifndef TZ_MODULEID_T | |||
| #define TZ_MODULEID_T | |||
| /// \details Data type that identifies secure software modules called by a process. | |||
| typedef uint32_t TZ_ModuleId_t; | |||
| #endif | |||
| /// \details TZ Memory ID identifies an allocated memory slot. | |||
| typedef uint32_t TZ_MemoryId_t; | |||
| /// Initialize secure context memory system | |||
| /// \return execution status (1: success, 0: error) | |||
| uint32_t TZ_InitContextSystem_S (void); | |||
| /// Allocate context memory for calling secure software modules in TrustZone | |||
| /// \param[in] module identifies software modules called from non-secure mode | |||
| /// \return value != 0 id TrustZone memory slot identifier | |||
| /// \return value 0 no memory available or internal error | |||
| TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); | |||
| /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); | |||
| /// Load secure context (called on RTOS thread context switch) | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); | |||
| /// Store secure context (called on RTOS thread context switch) | |||
| /// \param[in] id TrustZone memory slot identifier | |||
| /// \return execution status (1: success, 0: error) | |||
| uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); | |||
| #endif // TZ_CONTEXT_H | |||
| @@ -0,0 +1,517 @@ | |||
| /* ---------------------------------------------------------------------- | |||
| * Project: CMSIS DSP Library | |||
| * Title: arm_common_tables.h | |||
| * Description: Extern declaration for common tables | |||
| * | |||
| * $Date: 27. January 2017 | |||
| * $Revision: V.1.5.1 | |||
| * | |||
| * Target Processor: Cortex-M cores | |||
| * -------------------------------------------------------------------- */ | |||
| /* | |||
| * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef _ARM_COMMON_TABLES_H | |||
| #define _ARM_COMMON_TABLES_H | |||
| #include "arm_math.h" | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) | |||
| /* Double Precision Float CFFT twiddles */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREV_1024) | |||
| extern const uint16_t armBitRevTable[1024]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_16) | |||
| extern const uint64_t twiddleCoefF64_16[32]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_32) | |||
| extern const uint64_t twiddleCoefF64_32[64]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_64) | |||
| extern const uint64_t twiddleCoefF64_64[128]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_128) | |||
| extern const uint64_t twiddleCoefF64_128[256]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_256) | |||
| extern const uint64_t twiddleCoefF64_256[512]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_512) | |||
| extern const uint64_t twiddleCoefF64_512[1024]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_1024) | |||
| extern const uint64_t twiddleCoefF64_1024[2048]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_2048) | |||
| extern const uint64_t twiddleCoefF64_2048[4096]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_4096) | |||
| extern const uint64_t twiddleCoefF64_4096[8192]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_16) | |||
| extern const float32_t twiddleCoef_16[32]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_32) | |||
| extern const float32_t twiddleCoef_32[64]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_64) | |||
| extern const float32_t twiddleCoef_64[128]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_128) | |||
| extern const float32_t twiddleCoef_128[256]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_256) | |||
| extern const float32_t twiddleCoef_256[512]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_512) | |||
| extern const float32_t twiddleCoef_512[1024]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_1024) | |||
| extern const float32_t twiddleCoef_1024[2048]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_2048) | |||
| extern const float32_t twiddleCoef_2048[4096]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_4096) | |||
| extern const float32_t twiddleCoef_4096[8192]; | |||
| #define twiddleCoef twiddleCoef_4096 | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_16) | |||
| extern const q31_t twiddleCoef_16_q31[24]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_32) | |||
| extern const q31_t twiddleCoef_32_q31[48]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_64) | |||
| extern const q31_t twiddleCoef_64_q31[96]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_128) | |||
| extern const q31_t twiddleCoef_128_q31[192]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_256) | |||
| extern const q31_t twiddleCoef_256_q31[384]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_512) | |||
| extern const q31_t twiddleCoef_512_q31[768]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) | |||
| extern const q31_t twiddleCoef_1024_q31[1536]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) | |||
| extern const q31_t twiddleCoef_2048_q31[3072]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_4096) | |||
| extern const q31_t twiddleCoef_4096_q31[6144]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_16) | |||
| extern const q15_t twiddleCoef_16_q15[24]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_32) | |||
| extern const q15_t twiddleCoef_32_q15[48]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_64) | |||
| extern const q15_t twiddleCoef_64_q15[96]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_128) | |||
| extern const q15_t twiddleCoef_128_q15[192]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_256) | |||
| extern const q15_t twiddleCoef_256_q15[384]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_512) | |||
| extern const q15_t twiddleCoef_512_q15[768]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_1024) | |||
| extern const q15_t twiddleCoef_1024_q15[1536]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_2048) | |||
| extern const q15_t twiddleCoef_2048_q15[3072]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_4096) | |||
| extern const q15_t twiddleCoef_4096_q15[6144]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| /* Double Precision Float RFFT twiddles */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_32) | |||
| extern const uint64_t twiddleCoefF64_rfft_32[32]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_64) | |||
| extern const uint64_t twiddleCoefF64_rfft_64[64]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_128) | |||
| extern const uint64_t twiddleCoefF64_rfft_128[128]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_256) | |||
| extern const uint64_t twiddleCoefF64_rfft_256[256]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_512) | |||
| extern const uint64_t twiddleCoefF64_rfft_512[512]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_1024) | |||
| extern const uint64_t twiddleCoefF64_rfft_1024[1024]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_2048) | |||
| extern const uint64_t twiddleCoefF64_rfft_2048[2048]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_4096) | |||
| extern const uint64_t twiddleCoefF64_rfft_4096[4096]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_32) | |||
| extern const float32_t twiddleCoef_rfft_32[32]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_64) | |||
| extern const float32_t twiddleCoef_rfft_64[64]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_128) | |||
| extern const float32_t twiddleCoef_rfft_128[128]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_256) | |||
| extern const float32_t twiddleCoef_rfft_256[256]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_512) | |||
| extern const float32_t twiddleCoef_rfft_512[512]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_1024) | |||
| extern const float32_t twiddleCoef_rfft_1024[1024]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_2048) | |||
| extern const float32_t twiddleCoef_rfft_2048[2048]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_4096) | |||
| extern const float32_t twiddleCoef_rfft_4096[4096]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| /* Double precision floating-point bit reversal tables */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_16) | |||
| #define ARMBITREVINDEXTABLEF64_16_TABLE_LENGTH ((uint16_t)12) | |||
| extern const uint16_t armBitRevIndexTableF64_16[ARMBITREVINDEXTABLEF64_16_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_32) | |||
| #define ARMBITREVINDEXTABLEF64_32_TABLE_LENGTH ((uint16_t)24) | |||
| extern const uint16_t armBitRevIndexTableF64_32[ARMBITREVINDEXTABLEF64_32_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_64) | |||
| #define ARMBITREVINDEXTABLEF64_64_TABLE_LENGTH ((uint16_t)56) | |||
| extern const uint16_t armBitRevIndexTableF64_64[ARMBITREVINDEXTABLEF64_64_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_128) | |||
| #define ARMBITREVINDEXTABLEF64_128_TABLE_LENGTH ((uint16_t)112) | |||
| extern const uint16_t armBitRevIndexTableF64_128[ARMBITREVINDEXTABLEF64_128_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_256) | |||
| #define ARMBITREVINDEXTABLEF64_256_TABLE_LENGTH ((uint16_t)240) | |||
| extern const uint16_t armBitRevIndexTableF64_256[ARMBITREVINDEXTABLEF64_256_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_512) | |||
| #define ARMBITREVINDEXTABLEF64_512_TABLE_LENGTH ((uint16_t)480) | |||
| extern const uint16_t armBitRevIndexTableF64_512[ARMBITREVINDEXTABLEF64_512_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_1024) | |||
| #define ARMBITREVINDEXTABLEF64_1024_TABLE_LENGTH ((uint16_t)992) | |||
| extern const uint16_t armBitRevIndexTableF64_1024[ARMBITREVINDEXTABLEF64_1024_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_2048) | |||
| #define ARMBITREVINDEXTABLEF64_2048_TABLE_LENGTH ((uint16_t)1984) | |||
| extern const uint16_t armBitRevIndexTableF64_2048[ARMBITREVINDEXTABLEF64_2048_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_4096) | |||
| #define ARMBITREVINDEXTABLEF64_4096_TABLE_LENGTH ((uint16_t)4032) | |||
| extern const uint16_t armBitRevIndexTableF64_4096[ARMBITREVINDEXTABLEF64_4096_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| /* floating-point bit reversal tables */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_16) | |||
| #define ARMBITREVINDEXTABLE_16_TABLE_LENGTH ((uint16_t)20) | |||
| extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE_16_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_32) | |||
| #define ARMBITREVINDEXTABLE_32_TABLE_LENGTH ((uint16_t)48) | |||
| extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE_32_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_64) | |||
| #define ARMBITREVINDEXTABLE_64_TABLE_LENGTH ((uint16_t)56) | |||
| extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE_64_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_128) | |||
| #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208) | |||
| extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_256) | |||
| #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440) | |||
| extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_512) | |||
| #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448) | |||
| extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_1024) | |||
| #define ARMBITREVINDEXTABLE_1024_TABLE_LENGTH ((uint16_t)1800) | |||
| extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE_1024_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_2048) | |||
| #define ARMBITREVINDEXTABLE_2048_TABLE_LENGTH ((uint16_t)3808) | |||
| extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE_2048_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_4096) | |||
| #define ARMBITREVINDEXTABLE_4096_TABLE_LENGTH ((uint16_t)4032) | |||
| extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE_4096_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| /* fixed-point bit reversal tables */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_16) | |||
| #define ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH ((uint16_t)12) | |||
| extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_32) | |||
| #define ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH ((uint16_t)24) | |||
| extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_64) | |||
| #define ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH ((uint16_t)56) | |||
| extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_128) | |||
| #define ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH ((uint16_t)112) | |||
| extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_256) | |||
| #define ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH ((uint16_t)240) | |||
| extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_512) | |||
| #define ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH ((uint16_t)480) | |||
| extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_1024) | |||
| #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992) | |||
| extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_2048) | |||
| #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) | |||
| extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_4096) | |||
| #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) | |||
| extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_F32) | |||
| extern const float32_t realCoefA[8192]; | |||
| extern const float32_t realCoefB[8192]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q31) | |||
| extern const q31_t realCoefAQ31[8192]; | |||
| extern const q31_t realCoefBQ31[8192]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q15) | |||
| extern const q15_t realCoefAQ15[8192]; | |||
| extern const q15_t realCoefBQ15[8192]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_128) | |||
| extern const float32_t Weights_128[256]; | |||
| extern const float32_t cos_factors_128[128]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_512) | |||
| extern const float32_t Weights_512[1024]; | |||
| extern const float32_t cos_factors_512[512]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_2048) | |||
| extern const float32_t Weights_2048[4096]; | |||
| extern const float32_t cos_factors_2048[2048]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_8192) | |||
| extern const float32_t Weights_8192[16384]; | |||
| extern const float32_t cos_factors_8192[8192]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_128) | |||
| extern const q15_t WeightsQ15_128[256]; | |||
| extern const q15_t cos_factorsQ15_128[128]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_512) | |||
| extern const q15_t WeightsQ15_512[1024]; | |||
| extern const q15_t cos_factorsQ15_512[512]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_2048) | |||
| extern const q15_t WeightsQ15_2048[4096]; | |||
| extern const q15_t cos_factorsQ15_2048[2048]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_8192) | |||
| extern const q15_t WeightsQ15_8192[16384]; | |||
| extern const q15_t cos_factorsQ15_8192[8192]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_128) | |||
| extern const q31_t WeightsQ31_128[256]; | |||
| extern const q31_t cos_factorsQ31_128[128]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_512) | |||
| extern const q31_t WeightsQ31_512[1024]; | |||
| extern const q31_t cos_factorsQ31_512[512]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_2048) | |||
| extern const q31_t WeightsQ31_2048[4096]; | |||
| extern const q31_t cos_factorsQ31_2048[2048]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_8192) | |||
| extern const q31_t WeightsQ31_8192[16384]; | |||
| extern const q31_t cos_factorsQ31_8192[8192]; | |||
| #endif | |||
| #endif /* if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FAST_ALLOW_TABLES) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_RECIP_Q15) | |||
| extern const q15_t armRecipTableQ15[64]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_RECIP_Q31) | |||
| extern const q31_t armRecipTableQ31[64]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ | |||
| /* Tables for Fast Math Sine and Cosine */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_F32) | |||
| extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_Q31) | |||
| extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_Q15) | |||
| extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ | |||
| #if defined(ARM_MATH_MVEI) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q31_MVE) | |||
| extern const q31_t sqrtTable_Q31[256]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ | |||
| #endif | |||
| #if defined(ARM_MATH_MVEI) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q15_MVE) | |||
| extern const q15_t sqrtTable_Q15[256]; | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ | |||
| #endif | |||
| #endif /* if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FAST_TABLES) */ | |||
| #if (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) | |||
| extern const float32_t exp_tab[8]; | |||
| extern const float32_t __logf_lut_f32[8]; | |||
| #endif /* (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) */ | |||
| #if (defined(ARM_MATH_MVEI) || defined(ARM_MATH_HELIUM)) | |||
| extern const unsigned char hwLUT[256]; | |||
| #endif /* (defined(ARM_MATH_MVEI) || defined(ARM_MATH_HELIUM)) */ | |||
| #endif /* ARM_COMMON_TABLES_H */ | |||
| @@ -0,0 +1,76 @@ | |||
| /* ---------------------------------------------------------------------- | |||
| * Project: CMSIS DSP Library | |||
| * Title: arm_const_structs.h | |||
| * Description: Constant structs that are initialized for user convenience. | |||
| * For example, some can be given as arguments to the arm_cfft_f32() function. | |||
| * | |||
| * $Date: 27. January 2017 | |||
| * $Revision: V.1.5.1 | |||
| * | |||
| * Target Processor: Cortex-M cores | |||
| * -------------------------------------------------------------------- */ | |||
| /* | |||
| * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef _ARM_CONST_STRUCTS_H | |||
| #define _ARM_CONST_STRUCTS_H | |||
| #include "arm_math.h" | |||
| #include "arm_common_tables.h" | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len16; | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len32; | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len64; | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len128; | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len256; | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len512; | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len1024; | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len2048; | |||
| extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len4096; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; | |||
| extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; | |||
| extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; | |||
| extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; | |||
| #endif | |||
| @@ -0,0 +1,348 @@ | |||
| /* ---------------------------------------------------------------------- | |||
| * Project: CMSIS DSP Library | |||
| * Title: arm_helium_utils.h | |||
| * Description: Utility functions for Helium development | |||
| * | |||
| * $Date: 09. September 2019 | |||
| * $Revision: V.1.5.1 | |||
| * | |||
| * Target Processor: Cortex-M cores | |||
| * -------------------------------------------------------------------- */ | |||
| /* | |||
| * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef _ARM_UTILS_HELIUM_H_ | |||
| #define _ARM_UTILS_HELIUM_H_ | |||
| /*************************************** | |||
| Definitions available for MVEF and MVEI | |||
| ***************************************/ | |||
| #if defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEF) || defined(ARM_MATH_MVEI) | |||
| #define INACTIVELANE 0 /* inactive lane content */ | |||
| #endif /* defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEF) || defined(ARM_MATH_MVEI) */ | |||
| /*************************************** | |||
| Definitions available for MVEF only | |||
| ***************************************/ | |||
| #if defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEF) | |||
| __STATIC_FORCEINLINE float32_t vecAddAcrossF32Mve(float32x4_t in) | |||
| { | |||
| float32_t acc; | |||
| acc = vgetq_lane(in, 0) + vgetq_lane(in, 1) + | |||
| vgetq_lane(in, 2) + vgetq_lane(in, 3); | |||
| return acc; | |||
| } | |||
| /* newton initial guess */ | |||
| #define INVSQRT_MAGIC_F32 0x5f3759df | |||
| #define INVSQRT_NEWTON_MVE_F32(invSqrt, xHalf, xStart)\ | |||
| { \ | |||
| float32x4_t tmp; \ | |||
| \ | |||
| /* tmp = xhalf * x * x */ \ | |||
| tmp = vmulq(xStart, xStart); \ | |||
| tmp = vmulq(tmp, xHalf); \ | |||
| /* (1.5f - xhalf * x * x) */ \ | |||
| tmp = vsubq(vdupq_n_f32(1.5f), tmp); \ | |||
| /* x = x*(1.5f-xhalf*x*x); */ \ | |||
| invSqrt = vmulq(tmp, xStart); \ | |||
| } | |||
| #endif /* defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEF) */ | |||
| /*************************************** | |||
| Definitions available for MVEI only | |||
| ***************************************/ | |||
| #if defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEI) | |||
| #include "arm_common_tables.h" | |||
| /* Following functions are used to transpose matrix in f32 and q31 cases */ | |||
| __STATIC_INLINE arm_status arm_mat_trans_32bit_2x2_mve( | |||
| uint32_t * pDataSrc, | |||
| uint32_t * pDataDest) | |||
| { | |||
| static const uint32x4_t vecOffs = { 0, 2, 1, 3 }; | |||
| /* | |||
| * | |||
| * | 0 1 | => | 0 2 | | |||
| * | 2 3 | | 1 3 | | |||
| * | |||
| */ | |||
| uint32x4_t vecIn = vldrwq_u32((uint32_t const *)pDataSrc); | |||
| vstrwq_scatter_shifted_offset_u32(pDataDest, vecOffs, vecIn); | |||
| return (ARM_MATH_SUCCESS); | |||
| } | |||
| __STATIC_INLINE arm_status arm_mat_trans_32bit_3x3_mve( | |||
| uint32_t * pDataSrc, | |||
| uint32_t * pDataDest) | |||
| { | |||
| const uint32x4_t vecOffs1 = { 0, 3, 6, 1}; | |||
| const uint32x4_t vecOffs2 = { 4, 7, 2, 5}; | |||
| /* | |||
| * | |||
| * | 0 1 2 | | 0 3 6 | 4 x 32 flattened version | 0 3 6 1 | | |||
| * | 3 4 5 | => | 1 4 7 | => | 4 7 2 5 | | |||
| * | 6 7 8 | | 2 5 8 | (row major) | 8 . . . | | |||
| * | |||
| */ | |||
| uint32x4_t vecIn1 = vldrwq_u32((uint32_t const *) pDataSrc); | |||
| uint32x4_t vecIn2 = vldrwq_u32((uint32_t const *) &pDataSrc[4]); | |||
| vstrwq_scatter_shifted_offset_u32(pDataDest, vecOffs1, vecIn1); | |||
| vstrwq_scatter_shifted_offset_u32(pDataDest, vecOffs2, vecIn2); | |||
| pDataDest[8] = pDataSrc[8]; | |||
| return (ARM_MATH_SUCCESS); | |||
| } | |||
| __STATIC_INLINE arm_status arm_mat_trans_32bit_4x4_mve(uint32_t * pDataSrc, uint32_t * pDataDest) | |||
| { | |||
| /* | |||
| * 4x4 Matrix transposition | |||
| * is 4 x de-interleave operation | |||
| * | |||
| * 0 1 2 3 0 4 8 12 | |||
| * 4 5 6 7 1 5 9 13 | |||
| * 8 9 10 11 2 6 10 14 | |||
| * 12 13 14 15 3 7 11 15 | |||
| */ | |||
| uint32x4x4_t vecIn; | |||
| vecIn = vld4q((uint32_t const *) pDataSrc); | |||
| vstrwq(pDataDest, vecIn.val[0]); | |||
| pDataDest += 4; | |||
| vstrwq(pDataDest, vecIn.val[1]); | |||
| pDataDest += 4; | |||
| vstrwq(pDataDest, vecIn.val[2]); | |||
| pDataDest += 4; | |||
| vstrwq(pDataDest, vecIn.val[3]); | |||
| return (ARM_MATH_SUCCESS); | |||
| } | |||
| __STATIC_INLINE arm_status arm_mat_trans_32bit_generic_mve( | |||
| uint16_t srcRows, | |||
| uint16_t srcCols, | |||
| uint32_t * pDataSrc, | |||
| uint32_t * pDataDest) | |||
| { | |||
| uint32x4_t vecOffs; | |||
| uint32_t i; | |||
| uint32_t blkCnt; | |||
| uint32_t const *pDataC; | |||
| uint32_t *pDataDestR; | |||
| uint32x4_t vecIn; | |||
| vecOffs = vidupq_u32((uint32_t)0, 1); | |||
| vecOffs = vecOffs * srcCols; | |||
| i = srcCols; | |||
| do | |||
| { | |||
| pDataC = (uint32_t const *) pDataSrc; | |||
| pDataDestR = pDataDest; | |||
| blkCnt = srcRows >> 2; | |||
| while (blkCnt > 0U) | |||
| { | |||
| vecIn = vldrwq_gather_shifted_offset_u32(pDataC, vecOffs); | |||
| vstrwq(pDataDestR, vecIn); | |||
| pDataDestR += 4; | |||
| pDataC = pDataC + srcCols * 4; | |||
| /* | |||
| * Decrement the blockSize loop counter | |||
| */ | |||
| blkCnt--; | |||
| } | |||
| /* | |||
| * tail | |||
| */ | |||
| blkCnt = srcRows & 3; | |||
| if (blkCnt > 0U) | |||
| { | |||
| mve_pred16_t p0 = vctp32q(blkCnt); | |||
| vecIn = vldrwq_gather_shifted_offset_u32(pDataC, vecOffs); | |||
| vstrwq_p(pDataDestR, vecIn, p0); | |||
| } | |||
| pDataSrc += 1; | |||
| pDataDest += srcRows; | |||
| } | |||
| while (--i); | |||
| return (ARM_MATH_SUCCESS); | |||
| } | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q31_MVE) | |||
| __STATIC_INLINE q31x4_t FAST_VSQRT_Q31(q31x4_t vecIn) | |||
| { | |||
| q63x2_t vecTmpLL; | |||
| q31x4_t vecTmp0, vecTmp1; | |||
| q31_t scale; | |||
| q63_t tmp64; | |||
| q31x4_t vecNrm, vecDst, vecIdx, vecSignBits; | |||
| vecSignBits = vclsq(vecIn); | |||
| vecSignBits = vbicq(vecSignBits, 1); | |||
| /* | |||
| * in = in << no_of_sign_bits; | |||
| */ | |||
| vecNrm = vshlq(vecIn, vecSignBits); | |||
| /* | |||
| * index = in >> 24; | |||
| */ | |||
| vecIdx = vecNrm >> 24; | |||
| vecIdx = vecIdx << 1; | |||
| vecTmp0 = vldrwq_gather_shifted_offset_s32(sqrtTable_Q31, vecIdx); | |||
| vecIdx = vecIdx + 1; | |||
| vecTmp1 = vldrwq_gather_shifted_offset_s32(sqrtTable_Q31, vecIdx); | |||
| vecTmp1 = vqrdmulhq(vecTmp1, vecNrm); | |||
| vecTmp0 = vecTmp0 - vecTmp1; | |||
| vecTmp1 = vqrdmulhq(vecTmp0, vecTmp0); | |||
| vecTmp1 = vqrdmulhq(vecNrm, vecTmp1); | |||
| vecTmp1 = vdupq_n_s32(0x18000000) - vecTmp1; | |||
| vecTmp0 = vqrdmulhq(vecTmp0, vecTmp1); | |||
| vecTmpLL = vmullbq_int(vecNrm, vecTmp0); | |||
| /* | |||
| * scale elements 0, 2 | |||
| */ | |||
| scale = 26 + (vecSignBits[0] >> 1); | |||
| tmp64 = asrl(vecTmpLL[0], scale); | |||
| vecDst[0] = (q31_t) tmp64; | |||
| scale = 26 + (vecSignBits[2] >> 1); | |||
| tmp64 = asrl(vecTmpLL[1], scale); | |||
| vecDst[2] = (q31_t) tmp64; | |||
| vecTmpLL = vmulltq_int(vecNrm, vecTmp0); | |||
| /* | |||
| * scale elements 1, 3 | |||
| */ | |||
| scale = 26 + (vecSignBits[1] >> 1); | |||
| tmp64 = asrl(vecTmpLL[0], scale); | |||
| vecDst[1] = (q31_t) tmp64; | |||
| scale = 26 + (vecSignBits[3] >> 1); | |||
| tmp64 = asrl(vecTmpLL[1], scale); | |||
| vecDst[3] = (q31_t) tmp64; | |||
| /* | |||
| * set negative values to 0 | |||
| */ | |||
| vecDst = vdupq_m(vecDst, 0, vcmpltq_n_s32(vecIn, 0)); | |||
| return vecDst; | |||
| } | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q15_MVE) | |||
| __STATIC_INLINE q15x8_t FAST_VSQRT_Q15(q15x8_t vecIn) | |||
| { | |||
| q31x4_t vecTmpLev, vecTmpLodd, vecSignL; | |||
| q15x8_t vecTmp0, vecTmp1; | |||
| q15x8_t vecNrm, vecDst, vecIdx, vecSignBits; | |||
| vecDst = vuninitializedq_s16(); | |||
| vecSignBits = vclsq(vecIn); | |||
| vecSignBits = vbicq(vecSignBits, 1); | |||
| /* | |||
| * in = in << no_of_sign_bits; | |||
| */ | |||
| vecNrm = vshlq(vecIn, vecSignBits); | |||
| vecIdx = vecNrm >> 8; | |||
| vecIdx = vecIdx << 1; | |||
| vecTmp0 = vldrhq_gather_shifted_offset_s16(sqrtTable_Q15, vecIdx); | |||
| vecIdx = vecIdx + 1; | |||
| vecTmp1 = vldrhq_gather_shifted_offset_s16(sqrtTable_Q15, vecIdx); | |||
| vecTmp1 = vqrdmulhq(vecTmp1, vecNrm); | |||
| vecTmp0 = vecTmp0 - vecTmp1; | |||
| vecTmp1 = vqrdmulhq(vecTmp0, vecTmp0); | |||
| vecTmp1 = vqrdmulhq(vecNrm, vecTmp1); | |||
| vecTmp1 = vdupq_n_s16(0x1800) - vecTmp1; | |||
| vecTmp0 = vqrdmulhq(vecTmp0, vecTmp1); | |||
| vecSignBits = vecSignBits >> 1; | |||
| vecTmpLev = vmullbq_int(vecNrm, vecTmp0); | |||
| vecTmpLodd = vmulltq_int(vecNrm, vecTmp0); | |||
| vecTmp0 = vecSignBits + 10; | |||
| /* | |||
| * negate sign to apply register based vshl | |||
| */ | |||
| vecTmp0 = -vecTmp0; | |||
| /* | |||
| * shift even elements | |||
| */ | |||
| vecSignL = vmovlbq(vecTmp0); | |||
| vecTmpLev = vshlq(vecTmpLev, vecSignL); | |||
| /* | |||
| * shift odd elements | |||
| */ | |||
| vecSignL = vmovltq(vecTmp0); | |||
| vecTmpLodd = vshlq(vecTmpLodd, vecSignL); | |||
| /* | |||
| * merge and narrow odd and even parts | |||
| */ | |||
| vecDst = vmovnbq_s32(vecDst, vecTmpLev); | |||
| vecDst = vmovntq_s32(vecDst, vecTmpLodd); | |||
| /* | |||
| * set negative values to 0 | |||
| */ | |||
| vecDst = vdupq_m(vecDst, 0, vcmpltq_n_s16(vecIn, 0)); | |||
| return vecDst; | |||
| } | |||
| #endif | |||
| #endif /* defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEI) */ | |||
| #endif | |||
| @@ -0,0 +1,235 @@ | |||
| /* ---------------------------------------------------------------------- | |||
| * Project: CMSIS DSP Library | |||
| * Title: arm_mve_tables.h | |||
| * Description: common tables like fft twiddle factors, Bitreverse, reciprocal etc | |||
| * used for MVE implementation only | |||
| * | |||
| * $Date: 08. January 2020 | |||
| * $Revision: V1.7.0 | |||
| * | |||
| * Target Processor: Cortex-M cores | |||
| * -------------------------------------------------------------------- */ | |||
| /* | |||
| * Copyright (C) 2010-2020 ARM Limited or its affiliates. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef _ARM_MVE_TABLES_H | |||
| #define _ARM_MVE_TABLES_H | |||
| #include "arm_math.h" | |||
| #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_16) || defined(ARM_TABLE_TWIDDLECOEF_F32_32) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_16_f32[2]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_16_f32[2]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_16_f32[2]; | |||
| extern float32_t rearranged_twiddle_stride1_16_f32[8]; | |||
| extern float32_t rearranged_twiddle_stride2_16_f32[8]; | |||
| extern float32_t rearranged_twiddle_stride3_16_f32[8]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_64) || defined(ARM_TABLE_TWIDDLECOEF_F32_128) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_64_f32[3]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_64_f32[3]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_64_f32[3]; | |||
| extern float32_t rearranged_twiddle_stride1_64_f32[40]; | |||
| extern float32_t rearranged_twiddle_stride2_64_f32[40]; | |||
| extern float32_t rearranged_twiddle_stride3_64_f32[40]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_256) || defined(ARM_TABLE_TWIDDLECOEF_F32_512) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_256_f32[4]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_256_f32[4]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_256_f32[4]; | |||
| extern float32_t rearranged_twiddle_stride1_256_f32[168]; | |||
| extern float32_t rearranged_twiddle_stride2_256_f32[168]; | |||
| extern float32_t rearranged_twiddle_stride3_256_f32[168]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_1024) || defined(ARM_TABLE_TWIDDLECOEF_F32_2048) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_1024_f32[5]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_1024_f32[5]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_1024_f32[5]; | |||
| extern float32_t rearranged_twiddle_stride1_1024_f32[680]; | |||
| extern float32_t rearranged_twiddle_stride2_1024_f32[680]; | |||
| extern float32_t rearranged_twiddle_stride3_1024_f32[680]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_4096) || defined(ARM_TABLE_TWIDDLECOEF_F32_8192) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_4096_f32[6]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_4096_f32[6]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_4096_f32[6]; | |||
| extern float32_t rearranged_twiddle_stride1_4096_f32[2728]; | |||
| extern float32_t rearranged_twiddle_stride2_4096_f32[2728]; | |||
| extern float32_t rearranged_twiddle_stride3_4096_f32[2728]; | |||
| #endif | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) */ | |||
| #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */ | |||
| #if defined(ARM_MATH_MVEI) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_16) || defined(ARM_TABLE_TWIDDLECOEF_Q31_32) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_16_q31[2]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_16_q31[2]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_16_q31[2]; | |||
| extern q31_t rearranged_twiddle_stride1_16_q31[8]; | |||
| extern q31_t rearranged_twiddle_stride2_16_q31[8]; | |||
| extern q31_t rearranged_twiddle_stride3_16_q31[8]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_64) || defined(ARM_TABLE_TWIDDLECOEF_Q31_128) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_64_q31[3]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_64_q31[3]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_64_q31[3]; | |||
| extern q31_t rearranged_twiddle_stride1_64_q31[40]; | |||
| extern q31_t rearranged_twiddle_stride2_64_q31[40]; | |||
| extern q31_t rearranged_twiddle_stride3_64_q31[40]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_256) || defined(ARM_TABLE_TWIDDLECOEF_Q31_512) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_256_q31[4]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_256_q31[4]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_256_q31[4]; | |||
| extern q31_t rearranged_twiddle_stride1_256_q31[168]; | |||
| extern q31_t rearranged_twiddle_stride2_256_q31[168]; | |||
| extern q31_t rearranged_twiddle_stride3_256_q31[168]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) || defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_1024_q31[5]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_1024_q31[5]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_1024_q31[5]; | |||
| extern q31_t rearranged_twiddle_stride1_1024_q31[680]; | |||
| extern q31_t rearranged_twiddle_stride2_1024_q31[680]; | |||
| extern q31_t rearranged_twiddle_stride3_1024_q31[680]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_4096) || defined(ARM_TABLE_TWIDDLECOEF_Q31_8192) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_4096_q31[6]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_4096_q31[6]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_4096_q31[6]; | |||
| extern q31_t rearranged_twiddle_stride1_4096_q31[2728]; | |||
| extern q31_t rearranged_twiddle_stride2_4096_q31[2728]; | |||
| extern q31_t rearranged_twiddle_stride3_4096_q31[2728]; | |||
| #endif | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) */ | |||
| #endif /* defined(ARM_MATH_MVEI) */ | |||
| #if defined(ARM_MATH_MVEI) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_16) || defined(ARM_TABLE_TWIDDLECOEF_Q15_32) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_16_q15[2]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_16_q15[2]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_16_q15[2]; | |||
| extern q15_t rearranged_twiddle_stride1_16_q15[8]; | |||
| extern q15_t rearranged_twiddle_stride2_16_q15[8]; | |||
| extern q15_t rearranged_twiddle_stride3_16_q15[8]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_64) || defined(ARM_TABLE_TWIDDLECOEF_Q15_128) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_64_q15[3]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_64_q15[3]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_64_q15[3]; | |||
| extern q15_t rearranged_twiddle_stride1_64_q15[40]; | |||
| extern q15_t rearranged_twiddle_stride2_64_q15[40]; | |||
| extern q15_t rearranged_twiddle_stride3_64_q15[40]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_256) || defined(ARM_TABLE_TWIDDLECOEF_Q15_512) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_256_q15[4]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_256_q15[4]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_256_q15[4]; | |||
| extern q15_t rearranged_twiddle_stride1_256_q15[168]; | |||
| extern q15_t rearranged_twiddle_stride2_256_q15[168]; | |||
| extern q15_t rearranged_twiddle_stride3_256_q15[168]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_1024) || defined(ARM_TABLE_TWIDDLECOEF_Q15_2048) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_1024_q15[5]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_1024_q15[5]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_1024_q15[5]; | |||
| extern q15_t rearranged_twiddle_stride1_1024_q15[680]; | |||
| extern q15_t rearranged_twiddle_stride2_1024_q15[680]; | |||
| extern q15_t rearranged_twiddle_stride3_1024_q15[680]; | |||
| #endif | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_4096) || defined(ARM_TABLE_TWIDDLECOEF_Q15_8192) | |||
| extern uint32_t rearranged_twiddle_tab_stride1_arr_4096_q15[6]; | |||
| extern uint32_t rearranged_twiddle_tab_stride2_arr_4096_q15[6]; | |||
| extern uint32_t rearranged_twiddle_tab_stride3_arr_4096_q15[6]; | |||
| extern q15_t rearranged_twiddle_stride1_4096_q15[2728]; | |||
| extern q15_t rearranged_twiddle_stride2_4096_q15[2728]; | |||
| extern q15_t rearranged_twiddle_stride3_4096_q15[2728]; | |||
| #endif | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) */ | |||
| #endif /* defined(ARM_MATH_MVEI) */ | |||
| #if defined(ARM_MATH_MVEI) | |||
| #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) | |||
| #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) */ | |||
| #endif /* defined(ARM_MATH_MVEI) */ | |||
| #endif /*_ARM_MVE_TABLES_H*/ | |||
| @@ -0,0 +1,372 @@ | |||
| /****************************************************************************** | |||
| * @file arm_vec_math.h | |||
| * @brief Public header file for CMSIS DSP Library | |||
| * @version V1.7.0 | |||
| * @date 15. October 2019 | |||
| ******************************************************************************/ | |||
| /* | |||
| * Copyright (c) 2010-2019 Arm Limited or its affiliates. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef _ARM_VEC_MATH_H | |||
| #define _ARM_VEC_MATH_H | |||
| #include "arm_math.h" | |||
| #include "arm_common_tables.h" | |||
| #include "arm_helium_utils.h" | |||
| #ifdef __cplusplus | |||
| extern "C" | |||
| { | |||
| #endif | |||
| #if (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) | |||
| #define INV_NEWTON_INIT_F32 0x7EF127EA | |||
| static const float32_t __logf_rng_f32=0.693147180f; | |||
| /* fast inverse approximation (3x newton) */ | |||
| __STATIC_INLINE f32x4_t vrecip_medprec_f32( | |||
| f32x4_t x) | |||
| { | |||
| q31x4_t m; | |||
| f32x4_t b; | |||
| any32x4_t xinv; | |||
| f32x4_t ax = vabsq(x); | |||
| xinv.f = ax; | |||
| m = 0x3F800000 - (xinv.i & 0x7F800000); | |||
| xinv.i = xinv.i + m; | |||
| xinv.f = 1.41176471f - 0.47058824f * xinv.f; | |||
| xinv.i = xinv.i + m; | |||
| b = 2.0f - xinv.f * ax; | |||
| xinv.f = xinv.f * b; | |||
| b = 2.0f - xinv.f * ax; | |||
| xinv.f = xinv.f * b; | |||
| b = 2.0f - xinv.f * ax; | |||
| xinv.f = xinv.f * b; | |||
| xinv.f = vdupq_m(xinv.f, INFINITY, vcmpeqq(x, 0.0f)); | |||
| /* | |||
| * restore sign | |||
| */ | |||
| xinv.f = vnegq_m(xinv.f, xinv.f, vcmpltq(x, 0.0f)); | |||
| return xinv.f; | |||
| } | |||
| /* fast inverse approximation (4x newton) */ | |||
| __STATIC_INLINE f32x4_t vrecip_hiprec_f32( | |||
| f32x4_t x) | |||
| { | |||
| q31x4_t m; | |||
| f32x4_t b; | |||
| any32x4_t xinv; | |||
| f32x4_t ax = vabsq(x); | |||
| xinv.f = ax; | |||
| m = 0x3F800000 - (xinv.i & 0x7F800000); | |||
| xinv.i = xinv.i + m; | |||
| xinv.f = 1.41176471f - 0.47058824f * xinv.f; | |||
| xinv.i = xinv.i + m; | |||
| b = 2.0f - xinv.f * ax; | |||
| xinv.f = xinv.f * b; | |||
| b = 2.0f - xinv.f * ax; | |||
| xinv.f = xinv.f * b; | |||
| b = 2.0f - xinv.f * ax; | |||
| xinv.f = xinv.f * b; | |||
| b = 2.0f - xinv.f * ax; | |||
| xinv.f = xinv.f * b; | |||
| xinv.f = vdupq_m(xinv.f, INFINITY, vcmpeqq(x, 0.0f)); | |||
| /* | |||
| * restore sign | |||
| */ | |||
| xinv.f = vnegq_m(xinv.f, xinv.f, vcmpltq(x, 0.0f)); | |||
| return xinv.f; | |||
| } | |||
| __STATIC_INLINE f32x4_t vdiv_f32( | |||
| f32x4_t num, f32x4_t den) | |||
| { | |||
| return vmulq(num, vrecip_hiprec_f32(den)); | |||
| } | |||
| /** | |||
| @brief Single-precision taylor dev. | |||
| @param[in] x f32 quad vector input | |||
| @param[in] coeffs f32 quad vector coeffs | |||
| @return destination f32 quad vector | |||
| */ | |||
| __STATIC_INLINE f32x4_t vtaylor_polyq_f32( | |||
| f32x4_t x, | |||
| const float32_t * coeffs) | |||
| { | |||
| f32x4_t A = vfmasq(vdupq_n_f32(coeffs[4]), x, coeffs[0]); | |||
| f32x4_t B = vfmasq(vdupq_n_f32(coeffs[6]), x, coeffs[2]); | |||
| f32x4_t C = vfmasq(vdupq_n_f32(coeffs[5]), x, coeffs[1]); | |||
| f32x4_t D = vfmasq(vdupq_n_f32(coeffs[7]), x, coeffs[3]); | |||
| f32x4_t x2 = vmulq(x, x); | |||
| f32x4_t x4 = vmulq(x2, x2); | |||
| f32x4_t res = vfmaq(vfmaq_f32(A, B, x2), vfmaq_f32(C, D, x2), x4); | |||
| return res; | |||
| } | |||
| __STATIC_INLINE f32x4_t vmant_exp_f32( | |||
| f32x4_t x, | |||
| int32x4_t * e) | |||
| { | |||
| any32x4_t r; | |||
| int32x4_t n; | |||
| r.f = x; | |||
| n = r.i >> 23; | |||
| n = n - 127; | |||
| r.i = r.i - (n << 23); | |||
| *e = n; | |||
| return r.f; | |||
| } | |||
| __STATIC_INLINE f32x4_t vlogq_f32(f32x4_t vecIn) | |||
| { | |||
| q31x4_t vecExpUnBiased; | |||
| f32x4_t vecTmpFlt0, vecTmpFlt1; | |||
| f32x4_t vecAcc0, vecAcc1, vecAcc2, vecAcc3; | |||
| f32x4_t vecExpUnBiasedFlt; | |||
| /* | |||
| * extract exponent | |||
| */ | |||
| vecTmpFlt1 = vmant_exp_f32(vecIn, &vecExpUnBiased); | |||
| vecTmpFlt0 = vecTmpFlt1 * vecTmpFlt1; | |||
| /* | |||
| * a = (__logf_lut_f32[4] * r.f) + (__logf_lut_f32[0]); | |||
| */ | |||
| vecAcc0 = vdupq_n_f32(__logf_lut_f32[0]); | |||
| vecAcc0 = vfmaq(vecAcc0, vecTmpFlt1, __logf_lut_f32[4]); | |||
| /* | |||
| * b = (__logf_lut_f32[6] * r.f) + (__logf_lut_f32[2]); | |||
| */ | |||
| vecAcc1 = vdupq_n_f32(__logf_lut_f32[2]); | |||
| vecAcc1 = vfmaq(vecAcc1, vecTmpFlt1, __logf_lut_f32[6]); | |||
| /* | |||
| * c = (__logf_lut_f32[5] * r.f) + (__logf_lut_f32[1]); | |||
| */ | |||
| vecAcc2 = vdupq_n_f32(__logf_lut_f32[1]); | |||
| vecAcc2 = vfmaq(vecAcc2, vecTmpFlt1, __logf_lut_f32[5]); | |||
| /* | |||
| * d = (__logf_lut_f32[7] * r.f) + (__logf_lut_f32[3]); | |||
| */ | |||
| vecAcc3 = vdupq_n_f32(__logf_lut_f32[3]); | |||
| vecAcc3 = vfmaq(vecAcc3, vecTmpFlt1, __logf_lut_f32[7]); | |||
| /* | |||
| * a = a + b * xx; | |||
| */ | |||
| vecAcc0 = vfmaq(vecAcc0, vecAcc1, vecTmpFlt0); | |||
| /* | |||
| * c = c + d * xx; | |||
| */ | |||
| vecAcc2 = vfmaq(vecAcc2, vecAcc3, vecTmpFlt0); | |||
| /* | |||
| * xx = xx * xx; | |||
| */ | |||
| vecTmpFlt0 = vecTmpFlt0 * vecTmpFlt0; | |||
| vecExpUnBiasedFlt = vcvtq_f32_s32(vecExpUnBiased); | |||
| /* | |||
| * r.f = a + c * xx; | |||
| */ | |||
| vecAcc0 = vfmaq(vecAcc0, vecAcc2, vecTmpFlt0); | |||
| /* | |||
| * add exponent | |||
| * r.f = r.f + ((float32_t) m) * __logf_rng_f32; | |||
| */ | |||
| vecAcc0 = vfmaq(vecAcc0, vecExpUnBiasedFlt, __logf_rng_f32); | |||
| // set log0 down to -inf | |||
| vecAcc0 = vdupq_m(vecAcc0, -INFINITY, vcmpeqq(vecIn, 0.0f)); | |||
| return vecAcc0; | |||
| } | |||
| __STATIC_INLINE f32x4_t vexpq_f32( | |||
| f32x4_t x) | |||
| { | |||
| // Perform range reduction [-log(2),log(2)] | |||
| int32x4_t m = vcvtq_s32_f32(vmulq_n_f32(x, 1.4426950408f)); | |||
| f32x4_t val = vfmsq_f32(x, vcvtq_f32_s32(m), vdupq_n_f32(0.6931471805f)); | |||
| // Polynomial Approximation | |||
| f32x4_t poly = vtaylor_polyq_f32(val, exp_tab); | |||
| // Reconstruct | |||
| poly = (f32x4_t) (vqaddq_s32((q31x4_t) (poly), vqshlq_n_s32(m, 23))); | |||
| poly = vdupq_m(poly, 0.0f, vcmpltq_n_s32(m, -126)); | |||
| return poly; | |||
| } | |||
| __STATIC_INLINE f32x4_t arm_vec_exponent_f32(f32x4_t x, int32_t nb) | |||
| { | |||
| f32x4_t r = x; | |||
| nb--; | |||
| while (nb > 0) { | |||
| r = vmulq(r, x); | |||
| nb--; | |||
| } | |||
| return (r); | |||
| } | |||
| __STATIC_INLINE f32x4_t vrecip_f32(f32x4_t vecIn) | |||
| { | |||
| f32x4_t vecSx, vecW, vecTmp; | |||
| any32x4_t v; | |||
| vecSx = vabsq(vecIn); | |||
| v.f = vecIn; | |||
| v.i = vsubq(vdupq_n_s32(INV_NEWTON_INIT_F32), v.i); | |||
| vecW = vmulq(vecSx, v.f); | |||
| // v.f = v.f * (8 + w * (-28 + w * (56 + w * (-70 + w *(56 + w * (-28 + w * (8 - w))))))); | |||
| vecTmp = vsubq(vdupq_n_f32(8.0f), vecW); | |||
| vecTmp = vfmasq(vecW, vecTmp, -28.0f); | |||
| vecTmp = vfmasq(vecW, vecTmp, 56.0f); | |||
| vecTmp = vfmasq(vecW, vecTmp, -70.0f); | |||
| vecTmp = vfmasq(vecW, vecTmp, 56.0f); | |||
| vecTmp = vfmasq(vecW, vecTmp, -28.0f); | |||
| vecTmp = vfmasq(vecW, vecTmp, 8.0f); | |||
| v.f = vmulq(v.f, vecTmp); | |||
| v.f = vdupq_m(v.f, INFINITY, vcmpeqq(vecIn, 0.0f)); | |||
| /* | |||
| * restore sign | |||
| */ | |||
| v.f = vnegq_m(v.f, v.f, vcmpltq(vecIn, 0.0f)); | |||
| return v.f; | |||
| } | |||
| __STATIC_INLINE f32x4_t vtanhq_f32( | |||
| f32x4_t val) | |||
| { | |||
| f32x4_t x = | |||
| vminnmq_f32(vmaxnmq_f32(val, vdupq_n_f32(-10.f)), vdupq_n_f32(10.0f)); | |||
| f32x4_t exp2x = vexpq_f32(vmulq_n_f32(x, 2.f)); | |||
| f32x4_t num = vsubq_n_f32(exp2x, 1.f); | |||
| f32x4_t den = vaddq_n_f32(exp2x, 1.f); | |||
| f32x4_t tanh = vmulq_f32(num, vrecip_f32(den)); | |||
| return tanh; | |||
| } | |||
| __STATIC_INLINE f32x4_t vpowq_f32( | |||
| f32x4_t val, | |||
| f32x4_t n) | |||
| { | |||
| return vexpq_f32(vmulq_f32(n, vlogq_f32(val))); | |||
| } | |||
| #endif /* (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE)*/ | |||
| #if (defined(ARM_MATH_MVEI) || defined(ARM_MATH_HELIUM)) | |||
| #endif /* (defined(ARM_MATH_MVEI) || defined(ARM_MATH_HELIUM)) */ | |||
| #if (defined(ARM_MATH_NEON) || defined(ARM_MATH_NEON_EXPERIMENTAL)) && !defined(ARM_MATH_AUTOVECTORIZE) | |||
| #include "NEMath.h" | |||
| /** | |||
| * @brief Vectorized integer exponentiation | |||
| * @param[in] x value | |||
| * @param[in] nb integer exponent >= 1 | |||
| * @return x^nb | |||
| * | |||
| */ | |||
| __STATIC_INLINE float32x4_t arm_vec_exponent_f32(float32x4_t x, int32_t nb) | |||
| { | |||
| float32x4_t r = x; | |||
| nb --; | |||
| while(nb > 0) | |||
| { | |||
| r = vmulq_f32(r , x); | |||
| nb--; | |||
| } | |||
| return(r); | |||
| } | |||
| __STATIC_INLINE float32x4_t __arm_vec_sqrt_f32_neon(float32x4_t x) | |||
| { | |||
| float32x4_t x1 = vmaxq_f32(x, vdupq_n_f32(FLT_MIN)); | |||
| float32x4_t e = vrsqrteq_f32(x1); | |||
| e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); | |||
| e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); | |||
| return vmulq_f32(x, e); | |||
| } | |||
| __STATIC_INLINE int16x8_t __arm_vec_sqrt_q15_neon(int16x8_t vec) | |||
| { | |||
| float32x4_t tempF; | |||
| int32x4_t tempHI,tempLO; | |||
| tempLO = vmovl_s16(vget_low_s16(vec)); | |||
| tempF = vcvtq_n_f32_s32(tempLO,15); | |||
| tempF = __arm_vec_sqrt_f32_neon(tempF); | |||
| tempLO = vcvtq_n_s32_f32(tempF,15); | |||
| tempHI = vmovl_s16(vget_high_s16(vec)); | |||
| tempF = vcvtq_n_f32_s32(tempHI,15); | |||
| tempF = __arm_vec_sqrt_f32_neon(tempF); | |||
| tempHI = vcvtq_n_s32_f32(tempF,15); | |||
| return(vcombine_s16(vqmovn_s32(tempLO),vqmovn_s32(tempHI))); | |||
| } | |||
| __STATIC_INLINE int32x4_t __arm_vec_sqrt_q31_neon(int32x4_t vec) | |||
| { | |||
| float32x4_t temp; | |||
| temp = vcvtq_n_f32_s32(vec,31); | |||
| temp = __arm_vec_sqrt_f32_neon(temp); | |||
| return(vcvtq_n_s32_f32(temp,31)); | |||
| } | |||
| #endif /* (defined(ARM_MATH_NEON) || defined(ARM_MATH_NEON_EXPERIMENTAL)) && !defined(ARM_MATH_AUTOVECTORIZE) */ | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* _ARM_VEC_MATH_H */ | |||
| /** | |||
| * | |||
| * End of file. | |||
| */ | |||
| @@ -0,0 +1,56 @@ | |||
| /* ---------------------------------------------------------------------- | |||
| * Project: CMSIS NN Library | |||
| * Title: arm_nn_tables.h | |||
| * Description: Extern declaration for NN tables | |||
| * | |||
| * $Date: 17. January 2018 | |||
| * $Revision: V.1.0.0 | |||
| * | |||
| * Target Processor: Cortex-M cores | |||
| * -------------------------------------------------------------------- */ | |||
| /* | |||
| * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef _ARM_NN_TABLES_H | |||
| #define _ARM_NN_TABLES_H | |||
| #include "arm_math.h" | |||
| /** | |||
| * @brief tables for various activation functions | |||
| * | |||
| */ | |||
| extern const q15_t sigmoidTable_q15[256]; | |||
| extern const q7_t sigmoidTable_q7[256]; | |||
| extern const q7_t tanhTable_q7[256]; | |||
| extern const q15_t tanhTable_q15[256]; | |||
| /** | |||
| * @brief 2-way tables for various activation functions | |||
| * | |||
| * 2-way table, H table for value larger than 1/4 | |||
| * L table for value smaller than 1/4, H table for remaining | |||
| * We have this only for the q15_t version. It does not make | |||
| * sense to have it for q7_t type | |||
| */ | |||
| extern const q15_t sigmoidHTable_q15[192]; | |||
| extern const q15_t sigmoidLTable_q15[128]; | |||
| #endif /* ARM_NN_TABLES_H */ | |||
| @@ -0,0 +1,905 @@ | |||
| /* | |||
| * Copyright (C) 2010-2020 Arm Limited or its affiliates. All rights reserved. | |||
| * | |||
| * SPDX-License-Identifier: Apache-2.0 | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the License); you may | |||
| * not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an AS IS BASIS, WITHOUT | |||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| /* ---------------------------------------------------------------------- | |||
| * Project: CMSIS NN Library | |||
| * Title: arm_nnsupportfunctions.h | |||
| * Description: Public header file of support functions for CMSIS NN Library | |||
| * | |||
| * $Date: March 17, 2020 | |||
| * $Revision: V.4.0.3 | |||
| * | |||
| * Target Processor: Cortex-M cores | |||
| * -------------------------------------------------------------------- */ | |||
| #ifndef _ARM_NNSUPPORTFUNCTIONS_H_ | |||
| #define _ARM_NNSUPPORTFUNCTIONS_H_ | |||
| #include "arm_math.h" | |||
| #include "arm_common_tables.h" | |||
| #ifdef __cplusplus | |||
| extern "C" | |||
| { | |||
| #endif | |||
| #define LEFT_SHIFT(_shift) (_shift > 0 ? _shift : 0) | |||
| #define RIGHT_SHIFT(_shift) (_shift > 0 ? 0 : -_shift) | |||
| #define MASK_IF_ZERO(x) (x) == 0 ? ~0 : 0 | |||
| #define MASK_IF_NON_ZERO(x) (x) != 0 ? ~0 : 0 | |||
| #define SELECT_USING_MASK(mask, a, b) ((mask) & (a)) ^ (~(mask) & (b)) | |||
| #define MAX(A,B) ((A) > (B) ? (A) : (B)) | |||
| #define MIN(A,B) ((A) < (B) ? (A) : (B)) | |||
| #define CLAMP(x, h, l) MAX(MIN((x), (h)), (l)) | |||
| /** | |||
| * @brief Union for SIMD access of q31/q15/q7 types | |||
| */ | |||
| union arm_nnword | |||
| { | |||
| q31_t word; | |||
| /**< q31 type */ | |||
| q15_t half_words[2]; | |||
| /**< q15 type */ | |||
| q7_t bytes[4]; | |||
| /**< q7 type */ | |||
| }; | |||
| /** | |||
| * @brief Struct for specifying activation function types | |||
| * | |||
| */ | |||
| typedef enum | |||
| { | |||
| ARM_SIGMOID = 0, | |||
| /**< Sigmoid activation function */ | |||
| ARM_TANH = 1, | |||
| /**< Tanh activation function */ | |||
| } arm_nn_activation_type; | |||
| /** | |||
| * @defgroup nndata_convert Neural Network Data Conversion Functions | |||
| * | |||
| * Perform data type conversion in-between neural network operations | |||
| * | |||
| */ | |||
| /** | |||
| * @brief Converts the elements of the q7 vector to q15 vector without left-shift | |||
| * @param[in] *pSrc points to the q7 input vector | |||
| * @param[out] *pDst points to the q15 output vector | |||
| * @param[in] blockSize length of the input vector | |||
| * | |||
| */ | |||
| void arm_q7_to_q15_no_shift(const q7_t * pSrc, q15_t * pDst, uint32_t blockSize); | |||
| /** | |||
| * @brief Non-saturating addition of elements of a q7 vector | |||
| * @param[in] *input Pointer to the q7 input vector | |||
| * @param[out] *output Pointer to the q31 output variable. | |||
| * @param[in] block_size length of the input vector | |||
| * \par Description: | |||
| * | |||
| * 2^24 samples can be added without saturating the result. | |||
| * | |||
| * The equation used for the conversion process is: | |||
| * | |||
| * <pre> | |||
| * sum = input[0] + input[1] + .. + input[block_size -1] | |||
| * </pre> | |||
| * | |||
| * */ | |||
| void arm_nn_add_q7(const q7_t *input, q31_t *output, uint32_t block_size); | |||
| /** | |||
| * @brief Converts the elements of the q7 vector to reordered q15 vector without left-shift | |||
| * @param[in] *pSrc points to the q7 input vector | |||
| * @param[out] *pDst points to the q15 output vector | |||
| * @param[in] blockSize length of the input vector | |||
| * @return none. | |||
| * | |||
| */ | |||
| void arm_q7_to_q15_reordered_no_shift(const q7_t * pSrc, q15_t * pDst, uint32_t blockSize); | |||
| /** | |||
| * @brief Converts the elements from a q7 vector to a q15 vector with an added offset | |||
| * @param[in] src pointer to the q7 input vector | |||
| * @param[out] dst pointer to the q15 output vector | |||
| * @param[in] block_size length of the input vector | |||
| * @param[in] offset q7 offset to be added to each input vector element. | |||
| * | |||
| * \par Description: | |||
| * | |||
| * The equation used for the conversion process is: | |||
| * | |||
| * <pre> | |||
| * dst[n] = (q15_t) src[n] + offset; 0 <= n < block_size. | |||
| * </pre> | |||
| * | |||
| */ | |||
| void arm_q7_to_q15_with_offset(const q7_t *src, q15_t *dst, uint32_t block_size, q15_t offset); | |||
| /** | |||
| * @brief Converts the elements of the q7 vector to reordered q15 vector with an added offset | |||
| * @param[in] src pointer to the q7 input vector | |||
| * @param[out] dst pointer to the q15 output vector | |||
| * @param[in] block_size length of the input vector | |||
| * @param[in] offset offset to be added to each input vector element. | |||
| * @return none. | |||
| * | |||
| * @details This function does the q7 to q15 expansion with re-ordering of bytes. Re-ordering is a consequence of | |||
| * the sign extension intrinsic(DSP extension). The tail (i.e., last (N % 4) elements) retains its original | |||
| * order. | |||
| * | |||
| */ | |||
| void arm_q7_to_q15_reordered_with_offset(const q7_t *src, q15_t *dst, uint32_t block_size, q15_t offset); | |||
| /** | |||
| * @brief Converts the elements from a q7 vector and accumulate to a q15 vector | |||
| * @param[in] *src points to the q7 input vector | |||
| * @param[out] *dst points to the q15 output vector | |||
| * @param[in] block_size length of the input vector | |||
| * | |||
| * \par Description: | |||
| * | |||
| * The equation used for the conversion process is: | |||
| * | |||
| * <pre> | |||
| * dst[n] += (q15_t) src[n] ; 0 <= n < block_size. | |||
| * </pre> | |||
| * | |||
| */ | |||
| void arm_nn_accumulate_q7_to_q15(q15_t *dst, const q7_t *src, uint32_t block_size); | |||
| /** | |||
| * @brief Depthwise conv on an im2col buffer where the input channel equals output channel. | |||
| * @param[in] row pointer to row | |||
| * @param[in] col pointer to im2col buffer, always consists of 2 columns. | |||
| * @param[in] num_ch number of channels | |||
| * @param[in] out_shift pointer to per output channel requantization shift parameter. | |||
| * @param[in] out_mult pointer to per output channel requantization multiplier parameter. | |||
| * @param[in] out_offset output tensor offset. | |||
| * @param[in] activation_min minimum value to clamp the output to. Range : int8 | |||
| * @param[in] activation_max maximum value to clamp the output to. Range : int8 | |||
| * @param[in] kernel_size number of elements in one column. | |||
| * @param[in] output_bias per output channel bias. Range : int32 | |||
| * @param[out] out pointer to output | |||
| * @return The function returns one of the two | |||
| * 1. The incremented output pointer for a successful operation or | |||
| * 2. NULL if implementation is not available. | |||
| * | |||
| * @details Supported framework: TensorFlow Lite micro. | |||
| */ | |||
| q7_t *arm_nn_depthwise_conv_s8_core(const q7_t *row, | |||
| const q15_t *col, | |||
| const uint16_t num_ch, | |||
| const int32_t *out_shift, | |||
| const int32_t *out_mult, | |||
| const int32_t out_offset, | |||
| const int32_t activation_min, | |||
| const int32_t activation_max, | |||
| const uint16_t kernel_size, | |||
| const int32_t *const output_bias, | |||
| q7_t *out); | |||
| /** | |||
| * @brief General Matrix-multiplication function with per-channel requantization. | |||
| * @param[in] input_row pointer to row operand | |||
| * @param[in] input_col pointer to col operand | |||
| * @param[in] output_ch number of rows of input_row | |||
| * @param[in] col_batches number of column batches. Range: 1 to 4 | |||
| * @param[in] output_shift pointer to per output channel requantization shift parameter. | |||
| * @param[in] output_mult pointer to per output channel requantization multiplier parameter. | |||
| * @param[in] out_offset output tensor offset. | |||
| * @param[in] col_offset input tensor(col) offset. | |||
| * @param[in] row_offset kernel offset(row). Not used. | |||
| * @param[in] out_activation_min minimum value to clamp the output to. Range : int8 | |||
| * @param[in] out_activation_max maximum value to clamp the output to. Range : int8 | |||
| * @param[in] row_len number of elements in each row | |||
| * @param[in] bias per output channel bias. Range : int32 | |||
| * @param[in,out] out pointer to output | |||
| * @return The function returns one of the two | |||
| * 1. The incremented output pointer for a successful operation or | |||
| * 2. NULL if implementation is not available. | |||
| * | |||
| * @details Supported framework: TensorFlow Lite | |||
| */ | |||
| q7_t *arm_nn_mat_mult_s8(const q7_t *input_row, | |||
| const q7_t *input_col, | |||
| const uint16_t output_ch, | |||
| const uint16_t col_batches, | |||
| const int32_t *output_shift, | |||
| const int32_t *output_mult, | |||
| const int32_t out_offset, | |||
| const int32_t col_offset, | |||
| const int32_t row_offset, | |||
| const int16_t out_activation_min, | |||
| const int16_t out_activation_max, | |||
| const uint16_t row_len, | |||
| const int32_t *const bias, | |||
| q7_t *out); | |||
| /** | |||
| * @brief General Matrix-multiplication without requantization for one row & one column | |||
| * @param[in] row_elements number of row elements | |||
| * @param[in] row_base pointer to row operand | |||
| * @param[in] col_base pointer to col operand | |||
| * @param[out] sum_col pointer to store sum of column elements | |||
| * @param[out] output pointer to store result of multiply-accumulate | |||
| * @return The function returns the multiply-accumulated result of the row by column. | |||
| * | |||
| * @details Pseudo-code | |||
| * *output = 0 | |||
| * sum_col = 0 | |||
| * for (i = 0; i < row_elements; i++) | |||
| * *output += row_base[i] * col_base[i] | |||
| * sum_col += col_base[i] | |||
| * | |||
| */ | |||
| arm_status arm_nn_mat_mul_core_1x_s8(int32_t row_elements, | |||
| const int8_t *row_base, | |||
| const int8_t *col_base, | |||
| int32_t *const sum_col, | |||
| int32_t *const output); | |||
| /** | |||
| * @brief General Matrix-multiplication without requantization for four rows and one column | |||
| * @param[in] row_elements number of row elements | |||
| * @param[in] offset offset between rows. Can be the same as row_elements. | |||
| * For e.g, in a 1x1 conv scenario with stride as 1. | |||
| * @param[in] row_base pointer to row operand | |||
| * @param[in] col_base pointer to col operand | |||
| * @param[out] sum_col pointer to store sum of column elements | |||
| * @param[out] output pointer to store result(4 int32's) of multiply-accumulate | |||
| * @return The function returns the multiply-accumulated result of the row by column | |||
| * | |||
| * @details Pseudo-code | |||
| * output[0] = 0 | |||
| * .. | |||
| * output[3] = 0 | |||
| * sum_col = 0 | |||
| * for (i = 0; i < row_elements; i++) | |||
| * output[0] += row_base[i] * col_base[i] | |||
| * .. | |||
| * output[3] += row_base[i + (row_elements * 3)] * col_base[i] | |||
| * sum_col += col_base[i] | |||
| */ | |||
| arm_status arm_nn_mat_mul_core_4x_s8(const int32_t row_elements, | |||
| const int32_t offset, | |||
| const int8_t *row_base, | |||
| const int8_t *col_base, | |||
| int32_t *const sum_col, | |||
| int32_t *const output); | |||
| /** | |||
| * @brief General Matrix-multiplication function with per-channel requantization. | |||
| * This function assumes: | |||
| * - LHS input matrix NOT transposed (nt) | |||
| * - RHS input matrix transposed (t) | |||
| * | |||
| * @note This operation also performs the broadcast bias addition before the requantization | |||
| * | |||
| * @param[in] lhs Pointer to the LHS input matrix | |||
| * @param[in] rhs Pointer to the RHS input matrix | |||
| * @param[in] bias Pointer to the bias vector. The length of this vector is equal to the number of output columns (or RHS input rows) | |||
| * @param[out] dst Pointer to the output matrix with "m" rows and "n" columns | |||
| * @param[in] dst_multipliers Pointer to the multipliers vector needed for the per-channel requantization. The length of this vector is equal to | |||
| * the number of output columns (or RHS input rows) | |||
| * @param[in] dst_shifts Pointer to the shifts vector needed for the per-channel requantization. The length of this vector is equal to | |||
| * the number of output columns (or RHS input rows) | |||
| * @param[in] lhs_rows Number of LHS input rows | |||
| * @param[in] rhs_rows Number of RHS input rows | |||
| * @param[in] rhs_cols Number of LHS/RHS input columns | |||
| * @param[in] lhs_offset Offset to be applied to the LHS input value | |||
| * @param[in] dst_offset Offset to be applied the output result | |||
| * @param[in] activation_min Minimum value to clamp down the output. Range : int8 | |||
| * @param[in] activation_max Maximum value to clamp up the output. Range : int8 | |||
| * | |||
| * @return The function returns <code>ARM_MATH_SUCCESS</code> | |||
| * | |||
| */ | |||
| arm_status arm_nn_mat_mult_nt_t_s8(const q7_t *lhs, | |||
| const q7_t *rhs, | |||
| const q31_t *bias, | |||
| q7_t *dst, | |||
| const int32_t *dst_multipliers, | |||
| const int32_t *dst_shifts, | |||
| const int32_t lhs_rows, | |||
| const int32_t rhs_rows, | |||
| const int32_t rhs_cols, | |||
| const int32_t lhs_offset, | |||
| const int32_t dst_offset, | |||
| const int32_t activation_min, | |||
| const int32_t activation_max); | |||
| /** | |||
| * @brief s8 Vector by Matrix (transposed) multiplication | |||
| * | |||
| * @param[in] lhs Input left-hand side vector | |||
| * @param[in] rhs Input right-hand side matrix (transposed) | |||
| * @param[in] bias Input bias | |||
| * @param[out] dst Output vector | |||
| * @param[in] lhs_offset Offset to be added to the input values of the left-hand side vector. Range: -127 to 128 | |||
| * @param[in] rhs_offset Offset to be added to the input values of the right-hand side matrix. Range: -127 to 128 | |||
| * @param[in] dst_offset Offset to be added to the output values. Range: -127 to 128 | |||
| * @param[in] dst_multiplier Output multiplier | |||
| * @param[in] dst_shift Output shift | |||
| * @param[in] rhs_cols Number of columns in the right-hand side input matrix | |||
| * @param[in] rhs_rows Number of rows in the right-hand side input matrix | |||
| * @param[in] activation_min Minimum value to clamp the output to. Range: int8 | |||
| * @param[in] activation_max Maximum value to clamp the output to. Range: int8 | |||
| * | |||
| * @return The function returns <code>ARM_MATH_SUCCESS</code> | |||
| * | |||
| */ | |||
| arm_status arm_nn_vec_mat_mult_t_s8(const q7_t *lhs, | |||
| const q7_t *rhs, | |||
| const q31_t *bias, | |||
| q7_t *dst, | |||
| const int32_t lhs_offset, | |||
| const int32_t rhs_offset, | |||
| const int32_t dst_offset, | |||
| const int32_t dst_multiplier, | |||
| const int32_t dst_shift, | |||
| const int32_t rhs_cols, | |||
| const int32_t rhs_rows, | |||
| const int32_t activation_min, | |||
| const int32_t activation_max); | |||
| /** | |||
| * @brief Depthwise convolution of transposed rhs matrix with 4 lhs matrices. To be used in padded cases where | |||
| * the padding is -lhs_offset(Range: int8). Dimensions are the same for lhs and rhs. | |||
| * | |||
| * @param[in] lhs Input left-hand side matrix | |||
| * @param[in] rhs Input right-hand side matrix (transposed) | |||
| * @param[in] lhs_offset LHS matrix offset(input offset). Range: -127 to 128 | |||
| * @param[in] num_ch Number of channels in LHS/RHS | |||
| * @param[in] out_shift Per channel output shift. Length of vector is equal to number of channels | |||
| * @param[in] out_mult Per channel output multiplier. Length of vector is equal to number of channels | |||
| * @param[in] out_offset Offset to be added to the output values. Range: -127 to 128 | |||
| * @param[in] activation_min Minimum value to clamp the output to. Range: int8 | |||
| * @param[in] activation_max Maximum value to clamp the output to. Range: int8 | |||
| * @param[in] row_x_col (row_dimension * col_dimension) of LHS/RHS matrix | |||
| * @param[in] output_bias Per channel output bias. Length of vector is equal to number of channels | |||
| * @param[in] out Output pointer | |||
| * | |||
| * @return The function returns one of the two | |||
| * - Updated output pointer if an implementaiton is available | |||
| * - NULL if no implementation is available. | |||
| * | |||
| * @note If number of channels is not a multiple of 4, upto 3 elements outside the boundary will be read out | |||
| * for the following. | |||
| * - Output shift | |||
| * - Output multiplier | |||
| * - Output bias | |||
| * - rhs | |||
| */ | |||
| q7_t *arm_nn_depthwise_conv_nt_t_padded_s8(const q7_t *lhs, | |||
| const q7_t *rhs, | |||
| const int32_t lhs_offset, | |||
| const uint16_t num_ch, | |||
| const int32_t *out_shift, | |||
| const int32_t *out_mult, | |||
| const int32_t out_offset, | |||
| const int32_t activation_min, | |||
| const int32_t activation_max, | |||
| const uint16_t row_x_col, | |||
| const int32_t *const output_bias, | |||
| q7_t *out); | |||
| /** | |||
| * @brief Depthwise convolution of transposed rhs matrix with 4 lhs matrices. To be used in non-padded cases. | |||
| * Dimensions are the same for lhs and rhs. | |||
| * | |||
| * @param[in] lhs Input left-hand side matrix | |||
| * @param[in] rhs Input right-hand side matrix (transposed) | |||
| * @param[in] lhs_offset LHS matrix offset(input offset). Range: -127 to 128 | |||
| * @param[in] num_ch Number of channels in LHS/RHS | |||
| * @param[in] out_shift Per channel output shift. Length of vector is equal to number of channels. | |||
| * @param[in] out_mult Per channel output multiplier. Length of vector is equal to number of channels. | |||
| * @param[in] out_offset Offset to be added to the output values. Range: -127 to 128 | |||
| * @param[in] activation_min Minimum value to clamp the output to. Range: int8 | |||
| * @param[in] activation_max Maximum value to clamp the output to. Range: int8 | |||
| * @param[in] row_x_col (row_dimension * col_dimension) of LHS/RHS matrix | |||
| * @param[in] output_bias Per channel output bias. Length of vector is equal to number of channels. | |||
| * @param[in] out Output pointer | |||
| * | |||
| * @return The function returns one of the two | |||
| * - Updated output pointer if an implementaiton is available | |||
| * - NULL if no implementation is available. | |||
| * | |||
| * @note If number of channels is not a multiple of 4, upto 3 elements outside the boundary will be read out | |||
| * for the following. | |||
| * - Output shift | |||
| * - Output multiplier | |||
| * - Output bias | |||
| * - rhs | |||
| */ | |||
| q7_t *arm_nn_depthwise_conv_nt_t_s8(const q7_t *lhs, | |||
| const q7_t *rhs, | |||
| const int32_t lhs_offset, | |||
| const uint16_t num_ch, | |||
| const int32_t *out_shift, | |||
| const int32_t *out_mult, | |||
| const int32_t out_offset, | |||
| const int32_t activation_min, | |||
| const int32_t activation_max, | |||
| const uint16_t row_x_col, | |||
| const int32_t *const output_bias, | |||
| q7_t *out); | |||
| /** | |||
| @brief Read 2 q15 elements and post increment pointer. | |||
| @param[in] in_q15 Pointer to pointer that holds address of input. | |||
| @return q31 value | |||
| */ | |||
| __STATIC_FORCEINLINE q31_t arm_nn_read_q15x2_ia(const q15_t **in_q15) | |||
| { | |||
| q31_t val; | |||
| memcpy(&val, *in_q15, 4); | |||
| *in_q15 += 2; | |||
| return (val); | |||
| } | |||
| /** | |||
| @brief Read 4 q7 from q7 pointer and post increment pointer. | |||
| @param[in] in_q7 Pointer to pointer that holds address of input. | |||
| @return q31 value | |||
| */ | |||
| __STATIC_FORCEINLINE q31_t arm_nn_read_q7x4_ia(const q7_t **in_q7) | |||
| { | |||
| q31_t val; | |||
| memcpy(&val, *in_q7, 4); | |||
| *in_q7 += 4; | |||
| return (val); | |||
| } | |||
| /** | |||
| @brief Read 2 q15 from q15 pointer. | |||
| @param[in] in_q15 pointer to address of input. | |||
| @return q31 value | |||
| */ | |||
| __STATIC_FORCEINLINE q31_t arm_nn_read_q15x2(const q15_t *in_q15) | |||
| { | |||
| q31_t val; | |||
| memcpy(&val, in_q15, 4); | |||
| return (val); | |||
| } | |||
| /** | |||
| @brief Read 4 q7 values. | |||
| @param[in] in_q7 pointer to address of input. | |||
| @return q31 value | |||
| */ | |||
| __STATIC_FORCEINLINE q31_t arm_nn_read_q7x4(const q7_t *in_q7) | |||
| { | |||
| q31_t val; | |||
| memcpy(&val, in_q7, 4); | |||
| return (val); | |||
| } | |||
| /** | |||
| * @brief memset optimized for MVE | |||
| * @param[in, out] dst Destination pointer | |||
| * @param[in] val Value to set | |||
| * @param[in] block_size Number of bytes to copy. | |||
| * | |||
| */ | |||
| __STATIC_FORCEINLINE void arm_memset_q7(q7_t *dst, | |||
| const q7_t val, | |||
| uint32_t block_size) | |||
| { | |||
| #if defined(ARM_MATH_MVEI) | |||
| __asm volatile ( | |||
| " vdup.8 q0, %[set_val] \n" | |||
| " wlstp.8 lr, %[cnt], 1f \n" | |||
| "2: \n" | |||
| " vstrb.8 q0, [%[in]], 16 \n" | |||
| " letp lr, 2b \n" | |||
| "1: \n" | |||
| :[in] "+r"(dst) | |||
| :[cnt] "r"(block_size), [set_val] "r"(val) | |||
| :"q0", "memory", "r14"); | |||
| #else | |||
| memset(dst, val, block_size); | |||
| #endif | |||
| } | |||
| #if defined (ARM_MATH_DSP) | |||
| /** | |||
| * @brief read and expand one q7 word into two q15 words | |||
| */ | |||
| __STATIC_FORCEINLINE const q7_t *read_and_pad(const q7_t *source, q31_t * out1, q31_t * out2) | |||
| { | |||
| q31_t inA = arm_nn_read_q7x4_ia(&source); | |||
| q31_t inAbuf1 = __SXTB16(__ROR(inA, 8)); | |||
| q31_t inAbuf2 = __SXTB16(inA); | |||
| #ifndef ARM_MATH_BIG_ENDIAN | |||
| *out2 = __PKHTB(inAbuf1, inAbuf2, 16); | |||
| *out1 = __PKHBT(inAbuf2, inAbuf1, 16); | |||
| #else | |||
| *out1 = __PKHTB(inAbuf1, inAbuf2, 16); | |||
| *out2 = __PKHBT(inAbuf2, inAbuf1, 16); | |||
| #endif | |||
| return source; | |||
| } | |||
| /** | |||
| * @brief read and expand one q7 word into two q15 words with reordering | |||
| */ | |||
| __STATIC_FORCEINLINE const q7_t *read_and_pad_reordered(const q7_t *source, q31_t * out1, q31_t * out2) | |||
| { | |||
| q31_t inA = arm_nn_read_q7x4_ia(&source); | |||
| #ifndef ARM_MATH_BIG_ENDIAN | |||
| *out2 = __SXTB16(__ROR(inA, 8)); | |||
| *out1 = __SXTB16(inA); | |||
| #else | |||
| *out1 = __SXTB16(__ROR(inA, 8)); | |||
| *out2 = __SXTB16(inA); | |||
| #endif | |||
| return source; | |||
| } | |||
| /** | |||
| * @brief read and expand one q7 word into two q15 words with reordering and add an offset | |||
| */ | |||
| __STATIC_FORCEINLINE const q7_t *read_and_pad_reordered_with_offset(const q7_t *source, q31_t * out1, q31_t * out2, q31_t offset) | |||
| { | |||
| q31_t inA = arm_nn_read_q7x4_ia(&source); | |||
| #ifndef ARM_MATH_BIG_ENDIAN | |||
| *out2 = __SXTB16(__ROR(inA, 8)); | |||
| *out1 = __SXTB16(inA); | |||
| #else | |||
| *out1 = __SXTB16(__ROR(inA, 8)); | |||
| *out2 = __SXTB16(inA); | |||
| #endif | |||
| *out1 = __QADD16(*out1,offset); | |||
| *out2 = __QADD16(*out2,offset); | |||
| return source; | |||
| } | |||
| #endif | |||
| /** | |||
| * @defgroup NNBasicMath Basic Math Functions for Neural Network Computation | |||
| * | |||
| * Basic Math Functions for Neural Network Computation | |||
| * | |||
| */ | |||
| /** | |||
| * @brief q7 vector multiplication with variable output shifts | |||
| * @param[in] *pSrcA pointer to the first input vector | |||
| * @param[in] *pSrcB pointer to the second input vector | |||
| * @param[out] *pDst pointer to the output vector | |||
| * @param[in] out_shift amount of right-shift for output | |||
| * @param[in] blockSize number of samples in each vector | |||
| * @return none. | |||
| * | |||
| * <b>Scaling and Overflow Behavior:</b> | |||
| * \par | |||
| * The function uses saturating arithmetic. | |||
| * Results outside of the allowable q15 range [0x8000 0x7FFF] will be saturated. | |||
| */ | |||
| void arm_nn_mult_q15( | |||
| q15_t * pSrcA, | |||
| q15_t * pSrcB, | |||
| q15_t * pDst, | |||
| const uint16_t out_shift, | |||
| uint32_t blockSize); | |||
| /** | |||
| * @brief q7 vector multiplication with variable output shifts | |||
| * @param[in] *pSrcA pointer to the first input vector | |||
| * @param[in] *pSrcB pointer to the second input vector | |||
| * @param[out] *pDst pointer to the output vector | |||
| * @param[in] out_shift amount of right-shift for output | |||
| * @param[in] blockSize number of samples in each vector | |||
| * @return none. | |||
| * | |||
| * <b>Scaling and Overflow Behavior:</b> | |||
| * \par | |||
| * The function uses saturating arithmetic. | |||
| * Results outside of the allowable q7 range [0x80 0x7F] will be saturated. | |||
| */ | |||
| void arm_nn_mult_q7( | |||
| q7_t * pSrcA, | |||
| q7_t * pSrcB, | |||
| q7_t * pDst, | |||
| const uint16_t out_shift, | |||
| uint32_t blockSize); | |||
| /** | |||
| * @brief macro for adding rounding offset | |||
| */ | |||
| #ifndef ARM_NN_TRUNCATE | |||
| #define NN_ROUND(out_shift) ( (0x1u << out_shift) >> 1 ) | |||
| #else | |||
| #define NN_ROUND(out_shift) 0 | |||
| #endif | |||
| // Macros for shortening quantization functions' names and avoid long lines | |||
| #define MUL_SAT(a, b) arm_nn_sat_doubling_high_mult((a), (b)) | |||
| #define MUL_SAT_MVE(a, b) arm_sat_doubling_high_mult_mve_32x4((a), (b)) | |||
| #define MUL_POW2(a, b) arm_nn_mult_by_power_of_two((a), (b)) | |||
| #define DIV_POW2(a, b) arm_nn_divide_by_power_of_two((a), (b)) | |||
| #define DIV_POW2_MVE(a, b) arm_divide_by_power_of_two_mve((a), (b)) | |||
| #define EXP_ON_NEG(x) arm_nn_exp_on_negative_values((x)) | |||
| #define ONE_OVER1(x) arm_nn_one_over_one_plus_x_for_x_in_0_1((x)) | |||
| /** | |||
| * @brief Saturating doubling high multiply. Result matches | |||
| * NEON instruction VQRDMULH. | |||
| * @param[in] m1 Multiplicand | |||
| * @param[in] m2 Multiplier | |||
| * @return Result of multiplication. | |||
| * | |||
| */ | |||
| __STATIC_FORCEINLINE q31_t arm_nn_sat_doubling_high_mult(const q31_t m1, const q31_t m2) | |||
| { | |||
| q31_t result = 0; | |||
| // Rounding offset to add for a right shift of 31 | |||
| q63_t mult = 1 << 30; | |||
| if ((m1 < 0) ^ (m2 < 0)) | |||
| { | |||
| mult = 1 - mult; | |||
| } | |||
| // Gets resolved as a SMLAL instruction | |||
| mult = mult + (q63_t)m1 * m2; | |||
| // Utilize all of the upper 32 bits. This is the doubling step | |||
| // as well. | |||
| result = mult / (1UL << 31); | |||
| if ((m1 == m2) && (m1 == (int32_t)Q31_MIN)) | |||
| { | |||
| result = Q31_MAX; | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * @brief Rounding divide by power of two. | |||
| * @param[in] dividend - Dividend | |||
| * @param[in] exponent - Divisor = power(2, exponent) | |||
| * Range: [0, 31] | |||
| * @return Rounded result of division. Midpoint is rounded away from zero. | |||
| * | |||
| */ | |||
| __STATIC_FORCEINLINE q31_t arm_nn_divide_by_power_of_two(const q31_t dividend, const q31_t exponent) | |||
| { | |||
| q31_t result = 0; | |||
| const q31_t remainder_mask = (1l << exponent) - 1; | |||
| int32_t remainder = remainder_mask & dividend; | |||
| // Basic division | |||
| result = dividend >> exponent; | |||
| // Adjust 'result' for rounding (mid point away from zero) | |||
| q31_t threshold = remainder_mask >> 1; | |||
| if (result < 0) | |||
| { | |||
| threshold++; | |||
| } | |||
| if (remainder > threshold) | |||
| { | |||
| result++; | |||
| } | |||
| return result; | |||
| } | |||
| /** | |||
| * @brief Requantize a given value. | |||
| * @param[in] val Value to be requantized | |||
| * @param[in] multiplier multiplier | |||
| * @param[in] shift left or right shift for 'val * multiplier' | |||
| * | |||
| * @return Returns (val * multiplier)/(2 ^ shift) | |||
| * | |||
| */ | |||
| __STATIC_FORCEINLINE q31_t arm_nn_requantize(const q31_t val, const q31_t multiplier, const q31_t shift) | |||
| { | |||
| return arm_nn_divide_by_power_of_two(arm_nn_sat_doubling_high_mult(val * (1 << LEFT_SHIFT(shift)), multiplier), | |||
| RIGHT_SHIFT(shift)); | |||
| } | |||
| /** | |||
| * @brief memcpy optimized for MVE | |||
| * @param[in, out] dst Destination pointer | |||
| * @param[in] src Source pointer. | |||
| * @param[in] block_size Number of bytes to copy. | |||
| * | |||
| */ | |||
| __STATIC_FORCEINLINE void arm_memcpy_q7(q7_t *__RESTRICT dst, | |||
| const q7_t *__RESTRICT src, | |||
| uint32_t block_size) | |||
| { | |||
| #if defined(ARM_MATH_MVEI) | |||
| __asm volatile ( | |||
| " wlstp.8 lr, %[cnt], 1f \n" | |||
| "2: \n" | |||
| " vldrb.8 q0, [%[in]], 16 \n" | |||
| " vstrb.8 q0, [%[out]], 16 \n" | |||
| " letp lr, 2b \n" | |||
| "1: \n" | |||
| :[in] "+r"(src) | |||
| ,[out] "+r"(dst) | |||
| :[cnt] "r"(block_size) | |||
| :"q0", "memory", "r14"); | |||
| #else | |||
| memcpy(dst, src, block_size); | |||
| #endif | |||
| } | |||
| #if defined(ARM_MATH_MVEI) | |||
| /** | |||
| * @brief Vector saturating doubling high multiply returning high half. | |||
| * @param[in] m1 Multiplicand | |||
| * @param[in] m2 Multiplier | |||
| * @return Result of multiplication. | |||
| * | |||
| */ | |||
| __STATIC_FORCEINLINE int32x4_t arm_sat_doubling_high_mult_mve(const int32x4_t m1, const q31_t m2) | |||
| { | |||
| return vqrdmulhq_n_s32(m1, m2); | |||
| } | |||
| /** | |||
| * @brief Vector rounding divide by power of two. | |||
| * @param[in] dividend - Dividend vector | |||
| * @param[in] exponent - Divisor = power(2, exponent) | |||
| * Range: [0, 31] | |||
| * @return Rounded result of division. Midpoint is rounded away from zero. | |||
| * | |||
| */ | |||
| __STATIC_FORCEINLINE int32x4_t arm_divide_by_power_of_two_mve(const int32x4_t dividend, const q31_t exponent) | |||
| { | |||
| const int32x4_t shift = vdupq_n_s32(-exponent); | |||
| const int32x4_t fixup = vshrq_n_s32(vandq_s32(dividend, shift), 31); | |||
| const int32x4_t fixed_up_dividend = vqaddq_s32(dividend, fixup); | |||
| return vrshlq_s32(fixed_up_dividend, shift); | |||
| } | |||
| /** | |||
| * @brief Requantize a given vector. | |||
| * @param[in] val Vector to be requantized | |||
| * @param[in] multiplier multiplier | |||
| * @param[in] shift shift | |||
| * | |||
| * @return Returns (val * multiplier)/(2 ^ shift) | |||
| * | |||
| */ | |||
| __STATIC_FORCEINLINE int32x4_t arm_requantize_mve(const int32x4_t val, const q31_t multiplier, const q31_t shift) | |||
| { | |||
| return arm_divide_by_power_of_two_mve( | |||
| arm_sat_doubling_high_mult_mve(vshlq_s32(val, vdupq_n_s32(LEFT_SHIFT(shift))), multiplier), | |||
| RIGHT_SHIFT(shift)); | |||
| } | |||
| __STATIC_FORCEINLINE int32x4_t arm_sat_doubling_high_mult_mve_32x4(const int32x4_t m1, const int32x4_t m2) | |||
| { | |||
| return vqrdmulhq_s32(m1, m2); | |||
| } | |||
| __STATIC_FORCEINLINE int32x4_t arm_divide_by_power_of_two_mve_32x4(const int32x4_t dividend, const int32x4_t exponent) | |||
| { | |||
| const int32x4_t shift = -exponent; | |||
| const int32x4_t fixup = vshrq_n_s32(vandq_s32(dividend, shift), 31); | |||
| const int32x4_t fixed_up_dividend = vqaddq_s32(dividend, fixup); | |||
| return vrshlq_s32(fixed_up_dividend, shift); | |||
| } | |||
| __STATIC_FORCEINLINE int32x4_t arm_requantize_mve_32x4(const int32x4_t val, const int32x4_t multiplier, const int32x4_t shift) | |||
| { | |||
| const int32x4_t zz = vdupq_n_s32(0); | |||
| const mve_pred16_t p = vcmpgtq_n_s32(shift, 0); | |||
| const int32x4_t left_shift = vpselq_s32(shift, zz, p); | |||
| const int32x4_t right_shift = -vpselq_s32(zz, shift, p); | |||
| return arm_divide_by_power_of_two_mve_32x4(arm_sat_doubling_high_mult_mve_32x4(vshlq_s32(val, left_shift), multiplier), right_shift); | |||
| } | |||
| #endif | |||
| // @note The following functions are used only for softmax layer, scaled bits = 5 assumed | |||
| __STATIC_FORCEINLINE int32_t arm_nn_exp_on_negative_values(int32_t val) | |||
| { | |||
| int32_t mask = 0; | |||
| int32_t shift = 24; | |||
| const int32_t val_mod_minus_quarter = (val & ((1 << shift) - 1)) - (1 << shift); | |||
| const int32_t remainder = val_mod_minus_quarter - val; | |||
| const int32_t x = (val_mod_minus_quarter << 5) + (1 << 28); | |||
| const int32_t x2 = MUL_SAT(x, x); | |||
| int32_t result = 1895147668 + MUL_SAT(1895147668, x + | |||
| DIV_POW2(MUL_SAT(DIV_POW2(MUL_SAT(x2, x2), 2) + MUL_SAT(x2, x), 715827883) + x2, 1)); | |||
| #define SELECT_IF_NON_ZERO(x) \ | |||
| { \ | |||
| mask = MASK_IF_NON_ZERO(remainder & (1 << shift++)); \ | |||
| result = SELECT_USING_MASK(mask, MUL_SAT(result, x), result); \ | |||
| } | |||
| SELECT_IF_NON_ZERO(1672461947) | |||
| SELECT_IF_NON_ZERO(1302514674) | |||
| SELECT_IF_NON_ZERO(790015084) | |||
| SELECT_IF_NON_ZERO(290630308) | |||
| SELECT_IF_NON_ZERO(39332535) | |||
| SELECT_IF_NON_ZERO(720401) | |||
| SELECT_IF_NON_ZERO(242) | |||
| #undef SELECT_IF_NON_ZERO | |||
| mask = MASK_IF_ZERO(val); | |||
| return SELECT_USING_MASK(mask, Q31_MAX, result); | |||
| } | |||
| __STATIC_FORCEINLINE q31_t arm_nn_mult_by_power_of_two(const int32_t val, const int32_t exp) | |||
| { | |||
| const int32_t thresh = ((1 << (31 - exp)) - 1); | |||
| int32_t result = val << exp; | |||
| result = SELECT_USING_MASK(MASK_IF_NON_ZERO(val > thresh), Q31_MAX, result); | |||
| result = SELECT_USING_MASK(MASK_IF_NON_ZERO(val < -thresh), Q31_MIN, result); | |||
| return result; | |||
| } | |||
| __STATIC_FORCEINLINE int32_t arm_nn_one_over_one_plus_x_for_x_in_0_1(int32_t val) | |||
| { | |||
| const int64_t sum = (int64_t)val + (int64_t)Q31_MAX; | |||
| const int32_t half_denominator = (int32_t)((sum + (sum >= 0 ? 1 : -1)) / 2L); | |||
| int32_t x = 1515870810 + MUL_SAT(half_denominator, -1010580540); | |||
| const int32_t shift = (1 << 29); | |||
| x += MUL_POW2(MUL_SAT(x, shift - MUL_SAT(half_denominator, x)), 2); | |||
| x += MUL_POW2(MUL_SAT(x, shift - MUL_SAT(half_denominator, x)), 2); | |||
| x += MUL_POW2(MUL_SAT(x, shift - MUL_SAT(half_denominator, x)), 2); | |||
| return MUL_POW2(x, 1); | |||
| } | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif | |||
| @@ -0,0 +1,32 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_ADDER_H_ | |||
| #define MINDSPORE_LITE_NNACL_ADDER_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct AdderParameter { | |||
| OpParameter op_parameter_; | |||
| } AdderParameter; | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_ADDER_H_ | |||
| @@ -0,0 +1,54 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_ARG_MIN_MAX_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_ARG_MIN_MAX_PARAMETER_H_ | |||
| #ifdef ENABLE_ARM64 | |||
| #include <arm_neon.h> | |||
| #endif | |||
| #include "nnacl/op_base.h" | |||
| typedef int (*COMPARE_FUNCTION)(const void *a, const void *b); | |||
| typedef struct ArgElement { | |||
| uint32_t index_; | |||
| union ArgData { | |||
| int8_t i8_data_; | |||
| int32_t i_data_; | |||
| float f_data_; | |||
| #ifdef ENABLE_ARM64 | |||
| float16_t f16_data_; | |||
| #endif | |||
| } data_; | |||
| } ArgElement; | |||
| typedef struct ArgMinMaxParameter { | |||
| OpParameter op_parameter_; | |||
| bool out_value_; | |||
| bool keep_dims_; | |||
| bool get_max_; | |||
| int32_t axis_; | |||
| int32_t topk_; | |||
| int32_t axis_type_; | |||
| int32_t dims_size_; | |||
| int32_t data_type_; // equals to type_id | |||
| int32_t in_strides_[COMM_SHAPE_SIZE]; | |||
| int32_t out_strides_[COMM_SHAPE_SIZE]; | |||
| ArgElement *arg_elements_; | |||
| } ArgMinMaxParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_ARG_MIN_MAX_PARAMETER_H_ | |||
| @@ -0,0 +1,46 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_ARTITHMETIC_H_ | |||
| #define MINDSPORE_LITE_NNACL_ARTITHMETIC_H_ | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/common_func.h" | |||
| #include "nnacl/nnacl_utils.h" | |||
| typedef struct ArithmeticParameter { | |||
| OpParameter op_parameter_; | |||
| bool broadcasting_; | |||
| size_t ndim_; | |||
| int activation_type_; | |||
| int in_shape0_[10]; | |||
| int in_elements_num0_; | |||
| int in_shape1_[10]; | |||
| int in_elements_num1_; | |||
| int out_shape_[10]; | |||
| int out_elements_num_; | |||
| int in_strides0_[10]; | |||
| int in_strides1_[10]; | |||
| int out_strides_[10]; | |||
| int multiples0_[10]; | |||
| int multiples1_[10]; | |||
| int eltwise_mode_; // eltwise need | |||
| } ArithmeticParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_ARTITHMETIC_H_ | |||
| @@ -0,0 +1,30 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_ARITHMETIC_SELF_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_ARITHMETIC_SELF_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/errorcode.h" | |||
| #include "nnacl/int8/quantize.h" | |||
| // For Abs, Cos, Exp, Log, Square, Sqrt, Rsqrt ops. | |||
| typedef struct ArithmeticSelfParameter { | |||
| OpParameter op_parameter_; | |||
| ArithSelfQuantArg quant_arg_; | |||
| } ArithmeticSelfParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_ARITHMETIC_SELF_PARAMETER_H_ | |||
| @@ -0,0 +1,33 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_ASSEMBLY_GLOBAL_H | |||
| #define MINDSPORE_LITE_NNACL_ASSEMBLY_GLOBAL_H | |||
| .macro asm_function fname | |||
| #ifdef __APPLE__ | |||
| .globl _\fname; | |||
| _\fname : | |||
| #else | |||
| .global \fname; | |||
| #ifdef __ELE__ | |||
| .hidden \fname; | |||
| .type \fname, % function; | |||
| #endif | |||
| \fname : | |||
| #endif | |||
| .endm | |||
| #endif // MINDSPORE_LITE_NNACL_ASSEMBLY_GLOBAL_H | |||
| @@ -0,0 +1,34 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_BASE_ARITHMETIC_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_BASE_ARITHMETIC_BASE_H_ | |||
| #include "nnacl/arithmetic.h" | |||
| #include "nnacl/nnacl_utils.h" | |||
| #include "nnacl/nnacl_common.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void CalcMultiplesAndStrides(ArithmeticParameter *param); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_BASE_ARITHMETIC_BASE_H_ | |||
| @@ -0,0 +1,33 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_BATCH_TO_SPACE_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_BATCH_TO_SPACE_BASE_H_ | |||
| #include <string.h> | |||
| #include "nnacl/op_base.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void BatchToSpaceNoCropForNHWC(const void *input, void *output, const int *in_shape, int out_n, const int *block, | |||
| int data_size); | |||
| void BatchToSpaceForNHWC(const void *input, void *output, const int *in_shape, int out_n, const int *block, | |||
| const int *crops, int data_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_BATCH_TO_SPACE_BASE_H_ | |||
| @@ -0,0 +1,104 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_CAST_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_CAST_BASE_H_ | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/nnacl_common.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| inline void BoolToFloat32(const bool *input, float *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (float)input[i]; | |||
| } | |||
| } | |||
| inline void Uint8ToFloat32(const uint8_t *input, float *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (float)input[i]; | |||
| } | |||
| } | |||
| inline void Int32ToFloat32(const int32_t *input, float *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (float)input[i]; | |||
| } | |||
| } | |||
| inline void Int64ToFloat32(const int64_t *input, float *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (float)input[i]; | |||
| } | |||
| } | |||
| #ifdef ENABLE_FP16 | |||
| inline void Int64ToFp16(const int64_t *input, float16_t *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (float16_t)input[i]; | |||
| } | |||
| } | |||
| #endif | |||
| inline void Fp16ToFloat32(const uint16_t *input, float *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = ShortToFloat32(input[i]); | |||
| } | |||
| } | |||
| inline void Float32ToFp16(const float *input, uint16_t *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = Float32ToShort(input[i]); | |||
| } | |||
| } | |||
| inline void Float32ToInt32(const float *input, int32_t *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (int32_t)input[i]; | |||
| } | |||
| } | |||
| inline void Float32ToInt64(const float *input, int64_t *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (int64_t)input[i]; | |||
| } | |||
| } | |||
| inline void Int32ToInt64(const int32_t *input, int64_t *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (int64_t)input[i]; | |||
| } | |||
| } | |||
| inline void Float32ToInt16(const float *input, int16_t *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (int16_t)input[i]; | |||
| } | |||
| } | |||
| inline void BoolToInt32(const bool *input, int32_t *output, int number) { | |||
| for (int i = 0; i < number; ++i) { | |||
| output[i] = (int32_t)input[i]; | |||
| } | |||
| } | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_CAST_BASE_H_ | |||
| @@ -0,0 +1,32 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_FP32_CONCAT_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_FP32_CONCAT_BASE_H_ | |||
| #include <string.h> | |||
| #include "nnacl/op_base.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void Concat(void **input, int input_num, int axis, int **inputs_output_shape, size_t shape_size, void *output, | |||
| int task_id, int thread_num, int data_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_FP32_CONCAT_BASE_H_ | |||
| @@ -0,0 +1,32 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_BASE_CONV1X1_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_BASE_CONV1X1_BASE_H_ | |||
| #include "nnacl/conv_parameter.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void Conv1x1InputPack(const void *src_ptr, void *dst_ptr, ConvParameter *conv_param, int data_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_BASE_CONV1X1_BASE_H_ | |||
| @@ -0,0 +1,30 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_DEPTH_TO_SPACE_H_ | |||
| #define MINDSPORE_LITE_NNACL_DEPTH_TO_SPACE_H_ | |||
| #include <string.h> | |||
| #include "nnacl/depth_to_space_parameter.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void DepthToSpaceForNHWC(const void *input, void *output, const int *in_shape, const DepthToSpaceParameter *param); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_DEPTH_TO_SPACE_H_ | |||
| @@ -0,0 +1,32 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_FILL_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_FILL_BASE_H_ | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/errorcode.h" | |||
| #include "nnacl/fill_parameter.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| int FillFp32(float *output, int size, float data); | |||
| int FillInt32(int *output, int size, int data); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_FILL_BASE_H_ | |||
| @@ -0,0 +1,33 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_GATHER_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_GATHER_BASE_H_ | |||
| #include <string.h> | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/errorcode.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| int Gather(const void *input, int outer_size, int inner_size, int limit, const int *indices, int indices_element_size, | |||
| void *output, int data_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_GATHER_BASE_H_ | |||
| @@ -0,0 +1,63 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_MINIMAL_FILTERING_GENERATOR_H_ | |||
| #define MINDSPORE_LITE_NNACL_MINIMAL_FILTERING_GENERATOR_H_ | |||
| #ifdef ENABLE_ARM | |||
| #include <arm_neon.h> | |||
| #endif | |||
| #include <stdbool.h> | |||
| #include "nnacl/pack.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void Polynomial(const float *interval, float *m, int degree); | |||
| void DiagonalPlusMatrix(const float *matrix, float *diagonal_matrix, int degree); | |||
| void ResidueMatrix(const float *interval, float *b, int row, int col); | |||
| int LT(const float *poly_array, float *matrix_lt, int n); | |||
| void T(const float *poly_array, float *matrix_t, int n); | |||
| int B(const float *poly_array, float *matrix_b, int in_unit); | |||
| void GenerateIntervalArray(float *array, float interval, int degree); | |||
| void MatrixTranspose(const float *matrix, float *trans_matrix, int row, int col); | |||
| void MatrixMultiply(const float *matrix_a, const float *matrix_b, float *matrix_c, int m, int k, int n); | |||
| int CookToomFilter(float *matrix_a, float *matrix_at, float *matrix_b, float *matrix_bt, float *matrix_g, | |||
| float *matrix_gt, float coefficient, int out_unit, int filter_size); | |||
| void MatrixMultiplyWinograd(const float *matix_a, const float *matrix_b, float *matrix_c, int m, int k, int n, | |||
| int in_channel, int c4_channel); | |||
| int WinogradWeightTransform(const float *weight_data, float *winograd_data, float *matrix_g, const float *matrix_gt, | |||
| int oc_block, int input_unit_, int kernel_unit_, int channel, int batch, bool pack); | |||
| #if defined(ENABLE_ARM) || defined(ENABLE_SSE) | |||
| void MatrixMultiplyVec(const MS_FLOAT32X4 *matrix_a, const MS_FLOAT32X4 *matrix_b, MS_FLOAT32X4 *matrix_c, | |||
| const float *bias, int m, int k, int n); | |||
| #endif | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_MINIMAL_FILTERING_GENERATOR_H_ | |||
| @@ -0,0 +1,34 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_BASE_SLICE_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_BASE_SLICE_BASE_H_ | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/errorcode.h" | |||
| #include "nnacl/slice_parameter.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void PadSliceParameterTo4D(SliceParameter *param); | |||
| void DoSlice(const void *input, void *output, SliceParameter *param, int thread_id, int data_size); | |||
| void DoSliceNoParallel(const void *input, void *output, SliceParameter *param, int data_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_BASE_SLICE_BASE_H_ | |||
| @@ -0,0 +1,30 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_BASE_SPACE_TO_DEPTH_BASE_H_ | |||
| #define MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_BASE_SPACE_TO_DEPTH_BASE_H_ | |||
| #include "nnacl/op_base.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| int SpaceToDepthForNHWC(const void *input, void *output, const int *in_shape, const int *out_shape, int shape_size, | |||
| int block_size, int h_start, int h_end, int data_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_BASE_SPACE_TO_DEPTH_BASE_H_ | |||
| @@ -0,0 +1,32 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_NNACL_SPLIT_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_NNACL_SPLIT_BASE_H_ | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/split_parameter.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| int DoSplit(void *in_data, void **out_data, const int *input_shape, int offset, int num_unit, | |||
| SplitParameter *split_param, int data_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_NNACL_SPLIT_BASE_H_ | |||
| @@ -0,0 +1,30 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_STACK_H_ | |||
| #define MINDSPORE_LITE_NNACL_STACK_H_ | |||
| #include <string.h> | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/stack_parameter.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void Stack(char **inputs, char *output, size_t input_num, size_t copy_size, size_t outter_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_STACK_H_ | |||
| @@ -0,0 +1,53 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_BASE_TILE_H_ | |||
| #define MINDSPORE_LITE_NNACL_BASE_TILE_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct TileParameter { | |||
| // primitive parameter | |||
| OpParameter op_parameter_; | |||
| int multiples_[5]; | |||
| int dims_[5]; | |||
| size_t dims_size_; | |||
| size_t multiples_size_; | |||
| // shape correlative | |||
| int in_shape_[5]; | |||
| int out_shape_[5]; | |||
| int in_strides_[5]; | |||
| int out_strides_[5]; | |||
| // other parameter | |||
| int in_dim_; | |||
| size_t data_size_; | |||
| size_t fast_outer_size_; | |||
| size_t fast_stride_; | |||
| size_t fast_multiple_; | |||
| } TileParameter; | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void Tile(void *input_data, void *output_data, TileParameter *parameter); | |||
| void TileSimple(void *input_data, void *output_data, size_t begin, size_t end, TileParameter *parameter); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_BASE_TILE_H_ | |||
| @@ -0,0 +1,32 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_UNSTACK_H_ | |||
| #define MINDSPORE_LITE_NNACL_UNSTACK_H_ | |||
| #include <string.h> | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/unstack_parameter.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| void Unstack(const void *input, void **output, UnstackParameter *para, int data_size); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_UNSTACK_H_ | |||
| @@ -0,0 +1,34 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_ZEROSLIKE_BASE_H_ | |||
| #define MINDSPORE_LITE_NNACL_ZEROSLIKE_BASE_H_ | |||
| #include "nnacl/op_base.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| static inline void ApproximateZerosLike(void *output, int number, int data_size) { | |||
| memset(output, 0.0, number * data_size); | |||
| return; | |||
| } | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_ZEROSLIKE_BASE_H_ | |||
| @@ -0,0 +1,31 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_BATCH_TO_SPACE_H_ | |||
| #define MINDSPORE_LITE_NNACL_BATCH_TO_SPACE_H_ | |||
| #include <string.h> | |||
| #include "nnacl/op_base.h" | |||
| #define BATCH_TO_SPACE_BLOCK_SHAPE_SIZE 2 | |||
| typedef struct BatchToSpaceParameter { | |||
| OpParameter op_parameter_; | |||
| int32_t block_shape_[BATCH_TO_SPACE_BLOCK_SHAPE_SIZE]; | |||
| int32_t crops_[COMM_SHAPE_SIZE]; | |||
| bool no_crop_; | |||
| } BatchToSpaceParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_FP32_BATCH_TO_SPACE_H_ | |||
| @@ -0,0 +1,32 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_BATCHNORM_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_BATCHNORM_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct BatchNormParameter { | |||
| OpParameter op_parameter_; | |||
| float epsilon_; | |||
| float momentum_; | |||
| int unit_; | |||
| int units_; | |||
| int channel_; | |||
| bool fused_; | |||
| } BatchNormParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_BATCHNORM_PARAMETER_H_ | |||
| @@ -0,0 +1,34 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_FP32_BROADCAST_TO_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_FP32_BROADCAST_TO_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct BroadcastToParameter { | |||
| OpParameter op_parameter_; | |||
| int shape_[COMM_SHAPE_SIZE]; | |||
| size_t shape_size_; | |||
| } BroadcastToParameter; | |||
| typedef struct BroadcastShapeInfo { | |||
| int input_shape_[COMM_SHAPE_SIZE]; | |||
| int input_shape_size_; | |||
| int output_shape_[COMM_SHAPE_SIZE]; | |||
| int output_shape_size_; | |||
| } BroadcastShapeInfo; | |||
| #endif // MINDSPORE_LITE_NNACL_FP32_BROADCAST_TO_PARAMETER_H_ | |||
| @@ -0,0 +1,27 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_CAST_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_CAST_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct CastParameter { | |||
| OpParameter op_parameter_; | |||
| int dst_type_; | |||
| int src_type_; | |||
| } CastParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_CAST_PARAMETER_H_ | |||
| @@ -0,0 +1,77 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_COMMON_FUNC_H_ | |||
| #define MINDSPORE_LITE_NNACL_COMMON_FUNC_H_ | |||
| #include <string.h> | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/conv_parameter.h" | |||
| #include "nnacl/nnacl_common.h" | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| int8_t MinInt8(int8_t a, int8_t b); | |||
| int8_t MaxInt8(int8_t a, int8_t b); | |||
| void ReluFp32(float *data, float *dst, int ele_num); | |||
| void Relu6Fp32(float *data, float *dst, int ele_num); | |||
| #ifdef ENABLE_AVX | |||
| #ifdef WIN32 | |||
| void ReluFp32C8(float *data, float *dst, int ele_num); | |||
| void Relu6Fp32C8(float *data, float *dst, int ele_num); | |||
| #endif | |||
| #endif | |||
| int offset(const int *shape, const int dim0, const int dim1, const int dim2, const int dim3); | |||
| int offsetComm(const int *shape, const int dim0, const int dim1, const int dim2); | |||
| int offset4d(const int *shape, const int *dims); | |||
| static inline bool isAddOverflow(int32_t x, int32_t y) { | |||
| int32_t sum = x + y; | |||
| return (x > 0 && y > 0 && sum < 0) || (x < 0 && y < 0 && sum > 0); | |||
| } | |||
| static inline bool isMulOverflow(int32_t x, int32_t y) { | |||
| int32_t p = x * y; | |||
| return (x != 0) && (p / x != y); | |||
| } | |||
| static inline int GetStride(int *strides, const int *shape, int length) { | |||
| if (length <= 0) { | |||
| return 1; | |||
| } | |||
| int stride = 1; | |||
| for (int i = length - 1; i >= 0; --i) { | |||
| strides[i] = stride; | |||
| stride *= shape[i]; | |||
| } | |||
| return stride; | |||
| } | |||
| #ifdef ENABLE_ARM64 | |||
| void BiasAdd(const float *bias, float *data, size_t oc4, size_t plan_size); | |||
| void BiasAddRelu6(const float *bias, float *data, size_t oc4, size_t plan_size); | |||
| void BiasAddRelu(const float *bias, float *data, size_t oc4, size_t plan_size); | |||
| void Relu6(float *data, size_t element4); | |||
| void Relu(float *data, size_t element4); | |||
| #endif | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif /* MINDSPORE_LITE_NNACL_COMMON_FUNC_H_ */ | |||
| @@ -0,0 +1,35 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_CONCAT_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_CONCAT_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/int8/quantize.h" | |||
| typedef struct ConcatParameter { | |||
| OpParameter op_parameter_; | |||
| ConcatQuantArg quant_arg_; | |||
| int axis_; | |||
| int thread_count_; | |||
| int input_num_; | |||
| int **input_shapes_; | |||
| int *output_shapes_; | |||
| int64_t after_axis_size; | |||
| int64_t count_unit_; | |||
| } ConcatParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_CONCAT_PARAMETER_H_ | |||
| @@ -0,0 +1,31 @@ | |||
| /** | |||
| * Copyright 2020-2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct ConstantOfShapeParameter { | |||
| OpParameter op_parameter_; | |||
| union value_ { | |||
| float f32_value_; | |||
| int32_t int32_value_; | |||
| } value_; | |||
| int data_type_; | |||
| int element_size_; | |||
| } ConstantOfShapeParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_CONSTANT_OF_SHAPE_PARAMETER_H_ | |||
| @@ -0,0 +1,131 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_CONV_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_CONV_PARAMETER_H_ | |||
| #ifdef ENABLE_NEON | |||
| #include <arm_neon.h> | |||
| #endif | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/int8/quantize.h" | |||
| typedef struct ConvParameter { | |||
| OpParameter op_parameter_; | |||
| ConvQuantArg conv_quant_arg_; | |||
| int kernel_h_; | |||
| int kernel_w_; | |||
| int stride_h_; | |||
| int stride_w_; | |||
| int dilation_h_; | |||
| int dilation_w_; | |||
| int pad_u_; | |||
| int pad_d_; | |||
| int pad_l_; | |||
| int pad_r_; | |||
| int group_; | |||
| int tile_num_; | |||
| int input_batch_; | |||
| int input_h_; | |||
| int input_w_; | |||
| int input_channel_; | |||
| int output_batch_; | |||
| int output_h_; | |||
| int output_w_; | |||
| int output_channel_; | |||
| int thread_num_; | |||
| int input_unit_; | |||
| int output_unit_; | |||
| PadMode pad_mode_; | |||
| ActType act_type_; | |||
| int channel_multiplie_; | |||
| int output_padding_w_; | |||
| int output_padding_h_; | |||
| } ConvParameter; | |||
| typedef struct SlidingWindowParam { | |||
| int left_; | |||
| int right_; | |||
| int top_; | |||
| int bottom_; | |||
| int c_block_; | |||
| int block_channel_; | |||
| int ic4_channel_; | |||
| int out_step_; | |||
| int out_h_step_; | |||
| int in_step_; | |||
| int in_h_step_; | |||
| int in_sh_step_; // stride H | |||
| int in_sw_step_; // stride W | |||
| int in_kh_step_; // kernel H | |||
| int in_kw_step_; // kernel W | |||
| int kernel_step_; | |||
| } SlidingWindowParam; | |||
| #define OUPUT_UNIT 2 | |||
| #define DECONV_WINOGRAD_DEFAULT_UNIT 3 | |||
| #define DECONV_WINOGRAD_DEFAULT_TILE 8 | |||
| #define DECONV_WINOGRAD_BUFFER_COUNT 8 | |||
| typedef struct DeConvWg { | |||
| void *b_buffer_; | |||
| void *AT_; | |||
| void *BT_; | |||
| int kh_; | |||
| int kw_; | |||
| int k_; | |||
| int i_; | |||
| int o_; | |||
| } DeConvWg; | |||
| typedef struct DeConvWgABuffer { | |||
| bool buf_init_; | |||
| void *middle_buffer_; | |||
| void *dest_buffer_; | |||
| } DeConvWgABuffer; | |||
| typedef struct DeConvComputeUnit { | |||
| void *weight_; | |||
| void *tmp_buffer_; | |||
| int w_start_; | |||
| int h_start_; | |||
| int w_size_; | |||
| int h_size_; | |||
| bool use_winograd_; | |||
| DeConvWg winograd_; | |||
| } DeConvComputeUnit; | |||
| typedef struct DeConvParam { | |||
| DeConvComputeUnit *compute_units_; | |||
| int compute_size_; | |||
| DeConvWgABuffer a_buffer_[DECONV_WINOGRAD_BUFFER_COUNT]; | |||
| int input_plane_; | |||
| int output_plane_; | |||
| int kernel_plane_; | |||
| int ic_div4_; | |||
| int oc_div4_; | |||
| int ic_up4_; | |||
| int oc_up4_; | |||
| int thread_num_; | |||
| int in_tile_count_; | |||
| int in_tile_h_count_; | |||
| int in_tile_w_count_; | |||
| int out_tile_h_; | |||
| int out_tile_w_; | |||
| } DeConvParam; | |||
| #endif // MINDSPORE_LITE_NNACL_CONV_PARAMETER_H_ | |||
| @@ -0,0 +1,36 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_CROP_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_CROP_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/int8/quantize.h" | |||
| typedef struct CropParameter { | |||
| OpParameter op_parameter_; | |||
| CropQuantArg quant_arg; | |||
| int thread_count_; | |||
| int offset_size_; | |||
| int64_t offset_[COMM_SHAPE_SIZE]; | |||
| int64_t in_offset_[COMM_SHAPE_SIZE]; | |||
| int64_t axis_; | |||
| int *in_shape_; | |||
| int *out_shape_; | |||
| int input_dim_; | |||
| } CropParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_CROP_PARAMETER_H_ | |||
| @@ -0,0 +1,35 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_DEPTH_TO_SPACE_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_DEPTH_TO_SPACE_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct DepthToSpaceParameter { | |||
| OpParameter op_parameter_; | |||
| // primitive parameter | |||
| int32_t block_size_; | |||
| // shape correlative | |||
| int32_t in_stride_dim0_; | |||
| int32_t in_stride_dim1_; | |||
| int32_t in_stride_dim2_; | |||
| int32_t out_stride_dim0_; | |||
| int32_t out_stride_dim1_; | |||
| int32_t out_stride_dim2_; | |||
| // other parameter | |||
| uint8_t data_type_size_; | |||
| } DepthToSpaceParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_DEPTH_TO_SPACE_PARAMETER_H_ | |||
| @@ -0,0 +1,48 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_DETECTION_POST_PROCESS_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_DETECTION_POST_PROCESS_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct DetectionPostProcessParameter { | |||
| OpParameter op_parameter_; | |||
| float h_scale_; | |||
| float w_scale_; | |||
| float x_scale_; | |||
| float y_scale_; | |||
| float nms_iou_threshold_; | |||
| float nms_score_threshold_; | |||
| int64_t max_detections_; | |||
| int64_t detections_per_class_; | |||
| int64_t max_classes_per_detection_; | |||
| int64_t num_classes_; | |||
| bool use_regular_nms_; | |||
| bool out_quantized_; | |||
| float *anchors_; | |||
| void *decoded_boxes_; | |||
| void *nms_candidate_; | |||
| void *indexes_; | |||
| void *scores_; | |||
| void *all_class_indexes_; | |||
| void *all_class_scores_; | |||
| void *single_class_indexes_; | |||
| void *selected_; | |||
| } DetectionPostProcessParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_DETECTION_POST_PROCESS_PARAMETER_H_ | |||
| @@ -0,0 +1,62 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_ERRORCODE_H_ | |||
| #define MINDSPORE_LITE_NNACL_ERRORCODE_H_ | |||
| typedef enum ErrorCodeCommonEnum { | |||
| NNACL_OK = 0, | |||
| NNACL_ERR = 1, | |||
| NNACL_NULL_PTR, | |||
| NNACL_PARAM_INVALID, | |||
| NNACL_INFER_INVALID, | |||
| NNACL_INPUT_TENSOR_ERROR, | |||
| NNACL_COMMON_END = 9999 | |||
| } ErrorCodeCommonEnum; | |||
| typedef enum ErrorCodeFp32OpEnum { | |||
| NNACL_ERRCODE_OP_FP32_START = 10000, | |||
| NNACL_ERRCODE_STRASSEN_RECURSION_MALLOC, | |||
| NNACL_ERRCODE_REVERSE_MALLOC, | |||
| NNACL_ERRCODE_SQRT_NEGATIVE, | |||
| NNACL_ERRCODE_RSQRT_NEGATIVE, | |||
| NNACL_ERRCODE_RSQRT_NEGATIVE_OR_ZERO, | |||
| NNACL_ERRCODE_LOG_NEGATIVE_OR_ZERO, | |||
| NNACL_ERRCODE_DIVISOR_ZERO, | |||
| NNACL_ERRCODE_INDEX_OUT_OF_RANGE, | |||
| NNACL_ERRCODE_WINOGRAD_GENERATOR_ERROR, | |||
| NNACL_ERRCODE_OP_FP32_END = 19999 | |||
| } ErrorCodeFp32OpEnum; | |||
| typedef enum ErrorCodeFp16OpEnum { | |||
| NNACL_ERRCODE_OP_FP16_START = 20000, | |||
| NNACL_ERRCODE_OP_FP16_WINOGRAD_GENERATOR, | |||
| NNACL_ERRCODE_OP_FP16_END = 29999 | |||
| } ErrorCodeFp16OpEnum; | |||
| typedef enum ErrorCodeUint8OpEnum { | |||
| NNACL_ERRCODE_OP_UINT8_START = 30000, | |||
| NNACL_ERRCODE_OP_UINT8_END = 39999 | |||
| } ErrorCodeUint8OpEnum; | |||
| typedef enum ErrorCodeInt8OpEnum { | |||
| NNACL_ERRCODE_OP_INT8_START = 40000, | |||
| NNACL_ERRCODE_ADD_OVERFLOW, | |||
| NNACL_ERRCODE_MUL_OVERFLOW, | |||
| NNACL_ERRCODE_OP_INT8_END = 49999 | |||
| } ErrorCodeInt8OpEnums; | |||
| #endif // MINDSPORE_LITE_NNACL_ERRORCODE_H_ | |||
| @@ -0,0 +1,28 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_FILL_PARAMETER_H_ | |||
| #define MINDSPORE_LITE_NNACL_FILL_PARAMETER_H_ | |||
| #include "nnacl/op_base.h" | |||
| typedef struct FillParameter { | |||
| // Primitive parameter | |||
| OpParameter op_parameter_; | |||
| int dims_[COMM_SHAPE_SIZE]; | |||
| int num_dims_; | |||
| } FillParameter; | |||
| #endif // MINDSPORE_LITE_NNACL_FILL_PARAMETER_H_ | |||
| @@ -0,0 +1,49 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef MINDSPORE_LITE_NNACL_FP32_ACTIVATION_H_ | |||
| #define MINDSPORE_LITE_NNACL_FP32_ACTIVATION_H_ | |||
| #include <math.h> | |||
| #include "nnacl/op_base.h" | |||
| #include "nnacl/int8/fixed_point.h" | |||
| typedef struct ActivationParameter { | |||
| OpParameter op_parameter_; | |||
| int type_; | |||
| float alpha_; | |||
| float min_val_; | |||
| float max_val_; | |||
| } ActivationParameter; | |||
| #ifdef __cplusplus | |||
| extern "C" { | |||
| #endif | |||
| int Fp32Relu(const float *src, int length, float *dst); | |||
| int Fp32Relu6(const float *src, int length, float *dst); | |||
| int LRelu(const float *src, int length, float *dst, float alpha); | |||
| int Sigmoid(const float *src, int length, float *dst); | |||
| int Tanh(const float *src, int length, float *dst); | |||
| int HSigmoid(const float *src, int length, float *dst); | |||
| int Swish(const float *src, int length, float *dst); | |||
| int HSwish(const float *src, int length, float *dst); | |||
| int HardTanh(const float *src, int length, float *dst, float min_val, float max_val); | |||
| int Gelu(const float *src, int length, float *dst, bool approximate); | |||
| float TanhOpt(float src); | |||
| #ifdef __cplusplus | |||
| } | |||
| #endif | |||
| #endif // MINDSPORE_LITE_NNACL_FP32_ACTIVATION_H_ | |||