diff --git a/Hardware/FabReader2/FabReader2.kicad_prl b/Hardware/FabReader2/FabReader2.kicad_prl index 5edfb52..e9c83e3 100644 --- a/Hardware/FabReader2/FabReader2.kicad_prl +++ b/Hardware/FabReader2/FabReader2.kicad_prl @@ -1,6 +1,6 @@ { "board": { - "active_layer": 0, + "active_layer": 36, "active_layer_preset": "", "auto_track_width": true, "hidden_nets": [], @@ -62,7 +62,7 @@ 35, 36 ], - "visible_layers": "7fcfdff_80000007", + "visible_layers": "7fcffff_80000007", "zone_display_mode": 0 }, "meta": { diff --git a/Software/.cproject b/Software/.cproject new file mode 100644 index 0000000..fe6d489 --- /dev/null +++ b/Software/.cproject @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/.mxproject b/Software/.mxproject new file mode 100644 index 0000000..577c393 --- /dev/null +++ b/Software/.mxproject @@ -0,0 +1,25 @@ +[PreviousGenFiles] +AdvancedFolderStructure=true +HeaderFileListSize=3 +HeaderFiles#0=/Users/kjkriegel/Documents/Development/FabAccess/FabReader2/Software/Core/Inc/stm32l4xx_it.h +HeaderFiles#1=/Users/kjkriegel/Documents/Development/FabAccess/FabReader2/Software/Core/Inc/stm32l4xx_hal_conf.h +HeaderFiles#2=/Users/kjkriegel/Documents/Development/FabAccess/FabReader2/Software/Core/Inc/main.h +HeaderFolderListSize=1 +HeaderPath#0=/Users/kjkriegel/Documents/Development/FabAccess/FabReader2/Software/Core/Inc +HeaderFiles=; +SourceFileListSize=3 +SourceFiles#0=/Users/kjkriegel/Documents/Development/FabAccess/FabReader2/Software/Core/Src/stm32l4xx_it.c +SourceFiles#1=/Users/kjkriegel/Documents/Development/FabAccess/FabReader2/Software/Core/Src/stm32l4xx_hal_msp.c +SourceFiles#2=/Users/kjkriegel/Documents/Development/FabAccess/FabReader2/Software/Core/Src/main.c +SourceFolderListSize=1 +SourcePath#0=/Users/kjkriegel/Documents/Development/FabAccess/FabReader2/Software/Core/Src +SourceFiles=; + +[PreviousLibFiles] +LibFiles=Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_def.h;Drivers/STM32L4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_i2c.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_i2c_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ramfunc.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_dma.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_dma_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_cortex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_exti.h;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_tim_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_uart_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_def.h;Drivers/STM32L4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_i2c.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_i2c_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_rcc_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ramfunc.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_gpio_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_dma.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_dma_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_pwr_ex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_cortex.h;Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_exti.h;Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h;Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h;Drivers/CMSIS/Device/ST/STM32L4xx/Include/system_stm32l4xx.h;Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates/system_stm32l4xx.c;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/core_cm35p.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/core_armv81mml.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/cmsis_armclang_ltm.h; + +[PreviousUsedCubeIDEFiles] +SourceFiles=Core/Src/main.c;Core/Src/stm32l4xx_it.c;Core/Src/stm32l4xx_hal_msp.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c;Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates/system_stm32l4xx.c;Core/Src/system_stm32l4xx.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c;Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_exti.c;Drivers/CMSIS/Device/ST/STM32L4xx/Source/Templates/system_stm32l4xx.c;Core/Src/system_stm32l4xx.c;;; +HeaderPath=Drivers/STM32L4xx_HAL_Driver/Inc;Drivers/STM32L4xx_HAL_Driver/Inc/Legacy;Drivers/CMSIS/Device/ST/STM32L4xx/Include;Drivers/CMSIS/Include;Core/Inc; +CDefines=USE_HAL_DRIVER;STM32L476xx;USE_HAL_DRIVER;USE_HAL_DRIVER; + diff --git a/Software/.osx.project b/Software/.osx.project new file mode 100644 index 0000000..e69de29 diff --git a/Software/.project b/Software/.project new file mode 100644 index 0000000..958597d --- /dev/null +++ b/Software/.project @@ -0,0 +1,32 @@ + + + FabReader2 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + com.st.stm32cube.ide.mcu.MCUProjectNature + org.eclipse.cdt.core.cnature + com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature + com.st.stm32cube.ide.mcu.MCUCubeProjectNature + com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature + com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature + com.st.stm32cube.ide.mcu.MCURootProjectNature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Software/CMakeLists.txt b/Software/CMakeLists.txt deleted file mode 100644 index 925f8ad..0000000 --- a/Software/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE! -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_VERSION 1) -cmake_minimum_required(VERSION 3.22) - -# specify cross compilers and tools -set(CMAKE_C_COMPILER arm-none-eabi-gcc) -set(CMAKE_CXX_COMPILER arm-none-eabi-g++) -set(CMAKE_ASM_COMPILER arm-none-eabi-gcc) -set(CMAKE_AR arm-none-eabi-ar) -set(CMAKE_OBJCOPY arm-none-eabi-objcopy) -set(CMAKE_OBJDUMP arm-none-eabi-objdump) -set(SIZE arm-none-eabi-size) -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -# project settings -project(FabReader2 C CXX ASM) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_C_STANDARD 11) - -#Uncomment for hardware floating point -#add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING) -#add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16) -#add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16) - -#Uncomment for software floating point -#add_compile_options(-mfloat-abi=soft) - -add_compile_options(-mcpu=cortex-m4 -mthumb -mthumb-interwork) -add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0) - -# uncomment to mitigate c++17 absolute addresses warnings -#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register") - -# Enable assembler files preprocessing -add_compile_options($<$:-x$assembler-with-cpp>) - -if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") - message(STATUS "Maximum optimization for speed") - add_compile_options(-Ofast) -elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - message(STATUS "Maximum optimization for speed, debug info included") - add_compile_options(-Ofast -g) -elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") - message(STATUS "Maximum optimization for size") - add_compile_options(-Os) -else () - message(STATUS "Minimal optimization, debug info included") - add_compile_options(-Og -g) -endif () - -include_directories(Core/Inc Drivers/STM32L4xx_HAL_Driver/Inc Drivers/STM32L4xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32L4xx/Include Drivers/CMSIS/Include Drivers/BSP/Components/ST25R3911 Middlewares/ST/rfal/Inc Middlewares/ST/ndef/Inc/message Middlewares/ST/ndef/Inc/poller) - -add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32L476xx) - -file(GLOB_RECURSE SOURCES "Core/*.*" "Drivers/*.*") - -set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32L476RGTX_FLASH.ld) - -add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map) -add_link_options(-mcpu=cortex-m4 -mthumb -mthumb-interwork) -add_link_options(-T ${LINKER_SCRIPT}) - -add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT}) - -set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex) -set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin) - -add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD - COMMAND ${CMAKE_OBJCOPY} -Oihex $ ${HEX_FILE} - COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${BIN_FILE} - COMMENT "Building ${HEX_FILE} -Building ${BIN_FILE}") diff --git a/Software/CMakeLists_template.txt b/Software/CMakeLists_template.txt deleted file mode 100644 index a38456d..0000000 --- a/Software/CMakeLists_template.txt +++ /dev/null @@ -1,72 +0,0 @@ -#${templateWarning} -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_VERSION 1) -${cmakeRequiredVersion} -# specify cross compilers and tools -set(CMAKE_C_COMPILER arm-none-eabi-gcc) -set(CMAKE_CXX_COMPILER arm-none-eabi-g++) -set(CMAKE_ASM_COMPILER arm-none-eabi-gcc) -set(CMAKE_AR arm-none-eabi-ar) -set(CMAKE_OBJCOPY arm-none-eabi-objcopy) -set(CMAKE_OBJDUMP arm-none-eabi-objdump) -set(SIZE arm-none-eabi-size) -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) - -# project settings -project(${projectName} C CXX ASM) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_C_STANDARD 11) - -#Uncomment for hardware floating point -#add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING) -#add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16) -#add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16) - -#Uncomment for software floating point -#add_compile_options(-mfloat-abi=soft) - -add_compile_options(-mcpu=${mcpu} -mthumb -mthumb-interwork) -add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0) - -# uncomment to mitigate c++17 absolute addresses warnings -#set(CMAKE_CXX_FLAGS "$${CMAKE_CXX_FLAGS} -Wno-register") - -# Enable assembler files preprocessing -add_compile_options($<$:-x$assembler-with-cpp>) - -if ("$${CMAKE_BUILD_TYPE}" STREQUAL "Release") - message(STATUS "Maximum optimization for speed") - add_compile_options(-Ofast) -elseif ("$${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - message(STATUS "Maximum optimization for speed, debug info included") - add_compile_options(-Ofast -g) -elseif ("$${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") - message(STATUS "Maximum optimization for size") - add_compile_options(-Os) -else () - message(STATUS "Minimal optimization, debug info included") - add_compile_options(-Og -g) -endif () - -include_directories(${includes} Drivers/BSP/Components/ST25R3911 Middlewares/ST/rfal/Inc Middlewares/ST/ndef/Inc/message Middlewares/ST/ndef/Inc/poller) - -add_definitions(${defines}) - -file(GLOB_RECURSE SOURCES ${sources}) - -set(LINKER_SCRIPT $${CMAKE_SOURCE_DIR}/${linkerScript}) - -add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=$${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.map) -add_link_options(-mcpu=${mcpu} -mthumb -mthumb-interwork) -add_link_options(-T $${LINKER_SCRIPT}) - -add_executable($${PROJECT_NAME}.elf $${SOURCES} $${LINKER_SCRIPT}) - -set(HEX_FILE $${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.hex) -set(BIN_FILE $${PROJECT_BINARY_DIR}/$${PROJECT_NAME}.bin) - -add_custom_command(TARGET $${PROJECT_NAME}.elf POST_BUILD - COMMAND $${CMAKE_OBJCOPY} -Oihex $ $${HEX_FILE} - COMMAND $${CMAKE_OBJCOPY} -Obinary $ $${BIN_FILE} - COMMENT "Building $${HEX_FILE} -Building $${BIN_FILE}") diff --git a/Software/Core/Inc/demo.h b/Software/Core/Inc/demo.h deleted file mode 100644 index 79b564f..0000000 --- a/Software/Core/Inc/demo.h +++ /dev/null @@ -1,62 +0,0 @@ -/** - ****************************************************************************** - * - * COPYRIGHT(c) 2017 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -/*! \file - * - * \author - * - * \brief Demo functionality header file - * - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __DEMO_H -#define __DEMO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "platform.h" -#include "st_errno.h" - -/* Exported types ------------------------------------------------------------*/ -/* Exported constants --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ - -/* Exported functions ------------------------------------------------------- */ -bool demoIni( void ); -extern void demoCycle(void); - -#ifdef __cplusplus -} -#endif - -#endif /* __DEMO_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Inc/demo_ce.h b/Software/Core/Inc/demo_ce.h deleted file mode 100644 index 6bb2d90..0000000 --- a/Software/Core/Inc/demo_ce.h +++ /dev/null @@ -1,127 +0,0 @@ -/** - ****************************************************************************** - * @file demo_ce.h - * @author MMY Application Team - * @brief Implementation of Common CardEmulation parts - ****************************************************************************** - ** This notice applies to any and all portions of this file - * that are not between comment pairs USER CODE BEGIN and - * USER CODE END. Other portions of this file, whether - * inserted by the user or by software development tools - * are owned by their respective copyright owners. - * - * COPYRIGHT(c) 2018 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef DEMO_CE_H -#define DEMO_CE_H - -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "platform.h" - -/** @addtogroup X-CUBE-NFC6_Applications - * @brief Sample applications for X-NUCLEO-NFC06A1 STM32 expansion boards. - * @{ - */ - -/** @addtogroup CardEmulation - * @{ - */ - -/** @defgroup CE_CardEmul - * @brief Card Emulation management functions - * @{ - */ - - -/* Exported constants --------------------------------------------------------*/ -/* T3T Information Block Bytes offset */ -#define T3T_INFBLK_VER_OFFSET 0 -#define T3T_INFBLK_NBR_OFFSET 1 -#define T3T_INFBLK_NBW_OFFSET 2 -#define T3T_INFBLK_NMAXB_OFFSET 3 -#define T3T_INFBLK_WRITEFLAG_OFFSET 9 -#define T3T_INFBLK_RWFLAG_OFFSET 10 -#define T3T_INFBLK_LN_OFFSET 11 -#define T3T_INFBCK_CHECKSUM_OFFSET 14 - -/* T3T Information Block WriteFlag values */ -#define T3T_WRITEFLAG_OFF 0x00 -#define T3T_WRITEFLAG_ON 0x0F - -/* T3T COMMAND OFFSET */ -#define T3T_CHECK_RESP_CMD_OFFSET 0 -#define T3T_CHECK_RESP_NFCID2_OFFSET 1 -#define T3T_CHECK_RESP_SF1_OFFSET 9 -#define T3T_CHECK_RESP_SF2_OFFSET 10 -#define T3T_CHECK_RESP_NOB_OFFSET 11 -#define T3T_CHECK_RESP_DATA_OFFSET 12 -#define T3T_UPDATE_RESP_CMD_OFFSET 0 -#define T3T_UPDATE_RESP_NFCID2_OFFSET 1 -#define T3T_UPDATE_RESP_SF1_OFFSET 9 -#define T3T_UPDATE_RESP_SF2_OFFSET 10 - -/* External variables --------------------------------------------------------*/ -/* Exported macro ------------------------------------------------------------*/ -/* Exported functions ------------------------------------------------------- */ -/** @defgroup CE_CardEmul_Exported_functions - * @{ - */ -void demoCeInit(uint8_t* nfcfNfcid); -uint16_t demoCeT3T(uint8_t *rxData, uint16_t rxDataLen, uint8_t *txBuf, uint16_t txBufLen ); -uint16_t demoCeT4T(uint8_t *rxData, uint16_t rxDataLen, uint8_t *txBuf, uint16_t txBufLen ); - - - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus - } -#endif - -#endif /* DEMO_CE_H */ - -/******************* (C) COPYRIGHT 2018 STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Inc/logger.h b/Software/Core/Inc/logger.h deleted file mode 100644 index bb21870..0000000 --- a/Software/Core/Inc/logger.h +++ /dev/null @@ -1,96 +0,0 @@ -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/* - * PROJECT: - * $Revision: $ - * LANGUAGE: ANSI C - */ - -/*! \file - * - * \author - * - * \brief serial output log declaration file - * - */ -/*! - * - * This driver provides a printf-like way to output log messages - * via the UART interface. It makes use of the uart driver. - * - * API: - * - Write a log message to UART output: #DEBUG - */ - -#ifndef LOGGER_H -#define LOGGER_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" - -/* -****************************************************************************** -* DEFINES -****************************************************************************** -*/ -#define LOGGER_ON 1 -#define LOGGER_OFF 0 - -/*! - ***************************************************************************** - * \brief Writes out a formated string via UART interface - * - * This function is used to write a formated string via the UART interface. - * - ***************************************************************************** - */ -extern void logUsartInit(UART_HandleTypeDef *husart); - -/*! - ***************************************************************************** - * \brief Writes out a formated string via UART interface - * - * This function is used to write a formated string via the UART interface. - * - ***************************************************************************** - */ -extern int logUsart(const char* format, ...); - -/*! - ***************************************************************************** - * \brief helper to convert hex data into formated string - * - * \param[in] data : pointer to buffer to be dumped. - * - * \param[in] dataLen : buffer length - * - * \return hex formated string - * - ***************************************************************************** - */ -extern char* hex2Str(unsigned char * data, size_t dataLen); - -#endif /* LOGGER_H */ - diff --git a/Software/Core/Inc/main.h b/Software/Core/Inc/main.h deleted file mode 100644 index e8b346b..0000000 --- a/Software/Core/Inc/main.h +++ /dev/null @@ -1,101 +0,0 @@ -/** - ****************************************************************************** - * @file : main.h - * @brief : Header for main.c file. - * This file contains the common defines of the application. - ****************************************************************************** - ** This notice applies to any and all portions of this file - * that are not between comment pairs USER CODE BEGIN and - * USER CODE END. Other portions of this file, whether - * inserted by the user or by software development tools - * are owned by their respective copyright owners. - * - * COPYRIGHT(c) 2018 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __MAIN_H__ -#define __MAIN_H__ - -/* Includes ------------------------------------------------------------------*/ - -/* USER CODE BEGIN Includes */ - -/* USER CODE END Includes */ - -/* Private define ------------------------------------------------------------*/ - -#define B1_Pin GPIO_PIN_13 -#define B1_GPIO_Port GPIOC -#define IRQ_3911_Pin GPIO_PIN_0 -#define IRQ_3911_GPIO_Port GPIOA -#define IRQ_3911_EXTI_IRQn EXTI0_IRQn -#define LED_F_Pin GPIO_PIN_1 -#define LED_F_GPIO_Port GPIOA -#define LED_B_Pin GPIO_PIN_4 -#define LED_B_GPIO_Port GPIOA -#define LED_A_Pin GPIO_PIN_0 -#define LED_A_GPIO_Port GPIOB -#define LED_FIELD_Pin GPIO_PIN_8 -#define LED_FIELD_GPIO_Port GPIOA -#define TMS_Pin GPIO_PIN_13 -#define TMS_GPIO_Port GPIOA -#define TCK_Pin GPIO_PIN_14 -#define TCK_GPIO_Port GPIOA -#define SWO_Pin GPIO_PIN_3 -#define SWO_GPIO_Port GPIOB -#define LED_V_Pin GPIO_PIN_4 -#define LED_V_GPIO_Port GPIOB -#define LED_AP2P_Pin GPIO_PIN_5 -#define LED_AP2P_GPIO_Port GPIOB -#define SPI1_CS_Pin GPIO_PIN_6 -#define SPI1_CS_GPIO_Port GPIOB - -/* ########################## Assert Selection ############################## */ -/** - * @brief Uncomment the line below to expanse the "assert_param" macro in the - * HAL drivers code - */ -/* #define USE_FULL_ASSERT 1U */ - -/* USER CODE BEGIN Private defines */ - -/* USER CODE END Private defines */ - -#ifdef __cplusplus - extern "C" { -#endif -void _Error_Handler(char *, int); - -#define Error_Handler() _Error_Handler(__FILE__, __LINE__) -#ifdef __cplusplus -} -#endif - -#endif /* __MAIN_H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Inc/ndef_dump.h b/Software/Core/Inc/ndef_dump.h deleted file mode 100644 index 5df4424..0000000 --- a/Software/Core/Inc/ndef_dump.h +++ /dev/null @@ -1,247 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF message dump utils header file - * - */ - -#ifndef NDEF_DUMP_H -#define NDEF_DUMP_H - - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "platform.h" -#include "ndef_record.h" -#include "ndef_message.h" -#include "ndef_types.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/*! - ***************************************************************************** - * Dump an NDEF record - * - * This function dumps an NDEF record in a formatted readable style - * The verbose selector enables more or less dump output. - * - * \param[in] record - * \param[in] verbose - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordDump(const ndefRecord* record, bool verbose); - -/*! - ***************************************************************************** - * Dump an NDEF message - * - * This function dumps an NDEF message in a formatted readable style - * The verbose selector enables more or less dump output. - * - * \param[in] message - * \param[in] verbose - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMessageDump(const ndefMessage* message, bool verbose); - -/*! - ***************************************************************************** - * Dump an Empty type - * - * \param[in] empty: Type to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefEmptyTypeDump(const ndefType* empty); - -/*! - ***************************************************************************** - * Dump a Device Information RTD well-known type - * - * \param[in] devInfo: Well-known type to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdDeviceInfoDump(const ndefType* devInfo); - -/*! - ***************************************************************************** - * Dump a Text RTD well-known type - * - * \param[in] text: Well-known type to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdTextDump(const ndefType* text); - -/*! - ***************************************************************************** - * Dump a URI RTD well-known type - * - * \param[in] uri: Well-known type to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdUriDump(const ndefType* uri); - -/*! - ***************************************************************************** - * Dump an External RTD type - * - * \param[in] ext: Well-known type to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdAarDump(const ndefType* ext); - -/*! - ***************************************************************************** - * Dump a Media type - * - * \param[in] media: Media type to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMediaTypeDump(const ndefType* media); - -/*! - ***************************************************************************** - * Dump a vCard Media type - * - * \param[in] vCard: vCard to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMediaVCardDump(const ndefType* vCard); - -/*! - ***************************************************************************** - * Dump a Wifi Media type - * - * \param[in] wifi: Wifi parameters to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMediaWifiDump(const ndefType* wifi); - -/*! - ***************************************************************************** - * Dump a well-known type - * - * \param[in] record: Record to dump - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordDumpType(const ndefRecord* record); - -/*! - ***************************************************************************** - * Dump a raw buffer stored in a ndefBuffer - * - * This function dumps a raw buffer in a formatted style - * - * \param[in] string: Message displayed before the buffer - * \param[in] bufPayload: Payload buffer to display - * \param[in] verbose Increase the lenght displayed - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefBufferDump(const char* string, const ndefConstBuffer* bufPayload, bool verbose); - -/*! - ***************************************************************************** - * Dump a raw buffer stored in a ndefBuffer - * - * This function dumps a raw buffer in a formatted style - * - * \param[in] prefix: String displayed before the buffer - * \param[in] bufPayload: Payload buffer to display - * \param[in] suffix: String displayed after the buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefBufferPrint(const char* prefix, const ndefConstBuffer* bufPayload, const char* suffix); - -/*! - ***************************************************************************** - * Dump a raw buffer stored in a ndefBuffer8 - * - * This function dumps a raw buffer in a formatted style - * - * \param[in] prefix: String displayed before the buffer - * \param[in] bufPayload: Payload buffer to display - * \param[in] suffix: String displayed after the buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefBuffer8Print(const char* prefix, const ndefConstBuffer8* bufPayload, const char* suffix); - - -#endif /* NDEF_DUMP_H */ diff --git a/Software/Core/Inc/platform.h b/Software/Core/Inc/platform.h deleted file mode 100644 index 5812f9c..0000000 --- a/Software/Core/Inc/platform.h +++ /dev/null @@ -1,201 +0,0 @@ -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/*! \file - * - * \author - * - * \brief Platform header file. Defining platform independent functionality. - * - */ - - -/* - * PROJECT: - * $Revision: $ - * LANGUAGE: ISO C99 - */ - -/*! \file platform.h - * - * \author Gustavo Patricio - * - * \brief Platform specific definition layer - * - * This should contain all platform and hardware specifics such as - * GPIO assignment, system resources, locks, IRQs, etc - * - * Each distinct platform/system/board must provide this definitions - * for all SW layers to use - * - */ - -#ifndef PLATFORM_H -#define PLATFORM_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#ifdef STM32L476xx -#include "stm32l4xx_hal.h" -#else -#include "stm32f4xx_hal.h" -#endif - -#include -#include -#include - -#include "spi.h" -#include "timer.h" -#include "main.h" -#include "logger.h" - - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ -#define ST25R391X_SS_PIN SPI1_CS_Pin /*!< GPIO pin used for ST25R3911 SPI SS */ -#define ST25R391X_SS_PORT SPI1_CS_GPIO_Port /*!< GPIO port used for ST25R3911 SPI SS port */ - -#define ST25R391X_INT_PIN IRQ_3911_Pin /*!< GPIO pin used for ST25R3911 External Interrupt */ -#define ST25R391X_INT_PORT IRQ_3911_GPIO_Port /*!< GPIO port used for ST25R3911 External Interrupt */ - -#ifdef LED_FIELD_Pin -#define PLATFORM_LED_FIELD_PIN LED_FIELD_Pin /*!< GPIO pin used as field LED */ -#endif - -#ifdef LED_FIELD_GPIO_Port -#define PLATFORM_LED_FIELD_PORT LED_FIELD_GPIO_Port /*!< GPIO port used as field LED */ -#endif - - -#define PLATFORM_LED_A_PIN LED_A_Pin /*!< GPIO pin used for LED A */ -#define PLATFORM_LED_A_PORT LED_A_GPIO_Port /*!< GPIO port used for LED A */ -#define PLATFORM_LED_B_PIN LED_B_Pin /*!< GPIO pin used for LED B */ -#define PLATFORM_LED_B_PORT LED_B_GPIO_Port /*!< GPIO port used for LED B */ -#define PLATFORM_LED_F_PIN LED_F_Pin /*!< GPIO pin used for LED F */ -#define PLATFORM_LED_F_PORT LED_F_GPIO_Port /*!< GPIO port used for LED F */ -#define PLATFORM_LED_V_PIN LED_V_Pin /*!< GPIO pin used for LED V */ -#define PLATFORM_LED_V_PORT LED_V_GPIO_Port /*!< GPIO port used for LED V */ -#define PLATFORM_LED_AP2P_PIN LED_AP2P_Pin /*!< GPIO pin used for LED AP2P */ -#define PLATFORM_LED_AP2P_PORT LED_AP2P_GPIO_Port /*!< GPIO port used for LED AP2P*/ - -#define PLATFORM_USER_BUTTON_PIN B1_Pin /*!< GPIO pin user button */ -#define PLATFORM_USER_BUTTON_PORT B1_GPIO_Port /*!< GPIO port user button */ - - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ -#define platformProtectST25R391xComm() do{ globalCommProtectCnt++; __DSB();NVIC_DisableIRQ(EXTI0_IRQn);__DSB();__ISB();}while(0) /*!< Protect unique access to ST25R391x communication channel - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */ -#define platformUnprotectST25R391xComm() do{ if (--globalCommProtectCnt==0U) {NVIC_EnableIRQ(EXTI0_IRQn);} }while(0) /*!< Unprotect unique access to ST25R391x communication channel - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */ - -#define platformProtectST25R391xIrqStatus() platformProtectST25R391xComm() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */ -#define platformUnprotectST25R391xIrqStatus() platformUnprotectST25R391xComm() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */ - -#define platformProtectWorker() /* Protect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */ -#define platformUnprotectWorker() /* Unprotect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */ - - -#define platformIrqST25R3911SetCallback( cb ) -#define platformIrqST25R3911PinInitialize() - -#define platformIrqST25R3916SetCallback( cb ) -#define platformIrqST25R3916PinInitialize() - - -#define platformLedsInitialize() /*!< Initializes the pins used as LEDs to outputs*/ - -#define platformLedOff( port, pin ) platformGpioClear((port), (pin)) /*!< Turns the given LED Off */ -#define platformLedOn( port, pin ) platformGpioSet((port), (pin)) /*!< Turns the given LED On */ -#define platformLedToogle( port, pin ) platformGpioToogle((port), (pin)) /*!< Toogle the given LED */ - -#define platformGpioSet( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET) /*!< Turns the given GPIO High */ -#define platformGpioClear( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET) /*!< Turns the given GPIO Low */ -#define platformGpioToogle( port, pin ) HAL_GPIO_TogglePin(port, pin) /*!< Toogles the given GPIO */ -#define platformGpioIsHigh( port, pin ) (HAL_GPIO_ReadPin(port, pin) == GPIO_PIN_SET) /*!< Checks if the given LED is High */ -#define platformGpioIsLow( port, pin ) (!platformGpioIsHigh(port, pin)) /*!< Checks if the given LED is Low */ - -#define platformTimerCreate( t ) timerCalculateTimer(t) /*!< Create a timer with the given time (ms) */ -#define platformTimerIsExpired( timer ) timerIsExpired(timer) /*!< Checks if the given timer is expired */ -#define platformDelay( t ) HAL_Delay( t ) /*!< Performs a delay for the given time (ms) */ - -#define platformGetSysTick() HAL_GetTick() /*!< Get System Tick ( 1 tick = 1 ms) */ - -#define platformSpiSelect() platformGpioClear( ST25R391X_SS_PORT, ST25R391X_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Select */ -#define platformSpiDeselect() platformGpioSet( ST25R391X_SS_PORT, ST25R391X_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Deselect */ -#define platformSpiTxRx( txBuf, rxBuf, len ) spiTxRx( (txBuf), (rxBuf), (len) ) /*!< SPI transceive */ - - -#define platformI2CTx( txBuf, len ) /*!< I2C Transmit */ -#define platformI2CRx( txBuf, len ) /*!< I2C Receive */ -#define platformI2CStart() /*!< I2C Start condition */ -#define platformI2CStop() /*!< I2C Stop condition */ -#define platformI2CRepeatStart() /*!< I2C Repeat Start */ -#define platformI2CSlaveAddrWR(add) /*!< I2C Slave address for Write operation */ -#define platformI2CSlaveAddrRD(add) /*!< I2C Slave address for Read operation */ - -#define platformLog(...) logUsart(__VA_ARGS__) /*!< Log method */ - -/* -****************************************************************************** -* GLOBAL VARIABLES -****************************************************************************** -*/ -extern uint8_t globalCommProtectCnt; /* Global Protection Counter provided per platform - instantiated in main.c */ - -/* -****************************************************************************** -* RFAL FEATURES CONFIGURATION -****************************************************************************** -*/ - -#define RFAL_FEATURE_LISTEN_MODE false /*!< Enable/Disable RFAL support for Listen Mode */ -#define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable/Disable RFAL support for the Wake-Up mode */ -#define RFAL_FEATURE_NFCA true /*!< Enable/Disable RFAL support for NFC-A (ISO14443A) */ -#define RFAL_FEATURE_NFCB true /*!< Enable/Disable RFAL support for NFC-B (ISO14443B) */ -#define RFAL_FEATURE_NFCF true /*!< Enable/Disable RFAL support for NFC-F (FeliCa) */ -#define RFAL_FEATURE_NFCV true /*!< Enable/Disable RFAL support for NFC-V (ISO15693) */ -#define RFAL_FEATURE_T1T true /*!< Enable/Disable RFAL support for T1T (Topaz) */ -#define RFAL_FEATURE_T2T true /*!< Enable/Disable RFAL support for T2T */ -#define RFAL_FEATURE_T4T true /*!< Enable/Disable RFAL support for T4T */ -#define RFAL_FEATURE_ST25TB true /*!< Enable/Disable RFAL support for ST25TB */ -#define RFAL_FEATURE_ST25xV true /*!< Enable/Disable RFAL support for ST25TV/ST25DV */ -#define RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG false /*!< Enable/Disable Analog Configs to be dynamically updated (RAM) */ -#define RFAL_FEATURE_DYNAMIC_POWER false /*!< Enable/Disable RFAL dynamic power support */ -#define RFAL_FEATURE_ISO_DEP true /*!< Enable/Disable RFAL support for ISO-DEP (ISO14443-4) */ -#define RFAL_FEATURE_ISO_DEP_POLL true /*!< Enable/Disable RFAL support for Poller mode (PCD) ISO-DEP (ISO14443-4) */ -#define RFAL_FEATURE_ISO_DEP_LISTEN false /*!< Enable/Disable RFAL support for Listen mode (PICC) ISO-DEP (ISO14443-4) */ -#define RFAL_FEATURE_NFC_DEP true /*!< Enable/Disable RFAL support for NFC-DEP (NFCIP1/P2P) */ - - -#define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN 256U /*!< ISO-DEP I-Block max length. Please use values as defined by rfalIsoDepFSx */ -#define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN 1024U /*!< ISO-DEP APDU max length. Please use multiples of I-Block max length */ - -#endif /* PLATFORM_H */ - - diff --git a/Software/Core/Inc/spi.h b/Software/Core/Inc/spi.h deleted file mode 100644 index 267663d..0000000 --- a/Software/Core/Inc/spi.h +++ /dev/null @@ -1,104 +0,0 @@ -/** - ****************************************************************************** - * COPYRIGHT(c) 2016 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** -*/ -/*! \file - * - * \author - * - * \brief SPI communication header file - * - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __spi_H -#define __spi_H - -/* Includes ------------------------------------------------------------------*/ -#include "platform.h" - -/*! - ***************************************************************************** - * \brief Initalize SPI - * - * This function initalize the SPI handle. - * - * \param[in] hspi : pointer to initalized SPI block - * - ***************************************************************************** - */ -void spiInit(SPI_HandleTypeDef *hspi); - -/*! - ***************************************************************************** - * \brief Set SPI CS line - * - * \param[in] ssPort : pointer CS gpio port - * - * \param[in] ssPin : CS pin - * - * \return : none - * - ***************************************************************************** - */ -void spiSelect(GPIO_TypeDef *ssPort, uint16_t ssPin); - -/*! - ***************************************************************************** - * \brief Reset SPI CS line - * - * \param[in] ssPort : pointer CS gpio port - * - * \param[in] ssPin : CS pin - * - * \return : none - * - ***************************************************************************** - */ -void spiDeselect(GPIO_TypeDef *ssPort, uint16_t ssPin); - -/*! - ***************************************************************************** - * \brief Transmit Receive data - * - * This funtion transmits first no of "length" bytes from "txData" and tries - * then to receive "length" bytes. - * - * \param[in] txData : pointer to buffer to be transmitted. - * - * \param[out] rxData : pointer to buffer to be received. - * - * \param[in] length : buffer length - * - * \return : HAL error code - * - ***************************************************************************** - */ -HAL_StatusTypeDef spiTxRx(const uint8_t *txData, uint8_t *rxData, uint16_t length); - -#endif /*__spi_H */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Inc/usart.h b/Software/Core/Inc/usart.h deleted file mode 100644 index 80e7c3e..0000000 --- a/Software/Core/Inc/usart.h +++ /dev/null @@ -1,64 +0,0 @@ -/** - ****************************************************************************** - * COPYRIGHT(c) 2016 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** -*/ -/*! \file - * - * \author - * - * \brief UART communication header file - * - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __usart_H -#define __usart_H -#ifdef __cplusplus - extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "platform.h" - -void UsartInit(UART_HandleTypeDef *husart); -uint8_t UsartTxByte(uint8_t data); -uint8_t UsartTx(uint8_t *data, uint16_t dataLen); -uint8_t UsartRx(uint8_t *data, uint16_t *dataLen); - -#ifdef __cplusplus -} -#endif -#endif /*__usart_H */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Src/demo.c b/Software/Core/Src/demo.c deleted file mode 100644 index a81e9af..0000000 --- a/Software/Core/Src/demo.c +++ /dev/null @@ -1,651 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/*! \file - * - * \author - * - * \brief Demo application - * - * This demo shows how to poll for several types of NFC cards/devices and how - * to exchange data with these devices, using the RFAL library. - * - * This demo does not fully implement the activities according to the standards, - * it performs the required to communicate with a card/device and retrieve - * its UID. Also blocking methods are used for data exchange which may lead to - * long periods of blocking CPU/MCU. - * For standard compliant example please refer to the Examples provided - * with the RFAL library. - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "demo.h" -#include "utils.h" -#include "rfal_nfc.h" - -#if defined(ST25R3916) && defined(RFAL_FEATURE_LISTEN_MODE) -#include "demo_ce.h" -#endif - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - -/* Definition of possible states the demo state machine could have */ -#define DEMO_ST_NOTINIT 0 /*!< Demo State: Not initialized */ -#define DEMO_ST_START_DISCOVERY 1 /*!< Demo State: Start Discovery */ -#define DEMO_ST_DISCOVERY 2 /*!< Demo State: Discovery */ - -#define DEMO_NFCV_BLOCK_LEN 4 /*!< NFCV Block len */ - -#define DEMO_NFCV_USE_SELECT_MODE false /*!< NFCV demonstrate select mode */ -#define DEMO_NFCV_WRITE_TAG false /*!< NFCV demonstrate Write Single Block */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -/* P2P communication data */ -static uint8_t NFCID3[] = {0x01, 0xFE, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}; -static uint8_t GB[] = {0x46, 0x66, 0x6d, 0x01, 0x01, 0x11, 0x02, 0x02, 0x07, 0x80, 0x03, 0x02, 0x00, 0x03, 0x04, 0x01, 0x32, 0x07, 0x01, 0x03}; - -/* APDUs communication data */ -static uint8_t ndefSelectApp[] = { 0x00, 0xA4, 0x04, 0x00, 0x07, 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01, 0x00 }; -static uint8_t ccSelectFile[] = { 0x00, 0xA4, 0x00, 0x0C, 0x02, 0xE1, 0x03}; -static uint8_t readBynary[] = { 0x00, 0xB0, 0x00, 0x00, 0x0F }; -/*static uint8_t ppseSelectApp[] = { 0x00, 0xA4, 0x04, 0x00, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53, 0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0x00 };*/ - -/* P2P communication data */ -static uint8_t ndefLLCPSYMM[] = {0x00, 0x00}; -static uint8_t ndefInit[] = {0x05, 0x20, 0x06, 0x0F, 0x75, 0x72, 0x6E, 0x3A, 0x6E, 0x66, 0x63, 0x3A, 0x73, 0x6E, 0x3A, 0x73, 0x6E, 0x65, 0x70, 0x02, 0x02, 0x07, 0x80, 0x05, 0x01, 0x02}; -static uint8_t ndefUriSTcom[] = {0x13, 0x20, 0x00, 0x10, 0x02, 0x00, 0x00, 0x00, 0x19, 0xc1, 0x01, 0x00, 0x00, 0x00, 0x12, 0x55, 0x00, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x73, 0x74, 0x2e, 0x63, 0x6f, 0x6d}; - -#if defined(ST25R3916) && defined(RFAL_FEATURE_LISTEN_MODE) -/* NFC-A CE config */ -static uint8_t ceNFCA_NFCID[] = {0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; /* NFCID / UID (7 bytes) */ -static uint8_t ceNFCA_SENS_RES[] = {0x44, 0x00}; /* SENS_RES / ATQA */ -static uint8_t ceNFCA_SEL_RES = 0x20; /* SEL_RES / SAK */ - -/* NFC-F CE config */ -static uint8_t ceNFCF_nfcid2[] = {0x02, 0xFE, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; -static uint8_t ceNFCF_SC[] = {0x12, 0xFC}; -static uint8_t ceNFCF_SENSF_RES[] = {0x01, /* SENSF_RES */ - 0x02, 0xFE, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, /* NFCID2 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x00, /* PAD0, PAD01, MRTIcheck, MRTIupdate, PAD2 */ - 0x00, 0x00 }; /* RD */ -#endif /* RFAL_FEATURE_LISTEN_MODE */ - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ -static rfalNfcDiscoverParam discParam; -static uint8_t state = DEMO_ST_NOTINIT; - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -static void demoP2P( void ); -static void demoAPDU( void ); -static void demoNfcv( rfalNfcvListenDevice *nfcvDev ); -static void demoNfcf( rfalNfcfListenDevice *nfcfDev ); -static void demoCE( rfalNfcDevice *nfcDev ); -static void demoNotif( rfalNfcState st ); -ReturnCode demoTransceiveBlocking( uint8_t *txBuf, uint16_t txBufSize, uint8_t **rxBuf, uint16_t **rcvLen, uint32_t fwt ); - - - -/*! - ***************************************************************************** - * \brief Demo Notification - * - * This function receives the event notifications from RFAL - ***************************************************************************** - */ -static void demoNotif( rfalNfcState st ) -{ - uint8_t devCnt; - rfalNfcDevice *dev; - - - if( st == RFAL_NFC_STATE_WAKEUP_MODE ) - { - platformLog("Wake Up mode started \r\n"); - } - else if( st == RFAL_NFC_STATE_POLL_TECHDETECT ) - { - platformLog("Wake Up mode terminated. Polling for devices \r\n"); - } - else if( st == RFAL_NFC_STATE_POLL_SELECT ) - { - /* Multiple devices were found, activate first of them */ - rfalNfcGetDevicesFound( &dev, &devCnt ); - rfalNfcSelect( 0 ); - - platformLog("Multiple Tags detected: %d \r\n", devCnt); - } -} - -/*! - ***************************************************************************** - * \brief Demo Ini - * - * This function Initializes the required layers for the demo - * - * \return true : Initialization ok - * \return false : Initialization failed - ***************************************************************************** - */ -bool demoIni( void ) -{ - ReturnCode err; - - err = rfalNfcInitialize(); - if( err == ERR_NONE ) - { - discParam.compMode = RFAL_COMPLIANCE_MODE_NFC; - discParam.devLimit = 1U; - discParam.nfcfBR = RFAL_BR_212; - discParam.ap2pBR = RFAL_BR_424; - - ST_MEMCPY( &discParam.nfcid3, NFCID3, sizeof(NFCID3) ); - ST_MEMCPY( &discParam.GB, GB, sizeof(GB) ); - discParam.GBLen = sizeof(GB); - - discParam.notifyCb = demoNotif; - discParam.totalDuration = 1000U; - discParam.wakeupEnabled = false; - discParam.wakeupConfigDefault = true; - discParam.techs2Find = ( RFAL_NFC_POLL_TECH_A | RFAL_NFC_POLL_TECH_B | RFAL_NFC_POLL_TECH_F | RFAL_NFC_POLL_TECH_V | RFAL_NFC_POLL_TECH_ST25TB ); - -#if defined(ST25R3911) || defined(ST25R3916) - discParam.techs2Find |= RFAL_NFC_POLL_TECH_AP2P; -#endif /* ST25R95 */ - - -#if defined(ST25R3916) - - /* Set configuration for NFC-A CE */ - ST_MEMCPY( discParam.lmConfigPA.SENS_RES, ceNFCA_SENS_RES, RFAL_LM_SENS_RES_LEN ); /* Set SENS_RES / ATQA */ - ST_MEMCPY( discParam.lmConfigPA.nfcid, ceNFCA_NFCID, RFAL_NFCID2_LEN ); /* Set NFCID / UID */ - discParam.lmConfigPA.nfcidLen = RFAL_LM_NFCID_LEN_07; /* Set NFCID length to 7 bytes */ - discParam.lmConfigPA.SEL_RES = ceNFCA_SEL_RES; /* Set SEL_RES / SAK */ - - /* Set configuration for NFC-F CE */ - ST_MEMCPY( discParam.lmConfigPF.SC, ceNFCF_SC, RFAL_LM_SENSF_SC_LEN ); /* Set System Code */ - ST_MEMCPY( &ceNFCF_SENSF_RES[RFAL_NFCF_LENGTH_LEN], ceNFCF_nfcid2, RFAL_LM_SENSF_RES_LEN ); /* Load NFCID2 on SENSF_RES */ - ST_MEMCPY( discParam.lmConfigPF.SENSF_RES, ceNFCF_SENSF_RES, RFAL_LM_SENSF_RES_LEN ); /* Set SENSF_RES / Poll Response */ - - discParam.techs2Find |= ( RFAL_NFC_LISTEN_TECH_A | RFAL_NFC_LISTEN_TECH_F ); - -#endif /* ST25R95 */ - - state = DEMO_ST_START_DISCOVERY; - return true; - } - return false; -} - -/*! - ***************************************************************************** - * \brief Demo Cycle - * - * This function executes the demo state machine. - * It must be called periodically - ***************************************************************************** - */ -void demoCycle( void ) -{ - static rfalNfcDevice *nfcDevice; - - rfalNfcWorker(); /* Run RFAL worker periodically */ - - /*******************************************************************************/ - /* Check if USER button is pressed */ - if( platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN)) - { - discParam.wakeupEnabled = !discParam.wakeupEnabled; /* enable/disable wakeup */ - state = DEMO_ST_START_DISCOVERY; /* restart loop */ - platformLog("Toggling Wake Up mode %s\r\n", discParam.wakeupEnabled ? "ON": "OFF"); - - /* Debounce button */ - while( platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN) ); - } - - - switch( state ) - { - /*******************************************************************************/ - case DEMO_ST_START_DISCOVERY: - - platformLedOff(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN); - platformLedOff(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - platformLedOff(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN); - platformLedOff(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN); - platformLedOff(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN); - platformLedOff(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN); - - rfalNfcDeactivate( false ); - rfalNfcDiscover( &discParam ); - - state = DEMO_ST_DISCOVERY; - break; - - /*******************************************************************************/ - case DEMO_ST_DISCOVERY: - - if( rfalNfcIsDevActivated( rfalNfcGetState() ) ) - { - rfalNfcGetActiveDevice( &nfcDevice ); - - switch( nfcDevice->type ) - { - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_NFCA: - - platformLedOn(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN); - switch( nfcDevice->dev.nfca.type ) - { - case RFAL_NFCA_T1T: - platformLog("ISO14443A/Topaz (NFC-A T1T) TAG found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - break; - - case RFAL_NFCA_T4T: - platformLog("NFCA Passive ISO-DEP device found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - - demoAPDU(); - break; - - case RFAL_NFCA_T4T_NFCDEP: - case RFAL_NFCA_NFCDEP: - platformLog("NFCA Passive P2P device found. NFCID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - - demoP2P(); - break; - - default: - platformLog("ISO14443A/NFC-A card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - break; - } - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_NFCB: - - platformLog("ISO14443B/NFC-B card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - platformLedOn(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - - if( rfalNfcbIsIsoDepSupported( &nfcDevice->dev.nfcb ) ) - { - demoAPDU(); - } - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_NFCF: - - if( rfalNfcfIsNfcDepSupported( &nfcDevice->dev.nfcf ) ) - { - platformLog("NFCF Passive P2P device found. NFCID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - demoP2P(); - } - else - { - platformLog("Felica/NFC-F card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen )); - - demoNfcf( &nfcDevice->dev.nfcf ); - } - - platformLedOn(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN); - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_NFCV: - { - uint8_t devUID[RFAL_NFCV_UID_LEN]; - - ST_MEMCPY( devUID, nfcDevice->nfcid, nfcDevice->nfcidLen ); /* Copy the UID into local var */ - REVERSE_BYTES( devUID, RFAL_NFCV_UID_LEN ); /* Reverse the UID for display purposes */ - platformLog("ISO15693/NFC-V card found. UID: %s\r\n", hex2Str(devUID, RFAL_NFCV_UID_LEN)); - - platformLedOn(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN); - - demoNfcv( &nfcDevice->dev.nfcv ); - } - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_ST25TB: - - platformLog("ST25TB card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen )); - platformLedOn(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_AP2P: - - platformLog("NFC Active P2P device found. NFCID3: %s\r\n", hex2Str(nfcDevice->nfcid, nfcDevice->nfcidLen)); - platformLedOn(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN); - - demoP2P(); - break; - - /*******************************************************************************/ - case RFAL_NFC_POLL_TYPE_NFCA: - case RFAL_NFC_POLL_TYPE_NFCF: - - platformLog("Activated in CE %s mode.\r\n", (nfcDevice->type == RFAL_NFC_POLL_TYPE_NFCA) ? "NFC-A" : "NFC-F"); - platformLedOn( ((nfcDevice->type == RFAL_NFC_POLL_TYPE_NFCA) ? PLATFORM_LED_A_PORT : PLATFORM_LED_F_PORT), - ((nfcDevice->type == RFAL_NFC_POLL_TYPE_NFCA) ? PLATFORM_LED_A_PIN : PLATFORM_LED_F_PIN) ); - - demoCE( nfcDevice ); - break; - - /*******************************************************************************/ - default: - break; - } - - rfalNfcDeactivate( false ); - platformDelay( 500 ); - state = DEMO_ST_START_DISCOVERY; - } - break; - - /*******************************************************************************/ - case DEMO_ST_NOTINIT: - default: - break; - } -} - -static void demoCE( rfalNfcDevice *nfcDev ) -{ -#if defined(ST25R3916) && defined(RFAL_FEATURE_LISTEN_MODE) - - ReturnCode err; - uint8_t *rxData; - uint16_t *rcvLen; - uint8_t txBuf[100]; - uint16_t txLen; - - demoCeInit( ceNFCF_nfcid2 ); - - do - { - rfalNfcWorker(); - - switch( rfalNfcGetState() ) - { - case RFAL_NFC_STATE_ACTIVATED: - err = demoTransceiveBlocking( NULL, 0, &rxData, &rcvLen, 0); - break; - - case RFAL_NFC_STATE_DATAEXCHANGE: - case RFAL_NFC_STATE_DATAEXCHANGE_DONE: - - txLen = ( (nfcDev->type == RFAL_NFC_POLL_TYPE_NFCA) ? demoCeT4T( rxData, *rcvLen, txBuf, sizeof(txBuf) ): demoCeT3T( rxData, *rcvLen, txBuf, sizeof(txBuf) ) ); - err = demoTransceiveBlocking( txBuf, txLen, &rxData, &rcvLen, RFAL_FWT_NONE ); - break; - - case RFAL_NFC_STATE_LISTEN_SLEEP: - default: - break; - } - } - while( (err == ERR_NONE) || (err == ERR_SLEEP_REQ) ); - -#endif /* RFAL_FEATURE_LISTEN_MODE */ -} - -/*! - ***************************************************************************** - * \brief Demo NFC-F - * - * Example how to exchange read and write blocks on a NFC-F tag - * - ***************************************************************************** - */ -static void demoNfcf( rfalNfcfListenDevice *nfcfDev ) -{ - ReturnCode err; - uint8_t buf[ (RFAL_NFCF_NFCID2_LEN + RFAL_NFCF_CMD_LEN + (3*RFAL_NFCF_BLOCK_LEN)) ]; - uint16_t rcvLen; - rfalNfcfServ srv = RFAL_NFCF_SERVICECODE_RDWR; - rfalNfcfBlockListElem bl[3]; - rfalNfcfServBlockListParam servBlock; - //uint8_t wrData[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; - - servBlock.numServ = 1; /* Only one Service to be used */ - servBlock.servList = &srv; /* Service Code: NDEF is Read/Writeable */ - servBlock.numBlock = 1; /* Only one block to be used */ - servBlock.blockList = bl; - bl[0].conf = RFAL_NFCF_BLOCKLISTELEM_LEN; /* Two-byte Block List Element */ - bl[0].blockNum = 0x0001; /* Block: NDEF Data */ - - err = rfalNfcfPollerCheck( nfcfDev->sensfRes.NFCID2, &servBlock, buf, sizeof(buf), &rcvLen); - platformLog(" Check Block: %s Data: %s \r\n", (err != ERR_NONE) ? "FAIL": "OK", (err != ERR_NONE) ? "" : hex2Str( &buf[1], RFAL_NFCF_BLOCK_LEN) ); - - #if 0 /* Writing example */ - err = rfalNfcfPollerUpdate( nfcfDev->sensfRes.NFCID2, &servBlock, buf , sizeof(buf), wrData, buf, sizeof(buf) ); - platformLog(" Update Block: %s Data: %s \r\n", (err != ERR_NONE) ? "FAIL": "OK", (err != ERR_NONE) ? "" : hex2Str( wrData, RFAL_NFCF_BLOCK_LEN) ); - err = rfalNfcfPollerCheck( nfcfDev->sensfRes.NFCID2, &servBlock, buf, sizeof(buf), &rcvLen); - platformLog(" Check Block: %s Data: %s \r\n", (err != ERR_NONE) ? "FAIL": "OK", (err != ERR_NONE) ? "" : hex2Str( &buf[1], RFAL_NFCF_BLOCK_LEN) ); - #endif -} - -/*! - ***************************************************************************** - * \brief Demo NFC-V Exchange - * - * Example how to exchange read and write blocks on a NFC-V tag - * - ***************************************************************************** - */ -static void demoNfcv( rfalNfcvListenDevice *nfcvDev ) -{ - ReturnCode err; - uint16_t rcvLen; - uint8_t blockNum = 1; - uint8_t rxBuf[ 1 + DEMO_NFCV_BLOCK_LEN + RFAL_CRC_LEN ]; /* Flags + Block Data + CRC */ - uint8_t * uid; -#if DEMO_NFCV_WRITE_TAG - uint8_t wrData[DEMO_NFCV_BLOCK_LEN] = { 0x11, 0x22, 0x33, 0x99 }; /* Write block example */ -#endif - - - uid = nfcvDev->InvRes.UID; - - #if DEMO_NFCV_USE_SELECT_MODE - /* - * Activate selected state - */ - err = rfalNfcvPollerSelect(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev->InvRes.UID ); - platformLog(" Select %s \r\n", (err != ERR_NONE) ? "FAIL (revert to addressed mode)": "OK" ); - if( err == ERR_NONE ) - { - uid = NULL; - } - #endif - - /* - * Read block using Read Single Block command - * with addressed mode (uid != NULL) or selected mode (uid == NULL) - */ - err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, blockNum, rxBuf, sizeof(rxBuf), &rcvLen); - platformLog(" Read Block: %s %s\r\n", (err != ERR_NONE) ? "FAIL": "OK Data:", (err != ERR_NONE) ? "" : hex2Str( &rxBuf[1], DEMO_NFCV_BLOCK_LEN)); - - #if DEMO_NFCV_WRITE_TAG /* Writing example */ - err = rfalNfcvPollerWriteSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, blockNum, wrData, sizeof(wrData)); - platformLog(" Write Block: %s Data: %s\r\n", (err != ERR_NONE) ? "FAIL": "OK", hex2Str( wrData, DEMO_NFCV_BLOCK_LEN) ); - err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, blockNum, rxBuf, sizeof(rxBuf), &rcvLen); - platformLog(" Read Block: %s %s\r\n", (err != ERR_NONE) ? "FAIL": "OK Data:", (err != ERR_NONE) ? "" : hex2Str( &rxBuf[1], DEMO_NFCV_BLOCK_LEN)); - #endif -} - - -/*! - ***************************************************************************** - * \brief Demo P2P Exchange - * - * Sends a NDEF URI record 'http://www.ST.com' via NFC-DEP (P2P) protocol. - * - * This method sends a set of static predefined frames which tries to establish - * a LLCP connection, followed by the NDEF record, and then keeps sending - * LLCP SYMM packets to maintain the connection. - * - * - ***************************************************************************** - */ -void demoP2P( void ) -{ - uint16_t *rxLen; - uint8_t *rxData; - ReturnCode err; - - platformLog(" Initalize device .. "); - err = demoTransceiveBlocking( ndefInit, sizeof(ndefInit), &rxData, &rxLen, RFAL_FWT_NONE); - if( err != ERR_NONE ) - { - platformLog("failed."); - return; - } - platformLog("succeeded.\r\n"); - - platformLog(" Push NDEF Uri: www.ST.com .. "); - err = demoTransceiveBlocking( ndefUriSTcom, sizeof(ndefUriSTcom), &rxData, &rxLen, RFAL_FWT_NONE); - if( err != ERR_NONE ) - { - platformLog("failed."); - return; - } - platformLog("succeeded.\r\n"); - - - platformLog(" Device present, maintaining connection "); - while(err == ERR_NONE) - { - err = demoTransceiveBlocking( ndefLLCPSYMM, sizeof(ndefLLCPSYMM), &rxData, &rxLen, RFAL_FWT_NONE); - platformLog("."); - platformDelay(50); - } - platformLog("\r\n Device removed.\r\n"); -} - - -/*! - ***************************************************************************** - * \brief Demo APDUs Exchange - * - * Example how to exchange a set of predefined APDUs with PICC. The NDEF - * application will be selected and then CC will be selected and read. - * - ***************************************************************************** - */ -void demoAPDU( void ) -{ - ReturnCode err; - uint16_t *rxLen; - uint8_t *rxData; - - - /* Exchange APDU: NDEF Tag Application Select command */ - err = demoTransceiveBlocking( ndefSelectApp, sizeof(ndefSelectApp), &rxData, &rxLen, RFAL_FWT_NONE ); - platformLog(" Select NDEF Application: %s Data: %s\r\n", (err != ERR_NONE) ? "FAIL": "OK", hex2Str( rxData, *rxLen) ); - - if( (err == ERR_NONE) && rxData[0] == 0x90 && rxData[1] == 0x00) - { - /* Exchange APDU: Select Capability Container File */ - err = demoTransceiveBlocking( ccSelectFile, sizeof(ccSelectFile), &rxData, &rxLen, RFAL_FWT_NONE ); - platformLog(" Select CC: %s Data: %s\r\n", (err != ERR_NONE) ? "FAIL": "OK", hex2Str( rxData, *rxLen) ); - - /* Exchange APDU: Read Capability Container File */ - err = demoTransceiveBlocking( readBynary, sizeof(readBynary), &rxData, &rxLen, RFAL_FWT_NONE ); - platformLog(" Read CC: %s Data: %s\r\n", (err != ERR_NONE) ? "FAIL": "OK", hex2Str( rxData, *rxLen) ); - } -} - - -/*! - ***************************************************************************** - * \brief Demo Blocking Transceive - * - * Helper function to send data in a blocking manner via the rfalNfc module - * - * \warning A protocol transceive handles long timeouts (several seconds), - * transmission errors and retransmissions which may lead to a long period of - * time where the MCU/CPU is blocked in this method. - * This is a demo implementation, for a non-blocking usage example please - * refer to the Examples available with RFAL - * - * \param[in] txBuf : data to be transmitted - * \param[in] txBufSize : size of the data to be transmited - * \param[out] rxData : location where the received data has been placed - * \param[out] rcvLen : number of data bytes received - * \param[in] fwt : FWT to be used (only for RF frame interface, - * otherwise use RFAL_FWT_NONE) - * - * - * \return ERR_PARAM : Invalid parameters - * \return ERR_TIMEOUT : Timeout error - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, activation successful - * - ***************************************************************************** - */ -ReturnCode demoTransceiveBlocking( uint8_t *txBuf, uint16_t txBufSize, uint8_t **rxData, uint16_t **rcvLen, uint32_t fwt ) -{ - ReturnCode err; - - err = rfalNfcDataExchangeStart( txBuf, txBufSize, rxData, rcvLen, fwt ); - if( err == ERR_NONE ) - { - do{ - rfalNfcWorker(); - err = rfalNfcDataExchangeGetStatus(); - } - while( err == ERR_BUSY ); - } - return err; -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Src/demo_ce.c b/Software/Core/Src/demo_ce.c deleted file mode 100644 index 96e1a54..0000000 --- a/Software/Core/Src/demo_ce.c +++ /dev/null @@ -1,672 +0,0 @@ -/** - ****************************************************************************** - * @file demo_ce.c - * @author MMY Application Team - * @brief Body function to manage card emul mode - ****************************************************************************** - ** This notice applies to any and all portions of this file - * that are not between comment pairs USER CODE BEGIN and - * USER CODE END. Other portions of this file, whether - * inserted by the user or by software development tools - * are owned by their respective copyright owners. - * - * COPYRIGHT(c) 2018 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "demo_ce.h" -#include "utils.h" -#include "st_errno.h" -#include "rfal_rf.h" -#include "rfal_nfca.h" -#include "rfal_nfcf.h" - -/** @addtogroup X-CUBE-NFC6_Applications - * @{ - */ - -/** @addtogroup CardEmulation - * @{ - */ - -/** @addtogroup CE_CardEmul - * @{ - */ - -/* Private typedef -----------------------------------------------------------*/ -/** @defgroup CE_CardEmul_Private_Typedef - * @{ - */ -enum States -{ - STATE_IDLE = 0, /*!< Emulated Tag state idle */ - STATE_APP_SELECTED = 1, /*!< Emulated Tag state application selected */ - STATE_CC_SELECTED = 2, /*!< Emulated Tag state CCFile selected */ - STATE_FID_SELECTED = 3, /*!< Emulated Tag state FileID selected */ -}; -/** - * @} - */ - -/* Private define ------------------------------------------------------------*/ -/** @defgroup CE_CardEmul_Private_Define - * @{ - */ - -#define NDEF_SIZE 0xFFFE /*!< Max NDEF size emulated */ -#define T4T_CLA_00 0x00 /*!< CLA value for type 4 command */ -#define T4T_INS_SELECT 0xA4 /*!< INS value for select command */ -#define T4T_INS_READ 0xB0 /*!< INS value for reabbinary command */ -#define T4T_INS_UPDATE 0xD6 /*!< INS value for update command */ -#define FID_CC 0xE103 /*!< File ID number for CCFile */ -#define FID_NDEF 0xE104 /*!< File ID number for NDEF file */ -#define T3T_BLOCK_SIZE 0x10 /*!< Block size in Type 3 Tag */ -/** - * @} - */ - -/* Private macro -------------------------------------------------------------*/ -/* Private variables ---------------------------------------------------------*/ -/** @defgroup CE_CardEmul_Private_Variables - * @{ - */ -static uint8_t gNfcfNfcid[RFAL_NFCF_NFCID2_LEN]; -static uint8_t ndefFile[2048]; /*!< Buffer to store NDEF File */ -static int8_t nState = STATE_IDLE; /*!< Type 4 tag emulation status */ -static int32_t nSelectedIdx = -1; /*!< current file selected */ -static int32_t nFiles = 2; /*!< Number of file emulated */ - - -/** - * CCLEN : Indicates the size of this CC File
- * T4T_VNo : Indicates the Mapping Version
- * MLe high : Max R-APDU size
- * MLc high : Max C-APDU size
- * NDEF FCI T: Indicates the NDEF-File_Ctrl_TLV
- * NDEF FCI L: The length of the V-field
- * NDEF FCI V1: NDEF File Identifier
- * NDEF FCI V2: NDEF File size
- * NDEF FCI V3: NDEF Read AC
- * NDEF FCI V4: NDEF Write AC
- */ -static uint8_t ccfile[] = { - 0x00, 0x0F, /* CCLEN */ - 0x20, /* T4T_VNo */ - 0x00, 0x7F, /* MLe */ - 0x00, 0x7F, /* MLc */ - 0x04, /* T */ - 0x06, /* L */ - (FID_NDEF & 0xFF00) >> 8, (FID_NDEF & 0x00FF), /* V1 */ - (NDEF_SIZE & 0xFF00) >> 8, (NDEF_SIZE & 0x00FF), /* V2 */ - 0x00, /* V3 */ - 0x00 /* V4 */ -}; - -static uint32_t pdwFileSize[] = {sizeof(ccfile), NDEF_SIZE}; /*!< Current emulated files size */ - -/** - * NDEF length
- * NDEF Header: MB,ME,SR,Well known Type
- * NDEF type length
- * NDEF payload length
- * NDEF Type : URI
- * NDEF URI abreviation field : http://www.
- * NDEF URI string : st.com/st25r
- * NDEF URI string : st.com/st25-demo
- */ -static const uint8_t ndef_uri[] = { 0x00, 0x15, /* NDEF length */ - 0xD1, /* NDEF Header */ - 0x01, /* NDEF type length */ - 0x11, /* NDEF payload length */ - 0x55, /* NDEF Type */ - 0x01, /* NDEF URI abreviation field */ - 0x73, 0x74, 0x2E, 0x63, 0x6F, /* NDEF URI string */ - 0x6D, 0x2F, 0x73, 0x74, 0x32, - 0x35, 0x2D, 0x64, 0x65, 0x6D, 0x6F }; - -/** - * Ver : Indicates the NDEF mapping versiom
- * Nbr : Indicates the number of blocks that can be read
- * Nbw : Indicates the number of blocks that can be written
- * NmaxB : Indicates the maximum number of blocks available for NDEF data
- * WriteFlag : Indicates whether a previous NDEF write procedure has finished or not
- * RWFlag : Indicates data can be updated or not
- * Ln : Is the size of the actual stored NDEF data in bytes
- * Checksum : allows the Reader/Writer to check whether the Attribute Data are correct
- */ -static uint8_t InformationBlock[] = { 0x10, /* Ver */ - 0x0F, /* Nbr */ - 0x0D, /* Nbw */ - 0x00, 0x0F, /* NmaxB */ - 0x00, 0x00, 0x00, 0x00, /* RFU */ - 0x00, /* WriteFlag */ - 0x01, /* RWFlag */ - 0x00, 0x00, 0x15, /* Ln */ - 0x00, 0x51 /* Checksum */ - }; -/** - * @} - */ - -/* Private function prototypes -----------------------------------------------*/ - -/* Private functions ---------------------------------------------------------*/ -/** @defgroup CE_CardEmul_Private_Functions - * @{ - */ - -/** - ***************************************************************************** - * @brief Compare 2 commands supplied in parameters - * - * @param[in] cmd : pointer to the received command. - * @param[in] find : pointer to the avalaible command. - * @param[in] len : length of the available command. - * - * @retval True : Same command. - * @retval False : Different command. - ***************************************************************************** - */ -static bool cmdCompare(uint8_t *cmd, uint8_t *find, uint16_t len) -{ - for(int i = 0; i < 20; i++) - { - if(!memcmp(&cmd[i],find, len)) - { - return true; - } - } - return false; -} - -/** - ***************************************************************************** - * @brief Manage the T4T Select answer to the reader - * - * @param[in] cmdData : pointer to the received command. - * @param[out] rspData : pointer to the answer to send. - * - * @return Answer size. - ***************************************************************************** - */ -static uint16_t demoCeT4TSelect(uint8_t *cmdData, uint8_t *rspData) -{ - bool success = false; - /* - * Cmd: CLA(1) | INS(1) | P1(1) | P2(1) | Lc(1) | Data(n) | [Le(1)] - * Rsp: [FCI(n)] | SW12 - * - * Select App by Name NDEF: 00 A4 04 00 07 D2 76 00 00 85 01 01 00 - * Select App by Name NDEF 4 ST: 00 A4 04 00 07 A0 00 00 00 03 00 00 00 - * Select CC FID: 00 A4 00 0C 02 xx xx - * Select NDEF FID: 00 A4 00 0C 02 xx xx - */ - - uint8_t aid[] = {0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01}; - uint8_t fidCC[] = {FID_CC >> 8 , FID_CC & 0xFF}; - uint8_t fidNDEF[] = {FID_NDEF >> 8, FID_NDEF & 0xFF}; - uint8_t selectFileId[] = {0xA4, 0x00, 0x0C, 0x02, 0x00, 0x01 }; - - if(cmdCompare( cmdData, aid, sizeof(aid))) - { /* Select Appli */ - nState = STATE_APP_SELECTED; - success = true; - } - else if((nState >= STATE_APP_SELECTED) && cmdCompare(cmdData, fidCC, sizeof(fidCC))) - { /* Select CC */ - nState = STATE_CC_SELECTED; - nSelectedIdx = 0; - success = true; - } - else if((nState >= STATE_APP_SELECTED) && (cmdCompare(cmdData,fidNDEF,sizeof(fidNDEF)) || cmdCompare(cmdData,selectFileId,sizeof(selectFileId)))) - { /* Select NDEF */ - nState = STATE_FID_SELECTED; - nSelectedIdx = 1; - success = true; - } - else - { - nState = STATE_IDLE; - } - - rspData[0] = (success ? (char)0x90 : 0x6A); - rspData[1] = (success ? (char)0x00 : 0x82); - - return 2; -} - -/** - ***************************************************************************** - * @brief Manage the T4T Read answer to the reader - * - * @param[in] cmdData : pointer to the received command. - * @param[out] rspData : pointer to the answer to send. - * - * @return Answer size. - ***************************************************************************** - */ -static uint16_t demoCeT4TRead(uint8_t *cmdData, uint8_t *rspData) -{ - /* - * Cmd: CLA(1) | INS(1) | P1(1).. offset inside file high | P2(1).. offset inside file high | Le(1).. nBytes to read - * Rsp: BytesRead | SW12 - */ - unsigned short offset = (cmdData[2] << 8) | cmdData[3]; - unsigned short toRead = cmdData[4]; - uint8_t * ppbMemory; - - /* Any file selected */ - if(nSelectedIdx < 0 || nSelectedIdx >= nFiles) - { - rspData[0] = ((char)0x6A); - rspData[1] = ((char)0x82); - return 2; - } - - /* offset + length exceed file size */ - if((unsigned long)(offset + toRead) > pdwFileSize[nSelectedIdx]) - { - toRead = pdwFileSize[nSelectedIdx] - offset; - } - - ppbMemory = (nSelectedIdx == 0 ? ccfile : ndefFile); - /* read data */ - memcpy(rspData, &ppbMemory[offset], toRead); - - rspData[toRead] = ((char)0x90); - rspData[toRead+1] = ((char)0x00); - return toRead + 2; -} - -/** - ***************************************************************************** - * @brief Manage the T4T Update answer to the reader - * - * @param[in] cmdData : pointer to the received command. - * @param[in] rspData : pointer to the answer to send. - * - * @return Answer size. - ***************************************************************************** - */ -static uint16_t demoCeT4TUpdate(uint8_t *cmdData, uint8_t *rspData) -{ - uint32_t offset = (cmdData[2] << 8) | cmdData[3]; - uint32_t length = cmdData[4]; - - if(nSelectedIdx != 1) - { - rspData[0] = ((char)0x6A); - rspData[1] = ((char)0x82); - return 2; - } - - if((unsigned long)(offset + length) > pdwFileSize[nSelectedIdx]) - { - rspData[0] = ((char)0x62); - rspData[1] = ((char)0x82); - return 2; - } - - memcpy((ndefFile + offset), &cmdData[5], length); - - rspData[0] = ((char)0x90); - rspData[1] = ((char)0x00); - return 2; -} - -/** - ***************************************************************************** - * @brief Manage the T4T Read answer to the reader - * - * @param[in] cmdData : pointer to the received command. - * @param[out] rspData : pointer to the answer to send. - * - * @return Answer size. - ***************************************************************************** - */ -static uint16_t demoCeT3TCheck(uint8_t *cmdData, uint8_t *rspData) -{ - /* - * Cmd: cmd | NFCID2 | NoS | Service code list | NoB | Block list - * Rsp: rsp | NFCID2 | Status Flag 1 | Status Flag 2 | NoB | Block Data - */ - uint8_t *block; - uint16_t blocknb[256]; - uint32_t idx = 0; - uint32_t cnt = 0; - uint32_t nbmax = 0; - - /* Command response */ - rspData[idx++] = RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION + 1; - - /* NFCID 2 bytes */ - if( ST_BYTECMP( gNfcfNfcid, &cmdData[ RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CMD_LEN ], RFAL_NFCF_NFCID2_LEN ) == 0 ) - { - ST_MEMCPY( &rspData[idx], &gNfcfNfcid, RFAL_NFCF_NFCID2_LEN ); - idx += RFAL_NFCF_NFCID2_LEN; - } - else - { - /* If NFCID2 in command is different, no answer */ - return 0; - } - - /* Check for command errors */ - if( (cmdData[10] != 1) || ((cmdData[11] != 0x09) && (cmdData[11] != 0x0B)) - || (cmdData[13] == 0) || (cmdData[13] > InformationBlock[1]) ) - { - rspData[idx++] = 0xFF; - rspData[idx++] = 0xFF; - return idx; - } - else - { - rspData[idx++] = 0x00; - rspData[idx++] = 0x00; - } - - /* Nob */ - rspData[idx++] = cmdData[13]; - - /* Retrieving block to read */ - block = &cmdData[14]; - for( cnt = 0; cnt < cmdData[13]; cnt++ ) - { - /* Check block list element size */ - if( *block & 0x80 ) - { - /* 2-byte Block List element */ - blocknb[cnt] = *(block + 1); - block += 2; - } - else - { - /* 3-byte Block List element */ - blocknb[cnt] = *(block + 1); - blocknb[cnt] <<= 8; - blocknb[cnt] |= *(block + 2); - block += 3; - } - - /* Return error if Blocknb > NmaxB */ - nbmax = InformationBlock[3]; - nbmax = (nbmax << 8) | InformationBlock[4]; - if( blocknb[cnt] > nbmax ) - { - rspData[idx - 3] = 0xFF; - rspData[idx - 2] = 0x70; - return (idx - 1); - } - } - - for( cnt = 0; cnt < cmdData[13]; cnt++ ) - { - if( blocknb[cnt] == 0x0000 ) - { - /* Read information block */ - ST_MEMCPY( &rspData[idx], InformationBlock, sizeof(InformationBlock)); - idx += sizeof(InformationBlock); - } - else - { - /* Read ndef block */ - ST_MEMCPY( &rspData[idx], &ndefFile[2 + ((blocknb[cnt] - 1) * T3T_BLOCK_SIZE) ], T3T_BLOCK_SIZE); - idx += T3T_BLOCK_SIZE; - } - } - - return idx; -} - -/** - ***************************************************************************** - * @brief Manage the T3T Update answer to the reader - * - * @param[in] cmdData : pointer to the received command. - * @param[in] rspData : pointer to the answer to send. - * - * @return Answer size. - ***************************************************************************** - */ -static uint16_t demoCeT3TUpdate(uint8_t *cmdData, uint8_t *rspData) -{ - /* - * Cmd: cmd | NFCID2 | NoS | Service code list | NoB | Block list | Block Data - * Rsp: rsp | NFCID2 | Status Flag 1 | Status Flag 2 - */ - uint8_t *block; - uint16_t blocknb[256]; - uint32_t idx = 0; - uint32_t cnt = 0; - uint32_t nbmax = 0; - - /* Command response */ - rspData[idx++] = RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION + 1; - - /* NFCID 2 bytes */ - if( ST_BYTECMP( gNfcfNfcid, &cmdData[ RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CMD_LEN ], RFAL_NFCF_NFCID2_LEN ) == 0 ) - { - ST_MEMCPY( &rspData[idx], gNfcfNfcid, RFAL_NFCF_NFCID2_LEN ); - idx += RFAL_NFCF_NFCID2_LEN; - } - else - { - /* If NFCID2 in command is different, no answer */ - return 0; - } - - /* Check for command errors */ - if( (cmdData[10] != 1) || (cmdData[11] != 0x09) - || (cmdData[13] == 0) || (cmdData[13] > InformationBlock[2]) ) - { - rspData[idx++] = 0xFF; - rspData[idx++] = 0xFF; - return idx; - } - else - { - rspData[idx++] = 0x00; - rspData[idx++] = 0x00; - } - - - /* Retrieving block to read */ - block = &cmdData[14]; - for( cnt = 0; cnt < cmdData[13]; cnt++ ) - { - /* Check block list element size */ - if( *block & 0x80 ) - { - /* 2-byte Block List element */ - blocknb[cnt] = *(block + 1); - block += 2; - } - else - { - /* 3-byte Block List element */ - blocknb[cnt] = *(block + 1); - blocknb[cnt] <<= 8; - blocknb[cnt] |= *(block + 2); - block += 3; - } - /* Return error if Blocknb > NmaxB */ - nbmax = InformationBlock[3]; - nbmax = (nbmax << 8) | InformationBlock[4]; - if( blocknb[cnt] > nbmax ) - { - rspData[idx - 2] = 0xFF; - rspData[idx - 1] = 0x70; - return idx; - } - } - - for( cnt = 0; cnt < cmdData[13]; cnt++ ) - { - if( blocknb[cnt] == 0x0000 ) - { - /* Write information block */ - ST_MEMCPY( InformationBlock, block, T3T_BLOCK_SIZE); - block += T3T_BLOCK_SIZE; - } - else - { - /* Read ndef block */ - ST_MEMCPY( &ndefFile[2 + ((blocknb[cnt] - 1) * T3T_BLOCK_SIZE) ], block, T3T_BLOCK_SIZE); - block += T3T_BLOCK_SIZE; - } - } - - /* Status flag answer */ - rspData[idx++] = 0x00; - rspData[idx++] = 0x00; - - return idx; -} - - -/** - ***************************************************************************** - * @brief Demo CE Initialize - * - * Initializes the demo CE - * - * @param[in] nfcfNfcid : The NFCID to be used in T3T CE. - * - * @return None - ***************************************************************************** - */ -void demoCeInit( uint8_t* nfcfNfcid ) -{ - ST_MEMCPY(gNfcfNfcid, nfcfNfcid, RFAL_NFCF_NFCID2_LEN ); - ST_MEMCPY(ndefFile, (uint8_t *)ndef_uri, sizeof(ndef_uri) ); -} - -/** - ***************************************************************************** - * @brief Demo CE T3T - * - * Parses the received command and computes the response to be sent back to - * the Reader - * - * @param[in] rxData : pointer to the received command. - * @param[in] rxDataLen : length of the received command. - * @param[in] txBuf : pointer to where the response will be placed. - * @param[in] txBufLen : size of txBuf. - * - * @return Response size. - ***************************************************************************** - */ -uint16_t demoCeT4T(uint8_t *rxData, uint16_t rxDataLen, uint8_t *txBuf, uint16_t txBufLen ) -{ - if( (rxData == NULL) || (rxDataLen < 4) || (txBuf == NULL) || (txBufLen < 2) ) - { - return 0; - } - - if(rxData[0] == T4T_CLA_00) - { - switch(rxData[1]) - { - case T4T_INS_SELECT: - return demoCeT4TSelect(rxData, txBuf); - - case T4T_INS_READ: - return demoCeT4TRead(rxData, txBuf); - - case T4T_INS_UPDATE: - return demoCeT4TUpdate(rxData, txBuf); - - default: - break; - } - } - - /* Function not supported ... */ - txBuf[0] = ((char)0x68); - txBuf[1] = ((char)0x00); - return 2; -} - -/** - ***************************************************************************** - * @brief Demo CE T3T - * - * Parses the received command and computes the response to be sent back to - * the Reader - * - * @param[in] rxData : pointer to the received command. - * @param[in] rxDataLen : length of the received command. - * @param[in] txBuf : pointer to where the response will be placed. - * @param[in] txBufLen : size of txBuf. - * - * @return Response size. - ***************************************************************************** - */ -uint16_t demoCeT3T(uint8_t *rxData, uint16_t rxDataLen, uint8_t *txBuf, uint16_t txBufLen ) -{ - if( (rxData == NULL) || (rxDataLen < 4) || (txBuf == NULL) || (txBufLen < 2) ) - { - return 0; - } - - switch(rxData[1]) - { - case RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION: - return demoCeT3TCheck(rxData, txBuf); - - case RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION: - return demoCeT3TUpdate(rxData, txBuf); - - default: - break; - } - - /* Function not supported ... */ - txBuf[0] = ((char)0xFF); - txBuf[1] = ((char)0xFF); - return 2; -} - - - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Src/logger.c b/Software/Core/Src/logger.c deleted file mode 100644 index 76f006f..0000000 --- a/Software/Core/Src/logger.c +++ /dev/null @@ -1,157 +0,0 @@ -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/* - * PROJECT: - * $Revision: $ - * LANGUAGE: ANSI C - */ - -/*! \file - * - * \author - * - * \brief Debug log output utility implementation. - * - */ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "usart.h" -#include "logger.h" -#include "st_errno.h" -#include "utils.h" -#include -#include -#include - -/* -****************************************************************************** -* LOCAL DEFINES -****************************************************************************** -*/ - - -#if (USE_LOGGER == LOGGER_ON) - -#define MAX_HEX_STR 4 -#define MAX_HEX_STR_LENGTH 128 -char hexStr[MAX_HEX_STR][MAX_HEX_STR_LENGTH]; -uint8_t hexStrIdx = 0; -#endif /* #if USE_LOGGER == LOGGER_ON */ - -#define USART_TIMEOUT 1000 - -UART_HandleTypeDef *pLogUsart = 0; -uint8_t logUsartTx(uint8_t *data, uint16_t dataLen); - -/** - * @brief This function initalize the UART handle. - * @param husart : already initalized handle to USART HW - * @retval none : - */ -void logUsartInit(UART_HandleTypeDef *husart) -{ - pLogUsart = husart; -} - -/** - * @brief This function Transmit data via USART - * @param data : data to be transmitted - * @param dataLen : length of data to be transmitted - * @retval ERR_INVALID_HANDLE : in case the SPI HW is not initalized yet - * @retval others : HAL status - */ -uint8_t logUsartTx(uint8_t *data, uint16_t dataLen) -{ - if(pLogUsart == 0) - return ERR_INVALID_HANDLE; - - return HAL_UART_Transmit(pLogUsart, data, dataLen, USART_TIMEOUT); -} - -int logUsart(const char* format, ...) -{ - #if (USE_LOGGER == LOGGER_ON) - { - #define LOG_BUFFER_SIZE 256 - char buf[LOG_BUFFER_SIZE]; - va_list argptr; - va_start(argptr, format); - int cnt = vsnprintf(buf, LOG_BUFFER_SIZE, format, argptr); - va_end(argptr); - - /* */ - logUsartTx((uint8_t*)buf, strlen(buf)); - return cnt; - } - #else - { - return 0; - } - #endif /* #if USE_LOGGER == LOGGER_ON */ -} - -/* */ - -char* hex2Str(unsigned char * data, size_t dataLen) -{ - #if (USE_LOGGER == LOGGER_ON) - { - unsigned char * pin = data; - const char * hex = "0123456789ABCDEF"; - char * pout = hexStr[hexStrIdx]; - uint8_t i = 0; - uint8_t idx = hexStrIdx; - size_t len; - - if(dataLen == 0) - { - pout[0] = 0; - } - else - { - /* Trim data that doesn't fit in buffer */ - len = MIN( dataLen , (MAX_HEX_STR_LENGTH / 2) ); - - for(; i < (len - 1); ++i) - { - *pout++ = hex[(*pin>>4)&0xF]; - *pout++ = hex[(*pin++)&0xF]; - } - *pout++ = hex[(*pin>>4)&0xF]; - *pout++ = hex[(*pin)&0xF]; - *pout = 0; - } - - hexStrIdx++; - hexStrIdx %= MAX_HEX_STR; - - return hexStr[idx]; - } - #else - { - return NULL; - } - #endif /* #if USE_LOGGER == LOGGER_ON */ -} diff --git a/Software/Core/Src/main.c b/Software/Core/Src/main.c deleted file mode 100644 index d5d6266..0000000 --- a/Software/Core/Src/main.c +++ /dev/null @@ -1,439 +0,0 @@ - -/** - ****************************************************************************** - * @file : main.c - * @brief : Main program body - ****************************************************************************** - ** This notice applies to any and all portions of this file - * that are not between comment pairs USER CODE BEGIN and - * USER CODE END. Other portions of this file, whether - * inserted by the user or by software development tools - * are owned by their respective copyright owners. - * - * COPYRIGHT(c) 2018 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -/* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "stm32l4xx_hal.h" - -/* USER CODE BEGIN Includes */ -#include "demo.h" -#include "platform.h" -#include "spi.h" -#include "usart.h" -#include "logger.h" -#include "st_errno.h" -#include "rfal_nfc.h" -/* USER CODE END Includes */ - -/* Private variables ---------------------------------------------------------*/ -SPI_HandleTypeDef hspi1; - -UART_HandleTypeDef huart2; - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ -uint8_t globalCommProtectCnt = 0; -/* USER CODE END PV */ - -/* Private function prototypes -----------------------------------------------*/ -void SystemClock_Config(void); -static void MX_GPIO_Init(void); -static void MX_USART2_UART_Init(void); -static void MX_SPI1_Init(void); - -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ - -/* USER CODE END PFP */ - -/* USER CODE BEGIN 0 */ - - -/* USER CODE END 0 */ - - -/** - * @brief The application entry point. - * - * @retval None - */ -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 */ - MX_GPIO_Init(); - MX_USART2_UART_Init(); - MX_SPI1_Init(); - /* USER CODE BEGIN 2 */ - - /* Initialize driver*/ - spiInit(&hspi1); - - /* Initialize log module */ - logUsartInit(&huart2); - - platformLog("Welcome to X-NUCLEO-NFC05A1\r\n"); - - /* Initalize RFAL */ - if( !demoIni() ) - { - /* - * in case the rfal initalization failed signal it by flashing all LED - * and stoping all operations - */ - platformLog("Initialization failed..\r\n"); - while(1) - { - platformLedToogle(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN); - platformLedToogle(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN); - platformLedToogle(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - platformLedToogle(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN); - platformLedToogle(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN); - platformLedToogle(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN); - platformDelay(100); - } - } - else - { - platformLog("Initialization succeeded..\r\n"); - for (int i = 0; i < 6; i++) - { - platformLedToogle(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN); - platformLedToogle(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN); - platformLedToogle(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - platformLedToogle(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN); - platformLedToogle(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN); - platformLedToogle(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN); - platformDelay(200); - } - - platformLedOff(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN); - platformLedOff(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - platformLedOff(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN); - platformLedOff(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN); - platformLedOff(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN); - platformLedOff(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN); - } - - /* USER CODE END 2 */ - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - while (1) - { - /* Run Demo Application */ - demoCycle(); - - /* USER CODE END WHILE */ - - /* USER CODE BEGIN 3 */ - } - /* USER CODE END 3 */ - -} - -/** - * @brief System Clock Configuration - * @retval None - */ -void SystemClock_Config(void) -{ - - RCC_OscInitTypeDef RCC_OscInitStruct; - RCC_ClkInitTypeDef RCC_ClkInitStruct; - RCC_PeriphCLKInitTypeDef PeriphClkInit; - - /**Configure LSE Drive Capability - */ - HAL_PWR_EnableBkUpAccess(); - - __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); - - /**Initializes the CPU, AHB and APB busses clocks - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI; - RCC_OscInitStruct.LSEState = RCC_LSE_ON; - RCC_OscInitStruct.MSIState = RCC_MSI_ON; - RCC_OscInitStruct.MSICalibrationValue = 0; - RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - _Error_Handler(__FILE__, __LINE__); - } - - /**Initializes the CPU, AHB and APB busses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI; - 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_2) != HAL_OK) - { - _Error_Handler(__FILE__, __LINE__); - } - - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2; - PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) - { - _Error_Handler(__FILE__, __LINE__); - } - - /**Configure the main internal regulator output voltage - */ - if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) - { - _Error_Handler(__FILE__, __LINE__); - } - - /**Configure the Systick interrupt time - */ - HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); - - /**Configure the Systick - */ - HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); - - /**Enable MSI Auto calibration - */ - HAL_RCCEx_EnableMSIPLLMode(); - - /* SysTick_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); -} - -/* SPI1 init function */ -static void MX_SPI1_Init(void) -{ - - /* SPI1 parameter configuration*/ - hspi1.Instance = SPI1; - hspi1.Init.Mode = SPI_MODE_MASTER; - hspi1.Init.Direction = SPI_DIRECTION_2LINES; - hspi1.Init.DataSize = SPI_DATASIZE_8BIT; - hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; - hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; - hspi1.Init.NSS = SPI_NSS_SOFT; - hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; - hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; - hspi1.Init.TIMode = SPI_TIMODE_DISABLE; - hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; - hspi1.Init.CRCPolynomial = 7; - hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; - hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; - if (HAL_SPI_Init(&hspi1) != HAL_OK) - { - _Error_Handler(__FILE__, __LINE__); - } - -} - -/* USART2 init function */ -static void MX_USART2_UART_Init(void) -{ - - huart2.Instance = USART2; - huart2.Init.BaudRate = 115200; - huart2.Init.StopBits = UART_STOPBITS_1; - huart2.Init.Parity = UART_PARITY_NONE; - huart2.Init.Mode = UART_MODE_TX_RX; - huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart2.Init.OverSampling = UART_OVERSAMPLING_16; - huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; - huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - if (HAL_UART_Init(&huart2) != HAL_OK) - { - _Error_Handler(__FILE__, __LINE__); - } - -} - -/** Configure pins as - * Analog - * Input - * Output - * EVENT_OUT - * EXTI - * Free pins are configured automatically as Analog (this feature is enabled through - * the Code Generation settings) -*/ -static void MX_GPIO_Init(void) -{ - - GPIO_InitTypeDef GPIO_InitStruct; - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOA, LED_F_Pin|LED_B_Pin|LED_FIELD_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOB, LED_A_Pin|LED_V_Pin|LED_AP2P_Pin|SPI1_CS_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin : B1_Pin */ - GPIO_InitStruct.Pin = B1_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : PC0 PC1 PC2 PC3 - PC4 PC5 PC6 PC7 - PC8 PC9 PC10 PC11 - PC12 */ - GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 - |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7 - |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 - |GPIO_PIN_12; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - - /*Configure GPIO pin : IRQ_3911_Pin */ - GPIO_InitStruct.Pin = IRQ_3911_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(IRQ_3911_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : LED_F_Pin LED_B_Pin LED_FIELD_Pin */ - GPIO_InitStruct.Pin = LED_F_Pin|LED_B_Pin|LED_FIELD_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /*Configure GPIO pins : LED_A_Pin LED_V_Pin LED_AP2P_Pin SPI1_CS_Pin */ - GPIO_InitStruct.Pin = LED_A_Pin|LED_V_Pin|LED_AP2P_Pin|SPI1_CS_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pins : PB1 PB2 PB10 PB11 - PB12 PB13 PB14 PB15 - PB7 PB8 PB9 */ - GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10|GPIO_PIN_11 - |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15 - |GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pins : PA9 PA10 PA11 PA12 - PA15 */ - GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12 - |GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /*Configure GPIO pin : PD2 */ - GPIO_InitStruct.Pin = GPIO_PIN_2; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /* EXTI interrupt init*/ - HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(EXTI0_IRQn); - -} - -/* USER CODE BEGIN 4 */ - -/* USER CODE END 4 */ - -/** - * @brief This function is executed in case of error occurrence. - * @param file: The file name as string. - * @param line: The line in file as a number. - * @retval None - */ -void _Error_Handler(char *file, int line) -{ - /* USER CODE BEGIN Error_Handler_Debug */ - /* User can add his own implementation to report the HAL error return state */ - 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****/ diff --git a/Software/Core/Src/ndef_demo.c b/Software/Core/Src/ndef_demo.c deleted file mode 100644 index d6e373b..0000000 --- a/Software/Core/Src/ndef_demo.c +++ /dev/null @@ -1,1103 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/*! \file - * - * \author - * - * \brief Demo application - * - * This demo shows how to poll for several types of NFC cards/devices and how - * to exchange data with these devices, using the RFAL library. - * - * This demo does not fully implement the activities according to the standards, - * it performs the required to communicate with a card/device and retrieve - * its UID. Also blocking methods are used for data exchange which may lead to - * long periods of blocking CPU/MCU. - * For standard compliant example please refer to the Examples provided - * with the RFAL library. - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "demo.h" -#include "utils.h" -#include "rfal_nfc.h" -#include "ndef_poller.h" -#include "ndef_t2t.h" -#include "ndef_t4t.h" -#include "ndef_t5t.h" -#include "ndef_message.h" -#include "ndef_types_rtd.h" -#include "ndef_dump.h" - - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - -/* Definition of possible states the demo state machine could have */ -#define DEMO_ST_NOTINIT 0 /*!< Demo State: Not initialized */ -#define DEMO_ST_START_DISCOVERY 1 /*!< Demo State: Start Discovery */ -#define DEMO_ST_DISCOVERY 2 /*!< Demo State: Discovery */ - -#define NDEF_DEMO_READ 0U /*!< NDEF menu read */ -#define NDEF_DEMO_WRITE_MSG1 1U /*!< NDEF menu write 1 record */ -#define NDEF_DEMO_WRITE_MSG2 2U /*!< NDEF menu write 2 records */ -#define NDEF_DEMO_FORMAT_TAG 3U /*!< NDEF menu format tag */ -#if NDEF_FEATURE_ALL -#define NDEF_DEMO_MAX_FEATURES 4U /*!< Number of menu items */ -#else -#define NDEF_DEMO_MAX_FEATURES 1U /*!< Number of menu items */ -#endif /* NDEF_FEATURE_ALL */ -#define NDEF_WRITE_FORMAT_TIMEOUT 10000U /*!< When write or format mode is selected, demo returns back to read mode after a timeout */ -#define NDEF_LED_BLINK_DURATION 250U /*!< Led blink duration */ - -#define DEMO_RAW_MESSAGE_BUF_LEN 8192 /*!< Raw message buffer len */ - -#define DEMO_ST_MANUFACTURER_ID 0x02U /*!< ST Manufacturer ID */ - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -/* P2P communication data */ -static uint8_t NFCID3[] = {0x01, 0xFE, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}; -static uint8_t GB[] = {0x46, 0x66, 0x6d, 0x01, 0x01, 0x11, 0x02, 0x02, 0x07, 0x80, 0x03, 0x02, 0x00, 0x03, 0x04, 0x01, 0x32, 0x07, 0x01, 0x03}; - -#if defined(ST25R3916) && defined(RFAL_FEATURE_LISTEN_MODE) -/* NFC-A CE config */ -static uint8_t ceNFCA_NFCID[] = {0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; /* NFCID / UID (7 bytes) */ -static uint8_t ceNFCA_SENS_RES[] = {0x44, 0x00}; /* SENS_RES / ATQA */ -static uint8_t ceNFCA_SEL_RES = 0x20; /* SEL_RES / SAK */ - -/* NFC-F CE config */ -static uint8_t ceNFCF_nfcid2[] = {0x02, 0xFE, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; -static uint8_t ceNFCF_SC[] = {0x12, 0xFC}; -static uint8_t ceNFCF_SENSF_RES[] = {0x01, /* SENSF_RES */ - 0x02, 0xFE, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, /* NFCID2 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x7F, 0x00, /* PAD0, PAD01, MRTIcheck, MRTIupdate, PAD2 */ - 0x00, 0x00 }; /* RD */ -#endif /* RFAL_FEATURE_LISTEN_MODE */ - -/* P2P communication data */ -static uint8_t ndefLLCPSYMM[] = {0x00, 0x00}; -static uint8_t ndefInit[] = {0x05, 0x20, 0x06, 0x0F, 0x75, 0x72, 0x6E, 0x3A, 0x6E, 0x66, 0x63, 0x3A, 0x73, 0x6E, 0x3A, 0x73, 0x6E, 0x65, 0x70, 0x02, 0x02, 0x07, 0x80, 0x05, 0x01, 0x02}; -static const uint8_t ndefSnepPrefix[] = { 0x13, 0x20, 0x00, 0x10, 0x02, 0x00, 0x00, 0x00 }; -static const uint8_t URL[] = "st.com"; -static ndefConstBuffer bufURL = { URL, sizeof(URL) - 1 }; -static uint8_t ndefUriBuffer[255]; - -static uint8_t *ndefStates[] = -{ - (uint8_t *)"INVALID", - (uint8_t *)"INITIALIZED", - (uint8_t *)"READ/WRITE", - (uint8_t *)"READ-ONLY" -}; - -static const uint8_t *ndefDemoFeatureDescription[NDEF_DEMO_MAX_FEATURES] = -{ - (uint8_t *)"1. Tap a tag to read its content", -#if NDEF_FEATURE_ALL - (uint8_t *)"2. Present a tag to write a Text record", - (uint8_t *)"3. Present a tag to write a URI record and an Android Application record", - (uint8_t *)"4. Present an ST tag to format", -#endif /* NDEF_FEATURE_ALL */ -}; - -#if NDEF_FEATURE_ALL -static uint8_t ndefURI[] = "st.com"; -static uint8_t ndefTEXT[] = "Welcome to ST NDEF demo"; -static uint8_t ndefTextLangCode[] = "en"; - -static uint8_t ndefAndroidPackName[] = "com.st.st25nfc"; -#endif /* NDEF_FEATURE_ALL */ - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -static rfalNfcDiscoverParam discParam; -static uint8_t state = DEMO_ST_NOTINIT; - -static ndefContext ndefCtx; -static uint8_t ndefDemoFeature = NDEF_DEMO_READ; -static uint8_t ndefDemoPrevFeature = 0xFF; -static bool verbose = false; - -static uint8_t rawMessageBuf[DEMO_RAW_MESSAGE_BUF_LEN]; - -static uint32_t timer; -static uint32_t timerLed; -static bool ledOn; - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -static void demoNdef(rfalNfcDevice *nfcDevice); -static void ndefCCDump(ndefContext *ctx); -static void ndefDumpSysInfo(ndefContext *ctx); - -#if NDEF_FEATURE_ALL -static bool ndefIsSTTag(ndefContext *ctx); -static void LedNotificationWriteDone(void); -#endif /* NDEF_FEATURE_ALL */ - -static void demoP2P( void ); -ReturnCode demoTransceiveBlocking( uint8_t *txBuf, uint16_t txBufSize, uint8_t **rxBuf, uint16_t **rcvLen, uint32_t fwt ); - -static void ledsOn(void); -static void ledsOff(void); - -/*! - ***************************************************************************** - * \brief Check user button - * - * This function check whethe the user button has been pressed - ***************************************************************************** - */ - -static void checkUserButton(void) -{ - /* Check if USER button is pressed */ - if( platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN)) - { - ndefDemoFeature++; - ndefDemoFeature %= NDEF_DEMO_MAX_FEATURES; - - ledsOff(); - ndefDemoPrevFeature = ndefDemoFeature; - platformLog("%s\r\n", ndefDemoFeatureDescription[ndefDemoFeature]); - /* Debounce button */ - while( platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN) ); - if( ndefDemoFeature != NDEF_DEMO_READ ) - { - timer = platformTimerCreate(NDEF_WRITE_FORMAT_TIMEOUT); - timerLed = platformTimerCreate(NDEF_LED_BLINK_DURATION); - } - } -} - -/*! - ***************************************************************************** - * \brief Show usage - * - * This function displays usage information - ***************************************************************************** - */ -static void ndefShowDemoUsage() -{ -#if NDEF_FEATURE_ALL - uint32_t i; - - platformLog("Use the User button to cycle among the different modes:\r\n"); - for (i = 0; i < SIZEOF_ARRAY(ndefDemoFeatureDescription); i++) - { - platformLog("%s\r\n", ndefDemoFeatureDescription[i]); - } - platformLog("In Write or Format mode (menu 2, 3 or 4), the demo returns to Read mode (menu 1) if no tag detected after %d seconds\r\n\n", NDEF_WRITE_FORMAT_TIMEOUT/1000); -#endif /* NDEF_FEATURE_ALL */ -} - -/*! - ***************************************************************************** - * \brief Demo Ini - * - * This function Initializes the required layers for the demo - * - * \return true : Initialization ok - * \return false : Initialization failed - ***************************************************************************** - */ -bool demoIni( void ) -{ - ReturnCode err; - -#if defined(STM32L476xx) - if( (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) != 0) - { - verbose = true; - } -#endif - ndefShowDemoUsage(); - - err = rfalNfcInitialize(); - if( err == ERR_NONE ) - { - discParam.compMode = RFAL_COMPLIANCE_MODE_NFC; - discParam.devLimit = 1U; - discParam.nfcfBR = RFAL_BR_212; - discParam.ap2pBR = RFAL_BR_424; - - ST_MEMCPY( &discParam.nfcid3, NFCID3, sizeof(NFCID3) ); - ST_MEMCPY( &discParam.GB, GB, sizeof(GB) ); - discParam.GBLen = sizeof(GB); - - discParam.notifyCb = NULL; - discParam.totalDuration = 1000U; - discParam.wakeupEnabled = false; - discParam.wakeupConfigDefault = true; - discParam.techs2Find = ( RFAL_NFC_POLL_TECH_A | RFAL_NFC_POLL_TECH_B | RFAL_NFC_POLL_TECH_F | RFAL_NFC_POLL_TECH_V | RFAL_NFC_POLL_TECH_ST25TB ); -#if defined(ST25R3911) || defined(ST25R3916) - discParam.techs2Find |= RFAL_NFC_POLL_TECH_AP2P; -#endif /* ST25R3911 || ST25R3916 */ - - -#if defined(ST25R3916) - - /* Set configuration for NFC-A CE */ - ST_MEMCPY( discParam.lmConfigPA.SENS_RES, ceNFCA_SENS_RES, RFAL_LM_SENS_RES_LEN ); /* Set SENS_RES / ATQA */ - ST_MEMCPY( discParam.lmConfigPA.nfcid, ceNFCA_NFCID, RFAL_NFCID2_LEN ); /* Set NFCID / UID */ - discParam.lmConfigPA.nfcidLen = RFAL_LM_NFCID_LEN_07; /* Set NFCID length to 7 bytes */ - discParam.lmConfigPA.SEL_RES = ceNFCA_SEL_RES; /* Set SEL_RES / SAK */ - - /* Set configuration for NFC-F CE */ - ST_MEMCPY( discParam.lmConfigPF.SC, ceNFCF_SC, RFAL_LM_SENSF_SC_LEN ); /* Set System Code */ - ST_MEMCPY( &ceNFCF_SENSF_RES[RFAL_NFCF_LENGTH_LEN], ceNFCF_nfcid2, RFAL_LM_SENSF_RES_LEN ); /* Load NFCID2 on SENSF_RES */ - ST_MEMCPY( discParam.lmConfigPF.SENSF_RES, ceNFCF_SENSF_RES, RFAL_LM_SENSF_RES_LEN ); /* Set SENSF_RES / Poll Response */ - - discParam.techs2Find |= ( RFAL_NFC_LISTEN_TECH_A | RFAL_NFC_LISTEN_TECH_F ); - -#endif /* ST25R3916 */ - - state = DEMO_ST_START_DISCOVERY; - return true; - } - return false; -} - -/*! - ***************************************************************************** - * \brief Demo Cycle - * - * This function executes the demo state machine. - * It must be called periodically - ***************************************************************************** - */ -void demoCycle( void ) -{ - static rfalNfcDevice *nfcDevice; - - rfalNfcaSensRes sensRes; - rfalNfcaSelRes selRes; - - rfalNfcbSensbRes sensbRes; - uint8_t sensbResLen; - - uint8_t devCnt = 0; - rfalFeliCaPollRes cardList[1]; - uint8_t collisions = 0U; - rfalNfcfSensfRes* sensfRes; - - rfalNfcvInventoryRes invRes; - uint16_t rcvdLen; - - rfalNfcWorker(); /* Run RFAL worker periodically */ - - if( (ndefDemoFeature != NDEF_DEMO_READ) && (platformTimerIsExpired(timer)) ) - { - platformLog("Timer expired, back to Read mode...\r\n"); - ndefDemoFeature = NDEF_DEMO_READ; - } - - if( ndefDemoFeature != ndefDemoPrevFeature ) - { - ndefDemoPrevFeature = ndefDemoFeature; - platformLog("%s\r\n", ndefDemoFeatureDescription[ndefDemoFeature]); - } - - if( ndefDemoFeature != NDEF_DEMO_READ ) - { - if( platformTimerIsExpired(timerLed) ) - { - timerLed = platformTimerCreate(NDEF_LED_BLINK_DURATION); - ledOn = !ledOn; - } - if( ledOn ) - { - ledsOn(); - } - else - { - ledsOff(); - } - } - - checkUserButton(); - - switch( state ) - { - /*******************************************************************************/ - case DEMO_ST_START_DISCOVERY: - ledsOff(); - - rfalNfcDeactivate( false ); - rfalNfcDiscover( &discParam ); - - state = DEMO_ST_DISCOVERY; - break; - - /*******************************************************************************/ - case DEMO_ST_DISCOVERY: - if( rfalNfcIsDevActivated( rfalNfcGetState() ) ) - { - rfalNfcGetActiveDevice( &nfcDevice ); - - ledsOff(); - platformDelay(50); - ndefDemoPrevFeature = 0xFF; /* Force the display of the prompt */ - switch( nfcDevice->type ) - { - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_NFCA: - - platformLedOn(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN); - switch( nfcDevice->dev.nfca.type ) - { - case RFAL_NFCA_T1T: - platformLog("ISO14443A/Topaz (NFC-A T1T) TAG found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - rfalNfcaPollerSleep(); - break; - - case RFAL_NFCA_T4T: - platformLog("NFCA Passive ISO-DEP device found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - demoNdef(nfcDevice); - rfalIsoDepDeselect(); - break; - - case RFAL_NFCA_T4T_NFCDEP: - case RFAL_NFCA_NFCDEP: - platformLog("NFCA Passive P2P device found. NFCID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - demoP2P(); - break; - - default: - platformLog("ISO14443A/NFC-A card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - demoNdef(nfcDevice); - rfalNfcaPollerSleep(); - break; - } - /* Loop until tag is removed from the field */ - platformLog("Operation completed\r\nTag can be removed from the field\r\n"); - rfalNfcaPollerInitialize(); - while( rfalNfcaPollerCheckPresence(RFAL_14443A_SHORTFRAME_CMD_WUPA, &sensRes) == ERR_NONE ) - { - if( ((nfcDevice->dev.nfca.type == RFAL_NFCA_T1T) && (!rfalNfcaIsSensResT1T(&sensRes ))) || - ((nfcDevice->dev.nfca.type != RFAL_NFCA_T1T) && (rfalNfcaPollerSelect(nfcDevice->dev.nfca.nfcId1, nfcDevice->dev.nfca.nfcId1Len, &selRes) != ERR_NONE)) ) - { - break; - } - rfalNfcaPollerSleep(); - platformDelay(130); - } - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_NFCB: - - platformLog("ISO14443B/NFC-B card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - platformLedOn(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - - if( rfalNfcbIsIsoDepSupported( &nfcDevice->dev.nfcb ) ) - { - demoNdef(nfcDevice); - rfalIsoDepDeselect(); - } - else - { - rfalNfcbPollerSleep(nfcDevice->dev.nfcb.sensbRes.nfcid0); - } - /* Loop until tag is removed from the field */ - platformLog("Operation completed\r\nTag can be removed from the field\r\n"); - rfalNfcbPollerInitialize(); - while( rfalNfcbPollerCheckPresence(RFAL_NFCB_SENS_CMD_ALLB_REQ, RFAL_NFCB_SLOT_NUM_1, &sensbRes, &sensbResLen) == ERR_NONE ) - { - if( ST_BYTECMP(sensbRes.nfcid0, nfcDevice->dev.nfcb.sensbRes.nfcid0, RFAL_NFCB_NFCID0_LEN) != 0 ) - { - break; - } - rfalNfcbPollerSleep(nfcDevice->dev.nfcb.sensbRes.nfcid0); - platformDelay(130); - } - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_NFCF: - - if( rfalNfcfIsNfcDepSupported( &nfcDevice->dev.nfcf ) ) - { - platformLog("NFCF Passive P2P device found. NFCID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) ); - demoP2P(); - } - else - { - platformLog("Felica/NFC-F card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen )); - demoNdef(nfcDevice); - } - - platformLedOn(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN); - /* Loop until tag is removed from the field */ - platformLog("Operation completed\r\nTag can be removed from the field\r\n"); - devCnt = 1; - rfalNfcfPollerInitialize( RFAL_BR_212 ); - while (rfalNfcfPollerPoll( RFAL_FELICA_1_SLOT, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_NO_REQUEST, cardList, &devCnt, &collisions ) == ERR_NONE) - { - /* Skip the length field byte */ - sensfRes = (rfalNfcfSensfRes*)&((uint8_t *)cardList)[1]; - if( ST_BYTECMP(sensfRes->NFCID2, nfcDevice->dev.nfcf.sensfRes.NFCID2, RFAL_NFCF_NFCID2_LEN) != 0 ) - { - break; - } - platformDelay(130); - } - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_NFCV: - { - uint8_t devUID[RFAL_NFCV_UID_LEN]; - - ST_MEMCPY( devUID, nfcDevice->nfcid, nfcDevice->nfcidLen ); /* Copy the UID into local var */ - REVERSE_BYTES( devUID, RFAL_NFCV_UID_LEN ); /* Reverse the UID for display purposes */ - platformLog("ISO15693/NFC-V card found. UID: %s\r\n", hex2Str(devUID, RFAL_NFCV_UID_LEN)); - - platformLedOn(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN); - - demoNdef(nfcDevice); - - /* Loop until tag is removed from the field */ - platformLog("Operation completed\r\nTag can be removed from the field\r\n"); - rfalNfcvPollerInitialize(); - while (rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_1, RFAL_NFCV_UID_LEN * 8U, nfcDevice->dev.nfcv.InvRes.UID, &invRes, &rcvdLen) == ERR_NONE) - { - platformDelay(130); - } - } - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_ST25TB: - - platformLog("ST25TB card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen )); - platformLedOn(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - break; - - /*******************************************************************************/ - case RFAL_NFC_LISTEN_TYPE_AP2P: - - platformLog("NFC Active P2P device found. NFCID3: %s\r\n", hex2Str(nfcDevice->nfcid, nfcDevice->nfcidLen)); - platformLedOn(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN); - - demoP2P(); - break; - - /*******************************************************************************/ - default: - break; - } - - rfalNfcDeactivate( false ); - platformDelay( 500 ); - state = DEMO_ST_START_DISCOVERY; - } - break; - - /*******************************************************************************/ - case DEMO_ST_NOTINIT: - default: - break; - } -} - - -/*! - ***************************************************************************** - * \brief Demo P2P Exchange - * - * Sends a NDEF URI record 'http://www.ST.com' via NFC-DEP (P2P) protocol. - * - * This method sends a set of static predefined frames which tries to establish - * a LLCP connection, followed by the NDEF record, and then keeps sending - * LLCP SYMM packets to maintain the connection. - * - * - ***************************************************************************** - */ -void demoP2P( void ) -{ - uint16_t *rxLen; - uint8_t *rxData; - ReturnCode err; - - ndefBuffer bufPayload; - ndefMessage message; - ndefRecord record; - ndefType uri; - - platformLog(" Initalize device .. "); - err = demoTransceiveBlocking( ndefInit, sizeof(ndefInit), &rxData, &rxLen, RFAL_FWT_NONE); - if( err != ERR_NONE ) - { - platformLog("failed."); - return; - } - platformLog("succeeded.\r\n"); - - err = ndefRtdUri(&uri, NDEF_URI_PREFIX_HTTP_WWW, &bufURL); - err |= ndefRtdUriToRecord(&uri, &record); - - err |= ndefMessageInit(&message); - err |= ndefMessageAppend(&message, &record); /* To get MB and ME bits set */ - - /* Build the SNEP buffer made of the prefix, the length byte and the record */ - ST_MEMCPY(ndefUriBuffer, ndefSnepPrefix, sizeof(ndefSnepPrefix)); - - /* Skip 1 byte for length byte */ - bufPayload.buffer = ndefUriBuffer + sizeof(ndefSnepPrefix) + 1; - bufPayload.length = sizeof(ndefUriBuffer) - sizeof(ndefSnepPrefix); - err |= ndefMessageEncode(&message, &bufPayload); - - ndefUriBuffer[sizeof(ndefSnepPrefix)] = bufPayload.length; - - bufPayload.buffer = ndefUriBuffer; - bufPayload.length = sizeof(ndefSnepPrefix) + 1 + bufPayload.length; - - if( err != ERR_NONE ) - { - platformLog("NDEF message creation failed\r\n", err); - return; - } - - ndefBufferDump("URL converted to SNEP:\r\n", (ndefConstBuffer*)&bufPayload, true); - - platformLog(" Push NDEF Uri: www.ST.com .. "); - err = demoTransceiveBlocking(bufPayload.buffer, bufPayload.length, &rxData, &rxLen, RFAL_FWT_NONE); - if( err != ERR_NONE ) - { - platformLog("failed."); - return; - } - platformLog("succeeded.\r\n"); - - - platformLog(" Device present, maintaining connection "); - while(err == ERR_NONE) - { - err = demoTransceiveBlocking( ndefLLCPSYMM, sizeof(ndefLLCPSYMM), &rxData, &rxLen, RFAL_FWT_NONE); - platformLog("."); - platformDelay(50); - } - platformLog("\r\n Device removed.\r\n"); -} - - -/*! - ***************************************************************************** - * \brief Demo Blocking Transceive - * - * Helper function to send data in a blocking manner via the rfalNfc module - * - * \warning A protocol transceive handles long timeouts (several seconds), - * transmission errors and retransmissions which may lead to a long period of - * time where the MCU/CPU is blocked in this method. - * This is a demo implementation, for a non-blocking usage example please - * refer to the Examples available with RFAL - * - * \param[in] txBuf : data to be transmitted - * \param[in] txBufSize : size of the data to be transmited - * \param[out] rxData : location where the received data has been placed - * \param[out] rcvLen : number of data bytes received - * \param[in] fwt : FWT to be used (only for RF frame interface, - * otherwise use RFAL_FWT_NONE) - * - * - * \return ERR_PARAM : Invalid parameters - * \return ERR_TIMEOUT : Timeout error - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, activation successful - * - ***************************************************************************** - */ -ReturnCode demoTransceiveBlocking( uint8_t *txBuf, uint16_t txBufSize, uint8_t **rxData, uint16_t **rcvLen, uint32_t fwt ) -{ - ReturnCode err; - - err = rfalNfcDataExchangeStart( txBuf, txBufSize, rxData, rcvLen, fwt ); - if( err == ERR_NONE ) - { - do{ - rfalNfcWorker(); - err = rfalNfcDataExchangeGetStatus(); - } - while( err == ERR_BUSY ); - } - return err; -} - -static void demoNdef(rfalNfcDevice *pNfcDevice) -{ - ReturnCode err; - ndefMessage message; - uint32_t rawMessageLen; - ndefInfo info; - ndefBuffer bufRawMessage; - ndefConstBuffer bufConstRawMessage; - -#if NDEF_FEATURE_ALL - ndefRecord record1; - ndefRecord record2; - - ndefType text; - ndefType uri; - ndefType aar; - - ndefConstBuffer8 bufTextLangCode; - ndefConstBuffer bufTextLangText; - ndefConstBuffer bufUri; - ndefConstBuffer bufAndroidPackName; -#endif /* NDEF_FEATURE_ALL */ - - - /* - * Perform NDEF Context Initialization - */ - err = ndefPollerContextInitialization(&ndefCtx, pNfcDevice); - if( err != ERR_NONE ) - { - platformLog("NDEF NOT DETECTED (ndefPollerContextInitialization returns %d)\r\n", err); - return; - } - - if( verbose & (pNfcDevice->type == RFAL_NFC_LISTEN_TYPE_NFCV) ) - { - ndefDumpSysInfo(&ndefCtx); - } - - /* - * Perform NDEF Detect procedure - */ - err = ndefPollerNdefDetect(&ndefCtx, &info); - if( err != ERR_NONE ) - { - platformLog("NDEF NOT DETECTED (ndefPollerNdefDetect returns %d)\r\n", err); - if( ndefDemoFeature != NDEF_DEMO_FORMAT_TAG) - { - return; - } - } - else - { - platformLog("%s NDEF detected.\r\n", ndefStates[info.state]); - ndefCCDump(&ndefCtx); - - if( verbose ) - { - platformLog("NDEF Len: %d, Offset=%d\r\n", ndefCtx.messageLen, ndefCtx.messageOffset); - } - } - - switch( ndefDemoFeature ) - { - /* - * Demonstrate how to read the NDEF message from the Tag - */ - case NDEF_DEMO_READ: - if( info.state == NDEF_STATE_INITIALIZED ) - { - /* Nothing to read... */ - return; - } - err = ndefPollerReadRawMessage(&ndefCtx, rawMessageBuf, sizeof(rawMessageBuf), &rawMessageLen); - if( err != ERR_NONE ) - { - platformLog("NDEF message cannot be read (ndefPollerReadRawMessage returns %d)\r\n", err); - return; - } - if( verbose ) - { - bufRawMessage.buffer = rawMessageBuf; - bufRawMessage.length = rawMessageLen; - ndefBufferDump(" NDEF Content", (ndefConstBuffer*)&bufRawMessage, verbose); - } - bufConstRawMessage.buffer = rawMessageBuf; - bufConstRawMessage.length = rawMessageLen; - err = ndefMessageDecode(&bufConstRawMessage, &message); - if( err != ERR_NONE ) - { - platformLog("NDEF message cannot be decoded (ndefMessageDecode returns %d)\r\n", err); - return; - } - err = ndefMessageDump(&message, verbose); - if( err != ERR_NONE ) - { - platformLog("NDEF message cannot be displayed (ndefMessageDump returns %d)\r\n", err); - return; - } - break; - -#if NDEF_FEATURE_ALL - /* - * Demonstrate how to encode a text record and write the message to the tag - */ - case NDEF_DEMO_WRITE_MSG1: - ndefDemoFeature = NDEF_DEMO_READ; /* returns to READ mode after write */ - err = ndefMessageInit(&message); /* Initialize message structure */ - bufTextLangCode.buffer = ndefTextLangCode; - bufTextLangCode.length = strlen((char *)ndefTextLangCode); - - bufTextLangText.buffer = ndefTEXT; - bufTextLangText.length = strlen((char *)ndefTEXT); - - err |= ndefRtdText(&text, TEXT_ENCODING_UTF8, &bufTextLangCode, &bufTextLangText); /* Initialize Text type structure */ - err |= ndefRtdTextToRecord(&text, &record1); /* Encode Text Record */ - err |= ndefMessageAppend(&message, &record1); /* Append Text record to message */ - if( err != ERR_NONE ) - { - platformLog("Message creation failed\r\n", err); - return; - } - err = ndefPollerWriteMessage(&ndefCtx, &message); /* Write message */ - if( err != ERR_NONE ) - { - platformLog("Message cannot be written (ndefPollerWriteMessage return %d)\r\n", err); - return; - } - platformLog("Wrote 1 record to the Tag\r\n"); - if( verbose ) - { - /* Dump raw message */ - bufRawMessage.buffer = rawMessageBuf; - bufRawMessage.length = sizeof(rawMessageBuf); - err = ndefMessageEncode(&message, &bufRawMessage); - if( err == ERR_NONE ) - { - ndefBufferDump("Raw message", (ndefConstBuffer*)&bufRawMessage, verbose); - } - } - LedNotificationWriteDone(); - break; - - /* - * Demonstrate how to encode a URI record and a AAR record, how to encode the message to a raw buffer and then how to write the raw buffer - */ - case NDEF_DEMO_WRITE_MSG2: - ndefDemoFeature = NDEF_DEMO_READ; /* returns to READ mode after write */ - err = ndefMessageInit(&message); /* Initialize message structure */ - bufUri.buffer = ndefURI; - bufUri.length = strlen((char *)ndefURI); - err |= ndefRtdUri(&uri, NDEF_URI_PREFIX_HTTP_WWW, &bufUri); /* Initialize URI type structure */ - err |= ndefRtdUriToRecord(&uri, &record1); /* Encode URI Record */ - - bufAndroidPackName.buffer = ndefAndroidPackName; - bufAndroidPackName.length = sizeof(ndefAndroidPackName) - 1U; - err |= ndefRtdAar(&aar, &bufAndroidPackName); /* Initialize AAR type structure */ - err |= ndefRtdAarToRecord(&aar, &record2); /* Encode AAR record */ - - err |= ndefMessageAppend(&message, &record1); /* Append URI to message */ - err |= ndefMessageAppend(&message, &record2); /* Append AAR to message (record #2 is an example of preformatted record) */ - - bufRawMessage.buffer = rawMessageBuf; - bufRawMessage.length = sizeof(rawMessageBuf); - err |= ndefMessageEncode(&message, &bufRawMessage); /* Encode the message to the raw buffer */ - if( err != ERR_NONE ) - { - platformLog("Raw message creation failed\r\n", err); - return; - } - err = ndefPollerWriteRawMessage(&ndefCtx, bufRawMessage.buffer, bufRawMessage.length); - if( err != ERR_NONE ) - { - platformLog("Message cannot be written (ndefPollerWriteRawMessage return %d)\r\n", err); - return; - } - platformLog("Wrote 2 records to the Tag\r\n"); - if( verbose ) - { - /* Dump raw message */ - ndefBufferDump("Raw message", (ndefConstBuffer*)&bufRawMessage, verbose); - } - LedNotificationWriteDone(); - break; - - /* - * Demonstrate how to format a Tag - */ - case NDEF_DEMO_FORMAT_TAG: - ndefDemoFeature = NDEF_DEMO_READ; - if( !ndefIsSTTag(&ndefCtx) ) - { - platformLog("Manufacturer ID not found or not an ST tag. Format aborted \r\n"); - return; - } - platformLog("Formatting Tag...\r\n"); - /* Format Tag */ - err = ndefPollerTagFormat(&ndefCtx, NULL, 0); - if( err != ERR_NONE ) - { - platformLog("Tag cannot be formatted (ndefPollerTagFormat returns %d)\r\n", err); - return; - } - platformLog("Tag formatted\r\n"); - LedNotificationWriteDone(); - break; -#endif /* NDEF_FEATURE_ALL */ - - default: - ndefDemoFeature = NDEF_DEMO_READ; - break; - } - return; -} - -static void ndefT2TCCDump(ndefContext *ctx) -{ - ndefConstBuffer bufCcBuf; - - platformLog(" * Magic: %2.2Xh Version: %d.%d Size: %d (%d bytes) \r\n * readAccess: %2.2xh writeAccess: %2.2xh \r\n", ctx->cc.t2t.magicNumber, ctx->cc.t2t.majorVersion, ctx->cc.t2t.minorVersion, ctx->cc.t2t.size, ctx->cc.t2t.size * 8U, ctx->cc.t2t.readAccess, ctx->cc.t2t.writeAccess); - bufCcBuf.buffer = ctx->ccBuf; - bufCcBuf.length = 4; - ndefBufferDump(" CC Raw Data", &bufCcBuf, verbose); - -} - -static void ndefT3TAIBDump(ndefContext *ctx) -{ - ndefConstBuffer bufCcBuf; - - platformLog(" * Version: %d.%d Size: %d (%d bytes) NbR: %d NbW: %d\r\n * WriteFlag: %2.2xh RWFlag: %2.2xh \r\n", ctx->cc.t3t.majorVersion, ctx->cc.t3t.minorVersion, ctx->cc.t3t.nMaxB, ctx->cc.t3t.nMaxB * 16U, ctx->cc.t3t.nbR, ctx->cc.t3t.nbW, ctx->cc.t3t.writeFlag, ctx->cc.t3t.rwFlag); - bufCcBuf.buffer = ctx->ccBuf; - bufCcBuf.length = 16; - ndefBufferDump(" CC Raw Data", &bufCcBuf, verbose); -} - -static void ndefT4TCCDump(ndefContext *ctx) -{ - ndefConstBuffer bufCcBuf; - - platformLog(" * CCLEN: %d T4T_VNo: %xh MLe: %d MLc: %d FileId: %2.2x%2.2xh FileSize: %d\r\n * readAccess: %2.2xh writeAccess: %2.2xh\r\n", ctx->cc.t4t.ccLen, ctx->cc.t4t.vNo, ctx->cc.t4t.mLe, ctx->cc.t4t.mLc, ctx->cc.t4t.fileId[0], ctx->cc.t4t.fileId[1],ctx->cc.t4t.fileSize, ctx->cc.t4t.readAccess, ctx->cc.t4t.writeAccess); - bufCcBuf.buffer = ctx->ccBuf; - bufCcBuf.length = ctx->cc.t4t.ccLen; - ndefBufferDump(" CC File Raw Data", &bufCcBuf, verbose); -} - -static void ndefT5TCCDump(ndefContext *ctx) -{ - ndefConstBuffer bufCcBuf; - - platformLog(" * Block Length: %d\r\n", ctx->subCtx.t5t.blockLen); - platformLog(" * %d bytes CC\r\n * Magic: %2.2Xh Version: %d.%d MLEN: %d (%d bytes) \r\n * readAccess: %2.2xh writeAccess: %2.2xh \r\n", ctx->cc.t5t.ccLen, ctx->cc.t5t.magicNumber, ctx->cc.t5t.majorVersion, ctx->cc.t5t.minorVersion, ctx->cc.t5t.memoryLen, ctx->cc.t5t.memoryLen * 8U, ctx->cc.t5t.readAccess, ctx->cc.t5t.writeAccess); - platformLog(" * [%c] Special Frame\r\n", ctx->cc.t5t.specialFrame ? 'X' : ' '); - platformLog(" * [%c] Multiple block Read\r\n", ctx->cc.t5t.multipleBlockRead ? 'X' : ' '); - platformLog(" * [%c] Lock Block\r\n", ctx->cc.t5t.lockBlock ? 'X' : ' '); - bufCcBuf.buffer = ctx->ccBuf; - bufCcBuf.length = ctx->cc.t5t.ccLen; - ndefBufferDump(" CC Raw Data", &bufCcBuf, verbose); -} - -static void ndefCCDump(ndefContext *ctx) -{ - if( (ctx == NULL) || !verbose) - { - return; - } - platformLog("%s", (ctx->device.type == RFAL_NFC_LISTEN_TYPE_NFCF) ? "NDEF Attribute Information Block\r\n" : "NDEF Capability Container\r\n"); - switch( ctx->device.type ) - { - case RFAL_NFC_LISTEN_TYPE_NFCA: - switch( ctx->device.dev.nfca.type ) - { - case RFAL_NFCA_T2T: - ndefT2TCCDump(ctx); - break; - case RFAL_NFCA_T4T: - ndefT4TCCDump(ctx); - break; - default: - break; - } - break; - case RFAL_NFC_LISTEN_TYPE_NFCB: - ndefT4TCCDump(ctx); - break; - case RFAL_NFC_LISTEN_TYPE_NFCF: - ndefT3TAIBDump(ctx); - break; - case RFAL_NFC_LISTEN_TYPE_NFCV: - ndefT5TCCDump(ctx); - break; - default: - break; - } -} - -static void ndefDumpSysInfo(ndefContext *ctx) -{ - ndefSystemInformation *sysInfo; - - if( (ctx == NULL) || !verbose) - { - return; - } - - if( !ctx->subCtx.t5t.sysInfoSupported ) - { - return; - } - - sysInfo = &ctx->subCtx.t5t.sysInfo; - platformLog("System Information\r\n"); - platformLog(" * %d byte(s) memory addressing\r\n", ndefT5TSysInfoMOIValue(sysInfo->infoFlags) + 1); - if( ndefT5TSysInfoDFSIDPresent(sysInfo->infoFlags) ) - { - platformLog(" * DFSID=%2.2Xh\r\n", sysInfo->DFSID); - } - if( ndefT5TSysInfoAFIPresent(sysInfo->infoFlags) ) - { - platformLog(" * AFI=%2.2Xh\r\n", sysInfo->AFI); - } - if( ndefT5TSysInfoMemSizePresent(sysInfo->infoFlags) ) - { - platformLog(" * %d blocks, %d bytes per block\r\n", sysInfo->numberOfBlock, sysInfo->blockSize); - } - if( ndefT5TSysInfoICRefPresent(sysInfo->infoFlags) ) - { - platformLog(" * ICRef=%2.2xh\r\n", sysInfo->ICRef); - } - if( ndefT5TSysInfoCmdListPresent(sysInfo->infoFlags) ) - { - platformLog(" * [%c] ReadSingleBlock \r\n", ndefT5TSysInfoReadSingleBlockSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] WriteSingleBlock \r\n", ndefT5TSysInfoWriteSingleBlockSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] LockSingleBlock \r\n", ndefT5TSysInfoLockSingleBlockSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] ReadMultipleBlocks \r\n", ndefT5TSysInfoReadMultipleBlocksSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] WriteMultipleBlocks \r\n", ndefT5TSysInfoWriteMultipleBlocksSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] Select \r\n", ndefT5TSysInfoSelectSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] ResetToReady \r\n", ndefT5TSysInfoResetToReadySupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] GetMultipleBlockSecStatus \r\n", ndefT5TSysInfoGetMultipleBlockSecStatusSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] WriteAFI \r\n", ndefT5TSysInfoWriteAFISupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] LockAFI \r\n", ndefT5TSysInfoLockAFISupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] WriteDSFID \r\n", ndefT5TSysInfoWriteDSFIDSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] LockDSFID \r\n", ndefT5TSysInfoLockDSFIDSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] GetSystemInformation \r\n", ndefT5TSysInfoGetSystemInformationSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] CustomCmds \r\n", ndefT5TSysInfoCustomCmdsSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] FastReadMultipleBlocks \r\n", ndefT5TSysInfoFastReadMultipleBlocksSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] ExtReadSingleBlock \r\n", ndefT5TSysInfoExtReadSingleBlockSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] ExtWriteSingleBlock \r\n", ndefT5TSysInfoExtWriteSingleBlockSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] ExtLockSingleBlock \r\n", ndefT5TSysInfoExtLockSingleBlockSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] ExtReadMultipleBlocks \r\n", ndefT5TSysInfoExtReadMultipleBlocksSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] ExtWriteMultipleBlocks \r\n", ndefT5TSysInfoExtWriteMultipleBlocksSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] ExtGetMultipleBlockSecStatus \r\n", ndefT5TSysInfoExtGetMultipleBlockSecStatusSupported(sysInfo->supportedCmd) ? 'X' : ' '); - platformLog(" * [%c] FastExtendedReadMultipleBlocks \r\n", ndefT5TSysInfoFastExtendedReadMultipleBlocksSupported(sysInfo->supportedCmd) ? 'X' : ' '); - } - return; -} - -#if NDEF_FEATURE_ALL -static bool ndefIsSTTag(ndefContext *ctx) -{ - bool ret = false; - -#if defined(STM32L476xx) //FIXME: temporary code to enable format tag from any manufacturer - if( (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) != 0) - { - ret = true; - } -#endif - if( ctx == NULL ) - { - return ret; - } - switch (ctx->device.type) - { - case RFAL_NFC_LISTEN_TYPE_NFCA: - if( (ctx->device.dev.nfca.nfcId1Len != 4) && (ctx->device.dev.nfca.nfcId1[0] == 0x02 ) ) - { - ret = true; - } - break; - case RFAL_NFC_LISTEN_TYPE_NFCF: - break; - case RFAL_NFC_LISTEN_TYPE_NFCB: - break; - case RFAL_NFC_LISTEN_TYPE_NFCV: - if( ctx->device.dev.nfcv.InvRes.UID[6] == 0x02 ) - { - ret = true; - } - break; - default: - break; - } - return (ret); -} -#endif /* NDEF_FEATURE_ALL */ - -#if NDEF_FEATURE_ALL -static void LedNotificationWriteDone(void) -{ - uint32_t i; - - for (i = 0; i < 3; i++) - { - ledsOn(); - platformDelay(100); - - ledsOff(); - platformDelay(100); - } -} - -static void ledsOn(void) -{ - platformLedOn(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN); - platformLedOn(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - platformLedOn(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN); - platformLedOn(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN); - platformLedOn(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN); - platformLedOn(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN); -} - -static void ledsOff(void) -{ - platformLedOff(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN); - platformLedOff(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN); - platformLedOff(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN); - platformLedOff(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN); - platformLedOff(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN); - platformLedOff(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN); -} - -#endif /* NDEF_FEATURE_ALL */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Src/ndef_dump.c b/Software/Core/Src/ndef_dump.c deleted file mode 100644 index f14d90a..0000000 --- a/Software/Core/Src/ndef_dump.c +++ /dev/null @@ -1,721 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF message dump utils - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "platform.h" -#include "st_errno.h" -#include "utils.h" -#include "ndef_record.h" -#include "ndef_message.h" -#include "ndef_types_rtd.h" -#include "ndef_types_mime.h" -#include "ndef_dump.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -/*! Table to associate enums to pointer to function */ -typedef struct -{ - ndefTypeId typeId; /*!< NDEF type Id */ - ReturnCode (*dump)(const ndefType* type); /*!< Pointer to dump function */ -} ndefTypeDumpTable; - - -static const ndefTypeDumpTable typeDumpTable[] = -{ - { NDEF_TYPE_EMPTY, ndefEmptyTypeDump }, - { NDEF_TYPE_RTD_DEVICE_INFO, ndefRtdDeviceInfoDump }, - { NDEF_TYPE_RTD_TEXT, ndefRtdTextDump }, - { NDEF_TYPE_RTD_URI, ndefRtdUriDump }, - { NDEF_TYPE_RTD_AAR, ndefRtdAarDump }, - { NDEF_TYPE_MEDIA_VCARD, ndefMediaVCardDump }, - { NDEF_TYPE_MEDIA_WIFI, ndefMediaWifiDump }, -}; - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - -/*****************************************************************************/ -static bool isPrintableASCII(const uint8_t* str, uint32_t strLen) -{ - uint32_t i; - - if ((str == NULL) || (strLen == 0)) - { - return false; - } - - for (i = 0; i < strLen; i++) - { - if ((str[i] < 0x20) || (str[i] > 0x7E)) - { - return false; - } - } - - return true; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordDump(const ndefRecord* record, bool verbose) -{ - static uint32_t index; - const uint8_t *ndefTNFNames[] = - { - (uint8_t *)"Empty", - (uint8_t *)"NFC Forum well-known type [NFC RTD]", - (uint8_t *)"Media-type as defined in RFC 2046", - (uint8_t *)"Absolute URI as defined in RFC 3986", - (uint8_t *)"NFC Forum external type [NFC RTD]", - (uint8_t *)"Unknown", - (uint8_t *)"Unchanged", - (uint8_t *)"Reserved" - }; - uint8_t* headerSR = (uint8_t*)""; - ReturnCode err; - - if (record == NULL) - { - platformLog("No record\r\n"); - return ERR_NONE; - } - - if (ndefHeaderIsSetMB(record)) - { - index = 1U; - } - else - { - index++; - } - - if (verbose == true) - { - headerSR = (uint8_t*)(ndefHeaderIsSetSR(record) ? " - Short Record" : " - Standard Record"); - } - - platformLog("Record #%d%s\r\n", index, headerSR); - - /* Well-known type dump */ - err = ndefRecordDumpType(record); - if (verbose == true) - { - /* Raw dump */ - //platformLog(" MB:%d ME:%d CF:%d SR:%d IL:%d TNF:%d\r\n", ndefHeaderMB(record), ndefHeaderME(record), ndefHeaderCF(record), ndefHeaderSR(record), ndefHeaderIL(record), ndefHeaderTNF(record)); - platformLog(" MB ME CF SR IL TNF\r\n"); - platformLog(" %d %d %d %d %d %d\r\n", ndefHeaderMB(record), ndefHeaderME(record), ndefHeaderCF(record), ndefHeaderSR(record), ndefHeaderIL(record), ndefHeaderTNF(record)); - } - if ( (err != ERR_NONE) || (verbose == true) ) - { - platformLog(" Type Name Format: %s\r\n", ndefTNFNames[ndefHeaderTNF(record)]); - - uint8_t tnf; - ndefConstBuffer8 bufRecordType; - ndefRecordGetType(record, &tnf, &bufRecordType); - if ( (tnf == NDEF_TNF_EMPTY) && (bufRecordType.length == 0U) ) - { - platformLog(" Empty NDEF record\r\n"); - } - else - { - ndefBuffer8Print(" Type: \"", &bufRecordType, "\"\r\n"); - } - - if (ndefHeaderIsSetIL(record)) - { - /* ID Length bit set */ - ndefConstBuffer8 bufRecordId; - ndefRecordGetId(record, &bufRecordId); - ndefBuffer8Print(" ID: \"", &bufRecordId, "\"\r\n"); - } - - ndefConstBuffer bufRecordPayload; - ndefRecordGetPayload(record, &bufRecordPayload); - ndefBufferDump(" Payload:", &bufRecordPayload, verbose); - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefMessageDump(const ndefMessage* message, bool verbose) -{ - ReturnCode err; - ndefRecord* record; - - if (message == NULL) - { - platformLog("Empty NDEF message\r\n"); - return ERR_NONE; - } - else - { - platformLog("Decoding NDEF message\r\n"); - } - - record = ndefMessageGetFirstRecord(message); - - while (record != NULL) - { - err = ndefRecordDump(record, verbose); - if (err != ERR_NONE) - { - return err; - } - record = ndefMessageGetNextRecord(record); - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefEmptyTypeDump(const ndefType* empty) -{ - if (empty == NULL) - { - return ERR_PARAM; - } - - if (empty->id != NDEF_TYPE_EMPTY) - { - return ERR_PARAM; - } - - platformLog(" Empty record\r\n"); - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRtdDeviceInfoDump(const ndefType* devInfo) -{ - ndefTypeRtdDeviceInfo devInfoData; - uint32_t type; - uint32_t i; - - const uint8_t* ndefDeviceInfoName[] = - { - (uint8_t*)"Manufacturer", - (uint8_t*)"Model", - (uint8_t*)"Device", - (uint8_t*)"UUID", - (uint8_t*)"Firmware version", - }; - - if (devInfo == NULL) - { - return ERR_PARAM; - } - - if (devInfo->id != NDEF_TYPE_RTD_DEVICE_INFO) - { - return ERR_PARAM; - } - - ndefGetRtdDeviceInfo(devInfo, &devInfoData); - - platformLog(" Device Information:\r\n"); - - for (type = 0; type < NDEF_DEVICE_INFO_TYPE_COUNT; type++) - { - if (devInfoData.devInfo[type].buffer != NULL) - { - platformLog(" - %s: ", ndefDeviceInfoName[devInfoData.devInfo[type].type]); - - if (type != NDEF_DEVICE_INFO_UUID) - { - for (i = 0; i < devInfoData.devInfo[type].length; i++) - { - platformLog("%c", devInfoData.devInfo[type].buffer[i]); /* character */ - } - } - else - { - for (i = 0; i < devInfoData.devInfo[type].length; i++) - { - platformLog("%.2X", devInfoData.devInfo[type].buffer[i]); /* hex number */ - } - } - platformLog("\r\n"); - } - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRtdTextDump(const ndefType* text) -{ - uint8_t utfEncoding; - ndefConstBuffer8 bufLanguageCode; - ndefConstBuffer bufSentence; - - if (text == NULL) - { - return ERR_PARAM; - } - - if (text->id != NDEF_TYPE_RTD_TEXT) - { - return ERR_PARAM; - } - - ndefGetRtdText(text, &utfEncoding, &bufLanguageCode, &bufSentence); - - ndefBufferPrint(" Text: \"", &bufSentence, ""); - - platformLog("\" (%s,", utfEncoding == TEXT_ENCODING_UTF8 ? "UTF8" : "UTF16"); - - ndefBuffer8Print(" language code \"", &bufLanguageCode, "\")\r\n"); - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRtdUriDump(const ndefType* uri) -{ - ndefConstBuffer bufProtocol; - ndefConstBuffer bufUriString; - - if (uri == NULL) - { - return ERR_PARAM; - } - - if (uri->id != NDEF_TYPE_RTD_URI) - { - return ERR_PARAM; - } - - ndefGetRtdUri(uri, &bufProtocol, &bufUriString); - - ndefBufferPrint("URI: (", &bufProtocol, ")"); - ndefBufferPrint("", &bufUriString, "\r\n"); - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRtdAarDump(const ndefType* aar) -{ - ndefConstBuffer bufAarString; - - if (aar == NULL) - { - return ERR_PARAM; - } - - if (aar->id != NDEF_TYPE_RTD_AAR) - { - return ERR_PARAM; - } - - ndefGetRtdAar(aar, &bufAarString); - - ndefBufferPrint(" AAR Package: ", &bufAarString, "\r\n"); - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefMediaTypeDump(const ndefType* media) -{ - ndefConstBuffer8 bufType; - ndefConstBuffer bufPayload; - - if (media == NULL) - { - return ERR_PARAM; - } - - if (media->id != NDEF_TYPE_MEDIA) - { - return ERR_PARAM; - } - - ndefGetMedia(media, &bufType, &bufPayload); - - ndefBuffer8Print(" Media Type: ", &bufType, "\r\n"); - ndefBufferPrint(" Payload: ", &bufPayload, "\r\n"); - - return ERR_NONE; -} - - -/*****************************************************************************/ -static ReturnCode ndefMediaVCardTranslate(const ndefConstBuffer* bufText, ndefConstBuffer* bufTranslation) -{ - typedef struct { - uint8_t* vCardString; - uint8_t* english; - } ndefTranslate; - - const ndefTranslate translate[] = - { - { (uint8_t*)"N" , (uint8_t*)"Name" }, - { (uint8_t*)"FN" , (uint8_t*)"Formatted Name" }, - { (uint8_t*)"ADR" , (uint8_t*)"Address" }, - { (uint8_t*)"TEL" , (uint8_t*)"Phone" }, - { (uint8_t*)"EMAIL" , (uint8_t*)"Email" }, - { (uint8_t*)"TITLE" , (uint8_t*)"Title" }, - { (uint8_t*)"ORG" , (uint8_t*)"Org" }, - { (uint8_t*)"URL" , (uint8_t*)"URL" }, - { (uint8_t*)"PHOTO" , (uint8_t*)"Photo" }, - }; - - uint32_t i; - - if ( (bufText == NULL) || (bufTranslation == NULL) ) - { - return ERR_PROTO; - } - - for (i = 0; i < SIZEOF_ARRAY(translate); i++) - { - if (ST_BYTECMP(bufText->buffer, translate[i].vCardString, strlen((char*)translate[i].vCardString)) == 0) - { - bufTranslation->buffer = translate[i].english; - bufTranslation->length = strlen((char*)translate[i].english); - - return ERR_NONE; - } - } - - bufTranslation->buffer = bufText->buffer; - bufTranslation->length = bufText->length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefMediaVCardDump(const ndefType* vCard) -{ - ndefConstBuffer bufTypeN = { (uint8_t*)"N", strlen((char*)"N") }; - ndefConstBuffer bufTypeFN = { (uint8_t*)"FN", strlen((char*)"FN") }; - ndefConstBuffer bufTypeADR = { (uint8_t*)"ADR", strlen((char*)"ADR") }; - ndefConstBuffer bufTypeTEL = { (uint8_t*)"TEL", strlen((char*)"TEL") }; - ndefConstBuffer bufTypeEMAIL = { (uint8_t*)"EMAIL", strlen((char*)"EMAIL") }; - ndefConstBuffer bufTypeTITLE = { (uint8_t*)"TITLE", strlen((char*)"TITLE") }; - ndefConstBuffer bufTypeORG = { (uint8_t*)"ORG", strlen((char*)"ORG") }; - ndefConstBuffer bufTypeURL = { (uint8_t*)"URL", strlen((char*)"URL") }; - ndefConstBuffer bufTypePHOTO = { (uint8_t*)"PHOTO", strlen((char*)"PHOTO") }; - - const ndefConstBuffer* bufVCardField[] = { - &bufTypeN , - &bufTypeFN , - &bufTypeADR , - &bufTypeTEL , - &bufTypeEMAIL, - &bufTypeTITLE, - &bufTypeORG , - &bufTypeURL , - &bufTypePHOTO, - }; - - uint32_t i; - const ndefConstBuffer* bufType; - ndefConstBuffer bufSubType; - ndefConstBuffer bufValue; - - if (vCard == NULL) - { - return ERR_PARAM; - } - - if (vCard->id != NDEF_TYPE_MEDIA_VCARD) - { - return ERR_PARAM; - } - - platformLog(" vCard decoded: \r\n"); - - for (i = 0; i < SIZEOF_ARRAY(bufVCardField); i++) - { - /* Requesting vCard field */ - bufType = bufVCardField[i]; - - /* Get information from vCard */ - ndefGetVCard(vCard, bufType, &bufSubType, &bufValue); - - if (bufValue.buffer != NULL) - { - ndefConstBuffer bufTypeTranslate; - ndefMediaVCardTranslate(bufType, &bufTypeTranslate); - - /* Type */ - ndefBufferPrint(" ", &bufTypeTranslate, ""); - - /* Subtype, if any */ - if (bufSubType.buffer != NULL) - { - ndefBufferPrint(" (", &bufSubType, ")"); - } - - /* Value */ - if (ST_BYTECMP(bufType->buffer, bufTypePHOTO.buffer, bufTypePHOTO.length) != 0) - { - ndefBufferPrint(": ", &bufValue, "\r\n"); - } - else - { - platformLog("Photo: \r\n"); - } - } - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefMediaWifiDump(const ndefType* wifi) -{ - ndefTypeWifi wifiConfig; - - if (wifi == NULL) - { - return ERR_PARAM; - } - - if (wifi->id != NDEF_TYPE_MEDIA_WIFI) - { - return ERR_PARAM; - } - - ndefGetWifi(wifi, &wifiConfig); - - platformLog(" Wifi config: \r\n"); - ndefBufferDump(" Network SSID:", &wifiConfig.bufNetworkSSID, false); - ndefBufferDump(" Network Key:", &wifiConfig.bufNetworkKey, false); - platformLog(" Authentication: %d\r\n", wifiConfig.authentication); - platformLog(" Encryption: %d\r\n", wifiConfig.encryption); - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordDumpType(const ndefRecord* record) -{ - ReturnCode err; - ndefType type; - uint32_t i; - - err = ndefRecordToType(record, &type); - if (err != ERR_NONE) - { - return err; - } - - for (i = 0; i < SIZEOF_ARRAY(typeDumpTable); i++) - { - if (type.id == typeDumpTable[i].typeId) - { - /* Call the appropriate function to the matching record type */ - if (typeDumpTable[i].dump != NULL) - { - return typeDumpTable[i].dump(&type); - } - } - } - - return ERR_NOT_IMPLEMENTED; -} - - -/*****************************************************************************/ -static ReturnCode ndefBufferDumpLine(const uint8_t* buffer, const uint32_t offset, uint32_t lineLength, uint32_t remaining) -{ - uint32_t j; - - if (buffer == NULL) - { - return ERR_PARAM; - } - - platformLog(" [%.4X] ", offset); - - /* Dump hex data */ - for (j = 0; j < remaining; j++) - { - platformLog("%.2X ", buffer[offset + j]); - } - /* Fill hex section if needed */ - for (j = 0; j < lineLength - remaining; j++) - { - platformLog(" "); - } - - /* Dump characters */ - platformLog("|"); - for (j = 0; j < remaining; j++) - { - /* Dump only ASCII characters, otherwise replace with a '.' */ - platformLog("%2c", isPrintableASCII(&buffer[offset + j], 1) ? buffer[offset + j] : '.'); - } - /* Fill ASCII section if needed */ - for (j = 0; j < lineLength - remaining; j++) - { - platformLog(" "); - } - platformLog(" |\r\n"); - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefBufferDump(const char* string, const ndefConstBuffer* bufPayload, bool verbose) -{ - uint32_t bufferLengthMax = 32; - const uint32_t lineLength = 8; - uint32_t displayed; - uint32_t remaining; - uint32_t offset; - - if ( (string == NULL) || (bufPayload == NULL) ) - { - return ERR_PARAM; - } - - displayed = bufPayload->length; - remaining = bufPayload->length; - - platformLog("%s (length %d)\r\n", string, bufPayload->length); - if (bufPayload->buffer == NULL) - { - platformLog(" \r\n"); - return ERR_NONE; - } - - if (verbose == true) - { - bufferLengthMax = 256; - } - if (bufPayload->length > bufferLengthMax) - { - /* Truncate output */ - displayed = bufferLengthMax; - } - - for (offset = 0; offset < displayed; offset += lineLength) - { - ndefBufferDumpLine(bufPayload->buffer, offset, lineLength, remaining > lineLength ? lineLength : remaining); - remaining -= lineLength; - } - - if (displayed < bufPayload->length) - { - platformLog(" ... (truncated)\r\n"); - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefBufferPrint(const char* prefix, const ndefConstBuffer* bufString, const char* suffix) -{ - uint32_t i; - - if ( (prefix == NULL) || (bufString == NULL) || (bufString->buffer == NULL) || (suffix == NULL)) - { - return ERR_PARAM; - } - - platformLog("%s", prefix); - for (i = 0; i < bufString->length; i++) - { - platformLog("%c", bufString->buffer[i]); - } - platformLog("%s", suffix); - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefBuffer8Print(const char* prefix, const ndefConstBuffer8* bufString, const char* suffix) -{ - ndefConstBuffer buf; - - if (bufString == NULL) - { - return ERR_PARAM; - } - - buf.buffer = bufString->buffer; - buf.length = bufString->length; - - return ndefBufferPrint(prefix, &buf, suffix); -} diff --git a/Software/Core/Src/ndef_example_wrapper.c b/Software/Core/Src/ndef_example_wrapper.c deleted file mode 100644 index 50b3acd..0000000 --- a/Software/Core/Src/ndef_example_wrapper.c +++ /dev/null @@ -1,105 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/*! \file - * - * \author - * - * \brief Demo application - * - * This demo shows how to poll for several types of NFC cards/devices and how - * to exchange data with these devices, using the RFAL library. - * - * This demo does not fully implement the activities according to the standards, - * it performs the required to communicate with a card/device and retrieve - * its UID. Also blocking methods are used for data exchange which may lead to - * long periods of blocking CPU/MCU. - * For standard compliant example please refer to the Examples provided - * with the RFAL library. - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "demo.h" - -/*! NDEF read usage example */ -extern void ndefExampleRead(void); - -/*! NDEF write usage example */ -extern void ndefExampleWrite(void); - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ -static bool bWrite = false; - -/*! - ***************************************************************************** - * \brief Demo Ini - * - * \return true once initialized - * - * This function Initializes the required layers for the demo - ***************************************************************************** - */ -bool demoIni( void ) -{ - if( platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN)) - { - bWrite = !bWrite; - platformLog("Write: %s\r\n", bWrite ? "ON": "OFF"); - /* Debounce button */ - while( platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN) ); - } - return (true); -} - -/*! - ***************************************************************************** - * \brief Demo Cycle - * - * This function executes the demo state machine. - * It must be called periodically - ***************************************************************************** - */ -void demoCycle( void ) -{ - if( !bWrite ) - { - ndefExampleRead(); - } - else - { - ndefExampleWrite(); - } -} -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Src/spi.c b/Software/Core/Src/spi.c deleted file mode 100644 index 8792a1a..0000000 --- a/Software/Core/Src/spi.c +++ /dev/null @@ -1,96 +0,0 @@ -/** - ****************************************************************************** - * - * COPYRIGHT(c) 2016 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** -*/ - -/*! \file - * - * \author - * - * \brief SPI communication handling implementation. - * - */ - -/* Includes ------------------------------------------------------------------*/ - -#include "spi.h" -#include "st_errno.h" -#include "string.h" - -#define SPI_TIMEOUT 1000 -#define SPI_BUF_LEN 97 - - -static uint8_t txBuf[SPI_BUF_LEN]; -static uint8_t rxBuf[SPI_BUF_LEN]; - -SPI_HandleTypeDef *pSpi = 0; - - -void spiInit(SPI_HandleTypeDef *hspi) -{ - pSpi = hspi; - - /* enabling SPI block will put SCLK to output, guaranteeing proper state when spiSelect() gets called */ - __HAL_SPI_ENABLE(hspi); -} - -void spiSelect(GPIO_TypeDef *ssPort, uint16_t ssPin) -{ - HAL_GPIO_WritePin(ssPort, ssPin, GPIO_PIN_RESET); -} - -void spiDeselect(GPIO_TypeDef *ssPort, uint16_t ssPin) -{ - HAL_GPIO_WritePin(ssPort, ssPin, GPIO_PIN_SET); -} - -HAL_StatusTypeDef spiTxRx(const uint8_t *txData, uint8_t *rxData, uint16_t length) -{ - if(pSpi == 0) - return HAL_ERROR; - - if(length > SPI_BUF_LEN) - { - return HAL_ERROR; - } - - /* Initialize Tx data*/ - if(txData != NULL) - { - memcpy(txBuf, txData, length ); - } - else - { - memset(txBuf, 0x00, length ); - } - - return HAL_SPI_TransmitReceive(pSpi, txBuf, (rxData != NULL) ? rxData : rxBuf, length, SPI_TIMEOUT); -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Core/Src/syscalls.c b/Software/Core/Src/syscalls.c deleted file mode 100644 index fadb992..0000000 --- a/Software/Core/Src/syscalls.c +++ /dev/null @@ -1,155 +0,0 @@ -/** - ****************************************************************************** - * @file syscalls.c - * @author Auto-generated by STM32CubeIDE - * @brief STM32CubeIDE Minimal System calls file - * - * For more information about which c-functions - * need which of these lowlevel functions - * please consult the Newlib libc-manual - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Includes */ -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Variables */ -extern int __io_putchar(int ch) __attribute__((weak)); -extern int __io_getchar(void) __attribute__((weak)); - - -char *__env[1] = { 0 }; -char **environ = __env; - - -/* Functions */ -void initialise_monitor_handles() -{ -} - -int _getpid(void) -{ - return 1; -} - -int _kill(int pid, int sig) -{ - errno = EINVAL; - return -1; -} - -void _exit (int status) -{ - _kill(status, -1); - while (1) {} /* Make sure we hang here */ -} - -__attribute__((weak)) int _read(int file, char *ptr, int len) -{ - int DataIdx; - - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - *ptr++ = __io_getchar(); - } - -return len; -} - -__attribute__((weak)) int _write(int file, char *ptr, int len) -{ - int DataIdx; - - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - __io_putchar(*ptr++); - } - return len; -} - -int _close(int file) -{ - return -1; -} - - -int _fstat(int file, struct stat *st) -{ - st->st_mode = S_IFCHR; - return 0; -} - -int _isatty(int file) -{ - return 1; -} - -int _lseek(int file, int ptr, int dir) -{ - return 0; -} - -int _open(char *path, int flags, ...) -{ - /* Pretend like we always fail */ - return -1; -} - -int _wait(int *status) -{ - errno = ECHILD; - return -1; -} - -int _unlink(char *name) -{ - errno = ENOENT; - return -1; -} - -int _times(struct tms *buf) -{ - return -1; -} - -int _stat(char *file, struct stat *st) -{ - st->st_mode = S_IFCHR; - return 0; -} - -int _link(char *old, char *new) -{ - errno = EMLINK; - return -1; -} - -int _fork(void) -{ - errno = EAGAIN; - return -1; -} - -int _execve(char *name, char **argv, char **env) -{ - errno = ENOMEM; - return -1; -} diff --git a/Software/Core/Src/sysmem.c b/Software/Core/Src/sysmem.c deleted file mode 100644 index 54081ac..0000000 --- a/Software/Core/Src/sysmem.c +++ /dev/null @@ -1,79 +0,0 @@ -/** - ****************************************************************************** - * @file sysmem.c - * @author Generated by STM32CubeIDE - * @brief STM32CubeIDE System Memory calls file - * - * For more information about which C functions - * need which of these lowlevel functions - * please consult the newlib libc manual - ****************************************************************************** - * @attention - * - * Copyright (c) 2022 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ - -/* Includes */ -#include -#include - -/** - * Pointer to the current high watermark of the heap usage - */ -static uint8_t *__sbrk_heap_end = NULL; - -/** - * @brief _sbrk() allocates memory to the newlib heap and is used by malloc - * and others from the C library - * - * @verbatim - * ############################################################################ - * # .data # .bss # newlib heap # MSP stack # - * # # # # Reserved by _Min_Stack_Size # - * ############################################################################ - * ^-- RAM start ^-- _end _estack, RAM end --^ - * @endverbatim - * - * This implementation starts allocating at the '_end' linker symbol - * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack - * The implementation considers '_estack' linker symbol to be RAM end - * NOTE: If the MSP stack, at any point during execution, grows larger than the - * reserved size, please increase the '_Min_Stack_Size'. - * - * @param incr Memory size - * @return Pointer to allocated memory - */ -void *_sbrk(ptrdiff_t incr) -{ - extern uint8_t _end; /* Symbol defined in the linker script */ - extern uint8_t _estack; /* Symbol defined in the linker script */ - extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ - const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; - const uint8_t *max_heap = (uint8_t *)stack_limit; - uint8_t *prev_heap_end; - - /* Initialize heap end at first call */ - if (NULL == __sbrk_heap_end) - { - __sbrk_heap_end = &_end; - } - - /* Protect heap from growing into the reserved MSP stack */ - if (__sbrk_heap_end + incr > max_heap) - { - errno = ENOMEM; - return (void *)-1; - } - - prev_heap_end = __sbrk_heap_end; - __sbrk_heap_end += incr; - - return (void *)prev_heap_end; -} diff --git a/Software/Core/Src/usart.c b/Software/Core/Src/usart.c deleted file mode 100644 index 029d5d4..0000000 --- a/Software/Core/Src/usart.c +++ /dev/null @@ -1,109 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/*! \file - * - * \author - * - * \brief UART communication handling implementation. - * - */ - -/* Includes ------------------------------------------------------------------*/ - -#include "usart.h" -#include "st_errno.h" - -#define USART_TIMEOUT 1000 - -UART_HandleTypeDef *pUsart = 0; - -/** - * @brief This function initalize the UART handle. - * @param husart : already initalized handle to USART HW - * @retval none : - */ -void UsartInit(UART_HandleTypeDef *husart) -{ - pUsart = husart; -} - -/** - * @brief This function Transmit one data byte via USART - * @param data : data to be transmitted - * @retval ERR_INVALID_HANDLE : in case the SPI HW is not initalized yet - * @retval others : HAL status - */ -uint8_t UsartTxByte(uint8_t data) -{ - if(pUsart == 0) - return ERR_INVALID_HANDLE; - - return HAL_UART_Transmit(pUsart, &data, 1, USART_TIMEOUT); -} - -/** - * @brief This function Transmit data via USART - * @param data : data to be transmitted - * @param dataLen : length of data to be transmitted - * @retval ERR_INVALID_HANDLE : in case the SPI HW is not initalized yet - * @retval others : HAL status - */ -uint8_t UsartTx(uint8_t *data, uint16_t dataLen) -{ - if(pUsart == 0) - return ERR_INVALID_HANDLE; - - return HAL_UART_Transmit(pUsart, data, dataLen, USART_TIMEOUT); -} - -/** - * @brief This function Receive data via USART - * @param data : data where received data shall be stored - * @param dataLen : length of received data - * @retval ERR_INVALID_HANDLE : in case the SPI HW is not initalized yet - * @retval others : HAL status - */ -uint8_t UsartRx(uint8_t *data, uint16_t *dataLen) -{ - uint8_t err = ERR_NONE; - - if(pUsart == 0) - return ERR_INVALID_HANDLE; - - for(uint8_t i = 0; i < *dataLen; i++) { - err |= HAL_UART_Receive(pUsart, &data[i], 1, USART_TIMEOUT); - if(data[i] == 0) { - *dataLen = i; - } - } - return err; -} - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Drivers/BSP/Components/ST25R3911/Release_Notes.html b/Software/Drivers/BSP/Components/ST25R3911/Release_Notes.html deleted file mode 100644 index cefbfb6..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/Release_Notes.html +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - - - - - - Release Notes for ST25R3911 Driver - - - - - - - - - -
-


-

-
- - - - - - -
- - - - - - - - - -
-

Back to Release page

-
-

Release -Notes for ST25R3911 driver

-

Copyright -2017 STMicroelectronics

-

-
-

 

- - - - - - -
-

Update -History

- - -

V1.0.0 -/ 15-March-2017

-

Main -Changes

- - -
    -
  • First -official release.
  • -
- -

License
-

-
Redistribution -and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met:
-
-
    -
  1. Redistributions -of source code must retain the above copyright notice, this list of -conditions and the following disclaimer.
  2. -
  3. Redistributions -in binary form must reproduce the above copyright notice, this list of -conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution.
  4. -
  5. Neither the -name of STMicroelectronics nor the names of its contributors may be -used to endorse or promote products derived
    -
  6. -
-        -from this software without specific prior written permission.
-
- THIS -SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE.
-

- -
-
-

For -complete documentation on STM32 Microcontrollers -visit www.st.com/STM32

-
-

-
-
-

 

-
- - \ No newline at end of file diff --git a/Software/Drivers/BSP/Components/ST25R3911/st25r3911.c b/Software/Drivers/BSP/Components/ST25R3911/st25r3911.c deleted file mode 100644 index 366f9cd..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/st25r3911.c +++ /dev/null @@ -1,655 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R3911 firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Ulrich Herrmann - * - * \brief ST25R3911 high level interface - * - */ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ - -#include "st25r3911.h" -#include "st25r3911_com.h" -#include "st25r3911_interrupt.h" -#include "utils.h" - -/* -****************************************************************************** -* LOCAL DEFINES -****************************************************************************** -*/ - -#define ST25R3911_OSC_STABLE_TIMEOUT 10U /*!< Timeout for Oscillator to get stable, datasheet: 700us, take 5 ms */ -#define ST25R3911_CA_TIMEOUT 10U /*!< Timeout for Collision Avoidance command */ -#define ST25R3911_TOUT_CALIBRATE_CAP_SENSOR 4U /*!< Max duration Calibrate Capacitive Sensor command Datasheet: 3ms */ - -/* -****************************************************************************** -* LOCAL CONSTANTS -****************************************************************************** -*/ - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ -static uint32_t st25r3911NoResponseTime_64fcs; - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -static ReturnCode st25r3911ExecuteCommandAndGetResult(uint8_t cmd, uint8_t resreg, uint8_t sleeptime, uint8_t* result); - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - -void st25r3911TxRxOn( void ) -{ - st25r3911SetRegisterBits(ST25R3911_REG_OP_CONTROL, (ST25R3911_REG_OP_CONTROL_rx_en | ST25R3911_REG_OP_CONTROL_tx_en) ); -} - -void st25r3911TxRxOff( void ) -{ - st25r3911ClrRegisterBits(ST25R3911_REG_OP_CONTROL, (ST25R3911_REG_OP_CONTROL_rx_en | ST25R3911_REG_OP_CONTROL_tx_en) ); -} - - -void st25r3911OscOn( void ) -{ - /* Check if oscillator is already turned on and stable */ - /* Use ST25R3911_REG_OP_CONTROL_en instead of ST25R3911_REG_AUX_DISPLAY_osc_ok to be on the safe side */ - if( !st25r3911CheckReg( ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_en, ST25R3911_REG_OP_CONTROL_en ) ) - { - /* Clear any eventual previous oscillator IRQ */ - st25r3911GetInterrupt( ST25R3911_IRQ_MASK_OSC ); - - /* enable oscillator frequency stable interrupt */ - st25r3911EnableInterrupts(ST25R3911_IRQ_MASK_OSC); - - /* enable oscillator and regulator output */ - st25r3911ModifyRegister(ST25R3911_REG_OP_CONTROL, 0x00, ST25R3911_REG_OP_CONTROL_en); - - /* wait for the oscillator interrupt */ - st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_OSC, ST25R3911_OSC_STABLE_TIMEOUT); - st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_OSC); - } - -} - - -void st25r3911Initialize(void) -{ - uint16_t vdd_mV; - - /* first, reset the st25r3911 */ - st25r3911ExecuteCommand(ST25R3911_CMD_SET_DEFAULT); - - /* Set Operation Control Register to default value */ - st25r3911WriteRegister(ST25R3911_REG_OP_CONTROL, 0x00); - - /* enable pull downs on miso line */ - st25r3911ModifyRegister(ST25R3911_REG_IO_CONF2, 0, - ST25R3911_REG_IO_CONF2_miso_pd1 | - ST25R3911_REG_IO_CONF2_miso_pd2); - - /* after reset all interrupts are enabled. so disable them at first */ - st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_ALL); - /* and clear them, just to be sure... */ - st25r3911ClearInterrupts(); - - st25r3911OscOn(); - - /* Measure vdd and set sup3V bit accordingly */ - vdd_mV = st25r3911MeasureVoltage(ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd); - - st25r3911ModifyRegister(ST25R3911_REG_IO_CONF2, - ST25R3911_REG_IO_CONF2_sup3V, - (uint8_t)((vdd_mV < 3600U)?ST25R3911_REG_IO_CONF2_sup3V:0U)); - - /* Make sure Transmitter and Receiver are disabled */ - st25r3911TxRxOff(); - - return; -} - -void st25r3911Deinitialize(void) -{ - st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_ALL); - - /* Disabe Tx and Rx, Keep OSC */ - st25r3911TxRxOff(); - - return; -} - -ReturnCode st25r3911AdjustRegulators(uint16_t* result_mV) -{ - uint8_t result; - uint8_t io_conf2; - ReturnCode err = ERR_NONE; - - /* Reset logic and set regulated voltages to be defined by result of Adjust Regulators command */ - st25r3911SetRegisterBits( ST25R3911_REG_REGULATOR_CONTROL, ST25R3911_REG_REGULATOR_CONTROL_reg_s ); - st25r3911ClrRegisterBits( ST25R3911_REG_REGULATOR_CONTROL, ST25R3911_REG_REGULATOR_CONTROL_reg_s ); - - st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_ADJUST_REGULATORS, - ST25R3911_REG_REGULATOR_RESULT, - 5, - &result); - - st25r3911ReadRegister(ST25R3911_REG_IO_CONF2, &io_conf2); - - result >>= ST25R3911_REG_REGULATOR_RESULT_shift_reg; - result -= 5U; - if (result_mV != NULL) - { - if((io_conf2 & ST25R3911_REG_IO_CONF2_sup3V) != 0U) - { - *result_mV = 2400; - *result_mV += (uint16_t)result * 100U; - } - else - { - *result_mV = 3900; - *result_mV += (uint16_t)result * 120U; - } - } - return err; -} - -void st25r3911MeasureAmplitude(uint8_t* result) -{ - st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_AMPLITUDE, - ST25R3911_REG_AD_RESULT, - 10, - result); -} - -void st25r3911MeasurePhase(uint8_t* result) -{ - st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_PHASE, - ST25R3911_REG_AD_RESULT, - 10, - result); -} - -void st25r3911MeasureCapacitance(uint8_t* result) -{ - st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_CAPACITANCE, - ST25R3911_REG_AD_RESULT, - 10, - result); -} - -void st25r3911CalibrateAntenna(uint8_t* result) -{ - st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_CALIBRATE_ANTENNA, - ST25R3911_REG_ANT_CAL_RESULT, - 10, - result); -} - -void st25r3911CalibrateModulationDepth(uint8_t* result) -{ - st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_CALIBRATE_MODULATION, - ST25R3911_REG_AM_MOD_DEPTH_RESULT, - 10, - result); -} - - -ReturnCode st25r3911CalibrateCapacitiveSensor(uint8_t* result) -{ - ReturnCode ret; - uint8_t res; - - /* Clear Manual calibration values to enable automatic calibration mode */ - st25r3911ClrRegisterBits( ST25R3911_REG_CAP_SENSOR_CONTROL, ST25R3916_REG_CAP_SENSOR_CONTROL_mask_cs_mcal ); - - /* Execute automatic calibration */ - ret = st25r3911ExecuteCommandAndGetResult( ST25R3911_CMD_CALIBRATE_C_SENSOR, ST25R3911_REG_CAP_SENSOR_RESULT, ST25R3911_TOUT_CALIBRATE_CAP_SENSOR, &res ); - - /* Check wether the calibration was successull */ - if( ((res & ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_end) != ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_end) || - ((res & ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_err) == ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_err) || (ret != ERR_NONE) ) - { - return ERR_IO; - } - - if( result != NULL ) - { - (*result) = (uint8_t)(res >> ST25R3911_REG_CAP_SENSOR_CONTROL_shift_cs_mcal); - } - - return ERR_NONE; -} - - -ReturnCode st25r3911SetBitrate(uint8_t txRate, uint8_t rxRate) -{ - uint8_t reg; - - st25r3911ReadRegister(ST25R3911_REG_BIT_RATE, ®); - if (rxRate != ST25R3911_BR_DO_NOT_SET) - { - if(rxRate > ST25R3911_BR_3390) - { - return ERR_PARAM; - } - else - { - reg = (uint8_t)(reg & ~ST25R3911_REG_BIT_RATE_mask_rxrate); /* MISRA 10.3 */ - reg |= rxRate << ST25R3911_REG_BIT_RATE_shift_rxrate; - } - } - if (txRate != ST25R3911_BR_DO_NOT_SET) - { - if(txRate > ST25R3911_BR_6780) - { - return ERR_PARAM; - } - else - { - reg = (uint8_t)(reg & ~ST25R3911_REG_BIT_RATE_mask_txrate); /* MISRA 10.3 */ - reg |= txRate<> ST25R3911_REG_FIFO_RX_STATUS2_shift_fifo_lb); -} - -uint32_t st25r3911GetNoResponseTime_64fcs(void) -{ - return st25r3911NoResponseTime_64fcs; -} - -void st25r3911StartGPTimer_8fcs(uint16_t gpt_8fcs, uint8_t trigger_source) -{ - st25r3911SetGPTime_8fcs(gpt_8fcs); - - st25r3911ModifyRegister(ST25R3911_REG_GPT_CONTROL, - ST25R3911_REG_GPT_CONTROL_gptc_mask, - trigger_source); - if (trigger_source == 0U) - { - st25r3911ExecuteCommand(ST25R3911_CMD_START_GP_TIMER); - } - - return; -} - -void st25r3911SetGPTime_8fcs(uint16_t gpt_8fcs) -{ - st25r3911WriteRegister(ST25R3911_REG_GPT1, (uint8_t)(gpt_8fcs >> 8)); - st25r3911WriteRegister(ST25R3911_REG_GPT2, (uint8_t)(gpt_8fcs & 0xffU)); - - return; -} - -bool st25r3911CheckReg( uint8_t reg, uint8_t mask, uint8_t value ) -{ - uint8_t regVal; - - regVal = 0; - st25r3911ReadRegister( reg, ®Val ); - - return ((regVal & mask) == value ); -} - - -bool st25r3911CheckChipID( uint8_t *rev ) -{ - uint8_t ID; - - ID = 0; - st25r3911ReadRegister( ST25R3911_REG_IC_IDENTITY, &ID ); - - /* Check if IC Identity Register contains ST25R3911's IC type code */ - if( (ID & ST25R3911_REG_IC_IDENTITY_mask_ic_type) != ST25R3911_REG_IC_IDENTITY_ic_type ) - { - return false; - } - - if(rev != NULL) - { - *rev = (ID & ST25R3911_REG_IC_IDENTITY_mask_ic_rev); - } - - return true; -} - -ReturnCode st25r3911SetNoResponseTime_64fcs(uint32_t nrt_64fcs) -{ - ReturnCode err = ERR_NONE; - uint8_t nrt_step = 0; - uint32_t noResponseTime_64fcs = nrt_64fcs; /* MISRA 17.8: Use intermediate variable */ - - st25r3911NoResponseTime_64fcs = noResponseTime_64fcs; - if (noResponseTime_64fcs > (uint32_t)0xFFFFU) - { - nrt_step = ST25R3911_REG_GPT_CONTROL_nrt_step; - noResponseTime_64fcs = (noResponseTime_64fcs + 63U) / 64U; - if (noResponseTime_64fcs > (uint32_t)0xFFFFU) - { - noResponseTime_64fcs = 0xFFFFU; - err = ERR_PARAM; - } - st25r3911NoResponseTime_64fcs = 64U * noResponseTime_64fcs; - } - - st25r3911ModifyRegister(ST25R3911_REG_GPT_CONTROL, ST25R3911_REG_GPT_CONTROL_nrt_step, nrt_step); - st25r3911WriteRegister(ST25R3911_REG_NO_RESPONSE_TIMER1, (uint8_t)(noResponseTime_64fcs >> 8)); - st25r3911WriteRegister(ST25R3911_REG_NO_RESPONSE_TIMER2, (uint8_t)(noResponseTime_64fcs & 0xffU)); - - return err; -} - -ReturnCode st25r3911SetStartNoResponseTime_64fcs(uint32_t nrt_64fcs) -{ - ReturnCode err; - - err = st25r3911SetNoResponseTime_64fcs( nrt_64fcs ); - if(err == ERR_NONE) - { - st25r3911ExecuteCommand(ST25R3911_CMD_START_NO_RESPONSE_TIMER); - } - - return err; -} - -ReturnCode st25r3911PerformCollisionAvoidance( uint8_t FieldONCmd, uint8_t pdThreshold, uint8_t caThreshold, uint8_t nTRFW ) -{ - uint8_t treMask; - uint32_t irqs; - - if( (FieldONCmd != ST25R3911_CMD_INITIAL_RF_COLLISION) && - (FieldONCmd != ST25R3911_CMD_RESPONSE_RF_COLLISION_0) && - (FieldONCmd != ST25R3911_CMD_RESPONSE_RF_COLLISION_N) ) - { - return ERR_PARAM; - } - - /* Check if new thresholds are to be applied */ - if( (pdThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) || (caThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) ) - { - treMask = 0; - - if(pdThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) - { - treMask |= ST25R3911_REG_FIELD_THRESHOLD_mask_trg; - } - - if(caThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) - { - treMask |= ST25R3911_REG_FIELD_THRESHOLD_mask_rfe; - } - - /* Set Detection Threshold and|or Collision Avoidance Threshold */ - st25r3911ChangeRegisterBits( ST25R3911_REG_FIELD_THRESHOLD, treMask, (pdThreshold & ST25R3911_REG_FIELD_THRESHOLD_mask_trg) | (caThreshold & ST25R3911_REG_FIELD_THRESHOLD_mask_rfe ) ); - } - - /* Set n x TRFW */ - st25r3911ModifyRegister(ST25R3911_REG_AUX, ST25R3911_REG_AUX_mask_nfc_n, (nTRFW & ST25R3911_REG_AUX_mask_nfc_n) ); - - /* Enable and clear CA specific interrupts and execute command */ - st25r3911EnableInterrupts( (ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT) ); - st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT) ); - - st25r3911ExecuteCommand(FieldONCmd); - - irqs = st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT, ST25R3911_CA_TIMEOUT ); - - /* Clear any previous External Field events and disable CA specific interrupts */ - st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_EOF | ST25R3911_IRQ_MASK_EON) ); - st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT); - - - if((ST25R3911_IRQ_MASK_CAC & irqs) != 0U) /* Collision occurred */ - { - return ERR_RF_COLLISION; - } - - if((ST25R3911_IRQ_MASK_CAT & irqs) != 0U) /* No Collision detected, Field On */ - { - return ERR_NONE; - } - - /* No interrupt detected */ - return ERR_INTERNAL; -} - -ReturnCode st25r3911GetRegsDump(uint8_t* resRegDump, uint8_t* sizeRegDump) -{ - uint8_t regIt; - uint8_t regDump[ST25R3911_REG_IC_IDENTITY+1U]; - - if(!sizeRegDump || !resRegDump) - { - return ERR_PARAM; - } - - for( regIt = ST25R3911_REG_IO_CONF1; regIt < SIZEOF_ARRAY(regDump); regIt++ ) - { - st25r3911ReadRegister(regIt, ®Dump[regIt] ); - } - - *sizeRegDump = MIN(*sizeRegDump, regIt); - if( *sizeRegDump > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY(resRegDump, regDump, *sizeRegDump ); - } - - return ERR_NONE; -} - - -void st25r3911SetNumTxBits( uint32_t nBits ) -{ - st25r3911WriteRegister(ST25R3911_REG_NUM_TX_BYTES2, (uint8_t)((nBits >> 0) & 0xffU)); - st25r3911WriteRegister(ST25R3911_REG_NUM_TX_BYTES1, (uint8_t)((nBits >> 8) & 0xffU)); -} - - -bool st25r3911IsCmdValid( uint8_t cmd ) -{ - if( !((cmd >= ST25R3911_CMD_SET_DEFAULT) && (cmd <= ST25R3911_CMD_ANALOG_PRESET)) && - !((cmd >= ST25R3911_CMD_MASK_RECEIVE_DATA) && (cmd <= ST25R3911_CMD_CLEAR_RSSI)) && - !((cmd >= ST25R3911_CMD_TRANSPARENT_MODE) && (cmd <= ST25R3911_CMD_START_NO_RESPONSE_TIMER)) && - !((cmd >= ST25R3911_CMD_TEST_CLEARA) && (cmd <= ST25R3911_CMD_FUSE_PPROM)) ) - { - return false; - } - return true; -} - -ReturnCode st25r3911StreamConfigure(const struct st25r3911StreamConfig *config) -{ - uint8_t smd = 0; - uint8_t mode; - - if (config->useBPSK != 0U) - { - mode = ST25R3911_REG_MODE_om_bpsk_stream; - if ((config->din<2U) || (config->din>4U)) /* not in fc/4 .. fc/16 */ - { - return ERR_PARAM; - } - smd |= (4U - config->din) << ST25R3911_REG_STREAM_MODE_shift_scf; - - } - else - { - mode = ST25R3911_REG_MODE_om_subcarrier_stream; - if ((config->din<3U) || (config->din>6U)) /* not in fc/8 .. fc/64 */ - { - return ERR_PARAM; - } - smd |= (6U - config->din) << ST25R3911_REG_STREAM_MODE_shift_scf; - if (config->report_period_length == 0U) - { - return ERR_PARAM; - } - } - - if ((config->dout<1U) || (config->dout>7U)) /* not in fc/2 .. fc/128 */ - { - return ERR_PARAM; - } - smd |= (7U - config->dout) << ST25R3911_REG_STREAM_MODE_shift_stx; - - if (config->report_period_length > 3U) - { - return ERR_PARAM; - } - smd |= config->report_period_length << ST25R3911_REG_STREAM_MODE_shift_scp; - - st25r3911WriteRegister(ST25R3911_REG_STREAM_MODE, smd); - st25r3911ChangeRegisterBits(ST25R3911_REG_MODE, ST25R3911_REG_MODE_mask_om, mode); - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode st25r3911GetRSSI( uint16_t *amRssi, uint16_t *pmRssi ) -{ - /*******************************************************************************/ - /* MISRA 8.9 An object should be defined at block scope if its identifier only appears in a single function */ - /*< ST25R3911 RSSI Display Reg values:0 1 2 3 4 5 6 7 8 9 a b c d e f */ - const uint16_t st25r3911Rssi2mV[] = { 0 ,20 ,27 ,37 ,52 ,72 ,99 ,136 ,190 ,262 ,357 ,500 ,686 ,950, 0, 0 }; - - /* ST25R3911 2/3 stage gain reduction [dB] 0 0 0 0 0 3 6 9 12 15 18 na na na na na */ - const uint16_t st25r3911Gain2Percent[] = { 100, 100, 100, 100, 100, 141, 200, 281, 398, 562, 794, 1, 1, 1, 1, 1 }; - /*******************************************************************************/ - - uint8_t rssi; - uint8_t gainRed; - - st25r3911ReadRegister( ST25R3911_REG_RSSI_RESULT, &rssi ); - st25r3911ReadRegister( ST25R3911_REG_GAIN_RED_STATE, &gainRed ); - - if( amRssi != NULL ) - { - *amRssi = (uint16_t) ( ( (uint32_t)st25r3911Rssi2mV[ (rssi >> ST25R3911_REG_RSSI_RESULT_shift_rssi_am) ] * (uint32_t)st25r3911Gain2Percent[ (gainRed >> ST25R3911_REG_GAIN_RED_STATE_shift_gs_am) ] ) / 100U ); - } - - if( pmRssi != NULL ) - { - *pmRssi = (uint16_t) ( ( (uint32_t)st25r3911Rssi2mV[ (rssi & ST25R3911_REG_RSSI_RESULT_mask_rssi_pm) ] * (uint32_t)st25r3911Gain2Percent[ (gainRed & ST25R3911_REG_GAIN_RED_STATE_mask_gs_pm) ] ) / 100U ); - } - - return ERR_NONE; -} - -/* -****************************************************************************** -* LOCAL FUNCTIONS -****************************************************************************** -*/ -/*! - ***************************************************************************** - * \brief Executes a direct command and returns the result - * - * This function executes the direct command given by \a cmd waits for - * \a sleeptime for I_dct and returns the result read from register \a resreg. - * No checking of the validity of the cmd is performed. - * - * \param[in] cmd: direct command to execute. - * \param[in] resreg: Address of the register containing the result. - * \param[in] sleeptime: time in milliseconds to wait before reading the result. - * \param[out] result: 8 bit long result - * - ***************************************************************************** - */ -static ReturnCode st25r3911ExecuteCommandAndGetResult(uint8_t cmd, uint8_t resreg, uint8_t sleeptime, uint8_t* result) -{ - - st25r3911EnableInterrupts(ST25R3911_IRQ_MASK_DCT); - st25r3911GetInterrupt(ST25R3911_IRQ_MASK_DCT); - st25r3911ExecuteCommand(cmd); - st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_DCT, sleeptime); - st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_DCT); - - /* read out the result if the pointer is not NULL */ - if (result != NULL) - { - st25r3911ReadRegister(resreg, result); - } - - return ERR_NONE; -} diff --git a/Software/Drivers/BSP/Components/ST25R3911/st25r3911.h b/Software/Drivers/BSP/Components/ST25R3911/st25r3911.h deleted file mode 100644 index 3a81b34..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/st25r3911.h +++ /dev/null @@ -1,601 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R3911 firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Ulrich Herrmann - * - * \brief ST25R3911 declaration file - * - * API: - * - Initialize ST25R3911 driver: #st25r3911Initialize - * - Deinitialize ST25R3911 driver: #st25r3911Deinitialize - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-HAL - * \brief RFAL Hardware Abstraction Layer - * @{ - * - * \addtogroup ST25R3911 - * \brief RFAL ST25R3911 Driver - * @{ - * - * \addtogroup ST25R3911_Driver - * \brief RFAL ST25R3911 Driver - * @{ - * - */ - -#ifndef ST25R3911_H -#define ST25R3911_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" -#include "st_errno.h" - -/* -****************************************************************************** -* GLOBAL DATATYPES -****************************************************************************** -*/ - -/*! Parameters how the stream mode should work */ -struct st25r3911StreamConfig { - uint8_t useBPSK; /*!< 0: subcarrier, 1:BPSK */ - uint8_t din; /*!< the divider for the in subcarrier frequency: fc/2^din */ - uint8_t dout; /*!< the divider for the in subcarrier frequency fc/2^dout */ - uint8_t report_period_length; /*!< the length of the reporting period 2^report_period_length */ -}; - - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ -#define ST25R3911_FDT_NONE 0x00U /*!< Value indicating not to perform FDT */ - -#define MS_TO_64FCS(A) ((A) * 212U) /*!< Converts from ms to 64/fc steps */ -#define MS_FROM_64FCS(A) ((A) / 212U) /*!< Converts from 64/fc steps to ms */ - -/* ST25R3911 direct commands */ -#define ST25R3911_CMD_SET_DEFAULT 0xC1U /*!< Puts the chip in default state (same as after power-up) */ -#define ST25R3911_CMD_CLEAR_FIFO 0xC2U /*!< Stops all activities and clears FIFO */ -#define ST25R3911_CMD_TRANSMIT_WITH_CRC 0xC4U /*!< Transmit with CRC */ -#define ST25R3911_CMD_TRANSMIT_WITHOUT_CRC 0xC5U /*!< Transmit without CRC */ -#define ST25R3911_CMD_TRANSMIT_REQA 0xC6U /*!< Transmit REQA */ -#define ST25R3911_CMD_TRANSMIT_WUPA 0xC7U /*!< Transmit WUPA */ -#define ST25R3911_CMD_INITIAL_RF_COLLISION 0xC8U /*!< NFC transmit with Initial RF Collision Avoidance */ -#define ST25R3911_CMD_RESPONSE_RF_COLLISION_N 0xC9U /*!< NFC transmit with Response RF Collision Avoidance */ -#define ST25R3911_CMD_RESPONSE_RF_COLLISION_0 0xCAU /*!< NFC transmit with Response RF Collision Avoidance with n=0 */ -#define ST25R3911_CMD_NORMAL_NFC_MODE 0xCBU /*!< NFC switch to normal NFC mode */ -#define ST25R3911_CMD_ANALOG_PRESET 0xCCU /*!< Analog Preset */ -#define ST25R3911_CMD_MASK_RECEIVE_DATA 0xD0U /*!< Mask recive data */ -#define ST25R3911_CMD_UNMASK_RECEIVE_DATA 0xD1U /*!< Unmask recive data */ -#define ST25R3911_CMD_MEASURE_AMPLITUDE 0xD3U /*!< Measure singal amplitude on RFI inputs */ -#define ST25R3911_CMD_SQUELCH 0xD4U /*!< Squelch */ -#define ST25R3911_CMD_CLEAR_SQUELCH 0xD5U /*!< Clear Squelch */ -#define ST25R3911_CMD_ADJUST_REGULATORS 0xD6U /*!< Adjust regulators */ -#define ST25R3911_CMD_CALIBRATE_MODULATION 0xD7U /*!< Calibrate modulation depth */ -#define ST25R3911_CMD_CALIBRATE_ANTENNA 0xD8U /*!< Calibrate antenna */ -#define ST25R3911_CMD_MEASURE_PHASE 0xD9U /*!< Measure phase between RFO and RFI signal */ -#define ST25R3911_CMD_CLEAR_RSSI 0xDAU /*!< clear RSSI bits and restart the measurement */ -#define ST25R3911_CMD_TRANSPARENT_MODE 0xDCU /*!< Transparent mode */ -#define ST25R3911_CMD_CALIBRATE_C_SENSOR 0xDDU /*!< Calibrate the capacitive sensor */ -#define ST25R3911_CMD_MEASURE_CAPACITANCE 0xDEU /*!< Measure capacitance */ -#define ST25R3911_CMD_MEASURE_VDD 0xDFU /*!< Measure power supply voltage */ -#define ST25R3911_CMD_START_GP_TIMER 0xE0U /*!< Start the general purpose timer */ -#define ST25R3911_CMD_START_WUP_TIMER 0xE1U /*!< Start the wake-up timer */ -#define ST25R3911_CMD_START_MASK_RECEIVE_TIMER 0xE2U /*!< Start the mask-receive timer */ -#define ST25R3911_CMD_START_NO_RESPONSE_TIMER 0xE3U /*!< Start the no-repsonse timer */ -#define ST25R3911_CMD_TEST_CLEARA 0xFAU /*!< Clear Test register */ -#define ST25R3911_CMD_TEST_CLEARB 0xFBU /*!< Clear Test register */ -#define ST25R3911_CMD_TEST_ACCESS 0xFCU /*!< Enable R/W access to the test registers */ -#define ST25R3911_CMD_LOAD_PPROM 0xFDU /*!< Load data from the poly fuses to RAM */ -#define ST25R3911_CMD_FUSE_PPROM 0xFEU /*!< Fuse poly fuses with data from the RAM */ - - -#define ST25R3911_FIFO_DEPTH 96U /*!< Depth of FIFO */ - -#define ST25R3911_THRESHOLD_DO_NOT_SET 0xFFU /*!< Indicates not to change this Threshold */ - -#define ST25R3911_BR_DO_NOT_SET 0xFFU /*!< Indicates not to change this Bit Rate */ -#define ST25R3911_BR_106 0x00U /*!< ST25R3911 Bit Rate 106 kbit/s (fc/128) */ -#define ST25R3911_BR_212 0x01U /*!< ST25R3911 Bit Rate 212 kbit/s (fc/64) */ -#define ST25R3911_BR_424 0x02U /*!< ST25R3911 Bit Rate 424 kbit/s (fc/32) */ -#define ST25R3911_BR_848 0x03U /*!< ST25R3911 Bit Rate 848 kbit/s (fc/16) */ -#define ST25R3911_BR_1695 0x04U /*!< ST25R3911 Bit Rate 1696 kbit/s (fc/8) */ -#define ST25R3911_BR_3390 0x05U /*!< ST25R3911 Bit Rate 3390 kbit/s (fc/4) */ -#define ST25R3911_BR_6780 0x06U /*!< ST25R3911 Bit Rate 6780 kbit/s (fc/2) */ - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - -/*! Checks if General Purpose Timer is still running by reading gpt_on flag */ -#define st25r3911IsGPTRunning( ) ( st25r3911CheckReg(ST25R3911_REG_REGULATOR_RESULT, ST25R3911_REG_REGULATOR_RESULT_gpt_on, ST25R3911_REG_REGULATOR_RESULT_gpt_on) ) - -/*! Checks if CRC is configured to be in FIFO */ -#define st25r3911IsCRCinFIFO( ) ( st25r3911CheckReg(ST25R3911_REG_AUX, ST25R3911_REG_AUX_crc_2_fifo, ST25R3911_REG_AUX_crc_2_fifo) ) - -/*! Checks if External Filed is detected by reading ST25R3911 External Field - * Detector output */ -#define st25r3911IsExtFieldOn() ( st25r3911CheckReg(ST25R3911_REG_AUX_DISPLAY, ST25R3911_REG_AUX_DISPLAY_efd_o, ST25R3911_REG_AUX_DISPLAY_efd_o ) ) - -/*! Checks if Transmitter is enabled (Field On) */ -#define st25r3911IsTxEnabled() ( st25r3911CheckReg(ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_tx_en, ST25R3911_REG_OP_CONTROL_tx_en ) ) - -/*! Turn Off Tx (Field Off) */ -#define st25r3911TxOff() st25r3911ClrRegisterBits(ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_tx_en ); - -/*! Checks if last FIFO byte is complete */ -#define st25r3911IsLastFIFOComplete() st25r3911CheckReg( ST25R3911_REG_FIFO_RX_STATUS2, ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb, 0 ) - -/*! Checks if the Oscillator is enabled */ -#define st25r3911IsOscOn() st25r3911CheckReg( ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_en, ST25R3911_REG_OP_CONTROL_en ) - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief Turn on Oscillator and Regulator - * - * This function turn on oscillator and regulator and wait for the oscillator to - * become stable. - * - ***************************************************************************** - */ -extern void st25r3911OscOn( void ); - -/*! - ***************************************************************************** - * \brief Turn On Tx and Rx - * - * This function turns On Tx and Rx (Field On) - * - ***************************************************************************** - */ -extern void st25r3911TxRxOn( void ); - -/*! - ***************************************************************************** - * \brief Turn Off Tx and Rx - * - * This function turns Off Tx and Rx (Field Off) - * - ***************************************************************************** - */ -extern void st25r3911TxRxOff( void ); - -/*! - ***************************************************************************** - * \brief Initialise ST25R3911 driver - * - * This function initialises the ST25R3911 driver. - * - ***************************************************************************** - */ -extern void st25r3911Initialize( void ); - -/*! - ***************************************************************************** - * \brief Deinitialize ST25R3911 driver - * - * Calling this function deinitializes the ST25R3911 driver. - * - ***************************************************************************** - */ -extern void st25r3911Deinitialize( void ); - - -/*! - ***************************************************************************** - * \brief Sets the bitrate registers - * - * This function sets the bitrate register for rx and tx - * - * \param txRate : speed is 2^txrate * 106 kb/s - * 0xff : don't set txrate - * \param rxRate : speed is 2^rxrate * 106 kb/s - * 0xff : don't set rxrate - * - * \return ERR_NONE : No error, both bit rates were set - * \return ERR_PARAM: At least one bit rate was invalid - * - ***************************************************************************** - */ -extern ReturnCode st25r3911SetBitrate( uint8_t txRate, uint8_t rxRate ); - -/*! - ***************************************************************************** - * \brief Adjusts supply regulators according to the current supply voltage - * - * On this function the power level is measured in maximum load conditions and - * the regulated voltage reference is set to 250mV below this level. - * Execution of this function lasts arround 5ms. - * - * The regulated voltages will be set to the result of Adjust Regulators - * - * \param [out] result_mV : Result of calibration in milliVolts. - * - * \return ERR_IO : Error during communication with ST25R3911. - * \return ERR_NONE : No error. - * - ***************************************************************************** - */ -extern ReturnCode st25r3911AdjustRegulators( uint16_t* result_mV ); - -/*! - ***************************************************************************** - * \brief Measure Amplitude - * - * This function measured the amplitude on the RFI inputs and stores the - * result in parameter \a result. - * - * \param[out] result: 8 bit long result of RF measurement. - * - ***************************************************************************** - */ -extern void st25r3911MeasureAmplitude( uint8_t* result ); - -/*! - ***************************************************************************** - * \brief Measure Capacitance - * - * This function performs the capacitance measurement and stores the - * result in parameter \a result. - * - * \param[out] result: 8 bit long result of RF measurement. - * - ***************************************************************************** - */ -extern void st25r3911MeasureCapacitance( uint8_t* result ); - -/*! - ***************************************************************************** - * \brief Measure Voltage - * - * This function measures the voltage on one of VDD and VSP_* - * result in parameter \a result. - * - * \param[in] mpsv : one of ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd - * ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_rf - * ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_a - * or ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_d - * - * \return the measured voltage raw values - * - ***************************************************************************** - */ -extern uint8_t st25r3911MeasurePowerSupply( uint8_t mpsv ); - -/*! - ***************************************************************************** - * \brief Measure Voltage - * - * This function measures the voltage on one of VDD and VSP_* - * result in parameter \a result. - * - * \param[in] mpsv : one of ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd - * ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_rf - * ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_a - * or ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_d - * - * \return the measured voltage in mV - * - ***************************************************************************** - */ -extern uint16_t st25r3911MeasureVoltage( uint8_t mpsv ); - -/*! - ***************************************************************************** - * \brief Calibrate antenna - * - * This function is used to calibrate the antenna using a special sequence. - * The result is stored in the \a result parameter. - * - * \param[out] result: 8 bit long result of antenna calibration algorithm. - * - ***************************************************************************** - */ -extern void st25r3911CalibrateAntenna( uint8_t* result ); - -/*! - ***************************************************************************** - * \brief Measure Phase - * - * This function performs a Phase measurement. - * The result is stored in the \a result parameter. - * - * \param[out] result: 8 bit long result of the measurement. - * - ***************************************************************************** - */ -extern void st25r3911MeasurePhase( uint8_t* result ); - -/*! - ***************************************************************************** - * \brief Calibrate modulation depth - * - * This function is used to calibrate the modulation depth using a special sequence. - * The result is stored in the \a result parameter. - * - * \param[out] result: 8 bit long result of antenna calibration algorithm. - * - ***************************************************************************** - */ -extern void st25r3911CalibrateModulationDepth( uint8_t* result ); - - -/*! - ***************************************************************************** - * \brief Calibrate Capacitive Sensor - * - * This function performs automatic calibration of the capacitive sensor - * and stores the result in parameter \a result. - * - * \warning To avoid interference with Xtal oscillator and reader magnetic - * field, it is strongly recommended to perform calibration - * in Power-down mode only. - * This method does not modify the Oscillator nor transmitter state, - * these should be configured before by user. - * - * \param[out] result: 5 bit long result of the calibration. - * Binary weighted, step 0.1 pF, max 3.1 pF - * - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_IO : The calibration was not successful - * \return ERR_NONE : No error - * - ***************************************************************************** - */ -extern ReturnCode st25r3911CalibrateCapacitiveSensor( uint8_t* result ); - -/*! - ***************************************************************************** - * \brief set no response time - * - * This function executes sets the no response time to the defines value - * - * \param nrt_64fcs : no response time in 64/fc = 4.72us - * completion interrupt - * - * \return ERR_PARAM : if time is too large - */ -extern ReturnCode st25r3911SetNoResponseTime_64fcs( uint32_t nrt_64fcs ); - -/*! - ***************************************************************************** - * \brief set no response time - * - * This function executes sets and immediately start the no response timer - * to the defines value - * This is used when needs to add more time before timeout whitout Tx - * - * \param nrt_64fcs : no response time in 64/fc = 4.72us - * completion interrupt - * - * \return ERR_PARAM : if time is too large - */ -extern ReturnCode st25r3911SetStartNoResponseTime_64fcs( uint32_t nrt_64fcs ); - -/*! - ***************************************************************************** - * \brief Perform Collision Avoidance - * - * Performs Collision Avoidance with the given threshold and with the - * n number of TRFW - * - * \param[in] FieldONCmd : Field ON command to be executed ST25R3911_CMD_INITIAL_RF_COLLISION - * or ST25R3911_CMD_RESPONSE_RF_COLLISION_0/N - * \param[in] pdThreshold : Peer Detection Threshold (ST25R3916_REG_FIELD_THRESHOLD_trg_xx) - * 0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET) - * \param[in] caThreshold : Collision Avoidance Threshold (ST25R3916_REG_FIELD_THRESHOLD_rfe_xx) - * 0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET) - * \param[in] nTRFW : Number of TRFW - * - * \return ERR_NONE : no collision detected - * \return ERR_RF_COLLISION : collision detected - */ -extern ReturnCode st25r3911PerformCollisionAvoidance( uint8_t FieldONCmd, uint8_t pdThreshold, uint8_t caThreshold, uint8_t nTRFW ); - - -/*! - ***************************************************************************** - * \brief Get amount of bits of the last FIFO byte if incomplete - * - * Gets the number of bits of the last FIFO byte if incomplete - * - * \return the number of bits of the last FIFO byte if incomplete, 0 if - * the last byte is complete - * - ***************************************************************************** - */ -extern uint8_t st25r3911GetNumFIFOLastBits( void ); - -/*! - ***************************************************************************** - * \brief Get NRT time - * - * This returns the last value set on the NRT - * - * \warning it does not reads chip register, just the sw var that contains the - * last value set before - * - * \return the value of the NRT - */ -extern uint32_t st25r3911GetNoResponseTime_64fcs( void ); - -/*! - ***************************************************************************** - * \brief set general purpose timer timeout - * - * This function sets the proper registers but does not start the timer actually - * - * \param gpt_8fcs : general purpose timer timeout in 8/fc = 590ns - * - */ -extern void st25r3911SetGPTime_8fcs( uint16_t gpt_8fcs ); -/*! - ***************************************************************************** - * \brief Starts GPT with given timeout - * - * This function starts the general purpose timer with the given timeout - * - * \param gpt_8fcs : general purpose timer timeout in 8/fc = 590ns - * \param trigger_source : no trigger, start of Rx, end of Rx, end of Tx in NFC mode - */ -extern void st25r3911StartGPTimer_8fcs( uint16_t gpt_8fcs, uint8_t trigger_source ); - -/*! - ***************************************************************************** - * \brief Checks if register contains a expected value - * - * This function checks if the given reg contains a value that once masked - * equals the expected value - * - * \param reg : the register to check the value - * \param mask : the mask apply on register value - * \param value : expected value to be compared to - * - * \return true when reg contains the expected value | false otherwise - */ -bool st25r3911CheckReg( uint8_t reg, uint8_t mask, uint8_t value ); - -/*! - ***************************************************************************** - * \brief Sets the number Tx Bits - * - * Sets ST25R3911 internal registers with correct number of complete bytes and - * bits to be sent - * - * \param nBits : the number bits to be transmitted - ***************************************************************************** - */ -void st25r3911SetNumTxBits( uint32_t nBits ); - -/*! - ***************************************************************************** - * \brief Check Identity - * - * Checks if the chip ID is as expected. - * - * 5 bit IC type code for ST25R3911: 00001 - * The 3 lsb contain the IC revision code - * - * - * \param[out] rev : the IC revision code - * - * \return true when IC type is as expected - * - ***************************************************************************** - */ -bool st25r3911CheckChipID( uint8_t *rev ); - -/*! - ***************************************************************************** - * \brief Check if command is valid - * - * Checks if the given command is a valid ST25R3911 command - * - * \param[in] cmd: Command to check - * - * \return true if is a valid command - * \return false otherwise - * - ***************************************************************************** - */ -bool st25r3911IsCmdValid( uint8_t cmd ); - -/*! - ***************************************************************************** - * \brief Configure the stream mode of ST25R3911 - * - * This function initializes the stream with the given parameters - * - * \param[in] config : all settings for bitrates, type, etc. - - * \return ERR_NONE : No error, stream mode driver initialized. - * - ***************************************************************************** - */ -extern ReturnCode st25r3911StreamConfigure( const struct st25r3911StreamConfig *config ); - -/*! - ***************************************************************************** - * \brief Retrieves all internal registers from st25r3911 - */ -extern ReturnCode st25r3911GetRegsDump( uint8_t* resRegDump, uint8_t* sizeRegDump ); - - -/*! - ***************************************************************************** - * \brief Gets the RSSI values - * - * This function gets the RSSI value of the previous reception taking into - * account the gain reductions that were used. - * RSSI value for both AM and PM channel can be retrieved. - * - * \param[out] amRssi: the RSSI on the AM channel expressed in mV - * \param[out] pmRssi: the RSSI on the PM channel expressed in mV - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : No error - * - ***************************************************************************** - */ -ReturnCode st25r3911GetRSSI( uint16_t *amRssi, uint16_t *pmRssi ); - - -#endif /* ST25R3911_H */ - -/** - * @} - * - * @} - * - * @} - * - * @} - */ - diff --git a/Software/Drivers/BSP/Components/ST25R3911/st25r3911_com.c b/Software/Drivers/BSP/Components/ST25R3911/st25r3911_com.c deleted file mode 100644 index 30a5ddd..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/st25r3911_com.c +++ /dev/null @@ -1,457 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R3911 firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Ulrich Herrmann - * - * \brief Implementation of ST25R3911 communication. - * - */ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "st25r3911_com.h" -#include "st25r3911.h" -#include "utils.h" - - -/* -****************************************************************************** -* LOCAL DEFINES -****************************************************************************** -*/ - -#define ST25R3911_WRITE_MODE (0U) /*!< ST25R3911 SPI Operation Mode: Write */ -#define ST25R3911_READ_MODE (1U << 6) /*!< ST25R3911 SPI Operation Mode: Read */ -#define ST25R3911_FIFO_LOAD (2U << 6) /*!< ST25R3911 SPI Operation Mode: FIFO Load */ -#define ST25R3911_FIFO_READ (0xBFU) /*!< ST25R3911 SPI Operation Mode: FIFO Read */ -#define ST25R3911_CMD_MODE (3U << 6) /*!< ST25R3911 SPI Operation Mode: Direct Command */ - -#define ST25R3911_CMD_LEN (1U) /*!< ST25R3911 CMD length */ -#define ST25R3911_BUF_LEN (ST25R3911_CMD_LEN+ST25R3911_FIFO_DEPTH) /*!< ST25R3911 communication buffer: CMD + FIFO length */ - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ - -#ifdef ST25R391X_COM_SINGLETXRX -static uint8_t comBuf[ST25R3911_BUF_LEN]; /*!< ST25R3911 communication buffer */ -#endif /* ST25R391X_COM_SINGLETXRX */ - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -static inline void st25r3911CheckFieldSetLED(uint8_t value) -{ - if ((ST25R3911_REG_OP_CONTROL_tx_en & value) != 0U) - { -#ifdef PLATFORM_LED_FIELD_PIN - platformLedOn( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN ); - } - else - { - platformLedOff( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN ); -#endif /* PLATFORM_LED_FIELD_PIN */ - } -} - - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ -void st25r3911ReadRegister(uint8_t reg, uint8_t* value) -{ -#ifdef ST25R391X_COM_SINGLETXRX - uint8_t* buf = comBuf; -#else /* ST25R391X_COM_SINGLETXRX */ - uint8_t buf[2]; -#endif /* ST25R391X_COM_SINGLETXRX */ - - platformProtectST25R391xComm(); - platformSpiSelect(); - - buf[0] = (reg | ST25R3911_READ_MODE); - buf[1] = 0; - - platformSpiTxRx(buf, buf, 2); - - if(value != NULL) - { - *value = buf[1]; - } - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - - return; -} - - -void st25r3911ReadMultipleRegisters(uint8_t reg, uint8_t* values, uint8_t length) -{ -#if !defined(ST25R391X_COM_SINGLETXRX) - uint8_t cmd = (reg | ST25R3911_READ_MODE); -#endif /* !ST25R391X_COM_SINGLETXRX */ - - if (length > 0U) - { - platformProtectST25R391xComm(); - platformSpiSelect(); - -#ifdef ST25R391X_COM_SINGLETXRX - - ST_MEMSET( comBuf, 0x00, MIN( (ST25R3911_CMD_LEN + (uint32_t)length), ST25R3911_BUF_LEN ) ); - comBuf[0] = (reg | ST25R3911_READ_MODE); - - platformSpiTxRx(comBuf, comBuf, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) ); /* Transceive as a single SPI call */ - ST_MEMCPY( values, &comBuf[ST25R3911_CMD_LEN], MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) ); /* Copy from local buf to output buffer and skip cmd byte */ - -#else /* ST25R391X_COM_SINGLETXRX */ - - /* Since the result comes one byte later, let's first transmit the adddress with discarding the result */ - platformSpiTxRx(&cmd, NULL, ST25R3911_CMD_LEN); - platformSpiTxRx(NULL, values, length); - -#endif /* ST25R391X_COM_SINGLETXRX */ - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - } - - return; -} - -void st25r3911ReadTestRegister(uint8_t reg, uint8_t* value) -{ - -#ifdef ST25R391X_COM_SINGLETXRX - uint8_t* buf = comBuf; -#else /* ST25R391X_COM_SINGLETXRX */ - uint8_t buf[3]; -#endif /* ST25R391X_COM_SINGLETXRX */ - - platformProtectST25R391xComm(); - platformSpiSelect(); - - buf[0] = ST25R3911_CMD_TEST_ACCESS; - buf[1] = (reg | ST25R3911_READ_MODE); - buf[2] = 0x00; - - platformSpiTxRx(buf, buf, 3); - - if(value != NULL) - { - *value = buf[2]; - } - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - - return; -} - -void st25r3911WriteTestRegister(uint8_t reg, uint8_t value) -{ -#ifdef ST25R391X_COM_SINGLETXRX - uint8_t* buf = comBuf; -#else /* ST25R391X_COM_SINGLETXRX */ - uint8_t buf[3]; -#endif /* ST25R391X_COM_SINGLETXRX */ - - platformProtectST25R391xComm(); - platformSpiSelect(); - - buf[0] = ST25R3911_CMD_TEST_ACCESS; - buf[1] = (reg | ST25R3911_WRITE_MODE); - buf[2] = value; - - platformSpiTxRx(buf, NULL, 3); - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - - return; -} - -void st25r3911WriteRegister(uint8_t reg, uint8_t value) -{ -#ifdef ST25R391X_COM_SINGLETXRX - uint8_t* buf = comBuf; -#else /* ST25R391X_COM_SINGLETXRX */ - uint8_t buf[2]; -#endif /* ST25R391X_COM_SINGLETXRX */ - - if (ST25R3911_REG_OP_CONTROL == reg) - { - st25r3911CheckFieldSetLED(value); - } - - platformProtectST25R391xComm(); - platformSpiSelect(); - - buf[0] = reg | ST25R3911_WRITE_MODE; - buf[1] = value; - - platformSpiTxRx(buf, NULL, 2); - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - - return; -} - -void st25r3911ClrRegisterBits( uint8_t reg, uint8_t clr_mask ) -{ - uint8_t tmp; - - st25r3911ReadRegister(reg, &tmp); - tmp &= ~clr_mask; - st25r3911WriteRegister(reg, tmp); - - return; -} - - -void st25r3911SetRegisterBits( uint8_t reg, uint8_t set_mask ) -{ - uint8_t tmp; - - st25r3911ReadRegister(reg, &tmp); - tmp |= set_mask; - st25r3911WriteRegister(reg, tmp); - - return; -} - -void st25r3911ChangeRegisterBits(uint8_t reg, uint8_t valueMask, uint8_t value) -{ - st25r3911ModifyRegister(reg, valueMask, (valueMask & value) ); -} - -void st25r3911ModifyRegister(uint8_t reg, uint8_t clr_mask, uint8_t set_mask) -{ - uint8_t tmp; - - st25r3911ReadRegister(reg, &tmp); - - /* mask out the bits we don't want to change */ - tmp &= ~clr_mask; - /* set the new value */ - tmp |= set_mask; - st25r3911WriteRegister(reg, tmp); - - return; -} - -void st25r3911ChangeTestRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value ) -{ - uint8_t rdVal; - uint8_t wrVal; - - /* Read current reg value */ - st25r3911ReadTestRegister(reg, &rdVal); - - /* Compute new value */ - wrVal = (rdVal & ~valueMask); - wrVal |= (value & valueMask); - - /* Write new reg value */ - st25r3911WriteTestRegister(reg, wrVal ); - - return; -} - -void st25r3911WriteMultipleRegisters(uint8_t reg, const uint8_t* values, uint8_t length) -{ -#if !defined(ST25R391X_COM_SINGLETXRX) - uint8_t cmd = (reg | ST25R3911_WRITE_MODE); -#endif /* !ST25R391X_COM_SINGLETXRX */ - - if ((reg <= ST25R3911_REG_OP_CONTROL) && ((reg+length) >= ST25R3911_REG_OP_CONTROL)) - { - st25r3911CheckFieldSetLED(values[ST25R3911_REG_OP_CONTROL-reg]); - } - - if (length > 0U) - { - /* make this operation atomic */ - platformProtectST25R391xComm(); - platformSpiSelect(); - -#ifdef ST25R391X_COM_SINGLETXRX - - comBuf[0] = (reg | ST25R3911_WRITE_MODE); - ST_MEMCPY( &comBuf[ST25R3911_CMD_LEN], values, MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) ); - - platformSpiTxRx( comBuf, NULL, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) ); - -#else /*ST25R391X_COM_SINGLETXRX*/ - - platformSpiTxRx( &cmd, NULL, ST25R3911_CMD_LEN ); - platformSpiTxRx( values, NULL, length ); - -#endif /*ST25R391X_COM_SINGLETXRX*/ - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - } - - return; -} - - -void st25r3911WriteFifo(const uint8_t* values, uint8_t length) -{ -#if !defined(ST25R391X_COM_SINGLETXRX) - uint8_t cmd = ST25R3911_FIFO_LOAD; -#endif /* !ST25R391X_COM_SINGLETXRX */ - - if (length > 0U) - { - platformProtectST25R391xComm(); - platformSpiSelect(); - -#ifdef ST25R391X_COM_SINGLETXRX - - comBuf[0] = ST25R3911_FIFO_LOAD; - ST_MEMCPY( &comBuf[ST25R3911_CMD_LEN], values, MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) ); - - platformSpiTxRx( comBuf, NULL, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) ); - -#else /*ST25R391X_COM_SINGLETXRX*/ - - platformSpiTxRx( &cmd, NULL, ST25R3911_CMD_LEN ); - platformSpiTxRx( values, NULL, length ); - -#endif /*ST25R391X_COM_SINGLETXRX*/ - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - } - - return; -} - -void st25r3911ReadFifo(uint8_t* buf, uint8_t length) -{ -#if !defined(ST25R391X_COM_SINGLETXRX) - uint8_t cmd = ST25R3911_FIFO_READ; -#endif /* !ST25R391X_COM_SINGLETXRX */ - - if(length > 0U) - { - platformProtectST25R391xComm(); - platformSpiSelect(); - -#ifdef ST25R391X_COM_SINGLETXRX - - ST_MEMSET( comBuf, 0x00, MIN( (ST25R3911_CMD_LEN + (uint32_t)length), ST25R3911_BUF_LEN ) ); - comBuf[0] = ST25R3911_FIFO_READ; - - platformSpiTxRx( comBuf, comBuf, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) ); /* Transceive as a single SPI call */ - ST_MEMCPY( buf, &comBuf[ST25R3911_CMD_LEN], MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) ); /* Copy from local buf to output buffer and skip cmd byte */ - -#else /*ST25R391X_COM_SINGLETXRX*/ - - platformSpiTxRx( &cmd, NULL, ST25R3911_CMD_LEN ); - platformSpiTxRx( NULL, buf, length ); - -#endif /*ST25R391X_COM_SINGLETXRX*/ - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - } - - return; -} - -void st25r3911ExecuteCommand( uint8_t cmd ) -{ - uint8_t tmpCmd; /* MISRA 17.8 */ - -#ifdef PLATFORM_LED_FIELD_PIN - if ( (cmd >= ST25R3911_CMD_TRANSMIT_WITH_CRC) && (cmd <= ST25R3911_CMD_RESPONSE_RF_COLLISION_0)) - { - platformLedOff(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN); - } -#endif /* PLATFORM_LED_FIELD_PIN */ - - tmpCmd = (cmd | ST25R3911_CMD_MODE); - - platformProtectST25R391xComm(); - platformSpiSelect(); - - platformSpiTxRx( &tmpCmd, NULL, ST25R3911_CMD_LEN ); - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - - return; -} - - -void st25r3911ExecuteCommands(const uint8_t *cmds, uint8_t length) -{ - platformProtectST25R391xComm(); - platformSpiSelect(); - - platformSpiTxRx( cmds, NULL, length ); - - platformSpiDeselect(); - platformUnprotectST25R391xComm(); - - return; -} - -bool st25r3911IsRegValid( uint8_t reg ) -{ - if( !(( (int16_t)reg >= (int16_t)ST25R3911_REG_IO_CONF1) && (reg <= ST25R3911_REG_CAPACITANCE_MEASURE_RESULT)) && (reg != ST25R3911_REG_IC_IDENTITY) ) - { - return false; - } - return true; -} - -/* -****************************************************************************** -* LOCAL FUNCTIONS -****************************************************************************** -*/ - diff --git a/Software/Drivers/BSP/Components/ST25R3911/st25r3911_com.h b/Software/Drivers/BSP/Components/ST25R3911/st25r3911_com.h deleted file mode 100644 index c5f540f..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/st25r3911_com.h +++ /dev/null @@ -1,816 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R3911 firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Ulrich Herrmann - * - * \brief ST25R3911 communication declaration file - * - */ -/*! - * This driver provides basic abstraction for communication with the ST25R3911. - * It uses the SPI driver for interfacing with the ST25R3911. - * - * API: - * - Read Register: #st25r3911ReadRegister - * - Modify Register: #st25r3911ModifyRegister - * - Write Register: #st25r3911WriteRegister - * - Write Multiple Registers: #st25r3911WriteMultipleRegisters - * - Load ST25R3911 FIFO with data: #st25r3911WriteFifo - * - Read from ST25R3911 FIFO: #st25r3911ReadFifo - * - Execute direct command: #st25r3911ExecuteCommand - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-HAL - * \brief RFAL Hardware Abstraction Layer - * @{ - * - * \addtogroup ST25R3911 - * \brief RFAL ST25R3911 Driver - * @{ - * - * \addtogroup ST25R3911_Com - * \brief RFAL ST25R3911 Communication - * @{ - * - */ - -#ifndef ST25R3911_COM_H -#define ST25R3911_COM_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" -#include "st_errno.h" - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - -#define ST25R3911_FIFO_STATUS_LEN 2 /*!< Number of FIFO Status Register */ - - - - -#define ST25R3911_REG_IO_CONF1 0x00U /*!< RW IO Configuration Register 1 */ -#define ST25R3911_REG_IO_CONF2 0x01U /*!< RW IO Configuration Register 2 */ - -#define ST25R3911_REG_OP_CONTROL 0x02U /*!< RW Operation Control Register */ -#define ST25R3911_REG_MODE 0x03U /*!< RW Mode Definition Register */ -#define ST25R3911_REG_BIT_RATE 0x04U /*!< RW Bit Rate Definition Register */ - -#define ST25R3911_REG_ISO14443A_NFC 0x05U /*!< RW ISO14443A and NFC 106 kBit/s Settings Register */ -#define ST25R3911_REG_ISO14443B_1 0x06U /*!< RW ISO14443B Settings Register 1 */ -#define ST25R3911_REG_ISO14443B_2 0x07U /*!< RW ISO14443B Settings Register 2 */ -#define ST25R3911_REG_STREAM_MODE 0x08U /*!< RW Stream Mode Definition Register */ -#define ST25R3911_REG_AUX 0x09U /*!< RW Auxiliary Definition Register */ -#define ST25R3911_REG_RX_CONF1 0x0AU /*!< RW Receiver Configuration Register 1 */ -#define ST25R3911_REG_RX_CONF2 0x0BU /*!< RW Receiver Configuration Register 2 */ -#define ST25R3911_REG_RX_CONF3 0x0CU /*!< RW Receiver Configuration Register 3 */ -#define ST25R3911_REG_RX_CONF4 0x0DU /*!< RW Receiver Configuration Register 4 */ - -#define ST25R3911_REG_MASK_RX_TIMER 0x0EU /*!< RW Mask Receive Timer Register */ -#define ST25R3911_REG_NO_RESPONSE_TIMER1 0x0FU /*!< RW No-response Timer Register 1 */ -#define ST25R3911_REG_NO_RESPONSE_TIMER2 0x10U /*!< RW No-response Timer Register 2 */ -#define ST25R3911_REG_GPT_CONTROL 0x11U /*!< RW General Purpose Timer Control Register */ -#define ST25R3911_REG_GPT1 0x12U /*!< RW General Purpose Timer Register 1 */ -#define ST25R3911_REG_GPT2 0x13U /*!< RW General Purpose Timer Register 2 */ - -#define ST25R3911_REG_IRQ_MASK_MAIN 0x14U /*!< RW Mask Main Interrupt Register */ -#define ST25R3911_REG_IRQ_MASK_TIMER_NFC 0x15U /*!< RW Mask Timer and NFC Interrupt Register */ -#define ST25R3911_REG_IRQ_MASK_ERROR_WUP 0x16U /*!< RW Mask Error and Wake-up Interrupt Register */ -#define ST25R3911_REG_IRQ_MAIN 0x17U /*!< R Main Interrupt Register */ -#define ST25R3911_REG_IRQ_TIMER_NFC 0x18U /*!< R Timer and NFC Interrupt Register */ -#define ST25R3911_REG_IRQ_ERROR_WUP 0x19U /*!< R Error and Wake-up Interrupt Register */ -#define ST25R3911_REG_FIFO_RX_STATUS1 0x1AU /*!< R FIFO RX Status Register 1 */ -#define ST25R3911_REG_FIFO_RX_STATUS2 0x1BU /*!< R FIFO RX Status Register 2 */ -#define ST25R3911_REG_COLLISION_STATUS 0x1CU /*!< R Collision Display Register */ - -#define ST25R3911_REG_NUM_TX_BYTES1 0x1DU /*!< RW Number of Transmitted Bytes Register 1 */ -#define ST25R3911_REG_NUM_TX_BYTES2 0x1EU /*!< RW Number of Transmitted Bytes Register 2 */ - -#define ST25R3911_REG_NFCIP1_BIT_RATE 0x1FU /*!< R NFCIP Bit Rate Detection Display Register */ - -#define ST25R3911_REG_AD_RESULT 0x20U /*!< R A/D Converter Output Register */ - -#define ST25R3911_REG_ANT_CAL_CONTROL 0x21U /*!< RW Antenna Calibration Control Register */ -#define ST25R3911_REG_ANT_CAL_TARGET 0x22U /*!< RW Antenna Calibration Target Register */ -#define ST25R3911_REG_ANT_CAL_RESULT 0x23U /*!< R Antenna Calibration Display Register */ - -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL 0x24U /*!< RW AM Modulation Depth Control Register */ -#define ST25R3911_REG_AM_MOD_DEPTH_RESULT 0x25U /*!< R AM Modulation Depth Display Register */ -#define ST25R3911_REG_RFO_AM_ON_LEVEL 0x26U /*!< RW RFO AM Modulation (On) Level Definition Register */ -#define ST25R3911_REG_RFO_AM_OFF_LEVEL 0x27U /*!< RW RFO Normal (AM Off) Level Definition Register */ - -#define ST25R3911_REG_FIELD_THRESHOLD 0x29U /*!< RW External Field Detector Threshold Register */ - -#define ST25R3911_REG_REGULATOR_CONTROL 0x2AU /*!< RW Regulated Voltage Control Register */ -#define ST25R3911_REG_REGULATOR_RESULT 0x2BU /*!< R Regulator Display Register */ - -#define ST25R3911_REG_RSSI_RESULT 0x2CU /*!< R RSSI Display Register*/ -#define ST25R3911_REG_GAIN_RED_STATE 0x2DU /*!< R Gain Reduction State Register*/ - -#define ST25R3911_REG_CAP_SENSOR_CONTROL 0x2EU /*!< RW Capacitive Sensor Control Register */ -#define ST25R3911_REG_CAP_SENSOR_RESULT 0x2FU /*!< R Capacitive Sensor Display Register */ - -#define ST25R3911_REG_AUX_DISPLAY 0x30U /*!< R Auxiliary Display Register */ - -#define ST25R3911_REG_WUP_TIMER_CONTROL 0x31U /*!< RW Wake-up Timer Control Register */ -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF 0x32U /*!< RW Amplitude Measurement Configuration Register */ -#define ST25R3911_REG_AMPLITUDE_MEASURE_REF 0x33U /*!< RW Amplitude Measurement Reference Register */ -#define ST25R3911_REG_AMPLITUDE_MEASURE_AA_RESULT 0x34U /*!< R Amplitude Measurement Auto Averaging Display Register */ -#define ST25R3911_REG_AMPLITUDE_MEASURE_RESULT 0x35U /*!< R Amplitude Measurement Display Register */ -#define ST25R3911_REG_PHASE_MEASURE_CONF 0x36U /*!< RW Phase Measurement Configuration Register */ -#define ST25R3911_REG_PHASE_MEASURE_REF 0x37U /*!< RW Phase Measurement Reference Register */ -#define ST25R3911_REG_PHASE_MEASURE_AA_RESULT 0x38U /*!< R Phase Measurement Auto Averaging Display Register */ -#define ST25R3911_REG_PHASE_MEASURE_RESULT 0x39U /*!< R Phase Measurement Display Register */ -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF 0x3AU /*!< RW Capacitance Measurement Configuration Register */ -#define ST25R3911_REG_CAPACITANCE_MEASURE_REF 0x3BU /*!< RW Capacitance Measurement Reference Register */ -#define ST25R3911_REG_CAPACITANCE_MEASURE_AA_RESULT 0x3CU /*!< R Capacitance Measurement Auto Averaging Display Register */ -#define ST25R3911_REG_CAPACITANCE_MEASURE_RESULT 0x3DU /*!< R Capacitance Measurement Display Register */ - -#define ST25R3911_REG_IC_IDENTITY 0x3FU /*!< R Chip Id: 0 for old silicon, v2 silicon: 0x09 */ - - -/*! Register bit definitions \cond DOXYGEN_SUPRESS */ - -#define ST25R3911_REG_IO_CONF1_lf_clk_off (1U<<0) -#define ST25R3911_REG_IO_CONF1_out_cl0 (1U<<1) -#define ST25R3911_REG_IO_CONF1_out_cl1 (1U<<2) -#define ST25R3911_REG_IO_CONF1_mask_out_cl (3U<<1) -#define ST25R3911_REG_IO_CONF1_osc (1U<<3) -#define ST25R3911_REG_IO_CONF1_fifo_lt (1U<<4) -#define ST25R3911_REG_IO_CONF1_fifo_lt_32bytes (0U<<4) -#define ST25R3911_REG_IO_CONF1_fifo_lt_16bytes (1U<<4) -#define ST25R3911_REG_IO_CONF1_fifo_lr (1U<<5) -#define ST25R3911_REG_IO_CONF1_fifo_lr_64bytes (0U<<5) -#define ST25R3911_REG_IO_CONF1_fifo_lr_80bytes (1U<<5) -#define ST25R3911_REG_IO_CONF1_rfo2 (1U<<6) -#define ST25R3911_REG_IO_CONF1_single (1U<<7) -#define ST25R3911_REG_IO_CONF2_slow_up (1U<<0) -#define ST25R3911_REG_IO_CONF2_io_18 (1U<<2) -#define ST25R3911_REG_IO_CONF2_miso_pd1 (1U<<3) -#define ST25R3911_REG_IO_CONF2_miso_pd2 (1U<<4) -#define ST25R3911_REG_IO_CONF2_vspd_off (1U<<6) -#define ST25R3911_REG_IO_CONF2_sup3V (1U<<7) -#define ST25R3911_REG_OP_CONTROL_wu (1U<<2) -#define ST25R3911_REG_OP_CONTROL_tx_en (1U<<3) -#define ST25R3911_REG_OP_CONTROL_rx_man (1U<<4) -#define ST25R3911_REG_OP_CONTROL_rx_chn (1U<<5) -#define ST25R3911_REG_OP_CONTROL_rx_en (1U<<6) -#define ST25R3911_REG_OP_CONTROL_en (1U<<7) -#define ST25R3911_REG_MODE_nfc_ar (1U<<0) -#define ST25R3911_REG_MODE_nfc_ar_on (1U<<0) -#define ST25R3911_REG_MODE_nfc_ar_off (0U<<0) -#define ST25R3911_REG_MODE_mask_om (0xfU<<3) -#define ST25R3911_REG_MODE_om_nfc (0x0U<<3) -#define ST25R3911_REG_MODE_om_iso14443a (0x1U<<3) -#define ST25R3911_REG_MODE_om_iso14443b (0x2U<<3) -#define ST25R3911_REG_MODE_om_felica (0x3U<<3) -#define ST25R3911_REG_MODE_om_topaz (0x4U<<3) -#define ST25R3911_REG_MODE_om_subcarrier_stream (0xeU<<3) -#define ST25R3911_REG_MODE_om_bpsk_stream (0xfU<<3) -#define ST25R3911_REG_MODE_om_bit_rate_detection (0x0U<<3) -#define ST25R3911_REG_MODE_om_nfcip1_normal_mode (0x1U<<3) -#define ST25R3911_REG_MODE_targ (1U<<7) -#define ST25R3911_REG_MODE_targ_targ (1U<<7) -#define ST25R3911_REG_MODE_targ_init (0U<<7) -#define ST25R3911_REG_BIT_RATE_mask_txrate (0xfU<<4) -#define ST25R3911_REG_BIT_RATE_shift_txrate (4U) -#define ST25R3911_REG_BIT_RATE_txrate_106 (0x0U<<4) -#define ST25R3911_REG_BIT_RATE_txrate_212 (0x1U<<4) -#define ST25R3911_REG_BIT_RATE_txrate_424 (0x2U<<4) -#define ST25R3911_REG_BIT_RATE_txrate_848 (0x3U<<4) -#define ST25R3911_REG_BIT_RATE_txrate_1695 (0x4U<<4) -#define ST25R3911_REG_BIT_RATE_txrate_3390 (0x5U<<4) -#define ST25R3911_REG_BIT_RATE_txrate_6780 (0x6U<<4) -#define ST25R3911_REG_BIT_RATE_mask_rxrate (0xfU<<0) -#define ST25R3911_REG_BIT_RATE_shift_rxrate (0U) -#define ST25R3911_REG_BIT_RATE_rxrate_106 (0x0U<<0) -#define ST25R3911_REG_BIT_RATE_rxrate_212 (0x1U<<0) -#define ST25R3911_REG_BIT_RATE_rxrate_424 (0x2U<<0) -#define ST25R3911_REG_BIT_RATE_rxrate_848 (0x3U<<0) -#define ST25R3911_REG_BIT_RATE_rxrate_1695 (0x4U<<0) -#define ST25R3911_REG_BIT_RATE_rxrate_3390 (0x5U<<0) -#define ST25R3911_REG_BIT_RATE_rxrate_6780 (0x6U<<0) -#define ST25R3911_REG_ISO14443A_NFC_antcl (1U<<0) -#define ST25R3911_REG_ISO14443A_NFC_mask_p_len (0xfU<<1) -#define ST25R3911_REG_ISO14443A_NFC_shift_p_len (1U) -#define ST25R3911_REG_ISO14443A_NFC_nfc_f0 (1U<<5) -#define ST25R3911_REG_ISO14443A_NFC_nfc_f0_off (0U<<5) -#define ST25R3911_REG_ISO14443A_NFC_no_rx_par (1U<<6) -#define ST25R3911_REG_ISO14443A_NFC_no_rx_par_off (0U<<6) -#define ST25R3911_REG_ISO14443A_NFC_no_tx_par (1U<<7) -#define ST25R3911_REG_ISO14443A_NFC_no_tx_par_off (0U<<7) -#define ST25R3911_REG_ISO14443B_1_mask_eof (1U<<2) -#define ST25R3911_REG_ISO14443B_1_eof_10etu (0U<<2) -#define ST25R3911_REG_ISO14443B_1_eof_11etu (1U<<2) -#define ST25R3911_REG_ISO14443B_1_mask_sof (3U<<3) -#define ST25R3911_REG_ISO14443B_1_mask_sof_0 (1U<<4) -#define ST25R3911_REG_ISO14443B_1_sof_0_10etu (0U<<4) -#define ST25R3911_REG_ISO14443B_1_sof_0_11etu (1U<<4) -#define ST25R3911_REG_ISO14443B_1_mask_sof_1 (1U<<3) -#define ST25R3911_REG_ISO14443B_1_sof_1_2etu (0U<<3) -#define ST25R3911_REG_ISO14443B_1_sof_2_3etu (1U<<3) -#define ST25R3911_REG_ISO14443B_1_mask_egt (7U<<5) -#define ST25R3911_REG_ISO14443B_1_shift_egt (5U) -#define ST25R3911_REG_ISO14443B_2_eof_12 (1U<<3) -#define ST25R3911_REG_ISO14443B_2_eof_12_10to11etu (0U<<3) -#define ST25R3911_REG_ISO14443B_2_eof_12_10to12etu (1U<<3) -#define ST25R3911_REG_ISO14443B_2_no_eof (1U<<4) -#define ST25R3911_REG_ISO14443B_2_no_sof (1U<<5) -#define ST25R3911_REG_ISO14443B_2_mask_tr1 (3U<<6) -#define ST25R3911_REG_ISO14443B_2_shift_tr1 (6U) -#define ST25R3911_REG_ISO14443B_2_tr1_0 (1U<<6) -#define ST25R3911_REG_ISO14443B_2_tr1_1 (1U<<7) -#define ST25R3911_REG_ISO14443B_2_tr1_80fs80fs (0U<<6) -#define ST25R3911_REG_ISO14443B_2_tr1_64fs32fs (1U<<6) -#define ST25R3911_REG_STREAM_MODE_mask_stx (7U<<0) -#define ST25R3911_REG_STREAM_MODE_shift_stx (0U) -#define ST25R3911_REG_STREAM_MODE_stx_106 (0U<<0) -#define ST25R3911_REG_STREAM_MODE_stx_212 (1U<<0) -#define ST25R3911_REG_STREAM_MODE_stx_424 (2U<<0) -#define ST25R3911_REG_STREAM_MODE_stx_848 (3U<<0) -#define ST25R3911_REG_STREAM_MODE_stx_1695 (4U<<0) -#define ST25R3911_REG_STREAM_MODE_stx_3390 (5U<<0) -#define ST25R3911_REG_STREAM_MODE_stx_6780 (6U<<0) -#define ST25R3911_REG_STREAM_MODE_mask_scp (3U<<3) -#define ST25R3911_REG_STREAM_MODE_shift_scp (3U) -#define ST25R3911_REG_STREAM_MODE_scp_1pulse (0U<<3) -#define ST25R3911_REG_STREAM_MODE_scp_2pulses (1U<<3) -#define ST25R3911_REG_STREAM_MODE_scp_4pulses (2U<<3) -#define ST25R3911_REG_STREAM_MODE_scp_8pulses (3U<<3) -#define ST25R3911_REG_STREAM_MODE_mask_scf (3U<<5) -#define ST25R3911_REG_STREAM_MODE_shift_scf (5U) -#define ST25R3911_REG_STREAM_MODE_scf_bpsk848 (0U<<5) -#define ST25R3911_REG_STREAM_MODE_scf_bpsk1695 (1U<<5) -#define ST25R3911_REG_STREAM_MODE_scf_bpsk3390 (2U<<5) -#define ST25R3911_REG_STREAM_MODE_scf_bpsk106 (3U<<5) -#define ST25R3911_REG_STREAM_MODE_scf_sc212 (0U<<5) -#define ST25R3911_REG_STREAM_MODE_scf_sc424 (1U<<5) -#define ST25R3911_REG_STREAM_MODE_scf_sc848 (2U<<5) -#define ST25R3911_REG_STREAM_MODE_scf_sc1695 (3U<<5) -#define ST25R3911_REG_AUX_mask_nfc_n (3U<<0) -#define ST25R3911_REG_AUX_nfc_n0 (1U<<0) -#define ST25R3911_REG_AUX_nfc_n1 (1U<<1) -#define ST25R3911_REG_AUX_rx_tol (1U<<2) -#define ST25R3911_REG_AUX_ook_hr (1U<<3) -#define ST25R3911_REG_AUX_en_fd (1U<<4) -#define ST25R3911_REG_AUX_tr_am (1U<<5) -#define ST25R3911_REG_AUX_crc_2_fifo (1U<<6) -#define ST25R3911_REG_AUX_no_crc_rx (1U<<7) -#define ST25R3911_REG_RX_CONF1_z12k (1U<<0) -#define ST25R3911_REG_RX_CONF1_h80 (1U<<1) -#define ST25R3911_REG_RX_CONF1_h200 (1U<<2) -#define ST25R3911_REG_RX_CONF1_mask_lp (7U<<3) -#define ST25R3911_REG_RX_CONF1_lp_1200khz (0U<<3) -#define ST25R3911_REG_RX_CONF1_lp_600khz (1U<<3) -#define ST25R3911_REG_RX_CONF1_lp_300khz (2U<<3) -#define ST25R3911_REG_RX_CONF1_lp_2000khz (4U<<3) -#define ST25R3911_REG_RX_CONF1_lp_7000khz (5U<<3) -#define ST25R3911_REG_RX_CONF1_amd_sel (1U<<6) -#define ST25R3911_REG_RX_CONF1_ch_sel (1U<<7) -#define ST25R3911_REG_RX_CONF2_sqm_dyn (1U<<1) -#define ST25R3911_REG_RX_CONF2_agc_alg (1U<<2) -#define ST25R3911_REG_RX_CONF2_agc_m (1U<<3) -#define ST25R3911_REG_RX_CONF2_agc_en (1U<<4) -#define ST25R3911_REG_RX_CONF2_lf_en (1U<<5) -#define ST25R3911_REG_RX_CONF2_lf_op (1U<<6) -#define ST25R3911_REG_RX_CONF2_rx_lp (1U<<7) -#define ST25R3911_REG_RX_CONF3_rg_nfc (1U<<0) -#define ST25R3911_REG_RX_CONF3_lim (1U<<1) -#define ST25R3911_REG_RX_CONF3_shift_rg1_pm (2U) -#define ST25R3911_REG_RX_CONF3_mask_rg1_pm (0x7U<<2) -#define ST25R3911_REG_RX_CONF3_rg1_pm0 (1U<<2) -#define ST25R3911_REG_RX_CONF3_rg1_pm1 (1U<<3) -#define ST25R3911_REG_RX_CONF3_rg1_pm2 (1U<<4) -#define ST25R3911_REG_RX_CONF3_shift_rg1_am (5U) -#define ST25R3911_REG_RX_CONF3_mask_rg1_am (0x7U<<5) -#define ST25R3911_REG_RX_CONF3_rg1_am0 (1U<<5) -#define ST25R3911_REG_RX_CONF3_rg1_am1 (1U<<6) -#define ST25R3911_REG_RX_CONF3_rg1_am2 (1U<<7) -#define ST25R3911_REG_RX_CONF4_shift_rg2_pm (0U) -#define ST25R3911_REG_RX_CONF4_mask_rg2_pm (0xfU<<0) -#define ST25R3911_REG_RX_CONF4_rg2_pm0 (1U<<0) -#define ST25R3911_REG_RX_CONF4_rg2_pm1 (1U<<1) -#define ST25R3911_REG_RX_CONF4_rg2_pm2 (1U<<2) -#define ST25R3911_REG_RX_CONF4_rg2_pm3 (1U<<3) -#define ST25R3911_REG_RX_CONF4_shift_rg2_am (4U) -#define ST25R3911_REG_RX_CONF4_mask_rg2_am (0xfU<<4) -#define ST25R3911_REG_RX_CONF4_rg2_am0 (1U<<4) -#define ST25R3911_REG_RX_CONF4_rg2_am1 (1U<<5) -#define ST25R3911_REG_RX_CONF4_rg2_am2 (1U<<6) -#define ST25R3911_REG_RX_CONF4_rg2_am3 (1U<<7) -#define ST25R3911_REG_GPT_CONTROL_nrt_step (1U<<0) -#define ST25R3911_REG_GPT_CONTROL_nrt_emv (1U<<1) -#define ST25R3911_REG_GPT_CONTROL_gptc0 (1U<<5) -#define ST25R3911_REG_GPT_CONTROL_gptc1 (1U<<6) -#define ST25R3911_REG_GPT_CONTROL_gptc2 (1U<<7) -#define ST25R3911_REG_GPT_CONTROL_gptc_mask (0x7U<<5) -#define ST25R3911_REG_GPT_CONTROL_gptc_no_trigger (0x0U<<5) -#define ST25R3911_REG_GPT_CONTROL_gptc_erx (0x1U<<5) -#define ST25R3911_REG_GPT_CONTROL_gptc_srx (0x2U<<5) -#define ST25R3911_REG_GPT_CONTROL_gptc_etx_nfc (0x3U<<5) -#define ST25R3911_REG_FIFO_RX_STATUS2_np_lb (1U<<0) -#define ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb (7U<<1) -#define ST25R3911_REG_FIFO_RX_STATUS2_shift_fifo_lb (1U) -#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_lb0 (1U<<1) -#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_lb1 (1U<<2) -#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_lb2 (1U<<3) -#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_ncp (1U<<4) -#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_ovr (1U<<5) -#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_unf (1U<<6) -#define ST25R3911_REG_COLLISION_STATUS_c_pb (1U<<0) -#define ST25R3911_REG_COLLISION_STATUS_mask_c_bit (3U<<1) -#define ST25R3911_REG_COLLISION_STATUS_shift_c_bit (1U) -#define ST25R3911_REG_COLLISION_STATUS_mask_c_byte (0xfU<<4) -#define ST25R3911_REG_COLLISION_STATUS_shift_c_byte (4U) -#define ST25R3911_ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate0 (1U<<4) -#define ST25R3911_ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate1 (1U<<5) -#define ST25R3911_ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate2 (1U<<6) -#define ST25R3911_ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate3 (1U<<7) -#define ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate_mask (0xfU<<4) -#define ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate_shift (4U) -#define ST25R3911_REG_ANT_CAL_CONTROL_mask_tre (0xfU<<3) -#define ST25R3911_REG_ANT_CAL_CONTROL_shift_tre (3U) -#define ST25R3911_REG_ANT_CAL_CONTROL_tre_0 (1U<<3) -#define ST25R3911_REG_ANT_CAL_CONTROL_tre_1 (1U<<4) -#define ST25R3911_REG_ANT_CAL_CONTROL_tre_2 (1U<<5) -#define ST25R3911_REG_ANT_CAL_CONTROL_tre_3 (1U<<6) -#define ST25R3911_REG_ANT_CAL_CONTROL_trim_s (1U<<7) -#define ST25R3911_REG_ANT_CAL_RESULT_tri_err (1U<<3) -#define ST25R3911_REG_ANT_CAL_RESULT_tri_0 (1U<<4) -#define ST25R3911_REG_ANT_CAL_RESULT_tri_1 (1U<<5) -#define ST25R3911_REG_ANT_CAL_RESULT_tri_2 (1U<<6) -#define ST25R3911_REG_ANT_CAL_RESULT_tri_3 (1U<<7) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mask_mod (0x3fU<<1) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_shift_mod (1U) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_8percent (0xbU<<1) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_10percent (0xeU<<1) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_14percent (0x14U<<1) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_20percent (0x20U<<1) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_25percent (0x2aU<<1) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_30percent (0x37U<<1) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_33percent (0x3fU<<1) -#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_am_s (1U<<7) -#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram0 (1U<<0) -#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram1 (1U<<1) -#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram2 (1U<<2) -#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram3 (1U<<3) -#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram4 (1U<<4) -#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram5 (1U<<5) -#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram6 (1U<<6) -#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram7 (1U<<7) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_t0 (1U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_t1 (1U<<1) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_t2 (1U<<2) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_t3 (1U<<3) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_l0 (1U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_l1 (1U<<5) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_l2 (1U<<6) -#define ST25R3911_REG_FIELD_THRESHOLD_mask_trg (0x07U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_75mV (0x00U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_105mV (0x01U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_150mV (0x02U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_205mV (0x03U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_290mV (0x04U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_400mV (0x05U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_560mV (0x06U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_trg_800mV (0x07U<<4) -#define ST25R3911_REG_FIELD_THRESHOLD_mask_rfe (0x0FU<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_75mV (0x00U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_105mV (0x01U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_150mV (0x02U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_205mV (0x03U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_290mV (0x04U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_400mV (0x05U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_560mV (0x06U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_800mV (0x07U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_25mV (0x08U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_33mV (0x09U<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_47mV (0x0AU<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_64mV (0x0BU<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_90mV (0x0CU<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_125mV (0x0DU<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_175mV (0x0EU<<0) -#define ST25R3911_REG_FIELD_THRESHOLD_rfe_250mV (0x0FU<<0) -#define ST25R3911_REG_REGULATOR_CONTROL_shift_mpsv (1U) -#define ST25R3911_REG_REGULATOR_CONTROL_mask_mpsv (3U<<1) -#define ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd (0U<<1) -#define ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_a (1U<<1) -#define ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_d (2U<<1) -#define ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_rf (3U<<1) -#define ST25R3911_REG_REGULATOR_CONTROL_mask_rege (0xfU<<3) -#define ST25R3911_REG_REGULATOR_CONTROL_shift_rege (3U) -#define ST25R3911_REG_REGULATOR_CONTROL_reg_s (1U<<7) -#define ST25R3911_REG_REGULATOR_RESULT_mrt_on (1U<<0) -#define ST25R3911_REG_REGULATOR_RESULT_nrt_on (1U<<1) -#define ST25R3911_REG_REGULATOR_RESULT_gpt_on (1U<<2) -#define ST25R3911_REG_REGULATOR_RESULT_mask_reg (0xfU<<4) -#define ST25R3911_REG_REGULATOR_RESULT_shift_reg (4U) -#define ST25R3911_REG_REGULATOR_RESULT_reg_0 (1U<<4) -#define ST25R3911_REG_REGULATOR_RESULT_reg_1 (1U<<5) -#define ST25R3911_REG_REGULATOR_RESULT_reg_2 (1U<<6) -#define ST25R3911_REG_REGULATOR_RESULT_reg_3 (1U<<7) -#define ST25R3911_REG_RSSI_RESULT_mask_rssi_pm (0xfU) -#define ST25R3911_REG_RSSI_RESULT_shift_rssi_pm (0U) -#define ST25R3911_REG_RSSI_RESULT_rssi_pm0 (1U<<0) -#define ST25R3911_REG_RSSI_RESULT_rssi_pm1 (1U<<1) -#define ST25R3911_REG_RSSI_RESULT_rssi_pm2 (1U<<2) -#define ST25R3911_REG_RSSI_RESULT_rssi_pm3 (1U<<3) -#define ST25R3911_REG_RSSI_RESULT_mask_rssi_am (0xfU<<4) -#define ST25R3911_REG_RSSI_RESULT_shift_rssi_am (4U) -#define ST25R3911_REG_RSSI_RESULT_rssi_am_0 (1U<<4) -#define ST25R3911_REG_RSSI_RESULT_rssi_am_1 (1U<<5) -#define ST25R3911_REG_RSSI_RESULT_rssi_am_2 (1U<<6) -#define ST25R3911_REG_RSSI_RESULT_rssi_am_3 (1U<<7) -#define ST25R3911_REG_GAIN_RED_STATE_mask_gs_pm (0xfU) -#define ST25R3911_REG_GAIN_RED_STATE_shift_gs_pm (0U) -#define ST25R3911_REG_GAIN_RED_STATE_gs_pm_0 (1U<<0) -#define ST25R3911_REG_GAIN_RED_STATE_gs_pm_1 (1U<<1) -#define ST25R3911_REG_GAIN_RED_STATE_gs_pm_2 (1U<<2) -#define ST25R3911_REG_GAIN_RED_STATE_gs_pm_3 (1U<<3) -#define ST25R3911_REG_GAIN_RED_STATE_mask_gs_am (0xfU<<4) -#define ST25R3911_REG_GAIN_RED_STATE_shift_gs_am (4U) -#define ST25R3911_REG_GAIN_RED_STATE_gs_am_0 (1U<<4) -#define ST25R3911_REG_GAIN_RED_STATE_gs_am_1 (1U<<5) -#define ST25R3911_REG_GAIN_RED_STATE_gs_am_2 (1U<<6) -#define ST25R3911_REG_GAIN_RED_STATE_gs_am_3 (1U<<7) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_g0 (1U<<0) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_g1 (1U<<1) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_g2 (1U<<2) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_mask_cs_g (7U<<0) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal0 (1U<<3) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal1 (1U<<4) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal2 (1U<<5) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal3 (1U<<6) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal4 (1U<<7) -#define ST25R3916_REG_CAP_SENSOR_CONTROL_mask_cs_mcal (0x1fU<<3) -#define ST25R3911_REG_CAP_SENSOR_CONTROL_shift_cs_mcal (3U) -#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_err (1U<<1) -#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_end (1U<<2) -#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal0 (1U<<3) -#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal1 (1U<<4) -#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal2 (1U<<5) -#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal3 (1U<<6) -#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal4 (1U<<7) -#define ST25R3911_REG_AUX_DISPLAY_mrt_on (1U<<0) -#define ST25R3911_REG_AUX_DISPLAY_nrt_on (1U<<1) -#define ST25R3911_REG_AUX_DISPLAY_gpt_on (1U<<2) -#define ST25R3911_REG_AUX_DISPLAY_rx_on (1U<<3) -#define ST25R3911_REG_AUX_DISPLAY_osc_ok (1U<<4) -#define ST25R3911_REG_AUX_DISPLAY_tx_on (1U<<5) -#define ST25R3911_REG_AUX_DISPLAY_efd_o (1U<<6) -#define ST25R3911_REG_AUX_DISPLAY_a_cha (1U<<7) -#define ST25R3911_REG_WUP_TIMER_CONTROL_wcap (1U<<0) -#define ST25R3911_REG_WUP_TIMER_CONTROL_wph (1U<<1) -#define ST25R3911_REG_WUP_TIMER_CONTROL_wam (1U<<2) -#define ST25R3911_REG_WUP_TIMER_CONTROL_wto (1U<<3) -#define ST25R3911_REG_WUP_TIMER_CONTROL_wut0 (1U<<4) -#define ST25R3911_REG_WUP_TIMER_CONTROL_wut1 (1U<<5) -#define ST25R3911_REG_WUP_TIMER_CONTROL_wut2 (1U<<6) -#define ST25R3911_REG_WUP_TIMER_CONTROL_shift_wut (4U) -#define ST25R3911_REG_WUP_TIMER_CONTROL_wur (1U<<7) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_ae (1U<<0) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_aew0 (1U<<1) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_aew1 (1U<<2) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_shift_am_aew (1U) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_mask_am_aew (3U<<1) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_aam (1U<<3) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_d0 (1U<<4) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_d1 (1U<<5) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_d2 (1U<<6) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_d3 (1U<<7) -#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_shift_am_d (4U) -#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_ae (1U<<0) -#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_aew0 (1U<<1) -#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_aew1 (1U<<2) -#define ST25R3911_REG_PHASE_MEASURE_CONF_shift_pm_aew (1U) -#define ST25R3911_REG_PHASE_MEASURE_CONF_mask_pm_aew (3U<<1) -#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_aam (1U<<3) -#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_d0 (1U<<4) -#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_d1 (1U<<5) -#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_d2 (1U<<6) -#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_d3 (1U<<7) -#define ST25R3911_REG_PHASE_MEASURE_CONF_shift_pm_d (4U) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_ae (1U<<0) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_aew0 (1U<<1) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_aew1 (1U<<2) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_shift_cm_aew (1U) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_mask_cm_aew (3U<<1) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_aam (1U<<3) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_d0 (1U<<4) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_d1 (1U<<5) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_d2 (1U<<6) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_d3 (1U<<7) -#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_shift_cm_d (4U) -#define ST25R3911_REG_IC_IDENTITY_v2 (0x09U) -#define ST25R3911_REG_IC_IDENTITY_ic_type (1U<<3) -#define ST25R3911_REG_IC_IDENTITY_mask_ic_type (0x1FU<<3) -#define ST25R3911_REG_IC_IDENTITY_shift_ic_type (3U) -#define ST25R3911_REG_IC_IDENTITY_mask_ic_rev (7U) - -/*! \endcond DOXYGEN_SUPRESS */ - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -/*! - ***************************************************************************** - * \brief Returns the content of a register within the ST25R3911 - * - * This function is used to read out the content of ST25R3911 registers. - * - * \param[in] reg: Address of register to read. - * \param[out] value: Returned value. - * - ***************************************************************************** - */ -extern void st25r3911ReadRegister(uint8_t reg, uint8_t* value); - -/*! - ***************************************************************************** - * \brief Writes a given value to a register within the ST25R3911 - * - * This function is used to write \a value to address \a reg within the ST25R3911. - * - * \param[in] reg: Address of the register to write. - * \param[in] value: Value to be written. - * - ***************************************************************************** - */ -extern void st25r3911WriteRegister(uint8_t reg, uint8_t value); - -/*! - ***************************************************************************** - * \brief Cleart bits on Register - * - * This function clears the given bitmask on the register - * - * \warning This method does not guarantee consistency of register content - * when called from multiple contexts (task, ISR, thread) - * - * \param[in] reg: Address of the register clear - * \param[in] clr_mask: Bitmask of bit to be cleared - * - ***************************************************************************** - */ -extern void st25r3911ClrRegisterBits( uint8_t reg, uint8_t clr_mask ); - - -/*! - ***************************************************************************** - * \brief Set bits on Register - * - * This function sets the given bitmask on the register - * - * \warning This method does not guarantee consistency of register content - * when called from multiple contexts (task, ISR, thread) - * - * \param[in] reg: Address of the register clear - * \param[in] set_mask: Bitmask of bit to be cleared - * - ***************************************************************************** - */ -extern void st25r3911SetRegisterBits( uint8_t reg, uint8_t set_mask ); - - -/*! - ***************************************************************************** - * \brief Changes the given bits on a ST25R3911 register - * - * This function is used if only a particular bits should be changed within - * an ST25R3911 register. - * - * \warning This method does not guarantee consistency of register content - * when called from multiple contexts (task, ISR, thread) - * - * \param[in] reg: Address of the register to write. - * \param[in] valueMask: bitmask of bits to be changed - * \param[in] value: the bits to be written on the enabled valueMask bits - * - ***************************************************************************** - */ -extern void st25r3911ChangeRegisterBits(uint8_t reg, uint8_t valueMask, uint8_t value); - -/*! - ***************************************************************************** - * \brief Read a test register within the ST25R3911 - * - * This function is used to read the content of test address \a reg within the ST25R3911. - * - * \param[in] reg: Address of the register to read. - * \param[out] value: Returned read. - * - ***************************************************************************** - */ -extern void st25r3911ReadTestRegister(uint8_t reg, uint8_t* value); - -/*! - ***************************************************************************** - * \brief Writes a given value to a test register within the ST25R3911 - * - * This function is used to write \a value to test address \a reg within the ST25R3911. - * - * \param[in] reg: Address of the register to write. - * \param[in] value: Value to be written. - * - ***************************************************************************** - */ -extern void st25r3911WriteTestRegister(uint8_t reg, uint8_t value); - -/*! - ***************************************************************************** - * \brief Modifies a value within a ST25R3911 register - * - * This function is used if only a particular bits should be changed within - * an ST25R3911 register. - * - * \warning This method does not guarantee consistency of register content - * when called from multiple contexts (task, ISR, thread) - * - * \param[in] reg: Address of the register to write. - * \param[in] clr_mask: bitmask of bits to be cleared to 0. - * \param[in] set_mask: bitmask of bits to be set to 1. - * - ***************************************************************************** - */ -extern void st25r3911ModifyRegister(uint8_t reg, uint8_t clr_mask, uint8_t set_mask); - - -/*! - ***************************************************************************** - * \brief Changes the given bits on a ST25R3911 Test register - * - * This function is used if only a particular bits should be changed within - * an ST25R3916 register. - * - * \param[in] reg: Address of the Test register to change. - * \param[in] valueMask: bitmask of bits to be changed - * \param[in] value: the bits to be written on the enabled valueMask bits - * - * \warning This method does not guarantee consistency of register content - * when called from multiple contexts (task, ISR, thread) - - * \return ERR_NONE : Operation successful - * \return ERR_PARAM : Invalid parameter - * \return ERR_SEND : Transmission error or acknowledge not received - ***************************************************************************** - */ -extern void st25r3911ChangeTestRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value ); - -/*! - ***************************************************************************** - * \brief Writes multiple values to ST25R3911 registers - * - * This function is used to write multiple values to the ST25R3911 using the - * auto-increment feature. That is, after each write the address pointer - * inside the ST25R3911 gets incremented automatically. - * - * \param[in] reg: Address of the frist register to write. - * \param[in] values: pointer to a buffer containing the values to be written. - * \param[in] length: Number of values to be written. - * - ***************************************************************************** - */ -extern void st25r3911WriteMultipleRegisters(uint8_t reg, const uint8_t* values, uint8_t length); - -/*! - ***************************************************************************** - * \brief Reads from multiple ST25R3911 registers - * - * This function is used to read from multiple registers using the - * auto-increment feature. That is, after each read the address pointer - * inside the ST25R3911 gets incremented automatically. - * - * \param[in] reg: Address of the frist register to read from. - * \param[in] values: pointer to a buffer where the result shall be written to. - * \param[in] length: Number of registers to be read out. - * - ***************************************************************************** - */ -extern void st25r3911ReadMultipleRegisters(uint8_t reg, uint8_t* values, uint8_t length); - -/*! - ***************************************************************************** - * \brief Writes values to ST25R3911 FIFO - * - * This function needs to be called in order to write to the ST25R3911 FIFO. - * - * \param[in] values: pointer to a buffer containing the values to be written - * to the FIFO. - * \param[in] length: Number of values to be written. - * - ***************************************************************************** - */ -extern void st25r3911WriteFifo(const uint8_t* values, uint8_t length); - -/*! - ***************************************************************************** - * \brief Read values from ST25R3911 FIFO - * - * This function needs to be called in order to read from ST25R3911 FIFO. - * - * \param[out] buf: pointer to a buffer where the FIFO content shall be - * written to. - * \param[in] length: Number of bytes to read. (= size of \a buf) - * \note: This function doesn't check whether \a length is really the - * number of available bytes in FIFO - * - ***************************************************************************** - */ -extern void st25r3911ReadFifo(uint8_t* buf, uint8_t length); - -/*! - ***************************************************************************** - * \brief Execute a direct command - * - * This function is used to start so-called direct command. These commands - * are implemented inside the chip and each command has unique code (see - * datasheet). - * - * \param[in] cmd : code of the direct command to be executed. - * - ***************************************************************************** - */ -extern void st25r3911ExecuteCommand(uint8_t cmd); - -/*! - ***************************************************************************** - * \brief Execute several direct commands - * - * This function is used to start so-called direct command. These commands - * are implemented inside the chip and each command has unique code (see - * datasheet). - * - * \param[in] cmds : codes of the direct command to be executed. - * \param[in] length : number of commands to be executed - * - ***************************************************************************** - */ -extern void st25r3911ExecuteCommands(const uint8_t *cmds, uint8_t length); - -/*! - ***************************************************************************** - * \brief Check if register ID is valid - * - * Checks if the given register ID a valid ST25R3911 register - * - * \param[in] reg: Address of register to check - * - * \return true if is a valid register ID - * \return false otherwise - * - ***************************************************************************** - */ -extern bool st25r3911IsRegValid( uint8_t reg ); - -#endif /* ST25R3911_COM_H */ - -/** - * @} - * - * @} - * - * @} - * - * @} - */ - diff --git a/Software/Drivers/BSP/Components/ST25R3911/st25r3911_interrupt.c b/Software/Drivers/BSP/Components/ST25R3911/st25r3911_interrupt.c deleted file mode 100644 index abb3082..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/st25r3911_interrupt.c +++ /dev/null @@ -1,249 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R3911 firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Ulrich Herrmann - * - * \brief ST25R3911 Interrupt handling - * - */ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "st25r3911_interrupt.h" -#include "st25r3911_com.h" -#include "st25r3911.h" -#include "st_errno.h" -#include "utils.h" - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - -/*! Length of the interrupt registers */ -#define ST25R3911_INT_REGS_LEN ( (ST25R3911_REG_IRQ_ERROR_WUP - ST25R3911_REG_IRQ_MAIN) + 1U ) - -/* - ****************************************************************************** - * LOCAL DATA TYPES - ****************************************************************************** - */ - -/*! Holds current and previous interrupt callback pointer as well as current Interrupt status and mask */ -typedef struct -{ - void (*prevCallback)(void); /*!< call back function for 3911 interrupt */ - void (*callback)(void); /*!< call back function for 3911 interrupt */ - uint32_t status; /*!< latest interrupt status */ - uint32_t mask; /*!< Interrupt mask. Negative mask = ST25R3911 mask regs */ -}t_st25r3911Interrupt; - -/* -****************************************************************************** -* GLOBAL VARIABLES -****************************************************************************** -*/ - -static volatile t_st25r3911Interrupt st25r3911interrupt; /*!< Instance of ST25R3911 interrupt */ - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ -void st25r3911InitInterrupts( void ) -{ - platformIrqST25R3911PinInitialize(); - platformIrqST25R3911SetCallback( st25r3911Isr ); - - st25r3911interrupt.callback = NULL; - st25r3911interrupt.prevCallback = NULL; - st25r3911interrupt.status = ST25R3911_IRQ_MASK_NONE; - st25r3911interrupt.mask = ST25R3911_IRQ_MASK_NONE; - - /* Initialize LEDs if existing and defined */ - platformLedsInitialize(); - -#ifdef PLATFORM_LED_RX_PIN - platformLedOff( PLATFORM_LED_RX_PORT, PLATFORM_LED_RX_PIN ); -#endif /* PLATFORM_LED_RX_PIN */ - -#ifdef PLATFORM_LED_FIELD_PIN - platformLedOff( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN ); -#endif /* PLATFORM_LED_FIELD_PIN */ -} - -void st25r3911Isr( void ) -{ - st25r3911CheckForReceivedInterrupts(); - - if (NULL != st25r3911interrupt.callback) - { - st25r3911interrupt.callback(); - } -} - -void st25r3911CheckForReceivedInterrupts( void ) -{ - uint8_t iregs[ST25R3911_INT_REGS_LEN]; - uint32_t irqStatus; - - irqStatus = ST25R3911_IRQ_MASK_NONE; - ST_MEMSET( iregs, (int32_t)(ST25R3911_IRQ_MASK_ALL & 0xFFU), ST25R3911_INT_REGS_LEN ); /* MISRA 10.3 */ - - /* In case the IRQ is Edge (not Level) triggered read IRQs until done */ - while( platformGpioIsHigh( ST25R391X_INT_PORT, ST25R391X_INT_PIN ) ) - { - st25r3911ReadMultipleRegisters(ST25R3911_REG_IRQ_MAIN, iregs, sizeof(iregs)); - -#ifdef PLATFORM_LED_FIELD_PIN - if ((iregs[0] & ST25R3911_IRQ_MASK_TXE) != 0U) - { - platformLedOn( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN ); - } -#endif /* PLATFORM_LED_FIELD_PIN */ - -#ifdef PLATFORM_LED_RX_PIN - if ((iregs[0] & ST25R3911_IRQ_MASK_RXS) != 0) - { - platformLedOn( PLATFORM_LED_RX_PORT, PLATFORM_LED_RX_PIN ); - } - if (((iregs[0] & ST25R3911_IRQ_MASK_RXE) != 0) || ((iregs[1] & (ST25R3911_IRQ_MASK_NRE >> 8)) != 0)) /* In rare cases there is rxs but not rxe, then we have nre */ - { - platformLedOff( PLATFORM_LED_RX_PORT, PLATFORM_LED_RX_PIN ); - } -#endif /* PLATFORM_LED_RX_PIN */ - - irqStatus |= (uint32_t)iregs[0]; - irqStatus |= (uint32_t)iregs[1]<<8; - irqStatus |= (uint32_t)iregs[2]<<16; - } - - /* Forward all interrupts, even masked ones to application. */ - platformProtectST25R391xIrqStatus(); - st25r3911interrupt.status |= irqStatus; - platformUnprotectST25R391xIrqStatus(); -} - - -void st25r3911ModifyInterrupts(uint32_t clr_mask, uint32_t set_mask) -{ - uint8_t i; - uint32_t old_mask; - uint32_t new_mask; - - old_mask = st25r3911interrupt.mask; - new_mask = (~old_mask & set_mask) | (old_mask & clr_mask); - st25r3911interrupt.mask &= ~clr_mask; - st25r3911interrupt.mask |= set_mask; - for (i=0; i<3U ; i++) - { - if (((new_mask >> (i*8U)) & 0xffU) == 0U) { - continue; - } - st25r3911WriteRegister((ST25R3911_REG_IRQ_MASK_MAIN + i), (uint8_t)((st25r3911interrupt.mask>>(i*8U))&0xffU)); - } - return; -} - - -uint32_t st25r3911WaitForInterruptsTimed(uint32_t mask, uint16_t tmo) -{ - uint32_t tmr; - uint32_t status; - - tmr = platformTimerCreate(tmo); - do - { - status = (st25r3911interrupt.status & mask); - } while( ( !platformTimerIsExpired( tmr ) || (tmo == 0U)) && (status == 0U) ); - - status = st25r3911interrupt.status & mask; - - platformProtectST25R391xIrqStatus(); - st25r3911interrupt.status &= ~status; - platformUnprotectST25R391xIrqStatus(); - - return status; -} - -uint32_t st25r3911GetInterrupt(uint32_t mask) -{ - uint32_t irqs; - - irqs = (st25r3911interrupt.status & mask); - if (irqs != ST25R3911_IRQ_MASK_NONE) - { - platformProtectST25R391xIrqStatus(); - st25r3911interrupt.status &= ~irqs; - platformUnprotectST25R391xIrqStatus(); - } - return irqs; -} - -void st25r3911EnableInterrupts(uint32_t mask) -{ - st25r3911ModifyInterrupts(mask,0); -} - -void st25r3911DisableInterrupts(uint32_t mask) -{ - st25r3911ModifyInterrupts(0,mask); -} - -void st25r3911ClearInterrupts( void ) -{ - uint8_t iregs[3]; - - st25r3911ReadMultipleRegisters(ST25R3911_REG_IRQ_MAIN, iregs, 3); - - platformProtectST25R391xIrqStatus(); - st25r3911interrupt.status = 0; - platformUnprotectST25R391xIrqStatus(); - return; -} - -void st25r3911IRQCallbackSet( void (*cb)(void) ) -{ - st25r3911interrupt.prevCallback = st25r3911interrupt.callback; - st25r3911interrupt.callback = cb; -} - -void st25r3911IRQCallbackRestore( void ) -{ - st25r3911interrupt.callback = st25r3911interrupt.prevCallback; - st25r3911interrupt.prevCallback = NULL; -} - diff --git a/Software/Drivers/BSP/Components/ST25R3911/st25r3911_interrupt.h b/Software/Drivers/BSP/Components/ST25R3911/st25r3911_interrupt.h deleted file mode 100644 index f133d3f..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/st25r3911_interrupt.h +++ /dev/null @@ -1,250 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R3911 firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Ulrich Herrmann - * - * \brief ST25R3911 Interrupt header file - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-HAL - * \brief RFAL Hardware Abstraction Layer - * @{ - * - * \addtogroup ST25R3911 - * \brief RFAL ST25R3911 Driver - * @{ - * - * \addtogroup ST25R3911_Interrupt - * \brief RFAL ST25R3911 Interrupt - * @{ - * - */ - -#ifndef ST25R3911_INTERRUPT_H -#define ST25R3911_INTERRUPT_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - -/* Main interrupt register. */ -#define ST25R3911_IRQ_MASK_ALL (uint32_t)(0xFFFFFFU) /*!< All ST25R3911 interrupt sources */ -#define ST25R3911_IRQ_MASK_NONE (uint32_t)(0U) /*!< No ST25R3911 interrupt source */ -#define ST25R3911_IRQ_MASK_OSC (uint32_t)(0x80U) /*!< ST25R3911 oscillator stable interrupt */ -#define ST25R3911_IRQ_MASK_FWL (uint32_t)(0x40U) /*!< ST25R3911 FIFO water level interrupt */ -#define ST25R3911_IRQ_MASK_RXS (uint32_t)(0x20U) /*!< ST25R3911 start of receive interrupt */ -#define ST25R3911_IRQ_MASK_RXE (uint32_t)(0x10U) /*!< ST25R3911 end of receive interrupt */ -#define ST25R3911_IRQ_MASK_TXE (uint32_t)(0x08U) /*!< ST25R3911 end of transmission interrupt */ -#define ST25R3911_IRQ_MASK_COL (uint32_t)(0x04U) /*!< ST25R3911 bit collision interrupt */ - -/* Timer and NFC interrupt register. */ -#define ST25R3911_IRQ_MASK_DCT (uint32_t)(0x8000U) /*!< ST25R3911 termination of direct command interrupt */ -#define ST25R3911_IRQ_MASK_NRE (uint32_t)(0x4000U) /*!< ST25R3911 no-response timer expired interrupt */ -#define ST25R3911_IRQ_MASK_GPE (uint32_t)(0x2000U) /*!< ST25R3911 general purpose timer expired interrupt */ -#define ST25R3911_IRQ_MASK_EON (uint32_t)(0x1000U) /*!< ST25R3911 external field on interrupt */ -#define ST25R3911_IRQ_MASK_EOF (uint32_t)(0x0800U) /*!< ST25R3911 external field off interrupt */ -#define ST25R3911_IRQ_MASK_CAC (uint32_t)(0x0400U) /*!< ST25R3911 collision during RF collision avoidance interrupt */ -#define ST25R3911_IRQ_MASK_CAT (uint32_t)(0x0200U) /*!< ST25R3911 minimum guard time expired interrupt */ -#define ST25R3911_IRQ_MASK_NFCT (uint32_t)(0x0100U) /*!< ST25R3911 initiator bit rate recognized interrupt */ - -/* Error and wake-up interrupt register. */ -#define ST25R3911_IRQ_MASK_CRC (uint32_t)(0x800000U) /*!< ST25R3911 CRC error interrupt */ -#define ST25R3911_IRQ_MASK_PAR (uint32_t)(0x400000U) /*!< ST25R3911 parity error interrupt */ -#define ST25R3911_IRQ_MASK_ERR2 (uint32_t)(0x200000U) /*!< ST25R3911 soft framing error interrupt */ -#define ST25R3911_IRQ_MASK_ERR1 (uint32_t)(0x100000U) /*!< ST25R3911 hard framing error interrupt */ -#define ST25R3911_IRQ_MASK_WT (uint32_t)(0x080000U) /*!< ST25R3911 wake-up interrupt */ -#define ST25R3911_IRQ_MASK_WAM (uint32_t)(0x040000U) /*!< ST25R3911 wake-up due to amplitude interrupt */ -#define ST25R3911_IRQ_MASK_WPH (uint32_t)(0x020000U) /*!< ST25R3911 wake-up due to phase interrupt */ -#define ST25R3911_IRQ_MASK_WCAP (uint32_t)(0x010000U) /*!< ST25R3911 wake-up due to capacitance measurement */ - - -#define ST25R3911_IRQ_MASK_TIM (0x02U) /*!< additional interrupts in ST25R3911_REG_IRQ_TIMER_NFC */ -#define ST25R3911_IRQ_MASK_ERR (0x01U) /*!< additional interrupts in ST25R3911_REG_IRQ_ERROR_WUP */ - - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - - -/*! - ***************************************************************************** - * \brief Wait until an ST25R3911 interrupt occurs - * - * This function is used to access the ST25R3911 interrupt flags. Use this - * to wait for max. \a tmo milliseconds for the \b first interrupt indicated - * with mask \a mask to occur. - * - * \param[in] mask : mask indicating the interrupts to wait for. - * \param[in] tmo : time in milliseconds until timeout occurs. If set to 0 - * the functions waits forever. - * - * \return : 0 if timeout occurred otherwise a mask indicating the cleared - * interrupts. - * - ***************************************************************************** - */ -extern uint32_t st25r3911WaitForInterruptsTimed(uint32_t mask, uint16_t tmo); - -/*! - ***************************************************************************** - * \brief Get status for the given interrupt - * - * This function is used to check whether the interrupt given by \a mask - * has occurred. If yes the interrupt gets cleared. This function returns - * only status bits which are inside \a mask. - * - * \param[in] mask : mask indicating the interrupt to check for. - * - * \return the mask of the interrupts occurred - * - ***************************************************************************** - */ -extern uint32_t st25r3911GetInterrupt(uint32_t mask); - - -/*! - ***************************************************************************** - * \brief Init the 3911 interrupt - * - * This function initiates the 3911 interrupts. - * - ***************************************************************************** - */ -extern void st25r3911InitInterrupts( void ); - - -/*! - ***************************************************************************** - * \brief Modifies the Interrupt - * - * This function modifies the interrupt - * - * \param[in] clr_mask : bit mask to be cleared on the interrupt mask - * \param[in] set_mask : bit mask to be set on the interrupt mask - ***************************************************************************** - */ -extern void st25r3911ModifyInterrupts(uint32_t clr_mask, uint32_t set_mask); - - -/*! - ***************************************************************************** - * \brief Checks received interrupts - * - * Checks received interrupts and saves the result into global params - ***************************************************************************** - */ -extern void st25r3911CheckForReceivedInterrupts( void ); - - -/*! - ***************************************************************************** - * \brief ISR Service routine - * - * This function modifies the interrupt - ***************************************************************************** - */ -extern void st25r3911Isr( void ); - -/*! - ***************************************************************************** - * \brief Enable a given ST25R3911 Interrupt source - * - * This function enables all interrupts given by \a mask, - * ST25R3911_IRQ_MASK_ALL enables all interrupts. - * - * \param[in] mask: mask indicating the interrupts to be enabled - * - ***************************************************************************** - */ -extern void st25r3911EnableInterrupts(uint32_t mask); - -/*! - ***************************************************************************** - * \brief Disable one or more a given ST25R3911 Interrupt sources - * - * This function disables all interrupts given by \a mask. 0xff disables all. - * - * \param[in] mask: mask indicating the interrupts to be disabled. - * - ***************************************************************************** - */ -extern void st25r3911DisableInterrupts(uint32_t mask); - -/*! - ***************************************************************************** - * \brief Clear all st25r3911 irq flags - * - ***************************************************************************** - */ -extern void st25r3911ClearInterrupts(void); - -/*! - ***************************************************************************** - * \brief Sets IRQ callback for the ST25R3911 interrupt - * - ***************************************************************************** - */ -extern void st25r3911IRQCallbackSet(void (*cb)(void)); - -/*! - ***************************************************************************** - * \brief Sets IRQ callback for the ST25R3911 interrupt - * - ***************************************************************************** - */ -extern void st25r3911IRQCallbackRestore(void); - -#endif /* ST25R3911_ISR_H */ - -/** - * @} - * - * @} - * - * @} - * - * @} - */ diff --git a/Software/Drivers/BSP/Components/ST25R3911/st_errno.h b/Software/Drivers/BSP/Components/ST25R3911/st_errno.h deleted file mode 100644 index e3f051d..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/st_errno.h +++ /dev/null @@ -1,165 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: STxxxx firmware - * LANGUAGE: ISO C99 - */ - -/*! \file st_errno.h - * - * \author - * - * \brief Main error codes - * - */ - -#ifndef ST_ERRNO_H -#define ST_ERRNO_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ - - -/* -****************************************************************************** -* GLOBAL DATA TYPES -****************************************************************************** -*/ - -typedef uint16_t ReturnCode; /*!< Standard Return Code type from function. */ - -/* -****************************************************************************** -* DEFINES -****************************************************************************** -*/ - - -/* - * Error codes to be used within the application. - * They are represented by an uint8_t - */ - -#define ERR_NONE ((ReturnCode)0U) /*!< no error occurred */ -#define ERR_NOMEM ((ReturnCode)1U) /*!< not enough memory to perform the requested operation */ -#define ERR_BUSY ((ReturnCode)2U) /*!< device or resource busy */ -#define ERR_IO ((ReturnCode)3U) /*!< generic IO error */ -#define ERR_TIMEOUT ((ReturnCode)4U) /*!< error due to timeout */ -#define ERR_REQUEST ((ReturnCode)5U) /*!< invalid request or requested function can't be executed at the moment */ -#define ERR_NOMSG ((ReturnCode)6U) /*!< No message of desired type */ -#define ERR_PARAM ((ReturnCode)7U) /*!< Parameter error */ -#define ERR_SYSTEM ((ReturnCode)8U) /*!< System error */ -#define ERR_FRAMING ((ReturnCode)9U) /*!< Framing error */ -#define ERR_OVERRUN ((ReturnCode)10U) /*!< lost one or more received bytes */ -#define ERR_PROTO ((ReturnCode)11U) /*!< protocol error */ -#define ERR_INTERNAL ((ReturnCode)12U) /*!< Internal Error */ -#define ERR_AGAIN ((ReturnCode)13U) /*!< Call again */ -#define ERR_MEM_CORRUPT ((ReturnCode)14U) /*!< memory corruption */ -#define ERR_NOT_IMPLEMENTED ((ReturnCode)15U) /*!< not implemented */ -#define ERR_PC_CORRUPT ((ReturnCode)16U) /*!< Program Counter has been manipulated or spike/noise trigger illegal operation */ -#define ERR_SEND ((ReturnCode)17U) /*!< error sending*/ -#define ERR_IGNORE ((ReturnCode)18U) /*!< indicates error detected but to be ignored */ -#define ERR_SEMANTIC ((ReturnCode)19U) /*!< indicates error in state machine (unexpected cmd) */ -#define ERR_SYNTAX ((ReturnCode)20U) /*!< indicates error in state machine (unknown cmd) */ -#define ERR_CRC ((ReturnCode)21U) /*!< crc error */ -#define ERR_NOTFOUND ((ReturnCode)22U) /*!< transponder not found */ -#define ERR_NOTUNIQUE ((ReturnCode)23U) /*!< transponder not unique - more than one transponder in field */ -#define ERR_NOTSUPP ((ReturnCode)24U) /*!< requested operation not supported */ -#define ERR_WRITE ((ReturnCode)25U) /*!< write error */ -#define ERR_FIFO ((ReturnCode)26U) /*!< fifo over or underflow error */ -#define ERR_PAR ((ReturnCode)27U) /*!< parity error */ -#define ERR_DONE ((ReturnCode)28U) /*!< transfer has already finished */ -#define ERR_RF_COLLISION ((ReturnCode)29U) /*!< collision error (Bit Collision or during RF Collision avoidance ) */ -#define ERR_HW_OVERRUN ((ReturnCode)30U) /*!< lost one or more received bytes */ -#define ERR_RELEASE_REQ ((ReturnCode)31U) /*!< device requested release */ -#define ERR_SLEEP_REQ ((ReturnCode)32U) /*!< device requested sleep */ -#define ERR_WRONG_STATE ((ReturnCode)33U) /*!< incorrent state for requested operation */ -#define ERR_MAX_RERUNS ((ReturnCode)34U) /*!< blocking procedure reached maximum runs */ -#define ERR_DISABLED ((ReturnCode)35U) /*!< operation aborted due to disabled configuration */ -#define ERR_HW_MISMATCH ((ReturnCode)36U) /*!< expected hw do not match */ -#define ERR_LINK_LOSS ((ReturnCode)37U) /*!< Other device's field didn't behave as expected: turned off by Initiator in Passive mode, or AP2P did not turn on field */ -#define ERR_INVALID_HANDLE ((ReturnCode)38U) /*!< invalid or not initalized device handle */ - -#define ERR_INCOMPLETE_BYTE ((ReturnCode)40U) /*!< Incomplete byte rcvd */ -#define ERR_INCOMPLETE_BYTE_01 ((ReturnCode)41U) /*!< Incomplete byte rcvd - 1 bit */ -#define ERR_INCOMPLETE_BYTE_02 ((ReturnCode)42U) /*!< Incomplete byte rcvd - 2 bit */ -#define ERR_INCOMPLETE_BYTE_03 ((ReturnCode)43U) /*!< Incomplete byte rcvd - 3 bit */ -#define ERR_INCOMPLETE_BYTE_04 ((ReturnCode)44U) /*!< Incomplete byte rcvd - 4 bit */ -#define ERR_INCOMPLETE_BYTE_05 ((ReturnCode)45U) /*!< Incomplete byte rcvd - 5 bit */ -#define ERR_INCOMPLETE_BYTE_06 ((ReturnCode)46U) /*!< Incomplete byte rcvd - 6 bit */ -#define ERR_INCOMPLETE_BYTE_07 ((ReturnCode)47U) /*!< Incomplete byte rcvd - 7 bit */ - - - - -/* General Sub-category number */ -#define ERR_GENERIC_GRP (0x0000) /*!< Reserved value for generic error no */ -#define ERR_WARN_GRP (0x0100) /*!< Errors which are not expected in normal operation */ -#define ERR_PROCESS_GRP (0x0200) /*!< Processes management errors */ -#define ERR_SIO_GRP (0x0800) /*!< SIO errors due to logging */ -#define ERR_RINGBUF_GRP (0x0900) /*!< Ring Buffer errors */ -#define ERR_MQ_GRP (0x0A00) /*!< MQ errors */ -#define ERR_TIMER_GRP (0x0B00) /*!< Timer errors */ -#define ERR_RFAL_GRP (0x0C00) /*!< RFAL errors */ -#define ERR_UART_GRP (0x0D00) /*!< UART errors */ -#define ERR_SPI_GRP (0x0E00) /*!< SPI errors */ -#define ERR_I2C_GRP (0x0F00) /*!< I2c errors */ - - -#define ERR_INSERT_SIO_GRP(x) (ERR_SIO_GRP | (x)) /*!< Insert the SIO grp */ -#define ERR_INSERT_RINGBUF_GRP(x) (ERR_RINGBUF_GRP | (x)) /*!< Insert the Ring Buffer grp */ -#define ERR_INSERT_RFAL_GRP(x) (ERR_RFAL_GRP | (x)) /*!< Insert the RFAL grp */ -#define ERR_INSERT_SPI_GRP(x) (ERR_SPI_GRP | (x)) /*!< Insert the spi grp */ -#define ERR_INSERT_I2C_GRP(x) (ERR_I2C_GRP | (x)) /*!< Insert the i2c grp */ -#define ERR_INSERT_UART_GRP(x) (ERR_UART_GRP | (x)) /*!< Insert the uart grp */ -#define ERR_INSERT_TIMER_GRP(x) (ERR_TIMER_GRP | (x)) /*!< Insert the timer grp */ -#define ERR_INSERT_MQ_GRP(x) (ERR_MQ_GRP | (x)) /*!< Insert the mq grp */ -#define ERR_INSERT_PROCESS_GRP(x) (ERR_PROCESS_GRP | (x)) /*!< Insert the process grp */ -#define ERR_INSERT_WARN_GRP(x) (ERR_WARN_GRP | (x)) /*!< Insert the i2c grp */ -#define ERR_INSERT_GENERIC_GRP(x) (ERR_GENERIC_GRP | (x)) /*!< Insert the generic grp */ - - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - -#define ERR_NO_MASK(x) ((uint16_t)(x) & 0x00FFU) /*!< Mask the error number */ - - - -/*! Common code to exit a function with the error if function f return error */ -#define EXIT_ON_ERR(r, f) \ - (r) = (f); \ - if (ERR_NONE != (r)) \ - { \ - return (r); \ - } - -#endif /* ST_ERRNO_H */ - diff --git a/Software/Drivers/BSP/Components/ST25R3911/timer.c b/Software/Drivers/BSP/Components/ST25R3911/timer.c deleted file mode 100644 index b13c7a5..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/timer.c +++ /dev/null @@ -1,121 +0,0 @@ -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/* - * PROJECT: ST25R391x firmware - * $Revision: $ - * LANGUAGE: ANSI C - */ - -/*! \file timer.c - * - * \brief SW Timer implementation - * - * \author Gustavo Patricio - * - * This module makes use of a System Tick in millisconds and provides - * an abstraction for SW timers - * - */ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "timer.h" - - -/* -****************************************************************************** -* LOCAL DEFINES -****************************************************************************** -*/ - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ - -static uint32_t timerStopwatchTick; - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - - -/*******************************************************************************/ -uint32_t timerCalculateTimer( uint16_t time ) -{ - return (platformGetSysTick() + time); -} - - -/*******************************************************************************/ -bool timerIsExpired( uint32_t timer ) -{ - uint32_t uDiff; - int32_t sDiff; - - uDiff = (timer - platformGetSysTick()); /* Calculate the diff between the timers */ - sDiff = uDiff; /* Convert the diff to a signed var */ - /* Having done this has two side effects: - * 1) all differences smaller than -(2^31) ms (~25d) will become positive - * Signaling not expired: acceptable! - * 2) Time roll-over case will be handled correctly: super! - */ - - /* Check if the given timer has expired already */ - if( sDiff < 0 ) - { - return true; - } - - return false; -} - - -/*******************************************************************************/ -void timerDelay( uint16_t tOut ) -{ - uint32_t t; - - /* Calculate the timer and wait blocking until is running */ - t = timerCalculateTimer( tOut ); - while( timerIsRunning(t) ); -} - - -/*******************************************************************************/ -void timerStopwatchStart( void ) -{ - timerStopwatchTick = platformGetSysTick(); -} - - -/*******************************************************************************/ -uint32_t timerStopwatchMeasure( void ) -{ - return (uint32_t)(platformGetSysTick() - timerStopwatchTick); -} - diff --git a/Software/Drivers/BSP/Components/ST25R3911/timer.h b/Software/Drivers/BSP/Components/ST25R3911/timer.h deleted file mode 100644 index 4446d45..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/timer.h +++ /dev/null @@ -1,128 +0,0 @@ -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/* - * PROJECT: ST25R391x firmware - * $Revision: $ - * LANGUAGE: ANSI C - */ - -/*! \file timer.h - * - * \brief SW Timer implementation header file - * - * This module makes use of a System Tick in millisconds and provides - * an abstraction for SW timers - * - */ - - - /* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ -#define timerIsRunning(t) (!timerIsExpired(t)) - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - - /*! - ***************************************************************************** - * \brief Calculate Timer - * - * This method calculates when the timer will be expired given the amount - * time in milliseconds /a tOut. - * Once the timer has been calculated it will then be used to check when - * it expires. - * - * \see timersIsExpired - * - * \param[in] time : time/duration in Milliseconds for the timer - * - * \return u32 : The new timer calculated based on the given time - ***************************************************************************** - */ -uint32_t timerCalculateTimer( uint16_t time ); - - -/*! - ***************************************************************************** - * \brief Checks if a Timer is Expired - * - * This method checks if a timer has already expired. - * Based on the given timer previously calculated it checks if this timer - * has already elapsed - * - * \see timersCalculateTimer - * - * \param[in] timer : the timer to check - * - * \return true : timer has already expired - * \return false : timer is still running - ***************************************************************************** - */ -bool timerIsExpired( uint32_t timer ); - - - /*! - ***************************************************************************** - * \brief Performs a Delay - * - * This method performs a delay for the given amount of time in Milliseconds - * - * \param[in] time : time/duration in Milliseconds of the delay - * - ***************************************************************************** - */ -void timerDelay( uint16_t time ); - - -/*! - ***************************************************************************** - * \brief Stopwatch start - * - * This method initiates the stopwatch to later measure the time in ms - * - ***************************************************************************** - */ -void timerStopwatchStart( void ); - - -/*! - ***************************************************************************** - * \brief Stopwatch Measure - * - * This method returns the elapsed time in ms since the stopwatch was initiated - * - * \return The time in ms since the stopwatch was started - ***************************************************************************** - */ -uint32_t timerStopwatchMeasure( void ); diff --git a/Software/Drivers/BSP/Components/ST25R3911/utils.h b/Software/Drivers/BSP/Components/ST25R3911/utils.h deleted file mode 100644 index ba16770..0000000 --- a/Software/Drivers/BSP/Components/ST25R3911/utils.h +++ /dev/null @@ -1,111 +0,0 @@ - -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: NFCC firmware - * $Revision: $ - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Ulrich Herrmann - * - * \brief Common and helpful macros - * - */ - -#ifndef UTILS_H -#define UTILS_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ -/*! - * this macro evaluates an error variable \a ERR against an error code \a EC. - * in case it is not equal it jumps to the given label \a LABEL. - */ -#define EVAL_ERR_NE_GOTO(EC, ERR, LABEL) \ - if ((EC) != (ERR)) goto LABEL; - -/*! - * this macro evaluates an error variable \a ERR against an error code \a EC. - * in case it is equal it jumps to the given label \a LABEL. - */ -#define EVAL_ERR_EQ_GOTO(EC, ERR, LABEL) \ - if ((EC) == (ERR)) goto LABEL; - -#define SIZEOF_ARRAY(a) (sizeof(a) / sizeof((a)[0])) /*!< Compute the size of an array */ -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) /*!< Return the maximum of the 2 values */ -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) /*!< Return the minimum of the 2 values */ -#define BITMASK_1 (0x01) /*!< Bit mask for lsb bit */ -#define BITMASK_2 (0x03) /*!< Bit mask for two lsb bits */ -#define BITMASK_3 (0x07) /*!< Bit mask for three lsb bits */ -#define BITMASK_4 (0x0F) /*!< Bit mask for four lsb bits */ -#define U16TOU8(a) ((a) & 0x00FF) /*!< Cast 16-bit unsigned to 8-bit unsigned */ -#define GETU16(a) (((uint16_t)(a)[0] << 8) | (uint16_t)(a)[1])/*!< Cast two Big Endian 8-bits byte array to 16-bits unsigned */ -#define GETU32(a) (((uint32_t)(a)[0] << 24) | ((uint32_t)(a)[1] << 16) | ((uint32_t)(a)[2] << 8) | ((uint32_t)(a)[3])) /*!< Cast four Big Endian 8-bit byte array to 32-bit unsigned */ - -#define REVERSE_BYTES(pData, nDataSize) \ - {unsigned char swap, *lo = ((unsigned char *)(pData)), *hi = ((unsigned char *)(pData)) + (nDataSize) - 1; \ - while (lo < hi) { swap = *lo; *lo++ = *hi; *hi-- = swap; }} - -#ifdef __CSMC__ -/* STM8 COSMIC */ -#define ST_MEMMOVE(s1,s2,n) memmove(s1,s2,n) /*!< map memmove to string library code */ -static inline void * ST_MEMCPY(void *s1, const void *s2, uint32_t n) { return memcpy(s1,s2,(uint16_t)n); } /* PRQA S 0431 # MISRA 1.1 - string.h from Cosmic only provides functions with low qualified parameters */ -#define ST_MEMSET(s1,c,n) memset(s1,(char)(c),n) /*!< map memset to string library code */ -static inline int32_t ST_BYTECMP(void *s1, const void *s2, uint32_t n) { return (int32_t)memcmp(s1,s2,(uint16_t)n); } /* PRQA S 0431 # MISRA 1.1 - string.h from Cosmic only provides functions with low qualified parameters */ - -#else /* __CSMC__ */ - -#define ST_MEMMOVE memmove /*!< map memmove to string library code */ -#define ST_MEMCPY memcpy /*!< map memcpy to string library code */ -#define ST_MEMSET memset /*!< map memset to string library code */ -#define ST_BYTECMP memcmp /*!< map bytecmp to string library code */ -#endif /* __CSMC__ */ - -#define NO_WARNING(v) ((void) (v)) /*!< Macro to suppress compiler warning */ - - -#ifndef NULL - #define NULL (void*)0 /*!< represents a NULL pointer */ -#endif /* !NULL */ - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -#endif /* UTILS_H */ - diff --git a/Software/Drivers/BSP/NFC05A1/Release_Notes.html b/Software/Drivers/BSP/NFC05A1/Release_Notes.html deleted file mode 100644 index 14c714d..0000000 --- a/Software/Drivers/BSP/NFC05A1/Release_Notes.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - - - - - - - Release Notes for X-NUCLEO-NFC03A1 STM32 Expansion Board - - - - - - - - - - -
-


-

-
- - - - - - -
- - - - - - - - - -
-

Back to Release page

-
-

Release -Notes for X-NUCLEO-NFC05A1 STM32 Expansion Board

-

Copyright -2017 STMicroelectronics

-

-
-

 

- - - - - - -
- -

Update -History

- -

V1.0.0 -/ 15-March-2017

-

Main -Changes

- - - - - -
    -
  • First -official release.
  • -
- -

License
-

-
Redistribution -and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met:
-
-
    -
  1. Redistributions -of source code must retain the above copyright notice, this list of -conditions and the following disclaimer.
  2. -
  3. Redistributions -in binary form must reproduce the above copyright notice, this list of -conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution.
  4. -
  5. Neither the -name of STMicroelectronics nor the names of its contributors may be -used to endorse or promote products derived
    -
  6. -
-        -from this software without specific prior written permission.
-
- THIS -SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -THE POSSIBILITY OF SUCH DAMAGE.
-

- -
-
-

For -complete documentation on STM32 Microcontrollers -visit www.st.com/STM32

-
-

-
-
-

 

-
- - \ No newline at end of file diff --git a/Software/Drivers/BSP/NFC05A1/led.c b/Software/Drivers/BSP/NFC05A1/led.c deleted file mode 100644 index 27c80fc..0000000 --- a/Software/Drivers/BSP/NFC05A1/led.c +++ /dev/null @@ -1,145 +0,0 @@ -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/* - * PROJECT: ST25R3911 firmware - * $Revision: $ - * LANGUAGE: ANSI C - */ - -/*! \file - * - * \author - * - * \brief Implementation for controlling shield LEDs functionality - * - */ - -/*! - * - */ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#ifdef STM32L476xx -#include "stm32l4xx.h" -#else -#include "stm32f4xx.h" -#endif - -#include "led.h" -#include "main.h" - -volatile uint16_t msLedA = 0; -volatile uint16_t msLedB = 0; -volatile uint16_t msLedF = 0; -volatile uint16_t msLedV = 0; -volatile uint16_t msLedAP2P = 0; - -void ledOn(st25R3911Led_t Led) -{ - switch(Led){ - case LED_A: HAL_GPIO_WritePin(LED_A_GPIO_Port , LED_A_Pin , GPIO_PIN_SET); break; - case LED_B: HAL_GPIO_WritePin(LED_B_GPIO_Port , LED_B_Pin , GPIO_PIN_SET); break; - case LED_F: HAL_GPIO_WritePin(LED_F_GPIO_Port , LED_F_Pin , GPIO_PIN_SET); break; - case LED_V: HAL_GPIO_WritePin(LED_V_GPIO_Port , LED_V_Pin , GPIO_PIN_SET); break; - case LED_AP2P: HAL_GPIO_WritePin(LED_AP2P_GPIO_Port , LED_AP2P_Pin , GPIO_PIN_SET); break; - default: - break; - } -} - -void ledOff(st25R3911Led_t Led) -{ - switch(Led){ - case LED_A: HAL_GPIO_WritePin(LED_A_GPIO_Port , LED_A_Pin , GPIO_PIN_RESET); break; - case LED_B: HAL_GPIO_WritePin(LED_B_GPIO_Port , LED_B_Pin , GPIO_PIN_RESET); break; - case LED_F: HAL_GPIO_WritePin(LED_F_GPIO_Port , LED_F_Pin , GPIO_PIN_RESET); break; - case LED_V: HAL_GPIO_WritePin(LED_V_GPIO_Port , LED_V_Pin , GPIO_PIN_RESET); break; - case LED_AP2P: HAL_GPIO_WritePin(LED_AP2P_GPIO_Port , LED_AP2P_Pin , GPIO_PIN_RESET); break; - default: - break; - } -} - -void ledToggle(st25R3911Led_t Led) -{ - switch(Led){ - case LED_A: HAL_GPIO_TogglePin(LED_A_GPIO_Port , LED_A_Pin ); break; - case LED_B: HAL_GPIO_TogglePin(LED_B_GPIO_Port , LED_B_Pin ); break; - case LED_F: HAL_GPIO_TogglePin(LED_F_GPIO_Port , LED_F_Pin ); break; - case LED_V: HAL_GPIO_TogglePin(LED_V_GPIO_Port , LED_V_Pin ); break; - case LED_AP2P: HAL_GPIO_TogglePin(LED_AP2P_GPIO_Port , LED_AP2P_Pin ); break; - default: - break; - } -} - - - -void ledOnOff(st25R3911Led_t Led, uint32_t delay) -{ - ledOn(Led); - - switch(Led){ - case LED_A: msLedA = delay; break; - case LED_B: msLedB = delay; break; - case LED_F: msLedF = delay; break; - case LED_V: msLedV = delay; break; - case LED_AP2P: msLedAP2P = delay; break; - default: - break; - } -} -void ledFeedbackHandler() -{ - if(msLedA > 0){ - msLedA--; - if(msLedA == 0) - ledOff(LED_A); - } - - if(msLedB > 0){ - msLedB--; - if(msLedB == 0) - ledOff(LED_B); - } - - if(msLedF > 0){ - msLedF--; - if(msLedF == 0) - ledOff(LED_F); - } - - if(msLedV > 0){ - msLedV--; - if(msLedV == 0) - ledOff(LED_V); - } - - if(msLedAP2P > 0){ - msLedAP2P--; - if(msLedAP2P == 0) - ledOff(LED_AP2P); - } -} diff --git a/Software/Drivers/BSP/NFC05A1/led.h b/Software/Drivers/BSP/NFC05A1/led.h deleted file mode 100644 index f077431..0000000 --- a/Software/Drivers/BSP/NFC05A1/led.h +++ /dev/null @@ -1,81 +0,0 @@ -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/* - * PROJECT: ST25R3911 firmware - * $Revision: $ - * LANGUAGE: ANSI C - */ - -/*! \file - * - * \author - * - * \brief Module for controlling shield LEDs - * - */ -/*! - * - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef LED_H -#define LED_H - -/* Includes ------------------------------------------------------------------*/ -#include "stdint.h" - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ -extern volatile uint16_t msLedA; -extern volatile uint16_t msLedB; -extern volatile uint16_t msLedF; -extern volatile uint16_t msLedV; -extern volatile uint16_t msLedAP2P; - - -typedef enum -{ - LED_A = 0x1, - LED_B = 0x2, - LED_F = 0x3, - LED_V = 0x4, - LED_AP2P = 0x5, -}st25R3911Led_t; - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - -void ledOn(st25R3911Led_t Led); -void ledOff(st25R3911Led_t Led); -void ledToggle(st25R3911Led_t Led); - -#define VISUAL_FEEDBACK_DELAY 600 -void ledOnOff(st25R3911Led_t Led, uint32_t delay); -void ledFeedbackHandler(void); - -#endif /* LED_H */ - diff --git a/Software/Drivers/CMSIS/Include/cmsis_armcc.h b/Software/Drivers/CMSIS/Include/cmsis_armcc.h deleted file mode 100644 index f2bb66a..0000000 --- a/Software/Drivers/CMSIS/Include/cmsis_armcc.h +++ /dev/null @@ -1,734 +0,0 @@ -/**************************************************************************//** - * @file cmsis_armcc.h - * @brief CMSIS Cortex-M Core Function/Instruction Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#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 - -/* ########################### Core Function Access ########################### */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions - @{ - */ - -/* intrinsic void __enable_irq(); */ -/* 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 (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) - -/** - \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)1); -} - -#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */ - - -#if (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) - -/** - \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 (__FPU_PRESENT == 1U) && (__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 (__FPU_PRESENT == 1U) && (__FPU_USED == 1U) - register uint32_t __regfpscr __ASM("fpscr"); - __regfpscr = (fpscr); -#endif -} - -#endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */ - - - -/*@} 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() do {\ - __schedule_barrier();\ - __isb(0xF);\ - __schedule_barrier();\ - } while (0U) - -/** - \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() do {\ - __schedule_barrier();\ - __dsb(0xF);\ - __schedule_barrier();\ - } while (0U) - -/** - \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() do {\ - __schedule_barrier();\ - __dmb(0xF);\ - __schedule_barrier();\ - } while (0U) - -/** - \brief Reverse byte order (32 bit) - \details Reverses the byte order in integer value. - \param [in] value Value to reverse - \return Reversed value - */ -#define __REV __rev - - -/** - \brief Reverse byte order (16 bit) - \details Reverses the byte order in two unsigned short values. - \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 in signed short value - \details Reverses the byte order in a signed short value with sign extension to integer. - \param [in] value Value to reverse - \return Reversed value - */ -#ifndef __NO_EMBEDDED_ASM -__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_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] value Value to rotate - \param [in] value 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 (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) - #define __RBIT __rbit -#else -__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) -{ - uint32_t result; - int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */ - - result = value; /* r will be reversed bits of v; first get LSB of v */ - for (value >>= 1U; value; 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 (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) - -/** - \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) - -#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */ - -/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ - - -/* ################### Compiler specific Intrinsics ########################### */ -/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics - Access to dedicated SIMD instructions - @{ -*/ - -#if (__CORTEX_M >= 0x04U) /* only for Cortex-M4 and above */ - -#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)) - -#endif /* (__CORTEX_M >= 0x04) */ -/*@} end of group CMSIS_SIMD_intrinsics */ - - -#endif /* __CMSIS_ARMCC_H */ diff --git a/Software/Drivers/CMSIS/Include/cmsis_gcc.h b/Software/Drivers/CMSIS/Include/cmsis_gcc.h deleted file mode 100644 index d868f2e..0000000 --- a/Software/Drivers/CMSIS/Include/cmsis_gcc.h +++ /dev/null @@ -1,1373 +0,0 @@ -/**************************************************************************//** - * @file cmsis_gcc.h - * @brief CMSIS Cortex-M Core Function/Instruction Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#ifndef __CMSIS_GCC_H -#define __CMSIS_GCC_H - -/* ignore some GCC warnings */ -#if defined ( __GNUC__ ) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wconversion" -#pragma GCC diagnostic ignored "-Wunused-parameter" -#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. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void) -{ - __ASM volatile ("cpsie i" : : : "memory"); -} - - -/** - \brief Disable IRQ Interrupts - \details Disables IRQ interrupts by setting the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void) -{ - __ASM volatile ("cpsid i" : : : "memory"); -} - - -/** - \brief Get Control Register - \details Returns the content of the Control Register. - \return Control Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, control" : "=r" (result) ); - return(result); -} - - -/** - \brief Set Control Register - \details Writes the given value to the Control Register. - \param [in] control Control Register value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control) -{ - __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); -} - - -/** - \brief Get IPSR Register - \details Returns the content of the IPSR Register. - \return IPSR Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); - return(result); -} - - -/** - \brief Get APSR Register - \details Returns the content of the APSR Register. - \return APSR Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, apsr" : "=r" (result) ); - return(result); -} - - -/** - \brief Get xPSR Register - \details Returns the content of the xPSR Register. - - \return xPSR Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); - return(result); -} - - -/** - \brief Get Process Stack Pointer - \details Returns the current value of the Process Stack Pointer (PSP). - \return PSP Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void) -{ - register uint32_t result; - - __ASM volatile ("MRS %0, psp\n" : "=r" (result) ); - return(result); -} - - -/** - \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 - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp"); -} - - -/** - \brief Get Main Stack Pointer - \details Returns the current value of the Main Stack Pointer (MSP). - \return MSP Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void) -{ - register uint32_t result; - - __ASM volatile ("MRS %0, msp\n" : "=r" (result) ); - return(result); -} - - -/** - \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 - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp"); -} - - -/** - \brief Get Priority Mask - \details Returns the current state of the priority mask bit from the Priority Mask Register. - \return Priority Mask value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, primask" : "=r" (result) ); - return(result); -} - - -/** - \brief Set Priority Mask - \details Assigns the given value to the Priority Mask Register. - \param [in] priMask Priority Mask - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask) -{ - __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); -} - - -#if (__CORTEX_M >= 0x03U) - -/** - \brief Enable FIQ - \details Enables FIQ interrupts by clearing the F-bit in the CPSR. - Can only be executed in Privileged modes. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void) -{ - __ASM volatile ("cpsie f" : : : "memory"); -} - - -/** - \brief Disable FIQ - \details Disables FIQ interrupts by setting the F-bit in the CPSR. - Can only be executed in Privileged modes. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void) -{ - __ASM volatile ("cpsid f" : : : "memory"); -} - - -/** - \brief Get Base Priority - \details Returns the current value of the Base Priority register. - \return Base Priority register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, basepri" : "=r" (result) ); - return(result); -} - - -/** - \brief Set Base Priority - \details Assigns the given value to the Base Priority register. - \param [in] basePri Base Priority value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value) -{ - __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory"); -} - - -/** - \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 - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t value) -{ - __ASM volatile ("MSR basepri_max, %0" : : "r" (value) : "memory"); -} - - -/** - \brief Get Fault Mask - \details Returns the current value of the Fault Mask register. - \return Fault Mask register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); - return(result); -} - - -/** - \brief Set Fault Mask - \details Assigns the given value to the Fault Mask register. - \param [in] faultMask Fault Mask value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) -{ - __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); -} - -#endif /* (__CORTEX_M >= 0x03U) */ - - -#if (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) - -/** - \brief Get FPSCR - \details Returns the current value of the Floating Point Status/Control register. - \return Floating Point Status/Control register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void) -{ -#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U) - uint32_t result; - - /* Empty asm statement works as a scheduling barrier */ - __ASM volatile (""); - __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); - __ASM volatile (""); - return(result); -#else - return(0); -#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 - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) -{ -#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U) - /* Empty asm statement works as a scheduling barrier */ - __ASM volatile (""); - __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc"); - __ASM volatile (""); -#endif -} - -#endif /* (__CORTEX_M == 0x04U) || (__CORTEX_M == 0x07U) */ - - - -/*@} end of CMSIS_Core_RegAccFunctions */ - - -/* ########################## Core Instruction Access ######################### */ -/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface - Access to dedicated instructions - @{ -*/ - -/* Define macros for porting to both thumb1 and thumb2. - * For thumb1, use low register (r0-r7), specified by constraint "l" - * Otherwise, use general registers, specified by constraint "r" */ -#if defined (__thumb__) && !defined (__thumb2__) -#define __CMSIS_GCC_OUT_REG(r) "=l" (r) -#define __CMSIS_GCC_USE_REG(r) "l" (r) -#else -#define __CMSIS_GCC_OUT_REG(r) "=r" (r) -#define __CMSIS_GCC_USE_REG(r) "r" (r) -#endif - -/** - \brief No Operation - \details No Operation does nothing. This instruction can be used for code alignment purposes. - */ -__attribute__((always_inline)) __STATIC_INLINE void __NOP(void) -{ - __ASM volatile ("nop"); -} - - -/** - \brief Wait For Interrupt - \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs. - */ -__attribute__((always_inline)) __STATIC_INLINE void __WFI(void) -{ - __ASM volatile ("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. - */ -__attribute__((always_inline)) __STATIC_INLINE void __WFE(void) -{ - __ASM volatile ("wfe"); -} - - -/** - \brief Send Event - \details Send Event is a hint instruction. It causes an event to be signaled to the CPU. - */ -__attribute__((always_inline)) __STATIC_INLINE void __SEV(void) -{ - __ASM volatile ("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. - */ -__attribute__((always_inline)) __STATIC_INLINE void __ISB(void) -{ - __ASM volatile ("isb 0xF":::"memory"); -} - - -/** - \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. - */ -__attribute__((always_inline)) __STATIC_INLINE void __DSB(void) -{ - __ASM volatile ("dsb 0xF":::"memory"); -} - - -/** - \brief Data Memory Barrier - \details Ensures the apparent order of the explicit memory operations before - and after the instruction, without ensuring their completion. - */ -__attribute__((always_inline)) __STATIC_INLINE void __DMB(void) -{ - __ASM volatile ("dmb 0xF":::"memory"); -} - - -/** - \brief Reverse byte order (32 bit) - \details Reverses the byte order in integer value. - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __REV(uint32_t value) -{ -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) - return __builtin_bswap32(value); -#else - uint32_t result; - - __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); -#endif -} - - -/** - \brief Reverse byte order (16 bit) - \details Reverses the byte order in two unsigned short values. - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __REV16(uint32_t value) -{ - uint32_t result; - - __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); -} - - -/** - \brief Reverse byte order in signed short value - \details Reverses the byte order in a signed short value with sign extension to integer. - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__((always_inline)) __STATIC_INLINE int32_t __REVSH(int32_t value) -{ -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - return (short)__builtin_bswap16(value); -#else - int32_t result; - - __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); -#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] value Value to rotate - \param [in] value Number of Bits to rotate - \return Rotated value - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2) -{ - return (op1 >> op2) | (op1 << (32U - op2)); -} - - -/** - \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) __ASM volatile ("bkpt "#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 - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) -{ - uint32_t result; - -#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) - __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); -#else - int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */ - - result = value; /* r will be reversed bits of v; first get LSB of v */ - for (value >>= 1U; value; value >>= 1U) - { - result <<= 1U; - result |= value & 1U; - s--; - } - result <<= s; /* shift when v's highest bits are zero */ -#endif - return(result); -} - - -/** - \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 __builtin_clz - - -#if (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) - -/** - \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) - */ -__attribute__((always_inline)) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr) -{ - uint32_t result; - -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) ); -#else - /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not - accepted by assembler. So has to use following less efficient pattern. - */ - __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); -#endif - return ((uint8_t) result); /* Add explicit type cast here */ -} - - -/** - \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) - */ -__attribute__((always_inline)) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr) -{ - uint32_t result; - -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) ); -#else - /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not - accepted by assembler. So has to use following less efficient pattern. - */ - __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); -#endif - return ((uint16_t) result); /* Add explicit type cast here */ -} - - -/** - \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) - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr) -{ - uint32_t result; - - __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) ); - return(result); -} - - -/** - \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 - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) -{ - uint32_t result; - - __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); - return(result); -} - - -/** - \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 - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) -{ - uint32_t result; - - __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); - return(result); -} - - -/** - \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 - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) -{ - uint32_t result; - - __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); - return(result); -} - - -/** - \brief Remove the exclusive lock - \details Removes the exclusive lock which is created by LDREX. - */ -__attribute__((always_inline)) __STATIC_INLINE void __CLREX(void) -{ - __ASM volatile ("clrex" ::: "memory"); -} - - -/** - \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(ARG1,ARG2) \ -({ \ - uint32_t __RES, __ARG1 = (ARG1); \ - __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ - __RES; \ - }) - - -/** - \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(ARG1,ARG2) \ -({ \ - uint32_t __RES, __ARG1 = (ARG1); \ - __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ - __RES; \ - }) - - -/** - \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 - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __RRX(uint32_t value) -{ - uint32_t result; - - __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); -} - - -/** - \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) - */ -__attribute__((always_inline)) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *addr) -{ - uint32_t result; - -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*addr) ); -#else - /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not - accepted by assembler. So has to use following less efficient pattern. - */ - __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); -#endif - return ((uint8_t) result); /* Add explicit type cast here */ -} - - -/** - \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) - */ -__attribute__((always_inline)) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *addr) -{ - uint32_t result; - -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*addr) ); -#else - /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not - accepted by assembler. So has to use following less efficient pattern. - */ - __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); -#endif - return ((uint16_t) result); /* Add explicit type cast here */ -} - - -/** - \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) - */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *addr) -{ - uint32_t result; - - __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*addr) ); - return(result); -} - - -/** - \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 - */ -__attribute__((always_inline)) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *addr) -{ - __ASM volatile ("strbt %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) ); -} - - -/** - \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 - */ -__attribute__((always_inline)) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *addr) -{ - __ASM volatile ("strht %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) ); -} - - -/** - \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 - */ -__attribute__((always_inline)) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *addr) -{ - __ASM volatile ("strt %1, %0" : "=Q" (*addr) : "r" (value) ); -} - -#endif /* (__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U) */ - -/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ - - -/* ################### Compiler specific Intrinsics ########################### */ -/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics - Access to dedicated SIMD instructions - @{ -*/ - -#if (__CORTEX_M >= 0x04U) /* only for Cortex-M4 and above */ - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; - - __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); -} - -#define __SSAT16(ARG1,ARG2) \ -({ \ - int32_t __RES, __ARG1 = (ARG1); \ - __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ - __RES; \ - }) - -#define __USAT16(ARG1,ARG2) \ -({ \ - uint32_t __RES, __ARG1 = (ARG1); \ - __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ - __RES; \ - }) - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1) -{ - uint32_t result; - - __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1) -{ - uint32_t result; - - __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; - - __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; - - __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; - -#ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); -#else /* Big endian */ - __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); -#endif - - return(llr.w64); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; - -#ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); -#else /* Big endian */ - __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); -#endif - - return(llr.w64); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; - - __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; - - __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; - -#ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); -#else /* Big endian */ - __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); -#endif - - return(llr.w64); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; - -#ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); -#else /* Big endian */ - __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); -#endif - - return(llr.w64); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2) -{ - uint32_t result; - - __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QADD( int32_t op1, int32_t op2) -{ - int32_t result; - - __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __QSUB( int32_t op1, int32_t op2) -{ - int32_t result; - - __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); -} - -#define __PKHBT(ARG1,ARG2,ARG3) \ -({ \ - uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ - __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ - __RES; \ - }) - -#define __PKHTB(ARG1,ARG2,ARG3) \ -({ \ - uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ - if (ARG3 == 0) \ - __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \ - else \ - __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ - __RES; \ - }) - -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) -{ - int32_t result; - - __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); - return(result); -} - -#endif /* (__CORTEX_M >= 0x04) */ -/*@} end of group CMSIS_SIMD_intrinsics */ - - -#if defined ( __GNUC__ ) -#pragma GCC diagnostic pop -#endif - -#endif /* __CMSIS_GCC_H */ diff --git a/Software/Drivers/CMSIS/Include/core_cm0.h b/Software/Drivers/CMSIS/Include/core_cm0.h deleted file mode 100644 index fdee521..0000000 --- a/Software/Drivers/CMSIS/Include/core_cm0.h +++ /dev/null @@ -1,798 +0,0 @@ -/**************************************************************************//** - * @file core_cm0.h - * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_CM0_H_GENERIC -#define __CORE_CM0_H_GENERIC - -#include - -#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.
- Function definitions in header files are used to allow 'inlining'. - - \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers. - - \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code. - */ - - -/******************************************************************************* - * CMSIS definitions - ******************************************************************************/ -/** - \ingroup Cortex_M0 - @{ - */ - -/* CMSIS CM0 definitions */ -#define __CM0_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __CM0_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ -#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16U) | \ - __CM0_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_M (0x00U) /*!< Cortex-M Core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline - -#else - #error Unknown compiler -#endif - -/** __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_PCS_VFP - #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 ( __TMS470__ ) - #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 "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ - -#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 - - IO Type Qualifiers 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 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_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. - \return Masked and shifted value. -*/ -#define _VAL2FLD(field, value) ((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. - \return Masked and shifted bit field value. -*/ -#define _FLD2VAL(field, value) ((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 Cortex-M0 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. - @{ - */ - -/* Interrupt Priorities are WORD accessible only under ARMv6M */ -/* 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) ) - - -/** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) -{ - NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) -{ - NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not pending. - \return 1 Interrupt status is pending. - */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. - \param [in] IRQn Interrupt number. - \param [in] priority Priority to set. - */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if ((int32_t)(IRQn) < 0) - { - 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))); - } - else - { - 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))); - } -} - - -/** - \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. - \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)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); - } - else - { - return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); - } -} - - -/** - \brief System Reset - \details Initiates a system reset request to reset the MCU. - */ -__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 */ - - - -/* ################################## SysTick function ############################################ */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_SysTickFunctions SysTick Functions - \brief Functions that configure the System. - @{ - */ - -#if (__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 __Vendor_SysTickConfig is set to 1, then the - function SysTick_Config is not included. In this case, the file device.h - 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 */ diff --git a/Software/Drivers/CMSIS/Include/core_cm0plus.h b/Software/Drivers/CMSIS/Include/core_cm0plus.h deleted file mode 100644 index 7614450..0000000 --- a/Software/Drivers/CMSIS/Include/core_cm0plus.h +++ /dev/null @@ -1,914 +0,0 @@ -/**************************************************************************//** - * @file core_cm0plus.h - * @brief CMSIS Cortex-M0+ Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_CM0PLUS_H_GENERIC -#define __CORE_CM0PLUS_H_GENERIC - -#include - -#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.
- Function definitions in header files are used to allow 'inlining'. - - \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers. - - \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code. - */ - - -/******************************************************************************* - * CMSIS definitions - ******************************************************************************/ -/** - \ingroup Cortex-M0+ - @{ - */ - -/* CMSIS CM0+ definitions */ -#define __CM0PLUS_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __CM0PLUS_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ -#define __CM0PLUS_CMSIS_VERSION ((__CM0PLUS_CMSIS_VERSION_MAIN << 16U) | \ - __CM0PLUS_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_M (0x00U) /*!< Cortex-M Core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline - -#else - #error Unknown compiler -#endif - -/** __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_PCS_VFP - #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 ( __TMS470__ ) - #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 "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_CM0PLUS_H_GENERIC */ - -#ifndef __CMSIS_GENERIC - -#ifndef __CORE_CM0PLUS_H_DEPENDANT -#define __CORE_CM0PLUS_H_DEPENDANT - -#ifdef __cplusplus - extern "C" { -#endif - -/* check device defines and use defaults */ -#if defined __CHECK_DEVICE_DEFINES - #ifndef __CM0PLUS_REV - #define __CM0PLUS_REV 0x0000U - #warning "__CM0PLUS_REV not defined in device header file; using default!" - #endif - - #ifndef __MPU_PRESENT - #define __MPU_PRESENT 0U - #warning "__MPU_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __VTOR_PRESENT - #define __VTOR_PRESENT 0U - #warning "__VTOR_PRESENT 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 - - IO Type Qualifiers 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 - - Core MPU 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 nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ - 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 */ - -#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ -#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV 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 */ -#if (__VTOR_PRESENT == 1U) - __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ -#else - uint32_t RESERVED0; -#endif - __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 */ - -#if (__VTOR_PRESENT == 1U) -/* SCB Interrupt Control State Register Definitions */ -#define SCB_VTOR_TBLOFF_Pos 8U /*!< SCB VTOR: TBLOFF Position */ -#define SCB_VTOR_TBLOFF_Msk (0xFFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ -#endif - -/* 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 */ - -#if (__MPU_PRESENT == 1U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_MPU Memory Protection Unit (MPU) - \brief Type definitions for the Memory Protection Unit (MPU) - @{ - */ - -/** - \brief Structure type to access the Memory Protection Unit (MPU). - */ -typedef struct -{ - __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ - __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ - __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ -} MPU_Type; - -/* MPU Type Register Definitions */ -#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ -#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ - -#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ -#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ - -#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ -#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ - -/* MPU Control Register Definitions */ -#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ -#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ - -#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ -#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ - -#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ -#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ - -/* MPU Region Number Register Definitions */ -#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ -#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ - -/* MPU Region Base Address Register Definitions */ -#define MPU_RBAR_ADDR_Pos 8U /*!< MPU RBAR: ADDR Position */ -#define MPU_RBAR_ADDR_Msk (0xFFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ - -#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */ -#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ - -#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */ -#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */ - -/* MPU Region Attribute and Size Register Definitions */ -#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */ -#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ - -#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */ -#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */ - -#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */ -#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */ - -#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */ -#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */ - -#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */ -#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */ - -#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */ -#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */ - -#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */ -#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */ - -#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */ -#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ - -#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */ -#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ - -#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */ -#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */ - -/*@} end of group CMSIS_MPU */ -#endif - - -/** - \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. - \return Masked and shifted value. -*/ -#define _VAL2FLD(field, value) ((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. - \return Masked and shifted bit field value. -*/ -#define _FLD2VAL(field, value) ((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 Cortex-M0+ 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 */ - -#if (__MPU_PRESENT == 1U) - #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ - #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ -#endif - -/*@} */ - - - -/******************************************************************************* - * 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. - @{ - */ - -/* Interrupt Priorities are WORD accessible only under ARMv6M */ -/* 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) ) - - -/** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) -{ - NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) -{ - NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not pending. - \return 1 Interrupt status is pending. - */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. - \param [in] IRQn Interrupt number. - \param [in] priority Priority to set. - */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if ((int32_t)(IRQn) < 0) - { - 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))); - } - else - { - 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))); - } -} - - -/** - \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. - \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)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); - } - else - { - return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); - } -} - - -/** - \brief System Reset - \details Initiates a system reset request to reset the MCU. - */ -__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 */ - - - -/* ################################## SysTick function ############################################ */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_SysTickFunctions SysTick Functions - \brief Functions that configure the System. - @{ - */ - -#if (__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 __Vendor_SysTickConfig is set to 1, then the - function SysTick_Config is not included. In this case, the file device.h - 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_CM0PLUS_H_DEPENDANT */ - -#endif /* __CMSIS_GENERIC */ diff --git a/Software/Drivers/CMSIS/Include/core_cm3.h b/Software/Drivers/CMSIS/Include/core_cm3.h deleted file mode 100644 index 34ed84c..0000000 --- a/Software/Drivers/CMSIS/Include/core_cm3.h +++ /dev/null @@ -1,1763 +0,0 @@ -/**************************************************************************//** - * @file core_cm3.h - * @brief CMSIS Cortex-M3 Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_CM3_H_GENERIC -#define __CORE_CM3_H_GENERIC - -#include - -#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.
- Function definitions in header files are used to allow 'inlining'. - - \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers. - - \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code. - */ - - -/******************************************************************************* - * CMSIS definitions - ******************************************************************************/ -/** - \ingroup Cortex_M3 - @{ - */ - -/* CMSIS CM3 definitions */ -#define __CM3_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __CM3_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ -#define __CM3_CMSIS_VERSION ((__CM3_CMSIS_VERSION_MAIN << 16U) | \ - __CM3_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_M (0x03U) /*!< Cortex-M Core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline - -#else - #error Unknown compiler -#endif - -/** __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_PCS_VFP - #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 ( __TMS470__ ) - #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 "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_CM3_H_GENERIC */ - -#ifndef __CMSIS_GENERIC - -#ifndef __CORE_CM3_H_DEPENDANT -#define __CORE_CM3_H_DEPENDANT - -#ifdef __cplusplus - extern "C" { -#endif - -/* check device defines and use defaults */ -#if defined __CHECK_DEVICE_DEFINES - #ifndef __CM3_REV - #define __CM3_REV 0x0200U - #warning "__CM3_REV not defined in device header file; using default!" - #endif - - #ifndef __MPU_PRESENT - #define __MPU_PRESENT 0U - #warning "__MPU_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __NVIC_PRIO_BITS - #define __NVIC_PRIO_BITS 4U - #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 - - IO Type Qualifiers 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_M3 */ - - - -/******************************************************************************* - * Register Abstraction - Core Register contain: - - Core Register - - Core NVIC Register - - Core SCB Register - - Core SysTick Register - - Core Debug Register - - Core MPU 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:27; /*!< bit: 0..26 Reserved */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - 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 */ - -#define APSR_Q_Pos 27U /*!< APSR: Q Position */ -#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q 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 IT:2; /*!< bit: 25..26 saved IT state (read 0) */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - 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_Q_Pos 27U /*!< xPSR: Q Position */ -#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ - -#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ -#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT 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 nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ - 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 */ - -#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ -#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV 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[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ - uint32_t RESERVED0[24U]; - __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RSERVED1[24U]; - __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ - uint32_t RESERVED2[24U]; - __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ - uint32_t RESERVED3[24U]; - __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ - uint32_t RESERVED4[56U]; - __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ - uint32_t RESERVED5[644U]; - __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ -} NVIC_Type; - -/* Software Triggered Interrupt Register Definitions */ -#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */ -#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */ - -/*@} 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 */ - __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ - __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 */ - __IOM uint8_t SHP[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ - __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ - __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ - __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ - __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ - __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ - __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ - __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ - __IM uint32_t PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ - __IM uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ - __IM uint32_t MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ - __IM uint32_t ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ - uint32_t RESERVED0[5U]; - __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control 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_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */ -#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE 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 Vector Table Offset Register Definitions */ -#if (__CM3_REV < 0x0201U) /* core r2p1 */ -#define SCB_VTOR_TBLBASE_Pos 29U /*!< SCB VTOR: TBLBASE Position */ -#define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */ - -#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ -#define SCB_VTOR_TBLOFF_Msk (0x3FFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ -#else -#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ -#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ -#endif - -/* 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_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ -#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP 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 */ - -#define SCB_AIRCR_VECTRESET_Pos 0U /*!< SCB AIRCR: VECTRESET Position */ -#define SCB_AIRCR_VECTRESET_Msk (1UL /*<< SCB_AIRCR_VECTRESET_Pos*/) /*!< SCB AIRCR: VECTRESET 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_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */ -#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ - -#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */ -#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP 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 */ - -#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */ -#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ - -#define SCB_CCR_NONBASETHRDENA_Pos 0U /*!< SCB CCR: NONBASETHRDENA Position */ -#define SCB_CCR_NONBASETHRDENA_Msk (1UL /*<< SCB_CCR_NONBASETHRDENA_Pos*/) /*!< SCB CCR: NONBASETHRDENA Mask */ - -/* SCB System Handler Control and State Register Definitions */ -#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */ -#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ - -#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */ -#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ - -#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */ -#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ - -#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ -#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ - -#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */ -#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ - -#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */ -#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ - -#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */ -#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ - -#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */ -#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ - -#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */ -#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ - -#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */ -#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ - -#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */ -#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ - -#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */ -#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ - -#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */ -#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ - -#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */ -#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */ - -/* SCB Configurable Fault Status Register Definitions */ -#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */ -#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ - -#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */ -#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ - -#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ -#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ - -/* SCB Hard Fault Status Register Definitions */ -#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ -#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ - -#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */ -#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ - -#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */ -#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ - -/* SCB Debug Fault Status Register Definitions */ -#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */ -#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ - -#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */ -#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ - -#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */ -#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ - -#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */ -#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ - -#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */ -#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED 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[1U]; - __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ -#if ((defined __CM3_REV) && (__CM3_REV >= 0x200U)) - __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ -#else - uint32_t RESERVED1[1U]; -#endif -} SCnSCB_Type; - -/* Interrupt Controller Type Register Definitions */ -#define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */ -#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ - -/* Auxiliary Control Register Definitions */ - -#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */ -#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ - -#define SCnSCB_ACTLR_DISDEFWBUF_Pos 1U /*!< ACTLR: DISDEFWBUF Position */ -#define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */ - -#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */ -#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT 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_ITM Instrumentation Trace Macrocell (ITM) - \brief Type definitions for the Instrumentation Trace Macrocell (ITM) - @{ - */ - -/** - \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). - */ -typedef struct -{ - __OM union - { - __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ - __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ - __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ - } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ - uint32_t RESERVED0[864U]; - __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ - uint32_t RESERVED1[15U]; - __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ - uint32_t RESERVED2[15U]; - __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[29U]; - __OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */ - __IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */ - __IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */ - uint32_t RESERVED4[43U]; - __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ - __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ - uint32_t RESERVED5[6U]; - __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ - __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ - __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ - __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ - __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ - __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ - __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ - __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ - __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ - __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ - __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ - __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ -} ITM_Type; - -/* ITM Trace Privilege Register Definitions */ -#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ -#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ - -/* ITM Trace Control Register Definitions */ -#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ -#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ - -#define ITM_TCR_TraceBusID_Pos 16U /*!< ITM TCR: ATBID Position */ -#define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */ - -#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */ -#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ - -#define ITM_TCR_TSPrescale_Pos 8U /*!< ITM TCR: TSPrescale Position */ -#define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */ - -#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */ -#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ - -#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */ -#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */ - -#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */ -#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ - -#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */ -#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ - -#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ -#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ - -/* ITM Integration Write Register Definitions */ -#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */ -#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */ - -/* ITM Integration Read Register Definitions */ -#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */ -#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */ - -/* ITM Integration Mode Control Register Definitions */ -#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */ -#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */ - -/* ITM Lock Status Register Definitions */ -#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ -#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ - -#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */ -#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */ - -#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */ -#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */ - -/*@}*/ /* end of group CMSIS_ITM */ - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT) - \brief Type definitions for the Data Watchpoint and Trace (DWT) - @{ - */ - -/** - \brief Structure type to access the Data Watchpoint and Trace Register (DWT). - */ -typedef struct -{ - __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ - __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ - __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ - __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ - __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ - __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ - __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ - __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ - __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ - __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */ - __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ - uint32_t RESERVED0[1U]; - __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ - __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */ - __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ - uint32_t RESERVED1[1U]; - __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ - __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */ - __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ - uint32_t RESERVED2[1U]; - __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ - __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */ - __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ -} DWT_Type; - -/* DWT Control Register Definitions */ -#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */ -#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */ - -#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */ -#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */ - -#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */ -#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */ - -#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */ -#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */ - -#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */ -#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */ - -#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */ -#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */ - -#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */ -#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */ - -#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */ -#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */ - -#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */ -#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */ - -#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */ -#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */ - -#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */ -#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */ - -#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */ -#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */ - -#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */ -#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */ - -#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */ -#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */ - -#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */ -#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */ - -#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */ -#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */ - -#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */ -#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */ - -#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */ -#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */ - -/* DWT CPI Count Register Definitions */ -#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */ -#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */ - -/* DWT Exception Overhead Count Register Definitions */ -#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */ -#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */ - -/* DWT Sleep Count Register Definitions */ -#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */ -#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */ - -/* DWT LSU Count Register Definitions */ -#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */ -#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */ - -/* DWT Folded-instruction Count Register Definitions */ -#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */ -#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */ - -/* DWT Comparator Mask Register Definitions */ -#define DWT_MASK_MASK_Pos 0U /*!< DWT MASK: MASK Position */ -#define DWT_MASK_MASK_Msk (0x1FUL /*<< DWT_MASK_MASK_Pos*/) /*!< DWT MASK: MASK Mask */ - -/* DWT Comparator Function Register Definitions */ -#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */ -#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */ - -#define DWT_FUNCTION_DATAVADDR1_Pos 16U /*!< DWT FUNCTION: DATAVADDR1 Position */ -#define DWT_FUNCTION_DATAVADDR1_Msk (0xFUL << DWT_FUNCTION_DATAVADDR1_Pos) /*!< DWT FUNCTION: DATAVADDR1 Mask */ - -#define DWT_FUNCTION_DATAVADDR0_Pos 12U /*!< DWT FUNCTION: DATAVADDR0 Position */ -#define DWT_FUNCTION_DATAVADDR0_Msk (0xFUL << DWT_FUNCTION_DATAVADDR0_Pos) /*!< DWT FUNCTION: DATAVADDR0 Mask */ - -#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */ -#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */ - -#define DWT_FUNCTION_LNK1ENA_Pos 9U /*!< DWT FUNCTION: LNK1ENA Position */ -#define DWT_FUNCTION_LNK1ENA_Msk (0x1UL << DWT_FUNCTION_LNK1ENA_Pos) /*!< DWT FUNCTION: LNK1ENA Mask */ - -#define DWT_FUNCTION_DATAVMATCH_Pos 8U /*!< DWT FUNCTION: DATAVMATCH Position */ -#define DWT_FUNCTION_DATAVMATCH_Msk (0x1UL << DWT_FUNCTION_DATAVMATCH_Pos) /*!< DWT FUNCTION: DATAVMATCH Mask */ - -#define DWT_FUNCTION_CYCMATCH_Pos 7U /*!< DWT FUNCTION: CYCMATCH Position */ -#define DWT_FUNCTION_CYCMATCH_Msk (0x1UL << DWT_FUNCTION_CYCMATCH_Pos) /*!< DWT FUNCTION: CYCMATCH Mask */ - -#define DWT_FUNCTION_EMITRANGE_Pos 5U /*!< DWT FUNCTION: EMITRANGE Position */ -#define DWT_FUNCTION_EMITRANGE_Msk (0x1UL << DWT_FUNCTION_EMITRANGE_Pos) /*!< DWT FUNCTION: EMITRANGE Mask */ - -#define DWT_FUNCTION_FUNCTION_Pos 0U /*!< DWT FUNCTION: FUNCTION Position */ -#define DWT_FUNCTION_FUNCTION_Msk (0xFUL /*<< DWT_FUNCTION_FUNCTION_Pos*/) /*!< DWT FUNCTION: FUNCTION Mask */ - -/*@}*/ /* end of group CMSIS_DWT */ - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_TPI Trace Port Interface (TPI) - \brief Type definitions for the Trace Port Interface (TPI) - @{ - */ - -/** - \brief Structure type to access the Trace Port Interface Register (TPI). - */ -typedef struct -{ - __IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ - __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ - uint32_t RESERVED0[2U]; - __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ - uint32_t RESERVED1[55U]; - __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ - uint32_t RESERVED2[131U]; - __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ - __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ - __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ - uint32_t RESERVED3[759U]; - __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */ - __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ - __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ - uint32_t RESERVED4[1U]; - __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */ - __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */ - __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */ - uint32_t RESERVED5[39U]; - __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */ - __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */ - uint32_t RESERVED7[8U]; - __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */ - __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */ -} TPI_Type; - -/* TPI Asynchronous Clock Prescaler Register Definitions */ -#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */ -#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */ - -/* TPI Selected Pin Protocol Register Definitions */ -#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */ -#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */ - -/* TPI Formatter and Flush Status Register Definitions */ -#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */ -#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */ - -#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */ -#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */ - -#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */ -#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */ - -#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */ -#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */ - -/* TPI Formatter and Flush Control Register Definitions */ -#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */ -#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */ - -#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */ -#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */ - -/* TPI TRIGGER Register Definitions */ -#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */ -#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */ - -/* TPI Integration ETM Data Register Definitions (FIFO0) */ -#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */ -#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ - -#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */ -#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */ - -#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */ -#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ - -#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */ -#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */ - -#define TPI_FIFO0_ETM2_Pos 16U /*!< TPI FIFO0: ETM2 Position */ -#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */ - -#define TPI_FIFO0_ETM1_Pos 8U /*!< TPI FIFO0: ETM1 Position */ -#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */ - -#define TPI_FIFO0_ETM0_Pos 0U /*!< TPI FIFO0: ETM0 Position */ -#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */ - -/* TPI ITATBCTR2 Register Definitions */ -#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */ -#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */ - -/* TPI Integration ITM Data Register Definitions (FIFO1) */ -#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */ -#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ - -#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */ -#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */ - -#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */ -#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ - -#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */ -#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */ - -#define TPI_FIFO1_ITM2_Pos 16U /*!< TPI FIFO1: ITM2 Position */ -#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */ - -#define TPI_FIFO1_ITM1_Pos 8U /*!< TPI FIFO1: ITM1 Position */ -#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */ - -#define TPI_FIFO1_ITM0_Pos 0U /*!< TPI FIFO1: ITM0 Position */ -#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */ - -/* TPI ITATBCTR0 Register Definitions */ -#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */ -#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */ - -/* TPI Integration Mode Control Register Definitions */ -#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */ -#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ - -/* TPI DEVID Register Definitions */ -#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ -#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */ - -#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */ -#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */ - -#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */ -#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */ - -#define TPI_DEVID_MinBufSz_Pos 6U /*!< TPI DEVID: MinBufSz Position */ -#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */ - -#define TPI_DEVID_AsynClkIn_Pos 5U /*!< TPI DEVID: AsynClkIn Position */ -#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */ - -#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */ -#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */ - -/* TPI DEVTYPE Register Definitions */ -#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */ -#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ - -#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */ -#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ - -/*@}*/ /* end of group CMSIS_TPI */ - - -#if (__MPU_PRESENT == 1U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_MPU Memory Protection Unit (MPU) - \brief Type definitions for the Memory Protection Unit (MPU) - @{ - */ - -/** - \brief Structure type to access the Memory Protection Unit (MPU). - */ -typedef struct -{ - __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ - __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ - __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ - __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */ - __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */ - __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */ - __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ -} MPU_Type; - -/* MPU Type Register Definitions */ -#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ -#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ - -#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ -#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ - -#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ -#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ - -/* MPU Control Register Definitions */ -#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ -#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ - -#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ -#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ - -#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ -#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ - -/* MPU Region Number Register Definitions */ -#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ -#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ - -/* MPU Region Base Address Register Definitions */ -#define MPU_RBAR_ADDR_Pos 5U /*!< MPU RBAR: ADDR Position */ -#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ - -#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */ -#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ - -#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */ -#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */ - -/* MPU Region Attribute and Size Register Definitions */ -#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */ -#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ - -#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */ -#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */ - -#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */ -#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */ - -#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */ -#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */ - -#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */ -#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */ - -#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */ -#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */ - -#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */ -#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */ - -#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */ -#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ - -#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */ -#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ - -#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */ -#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */ - -/*@} end of group CMSIS_MPU */ -#endif - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) - \brief Type definitions for the Core Debug Registers - @{ - */ - -/** - \brief Structure type to access the Core Debug Register (CoreDebug). - */ -typedef struct -{ - __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ - __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ - __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ - __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ -} CoreDebug_Type; - -/* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ - -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ - -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ - -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ - -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ - -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ - -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ - -#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ - -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ - -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ - -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ - -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ - -/* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ - -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ - -/* Debug Exception and Monitor Control Register Definitions */ -#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */ -#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ - -#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */ -#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ - -#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */ -#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ - -#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */ -#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ - -#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */ -#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ - -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ - -#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */ -#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ - -#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */ -#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ - -#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */ -#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ - -#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */ -#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ - -#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */ -#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ - -#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */ -#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ - -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ - -/*@} 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. - \return Masked and shifted value. -*/ -#define _VAL2FLD(field, value) ((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. - \return Masked and shifted bit field value. -*/ -#define _FLD2VAL(field, value) ((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 Cortex-M3 Hardware */ -#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ -#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ -#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ -#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ -#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug 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 */ -#define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ -#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ -#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ -#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ - -#if (__MPU_PRESENT == 1U) - #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ - #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ -#endif - -/*@} */ - - - -/******************************************************************************* - * Hardware Abstraction Layer - Core Function Interface contains: - - Core NVIC Functions - - Core SysTick Functions - - Core Debug 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. - @{ - */ - -/** - \brief Set Priority Grouping - \details Sets the priority grouping field using the required unlock sequence. - The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. - Only values from 0..7 are used. - 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 Priority grouping field. - */ -__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) -{ - uint32_t reg_value; - uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ - - reg_value = SCB->AIRCR; /* read old register configuration */ - reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ - reg_value = (reg_value | - ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ - SCB->AIRCR = reg_value; -} - - -/** - \brief Get Priority Grouping - \details Reads the priority grouping field from the NVIC Interrupt Controller. - \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). - */ -__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void) -{ - return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); -} - - -/** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) -{ - NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) -{ - NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not pending. - \return 1 Interrupt status is pending. - */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Active Interrupt - \details Reads the active register in NVIC and returns the active bit. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not active. - \return 1 Interrupt status is active. - */ -__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. - \param [in] IRQn Interrupt number. - \param [in] priority Priority to set. - */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if ((int32_t)(IRQn) < 0) - { - SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } - else - { - NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } -} - - -/** - \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. - \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)SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); - } - else - { - return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (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 System Reset - \details Initiates a system reset request to reset the MCU. - */ -__STATIC_INLINE void NVIC_SystemReset(void) -{ - __DSB(); /* Ensure all outstanding memory accesses included - buffered write are completed before reset */ - SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | - SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */ - __DSB(); /* Ensure completion of memory access */ - - for(;;) /* wait until reset */ - { - __NOP(); - } -} - -/*@} end of CMSIS_Core_NVICFunctions */ - - - -/* ################################## SysTick function ############################################ */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_SysTickFunctions SysTick Functions - \brief Functions that configure the System. - @{ - */ - -#if (__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 __Vendor_SysTickConfig is set to 1, then the - function SysTick_Config is not included. In this case, the file device.h - 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 */ - - - -/* ##################################### Debug In/Output function ########################################### */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_core_DebugFunctions ITM Functions - \brief Functions that access the ITM debug interface. - @{ - */ - -extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ -#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ - - -/** - \brief ITM Send Character - \details Transmits a character via the ITM channel 0, and - \li Just returns when no debugger is connected that has booked the output. - \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted. - \param [in] ch Character to transmit. - \returns Character to transmit. - */ -__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) -{ - if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ - ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */ - { - while (ITM->PORT[0U].u32 == 0UL) - { - __NOP(); - } - ITM->PORT[0U].u8 = (uint8_t)ch; - } - return (ch); -} - - -/** - \brief ITM Receive Character - \details Inputs a character via the external variable \ref ITM_RxBuffer. - \return Received character. - \return -1 No character pending. - */ -__STATIC_INLINE int32_t ITM_ReceiveChar (void) -{ - int32_t ch = -1; /* no character available */ - - if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) - { - ch = ITM_RxBuffer; - ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ - } - - return (ch); -} - - -/** - \brief ITM Check Character - \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer. - \return 0 No character available. - \return 1 Character available. - */ -__STATIC_INLINE int32_t ITM_CheckChar (void) -{ - - if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) - { - return (0); /* no character available */ - } - else - { - return (1); /* character available */ - } -} - -/*@} end of CMSIS_core_DebugFunctions */ - - - - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_CM3_H_DEPENDANT */ - -#endif /* __CMSIS_GENERIC */ diff --git a/Software/Drivers/CMSIS/Include/core_cm4.h b/Software/Drivers/CMSIS/Include/core_cm4.h deleted file mode 100644 index 01cb73b..0000000 --- a/Software/Drivers/CMSIS/Include/core_cm4.h +++ /dev/null @@ -1,1937 +0,0 @@ -/**************************************************************************//** - * @file core_cm4.h - * @brief CMSIS Cortex-M4 Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_CM4_H_GENERIC -#define __CORE_CM4_H_GENERIC - -#include - -#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.
- Function definitions in header files are used to allow 'inlining'. - - \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers. - - \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code. - */ - - -/******************************************************************************* - * CMSIS definitions - ******************************************************************************/ -/** - \ingroup Cortex_M4 - @{ - */ - -/* CMSIS CM4 definitions */ -#define __CM4_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __CM4_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ -#define __CM4_CMSIS_VERSION ((__CM4_CMSIS_VERSION_MAIN << 16U) | \ - __CM4_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_M (0x04U) /*!< Cortex-M Core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline - -#else - #error Unknown compiler -#endif - -/** __FPU_USED indicates whether an FPU is used or not. - For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions. -*/ -#if defined ( __CC_ARM ) - #if defined __TARGET_FPU_VFP - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #if defined __ARM_PCS_VFP - #if (__FPU_PRESENT == 1) - #define __FPU_USED 1U - #else - #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __GNUC__ ) - #if defined (__VFP_FP__) && !defined(__SOFTFP__) - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __ICCARM__ ) - #if defined __ARMVFP__ - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __TMS470__ ) - #if defined __TI_VFP_SUPPORT__ - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __TASKING__ ) - #if defined __FPU_VFP__ - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __CSMC__ ) - #if ( __CSMC__ & 0x400U) - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#endif - -#include "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ -#include "core_cmSimd.h" /* Compiler specific SIMD Intrinsics */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_CM4_H_GENERIC */ - -#ifndef __CMSIS_GENERIC - -#ifndef __CORE_CM4_H_DEPENDANT -#define __CORE_CM4_H_DEPENDANT - -#ifdef __cplusplus - extern "C" { -#endif - -/* check device defines and use defaults */ -#if defined __CHECK_DEVICE_DEFINES - #ifndef __CM4_REV - #define __CM4_REV 0x0000U - #warning "__CM4_REV not defined in device header file; using default!" - #endif - - #ifndef __FPU_PRESENT - #define __FPU_PRESENT 0U - #warning "__FPU_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __MPU_PRESENT - #define __MPU_PRESENT 0U - #warning "__MPU_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __NVIC_PRIO_BITS - #define __NVIC_PRIO_BITS 4U - #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 - - IO Type Qualifiers 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_M4 */ - - - -/******************************************************************************* - * Register Abstraction - Core Register contain: - - Core Register - - Core NVIC Register - - Core SCB Register - - Core SysTick Register - - Core Debug Register - - Core MPU Register - - Core FPU 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:16; /*!< bit: 0..15 Reserved */ - uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ - uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - 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 */ - -#define APSR_Q_Pos 27U /*!< APSR: Q Position */ -#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q Mask */ - -#define APSR_GE_Pos 16U /*!< APSR: GE Position */ -#define APSR_GE_Msk (0xFUL << APSR_GE_Pos) /*!< APSR: GE 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:7; /*!< bit: 9..15 Reserved */ - uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ - uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ - uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ - uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - 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_Q_Pos 27U /*!< xPSR: Q Position */ -#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ - -#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ -#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */ - -#define xPSR_T_Pos 24U /*!< xPSR: T Position */ -#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ - -#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */ -#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE 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 nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ - uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ - uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ - uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ -} CONTROL_Type; - -/* CONTROL Register Definitions */ -#define CONTROL_FPCA_Pos 2U /*!< CONTROL: FPCA Position */ -#define CONTROL_FPCA_Msk (1UL << CONTROL_FPCA_Pos) /*!< CONTROL: FPCA Mask */ - -#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ -#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ - -#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ -#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV 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[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ - uint32_t RESERVED0[24U]; - __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RSERVED1[24U]; - __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ - uint32_t RESERVED2[24U]; - __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ - uint32_t RESERVED3[24U]; - __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ - uint32_t RESERVED4[56U]; - __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ - uint32_t RESERVED5[644U]; - __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ -} NVIC_Type; - -/* Software Triggered Interrupt Register Definitions */ -#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */ -#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */ - -/*@} 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 */ - __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ - __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 */ - __IOM uint8_t SHP[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ - __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ - __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ - __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ - __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ - __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ - __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ - __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ - __IM uint32_t PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ - __IM uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ - __IM uint32_t MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ - __IM uint32_t ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ - uint32_t RESERVED0[5U]; - __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control 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_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */ -#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE 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 Vector Table Offset Register Definitions */ -#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ -#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF 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_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ -#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP 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 */ - -#define SCB_AIRCR_VECTRESET_Pos 0U /*!< SCB AIRCR: VECTRESET Position */ -#define SCB_AIRCR_VECTRESET_Msk (1UL /*<< SCB_AIRCR_VECTRESET_Pos*/) /*!< SCB AIRCR: VECTRESET 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_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */ -#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ - -#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */ -#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP 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 */ - -#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */ -#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ - -#define SCB_CCR_NONBASETHRDENA_Pos 0U /*!< SCB CCR: NONBASETHRDENA Position */ -#define SCB_CCR_NONBASETHRDENA_Msk (1UL /*<< SCB_CCR_NONBASETHRDENA_Pos*/) /*!< SCB CCR: NONBASETHRDENA Mask */ - -/* SCB System Handler Control and State Register Definitions */ -#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */ -#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ - -#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */ -#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ - -#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */ -#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ - -#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ -#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ - -#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */ -#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ - -#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */ -#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ - -#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */ -#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ - -#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */ -#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ - -#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */ -#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ - -#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */ -#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ - -#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */ -#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ - -#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */ -#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ - -#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */ -#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ - -#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */ -#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */ - -/* SCB Configurable Fault Status Register Definitions */ -#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */ -#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ - -#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */ -#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ - -#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ -#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ - -/* SCB Hard Fault Status Register Definitions */ -#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ -#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ - -#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */ -#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ - -#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */ -#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ - -/* SCB Debug Fault Status Register Definitions */ -#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */ -#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ - -#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */ -#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ - -#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */ -#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ - -#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */ -#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ - -#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */ -#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED 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[1U]; - __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ - __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ -} SCnSCB_Type; - -/* Interrupt Controller Type Register Definitions */ -#define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */ -#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ - -/* Auxiliary Control Register Definitions */ -#define SCnSCB_ACTLR_DISOOFP_Pos 9U /*!< ACTLR: DISOOFP Position */ -#define SCnSCB_ACTLR_DISOOFP_Msk (1UL << SCnSCB_ACTLR_DISOOFP_Pos) /*!< ACTLR: DISOOFP Mask */ - -#define SCnSCB_ACTLR_DISFPCA_Pos 8U /*!< ACTLR: DISFPCA Position */ -#define SCnSCB_ACTLR_DISFPCA_Msk (1UL << SCnSCB_ACTLR_DISFPCA_Pos) /*!< ACTLR: DISFPCA Mask */ - -#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */ -#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ - -#define SCnSCB_ACTLR_DISDEFWBUF_Pos 1U /*!< ACTLR: DISDEFWBUF Position */ -#define SCnSCB_ACTLR_DISDEFWBUF_Msk (1UL << SCnSCB_ACTLR_DISDEFWBUF_Pos) /*!< ACTLR: DISDEFWBUF Mask */ - -#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */ -#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT 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_ITM Instrumentation Trace Macrocell (ITM) - \brief Type definitions for the Instrumentation Trace Macrocell (ITM) - @{ - */ - -/** - \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). - */ -typedef struct -{ - __OM union - { - __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ - __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ - __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ - } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ - uint32_t RESERVED0[864U]; - __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ - uint32_t RESERVED1[15U]; - __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ - uint32_t RESERVED2[15U]; - __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[29U]; - __OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */ - __IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */ - __IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */ - uint32_t RESERVED4[43U]; - __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ - __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ - uint32_t RESERVED5[6U]; - __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ - __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ - __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ - __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ - __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ - __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ - __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ - __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ - __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ - __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ - __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ - __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ -} ITM_Type; - -/* ITM Trace Privilege Register Definitions */ -#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ -#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ - -/* ITM Trace Control Register Definitions */ -#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ -#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ - -#define ITM_TCR_TraceBusID_Pos 16U /*!< ITM TCR: ATBID Position */ -#define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */ - -#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */ -#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ - -#define ITM_TCR_TSPrescale_Pos 8U /*!< ITM TCR: TSPrescale Position */ -#define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */ - -#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */ -#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ - -#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */ -#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */ - -#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */ -#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ - -#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */ -#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ - -#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ -#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ - -/* ITM Integration Write Register Definitions */ -#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */ -#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */ - -/* ITM Integration Read Register Definitions */ -#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */ -#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */ - -/* ITM Integration Mode Control Register Definitions */ -#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */ -#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */ - -/* ITM Lock Status Register Definitions */ -#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ -#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ - -#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */ -#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */ - -#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */ -#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */ - -/*@}*/ /* end of group CMSIS_ITM */ - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT) - \brief Type definitions for the Data Watchpoint and Trace (DWT) - @{ - */ - -/** - \brief Structure type to access the Data Watchpoint and Trace Register (DWT). - */ -typedef struct -{ - __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ - __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ - __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ - __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ - __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ - __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ - __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ - __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ - __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ - __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */ - __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ - uint32_t RESERVED0[1U]; - __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ - __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */ - __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ - uint32_t RESERVED1[1U]; - __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ - __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */ - __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ - uint32_t RESERVED2[1U]; - __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ - __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */ - __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ -} DWT_Type; - -/* DWT Control Register Definitions */ -#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */ -#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */ - -#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */ -#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */ - -#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */ -#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */ - -#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */ -#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */ - -#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */ -#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */ - -#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */ -#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */ - -#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */ -#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */ - -#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */ -#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */ - -#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */ -#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */ - -#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */ -#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */ - -#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */ -#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */ - -#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */ -#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */ - -#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */ -#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */ - -#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */ -#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */ - -#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */ -#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */ - -#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */ -#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */ - -#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */ -#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */ - -#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */ -#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */ - -/* DWT CPI Count Register Definitions */ -#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */ -#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */ - -/* DWT Exception Overhead Count Register Definitions */ -#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */ -#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */ - -/* DWT Sleep Count Register Definitions */ -#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */ -#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */ - -/* DWT LSU Count Register Definitions */ -#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */ -#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */ - -/* DWT Folded-instruction Count Register Definitions */ -#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */ -#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */ - -/* DWT Comparator Mask Register Definitions */ -#define DWT_MASK_MASK_Pos 0U /*!< DWT MASK: MASK Position */ -#define DWT_MASK_MASK_Msk (0x1FUL /*<< DWT_MASK_MASK_Pos*/) /*!< DWT MASK: MASK Mask */ - -/* DWT Comparator Function Register Definitions */ -#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */ -#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */ - -#define DWT_FUNCTION_DATAVADDR1_Pos 16U /*!< DWT FUNCTION: DATAVADDR1 Position */ -#define DWT_FUNCTION_DATAVADDR1_Msk (0xFUL << DWT_FUNCTION_DATAVADDR1_Pos) /*!< DWT FUNCTION: DATAVADDR1 Mask */ - -#define DWT_FUNCTION_DATAVADDR0_Pos 12U /*!< DWT FUNCTION: DATAVADDR0 Position */ -#define DWT_FUNCTION_DATAVADDR0_Msk (0xFUL << DWT_FUNCTION_DATAVADDR0_Pos) /*!< DWT FUNCTION: DATAVADDR0 Mask */ - -#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */ -#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */ - -#define DWT_FUNCTION_LNK1ENA_Pos 9U /*!< DWT FUNCTION: LNK1ENA Position */ -#define DWT_FUNCTION_LNK1ENA_Msk (0x1UL << DWT_FUNCTION_LNK1ENA_Pos) /*!< DWT FUNCTION: LNK1ENA Mask */ - -#define DWT_FUNCTION_DATAVMATCH_Pos 8U /*!< DWT FUNCTION: DATAVMATCH Position */ -#define DWT_FUNCTION_DATAVMATCH_Msk (0x1UL << DWT_FUNCTION_DATAVMATCH_Pos) /*!< DWT FUNCTION: DATAVMATCH Mask */ - -#define DWT_FUNCTION_CYCMATCH_Pos 7U /*!< DWT FUNCTION: CYCMATCH Position */ -#define DWT_FUNCTION_CYCMATCH_Msk (0x1UL << DWT_FUNCTION_CYCMATCH_Pos) /*!< DWT FUNCTION: CYCMATCH Mask */ - -#define DWT_FUNCTION_EMITRANGE_Pos 5U /*!< DWT FUNCTION: EMITRANGE Position */ -#define DWT_FUNCTION_EMITRANGE_Msk (0x1UL << DWT_FUNCTION_EMITRANGE_Pos) /*!< DWT FUNCTION: EMITRANGE Mask */ - -#define DWT_FUNCTION_FUNCTION_Pos 0U /*!< DWT FUNCTION: FUNCTION Position */ -#define DWT_FUNCTION_FUNCTION_Msk (0xFUL /*<< DWT_FUNCTION_FUNCTION_Pos*/) /*!< DWT FUNCTION: FUNCTION Mask */ - -/*@}*/ /* end of group CMSIS_DWT */ - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_TPI Trace Port Interface (TPI) - \brief Type definitions for the Trace Port Interface (TPI) - @{ - */ - -/** - \brief Structure type to access the Trace Port Interface Register (TPI). - */ -typedef struct -{ - __IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ - __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ - uint32_t RESERVED0[2U]; - __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ - uint32_t RESERVED1[55U]; - __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ - uint32_t RESERVED2[131U]; - __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ - __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ - __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ - uint32_t RESERVED3[759U]; - __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */ - __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ - __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ - uint32_t RESERVED4[1U]; - __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */ - __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */ - __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */ - uint32_t RESERVED5[39U]; - __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */ - __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */ - uint32_t RESERVED7[8U]; - __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */ - __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */ -} TPI_Type; - -/* TPI Asynchronous Clock Prescaler Register Definitions */ -#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */ -#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */ - -/* TPI Selected Pin Protocol Register Definitions */ -#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */ -#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */ - -/* TPI Formatter and Flush Status Register Definitions */ -#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */ -#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */ - -#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */ -#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */ - -#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */ -#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */ - -#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */ -#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */ - -/* TPI Formatter and Flush Control Register Definitions */ -#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */ -#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */ - -#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */ -#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */ - -/* TPI TRIGGER Register Definitions */ -#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */ -#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */ - -/* TPI Integration ETM Data Register Definitions (FIFO0) */ -#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */ -#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ - -#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */ -#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */ - -#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */ -#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ - -#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */ -#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */ - -#define TPI_FIFO0_ETM2_Pos 16U /*!< TPI FIFO0: ETM2 Position */ -#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */ - -#define TPI_FIFO0_ETM1_Pos 8U /*!< TPI FIFO0: ETM1 Position */ -#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */ - -#define TPI_FIFO0_ETM0_Pos 0U /*!< TPI FIFO0: ETM0 Position */ -#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */ - -/* TPI ITATBCTR2 Register Definitions */ -#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */ -#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */ - -/* TPI Integration ITM Data Register Definitions (FIFO1) */ -#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */ -#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ - -#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */ -#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */ - -#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */ -#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ - -#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */ -#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */ - -#define TPI_FIFO1_ITM2_Pos 16U /*!< TPI FIFO1: ITM2 Position */ -#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */ - -#define TPI_FIFO1_ITM1_Pos 8U /*!< TPI FIFO1: ITM1 Position */ -#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */ - -#define TPI_FIFO1_ITM0_Pos 0U /*!< TPI FIFO1: ITM0 Position */ -#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */ - -/* TPI ITATBCTR0 Register Definitions */ -#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */ -#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */ - -/* TPI Integration Mode Control Register Definitions */ -#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */ -#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ - -/* TPI DEVID Register Definitions */ -#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ -#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */ - -#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */ -#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */ - -#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */ -#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */ - -#define TPI_DEVID_MinBufSz_Pos 6U /*!< TPI DEVID: MinBufSz Position */ -#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */ - -#define TPI_DEVID_AsynClkIn_Pos 5U /*!< TPI DEVID: AsynClkIn Position */ -#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */ - -#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */ -#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */ - -/* TPI DEVTYPE Register Definitions */ -#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */ -#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ - -#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */ -#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ - -/*@}*/ /* end of group CMSIS_TPI */ - - -#if (__MPU_PRESENT == 1U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_MPU Memory Protection Unit (MPU) - \brief Type definitions for the Memory Protection Unit (MPU) - @{ - */ - -/** - \brief Structure type to access the Memory Protection Unit (MPU). - */ -typedef struct -{ - __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ - __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ - __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ - __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */ - __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */ - __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */ - __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ -} MPU_Type; - -/* MPU Type Register Definitions */ -#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ -#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ - -#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ -#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ - -#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ -#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ - -/* MPU Control Register Definitions */ -#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ -#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ - -#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ -#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ - -#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ -#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ - -/* MPU Region Number Register Definitions */ -#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ -#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ - -/* MPU Region Base Address Register Definitions */ -#define MPU_RBAR_ADDR_Pos 5U /*!< MPU RBAR: ADDR Position */ -#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ - -#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */ -#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ - -#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */ -#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */ - -/* MPU Region Attribute and Size Register Definitions */ -#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */ -#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ - -#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */ -#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */ - -#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */ -#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */ - -#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */ -#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */ - -#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */ -#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */ - -#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */ -#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */ - -#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */ -#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */ - -#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */ -#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ - -#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */ -#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ - -#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */ -#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */ - -/*@} end of group CMSIS_MPU */ -#endif - - -#if (__FPU_PRESENT == 1U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_FPU Floating Point Unit (FPU) - \brief Type definitions for the Floating Point Unit (FPU) - @{ - */ - -/** - \brief Structure type to access the Floating Point Unit (FPU). - */ -typedef struct -{ - uint32_t RESERVED0[1U]; - __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ - __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ - __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ - __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ - __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ -} FPU_Type; - -/* Floating-Point Context Control Register Definitions */ -#define FPU_FPCCR_ASPEN_Pos 31U /*!< FPCCR: ASPEN bit Position */ -#define FPU_FPCCR_ASPEN_Msk (1UL << FPU_FPCCR_ASPEN_Pos) /*!< FPCCR: ASPEN bit Mask */ - -#define FPU_FPCCR_LSPEN_Pos 30U /*!< FPCCR: LSPEN Position */ -#define FPU_FPCCR_LSPEN_Msk (1UL << FPU_FPCCR_LSPEN_Pos) /*!< FPCCR: LSPEN bit Mask */ - -#define FPU_FPCCR_MONRDY_Pos 8U /*!< FPCCR: MONRDY Position */ -#define FPU_FPCCR_MONRDY_Msk (1UL << FPU_FPCCR_MONRDY_Pos) /*!< FPCCR: MONRDY bit Mask */ - -#define FPU_FPCCR_BFRDY_Pos 6U /*!< FPCCR: BFRDY Position */ -#define FPU_FPCCR_BFRDY_Msk (1UL << FPU_FPCCR_BFRDY_Pos) /*!< FPCCR: BFRDY bit Mask */ - -#define FPU_FPCCR_MMRDY_Pos 5U /*!< FPCCR: MMRDY Position */ -#define FPU_FPCCR_MMRDY_Msk (1UL << FPU_FPCCR_MMRDY_Pos) /*!< FPCCR: MMRDY bit Mask */ - -#define FPU_FPCCR_HFRDY_Pos 4U /*!< FPCCR: HFRDY Position */ -#define FPU_FPCCR_HFRDY_Msk (1UL << FPU_FPCCR_HFRDY_Pos) /*!< FPCCR: HFRDY bit Mask */ - -#define FPU_FPCCR_THREAD_Pos 3U /*!< FPCCR: processor mode bit Position */ -#define FPU_FPCCR_THREAD_Msk (1UL << FPU_FPCCR_THREAD_Pos) /*!< FPCCR: processor mode active bit Mask */ - -#define FPU_FPCCR_USER_Pos 1U /*!< FPCCR: privilege level bit Position */ -#define FPU_FPCCR_USER_Msk (1UL << FPU_FPCCR_USER_Pos) /*!< FPCCR: privilege level bit Mask */ - -#define FPU_FPCCR_LSPACT_Pos 0U /*!< FPCCR: Lazy state preservation active bit Position */ -#define FPU_FPCCR_LSPACT_Msk (1UL /*<< FPU_FPCCR_LSPACT_Pos*/) /*!< FPCCR: Lazy state preservation active bit Mask */ - -/* Floating-Point Context Address Register Definitions */ -#define FPU_FPCAR_ADDRESS_Pos 3U /*!< FPCAR: ADDRESS bit Position */ -#define FPU_FPCAR_ADDRESS_Msk (0x1FFFFFFFUL << FPU_FPCAR_ADDRESS_Pos) /*!< FPCAR: ADDRESS bit Mask */ - -/* Floating-Point Default Status Control Register Definitions */ -#define FPU_FPDSCR_AHP_Pos 26U /*!< FPDSCR: AHP bit Position */ -#define FPU_FPDSCR_AHP_Msk (1UL << FPU_FPDSCR_AHP_Pos) /*!< FPDSCR: AHP bit Mask */ - -#define FPU_FPDSCR_DN_Pos 25U /*!< FPDSCR: DN bit Position */ -#define FPU_FPDSCR_DN_Msk (1UL << FPU_FPDSCR_DN_Pos) /*!< FPDSCR: DN bit Mask */ - -#define FPU_FPDSCR_FZ_Pos 24U /*!< FPDSCR: FZ bit Position */ -#define FPU_FPDSCR_FZ_Msk (1UL << FPU_FPDSCR_FZ_Pos) /*!< FPDSCR: FZ bit Mask */ - -#define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ -#define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ - -/* Media and FP Feature Register 0 Definitions */ -#define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */ -#define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */ - -#define FPU_MVFR0_Short_vectors_Pos 24U /*!< MVFR0: Short vectors bits Position */ -#define FPU_MVFR0_Short_vectors_Msk (0xFUL << FPU_MVFR0_Short_vectors_Pos) /*!< MVFR0: Short vectors bits Mask */ - -#define FPU_MVFR0_Square_root_Pos 20U /*!< MVFR0: Square root bits Position */ -#define FPU_MVFR0_Square_root_Msk (0xFUL << FPU_MVFR0_Square_root_Pos) /*!< MVFR0: Square root bits Mask */ - -#define FPU_MVFR0_Divide_Pos 16U /*!< MVFR0: Divide bits Position */ -#define FPU_MVFR0_Divide_Msk (0xFUL << FPU_MVFR0_Divide_Pos) /*!< MVFR0: Divide bits Mask */ - -#define FPU_MVFR0_FP_excep_trapping_Pos 12U /*!< MVFR0: FP exception trapping bits Position */ -#define FPU_MVFR0_FP_excep_trapping_Msk (0xFUL << FPU_MVFR0_FP_excep_trapping_Pos) /*!< MVFR0: FP exception trapping bits Mask */ - -#define FPU_MVFR0_Double_precision_Pos 8U /*!< MVFR0: Double-precision bits Position */ -#define FPU_MVFR0_Double_precision_Msk (0xFUL << FPU_MVFR0_Double_precision_Pos) /*!< MVFR0: Double-precision bits Mask */ - -#define FPU_MVFR0_Single_precision_Pos 4U /*!< MVFR0: Single-precision bits Position */ -#define FPU_MVFR0_Single_precision_Msk (0xFUL << FPU_MVFR0_Single_precision_Pos) /*!< MVFR0: Single-precision bits Mask */ - -#define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */ -#define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */ - -/* Media and FP Feature Register 1 Definitions */ -#define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */ -#define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */ - -#define FPU_MVFR1_FP_HPFP_Pos 24U /*!< MVFR1: FP HPFP bits Position */ -#define FPU_MVFR1_FP_HPFP_Msk (0xFUL << FPU_MVFR1_FP_HPFP_Pos) /*!< MVFR1: FP HPFP bits Mask */ - -#define FPU_MVFR1_D_NaN_mode_Pos 4U /*!< MVFR1: D_NaN mode bits Position */ -#define FPU_MVFR1_D_NaN_mode_Msk (0xFUL << FPU_MVFR1_D_NaN_mode_Pos) /*!< MVFR1: D_NaN mode bits Mask */ - -#define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */ -#define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */ - -/*@} end of group CMSIS_FPU */ -#endif - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) - \brief Type definitions for the Core Debug Registers - @{ - */ - -/** - \brief Structure type to access the Core Debug Register (CoreDebug). - */ -typedef struct -{ - __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ - __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ - __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ - __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ -} CoreDebug_Type; - -/* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ - -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ - -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ - -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ - -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ - -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ - -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ - -#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ - -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ - -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ - -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ - -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ - -/* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ - -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ - -/* Debug Exception and Monitor Control Register Definitions */ -#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */ -#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ - -#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */ -#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ - -#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */ -#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ - -#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */ -#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ - -#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */ -#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ - -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ - -#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */ -#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ - -#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */ -#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ - -#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */ -#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ - -#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */ -#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ - -#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */ -#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ - -#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */ -#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ - -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ - -/*@} 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. - \return Masked and shifted value. -*/ -#define _VAL2FLD(field, value) ((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. - \return Masked and shifted bit field value. -*/ -#define _FLD2VAL(field, value) ((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 Cortex-M4 Hardware */ -#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ -#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ -#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ -#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ -#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug 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 */ -#define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ -#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ -#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ -#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ - -#if (__MPU_PRESENT == 1U) - #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ - #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ -#endif - -#if (__FPU_PRESENT == 1U) - #define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */ - #define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */ -#endif - -/*@} */ - - - -/******************************************************************************* - * Hardware Abstraction Layer - Core Function Interface contains: - - Core NVIC Functions - - Core SysTick Functions - - Core Debug 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. - @{ - */ - -/** - \brief Set Priority Grouping - \details Sets the priority grouping field using the required unlock sequence. - The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. - Only values from 0..7 are used. - 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 Priority grouping field. - */ -__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) -{ - uint32_t reg_value; - uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ - - reg_value = SCB->AIRCR; /* read old register configuration */ - reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ - reg_value = (reg_value | - ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ - SCB->AIRCR = reg_value; -} - - -/** - \brief Get Priority Grouping - \details Reads the priority grouping field from the NVIC Interrupt Controller. - \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). - */ -__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void) -{ - return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); -} - - -/** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) -{ - NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) -{ - NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not pending. - \return 1 Interrupt status is pending. - */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Active Interrupt - \details Reads the active register in NVIC and returns the active bit. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not active. - \return 1 Interrupt status is active. - */ -__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. - \param [in] IRQn Interrupt number. - \param [in] priority Priority to set. - */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if ((int32_t)(IRQn) < 0) - { - SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } - else - { - NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } -} - - -/** - \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. - \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)SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); - } - else - { - return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (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 System Reset - \details Initiates a system reset request to reset the MCU. - */ -__STATIC_INLINE void NVIC_SystemReset(void) -{ - __DSB(); /* Ensure all outstanding memory accesses included - buffered write are completed before reset */ - SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | - SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */ - __DSB(); /* Ensure completion of memory access */ - - for(;;) /* wait until reset */ - { - __NOP(); - } -} - -/*@} end of CMSIS_Core_NVICFunctions */ - - - -/* ################################## SysTick function ############################################ */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_SysTickFunctions SysTick Functions - \brief Functions that configure the System. - @{ - */ - -#if (__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 __Vendor_SysTickConfig is set to 1, then the - function SysTick_Config is not included. In this case, the file device.h - 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 */ - - - -/* ##################################### Debug In/Output function ########################################### */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_core_DebugFunctions ITM Functions - \brief Functions that access the ITM debug interface. - @{ - */ - -extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ -#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ - - -/** - \brief ITM Send Character - \details Transmits a character via the ITM channel 0, and - \li Just returns when no debugger is connected that has booked the output. - \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted. - \param [in] ch Character to transmit. - \returns Character to transmit. - */ -__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) -{ - if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ - ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */ - { - while (ITM->PORT[0U].u32 == 0UL) - { - __NOP(); - } - ITM->PORT[0U].u8 = (uint8_t)ch; - } - return (ch); -} - - -/** - \brief ITM Receive Character - \details Inputs a character via the external variable \ref ITM_RxBuffer. - \return Received character. - \return -1 No character pending. - */ -__STATIC_INLINE int32_t ITM_ReceiveChar (void) -{ - int32_t ch = -1; /* no character available */ - - if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) - { - ch = ITM_RxBuffer; - ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ - } - - return (ch); -} - - -/** - \brief ITM Check Character - \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer. - \return 0 No character available. - \return 1 Character available. - */ -__STATIC_INLINE int32_t ITM_CheckChar (void) -{ - - if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) - { - return (0); /* no character available */ - } - else - { - return (1); /* character available */ - } -} - -/*@} end of CMSIS_core_DebugFunctions */ - - - - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_CM4_H_DEPENDANT */ - -#endif /* __CMSIS_GENERIC */ diff --git a/Software/Drivers/CMSIS/Include/core_cm7.h b/Software/Drivers/CMSIS/Include/core_cm7.h deleted file mode 100644 index 20963c1..0000000 --- a/Software/Drivers/CMSIS/Include/core_cm7.h +++ /dev/null @@ -1,2512 +0,0 @@ -/**************************************************************************//** - * @file core_cm7.h - * @brief CMSIS Cortex-M7 Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_CM7_H_GENERIC -#define __CORE_CM7_H_GENERIC - -#include - -#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.
- Function definitions in header files are used to allow 'inlining'. - - \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers. - - \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code. - */ - - -/******************************************************************************* - * CMSIS definitions - ******************************************************************************/ -/** - \ingroup Cortex_M7 - @{ - */ - -/* CMSIS CM7 definitions */ -#define __CM7_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __CM7_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ -#define __CM7_CMSIS_VERSION ((__CM7_CMSIS_VERSION_MAIN << 16U) | \ - __CM7_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_M (0x07U) /*!< Cortex-M Core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline - -#else - #error Unknown compiler -#endif - -/** __FPU_USED indicates whether an FPU is used or not. - For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions. -*/ -#if defined ( __CC_ARM ) - #if defined __TARGET_FPU_VFP - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #if defined __ARM_PCS_VFP - #if (__FPU_PRESENT == 1) - #define __FPU_USED 1U - #else - #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __GNUC__ ) - #if defined (__VFP_FP__) && !defined(__SOFTFP__) - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __ICCARM__ ) - #if defined __ARMVFP__ - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __TMS470__ ) - #if defined __TI_VFP_SUPPORT__ - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __TASKING__ ) - #if defined __FPU_VFP__ - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#elif defined ( __CSMC__ ) - #if ( __CSMC__ & 0x400U) - #if (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif - -#endif - -#include "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ -#include "core_cmSimd.h" /* Compiler specific SIMD Intrinsics */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_CM7_H_GENERIC */ - -#ifndef __CMSIS_GENERIC - -#ifndef __CORE_CM7_H_DEPENDANT -#define __CORE_CM7_H_DEPENDANT - -#ifdef __cplusplus - extern "C" { -#endif - -/* check device defines and use defaults */ -#if defined __CHECK_DEVICE_DEFINES - #ifndef __CM7_REV - #define __CM7_REV 0x0000U - #warning "__CM7_REV not defined in device header file; using default!" - #endif - - #ifndef __FPU_PRESENT - #define __FPU_PRESENT 0U - #warning "__FPU_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __MPU_PRESENT - #define __MPU_PRESENT 0U - #warning "__MPU_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __ICACHE_PRESENT - #define __ICACHE_PRESENT 0U - #warning "__ICACHE_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __DCACHE_PRESENT - #define __DCACHE_PRESENT 0U - #warning "__DCACHE_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __DTCM_PRESENT - #define __DTCM_PRESENT 0U - #warning "__DTCM_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __NVIC_PRIO_BITS - #define __NVIC_PRIO_BITS 3U - #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 - - IO Type Qualifiers 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_M7 */ - - - -/******************************************************************************* - * Register Abstraction - Core Register contain: - - Core Register - - Core NVIC Register - - Core SCB Register - - Core SysTick Register - - Core Debug Register - - Core MPU Register - - Core FPU 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:16; /*!< bit: 0..15 Reserved */ - uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ - uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - 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 */ - -#define APSR_Q_Pos 27U /*!< APSR: Q Position */ -#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q Mask */ - -#define APSR_GE_Pos 16U /*!< APSR: GE Position */ -#define APSR_GE_Msk (0xFUL << APSR_GE_Pos) /*!< APSR: GE 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:7; /*!< bit: 9..15 Reserved */ - uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ - uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ - uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ - uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - 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_Q_Pos 27U /*!< xPSR: Q Position */ -#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ - -#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ -#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT Mask */ - -#define xPSR_T_Pos 24U /*!< xPSR: T Position */ -#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */ - -#define xPSR_GE_Pos 16U /*!< xPSR: GE Position */ -#define xPSR_GE_Msk (0xFUL << xPSR_GE_Pos) /*!< xPSR: GE 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 nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ - uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ - uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ - uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ -} CONTROL_Type; - -/* CONTROL Register Definitions */ -#define CONTROL_FPCA_Pos 2U /*!< CONTROL: FPCA Position */ -#define CONTROL_FPCA_Msk (1UL << CONTROL_FPCA_Pos) /*!< CONTROL: FPCA Mask */ - -#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */ -#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */ - -#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ -#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV 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[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ - uint32_t RESERVED0[24U]; - __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RSERVED1[24U]; - __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ - uint32_t RESERVED2[24U]; - __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ - uint32_t RESERVED3[24U]; - __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ - uint32_t RESERVED4[56U]; - __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ - uint32_t RESERVED5[644U]; - __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ -} NVIC_Type; - -/* Software Triggered Interrupt Register Definitions */ -#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */ -#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */ - -/*@} 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 */ - __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ - __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 */ - __IOM uint8_t SHPR[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ - __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ - __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ - __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ - __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ - __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ - __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ - __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ - __IM uint32_t ID_PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ - __IM uint32_t ID_DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ID_AFR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ - __IM uint32_t ID_MFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ - __IM uint32_t ID_ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ - uint32_t RESERVED0[1U]; - __IM uint32_t CLIDR; /*!< Offset: 0x078 (R/ ) Cache Level ID register */ - __IM uint32_t CTR; /*!< Offset: 0x07C (R/ ) Cache Type register */ - __IM uint32_t CCSIDR; /*!< Offset: 0x080 (R/ ) Cache Size ID Register */ - __IOM uint32_t CSSELR; /*!< Offset: 0x084 (R/W) Cache Size Selection Register */ - __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ - uint32_t RESERVED3[93U]; - __OM uint32_t STIR; /*!< Offset: 0x200 ( /W) Software Triggered Interrupt Register */ - uint32_t RESERVED4[15U]; - __IM uint32_t MVFR0; /*!< Offset: 0x240 (R/ ) Media and VFP Feature Register 0 */ - __IM uint32_t MVFR1; /*!< Offset: 0x244 (R/ ) Media and VFP Feature Register 1 */ - __IM uint32_t MVFR2; /*!< Offset: 0x248 (R/ ) Media and VFP Feature Register 1 */ - uint32_t RESERVED5[1U]; - __OM uint32_t ICIALLU; /*!< Offset: 0x250 ( /W) I-Cache Invalidate All to PoU */ - uint32_t RESERVED6[1U]; - __OM uint32_t ICIMVAU; /*!< Offset: 0x258 ( /W) I-Cache Invalidate by MVA to PoU */ - __OM uint32_t DCIMVAC; /*!< Offset: 0x25C ( /W) D-Cache Invalidate by MVA to PoC */ - __OM uint32_t DCISW; /*!< Offset: 0x260 ( /W) D-Cache Invalidate by Set-way */ - __OM uint32_t DCCMVAU; /*!< Offset: 0x264 ( /W) D-Cache Clean by MVA to PoU */ - __OM uint32_t DCCMVAC; /*!< Offset: 0x268 ( /W) D-Cache Clean by MVA to PoC */ - __OM uint32_t DCCSW; /*!< Offset: 0x26C ( /W) D-Cache Clean by Set-way */ - __OM uint32_t DCCIMVAC; /*!< Offset: 0x270 ( /W) D-Cache Clean and Invalidate by MVA to PoC */ - __OM uint32_t DCCISW; /*!< Offset: 0x274 ( /W) D-Cache Clean and Invalidate by Set-way */ - uint32_t RESERVED7[6U]; - __IOM uint32_t ITCMCR; /*!< Offset: 0x290 (R/W) Instruction Tightly-Coupled Memory Control Register */ - __IOM uint32_t DTCMCR; /*!< Offset: 0x294 (R/W) Data Tightly-Coupled Memory Control Registers */ - __IOM uint32_t AHBPCR; /*!< Offset: 0x298 (R/W) AHBP Control Register */ - __IOM uint32_t CACR; /*!< Offset: 0x29C (R/W) L1 Cache Control Register */ - __IOM uint32_t AHBSCR; /*!< Offset: 0x2A0 (R/W) AHB Slave Control Register */ - uint32_t RESERVED8[1U]; - __IOM uint32_t ABFSR; /*!< Offset: 0x2A8 (R/W) Auxiliary Bus Fault Status 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_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */ -#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE 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 Vector Table Offset Register Definitions */ -#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ -#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF 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_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ -#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP 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 */ - -#define SCB_AIRCR_VECTRESET_Pos 0U /*!< SCB AIRCR: VECTRESET Position */ -#define SCB_AIRCR_VECTRESET_Msk (1UL /*<< SCB_AIRCR_VECTRESET_Pos*/) /*!< SCB AIRCR: VECTRESET 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_BP_Pos 18U /*!< SCB CCR: Branch prediction enable bit Position */ -#define SCB_CCR_BP_Msk (1UL << SCB_CCR_BP_Pos) /*!< SCB CCR: Branch prediction enable bit Mask */ - -#define SCB_CCR_IC_Pos 17U /*!< SCB CCR: Instruction cache enable bit Position */ -#define SCB_CCR_IC_Msk (1UL << SCB_CCR_IC_Pos) /*!< SCB CCR: Instruction cache enable bit Mask */ - -#define SCB_CCR_DC_Pos 16U /*!< SCB CCR: Cache enable bit Position */ -#define SCB_CCR_DC_Msk (1UL << SCB_CCR_DC_Pos) /*!< SCB CCR: Cache enable bit Mask */ - -#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_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */ -#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ - -#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */ -#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP 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 */ - -#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */ -#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ - -#define SCB_CCR_NONBASETHRDENA_Pos 0U /*!< SCB CCR: NONBASETHRDENA Position */ -#define SCB_CCR_NONBASETHRDENA_Msk (1UL /*<< SCB_CCR_NONBASETHRDENA_Pos*/) /*!< SCB CCR: NONBASETHRDENA Mask */ - -/* SCB System Handler Control and State Register Definitions */ -#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */ -#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ - -#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */ -#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ - -#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */ -#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ - -#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ -#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ - -#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */ -#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ - -#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */ -#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ - -#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */ -#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ - -#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */ -#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ - -#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */ -#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ - -#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */ -#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ - -#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */ -#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ - -#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */ -#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ - -#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */ -#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ - -#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */ -#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */ - -/* SCB Configurable Fault Status Register Definitions */ -#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */ -#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ - -#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */ -#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ - -#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ -#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ - -/* SCB Hard Fault Status Register Definitions */ -#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ -#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ - -#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */ -#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ - -#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */ -#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ - -/* SCB Debug Fault Status Register Definitions */ -#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */ -#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ - -#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */ -#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ - -#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */ -#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ - -#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */ -#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ - -#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */ -#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED Mask */ - -/* SCB Cache Level ID Register Definitions */ -#define SCB_CLIDR_LOUU_Pos 27U /*!< SCB CLIDR: LoUU Position */ -#define SCB_CLIDR_LOUU_Msk (7UL << SCB_CLIDR_LOUU_Pos) /*!< SCB CLIDR: LoUU Mask */ - -#define SCB_CLIDR_LOC_Pos 24U /*!< SCB CLIDR: LoC Position */ -#define SCB_CLIDR_LOC_Msk (7UL << SCB_CLIDR_LOC_Pos) /*!< SCB CLIDR: LoC Mask */ - -/* SCB Cache Type Register Definitions */ -#define SCB_CTR_FORMAT_Pos 29U /*!< SCB CTR: Format Position */ -#define SCB_CTR_FORMAT_Msk (7UL << SCB_CTR_FORMAT_Pos) /*!< SCB CTR: Format Mask */ - -#define SCB_CTR_CWG_Pos 24U /*!< SCB CTR: CWG Position */ -#define SCB_CTR_CWG_Msk (0xFUL << SCB_CTR_CWG_Pos) /*!< SCB CTR: CWG Mask */ - -#define SCB_CTR_ERG_Pos 20U /*!< SCB CTR: ERG Position */ -#define SCB_CTR_ERG_Msk (0xFUL << SCB_CTR_ERG_Pos) /*!< SCB CTR: ERG Mask */ - -#define SCB_CTR_DMINLINE_Pos 16U /*!< SCB CTR: DminLine Position */ -#define SCB_CTR_DMINLINE_Msk (0xFUL << SCB_CTR_DMINLINE_Pos) /*!< SCB CTR: DminLine Mask */ - -#define SCB_CTR_IMINLINE_Pos 0U /*!< SCB CTR: ImInLine Position */ -#define SCB_CTR_IMINLINE_Msk (0xFUL /*<< SCB_CTR_IMINLINE_Pos*/) /*!< SCB CTR: ImInLine Mask */ - -/* SCB Cache Size ID Register Definitions */ -#define SCB_CCSIDR_WT_Pos 31U /*!< SCB CCSIDR: WT Position */ -#define SCB_CCSIDR_WT_Msk (1UL << SCB_CCSIDR_WT_Pos) /*!< SCB CCSIDR: WT Mask */ - -#define SCB_CCSIDR_WB_Pos 30U /*!< SCB CCSIDR: WB Position */ -#define SCB_CCSIDR_WB_Msk (1UL << SCB_CCSIDR_WB_Pos) /*!< SCB CCSIDR: WB Mask */ - -#define SCB_CCSIDR_RA_Pos 29U /*!< SCB CCSIDR: RA Position */ -#define SCB_CCSIDR_RA_Msk (1UL << SCB_CCSIDR_RA_Pos) /*!< SCB CCSIDR: RA Mask */ - -#define SCB_CCSIDR_WA_Pos 28U /*!< SCB CCSIDR: WA Position */ -#define SCB_CCSIDR_WA_Msk (1UL << SCB_CCSIDR_WA_Pos) /*!< SCB CCSIDR: WA Mask */ - -#define SCB_CCSIDR_NUMSETS_Pos 13U /*!< SCB CCSIDR: NumSets Position */ -#define SCB_CCSIDR_NUMSETS_Msk (0x7FFFUL << SCB_CCSIDR_NUMSETS_Pos) /*!< SCB CCSIDR: NumSets Mask */ - -#define SCB_CCSIDR_ASSOCIATIVITY_Pos 3U /*!< SCB CCSIDR: Associativity Position */ -#define SCB_CCSIDR_ASSOCIATIVITY_Msk (0x3FFUL << SCB_CCSIDR_ASSOCIATIVITY_Pos) /*!< SCB CCSIDR: Associativity Mask */ - -#define SCB_CCSIDR_LINESIZE_Pos 0U /*!< SCB CCSIDR: LineSize Position */ -#define SCB_CCSIDR_LINESIZE_Msk (7UL /*<< SCB_CCSIDR_LINESIZE_Pos*/) /*!< SCB CCSIDR: LineSize Mask */ - -/* SCB Cache Size Selection Register Definitions */ -#define SCB_CSSELR_LEVEL_Pos 1U /*!< SCB CSSELR: Level Position */ -#define SCB_CSSELR_LEVEL_Msk (7UL << SCB_CSSELR_LEVEL_Pos) /*!< SCB CSSELR: Level Mask */ - -#define SCB_CSSELR_IND_Pos 0U /*!< SCB CSSELR: InD Position */ -#define SCB_CSSELR_IND_Msk (1UL /*<< SCB_CSSELR_IND_Pos*/) /*!< SCB CSSELR: InD Mask */ - -/* SCB Software Triggered Interrupt Register Definitions */ -#define SCB_STIR_INTID_Pos 0U /*!< SCB STIR: INTID Position */ -#define SCB_STIR_INTID_Msk (0x1FFUL /*<< SCB_STIR_INTID_Pos*/) /*!< SCB STIR: INTID Mask */ - -/* SCB D-Cache Invalidate by Set-way Register Definitions */ -#define SCB_DCISW_WAY_Pos 30U /*!< SCB DCISW: Way Position */ -#define SCB_DCISW_WAY_Msk (3UL << SCB_DCISW_WAY_Pos) /*!< SCB DCISW: Way Mask */ - -#define SCB_DCISW_SET_Pos 5U /*!< SCB DCISW: Set Position */ -#define SCB_DCISW_SET_Msk (0x1FFUL << SCB_DCISW_SET_Pos) /*!< SCB DCISW: Set Mask */ - -/* SCB D-Cache Clean by Set-way Register Definitions */ -#define SCB_DCCSW_WAY_Pos 30U /*!< SCB DCCSW: Way Position */ -#define SCB_DCCSW_WAY_Msk (3UL << SCB_DCCSW_WAY_Pos) /*!< SCB DCCSW: Way Mask */ - -#define SCB_DCCSW_SET_Pos 5U /*!< SCB DCCSW: Set Position */ -#define SCB_DCCSW_SET_Msk (0x1FFUL << SCB_DCCSW_SET_Pos) /*!< SCB DCCSW: Set Mask */ - -/* SCB D-Cache Clean and Invalidate by Set-way Register Definitions */ -#define SCB_DCCISW_WAY_Pos 30U /*!< SCB DCCISW: Way Position */ -#define SCB_DCCISW_WAY_Msk (3UL << SCB_DCCISW_WAY_Pos) /*!< SCB DCCISW: Way Mask */ - -#define SCB_DCCISW_SET_Pos 5U /*!< SCB DCCISW: Set Position */ -#define SCB_DCCISW_SET_Msk (0x1FFUL << SCB_DCCISW_SET_Pos) /*!< SCB DCCISW: Set Mask */ - -/* Instruction Tightly-Coupled Memory Control Register Definitions */ -#define SCB_ITCMCR_SZ_Pos 3U /*!< SCB ITCMCR: SZ Position */ -#define SCB_ITCMCR_SZ_Msk (0xFUL << SCB_ITCMCR_SZ_Pos) /*!< SCB ITCMCR: SZ Mask */ - -#define SCB_ITCMCR_RETEN_Pos 2U /*!< SCB ITCMCR: RETEN Position */ -#define SCB_ITCMCR_RETEN_Msk (1UL << SCB_ITCMCR_RETEN_Pos) /*!< SCB ITCMCR: RETEN Mask */ - -#define SCB_ITCMCR_RMW_Pos 1U /*!< SCB ITCMCR: RMW Position */ -#define SCB_ITCMCR_RMW_Msk (1UL << SCB_ITCMCR_RMW_Pos) /*!< SCB ITCMCR: RMW Mask */ - -#define SCB_ITCMCR_EN_Pos 0U /*!< SCB ITCMCR: EN Position */ -#define SCB_ITCMCR_EN_Msk (1UL /*<< SCB_ITCMCR_EN_Pos*/) /*!< SCB ITCMCR: EN Mask */ - -/* Data Tightly-Coupled Memory Control Register Definitions */ -#define SCB_DTCMCR_SZ_Pos 3U /*!< SCB DTCMCR: SZ Position */ -#define SCB_DTCMCR_SZ_Msk (0xFUL << SCB_DTCMCR_SZ_Pos) /*!< SCB DTCMCR: SZ Mask */ - -#define SCB_DTCMCR_RETEN_Pos 2U /*!< SCB DTCMCR: RETEN Position */ -#define SCB_DTCMCR_RETEN_Msk (1UL << SCB_DTCMCR_RETEN_Pos) /*!< SCB DTCMCR: RETEN Mask */ - -#define SCB_DTCMCR_RMW_Pos 1U /*!< SCB DTCMCR: RMW Position */ -#define SCB_DTCMCR_RMW_Msk (1UL << SCB_DTCMCR_RMW_Pos) /*!< SCB DTCMCR: RMW Mask */ - -#define SCB_DTCMCR_EN_Pos 0U /*!< SCB DTCMCR: EN Position */ -#define SCB_DTCMCR_EN_Msk (1UL /*<< SCB_DTCMCR_EN_Pos*/) /*!< SCB DTCMCR: EN Mask */ - -/* AHBP Control Register Definitions */ -#define SCB_AHBPCR_SZ_Pos 1U /*!< SCB AHBPCR: SZ Position */ -#define SCB_AHBPCR_SZ_Msk (7UL << SCB_AHBPCR_SZ_Pos) /*!< SCB AHBPCR: SZ Mask */ - -#define SCB_AHBPCR_EN_Pos 0U /*!< SCB AHBPCR: EN Position */ -#define SCB_AHBPCR_EN_Msk (1UL /*<< SCB_AHBPCR_EN_Pos*/) /*!< SCB AHBPCR: EN Mask */ - -/* L1 Cache Control Register Definitions */ -#define SCB_CACR_FORCEWT_Pos 2U /*!< SCB CACR: FORCEWT Position */ -#define SCB_CACR_FORCEWT_Msk (1UL << SCB_CACR_FORCEWT_Pos) /*!< SCB CACR: FORCEWT Mask */ - -#define SCB_CACR_ECCEN_Pos 1U /*!< SCB CACR: ECCEN Position */ -#define SCB_CACR_ECCEN_Msk (1UL << SCB_CACR_ECCEN_Pos) /*!< SCB CACR: ECCEN Mask */ - -#define SCB_CACR_SIWT_Pos 0U /*!< SCB CACR: SIWT Position */ -#define SCB_CACR_SIWT_Msk (1UL /*<< SCB_CACR_SIWT_Pos*/) /*!< SCB CACR: SIWT Mask */ - -/* AHBS Control Register Definitions */ -#define SCB_AHBSCR_INITCOUNT_Pos 11U /*!< SCB AHBSCR: INITCOUNT Position */ -#define SCB_AHBSCR_INITCOUNT_Msk (0x1FUL << SCB_AHBPCR_INITCOUNT_Pos) /*!< SCB AHBSCR: INITCOUNT Mask */ - -#define SCB_AHBSCR_TPRI_Pos 2U /*!< SCB AHBSCR: TPRI Position */ -#define SCB_AHBSCR_TPRI_Msk (0x1FFUL << SCB_AHBPCR_TPRI_Pos) /*!< SCB AHBSCR: TPRI Mask */ - -#define SCB_AHBSCR_CTL_Pos 0U /*!< SCB AHBSCR: CTL Position*/ -#define SCB_AHBSCR_CTL_Msk (3UL /*<< SCB_AHBPCR_CTL_Pos*/) /*!< SCB AHBSCR: CTL Mask */ - -/* Auxiliary Bus Fault Status Register Definitions */ -#define SCB_ABFSR_AXIMTYPE_Pos 8U /*!< SCB ABFSR: AXIMTYPE Position*/ -#define SCB_ABFSR_AXIMTYPE_Msk (3UL << SCB_ABFSR_AXIMTYPE_Pos) /*!< SCB ABFSR: AXIMTYPE Mask */ - -#define SCB_ABFSR_EPPB_Pos 4U /*!< SCB ABFSR: EPPB Position*/ -#define SCB_ABFSR_EPPB_Msk (1UL << SCB_ABFSR_EPPB_Pos) /*!< SCB ABFSR: EPPB Mask */ - -#define SCB_ABFSR_AXIM_Pos 3U /*!< SCB ABFSR: AXIM Position*/ -#define SCB_ABFSR_AXIM_Msk (1UL << SCB_ABFSR_AXIM_Pos) /*!< SCB ABFSR: AXIM Mask */ - -#define SCB_ABFSR_AHBP_Pos 2U /*!< SCB ABFSR: AHBP Position*/ -#define SCB_ABFSR_AHBP_Msk (1UL << SCB_ABFSR_AHBP_Pos) /*!< SCB ABFSR: AHBP Mask */ - -#define SCB_ABFSR_DTCM_Pos 1U /*!< SCB ABFSR: DTCM Position*/ -#define SCB_ABFSR_DTCM_Msk (1UL << SCB_ABFSR_DTCM_Pos) /*!< SCB ABFSR: DTCM Mask */ - -#define SCB_ABFSR_ITCM_Pos 0U /*!< SCB ABFSR: ITCM Position*/ -#define SCB_ABFSR_ITCM_Msk (1UL /*<< SCB_ABFSR_ITCM_Pos*/) /*!< SCB ABFSR: ITCM 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[1U]; - __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ - __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ -} SCnSCB_Type; - -/* Interrupt Controller Type Register Definitions */ -#define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */ -#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM Mask */ - -/* Auxiliary Control Register Definitions */ -#define SCnSCB_ACTLR_DISITMATBFLUSH_Pos 12U /*!< ACTLR: DISITMATBFLUSH Position */ -#define SCnSCB_ACTLR_DISITMATBFLUSH_Msk (1UL << SCnSCB_ACTLR_DISITMATBFLUSH_Pos) /*!< ACTLR: DISITMATBFLUSH Mask */ - -#define SCnSCB_ACTLR_DISRAMODE_Pos 11U /*!< ACTLR: DISRAMODE Position */ -#define SCnSCB_ACTLR_DISRAMODE_Msk (1UL << SCnSCB_ACTLR_DISRAMODE_Pos) /*!< ACTLR: DISRAMODE Mask */ - -#define SCnSCB_ACTLR_FPEXCODIS_Pos 10U /*!< ACTLR: FPEXCODIS Position */ -#define SCnSCB_ACTLR_FPEXCODIS_Msk (1UL << SCnSCB_ACTLR_FPEXCODIS_Pos) /*!< ACTLR: FPEXCODIS Mask */ - -#define SCnSCB_ACTLR_DISFOLD_Pos 2U /*!< ACTLR: DISFOLD Position */ -#define SCnSCB_ACTLR_DISFOLD_Msk (1UL << SCnSCB_ACTLR_DISFOLD_Pos) /*!< ACTLR: DISFOLD Mask */ - -#define SCnSCB_ACTLR_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */ -#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT 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_ITM Instrumentation Trace Macrocell (ITM) - \brief Type definitions for the Instrumentation Trace Macrocell (ITM) - @{ - */ - -/** - \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). - */ -typedef struct -{ - __OM union - { - __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ - __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ - __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ - } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ - uint32_t RESERVED0[864U]; - __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ - uint32_t RESERVED1[15U]; - __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ - uint32_t RESERVED2[15U]; - __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[29U]; - __OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */ - __IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */ - __IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */ - uint32_t RESERVED4[43U]; - __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ - __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ - uint32_t RESERVED5[6U]; - __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ - __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ - __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ - __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ - __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ - __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ - __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ - __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ - __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ - __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ - __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ - __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ -} ITM_Type; - -/* ITM Trace Privilege Register Definitions */ -#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ -#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ - -/* ITM Trace Control Register Definitions */ -#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ -#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ - -#define ITM_TCR_TraceBusID_Pos 16U /*!< ITM TCR: ATBID Position */ -#define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */ - -#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */ -#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ - -#define ITM_TCR_TSPrescale_Pos 8U /*!< ITM TCR: TSPrescale Position */ -#define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */ - -#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */ -#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ - -#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */ -#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */ - -#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */ -#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ - -#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */ -#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ - -#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ -#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ - -/* ITM Integration Write Register Definitions */ -#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */ -#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */ - -/* ITM Integration Read Register Definitions */ -#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */ -#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */ - -/* ITM Integration Mode Control Register Definitions */ -#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */ -#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */ - -/* ITM Lock Status Register Definitions */ -#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ -#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ - -#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */ -#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */ - -#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */ -#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */ - -/*@}*/ /* end of group CMSIS_ITM */ - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT) - \brief Type definitions for the Data Watchpoint and Trace (DWT) - @{ - */ - -/** - \brief Structure type to access the Data Watchpoint and Trace Register (DWT). - */ -typedef struct -{ - __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ - __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ - __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ - __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ - __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ - __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ - __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ - __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ - __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ - __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */ - __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ - uint32_t RESERVED0[1U]; - __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ - __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */ - __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ - uint32_t RESERVED1[1U]; - __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ - __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */ - __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ - uint32_t RESERVED2[1U]; - __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ - __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */ - __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ - uint32_t RESERVED3[981U]; - __OM uint32_t LAR; /*!< Offset: 0xFB0 ( W) Lock Access Register */ - __IM uint32_t LSR; /*!< Offset: 0xFB4 (R ) Lock Status Register */ -} DWT_Type; - -/* DWT Control Register Definitions */ -#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */ -#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */ - -#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */ -#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */ - -#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */ -#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */ - -#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */ -#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */ - -#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */ -#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */ - -#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */ -#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */ - -#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */ -#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */ - -#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */ -#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */ - -#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */ -#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */ - -#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */ -#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */ - -#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */ -#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */ - -#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */ -#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */ - -#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */ -#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */ - -#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */ -#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */ - -#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */ -#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */ - -#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */ -#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */ - -#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */ -#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */ - -#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */ -#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */ - -/* DWT CPI Count Register Definitions */ -#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */ -#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */ - -/* DWT Exception Overhead Count Register Definitions */ -#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */ -#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */ - -/* DWT Sleep Count Register Definitions */ -#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */ -#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */ - -/* DWT LSU Count Register Definitions */ -#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */ -#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */ - -/* DWT Folded-instruction Count Register Definitions */ -#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */ -#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */ - -/* DWT Comparator Mask Register Definitions */ -#define DWT_MASK_MASK_Pos 0U /*!< DWT MASK: MASK Position */ -#define DWT_MASK_MASK_Msk (0x1FUL /*<< DWT_MASK_MASK_Pos*/) /*!< DWT MASK: MASK Mask */ - -/* DWT Comparator Function Register Definitions */ -#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */ -#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */ - -#define DWT_FUNCTION_DATAVADDR1_Pos 16U /*!< DWT FUNCTION: DATAVADDR1 Position */ -#define DWT_FUNCTION_DATAVADDR1_Msk (0xFUL << DWT_FUNCTION_DATAVADDR1_Pos) /*!< DWT FUNCTION: DATAVADDR1 Mask */ - -#define DWT_FUNCTION_DATAVADDR0_Pos 12U /*!< DWT FUNCTION: DATAVADDR0 Position */ -#define DWT_FUNCTION_DATAVADDR0_Msk (0xFUL << DWT_FUNCTION_DATAVADDR0_Pos) /*!< DWT FUNCTION: DATAVADDR0 Mask */ - -#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */ -#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */ - -#define DWT_FUNCTION_LNK1ENA_Pos 9U /*!< DWT FUNCTION: LNK1ENA Position */ -#define DWT_FUNCTION_LNK1ENA_Msk (0x1UL << DWT_FUNCTION_LNK1ENA_Pos) /*!< DWT FUNCTION: LNK1ENA Mask */ - -#define DWT_FUNCTION_DATAVMATCH_Pos 8U /*!< DWT FUNCTION: DATAVMATCH Position */ -#define DWT_FUNCTION_DATAVMATCH_Msk (0x1UL << DWT_FUNCTION_DATAVMATCH_Pos) /*!< DWT FUNCTION: DATAVMATCH Mask */ - -#define DWT_FUNCTION_CYCMATCH_Pos 7U /*!< DWT FUNCTION: CYCMATCH Position */ -#define DWT_FUNCTION_CYCMATCH_Msk (0x1UL << DWT_FUNCTION_CYCMATCH_Pos) /*!< DWT FUNCTION: CYCMATCH Mask */ - -#define DWT_FUNCTION_EMITRANGE_Pos 5U /*!< DWT FUNCTION: EMITRANGE Position */ -#define DWT_FUNCTION_EMITRANGE_Msk (0x1UL << DWT_FUNCTION_EMITRANGE_Pos) /*!< DWT FUNCTION: EMITRANGE Mask */ - -#define DWT_FUNCTION_FUNCTION_Pos 0U /*!< DWT FUNCTION: FUNCTION Position */ -#define DWT_FUNCTION_FUNCTION_Msk (0xFUL /*<< DWT_FUNCTION_FUNCTION_Pos*/) /*!< DWT FUNCTION: FUNCTION Mask */ - -/*@}*/ /* end of group CMSIS_DWT */ - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_TPI Trace Port Interface (TPI) - \brief Type definitions for the Trace Port Interface (TPI) - @{ - */ - -/** - \brief Structure type to access the Trace Port Interface Register (TPI). - */ -typedef struct -{ - __IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ - __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ - uint32_t RESERVED0[2U]; - __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ - uint32_t RESERVED1[55U]; - __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ - uint32_t RESERVED2[131U]; - __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ - __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ - __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ - uint32_t RESERVED3[759U]; - __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */ - __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ - __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ - uint32_t RESERVED4[1U]; - __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */ - __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */ - __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */ - uint32_t RESERVED5[39U]; - __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */ - __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */ - uint32_t RESERVED7[8U]; - __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */ - __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */ -} TPI_Type; - -/* TPI Asynchronous Clock Prescaler Register Definitions */ -#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */ -#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */ - -/* TPI Selected Pin Protocol Register Definitions */ -#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */ -#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */ - -/* TPI Formatter and Flush Status Register Definitions */ -#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */ -#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */ - -#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */ -#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */ - -#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */ -#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */ - -#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */ -#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */ - -/* TPI Formatter and Flush Control Register Definitions */ -#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */ -#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */ - -#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */ -#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */ - -/* TPI TRIGGER Register Definitions */ -#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */ -#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */ - -/* TPI Integration ETM Data Register Definitions (FIFO0) */ -#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */ -#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ - -#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */ -#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */ - -#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */ -#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ - -#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */ -#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */ - -#define TPI_FIFO0_ETM2_Pos 16U /*!< TPI FIFO0: ETM2 Position */ -#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */ - -#define TPI_FIFO0_ETM1_Pos 8U /*!< TPI FIFO0: ETM1 Position */ -#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */ - -#define TPI_FIFO0_ETM0_Pos 0U /*!< TPI FIFO0: ETM0 Position */ -#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */ - -/* TPI ITATBCTR2 Register Definitions */ -#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */ -#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */ - -/* TPI Integration ITM Data Register Definitions (FIFO1) */ -#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */ -#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ - -#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */ -#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */ - -#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */ -#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ - -#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */ -#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */ - -#define TPI_FIFO1_ITM2_Pos 16U /*!< TPI FIFO1: ITM2 Position */ -#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */ - -#define TPI_FIFO1_ITM1_Pos 8U /*!< TPI FIFO1: ITM1 Position */ -#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */ - -#define TPI_FIFO1_ITM0_Pos 0U /*!< TPI FIFO1: ITM0 Position */ -#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */ - -/* TPI ITATBCTR0 Register Definitions */ -#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */ -#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */ - -/* TPI Integration Mode Control Register Definitions */ -#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */ -#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ - -/* TPI DEVID Register Definitions */ -#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ -#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */ - -#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */ -#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */ - -#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */ -#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */ - -#define TPI_DEVID_MinBufSz_Pos 6U /*!< TPI DEVID: MinBufSz Position */ -#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */ - -#define TPI_DEVID_AsynClkIn_Pos 5U /*!< TPI DEVID: AsynClkIn Position */ -#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */ - -#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */ -#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */ - -/* TPI DEVTYPE Register Definitions */ -#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */ -#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ - -#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */ -#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ - -/*@}*/ /* end of group CMSIS_TPI */ - - -#if (__MPU_PRESENT == 1U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_MPU Memory Protection Unit (MPU) - \brief Type definitions for the Memory Protection Unit (MPU) - @{ - */ - -/** - \brief Structure type to access the Memory Protection Unit (MPU). - */ -typedef struct -{ - __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ - __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ - __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ - __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */ - __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */ - __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */ - __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ -} MPU_Type; - -/* MPU Type Register Definitions */ -#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ -#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ - -#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ -#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ - -#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ -#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ - -/* MPU Control Register Definitions */ -#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ -#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ - -#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ -#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ - -#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ -#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ - -/* MPU Region Number Register Definitions */ -#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ -#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ - -/* MPU Region Base Address Register Definitions */ -#define MPU_RBAR_ADDR_Pos 5U /*!< MPU RBAR: ADDR Position */ -#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ - -#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */ -#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ - -#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */ -#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */ - -/* MPU Region Attribute and Size Register Definitions */ -#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */ -#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ - -#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */ -#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */ - -#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */ -#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */ - -#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */ -#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */ - -#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */ -#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */ - -#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */ -#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */ - -#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */ -#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */ - -#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */ -#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ - -#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */ -#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ - -#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */ -#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */ - -/*@} end of group CMSIS_MPU */ -#endif - - -#if (__FPU_PRESENT == 1U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_FPU Floating Point Unit (FPU) - \brief Type definitions for the Floating Point Unit (FPU) - @{ - */ - -/** - \brief Structure type to access the Floating Point Unit (FPU). - */ -typedef struct -{ - uint32_t RESERVED0[1U]; - __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ - __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ - __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ - __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ - __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ - __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and FP Feature Register 2 */ -} FPU_Type; - -/* Floating-Point Context Control Register Definitions */ -#define FPU_FPCCR_ASPEN_Pos 31U /*!< FPCCR: ASPEN bit Position */ -#define FPU_FPCCR_ASPEN_Msk (1UL << FPU_FPCCR_ASPEN_Pos) /*!< FPCCR: ASPEN bit Mask */ - -#define FPU_FPCCR_LSPEN_Pos 30U /*!< FPCCR: LSPEN Position */ -#define FPU_FPCCR_LSPEN_Msk (1UL << FPU_FPCCR_LSPEN_Pos) /*!< FPCCR: LSPEN bit Mask */ - -#define FPU_FPCCR_MONRDY_Pos 8U /*!< FPCCR: MONRDY Position */ -#define FPU_FPCCR_MONRDY_Msk (1UL << FPU_FPCCR_MONRDY_Pos) /*!< FPCCR: MONRDY bit Mask */ - -#define FPU_FPCCR_BFRDY_Pos 6U /*!< FPCCR: BFRDY Position */ -#define FPU_FPCCR_BFRDY_Msk (1UL << FPU_FPCCR_BFRDY_Pos) /*!< FPCCR: BFRDY bit Mask */ - -#define FPU_FPCCR_MMRDY_Pos 5U /*!< FPCCR: MMRDY Position */ -#define FPU_FPCCR_MMRDY_Msk (1UL << FPU_FPCCR_MMRDY_Pos) /*!< FPCCR: MMRDY bit Mask */ - -#define FPU_FPCCR_HFRDY_Pos 4U /*!< FPCCR: HFRDY Position */ -#define FPU_FPCCR_HFRDY_Msk (1UL << FPU_FPCCR_HFRDY_Pos) /*!< FPCCR: HFRDY bit Mask */ - -#define FPU_FPCCR_THREAD_Pos 3U /*!< FPCCR: processor mode bit Position */ -#define FPU_FPCCR_THREAD_Msk (1UL << FPU_FPCCR_THREAD_Pos) /*!< FPCCR: processor mode active bit Mask */ - -#define FPU_FPCCR_USER_Pos 1U /*!< FPCCR: privilege level bit Position */ -#define FPU_FPCCR_USER_Msk (1UL << FPU_FPCCR_USER_Pos) /*!< FPCCR: privilege level bit Mask */ - -#define FPU_FPCCR_LSPACT_Pos 0U /*!< FPCCR: Lazy state preservation active bit Position */ -#define FPU_FPCCR_LSPACT_Msk (1UL /*<< FPU_FPCCR_LSPACT_Pos*/) /*!< FPCCR: Lazy state preservation active bit Mask */ - -/* Floating-Point Context Address Register Definitions */ -#define FPU_FPCAR_ADDRESS_Pos 3U /*!< FPCAR: ADDRESS bit Position */ -#define FPU_FPCAR_ADDRESS_Msk (0x1FFFFFFFUL << FPU_FPCAR_ADDRESS_Pos) /*!< FPCAR: ADDRESS bit Mask */ - -/* Floating-Point Default Status Control Register Definitions */ -#define FPU_FPDSCR_AHP_Pos 26U /*!< FPDSCR: AHP bit Position */ -#define FPU_FPDSCR_AHP_Msk (1UL << FPU_FPDSCR_AHP_Pos) /*!< FPDSCR: AHP bit Mask */ - -#define FPU_FPDSCR_DN_Pos 25U /*!< FPDSCR: DN bit Position */ -#define FPU_FPDSCR_DN_Msk (1UL << FPU_FPDSCR_DN_Pos) /*!< FPDSCR: DN bit Mask */ - -#define FPU_FPDSCR_FZ_Pos 24U /*!< FPDSCR: FZ bit Position */ -#define FPU_FPDSCR_FZ_Msk (1UL << FPU_FPDSCR_FZ_Pos) /*!< FPDSCR: FZ bit Mask */ - -#define FPU_FPDSCR_RMode_Pos 22U /*!< FPDSCR: RMode bit Position */ -#define FPU_FPDSCR_RMode_Msk (3UL << FPU_FPDSCR_RMode_Pos) /*!< FPDSCR: RMode bit Mask */ - -/* Media and FP Feature Register 0 Definitions */ -#define FPU_MVFR0_FP_rounding_modes_Pos 28U /*!< MVFR0: FP rounding modes bits Position */ -#define FPU_MVFR0_FP_rounding_modes_Msk (0xFUL << FPU_MVFR0_FP_rounding_modes_Pos) /*!< MVFR0: FP rounding modes bits Mask */ - -#define FPU_MVFR0_Short_vectors_Pos 24U /*!< MVFR0: Short vectors bits Position */ -#define FPU_MVFR0_Short_vectors_Msk (0xFUL << FPU_MVFR0_Short_vectors_Pos) /*!< MVFR0: Short vectors bits Mask */ - -#define FPU_MVFR0_Square_root_Pos 20U /*!< MVFR0: Square root bits Position */ -#define FPU_MVFR0_Square_root_Msk (0xFUL << FPU_MVFR0_Square_root_Pos) /*!< MVFR0: Square root bits Mask */ - -#define FPU_MVFR0_Divide_Pos 16U /*!< MVFR0: Divide bits Position */ -#define FPU_MVFR0_Divide_Msk (0xFUL << FPU_MVFR0_Divide_Pos) /*!< MVFR0: Divide bits Mask */ - -#define FPU_MVFR0_FP_excep_trapping_Pos 12U /*!< MVFR0: FP exception trapping bits Position */ -#define FPU_MVFR0_FP_excep_trapping_Msk (0xFUL << FPU_MVFR0_FP_excep_trapping_Pos) /*!< MVFR0: FP exception trapping bits Mask */ - -#define FPU_MVFR0_Double_precision_Pos 8U /*!< MVFR0: Double-precision bits Position */ -#define FPU_MVFR0_Double_precision_Msk (0xFUL << FPU_MVFR0_Double_precision_Pos) /*!< MVFR0: Double-precision bits Mask */ - -#define FPU_MVFR0_Single_precision_Pos 4U /*!< MVFR0: Single-precision bits Position */ -#define FPU_MVFR0_Single_precision_Msk (0xFUL << FPU_MVFR0_Single_precision_Pos) /*!< MVFR0: Single-precision bits Mask */ - -#define FPU_MVFR0_A_SIMD_registers_Pos 0U /*!< MVFR0: A_SIMD registers bits Position */ -#define FPU_MVFR0_A_SIMD_registers_Msk (0xFUL /*<< FPU_MVFR0_A_SIMD_registers_Pos*/) /*!< MVFR0: A_SIMD registers bits Mask */ - -/* Media and FP Feature Register 1 Definitions */ -#define FPU_MVFR1_FP_fused_MAC_Pos 28U /*!< MVFR1: FP fused MAC bits Position */ -#define FPU_MVFR1_FP_fused_MAC_Msk (0xFUL << FPU_MVFR1_FP_fused_MAC_Pos) /*!< MVFR1: FP fused MAC bits Mask */ - -#define FPU_MVFR1_FP_HPFP_Pos 24U /*!< MVFR1: FP HPFP bits Position */ -#define FPU_MVFR1_FP_HPFP_Msk (0xFUL << FPU_MVFR1_FP_HPFP_Pos) /*!< MVFR1: FP HPFP bits Mask */ - -#define FPU_MVFR1_D_NaN_mode_Pos 4U /*!< MVFR1: D_NaN mode bits Position */ -#define FPU_MVFR1_D_NaN_mode_Msk (0xFUL << FPU_MVFR1_D_NaN_mode_Pos) /*!< MVFR1: D_NaN mode bits Mask */ - -#define FPU_MVFR1_FtZ_mode_Pos 0U /*!< MVFR1: FtZ mode bits Position */ -#define FPU_MVFR1_FtZ_mode_Msk (0xFUL /*<< FPU_MVFR1_FtZ_mode_Pos*/) /*!< MVFR1: FtZ mode bits Mask */ - -/* Media and FP Feature Register 2 Definitions */ - -/*@} end of group CMSIS_FPU */ -#endif - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) - \brief Type definitions for the Core Debug Registers - @{ - */ - -/** - \brief Structure type to access the Core Debug Register (CoreDebug). - */ -typedef struct -{ - __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ - __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ - __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ - __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ -} CoreDebug_Type; - -/* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ - -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ - -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ - -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ - -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ - -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ - -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ - -#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ - -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ - -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ - -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ - -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ - -/* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ - -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ - -/* Debug Exception and Monitor Control Register Definitions */ -#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */ -#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ - -#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */ -#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ - -#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */ -#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ - -#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */ -#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ - -#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */ -#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ - -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ - -#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */ -#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ - -#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */ -#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ - -#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */ -#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ - -#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */ -#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ - -#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */ -#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ - -#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */ -#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ - -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ - -/*@} 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. - \return Masked and shifted value. -*/ -#define _VAL2FLD(field, value) ((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. - \return Masked and shifted bit field value. -*/ -#define _FLD2VAL(field, value) ((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 Cortex-M4 Hardware */ -#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ -#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ -#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ -#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ -#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug 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 */ -#define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ -#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ -#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ -#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ - -#if (__MPU_PRESENT == 1U) - #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ - #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ -#endif - -#if (__FPU_PRESENT == 1U) - #define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */ - #define FPU ((FPU_Type *) FPU_BASE ) /*!< Floating Point Unit */ -#endif - -/*@} */ - - - -/******************************************************************************* - * Hardware Abstraction Layer - Core Function Interface contains: - - Core NVIC Functions - - Core SysTick Functions - - Core Debug 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. - @{ - */ - -/** - \brief Set Priority Grouping - \details Sets the priority grouping field using the required unlock sequence. - The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. - Only values from 0..7 are used. - 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 Priority grouping field. - */ -__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) -{ - uint32_t reg_value; - uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ - - reg_value = SCB->AIRCR; /* read old register configuration */ - reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ - reg_value = (reg_value | - ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ - SCB->AIRCR = reg_value; -} - - -/** - \brief Get Priority Grouping - \details Reads the priority grouping field from the NVIC Interrupt Controller. - \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). - */ -__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void) -{ - return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); -} - - -/** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) -{ - NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) -{ - NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not pending. - \return 1 Interrupt status is pending. - */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Active Interrupt - \details Reads the active register in NVIC and returns the active bit. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not active. - \return 1 Interrupt status is active. - */ -__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. - \param [in] IRQn Interrupt number. - \param [in] priority Priority to set. - */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if ((int32_t)(IRQn) < 0) - { - SCB->SHPR[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } - else - { - NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } -} - - -/** - \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. - \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)SCB->SHPR[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); - } - else - { - return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (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 System Reset - \details Initiates a system reset request to reset the MCU. - */ -__STATIC_INLINE void NVIC_SystemReset(void) -{ - __DSB(); /* Ensure all outstanding memory accesses included - buffered write are completed before reset */ - SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | - SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */ - __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) -{ - uint32_t mvfr0; - - mvfr0 = SCB->MVFR0; - if ((mvfr0 & 0x00000FF0UL) == 0x220UL) - { - return 2UL; /* Double + Single precision FPU */ - } - else if ((mvfr0 & 0x00000FF0UL) == 0x020UL) - { - return 1UL; /* Single precision FPU */ - } - else - { - return 0UL; /* No FPU */ - } -} - - -/*@} end of CMSIS_Core_FpuFunctions */ - - - -/* ########################## Cache functions #################################### */ -/** - \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 ) - - -/** - \brief Enable I-Cache - \details Turns on I-Cache - */ -__STATIC_INLINE void SCB_EnableICache (void) -{ - #if (__ICACHE_PRESENT == 1U) - __DSB(); - __ISB(); - SCB->ICIALLU = 0UL; /* invalidate I-Cache */ - SCB->CCR |= (uint32_t)SCB_CCR_IC_Msk; /* enable I-Cache */ - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Disable I-Cache - \details Turns off I-Cache - */ -__STATIC_INLINE void SCB_DisableICache (void) -{ - #if (__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_INLINE void SCB_InvalidateICache (void) -{ - #if (__ICACHE_PRESENT == 1U) - __DSB(); - __ISB(); - SCB->ICIALLU = 0UL; - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Enable D-Cache - \details Turns on D-Cache - */ -__STATIC_INLINE void SCB_EnableDCache (void) -{ - #if (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = (0U << 1U) | 0U; /* 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--); - } while(sets--); - __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_INLINE void SCB_DisableDCache (void) -{ - #if (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = (0U << 1U) | 0U; /* Level 1 data cache */ - __DSB(); - - ccsidr = SCB->CCSIDR; - - SCB->CCR &= ~(uint32_t)SCB_CCR_DC_Msk; /* disable D-Cache */ - - /* 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--); - } while(sets--); - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Invalidate D-Cache - \details Invalidates D-Cache - */ -__STATIC_INLINE void SCB_InvalidateDCache (void) -{ - #if (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = (0U << 1U) | 0U; /* 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--); - } while(sets--); - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Clean D-Cache - \details Cleans D-Cache - */ -__STATIC_INLINE void SCB_CleanDCache (void) -{ - #if (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = (0U << 1U) | 0U; /* 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--); - } while(sets--); - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief Clean & Invalidate D-Cache - \details Cleans and Invalidates D-Cache - */ -__STATIC_INLINE void SCB_CleanInvalidateDCache (void) -{ - #if (__DCACHE_PRESENT == 1U) - uint32_t ccsidr; - uint32_t sets; - uint32_t ways; - - SCB->CSSELR = (0U << 1U) | 0U; /* 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--); - } while(sets--); - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief D-Cache Invalidate by address - \details Invalidates D-Cache for the given address - \param[in] addr address (aligned to 32-byte boundary) - \param[in] dsize size of memory block (in number of bytes) -*/ -__STATIC_INLINE void SCB_InvalidateDCache_by_Addr (uint32_t *addr, int32_t dsize) -{ - #if (__DCACHE_PRESENT == 1U) - int32_t op_size = dsize; - uint32_t op_addr = (uint32_t)addr; - int32_t linesize = 32U; /* in Cortex-M7 size of cache line is fixed to 8 words (32 bytes) */ - - __DSB(); - - while (op_size > 0) { - SCB->DCIMVAC = op_addr; - op_addr += linesize; - op_size -= linesize; - } - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief D-Cache Clean by address - \details Cleans D-Cache for the given address - \param[in] addr address (aligned to 32-byte boundary) - \param[in] dsize size of memory block (in number of bytes) -*/ -__STATIC_INLINE void SCB_CleanDCache_by_Addr (uint32_t *addr, int32_t dsize) -{ - #if (__DCACHE_PRESENT == 1) - int32_t op_size = dsize; - uint32_t op_addr = (uint32_t) addr; - int32_t linesize = 32U; /* in Cortex-M7 size of cache line is fixed to 8 words (32 bytes) */ - - __DSB(); - - while (op_size > 0) { - SCB->DCCMVAC = op_addr; - op_addr += linesize; - op_size -= linesize; - } - - __DSB(); - __ISB(); - #endif -} - - -/** - \brief D-Cache Clean and Invalidate by address - \details Cleans and invalidates D_Cache for the given address - \param[in] addr address (aligned to 32-byte boundary) - \param[in] dsize size of memory block (in number of bytes) -*/ -__STATIC_INLINE void SCB_CleanInvalidateDCache_by_Addr (uint32_t *addr, int32_t dsize) -{ - #if (__DCACHE_PRESENT == 1U) - int32_t op_size = dsize; - uint32_t op_addr = (uint32_t) addr; - int32_t linesize = 32U; /* in Cortex-M7 size of cache line is fixed to 8 words (32 bytes) */ - - __DSB(); - - while (op_size > 0) { - SCB->DCCIMVAC = op_addr; - op_addr += linesize; - op_size -= linesize; - } - - __DSB(); - __ISB(); - #endif -} - - -/*@} end of CMSIS_Core_CacheFunctions */ - - - -/* ################################## SysTick function ############################################ */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_SysTickFunctions SysTick Functions - \brief Functions that configure the System. - @{ - */ - -#if (__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 __Vendor_SysTickConfig is set to 1, then the - function SysTick_Config is not included. In this case, the file device.h - 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 */ - - - -/* ##################################### Debug In/Output function ########################################### */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_core_DebugFunctions ITM Functions - \brief Functions that access the ITM debug interface. - @{ - */ - -extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ -#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ - - -/** - \brief ITM Send Character - \details Transmits a character via the ITM channel 0, and - \li Just returns when no debugger is connected that has booked the output. - \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted. - \param [in] ch Character to transmit. - \returns Character to transmit. - */ -__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) -{ - if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ - ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */ - { - while (ITM->PORT[0U].u32 == 0UL) - { - __NOP(); - } - ITM->PORT[0U].u8 = (uint8_t)ch; - } - return (ch); -} - - -/** - \brief ITM Receive Character - \details Inputs a character via the external variable \ref ITM_RxBuffer. - \return Received character. - \return -1 No character pending. - */ -__STATIC_INLINE int32_t ITM_ReceiveChar (void) -{ - int32_t ch = -1; /* no character available */ - - if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) - { - ch = ITM_RxBuffer; - ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ - } - - return (ch); -} - - -/** - \brief ITM Check Character - \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer. - \return 0 No character available. - \return 1 Character available. - */ -__STATIC_INLINE int32_t ITM_CheckChar (void) -{ - - if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) - { - return (0); /* no character available */ - } - else - { - return (1); /* character available */ - } -} - -/*@} end of CMSIS_core_DebugFunctions */ - - - - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_CM7_H_DEPENDANT */ - -#endif /* __CMSIS_GENERIC */ diff --git a/Software/Drivers/CMSIS/Include/core_sc000.h b/Software/Drivers/CMSIS/Include/core_sc000.h deleted file mode 100644 index ea16bf3..0000000 --- a/Software/Drivers/CMSIS/Include/core_sc000.h +++ /dev/null @@ -1,926 +0,0 @@ -/**************************************************************************//** - * @file core_sc000.h - * @brief CMSIS SC000 Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_SC000_H_GENERIC -#define __CORE_SC000_H_GENERIC - -#include - -#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.
- Function definitions in header files are used to allow 'inlining'. - - \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers. - - \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code. - */ - - -/******************************************************************************* - * CMSIS definitions - ******************************************************************************/ -/** - \ingroup SC000 - @{ - */ - -/* CMSIS SC000 definitions */ -#define __SC000_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __SC000_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ -#define __SC000_CMSIS_VERSION ((__SC000_CMSIS_VERSION_MAIN << 16U) | \ - __SC000_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_SC (000U) /*!< Cortex secure core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline - -#else - #error Unknown compiler -#endif - -/** __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_PCS_VFP - #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 ( __TMS470__ ) - #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 "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_SC000_H_GENERIC */ - -#ifndef __CMSIS_GENERIC - -#ifndef __CORE_SC000_H_DEPENDANT -#define __CORE_SC000_H_DEPENDANT - -#ifdef __cplusplus - extern "C" { -#endif - -/* check device defines and use defaults */ -#if defined __CHECK_DEVICE_DEFINES - #ifndef __SC000_REV - #define __SC000_REV 0x0000U - #warning "__SC000_REV not defined in device header file; using default!" - #endif - - #ifndef __MPU_PRESENT - #define __MPU_PRESENT 0U - #warning "__MPU_PRESENT 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 - - IO Type Qualifiers 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 SC000 */ - - - -/******************************************************************************* - * Register Abstraction - Core Register contain: - - Core Register - - Core NVIC Register - - Core SCB Register - - Core SysTick Register - - Core MPU 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 */ - __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ - __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 RESERVED0[1U]; - __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 */ - uint32_t RESERVED1[154U]; - __IOM uint32_t SFCR; /*!< Offset: 0x290 (R/W) Security Features Control 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 Interrupt Control State Register Definitions */ -#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ -#define SCB_VTOR_TBLOFF_Msk (0x1FFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF 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_DISMCYCINT_Pos 0U /*!< ACTLR: DISMCYCINT Position */ -#define SCnSCB_ACTLR_DISMCYCINT_Msk (1UL /*<< SCnSCB_ACTLR_DISMCYCINT_Pos*/) /*!< ACTLR: DISMCYCINT 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 */ - -#if (__MPU_PRESENT == 1U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_MPU Memory Protection Unit (MPU) - \brief Type definitions for the Memory Protection Unit (MPU) - @{ - */ - -/** - \brief Structure type to access the Memory Protection Unit (MPU). - */ -typedef struct -{ - __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ - __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ - __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ -} MPU_Type; - -/* MPU Type Register Definitions */ -#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ -#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ - -#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ -#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ - -#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ -#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ - -/* MPU Control Register Definitions */ -#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ -#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ - -#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ -#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ - -#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ -#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ - -/* MPU Region Number Register Definitions */ -#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ -#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ - -/* MPU Region Base Address Register Definitions */ -#define MPU_RBAR_ADDR_Pos 8U /*!< MPU RBAR: ADDR Position */ -#define MPU_RBAR_ADDR_Msk (0xFFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ - -#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */ -#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ - -#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */ -#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */ - -/* MPU Region Attribute and Size Register Definitions */ -#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */ -#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ - -#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */ -#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */ - -#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */ -#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */ - -#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */ -#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */ - -#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */ -#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */ - -#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */ -#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */ - -#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */ -#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */ - -#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */ -#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ - -#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */ -#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ - -#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */ -#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */ - -/*@} end of group CMSIS_MPU */ -#endif - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) - \brief SC000 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor. - Therefore they are not covered by the SC000 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. - \return Masked and shifted value. -*/ -#define _VAL2FLD(field, value) ((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. - \return Masked and shifted bit field value. -*/ -#define _FLD2VAL(field, value) ((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 SC000 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 */ - -#if (__MPU_PRESENT == 1U) - #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ - #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ -#endif - -/*@} */ - - - -/******************************************************************************* - * 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. - @{ - */ - -/* Interrupt Priorities are WORD accessible only under ARMv6M */ -/* 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) ) - - -/** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) -{ - NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) -{ - NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not pending. - \return 1 Interrupt status is pending. - */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. - \param [in] IRQn Interrupt number. - \param [in] priority Priority to set. - */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if ((int32_t)(IRQn) < 0) - { - 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))); - } - else - { - 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))); - } -} - - -/** - \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. - \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)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); - } - else - { - return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS))); - } -} - - -/** - \brief System Reset - \details Initiates a system reset request to reset the MCU. - */ -__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 */ - - - -/* ################################## SysTick function ############################################ */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_SysTickFunctions SysTick Functions - \brief Functions that configure the System. - @{ - */ - -#if (__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 __Vendor_SysTickConfig is set to 1, then the - function SysTick_Config is not included. In this case, the file device.h - 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_SC000_H_DEPENDANT */ - -#endif /* __CMSIS_GENERIC */ diff --git a/Software/Drivers/CMSIS/Include/core_sc300.h b/Software/Drivers/CMSIS/Include/core_sc300.h deleted file mode 100644 index 820cef4..0000000 --- a/Software/Drivers/CMSIS/Include/core_sc300.h +++ /dev/null @@ -1,1745 +0,0 @@ -/**************************************************************************//** - * @file core_sc300.h - * @brief CMSIS SC300 Core Peripheral Access Layer Header File - * @version V4.30 - * @date 20. October 2015 - ******************************************************************************/ -/* Copyright (c) 2009 - 2015 ARM LIMITED - - All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - Neither the name of ARM nor the names of its contributors may be used - to endorse or promote products derived from this software without - specific prior written permission. - * - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------------*/ - - -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #pragma clang system_header /* treat file as system include file */ -#endif - -#ifndef __CORE_SC300_H_GENERIC -#define __CORE_SC300_H_GENERIC - -#include - -#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.
- Function definitions in header files are used to allow 'inlining'. - - \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers. - - \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code. - */ - - -/******************************************************************************* - * CMSIS definitions - ******************************************************************************/ -/** - \ingroup SC3000 - @{ - */ - -/* CMSIS SC300 definitions */ -#define __SC300_CMSIS_VERSION_MAIN (0x04U) /*!< [31:16] CMSIS HAL main version */ -#define __SC300_CMSIS_VERSION_SUB (0x1EU) /*!< [15:0] CMSIS HAL sub version */ -#define __SC300_CMSIS_VERSION ((__SC300_CMSIS_VERSION_MAIN << 16U) | \ - __SC300_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_SC (300U) /*!< Cortex secure core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __TMS470__ ) - #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __CSMC__ ) - #define __packed - #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ - #define __INLINE inline /*!< inline keyword for COSMIC Compiler. Use -pc99 on compile line */ - #define __STATIC_INLINE static inline - -#else - #error Unknown compiler -#endif - -/** __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_PCS_VFP - #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 ( __TMS470__ ) - #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 "core_cmInstr.h" /* Core Instruction Access */ -#include "core_cmFunc.h" /* Core Function Access */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_SC300_H_GENERIC */ - -#ifndef __CMSIS_GENERIC - -#ifndef __CORE_SC300_H_DEPENDANT -#define __CORE_SC300_H_DEPENDANT - -#ifdef __cplusplus - extern "C" { -#endif - -/* check device defines and use defaults */ -#if defined __CHECK_DEVICE_DEFINES - #ifndef __SC300_REV - #define __SC300_REV 0x0000U - #warning "__SC300_REV not defined in device header file; using default!" - #endif - - #ifndef __MPU_PRESENT - #define __MPU_PRESENT 0U - #warning "__MPU_PRESENT not defined in device header file; using default!" - #endif - - #ifndef __NVIC_PRIO_BITS - #define __NVIC_PRIO_BITS 4U - #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 - - IO Type Qualifiers 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 SC300 */ - - - -/******************************************************************************* - * Register Abstraction - Core Register contain: - - Core Register - - Core NVIC Register - - Core SCB Register - - Core SysTick Register - - Core Debug Register - - Core MPU 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:27; /*!< bit: 0..26 Reserved */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - 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 */ - -#define APSR_Q_Pos 27U /*!< APSR: Q Position */ -#define APSR_Q_Msk (1UL << APSR_Q_Pos) /*!< APSR: Q 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 IT:2; /*!< bit: 25..26 saved IT state (read 0) */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - 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_Q_Pos 27U /*!< xPSR: Q Position */ -#define xPSR_Q_Msk (1UL << xPSR_Q_Pos) /*!< xPSR: Q Mask */ - -#define xPSR_IT_Pos 25U /*!< xPSR: IT Position */ -#define xPSR_IT_Msk (3UL << xPSR_IT_Pos) /*!< xPSR: IT 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 nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ - 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 */ - -#define CONTROL_nPRIV_Pos 0U /*!< CONTROL: nPRIV Position */ -#define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/) /*!< CONTROL: nPRIV 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[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ - uint32_t RESERVED0[24U]; - __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RSERVED1[24U]; - __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ - uint32_t RESERVED2[24U]; - __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ - uint32_t RESERVED3[24U]; - __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ - uint32_t RESERVED4[56U]; - __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ - uint32_t RESERVED5[644U]; - __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ -} NVIC_Type; - -/* Software Triggered Interrupt Register Definitions */ -#define NVIC_STIR_INTID_Pos 0U /*!< STIR: INTLINESNUM Position */ -#define NVIC_STIR_INTID_Msk (0x1FFUL /*<< NVIC_STIR_INTID_Pos*/) /*!< STIR: INTLINESNUM Mask */ - -/*@} 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 */ - __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ - __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 */ - __IOM uint8_t SHP[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ - __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ - __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ - __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ - __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ - __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ - __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ - __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ - __IM uint32_t PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ - __IM uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ - __IM uint32_t MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ - __IM uint32_t ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ - uint32_t RESERVED0[5U]; - __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ - uint32_t RESERVED1[129U]; - __IOM uint32_t SFCR; /*!< Offset: 0x290 (R/W) Security Features Control 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_RETTOBASE_Pos 11U /*!< SCB ICSR: RETTOBASE Position */ -#define SCB_ICSR_RETTOBASE_Msk (1UL << SCB_ICSR_RETTOBASE_Pos) /*!< SCB ICSR: RETTOBASE 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 Vector Table Offset Register Definitions */ -#define SCB_VTOR_TBLBASE_Pos 29U /*!< SCB VTOR: TBLBASE Position */ -#define SCB_VTOR_TBLBASE_Msk (1UL << SCB_VTOR_TBLBASE_Pos) /*!< SCB VTOR: TBLBASE Mask */ - -#define SCB_VTOR_TBLOFF_Pos 7U /*!< SCB VTOR: TBLOFF Position */ -#define SCB_VTOR_TBLOFF_Msk (0x3FFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF 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_PRIGROUP_Pos 8U /*!< SCB AIRCR: PRIGROUP Position */ -#define SCB_AIRCR_PRIGROUP_Msk (7UL << SCB_AIRCR_PRIGROUP_Pos) /*!< SCB AIRCR: PRIGROUP 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 */ - -#define SCB_AIRCR_VECTRESET_Pos 0U /*!< SCB AIRCR: VECTRESET Position */ -#define SCB_AIRCR_VECTRESET_Msk (1UL /*<< SCB_AIRCR_VECTRESET_Pos*/) /*!< SCB AIRCR: VECTRESET 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_BFHFNMIGN_Pos 8U /*!< SCB CCR: BFHFNMIGN Position */ -#define SCB_CCR_BFHFNMIGN_Msk (1UL << SCB_CCR_BFHFNMIGN_Pos) /*!< SCB CCR: BFHFNMIGN Mask */ - -#define SCB_CCR_DIV_0_TRP_Pos 4U /*!< SCB CCR: DIV_0_TRP Position */ -#define SCB_CCR_DIV_0_TRP_Msk (1UL << SCB_CCR_DIV_0_TRP_Pos) /*!< SCB CCR: DIV_0_TRP 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 */ - -#define SCB_CCR_USERSETMPEND_Pos 1U /*!< SCB CCR: USERSETMPEND Position */ -#define SCB_CCR_USERSETMPEND_Msk (1UL << SCB_CCR_USERSETMPEND_Pos) /*!< SCB CCR: USERSETMPEND Mask */ - -#define SCB_CCR_NONBASETHRDENA_Pos 0U /*!< SCB CCR: NONBASETHRDENA Position */ -#define SCB_CCR_NONBASETHRDENA_Msk (1UL /*<< SCB_CCR_NONBASETHRDENA_Pos*/) /*!< SCB CCR: NONBASETHRDENA Mask */ - -/* SCB System Handler Control and State Register Definitions */ -#define SCB_SHCSR_USGFAULTENA_Pos 18U /*!< SCB SHCSR: USGFAULTENA Position */ -#define SCB_SHCSR_USGFAULTENA_Msk (1UL << SCB_SHCSR_USGFAULTENA_Pos) /*!< SCB SHCSR: USGFAULTENA Mask */ - -#define SCB_SHCSR_BUSFAULTENA_Pos 17U /*!< SCB SHCSR: BUSFAULTENA Position */ -#define SCB_SHCSR_BUSFAULTENA_Msk (1UL << SCB_SHCSR_BUSFAULTENA_Pos) /*!< SCB SHCSR: BUSFAULTENA Mask */ - -#define SCB_SHCSR_MEMFAULTENA_Pos 16U /*!< SCB SHCSR: MEMFAULTENA Position */ -#define SCB_SHCSR_MEMFAULTENA_Msk (1UL << SCB_SHCSR_MEMFAULTENA_Pos) /*!< SCB SHCSR: MEMFAULTENA Mask */ - -#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */ -#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ - -#define SCB_SHCSR_BUSFAULTPENDED_Pos 14U /*!< SCB SHCSR: BUSFAULTPENDED Position */ -#define SCB_SHCSR_BUSFAULTPENDED_Msk (1UL << SCB_SHCSR_BUSFAULTPENDED_Pos) /*!< SCB SHCSR: BUSFAULTPENDED Mask */ - -#define SCB_SHCSR_MEMFAULTPENDED_Pos 13U /*!< SCB SHCSR: MEMFAULTPENDED Position */ -#define SCB_SHCSR_MEMFAULTPENDED_Msk (1UL << SCB_SHCSR_MEMFAULTPENDED_Pos) /*!< SCB SHCSR: MEMFAULTPENDED Mask */ - -#define SCB_SHCSR_USGFAULTPENDED_Pos 12U /*!< SCB SHCSR: USGFAULTPENDED Position */ -#define SCB_SHCSR_USGFAULTPENDED_Msk (1UL << SCB_SHCSR_USGFAULTPENDED_Pos) /*!< SCB SHCSR: USGFAULTPENDED Mask */ - -#define SCB_SHCSR_SYSTICKACT_Pos 11U /*!< SCB SHCSR: SYSTICKACT Position */ -#define SCB_SHCSR_SYSTICKACT_Msk (1UL << SCB_SHCSR_SYSTICKACT_Pos) /*!< SCB SHCSR: SYSTICKACT Mask */ - -#define SCB_SHCSR_PENDSVACT_Pos 10U /*!< SCB SHCSR: PENDSVACT Position */ -#define SCB_SHCSR_PENDSVACT_Msk (1UL << SCB_SHCSR_PENDSVACT_Pos) /*!< SCB SHCSR: PENDSVACT Mask */ - -#define SCB_SHCSR_MONITORACT_Pos 8U /*!< SCB SHCSR: MONITORACT Position */ -#define SCB_SHCSR_MONITORACT_Msk (1UL << SCB_SHCSR_MONITORACT_Pos) /*!< SCB SHCSR: MONITORACT Mask */ - -#define SCB_SHCSR_SVCALLACT_Pos 7U /*!< SCB SHCSR: SVCALLACT Position */ -#define SCB_SHCSR_SVCALLACT_Msk (1UL << SCB_SHCSR_SVCALLACT_Pos) /*!< SCB SHCSR: SVCALLACT Mask */ - -#define SCB_SHCSR_USGFAULTACT_Pos 3U /*!< SCB SHCSR: USGFAULTACT Position */ -#define SCB_SHCSR_USGFAULTACT_Msk (1UL << SCB_SHCSR_USGFAULTACT_Pos) /*!< SCB SHCSR: USGFAULTACT Mask */ - -#define SCB_SHCSR_BUSFAULTACT_Pos 1U /*!< SCB SHCSR: BUSFAULTACT Position */ -#define SCB_SHCSR_BUSFAULTACT_Msk (1UL << SCB_SHCSR_BUSFAULTACT_Pos) /*!< SCB SHCSR: BUSFAULTACT Mask */ - -#define SCB_SHCSR_MEMFAULTACT_Pos 0U /*!< SCB SHCSR: MEMFAULTACT Position */ -#define SCB_SHCSR_MEMFAULTACT_Msk (1UL /*<< SCB_SHCSR_MEMFAULTACT_Pos*/) /*!< SCB SHCSR: MEMFAULTACT Mask */ - -/* SCB Configurable Fault Status Register Definitions */ -#define SCB_CFSR_USGFAULTSR_Pos 16U /*!< SCB CFSR: Usage Fault Status Register Position */ -#define SCB_CFSR_USGFAULTSR_Msk (0xFFFFUL << SCB_CFSR_USGFAULTSR_Pos) /*!< SCB CFSR: Usage Fault Status Register Mask */ - -#define SCB_CFSR_BUSFAULTSR_Pos 8U /*!< SCB CFSR: Bus Fault Status Register Position */ -#define SCB_CFSR_BUSFAULTSR_Msk (0xFFUL << SCB_CFSR_BUSFAULTSR_Pos) /*!< SCB CFSR: Bus Fault Status Register Mask */ - -#define SCB_CFSR_MEMFAULTSR_Pos 0U /*!< SCB CFSR: Memory Manage Fault Status Register Position */ -#define SCB_CFSR_MEMFAULTSR_Msk (0xFFUL /*<< SCB_CFSR_MEMFAULTSR_Pos*/) /*!< SCB CFSR: Memory Manage Fault Status Register Mask */ - -/* SCB Hard Fault Status Register Definitions */ -#define SCB_HFSR_DEBUGEVT_Pos 31U /*!< SCB HFSR: DEBUGEVT Position */ -#define SCB_HFSR_DEBUGEVT_Msk (1UL << SCB_HFSR_DEBUGEVT_Pos) /*!< SCB HFSR: DEBUGEVT Mask */ - -#define SCB_HFSR_FORCED_Pos 30U /*!< SCB HFSR: FORCED Position */ -#define SCB_HFSR_FORCED_Msk (1UL << SCB_HFSR_FORCED_Pos) /*!< SCB HFSR: FORCED Mask */ - -#define SCB_HFSR_VECTTBL_Pos 1U /*!< SCB HFSR: VECTTBL Position */ -#define SCB_HFSR_VECTTBL_Msk (1UL << SCB_HFSR_VECTTBL_Pos) /*!< SCB HFSR: VECTTBL Mask */ - -/* SCB Debug Fault Status Register Definitions */ -#define SCB_DFSR_EXTERNAL_Pos 4U /*!< SCB DFSR: EXTERNAL Position */ -#define SCB_DFSR_EXTERNAL_Msk (1UL << SCB_DFSR_EXTERNAL_Pos) /*!< SCB DFSR: EXTERNAL Mask */ - -#define SCB_DFSR_VCATCH_Pos 3U /*!< SCB DFSR: VCATCH Position */ -#define SCB_DFSR_VCATCH_Msk (1UL << SCB_DFSR_VCATCH_Pos) /*!< SCB DFSR: VCATCH Mask */ - -#define SCB_DFSR_DWTTRAP_Pos 2U /*!< SCB DFSR: DWTTRAP Position */ -#define SCB_DFSR_DWTTRAP_Msk (1UL << SCB_DFSR_DWTTRAP_Pos) /*!< SCB DFSR: DWTTRAP Mask */ - -#define SCB_DFSR_BKPT_Pos 1U /*!< SCB DFSR: BKPT Position */ -#define SCB_DFSR_BKPT_Msk (1UL << SCB_DFSR_BKPT_Pos) /*!< SCB DFSR: BKPT Mask */ - -#define SCB_DFSR_HALTED_Pos 0U /*!< SCB DFSR: HALTED Position */ -#define SCB_DFSR_HALTED_Msk (1UL /*<< SCB_DFSR_HALTED_Pos*/) /*!< SCB DFSR: HALTED 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[1U]; - __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ - uint32_t RESERVED1[1U]; -} SCnSCB_Type; - -/* Interrupt Controller Type Register Definitions */ -#define SCnSCB_ICTR_INTLINESNUM_Pos 0U /*!< ICTR: INTLINESNUM Position */ -#define SCnSCB_ICTR_INTLINESNUM_Msk (0xFUL /*<< SCnSCB_ICTR_INTLINESNUM_Pos*/) /*!< ICTR: INTLINESNUM 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_ITM Instrumentation Trace Macrocell (ITM) - \brief Type definitions for the Instrumentation Trace Macrocell (ITM) - @{ - */ - -/** - \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). - */ -typedef struct -{ - __OM union - { - __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ - __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ - __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ - } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ - uint32_t RESERVED0[864U]; - __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ - uint32_t RESERVED1[15U]; - __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ - uint32_t RESERVED2[15U]; - __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[29U]; - __OM uint32_t IWR; /*!< Offset: 0xEF8 ( /W) ITM Integration Write Register */ - __IM uint32_t IRR; /*!< Offset: 0xEFC (R/ ) ITM Integration Read Register */ - __IOM uint32_t IMCR; /*!< Offset: 0xF00 (R/W) ITM Integration Mode Control Register */ - uint32_t RESERVED4[43U]; - __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ - __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ - uint32_t RESERVED5[6U]; - __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ - __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ - __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ - __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ - __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ - __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ - __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ - __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ - __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ - __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ - __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ - __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ -} ITM_Type; - -/* ITM Trace Privilege Register Definitions */ -#define ITM_TPR_PRIVMASK_Pos 0U /*!< ITM TPR: PRIVMASK Position */ -#define ITM_TPR_PRIVMASK_Msk (0xFUL /*<< ITM_TPR_PRIVMASK_Pos*/) /*!< ITM TPR: PRIVMASK Mask */ - -/* ITM Trace Control Register Definitions */ -#define ITM_TCR_BUSY_Pos 23U /*!< ITM TCR: BUSY Position */ -#define ITM_TCR_BUSY_Msk (1UL << ITM_TCR_BUSY_Pos) /*!< ITM TCR: BUSY Mask */ - -#define ITM_TCR_TraceBusID_Pos 16U /*!< ITM TCR: ATBID Position */ -#define ITM_TCR_TraceBusID_Msk (0x7FUL << ITM_TCR_TraceBusID_Pos) /*!< ITM TCR: ATBID Mask */ - -#define ITM_TCR_GTSFREQ_Pos 10U /*!< ITM TCR: Global timestamp frequency Position */ -#define ITM_TCR_GTSFREQ_Msk (3UL << ITM_TCR_GTSFREQ_Pos) /*!< ITM TCR: Global timestamp frequency Mask */ - -#define ITM_TCR_TSPrescale_Pos 8U /*!< ITM TCR: TSPrescale Position */ -#define ITM_TCR_TSPrescale_Msk (3UL << ITM_TCR_TSPrescale_Pos) /*!< ITM TCR: TSPrescale Mask */ - -#define ITM_TCR_SWOENA_Pos 4U /*!< ITM TCR: SWOENA Position */ -#define ITM_TCR_SWOENA_Msk (1UL << ITM_TCR_SWOENA_Pos) /*!< ITM TCR: SWOENA Mask */ - -#define ITM_TCR_DWTENA_Pos 3U /*!< ITM TCR: DWTENA Position */ -#define ITM_TCR_DWTENA_Msk (1UL << ITM_TCR_DWTENA_Pos) /*!< ITM TCR: DWTENA Mask */ - -#define ITM_TCR_SYNCENA_Pos 2U /*!< ITM TCR: SYNCENA Position */ -#define ITM_TCR_SYNCENA_Msk (1UL << ITM_TCR_SYNCENA_Pos) /*!< ITM TCR: SYNCENA Mask */ - -#define ITM_TCR_TSENA_Pos 1U /*!< ITM TCR: TSENA Position */ -#define ITM_TCR_TSENA_Msk (1UL << ITM_TCR_TSENA_Pos) /*!< ITM TCR: TSENA Mask */ - -#define ITM_TCR_ITMENA_Pos 0U /*!< ITM TCR: ITM Enable bit Position */ -#define ITM_TCR_ITMENA_Msk (1UL /*<< ITM_TCR_ITMENA_Pos*/) /*!< ITM TCR: ITM Enable bit Mask */ - -/* ITM Integration Write Register Definitions */ -#define ITM_IWR_ATVALIDM_Pos 0U /*!< ITM IWR: ATVALIDM Position */ -#define ITM_IWR_ATVALIDM_Msk (1UL /*<< ITM_IWR_ATVALIDM_Pos*/) /*!< ITM IWR: ATVALIDM Mask */ - -/* ITM Integration Read Register Definitions */ -#define ITM_IRR_ATREADYM_Pos 0U /*!< ITM IRR: ATREADYM Position */ -#define ITM_IRR_ATREADYM_Msk (1UL /*<< ITM_IRR_ATREADYM_Pos*/) /*!< ITM IRR: ATREADYM Mask */ - -/* ITM Integration Mode Control Register Definitions */ -#define ITM_IMCR_INTEGRATION_Pos 0U /*!< ITM IMCR: INTEGRATION Position */ -#define ITM_IMCR_INTEGRATION_Msk (1UL /*<< ITM_IMCR_INTEGRATION_Pos*/) /*!< ITM IMCR: INTEGRATION Mask */ - -/* ITM Lock Status Register Definitions */ -#define ITM_LSR_ByteAcc_Pos 2U /*!< ITM LSR: ByteAcc Position */ -#define ITM_LSR_ByteAcc_Msk (1UL << ITM_LSR_ByteAcc_Pos) /*!< ITM LSR: ByteAcc Mask */ - -#define ITM_LSR_Access_Pos 1U /*!< ITM LSR: Access Position */ -#define ITM_LSR_Access_Msk (1UL << ITM_LSR_Access_Pos) /*!< ITM LSR: Access Mask */ - -#define ITM_LSR_Present_Pos 0U /*!< ITM LSR: Present Position */ -#define ITM_LSR_Present_Msk (1UL /*<< ITM_LSR_Present_Pos*/) /*!< ITM LSR: Present Mask */ - -/*@}*/ /* end of group CMSIS_ITM */ - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_DWT Data Watchpoint and Trace (DWT) - \brief Type definitions for the Data Watchpoint and Trace (DWT) - @{ - */ - -/** - \brief Structure type to access the Data Watchpoint and Trace Register (DWT). - */ -typedef struct -{ - __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ - __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ - __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ - __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ - __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ - __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ - __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ - __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ - __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ - __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */ - __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ - uint32_t RESERVED0[1U]; - __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ - __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */ - __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ - uint32_t RESERVED1[1U]; - __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ - __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */ - __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ - uint32_t RESERVED2[1U]; - __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ - __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */ - __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ -} DWT_Type; - -/* DWT Control Register Definitions */ -#define DWT_CTRL_NUMCOMP_Pos 28U /*!< DWT CTRL: NUMCOMP Position */ -#define DWT_CTRL_NUMCOMP_Msk (0xFUL << DWT_CTRL_NUMCOMP_Pos) /*!< DWT CTRL: NUMCOMP Mask */ - -#define DWT_CTRL_NOTRCPKT_Pos 27U /*!< DWT CTRL: NOTRCPKT Position */ -#define DWT_CTRL_NOTRCPKT_Msk (0x1UL << DWT_CTRL_NOTRCPKT_Pos) /*!< DWT CTRL: NOTRCPKT Mask */ - -#define DWT_CTRL_NOEXTTRIG_Pos 26U /*!< DWT CTRL: NOEXTTRIG Position */ -#define DWT_CTRL_NOEXTTRIG_Msk (0x1UL << DWT_CTRL_NOEXTTRIG_Pos) /*!< DWT CTRL: NOEXTTRIG Mask */ - -#define DWT_CTRL_NOCYCCNT_Pos 25U /*!< DWT CTRL: NOCYCCNT Position */ -#define DWT_CTRL_NOCYCCNT_Msk (0x1UL << DWT_CTRL_NOCYCCNT_Pos) /*!< DWT CTRL: NOCYCCNT Mask */ - -#define DWT_CTRL_NOPRFCNT_Pos 24U /*!< DWT CTRL: NOPRFCNT Position */ -#define DWT_CTRL_NOPRFCNT_Msk (0x1UL << DWT_CTRL_NOPRFCNT_Pos) /*!< DWT CTRL: NOPRFCNT Mask */ - -#define DWT_CTRL_CYCEVTENA_Pos 22U /*!< DWT CTRL: CYCEVTENA Position */ -#define DWT_CTRL_CYCEVTENA_Msk (0x1UL << DWT_CTRL_CYCEVTENA_Pos) /*!< DWT CTRL: CYCEVTENA Mask */ - -#define DWT_CTRL_FOLDEVTENA_Pos 21U /*!< DWT CTRL: FOLDEVTENA Position */ -#define DWT_CTRL_FOLDEVTENA_Msk (0x1UL << DWT_CTRL_FOLDEVTENA_Pos) /*!< DWT CTRL: FOLDEVTENA Mask */ - -#define DWT_CTRL_LSUEVTENA_Pos 20U /*!< DWT CTRL: LSUEVTENA Position */ -#define DWT_CTRL_LSUEVTENA_Msk (0x1UL << DWT_CTRL_LSUEVTENA_Pos) /*!< DWT CTRL: LSUEVTENA Mask */ - -#define DWT_CTRL_SLEEPEVTENA_Pos 19U /*!< DWT CTRL: SLEEPEVTENA Position */ -#define DWT_CTRL_SLEEPEVTENA_Msk (0x1UL << DWT_CTRL_SLEEPEVTENA_Pos) /*!< DWT CTRL: SLEEPEVTENA Mask */ - -#define DWT_CTRL_EXCEVTENA_Pos 18U /*!< DWT CTRL: EXCEVTENA Position */ -#define DWT_CTRL_EXCEVTENA_Msk (0x1UL << DWT_CTRL_EXCEVTENA_Pos) /*!< DWT CTRL: EXCEVTENA Mask */ - -#define DWT_CTRL_CPIEVTENA_Pos 17U /*!< DWT CTRL: CPIEVTENA Position */ -#define DWT_CTRL_CPIEVTENA_Msk (0x1UL << DWT_CTRL_CPIEVTENA_Pos) /*!< DWT CTRL: CPIEVTENA Mask */ - -#define DWT_CTRL_EXCTRCENA_Pos 16U /*!< DWT CTRL: EXCTRCENA Position */ -#define DWT_CTRL_EXCTRCENA_Msk (0x1UL << DWT_CTRL_EXCTRCENA_Pos) /*!< DWT CTRL: EXCTRCENA Mask */ - -#define DWT_CTRL_PCSAMPLENA_Pos 12U /*!< DWT CTRL: PCSAMPLENA Position */ -#define DWT_CTRL_PCSAMPLENA_Msk (0x1UL << DWT_CTRL_PCSAMPLENA_Pos) /*!< DWT CTRL: PCSAMPLENA Mask */ - -#define DWT_CTRL_SYNCTAP_Pos 10U /*!< DWT CTRL: SYNCTAP Position */ -#define DWT_CTRL_SYNCTAP_Msk (0x3UL << DWT_CTRL_SYNCTAP_Pos) /*!< DWT CTRL: SYNCTAP Mask */ - -#define DWT_CTRL_CYCTAP_Pos 9U /*!< DWT CTRL: CYCTAP Position */ -#define DWT_CTRL_CYCTAP_Msk (0x1UL << DWT_CTRL_CYCTAP_Pos) /*!< DWT CTRL: CYCTAP Mask */ - -#define DWT_CTRL_POSTINIT_Pos 5U /*!< DWT CTRL: POSTINIT Position */ -#define DWT_CTRL_POSTINIT_Msk (0xFUL << DWT_CTRL_POSTINIT_Pos) /*!< DWT CTRL: POSTINIT Mask */ - -#define DWT_CTRL_POSTPRESET_Pos 1U /*!< DWT CTRL: POSTPRESET Position */ -#define DWT_CTRL_POSTPRESET_Msk (0xFUL << DWT_CTRL_POSTPRESET_Pos) /*!< DWT CTRL: POSTPRESET Mask */ - -#define DWT_CTRL_CYCCNTENA_Pos 0U /*!< DWT CTRL: CYCCNTENA Position */ -#define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */ - -/* DWT CPI Count Register Definitions */ -#define DWT_CPICNT_CPICNT_Pos 0U /*!< DWT CPICNT: CPICNT Position */ -#define DWT_CPICNT_CPICNT_Msk (0xFFUL /*<< DWT_CPICNT_CPICNT_Pos*/) /*!< DWT CPICNT: CPICNT Mask */ - -/* DWT Exception Overhead Count Register Definitions */ -#define DWT_EXCCNT_EXCCNT_Pos 0U /*!< DWT EXCCNT: EXCCNT Position */ -#define DWT_EXCCNT_EXCCNT_Msk (0xFFUL /*<< DWT_EXCCNT_EXCCNT_Pos*/) /*!< DWT EXCCNT: EXCCNT Mask */ - -/* DWT Sleep Count Register Definitions */ -#define DWT_SLEEPCNT_SLEEPCNT_Pos 0U /*!< DWT SLEEPCNT: SLEEPCNT Position */ -#define DWT_SLEEPCNT_SLEEPCNT_Msk (0xFFUL /*<< DWT_SLEEPCNT_SLEEPCNT_Pos*/) /*!< DWT SLEEPCNT: SLEEPCNT Mask */ - -/* DWT LSU Count Register Definitions */ -#define DWT_LSUCNT_LSUCNT_Pos 0U /*!< DWT LSUCNT: LSUCNT Position */ -#define DWT_LSUCNT_LSUCNT_Msk (0xFFUL /*<< DWT_LSUCNT_LSUCNT_Pos*/) /*!< DWT LSUCNT: LSUCNT Mask */ - -/* DWT Folded-instruction Count Register Definitions */ -#define DWT_FOLDCNT_FOLDCNT_Pos 0U /*!< DWT FOLDCNT: FOLDCNT Position */ -#define DWT_FOLDCNT_FOLDCNT_Msk (0xFFUL /*<< DWT_FOLDCNT_FOLDCNT_Pos*/) /*!< DWT FOLDCNT: FOLDCNT Mask */ - -/* DWT Comparator Mask Register Definitions */ -#define DWT_MASK_MASK_Pos 0U /*!< DWT MASK: MASK Position */ -#define DWT_MASK_MASK_Msk (0x1FUL /*<< DWT_MASK_MASK_Pos*/) /*!< DWT MASK: MASK Mask */ - -/* DWT Comparator Function Register Definitions */ -#define DWT_FUNCTION_MATCHED_Pos 24U /*!< DWT FUNCTION: MATCHED Position */ -#define DWT_FUNCTION_MATCHED_Msk (0x1UL << DWT_FUNCTION_MATCHED_Pos) /*!< DWT FUNCTION: MATCHED Mask */ - -#define DWT_FUNCTION_DATAVADDR1_Pos 16U /*!< DWT FUNCTION: DATAVADDR1 Position */ -#define DWT_FUNCTION_DATAVADDR1_Msk (0xFUL << DWT_FUNCTION_DATAVADDR1_Pos) /*!< DWT FUNCTION: DATAVADDR1 Mask */ - -#define DWT_FUNCTION_DATAVADDR0_Pos 12U /*!< DWT FUNCTION: DATAVADDR0 Position */ -#define DWT_FUNCTION_DATAVADDR0_Msk (0xFUL << DWT_FUNCTION_DATAVADDR0_Pos) /*!< DWT FUNCTION: DATAVADDR0 Mask */ - -#define DWT_FUNCTION_DATAVSIZE_Pos 10U /*!< DWT FUNCTION: DATAVSIZE Position */ -#define DWT_FUNCTION_DATAVSIZE_Msk (0x3UL << DWT_FUNCTION_DATAVSIZE_Pos) /*!< DWT FUNCTION: DATAVSIZE Mask */ - -#define DWT_FUNCTION_LNK1ENA_Pos 9U /*!< DWT FUNCTION: LNK1ENA Position */ -#define DWT_FUNCTION_LNK1ENA_Msk (0x1UL << DWT_FUNCTION_LNK1ENA_Pos) /*!< DWT FUNCTION: LNK1ENA Mask */ - -#define DWT_FUNCTION_DATAVMATCH_Pos 8U /*!< DWT FUNCTION: DATAVMATCH Position */ -#define DWT_FUNCTION_DATAVMATCH_Msk (0x1UL << DWT_FUNCTION_DATAVMATCH_Pos) /*!< DWT FUNCTION: DATAVMATCH Mask */ - -#define DWT_FUNCTION_CYCMATCH_Pos 7U /*!< DWT FUNCTION: CYCMATCH Position */ -#define DWT_FUNCTION_CYCMATCH_Msk (0x1UL << DWT_FUNCTION_CYCMATCH_Pos) /*!< DWT FUNCTION: CYCMATCH Mask */ - -#define DWT_FUNCTION_EMITRANGE_Pos 5U /*!< DWT FUNCTION: EMITRANGE Position */ -#define DWT_FUNCTION_EMITRANGE_Msk (0x1UL << DWT_FUNCTION_EMITRANGE_Pos) /*!< DWT FUNCTION: EMITRANGE Mask */ - -#define DWT_FUNCTION_FUNCTION_Pos 0U /*!< DWT FUNCTION: FUNCTION Position */ -#define DWT_FUNCTION_FUNCTION_Msk (0xFUL /*<< DWT_FUNCTION_FUNCTION_Pos*/) /*!< DWT FUNCTION: FUNCTION Mask */ - -/*@}*/ /* end of group CMSIS_DWT */ - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_TPI Trace Port Interface (TPI) - \brief Type definitions for the Trace Port Interface (TPI) - @{ - */ - -/** - \brief Structure type to access the Trace Port Interface Register (TPI). - */ -typedef struct -{ - __IOM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ - __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ - uint32_t RESERVED0[2U]; - __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ - uint32_t RESERVED1[55U]; - __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ - uint32_t RESERVED2[131U]; - __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ - __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ - __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ - uint32_t RESERVED3[759U]; - __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER */ - __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ - __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ - uint32_t RESERVED4[1U]; - __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */ - __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */ - __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */ - uint32_t RESERVED5[39U]; - __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */ - __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */ - uint32_t RESERVED7[8U]; - __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */ - __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */ -} TPI_Type; - -/* TPI Asynchronous Clock Prescaler Register Definitions */ -#define TPI_ACPR_PRESCALER_Pos 0U /*!< TPI ACPR: PRESCALER Position */ -#define TPI_ACPR_PRESCALER_Msk (0x1FFFUL /*<< TPI_ACPR_PRESCALER_Pos*/) /*!< TPI ACPR: PRESCALER Mask */ - -/* TPI Selected Pin Protocol Register Definitions */ -#define TPI_SPPR_TXMODE_Pos 0U /*!< TPI SPPR: TXMODE Position */ -#define TPI_SPPR_TXMODE_Msk (0x3UL /*<< TPI_SPPR_TXMODE_Pos*/) /*!< TPI SPPR: TXMODE Mask */ - -/* TPI Formatter and Flush Status Register Definitions */ -#define TPI_FFSR_FtNonStop_Pos 3U /*!< TPI FFSR: FtNonStop Position */ -#define TPI_FFSR_FtNonStop_Msk (0x1UL << TPI_FFSR_FtNonStop_Pos) /*!< TPI FFSR: FtNonStop Mask */ - -#define TPI_FFSR_TCPresent_Pos 2U /*!< TPI FFSR: TCPresent Position */ -#define TPI_FFSR_TCPresent_Msk (0x1UL << TPI_FFSR_TCPresent_Pos) /*!< TPI FFSR: TCPresent Mask */ - -#define TPI_FFSR_FtStopped_Pos 1U /*!< TPI FFSR: FtStopped Position */ -#define TPI_FFSR_FtStopped_Msk (0x1UL << TPI_FFSR_FtStopped_Pos) /*!< TPI FFSR: FtStopped Mask */ - -#define TPI_FFSR_FlInProg_Pos 0U /*!< TPI FFSR: FlInProg Position */ -#define TPI_FFSR_FlInProg_Msk (0x1UL /*<< TPI_FFSR_FlInProg_Pos*/) /*!< TPI FFSR: FlInProg Mask */ - -/* TPI Formatter and Flush Control Register Definitions */ -#define TPI_FFCR_TrigIn_Pos 8U /*!< TPI FFCR: TrigIn Position */ -#define TPI_FFCR_TrigIn_Msk (0x1UL << TPI_FFCR_TrigIn_Pos) /*!< TPI FFCR: TrigIn Mask */ - -#define TPI_FFCR_EnFCont_Pos 1U /*!< TPI FFCR: EnFCont Position */ -#define TPI_FFCR_EnFCont_Msk (0x1UL << TPI_FFCR_EnFCont_Pos) /*!< TPI FFCR: EnFCont Mask */ - -/* TPI TRIGGER Register Definitions */ -#define TPI_TRIGGER_TRIGGER_Pos 0U /*!< TPI TRIGGER: TRIGGER Position */ -#define TPI_TRIGGER_TRIGGER_Msk (0x1UL /*<< TPI_TRIGGER_TRIGGER_Pos*/) /*!< TPI TRIGGER: TRIGGER Mask */ - -/* TPI Integration ETM Data Register Definitions (FIFO0) */ -#define TPI_FIFO0_ITM_ATVALID_Pos 29U /*!< TPI FIFO0: ITM_ATVALID Position */ -#define TPI_FIFO0_ITM_ATVALID_Msk (0x3UL << TPI_FIFO0_ITM_ATVALID_Pos) /*!< TPI FIFO0: ITM_ATVALID Mask */ - -#define TPI_FIFO0_ITM_bytecount_Pos 27U /*!< TPI FIFO0: ITM_bytecount Position */ -#define TPI_FIFO0_ITM_bytecount_Msk (0x3UL << TPI_FIFO0_ITM_bytecount_Pos) /*!< TPI FIFO0: ITM_bytecount Mask */ - -#define TPI_FIFO0_ETM_ATVALID_Pos 26U /*!< TPI FIFO0: ETM_ATVALID Position */ -#define TPI_FIFO0_ETM_ATVALID_Msk (0x3UL << TPI_FIFO0_ETM_ATVALID_Pos) /*!< TPI FIFO0: ETM_ATVALID Mask */ - -#define TPI_FIFO0_ETM_bytecount_Pos 24U /*!< TPI FIFO0: ETM_bytecount Position */ -#define TPI_FIFO0_ETM_bytecount_Msk (0x3UL << TPI_FIFO0_ETM_bytecount_Pos) /*!< TPI FIFO0: ETM_bytecount Mask */ - -#define TPI_FIFO0_ETM2_Pos 16U /*!< TPI FIFO0: ETM2 Position */ -#define TPI_FIFO0_ETM2_Msk (0xFFUL << TPI_FIFO0_ETM2_Pos) /*!< TPI FIFO0: ETM2 Mask */ - -#define TPI_FIFO0_ETM1_Pos 8U /*!< TPI FIFO0: ETM1 Position */ -#define TPI_FIFO0_ETM1_Msk (0xFFUL << TPI_FIFO0_ETM1_Pos) /*!< TPI FIFO0: ETM1 Mask */ - -#define TPI_FIFO0_ETM0_Pos 0U /*!< TPI FIFO0: ETM0 Position */ -#define TPI_FIFO0_ETM0_Msk (0xFFUL /*<< TPI_FIFO0_ETM0_Pos*/) /*!< TPI FIFO0: ETM0 Mask */ - -/* TPI ITATBCTR2 Register Definitions */ -#define TPI_ITATBCTR2_ATREADY_Pos 0U /*!< TPI ITATBCTR2: ATREADY Position */ -#define TPI_ITATBCTR2_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR2_ATREADY_Pos*/) /*!< TPI ITATBCTR2: ATREADY Mask */ - -/* TPI Integration ITM Data Register Definitions (FIFO1) */ -#define TPI_FIFO1_ITM_ATVALID_Pos 29U /*!< TPI FIFO1: ITM_ATVALID Position */ -#define TPI_FIFO1_ITM_ATVALID_Msk (0x3UL << TPI_FIFO1_ITM_ATVALID_Pos) /*!< TPI FIFO1: ITM_ATVALID Mask */ - -#define TPI_FIFO1_ITM_bytecount_Pos 27U /*!< TPI FIFO1: ITM_bytecount Position */ -#define TPI_FIFO1_ITM_bytecount_Msk (0x3UL << TPI_FIFO1_ITM_bytecount_Pos) /*!< TPI FIFO1: ITM_bytecount Mask */ - -#define TPI_FIFO1_ETM_ATVALID_Pos 26U /*!< TPI FIFO1: ETM_ATVALID Position */ -#define TPI_FIFO1_ETM_ATVALID_Msk (0x3UL << TPI_FIFO1_ETM_ATVALID_Pos) /*!< TPI FIFO1: ETM_ATVALID Mask */ - -#define TPI_FIFO1_ETM_bytecount_Pos 24U /*!< TPI FIFO1: ETM_bytecount Position */ -#define TPI_FIFO1_ETM_bytecount_Msk (0x3UL << TPI_FIFO1_ETM_bytecount_Pos) /*!< TPI FIFO1: ETM_bytecount Mask */ - -#define TPI_FIFO1_ITM2_Pos 16U /*!< TPI FIFO1: ITM2 Position */ -#define TPI_FIFO1_ITM2_Msk (0xFFUL << TPI_FIFO1_ITM2_Pos) /*!< TPI FIFO1: ITM2 Mask */ - -#define TPI_FIFO1_ITM1_Pos 8U /*!< TPI FIFO1: ITM1 Position */ -#define TPI_FIFO1_ITM1_Msk (0xFFUL << TPI_FIFO1_ITM1_Pos) /*!< TPI FIFO1: ITM1 Mask */ - -#define TPI_FIFO1_ITM0_Pos 0U /*!< TPI FIFO1: ITM0 Position */ -#define TPI_FIFO1_ITM0_Msk (0xFFUL /*<< TPI_FIFO1_ITM0_Pos*/) /*!< TPI FIFO1: ITM0 Mask */ - -/* TPI ITATBCTR0 Register Definitions */ -#define TPI_ITATBCTR0_ATREADY_Pos 0U /*!< TPI ITATBCTR0: ATREADY Position */ -#define TPI_ITATBCTR0_ATREADY_Msk (0x1UL /*<< TPI_ITATBCTR0_ATREADY_Pos*/) /*!< TPI ITATBCTR0: ATREADY Mask */ - -/* TPI Integration Mode Control Register Definitions */ -#define TPI_ITCTRL_Mode_Pos 0U /*!< TPI ITCTRL: Mode Position */ -#define TPI_ITCTRL_Mode_Msk (0x1UL /*<< TPI_ITCTRL_Mode_Pos*/) /*!< TPI ITCTRL: Mode Mask */ - -/* TPI DEVID Register Definitions */ -#define TPI_DEVID_NRZVALID_Pos 11U /*!< TPI DEVID: NRZVALID Position */ -#define TPI_DEVID_NRZVALID_Msk (0x1UL << TPI_DEVID_NRZVALID_Pos) /*!< TPI DEVID: NRZVALID Mask */ - -#define TPI_DEVID_MANCVALID_Pos 10U /*!< TPI DEVID: MANCVALID Position */ -#define TPI_DEVID_MANCVALID_Msk (0x1UL << TPI_DEVID_MANCVALID_Pos) /*!< TPI DEVID: MANCVALID Mask */ - -#define TPI_DEVID_PTINVALID_Pos 9U /*!< TPI DEVID: PTINVALID Position */ -#define TPI_DEVID_PTINVALID_Msk (0x1UL << TPI_DEVID_PTINVALID_Pos) /*!< TPI DEVID: PTINVALID Mask */ - -#define TPI_DEVID_MinBufSz_Pos 6U /*!< TPI DEVID: MinBufSz Position */ -#define TPI_DEVID_MinBufSz_Msk (0x7UL << TPI_DEVID_MinBufSz_Pos) /*!< TPI DEVID: MinBufSz Mask */ - -#define TPI_DEVID_AsynClkIn_Pos 5U /*!< TPI DEVID: AsynClkIn Position */ -#define TPI_DEVID_AsynClkIn_Msk (0x1UL << TPI_DEVID_AsynClkIn_Pos) /*!< TPI DEVID: AsynClkIn Mask */ - -#define TPI_DEVID_NrTraceInput_Pos 0U /*!< TPI DEVID: NrTraceInput Position */ -#define TPI_DEVID_NrTraceInput_Msk (0x1FUL /*<< TPI_DEVID_NrTraceInput_Pos*/) /*!< TPI DEVID: NrTraceInput Mask */ - -/* TPI DEVTYPE Register Definitions */ -#define TPI_DEVTYPE_MajorType_Pos 4U /*!< TPI DEVTYPE: MajorType Position */ -#define TPI_DEVTYPE_MajorType_Msk (0xFUL << TPI_DEVTYPE_MajorType_Pos) /*!< TPI DEVTYPE: MajorType Mask */ - -#define TPI_DEVTYPE_SubType_Pos 0U /*!< TPI DEVTYPE: SubType Position */ -#define TPI_DEVTYPE_SubType_Msk (0xFUL /*<< TPI_DEVTYPE_SubType_Pos*/) /*!< TPI DEVTYPE: SubType Mask */ - -/*@}*/ /* end of group CMSIS_TPI */ - - -#if (__MPU_PRESENT == 1U) -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_MPU Memory Protection Unit (MPU) - \brief Type definitions for the Memory Protection Unit (MPU) - @{ - */ - -/** - \brief Structure type to access the Memory Protection Unit (MPU). - */ -typedef struct -{ - __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ - __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ - __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ - __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */ - __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */ - __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */ - __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ -} MPU_Type; - -/* MPU Type Register Definitions */ -#define MPU_TYPE_IREGION_Pos 16U /*!< MPU TYPE: IREGION Position */ -#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ - -#define MPU_TYPE_DREGION_Pos 8U /*!< MPU TYPE: DREGION Position */ -#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ - -#define MPU_TYPE_SEPARATE_Pos 0U /*!< MPU TYPE: SEPARATE Position */ -#define MPU_TYPE_SEPARATE_Msk (1UL /*<< MPU_TYPE_SEPARATE_Pos*/) /*!< MPU TYPE: SEPARATE Mask */ - -/* MPU Control Register Definitions */ -#define MPU_CTRL_PRIVDEFENA_Pos 2U /*!< MPU CTRL: PRIVDEFENA Position */ -#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ - -#define MPU_CTRL_HFNMIENA_Pos 1U /*!< MPU CTRL: HFNMIENA Position */ -#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ - -#define MPU_CTRL_ENABLE_Pos 0U /*!< MPU CTRL: ENABLE Position */ -#define MPU_CTRL_ENABLE_Msk (1UL /*<< MPU_CTRL_ENABLE_Pos*/) /*!< MPU CTRL: ENABLE Mask */ - -/* MPU Region Number Register Definitions */ -#define MPU_RNR_REGION_Pos 0U /*!< MPU RNR: REGION Position */ -#define MPU_RNR_REGION_Msk (0xFFUL /*<< MPU_RNR_REGION_Pos*/) /*!< MPU RNR: REGION Mask */ - -/* MPU Region Base Address Register Definitions */ -#define MPU_RBAR_ADDR_Pos 5U /*!< MPU RBAR: ADDR Position */ -#define MPU_RBAR_ADDR_Msk (0x7FFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ - -#define MPU_RBAR_VALID_Pos 4U /*!< MPU RBAR: VALID Position */ -#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ - -#define MPU_RBAR_REGION_Pos 0U /*!< MPU RBAR: REGION Position */ -#define MPU_RBAR_REGION_Msk (0xFUL /*<< MPU_RBAR_REGION_Pos*/) /*!< MPU RBAR: REGION Mask */ - -/* MPU Region Attribute and Size Register Definitions */ -#define MPU_RASR_ATTRS_Pos 16U /*!< MPU RASR: MPU Region Attribute field Position */ -#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ - -#define MPU_RASR_XN_Pos 28U /*!< MPU RASR: ATTRS.XN Position */ -#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */ - -#define MPU_RASR_AP_Pos 24U /*!< MPU RASR: ATTRS.AP Position */ -#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */ - -#define MPU_RASR_TEX_Pos 19U /*!< MPU RASR: ATTRS.TEX Position */ -#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */ - -#define MPU_RASR_S_Pos 18U /*!< MPU RASR: ATTRS.S Position */ -#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */ - -#define MPU_RASR_C_Pos 17U /*!< MPU RASR: ATTRS.C Position */ -#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */ - -#define MPU_RASR_B_Pos 16U /*!< MPU RASR: ATTRS.B Position */ -#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */ - -#define MPU_RASR_SRD_Pos 8U /*!< MPU RASR: Sub-Region Disable Position */ -#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ - -#define MPU_RASR_SIZE_Pos 1U /*!< MPU RASR: Region Size Field Position */ -#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ - -#define MPU_RASR_ENABLE_Pos 0U /*!< MPU RASR: Region enable bit Position */ -#define MPU_RASR_ENABLE_Msk (1UL /*<< MPU_RASR_ENABLE_Pos*/) /*!< MPU RASR: Region enable bit Disable Mask */ - -/*@} end of group CMSIS_MPU */ -#endif - - -/** - \ingroup CMSIS_core_register - \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) - \brief Type definitions for the Core Debug Registers - @{ - */ - -/** - \brief Structure type to access the Core Debug Register (CoreDebug). - */ -typedef struct -{ - __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ - __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ - __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ - __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ -} CoreDebug_Type; - -/* Debug Halting Control and Status Register Definitions */ -#define CoreDebug_DHCSR_DBGKEY_Pos 16U /*!< CoreDebug DHCSR: DBGKEY Position */ -#define CoreDebug_DHCSR_DBGKEY_Msk (0xFFFFUL << CoreDebug_DHCSR_DBGKEY_Pos) /*!< CoreDebug DHCSR: DBGKEY Mask */ - -#define CoreDebug_DHCSR_S_RESET_ST_Pos 25U /*!< CoreDebug DHCSR: S_RESET_ST Position */ -#define CoreDebug_DHCSR_S_RESET_ST_Msk (1UL << CoreDebug_DHCSR_S_RESET_ST_Pos) /*!< CoreDebug DHCSR: S_RESET_ST Mask */ - -#define CoreDebug_DHCSR_S_RETIRE_ST_Pos 24U /*!< CoreDebug DHCSR: S_RETIRE_ST Position */ -#define CoreDebug_DHCSR_S_RETIRE_ST_Msk (1UL << CoreDebug_DHCSR_S_RETIRE_ST_Pos) /*!< CoreDebug DHCSR: S_RETIRE_ST Mask */ - -#define CoreDebug_DHCSR_S_LOCKUP_Pos 19U /*!< CoreDebug DHCSR: S_LOCKUP Position */ -#define CoreDebug_DHCSR_S_LOCKUP_Msk (1UL << CoreDebug_DHCSR_S_LOCKUP_Pos) /*!< CoreDebug DHCSR: S_LOCKUP Mask */ - -#define CoreDebug_DHCSR_S_SLEEP_Pos 18U /*!< CoreDebug DHCSR: S_SLEEP Position */ -#define CoreDebug_DHCSR_S_SLEEP_Msk (1UL << CoreDebug_DHCSR_S_SLEEP_Pos) /*!< CoreDebug DHCSR: S_SLEEP Mask */ - -#define CoreDebug_DHCSR_S_HALT_Pos 17U /*!< CoreDebug DHCSR: S_HALT Position */ -#define CoreDebug_DHCSR_S_HALT_Msk (1UL << CoreDebug_DHCSR_S_HALT_Pos) /*!< CoreDebug DHCSR: S_HALT Mask */ - -#define CoreDebug_DHCSR_S_REGRDY_Pos 16U /*!< CoreDebug DHCSR: S_REGRDY Position */ -#define CoreDebug_DHCSR_S_REGRDY_Msk (1UL << CoreDebug_DHCSR_S_REGRDY_Pos) /*!< CoreDebug DHCSR: S_REGRDY Mask */ - -#define CoreDebug_DHCSR_C_SNAPSTALL_Pos 5U /*!< CoreDebug DHCSR: C_SNAPSTALL Position */ -#define CoreDebug_DHCSR_C_SNAPSTALL_Msk (1UL << CoreDebug_DHCSR_C_SNAPSTALL_Pos) /*!< CoreDebug DHCSR: C_SNAPSTALL Mask */ - -#define CoreDebug_DHCSR_C_MASKINTS_Pos 3U /*!< CoreDebug DHCSR: C_MASKINTS Position */ -#define CoreDebug_DHCSR_C_MASKINTS_Msk (1UL << CoreDebug_DHCSR_C_MASKINTS_Pos) /*!< CoreDebug DHCSR: C_MASKINTS Mask */ - -#define CoreDebug_DHCSR_C_STEP_Pos 2U /*!< CoreDebug DHCSR: C_STEP Position */ -#define CoreDebug_DHCSR_C_STEP_Msk (1UL << CoreDebug_DHCSR_C_STEP_Pos) /*!< CoreDebug DHCSR: C_STEP Mask */ - -#define CoreDebug_DHCSR_C_HALT_Pos 1U /*!< CoreDebug DHCSR: C_HALT Position */ -#define CoreDebug_DHCSR_C_HALT_Msk (1UL << CoreDebug_DHCSR_C_HALT_Pos) /*!< CoreDebug DHCSR: C_HALT Mask */ - -#define CoreDebug_DHCSR_C_DEBUGEN_Pos 0U /*!< CoreDebug DHCSR: C_DEBUGEN Position */ -#define CoreDebug_DHCSR_C_DEBUGEN_Msk (1UL /*<< CoreDebug_DHCSR_C_DEBUGEN_Pos*/) /*!< CoreDebug DHCSR: C_DEBUGEN Mask */ - -/* Debug Core Register Selector Register Definitions */ -#define CoreDebug_DCRSR_REGWnR_Pos 16U /*!< CoreDebug DCRSR: REGWnR Position */ -#define CoreDebug_DCRSR_REGWnR_Msk (1UL << CoreDebug_DCRSR_REGWnR_Pos) /*!< CoreDebug DCRSR: REGWnR Mask */ - -#define CoreDebug_DCRSR_REGSEL_Pos 0U /*!< CoreDebug DCRSR: REGSEL Position */ -#define CoreDebug_DCRSR_REGSEL_Msk (0x1FUL /*<< CoreDebug_DCRSR_REGSEL_Pos*/) /*!< CoreDebug DCRSR: REGSEL Mask */ - -/* Debug Exception and Monitor Control Register Definitions */ -#define CoreDebug_DEMCR_TRCENA_Pos 24U /*!< CoreDebug DEMCR: TRCENA Position */ -#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */ - -#define CoreDebug_DEMCR_MON_REQ_Pos 19U /*!< CoreDebug DEMCR: MON_REQ Position */ -#define CoreDebug_DEMCR_MON_REQ_Msk (1UL << CoreDebug_DEMCR_MON_REQ_Pos) /*!< CoreDebug DEMCR: MON_REQ Mask */ - -#define CoreDebug_DEMCR_MON_STEP_Pos 18U /*!< CoreDebug DEMCR: MON_STEP Position */ -#define CoreDebug_DEMCR_MON_STEP_Msk (1UL << CoreDebug_DEMCR_MON_STEP_Pos) /*!< CoreDebug DEMCR: MON_STEP Mask */ - -#define CoreDebug_DEMCR_MON_PEND_Pos 17U /*!< CoreDebug DEMCR: MON_PEND Position */ -#define CoreDebug_DEMCR_MON_PEND_Msk (1UL << CoreDebug_DEMCR_MON_PEND_Pos) /*!< CoreDebug DEMCR: MON_PEND Mask */ - -#define CoreDebug_DEMCR_MON_EN_Pos 16U /*!< CoreDebug DEMCR: MON_EN Position */ -#define CoreDebug_DEMCR_MON_EN_Msk (1UL << CoreDebug_DEMCR_MON_EN_Pos) /*!< CoreDebug DEMCR: MON_EN Mask */ - -#define CoreDebug_DEMCR_VC_HARDERR_Pos 10U /*!< CoreDebug DEMCR: VC_HARDERR Position */ -#define CoreDebug_DEMCR_VC_HARDERR_Msk (1UL << CoreDebug_DEMCR_VC_HARDERR_Pos) /*!< CoreDebug DEMCR: VC_HARDERR Mask */ - -#define CoreDebug_DEMCR_VC_INTERR_Pos 9U /*!< CoreDebug DEMCR: VC_INTERR Position */ -#define CoreDebug_DEMCR_VC_INTERR_Msk (1UL << CoreDebug_DEMCR_VC_INTERR_Pos) /*!< CoreDebug DEMCR: VC_INTERR Mask */ - -#define CoreDebug_DEMCR_VC_BUSERR_Pos 8U /*!< CoreDebug DEMCR: VC_BUSERR Position */ -#define CoreDebug_DEMCR_VC_BUSERR_Msk (1UL << CoreDebug_DEMCR_VC_BUSERR_Pos) /*!< CoreDebug DEMCR: VC_BUSERR Mask */ - -#define CoreDebug_DEMCR_VC_STATERR_Pos 7U /*!< CoreDebug DEMCR: VC_STATERR Position */ -#define CoreDebug_DEMCR_VC_STATERR_Msk (1UL << CoreDebug_DEMCR_VC_STATERR_Pos) /*!< CoreDebug DEMCR: VC_STATERR Mask */ - -#define CoreDebug_DEMCR_VC_CHKERR_Pos 6U /*!< CoreDebug DEMCR: VC_CHKERR Position */ -#define CoreDebug_DEMCR_VC_CHKERR_Msk (1UL << CoreDebug_DEMCR_VC_CHKERR_Pos) /*!< CoreDebug DEMCR: VC_CHKERR Mask */ - -#define CoreDebug_DEMCR_VC_NOCPERR_Pos 5U /*!< CoreDebug DEMCR: VC_NOCPERR Position */ -#define CoreDebug_DEMCR_VC_NOCPERR_Msk (1UL << CoreDebug_DEMCR_VC_NOCPERR_Pos) /*!< CoreDebug DEMCR: VC_NOCPERR Mask */ - -#define CoreDebug_DEMCR_VC_MMERR_Pos 4U /*!< CoreDebug DEMCR: VC_MMERR Position */ -#define CoreDebug_DEMCR_VC_MMERR_Msk (1UL << CoreDebug_DEMCR_VC_MMERR_Pos) /*!< CoreDebug DEMCR: VC_MMERR Mask */ - -#define CoreDebug_DEMCR_VC_CORERESET_Pos 0U /*!< CoreDebug DEMCR: VC_CORERESET Position */ -#define CoreDebug_DEMCR_VC_CORERESET_Msk (1UL /*<< CoreDebug_DEMCR_VC_CORERESET_Pos*/) /*!< CoreDebug DEMCR: VC_CORERESET Mask */ - -/*@} 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. - \return Masked and shifted value. -*/ -#define _VAL2FLD(field, value) ((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. - \return Masked and shifted bit field value. -*/ -#define _FLD2VAL(field, value) ((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 Cortex-M3 Hardware */ -#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ -#define ITM_BASE (0xE0000000UL) /*!< ITM Base Address */ -#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ -#define TPI_BASE (0xE0040000UL) /*!< TPI Base Address */ -#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug 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 */ -#define ITM ((ITM_Type *) ITM_BASE ) /*!< ITM configuration struct */ -#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ -#define TPI ((TPI_Type *) TPI_BASE ) /*!< TPI configuration struct */ -#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ - -#if (__MPU_PRESENT == 1U) - #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ - #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ -#endif - -/*@} */ - - - -/******************************************************************************* - * Hardware Abstraction Layer - Core Function Interface contains: - - Core NVIC Functions - - Core SysTick Functions - - Core Debug 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. - @{ - */ - -/** - \brief Set Priority Grouping - \details Sets the priority grouping field using the required unlock sequence. - The parameter PriorityGroup is assigned to the field SCB->AIRCR [10:8] PRIGROUP field. - Only values from 0..7 are used. - 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 Priority grouping field. - */ -__STATIC_INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) -{ - uint32_t reg_value; - uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ - - reg_value = SCB->AIRCR; /* read old register configuration */ - reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ - reg_value = (reg_value | - ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << 8U) ); /* Insert write key and priorty group */ - SCB->AIRCR = reg_value; -} - - -/** - \brief Get Priority Grouping - \details Reads the priority grouping field from the NVIC Interrupt Controller. - \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). - */ -__STATIC_INLINE uint32_t NVIC_GetPriorityGrouping(void) -{ - return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); -} - - -/** - \brief Enable External Interrupt - \details Enables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) -{ - NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Disable External Interrupt - \details Disables a device-specific interrupt in the NVIC interrupt controller. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) -{ - NVIC->ICER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Pending Interrupt - \details Reads the pending register in the NVIC and returns the pending bit for the specified interrupt. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not pending. - \return 1 Interrupt status is pending. - */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Pending Interrupt - \details Sets the pending bit of an external interrupt. - \param [in] IRQn Interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ISPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Clear Pending Interrupt - \details Clears the pending bit of an external interrupt. - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ICPR[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL)); -} - - -/** - \brief Get Active Interrupt - \details Reads the active register in NVIC and returns the active bit. - \param [in] IRQn Interrupt number. - \return 0 Interrupt status is not active. - \return 1 Interrupt status is active. - */ -__STATIC_INLINE uint32_t NVIC_GetActive(IRQn_Type IRQn) -{ - return((uint32_t)(((NVIC->IABR[(((uint32_t)(int32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); -} - - -/** - \brief Set Interrupt Priority - \details Sets the priority of an interrupt. - \note The priority cannot be set for every core interrupt. - \param [in] IRQn Interrupt number. - \param [in] priority Priority to set. - */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if ((int32_t)(IRQn) < 0) - { - SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } - else - { - NVIC->IP[((uint32_t)(int32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } -} - - -/** - \brief Get Interrupt Priority - \details Reads the priority of an interrupt. - The interrupt number can be positive to specify an external (device specific) interrupt, - or negative to specify an internal (core) interrupt. - \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)SCB->SHP[(((uint32_t)(int32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); - } - else - { - return(((uint32_t)NVIC->IP[((uint32_t)(int32_t)IRQn)] >> (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 System Reset - \details Initiates a system reset request to reset the MCU. - */ -__STATIC_INLINE void NVIC_SystemReset(void) -{ - __DSB(); /* Ensure all outstanding memory accesses included - buffered write are completed before reset */ - SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | - SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */ - __DSB(); /* Ensure completion of memory access */ - - for(;;) /* wait until reset */ - { - __NOP(); - } -} - -/*@} end of CMSIS_Core_NVICFunctions */ - - - -/* ################################## SysTick function ############################################ */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_SysTickFunctions SysTick Functions - \brief Functions that configure the System. - @{ - */ - -#if (__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 __Vendor_SysTickConfig is set to 1, then the - function SysTick_Config is not included. In this case, the file device.h - 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 */ - - - -/* ##################################### Debug In/Output function ########################################### */ -/** - \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_core_DebugFunctions ITM Functions - \brief Functions that access the ITM debug interface. - @{ - */ - -extern volatile int32_t ITM_RxBuffer; /*!< External variable to receive characters. */ -#define ITM_RXBUFFER_EMPTY 0x5AA55AA5U /*!< Value identifying \ref ITM_RxBuffer is ready for next character. */ - - -/** - \brief ITM Send Character - \details Transmits a character via the ITM channel 0, and - \li Just returns when no debugger is connected that has booked the output. - \li Is blocking when a debugger is connected, but the previous character sent has not been transmitted. - \param [in] ch Character to transmit. - \returns Character to transmit. - */ -__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) -{ - if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ - ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */ - { - while (ITM->PORT[0U].u32 == 0UL) - { - __NOP(); - } - ITM->PORT[0U].u8 = (uint8_t)ch; - } - return (ch); -} - - -/** - \brief ITM Receive Character - \details Inputs a character via the external variable \ref ITM_RxBuffer. - \return Received character. - \return -1 No character pending. - */ -__STATIC_INLINE int32_t ITM_ReceiveChar (void) -{ - int32_t ch = -1; /* no character available */ - - if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) - { - ch = ITM_RxBuffer; - ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ - } - - return (ch); -} - - -/** - \brief ITM Check Character - \details Checks whether a character is pending for reading in the variable \ref ITM_RxBuffer. - \return 0 No character available. - \return 1 Character available. - */ -__STATIC_INLINE int32_t ITM_CheckChar (void) -{ - - if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) - { - return (0); /* no character available */ - } - else - { - return (1); /* character available */ - } -} - -/*@} end of CMSIS_core_DebugFunctions */ - - - - -#ifdef __cplusplus -} -#endif - -#endif /* __CORE_SC300_H_DEPENDANT */ - -#endif /* __CMSIS_GENERIC */ diff --git a/Software/FabReader2.ioc b/Software/FabReader2.ioc deleted file mode 100644 index 721d858..0000000 --- a/Software/FabReader2.ioc +++ /dev/null @@ -1,184 +0,0 @@ -#MicroXplorer Configuration settings - do not modify -File.Version=6 -KeepUserPlacement=false -Mcu.CPN=STM32L476RGT3 -Mcu.Family=STM32L4 -Mcu.IP0=NVIC -Mcu.IP1=RCC -Mcu.IP2=SYS -Mcu.IP3=USART2 -Mcu.IPNb=4 -Mcu.Name=STM32L476R(C-E-G)Tx -Mcu.Package=LQFP64 -Mcu.Pin0=PC13 -Mcu.Pin1=PC14-OSC32_IN (PC14) -Mcu.Pin10=PB3 (JTDO-TRACESWO) -Mcu.Pin11=VP_SYS_VS_Systick -Mcu.Pin2=PC15-OSC32_OUT (PC15) -Mcu.Pin3=PH0-OSC_IN (PH0) -Mcu.Pin4=PH1-OSC_OUT (PH1) -Mcu.Pin5=PA2 -Mcu.Pin6=PA3 -Mcu.Pin7=PA5 -Mcu.Pin8=PA13 (JTMS-SWDIO) -Mcu.Pin9=PA14 (JTCK-SWCLK) -Mcu.PinsNb=12 -Mcu.ThirdPartyNb=0 -Mcu.UserConstants= -Mcu.UserName=STM32L476RGTx -MxCube.Version=6.5.0 -MxDb.Version=DB.6.0.50 -NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true -NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true -NVIC.ForceEnableDMAVector=true -NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true -NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true -NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true -NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true -NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 -NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true -NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true -NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:true -PA13\ (JTMS-SWDIO).GPIOParameters=GPIO_Label -PA13\ (JTMS-SWDIO).GPIO_Label=TMS -PA13\ (JTMS-SWDIO).Locked=true -PA13\ (JTMS-SWDIO).Mode=Serial_Wire -PA13\ (JTMS-SWDIO).Signal=SYS_JTMS-SWDIO -PA14\ (JTCK-SWCLK).GPIOParameters=GPIO_Label -PA14\ (JTCK-SWCLK).GPIO_Label=TCK -PA14\ (JTCK-SWCLK).Locked=true -PA14\ (JTCK-SWCLK).Mode=Serial_Wire -PA14\ (JTCK-SWCLK).Signal=SYS_JTCK-SWCLK -PA2.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label,GPIO_Mode -PA2.GPIO_Label=USART_TX -PA2.GPIO_Mode=GPIO_MODE_AF_PP -PA2.GPIO_PuPd=GPIO_NOPULL -PA2.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PA2.Locked=true -PA2.Mode=Asynchronous -PA2.Signal=USART2_TX -PA3.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label,GPIO_Mode -PA3.GPIO_Label=USART_RX -PA3.GPIO_Mode=GPIO_MODE_AF_PP -PA3.GPIO_PuPd=GPIO_NOPULL -PA3.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH -PA3.Locked=true -PA3.Mode=Asynchronous -PA3.Signal=USART2_RX -PA5.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultOutputPP -PA5.GPIO_Label=LD2 [green Led] -PA5.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_PP -PA5.GPIO_PuPd=GPIO_NOPULL -PA5.GPIO_Speed=GPIO_SPEED_FREQ_LOW -PA5.Locked=true -PA5.Signal=GPIO_Output -PB3\ (JTDO-TRACESWO).GPIOParameters=GPIO_Label -PB3\ (JTDO-TRACESWO).GPIO_Label=SWO -PB3\ (JTDO-TRACESWO).Locked=true -PB3\ (JTDO-TRACESWO).Signal=SYS_JTDO-SWO -PC13.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI -PC13.GPIO_Label=B1 [Blue PushButton] -PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING -PC13.GPIO_PuPd=GPIO_NOPULL -PC13.Locked=true -PC13.Signal=GPXTI13 -PC14-OSC32_IN\ (PC14).Locked=true -PC14-OSC32_IN\ (PC14).Mode=LSE-External-Oscillator -PC14-OSC32_IN\ (PC14).Signal=RCC_OSC32_IN -PC15-OSC32_OUT\ (PC15).Locked=true -PC15-OSC32_OUT\ (PC15).Mode=LSE-External-Oscillator -PC15-OSC32_OUT\ (PC15).Signal=RCC_OSC32_OUT -PH0-OSC_IN\ (PH0).Locked=true -PH0-OSC_IN\ (PH0).Signal=RCC_OSC_IN -PH1-OSC_OUT\ (PH1).Locked=true -PH1-OSC_OUT\ (PH1).Signal=RCC_OSC_OUT -PinOutPanel.RotationAngle=0 -ProjectManager.AskForMigrate=true -ProjectManager.BackupPrevious=false -ProjectManager.CompilerOptimize=6 -ProjectManager.ComputerToolchain=false -ProjectManager.CoupleFile=false -ProjectManager.CustomerFirmwarePackage= -ProjectManager.DefaultFWLocation=true -ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32L476RGTx -ProjectManager.FirmwarePackage=STM32Cube FW_L4 V1.17.2 -ProjectManager.FreePins=false -ProjectManager.HalAssertFull=false -ProjectManager.HeapSize=0x200 -ProjectManager.KeepUserCode=true -ProjectManager.LastFirmware=true -ProjectManager.LibraryCopy=1 -ProjectManager.MainLocation=Core/Src -ProjectManager.NoMain=false -ProjectManager.PreviousToolchain=STM32CubeIDE -ProjectManager.ProjectBuild=false -ProjectManager.ProjectFileName=FabReader2.ioc -ProjectManager.ProjectName=FabReader2 -ProjectManager.RegisterCallBack= -ProjectManager.StackSize=0x400 -ProjectManager.TargetToolchain=STM32CubeIDE -ProjectManager.ToolChainLocation= -ProjectManager.UnderRoot=true -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART2_UART_Init-USART2-false-HAL-true -RCC.ADCFreq_Value=64000000 -RCC.AHBFreq_Value=80000000 -RCC.APB1Freq_Value=80000000 -RCC.APB1TimFreq_Value=80000000 -RCC.APB2Freq_Value=80000000 -RCC.APB2TimFreq_Value=80000000 -RCC.CortexFreq_Value=80000000 -RCC.DFSDMFreq_Value=80000000 -RCC.FCLKCortexFreq_Value=80000000 -RCC.FamilyName=M -RCC.HCLKFreq_Value=80000000 -RCC.HSE_VALUE=8000000 -RCC.HSI_VALUE=16000000 -RCC.I2C1Freq_Value=80000000 -RCC.I2C2Freq_Value=80000000 -RCC.I2C3Freq_Value=80000000 -RCC.IPParameters=ADCFreq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,DFSDMFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSI_VALUE,MCO1PinFreq_Value,MSI_VALUE,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PLLSAI1PoutputFreq_Value,PLLSAI1QoutputFreq_Value,PLLSAI1RoutputFreq_Value,PLLSAI2PoutputFreq_Value,PLLSAI2RoutputFreq_Value,PLLSourceVirtual,PREFETCH_ENABLE,PWRFreq_Value,RNGFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMCFreq_Value,SWPMI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAI1OutputFreq_Value,VCOSAI2OutputFreq_Value -RCC.LPTIM1Freq_Value=80000000 -RCC.LPTIM2Freq_Value=80000000 -RCC.LPUART1Freq_Value=80000000 -RCC.LSCOPinFreq_Value=32000 -RCC.LSI_VALUE=32000 -RCC.MCO1PinFreq_Value=80000000 -RCC.MSI_VALUE=4000000 -RCC.PLLN=10 -RCC.PLLPoutputFreq_Value=22857142.85714286 -RCC.PLLQoutputFreq_Value=80000000 -RCC.PLLRCLKFreq_Value=80000000 -RCC.PLLSAI1PoutputFreq_Value=18285714.285714287 -RCC.PLLSAI1QoutputFreq_Value=64000000 -RCC.PLLSAI1RoutputFreq_Value=64000000 -RCC.PLLSAI2PoutputFreq_Value=18285714.285714287 -RCC.PLLSAI2RoutputFreq_Value=64000000 -RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSI -RCC.PREFETCH_ENABLE=1 -RCC.PWRFreq_Value=80000000 -RCC.RNGFreq_Value=64000000 -RCC.SAI1Freq_Value=18285714.285714287 -RCC.SAI2Freq_Value=18285714.285714287 -RCC.SDMMCFreq_Value=64000000 -RCC.SWPMI1Freq_Value=80000000 -RCC.SYSCLKFreq_VALUE=80000000 -RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK -RCC.UART4Freq_Value=80000000 -RCC.UART5Freq_Value=80000000 -RCC.USART1Freq_Value=80000000 -RCC.USART2Freq_Value=80000000 -RCC.USART3Freq_Value=80000000 -RCC.USBFreq_Value=64000000 -RCC.VCOInputFreq_Value=16000000 -RCC.VCOOutputFreq_Value=160000000 -RCC.VCOSAI1OutputFreq_Value=128000000 -RCC.VCOSAI2OutputFreq_Value=128000000 -SH.GPXTI13.0=GPIO_EXTI13 -SH.GPXTI13.ConfNb=1 -USART2.IPParameters=VirtualMode-Asynchronous -USART2.VirtualMode-Asynchronous=VM_ASYNC -VP_SYS_VS_Systick.Mode=SysTick -VP_SYS_VS_Systick.Signal=SYS_VS_Systick -board=NUCLEO-L476RG -boardIOC=true diff --git a/Software/Middlewares/ST/ndef/Inc/message/ndef_buffer.h b/Software/Middlewares/ST/ndef/Inc/message/ndef_buffer.h deleted file mode 100644 index d43aa47..0000000 --- a/Software/Middlewares/ST/ndef/Inc/message/ndef_buffer.h +++ /dev/null @@ -1,86 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF buffer type structures - * - */ - -#ifndef NDEF_BUFFER_H -#define NDEF_BUFFER_H - - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/*! NDEF structure to handle const buffers */ -typedef struct -{ - const uint8_t* buffer; /*!< Pointer to const buffer */ - uint32_t length; /*!< buffer length */ -} ndefConstBuffer; - - -/*! NDEF structure to handle buffers */ -typedef struct -{ - uint8_t* buffer; /*!< Pointer to buffer */ - uint32_t length; /*!< buffer length */ -} ndefBuffer; - - -/*! NDEF structure to handle const buffers limited to 256 bytes */ -typedef struct -{ - const uint8_t* buffer; /*!< Pointer to const buffer */ - uint8_t length; /*!< buffer length */ -} ndefConstBuffer8; - - -/*! NDEF structure to handle buffers limited to 256 bytes */ -typedef struct -{ - uint8_t* buffer; /*!< Pointer to buffer */ - uint8_t length; /*!< buffer length */ -} ndefBuffer8; - - -#endif /* NDEF_BUFFER_H */ diff --git a/Software/Middlewares/ST/ndef/Inc/message/ndef_message.h b/Software/Middlewares/ST/ndef/Inc/message/ndef_message.h deleted file mode 100644 index c7dd4eb..0000000 --- a/Software/Middlewares/ST/ndef/Inc/message/ndef_message.h +++ /dev/null @@ -1,196 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF message header file - * - * NDEF Message provides functionalities required to perform message management. - * A message is a list of records. - * - * The most common interfaces are: - *
  ndefMessageReset() - *
  ndefMessageAppend() - *
  ndefMessageEncode() - *
  ndefMessageDecode() - * - * \addtogroup NDEF - * @{ - * - */ - -#ifndef NDEF_MESSAGE_H -#define NDEF_MESSAGE_H - - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "ndef_record.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -/*! Message scanning macros */ -#define ndefMessageGetFirstRecord(message) (((message) == NULL) ? NULL : (message)->record) /*!< Get first record */ -#define ndefMessageGetNextRecord(record) (((record) == NULL) ? NULL : (record)->next) /*!< Get next record */ - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/*! Message information */ -typedef struct -{ - uint32_t length; /*!< Message length in bytes */ - uint32_t recordCount; /*!< Number of records in the message */ -} ndefMessageInfo; - - -/*! NDEF message */ -struct ndefMessageStruct -{ - ndefRecord* record; /*!< Pointer to a record */ - ndefMessageInfo info; /*!< Message information, e.g. length in bytes, record count */ -}; - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/*! - ***************************************************************************** - * Initialize an empty NDEF message - * - * \param[in,out] message to initialize - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMessageInit(ndefMessage* message); - - -/*! - ***************************************************************************** - * Get NDEF message information - * - * Return the message information - * - * \param[in] message - * \param[out] info: e.g. message length in bytes, number of records - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMessageGetInfo(const ndefMessage* message, ndefMessageInfo* info); - - -/*! - ***************************************************************************** - * Get the number of NDEF message records - * - * Return the number of records in the given message - * - * \param[in] message - * - * \return number of records - ***************************************************************************** - */ -uint32_t ndefMessageGetRecordCount(const ndefMessage* message); - - -/*! - ***************************************************************************** - * Append a record to an NDEF message - * - * \param[in] record: Record to append - * \param[in,out] message: Message to be appended with the given record - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMessageAppend(ndefMessage* message, ndefRecord* record); - - -/*! - ***************************************************************************** - * Decode a raw buffer to an NDEF message - * - * Convert a raw buffer to a message - * - * \param[in] bufPayload: Payload buffer to convert into message - * \param[out] message: Message created from the raw buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMessageDecode(const ndefConstBuffer* bufPayload, ndefMessage* message); - - -/*! - ***************************************************************************** - * Encode an NDEF message to a raw buffer - * - * Convert a message to a raw buffer - * - * \param[in] message: Message to convert - * \param[in,out] bufPayload: Output buffer to store the converted message - * The input length provides the output buffer allocated - * length, used for parameter check to avoid overflow. - * In case the buffer provided is too short, it is - * updated with the required buffer length. - * On success, it is updated with the actual buffer - * length used to contain the converted message. - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMessageEncode(const ndefMessage* message, ndefBuffer* bufPayload); - - -#endif /* NDEF_MESSAGE_H */ - -/** - * @} - * - */ diff --git a/Software/Middlewares/ST/ndef/Inc/message/ndef_record.h b/Software/Middlewares/ST/ndef/Inc/message/ndef_record.h deleted file mode 100644 index 5b5e9ec..0000000 --- a/Software/Middlewares/ST/ndef/Inc/message/ndef_record.h +++ /dev/null @@ -1,412 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF record header file - * - * - * NDEF record provides functionalities required to perform record management. - * - * - * \addtogroup NDEF - * @{ - * - */ - -#ifndef NDEF_RECORD_H -#define NDEF_RECORD_H - - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "platform.h" -#include "st_errno.h" -#include "ndef_buffer.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define NDEF_RECORD_HEADER_LEN 7U /*!< Record header length (sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint32_t) + sizeof(uint8_t) */ - -#define NDEF_SHORT_RECORD_LENGTH_MAX 255U /*!< Short record maximum length */ - - -/*! Type Name Format aka TNF types */ -#define NDEF_TNF_EMPTY 0U /*!< TNF Empty */ -#define NDEF_TNF_RTD_WELL_KNOWN_TYPE 1U /*!< TNF Well-known Type */ -#define NDEF_TNF_MEDIA_TYPE 2U /*!< TNF Media Type */ -#define NDEF_TNF_URI 3U /*!< TNF URI */ -#define NDEF_TNF_RTD_EXTERNAL_TYPE 4U /*!< TNF External Type */ -#define NDEF_TNF_UNKNOWN 5U /*!< TNF Unknown */ -#define NDEF_TNF_UNCHANGED 6U /*!< TNF Unchanged */ -#define NDEF_TNF_RESERVED 7U /*!< TNF Reserved */ - -#define NDEF_TNF_MASK 7U /*!< Type Name Format mask */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/*! Build the record header byte, made of MB, ME, CF, SR, IL bits and TNF type */ -#define ndefHeader(MB, ME, CF, SR, IL, TNF) ((((MB) & 1U) << 7U) | (((ME) & 1U) << 6U) | (((CF) & 1U) << 5U) | (((SR) & 1U) << 4U) | (((IL) & 1U) << 3U) | ((uint8_t)(TNF) & NDEF_TNF_MASK) ) /*< Build the record header byte, made of MB, ME, CF, SR, IL bits and TNF type */ - -/*! Read bits in header byte */ -#define ndefHeaderMB(record) ( ((record)->header & 0x80U) >> 7 ) /*!< Return the MB bit from the record header byte */ -#define ndefHeaderME(record) ( ((record)->header & 0x40U) >> 6 ) /*!< Return the ME bit from the record header byte */ -#define ndefHeaderCF(record) ( ((record)->header & 0x20U) >> 5 ) /*!< Return the CF bit from the record header byte */ -#define ndefHeaderSR(record) ( ((record)->header & 0x10U) >> 4 ) /*!< Return the SR bit from the record header byte */ -#define ndefHeaderIL(record) ( ((record)->header & 0x08U) >> 3 ) /*!< Return the IL bit from the record header byte */ -#define ndefHeaderTNF(record) ( (record)->header & NDEF_TNF_MASK ) /*!< Return the TNF type from the record header byte */ - -/*! Set bits in header byte */ -#define ndefHeaderSetMB(record) ( (record)->header |= (1U << 7) ) /*!< Set the MB bit in the record header byte */ -#define ndefHeaderSetME(record) ( (record)->header |= (1U << 6) ) /*!< Set the ME bit in the record header byte */ -#define ndefHeaderSetCF(record) ( (record)->header |= (1U << 5) ) /*!< Set the CF bit in the record header byte */ -#define ndefHeaderSetSR(record) ( (record)->header |= (1U << 4) ) /*!< Set the SR bit in the record header byte */ -#define ndefHeaderSetIL(record) ( (record)->header |= (1U << 3) ) /*!< Set the IL bit in the record header byte */ -#define ndefHeaderSetTNF(record, value) ( (record)->header |= (uint8_t)(value) & NDEF_TNF_MASK ) /*!< Set the TNF type in the record header byte */ - -/*! Clear bits in header byte */ -#define ndefHeaderClearMB(record) ( (record)->header &= 0x7FU ) /*!< Clear the MB bit in the record header byte */ -#define ndefHeaderClearME(record) ( (record)->header &= 0xBFU ) /*!< Clear the ME bit in the record header byte */ -#define ndefHeaderClearCF(record) ( (record)->header &= 0xDFU ) /*!< Clear the CF bit in the record header byte */ -#define ndefHeaderClearSR(record) ( (record)->header &= 0xEFU ) /*!< Clear the SR bit in the record header byte */ -#define ndefHeaderClearIL(record) ( (record)->header &= 0xF7U ) /*!< Clear the IL bit in the record header byte */ -#define ndefHeaderClearTNF(record, value) ( (record)->header &= 0xF8U ) /*!< Clear the TNF type in the record header byte */ - -/*! Set or Clear the MB/ME bit in header byte */ -#define ndefHeaderSetValueMB(record, value) do{ (record)->header &= 0x7FU; (record)->header |= (((uint8_t)(value)) & 1U) << 7; }while(0) /*!< Write the value to the MB bit in the record header byte */ -#define ndefHeaderSetValueME(record, value) do{ (record)->header &= 0xBFU; (record)->header |= (((uint8_t)(value)) & 1U) << 6; }while(0) /*!< Write the value to the ME bit in the record header byte */ -#define ndefHeaderSetValueSR(record, value) do{ (record)->header &= 0xEFU; (record)->header |= (((uint8_t)(value)) & 1U) << 4; }while(0) /*!< Write the value to the SR bit in the record header byte */ - -/*! Test bit in header byte */ -#define ndefHeaderIsSetMB(record) ( ndefHeaderMB(record) == 1U ) /*!< Return true if the Message Begin bit is set */ -#define ndefHeaderIsSetSR(record) ( ndefHeaderSR(record) == 1U ) /*!< Return true if the Short Record bit is set */ -#define ndefHeaderIsSetIL(record) ( ndefHeaderIL(record) == 1U ) /*!< Return true if the Id Length bit is set */ - - -typedef struct ndefTypeStruct ndefType; /*!< Forward declaration */ -typedef struct ndefMessageStruct ndefMessage; /*!< Forward declaration */ - -/*! Record type */ -typedef struct ndefRecordStruct -{ - uint8_t header; /*!< Header byte made of MB:1 ME:1 CF:1 SR:1 IL:1 TNF:3 => 8 bits */ - uint8_t typeLength; /*!< Type length in bytes */ - uint8_t idLength; /*!< Id Length, presence depends on the IL bit */ - const uint8_t* type; /*!< Type follows the structure implied by the value of the TNF field */ - const uint8_t* id; /*!< Id (middle and terminating record chunks MUST NOT have an ID field) */ - ndefConstBuffer bufPayload; /*!< Payload buffer. Payload length depends on the SR bit (either coded on 1 or 4 bytes) */ - - const ndefType* ndeftype; /*!< Well-known type data */ - - struct ndefRecordStruct* next; /*!< Pointer to the next record, if any */ -} ndefRecord; - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -/*! - ***************************************************************************** - * Reset an NDEF record - * - * This function clears every record field - * - * \param[in,out] record to reset - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordReset(ndefRecord* record); - - -/*! - ***************************************************************************** - * Initialize an NDEF record - * - * This function initializes all record fields - * - * \param[in,out] record: Record to initialize - * \param[in] tnf: TNF type - * \param[in] bufType: Type buffer - * \param[in] bufId: Id buffer - * \param[in] bufPayload: Payload buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordInit(ndefRecord* record, uint8_t tnf, const ndefConstBuffer8* bufType, const ndefConstBuffer8* bufId, const ndefConstBuffer* bufPayload); - - -/*! - ***************************************************************************** - * Get NDEF record header length - * - * Return the length of header for the given record - * - * \param[in] record - * - * \return header length in bytes - ***************************************************************************** - */ -uint32_t ndefRecordGetHeaderLength(const ndefRecord* record); - - -/*! - ***************************************************************************** - * Get NDEF record length - * - * Return the length of the given record, needed to store it as a raw buffer - * - * \param[in] record - * - * \return record length in bytes - ***************************************************************************** - */ -uint32_t ndefRecordGetLength(const ndefRecord* record); - - -/*! - ***************************************************************************** - * Set NDEF record type - * - * Set the type for the given record - * - * \param[in,out] record: Record to set the type - * \param[in] tnf: TNF type - * \param[in] bufType: Type buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordSetType(ndefRecord* record, uint8_t tnf, const ndefConstBuffer8* bufType); - - -/*! - ***************************************************************************** - * Get NDEF record type - * - * Return the type for the given record - * - * \param[in] record: Record to get the type from - * \param[out] tnf: Pointer to the TNF type - * \param[out] bufType: Type string buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordGetType(const ndefRecord* record, uint8_t* tnf, ndefConstBuffer8* bufType); - -/*! - ***************************************************************************** - * Check the record type matches a given type - * - * \param[in] record: Record to get the type from - * \param[out] tnf: the TNF type to compare with - * \param[out] bufType: Type string buffer to compare with - * - * \return true or false - ***************************************************************************** - */ -bool ndefRecordTypeMatch(const ndefRecord* record, uint8_t tnf, const ndefConstBuffer8* bufType); - - -/*! - ***************************************************************************** - * Set NDEF record Id - * - * Set the Id for the given NDEF record - * - * \param[in] record: Record to set the Id - * \param[out] bufId: Id buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordSetId(ndefRecord* record, const ndefConstBuffer8* bufId); - - -/*! - ***************************************************************************** - * Get NDEF record Id - * - * Return the Id for the given NDEF record - * - * \param[in] record: Record to get the Id from - * \param[out] bufId: Id buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordGetId(const ndefRecord* record, ndefConstBuffer8* bufId); - - -/*! - ***************************************************************************** - * Set NDEF record payload - * - * Set the payload for the given record, update the SR bit accordingly - * - * \param[in,out] record: Record to set the payload - * \param[in] bufPayload: Payload buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordSetPayload(ndefRecord* record, const ndefConstBuffer* bufPayload); - - -/*! - ***************************************************************************** - * Get NDEF record payload - * - * Return the payload for the given record - * - * \param[in] record: Record to get the payload from - * \param[out] bufPayload: Payload buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordGetPayload(const ndefRecord* record, ndefConstBuffer* bufPayload); - - -/*! - ***************************************************************************** - * Decode a raw buffer to create an NDEF record - * - * Convert a raw buffer to a record - * - * \param[in] bufPayload: Payload buffer to convert into record - * \param[out] record: Record created from the raw buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordDecode(const ndefConstBuffer* bufPayload, ndefRecord* record); - - -/*! - ***************************************************************************** - * Encode an NDEF record header to a raw buffer - * - * Convert a record header to a raw buffer. It is made of: - * "header byte" (1 byte), type length (1 byte), - * payload length (4 bytes), Id length (1 byte). - * Total 7 bytes. - * - * \param[in] record: Record header to convert - * \param[in,out] bufHeader: Output buffer to store the converted record header - * The input length provides the output buffer allocated - * length, used for parameter check to avoid overflow. - * In case the buffer provided is too short, it is - * updated with the required buffer length. - * On success, it is updated with the actual buffer - * length used to contain the converted record. - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordEncodeHeader(const ndefRecord* record, ndefBuffer* bufHeader); - - -/*! - ***************************************************************************** - * Encode an NDEF record to a raw buffer - * - * Convert a record to a raw buffer - * - * \param[in] record: Record to convert - * \param[in,out] bufRecord: Output buffer to store the converted record - * The input length provides the output buffer allocated - * length, used for parameter check to avoid overflow. - * In case the buffer provided is too short, it is - * updated with the required buffer length. - * On success, it is updated with the actual buffer - * length used to contain the converted record. - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordEncode(const ndefRecord* record, ndefBuffer* bufRecord); - - -/*! - ***************************************************************************** - * Get NDEF record payload length - * - * Return the length of payload for the given record - * - * \param[in] record - * - * \return payload length in bytes - ***************************************************************************** - */ -uint32_t ndefRecordGetPayloadLength(const ndefRecord* record); - - -/*! - ***************************************************************************** - * Return a payload elementary item needed to build the complete record payload - * - * Call this function to get either the first payload item, or the next one. - * Returns the next payload item, call it until it returns NULL. - * - * \param[in] record: Record - * \param[out] bufPayloadItem: The payload item returned - * \param[in] begin: Tell to return the first payload item or the next one - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -const uint8_t* ndefRecordGetPayloadItem(const ndefRecord* record, ndefConstBuffer* bufPayloadItem, bool begin); - - -#endif /* NDEF_RECORD_H */ - -/** - * @} - * - */ diff --git a/Software/Middlewares/ST/ndef/Inc/message/ndef_type_wifi.h b/Software/Middlewares/ST/ndef/Inc/message/ndef_type_wifi.h deleted file mode 100644 index ddf8678..0000000 --- a/Software/Middlewares/ST/ndef/Inc/message/ndef_type_wifi.h +++ /dev/null @@ -1,161 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF Wifi type header file - * - * NDEF Wifi type provides functionalities to handle Wifi records. - * - * \addtogroup NDEF - * @{ - * - */ - -#ifndef NDEF_TYPE_WIFI_H -#define NDEF_TYPE_WIFI_H - - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "ndef_types.h" -#include "ndef_record.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -#define NDEF_WIFI_AUTHENTICATION_NONE 0U /*!< WPS No Authentication (Should be 1, but set to 0 for Android native support) */ -#define NDEF_WIFI_AUTHENTICATION_WPAPSK 2U /*!< WPS Authentication based on WPAPSK */ -#define NDEF_WIFI_AUTHENTICATION_SHARED 3U /*!< WPS Authentication */ -#define NDEF_WIFI_AUTHENTICATION_WPA 4U /*!< WPS Authentication based on WPA */ -#define NDEF_WIFI_AUTHENTICATION_WPA2 5U /*!< WPS Authentication based on WPA2 */ -#define NDEF_WIFI_AUTHENTICATION_WPA2PSK 6U /*!< WPS Authentication based on WPA2PSK */ - - -#define NDEF_WIFI_ENCRYPTION_NONE 0U /*!< WPS No Encryption (Should be 1, but set to 0 for Android native support) */ -#define NDEF_WIFI_ENCRYPTION_WEP 2U /*!< WPS Encryption based on WEP */ -#define NDEF_WIFI_ENCRYPTION_TKIP 3U /*!< WPS Encryption based on TKIP */ -#define NDEF_WIFI_ENCRYPTION_AES 4U /*!< WPS Encryption based on AES */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/*! Structure to store Network SSID, Authentication Type, Encryption Type and Network Key */ -typedef struct -{ - ndefConstBuffer bufNetworkSSID; /*!< Network SSID */ - ndefConstBuffer bufNetworkKey; /*!< Network Key */ - uint8_t authentication; /*!< Authentication type */ - uint8_t encryption; /*!< Encryption */ -} ndefTypeWifi; - - -/*! Wifi Record Type buffers */ -extern const ndefConstBuffer8 bufMediaTypeWifi; /*! Wifi Record Type buffer */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/*! - ***************************************************************************** - * Initialize a Wifi configuration - * - * \param[out] wifi: wifi type to initialize - * \param[in] wifiConfig: wifi configuration to use - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefWifi(ndefType* wifi, const ndefTypeWifi* wifiConfig); - - -/*! - ***************************************************************************** - * Get Wifi configuration - * - * \param[in] wifi: wifi type to get information from - * \param[out] wifiConfig: wifi configuration - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefGetWifi(const ndefType* wifi, ndefTypeWifi* wifiConfig); - - -/*! - ***************************************************************************** - * Convert an NDEF record to a wifi type - * - * \param[in] record: Record to convert - * \param[out] wifi: The converted wifi type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToWifi(const ndefRecord* record, ndefType* wifi); - - -/*! - ***************************************************************************** - * Convert a wifi type to an NDEF record - * - * \param[in] wifi: wifi type to convert - * \param[out] record: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefWifiToRecord(const ndefType* wifi, ndefRecord* record); - - -#endif /* NDEF_TYPE_WIFI_H */ - -/** - * @} - * - */ diff --git a/Software/Middlewares/ST/ndef/Inc/message/ndef_types.h b/Software/Middlewares/ST/ndef/Inc/message/ndef_types.h deleted file mode 100644 index 768f88c..0000000 --- a/Software/Middlewares/ST/ndef/Inc/message/ndef_types.h +++ /dev/null @@ -1,330 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Common NDEF RTD (well-known and external) and Media types header file - * - * NDEF types provides an abstraction layer gathering both the RTD and MIME types - * in a single generic ndefType interface. - * See ndefTypeStruct and ndefType - * - * \addtogroup NDEF - * @{ - * - */ - -#ifndef NDEF_TYPES_H -#define NDEF_TYPES_H - - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "platform.h" -#include "ndef_record.h" -#include "ndef_buffer.h" -#include "ndef_type_wifi.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/*! Device Information defines */ -#define NDEF_UUID_LENGTH 16U /*!< Device Information UUID length */ - - -/*! Text defines */ -/*! RTD Type Text Encoding */ -#define TEXT_ENCODING_UTF8 0U /*!< UTF8 text encoding */ -#define TEXT_ENCODING_UTF16 1U /*!< UTF16 text encoding */ - -#define NDEF_RTD_TEXT_ENCODING_MASK 0x80U /*!< Text encoding mask */ -#define NDEF_RTD_TEXT_ENCODING_SHIFT 7U /*!< Text encoding bit shift */ - - -/*! RTD Type URI Protocols */ -#define NDEF_URI_PREFIX_NONE 0x00U /*!< No URI Protocol */ -#define NDEF_URI_PREFIX_HTTP_WWW 0x01U /*!< URI Protocol http://www. */ -#define NDEF_URI_PREFIX_HTTPS_WWW 0x02U /*!< URI Protocol https://www. */ -#define NDEF_URI_PREFIX_HTTP 0x03U /*!< URI Protocol http:// */ -#define NDEF_URI_PREFIX_HTTPS 0x04U /*!< URI Protocol https:// */ -#define NDEF_URI_PREFIX_TEL 0x05U /*!< URI Protocol tel: */ -#define NDEF_URI_PREFIX_MAILTO 0x06U /*!< URI Protocol mailto: */ -#define NDEF_URI_PREFIX_FTP_ANONYMOUS 0x07U /*!< URI Protocol ftp://anonymous@ */ -#define NDEF_URI_PREFIX_FTP_FTP 0x08U /*!< URI Protocol ftp://ftp. */ -#define NDEF_URI_PREFIX_FTPS 0x09U /*!< URI Protocol ftps:// */ -#define NDEF_URI_PREFIX_SFTP 0x0AU /*!< URI Protocol sftp:// */ -#define NDEF_URI_PREFIX_SMB 0x0BU /*!< URI Protocol smb:// */ -#define NDEF_URI_PREFIX_NFS 0x0CU /*!< URI Protocol nfs:// */ -#define NDEF_URI_PREFIX_FTP 0x0DU /*!< URI Protocol ftp:// */ -#define NDEF_URI_PREFIX_DAV 0x0EU /*!< URI Protocol dav:// */ -#define NDEF_URI_PREFIX_NEWS 0x0FU /*!< URI Protocol news: */ -#define NDEF_URI_PREFIX_TELNET 0x10U /*!< URI Protocol telnet:// */ -#define NDEF_URI_PREFIX_IMAP 0x11U /*!< URI Protocol imap: */ -#define NDEF_URI_PREFIX_RTSP 0x12U /*!< URI Protocol rtsp:// */ -#define NDEF_URI_PREFIX_URN 0x13U /*!< URI Protocol urn: */ -#define NDEF_URI_PREFIX_POP 0x14U /*!< URI Protocol pop: */ -#define NDEF_URI_PREFIX_SIP 0x15U /*!< URI Protocol sip: */ -#define NDEF_URI_PREFIX_SIPS 0x16U /*!< URI Protocol sips: */ -#define NDEF_URI_PREFIX_TFTP 0x17U /*!< URI Protocol tftp: */ -#define NDEF_URI_PREFIX_BTSPP 0x18U /*!< URI Protocol btspp:// */ -#define NDEF_URI_PREFIX_BTL2CAP 0x19U /*!< URI Protocol btl2cap:// */ -#define NDEF_URI_PREFIX_BTGOEP 0x1AU /*!< URI Protocol btgoep:// */ -#define NDEF_URI_PREFIX_TCPOBEX 0x1BU /*!< URI Protocol tcpobex:// */ -#define NDEF_URI_PREFIX_IRDAOBEX 0x1CU /*!< URI Protocol irdaobex:// */ -#define NDEF_URI_PREFIX_FILE 0x1DU /*!< URI Protocol file:// */ -#define NDEF_URI_PREFIX_URN_EPC_ID 0x1EU /*!< URI Protocol urn:epc:id: */ -#define NDEF_URI_PREFIX_URN_EPC_TAG 0x1FU /*!< URI Protocol urn:epc:tag */ -#define NDEF_URI_PREFIX_URN_EPC_PAT 0x20U /*!< URI Protocol urn:epc:pat: */ -#define NDEF_URI_PREFIX_URN_EPC_RAW 0x21U /*!< URI Protocol urn:epc:raw: */ -#define NDEF_URI_PREFIX_URN_EPC 0x22U /*!< URI Protocol urn:epc: */ -#define NDEF_URI_PREFIX_URN_NFC 0x23U /*!< URI Protocol urn:nfc: */ -#define NDEF_URI_PREFIX_AUTODETECT 0x24U /*!< ST Protocol Autodetect */ -#define NDEF_URI_PREFIX_COUNT 0x25U /*!< Number of URI protocols */ - - -/*! vCard defines */ -#define NDEF_VCARD_ENTRY_MAX 16U /*!< vCard maximum entries */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/*! RTD Device Information types */ -#define NDEF_DEVICE_INFO_MANUFACTURER_NAME 0U /*!< Manufacturer name */ -#define NDEF_DEVICE_INFO_MODEL_NAME 1U /*!< Model name */ -#define NDEF_DEVICE_INFO_DEVICE_UNIQUE_NAME 2U /*!< Device Unique Name aka "Friendly Name" */ -#define NDEF_DEVICE_INFO_UUID 3U /*!< UUID */ -#define NDEF_DEVICE_INFO_FIRMWARE_VERSION 4U /*!< Firmware Version */ -#define NDEF_DEVICE_INFO_TYPE_COUNT 5U /*!< Maximum Device Information types */ - - -/*! RTD Device Information Entry */ -typedef struct -{ - uint8_t type; /*!< Device Information Type */ - uint8_t length; /*!< Device Information length */ - const uint8_t* buffer; /*!< Device Information pointer to buffer */ -} ndefDeviceInfoEntry; - - -/*! RTD Type Device Information */ -typedef struct -{ - ndefDeviceInfoEntry devInfo[NDEF_DEVICE_INFO_TYPE_COUNT]; /*!< Device Information entries */ -} ndefTypeRtdDeviceInfo; - - -/*! RTD Type Text */ -typedef struct -{ - uint8_t status; /*!< Status byte */ - ndefConstBuffer8 bufLanguageCode; /*!< ISO/IANA language code buffer */ - ndefConstBuffer bufSentence; /*!< Sentence buffer */ -} ndefTypeRtdText; - - -/*! RTD Type URI */ -typedef struct -{ - uint8_t protocol; /*!< Protocol Idendifier */ - ndefConstBuffer bufUriString; /*!< URI string buffer */ -} ndefTypeRtdUri; - - -/*! RTD Android Application Record External Type */ -typedef struct -{ - ndefConstBuffer8 bufType; /*!< AAR type */ - ndefConstBuffer bufPayload; /*!< AAR payload */ -} ndefTypeRtdAar; - - -/*! Media Type */ -typedef struct -{ - ndefConstBuffer8 bufType; /*!< Media type */ - ndefConstBuffer bufPayload; /*!< Media payload */ -} ndefTypeMedia; - - -/*! vCard input */ -typedef struct -{ - ndefConstBuffer* bufType; /*!< Type buffer */ - ndefConstBuffer* bufSubType; /*!< SubType buffer */ - ndefConstBuffer* bufValue; /*!< Value buffer */ -} ndefVCardInput; - - -/*! vCard Entry */ -typedef struct -{ - const uint8_t* bufTypeBuffer; /*!< Type buffer */ - const uint8_t* bufSubTypeBuffer; /*!< Subtype buffer */ - const uint8_t* bufValueBuffer; /*!< Value buffer */ - /* All lengths below fit in a word */ - uint8_t bufTypeLength; /*!< Type buffer length */ - uint8_t bufSubTypeLength; /*!< Subtype buffer length */ - uint16_t bufValueLength; /*!< Value buffer length */ -} ndefVCardEntry; - - -/*! NDEF Type vCard */ -typedef struct -{ - ndefVCardEntry entry[NDEF_VCARD_ENTRY_MAX]; /*!< vCard entries */ -} ndefTypeVCard; - - -/*****************************************************************************/ - -/*! NDEF Type Id enum */ -typedef enum -{ - NDEF_TYPE_EMPTY = 0, - NDEF_TYPE_RTD_DEVICE_INFO, - NDEF_TYPE_RTD_TEXT, - NDEF_TYPE_RTD_URI, - NDEF_TYPE_RTD_AAR, - NDEF_TYPE_MEDIA, - NDEF_TYPE_MEDIA_VCARD, - NDEF_TYPE_MEDIA_WIFI, - NDEF_TYPE_ID_COUNT /* Keep this one last */ -} ndefTypeId; - - -/*! NDEF abstraction Struct */ -struct ndefTypeStruct -{ - ndefTypeId id; /*!< Type Id */ - uint32_t (*getPayloadLength)(const ndefType* type); /*!< Return payload length, specific to each type */ - const uint8_t* (*getPayloadItem)(const ndefType* type, ndefConstBuffer* item, bool begin); /*!< Payload Encoder, specific to each type */ - union - { - ndefTypeRtdDeviceInfo deviceInfo; /*!< Device Information */ - ndefTypeRtdText text; /*!< Text */ - ndefTypeRtdUri uri; /*!< URI */ - ndefTypeRtdAar aar; /*!< AAR */ - ndefTypeMedia media; /*!< Media */ - ndefTypeVCard vCard; /*!< vCard */ - ndefTypeWifi wifi; /*!< Wifi */ - } data; /*!< Type data union */ -}; - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/*! - ***************************************************************************** - * Return an NDEF record type Id - * - * \param[in] record: Record to get the type from - * \param[out] typeId: The record RTD type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordTypeStringToTypeId(const ndefRecord* record, ndefTypeId* typeId); - - -/*! - ***************************************************************************** - * Convert a record to a supported type - * - * \param[in] record: Record to read - * \param[out] type: Type to store the converted record - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToType(const ndefRecord* record, ndefType* type); - - -/*! - ***************************************************************************** - * Convert a supported type to a record - * - * \param[in] type: Pointer to the type to read data from - * \param[out] record: Record to fill - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefTypeToRecord(const ndefType* type, ndefRecord* record); - - -/*! - ***************************************************************************** - * Set the NDEF specific structure to process NDEF types - * - * \param[in] record: Record - * \param[out] type: NDEF type structure - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordSetNdefType(ndefRecord* record, const ndefType* type); - - -/*! - ***************************************************************************** - * Get the NDEF type structure of this record - * - * \param[in] record: Record - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -const ndefType* ndefRecordGetNdefType(const ndefRecord* record); - - -#endif /* NDEF_TYPES_H */ - -/** - * @} - * - */ diff --git a/Software/Middlewares/ST/ndef/Inc/message/ndef_types_mime.h b/Software/Middlewares/ST/ndef/Inc/message/ndef_types_mime.h deleted file mode 100644 index 6f84592..0000000 --- a/Software/Middlewares/ST/ndef/Inc/message/ndef_types_mime.h +++ /dev/null @@ -1,203 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF MIME types header file - * - * NDEF MIME type provides functionalities to handle MIME records, such as vCard or generic media. - * - * \addtogroup NDEF - * @{ - * - */ - -#ifndef NDEF_TYPES_MIME_H -#define NDEF_TYPES_MIME_H - - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "ndef_types.h" -#include "ndef_record.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/*! Media Record Type buffers */ -extern const ndefConstBuffer8 bufMediaTypeVCard; /*! vCard Record Type buffer */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/*************** - * Media - *************** - */ - -/*! - ***************************************************************************** - * Initialize a Media type - * - * \param[out] media: Media type to initialize - * \param[in] bufType: Type buffer - * \param[in] bufPayload: Payload buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMedia(ndefType* media, const ndefConstBuffer8* bufType, const ndefConstBuffer* bufPayload); - - -/*! - ***************************************************************************** - * Get Media type content - * - * \param[in] media: Media type to get information from - * \param[out] bufType: Type buffer - * \param[out] bufPayload: Payload buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefGetMedia(const ndefType* media, ndefConstBuffer8* bufType, ndefConstBuffer* bufPayload); - - -/*! - ***************************************************************************** - * Convert an NDEF record to a Media type - * - * \param[in] record: Record to convert - * \param[out] media: The converted Media type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToMedia(const ndefRecord* record, ndefType* media); - - -/*! - ***************************************************************************** - * Convert a Media type to an NDEF record - * - * \param[in] media: Type to convert - * \param[out] record: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefMediaToRecord(const ndefType* media, ndefRecord* record); - - -/*************** - * vCard - *************** - */ - -/*! - ***************************************************************************** - * Initialize a vCard - * - * \param[out] vCard: vCard type to initialize - * \param[in] bufVCardInput: vCard buffer content - * \param[in] bufVCardInputCount: Number of vCard entries - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefVCard(ndefType* vCard, const ndefVCardInput* bufVCardInput, uint32_t bufVCardInputCount); - - -/*! - ***************************************************************************** - * Get vCard content - * - * \param[in] vCard: vCard type to get information from - * \param[out] bufType: Type buffer to extract - * \param[out] bufSubType: SubType buffer extracted. Can be NULL is not required - * \param[out] bufValue: Value buffer extracted - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefGetVCard(const ndefType* vCard, const ndefConstBuffer* bufType, ndefConstBuffer* bufSubType, ndefConstBuffer* bufValue); - - -/*! - ***************************************************************************** - * Convert an NDEF record to a vCard - * - * \param[in] record: Record to convert - * \param[out] vCard: The converted vCard type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToVCard(const ndefRecord* record, ndefType* vCard); - - -/*! - ***************************************************************************** - * Convert a vCard type to an NDEF record - * - * \param[in] vCard: vCard type to convert - * \param[out] record: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefVCardToRecord(const ndefType* vCard, ndefRecord* record); - - -#endif /* NDEF_TYPES_MIME_H */ - -/** - * @} - * - */ diff --git a/Software/Middlewares/ST/ndef/Inc/message/ndef_types_rtd.h b/Software/Middlewares/ST/ndef/Inc/message/ndef_types_rtd.h deleted file mode 100644 index 7d65a75..0000000 --- a/Software/Middlewares/ST/ndef/Inc/message/ndef_types_rtd.h +++ /dev/null @@ -1,366 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF RTD (well-known and external) types header file - * - * NDEF RTD provides functionalities to handle RTD records, such as Text or URI. - * - * \addtogroup NDEF - * @{ - * - */ - -#ifndef NDEF_TYPES_RTD_H -#define NDEF_TYPES_RTD_H - - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "ndef_types.h" -#include "ndef_record.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/*! RTD Record Type buffers */ -extern const ndefConstBuffer8 bufRtdTypeDeviceInfo; /*! Device Information Record Type buffer */ -extern const ndefConstBuffer8 bufRtdTypeText; /*! Text Record Type buffer */ -extern const ndefConstBuffer8 bufRtdTypeUri; /*! URI Record Type buffer */ -extern const ndefConstBuffer8 bufRtdTypeAar; /*! AAR (Android Application Record) Record Type buffer */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/*************** - * Empty type - *************** - */ - -/*! - ***************************************************************************** - * Initialize an Empty type - * - * \param[out] empty: Type to initialize - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefEmptyType(ndefType* empty); - - -/*! - ***************************************************************************** - * Convert an NDEF record to an Empty type - * - * \param[in] record: Record to convert - * \param[out] empty: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToEmptyType(const ndefRecord* record, ndefType* empty); - - -/*! - ***************************************************************************** - * Convert an Empty type to an NDEF record - * - * \param[in] empty: Type to convert - * \param[out] record: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefEmptyTypeToRecord(const ndefType* empty, ndefRecord* record); - - -/********************* - * Device Information - ********************* - */ - -/*! - ***************************************************************************** - * Initialize a RTD Device Information type - * - * \param[out] devInfo: Type to initialize - * \param[in] devInfoData: Device Information data - * \param[in] devInfoDataCount: Number of Device Information data - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdDeviceInfo(ndefType* devInfo, const ndefDeviceInfoEntry* devInfoData, uint8_t devInfoDataCount); - - -/*! - ***************************************************************************** - * Get RTD Device Information type content - * - * \param[in] devInfo: Type to get information from - * \param[out] devInfoData: Device Information data - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefGetRtdDeviceInfo(const ndefType* devInfo, ndefTypeRtdDeviceInfo* devInfoData); - - -/*! - ***************************************************************************** - * Convert an NDEF record to a Device Information RTD type - * - * \param[in] record: Record to convert - * \param[out] devInfo: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToRtdDeviceInfo(const ndefRecord* record, ndefType* devInfo); - - -/*! - ***************************************************************************** - * Convert a Device Information RTD type to an NDEF record - * - * \param[in] devInfo: Type to convert - * \param[out] record: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdDeviceInfoToRecord(const ndefType* devInfo, ndefRecord* record); - - -/*************** - * Text - *************** - */ - - -/*! - ***************************************************************************** - * Initialize a Text RTD type - * - * \param[out] text: Type to initialize - * \param[out] utfEncoding: UTF-8/UTF-16 - * \param[in] bufLanguageCode: ISO/IANA language code buffer - * \param[in] bufSentence: Actual text buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdText(ndefType* text, uint8_t utfEncoding, const ndefConstBuffer8* bufLanguageCode, const ndefConstBuffer* bufSentence); - - -/*! - ***************************************************************************** - * Get RTD Text type content - * - * \param[in] text: Type to get information from - * \param[out] utfEncoding: UTF-8/UTF-16 - * \param[out] bufLanguageCode: ISO/IANA language code buffer - * \param[out] bufSentence: Actual text buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefGetRtdText(const ndefType* text, uint8_t* utfEncoding, ndefConstBuffer8* bufLanguageCode, ndefConstBuffer* bufSentence); - - -/*! - ***************************************************************************** - * Convert an NDEF record to a Text type - * - * \param[in] record: Record to convert - * \param[out] text: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToRtdText(const ndefRecord* record, ndefType* text); - - -/*! - ***************************************************************************** - * Convert a Text RTD type to an NDEF record - * - * \param[in] text: Type to convert - * \param[out] record: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdTextToRecord(const ndefType* text, ndefRecord* record); - - -/*************** - * URI - *************** - */ - -/*! - ***************************************************************************** - * Initialize a URI RTD type - * - * \param[out] uri: Type to initialize - * \param[in] protocol: URI protocol - * \param[in] bufUriString: URI string buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdUri(ndefType* uri, uint8_t protocol, const ndefConstBuffer* bufUriString); - - -/*! - ***************************************************************************** - * Get URI RTD type content - * - * \param[in] uri: Type to get information from - * \param[out] bufProtocol: URI protocol buffer - * \param[out] bufUriString: URI string buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefGetRtdUri(const ndefType* uri, ndefConstBuffer* bufProtocol, ndefConstBuffer* bufUriString); - - -/*! - ***************************************************************************** - * Convert an NDEF record to a URI RTD type - * - * \param[in] record: Record to convert - * \param[out] uri: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToRtdUri(const ndefRecord* record, ndefType* uri); - - -/*! - ***************************************************************************** - * Convert a URI RTD type to an NDEF record - * - * \param[in] uri: Type to convert - * \param[out] record: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdUriToRecord(const ndefType* uri, ndefRecord* record); - - -/******************* - * AAR External Type - ******************* - */ - -/*! - ***************************************************************************** - * Initialize an RTD Android Application Record External type - * - * \param[out] aar: Type to initialize - * \param[in] bufPayload: Payload buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdAar(ndefType* aar, const ndefConstBuffer* bufPayload); - - -/*! - ***************************************************************************** - * Get RTD Android Application Record type content - * - * \param[in] aar: Type to get information from - * \param[out] bufAarString: AAR string buffer - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefGetRtdAar(const ndefType* aar, ndefConstBuffer* bufAarString); - - -/*! - ***************************************************************************** - * Convert an NDEF record to an RTD Android Application Record External type - * - * \param[in] record: Record to convert - * \param[out] aar: The converted AAR external type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRecordToRtdAar(const ndefRecord* record, ndefType* aar); - - -/*! - ***************************************************************************** - * Convert an RTD Android Application Record External type to an NDEF record - * - * \param[in] aar: AAR External type to convert - * \param[out] record: The converted type - * - * \return ERR_NONE if successful or a standard error code - ***************************************************************************** - */ -ReturnCode ndefRtdAarToRecord(const ndefType* aar, ndefRecord* record); - - -#endif /* NDEF_TYPES_RTD_H */ - -/** - * @} - * - */ diff --git a/Software/Middlewares/ST/ndef/Inc/poller/ndef_poller.h b/Software/Middlewares/ST/ndef/Inc/poller/ndef_poller.h deleted file mode 100644 index 1b92374..0000000 --- a/Software/Middlewares/ST/ndef/Inc/poller/ndef_poller.h +++ /dev/null @@ -1,594 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum Tags - * - * NDEF provides several functionalities required to perform NFC NDEF activities. - *
The NDEF encapsulates the different tag technologies (T2T, T3T, T4AT, T4BT, T5T) - * into a common and easy to use interface. - * - * It provides interfaces to Detect, Read, Write and Format NDEF. - * - * The most common interfaces are: - *
  ndefPollerContextInitialization() - *
  ndefPollerNdefDetect() - *
  ndefPollerReadRawMessage() - *
  ndefPollerWriteRawMessage() - *
  ndefPollerTagFormat() - *
  ndefPollerWriteMessage() - * - * - * An NDEF read usage example is provided here: \ref ndef_example_read.c - * \example ndef_example_read.c - * - * An NDEF write usage example is provided here: \ref ndef_example_write.c - * \example ndef_example_write.c - * - * \addtogroup NDEF - * @{ - * - */ - - -#ifndef NDEF_POLLER_H -#define NDEF_POLLER_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_nfca.h" -#include "rfal_nfcb.h" -#include "rfal_nfcf.h" -#include "rfal_nfcv.h" -#include "rfal_nfc.h" -#include "rfal_isoDep.h" -#include "rfal_t4t.h" -#include "ndef_record.h" -#include "ndef_message.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define NDEF_CC_BUF_LEN 17U /*!< CC buffer len. Max len = 17 in case of T4T v3 */ -#define NDEF_NFCV_SUPPORTED_CMD_LEN 4U /*!< Ext sys info supported commands list len */ - -#define NDEF_SHORT_VFIELD_MAX_LEN 254U /*!< Max V-field length for 1-byte Lengh encoding */ -#define NDEF_TERMINATOR_TLV_LEN 1U /*!< Terminator TLV size */ -#define NDEF_TERMINATOR_TLV_T 0xFEU /*!< Terminator TLV T=FEh */ - -#define NDEF_T2T_READ_RESP_SIZE 16U /*!< Size of the READ response i.e. four blocks */ - -#define NDEF_T3T_BLOCK_SIZE 16U /*!< size for a block in t3t */ -#define NDEF_T3T_MAX_NB_BLOCKS 4U /*!< size for a block in t3t */ -#define NDEF_T3T_MAX_RX_SIZE ((NDEF_T3T_BLOCK_SIZE*NDEF_T3T_MAX_NB_BLOCKS) + 16U) /*!< size for receive 4 blocks of 16 + UID + HEADER + CHECKSUM */ -#define NDEF_T3T_MAX_TX_SIZE ((NDEF_T3T_BLOCK_SIZE*NDEF_T3T_MAX_NB_BLOCKS) + 16U) /*!< size for send Check 4 blocks of 16 + UID + HEADER + CHECKSUM */ - -#define NDEF_T5T_TxRx_BUFF_HEADER_SIZE 1U /*!< Request Flags/Responses Flags size */ -#define NDEF_T5T_TxRx_BUFF_FOOTER_SIZE 2U /*!< CRC size */ - -#define NDEF_T5T_TxRx_BUFF_SIZE \ - (32U + NDEF_T5T_TxRx_BUFF_HEADER_SIZE + NDEF_T5T_TxRx_BUFF_FOOTER_SIZE) /*!< T5T working buffer size */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define ndefBytes2Uint16(hiB, loB) ((uint16_t)((((uint32_t)(hiB)) << 8U) | ((uint32_t)(loB)))) /*!< convert 2 bytes to a u16 */ - -#define ndefMajorVersion(V) ((uint8_t)((V) >> 4U)) /*!< Get major version */ -#define ndefMinorVersion(V) ((uint8_t)((V) & 0xFU)) /*!< Get minor version */ - -/* - ****************************************************************************** - * NDEF FEATURES CONFIGURATION - ****************************************************************************** - */ - -#define NDEF_FEATURE_ALL true /*!< Enable/Disable NDEF support for full features (write NDEF, format, ...) */ - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/*! NDEF device type */ -typedef enum { - NDEF_DEV_NONE = 0x00U, /*!< Device type undef */ - NDEF_DEV_T1T = 0x01U, /*!< Device type T1T */ - NDEF_DEV_T2T = 0x02U, /*!< Device type T2T */ - NDEF_DEV_T3T = 0x03U, /*!< Device type T3T */ - NDEF_DEV_T4T = 0x04U, /*!< Device type T4AT */ - NDEF_DEV_T5T = 0x05U, /*!< Device type T5T */ -} ndefDeviceType; - -/*! NDEF states */ -typedef enum { - NDEF_STATE_INVALID = 0x00U, /*!< Invalid state (e.g. no CC) */ - NDEF_STATE_INITIALIZED = 0x01U, /*!< State Initialized (no NDEF message) */ - NDEF_STATE_READWRITE = 0x02U, /*!< Valid NDEF found. Read/Write capability */ - NDEF_STATE_READONLY = 0x03U, /*!< Valid NDEF found. Read only */ -} ndefState; - -/*! NDEF Information */ -typedef struct { - uint8_t majorVersion; /*!< Major version */ - uint8_t minorVersion; /*!< Minor version */ - uint32_t areaLen; /*!< Area Len for NDEF storage */ - uint32_t areaAvalableSpaceLen; /*!< Remaining Space in case a propTLV is present */ - uint32_t messageLen; /*!< NDEF message Len */ - ndefState state; /*!< Tag state e.g. NDEF_STATE_INITIALIZED */ -} ndefInfo; - -/*! NFCV (Extended) System Information */ -typedef struct { - uint16_t numberOfBlock; /*!< Number of block */ - uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< UID Value */ - uint8_t supportedCmd[NDEF_NFCV_SUPPORTED_CMD_LEN];/*!< Supported Commands list */ - uint8_t infoFlags; /*!< Information flags */ - uint8_t DFSID; /*!< DFSID Value */ - uint8_t AFI; /*!< AFI Value */ - uint8_t blockSize; /*!< Block Size Value */ - uint8_t ICRef; /*!< IC Reference */ -} ndefSystemInformation; - -/*! T1T Capability Container */ -typedef struct { - uint8_t magicNumber; /*!< Magic number e.g. E1h */ - uint8_t majorVersion; /*!< Major version i.e 1 */ - uint8_t minorVersion; /*!< Minor version i.e 2 */ - uint16_t tagMemorySize; /*!< Tag Memory Size (TMS) */ - uint8_t readAccess; /*!< NDEF READ access condition */ - uint8_t writeAccess; /*!< NDEF WRITE access condition */ -} ndefCapabilityContainerT1T; - -/*! T2T Capability Container */ -typedef struct { - uint8_t magicNumber; /*!< Magic number e.g. E1h */ - uint8_t majorVersion; /*!< Major version i.e 1 */ - uint8_t minorVersion; /*!< Minor version i.e 2 */ - uint8_t size; /*!< Size. T2T_Area_Size = Size * 8 */ - uint8_t readAccess; /*!< NDEF READ access condition */ - uint8_t writeAccess; /*!< NDEF WRITE access condition */ -} ndefCapabilityContainerT2T; - -/*! T3T Attribute info block */ -typedef struct { - uint8_t majorVersion; /*!< Major version i.e 1 */ - uint8_t minorVersion; /*!< Minor version i.e 2 */ - uint8_t nbR; /*!< Nbr: number of blocks read in one CHECK cmd */ - uint8_t nbW; /*!< Nbr: number of blocks written in one UPDATE cmd */ - uint16_t nMaxB; /*!< NmaxB: max number of blocks for NDEF data */ - uint8_t writeFlag; /*!< WriteFlag indicates completion of previous NDEF */ - uint8_t rwFlag; /*!< RWFlag indicates whether the NDEF can be updated */ - uint32_t Ln; /*!< Ln size of the actual stored NDEF data in bytes */ -} ndefAttribInfoBlockT3T; - -/*! T4T Capability Container */ -typedef struct { - uint16_t ccLen; /*!< CCFILE Len */ - uint8_t vNo; /*!< Mapping version */ - uint16_t mLe; /*!< Max data size that can be read using a ReadBinary */ - uint16_t mLc; /*!< Max data size that can be sent using a single cmd */ - uint8_t fileId[2]; /*!< NDEF File Identifier */ - uint32_t fileSize; /*!< NDEF File Size */ - uint8_t readAccess; /*!< NDEF File READ access condition */ - uint8_t writeAccess; /*!< NDEF File WRITE access condition */ -} ndefCapabilityContainerT4T; - -/*! T5T Capability Container */ -typedef struct { - uint8_t ccLen; /*!< CC Len */ - uint8_t magicNumber; /*!< Magic number i.e. E1h or E2h */ - uint8_t majorVersion; /*!< Major version i.e 1 */ - uint8_t minorVersion; /*!< Minor version i.e 0 */ - uint8_t readAccess; /*!< NDEF READ access condition */ - uint8_t writeAccess; /*!< NDEF WRITE access condition */ - bool specialFrame; /*!< Use Special Frames for Write-alike commands */ - bool lockBlock; /*!< (EXTENDED_)LOCK_SINGLE_BLOCK supported */ - bool multipleBlockRead; /*!< (EXTENDED_)READ_MULTIPLE_BLOCK supported */ - bool mlenOverflow; /*!< memory size exceeds 2040 bytes (Android) */ - uint16_t memoryLen; /*!< MLEN (Memory Len). T5T_Area size = 8 * MLEN (bytes)*/ -} ndefCapabilityContainerT5T; - -/*! Generic Capability Container */ -typedef union { - ndefCapabilityContainerT1T t1t; /*!< T1T Capability Container */ - ndefCapabilityContainerT2T t2t; /*!< T2T Capability Container */ - ndefAttribInfoBlockT3T t3t; /*!< T3T Attribute Information Block */ - ndefCapabilityContainerT4T t4t; /*!< T4T Capability Container */ - ndefCapabilityContainerT5T t5t; /*!< T5T Capability Container */ -} ndefCapabilityContainer; - -/*! NDEF T1T sub context structure */ -typedef struct { - void * rfu; /*!< RFU */ -} ndefT1TContext; - -/*! NDEF T2T sub context structure */ -typedef struct { - uint8_t currentSecNo; /*!< Current sector number */ - uint8_t cacheBuf[NDEF_T2T_READ_RESP_SIZE]; /*!< Cache buffer */ - uint32_t cacheAddr; /*!< Address of cached data */ - uint32_t offsetNdefTLV; /*!< NDEF TLV message offset */ -} ndefT2TContext; - -/*! NDEF T3T sub context structure */ -typedef struct { - uint8_t txbuf[NDEF_T3T_MAX_TX_SIZE]; /*!< Tx buffer dedicated for T3T internal operations */ - uint8_t rxbuf[NDEF_T3T_MAX_RX_SIZE]; /*!< Rx buffer dedicated for T3T internal operations */ - rfalNfcfBlockListElem listBlocks[NDEF_T3T_MAX_NB_BLOCKS]; /*!< block number list for T3T internal operations */ -} ndefT3TContext; - -/*! NDEF T4T sub context structure */ -typedef struct { - uint8_t curMLe; /*!< Current MLe. Default Fh until CC file is read */ - uint8_t curMLc; /*!< Current MLc. Default Dh until CC file is read */ - bool mv1Flag; /*!< Mapping version 1 flag */ - rfalIsoDepApduBufFormat cApduBuf; /*!< Command-APDU buffer */ - rfalIsoDepApduBufFormat rApduBuf; /*!< Response-APDU buffer */ - rfalT4tRApduParam respAPDU; /*!< Response-APDU params */ - rfalIsoDepBufFormat tmpBuf; /*!< I-Block temporary buffer */ - uint16_t rApduBodyLen; /*!< Response Body Len */ -} ndefT4TContext; - -/*! NDEF T5T sub context structure */ -typedef struct { - uint8_t * pAddressedUid; /*!< Pointer to UID in Addr mode or NULL selected one */ - uint32_t TlvNDEFOffset; /*!< NDEF TLV message offset */ - uint8_t blockLen; /*!< T5T BLEN parameter */ - ndefSystemInformation sysInfo; /*!< System Information (when supported) */ - bool sysInfoSupported; /*!< System Information Supported flag */ - bool legacySTHighDensity; /*!< Legacy ST High Density flag */ - uint8_t txrxBuf[NDEF_T5T_TxRx_BUFF_SIZE]; /*!< Tx Rx Buffer */ -} ndefT5TContext; - -/*! NDEF context structure */ -typedef struct { - rfalNfcDevice device; /*!< ndef Device */ - ndefState state; /*!< Tag state e.g. NDEF_STATE_INITIALIZED */ - ndefCapabilityContainer cc; /*!< Capability Container */ - uint32_t messageLen; /*!< NDEF message len */ - uint32_t messageOffset; /*!< NDEF message offset */ - uint32_t areaLen; /*!< Area Len for NDEF storage */ - uint8_t ccBuf[NDEF_CC_BUF_LEN]; /*!< buffer for CC */ - const struct ndefPollerWrapperStruct* - ndefPollWrapper; /*!< pointer to array of function for wrapper */ - union { - ndefT1TContext t1t; /*!< T1T context */ - ndefT2TContext t2t; /*!< T2T context */ - ndefT3TContext t3t; /*!< T3T context */ -#if RFAL_FEATURE_T4T - ndefT4TContext t4t; /*!< T4T context */ -#endif - ndefT5TContext t5t; /*!< T5T context */ - } subCtx; /*!< Sub-context union */ - -} ndefContext; - -/*! Wrapper struture to hold the function pointers on each tag type */ -typedef struct ndefPollerWrapperStruct -{ - ReturnCode (* pollerContextInitialization)(ndefContext *ctx, const rfalNfcDevice *dev); /*!< ContextInitialization function pointer */ - ReturnCode (* pollerNdefDetect)(ndefContext *ctx, ndefInfo *info); /*!< NdefDetect function pointer */ - ReturnCode (* pollerReadBytes)(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen); /*!< Read function pointer */ - ReturnCode (* pollerReadRawMessage)(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen); /*!< ReadRawMessage function pointer */ -#if NDEF_FEATURE_ALL - ReturnCode (* pollerWriteBytes)(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len); /*!< Write function pointer */ - ReturnCode (* pollerWriteRawMessage)(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen); /*!< WriteRawMessage function pointer */ - ReturnCode (* pollerTagFormat)(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options); /*!< TagFormat function pointer */ - ReturnCode (* pollerWriteRawMessageLen)(ndefContext *ctx, uint32_t rawMessageLen); /*!< WriteRawMessageLen function pointer */ - ReturnCode (* pollerCheckPresence)(ndefContext *ctx); /*!< CheckPresence function pointer */ - ReturnCode (* pollerCheckAvailableSpace)(const ndefContext *ctx, uint32_t messageLen); /*!< CheckAvailableSpace function pointer */ - ReturnCode (* pollerBeginWriteMessage)(ndefContext *ctx, uint32_t messageLen); /*!< BeginWriteMessage function pointer */ - ReturnCode (* pollerEndWriteMessage)(ndefContext *ctx, uint32_t messageLen); /*!< EndWriteMessage function pointer */ -#endif /* NDEF_FEATURE_ALL */ -} ndefPollerWrapper; - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -/*! - ***************************************************************************** - * \brief Handle NDEF context activation - * - * This method performs the initialization of the NDEF context. - * It must be called after a successful - * anti-collision procedure and prior to any NDEF procedures such as NDEF - * detection procedure. - * - * \param[in] ctx : ndef Context - * \param[in] dev : ndef Device - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev); - - -/*! - ***************************************************************************** - * \brief NDEF Detection procedure - * - * This method performs the NDEF Detection procedure - * - * \param[in] ctx : ndef Context - * \param[out] info : ndef Information (optional parameter, NULL may be used when no NDEF Information is needed) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : Detection failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerNdefDetect(ndefContext *ctx, ndefInfo *info); - - -/*! - ***************************************************************************** - * \brief Read data - * - * This method reads arbitrary length data - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to start reading data - * \param[in] len : requested len - * \param[out] buf : buffer to place the data read from the tag - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerReadBytes(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen); - - -/*! - ***************************************************************************** - * \brief Write data - * - * This method writes arbitrary length data from the current selected file - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to start writing data - * \param[in] buf : data to write - * \param[in] len : buf len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len); - - -/*! - ***************************************************************************** - * \brief Read raw NDEF message - * - * This method reads a raw NDEF message. - * Prior to NDEF Read procedure, a successful ndefPollerNdefDetect() - * has to be performed. - * - * - * \param[in] ctx : ndef Context - * \param[out] buf : buffer to place the NDEF message - * \param[in] bufLen : buffer length - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen); - - -/*! - ***************************************************************************** - * \brief Write raw NDEF message - * - * This method writes a raw NDEF message. - * Prior to NDEF Write procedure, a successful ndefPollerNdefDetect() - * has to be performed. - * - * \param[in] ctx : ndef Context - * \param[in] buf : raw message buffer - * \param[in] bufLen : buffer length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen); - - -/*! - ***************************************************************************** - * \brief Format Tag - * - * This method format a tag to make it ready for NDEF storage. - * cc and options parameters usage is described in each technology method - * (ndefT[2345]TPollerTagFormat) - * - * \param[in] ctx : ndef Context - * \param[in] cc : Capability Container - * \param[in] options : specific flags - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options); - - -/*! - ***************************************************************************** - * \brief Write NDEF message length - * - * This method writes the NLEN field - * - * \param[in] ctx : ndef Context - * \param[in] rawMessageLen: len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen); - - - /*! - ***************************************************************************** - * \brief Write an NDEF message - * - * Write the NDEF message to the tag - * - * \param[in] ctx: NDEF Context - * \param[in] message: Message to write - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerWriteMessage(ndefContext *ctx, const ndefMessage* message); - - -/*! - ***************************************************************************** - * \brief Check Presence - * - * This method check whether an NFC tag is still present in the operating field - * - * \param[in] ctx : ndef Context - - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefPollerCheckPresence(ndefContext *ctx); - - -/*! - ***************************************************************************** - * \brief Check Available Space - * - * This method check whether a NFC tag has enough space to write a message of a given length - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief Begin Write Message - * - * This method sets the L-field to 0 (T1T, T2T, T4T, T5T) or set the WriteFlag (T3T) and sets the message offset to the proper value according to messageLen - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief End Write Message - * - * This method updates the L-field value after the message has been written and resets the WriteFlag (for T3T only) - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -#endif /* NDEF_POLLER_H */ - -/** - * @} - * - */ diff --git a/Software/Middlewares/ST/ndef/Inc/poller/ndef_t2t.h b/Software/Middlewares/ST/ndef/Inc/poller/ndef_t2t.h deleted file mode 100644 index c6cf2b1..0000000 --- a/Software/Middlewares/ST/ndef/Inc/poller/ndef_t2t.h +++ /dev/null @@ -1,340 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum T2T - * - * NDEF T2T provides several functionalities required to - * perform NDEF message management with T2T tags. - * - * The most common interfaces are - *
  ndefT2TPollerContextInitialization() - *
  ndefT2TPollerNdefDetect() - *
  ndefT2TPollerReadRawMessage() - *
  ndefT2TPollerWriteRawMessage() - *
  ndefT2TPollerTagFormat() - * - * - * \addtogroup NDEF - * @{ - * - */ - - -#ifndef NDEF_T2T_H -#define NDEF_T2T_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_nfca.h" -#include "rfal_t2t.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - - /* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -/*! - ***************************************************************************** - * \brief Handle T2T NDEF context activation - * - * This method performs the initialization of the NDEF context and handles - * the activation of the ISO-DEP layer. It must be called after a successful - * anti-collision procedure and prior to any NDEF procedures such as NDEF - * detection procedure. - * - * \param[in] ctx : ndef Context - * \param[in] dev : ndef Device - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev); - - -/*! - ***************************************************************************** - * \brief T2T NDEF Detection procedure - * - * This method performs the T2T NDEF Detection procedure - * - * - * \param[in] ctx : ndef Context - * \param[out] info : ndef Information (optional parameter, NULL may be used when no NDEF Information is needed) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : Detection failed (application or ccfile not found) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerNdefDetect(ndefContext *ctx, ndefInfo *info); - - -/*! - ***************************************************************************** - * \brief T2T Read data from tag memory - * - * This method reads arbitrary length data from the current selected file - * - * \param[in] ctx : ndef Context - * \param[in] len : requested len - * \param[in] offset : file offset of where to start reading data - * \param[out] buf : buffer to place the data read from the tag - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerReadBytes(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen); - - -/*! - ***************************************************************************** - * \brief T2T write data to tag memory - * - * This method reads arbitrary length data from the current selected file - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to start writing data - * \param[in] buf : data to write - * \param[in] len : buf len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len); - - -/*! - ***************************************************************************** - * \brief T2T Read raw NDEF message - * - * This method reads a raw NDEF message from the current selected file. - * Prior to NDEF Read procedure, a successful ndefT2TPollerNdefDetect() - * has to be performed. - * - * \param[in] ctx : ndef Context - * \param[out] buf : buffer to place the NDEF message - * \param[in] bufLen : buffer length - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen); - - -/*! - ***************************************************************************** - * \brief T2T Write raw NDEF message - * - * This method writes a raw NDEF message in the current selected file. - * Prior to NDEF Write procedure, a successful ndefT2TPollerNdefDetect() - * has to be performed. - * - * \warning Current selected file must not be changed between NDEF Detect - * procedure and NDEF Write procedure. If another file is selected before - * NDEF Write procedure, it is user responsibility to re-select NDEF file - * or to call ndefT2TPollerNdefDetect() to restore proper context. - * - * \param[in] ctx : ndef Context - * \param[in] buf : raw message buffer - * \param[in] bufLen : buffer length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen); - - -/*! - ***************************************************************************** - * \brief T2T Write NDEF message length - * - * This method writes the NLEN field (V2 mapping) or the ENLEN (V3 mapping). - * - * \param[in] ctx : ndef Context - * \param[in] rawMessageLen: len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen); - - -/*! - ***************************************************************************** - * \brief T2T Format Tag - * - * This method formats a tag to make it ready for NDEF storage. - * The Capability Container block is written only for virgin tags. - * If the cc parameter is not provided (i.e. NULL), a default one is used - * with T2T_AreaSize = 48 bytes. - * Beware that formatting is on most tags a one time operation (OTP bits!!!!) - * Doing a wrong format may render your tag unusable. - * options parameter is not used for T2T Tag Format method - * - * \param[in] ctx : ndef Context - * \param[in] cc : Capability Container - * \param[in] options: specific flags - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options); - - -/*! - ***************************************************************************** - * \brief T2T Check Presence - * - * This method checks whether a T2T tag is still present in the operating field - * - * \param[in] ctx : ndef Context - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT2TPollerCheckPresence(ndefContext *ctx); - - -/*! - ***************************************************************************** - * \brief T2T Check Available Space - * - * This method checks whether a T2T tag has enough space to write a message of a given length - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT2TPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief T2T Begin Write Message - * - * This method sets the L-field to 0 and sets the message offset to the proper value according to messageLen - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT2TPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief T2T End Write Message - * - * This method updates the L-field value after the message has been written - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT2TPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -#endif /* NDEF_T2T_H */ - -/** - * @} - */ diff --git a/Software/Middlewares/ST/ndef/Inc/poller/ndef_t3t.h b/Software/Middlewares/ST/ndef/Inc/poller/ndef_t3t.h deleted file mode 100644 index 0735413..0000000 --- a/Software/Middlewares/ST/ndef/Inc/poller/ndef_t3t.h +++ /dev/null @@ -1,339 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum T3T - * - * NDEF T3T provides several functionalities required to - * perform NDEF message management with T3T tags. - * - * The most common interfaces are - *
  ndefT3TPollerContextInitialization() - *
  ndefT3TPollerNdefDetect() - *
  ndefT3TPollerReadRawMessage() - *
  ndefT3TPollerWriteRawMessage() - *
  ndefT3TPollerTagFormat() - * - * - * \addtogroup NDEF - * @{ - * - */ - - -#ifndef NDEF_T3T_H -#define NDEF_T3T_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_nfcv.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - - /* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -/*! - ***************************************************************************** - * \brief Handle T3T NDEF context activation - * - * This method performs the initialization of the NDEF context and handles - * the activation of the ISO-DEP layer. It must be called after a successful - * anti-collision procedure and prior to any NDEF procedures such as NDEF - * detection procedure. - * - * \param[in] ctx : ndef Context - * \param[in] dev : ndef Device - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev); - - -/*! - ***************************************************************************** - * \brief T3T NDEF Detection procedure - * - * This method performs the T3T NDEF Detection procedure - * - * - * \param[in] ctx : ndef Context - * \param[out] info : ndef Information (optional parameter, NULL may be used when no NDEF Information is needed) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : Detection failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerNdefDetect(ndefContext *ctx, ndefInfo *info); - - -/*! - ***************************************************************************** - * \brief T3T Read data from file - * - * This method reads arbitrary length data from the current selected file - * - * \param[in] ctx : ndef Context - * \param[in] len : requested len - * \param[in] offset : file offset of where to start reading data - * \param[out] buf : buffer to place the data read from the tag - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerReadBytes(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen); - - -/*! - ***************************************************************************** - * \brief T3T write data to file - * - * This method reads arbitrary length data from the current selected file - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to start writing data - * \param[in] buf : data to write - * \param[in] len : buf len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len); - - -/*! - ***************************************************************************** - * \brief T3T Read raw NDEF message - * - * This method reads a raw NDEF message from the current selected file. - * Prior to NDEF Read procedure, a successful ndefT3TPollerNdefDetect() - * has to be performed. - * - * \param[in] ctx : ndef Context - * \param[out] buf : buffer to place the NDEF message - * \param[in] bufLen : buffer length - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen); - - -/*! - ***************************************************************************** - * \brief T3T Write raw NDEF message - * - * This method writes a raw NDEF message in the current selected file. - * Prior to NDEF Write procedure, a successful ndefT3TPollerNdefDetect() - * has to be performed. - * - * \warning Current selected file must not be changed between NDEF Detect - * procedure and NDEF Write procedure. If another file is selected before - * NDEF Write procedure, it is user responsibility to re-select NDEF file - * or to call ndefT3TPollerNdefDetect() to restore proper context. - * - * \param[in] ctx : ndef Context - * \param[in] buf : raw message buffer - * \param[in] bufLen : buffer length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen); - - -/*! - ***************************************************************************** - * \brief T3T Write NDEF message length - * - * This method writes the NLEN field (V2 mapping) or the ENLEN (V3 mapping). - * - * \param[in] ctx : ndef Context - * \param[in] rawMessageLen: len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen); - - -/*! - ***************************************************************************** - * \brief T3T Format Tag - * - * This method formats a tag to make it ready for NDEF storage. - * cc parameter contains the Attribute Information Block fields - * If cc parameter is not provided (i.e. NULL), this method assumes - * that the AIB is already present. - * options parameter is not used for T3T Tag Format method - * - * - * \param[in] ctx : ndef Context - * \param[in] cc : Capability Container - * \param[in] options: specific flags - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options); - - -/*! - ***************************************************************************** - * \brief T3T Check Presence - * - * This method checks whether a T3T tag is still present in the operating field - * - * \param[in] ctx : ndef Context - - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT3TPollerCheckPresence(ndefContext *ctx); - - -/*! - ***************************************************************************** - * \brief T3T Check Available Space - * - * This method checks whether a T3T tag has enough space to write a message of a given length - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT3TPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief T3T Begin Write Message - * - * This method sets the WriteFlag to the appropriate value before starting to write the NDEF message - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT3TPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief T3T End Write Message - * - * This method updates the Ln field of the AIB and resets the WriteFlag - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT3TPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -#endif /* NDEF_T3T_H */ - -/** - * @} - */ diff --git a/Software/Middlewares/ST/ndef/Inc/poller/ndef_t4t.h b/Software/Middlewares/ST/ndef/Inc/poller/ndef_t4t.h deleted file mode 100644 index fda4f03..0000000 --- a/Software/Middlewares/ST/ndef/Inc/poller/ndef_t4t.h +++ /dev/null @@ -1,485 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum T4T - * - * NDEF T4T provides several functionalities required to - * perform NDEF message management with T4T tags. - * - * The most common interfaces are - *
  ndefT4TPollerContextInitialization() - *
  ndefT4TPollerNdefDetect() - *
  ndefT4TPollerReadRawMessage() - *
  ndefT4TPollerWriteRawMessage() - *
  ndefT4TPollerTagFormat() - * - * - * \addtogroup NDEF - * @{ - * - */ - - -#ifndef NDEF_T4T_H -#define NDEF_T4T_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_nfca.h" -#include "rfal_nfcb.h" -#include "rfal_nfcf.h" -#include "rfal_nfcv.h" -#include "rfal_isoDep.h" -#include "rfal_t4t.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define NDEF_T4T_MAPPING_VERSION_2_0 0x20U /*!< Mapping version 2.0 */ -#define NDEF_T4T_MAPPING_VERSION_3_0 0x30U /*!< Mapping version 3.0 */ - -#define NDEF_T4T_MAX_RAPDU_BODY_LEN 256U /*!< Maximun Response-APDU response body length (short field coding) */ -#define NDEF_T4T_MAX_RAPDU_LEN (NDEF_T4T_MAX_RAPDU_BODY_LEN + RFAL_T4T_MAX_RAPDU_SW1SW2_LEN) /*!< Maximun Response-APDU Length (short field coding) */ - -#define NDEF_T4T_MAX_CAPDU_BODY_LEN 255U /*!< Maximun Command-APDU data length (short field coding) */ -#define NDEF_T4T_MAX_CAPDU_LEN ( RFAL_T4T_MAX_CAPDU_PROLOGUE_LEN \ - + RFAL_T4T_LC_LEN \ - + NDEF_T4T_MAX_CAPDU_BODY_LEN \ - + RFAL_T4T_LC_LEN ) /*!< Maximun Command-APDU Length (short field coding) */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ -#define ndefT4TIsReadAccessGranted(r) ( ((r) == 0x00U) || (((r) >= 0x80U) && ((r) <= 0xFEU)) ) /*!< Read access status */ -#define ndefT4TIsWriteAccessGranted(w) ( ((w) == 0x00U) || (((w) >= 0x80U) && ((w) <= 0xFEU)) ) /*!< Write access status */ - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief Handle T4T NDEF context activation - * - * This method performs the initialization of the NDEF context and handles - * the activation of the ISO-DEP layer. It must be called after a successful - * anti-collision procedure and prior to any NDEF procedures such as NDEF - * detection procedure. - * - * \param[in] ctx : ndef Context - * \param[in] dev : ndef Device - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev); - - -/*! - ***************************************************************************** - * \brief T4T NDEF Detection procedure - * - * This method performs the T4T NDEF Detection procedure - * - * - * \param[in] ctx : ndef Context - * \param[out] info : ndef Information (optional parameter, NULL may be used when no NDEF Information is needed) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : Detection failed (application or ccfile not found) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerNdefDetect(ndefContext *ctx, ndefInfo *info); - - -/*! - ***************************************************************************** - * \brief T4T Select NDEF Tag Application - * - * This method sends the Select NDEF tag application. If V2 Tag Application - * is not found, a Select NDEF tag V1 application is sent/ - * - * \param[in] ctx : ndef Context - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : Application not found - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerSelectNdefTagApplication(ndefContext *ctx); - - -/*! - ***************************************************************************** - * \brief T4T Select File - * - * This method sends a Select File Command-APDU. - * - * The following fields of the ndef Context must be filled up before calling - * this method: - * - devType: device type - * - subCtx.t4t.mv1Flag: Mapping version 1 flag - * - * \param[in] ctx : ndef Context - * \param[in] fileId : file identifier - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : File not found - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerSelectFile(ndefContext *ctx, const uint8_t *fileId); - - -/*! - ***************************************************************************** - * \brief T4T ReadBinary - * - * This method reads the data from the tag using a single - * ReadBinary command - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to star reading data; valid range 0000h-7FFFh - * \param[in] len : requested len (short field coding) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerReadBinary(ndefContext *ctx, uint16_t offset, uint8_t len); - - -/*! - ***************************************************************************** - * \brief T4T ReadBinary with ODO - * - * This method reads the data from the tag using a single - * ReadBinary ODO command - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to star reading data; valid range 0000h-7FFFh - * \param[in] len : requested len (short field coding) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerReadBinaryODO(ndefContext *ctx, uint32_t offset, uint8_t len); - - -/*! - ***************************************************************************** - * \brief T4T Read data from file - * - * This method reads arbitrary length data from the current selected file - * - * \param[in] ctx : ndef Context - * \param[in] len : requested len - * \param[in] offset : file offset of where to start reading data - * \param[out] buf : buffer to place the data read from the tag - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerReadBytes(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen); - -/*! - ***************************************************************************** - * \brief T4T WriteBinary - * - * This method writes the data to the tag using a single - * WriteBinary command - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to star reading data; valid range 0000h-7FFFh - * \param[in] data : data to be written - * \param[in] len : data length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerWriteBinary(ndefContext *ctx, uint16_t offset, const uint8_t *data, uint8_t len); - - -/*! - ***************************************************************************** - * \brief T4T WriteBinary with ODO - * - * This method writes the data to the tag using a single - * WriteBinary ODO command - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to star reading data; valid range 0000h-7FFFh - * \param[in] data : data to be written - * \param[in] len : data length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerWriteBinaryODO(ndefContext *ctx, uint32_t offset, const uint8_t *data, uint8_t len); - -/*! - ***************************************************************************** - * \brief T4T write data to file - * - * This method reads arbitrary length data from the current selected file - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to start writing data - * \param[in] buf : data to write - * \param[in] len : buf len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len); - - -/*! - ***************************************************************************** - * \brief T4T Read raw NDEF message - * - * This method reads a raw NDEF message from the current selected file. - * Prior to NDEF Read procedure, a successfull ndefT4TPollerNdefDetect() - * has to be performed. - * - * \warning Current selected file must not be changed between NDEF Detect - * procedure and NDEF Read procedure. If another file is selected before - * NDEF Read procedure, it is user responsibility to re-select NDEF file - * or to call ndefT4TPollerNdefDetect() to restore proper context. - * - * \param[in] ctx : ndef Context - * \param[out] buf : buffer to place the NDEF message - * \param[in] bufLen : buffer length - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen); - - -/*! - ***************************************************************************** - * \brief T4T Write raw NDEF message - * - * This method writes a raw NDEF message in the current selected file. - * Prior to NDEF Write procedure, a successfull ndefT4TPollerNdefDetect() - * has to be performed. - * - * \warning Current selected file must not be changed between NDEF Detect - * procedure and NDEF Write procedure. If another file is selected before - * NDEF Write procedure, it is user responsibility to re-select NDEF file - * or to call ndefT4TPollerNdefDetect() to restore proper context. - * - * \param[in] ctx : ndef Context - * \param[in] buf : raw message buffer - * \param[in] bufLen : buffer length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen); - - -/*! - ***************************************************************************** - * \brief T4T Write NDEF message length - * - * This method writes the NLEN field (V2 mapping) or the ENLEN (V3 mapping). - * - * \param[in] ctx : ndef Context - * \param[in] rawMessageLen: len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen); - - -/*! - ***************************************************************************** - * \brief T4T Format Tag - * - * This method formats a tag to make it ready for NDEF storage. In case of T4T, - * it writes NLEN/ENLEN=0 to the NDEF File. - * cc and options parameters are not used for T4T Tag Format method. - * - * \param[in] ctx : ndef Context - * \param[in] cc : Capability Container - * \param[in] options: specific flags - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed (SW1SW2 <> 9000h) - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options); - - -/*! - ***************************************************************************** - * \brief T4T Check Presence - * - * This method checks whether a T4T tag is still present in the operating field - * - * \param[in] ctx : ndef Context - - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT4TPollerCheckPresence(ndefContext *ctx); - - -/*! - ***************************************************************************** - * \brief T4T Check Available Space - * - * This method checks whether a T4T tag has enough space to write a message of a given length - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT4TPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief T4T Begin Write Message - * - * This method sets the L-field to 0 - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT4TPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief T4T End Write Message - * - * This method updates the L-field value after the message has been written - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT4TPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -#endif /* NDEF_T4T_H */ - -/** - * @} - */ diff --git a/Software/Middlewares/ST/ndef/Inc/poller/ndef_t5t.h b/Software/Middlewares/ST/ndef/Inc/poller/ndef_t5t.h deleted file mode 100644 index 2ae1a3d..0000000 --- a/Software/Middlewares/ST/ndef/Inc/poller/ndef_t5t.h +++ /dev/null @@ -1,412 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum T5T - * - * NDEF T5T provides several functionalities required to - * perform NDEF message management with T5T tags. - * - * The most common interfaces are - *
  ndefT5TPollerContextInitialization() - *
  ndefT5TPollerNdefDetect() - *
  ndefT5TPollerReadRawMessage() - *
  ndefT5TPollerWriteRawMessage() - *
  ndefT5TPollerTagFormat() - * - * - * \addtogroup NDEF - * @{ - * - */ - - -#ifndef NDEF_T5T_H -#define NDEF_T5T_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_nfcv.h" -#include "rfal_st25xv.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define NDEF_SYSINFO_FLAG_DFSID_POS (0U) /*!< Info flags DFSID flag position */ -#define NDEF_SYSINFO_FLAG_AFI_POS (1U) /*!< Info flags AFI flag position */ -#define NDEF_SYSINFO_FLAG_MEMSIZE_POS (2U) /*!< Info flags Memory Size flag position */ -#define NDEF_SYSINFO_FLAG_ICREF_POS (3U) /*!< Info flags IC reference flag position */ -#define NDEF_SYSINFO_FLAG_MOI_POS (4U) /*!< Info flags MOI flag position */ -#define NDEF_SYSINFO_FLAG_CMDLIST_POS (5U) /*!< Info flags Command List flag position */ -#define NDEF_SYSINFO_FLAG_CSI_POS (6U) /*!< Info flags CSI flag position */ -#define NDEF_SYSINFO_FLAG_LEN_POS (7U) /*!< Info flags Length position */ - -#define NDEF_CMDLIST_READSINGLEBLOCK_POS (0U) /*!< Cmd List: ReadSingleBlock position */ -#define NDEF_CMDLIST_WRITESINGLEBLOCK_POS (1U) /*!< Cmd List: WriteSingleBlock position */ -#define NDEF_CMDLIST_LOCKSINGLEBLOCK_POS (2U) /*!< Cmd List: LockSingleBlock position */ -#define NDEF_CMDLIST_READMULTIPLEBLOCKS_POS (3U) /*!< Cmd List: ReadMultipleBlocks position */ -#define NDEF_CMDLIST_WRITEMULTIPLEBLOCKS_POS (4U) /*!< Cmd List: WriteMultipleBlocks position */ -#define NDEF_CMDLIST_SELECT_POS (5U) /*!< Cmd List: SelectSupported position */ -#define NDEF_CMDLIST_RESETTOREADY_POS (6U) /*!< Cmd List: ResetToReady position */ -#define NDEF_CMDLIST_GETMULTIPLEBLOCKSECSTATUS_POS (7U) /*!< Cmd List: GetMultipleBlockSecStatus position */ - -#define NDEF_CMDLIST_WRITEAFI_POS (0U) /*!< Cmd List: WriteAFI position */ -#define NDEF_CMDLIST_LOCKAFI_POS (1U) /*!< Cmd List: LockAFI position */ -#define NDEF_CMDLIST_WRITEDSFID_POS (2U) /*!< Cmd List: WriteDSFID position */ -#define NDEF_CMDLIST_LOCKDSFID_POS (3U) /*!< Cmd List: LockDSFID position */ -#define NDEF_CMDLIST_GETSYSTEMINFORMATION_POS (4U) /*!< Cmd List: GetSystemInformation position */ -#define NDEF_CMDLIST_CUSTOMCMDS_POS (5U) /*!< Cmd List: CustomCmds position */ -#define NDEF_CMDLIST_FASTREADMULTIPLEBLOCKS_POS (6U) /*!< Cmd List: FastReadMultipleBlocks position */ - -#define NDEF_CMDLIST_EXTREADSINGLEBLOCK_POS (0U) /*!< Cmd List: ExtReadSingleBlock position */ -#define NDEF_CMDLIST_EXTWRITESINGLEBLOCK_POS (1U) /*!< Cmd List: ExtWriteSingleBlock position */ -#define NDEF_CMDLIST_EXTLOCKSINGLEBLOCK_POS (2U) /*!< Cmd List: ExtLockSingleBlock position */ -#define NDEF_CMDLIST_EXTREADMULTIPLEBLOCKS_POS (3U) /*!< Cmd List: ExtReadMultipleBlocks position */ -#define NDEF_CMDLIST_EXTWRITEMULTIPLEBLOCKS_POS (4U) /*!< Cmd List: ExtWriteMultipleBlocks position */ -#define NDEF_CMDLIST_EXTGETMULTIPLEBLOCKSECSTATUS_POS (5U) /*!< Cmd List: ExtGetMultipleBlockSecStatus position */ -#define NDEF_CMDLIST_FASTEXTENDEDREADMULTIPLEBLOCKS_POS (6U) /*!< Cmd List: FastExtendedReadMultipleBlocks position */ - -#define NDEF_T5T_CC_MAGIC_1_BYTE_ADDR_MODE 0xE1U /*!< T5T CC Magic Number (1-byte Addres Mode) */ -#define NDEF_T5T_CC_MAGIC_2_BYTE_ADDR_MODE 0xE2U /*!< T5T CC Magic Number (2-byte Addres Mode) */ -#define NDEF_T5T_CC_LEN_4_BYTES 4U /*!< T5T CC Length (4 bytes) */ -#define NDEF_T5T_CC_LEN_8_BYTES 8U /*!< T5T CC Length (8 bytes) */ -#define NDEF_T5T_FORMAT_OPTION_NFC_FORUM 1U /*!< Format tag according to NFC Forum MLEN computation */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define ndefT5TSysInfoDFSIDPresent(infoFlags) (((infoFlags) >> NDEF_SYSINFO_FLAG_DFSID_POS) & 0x01U) /*!< Returns DFSID presence flag */ -#define ndefT5TSysInfoAFIPresent(infoFlags) (((infoFlags) >> NDEF_SYSINFO_FLAG_AFI_POS) & 0x01U) /*!< Returns AFI presence flag */ -#define ndefT5TSysInfoMemSizePresent(infoFlags) (((infoFlags) >> NDEF_SYSINFO_FLAG_MEMSIZE_POS) & 0x01U) /*!< Returns Memory size presence flag */ -#define ndefT5TSysInfoICRefPresent(infoFlags) (((infoFlags) >> NDEF_SYSINFO_FLAG_ICREF_POS) & 0x01U) /*!< Returns IC Reference presence flag */ -#define ndefT5TSysInfoMOIValue(infoFlags) (((infoFlags) >> NDEF_SYSINFO_FLAG_MOI_POS) & 0x01U) /*!< Returns MOI value */ -#define ndefT5TSysInfoCmdListPresent(infoFlags) (((infoFlags) >> NDEF_SYSINFO_FLAG_CMDLIST_POS) & 0x01U) /*!< Returns Command List presence flag */ -#define ndefT5TSysInfoCSIPresent(infoFlags) (((infoFlags) >> NDEF_SYSINFO_FLAG_CSI_POS) & 0x01U) /*!< Returns CSI presence flag */ -#define ndefT5TSysInfoLenValue(infoFlags) (((infoFlags) >> NDEF_SYSINFO_FLAG_LEN_POS) & 0x01U) /*!< Returns Info flag len value */ - -#define ndefT5TSysInfoReadSingleBlockSupported(cmdList) (((cmdList)[0] >> NDEF_CMDLIST_READSINGLEBLOCK_POS) & 0x01U) /*!< Returns ReadSingleBlock support flag */ -#define ndefT5TSysInfoWriteSingleBlockSupported(cmdList) (((cmdList)[0] >> NDEF_CMDLIST_WRITESINGLEBLOCK_POS) & 0x01U) /*!< Returns WriteSingleBlock support flag */ -#define ndefT5TSysInfoLockSingleBlockSupported(cmdList) (((cmdList)[0] >> NDEF_CMDLIST_LOCKSINGLEBLOCK_POS) & 0x01U) /*!< Returns LockSingleBlock support flag */ -#define ndefT5TSysInfoReadMultipleBlocksSupported(cmdList) (((cmdList)[0] >> NDEF_CMDLIST_READMULTIPLEBLOCKS_POS) & 0x01U) /*!< Returns ReadMultipleBlocks support flag */ -#define ndefT5TSysInfoWriteMultipleBlocksSupported(cmdList) (((cmdList)[0] >> NDEF_CMDLIST_WRITEMULTIPLEBLOCKS_POS) & 0x01U) /*!< Returns WriteMultipleBlocks support flag */ -#define ndefT5TSysInfoSelectSupported(cmdList) (((cmdList)[0] >> NDEF_CMDLIST_SELECT_POS) & 0x01U) /*!< Returns SelectSupported support flag */ -#define ndefT5TSysInfoResetToReadySupported(cmdList) (((cmdList)[0] >> NDEF_CMDLIST_RESETTOREADY_POS) & 0x01U) /*!< Returns ResetToReady support flag */ -#define ndefT5TSysInfoGetMultipleBlockSecStatusSupported(cmdList) (((cmdList)[0] >> NDEF_CMDLIST_GETMULTIPLEBLOCKSECSTATUS_POS) & 0x01U) /*!< Returns GetMultipleBlockSecStatus support flag */ - -#define ndefT5TSysInfoWriteAFISupported(cmdList) (((cmdList)[1] >> NDEF_CMDLIST_WRITEAFI_POS) & 0x01U) /*!< Returns WriteAFI support flag */ -#define ndefT5TSysInfoLockAFISupported(cmdList) (((cmdList)[1] >> NDEF_CMDLIST_LOCKAFI_POS) & 0x01U) /*!< Returns LockAFI support flag */ -#define ndefT5TSysInfoWriteDSFIDSupported(cmdList) (((cmdList)[1] >> NDEF_CMDLIST_WRITEDSFID_POS) & 0x01U) /*!< Returns WriteDSFID support flag */ -#define ndefT5TSysInfoLockDSFIDSupported(cmdList) (((cmdList)[1] >> NDEF_CMDLIST_LOCKDSFID_POS) & 0x01U) /*!< Returns LockDSFID support flag */ -#define ndefT5TSysInfoGetSystemInformationSupported(cmdList) (((cmdList)[1] >> NDEF_CMDLIST_GETSYSTEMINFORMATION_POS) & 0x01U) /*!< Returns GetSystemInformation support flag */ -#define ndefT5TSysInfoCustomCmdsSupported(cmdList) (((cmdList)[1] >> NDEF_CMDLIST_CUSTOMCMDS_POS) & 0x01U) /*!< Returns CustomCmds support flag */ -#define ndefT5TSysInfoFastReadMultipleBlocksSupported(cmdList) (((cmdList)[1] >> NDEF_CMDLIST_FASTREADMULTIPLEBLOCKS_POS) & 0x01U) /*!< Returns FastReadMultipleBlocks support flag */ - -#define ndefT5TSysInfoExtReadSingleBlockSupported(cmdList) (((cmdList)[2] >> NDEF_CMDLIST_EXTREADSINGLEBLOCK_POS) & 0x01U) /*!< Returns ExtReadSingleBlock support flag */ -#define ndefT5TSysInfoExtWriteSingleBlockSupported(cmdList) (((cmdList)[2] >> NDEF_CMDLIST_EXTWRITESINGLEBLOCK_POS) & 0x01U) /*!< Returns ExtWriteSingleBlock support flag */ -#define ndefT5TSysInfoExtLockSingleBlockSupported(cmdList) (((cmdList)[2] >> NDEF_CMDLIST_EXTLOCKSINGLEBLOCK_POS) & 0x01U) /*!< Returns ExtLockSingleBlock support flag */ -#define ndefT5TSysInfoExtReadMultipleBlocksSupported(cmdList) (((cmdList)[2] >> NDEF_CMDLIST_EXTREADMULTIPLEBLOCKS_POS) & 0x01U) /*!< Returns ExtReadMultipleBlocks support flag */ -#define ndefT5TSysInfoExtWriteMultipleBlocksSupported(cmdList) (((cmdList)[2] >> NDEF_CMDLIST_EXTWRITEMULTIPLEBLOCKS_POS) & 0x01U) /*!< Returns ExtWriteMultipleBlocks support flag */ -#define ndefT5TSysInfoExtGetMultipleBlockSecStatusSupported(cmdList) (((cmdList)[2] >> NDEF_CMDLIST_EXTGETMULTIPLEBLOCKSECSTATUS_POS) & 0x01U) /*!< Returns ExtGetMultipleBlockSecStatus support flag */ -#define ndefT5TSysInfoFastExtendedReadMultipleBlocksSupported(cmdList) (((cmdList)[2] >> NDEF_CMDLIST_FASTEXTENDEDREADMULTIPLEBLOCKS_POS) & 0x01U) /*!< Returns FastExtendedReadMultipleBlocks support flag */ - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -/*! - ***************************************************************************** - * \brief Handle T5T NDEF context activation - * - * This method performs the initialisation of the NDEF context. - * It must be called after a successfull - * anticollition procedure and prior to any NDEF procedures such as NDEF - * detection procedure. - * - * \param[in] ctx : ndef Context - * \param[in] dev : ndef Device - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev); - - -/*! - ***************************************************************************** - * \brief T5T NDEF Detection procedure - * - * This method performs the T5T NDEF Detection procedure - * - * - * \param[in] ctx : ndef Context - * \param[out] info : ndef Information (optional parameter, NULL may be used when no NDEF Information is needed) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : Detection failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerNdefDetect(ndefContext *ctx, ndefInfo *info); - - -/*! - ***************************************************************************** - * \brief T5T Read data from tag memory - * - * This method reads arbitrary length data from tag memory - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to start reading data - * \param[in] len : requested len - * \param[out] buf : buffer to place the data read from the tag - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerReadBytes(ndefContext * ctx, uint32_t offset, uint32_t len, uint8_t* buf, uint32_t * rcvdLen); - - -/*! - ***************************************************************************** - * \brief T5T write data to tag memory - * - * This method write arbitrary length data from to tag memory - * - * \param[in] ctx : ndef Context - * \param[in] offset : file offset of where to start writing data - * \param[in] buf : data to write - * \param[in] len : buf len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t * buf, uint32_t len); - - -/*! - ***************************************************************************** - * \brief T5T Read raw NDEF message - * - * This method reads a raw NDEF message from the current selected file. - * Prior to NDEF Read procedure, a successfull ndefT5TPollerNdefDetect() - * has to be performed. - * - * \param[in] ctx : ndef Context - * \param[out] buf : buffer to place the NDEF message - * \param[in] bufLen : buffer length - * \param[out] rcvdLen: received length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : read failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen); - - -/*! - ***************************************************************************** - * \brief T5T Write raw NDEF message - * - * This method writes a raw NDEF message in the current selected file. - * Prior to NDEF Write procedure, a successfull ndefT5TPollerNdefDetect() - * has to be performed. - * - * \param[in] ctx : ndef Context - * \param[in] buf : raw message buffer - * \param[in] bufLen : buffer length - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen); - - -/*! - ***************************************************************************** - * \brief T5T Write NDEF message length - * - * This method writes the L field to the tag memory - * - * \param[in] ctx : ndef Context - * \param[in] rawMessageLen: len - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerWriteRawMessageLen( ndefContext *ctx, uint32_t rawMessageLen); - - -/*! - ***************************************************************************** - * \brief T5T Format Tag - * - * This method format a tag to make it ready for NDEF storage. - * When the cc parameter is provided, the Capability Container is initialized - * with the value provided by the user. - * When the cc parameter is not provided (i.e. NULL), this method - * retrieves the appropriate CC field from (Extended) Get System Information - * or returns ERR_REQUEST if (Extended) Get System Information is not supported. - * The option parameter is used in case of NULL cc parameter to choose - * between Android CC format (default when option = 0) - * or NFC Forum Format (option = NDEF_T5T_FORMAT_OPTION_NFC_FORUM) - * - * - * \param[in] ctx : ndef Context - * \param[in] cc : Capability Container - * \param[in] options : specific flags - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_REQUEST : write failed - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options); - - -/*! - ***************************************************************************** - * \brief T5T Check Presence - * - * This method check whether a T5T tag is still present in the operating field - * - * \param[in] ctx : ndef Context - - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode ndefT5TPollerCheckPresence(ndefContext *ctx); - - -/*! - ***************************************************************************** - * \brief T5T Check Available Space - * - * This method check whether a T5T tag has enough space to write a message of a given length - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT5TPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief T5T Begin Write Message - * - * This method sets the L-field to 0 and sets the message offset to the proper value according to messageLen - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT5TPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -/*! - ***************************************************************************** - * \brief T5T End Write Message - * - * This method updates the L-field value after the message has been written - * - * \param[in] ctx : ndef Context - * \param[in] messageLen: message length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOMEM : not enough space - * \return ERR_NONE : Enough space for message of messageLen length - ***************************************************************************** - */ -ReturnCode ndefT5TPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen); - - -#endif /* NDEF_T5T_H */ - -/** - * @} - */ diff --git a/Software/Middlewares/ST/ndef/Src/message/ndef_message.c b/Software/Middlewares/ST/ndef/Src/message/ndef_message.c deleted file mode 100644 index 68176af..0000000 --- a/Software/Middlewares/ST/ndef/Src/message/ndef_message.c +++ /dev/null @@ -1,299 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF message - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "platform.h" -#include "st_errno.h" -#include "utils.h" -#include "ndef_record.h" -#include "ndef_message.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define NDEF_MAX_RECORD 10U /*!< Maximum number of records */ - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ -static uint8_t ndefRecordPoolIndex = 0; - - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/*****************************************************************************/ -static ndefRecord* ndefAllocRecord(void) -{ - static ndefRecord ndefRecordPool[NDEF_MAX_RECORD]; - - if (ndefRecordPoolIndex >= NDEF_MAX_RECORD) - { - return NULL; - } - - return &ndefRecordPool[ndefRecordPoolIndex++]; -} - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ -/*****************************************************************************/ - - -ReturnCode ndefMessageInit(ndefMessage* message) -{ - if (message == NULL) - { - return ERR_PARAM; - } - - message->record = NULL; - message->info.length = 0; - message->info.recordCount = 0; - - ndefRecordPoolIndex = 0; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefMessageGetInfo(const ndefMessage* message, ndefMessageInfo* info) -{ - ndefRecord* record; - uint32_t length = 0; - uint32_t recordCount = 0; - - if ( (message == NULL) || (info == NULL) ) - { - return ERR_PARAM; - } - - record = message->record; - - while (record != NULL) - { - length += ndefRecordGetLength(record); - recordCount++; - - record = record->next; - } - - info->length = length; - info->recordCount = recordCount; - - return ERR_NONE; -} - - -/*****************************************************************************/ -uint32_t ndefMessageGetRecordCount(const ndefMessage* message) -{ - ndefMessageInfo info; - - if (ndefMessageGetInfo(message, &info) == ERR_NONE) - { - return info.recordCount; - } - - return 0; -} - - -/*****************************************************************************/ -ReturnCode ndefMessageAppend(ndefMessage* message, ndefRecord* record) -{ - if ( (message == NULL) || (record == NULL) ) - { - return ERR_PARAM; - } - - /* Clear the Message Begin bit */ - ndefHeaderClearMB(record); - - /* Record is appended so it is the last in the list, set the Message End bit */ - ndefHeaderSetME(record); - - record->next = NULL; - - if (message->record == NULL) - { - /* Set the Message Begin bit for the first record only */ - ndefHeaderSetMB(record); - - message->record = record; - } - else - { - ndefRecord* current = message->record; - - /* Go through the list of records */ - while (current->next != NULL) - { - current = current->next; - } - - /* Clear the Message End bit to the record before the one being appended */ - ndefHeaderClearME(current); - - /* Append to the last record */ - current->next = record; - } - - message->info.length += ndefRecordGetLength(record); - message->info.recordCount += 1U; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefMessageDecode(const ndefConstBuffer* bufPayload, ndefMessage* message) -{ - ReturnCode err; - uint32_t offset; - - if ( (bufPayload == NULL) || (bufPayload->buffer == NULL) || (message == NULL) ) - { - return ERR_PARAM; - } - - err = ndefMessageInit(message); - if (err != ERR_NONE) - { - return err; - } - - offset = 0; - while (offset < bufPayload->length) - { - ndefConstBuffer bufRecord; - ndefRecord* record = ndefAllocRecord(); - if (record == NULL) - { - return ERR_NOMEM; - } - bufRecord.buffer = &bufPayload->buffer[offset]; - bufRecord.length = bufPayload->length - offset; - err = ndefRecordDecode(&bufRecord, record); - if (err != ERR_NONE) - { - return err; - } - offset += ndefRecordGetLength(record); - - err = ndefMessageAppend(message, record); - if (err != ERR_NONE) - { - return err; - } - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefMessageEncode(const ndefMessage* message, ndefBuffer* bufPayload) -{ - ReturnCode err; - ndefMessageInfo info; - ndefRecord* record; - uint32_t offset; - uint32_t remainingLength; - - if ( (message == NULL) || (bufPayload == NULL) || (bufPayload->buffer == NULL) ) - { - return ERR_PARAM; - } - - err = ndefMessageGetInfo(message, &info); - if ( (err != ERR_NONE) || (bufPayload->length < info.length) ) - { - bufPayload->length = info.length; - return ERR_NOMEM; - } - - /* Get the first record */ - record = ndefMessageGetFirstRecord(message); - offset = 0; - remainingLength = bufPayload->length; - - while (record != NULL) - { - ndefBuffer bufRecord; - bufRecord.buffer = &bufPayload->buffer[offset]; - bufRecord.length = remainingLength; - err = ndefRecordEncode(record, &bufRecord); - if (err != ERR_NONE) - { - bufPayload->length = info.length; - return err; - } - offset += bufRecord.length; - remainingLength -= bufRecord.length; - - record = ndefMessageGetNextRecord(record); - } - - bufPayload->length = offset; - return ERR_NONE; -} diff --git a/Software/Middlewares/ST/ndef/Src/message/ndef_record.c b/Software/Middlewares/ST/ndef/Src/message/ndef_record.c deleted file mode 100644 index d8d2faf..0000000 --- a/Software/Middlewares/ST/ndef/Src/message/ndef_record.c +++ /dev/null @@ -1,627 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF record - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "platform.h" -#include "st_errno.h" -#include "utils.h" -#include "ndef_record.h" -#include "ndef_message.h" -#include "ndef_types.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - -/*****************************************************************************/ -ReturnCode ndefRecordReset(ndefRecord* record) -{ - ndefConstBuffer8 bufEmpty = { NULL, 0 }; - ndefConstBuffer bufEmptyPayload = { NULL, 0 }; - - if (record == NULL) - { - return ERR_PARAM; - } - - record->header = ndefHeader(0U, 0U, 0U, 0U, 0U, NDEF_TNF_EMPTY); - - (void)ndefRecordSetType(record, NDEF_TNF_EMPTY, &bufEmpty); - - (void)ndefRecordSetId(record, &bufEmpty); - - /* Set the SR bit */ - (void)ndefRecordSetPayload(record, &bufEmptyPayload); - - record->ndeftype = NULL; - - record->next = NULL; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordInit(ndefRecord* record, uint8_t tnf, const ndefConstBuffer8* bufType, const ndefConstBuffer8* bufId, const ndefConstBuffer* bufPayload) -{ - if ( (record == NULL) || (bufType == NULL) || (bufPayload == NULL) ) - { - return ERR_PARAM; - } - - (void)ndefRecordReset(record); - - (void)ndefRecordSetType(record, tnf, bufType); - - (void)ndefRecordSetId(record, bufId); - - (void)ndefRecordSetPayload(record, bufPayload); - - return ERR_NONE; -} - - -/*****************************************************************************/ -uint32_t ndefRecordGetHeaderLength(const ndefRecord* record) -{ - uint32_t length; - - if (record == NULL) - { - return 0; - } - - length = sizeof(uint8_t); /* header (MB:1 + ME:1 + CF:1 + SR:1 + IL:1 + TNF:3 => 8 bits) */ - length += sizeof(uint8_t); /* Type length */ - if (ndefHeaderIsSetSR(record)) - { - length += sizeof(uint8_t); /* Short record */ - } - else - { - length += sizeof(uint32_t); /* Standard record */ - } - if (ndefHeaderIsSetIL(record)) - { - length += sizeof(uint8_t); /* Id length */ - } - length += record->typeLength; /* Type */ - length += record->idLength; /* Id */ - - return length; -} - - -/*****************************************************************************/ -uint32_t ndefRecordGetLength(const ndefRecord* record) -{ - uint32_t length; - - if (record == NULL) - { - return 0; - } - - length = ndefRecordGetHeaderLength(record); /* Header */ - length += ndefRecordGetPayloadLength(record); /* Payload */ - - return length; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordSetType(ndefRecord* record, uint8_t tnf, const ndefConstBuffer8* bufType) -{ - if ( (record == NULL) || - (bufType == NULL) || - ( (bufType->buffer == NULL) && (bufType->length != 0U) ) ) - { - return ERR_PARAM; - } - - ndefHeaderSetTNF(record, tnf); - - record->typeLength = bufType->length; - record->type = bufType->buffer; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordGetType(const ndefRecord* record, uint8_t* tnf, ndefConstBuffer8* bufType) -{ - if ( (record == NULL) || (tnf == NULL) || (bufType == NULL) ) - { - return ERR_PARAM; - } - - *tnf = ndefHeaderTNF(record); - bufType->buffer = record->type; - bufType->length = record->typeLength; - - return ERR_NONE; -} - - -/*****************************************************************************/ -bool ndefRecordTypeMatch(const ndefRecord* record, uint8_t tnf, const ndefConstBuffer8* bufType) -{ - if ( (record == NULL) || (bufType == NULL) ) - { - return false; - } - - if ( (ndefHeaderTNF(record) == tnf) && - (record->typeLength == bufType->length) && - (ST_BYTECMP(record->type, bufType->buffer, bufType->length) == 0) ) - { - return true; - } - - return false; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordSetId(ndefRecord* record, const ndefConstBuffer8* bufId) -{ - if ( (record == NULL) || - (bufId == NULL) || - ( (bufId->buffer == NULL) && (bufId->length != 0U) ) ) - { - return ERR_PARAM; - } - - if (bufId->buffer != NULL) - { - ndefHeaderSetIL(record); - } - else - { - ndefHeaderClearIL(record); - } - - record->id = bufId->buffer; - record->idLength = bufId->length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordGetId(const ndefRecord* record, ndefConstBuffer8* bufId) -{ - if ( (record == NULL) || (bufId == NULL) ) - { - return ERR_PARAM; - } - - bufId->buffer = record->id; - bufId->length = record->idLength; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordSetPayload(ndefRecord* record, const ndefConstBuffer* bufPayload) -{ - if ( (record == NULL) || - (bufPayload == NULL) || - ( (bufPayload->buffer == NULL) && (bufPayload->length != 0U) ) ) - { - return ERR_PARAM; - } - - ndefHeaderSetValueSR(record, (bufPayload->length <= NDEF_SHORT_RECORD_LENGTH_MAX) ? 1 : 0); - - record->bufPayload.buffer = bufPayload->buffer; - record->bufPayload.length = bufPayload->length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordGetPayload(const ndefRecord* record, ndefConstBuffer* bufPayload) -{ - if ( (record == NULL) || (bufPayload == NULL) ) - { - return ERR_PARAM; - } - - bufPayload->buffer = record->bufPayload.buffer; - bufPayload->length = ndefRecordGetPayloadLength(record); - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordDecode(const ndefConstBuffer* bufPayload, ndefRecord* record) -{ - uint32_t offset; - - if ( (bufPayload == NULL) || (bufPayload->buffer == NULL) || (record == NULL) ) - { - return ERR_PARAM; - } - - if (ndefRecordReset(record) != ERR_NONE) - { - return ERR_INTERNAL; - } - - /* Get "header" byte */ - offset = 0; - if ((offset + sizeof(uint8_t)) > bufPayload->length) - { - return ERR_PROTO; - } - record->header = bufPayload->buffer[offset]; - offset++; - - /* Get Type length */ - if ((offset + sizeof(uint8_t)) > bufPayload->length) - { - return ERR_PROTO; - } - record->typeLength = bufPayload->buffer[offset]; - offset++; - - /* Decode Payload length */ - if (ndefHeaderIsSetSR(record)) - { - /* Short record */ - if ((offset + sizeof(uint8_t)) > bufPayload->length) - { - return ERR_PROTO; - } - record->bufPayload.length = bufPayload->buffer[offset]; /* length stored on a single byte for Short Record */ - offset++; - } - else - { - /* Standard record */ - if ((offset + sizeof(uint32_t)) > bufPayload->length) - { - return ERR_PROTO; - } - record->bufPayload.length = GETU32(&bufPayload->buffer[offset]); - offset += sizeof(uint32_t); - } - - /* Get Id length */ - if (ndefHeaderIsSetIL(record)) - { - if ((offset + sizeof(uint8_t)) > bufPayload->length) - { - return ERR_PROTO; - } - record->idLength = bufPayload->buffer[offset]; - offset++; - } - else - { - record->idLength = 0; - } - - /* Get Type */ - if (record->typeLength > 0U) - { - if ((offset + record->typeLength) > bufPayload->length) - { - return ERR_PROTO; - } - record->type = &bufPayload->buffer[offset]; - offset += record->typeLength; - } - else - { - record->type = NULL; - } - - /* Get Id */ - if (record->idLength > 0U) - { - if ((offset + record->idLength) > bufPayload->length) - { - return ERR_PROTO; - } - record->id = &bufPayload->buffer[offset]; - offset += record->idLength; - } - else - { - record->id = NULL; - } - - /* Get Payload */ - if (record->bufPayload.length > 0U) - { - if ((offset + record->bufPayload.length) > bufPayload->length) - { - return ERR_PROTO; - } - record->bufPayload.buffer = &bufPayload->buffer[offset]; - } - else - { - record->bufPayload.buffer = NULL; - } - - // Doesn't recognize WKT ... - - record->next = NULL; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordEncodeHeader(const ndefRecord* record, ndefBuffer* bufHeader) -{ - uint32_t offset; - uint32_t payloadLength; - - if ( (record == NULL) || (bufHeader == NULL) || (bufHeader->buffer == NULL) ) - { - return ERR_PARAM; - } - - if (bufHeader->length < NDEF_RECORD_HEADER_LEN) - { - bufHeader->length = NDEF_RECORD_HEADER_LEN; - return ERR_NOMEM; - } - - /* Start encoding the record */ - offset = 0; - bufHeader->buffer[offset] = record->header; - offset++; - - /* Set Type length */ - bufHeader->buffer[offset] = record->typeLength; - offset++; - - /* Encode Payload length */ - payloadLength = ndefRecordGetPayloadLength(record); - - if (payloadLength <= NDEF_SHORT_RECORD_LENGTH_MAX) - { - /* Short record */ - bufHeader->buffer[offset] = (uint8_t)payloadLength; - offset++; - } - else - { - /* Standard record */ - bufHeader->buffer[offset] = (uint8_t)(payloadLength >> 24); - offset++; - bufHeader->buffer[offset] = (uint8_t)(payloadLength >> 16); - offset++; - bufHeader->buffer[offset] = (uint8_t)(payloadLength >> 8); - offset++; - bufHeader->buffer[offset] = (uint8_t)(payloadLength); - offset++; - } - - /* Encode Id length */ - if (ndefHeaderIsSetIL(record)) - { - bufHeader->buffer[offset] = record->idLength; - offset++; - } - - bufHeader->length = offset; - - return ERR_NONE; -} - - -/*****************************************************************************/ -static ReturnCode ndefRecordPayloadEncode(const ndefRecord* record, ndefBuffer* bufPayload) -{ - uint32_t payloadLength; - uint32_t offset; - bool begin; - ndefConstBuffer bufPayloadItem; - - if ( (record == NULL) || (bufPayload == NULL) ) - { - return ERR_PROTO; - } - - payloadLength = ndefRecordGetPayloadLength(record); - if (payloadLength > bufPayload->length) - { - return ERR_NOMEM; - } - - begin = true; - offset = 0; - while (ndefRecordGetPayloadItem(record, &bufPayloadItem, begin) != NULL) - { - begin = false; - if (bufPayloadItem.length > 0U) - { - ST_MEMCPY(&bufPayload->buffer[offset], bufPayloadItem.buffer, bufPayloadItem.length); - } - offset += bufPayloadItem.length; - } - - bufPayload->length = offset; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordEncode(const ndefRecord* record, ndefBuffer* bufRecord) -{ - ReturnCode err; - ndefBuffer bufHeader; - ndefBuffer bufPayload; - uint32_t offset; - - if ( (record == NULL) || (bufRecord == NULL) || (bufRecord->buffer == NULL) ) - { - return ERR_PARAM; - } - - if (bufRecord->length < ndefRecordGetLength(record)) - { - bufRecord->length = ndefRecordGetLength(record); - return ERR_NOMEM; - } - - /* Encode header at the begining of buffer provided */ - bufHeader.buffer = bufRecord->buffer; - bufHeader.length = bufRecord->length; - err = ndefRecordEncodeHeader(record, &bufHeader); - if (err != ERR_NONE) - { - return err; - } - - offset = bufHeader.length; - - /* Set Type */ - if (record->typeLength > 0U) - { - (void)ST_MEMCPY(&bufRecord->buffer[offset], record->type, record->typeLength); - offset += record->typeLength; - } - - /* Set Id */ - if (record->idLength > 0U) - { - (void)ST_MEMCPY(&bufRecord->buffer[offset], record->id, record->idLength); - offset += record->idLength; - } - - /* Set Payload */ - bufPayload.buffer = &bufRecord->buffer[offset]; - bufPayload.length = bufRecord->length - offset; - err = ndefRecordPayloadEncode(record, &bufPayload); - if (err != ERR_NONE) - { - return err; - } - - bufRecord->length = offset + bufPayload.length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -uint32_t ndefRecordGetPayloadLength(const ndefRecord* record) -{ - uint32_t payloadLength; - - if (record == NULL) - { - return 0; - } - - if ( (record->ndeftype != NULL) && (record->ndeftype->getPayloadLength != NULL) ) - { - payloadLength = record->ndeftype->getPayloadLength(record->ndeftype); - } - else - { - payloadLength = record->bufPayload.length; - } - - return payloadLength; -} - - -/*****************************************************************************/ -const uint8_t* ndefRecordGetPayloadItem(const ndefRecord* record, ndefConstBuffer* bufPayloadItem, bool begin) -{ - if ( (record == NULL) || (bufPayloadItem == NULL) ) - { - return NULL; - } - - bufPayloadItem->buffer = NULL; - bufPayloadItem->length = 0; - - if ( (record->ndeftype != NULL) && (record->ndeftype->getPayloadItem != NULL) ) - { - record->ndeftype->getPayloadItem(record->ndeftype, bufPayloadItem, begin); - } - else - { - if (begin == true) - { - (void)ndefRecordGetPayload(record, bufPayloadItem); - } - } - - return bufPayloadItem->buffer; -} diff --git a/Software/Middlewares/ST/ndef/Src/message/ndef_type_wifi.c b/Software/Middlewares/ST/ndef/Src/message/ndef_type_wifi.c deleted file mode 100644 index 7c43574..0000000 --- a/Software/Middlewares/ST/ndef/Src/message/ndef_type_wifi.c +++ /dev/null @@ -1,512 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF Wifi type - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - - -#include "platform.h" -#include "st_errno.h" -#include "utils.h" -#include "ndef_record.h" -#include "ndef_types.h" -#include "ndef_type_wifi.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - - -/*! Wifi Type strings */ -static const uint8_t ndefMediaTypeWifi[] = "application/vnd.wfa.wsc"; /*!< Wi-Fi Simple Configuration Type */ - -const ndefConstBuffer8 bufMediaTypeWifi = { ndefMediaTypeWifi, sizeof(ndefMediaTypeWifi) - 1U }; /*!< Wifi Type buffer */ - - -/*! Wifi OBB (WPS) */ - -#define NDEF_WIFI_DEFAULT_NETWORK_KEY "00000000" /*! Network key to be used when the Authentication is set to None. - Althought WPS defines a 0-length network key in such case, - a 8 digit value is required with tested phones. */ - -#define NDEF_WIFI_NETWORK_SSID_LENGTH 32U /*!< Network SSID length */ -#define NDEF_WIFI_NETWORK_KEY_LENGTH 32U /*!< Network Key length */ - -#define NDEF_WIFI_ENCRYPTION_TYPE_LENGTH 2U /*!< Encryption type length */ -#define NDEF_WIFI_AUTHENTICATION_TYPE_LENGTH 2U /*!< Authentication type length */ -#define WIFI_SSID_TYPE_LENGTH 2U /*!< SSID type length */ -#define WIFI_SSID_KEY_TYPE_LENGTH 2U /*!< SSID key type length */ - -#define NDEF_WIFI_ATTRIBUTE_ID_SSID_LSB 0x10U /*!< SSID Attribute ID LSB */ -#define NDEF_WIFI_ATTRIBUTE_ID_SSID_MSB 0x45U /*!< SSID Attribute ID MSB */ - -#define NDEF_WIFI_ATTRIBUTE_ID_NETWORK_LSB 0x10U /*!< Network Attribute ID LSB */ -#define NDEF_WIFI_ATTRIBUTE_ID_NETWORK_MSB 0x27U /*!< Network Attribute ID MSB */ - -#define NDEF_WIFI_ATTRIBUTE_ENCRYPTION 0x0FU /*!< Encryption attribute */ -#define NDEF_WIFI_ATTRIBUTE_AUTHENTICATION 0x03U /*!< Authentication attribute */ - -#define NDEF_WIFI_ATTRIBUTE_ID_OFFSET 0x01U /*!< Attribute Id offset */ -#define NDEF_WIFI_ATTRIBUTE_LENGTH_MSB_OFFSET 0x02U /*!< Attribute length MSB offset */ -#define NDEF_WIFI_ATTRIBUTE_LENGTH_LSB_OFFSET 0x03U /*!< Attribute length LSB offset */ -#define NDEF_WIFI_ATTRIBUTE_DATA_OFFSET 0x04U /*!< Attribute data offset */ -#define NDEF_WIFI_ATTRIBUTE_ENCRYPTION_LSB_OFFSET 0x05U /*!< Attribute encryption offset */ -#define NDEF_WIFI_ATTRIBUTE_AUTHENTICATION_LSB_OFFSET 0x05U /*!< Attribute authentication offset */ - - -static uint8_t wifiConfigToken1[] = { - 0x10, 0x4A, /* Attribute ID: Version */ - 0x00, 0x01, /* Attribute ID Length */ - 0x10, /* Version 1.0 */ - 0x10, 0x0E, /* Attribute ID Credential */ - 0x00, 0x48, /* Attribute ID Length */ - 0x10, 0x26, /* Attribute ID: Network Index */ - 0x00, 0x01, /* Attribute Length */ - 0x01, /* Index */ - 0x10, 0x45 /* Attribute ID: SSID */ -}; - -static uint8_t wifiConfigToken3[] = { - 0x10, 0x03, /* Attribute ID:Authentication Type */ - 0x00, 0x02, /* Attribute Length */ - 0x00, 0x01, /* Attribute Type: Open */ - 0x10, 0x0F, /* Attribute ID: Encryption Type */ - 0x00, 0x02, /* Attribute Length */ - 0x00, 0x01, /* Encryption Type: None */ - 0x10, 0x27 /* Attribute ID: Network Key */ -}; - -static uint8_t wifiConfigToken5[] = { - 0x10, 0x20, /* Attribute ID: MAC Address */ - 0x00, 0x06, /* Attribute Length */ - 0, /* MAC-ADDRESS */ - 0, /* MAC-ADDRESS */ - 0, /* MAC-ADDRESS */ - 0, /* MAC-ADDRESS */ - 0, /* MAC-ADDRESS */ - 0, /* MAC-ADDRESS */ - 0x10, 0x49, /* Attribute ID: Vendor Extension */ - 0x00, 0x06, /* Attribute Length */ - 0x00, 0x37, 0x2A, /* Vendor ID: WFA */ - 0x02, /* Subelement ID:Network Key Shareable */ - 0x01, /* Subelement Length */ - 0x01, /* Network Key Shareable: TRUE */ - 0x10, 0x49, /* Attribute ID: Vendor Extension */ - 0x00, 0x06, /* Attribute Length */ - 0x00, 0x37, 0x2A, /* Vendor ID: WFA */ - 0x00, /* Subelement ID: Version2 */ - 0x01, /* Subelement Length: 1 */ - 0x20 /* Version 2 */ -}; - - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - -/*****************************************************************************/ -/*! Manage a Wifi Out-Of-Band NDEF message, to start a communication based on Wifi. - * The Wifi OOB format is described by the Wifi Protected Setup specification. - * It consists in a list of data elements formated as type-length-value. - - The Wifi OOB in a NDEF record has the following structure: - - Version - - Credential - - Network index - - SSID - - Authentication Type - - Encryption Type - - Network Key - - MAC Address - - Vendor Extension - - Network Key Shareable - - Vendor Extension - - Version2 - - Note: If the `Network key` is set to an empty buffer, the library sets it to "0x00000000" - Even if 0-length Network Key is supposed to be supported, smartphones dont necessarily accept it. - */ - - -/*****************************************************************************/ -static uint32_t ndefWifiPayloadGetLength(const ndefType* wifi) -{ - const ndefTypeWifi* wifiData; - uint32_t payloadLength; - - if ( (wifi == NULL) || (wifi->id != NDEF_TYPE_MEDIA_WIFI) ) - { - return 0; - } - - wifiData = &wifi->data.wifi; - - payloadLength = sizeof(wifiConfigToken1) - + WIFI_SSID_TYPE_LENGTH + wifiData->bufNetworkSSID.length - + sizeof(wifiConfigToken3) - + WIFI_SSID_KEY_TYPE_LENGTH + wifiData->bufNetworkKey.length - + sizeof(wifiConfigToken5); - - return payloadLength; -} - - -/*****************************************************************************/ -static const uint8_t* ndefWifiToPayloadItem(const ndefType* wifi, ndefConstBuffer* bufItem, bool begin) -{ - static uint32_t item = 0; - const ndefTypeWifi* wifiData; - uint16_t credentialLength; - - uint8_t defaultKey[4] = {0, 0, 0, 0}; - ndefConstBuffer8 bufDefaultNetworkKey = { defaultKey, sizeof(defaultKey) }; - - const uint8_t CONFIG_TOKEN_1_CREDENTIAL_LENGTH_INDEX = 7U; - const uint8_t CONFIG_TOKEN_3_AUTHENTICATION_TYPE_INDEX = 5U; - const uint8_t CONFIG_TOKEN_3_ENCRYPTION_TYPE_INDEX = 11U; - - static uint8_t zero[] = { 0 }; - static ndefConstBuffer8 bufZero = { zero, sizeof(zero) }; - - if ( (wifi == NULL) || (wifi->id != NDEF_TYPE_MEDIA_WIFI) || - (bufItem == NULL) ) - { - return NULL; - } - - wifiData = &wifi->data.wifi; - - if (begin == true) - { - item = 0; - } - - bufItem->buffer = NULL; - bufItem->length = 0; - - switch (item) - { - case 0: - /* Config Token1 */ - - /* Update Token1 with credential length */ - credentialLength = (uint16_t)(5U + /* Network index */ - 2U + /* SSID type */ - 2U + /* SSID key length */ - wifiData->bufNetworkSSID.length + /* SSID key */ - sizeof(wifiConfigToken3) + /* Token3 length */ - 2U + /* Network key length */ - wifiData->bufNetworkKey.length + /* Network key */ - sizeof(wifiConfigToken5)); /* Token5 length */ - - wifiConfigToken1[CONFIG_TOKEN_1_CREDENTIAL_LENGTH_INDEX] = (uint8_t)(credentialLength >> 8U); - wifiConfigToken1[CONFIG_TOKEN_1_CREDENTIAL_LENGTH_INDEX + 1U] = (uint8_t)(credentialLength & 0xFFU); - - bufItem->buffer = wifiConfigToken1; - bufItem->length = sizeof(wifiConfigToken1); - break; - - case 1: - /* SSID Length (1st byte) */ - bufItem->buffer = bufZero.buffer; - bufItem->length = bufZero.length; - break; - - case 2: - /* SSID Length (2nd byte) */ - bufItem->buffer = (const uint8_t*)&wifiData->bufNetworkSSID.length; - bufItem->length = 1U; - break; - - case 3: - /* SSID Value */ - bufItem->buffer = wifiData->bufNetworkSSID.buffer; - bufItem->length = wifiData->bufNetworkSSID.length; - break; - - case 4: - /* Config Token3 */ - - /* Update Token3 with Autentication and Encryption Types */ - wifiConfigToken3[CONFIG_TOKEN_3_AUTHENTICATION_TYPE_INDEX] = wifiData->authentication; - wifiConfigToken3[CONFIG_TOKEN_3_ENCRYPTION_TYPE_INDEX] = wifiData->encryption; - - bufItem->buffer = wifiConfigToken3; - bufItem->length = sizeof(wifiConfigToken3); - break; - - case 5: - /* SSID Key Length (1st byte) */ - bufItem->buffer = bufZero.buffer; - bufItem->length = bufZero.length; - break; - - case 6: - /* SSID Key Length (2 bytes) */ - bufItem->buffer = (const uint8_t*)&wifiData->bufNetworkKey.length; - bufItem->length = 1U; - break; - - case 7: - /* SSID Key Value */ - if(wifiData->bufNetworkKey.length == 0U) - { - /* Empty network key is not supported by Phones */ - bufItem->buffer = bufDefaultNetworkKey.buffer; - bufItem->length = bufDefaultNetworkKey.length; - } - else - { - bufItem->buffer = wifiData->bufNetworkKey.buffer; - bufItem->length = wifiData->bufNetworkKey.length; - } - break; - - case 8: - /* Config Token5 */ - bufItem->buffer = wifiConfigToken5; - bufItem->length = sizeof(wifiConfigToken5); - break; - - default: - bufItem->buffer = NULL; - bufItem->length = 0; - break; - } - - /* Move to next item for next call */ - item++; - - return bufItem->buffer; -} - - -/*****************************************************************************/ -ReturnCode ndefWifi(ndefType* wifi, const ndefTypeWifi* wifiConfig) -{ - ndefTypeWifi* wifiData; - - if ( (wifi == NULL) || (wifiConfig == NULL) ) - { - return ERR_PARAM; - } - - wifi->id = NDEF_TYPE_MEDIA_WIFI; - wifi->getPayloadLength = ndefWifiPayloadGetLength; - wifi->getPayloadItem = ndefWifiToPayloadItem; - wifiData = &wifi->data.wifi; - - wifiData->bufNetworkSSID = wifiConfig->bufNetworkSSID; - wifiData->bufNetworkKey = wifiConfig->bufNetworkKey; - wifiData->authentication = wifiConfig->authentication; - wifiData->encryption = wifiConfig->encryption; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefGetWifi(const ndefType* wifi, ndefTypeWifi* wifiConfig) -{ - const ndefTypeWifi* wifiData; - - if ( (wifi == NULL) || (wifi->id != NDEF_TYPE_MEDIA_WIFI) || - (wifiConfig == NULL) ) - { - return ERR_PARAM; - } - - wifiData = &wifi->data.wifi; - - wifiConfig->bufNetworkSSID.buffer = wifiData->bufNetworkSSID.buffer; - wifiConfig->bufNetworkSSID.length = wifiData->bufNetworkSSID.length; - wifiConfig->bufNetworkKey.buffer = wifiData->bufNetworkKey.buffer; - wifiConfig->bufNetworkKey.length = wifiData->bufNetworkKey.length; - wifiConfig->authentication = wifiData->authentication; - wifiConfig->encryption = wifiData->encryption; - - return ERR_NONE; -} - - -/*****************************************************************************/ -static ReturnCode ndefPayloadToWifi(const ndefConstBuffer* bufPayload, ndefType* wifi) -{ - ndefTypeWifi wifiConfig; - uint32_t offset; - - if ( (bufPayload == NULL) || (wifi == NULL) ) - { - return ERR_PARAM; - } - - wifiConfig.bufNetworkSSID.buffer = NULL; - wifiConfig.bufNetworkSSID.length = 0; - wifiConfig.bufNetworkKey.buffer = NULL; - wifiConfig.bufNetworkKey.length = 0; - wifiConfig.authentication = 0; - wifiConfig.encryption = 0; - - offset = 0; - while (offset < bufPayload->length) - { - uint8_t attribute = bufPayload->buffer[offset]; - if (attribute == NDEF_WIFI_ATTRIBUTE_ID_SSID_LSB) - { - uint8_t data1 = bufPayload->buffer[offset + NDEF_WIFI_ATTRIBUTE_LENGTH_MSB_OFFSET]; - uint8_t data2 = bufPayload->buffer[offset + NDEF_WIFI_ATTRIBUTE_LENGTH_LSB_OFFSET]; - uint32_t length = ((uint32_t)data1 << 8U) | data2; - - switch (bufPayload->buffer[offset + NDEF_WIFI_ATTRIBUTE_ID_OFFSET]) - { - case NDEF_WIFI_ATTRIBUTE_ID_SSID_MSB: - /* Network SSID */ - if (length > NDEF_WIFI_NETWORK_SSID_LENGTH) - { - return ERR_PROTO; - } - wifiConfig.bufNetworkSSID.buffer = &bufPayload->buffer[offset + NDEF_WIFI_ATTRIBUTE_DATA_OFFSET]; - wifiConfig.bufNetworkSSID.length = length; - offset += (NDEF_WIFI_ATTRIBUTE_DATA_OFFSET + length); - break; - case NDEF_WIFI_ATTRIBUTE_ID_NETWORK_MSB: - /* Network key */ - if (length > NDEF_WIFI_NETWORK_KEY_LENGTH) - { - return ERR_PROTO; - } - wifiConfig.bufNetworkKey.buffer = &bufPayload->buffer[offset + NDEF_WIFI_ATTRIBUTE_DATA_OFFSET]; - wifiConfig.bufNetworkKey.length = length; - offset += (NDEF_WIFI_ATTRIBUTE_DATA_OFFSET + length); - break; - case NDEF_WIFI_ATTRIBUTE_AUTHENTICATION: - /* Authentication */ - if (length != NDEF_WIFI_AUTHENTICATION_TYPE_LENGTH) - { - return ERR_PROTO; - } - wifiConfig.authentication = bufPayload->buffer[offset + NDEF_WIFI_ATTRIBUTE_AUTHENTICATION_LSB_OFFSET]; - offset += (NDEF_WIFI_ATTRIBUTE_DATA_OFFSET + length); - break; - case NDEF_WIFI_ATTRIBUTE_ENCRYPTION: - /* Encryption */ - if (length != NDEF_WIFI_ENCRYPTION_TYPE_LENGTH) - { - return ERR_PROTO; - } - wifiConfig.encryption = bufPayload->buffer[offset + NDEF_WIFI_ATTRIBUTE_ENCRYPTION_LSB_OFFSET]; - offset += (NDEF_WIFI_ATTRIBUTE_DATA_OFFSET + length); - break; - default: - offset++; - break; - } - } - else - { - offset++; - } - } - - return ndefWifi(wifi, &wifiConfig); -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToWifi(const ndefRecord* record, ndefType* wifi) -{ - const ndefType* ndeftype; - - if ( (record == NULL) || (wifi == NULL) ) - { - return ERR_PARAM; - } - - if ( ! ndefRecordTypeMatch(record, NDEF_TNF_MEDIA_TYPE, &bufMediaTypeWifi)) /* "application/vnd.wfa.wsc" */ - { - return ERR_PROTO; - } - - ndeftype = ndefRecordGetNdefType(record); - if (ndeftype != NULL) - { - (void)ST_MEMCPY(wifi, ndeftype, sizeof(ndefType)); - return ERR_NONE; - } - - return ndefPayloadToWifi(&record->bufPayload, wifi); -} - - -/*****************************************************************************/ -ReturnCode ndefWifiToRecord(const ndefType* wifi, ndefRecord* record) -{ - if ( (wifi == NULL) || (wifi->id != NDEF_TYPE_MEDIA_WIFI) || - (record == NULL) ) - { - return ERR_PARAM; - } - - (void)ndefRecordReset(record); - - (void)ndefRecordSetType(record, NDEF_TNF_MEDIA_TYPE, &bufMediaTypeWifi); - - (void)ndefRecordSetNdefType(record, wifi); - - return ERR_NONE; -} diff --git a/Software/Middlewares/ST/ndef/Src/message/ndef_types.c b/Software/Middlewares/ST/ndef/Src/message/ndef_types.c deleted file mode 100644 index e5f3a41..0000000 --- a/Software/Middlewares/ST/ndef/Src/message/ndef_types.c +++ /dev/null @@ -1,321 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF RTD and MIME types - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "platform.h" -#include "st_errno.h" -#include "utils.h" -#include "ndef_record.h" -#include "ndef_types.h" -#include "ndef_types_rtd.h" -#include "ndef_types_mime.h" -#include "ndef_type_wifi.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - - -/*! NDEF type table to associate a ndefTypeId and a string */ -typedef struct -{ - ndefTypeId typeId; /*!< NDEF Type Id */ - uint8_t tnf; /*!< TNF */ - const ndefConstBuffer8* bufTypeString; /*!< Type String buffer */ -} ndefTypeTable; - - -/*! Type wrapper to function pointers */ -typedef struct -{ - ndefTypeId typeId; /*!< NDEF Type Id */ - ReturnCode (*recordToType)(const ndefRecord* record, ndefType* type); /*!< Pointer to read function */ - ReturnCode (*typeToRecord)(const ndefType* type, ndefRecord* record); /*!< Pointer to write function */ -} ndefTypeConverter; - - -/*! Array to match RTD strings with Well-known types, and converting functions */ -static const ndefTypeConverter typeConverterTable[] = -{ - { NDEF_TYPE_EMPTY, ndefRecordToEmptyType, ndefEmptyTypeToRecord }, - { NDEF_TYPE_RTD_DEVICE_INFO, ndefRecordToRtdDeviceInfo, ndefRtdDeviceInfoToRecord }, - { NDEF_TYPE_RTD_TEXT, ndefRecordToRtdText, ndefRtdTextToRecord }, - { NDEF_TYPE_RTD_URI, ndefRecordToRtdUri, ndefRtdUriToRecord }, - { NDEF_TYPE_RTD_AAR, ndefRecordToRtdAar, ndefRtdAarToRecord }, - { NDEF_TYPE_MEDIA_VCARD, ndefRecordToVCard, ndefVCardToRecord }, - { NDEF_TYPE_MEDIA_WIFI, ndefRecordToWifi, ndefWifiToRecord }, -}; - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - -/*****************************************************************************/ -static ReturnCode ndefTypeStringToTypeId(uint8_t tnf, const ndefConstBuffer8* bufTypeString, ndefTypeId* typeId) -{ - /*! Empty string */ - static const uint8_t ndefTypeEmpty[] = ""; /*!< Empty string */ - static ndefConstBuffer8 bufTypeEmpty = { ndefTypeEmpty, sizeof(ndefTypeEmpty) - 1U }; - - // TODO Transform the enum (u32) to defines (u8), re-order to u32-u8-u8 to compact buffer ! - static const ndefTypeTable typeTable[] = - { - { NDEF_TYPE_EMPTY, NDEF_TNF_EMPTY, &bufTypeEmpty }, - { NDEF_TYPE_RTD_DEVICE_INFO, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeDeviceInfo }, - { NDEF_TYPE_RTD_TEXT, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeText }, - { NDEF_TYPE_RTD_URI, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeUri }, - { NDEF_TYPE_RTD_AAR, NDEF_TNF_RTD_EXTERNAL_TYPE, &bufRtdTypeAar }, - { NDEF_TYPE_MEDIA_VCARD, NDEF_TNF_MEDIA_TYPE, &bufMediaTypeVCard }, - { NDEF_TYPE_MEDIA_WIFI, NDEF_TNF_MEDIA_TYPE, &bufMediaTypeWifi }, - }; - - uint32_t i; - - if ( (bufTypeString == NULL) || (typeId == NULL) ) - { - return ERR_PROTO; - } - - for (i = 0; i < SIZEOF_ARRAY(typeTable); i++) - { - /* Check TNF and length are the same, then compare the content */ - if (typeTable[i].tnf == tnf) - { - if (bufTypeString->length == typeTable[i].bufTypeString->length) - { - if (bufTypeString->length == 0U) - { - /* Empty type */ - *typeId = typeTable[i].typeId; - return ERR_NONE; - } - else - { - if (ST_BYTECMP(typeTable[i].bufTypeString->buffer, bufTypeString->buffer, bufTypeString->length) == 0) - { - *typeId = typeTable[i].typeId; - return ERR_NONE; - } - } - } - } - } - - return ERR_NOTFOUND; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordTypeStringToTypeId(const ndefRecord* record, ndefTypeId* typeId) -{ - ReturnCode err; - - uint8_t tnf; - ndefConstBuffer8 bufRecordType; - - if ( (record == NULL) || (typeId == NULL) ) - { - return ERR_PARAM; - } - - err = ndefRecordGetType(record, &tnf, &bufRecordType); - if (err != ERR_NONE) - { - return err; - } - if (tnf >= NDEF_TNF_RESERVED) - { - return ERR_INTERNAL; - } - - switch (tnf) - { - case NDEF_TNF_EMPTY: /* Fall through */ - case NDEF_TNF_RTD_WELL_KNOWN_TYPE: /* Fall through */ - case NDEF_TNF_RTD_EXTERNAL_TYPE: /* Fall through */ - case NDEF_TNF_MEDIA_TYPE: /* Fall through */ - err = ndefTypeStringToTypeId(tnf, &bufRecordType, typeId); - break; - default: - err = ERR_NOT_IMPLEMENTED; - break; - } - - return err; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToType(const ndefRecord* record, ndefType* type) -{ - const ndefType* ndeftype; - ReturnCode err; - ndefTypeId typeId; - uint32_t i; - - ndeftype = ndefRecordGetNdefType(record); - if (ndeftype != NULL) - { - /* Return the well-known type contained in the record */ - (void)ST_MEMCPY(type, ndeftype, sizeof(ndefType)); - return ERR_NONE; - } - - err = ndefRecordTypeStringToTypeId(record, &typeId); - if (err != ERR_NONE) - { - return err; - } - - for (i = 0; i < SIZEOF_ARRAY(typeConverterTable); i++) - { - if (typeId == typeConverterTable[i].typeId) - { - /* Call the appropriate function to the matching type */ - if (typeConverterTable[i].recordToType != NULL) - { - return typeConverterTable[i].recordToType(record, type); - } - } - } - - return ERR_NOT_IMPLEMENTED; -} - - -/*****************************************************************************/ -ReturnCode ndefTypeToRecord(const ndefType* type, ndefRecord* record) -{ - uint32_t i; - - if (type == NULL) - { - return ERR_PARAM; - } - - for (i = 0; i < SIZEOF_ARRAY(typeConverterTable); i++) - { - if (type->id == typeConverterTable[i].typeId) - { - /* Call the appropriate function to the matching type */ - if (typeConverterTable[i].typeToRecord != NULL) - { - return typeConverterTable[i].typeToRecord(type, record); - } - } - } - - return ERR_NOT_IMPLEMENTED; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordSetNdefType(ndefRecord* record, const ndefType* type) -{ - uint32_t payloadLength; - - if ( (record == NULL) || - (type == NULL) || - (type->id > NDEF_TYPE_ID_COUNT) || - (type->getPayloadLength == NULL) || - (type->getPayloadItem == NULL) ) - { - return ERR_PARAM; - } - - record->ndeftype = type; - - /* Set Short Record bit accordingly */ - payloadLength = ndefRecordGetPayloadLength(record); - ndefHeaderSetValueSR(record, (payloadLength <= NDEF_SHORT_RECORD_LENGTH_MAX) ? 1 : 0); - - return ERR_NONE; -} - - -/*****************************************************************************/ -const ndefType* ndefRecordGetNdefType(const ndefRecord* record) -{ - if (record == NULL) - { - return NULL; - } - - if (record->ndeftype != NULL) - { - /* Check whether it is a valid NDEF type */ - if ( (record->ndeftype->id < NDEF_TYPE_ID_COUNT) && - (record->ndeftype->getPayloadItem != NULL) && - (record->ndeftype->getPayloadLength != NULL) ) - { - return record->ndeftype; - } - } - - return NULL; -} diff --git a/Software/Middlewares/ST/ndef/Src/message/ndef_types_mime.c b/Software/Middlewares/ST/ndef/Src/message/ndef_types_mime.c deleted file mode 100644 index f93ce16..0000000 --- a/Software/Middlewares/ST/ndef/Src/message/ndef_types_mime.c +++ /dev/null @@ -1,766 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF MIME types - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - - -#include "platform.h" -#include "st_errno.h" -#include "utils.h" -#include "ndef_record.h" -#include "ndef_types.h" -#include "ndef_types_mime.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - - -/*! Media Type strings */ -static const uint8_t ndefMediaTypeVCard[] = "text/x-vCard"; /*!< vCard Type */ - -const ndefConstBuffer8 bufMediaTypeVCard = { ndefMediaTypeVCard, sizeof(ndefMediaTypeVCard) - 1U }; /*!< vCard Type buffer */ - - -/*! vCard delimiters */ -static const uint8_t COLON[] = ":"; -static const uint8_t SEMICOLON[] = ";"; -static const uint8_t NEWLINE[] = "\r\n"; - -static const ndefConstBuffer bufDelimiterColon = { COLON, sizeof(COLON) - 1U }; /*!< ":" */ -static const ndefConstBuffer bufDelimiterSemicolon = { SEMICOLON, sizeof(SEMICOLON) - 1U }; /*!< ";" */ -static const ndefConstBuffer bufDelimiterNewLine = { NEWLINE, sizeof(NEWLINE) - 1U}; /*!< "\r\n" */ - -/*! vCard keyword types */ -static const uint8_t TYPE_BEGIN[] = "BEGIN"; -static const uint8_t TYPE_END[] = "END"; -static const uint8_t TYPE_VERSION[] = "VERSION"; -static const uint8_t VALUE_VCARD[] = "VCARD"; -static const uint8_t VALUE_2_1[] = "2.1"; - -static const ndefConstBuffer bufTypeBegin = { TYPE_BEGIN, sizeof(TYPE_BEGIN) - 1U }; /*!< "BEGIN" */ -static const ndefConstBuffer bufTypeEnd = { TYPE_END, sizeof(TYPE_END) - 1U }; /*!< "END" */ -static const ndefConstBuffer bufTypeVersion = { TYPE_VERSION, sizeof(TYPE_VERSION) - 1U }; /*!< "VERSION" */ -static const ndefConstBuffer bufValueVCard = { VALUE_VCARD, sizeof(VALUE_VCARD) - 1U }; /*!< "VCARD" */ -static const ndefConstBuffer bufValue_2_1 = { VALUE_2_1, sizeof(VALUE_2_1) - 1U }; /*!< "2.1" */ - - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - -/* - * Media - */ - - -/*****************************************************************************/ -ReturnCode ndefMedia(ndefType* media, const ndefConstBuffer8* bufType, const ndefConstBuffer* bufPayload) -{ - ndefTypeMedia* typeMedia; - - if ( (media == NULL) || - (bufType == NULL) || (bufType->buffer == NULL) || (bufType->length == 0U) || - (bufPayload == NULL) || (bufPayload->buffer == NULL) || (bufPayload->length == 0U) ) - { - return ERR_PARAM; - } - - media->id = NDEF_TYPE_MEDIA; - media->getPayloadLength = NULL; - media->getPayloadItem = NULL; - typeMedia = &media->data.media; - - typeMedia->bufType.buffer = bufType->buffer; - typeMedia->bufType.length = bufType->length; - typeMedia->bufPayload.buffer = bufPayload->buffer; - typeMedia->bufPayload.length = bufPayload->length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefGetMedia(const ndefType* media, ndefConstBuffer8* bufType, ndefConstBuffer* bufPayload) -{ - const ndefTypeMedia* typeMedia; - - if ( (media == NULL) || (media->id != NDEF_TYPE_MEDIA) || - (bufType == NULL) || (bufPayload == NULL) ) - { - return ERR_PARAM; - } - - typeMedia = &media->data.media; - - bufType->buffer = typeMedia->bufType.buffer; - bufType->length = typeMedia->bufType.length; - - bufPayload->buffer = typeMedia->bufPayload.buffer; - bufPayload->length = typeMedia->bufPayload.length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToMedia(const ndefRecord* record, ndefType* media) -{ - const ndefType* ndeftype; - ndefConstBuffer8 bufType; - - if ( (record == NULL) || (media == NULL) ) - { - return ERR_PARAM; - } - - if (ndefHeaderTNF(record) != NDEF_TNF_MEDIA_TYPE) - { - return ERR_PROTO; - } - - ndeftype = ndefRecordGetNdefType(record); - if (ndeftype != NULL) - { - (void)ST_MEMCPY(media, ndeftype, sizeof(ndefType)); - return ERR_NONE; - } - - bufType.buffer = record->type; - bufType.length = record->typeLength; - - return ndefMedia(media, &bufType, &record->bufPayload); -} - - -/*****************************************************************************/ -ReturnCode ndefMediaToRecord(const ndefType* media, ndefRecord* record) -{ - const ndefTypeMedia* typeMedia; - - if ( (media == NULL) || (media->id != NDEF_TYPE_MEDIA) || - (record == NULL) ) - { - return ERR_PARAM; - } - - typeMedia = &media->data.media; - - (void)ndefRecordReset(record); - - (void)ndefRecordSetType(record, NDEF_TNF_MEDIA_TYPE, &typeMedia->bufType); - - (void)ndefRecordSetPayload(record, &typeMedia->bufPayload); - - return ERR_NONE; -} - - -/* - * VCard - */ - - -/*****************************************************************************/ -static uint32_t ndefVCardPayloadGetLength(const ndefType* vCard) -{ - const ndefTypeVCard* vCardData; - uint32_t payloadLength = 0; - uint32_t i; - - if ( (vCard == NULL) || (vCard->id != NDEF_TYPE_MEDIA_VCARD) ) - { - return 0; - } - - vCardData = &vCard->data.vCard; - - payloadLength += bufTypeBegin.length; - payloadLength += bufDelimiterColon.length; - payloadLength += bufValueVCard.length; - payloadLength += bufDelimiterNewLine.length; - - payloadLength += bufTypeVersion.length; - payloadLength += bufDelimiterColon.length; - payloadLength += bufValue_2_1.length; - payloadLength += bufDelimiterNewLine.length; - - i = 0; - while (vCardData->entry[i].bufTypeBuffer != NULL) - { - payloadLength += vCardData->entry[i].bufTypeLength; - - if (vCardData->entry[i].bufSubTypeBuffer != NULL) - { - payloadLength += bufDelimiterSemicolon.length; - payloadLength += vCardData->entry[i].bufSubTypeLength; - } - - payloadLength += bufDelimiterColon.length; - - payloadLength += vCardData->entry[i].bufValueLength; - payloadLength += bufDelimiterNewLine.length; - - i++; - } - - payloadLength += bufTypeEnd.length; - payloadLength += bufDelimiterColon.length; - payloadLength += bufValueVCard.length; - /* No New line after "END:VCARD" */ - - return payloadLength; -} - - -/*****************************************************************************/ -static const uint8_t* ndefVCardToPayloadItem(const ndefType* vCard, ndefConstBuffer* bufItem, bool begin) -{ - static uint32_t item = 0; - static uint32_t userItem = 0; - static uint32_t index = 0; - const ndefTypeVCard* vCardData; - - if ( (vCard == NULL) || (vCard->id != NDEF_TYPE_MEDIA_VCARD) || - (bufItem == NULL) ) - { - return NULL; - } - - vCardData = &vCard->data.vCard; - - if (begin == true) - { - item = 0; - userItem = 0; - index = 0; - } - - bufItem->buffer = NULL; - bufItem->length = 0; - - /* Check for for empty vCard */ - if (vCardData->entry[0].bufTypeBuffer == NULL) - { - return NULL; - } - - switch (item) - { - /* BEGIN:VCARD\r\n */ - case 0: - bufItem->buffer = bufTypeBegin.buffer; - bufItem->length = bufTypeBegin.length; - item++; /* Move to next item for next call */ - break; - case 1: - bufItem->buffer = bufDelimiterColon.buffer; - bufItem->length = bufDelimiterColon.length; - item++; /* Move to next item for next call */ - break; - case 2: - bufItem->buffer = bufValueVCard.buffer; - bufItem->length = bufValueVCard.length; - item++; /* Move to next item for next call */ - break; - case 3: - bufItem->buffer = bufDelimiterNewLine.buffer; - bufItem->length = bufDelimiterNewLine.length; - item++; /* Move to next item for next call */ - break; - - /* VERSION:2.1\r\n */ - case 4: - bufItem->buffer = bufTypeVersion.buffer; - bufItem->length = bufTypeVersion.length; - item++; /* Move to next item for next call */ - break; - case 5: - bufItem->buffer = bufDelimiterColon.buffer; - bufItem->length = bufDelimiterColon.length; - item++; /* Move to next item for next call */ - break; - case 6: - bufItem->buffer = bufValue_2_1.buffer; - bufItem->length = bufValue_2_1.length; - item++; /* Move to next item for next call */ - break; - case 7: - bufItem->buffer = bufDelimiterNewLine.buffer; - bufItem->length = bufDelimiterNewLine.length; - item++; /* Move to next item for next call */ - userItem = 0; - index = 0; - break; - case 8: - /* User data */ - switch (userItem) - { - case 0: - /* Type */ - if (vCardData->entry[index].bufTypeBuffer == NULL) - { - bufItem->buffer = bufTypeEnd.buffer; - bufItem->length = bufTypeEnd.length; - item++; /* Exit the user item loop */ - break; - } - bufItem->buffer = vCardData->entry[index].bufTypeBuffer; - bufItem->length = vCardData->entry[index].bufTypeLength; - - if (vCardData->entry[index].bufSubTypeBuffer != NULL) - { - userItem++; - } - else - { - userItem += 3U; /* Skip sending semicolon and subtype, move to colon */ - } - break; - case 1: - bufItem->buffer = bufDelimiterSemicolon.buffer; - bufItem->length = bufDelimiterSemicolon.length; - userItem++; - break; - case 2: - /* Subtype */ - bufItem->buffer = vCardData->entry[index].bufSubTypeBuffer; - bufItem->length = vCardData->entry[index].bufSubTypeLength; - userItem++; - break; - case 3: - bufItem->buffer = bufDelimiterColon.buffer; - bufItem->length = bufDelimiterColon.length; - userItem++; - break; - case 4: - /* Value */ - bufItem->buffer = vCardData->entry[index].bufValueBuffer; - bufItem->length = vCardData->entry[index].bufValueLength; - userItem++; - break; - case 5: - bufItem->buffer = bufDelimiterNewLine.buffer; - bufItem->length = bufDelimiterNewLine.length; - index++; - userItem = 0; /* Looping to case 0 */ - break; - default: - /* MISRA 16.4: mandatory default statement */ - break; - } - break; - case 9: - bufItem->buffer = bufDelimiterColon.buffer; - bufItem->length = bufDelimiterColon.length; - item++; /* Move to next item for next call */ - break; - case 10: - bufItem->buffer = bufValueVCard.buffer; - bufItem->length = bufValueVCard.length; - item++; /* Move to next item for next call */ - break; - default: - bufItem->buffer = NULL; - bufItem->length = 0; - break; - } - - return bufItem->buffer; -} - - -/*****************************************************************************/ -ReturnCode ndefVCard(ndefType* vCard, const ndefVCardInput* bufVCardInput, uint32_t bufVCardInputCount) -{ - ndefTypeVCard* vCardData; - uint32_t i; - - if ( (vCard == NULL) || (bufVCardInput == NULL) || - (bufVCardInputCount == 0U) || (bufVCardInputCount > NDEF_VCARD_ENTRY_MAX) ) - { - return ERR_PARAM; - } - - vCard->id = NDEF_TYPE_MEDIA_VCARD; - vCard->getPayloadLength = ndefVCardPayloadGetLength; - vCard->getPayloadItem = ndefVCardToPayloadItem; - vCardData = &vCard->data.vCard; - - /* Initialize array */ - for (i = 0; i < NDEF_VCARD_ENTRY_MAX; i++) - { - vCardData->entry[i].bufTypeBuffer = NULL; - vCardData->entry[i].bufTypeLength = 0; - vCardData->entry[i].bufSubTypeBuffer = NULL; - vCardData->entry[i].bufSubTypeLength = 0; - vCardData->entry[i].bufValueBuffer = NULL; - vCardData->entry[i].bufValueLength = 0; - } - - /* Pointer to user input */ - for (i = 0; i < bufVCardInputCount; i++) - { - vCardData->entry[i].bufTypeBuffer = bufVCardInput[i].bufType->buffer; - vCardData->entry[i].bufSubTypeBuffer = bufVCardInput[i].bufSubType->buffer; - vCardData->entry[i].bufValueBuffer = bufVCardInput[i].bufValue->buffer; - - vCardData->entry[i].bufTypeLength = (uint8_t)bufVCardInput[i].bufType->length; - vCardData->entry[i].bufSubTypeLength = (uint8_t)bufVCardInput[i].bufSubType->length; - vCardData->entry[i].bufValueLength = (uint16_t)bufVCardInput[i].bufValue->length; - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefGetVCard(const ndefType* vCard, const ndefConstBuffer* bufType, ndefConstBuffer* bufSubType, ndefConstBuffer* bufValue) -{ - const ndefTypeVCard* vCardData; - uint32_t i; - - if ( (vCard == NULL) || (vCard->id != NDEF_TYPE_MEDIA_VCARD) || - (bufType == NULL) || (bufSubType == NULL) || (bufValue == NULL) ) - { - return ERR_PARAM; - } - - vCardData = &vCard->data.vCard; - - bufSubType->buffer = NULL; - bufSubType->length = 0; - - bufValue->buffer = NULL; - bufValue->length = 0; - - for (i = 0; i < NDEF_VCARD_ENTRY_MAX; i++) - { - if ( (vCardData->entry[i].bufTypeLength != 0U) && - (vCardData->entry[i].bufTypeLength == bufType->length) ) - { - if (bufType->length > 0U) - { - if (ST_BYTECMP(vCardData->entry[i].bufTypeBuffer, bufType->buffer, bufType->length) == 0) - { - bufSubType->buffer = vCardData->entry[i].bufSubTypeBuffer; - bufSubType->length = vCardData->entry[i].bufSubTypeLength; - - bufValue->buffer = vCardData->entry[i].bufValueBuffer; - bufValue->length = vCardData->entry[i].bufValueLength; - - return ERR_NONE; - } - } - } - } - - return ERR_NOTFOUND; -} - - -/*****************************************************************************/ -static ReturnCode ndefVCardFindMarker(const ndefConstBuffer* bufPayload, const ndefConstBuffer* bufMarker, uint32_t* offset) -{ - uint32_t tempOffset; - - if ( (bufPayload == NULL) || (bufPayload->buffer == NULL) || - (bufMarker == NULL) || (bufMarker->buffer == NULL) || - (offset == NULL) ) - { - return ERR_PROTO; - } - - tempOffset = 0; - while (tempOffset < (bufPayload->length - bufMarker->length)) - { - if (bufMarker->length > 0U) - { - // TODO Convert To Upper to be case insensitive - if (ST_BYTECMP(&bufPayload->buffer[tempOffset], bufMarker->buffer, bufMarker->length) == 0) - { - *offset = tempOffset; - return ERR_NONE; - } - } - tempOffset++; - } - - return ERR_NOTFOUND; -} - - -/*****************************************************************************/ -static ReturnCode ndefVCardExtractLine(const ndefConstBuffer* bufPayload, const ndefConstBuffer* bufMarker, ndefConstBuffer* bufLine) -{ - ReturnCode err; - uint32_t markerOffset; - - if ( (bufPayload == NULL) || (bufPayload->buffer == NULL) || - (bufMarker == NULL) || (bufMarker->buffer == NULL) || - (bufLine == NULL) || (bufLine->buffer == NULL) ) - { - return ERR_PROTO; - } - - err = ndefVCardFindMarker(bufPayload, bufMarker, &markerOffset); - if (err == ERR_NONE) - { - /* Return up to the marker */ - bufLine->buffer = bufPayload->buffer; - bufLine->length = markerOffset; - } - else - { - /* Return up to the end of the payload */ - bufLine->buffer = bufPayload->buffer; - bufLine->length = bufPayload->length; - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -static ReturnCode ndefVCardParseLine(const ndefConstBuffer* bufLine, ndefVCardEntry* vCardEntry) -{ - ReturnCode err; - ndefConstBuffer bufKeyword; - uint32_t semicolonOffset; - uint32_t colonOffset; - - if ( (bufLine == NULL) || (bufLine->buffer == NULL) || (vCardEntry == NULL) ) - { - return ERR_PROTO; - } - - /* Look for the type delimiter colon ":" */ - err = ndefVCardFindMarker(bufLine, &bufDelimiterColon, &colonOffset); - if (err != ERR_NONE) - { - /* Invalid line */ - return err; - } - - /* Keyword is located at the begining of the line up to the delimiter colon */ - bufKeyword.buffer = bufLine->buffer; - bufKeyword.length = colonOffset; - - vCardEntry->bufTypeBuffer = bufLine->buffer; - vCardEntry->bufTypeLength = (uint8_t)colonOffset; - - /* Look for any subtype delimiter semicolon ";" */ - err = ndefVCardFindMarker(&bufKeyword, &bufDelimiterSemicolon, &semicolonOffset); - if (err == ERR_NONE) - { - /* Subtype found (remove the leading ";") */ - vCardEntry->bufSubTypeBuffer = &bufLine->buffer[semicolonOffset + 1U]; - vCardEntry->bufSubTypeLength = (uint8_t)(colonOffset - semicolonOffset - 1U); - - /* Adjust the Type length */ - vCardEntry->bufTypeLength -= vCardEntry->bufSubTypeLength + 1U; - } - - /* The value follows ":" until the end of the line */ - vCardEntry->bufValueBuffer = &bufLine->buffer[colonOffset + 1U]; - vCardEntry->bufValueLength = (uint16_t)(bufLine->length - colonOffset); - - return ERR_NONE; -} - - -/*****************************************************************************/ -static bool ndefIsVCardTypeFound(const ndefTypeVCard* vCard, const uint8_t* typeString) -{ - uint32_t i; - for (i = 0; i < NDEF_VCARD_ENTRY_MAX; i++) - { - if (vCard->entry[i].bufTypeLength > 0U) - { - if (ST_BYTECMP(typeString, vCard->entry[i].bufTypeBuffer, vCard->entry[i].bufTypeLength) == 0) - { - return true; - } - } - } - - return false; -} - - -/*****************************************************************************/ -static ReturnCode ndefPayloadToVcard(const ndefConstBuffer* bufPayload, ndefType* vCard) -{ - ReturnCode err; - ndefTypeVCard* vCardData; - - uint32_t i; - uint32_t offset; - uint32_t entry_count; - ndefConstBuffer bufLinePayload; - ndefConstBuffer bufLine; - - if ( (bufPayload == NULL) || (bufPayload->buffer == NULL) || (bufPayload->length == 0U) || - (vCard == NULL) ) - { - return ERR_PROTO; - } - - vCard->id = NDEF_TYPE_MEDIA_VCARD; - vCard->getPayloadLength = ndefVCardPayloadGetLength; - vCard->getPayloadItem = ndefVCardToPayloadItem; - vCardData = &vCard->data.vCard; - - /* Clear the vCard before parsing */ - for (i = 0; i < NDEF_VCARD_ENTRY_MAX; i++) - { - vCardData->entry[i].bufTypeBuffer = NULL; - vCardData->entry[i].bufTypeLength = 0; - vCardData->entry[i].bufSubTypeBuffer = NULL; - vCardData->entry[i].bufSubTypeLength = 0; - vCardData->entry[i].bufValueBuffer = NULL; - vCardData->entry[i].bufValueLength = 0; - } - - offset = 0; - entry_count = 0; - while ( (offset < bufPayload->length) && (entry_count < NDEF_VCARD_ENTRY_MAX) ) - { - /* Search an "end of line" or end of payload among the remaining to parse */ - bufLinePayload.buffer = &bufPayload->buffer[offset]; - bufLinePayload.length = bufPayload->length - offset; - - (void)ndefVCardExtractLine(&bufLinePayload, &bufDelimiterNewLine, &bufLine); - - /* Parse line and fill vCard entry */ - err = ndefVCardParseLine(&bufLine, &vCardData->entry[entry_count]); - if (err == ERR_NONE) - { - entry_count++; - } - - /* Move to the next line */ - offset += bufLine.length + bufDelimiterNewLine.length; - } - - /* Check BEGIN, VERSION and END types exist */ - if (ndefIsVCardTypeFound(vCardData, bufTypeBegin.buffer) == false) - { - return ERR_SYNTAX; - } - else if (ndefIsVCardTypeFound(vCardData, bufTypeVersion.buffer) == false) - { - return ERR_SYNTAX; - } - else if (ndefIsVCardTypeFound(vCardData, bufTypeEnd.buffer) == false) - { - return ERR_SYNTAX; - } - else - { - /* MISRA 15.7 - Empty else */ - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToVCard(const ndefRecord* record, ndefType* vCard) -{ - const ndefType* ndeftype; - - if ( (record == NULL) || (vCard == NULL) ) - { - return ERR_PARAM; - } - - if ( ! ndefRecordTypeMatch(record, NDEF_TNF_MEDIA_TYPE, &bufMediaTypeVCard)) /* "text/x-vCard" */ - { - return ERR_PROTO; - } - - ndeftype = ndefRecordGetNdefType(record); - if (ndeftype != NULL) - { - (void)ST_MEMCPY(vCard, ndeftype, sizeof(ndefType)); - return ERR_NONE; - } - - return ndefPayloadToVcard(&record->bufPayload, vCard); -} - - -/*****************************************************************************/ -ReturnCode ndefVCardToRecord(const ndefType* vCard, ndefRecord* record) -{ - if ( (vCard == NULL) || (vCard->id != NDEF_TYPE_MEDIA_VCARD) || - (record == NULL) ) - { - return ERR_PARAM; - } - - (void)ndefRecordReset(record); - - (void)ndefRecordSetType(record, NDEF_TNF_MEDIA_TYPE, &bufMediaTypeVCard); - - (void)ndefRecordSetNdefType(record, vCard); - - return ERR_NONE; -} diff --git a/Software/Middlewares/ST/ndef/Src/message/ndef_types_rtd.c b/Software/Middlewares/ST/ndef/Src/message/ndef_types_rtd.c deleted file mode 100644 index fe3ae0e..0000000 --- a/Software/Middlewares/ST/ndef/Src/message/ndef_types_rtd.c +++ /dev/null @@ -1,1167 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief NDEF RTD (well-known and external) types - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "platform.h" -#include "st_errno.h" -#include "utils.h" -#include "ndef_record.h" -#include "ndef_types.h" -#include "ndef_types_rtd.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -/*! Device Information defines */ -#define NDEF_RTD_DEVICE_INFO_PAYLOAD_MIN (2U * (sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint8_t))) /*!< Device Information minimum length (2 required TLV structures) */ -#define NDEF_RTD_DEVICE_INFO_PAYLOAD_MAX ((4U * (sizeof(uint8_t) + sizeof(uint8_t) + 255U)) + (sizeof(uint8_t) + sizeof(uint8_t) + 16U)) /*!< Device Information maximum length */ -#define NDEF_RTD_DEVICE_INFO_TLV_LENGTH_MIN (sizeof(uint8_t) + sizeof(uint8_t)) /*!< Device Information minimum TLV length */ - -/*! Text defines */ -#define NDEF_RTD_TEXT_STATUS_OFFSET 0U /*!< Text status offset */ -#define NDEF_RTD_TEXT_LANGUAGE_OFFSET 1U /*!< Text language offset */ - -#define NDEF_RTD_TEXT_LANGUAGE_CODE_LEN_MASK 0x3FU /*!< IANA language code mask (length coded on 6 bits) */ - -#define NDEF_RTD_TEXT_PAYLOAD_LENGTH_MIN (sizeof(uint8_t) + sizeof(uint8_t)) /*!< Minimum Text Payload length */ - -/*! URI defines */ -#define NDEF_RTD_URI_PROTOCOL_LEN 1U /*!< URI protocol length */ -#define NDEF_RTD_URI_PAYLOAD_LENGTH_MIN (NDEF_RTD_URI_PROTOCOL_LEN + sizeof(uint8_t)) /*!< URI minimum payload length */ - -/*! URI defines */ -#define NDEF_RTD_URI_ID_CODE_OFFSET 0U /*!< URI Id code offset */ -#define NDEF_RTD_URI_FIELD_OFFSET 1U /*!< URI field offset */ - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - - -/*! RTD Type strings */ -static const uint8_t ndefRtdTypeDeviceInfo[] = "Di"; /*!< Device Information Record Type {0x44, 0x69} */ -static const uint8_t ndefRtdTypeText[] = "T"; /*!< Text Record Type {0x54} */ -static const uint8_t ndefRtdTypeUri[] = "U"; /*!< URI Record Type {0x55} */ -static const uint8_t ndefRtdTypeAar[] = "android.com:pkg"; /*!< External Type (Android Application Record) */ - -const ndefConstBuffer8 bufRtdTypeDeviceInfo = { ndefRtdTypeDeviceInfo, sizeof(ndefRtdTypeDeviceInfo) - 1U }; /*!< Device Information Record Type buffer */ -const ndefConstBuffer8 bufRtdTypeText = { ndefRtdTypeText, sizeof(ndefRtdTypeText) - 1U }; /*!< Text Record Type buffer */ -const ndefConstBuffer8 bufRtdTypeUri = { ndefRtdTypeUri, sizeof(ndefRtdTypeUri) - 1U }; /*!< URI Record Type buffer */ -const ndefConstBuffer8 bufRtdTypeAar = { ndefRtdTypeAar, sizeof(ndefRtdTypeAar) - 1U }; /*!< AAR External Type Record buffer */ - - -/*! URI Type strings */ -static const uint8_t ndefUriPrefixNone[] = ""; -static const uint8_t ndefUriPrefixHttpWww[] = "http://www."; -static const uint8_t ndefUriPrefixHttpsWww[] = "https://www."; -static const uint8_t ndefUriPrefixHttp[] = "http://"; -static const uint8_t ndefUriPrefixHttps[] = "https://"; -static const uint8_t ndefUriPrefixTel[] = "tel:"; -static const uint8_t ndefUriPrefixMailto[] = "mailto:"; -static const uint8_t ndefUriPrefixFtpAnonymous[] = "ftp://anonymous:anonymous@"; -static const uint8_t ndefUriPrefixFtpFtp[] = "ftp://ftp."; -static const uint8_t ndefUriPrefixFtps[] = "ftps://"; -static const uint8_t ndefUriPrefixSftp[] = "sftp://"; -static const uint8_t ndefUriPrefixSmb[] = "smb://"; -static const uint8_t ndefUriPrefixNfs[] = "nfs://"; -static const uint8_t ndefUriPrefixFtp[] = "ftp://"; -static const uint8_t ndefUriPrefixDav[] = "dav://"; -static const uint8_t ndefUriPrefixNews[] = "news:"; -static const uint8_t ndefUriPrefixTelnet[] = "telnet://"; -static const uint8_t ndefUriPrefixImap[] = "imap:"; -static const uint8_t ndefUriPrefixRtsp[] = "rtsp://"; -static const uint8_t ndefUriPrefixUrn[] = "urn:"; -static const uint8_t ndefUriPrefixPop[] = "pop:"; -static const uint8_t ndefUriPrefixSip[] = "sip:"; -static const uint8_t ndefUriPrefixSips[] = "sips:"; -static const uint8_t ndefUriPrefixTftp[] = "tftp:"; -static const uint8_t ndefUriPrefixBtspp[] = "btspp://"; -static const uint8_t ndefUriPrefixBtl2cap[] = "btl2cap://"; -static const uint8_t ndefUriPrefixBtgoep[] = "btgoep://"; -static const uint8_t ndefUriPrefixTcpobex[] = "tcpobex://"; -static const uint8_t ndefUriPrefixIrdaobex[] = "irdaobex://"; -static const uint8_t ndefUriPrefixFile[] = "file://"; -static const uint8_t ndefUriPrefixUrnEpcId[] = "urn:epc:id:"; -static const uint8_t ndefUriPrefixUrnEpcTag[] = "urn:epc:tag"; -static const uint8_t ndefUriPrefixUrnEpcPat[] = "urn:epc:pat:"; -static const uint8_t ndefUriPrefixUrnEpcRaw[] = "urn:epc:raw:"; -static const uint8_t ndefUriPrefixUrnEpe[] = "urn:epc:"; -static const uint8_t ndefUriPrefixUrnNfc[] = "urn:nfc:"; -static const uint8_t ndefUriPrefixEmpty[] = ""; /* Autodetect filler */ - -static const ndefConstBuffer ndefUriPrefix[NDEF_URI_PREFIX_COUNT] = -{ - { ndefUriPrefixNone , sizeof(ndefUriPrefixNone ) - 1U }, - { ndefUriPrefixHttpWww , sizeof(ndefUriPrefixHttpWww ) - 1U }, - { ndefUriPrefixHttpsWww , sizeof(ndefUriPrefixHttpsWww ) - 1U }, - { ndefUriPrefixHttp , sizeof(ndefUriPrefixHttp ) - 1U }, - { ndefUriPrefixHttps , sizeof(ndefUriPrefixHttps ) - 1U }, - { ndefUriPrefixTel , sizeof(ndefUriPrefixTel ) - 1U }, - { ndefUriPrefixMailto , sizeof(ndefUriPrefixMailto ) - 1U }, - { ndefUriPrefixFtpAnonymous, sizeof(ndefUriPrefixFtpAnonymous) - 1U }, - { ndefUriPrefixFtpFtp , sizeof(ndefUriPrefixFtpFtp ) - 1U }, - { ndefUriPrefixFtps , sizeof(ndefUriPrefixFtps ) - 1U }, - { ndefUriPrefixSftp , sizeof(ndefUriPrefixSftp ) - 1U }, - { ndefUriPrefixSmb , sizeof(ndefUriPrefixSmb ) - 1U }, - { ndefUriPrefixNfs , sizeof(ndefUriPrefixNfs ) - 1U }, - { ndefUriPrefixFtp , sizeof(ndefUriPrefixFtp ) - 1U }, - { ndefUriPrefixDav , sizeof(ndefUriPrefixDav ) - 1U }, - { ndefUriPrefixNews , sizeof(ndefUriPrefixNews ) - 1U }, - { ndefUriPrefixTelnet , sizeof(ndefUriPrefixTelnet ) - 1U }, - { ndefUriPrefixImap , sizeof(ndefUriPrefixImap ) - 1U }, - { ndefUriPrefixRtsp , sizeof(ndefUriPrefixRtsp ) - 1U }, - { ndefUriPrefixUrn , sizeof(ndefUriPrefixUrn ) - 1U }, - { ndefUriPrefixPop , sizeof(ndefUriPrefixPop ) - 1U }, - { ndefUriPrefixSip , sizeof(ndefUriPrefixSip ) - 1U }, - { ndefUriPrefixSips , sizeof(ndefUriPrefixSips ) - 1U }, - { ndefUriPrefixTftp , sizeof(ndefUriPrefixTftp ) - 1U }, - { ndefUriPrefixBtspp , sizeof(ndefUriPrefixBtspp ) - 1U }, - { ndefUriPrefixBtl2cap , sizeof(ndefUriPrefixBtl2cap ) - 1U }, - { ndefUriPrefixBtgoep , sizeof(ndefUriPrefixBtgoep ) - 1U }, - { ndefUriPrefixTcpobex , sizeof(ndefUriPrefixTcpobex ) - 1U }, - { ndefUriPrefixIrdaobex , sizeof(ndefUriPrefixIrdaobex ) - 1U }, - { ndefUriPrefixFile , sizeof(ndefUriPrefixFile ) - 1U }, - { ndefUriPrefixUrnEpcId , sizeof(ndefUriPrefixUrnEpcId ) - 1U }, - { ndefUriPrefixUrnEpcTag , sizeof(ndefUriPrefixUrnEpcTag ) - 1U }, - { ndefUriPrefixUrnEpcPat , sizeof(ndefUriPrefixUrnEpcPat ) - 1U }, - { ndefUriPrefixUrnEpcRaw , sizeof(ndefUriPrefixUrnEpcRaw ) - 1U }, - { ndefUriPrefixUrnEpe , sizeof(ndefUriPrefixUrnEpe ) - 1U }, - { ndefUriPrefixUrnNfc , sizeof(ndefUriPrefixUrnNfc ) - 1U }, - { ndefUriPrefixEmpty , sizeof(ndefUriPrefixEmpty ) - 1U } -}; - - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - -/* - * Empty record - */ - - -/*****************************************************************************/ -static uint32_t ndefEmptyTypePayloadGetLength(const ndefType* empty) -{ - if ( (empty == NULL) || (empty->id != NDEF_TYPE_EMPTY) ) - { - return 0; - } - - return 0; -} - - -/*****************************************************************************/ -static const uint8_t* ndefEmptyTypePayloadItem(const ndefType* empty, ndefConstBuffer* bufItem, bool begin) -{ - if ( (empty == NULL) || (empty->id != NDEF_TYPE_EMPTY) ) - { - return NULL; - } - - NO_WARNING(begin); - - if (bufItem != NULL) - { - bufItem->buffer = NULL; - bufItem->length = 0; - } - - return NULL; -} - - -/*****************************************************************************/ -ReturnCode ndefEmptyType(ndefType* empty) -{ - if (empty == NULL) - { - return ERR_PARAM; - } - - empty->id = NDEF_TYPE_EMPTY; - empty->getPayloadLength = ndefEmptyTypePayloadGetLength; - empty->getPayloadItem = ndefEmptyTypePayloadItem; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToEmptyType(const ndefRecord* record, ndefType* empty) -{ - ndefConstBuffer8 bufEmpty = { NULL, 0 }; - - if ( (record == NULL) || (empty == NULL) ) - { - return ERR_PARAM; - } - - if ( ! ndefRecordTypeMatch(record, NDEF_TNF_EMPTY, &bufEmpty)) - { - return ERR_PARAM; - } - - if ( (record->idLength != 0U) || (record->id != NULL) || - (record->bufPayload.length != 0U) || (record->bufPayload.buffer != NULL) ) - { - return ERR_PARAM; - } - - return ndefEmptyType(empty); -} - - -/*****************************************************************************/ -ReturnCode ndefEmptyTypeToRecord(const ndefType* empty, ndefRecord* record) -{ - if ( (empty == NULL) || (empty->id != NDEF_TYPE_EMPTY) || - (record == NULL) ) - { - return ERR_PARAM; - } - - (void)ndefRecordReset(record); - - (void)ndefRecordSetNdefType(record, empty); - - return ERR_NONE; -} - - -/* - * Device Information - */ - - -/*****************************************************************************/ -static uint32_t ndefRtdDeviceInfoPayloadGetLength(const ndefType* devInfo) -{ - const ndefTypeRtdDeviceInfo* rtdDevInfo; - uint32_t payloadLength = 0; - uint32_t i; - - if ( (devInfo == NULL) || (devInfo->id != NDEF_TYPE_RTD_DEVICE_INFO) ) - { - return 0; - } - - rtdDevInfo = &devInfo->data.deviceInfo; - - for (i = 0; i < NDEF_DEVICE_INFO_TYPE_COUNT; i++) - { - if (rtdDevInfo->devInfo[i].length != 0U) - { - payloadLength += sizeof(rtdDevInfo->devInfo[i].type) + sizeof(rtdDevInfo->devInfo[i].length) + (uint32_t)rtdDevInfo->devInfo[i].length; - } - } - - return payloadLength; -} - - -/*****************************************************************************/ -static const uint8_t* ndefRtdDeviceInfoToPayloadItem(const ndefType* devInfo, ndefConstBuffer* bufItem, bool begin) -{ - static uint32_t item = 0; - const ndefTypeRtdDeviceInfo* rtdDevInfo; - uint32_t index; - - if ( (devInfo == NULL) || (devInfo->id != NDEF_TYPE_RTD_DEVICE_INFO) || - (bufItem == NULL) ) - { - return NULL; - } - - rtdDevInfo = &devInfo->data.deviceInfo; - - if (begin == true) - { - item = 0; - } - - bufItem->buffer = NULL; - bufItem->length = 0; - - index = item / 3U; - - /* Stop streaming on first empty entry */ - if (rtdDevInfo->devInfo[index].length > 0U) - { - switch (item % 3U) - { - case 0: - bufItem->buffer = &rtdDevInfo->devInfo[index].type; - bufItem->length = sizeof(rtdDevInfo->devInfo[index].type); - break; - case 1: - bufItem->buffer = &rtdDevInfo->devInfo[index].length; - bufItem->length = sizeof(rtdDevInfo->devInfo[index].length); - break; - case 2: - bufItem->buffer = rtdDevInfo->devInfo[index].buffer; - bufItem->length = rtdDevInfo->devInfo[index].length; - break; - default: - bufItem->buffer = NULL; - bufItem->length = 0; - break; - } - } - - /* Move to next item for next call */ - item++; - - return bufItem->buffer; -} - - -/*****************************************************************************/ -ReturnCode ndefRtdDeviceInfo(ndefType* devInfo, const ndefDeviceInfoEntry* devInfoData, uint8_t devInfoDataCount) -{ - ndefTypeRtdDeviceInfo* rtdDevInfo; - uint32_t i; - uint8_t count; - uint8_t manufacturerNameIndex; - uint8_t modelNameIndex; - - if ( (devInfo == NULL) || - (devInfoData == NULL) || (devInfoData->length == 0U) || - (devInfoDataCount == 0U) || (devInfoDataCount > NDEF_DEVICE_INFO_TYPE_COUNT) ) - { - return ERR_PARAM; - } - - devInfo->id = NDEF_TYPE_RTD_DEVICE_INFO; - devInfo->getPayloadLength = ndefRtdDeviceInfoPayloadGetLength; - devInfo->getPayloadItem = ndefRtdDeviceInfoToPayloadItem; - rtdDevInfo = &devInfo->data.deviceInfo; - - /* Clear the Device Information structure before parsing */ - for (i = 0; i < NDEF_DEVICE_INFO_TYPE_COUNT; i++) - { - rtdDevInfo->devInfo[i].type = 0; - rtdDevInfo->devInfo[i].length = 0; - rtdDevInfo->devInfo[i].buffer = NULL; - } - - /* Read Type, Length and Value fields */ - /* Not checking multiple occurences of a given field, use the last one */ - count = 0; - manufacturerNameIndex = 0; - modelNameIndex = 0; - - while (count < devInfoDataCount) - { - uint8_t type = devInfoData[count].type; - uint8_t length = devInfoData[count].length; - if ((type == NDEF_DEVICE_INFO_UUID) && (length != NDEF_UUID_LENGTH)) - { - return ERR_PROTO; - } - if ( (type > NDEF_DEVICE_INFO_TYPE_COUNT) || (length == 0U) ) - { - return ERR_PROTO; - } - if (type == NDEF_DEVICE_INFO_MANUFACTURER_NAME) - { - manufacturerNameIndex = count; - } - else - { - if (type == NDEF_DEVICE_INFO_MODEL_NAME) - { - modelNameIndex = count; - } - } - - rtdDevInfo->devInfo[count].type = type; - rtdDevInfo->devInfo[count].length = length; - rtdDevInfo->devInfo[count].buffer = devInfoData[count].buffer; - count++; - } - - /* Check that both required fields are there */ - if ( (manufacturerNameIndex != modelNameIndex) && - (rtdDevInfo->devInfo[manufacturerNameIndex].buffer != NULL) && - (rtdDevInfo->devInfo[modelNameIndex].buffer != NULL) ) - { - return ERR_NONE; - } - else - { - return ERR_PARAM; - } -} - - -/*****************************************************************************/ -ReturnCode ndefGetRtdDeviceInfo(const ndefType* devInfo, ndefTypeRtdDeviceInfo* devInfoData) -{ - const ndefTypeRtdDeviceInfo* rtdDevInfo; - uint32_t i; - - if ( (devInfo == NULL) || (devInfo->id != NDEF_TYPE_RTD_DEVICE_INFO) || - (devInfoData == NULL) ) - { - return ERR_PARAM; - } - - rtdDevInfo = &devInfo->data.deviceInfo; - - for (i = 0; i < NDEF_DEVICE_INFO_TYPE_COUNT; i++) - { - devInfoData->devInfo[i].type = rtdDevInfo->devInfo[i].type; - devInfoData->devInfo[i].length = rtdDevInfo->devInfo[i].length; - devInfoData->devInfo[i].buffer = rtdDevInfo->devInfo[i].buffer; - } - - return ERR_NONE; -} - - -/*****************************************************************************/ -static ReturnCode ndefPayloadToRtdDeviceInfo(const ndefConstBuffer* bufDevInfo, ndefType* devInfo) -{ - ndefTypeRtdDeviceInfo* rtdDevInfo; - uint32_t i; - uint32_t offset; - uint8_t count; - uint8_t manufacturerNameIndex; - uint8_t modelNameIndex; - - if ( (bufDevInfo == NULL) || (bufDevInfo->buffer == NULL) || (bufDevInfo->length == 0U) || - (devInfo == NULL) ) - { - return ERR_PARAM; - } - - devInfo->id = NDEF_TYPE_RTD_DEVICE_INFO; - devInfo->getPayloadLength = ndefRtdDeviceInfoPayloadGetLength; - devInfo->getPayloadItem = ndefRtdDeviceInfoToPayloadItem; - rtdDevInfo = &devInfo->data.deviceInfo; - - if ( (bufDevInfo->length < NDEF_RTD_DEVICE_INFO_PAYLOAD_MIN) || - (bufDevInfo->length > NDEF_RTD_DEVICE_INFO_PAYLOAD_MAX) ) - { - return ERR_PROTO; - } - - /* Extract device information from the buffer */ - - /* Clear the Device Information structure before parsing */ - for (i = 0; i < NDEF_DEVICE_INFO_TYPE_COUNT; i++) - { - rtdDevInfo->devInfo[i].type = 0; - rtdDevInfo->devInfo[i].length = 0; - rtdDevInfo->devInfo[i].buffer = NULL; - } - - /* Read Type, Length and Value fields */ - /* Not checking multiple occurences of a given field, use the last one */ - offset = 0; - count = 0; - manufacturerNameIndex = 0; - modelNameIndex = 0; - - while ( ((offset + NDEF_RTD_DEVICE_INFO_TLV_LENGTH_MIN) < bufDevInfo->length) - && (count < NDEF_DEVICE_INFO_TYPE_COUNT) ) - { - uint8_t type = bufDevInfo->buffer[offset]; - uint8_t length = bufDevInfo->buffer[offset + 1U]; - if ((type == NDEF_DEVICE_INFO_UUID) && (length != NDEF_UUID_LENGTH)) - { - return ERR_PROTO; - } - if ( (type > NDEF_DEVICE_INFO_TYPE_COUNT) || (length == 0U) ) - { - return ERR_PROTO; - } - if (type == NDEF_DEVICE_INFO_MANUFACTURER_NAME) - { - manufacturerNameIndex = count; - } - else - { - if (type == NDEF_DEVICE_INFO_MODEL_NAME) - { - modelNameIndex = count; - } - } - - rtdDevInfo->devInfo[count].type = type; - rtdDevInfo->devInfo[count].length = length; - rtdDevInfo->devInfo[count].buffer = &bufDevInfo->buffer[offset + 2U]; - count++; - - /* Next entry */ - offset += sizeof(uint8_t) + sizeof(uint8_t) + (uint32_t)length; - } - - /* Check both required fields are there */ - if ( (manufacturerNameIndex != modelNameIndex) && - (rtdDevInfo->devInfo[manufacturerNameIndex].buffer != NULL) && - (rtdDevInfo->devInfo[modelNameIndex].buffer != NULL) ) - { - return ERR_NONE; - } - else - { - return ERR_PARAM; - } -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToRtdDeviceInfo(const ndefRecord* record, ndefType* devInfo) -{ - const ndefType* ndeftype; - - if ( (record == NULL) || (devInfo == NULL) ) - { - return ERR_PARAM; - } - - if ( ! ndefRecordTypeMatch(record, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeDeviceInfo)) /* "Di" */ - { - return ERR_PROTO; - } - - ndeftype = ndefRecordGetNdefType(record); - if (ndeftype != NULL) - { - (void)ST_MEMCPY(devInfo, ndeftype, sizeof(ndefType)); - return ERR_NONE; - } - - if (record->bufPayload.length < NDEF_RTD_DEVICE_INFO_PAYLOAD_MIN) /* Device Information Payload Min */ - { - return ERR_PROTO; - } - - return ndefPayloadToRtdDeviceInfo(&record->bufPayload, devInfo); -} - - -/*****************************************************************************/ -ReturnCode ndefRtdDeviceInfoToRecord(const ndefType* devInfo, ndefRecord* record) -{ - if ( (devInfo == NULL) || (devInfo->id != NDEF_TYPE_RTD_DEVICE_INFO) || - (record == NULL) ) - { - return ERR_PARAM; - } - - (void)ndefRecordReset(record); - - /* "Di" */ - (void)ndefRecordSetType(record, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeDeviceInfo); - - (void)ndefRecordSetNdefType(record, devInfo); - - return ERR_NONE; -} - - -/* - * Text - */ - - -/*****************************************************************************/ -static uint32_t ndefRtdTextPayloadGetLength(const ndefType* text) -{ - const ndefTypeRtdText* rtdText; - - if ( (text == NULL) || (text->id != NDEF_TYPE_RTD_TEXT) ) - { - return 0; - } - - rtdText = &text->data.text; - - return sizeof(rtdText->status) + rtdText->bufLanguageCode.length + rtdText->bufSentence.length; -} - - -/*****************************************************************************/ -static const uint8_t* ndefRtdTextToPayloadItem(const ndefType* text, ndefConstBuffer* bufItem, bool begin) -{ - static uint32_t item = 0; - const ndefTypeRtdText* rtdText; - - if ( (text == NULL) || (text->id != NDEF_TYPE_RTD_TEXT) || - (bufItem == NULL) ) - { - return NULL; - } - - rtdText = &text->data.text; - - if (begin == true) - { - item = 0; - } - - switch (item) - { - case 0: - /* Status byte */ - bufItem->buffer = &rtdText->status; - bufItem->length = sizeof(rtdText->status); - break; - - case 1: - /* Language Code */ - bufItem->buffer = rtdText->bufLanguageCode.buffer; - bufItem->length = rtdText->bufLanguageCode.length; - break; - - case 2: - /* Actual text */ - bufItem->buffer = rtdText->bufSentence.buffer; - bufItem->length = rtdText->bufSentence.length; - break; - - default: - bufItem->buffer = NULL; - bufItem->length = 0; - break; - } - - /* Move to next item for next call */ - item++; - - return bufItem->buffer; -} - - -/*****************************************************************************/ -ReturnCode ndefRtdText(ndefType* text, uint8_t utfEncoding, const ndefConstBuffer8* bufLanguageCode, const ndefConstBuffer* bufSentence) -{ - ndefTypeRtdText* rtdText; - - if ( (text == NULL) || - (bufLanguageCode == NULL) || (bufLanguageCode->buffer == NULL) || (bufLanguageCode->length == 0U) || - (bufSentence == NULL) || (bufSentence->buffer == NULL) || (bufSentence->length == 0U) ) - { - return ERR_PARAM; - } - - if (bufLanguageCode->length > NDEF_RTD_TEXT_LANGUAGE_CODE_LEN_MASK) - { - return ERR_PROTO; - } - - if ( (utfEncoding != TEXT_ENCODING_UTF8) && (utfEncoding != TEXT_ENCODING_UTF16) ) - { - return ERR_PARAM; - } - - text->id = NDEF_TYPE_RTD_TEXT; - text->getPayloadLength = ndefRtdTextPayloadGetLength; - text->getPayloadItem = ndefRtdTextToPayloadItem; - rtdText = &text->data.text; - - rtdText->status = (utfEncoding << NDEF_RTD_TEXT_ENCODING_SHIFT) | (bufLanguageCode->length & NDEF_RTD_TEXT_LANGUAGE_CODE_LEN_MASK); - - rtdText->bufLanguageCode.buffer = bufLanguageCode->buffer; - rtdText->bufLanguageCode.length = bufLanguageCode->length; - - rtdText->bufSentence.buffer = bufSentence->buffer; - rtdText->bufSentence.length = bufSentence->length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefGetRtdText(const ndefType* text, uint8_t* utfEncoding, ndefConstBuffer8* bufLanguageCode, ndefConstBuffer* bufSentence) -{ - const ndefTypeRtdText* rtdText; - - if ( (text == NULL) || (text->id != NDEF_TYPE_RTD_TEXT) || - (utfEncoding == NULL) || (bufLanguageCode == NULL) || (bufSentence == NULL) ) - { - return ERR_PARAM; - } - - rtdText = &text->data.text; - - *utfEncoding = (rtdText->status >> NDEF_RTD_TEXT_ENCODING_SHIFT) & 1U; - - bufLanguageCode->buffer = rtdText->bufLanguageCode.buffer; - bufLanguageCode->length = rtdText->bufLanguageCode.length; - - bufSentence->buffer = rtdText->bufSentence.buffer; - bufSentence->length = rtdText->bufSentence.length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -static ReturnCode ndefPayloadToRtdText(const ndefConstBuffer* bufText, ndefType* text) -{ - ndefTypeRtdText* rtdText; - uint8_t status; - uint8_t languageCodeLength; - - if ( (bufText == NULL) || (bufText->buffer == NULL) || (bufText->length == 0U) || - (text == NULL) ) - { - return ERR_PARAM; - } - - text->id = NDEF_TYPE_RTD_TEXT; - text->getPayloadLength = ndefRtdTextPayloadGetLength; - text->getPayloadItem = ndefRtdTextToPayloadItem; - rtdText = &text->data.text; - - /* Extract info from the payload */ - status = bufText->buffer[NDEF_RTD_TEXT_STATUS_OFFSET]; - - rtdText->status = status; - - /* Extract info from the status byte */ - //uint8_t textUtfEncoding = (status & NDEF_RTD_TEXT_ENCODING_MASK) >> NDEF_RTD_TEXT_ENCODING_SHIFT; - languageCodeLength = (status & NDEF_RTD_TEXT_LANGUAGE_CODE_LEN_MASK); - - rtdText->bufLanguageCode.buffer = &(bufText->buffer[NDEF_RTD_TEXT_LANGUAGE_OFFSET]); - rtdText->bufLanguageCode.length = languageCodeLength; - - rtdText->bufSentence.buffer = &(bufText->buffer[NDEF_RTD_TEXT_LANGUAGE_OFFSET + languageCodeLength]); - rtdText->bufSentence.length = bufText->length - sizeof(status) - languageCodeLength; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToRtdText(const ndefRecord* record, ndefType* text) -{ - const ndefType* ndeftype; - - if ( (record == NULL) || (text == NULL) ) - { - return ERR_PARAM; - } - - if ( ! ndefRecordTypeMatch(record, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeText)) /* "T" */ - { - return ERR_PROTO; - } - - ndeftype = ndefRecordGetNdefType(record); - if (ndeftype != NULL) - { - (void)ST_MEMCPY(text, ndeftype, sizeof(ndefType)); - return ERR_NONE; - } - - if (record->bufPayload.length < NDEF_RTD_TEXT_PAYLOAD_LENGTH_MIN) /* Text Payload Min */ - { - return ERR_PROTO; - } - - return ndefPayloadToRtdText(&record->bufPayload, text); -} - - -/*****************************************************************************/ -ReturnCode ndefRtdTextToRecord(const ndefType* text, ndefRecord* record) -{ - if ( (text == NULL) || (text->id != NDEF_TYPE_RTD_TEXT) || - (record == NULL) ) - { - return ERR_PARAM; - } - - (void)ndefRecordReset(record); - - /* "T" */ - (void)ndefRecordSetType(record, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeText); - - (void)ndefRecordSetNdefType(record, text); - - return ERR_NONE; -} - - -/* - * URI - */ - - -/*****************************************************************************/ -static uint32_t ndefRtdUriPayloadGetLength(const ndefType* uri) -{ - const ndefTypeRtdUri* rtdUri; - - if ( (uri == NULL) || (uri->id != NDEF_TYPE_RTD_URI) ) - { - return 0; - } - - rtdUri = &uri->data.uri; - - return sizeof(rtdUri->protocol) + rtdUri->bufUriString.length; -} - - -/*****************************************************************************/ -static const uint8_t* ndefRtdUriToPayloadItem(const ndefType* uri, ndefConstBuffer* bufItem, bool begin) -{ - static uint32_t item = 0; - const ndefTypeRtdUri* rtdUri; - - if ( (uri == NULL) || (uri->id != NDEF_TYPE_RTD_URI) || - (bufItem == NULL) ) - { - return NULL; - } - - rtdUri = &uri->data.uri; - - if (begin == true) - { - item = 0; - } - - switch (item) - { - case 0: - /* Protocol byte */ - bufItem->buffer = &rtdUri->protocol; - bufItem->length = sizeof(rtdUri->protocol); - break; - - case 1: - /* URI string */ - bufItem->buffer = rtdUri->bufUriString.buffer; - bufItem->length = rtdUri->bufUriString.length; - break; - - default: - bufItem->buffer = NULL; - bufItem->length = 0; - break; - } - - /* Move to next item for next call */ - item++; - - return bufItem->buffer; -} - - -/*****************************************************************************/ -static ReturnCode ndefRtdUriProtocolAutodetect(uint8_t* protocol, ndefConstBuffer* bufUriString) -{ - uint8_t i; /* Protocol fits in 1 byte */ - - if ( (protocol == NULL) || - (*protocol != NDEF_URI_PREFIX_AUTODETECT) || - (bufUriString == NULL) ) - { - return ERR_PARAM; - } - - for (i = 0; i < NDEF_URI_PREFIX_COUNT; i++) - { - if (ndefUriPrefix[i].length > 0U) - { - if (ST_BYTECMP(bufUriString->buffer, ndefUriPrefix[i].buffer, ndefUriPrefix[i].length) == 0) - { - *protocol = i; - /* Move after the protocol string */ - bufUriString->buffer = &bufUriString->buffer[ndefUriPrefix[i].length]; - bufUriString->length -= ndefUriPrefix[i].length; - return ERR_NONE; - } - } - } - - *protocol = NDEF_URI_PREFIX_NONE; - - return ERR_NOTFOUND; -} - - -/*****************************************************************************/ -ReturnCode ndefRtdUri(ndefType* uri, uint8_t protocol, const ndefConstBuffer* bufUriString) -{ - ndefTypeRtdUri* rtdUri; - ndefConstBuffer bufUri; - uint8_t protocolDetect; - - if ( (uri == NULL) || (protocol >= NDEF_URI_PREFIX_COUNT) || - (bufUriString == NULL) || (bufUriString->buffer == NULL) || (bufUriString->length == 0U) ) - { - return ERR_PARAM; - } - - uri->id = NDEF_TYPE_RTD_URI; - uri->getPayloadLength = ndefRtdUriPayloadGetLength; - uri->getPayloadItem = ndefRtdUriToPayloadItem; - rtdUri = &uri->data.uri; - - bufUri.buffer = bufUriString->buffer; - bufUri.length = bufUriString->length; - protocolDetect = protocol; - if (protocol == NDEF_URI_PREFIX_AUTODETECT) - { - /* Update protocol and URI buffer */ - (void)ndefRtdUriProtocolAutodetect(&protocolDetect, &bufUri); - } - rtdUri->protocol = protocolDetect; - - rtdUri->bufUriString.buffer = bufUri.buffer; - rtdUri->bufUriString.length = bufUri.length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefGetRtdUri(const ndefType* uri, ndefConstBuffer* bufProtocol, ndefConstBuffer* bufUriString) -{ - const ndefTypeRtdUri* rtdUri; - - if ( (uri == NULL) || (uri->id != NDEF_TYPE_RTD_URI) || - (bufProtocol == NULL) || (bufUriString == NULL) ) - { - return ERR_PARAM; - } - - rtdUri = &uri->data.uri; - - bufProtocol->buffer = ndefUriPrefix[rtdUri->protocol].buffer; - bufProtocol->length = ndefUriPrefix[rtdUri->protocol].length; - - bufUriString->buffer = rtdUri->bufUriString.buffer; - bufUriString->length = rtdUri->bufUriString.length; - - return ERR_NONE; -} - -/*****************************************************************************/ -static ReturnCode ndefPayloadToRtdUri(const ndefConstBuffer* bufUri, ndefType* uri) -{ - uint8_t protocol; - - if ( (bufUri == NULL) || (bufUri->buffer == NULL) || (bufUri->length == 0U) || - (uri == NULL) ) - { - return ERR_PARAM; - } - - /* Extract info from the payload */ - protocol = bufUri->buffer[NDEF_RTD_URI_ID_CODE_OFFSET]; - - ndefConstBuffer bufStringUri; - bufStringUri.buffer = &bufUri->buffer[NDEF_RTD_URI_FIELD_OFFSET]; - bufStringUri.length = bufUri->length - sizeof(protocol); - - return ndefRtdUri(uri, protocol, &bufStringUri); -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToRtdUri(const ndefRecord* record, ndefType* uri) -{ - const ndefType* ndeftype; - - if ( (record == NULL) || (uri == NULL) ) - { - return ERR_PARAM; - } - - if ( ! ndefRecordTypeMatch(record, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeUri)) /* "U" */ - { - return ERR_PROTO; - } - - ndeftype = ndefRecordGetNdefType(record); - if (ndeftype != NULL) - { - (void)ST_MEMCPY(uri, ndeftype, sizeof(ndefType)); - return ERR_NONE; - } - - if (record->bufPayload.length < NDEF_RTD_URI_PAYLOAD_LENGTH_MIN) - { - return ERR_PROTO; - } - - return ndefPayloadToRtdUri(&record->bufPayload, uri); -} - - -/*****************************************************************************/ -ReturnCode ndefRtdUriToRecord(const ndefType* uri, ndefRecord* record) -{ - if ( (uri == NULL) || (uri->id != NDEF_TYPE_RTD_URI) || - (record == NULL) ) - { - return ERR_PARAM; - } - - (void)ndefRecordReset(record); - - /* "U" */ - (void)ndefRecordSetType(record, NDEF_TNF_RTD_WELL_KNOWN_TYPE, &bufRtdTypeUri); - - (void)ndefRecordSetNdefType(record, uri); - - return ERR_NONE; -} - - -/* - * NFC Forum External Type (Android Application Record) - */ - - -/*****************************************************************************/ -ReturnCode ndefRtdAar(ndefType* aar, const ndefConstBuffer* bufPayload) -{ - ndefTypeRtdAar* rtdAar; - - if ( (aar == NULL) || - (bufPayload == NULL) || (bufPayload->buffer == NULL) || (bufPayload->length == 0U) ) - { - return ERR_PARAM; - } - - aar->id = NDEF_TYPE_RTD_AAR; - aar->getPayloadLength = NULL; - aar->getPayloadItem = NULL; - rtdAar = &aar->data.aar; - - rtdAar->bufType.buffer = bufRtdTypeAar.buffer; - rtdAar->bufType.length = bufRtdTypeAar.length; - rtdAar->bufPayload.buffer = bufPayload->buffer; - rtdAar->bufPayload.length = bufPayload->length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefGetRtdAar(const ndefType* aar, ndefConstBuffer* bufAarString) -{ - const ndefTypeRtdAar* rtdAar; - - if ( (aar == NULL) || (aar->id != NDEF_TYPE_RTD_AAR) || - (bufAarString == NULL) ) - { - return ERR_PARAM; - } - - rtdAar = &aar->data.aar; - - bufAarString->buffer = rtdAar->bufPayload.buffer; - bufAarString->length = rtdAar->bufPayload.length; - - return ERR_NONE; -} - - -/*****************************************************************************/ -ReturnCode ndefRecordToRtdAar(const ndefRecord* record, ndefType* aar) -{ - if ( (record == NULL) || (aar == NULL) ) - { - return ERR_PARAM; - } - - if ( ! ndefRecordTypeMatch(record, NDEF_TNF_RTD_EXTERNAL_TYPE, &bufRtdTypeAar)) /* "android.com:pkg" */ - { - return ERR_PROTO; - } - - /* No constraint on payload length */ - - return ndefRtdAar(aar, &record->bufPayload); -} - - -/*****************************************************************************/ -ReturnCode ndefRtdAarToRecord(const ndefType* aar, ndefRecord* record) -{ - const ndefTypeRtdAar* rtdAar; - - if ( (aar == NULL) || (aar->id != NDEF_TYPE_RTD_AAR) || - (record == NULL) ) - { - return ERR_PARAM; - } - - rtdAar = &aar->data.aar; - - (void)ndefRecordReset(record); - - /* "android.com:pkg" */ - (void)ndefRecordSetType(record, NDEF_TNF_RTD_EXTERNAL_TYPE, &bufRtdTypeAar); - - (void)ndefRecordSetPayload(record, &rtdAar->bufPayload); - - return ERR_NONE; -} diff --git a/Software/Middlewares/ST/ndef/Src/poller/ndef_poller.c b/Software/Middlewares/ST/ndef/Src/poller/ndef_poller.c deleted file mode 100644 index 61f06e2..0000000 --- a/Software/Middlewares/ST/ndef/Src/poller/ndef_poller.c +++ /dev/null @@ -1,588 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum Tags - * - * This module provides an interface to handle NDEF message - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "ndef_poller.h" -#include "ndef_t2t.h" -#include "ndef_t3t.h" -#include "ndef_t4t.h" -#include "ndef_t5t.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -static ndefDeviceType ndefPollerGetDeviceType(const rfalNfcDevice *dev); - -/* - ****************************************************************************** - * GLOBAL VARIABLE DEFINITIONS - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - -/*******************************************************************************/ -ReturnCode ndefPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev) -{ -#if RFAL_FEATURE_T1T - static const ndefPollerWrapper ndefT1TWrapper = - { - NULL, /* ndefT1TPollerContextInitialization, */ - NULL, /* ndefT1TPollerNdefDetect, */ - NULL, /* ndefT1TPollerReadBytes, */ - NULL, /* ndefT1TPollerReadRawMessage, */ -#if NDEF_FEATURE_ALL - NULL, /* ndefT1TPollerWriteBytes, */ - NULL, /* ndefT1TPollerWriteRawMessage, */ - NULL, /* ndefT1TPollerTagFormat, */ - NULL, /* ndefT1TPollerWriteRawMessageLen */ - NULL, /* ndefT1TPollerCheckPresence */ - NULL, /* ndefT1TPollerCheckAvailableSpace */ - NULL, /* ndefT1TPollerBeginWriteMessage */ - NULL /* ndefT1TPollerEndWriteMessage */ -#endif /* NDEF_FEATURE_ALL */ - }; -#endif /* RFAL_FEATURE_T1T */ - -#if RFAL_FEATURE_T2T - static const ndefPollerWrapper ndefT2TWrapper = - { - ndefT2TPollerContextInitialization, - ndefT2TPollerNdefDetect, - ndefT2TPollerReadBytes, - ndefT2TPollerReadRawMessage, -#if NDEF_FEATURE_ALL - ndefT2TPollerWriteBytes, - ndefT2TPollerWriteRawMessage, - ndefT2TPollerTagFormat, - ndefT2TPollerWriteRawMessageLen, - ndefT2TPollerCheckPresence, - ndefT2TPollerCheckAvailableSpace, - ndefT2TPollerBeginWriteMessage, - ndefT2TPollerEndWriteMessage -#endif /* NDEF_FEATURE_ALL */ - }; -#endif /* RFAL_FEATURE_T2T */ - -#if RFAL_FEATURE_NFCF - static const ndefPollerWrapper ndefT3TWrapper = - { - ndefT3TPollerContextInitialization, - ndefT3TPollerNdefDetect, - ndefT3TPollerReadBytes, - ndefT3TPollerReadRawMessage, -#if NDEF_FEATURE_ALL - ndefT3TPollerWriteBytes, - ndefT3TPollerWriteRawMessage, - ndefT3TPollerTagFormat, - ndefT3TPollerWriteRawMessageLen, - ndefT3TPollerCheckPresence, - ndefT3TPollerCheckAvailableSpace, - ndefT3TPollerBeginWriteMessage, - ndefT3TPollerEndWriteMessage -#endif /* NDEF_FEATURE_ALL */ - }; -#endif /* RFAL_FEATURE_NFCF */ - -#if RFAL_FEATURE_T4T - static const ndefPollerWrapper ndefT4TWrapper = - { - ndefT4TPollerContextInitialization, - ndefT4TPollerNdefDetect, - ndefT4TPollerReadBytes, - ndefT4TPollerReadRawMessage, -#if NDEF_FEATURE_ALL - ndefT4TPollerWriteBytes, - ndefT4TPollerWriteRawMessage, - ndefT4TPollerTagFormat, - ndefT4TPollerWriteRawMessageLen, - ndefT4TPollerCheckPresence, - ndefT4TPollerCheckAvailableSpace, - ndefT4TPollerBeginWriteMessage, - ndefT4TPollerEndWriteMessage -#endif /* NDEF_FEATURE_ALL */ - }; -#endif /* RFAL_FEATURE_T4T */ - -#if RFAL_FEATURE_NFCV - static const ndefPollerWrapper ndefT5TWrapper = - { - ndefT5TPollerContextInitialization, - ndefT5TPollerNdefDetect, - ndefT5TPollerReadBytes, - ndefT5TPollerReadRawMessage, -#if NDEF_FEATURE_ALL - ndefT5TPollerWriteBytes, - ndefT5TPollerWriteRawMessage, - ndefT5TPollerTagFormat, - ndefT5TPollerWriteRawMessageLen, - ndefT5TPollerCheckPresence, - ndefT5TPollerCheckAvailableSpace, - ndefT5TPollerBeginWriteMessage, - ndefT5TPollerEndWriteMessage -#endif /* NDEF_FEATURE_ALL */ - }; -#endif /* RFAL_FEATURE_NFCV */ - - static const ndefPollerWrapper *ndefPollerWrappers[] = - { - NULL, -#if RFAL_FEATURE_T1T - &ndefT1TWrapper, -#else - NULL, -#endif -#if RFAL_FEATURE_T2T - &ndefT2TWrapper, -#else - NULL, -#endif -#if RFAL_FEATURE_NFCF - &ndefT3TWrapper, -#else - NULL, -#endif -#if RFAL_FEATURE_T4T - &ndefT4TWrapper, -#else - NULL, -#endif -#if RFAL_FEATURE_NFCV - &ndefT5TWrapper, -#else - NULL, -#endif - }; - - if( (ctx == NULL) || (dev == NULL) ) - { - return ERR_PARAM; - } - - ctx->ndefPollWrapper = ndefPollerWrappers[ndefPollerGetDeviceType(dev)]; - - /* ndefPollWrapper is NULL when support of a given tag type is not enabled */ - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_NOTSUPP; - } - - return (ctx->ndefPollWrapper->pollerContextInitialization)(ctx, dev); -} - -/*******************************************************************************/ -ReturnCode ndefPollerNdefDetect(ndefContext *ctx, ndefInfo *info) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerNdefDetect)(ctx, info); -} - -/*******************************************************************************/ -ReturnCode ndefPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerReadRawMessage)(ctx, buf, bufLen, rcvdLen); -} - -/*******************************************************************************/ -ReturnCode ndefPollerReadBytes(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerReadBytes)(ctx, offset, len, buf, rcvdLen); -} - -#if NDEF_FEATURE_ALL - -/*******************************************************************************/ -ReturnCode ndefPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerWriteRawMessage)(ctx, buf, bufLen); -} - -/*******************************************************************************/ -ReturnCode ndefPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerTagFormat)(ctx, cc, options); -} - -/*******************************************************************************/ -ReturnCode ndefPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerWriteRawMessageLen)(ctx, rawMessageLen); -} - -/*******************************************************************************/ -ReturnCode ndefPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerWriteBytes)(ctx, offset, buf, len); -} - -/*******************************************************************************/ -ReturnCode ndefPollerCheckPresence(ndefContext *ctx) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerCheckPresence)(ctx); -} - -/*******************************************************************************/ -ReturnCode ndefPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerCheckAvailableSpace)(ctx, messageLen); -} - -/*******************************************************************************/ -ReturnCode ndefPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerBeginWriteMessage)(ctx, messageLen); -} - -/*******************************************************************************/ -ReturnCode ndefPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - if( ctx->ndefPollWrapper == NULL ) - { - return ERR_WRONG_STATE; - } - - return (ctx->ndefPollWrapper->pollerEndWriteMessage)(ctx, messageLen); -} - -/*******************************************************************************/ -ReturnCode ndefPollerWriteMessage(ndefContext *ctx, const ndefMessage* message) -{ - ReturnCode err; - ndefMessageInfo info; - ndefRecord* record; - uint8_t recordHeaderBuf[NDEF_RECORD_HEADER_LEN]; - ndefBuffer bufHeader; - ndefConstBuffer bufPayloadItem; - uint32_t offset; - bool firstPayloadItem; - - if ( (ctx == NULL) || (message == NULL) ) - { - return ERR_PARAM; - } - - if ( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - return ERR_WRONG_STATE; - } - - (void)ndefMessageGetInfo(message, &info); - - /* Verify length of the NDEF message */ - err = ndefPollerCheckAvailableSpace(ctx, info.length); - if (err != ERR_NONE) - { - /* Conclude procedure */ - return ERR_PARAM; - } - - /* Reset L-Field/NLEN field */ - err = ndefPollerBeginWriteMessage(ctx, info.length); - if (err != ERR_NONE) - { - ctx->state = NDEF_STATE_INVALID; - /* Conclude procedure */ - return err; - } - - if (info.length != 0U) - { - offset = ctx->messageOffset; - record = ndefMessageGetFirstRecord(message); - - while (record != NULL) - { - bufHeader.buffer = recordHeaderBuf; - bufHeader.length = sizeof(recordHeaderBuf); - (void)ndefRecordEncodeHeader(record, &bufHeader); - err = ndefPollerWriteBytes(ctx, offset, bufHeader.buffer, bufHeader.length); - if (err != ERR_NONE) - { - return err; - } - offset += bufHeader.length; - // TODO Use API to access record internal - if (record->typeLength != 0U) - { - err = ndefPollerWriteBytes(ctx, offset, record->type, record->typeLength); - if (err != ERR_NONE) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return err; - } - offset += record->typeLength; - } - if (record->idLength != 0U) - { - err = ndefPollerWriteBytes(ctx, offset, record->id, record->idLength); - if (err != ERR_NONE) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return err; - } - offset += record->idLength; - } - if (ndefRecordGetPayloadLength(record) != 0U) - { - firstPayloadItem = true; - while (ndefRecordGetPayloadItem(record, &bufPayloadItem, firstPayloadItem) != NULL) - { - firstPayloadItem = false; - err = ndefPollerWriteBytes(ctx, offset, bufPayloadItem.buffer, bufPayloadItem.length); - if (err != ERR_NONE) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return err; - } - offset += bufPayloadItem.length; - } - } - record = ndefMessageGetNextRecord(record); - } - - err = ndefPollerEndWriteMessage(ctx, info.length); - if (err != ERR_NONE) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return err; - } - } - - return ERR_NONE; -} - -#endif /* NDEF_FEATURE_ALL */ - -/*******************************************************************************/ -static ndefDeviceType ndefPollerGetDeviceType(const rfalNfcDevice *dev) -{ - ndefDeviceType type; - - if( dev == NULL ) - { - type = NDEF_DEV_NONE; - } - else - { - switch( dev->type ) - { - case RFAL_NFC_LISTEN_TYPE_NFCA: - switch( dev->dev.nfca.type ) - { - case RFAL_NFCA_T1T: - type = NDEF_DEV_T1T; - break; - case RFAL_NFCA_T2T: - type = NDEF_DEV_T2T; - break; - case RFAL_NFCA_T4T: - type = NDEF_DEV_T4T; - break; - default: - type = NDEF_DEV_NONE; - break; - } - break; - case RFAL_NFC_LISTEN_TYPE_NFCB: - type = NDEF_DEV_T4T; - break; - case RFAL_NFC_LISTEN_TYPE_NFCF: - type = NDEF_DEV_T3T; - break; - case RFAL_NFC_LISTEN_TYPE_NFCV: - type = NDEF_DEV_T5T; - break; - default: - type = NDEF_DEV_NONE; - break; - } - } - return type; -} - - diff --git a/Software/Middlewares/ST/ndef/Src/poller/ndef_t2t.c b/Software/Middlewares/ST/ndef/Src/poller/ndef_t2t.c deleted file mode 100644 index c120b85..0000000 --- a/Software/Middlewares/ST/ndef/Src/poller/ndef_t2t.c +++ /dev/null @@ -1,835 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum T2T - * - * This module provides an interface to perform as a NFC Reader/Writer - * to handle a Type 2 Tag T2T - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - #include "ndef_poller.h" - #include "ndef_t2t.h" - #include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_T2T - #error " RFAL: Module configuration missing. Please enable/disable T2T module by setting: RFAL_FEATURE_T2T " -#endif - -#if RFAL_FEATURE_T2T - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define NDEF_T2T_BLOCK_SIZE 4U /*!< block size */ -#define NDEF_T2T_MAX_SECTOR 255U /*!< Max Number of Sector in Sector Select Command */ /* 00h -- FEh: 255 sectors */ -#define NDEF_T2T_BLOCKS_PER_SECTOR 256U /*!< Number of Block per Sector */ -#define NDEF_T2T_BYTES_PER_SECTOR (NDEF_T2T_BLOCKS_PER_SECTOR * NDEF_T2T_BLOCK_SIZE) /*!< Number of Bytes per Sector */ -#define NDEF_T2T_MAX_OFFSET (NDEF_T2T_BYTES_PER_SECTOR * NDEF_T2T_MAX_SECTOR) /*!< Maximum offset allowed */ -#define NDEF_T2T_3_BYTES_TLV_LEN 0xFFU /* FFh indicates the use of 3 bytes got the L field */ -#define NDEF_T2T_STATIC_MEM_SIZE 48U /* Static memory size */ - -#define NDEF_T2T_CC_OFFSET 12U /*!< CC offset */ -#define NDEF_T2T_CC_LEN 4U /*!< CC length */ -#define NDEF_T2T_AREA_OFFSET 16U /*!< T2T Area starts at block #4 */ - -#define NDEF_T2T_MAGIC 0xE1U /*!< CC Magic Number */ -#define NDEF_T2T_CC_0 0U /*!< CC_0: Magic Number */ -#define NDEF_T2T_CC_1 1U /*!< CC_1: Version */ -#define NDEF_T2T_CC_2 2U /*!< CC_2: Size */ -#define NDEF_T2T_CC_3 3U /*!< CC_3: Access conditions */ - -#define NDEF_T2T_VERSION_1_0 0x10U /*!< Version 1.0 */ - -#define NDEF_T2T_SIZE_DIVIDER 8U /*!< T2T_area size is measured in bytes is equal to 8 * Size */ - -#define NDEF_T2T_TLV_NULL 0x00U /*!< Null TLV */ -#define NDEF_T2T_TLV_LOCK_CTRL 0x01U /*!< Lock Control TLV */ -#define NDEF_T2T_TLV_MEMORY_CTRL 0x02U /*!< Memory Control TLV */ -#define NDEF_T2T_TLV_NDEF_MESSAGE 0x03U /*!< NDEF Message TLV */ -#define NDEF_T2T_TLV_PROPRIETRARY 0xFDU /*!< Proprietary TLV */ -#define NDEF_T2T_TLV_TERMINATOR 0xFEU /*!< Terminator TLV */ - -#define NDEF_T2T_TLV_L_3_BYTES_LEN 3U /*!< TLV L Length: 3 bytes */ -#define NDEF_T2T_TLV_L_1_BYTES_LEN 1U /*!< TLV L Length: 1 bytes */ -#define NDEF_T2T_TLV_T_LEN 1U /*!< TLV T Length: 1 bytes */ - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define ndefT2TisT2TDevice(device) ((((device)->type == RFAL_NFC_LISTEN_TYPE_NFCA) && ((device)->dev.nfca.type == RFAL_NFCA_T2T))) -#define ndefT2TInvalidateCache(ctx) { (ctx)->subCtx.t2t.cacheAddr = 0xFFFFFFFFU; } - - -#define ndefT2TIsReadOnlyAccessGranted(ctx) (((ctx)->cc.t2t.readAccess == 0x0U) && ((ctx)->cc.t2t.writeAccess == 0xFU)) -#define ndefT2TIsReadWriteAccessGranted(ctx) (((ctx)->cc.t2t.readAccess == 0x0U) && ((ctx)->cc.t2t.writeAccess == 0x0U)) - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ -static ReturnCode ndefT2TPollerReadBlock(ndefContext *ctx, uint16_t blockAddr, uint8_t *buf); - -#if NDEF_FEATURE_ALL -static ReturnCode ndefT2TPollerWriteBlock(ndefContext *ctx, uint16_t blockAddr, const uint8_t *buf); -#endif /* NDEF_FEATURE_ALL */ - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - -/*******************************************************************************/ -static ReturnCode ndefT2TPollerReadBlock(ndefContext *ctx, uint16_t blockAddr, uint8_t *buf) -{ - ReturnCode ret; - uint8_t secNo; - uint8_t blNo; - uint16_t rcvdLen; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) || (buf == NULL) ) - { - return ERR_PARAM; - } - - secNo = (uint8_t)(blockAddr >> 8U); - blNo = (uint8_t)blockAddr; - - if( secNo != ctx->subCtx.t2t.currentSecNo ) - { - ret = rfalT2TPollerSectorSelect(secNo); - if( ret != ERR_NONE ) - { - return ret; - } - ctx->subCtx.t2t.currentSecNo = secNo; - } - - ret = rfalT2TPollerRead(blNo, buf, NDEF_T2T_READ_RESP_SIZE, &rcvdLen); - - if( (ret == ERR_NONE) && (rcvdLen != NDEF_T2T_READ_RESP_SIZE) ) - { - return ERR_PROTO; - } - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerReadBytes(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen) -{ - ReturnCode ret; - uint8_t le; - uint32_t lvOffset = offset; - uint32_t lvLen = len; - uint8_t * lvBuf = buf; - uint16_t blockAddr; - uint8_t byteNo; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) || (lvLen == 0U) || (offset > NDEF_T2T_MAX_OFFSET) ) - { - return ERR_PARAM; - } - - if( (offset >= ctx->subCtx.t2t.cacheAddr) && (offset < (ctx->subCtx.t2t.cacheAddr + NDEF_T2T_READ_RESP_SIZE)) && ((offset + len) < (ctx->subCtx.t2t.cacheAddr + NDEF_T2T_READ_RESP_SIZE)) ) - { - /* data in cache buffer */ - (void)ST_MEMCPY(lvBuf, &ctx->subCtx.t2t.cacheBuf[offset - ctx->subCtx.t2t.cacheAddr], len); - } - else - { - do { - blockAddr = (uint16_t)(lvOffset / NDEF_T2T_BLOCK_SIZE); - byteNo = (uint8_t)(lvOffset % NDEF_T2T_BLOCK_SIZE); - le = (lvLen < NDEF_T2T_READ_RESP_SIZE) ? (uint8_t)lvLen : (uint8_t)NDEF_T2T_READ_RESP_SIZE; - - if( (byteNo != 0U ) || (lvLen < NDEF_T2T_READ_RESP_SIZE) ) - { - ret = ndefT2TPollerReadBlock(ctx, blockAddr, ctx->subCtx.t2t.cacheBuf); - if( ret != ERR_NONE ) - { - ndefT2TInvalidateCache(ctx); - return ret; - } - ctx->subCtx.t2t.cacheAddr = (uint32_t)blockAddr * NDEF_T2T_BLOCK_SIZE; - if( (NDEF_T2T_READ_RESP_SIZE - byteNo) < le ) - { - le = NDEF_T2T_READ_RESP_SIZE - byteNo; - } - if( le > 0U) - { - (void)ST_MEMCPY(lvBuf, &ctx->subCtx.t2t.cacheBuf[byteNo], le); - } - } - else - { - ret = ndefT2TPollerReadBlock(ctx, blockAddr, lvBuf); - if( ret != ERR_NONE ) - { - return ret; - } - if( lvLen == le ) - { - /* cache the last read block */ - (void)ST_MEMCPY(&ctx->subCtx.t2t.cacheBuf[0], lvBuf, NDEF_T2T_READ_RESP_SIZE); - ctx->subCtx.t2t.cacheAddr = (uint32_t)blockAddr * NDEF_T2T_BLOCK_SIZE; - } - } - lvBuf = &lvBuf[le]; - lvOffset += le; - lvLen -= le; - - } while( lvLen != 0U ); - } - - if( rcvdLen != NULL ) - { - *rcvdLen = len; - } - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev) -{ - if( (ctx == NULL) || (dev == NULL) || !ndefT2TisT2TDevice(dev) ) - { - return ERR_PARAM; - } - - (void)ST_MEMCPY(&ctx->device, dev, sizeof(ctx->device)); - - ctx->state = NDEF_STATE_INVALID; - ctx->subCtx.t2t.currentSecNo = 0U; - ndefT2TInvalidateCache(ctx); - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerNdefDetect(ndefContext *ctx, ndefInfo *info) -{ - ReturnCode ret; - uint8_t data[2]; - uint32_t offset; - uint16_t lenTLV; - uint8_t typeTLV; - - if( info != NULL ) - { - info->state = NDEF_STATE_INVALID; - info->majorVersion = 0U; - info->minorVersion = 0U; - info->areaLen = 0U; - info->areaAvalableSpaceLen = 0U; - info->messageLen = 0U; - } - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - ctx->state = NDEF_STATE_INVALID; - - /* Read CC TS T2T v1.0 7.5.1.1 */ - ret = ndefT2TPollerReadBytes(ctx, NDEF_T2T_CC_OFFSET, NDEF_T2T_CC_LEN, ctx->ccBuf, NULL); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - return ret; - } - ctx->cc.t2t.magicNumber = ctx->ccBuf[NDEF_T2T_CC_0]; - ctx->cc.t2t.majorVersion = ndefMajorVersion(ctx->ccBuf[NDEF_T2T_CC_1]); - ctx->cc.t2t.minorVersion = ndefMinorVersion(ctx->ccBuf[NDEF_T2T_CC_1]); - ctx->cc.t2t.size = ctx->ccBuf[NDEF_T2T_CC_2]; - ctx->cc.t2t.readAccess = (uint8_t)(ctx->ccBuf[NDEF_T2T_CC_3] >> 4U); - ctx->cc.t2t.writeAccess = (uint8_t)(ctx->ccBuf[NDEF_T2T_CC_3] & 0xFU); - ctx->areaLen = (uint32_t)ctx->cc.t2t.size * NDEF_T2T_SIZE_DIVIDER; - /* Check version number TS T2T v1.0 7.5.1.2 */ - if( (ctx->cc.t2t.magicNumber != NDEF_T2T_MAGIC) || (ctx->cc.t2t.majorVersion > ndefMajorVersion(NDEF_T2T_VERSION_1_0)) ) - { - /* Conclude procedure TS T2T v1.0 7.5.1.2 */ - return ERR_REQUEST; - } - /* Search for NDEF message TLV TS T2T v1.0 7.5.1.3 */ - offset = NDEF_T2T_AREA_OFFSET; - while ( (offset < (NDEF_T2T_AREA_OFFSET + ctx->areaLen)) ) - { - ret = ndefT2TPollerReadBytes(ctx, offset, 1, data, NULL); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - return ret; - } - typeTLV = data[0]; - if( typeTLV == NDEF_T2T_TLV_NDEF_MESSAGE ) - { - ctx->subCtx.t2t.offsetNdefTLV = offset; - } - offset++; - if( typeTLV == NDEF_T2T_TLV_TERMINATOR ) - { - break; - } - if( typeTLV == NDEF_T2T_TLV_NULL ) - { - continue; - } - /* read TLV Len */ - ret = ndefT2TPollerReadBytes(ctx, offset, 1, data, NULL); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - return ret; - } - offset++; - lenTLV = data[0]; - if( lenTLV == NDEF_T2T_3_BYTES_TLV_LEN ) - { - ret = ndefT2TPollerReadBytes(ctx, offset, 2, data, NULL); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - return ret; - } - offset += 2U; - lenTLV = GETU16(&data[0]); - } - - if( (typeTLV == NDEF_T2T_TLV_LOCK_CTRL) || (typeTLV == NDEF_T2T_TLV_MEMORY_CTRL) ) - { - /* No support of Lock control or Memory control in this version */ - return ERR_REQUEST; - } - /* NDEF message present TLV TS T2T v1.0 7.5.1.4 */ - if( typeTLV == NDEF_T2T_TLV_NDEF_MESSAGE ) - { - /* Read length TS T2T v1.0 7.5.1.5 */ - ctx->messageLen = lenTLV; - ctx->messageOffset = offset; - if( ctx->messageLen == 0U ) - { - if( !(ndefT2TIsReadWriteAccessGranted(ctx)) ) - { - /* Conclude procedure */ - return ERR_REQUEST; - } - /* Empty message found TS T2T v1.0 7.5.1.6 & TS T2T v1.0 7.4.2.1 */ - ctx->state = NDEF_STATE_INITIALIZED; - } - else - { - if( (ndefT2TIsReadWriteAccessGranted(ctx)) ) - { - /* Empty message found TS T2T v1.0 7.5.1.7 & TS T2T v1.0 7.4.3.1 */ - ctx->state = NDEF_STATE_READWRITE; - } - else - { - if( !(ndefT2TIsReadOnlyAccessGranted(ctx)) ) - { - /* Conclude procedure */ - return ERR_REQUEST; - } - /* Empty message found TS T2T v1.0 7.5.1.7 & TS T2T v1.0 7.4.4.1 */ - ctx->state = NDEF_STATE_READONLY; - } - } - if( info != NULL ) - { - info->state = ctx->state; - info->majorVersion = ndefMajorVersion(ctx->cc.t4t.vNo); - info->minorVersion = ndefMinorVersion(ctx->cc.t4t.vNo); - info->areaLen = ctx->areaLen; - info->areaAvalableSpaceLen = ctx->areaLen - ctx->messageOffset; - info->messageLen = ctx->messageLen; - } - return ERR_NONE; - } - offset += lenTLV; - } - return ERR_REQUEST; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) || (buf == NULL) ) - { - return ERR_PARAM; - } - - /* TS T2T v1.0 7.5.2.1: T2T NDEF Detect should have been called before NDEF read procedure */ - /* Warning: current tag content must not be changed between NDEF Detect procedure and NDEF read procedure*/ - - /* TS T2T v1.0 7.5.2.3: check presence of NDEF message */ - if ( ctx->state <= NDEF_STATE_INITIALIZED ) - { - /* Conclude procedure TS T4T v1.0 7.2.2.2 */ - return ERR_WRONG_STATE; - } - - if( ctx->messageLen > bufLen ) - { - return ERR_NOMEM; - } - - /* Current implementation does not support Rsvd_area */ - ret = ndefT2TPollerReadBytes( ctx, ctx->messageOffset, ctx->messageLen, buf, rcvdLen ); - if( ret != ERR_NONE ) - { - ctx->state = NDEF_STATE_INVALID; - } - return ret; -} - -#if NDEF_FEATURE_ALL - -/*******************************************************************************/ -static ReturnCode ndefT2TPollerWriteBlock(ndefContext *ctx, uint16_t blockAddr, const uint8_t *buf) -{ - ReturnCode ret; - uint8_t secNo; - uint8_t blNo; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) || (buf == NULL) ) - { - return ERR_PARAM; - } - - secNo = (uint8_t)(blockAddr >> 8U); - blNo = (uint8_t)blockAddr; - - if( secNo != ctx->subCtx.t2t.currentSecNo ) - { - ret = rfalT2TPollerSectorSelect(secNo); - if( ret != ERR_NONE ) - { - return ret; - } - ctx->subCtx.t2t.currentSecNo = secNo; - } - - ret = rfalT2TPollerWrite(blNo, buf); - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len) -{ - ReturnCode ret; - uint32_t lvOffset = offset; - uint32_t lvLen = len; - const uint8_t * lvBuf = buf; - uint16_t blockAddr; - uint8_t byteNo; - uint8_t le; - uint8_t tempBuf[NDEF_T2T_READ_RESP_SIZE]; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) || (lvLen == 0U) ) - { - return ERR_PARAM; - } - - ndefT2TInvalidateCache(ctx); - - do - { - blockAddr = (uint16_t)(lvOffset / NDEF_T2T_BLOCK_SIZE); - byteNo = (uint8_t)(lvOffset % NDEF_T2T_BLOCK_SIZE); - le = (lvLen < NDEF_T2T_BLOCK_SIZE) ? (uint8_t)lvLen : (uint8_t)NDEF_T2T_BLOCK_SIZE; - if( (byteNo != 0U ) || (lvLen < NDEF_T2T_BLOCK_SIZE) ) - { - ret = ndefT2TPollerReadBlock(ctx, blockAddr, tempBuf); - if( ret != ERR_NONE ) - { - return ret; - } - if( (NDEF_T2T_BLOCK_SIZE - byteNo) < le ) - { - le = NDEF_T2T_BLOCK_SIZE - byteNo; - } - if( le > 0U ) - { - (void)ST_MEMCPY(&tempBuf[byteNo], lvBuf, le); - } - ret = ndefT2TPollerWriteBlock(ctx, blockAddr, tempBuf); - if( ret != ERR_NONE ) - { - return ret; - } - } - else - { - ret = ndefT2TPollerWriteBlock(ctx, blockAddr, lvBuf); - if( ret != ERR_NONE ) - { - return ret; - } - } - lvBuf = &lvBuf[le]; - lvOffset += le; - lvLen -= le; - - } while( lvLen != 0U ); - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen) -{ - ReturnCode ret; - uint8_t buf[NDEF_T2T_BLOCK_SIZE]; - uint8_t dataIt; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - return ERR_WRONG_STATE; - } - dataIt = 0U; - buf[dataIt] = NDEF_T2T_TLV_NDEF_MESSAGE; - dataIt++; - if( rawMessageLen <= NDEF_SHORT_VFIELD_MAX_LEN ) - { - buf[dataIt] = (uint8_t) rawMessageLen; - dataIt++; - } - else - { - buf[dataIt] = (uint8_t) (rawMessageLen >> 8U); - dataIt++; - buf[dataIt] = (uint8_t) rawMessageLen; - dataIt++; - } - if( rawMessageLen == 0U ) - { - buf[dataIt] = NDEF_T2T_TLV_TERMINATOR; - dataIt++; - } - - ret = ndefT2TPollerWriteBytes(ctx, ctx->subCtx.t2t.offsetNdefTLV, buf, dataIt); - if( (ret != ERR_NONE) && (rawMessageLen != 0U) && ((ctx->messageOffset + rawMessageLen) < ctx->areaLen) ) - { - /* Write Terminator TLV */ - dataIt = 0U; - buf[dataIt] = NDEF_T2T_TLV_TERMINATOR; - dataIt++; - (void)ndefT2TPollerWriteBytes(ctx, ctx->messageOffset + rawMessageLen, buf, dataIt ); - } - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) || ((buf == NULL) && (bufLen != 0U)) ) - { - return ERR_PARAM; - } - - /* TS T2T v1.0 7.5.3.1/2: T4T NDEF Detect should have been called before NDEF write procedure */ - /* Warning: current tag content must not be changed between NDEF Detect procedure and NDEF Write procedure*/ - - /* TS T2T v1.0 7.5.3.3: check write access condition */ - if ( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - /* Conclude procedure */ - return ERR_WRONG_STATE; - } - - /* TS T2T v1.0 7.5.3.3: verify available space */ - ret = ndefT2TPollerCheckAvailableSpace(ctx, bufLen); - if( ret != ERR_NONE ) - { - /* Conclude procedures */ - return ERR_PARAM; - } - - /* TS T2T v1.0 7.5.3.4: reset L_Field to 0 */ - /* and update ctx->messageOffset according to L-field len */ - ret = ndefT2TPollerBeginWriteMessage(ctx, bufLen); - if( ret != ERR_NONE ) - { - ctx->state = NDEF_STATE_INVALID; - /* Conclude procedure */ - return ret; - } - - if( bufLen != 0U ) - { - /* TS T2T v1.0 7.5.3.5: write new NDEF message */ - ret = ndefT2TPollerWriteBytes(ctx, ctx->messageOffset, buf, bufLen); - if (ret != ERR_NONE) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - - /* TS T2T v1.0 7.5.3.6 & 7.5.3.7: update L_Field and write Terminator TLV */ - ret = ndefT2TPollerEndWriteMessage(ctx, bufLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - } - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options) -{ - ReturnCode ret; - uint8_t dataIt; - static const uint8_t emptyNdef[] = {NDEF_T2T_TLV_NDEF_MESSAGE, 0x00U, NDEF_T2T_TLV_TERMINATOR, 0x00U}; - - NO_WARNING(options); - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - /* - * Read CC area - */ - ret = ndefT2TPollerReadBytes(ctx, NDEF_T2T_CC_OFFSET, NDEF_T2T_CC_LEN, ctx->ccBuf, NULL); - if( ret != ERR_NONE ) - { - return ret; - } - - ndefT2TInvalidateCache(ctx); - - /* - * Write CC only in case of virgin CC area - */ - if( (ctx->ccBuf[NDEF_T2T_CC_0] == 0U) && (ctx->ccBuf[NDEF_T2T_CC_1] == 0U) && (ctx->ccBuf[NDEF_T2T_CC_2] == 0U) && (ctx->ccBuf[NDEF_T2T_CC_3] == 0U) ) - { - dataIt = 0U; - if( cc == NULL ) - { - /* Use default values if no cc provided */ - ctx->ccBuf[dataIt] = NDEF_T2T_MAGIC; - dataIt++; - ctx->ccBuf[dataIt] = NDEF_T2T_VERSION_1_0; - dataIt++; - ctx->ccBuf[dataIt] = NDEF_T2T_STATIC_MEM_SIZE / NDEF_T2T_SIZE_DIVIDER; - dataIt++; - ctx->ccBuf[dataIt] = 0x00U; - dataIt++; - } - else - { - ctx->ccBuf[dataIt] = cc->t2t.magicNumber; - dataIt++; - ctx->ccBuf[dataIt] = (uint8_t)(cc->t2t.majorVersion << 4U) | cc->t2t.minorVersion; - dataIt++; - ctx->ccBuf[dataIt] = cc->t2t.size; - dataIt++; - ctx->ccBuf[dataIt] = (uint8_t)(cc->t2t.readAccess << 4U) | cc->t2t.writeAccess; - dataIt++; - } - ret = ndefT2TPollerWriteBlock(ctx, NDEF_T2T_CC_OFFSET/NDEF_T2T_BLOCK_SIZE, ctx->ccBuf); - if( ret != ERR_NONE ) - { - return ret; - } - } - - /* - * Write NDEF place holder - */ - ret = ndefT2TPollerWriteBlock(ctx, NDEF_T2T_AREA_OFFSET/NDEF_T2T_BLOCK_SIZE, emptyNdef); - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerCheckPresence(ndefContext *ctx) -{ - ReturnCode ret; - uint16_t blockAddr; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - blockAddr = 0U; - ret = ndefT2TPollerReadBlock(ctx, blockAddr, ctx->subCtx.t2t.cacheBuf); - if( ret != ERR_NONE ) - { - ndefT2TInvalidateCache(ctx); - return ret; - } - ctx->subCtx.t2t.cacheAddr = (uint32_t)blockAddr * NDEF_T2T_BLOCK_SIZE; - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen) -{ - uint32_t lLen; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if ( ctx->state == NDEF_STATE_INVALID ) - { - return ERR_WRONG_STATE; - } - - lLen = ( messageLen > NDEF_SHORT_VFIELD_MAX_LEN) ? NDEF_T2T_TLV_L_3_BYTES_LEN : NDEF_T2T_TLV_L_1_BYTES_LEN; - - if( (messageLen + ctx->subCtx.t2t.offsetNdefTLV + NDEF_T2T_TLV_T_LEN + lLen) > (ctx->areaLen + NDEF_T2T_AREA_OFFSET) ) - { - return ERR_NOMEM; - } - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - ReturnCode ret; - uint32_t lLen; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - return ERR_WRONG_STATE; - } - - /* TS T2T v1.0 7.5.3.4: reset L_Field to 0 */ - ret = ndefT2TPollerWriteRawMessageLen(ctx, 0U); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - - lLen = ( messageLen > NDEF_SHORT_VFIELD_MAX_LEN) ? NDEF_T2T_TLV_L_3_BYTES_LEN : NDEF_T2T_TLV_L_1_BYTES_LEN; - ctx->messageOffset = ctx->subCtx.t2t.offsetNdefTLV; - ctx->messageOffset += NDEF_T2T_TLV_T_LEN; /* T Len */ - ctx->messageOffset += lLen; /* L Len */ - - ctx->state = NDEF_STATE_INITIALIZED; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT2TPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT2TisT2TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( ctx->state != NDEF_STATE_INITIALIZED ) - { - return ERR_WRONG_STATE; - } - - /* TS T2T v1.0 7.5.3.6 & 7.5.3.7: update L_Field and write Terminator TLV */ - ret = ndefT2TPollerWriteRawMessageLen(ctx, messageLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - ctx->messageLen = messageLen; - ctx->state = (ctx->messageLen == 0U) ? NDEF_STATE_INITIALIZED : NDEF_STATE_READWRITE; - return ERR_NONE; -} - -#endif /* NDEF_FEATURE_ALL */ - -#endif /* RFAL_FEATURE_T2T */ diff --git a/Software/Middlewares/ST/ndef/Src/poller/ndef_t3t.c b/Software/Middlewares/ST/ndef/Src/poller/ndef_t3t.c deleted file mode 100644 index 9edf111..0000000 --- a/Software/Middlewares/ST/ndef/Src/poller/ndef_t3t.c +++ /dev/null @@ -1,912 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum T3T - * - * This module provides an interface to perform as a NFC Reader/Writer - * to handle a Type 3 Tag T3T - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - #include "ndef_poller.h" - #include "ndef_t3t.h" - #include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_NFCF - #error " RFAL: Module configuration missing. Please enable/disable T3T module by setting: RFAL_FEATURE_NFCF " -#endif - -//#define RFAL_FEATURE_NFCF - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ -#define NDEF_T3T_MAX_DEVICE 1U /*!< T3T maximum number of device for detection */ -#define NDEF_T3T_SYSTEMCODE 0x12FCU /*!< SENSF_RES System Code for T3T TS T3T 1.0 7.1.1.1 */ -#define NDEF_T3T_WRITEFLAG_ON 0xFU /*!< WriteFlag ON value TS T3T 1.0 7.2.2.16 */ -#define NDEF_T3T_WRITEFLAG_OFF 0x0U /*!< WriteFlag OFF value TS T3T 1.0 7.2.2.16 */ -#define NDEF_T3T_AREA_OFFSET 16U /*!< T3T Area starts at block #1 */ -#define NDEF_T3T_BLOCKLEN 16U /*!< T3T block len is always 16 */ -#define NDEF_T3T_NBBLOCKSMAX 4U /*!< T3T max nb of blocks per read/write */ -#define NDEF_T3T_FLAG_RW 1U /*!< T3T read/write flag value */ -#define NDEF_T3T_FLAG_RO 0U /*!< T3T read only flag value */ -#define NDEF_T3T_SENSFRES_NFCID2 2U /*!< T3T offset of UID in SENSFRES struct */ -#define NDEF_T3T_ATTRIB_INFO_CHECKSUM_LEN 0xEU /*!< T3T checksum len for attribute info to compute */ -#define NDEF_T3T_ATTRIB_INFO_OFFSET_VERSION 0x0U /*!< T3T attribute info offset of version */ -#define NDEF_T3T_ATTRIB_INFO_OFFSET_NBR 1U /*!< T3T attribute info offset of number of read */ -#define NDEF_T3T_ATTRIB_INFO_OFFSET_NBW 2U /*!< T3T attribute info offset of number of write */ -#define NDEF_T3T_ATTRIB_INFO_OFFSET_MAXB 3U /*!< T3T attribute info offset of MAXB */ -#define NDEF_T3T_ATTRIB_INFO_OFFSET_FLAG_W 9U /*!< T3T attribute info offset of Write flag */ -#define NDEF_T3T_ATTRIB_INFO_OFFSET_FLAG_RW 10U /*!< T3T attribute info offset of Read/Write flag */ -#define NDEF_T3T_ATTRIB_INFO_OFFSET_FLAG_LN 11U /*!< T3T attribute info offset of LN field */ -#define NDEF_T3T_ATTRIB_INFO_VERSION_1_0 0x10U /*!< T3T attribute info full version number */ -#define NDEF_T3T_ATTRIB_INFO_BLOCK_NB 0U /*!< T3T attribute info block number */ -#define NDEF_T3T_BLOCKNB_CONF 0x80U /*!< T3T TxRx config value for Read/Write block */ -#define NDEF_T3T_CHECK_NB_BLOCKS_LEN 1U /*!< T3T Length of the Nb of blocks in the CHECK reply */ - -#ifdef RFAL_FEATURE_NFCF - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define ndefT3TisT3TDevice(device) ((device)->type == RFAL_NFC_LISTEN_TYPE_NFCF) -#define ndefT3TIsWriteFlagON(writeFlag) ((writeFlag) == NDEF_T3T_WRITEFLAG_ON) - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ -static ReturnCode ndefT3TPollerReadBlocks ( ndefContext * ctx, uint16_t blockNum, uint8_t nbBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); -static ReturnCode ndefT3TPollerReadAttributeInformationBlock ( ndefContext * ctx); - -#if NDEF_FEATURE_ALL -static ReturnCode ndefT3TPollerWriteBlocks ( ndefContext * ctx, uint16_t blockNum, uint8_t nbBlocks, const uint8_t* dataBlocks); -static ReturnCode ndefT3TPollerWriteAttributeInformationBlock( ndefContext * ctx); -#endif /* NDEF_FEATURE_ALL */ - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - -/*******************************************************************************/ -static ReturnCode ndefT3TPollerReadBlocks( ndefContext *ctx, uint16_t blockNum, uint8_t nbBlocks, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - ReturnCode ret; - uint16_t requestedDataSize; - rfalNfcfServBlockListParam servBlock; - rfalNfcfBlockListElem * listBlocks; - uint8_t index; - uint16_t rcvdLen = 0U; - rfalNfcfServ serviceCodeLst = 0x000BU; /* serviceCodeLst */ - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - requestedDataSize = (uint16_t)nbBlocks * NDEF_T3T_BLOCK_SIZE; - if( rxBufLen < requestedDataSize ) - { - return ERR_PARAM; - } - - listBlocks = ctx->subCtx.t3t.listBlocks; - - for (index = 0U; index < nbBlocks; index++ ) - { - /* Write each block number (16 bits per block address) */ - listBlocks[index].conf = (uint8_t) NDEF_T3T_BLOCKNB_CONF; - listBlocks[index].blockNum = (uint16_t)( blockNum + (uint16_t) index); - } - - servBlock.numServ = 1U; - servBlock.servList = &serviceCodeLst; - servBlock.numBlock = nbBlocks; - servBlock.blockList = listBlocks; - - ret = rfalNfcfPollerCheck(ctx->device.dev.nfcf.sensfRes.NFCID2, &servBlock, ctx->subCtx.t3t.rxbuf, (uint16_t)sizeof(ctx->subCtx.t3t.rxbuf), &rcvdLen); - if (ret != ERR_NONE) - { - return ret; - } - if( rcvdLen != (uint16_t)(NDEF_T3T_CHECK_NB_BLOCKS_LEN + requestedDataSize) ) - { - return ERR_REQUEST; - } - if( requestedDataSize > 0U ) - { - (void)ST_MEMCPY( rxBuf, &ctx->subCtx.t3t.rxbuf[NDEF_T3T_CHECK_NB_BLOCKS_LEN], requestedDataSize ); - if (rcvLen != NULL) - { - *rcvLen = requestedDataSize; - } - } - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerReadBytes(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen) -{ - uint16_t res; - uint16_t nbRead; - ReturnCode result = ERR_NONE; - uint32_t currentLen = len; - uint32_t lvRcvLen = 0U; - const uint16_t blockLen = (uint16_t) NDEF_T3T_BLOCKLEN; - uint16_t startBlock = (uint16_t) (offset / blockLen); - uint16_t startAddr = (uint16_t) (startBlock * blockLen); - uint16_t startOffset= (uint16_t) (offset - (uint32_t) startAddr); - uint16_t nbBlocks = (uint16_t) NDEF_T3T_NBBLOCKSMAX; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) || (len == 0U) ) - { - return ERR_PARAM; - } - if (ctx->state != NDEF_STATE_INVALID) - { - nbBlocks = ctx->cc.t3t.nbR; - } - - if ( startOffset != 0U ) - { - /* Unaligned read, need to use a tmp buffer */ - res = ndefT3TPollerReadBlocks(ctx, startBlock, 1U /* One block */ , ctx->subCtx.t3t.rxbuf, blockLen, &nbRead); - if (res != ERR_NONE) - { - /* Check result */ - result = res; - } - else if (nbRead != NDEF_T3T_BLOCKLEN) - { - /* Check len */ - result = ERR_MEM_CORRUPT; - } - else - { - nbRead = (uint16_t) (nbRead - (uint16_t)startOffset); - if ((uint32_t) nbRead > currentLen) - { - nbRead = (uint16_t) currentLen; - } - if (nbRead > 0U) - { - (void)ST_MEMCPY(buf, &ctx->subCtx.t3t.rxbuf[offset], (uint32_t)nbRead); - } - lvRcvLen += (uint32_t) nbRead; - currentLen -= (uint32_t) nbRead; - startBlock++; - } - } - - while ( (currentLen >= (uint32_t)blockLen) && (result == ERR_NONE) ) - { - if ( currentLen < ((uint32_t)blockLen * nbBlocks) ) - { - /* Reduce the nb of blocks to read */ - nbBlocks = (uint16_t) (currentLen / blockLen); - } - res = ndefT3TPollerReadBlocks(ctx, startBlock, (uint8_t)nbBlocks, ctx->subCtx.t3t.rxbuf, blockLen * nbBlocks, &nbRead); - if (res != ERR_NONE) - { - /* Check result */ - return res; - } - else if (nbRead != (blockLen * nbBlocks)) - { - /* Check len */ - return ERR_MEM_CORRUPT; - } - else - { - (void)ST_MEMCPY(&buf[lvRcvLen], ctx->subCtx.t3t.rxbuf, (uint32_t)currentLen); - lvRcvLen += nbRead; - currentLen -= nbRead; - startBlock += nbBlocks; - } - } - if ( (currentLen > 0U) && (result == ERR_NONE) ) - { - /* Unaligned read, need to use a tmp buffer */ - res = ndefT3TPollerReadBlocks(ctx, startBlock, 1U /* One block */, ctx->subCtx.t3t.rxbuf, blockLen, &nbRead); - if (res != ERR_NONE) - { - /* Check result */ - return res; - } - else if (nbRead != NDEF_T3T_BLOCKLEN) - { - /* Check len */ - return ERR_MEM_CORRUPT; - } - else - { - if (currentLen > 0U) - { - (void)ST_MEMCPY(&buf[lvRcvLen], ctx->subCtx.t3t.rxbuf, (uint32_t)currentLen); - } - lvRcvLen += (uint32_t) currentLen; - currentLen -= (uint32_t) currentLen; - } - } - if ( (currentLen == 0U) && (result == ERR_NONE) ) - { - result = ERR_NONE; - } - if( rcvdLen != NULL ) - { - *rcvdLen = lvRcvLen; - } - return result; -} - -/*******************************************************************************/ -static ReturnCode ndefT3TPollerReadAttributeInformationBlock( ndefContext * ctx) -{ - /* Follow 7.4.1 NDEF Detection Procedure */ - ReturnCode retcode; - uint8_t * rxbuf; - uint16_t checksum_received; - uint16_t checksum_computed = 0U; - uint16_t rcvLen = 0U; - uint8_t i; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - rxbuf = ctx->ccBuf; - retcode = ndefT3TPollerReadBlocks( ctx, NDEF_T3T_ATTRIB_INFO_BLOCK_NB, 1U /* One block */, rxbuf, NDEF_T3T_BLOCK_SIZE, &rcvLen ); - if ( (retcode != ERR_NONE) && (rcvLen != NDEF_T3T_BLOCK_SIZE) ) - { - return retcode; - } - /* Now compute checksum */ - for (i = 0U; i < NDEF_T3T_ATTRIB_INFO_CHECKSUM_LEN; i++) - { - checksum_computed += (uint16_t) rxbuf[i]; - } - checksum_received = ((uint16_t)rxbuf[NDEF_T3T_ATTRIB_INFO_CHECKSUM_LEN] << 8U) + (uint16_t)rxbuf[NDEF_T3T_ATTRIB_INFO_CHECKSUM_LEN+ 1U]; - if (checksum_received != checksum_computed) - { - return ERR_REQUEST; - } - - /* Now copy the attribute struct */ - ctx->cc.t3t.majorVersion = ( rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_VERSION] >> 4U); - ctx->cc.t3t.minorVersion = ( rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_VERSION] & 0xFU); - ctx->cc.t3t.nbR = rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_NBR]; - ctx->cc.t3t.nbW = rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_NBW]; - ctx->cc.t3t.nMaxB = ((uint16_t)rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_MAXB] << 8U) + (uint16_t)rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_MAXB + 1U]; - ctx->cc.t3t.writeFlag = rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_FLAG_W]; - ctx->cc.t3t.rwFlag = rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_FLAG_RW]; - ctx->cc.t3t.Ln = ((uint32_t)rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_FLAG_LN + 0U] << 0x10U) - | ((uint32_t)rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_FLAG_LN + 1U] << 0x8U) - | (uint32_t)rxbuf[NDEF_T3T_ATTRIB_INFO_OFFSET_FLAG_LN + 2U]; - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev) -{ - if( (ctx == NULL) || (dev == NULL) || !ndefT3TisT3TDevice(dev) ) - { - return ERR_PARAM; - } - - (void)ST_MEMCPY(&ctx->device, dev, sizeof(ctx->device)); - - ctx->state = NDEF_STATE_INVALID; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerNdefDetect(ndefContext *ctx, ndefInfo *info) -{ - ReturnCode retcode; - rfalFeliCaPollRes pollRes[NDEF_T3T_MAX_DEVICE]; - uint8_t devCnt = NDEF_T3T_MAX_DEVICE; - uint8_t collisions = 0U; - - if( info != NULL ) - { - info->state = NDEF_STATE_INVALID; - info->majorVersion = 0U; - info->minorVersion = 0U; - info->areaLen = 0U; - info->areaAvalableSpaceLen = 0U; - info->messageLen = 0U; - } - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - ctx->state = NDEF_STATE_INVALID; - - /* TS T3T v1.0 7.4.1.1 the Reader/Writer SHALL send a SENSF_REQ Command with System Code set to 12FCh. */ - retcode = rfalNfcfPollerPoll( RFAL_FELICA_1_SLOT, NDEF_T3T_SYSTEMCODE, (uint8_t)RFAL_FELICA_POLL_RC_NO_REQUEST, pollRes, &devCnt, &collisions ); - if( retcode != ERR_NONE ) - { - /* TS T3T v1.0 7.4.1.2 Conclude procedure. */ - return retcode; - } - - /* Check if UID of the first card is the same */ - if( ST_BYTECMP(&(pollRes[0U][NDEF_T3T_SENSFRES_NFCID2]), ctx->device.dev.nfcf.sensfRes.NFCID2, RFAL_NFCF_NFCID2_LEN ) != 0 ) - { - return ERR_REQUEST; /* Wrong UID */ - } - - /* TS T3T v1.0 7.4.1.3 The Reader/Writer SHALL read the Attribute Information Block using the CHECK Command. */ - /* TS T3T v1.0 7.4.1.4 The Reader/Writer SHALL verify the value of Checksum of the Attribute Information Block. */ - retcode = ndefT3TPollerReadAttributeInformationBlock(ctx); - if( retcode != ERR_NONE ) - { - return retcode; - } - - /* TS T3T v1.0 7.4.1.6 The Reader/Writer SHALL check if it supports the NDEF mapping version number based on the rules given in Section 7.3. */ - if( ctx->cc.t3t.majorVersion != ndefMajorVersion(NDEF_T3T_ATTRIB_INFO_VERSION_1_0) ) - { - return ERR_REQUEST; - } - - ctx->messageLen = ctx->cc.t3t.Ln; - ctx->messageOffset = NDEF_T3T_AREA_OFFSET; - ctx->areaLen = (uint32_t)ctx->cc.t3t.nMaxB * NDEF_T3T_BLOCK_SIZE; - ctx->state = NDEF_STATE_INITIALIZED; - if (ctx->messageLen > 0U) - { - if (ctx->cc.t3t.rwFlag == NDEF_T3T_FLAG_RW) - { - ctx->state = NDEF_STATE_READWRITE; - } - else - { - if (ctx->cc.t3t.rwFlag == NDEF_T3T_FLAG_RO) - { - ctx->state = NDEF_STATE_READONLY; - } - } - } - - if( info != NULL ) - { - info->state = ctx->state; - info->majorVersion = ctx->cc.t3t.majorVersion; - info->minorVersion = ctx->cc.t3t.minorVersion; - info->areaLen = ctx->areaLen; - info->areaAvalableSpaceLen = ctx->areaLen; - info->messageLen = ctx->messageLen; - } - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) || (buf == NULL) ) - { - return ERR_PARAM; - } - - /* TS T3T v1.0 7.4.2: This procedure assumes that the Reader/Writer has successfully performed the NDEF detection procedure. */ - /* Warning: current tag content must not be changed between NDEF Detect procedure and NDEF read procedure*/ - if ( ctx->state <= NDEF_STATE_INITIALIZED ) - { - return ERR_WRONG_STATE; - } - /* TS T3T v1.0 7.4.2.1: If the WriteFlag remembered during the NDEF detection procedure is set to ON, the NDEF data may be inconsistent ...*/ - if( ndefT3TIsWriteFlagON(ctx->cc.t3t.writeFlag) ) - { - /* TS T3T v1.0 7.4.2.1: ... the Reader/Writer SHALL conclude the NDEF read procedure*/ - return ERR_WRONG_STATE; - } - - if( ctx->messageLen > bufLen ) - { - return ERR_NOMEM; - } - - /* TS T3T v1.0 7.4.2.2: Read NDEF data */ - ret = ndefT3TPollerReadBytes( ctx, ctx->messageOffset, ctx->messageLen, buf, rcvdLen ); - if( ret != ERR_NONE ) - { - ctx->state = NDEF_STATE_INVALID; - } - return ret; -} - -#if NDEF_FEATURE_ALL - -/*******************************************************************************/ -static ReturnCode ndefT3TPollerWriteBlocks( ndefContext * ctx, uint16_t blockNum, uint8_t nbBlocks, const uint8_t* dataBlocks) -{ - ReturnCode ret; - rfalNfcfServBlockListParam servBlock; - rfalNfcfBlockListElem * listBlocks; - uint8_t index; - rfalNfcfServ serviceCodeLst = 0x0009U; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - listBlocks = ctx->subCtx.t3t.listBlocks; - - for (index = 0U; index < nbBlocks; index++) - { - /* Write each block number (16 bits per block address) */ - listBlocks[index].conf = (uint8_t) NDEF_T3T_BLOCKNB_CONF; - listBlocks[index].blockNum = (uint16_t)( blockNum + (uint16_t) index); - } - servBlock.numServ = 1U; - servBlock.servList = &serviceCodeLst; - servBlock.numBlock = nbBlocks; - servBlock.blockList = listBlocks; - - ret = rfalNfcfPollerUpdate( ctx->device.dev.nfcf.sensfRes.NFCID2, &servBlock, ctx->subCtx.t3t.txbuf, (uint16_t)sizeof(ctx->subCtx.t3t.txbuf), dataBlocks, ctx->subCtx.t3t.rxbuf, (uint16_t)sizeof(ctx->subCtx.t3t.rxbuf)); - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len) -{ - uint16_t nbRead; - uint16_t nbWrite; - uint16_t res; - ReturnCode result = ERR_NONE; - uint32_t currentLen = len; - uint32_t txtLen = 0U; - const uint16_t blockLen = (uint16_t )NDEF_T3T_BLOCKLEN; - uint16_t nbBlocks = (uint16_t ) NDEF_T3T_NBBLOCKSMAX; - uint16_t startBlock = (uint16_t) (offset / blockLen); - uint16_t startAddr = (uint16_t) (startBlock * blockLen); - uint16_t startOffset= (uint16_t) (offset - (uint32_t) startAddr); - uint8_t tmpBuf[NDEF_T3T_BLOCKLEN]; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) || (len == 0U) ) - { - return ERR_PARAM; - } - if (ctx->state != NDEF_STATE_INVALID) - { - nbBlocks = ctx->cc.t3t.nbW; - } - - if ( startOffset != 0U ) - { - /* Unaligned write, need to use a tmp buffer */ - res = ndefT3TPollerReadBlocks(ctx, startBlock, 1, tmpBuf, blockLen, &nbRead); - if (res != ERR_NONE) - { - /* Check result */ - result = res; - } - else if (nbRead != blockLen) - { - /* Check len */ - result = ERR_MEM_CORRUPT; - } - else - { - /* Fill the rest of the buffer with user data */ - nbWrite = NDEF_T3T_BLOCKLEN - startOffset; - if (nbWrite > len) - { - nbWrite = (uint16_t) len; - } - (void)ST_MEMCPY(&tmpBuf[startOffset], buf, nbWrite); - res = ndefT3TPollerWriteBlocks(ctx, startBlock, 1U /* One block */, tmpBuf); - if (res == ERR_NONE) - { - txtLen += (uint32_t) nbWrite; - currentLen -= (uint32_t) nbWrite; - startBlock++; - } - else - { - result = res; /* Copy the error code */ - } - } - } - while ( (currentLen >= (uint32_t)blockLen) && (result == ERR_NONE) ) - { - if ( currentLen < ((uint32_t)blockLen * nbBlocks) ) - { - /* Reduce the nb of blocks to read */ - nbBlocks = (uint16_t) (currentLen / blockLen); - } - nbWrite = blockLen * nbBlocks; - res = ndefT3TPollerWriteBlocks(ctx, startBlock, (uint8_t) nbBlocks, &buf[txtLen]); - if (res != ERR_NONE) - { - /* Check result */ - result = res; - } - else - { - txtLen += nbWrite; - currentLen -= nbWrite; - startBlock += nbBlocks; - } - } - if ( (currentLen > 0U) && (result == ERR_NONE) ) - { - /* Unaligned write, need to use a tmp buffer */ - res = ndefT3TPollerReadBlocks(ctx, startBlock, 1U /* One block */, tmpBuf, blockLen, &nbRead); - if (res != ERR_NONE) - { - /* Check result */ - result = res; - } - else if (nbRead != blockLen) - { - /* Check len */ - result = ERR_MEM_CORRUPT; - } - else - { - /* Fill the beginning of the buffer with user data */ - (void)ST_MEMCPY( tmpBuf, &buf[txtLen], currentLen); - res = ndefT3TPollerWriteBlocks(ctx, startBlock, 1U /* One block */, tmpBuf); - if (res == ERR_NONE) - { - currentLen = 0U; - } - else - { - result = res; /* Copy the error code */ - } - } - } - if ( (currentLen == 0U) && (result == ERR_NONE) ) - { - result = ERR_NONE; - } - return result; -} - -/*******************************************************************************/ -static ReturnCode ndefT3TPollerWriteAttributeInformationBlock(ndefContext * ctx) -{ - uint8_t dataIt; - uint16_t checksum; - uint8_t * buf; - ReturnCode ret; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - if ( ctx->state < NDEF_STATE_INITIALIZED ) - { - return ERR_WRONG_STATE; - } - dataIt = 0U; - buf = ctx->ccBuf; - checksum = 0U; - buf[dataIt] = ((uint8_t)(ctx->cc.t3t.majorVersion << 4U)) | ctx->cc.t3t.minorVersion; /* Byte 0 Ver */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = ctx->cc.t3t.nbR; /* Byte 1 Nbr */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = ctx->cc.t3t.nbW; /* Byte 2 Nbw */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = (uint8_t)(ctx->cc.t3t.nMaxB >> 8U); /* Byte 3 NmaxB (MSB) */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = (uint8_t)(ctx->cc.t3t.nMaxB >> 0U); /* Byte 4 NmaxB (LSB) */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = 0U; /* Byte 5 RFU */ - dataIt++; - buf[dataIt] = 0U; /* Byte 6 RFU */ - dataIt++; - buf[dataIt] = 0U; /* Byte 7 RFU */ - dataIt++; - buf[dataIt] = 0U; /* Byte 8 RFU */ - dataIt++; - buf[dataIt] = ctx->cc.t3t.writeFlag; /* Byte 9 WriteFlag */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = ctx->cc.t3t.rwFlag; /* Byte 10 RWFlag */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = (uint8_t)(ctx->cc.t3t.Ln >> 16U); /* Byte 11 Ln (MSB) */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = (uint8_t)(ctx->cc.t3t.Ln >> 8U); /* Byte 12 Ln (middle) */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = (uint8_t)(ctx->cc.t3t.Ln >> 0U); /* Byte 13 Ln (LSB) */ - checksum += buf[dataIt]; - dataIt++; - buf[dataIt] = (uint8_t)(checksum >> 8U); /* Byte 14 checksum MSB */ - dataIt++; - buf[dataIt] = (uint8_t)(checksum >> 0U); /* Byte 15 checksum LSB */ - dataIt++; - - ret = ndefT3TPollerWriteBlocks(ctx, NDEF_T3T_ATTRIB_INFO_BLOCK_NB, 1U /* One block */, buf); - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) || ((buf == NULL) && (bufLen != 0U)) ) - { - return ERR_PARAM; - } - /* TS T3T v1.0 7.4.3: This procedure assumes that the Reader/Writer has successfully performed the NDEF detection procedure... */ - /* Warning: current tag content must not be changed between NDEF Detect procedure and NDEF read procedure*/ - - /* TS T3T v1.0 7.4.3: ... and that the RWFlag in the Attribute Information Block is set to 01h. */ - if ( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - /* Conclude procedure */ - return ERR_WRONG_STATE; - } - - /* TS T3T v1.0 7.4.3.2: verify available space */ - ret = ndefT3TPollerCheckAvailableSpace(ctx, bufLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - return ERR_PARAM; - } - - /* TS T3T v1.0 7.4.3.3: update WriteFlag */ - ret = ndefT3TPollerBeginWriteMessage(ctx, bufLen); - if( ret != ERR_NONE ) - { - ctx->state = NDEF_STATE_INVALID; - /* Conclude procedure */ - return ret; - } - - if( bufLen != 0U ) - { - /* TS T3T v1.0 7.4.3.4: write new NDEF message */ - ret = ndefT3TPollerWriteBytes(ctx, ctx->messageOffset, buf, bufLen); - if (ret != ERR_NONE) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - } - /* TS T3T v1.0 7.4.3.5: update Ln value and set WriteFlag to OFF */ - ret = ndefT3TPollerEndWriteMessage(ctx, bufLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer * cc, uint32_t options) -{ - ReturnCode res; - rfalFeliCaPollRes buffOut [NDEF_T3T_MAX_DEVICE]; - uint8_t devCnt = NDEF_T3T_MAX_DEVICE; - uint8_t collisions = 0U; - NO_WARNING(options); /* options not used in T3T */ - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - if ( cc == NULL) - { - /* No default CC found so have to analyse the tag */ - res = ndefT3TPollerReadAttributeInformationBlock(ctx); /* Read current cc */ - if (res != ERR_NONE) - { - return res; - } - } - else - { - /* Nothing to do */ - (void)ST_MEMCPY(&ctx->cc, cc, sizeof(ndefCapabilityContainer)); - } - - /* 4.3.3 System Definition Information for SystemCode = 0x12FC (NDEF) */ - res = rfalNfcfPollerPoll( RFAL_FELICA_1_SLOT, NDEF_T3T_SYSTEMCODE, (uint8_t)RFAL_FELICA_POLL_RC_NO_REQUEST, buffOut, &devCnt, &collisions ); - if (res != ERR_NONE) - { - return res; - } - res = rfalNfcfPollerPoll( RFAL_FELICA_1_SLOT, NDEF_T3T_SYSTEMCODE, (uint8_t)RFAL_FELICA_POLL_RC_SYSTEM_CODE, buffOut, &devCnt, &collisions ); - if (res != ERR_NONE) - { - return res; - } - ctx->state = NDEF_STATE_INITIALIZED; /* to be sure that the block will be written */ - ctx->cc.t3t.Ln = 0U; /* Force actual stored NDEF size to 0 */ - ctx->cc.t3t.writeFlag = 0U; /* Force WriteFlag to 0 */ - res = ndefT3TPollerWriteAttributeInformationBlock(ctx); - return res; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerCheckPresence(ndefContext *ctx) -{ - ReturnCode retcode; - uint16_t nbRead; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - /* Perform a simple readblock */ - retcode = ndefT3TPollerReadBlocks(ctx, 0U /* First block */, 1U /* One Block */, ctx->subCtx.t3t.rxbuf, NDEF_T3T_BLOCKLEN, &nbRead); - return retcode; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen) -{ - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if ( ctx->state == NDEF_STATE_INVALID ) - { - return ERR_WRONG_STATE; - } - if( messageLen > ctx->areaLen ) - { - return ERR_NOMEM; - } - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - ReturnCode ret; - NO_WARNING(messageLen); - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - return ERR_WRONG_STATE; - } - /* Update WriteFlag */ - ctx->cc.t3t.writeFlag = NDEF_T3T_WRITEFLAG_ON; - ret = ndefT3TPollerWriteAttributeInformationBlock(ctx); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - ctx->state = NDEF_STATE_INITIALIZED; - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - if( ctx->state != NDEF_STATE_INITIALIZED ) - { - return ERR_WRONG_STATE; - } - /* TS T3T v1.0 7.4.3.5 Update Attribute Information Block */ - ctx->cc.t3t.writeFlag = NDEF_T3T_WRITEFLAG_OFF; - ctx->cc.t3t.Ln = messageLen; - ret = ndefT3TPollerWriteAttributeInformationBlock(ctx); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - ctx->messageLen = messageLen; - ctx->state = (ctx->messageLen == 0U) ? NDEF_STATE_INITIALIZED : NDEF_STATE_READWRITE; - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT3TPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen) -{ - if( (ctx == NULL) || !ndefT3TisT3TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - return ERR_WRONG_STATE; - } - return ndefT3TPollerEndWriteMessage(ctx, rawMessageLen); -} - -#endif /* NDEF_FEATURE_ALL */ - -#endif /* RFAL_FEATURE_NFCF */ diff --git a/Software/Middlewares/ST/ndef/Src/poller/ndef_t4t.c b/Software/Middlewares/ST/ndef/Src/poller/ndef_t4t.c deleted file mode 100644 index 48fd193..0000000 --- a/Software/Middlewares/ST/ndef/Src/poller/ndef_t4t.c +++ /dev/null @@ -1,933 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC Forum T4T - * - * This module provides an interface to perform as a NFC Reader/Writer - * to handle a Type 4 Tag T4T - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - #include "ndef_poller.h" - #include "ndef_t4t.h" - #include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_T4T - #error " RFAL: Module configuration missing. Please enable/disable T4T module by setting: RFAL_FEATURE_T4T " -#endif - -#if RFAL_FEATURE_T4T - -#if RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN < MAX(NDEF_T4T_MAX_CAPDU_LEN, NDEF_T4T_MAX_RAPDU_LEN) - #error " RFAL: ISO-DEP APDU Max length must be greater than ISO7816 Command/Response-APDU length. Please increase RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN" -#endif - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define NDEF_T4T_FID_SIZE 2U /*!< File Id size */ -#define NDEF_T4T_WRITE_ODO_PREFIX_SIZE 7U /*!< Size of ODO for Write Binary: 54 03 xxyyzz 53 Ld */ - -#define NDEF_T4T_DEFAULT_MLC 0x000DU /*!< Defauit Max Lc value before reading CCFILE values */ -#define NDEF_T4T_DEFAULT_MLE 0x000FU /*!< Defauit Max Le value before reading CCFILE values */ - -#define NDEF_T4T_OFFSET_MAX 0x7FFFU /*!< Maximum offset value for ReadBinary */ -#define NDEF_T4T_ODO_OFFSET_MAX 0xFFFFFEU /*!< Maximum offset value for ReadBinary with ODO */ - -#define NDEF_T4T_CCFILEV2_LEN 15U /*!< CCFILE Len mapping version V2 */ -#define NDEF_T4T_CCFILEV3_LEN 17U /*!< CCFILE Len mapping version V3 */ - -#define NDEF_T4T_NDEF_CTLV_T 0x04U /*!< NDEF-File_Ctrl_TLV T field value */ -#define NDEF_T4T_ENDEF_CTLV_T 0x06U /*!< ENDEF-File_Ctrl_TLV T field value */ - -#define NDEF_T4T_NDEF_CTLV_L 0x06U /*!< NDEF-File_Ctrl_TLV T field value */ -#define NDEF_T4T_ENDEF_CTLV_L 0x08U /*!< ENDEF-File_Ctrl_TLV T field value */ - -#define NDEF_T4T_MIN_VALID_MLE 0x000FU /*!< Min valid MLe. MLe valid range 000Fh-FFFFh */ -#define NDEF_T4T_MIN_VALID_MLC 0x000DU /*!< Min valid MLc. MLc valid range 000Dh-FFFFh */ - -#define NDEF_T4T_NLEN_LEN 2U /*!< NLEN LEN (mapping version v2.0): 2 bytes */ -#define NDEF_T4T_ENLEN_LEN 4U /*!< ENLEN LEN (mapping version v3.0): 4 bytes */ - -#define NDEF_T4T_MIN_NLEN 3U /*!< Minimun non null NLEN value. TS T4T v1.0 B */ - -#define NDEF_T4T_MV2_MAX_OFSSET 0x7FFFU /*!< ReadBinary maximum Offset (offset range 0000-7FFFh)*/ - -#define NDEF_T4T_MAX_MLE 255U /*!< Maximum MLe value supported in this implementation (short field coding). Le=0 (MLe=256) not supported by some tag. */ -#define NDEF_T4T_MAX_MLC 255U /*!< Maximum MLc value supported in this implementation (short field coding). */ - -/* - ****************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define ndefT4TisT4TDevice(device) ((((device)->type == RFAL_NFC_LISTEN_TYPE_NFCA) && ((device)->dev.nfca.type == RFAL_NFCA_T4T)) || ((device)->type == RFAL_NFC_LISTEN_TYPE_NFCB)) - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ -static void ndefT4TInitializeIsoDepTxRxParam(ndefContext *ctx, rfalIsoDepApduTxRxParam *isoDepAPDU); -static ReturnCode ndefT4TTransceiveTxRx(ndefContext *ctx, rfalIsoDepApduTxRxParam *isoDepAPDU); -static ReturnCode ndefT4TReadAndParseCCFile(ndefContext *ctx); - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - -/*******************************************************************************/ -static void ndefT4TInitializeIsoDepTxRxParam(ndefContext *ctx, rfalIsoDepApduTxRxParam *isoDepAPDU) -{ - /* Initialize the ISO-DEP protocol transceive context */ - isoDepAPDU->txBuf = &ctx->subCtx.t4t.cApduBuf; - isoDepAPDU->DID = ctx->device.proto.isoDep.info.DID; - isoDepAPDU->FWT = ctx->device.proto.isoDep.info.FWT; - isoDepAPDU->dFWT = ctx->device.proto.isoDep.info.dFWT; - isoDepAPDU->FSx = ctx->device.proto.isoDep.info.FSx; - isoDepAPDU->ourFSx = RFAL_ISODEP_FSX_KEEP; - isoDepAPDU->rxBuf = &ctx->subCtx.t4t.rApduBuf; - isoDepAPDU->tmpBuf = &ctx->subCtx.t4t.tmpBuf; -} - -/*******************************************************************************/ -static ReturnCode ndefT4TTransceiveTxRx(ndefContext *ctx, rfalIsoDepApduTxRxParam *isoDepAPDU) -{ - ReturnCode ret; - - /* Initialize respAPDU */ - ctx->subCtx.t4t.respAPDU.rApduBuf = &ctx->subCtx.t4t.rApduBuf; - isoDepAPDU->rxLen = &ctx->subCtx.t4t.respAPDU.rcvdLen; - - ret = rfalIsoDepStartApduTransceive(*isoDepAPDU); - if( ret == ERR_NONE ) - { - do { - /* Blocking implementation, T4T may define rather long timeouts */ - rfalWorker(); - ret = rfalIsoDepGetApduTransceiveStatus(); - } while (ret == ERR_BUSY); - } - - if (ret != ERR_NONE) - { - return ret; - } - - ret = rfalT4TPollerParseRAPDU(&ctx->subCtx.t4t.respAPDU); - ctx->subCtx.t4t.rApduBodyLen = ctx->subCtx.t4t.respAPDU.rApduBodyLen; - - return ret; -} - -/*******************************************************************************/ -static ReturnCode ndefT4TReadAndParseCCFile(ndefContext *ctx) -{ - static const uint8_t RFAL_T4T_FID_CC[] = {0xE1, 0x03}; /*!< FID_CC-File T4T 1.0 4.2 */ - - ReturnCode ret; - uint8_t dataIt; - - /* Select CCFILE TS T4T v1.0 7.2.1.3 */ - ret = ndefT4TPollerSelectFile(ctx, RFAL_T4T_FID_CC); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.4 */ - return ret; - } - - /* Read CCFILE TS T4T v1.0 7.2.1.5 */ - /* read CCFILE assuming at least 15 bytes are available. If V3 found will read the extra bytes in a second step */ - ret = ndefT4TPollerReadBinary(ctx, 0U, NDEF_T4T_CCFILEV2_LEN); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.6 */ - return ret; - } - (void)ST_MEMCPY(ctx->ccBuf, ctx->subCtx.t4t.rApduBuf.apdu, NDEF_T4T_CCFILEV2_LEN); - dataIt = 0; - ctx->cc.t4t.ccLen = GETU16(&ctx->ccBuf[dataIt]); - dataIt += (uint8_t)sizeof(uint16_t); - ctx->cc.t4t.vNo = ctx->ccBuf[dataIt]; - dataIt++; - ctx->cc.t4t.mLe = GETU16(&ctx->ccBuf[dataIt]); - dataIt += (uint8_t)sizeof(uint16_t); - ctx->cc.t4t.mLc = GETU16(&ctx->ccBuf[dataIt]); - dataIt += (uint8_t)sizeof(uint16_t); - - /* TS T4T v1.0 7.2.1.7 verify MLe and MLc are within the valid range */ - if( (ctx->cc.t4t.mLe < NDEF_T4T_MIN_VALID_MLE) || (ctx->cc.t4t.mLc < NDEF_T4T_MIN_VALID_MLC) ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.8 */ - return ERR_REQUEST; - } - - ctx->subCtx.t4t.curMLe = (uint8_t)MIN(ctx->cc.t4t.mLe, NDEF_T4T_MAX_MLE); /* Only short field codind supported */ - ctx->subCtx.t4t.curMLc = (uint8_t)MIN(ctx->cc.t4t.mLc, NDEF_T4T_MAX_MLC); /* Only short field codind supported */ - - /* TS T4T v1.0 7.2.1.7 and 4.3.2.4 verify support of mapping version */ - if( ndefMajorVersion(ctx->cc.t4t.vNo) > ndefMajorVersion(NDEF_T4T_MAPPING_VERSION_3_0) ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.8 */ - return ERR_REQUEST; - } - if( ndefMajorVersion(ctx->cc.t4t.vNo) == ndefMajorVersion(NDEF_T4T_MAPPING_VERSION_3_0) ) - { - /* V3 found: read remainng bytes */ - ret = ndefT4TPollerReadBinary(ctx, NDEF_T4T_CCFILEV2_LEN, NDEF_T4T_CCFILEV3_LEN - NDEF_T4T_CCFILEV2_LEN); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.6 */ - return ret; - } - (void)ST_MEMCPY(&ctx->ccBuf[NDEF_T4T_CCFILEV2_LEN], ctx->subCtx.t4t.rApduBuf.apdu, NDEF_T4T_CCFILEV3_LEN - NDEF_T4T_CCFILEV2_LEN); - - /* TS T4T v1.0 7.2.1.7 verify coding as in table 5 */ - if( ctx->ccBuf[dataIt] != NDEF_T4T_ENDEF_CTLV_T ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.8 */ - return ERR_REQUEST; - } - dataIt++; - if( ctx->ccBuf[dataIt] < NDEF_T4T_ENDEF_CTLV_L ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.8 */ - return ERR_REQUEST; - } - dataIt++; - ctx->cc.t4t.fileId[0U] = ctx->ccBuf[dataIt]; - dataIt++; - ctx->cc.t4t.fileId[1U] = ctx->ccBuf[dataIt]; - dataIt++; - ctx->cc.t4t.fileSize = GETU32(&ctx->ccBuf[dataIt]); - dataIt += (uint8_t)sizeof(uint32_t); - ctx->cc.t4t.readAccess = ctx->ccBuf[dataIt]; - dataIt++; - ctx->cc.t4t.writeAccess = ctx->ccBuf[dataIt]; - dataIt++; - } - else - { - if( ctx->ccBuf[dataIt] != NDEF_T4T_NDEF_CTLV_T ) - { - return ERR_REQUEST; - } - dataIt++; - if( ctx->ccBuf[dataIt] < NDEF_T4T_NDEF_CTLV_L ) - { - return ERR_REQUEST; - } - dataIt++; - ctx->cc.t4t.fileId[0U] = ctx->ccBuf[dataIt]; - dataIt++; - ctx->cc.t4t.fileId[1U] = ctx->ccBuf[dataIt]; - dataIt++; - ctx->cc.t4t.fileSize = ndefBytes2Uint16(ctx->ccBuf[dataIt], ctx->ccBuf[dataIt + 1U]); - dataIt += (uint8_t)sizeof(uint16_t); - ctx->cc.t4t.readAccess = ctx->ccBuf[dataIt]; - dataIt++; - ctx->cc.t4t.writeAccess = ctx->ccBuf[dataIt]; - dataIt++; - } - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerSelectNdefTagApplication(ndefContext *ctx) -{ - ReturnCode ret; - rfalIsoDepApduTxRxParam isoDepAPDU; - static const uint8_t NDEF_T4T_AID_NDEF[] = {0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01}; /*!< AID_NDEF v2.0 or higher T4T 1.0 4.3.3 */ - static const uint8_t NDEF_T4T_AID_NDEF_V1[] = {0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00}; /*!< AID_NDEF v1.0 T4T 1.0 4.3.3 */ - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - ndefT4TInitializeIsoDepTxRxParam(ctx, &isoDepAPDU); - (void)rfalT4TPollerComposeSelectAppl(isoDepAPDU.txBuf, NDEF_T4T_AID_NDEF, (uint8_t)sizeof(NDEF_T4T_AID_NDEF), &isoDepAPDU.txBufLen); - ret = ndefT4TTransceiveTxRx(ctx, &isoDepAPDU); - - if( ret == ERR_NONE ) - { - /* application v2 or higher found */ - ctx->subCtx.t4t.mv1Flag = false; - return ret; - } - - if( ret != ERR_REQUEST ) - { - return ret; - } - - /* if v2 application not found, try v1 */ - (void)rfalT4TPollerComposeSelectAppl(isoDepAPDU.txBuf, NDEF_T4T_AID_NDEF_V1, (uint8_t)sizeof(NDEF_T4T_AID_NDEF_V1), &isoDepAPDU.txBufLen); - ret = ndefT4TTransceiveTxRx(ctx, &isoDepAPDU); - - if( ret == ERR_NONE ) - { - /* application v1 found */ - ctx->subCtx.t4t.mv1Flag = true; - } - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerSelectFile(ndefContext *ctx, const uint8_t *fileId) -{ - ReturnCode ret; - rfalIsoDepApduTxRxParam isoDepAPDU; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - ndefT4TInitializeIsoDepTxRxParam(ctx, &isoDepAPDU); - - if (ctx->subCtx.t4t.mv1Flag) - { - (void)rfalT4TPollerComposeSelectFileV1Mapping(isoDepAPDU.txBuf, fileId, (uint8_t)sizeof(fileId), &isoDepAPDU.txBufLen); - } - else - { - (void)rfalT4TPollerComposeSelectFile(isoDepAPDU.txBuf, fileId, NDEF_T4T_FID_SIZE, &isoDepAPDU.txBufLen); - } - - ret = ndefT4TTransceiveTxRx(ctx, &isoDepAPDU); - - return ret; -} - - -/*******************************************************************************/ -ReturnCode ndefT4TPollerReadBinary(ndefContext *ctx, uint16_t offset, uint8_t len) -{ - ReturnCode ret; - rfalIsoDepApduTxRxParam isoDepAPDU; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) || (len > ctx->subCtx.t4t.curMLe) || (offset > NDEF_T4T_OFFSET_MAX) ) - { - return ERR_PARAM; - } - - ndefT4TInitializeIsoDepTxRxParam(ctx, &isoDepAPDU); - (void)rfalT4TPollerComposeReadData(isoDepAPDU.txBuf, offset, len, &isoDepAPDU.txBufLen); - ret = ndefT4TTransceiveTxRx(ctx, &isoDepAPDU); - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerReadBinaryODO(ndefContext *ctx, uint32_t offset, uint8_t len) -{ - ReturnCode ret; - rfalIsoDepApduTxRxParam isoDepAPDU; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) || (len > ctx->subCtx.t4t.curMLe) || (offset > NDEF_T4T_ODO_OFFSET_MAX) ) - { - return ERR_PARAM; - } - - ndefT4TInitializeIsoDepTxRxParam(ctx, &isoDepAPDU); - (void)rfalT4TPollerComposeReadDataODO(isoDepAPDU.txBuf, offset, len, &isoDepAPDU.txBufLen); - ret = ndefT4TTransceiveTxRx(ctx, &isoDepAPDU); - - return ret; - } - -/*******************************************************************************/ -ReturnCode ndefT4TPollerReadBytes(ndefContext *ctx, uint32_t offset, uint32_t len, uint8_t *buf, uint32_t *rcvdLen) -{ - ReturnCode ret; - uint8_t le; - uint32_t lvOffset = offset; - uint32_t lvLen = len; - uint8_t * lvBuf = buf; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) || (lvLen == 0U) ) - { - return ERR_PARAM; - } - if( rcvdLen != NULL ) - { - *rcvdLen = 0U; - } - - do { - le = ( lvLen > ctx->subCtx.t4t.curMLe ) ? ctx->subCtx.t4t.curMLe : (uint8_t)lvLen; - if( lvOffset > NDEF_T4T_MV2_MAX_OFSSET ) - { - ret = ndefT4TPollerReadBinaryODO(ctx, lvOffset, le); - } - else - { - ret = ndefT4TPollerReadBinary(ctx, (uint16_t)lvOffset, le); - } - if( ret != ERR_NONE ) - { - return ret; - } - if( ctx->subCtx.t4t.rApduBodyLen == 0U ) - { - break; /* no more to read */ - } - if( ctx->subCtx.t4t.rApduBodyLen > lvLen ) - { - return ERR_SYSTEM; - } - (void)ST_MEMCPY(lvBuf, ctx->subCtx.t4t.rApduBuf.apdu, ctx->subCtx.t4t.rApduBodyLen); - lvBuf = &lvBuf[ctx->subCtx.t4t.rApduBodyLen]; - lvOffset += ctx->subCtx.t4t.rApduBodyLen; - lvLen -= ctx->subCtx.t4t.rApduBodyLen; - if( rcvdLen != NULL ) - { - *rcvdLen += ctx->subCtx.t4t.rApduBodyLen; - } - } while( lvLen != 0U ); - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev) -{ - if( (ctx == NULL) || (dev == NULL) || !ndefT4TisT4TDevice(dev) ) - { - return ERR_PARAM; - } - - (void)ST_MEMCPY(&ctx->device, dev, sizeof(ctx->device)); - - ctx->state = NDEF_STATE_INVALID; - ctx->subCtx.t4t.curMLc = NDEF_T4T_DEFAULT_MLC; - ctx->subCtx.t4t.curMLe = NDEF_T4T_DEFAULT_MLE; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerNdefDetect(ndefContext *ctx, ndefInfo *info) -{ - ReturnCode ret; - uint8_t* nLen; - uint8_t nlenLen; - - if( info != NULL ) - { - info->state = NDEF_STATE_INVALID; - info->majorVersion = 0U; - info->minorVersion = 0U; - info->areaLen = 0U; - info->areaAvalableSpaceLen = 0U; - info->messageLen = 0U; - } - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - ctx->state = NDEF_STATE_INVALID; - - /* Select NDEF Tag application TS T4T v1.0 7.2.1.1 */ - ret = ndefT4TPollerSelectNdefTagApplication(ctx); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.2 */ - return ret; - } - - /* TS T4T v1.0 7.2.1.3 and following */ - ret = ndefT4TReadAndParseCCFile(ctx); - if( ret != ERR_NONE ) - { - return ret; - } - nlenLen = ( ndefMajorVersion(ctx->cc.t4t.vNo) == ndefMajorVersion(NDEF_T4T_MAPPING_VERSION_3_0) ) ? NDEF_T4T_ENLEN_LEN : NDEF_T4T_NLEN_LEN; - - /* TS T4T v1.0 7.2.1.7 verify file READ access */ - if( !(ndefT4TIsReadAccessGranted(ctx->cc.t4t.readAccess)) ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.8 */ - return ERR_REQUEST; - } - /* File size need at least be enough to store NLEN or ENLEN */ - if( ctx->cc.t4t.fileSize < nlenLen) - { - return ERR_REQUEST; - } - - /* Select NDEF File TS T4T v1.0 7.2.1.9 */ - ret = ndefT4TPollerSelectFile(ctx, ctx->cc.t4t.fileId); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.10 */ - return ret; - } - /* Read NLEN/ENLEN TS T4T v1.0 7.2.1.11 */ - ret = ndefT4TPollerReadBinary(ctx, 0U, nlenLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.11 */ - return ret; - } - nLen = ctx->subCtx.t4t.rApduBuf.apdu; - ctx->messageLen = (nlenLen == NDEF_T4T_ENLEN_LEN) ? GETU32(&nLen[0]) : (uint32_t)ndefBytes2Uint16(nLen[0], nLen[1]); - ctx->messageOffset = nlenLen; - ctx->areaLen = ctx->cc.t4t.fileSize; - - if ( (ctx->messageLen > (ctx->cc.t4t.fileSize - nlenLen)) || ((ctx->messageLen > 0U) && (ctx->messageLen < NDEF_T4T_MIN_NLEN)) ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.11 */ - return ERR_REQUEST; - } - - if( ctx->messageLen == 0U ) - { - if( !(ndefT4TIsWriteAccessGranted(ctx->cc.t4t.writeAccess)) ) - { - /* Conclude procedure TS T4T v1.0 7.2.1.11 */ - return ERR_REQUEST; - } - ctx->state = NDEF_STATE_INITIALIZED; - } - else - { - ctx->state = (ndefT4TIsWriteAccessGranted(ctx->cc.t4t.writeAccess)) ? NDEF_STATE_READWRITE : NDEF_STATE_READONLY; - } - if( info != NULL ) - { - info->state = ctx->state; - info->majorVersion = ndefMajorVersion(ctx->cc.t4t.vNo); - info->minorVersion = ndefMinorVersion(ctx->cc.t4t.vNo); - info->areaLen = ctx->areaLen; - info->areaAvalableSpaceLen = ctx->areaLen - ctx->messageOffset; - info->messageLen = ctx->messageLen; - } - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) || (buf == NULL) ) - { - return ERR_PARAM; - } - /* TS T4T v1.0 7.2.2.1: T4T NDEF Detect should have been called before NDEF read procedure */ - /* Warning: current selected file must not be changed between NDEF Detect procedure and NDEF read procedure*/ - - /* TS T4T v1.0 7.3.3.2: check presence of NDEF message */ - if ( ctx->state <= NDEF_STATE_INITIALIZED ) - { - /* Conclude procedure TS T4T v1.0 7.2.2.2 */ - return ERR_WRONG_STATE; - } - - if( ctx->messageLen > bufLen ) - { - return ERR_NOMEM; - } - - /* TS T4T v1.0 7.3.3.3: read the NDEF message */ - ret = ndefT4TPollerReadBytes(ctx, ctx->messageOffset, ctx->messageLen, buf, rcvdLen); - if( ret != ERR_NONE ) - { - ctx->state = NDEF_STATE_INVALID; - } - - return ret; -} - -#if NDEF_FEATURE_ALL - -/*******************************************************************************/ -ReturnCode ndefT4TPollerWriteBinary(ndefContext *ctx, uint16_t offset, const uint8_t *data, uint8_t len) -{ - ReturnCode ret; - rfalIsoDepApduTxRxParam isoDepAPDU; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) || (len > ctx->subCtx.t4t.curMLc) || (offset > NDEF_T4T_OFFSET_MAX) ) - { - return ERR_PARAM; - } - - ndefT4TInitializeIsoDepTxRxParam(ctx, &isoDepAPDU); - (void)rfalT4TPollerComposeWriteData(isoDepAPDU.txBuf, offset, data, len, &isoDepAPDU.txBufLen); - ret = ndefT4TTransceiveTxRx(ctx, &isoDepAPDU); - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerWriteBinaryODO(ndefContext *ctx, uint32_t offset, const uint8_t *data, uint8_t len) -{ - ReturnCode ret; - rfalIsoDepApduTxRxParam isoDepAPDU; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) || (len > ctx->subCtx.t4t.curMLc) || (offset > NDEF_T4T_ODO_OFFSET_MAX) ) - { - return ERR_PARAM; - } - - ndefT4TInitializeIsoDepTxRxParam(ctx, &isoDepAPDU); - (void)rfalT4TPollerComposeWriteDataODO(isoDepAPDU.txBuf, offset, data, len, &isoDepAPDU.txBufLen); - ret = ndefT4TTransceiveTxRx(ctx, &isoDepAPDU); - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t *buf, uint32_t len) -{ - ReturnCode ret; - uint8_t lc; - uint32_t lvOffset = offset; - uint32_t lvLen = len; - const uint8_t * lvBuf = buf; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) || (lvLen == 0U) ) - { - return ERR_PARAM; - } - - do { - - if( lvOffset > NDEF_T4T_MV2_MAX_OFSSET ) - { - lc = ( lvLen > ((uint32_t)ctx->subCtx.t4t.curMLc - NDEF_T4T_WRITE_ODO_PREFIX_SIZE) ) ? (uint8_t)(ctx->subCtx.t4t.curMLc - NDEF_T4T_WRITE_ODO_PREFIX_SIZE) : (uint8_t)lvLen; - ret = ndefT4TPollerWriteBinaryODO(ctx, lvOffset, lvBuf, lc); - } - else - { - lc = ( lvLen > ctx->subCtx.t4t.curMLc ) ? ctx->subCtx.t4t.curMLc : (uint8_t)lvLen; - ret = ndefT4TPollerWriteBinary(ctx, (uint16_t)lvOffset, lvBuf, lc); - } - if( ret != ERR_NONE ) - { - return ret; - } - lvBuf = &lvBuf[lc]; - lvOffset += lc; - lvLen -= lc; - } while( lvLen != 0U ); - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen) -{ - ReturnCode ret; - uint8_t buf[NDEF_T4T_ENLEN_LEN]; - uint8_t dataIt; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if ( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - return ERR_WRONG_STATE; - } - - dataIt = 0U; - if( ndefMajorVersion(ctx->cc.t4t.vNo) == ndefMajorVersion(NDEF_T4T_MAPPING_VERSION_3_0) ) - { - buf[dataIt] = (uint8_t)(rawMessageLen >> 24U); - dataIt++; - buf[dataIt] = (uint8_t)(rawMessageLen >> 16U); - dataIt++; - buf[dataIt] = (uint8_t)(rawMessageLen >> 8U); - dataIt++; - buf[dataIt] = (uint8_t)(rawMessageLen); - dataIt++; - } - else - { - buf[dataIt] = (uint8_t)(rawMessageLen >> 8U); - dataIt++; - buf[dataIt] = (uint8_t)(rawMessageLen); - dataIt++; - } - - ret = ndefT4TPollerWriteBytes(ctx, 0U, buf, dataIt); - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerWriteRawMessage(ndefContext *ctx, const uint8_t *buf, uint32_t bufLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) || ((buf == NULL) && (bufLen != 0U)) ) - { - return ERR_PARAM; - } - - /* TS T4T v1.0 7.2.3.1: T4T NDEF Detect should have been called before NDEF write procedure */ - /* Warning: current selected file must not be changed between NDEF Detect procedure and NDEF Write procedure*/ - - /* TS T4T v1.0 7.3.3.2: check write access condition */ - if ( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - /* Conclude procedure TS T4T v1.0 7.2.3.2 */ - return ERR_WRONG_STATE; - } - - /* TS T4T v1.0 7.2.3.3: check Mapping Version */ - /* Done automatically inside underlying fucntions */ - - /* TS T4T v1.0 7.2.3.4/8 verify length of the NDEF message */ - ret = ndefT4TPollerCheckAvailableSpace(ctx, bufLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.3.4/8 */ - return ERR_PARAM; - } - - /* TS T4T v1.0 7.2.3.5/9 Write value 0000h in NLEN field (resp. 00000000h in ENLEN field) */ - ret = ndefT4TPollerBeginWriteMessage(ctx, bufLen); - if( ret != ERR_NONE ) - { - ctx->state = NDEF_STATE_INVALID; - /* Conclude procedure TS T4T v1.0 7.2.3.5/9 */ - return ret; - } - - if( bufLen != 0U ) - { - /* TS T4T v1.0 7.2.3.6/10 Write NDEF message) */ - ret = ndefT4TPollerWriteBytes(ctx, ctx->messageOffset, buf, bufLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.3.6/10 */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - - /* TS T4T v1.0 7.2.3.7/11 Write value length in NLEN field (resp. in ENLEN field) */ - ret = ndefT4TPollerEndWriteMessage(ctx, bufLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure TS T4T v1.0 7.2.3.7/11 */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - } - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerTagFormat(ndefContext *ctx, const ndefCapabilityContainer *cc, uint32_t options) -{ - ReturnCode ret; - - uint8_t buf[NDEF_T4T_ENLEN_LEN]; - - NO_WARNING(cc); - NO_WARNING(options); - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - ret = ndefT4TPollerSelectNdefTagApplication(ctx); - if( ret != ERR_NONE ) - { - return ret; - } - - ret = ndefT4TReadAndParseCCFile(ctx); - if( ret != ERR_NONE ) - { - return ret; - } - - ret = ndefT4TPollerSelectFile(ctx, ctx->cc.t4t.fileId); - if( ret != ERR_NONE ) - { - return ret; - } - (void)ST_MEMSET(buf, 0x00, sizeof(buf)); - ret = ndefT4TPollerWriteBytes(ctx, 0U, buf, ( ndefMajorVersion(ctx->cc.t4t.vNo) == ndefMajorVersion(NDEF_T4T_MAPPING_VERSION_3_0) ) ? NDEF_T4T_ENLEN_LEN : NDEF_T4T_NLEN_LEN); - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerCheckPresence(ndefContext *ctx) -{ - rfalIsoDepApduTxRxParam isoDepAPDU; - ReturnCode ret; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - ndefT4TInitializeIsoDepTxRxParam(ctx, &isoDepAPDU); - (void)rfalT4TPollerComposeReadData(isoDepAPDU.txBuf, 0, 1, &isoDepAPDU.txBufLen); - - /* Initialize respAPDU */ - ctx->subCtx.t4t.respAPDU.rApduBuf = &ctx->subCtx.t4t.rApduBuf; - isoDepAPDU.rxLen = &ctx->subCtx.t4t.respAPDU.rcvdLen; - - (void)rfalIsoDepStartApduTransceive(isoDepAPDU); - do { - /* Blocking implementation, T4T may define rather long timeouts */ - rfalWorker(); - ret = rfalIsoDepGetApduTransceiveStatus(); - } while (ret == ERR_BUSY); - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen) -{ - uint8_t nlenLen; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if ( ctx->state == NDEF_STATE_INVALID ) - { - return ERR_WRONG_STATE; - } - - nlenLen = ( ndefMajorVersion(ctx->cc.t4t.vNo) == ndefMajorVersion(NDEF_T4T_MAPPING_VERSION_3_0) ) ? NDEF_T4T_ENLEN_LEN : NDEF_T4T_NLEN_LEN; - if( (messageLen + (uint32_t)nlenLen) > ctx->cc.t4t.fileSize ) - { - return ERR_NOMEM; - } - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - ReturnCode ret; - NO_WARNING(messageLen); - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - return ERR_WRONG_STATE; - } - - /* TS T4T v1.0 7.2.3.5/9 Write value 0000h in NLEN field (resp. 00000000h in ENLEN field) */ - ret = ndefT4TPollerWriteRawMessageLen(ctx, 0U); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - - ctx->state = NDEF_STATE_INITIALIZED; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT4TPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT4TisT4TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( ctx->state != NDEF_STATE_INITIALIZED ) - { - return ERR_WRONG_STATE; - } - - /* TS T4T v1.0 7.2.3.7/11 Write value length in NLEN field (resp. in ENLEN field) */ - ret = ndefT4TPollerWriteRawMessageLen(ctx, messageLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - ctx->messageLen = messageLen; - ctx->state = (ctx->messageLen == 0U) ? NDEF_STATE_INITIALIZED : NDEF_STATE_READWRITE; - return ERR_NONE; -} - -#endif /* NDEF_FEATURE_ALL */ - -#endif /* RFAL_FEATURE_T4T */ diff --git a/Software/Middlewares/ST/ndef/Src/poller/ndef_t5t.c b/Software/Middlewares/ST/ndef/Src/poller/ndef_t5t.c deleted file mode 100644 index bb5934f..0000000 --- a/Software/Middlewares/ST/ndef/Src/poller/ndef_t5t.c +++ /dev/null @@ -1,1149 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: NDEF firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author - * - * \brief Provides NDEF methods and definitions to access NFC-V Forum T5T - * - * This module provides an interface to perform as a NFC-V Reader/Writer - * to handle a Type 5 Tag T5T - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - #include "ndef_poller.h" - #include "ndef_t5t.h" - #include "utils.h" - - /* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_NFCV - #error " RFAL: Module configuration missing. Please enable/disable T5T support by setting: RFAL_FEATURE_NFCV " -#endif - -#if RFAL_FEATURE_NFCV - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define NDEF_T5T_UID_MANUFACTURER_ID_POS 6U /*!< Manufacturer ID Offset in UID buffer (reverse) */ -#define NDEF_T5T_MANUFACTURER_ID_ST 0x02U /*!< Manufacturer ID for ST */ - -#define NDEF_T5T_SYSINFO_MAX_LEN 22U /*!< Max length for (Extended) Get System Info response */ - -#define NDEF_T5T_MLEN_DIVIDER 8U /*!< T5T_area size is measured in bytes is equal to 8 * MLEN */ - -#define NDEF_T5T_TLV_L_3_BYTES_LEN 3U /*!< TLV L Length: 3 bytes */ -#define NDEF_T5T_TLV_L_1_BYTES_LEN 1U /*!< TLV L Length: 1 bytes */ -#define NDEF_T5T_TLV_T_LEN 1U /*!< TLV T Length: 1 bytes */ - -#define NDEF_T5T_MAX_BLOCK_1_BYTE_ADDR 256U /*!< Max number of blocks for 1 byte addressing */ -#define NDEF_T5T_MAX_MLEN_1_BYTE_ENCODING 256U /*!< MLEN max value for 1 byte encoding */ - -#define NDEF_T5T_TL_MAX_SIZE (NDEF_T5T_TLV_T_LEN \ - + NDEF_T5T_TLV_L_3_BYTES_LEN) /*!< Max TL size */ - -#define NDEF_T5T_TLV_NDEF 0x03U /*!< TLV flag NDEF value */ -#define NDEF_T5T_TLV_PROPRIETARY 0xFDU /*!< TLV flag PROPRIETARY value */ -#define NDEF_T5T_TLV_TERMINATOR 0xFEU /*!< TLV flag TERMINATOR value */ -#define NDEF_T5T_TLV_RFU 0x00U /*!< TLV flag RFU value */ - -/* - ***************************************************************************** - * GLOBAL TYPES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define ndefT5TisT5TDevice(device) ((device)->type == RFAL_NFC_LISTEN_TYPE_NFCV) - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -static ReturnCode ndefT5TPollerReadSingleBlock(ndefContext *ctx, uint16_t blockNum, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvLen); -static ReturnCode ndefT5TGetSystemInformation(ndefContext *ctx, bool extended); - -#if NDEF_FEATURE_ALL -static ReturnCode ndefT5TWriteCC(ndefContext *ctx); -static ReturnCode ndefT5TPollerWriteSingleBlock(ndefContext *ctx, uint16_t blockNum, const uint8_t* wrData); -static ReturnCode ndefT5TPollerReadMultipleBlocks(ndefContext *ctx, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvLen); -#endif /* NDEF_FEATURE_ALL */ - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - -/*******************************************************************************/ -ReturnCode ndefT5TPollerReadBytes(ndefContext * ctx, uint32_t offset, uint32_t len, uint8_t* buf, uint32_t * rcvdLen ) -{ - uint8_t lastVal; - uint8_t status; - uint16_t res; - uint16_t nbRead; - uint16_t blockLen; - uint16_t startBlock; - uint16_t startAddr; - ReturnCode result = ERR_PARAM; - uint32_t currentLen = len; - uint32_t lvRcvLen = 0U; - - if ( ( ctx != NULL) && (ctx->subCtx.t5t.blockLen > 0U) && (buf != NULL) && (len > 0U) ) - { - blockLen = (uint16_t )ctx->subCtx.t5t.blockLen; - if( blockLen == 0U ) - { - return ERR_SYSTEM; - } - startBlock = (uint16_t) (offset / blockLen); - startAddr = (uint16_t) (startBlock * blockLen); - - res = ndefT5TPollerReadSingleBlock(ctx, startBlock, ctx->subCtx.t5t.txrxBuf, blockLen + 3U, &nbRead); - if ( (res == ERR_NONE) && (ctx->subCtx.t5t.txrxBuf[0U] == 0U) && (nbRead > 0U) ) - { - nbRead = (uint16_t) (nbRead + startAddr - (uint16_t)offset - 1U ); - if ((uint32_t) nbRead > currentLen) - { - nbRead = (uint16_t) currentLen; - } - if (nbRead > 0U) - { - (void)ST_MEMCPY(buf, &ctx->subCtx.t5t.txrxBuf[1U - startAddr + (uint16_t)offset], (uint32_t)nbRead); - } - lvRcvLen += (uint32_t) nbRead; - currentLen -= (uint32_t) nbRead; - while (currentLen >= ((uint32_t)blockLen + 2U) ) - { - startBlock++; - lastVal = buf[lvRcvLen - 1U]; - res = ndefT5TPollerReadSingleBlock(ctx, startBlock, &buf[lvRcvLen - 1U], blockLen + 3U, &nbRead); - status = buf[lvRcvLen - 1U]; /* Keep status */ - buf[lvRcvLen - 1U] = lastVal; /* Restore previous value */ - if ( (res == ERR_NONE) && (nbRead > 0U) && (status == 0U)) - { - lvRcvLen += blockLen; - currentLen -= blockLen; - } - else - { - break; - } - } - while (currentLen > 0U) - { - startBlock++; - res = ndefT5TPollerReadSingleBlock(ctx, startBlock, ctx->subCtx.t5t.txrxBuf, blockLen + 3U, &nbRead); - if ( (res == ERR_NONE) && (ctx->subCtx.t5t.txrxBuf[0U] == 0U) && (nbRead > 0U)) - { - -- nbRead; /* remove status char */ - if (nbRead > currentLen) - { - nbRead = (uint16_t)currentLen; - } - if (nbRead > 0U) - { - (void)ST_MEMCPY(&buf[lvRcvLen], & ctx->subCtx.t5t.txrxBuf[1U], nbRead); - } - lvRcvLen += nbRead; - currentLen -= nbRead; - } - else - { - break; - } - } - } - } - if (currentLen == 0U) - { - result = ERR_NONE; - } - if( rcvdLen != NULL ) - { - * rcvdLen = lvRcvLen; - } - return result; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerContextInitialization(ndefContext *ctx, const rfalNfcDevice *dev) -{ - ReturnCode result; - uint16_t rcvLen; - - if( (ctx == NULL) || (dev == NULL) || !ndefT5TisT5TDevice(dev) ) - { - return ERR_PARAM; - } - - (void)ST_MEMCPY(&ctx->device, dev, sizeof(ctx->device)); - - /* Reset info about the card */ - ctx->state = NDEF_STATE_INVALID; - ctx->messageOffset = 0U; - ctx->messageLen = 0U; - ctx->subCtx.t5t.blockLen = 0U; - ctx->subCtx.t5t.pAddressedUid = ctx->device.dev.nfcv.InvRes.UID; /* By default work in addressed mode */ - ctx->subCtx.t5t.TlvNDEFOffset = 0U; /* Offset for TLV */ - - ctx->subCtx.t5t.legacySTHighDensity = false; - result = ndefT5TPollerReadSingleBlock( ctx, 0U, ctx->subCtx.t5t.txrxBuf, (uint16_t)sizeof(ctx->subCtx.t5t.txrxBuf), &rcvLen ); - if( (result != ERR_NONE) && (ctx->device.dev.nfcv.InvRes.UID[NDEF_T5T_UID_MANUFACTURER_ID_POS] == NDEF_T5T_MANUFACTURER_ID_ST) ) - { - /* Try High Density Legacy mode */ - ctx->subCtx.t5t.legacySTHighDensity = true; - result = ndefT5TPollerReadSingleBlock( ctx, 0U, ctx->subCtx.t5t.txrxBuf, (uint16_t)sizeof(ctx->subCtx.t5t.txrxBuf), &rcvLen ); - if( result != ERR_NONE ) - { - return result; - } - } - - if( (rcvLen > 1U) && (ctx->subCtx.t5t.txrxBuf[0U] == (uint8_t) 0U) ) - { - ctx->subCtx.t5t.blockLen = (uint8_t) (rcvLen - 1U); - } - else - { - return ERR_PROTO; - } - - if (rfalNfcvPollerSelect( (uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT, ctx->device.dev.nfcv.InvRes.UID) == ERR_NONE) - { - ctx->subCtx.t5t.pAddressedUid = NULL; /* Switch to selected mode */ - } - - ctx->subCtx.t5t.sysInfoSupported = false; - - if( !ctx->subCtx.t5t.legacySTHighDensity) - { - /* Extended Get System Info */ - if( ndefT5TGetSystemInformation(ctx, true) == ERR_NONE ) - { - ctx->subCtx.t5t.sysInfoSupported = true; - } - } - if( !ctx->subCtx.t5t.sysInfoSupported ) - { - /* Get System Info */ - if( ndefT5TGetSystemInformation(ctx, false) == ERR_NONE ) - { - ctx->subCtx.t5t.sysInfoSupported = true; - } - } - return result; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerNdefDetect(ndefContext * ctx, ndefInfo *info) -{ - ReturnCode result; - uint8_t tmpBuf[NDEF_T5T_TL_MAX_SIZE]; - ReturnCode returnCode = ERR_REQUEST; /* Default return code */ - uint16_t offset; - uint16_t length; - uint32_t TlvOffset; - bool bExit; - uint32_t rcvLen; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - ctx->state = NDEF_STATE_INVALID; - ctx->cc.t5t.ccLen = 0U; - ctx->cc.t5t.memoryLen = 0U; - ctx->messageLen = 0U; - ctx->messageOffset = 0U; - - if( info != NULL ) - { - info->state = NDEF_STATE_INVALID; - info->majorVersion = 0U; - info->minorVersion = 0U; - info->areaLen = 0U; - info->areaAvalableSpaceLen = 0U; - info->messageLen = 0U; - } - - result = ndefT5TPollerReadBytes(ctx, 0U, 8U, ctx->ccBuf, &rcvLen); - if ( (result == ERR_NONE) && (rcvLen == 8U) && ( (ctx->ccBuf[0] == (uint8_t)0xE1U) || (ctx->ccBuf[0] == (uint8_t)0xE2U) ) ) - { - ctx->cc.t5t.magicNumber = ctx->ccBuf[0U]; - ctx->cc.t5t.majorVersion = (ctx->ccBuf[1U] >> 6U ) & 0x03U; - ctx->cc.t5t.minorVersion = (ctx->ccBuf[1U] >> 4U ) & 0x03U; - ctx->cc.t5t.readAccess = (ctx->ccBuf[1U] >> 2U ) & 0x03U; - ctx->cc.t5t.writeAccess = (ctx->ccBuf[1U] >> 0U ) & 0x03U; - ctx->cc.t5t.memoryLen = ctx->ccBuf[2U]; - ctx->cc.t5t.multipleBlockRead = (((ctx->ccBuf[3U] >> 0U ) & 0x01U) != 0U); - ctx->cc.t5t.mlenOverflow = (((ctx->ccBuf[3U] >> 2U ) & 0x01U) != 0U); - ctx->cc.t5t.lockBlock = (((ctx->ccBuf[3U] >> 3U ) & 0x01U) != 0U); - ctx->cc.t5t.specialFrame = (((ctx->ccBuf[3U] >> 4U ) & 0x01U) != 0U); - ctx->state = NDEF_STATE_INITIALIZED; - - if ( ctx->cc.t5t.memoryLen != 0U) - { - ctx->cc.t5t.ccLen = NDEF_T5T_CC_LEN_4_BYTES; - if( (ctx->cc.t5t.memoryLen == 0xFFU) && ctx->cc.t5t.mlenOverflow ) - { - if( (ctx->subCtx.t5t.sysInfoSupported==true) && ( ndefT5TSysInfoMemSizePresent(ctx->subCtx.t5t.sysInfo.infoFlags) != 0U) ) - { - ctx->cc.t5t.memoryLen = (uint16_t)((ctx->subCtx.t5t.sysInfo.numberOfBlock * ctx->subCtx.t5t.sysInfo.blockSize) / NDEF_T5T_MLEN_DIVIDER); - } - } - } - else - { - ctx->cc.t5t.ccLen = NDEF_T5T_CC_LEN_8_BYTES; - ctx->cc.t5t.memoryLen = ((uint16_t)ctx->ccBuf[6U] << 8U) + (uint16_t)ctx->ccBuf[7U]; - } - if( (ctx->subCtx.t5t.sysInfoSupported==true) && - (ndefT5TSysInfoMemSizePresent(ctx->subCtx.t5t.sysInfo.infoFlags)!= 0U) && - (ctx->cc.t5t.memoryLen == (uint16_t)((ctx->subCtx.t5t.sysInfo.numberOfBlock * ctx->subCtx.t5t.sysInfo.blockSize) / NDEF_T5T_MLEN_DIVIDER)) && - (ctx->cc.t5t.memoryLen > 0U) ) - { - ctx->cc.t5t.memoryLen--; /* remove CC area from memory len */ - } - ctx->messageLen = 0U; - ctx->messageOffset = ctx->cc.t5t.ccLen; - TlvOffset = ctx->cc.t5t.ccLen; - bExit = false; - do - { - result = ndefT5TPollerReadBytes(ctx, TlvOffset, NDEF_T5T_TL_MAX_SIZE, tmpBuf, &rcvLen); - if ( (result != ERR_NONE) || ( rcvLen != NDEF_T5T_TL_MAX_SIZE) ) - { - break; - } - offset = 2U; - length = tmpBuf[1U]; - if ( length == (NDEF_SHORT_VFIELD_MAX_LEN + 1U) ) - { - /* Size is encoded in 1 + 2 bytes */ - length = (((uint16_t)tmpBuf[2U]) << 8U) + (uint16_t)tmpBuf[3U]; - offset += 2U; - } - if (tmpBuf[0U] == (uint8_t)NDEF_T5T_TLV_NDEF) - { - /* NDEF record return it */ - returnCode = ERR_NONE; /* Default */ - ctx->subCtx.t5t.TlvNDEFOffset = TlvOffset; /* Offset for TLV */ - ctx->messageOffset = TlvOffset + offset; - ctx->messageLen = length; - TlvOffset = 0U; - if (length == 0U) - { - /* Req 40 7.5.1.6 */ - if ( (ctx->cc.t5t.readAccess == 0U) && (ctx->cc.t5t.writeAccess == 0U) ) - { - ctx->state = NDEF_STATE_INITIALIZED; - } - else - { - ctx->state = NDEF_STATE_INVALID; - returnCode = ERR_REQUEST; /* Default */ - } - bExit = true; - } - else - { - if (ctx->cc.t5t.readAccess == 0U) - { - if (ctx->cc.t5t.writeAccess == 0U) - { - ctx->state = NDEF_STATE_READWRITE; - } - else - { - ctx->state = NDEF_STATE_READONLY; - } - } - bExit = true; - } - } - else if (tmpBuf[0U]== (uint8_t) NDEF_T5T_TLV_TERMINATOR) - { - /* NDEF end */ - TlvOffset = 0U; - bExit = true; - } - else if (tmpBuf[0U]== (uint8_t) NDEF_T5T_TLV_PROPRIETARY) - { /* proprietary go next, nothing to do */ - TlvOffset += (uint32_t)offset + (uint32_t)length; - } - else - { - /* RFU value */ - TlvOffset = 0U; - bExit = true; - } - } while ( ( TlvOffset > 0U) && (bExit == false) ); - } - else - { - /* No CCFile */ - returnCode = ERR_REQUEST; - if (result != ERR_NONE) - { - returnCode = result; - } - } - - /* TS T5T v1.0 4.3.1.17 T5T_area size is measured in bytes is equal to 8 * MLEN */ - ctx->areaLen = (uint32_t)ctx->cc.t5t.memoryLen * NDEF_T5T_MLEN_DIVIDER; - if( info != NULL ) - { - info->state = ctx->state; - info->majorVersion = ctx->cc.t5t.majorVersion; - info->minorVersion = ctx->cc.t5t.minorVersion; - info->areaLen = ctx->areaLen; - info->areaAvalableSpaceLen = (uint32_t)ctx->cc.t5t.ccLen + ctx->areaLen - ctx->messageOffset; - info->messageLen = ctx->messageLen; - } - return returnCode; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerReadRawMessage(ndefContext *ctx, uint8_t *buf, uint32_t bufLen, uint32_t *rcvdLen) -{ - ReturnCode result; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) || (buf == NULL) ) - { - return ERR_PARAM; - } - - if( ctx->messageLen > bufLen ) - { - return ERR_NOMEM; - } - - result = ndefT5TPollerReadBytes( ctx, ctx->messageOffset, ctx->messageLen, buf, rcvdLen ); - return result; -} - -#if NDEF_FEATURE_ALL - -/*******************************************************************************/ -ReturnCode ndefT5TPollerWriteBytes(ndefContext *ctx, uint32_t offset, const uint8_t * buf, uint32_t len) -{ - ReturnCode result = ERR_REQUEST; - ReturnCode res; - uint16_t nbRead; - uint16_t blockLen16; - uint16_t startBlock; - uint16_t startAddr ; - const uint8_t * wrbuf = buf; - uint32_t currentLen = len; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) || (len == 0U) || (ctx->subCtx.t5t.blockLen == 0U)) - { - return ERR_PARAM; - } - blockLen16 = (uint16_t )ctx->subCtx.t5t.blockLen; - if( blockLen16 == 0U ) - { - return ERR_SYSTEM; - } - startBlock = (uint16_t) (offset / blockLen16); - startAddr = (uint16_t) (startBlock * blockLen16); - - if (startAddr != offset) - { - /* Unaligned start offset must read the first block before */ - res = ndefT5TPollerReadSingleBlock(ctx, startBlock, ctx->subCtx.t5t.txrxBuf, blockLen16 + 3U, &nbRead); - if ( (res == ERR_NONE) && (ctx->subCtx.t5t.txrxBuf[0U] == 0U) && (nbRead > 0U) ) - { - nbRead = (uint16_t) ((uint32_t)nbRead - 1U + startAddr - offset); - if (nbRead > (uint32_t) currentLen) - { - nbRead = (uint16_t) currentLen; - } - if (nbRead > 0U) - { - (void)ST_MEMCPY(&ctx->subCtx.t5t.txrxBuf[1U - startAddr + (uint16_t)offset], wrbuf, nbRead); - } - res = ndefT5TPollerWriteSingleBlock(ctx, startBlock, &ctx->subCtx.t5t.txrxBuf[1U]); - if (res != ERR_NONE) - { - return res; - } - } - else - { - if (res != ERR_NONE) - { - result = res; - } - else - { - result = ERR_PARAM; - } - return result; - } - currentLen -= nbRead; - wrbuf = &wrbuf[nbRead]; - startBlock++; - } - while (currentLen >= blockLen16) - { - res = ndefT5TPollerWriteSingleBlock(ctx, startBlock, wrbuf); - if (res == ERR_NONE) - { - currentLen -= blockLen16; - wrbuf = &wrbuf[blockLen16]; - startBlock++; - } - else - { - result = res; - break; - } - } - if ( (currentLen != 0U) && (currentLen < blockLen16) ) - { - /* Unaligned end, must read the first block before */ - res = ndefT5TPollerReadSingleBlock(ctx, startBlock, ctx->subCtx.t5t.txrxBuf, blockLen16 + 3U, &nbRead); - if ( (res == ERR_NONE) && (ctx->subCtx.t5t.txrxBuf[0U] == 0U) && (nbRead > 0U) ) - { - if (currentLen > 0U) { (void)ST_MEMCPY(&ctx->subCtx.t5t.txrxBuf[1U], wrbuf, currentLen); } - res = ndefT5TPollerWriteSingleBlock(ctx, startBlock, &ctx->subCtx.t5t.txrxBuf[1U]); - if (res != ERR_NONE) - { - result = res; - } - else - { - currentLen = 0U; - } - } - else - { - if (res != ERR_NONE) - { - result = res; - } - else - { - result = ERR_PARAM; - } - return result; - } - } - if (currentLen == 0U) - { - result = ERR_NONE; - } - return result; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerWriteRawMessageLen(ndefContext *ctx, uint32_t rawMessageLen) -{ - uint8_t TLV[8U]; - ReturnCode result = ERR_PARAM; - uint8_t len = 0U; - - if( (ctx != NULL) && ndefT5TisT5TDevice(&ctx->device)) - { - if ( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - result = ERR_WRONG_STATE; - } - else - { - TLV[len] = NDEF_T5T_TLV_NDEF; - len++; - if (rawMessageLen <= NDEF_SHORT_VFIELD_MAX_LEN) - { - TLV[len] = (uint8_t) rawMessageLen; - len++; - } - else - { - TLV[len] = (uint8_t) (rawMessageLen >> 8U); - len++; - TLV[len] = (uint8_t) rawMessageLen; - len++; - } - if (rawMessageLen == 0U) - { - TLV[len] = NDEF_TERMINATOR_TLV_T; /* TLV terminator */ - len++; - } - - result = ndefT5TPollerWriteBytes(ctx, ctx->subCtx.t5t.TlvNDEFOffset, TLV, len); - if ((result == ERR_NONE) && (rawMessageLen != 0U)) - { /* T5T need specific terminator */ - len = 0U; - TLV[len] = NDEF_TERMINATOR_TLV_T; /* TLV terminator */ - len++; - result = ndefT5TPollerWriteBytes(ctx, ctx->messageOffset + rawMessageLen, TLV, len ); - } - } - } - return result; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerWriteRawMessage(ndefContext *ctx, const uint8_t * buf, uint32_t bufLen) -{ - uint32_t len = bufLen ; - ReturnCode result; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) || (buf == NULL) ) - { - return ERR_PARAM; - } - - /* TS T5T v1.0 7.5.3.1/2: T5T NDEF Detect should have been called before NDEF write procedure */ - /* Warning: current tag content must not be changed between NDEF Detect procedure and NDEF Write procedure*/ - - /* TS T5T v1.0 7.5.3.3: check write access condition */ - if ( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - /* Conclude procedure */ - return ERR_WRONG_STATE; - } - - /* TS T5T v1.0 7.5.3.3: verify available space */ - result = ndefT5TPollerCheckAvailableSpace(ctx, bufLen); - if( result != ERR_NONE ) - { - /* Conclude procedures */ - return ERR_PARAM; - } - /* TS T5T v1.0 7.5.3.4: reset L-Field to 0 */ - /* and update ctx->messageOffset according to L-field len */ - result = ndefT5TPollerBeginWriteMessage(ctx, bufLen); - if (result != ERR_NONE) - { - ctx->state = NDEF_STATE_INVALID; - /* Conclude procedure */ - return result; - } - if( bufLen != 0U ) - { - /* TS T5T v1.0 7.5.3.5: write new NDEF message */ - result = ndefT5TPollerWriteBytes(ctx, ctx->messageOffset, buf, len); - if (result != ERR_NONE) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return result; - } - /* TS T5T v1.0 7.5.3.6 & 7.5.3.7: update L-Field and write Terminator TLV */ - result = ndefT5TPollerEndWriteMessage(ctx, len); - if (result != ERR_NONE) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return result; - } - } - return result; -} - -/*******************************************************************************/ -static ReturnCode ndefT5TWriteCC(ndefContext *ctx) -{ - ReturnCode ret; - uint8_t* buf; - uint8_t dataIt; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - buf = ctx->ccBuf; - dataIt = 0U; - /* Encode CC */ - buf[dataIt] = ctx->cc.t5t.magicNumber; /* Byte 0 */ - dataIt++; - buf[dataIt] = (uint8_t)(((ctx->cc.t5t.majorVersion & 0x03U) << 6) | /* Byte 1 */ - ((ctx->cc.t5t.minorVersion & 0x03U) << 4) | /* */ - ((ctx->cc.t5t.readAccess & 0x03U) << 2) | /* */ - ((ctx->cc.t5t.writeAccess & 0x03U) << 0)); /* */ - dataIt++; - buf[dataIt] = (ctx->cc.t5t.ccLen == NDEF_T5T_CC_LEN_8_BYTES) ? 0U : (uint8_t)ctx->cc.t5t.memoryLen; /* Byte 2 */ - dataIt++; - buf[dataIt] = 0U; /* Byte 3 */ - if( ctx->cc.t5t.multipleBlockRead ) { buf[dataIt] |= 0x01U; } /* Byte 3 b0 MBREAD */ - if( ctx->cc.t5t.mlenOverflow ) { buf[dataIt] |= 0x04U; } /* Byte 3 b2 Android MLEN overflow */ - if( ctx->cc.t5t.lockBlock ) { buf[dataIt] |= 0x08U; } /* Byte 3 b3 Lock Block */ - if( ctx->cc.t5t.specialFrame ) { buf[dataIt] |= 0x10U; } /* Byte 3 b4 Special Frame */ - dataIt++; - if( ctx->cc.t5t.ccLen == NDEF_T5T_CC_LEN_8_BYTES ) - { - buf[dataIt] = 0U; /* Byte 4 */ - dataIt++; - buf[dataIt] = 0U; /* Byte 5 */ - dataIt++; - buf[dataIt] = (uint8_t)(ctx->cc.t5t.memoryLen >> 8); /* Byte 6 */ - dataIt++; - buf[dataIt] = (uint8_t)(ctx->cc.t5t.memoryLen >> 0); /* Byte 7 */ - dataIt++; - } - - ret = ndefT5TPollerWriteBytes(ctx, 0U, buf, ctx->cc.t5t.ccLen ); - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerTagFormat(ndefContext * ctx, const ndefCapabilityContainer *cc, uint32_t options) -{ - uint16_t rcvdLen; - ReturnCode result; - static const uint8_t emptyNDEF[] = { 0x03U, 0x00U, 0xFEU, 0x00U}; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - /* Reset previous potential info about NDEF messages */ - ctx->messageLen = 0U; - ctx->messageOffset = 0U; - ctx->subCtx.t5t.TlvNDEFOffset = 0U; - - if( cc != NULL ) - { - if( (cc->t5t.ccLen != NDEF_T5T_CC_LEN_8_BYTES) && (cc->t5t.ccLen != NDEF_T5T_CC_LEN_4_BYTES) ) - { - return ERR_PARAM; - } - (void)ST_MEMCPY(&ctx->cc, cc, sizeof(ndefCapabilityContainer)); - } - else - { - /* Try to find the appropriate cc values */ - ctx->cc.t5t.magicNumber = NDEF_T5T_CC_MAGIC_1_BYTE_ADDR_MODE; /* E1 */ - ctx->cc.t5t.majorVersion = 1U; - ctx->cc.t5t.minorVersion = 0U; - ctx->cc.t5t.readAccess = 0U; - ctx->cc.t5t.writeAccess = 0U; - ctx->cc.t5t.lockBlock = false; - ctx->cc.t5t.specialFrame = false; - ctx->cc.t5t.memoryLen = 0U; - ctx->cc.t5t.mlenOverflow = false; - - result = ndefT5TPollerReadMultipleBlocks(ctx, 0U, 0U, ctx->subCtx.t5t.txrxBuf, (uint16_t)sizeof(ctx->subCtx.t5t.txrxBuf), &rcvdLen); - ctx->cc.t5t.multipleBlockRead = (result == ERR_NONE) ? true : false; - - /* Try to retrieve the tag's size using getSystemInfo and GetExtSystemInfo */ - - if ( (ctx->subCtx.t5t.sysInfoSupported==true) && (ndefT5TSysInfoMemSizePresent(ctx->subCtx.t5t.sysInfo.infoFlags)!=0U) ) - { - ctx->cc.t5t.memoryLen = (uint16_t)((ctx->subCtx.t5t.sysInfo.numberOfBlock * ctx->subCtx.t5t.sysInfo.blockSize) / NDEF_T5T_MLEN_DIVIDER); - - if( (options & NDEF_T5T_FORMAT_OPTION_NFC_FORUM) == NDEF_T5T_FORMAT_OPTION_NFC_FORUM ) /* NFC Forum format */ - { - if( ctx->cc.t5t.memoryLen >= NDEF_T5T_MAX_MLEN_1_BYTE_ENCODING ) - { - ctx->cc.t5t.ccLen = NDEF_T5T_CC_LEN_8_BYTES; - } - if( ctx->cc.t5t.memoryLen > 0U ) - { - ctx->cc.t5t.memoryLen--; /* remove CC area from memory len */ - } - } - else /* Android format */ - { - ctx->cc.t5t.ccLen = NDEF_T5T_CC_LEN_4_BYTES; - if( ctx->cc.t5t.memoryLen >= NDEF_T5T_MAX_MLEN_1_BYTE_ENCODING ) - { - ctx->cc.t5t.mlenOverflow = true; - ctx->cc.t5t.memoryLen = 0xFFU; - } - } - - if( !ctx->subCtx.t5t.legacySTHighDensity && (ctx->subCtx.t5t.sysInfo.numberOfBlock > NDEF_T5T_MAX_BLOCK_1_BYTE_ADDR) ) - { - ctx->cc.t5t.magicNumber = NDEF_T5T_CC_MAGIC_2_BYTE_ADDR_MODE; /* E2 */ - } - } - else - { - return ERR_REQUEST; - } - } - - result = ndefT5TWriteCC(ctx); - if( result != ERR_NONE ) - { - /* If write fails, try to use special frame if not yet used */ - if( !ctx->cc.t5t.specialFrame ) - { - platformDelay(20U); /* Wait to be sure that previous command has ended */ - ctx->cc.t5t.specialFrame = true; /* Add option flag */ - result = ndefT5TWriteCC(ctx); - if( result != ERR_NONE ) - { - ctx->cc.t5t.specialFrame = false; /* Add option flag */ - return result; - } - } - else - { - return result; - } - } - /* Update info about current NDEF */ - - ctx->subCtx.t5t.TlvNDEFOffset = ctx->cc.t5t.ccLen; - - result = ndefT5TPollerWriteBytes(ctx, ctx->subCtx.t5t.TlvNDEFOffset, emptyNDEF, sizeof(emptyNDEF) ); - if (result == ERR_NONE) - { - /* Update info about current NDEF */ - ctx->messageOffset = (uint32_t)ctx->cc.t5t.ccLen + 0x02U; - ctx->state = NDEF_STATE_INITIALIZED; - } - return result; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerCheckPresence(ndefContext *ctx) -{ - ReturnCode ret; - uint16_t blockAddr; - uint16_t rcvLen; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - blockAddr = 0U; - - ret = ndefT5TPollerReadSingleBlock( ctx, blockAddr, ctx->subCtx.t5t.txrxBuf, (uint16_t)sizeof(ctx->subCtx.t5t.txrxBuf), &rcvLen ); - - return ret; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerCheckAvailableSpace(const ndefContext *ctx, uint32_t messageLen) -{ - uint32_t lLen; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if ( ctx->state == NDEF_STATE_INVALID ) - { - return ERR_WRONG_STATE; - } - - lLen = ( messageLen > NDEF_SHORT_VFIELD_MAX_LEN) ? NDEF_T5T_TLV_L_3_BYTES_LEN : NDEF_T5T_TLV_L_1_BYTES_LEN; - - if( (messageLen + ctx->subCtx.t5t.TlvNDEFOffset + NDEF_T5T_TLV_T_LEN + lLen) > (ctx->areaLen + ctx->cc.t5t.ccLen) ) - { - return ERR_NOMEM; - } - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerBeginWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - ReturnCode ret; - uint32_t lLen; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( (ctx->state != NDEF_STATE_INITIALIZED) && (ctx->state != NDEF_STATE_READWRITE) ) - { - return ERR_WRONG_STATE; - } - - /* TS T5T v1.0 7.5.3.4: reset L-Field to 0 */ - ret = ndefT5TPollerWriteRawMessageLen(ctx, 0U); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - - lLen = ( messageLen > NDEF_SHORT_VFIELD_MAX_LEN) ? NDEF_T5T_TLV_L_3_BYTES_LEN : NDEF_T5T_TLV_L_1_BYTES_LEN; - ctx->messageOffset = ctx->subCtx.t5t.TlvNDEFOffset; - ctx->messageOffset += NDEF_T5T_TLV_T_LEN; /* T Len */ - ctx->messageOffset += lLen; /* L Len */ - ctx->state = NDEF_STATE_INITIALIZED; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode ndefT5TPollerEndWriteMessage(ndefContext *ctx, uint32_t messageLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( ctx->state != NDEF_STATE_INITIALIZED ) - { - return ERR_WRONG_STATE; - } - - /* TS T5T v1.0 7.5.3.6 & 7.5.3.7: update L-Field and write Terminator TLV */ - ret = ndefT5TPollerWriteRawMessageLen(ctx, messageLen); - if( ret != ERR_NONE ) - { - /* Conclude procedure */ - ctx->state = NDEF_STATE_INVALID; - return ret; - } - ctx->messageLen = messageLen; - ctx->state = (ctx->messageLen == 0U) ? NDEF_STATE_INITIALIZED : NDEF_STATE_READWRITE; - return ERR_NONE; -} - -/*******************************************************************************/ -static ReturnCode ndefT5TPollerWriteSingleBlock(ndefContext *ctx, uint16_t blockNum, const uint8_t* wrData) -{ - ReturnCode ret; - uint8_t flags; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - flags = ctx->cc.t5t.specialFrame ? ((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT | (uint8_t)RFAL_NFCV_REQ_FLAG_OPTION): (uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT; - - if( ctx->subCtx.t5t.legacySTHighDensity ) - { - ret = rfalST25xVPollerM24LRWriteSingleBlock(flags, ctx->subCtx.t5t.pAddressedUid, blockNum, wrData, ctx->subCtx.t5t.blockLen); - } - else - { - if( blockNum < NDEF_T5T_MAX_BLOCK_1_BYTE_ADDR ) - { - ret = rfalNfcvPollerWriteSingleBlock(flags, ctx->subCtx.t5t.pAddressedUid, (uint8_t)blockNum, wrData, ctx->subCtx.t5t.blockLen); - } - else - { - ret = rfalNfcvPollerExtendedWriteSingleBlock(flags, ctx->subCtx.t5t.pAddressedUid, blockNum, wrData, ctx->subCtx.t5t.blockLen); - } - } - - return ret; -} - -/*******************************************************************************/ -static ReturnCode ndefT5TPollerReadMultipleBlocks(ndefContext *ctx, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( ctx->subCtx.t5t.legacySTHighDensity ) - { - - ret = rfalST25xVPollerM24LRReadMultipleBlocks((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT, ctx->subCtx.t5t.pAddressedUid, firstBlockNum, numOfBlocks, rxBuf, rxBufLen, rcvLen); - } - else - { - if( firstBlockNum < NDEF_T5T_MAX_BLOCK_1_BYTE_ADDR ) - { - ret = rfalNfcvPollerReadMultipleBlocks((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT, ctx->subCtx.t5t.pAddressedUid, (uint8_t)firstBlockNum, numOfBlocks, rxBuf, rxBufLen, rcvLen); - } - else - { - ret = rfalNfcvPollerExtendedReadMultipleBlocks((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT, ctx->subCtx.t5t.pAddressedUid, firstBlockNum, numOfBlocks, rxBuf, rxBufLen, rcvLen); - } - } - - return ret; -} - -#endif /* NDEF_FEATURE_ALL */ - -/*******************************************************************************/ -static ReturnCode ndefT5TPollerReadSingleBlock(ndefContext *ctx, uint16_t blockNum, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvLen) -{ - ReturnCode ret; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( ctx->subCtx.t5t.legacySTHighDensity ) - { - - ret = rfalST25xVPollerM24LRReadSingleBlock((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT, ctx->subCtx.t5t.pAddressedUid, blockNum, rxBuf, rxBufLen, rcvLen); - } - else - { - if( blockNum < NDEF_T5T_MAX_BLOCK_1_BYTE_ADDR ) - { - ret = rfalNfcvPollerReadSingleBlock((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT, ctx->subCtx.t5t.pAddressedUid, (uint8_t)blockNum, rxBuf, rxBufLen, rcvLen); - } - else - { - ret = rfalNfcvPollerExtendedReadSingleBlock((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT, ctx->subCtx.t5t.pAddressedUid, blockNum, rxBuf, rxBufLen, rcvLen); - } - } - - return ret; -} - -/*******************************************************************************/ -static ReturnCode ndefT5TGetSystemInformation(ndefContext *ctx, bool extended) -{ - ReturnCode ret; - uint8_t rxBuf[NDEF_T5T_SYSINFO_MAX_LEN]; - uint16_t rcvLen; - uint8_t* resp; - - if( (ctx == NULL) || !ndefT5TisT5TDevice(&ctx->device) ) - { - return ERR_PARAM; - } - - if( extended ) - { - ret = rfalNfcvPollerExtendedGetSystemInformation((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT, ctx->subCtx.t5t.pAddressedUid, (uint8_t)RFAL_NFCV_SYSINFO_REQ_ALL, rxBuf, (uint16_t)sizeof(rxBuf), &rcvLen); - } - else - { - ret = rfalNfcvPollerGetSystemInformation(ctx->subCtx.t5t.legacySTHighDensity ? ((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT) : ((uint8_t)RFAL_NFCV_REQ_FLAG_DEFAULT), ctx->subCtx.t5t.pAddressedUid, rxBuf, (uint16_t)sizeof(rxBuf), &rcvLen); - } - - if( ret != ERR_NONE ) - { - return ret; - } - - /* FIXME check buf rcvLen */ - resp = &rxBuf[0U]; - /* skip Flags */ - resp++; - /* get Info flags */ - ctx->subCtx.t5t.sysInfo.infoFlags = *resp; - resp++; - if( extended && (ndefT5TSysInfoLenValue(ctx->subCtx.t5t.sysInfo.infoFlags) != 0U) ) - { - return ERR_PROTO; - } - /* get UID */ - (void)ST_MEMCPY(ctx->subCtx.t5t.sysInfo.UID, resp, RFAL_NFCV_UID_LEN); - resp = &resp[RFAL_NFCV_UID_LEN]; - if( ndefT5TSysInfoDFSIDPresent(ctx->subCtx.t5t.sysInfo.infoFlags) != 0U) - { - ctx->subCtx.t5t.sysInfo.DFSID = *resp; - resp++; - } - if( ndefT5TSysInfoAFIPresent(ctx->subCtx.t5t.sysInfo.infoFlags) != 0U ) - { - ctx->subCtx.t5t.sysInfo.AFI = *resp; - resp++; - } - if( ndefT5TSysInfoMemSizePresent(ctx->subCtx.t5t.sysInfo.infoFlags) != 0U ) - { - if ( ctx->subCtx.t5t.legacySTHighDensity || extended ) - { - /* LRIS64K/M24LR16/M24LR64 */ - ctx->subCtx.t5t.sysInfo.numberOfBlock = *resp; - resp++; - ctx->subCtx.t5t.sysInfo.numberOfBlock |= (((uint16_t)*resp) << 8U); - resp++; - } - else - { - ctx->subCtx.t5t.sysInfo.numberOfBlock = *resp; - resp++; - } - ctx->subCtx.t5t.sysInfo.blockSize = *resp; - resp++; - /* Add 1 to get real values*/ - ctx->subCtx.t5t.sysInfo.numberOfBlock++; - ctx->subCtx.t5t.sysInfo.blockSize++; - } - if( ndefT5TSysInfoICRefPresent(ctx->subCtx.t5t.sysInfo.infoFlags) != 0U ) - { - ctx->subCtx.t5t.sysInfo.ICRef = *resp; - resp++; - } - if( extended && (ndefT5TSysInfoCmdListPresent(ctx->subCtx.t5t.sysInfo.infoFlags) != 0U) ) - { - ctx->subCtx.t5t.sysInfo.supportedCmd[0U] = *resp; - resp++; - ctx->subCtx.t5t.sysInfo.supportedCmd[1U] = *resp; - resp++; - ctx->subCtx.t5t.sysInfo.supportedCmd[2U] = *resp; - resp++; - ctx->subCtx.t5t.sysInfo.supportedCmd[3U] = *resp; - resp++; - } - return ERR_NONE; -} - -#endif /* RFAL_FEATURE_NFCV */ diff --git a/Software/Middlewares/ST/ndef/doc/changelog.txt b/Software/Middlewares/ST/ndef/doc/changelog.txt deleted file mode 100644 index 8ca5d96..0000000 --- a/Software/Middlewares/ST/ndef/doc/changelog.txt +++ /dev/null @@ -1,57 +0,0 @@ -====================== -NDEF library changelog -====================== - - -=================================================================================================== - -v1.0.4 (July 22th, 2019) -Tested with RFAL 2.0.10 -Updates to fix MISRA warnings reported by IAR - -=================================================================================================== - -v1.0.2 (April 11th, 2019) -Release of RFAL v2.0.6, providing Higher Layer API. - -=================================================================================================== - -v1.0.0 (March 29th, 2019) -sha1: 22084be2253ae0c4696865884abd99ed9cbee319 -============================================== - -Initial NDEF library release - -The NDEF library provides an API to NDEF message and record management. - -The Software design is split in RF Technology-independent layer and RF Technology-dependent layer: - - Message, record and supported types management layer (Technology independent) - - NDEF wrapper layer abstracting the underlying technologies - - NDEF Technology layer defining a common API on top of the RFAL (Technology dependent) - -The NDEF wrapper on top of the NDEF Technology-dependent components allows to manage NDEF tags without -taking care of the underlying NFC Technologies. - -The types currently supported are the following: - - RTD Device Information - - RTD Text - - RTD URI - - AAR (Android Application Record) - - vCard - - Wifi - -The NFC technologies currently supported by the NDEF layer are: T2T, T3T, T4AT, T4BT and T5T. - -See the ndef.chm documentation for further details and use examples. - -Tested on hardware: Nucleo STM32L476RG + X-NUCLEO-NFC05A1 (ST25R3911) -Software dependency: RFAL above v2.0.4 (needs RFAL Higher Layer) -C99, MISRA C 2012 compliant - -Tests: ------- - - Unitary tests: Passed - - Smoke tests: Write supported types (T2T, T3T, T4AT, T4BT, T5T): Passed - Read supported types (T2T, T3T, T4AT, T4BT, T5T): Passed - Check presence (T2T, T3T, T4AT, T4BT, T5T): Passed - Format (T2T, T3T, T4AT, T4BT, T5T): Passed diff --git a/Software/Middlewares/ST/ndef/doc/examples/ndef_example_read.c b/Software/Middlewares/ST/ndef/doc/examples/ndef_example_read.c deleted file mode 100644 index adf0d24..0000000 --- a/Software/Middlewares/ST/ndef/doc/examples/ndef_example_read.c +++ /dev/null @@ -1,278 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/* \file ndef_example_read.c - * - * \example ndef_example_read.c - * - * \author - * - * \brief NDEF Read example code - * - * This demo shows how to poll for several types of NFC cards/devices and how - * to Read NDEF using the RFAL and NDEF libraries. - * - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "utils.h" -#include "rfal_nfc.h" -#include "ndef_poller.h" -#include "ndef_message.h" -#include "ndef_types_rtd.h" -#include "ndef_types_mime.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define DEMO_RAW_MESSAGE_BUF_LEN 8192 /*!< raw message buffer size */ - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -static rfalNfcDevice *nfcDevice; -static rfalNfcDiscoverParam discParam = -{ - .compMode = RFAL_COMPLIANCE_MODE_NFC, - .devLimit = 1U, - .nfcfBR = RFAL_BR_212, - .ap2pBR = RFAL_BR_424, - .nfcid3 = NULL, - .GB = NULL, - .GBLen = 0, - .notifyCb = NULL, - .totalDuration = 1000U, - .wakeupEnabled = false, - .wakeupConfigDefault = true, - .techs2Find = ( RFAL_NFC_POLL_TECH_A | RFAL_NFC_POLL_TECH_B | RFAL_NFC_POLL_TECH_F | RFAL_NFC_POLL_TECH_V ) -}; - -static ndefContext ndefCtx; -static uint8_t rawMessageBuf[DEMO_RAW_MESSAGE_BUF_LEN]; - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ -void ndefExampleParseMessage(uint8_t* rawMsgBuf, uint32_t rawMsgLen); -void ndefExampleParseRecord(ndefRecord *record); -void ndefExamplePrintString(const uint8_t* str, uint32_t strLen); - -/*! - ***************************************************************************** - * \brief ndefExampleRead - * - * This function performs the various NFC activities up to the NDEF tag reading - ***************************************************************************** - */ -void ndefExampleRead( void ) -{ - ReturnCode err; - uint32_t rawMessageLen; - - /* - * RFAL Init - */ - err = rfalNfcInitialize(); - if( err != ERR_NONE ) - { - platformLog("rfalNfcInitialize return %d\r\n", err); - return; - } - - rfalNfcDeactivate( false ); - rfalNfcDiscover( &discParam ); - - /* - * Read loop - */ - while (1) - { - rfalNfcWorker(); - if( rfalNfcIsDevActivated(rfalNfcGetState()) ) - { - /* - * Retrieve NFC device - */ - rfalNfcGetActiveDevice(&nfcDevice); - - /* - * Perform NDEF Context Initialization - */ - err = ndefPollerContextInitialization(&ndefCtx, nfcDevice); - if( err != ERR_NONE ) - { - platformLog("NDEF NOT DETECTED (ndefPollerContextInitialization returns %d)\r\n", err); - return; - } - - /* - * Perform NDEF Detect procedure - */ - err = ndefPollerNdefDetect(&ndefCtx, NULL); - if( err != ERR_NONE ) - { - platformLog("NDEF NOT DETECTED (ndefPollerNdefDetect returns %d)\r\n", err); - return; - } - - /* - * Perform NDEF read procedure - */ - err = ndefPollerReadRawMessage(&ndefCtx, rawMessageBuf, sizeof(rawMessageBuf), &rawMessageLen); - if( err != ERR_NONE ) - { - platformLog("NDEF message cannot be read (ndefPollerReadRawMessage returns %d)\r\n", err); - return; - } - - platformLog("NDEF Read successful\r\n"); - - /* - * Parse message content - */ - ndefExampleParseMessage(rawMessageBuf, rawMessageLen); - - return; - } - } -} - -/*! - ***************************************************************************** - * \brief ndefExampleParseMessage - * - * This function parses the NDEF message - ***************************************************************************** - */ -void ndefExampleParseMessage(uint8_t* rawMsgBuf, uint32_t rawMsgLen) -{ - ReturnCode err; - ndefConstBuffer bufRawMessage; - ndefMessage message; - ndefRecord* record; - - bufRawMessage.buffer = rawMsgBuf; - bufRawMessage.length = rawMsgLen; - - err = ndefMessageDecode(&bufRawMessage, &message); - if (err != ERR_NONE) - { - return; - } - - record = ndefMessageGetFirstRecord(&message); - - while (record != NULL) - { - ndefExampleParseRecord(record); - record = ndefMessageGetNextRecord(record); - } -} - -/*! - ***************************************************************************** - * \brief ndefExamplePrintString - * - * This function prints a String of a given Length - ***************************************************************************** - */ -void ndefExamplePrintString(const uint8_t* str, uint32_t strLen) -{ - uint32_t i; - const uint8_t* c; - - i = strLen; - c = str; - - while (i-- > 0U) - { - platformLog("%c", *c); - c++; - } - platformLog("\r\n"); -} - -/*! - ***************************************************************************** - * \brief ndefExampleParseRecord - * - * This function parses a given record - ***************************************************************************** - */ -void ndefExampleParseRecord(ndefRecord* record) -{ - ReturnCode err; - ndefType type; - - err = ndefRecordToType(record, &type); - if (err != ERR_NONE) - { - return; - } - - switch (type.id) - { - case NDEF_TYPE_EMPTY: - platformLog(" * Empty record\r\n"); - break; - case NDEF_TYPE_RTD_TEXT: - platformLog(" * TEXT record: "); - ndefExamplePrintString(type.data.text.bufSentence.buffer, type.data.text.bufSentence.length); - break; - case NDEF_TYPE_RTD_URI: - platformLog(" * URI record: "); - ndefExamplePrintString(type.data.uri.bufUriString.buffer, type.data.uri.bufUriString.length); - break; - case NDEF_TYPE_RTD_AAR: - platformLog(" * AAR record: "); - ndefExamplePrintString(type.data.aar.bufPayload.buffer, type.data.aar.bufPayload.length); - break; - case NDEF_TYPE_RTD_DEVICE_INFO: - platformLog(" * Device Info record\r\n"); - break; - case NDEF_TYPE_MEDIA_VCARD: - platformLog(" * vCard record\r\n"); - break; - case NDEF_TYPE_MEDIA_WIFI: - platformLog(" * WIFI record\r\n"); - break; - default: - platformLog(" * Other record\r\n"); - break; - } -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Middlewares/ST/ndef/doc/examples/ndef_example_write.c b/Software/Middlewares/ST/ndef/doc/examples/ndef_example_write.c deleted file mode 100644 index d3516b0..0000000 --- a/Software/Middlewares/ST/ndef/doc/examples/ndef_example_write.c +++ /dev/null @@ -1,174 +0,0 @@ -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2019 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ -/* \file ndef_example_write.c - * - * \example ndef_example_write.c - * - * \author - * - * \brief NDEF Write example code - * - * This demo shows how to poll for several types of NFC cards/devices and how - * to Encode and Write an NDEF message using the RFAL and NDEF libraries. - * - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "utils.h" -#include "rfal_nfc.h" -#include "ndef_poller.h" -#include "ndef_message.h" -#include "ndef_types_rtd.h" -#include "ndef_types_mime.h" - - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -static rfalNfcDevice *nfcDevice; -static rfalNfcDiscoverParam discParam = -{ - .compMode = RFAL_COMPLIANCE_MODE_NFC, - .devLimit = 1U, - .nfcfBR = RFAL_BR_212, - .ap2pBR = RFAL_BR_424, - .nfcid3 = NULL, - .GB = NULL, - .GBLen = 0, - .notifyCb = NULL, - .totalDuration = 1000U, - .wakeupEnabled = false, - .wakeupConfigDefault = true, - .techs2Find = ( RFAL_NFC_POLL_TECH_A | RFAL_NFC_POLL_TECH_B | RFAL_NFC_POLL_TECH_F | RFAL_NFC_POLL_TECH_V ) -}; - -static ndefContext ndefCtx; - - -/*! - ***************************************************************************** - * \brief ndefExampleWrite - * - * This function performs the various NFC activities up to the NDEF tag writing - ***************************************************************************** - */ -void ndefExampleWrite( void ) -{ - ReturnCode err; - ndefConstBuffer bufUri; - ndefType uri; - ndefRecord record; - ndefMessage message; - static uint8_t ndefURI[] = "st.com"; - - /* - * Message creation - */ - err = ndefMessageInit(&message); /* Initialize message structure */ - bufUri.buffer = ndefURI; - bufUri.length = strlen((char *)ndefURI); - err |= ndefRtdUri(&uri, NDEF_URI_PREFIX_HTTP_WWW, &bufUri); /* Initialize URI type structure */ - err |= ndefRtdUriToRecord(&uri, &record); /* Encode URI Record */ - err |= ndefMessageAppend(&message, &record); /* Append URI to message */ - if( err != ERR_NONE ) - { - platformLog("Message creation failed\r\n", err); - return; - } - - /* - * RFAL Init - */ - err = rfalNfcInitialize(); - if( err != ERR_NONE ) - { - platformLog("rfalNfcInitialize return %d\r\n", err); - return; - } - - rfalNfcDeactivate( false ); - rfalNfcDiscover( &discParam ); - - /* - * Write loop - */ - while (1) - { - rfalNfcWorker(); - if( rfalNfcIsDevActivated(rfalNfcGetState()) ) - { - /* - * Retrieve NFC device - */ - rfalNfcGetActiveDevice(&nfcDevice); - - /* - * Perform NDEF Context Initialization - */ - err = ndefPollerContextInitialization(&ndefCtx, nfcDevice); - if( err != ERR_NONE ) - { - platformLog("NDEF NOT DETECTED (ndefPollerContextInitialization returns %d)\r\n", err); - return; - } - - /* - * Perform NDEF Detect procedure - */ - err = ndefPollerNdefDetect(&ndefCtx, NULL); - if( err != ERR_NONE ) - { - platformLog("NDEF NOT DETECTED (ndefPollerNdefDetect returns %d)\r\n", err); - return; - } - - /* - * Perform NDEF write procedure - */ - err = ndefPollerWriteMessage(&ndefCtx, &message); - if( err != ERR_NONE ) - { - platformLog("NDEF message cannot be written (ndefPollerReadRawMessage returns %d)\r\n", err); - return; - } - - platformLog("NDEF Write successful\r\n"); - return; - } - } -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Software/Middlewares/ST/ndef/doc/ndef.chm b/Software/Middlewares/ST/ndef/doc/ndef.chm deleted file mode 100644 index 564b269..0000000 Binary files a/Software/Middlewares/ST/ndef/doc/ndef.chm and /dev/null differ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_analogConfig.h b/Software/Middlewares/ST/rfal/Inc/rfal_analogConfig.h deleted file mode 100644 index 6da5de9..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_analogConfig.h +++ /dev/null @@ -1,334 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_AnalogConfig.h - * - * \author bkam - * - * \brief RF Chip Analog Configuration Settings - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-HAL - * \brief RFAL Hardware Abstraction Layer - * @{ - * - * \addtogroup AnalogConfig - * \brief RFAL Analog Config Module - * @{ - * - */ - -#ifndef RFAL_ANALOG_CONFIG_H -#define RFAL_ANALOG_CONFIG_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" - -/* - ****************************************************************************** - * DEFINES - ****************************************************************************** - */ - -#define RFAL_ANALOG_CONFIG_LUT_SIZE (87U) /*!< Maximum number of Configuration IDs in the Loop Up Table */ -#define RFAL_ANALOG_CONFIG_LUT_NOT_FOUND (0xFFU) /*!< Index value indicating no Configuration IDs found */ - -#define RFAL_ANALOG_CONFIG_TBL_SIZE (1024U) /*!< Maximum number of Register-Mask-Value in the Setting List */ - - -#define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK (0x8000U) /*!< Mask bit of Poll Mode in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_TECH_MASK (0x7F00U) /*!< Mask bits for Technology in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_MASK (0x00F0U) /*!< Mask bits for Bit rate in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_DIRECTION_MASK (0x0003U) /*!< Mask bits for Direction in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK (0x00FFU) /*!< Mask bits for Chip Specific Technology */ - -#define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_SHIFT (15U) /*!< Shift value of Poll Mode in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_TECH_SHIFT (8U) /*!< Shift value for Technology in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_SHIFT (4U) /*!< Shift value for Technology in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_DIRECTION_SHIFT (0U) /*!< Shift value for Direction in Analog Configuration ID */ - -#define RFAL_ANALOG_CONFIG_POLL (0x0000U) /*!< Poll Mode bit setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_LISTEN (0x8000U) /*!< Listen Mode bit setting in Analog Configuration ID */ - -#define RFAL_ANALOG_CONFIG_TECH_CHIP (0x0000U) /*!< Chip-Specific bit setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_TECH_NFCA (0x0100U) /*!< NFC-A Technology bits setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_TECH_NFCB (0x0200U) /*!< NFC-B Technology bits setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_TECH_NFCF (0x0400U) /*!< NFC-F Technology bits setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_TECH_AP2P (0x0800U) /*!< AP2P Technology bits setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_TECH_NFCV (0x1000U) /*!< NFC-V Technology bits setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_TECH_RFU (0x2000U) /*!< RFU for Technology bits */ - -#define RFAL_ANALOG_CONFIG_BITRATE_COMMON (0x0000U) /*!< Common settings for all bit rates in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_106 (0x0010U) /*!< 106kbits/s settings in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_212 (0x0020U) /*!< 212kbits/s settings in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_424 (0x0030U) /*!< 424kbits/s settings in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_848 (0x0040U) /*!< 848kbits/s settings in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_1695 (0x0050U) /*!< 1695kbits/s settings in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_3390 (0x0060U) /*!< 3390kbits/s settings in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_6780 (0x0070U) /*!< 6780kbits/s settings in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_1OF4 (0x00C0U) /*!< 1 out of 4 for NFC-V setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_BITRATE_1OF256 (0x00D0U) /*!< 1 out of 256 for NFC-V setting in Analog Configuration ID */ - -#define RFAL_ANALOG_CONFIG_NO_DIRECTION (0x0000U) /*!< No direction setting in Analog Conf ID (Chip Specific only) */ -#define RFAL_ANALOG_CONFIG_TX (0x0001U) /*!< Transmission bit setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_RX (0x0002U) /*!< Reception bit setting in Analog Configuration ID */ -#define RFAL_ANALOG_CONFIG_ANTICOL (0x0003U) /*!< Anticollision setting in Analog Configuration ID */ - -#define RFAL_ANALOG_CONFIG_CHIP_INIT (0x0000U) /*!< Chip-Specific event: Startup;Reset;Initialize */ -#define RFAL_ANALOG_CONFIG_CHIP_DEINIT (0x0001U) /*!< Chip-Specific event: Deinitialize */ -#define RFAL_ANALOG_CONFIG_CHIP_FIELD_ON (0x0002U) /*!< Chip-Specific event: Field On */ -#define RFAL_ANALOG_CONFIG_CHIP_FIELD_OFF (0x0003U) /*!< Chip-Specific event: Field Off */ -#define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_ON (0x0004U) /*!< Chip-Specific event: Wake-up On */ -#define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_OFF (0x0005U) /*!< Chip-Specific event: Wake-up Off */ -#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON (0x0006U) /*!< Chip-Specific event: Listen On */ -#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_OFF (0x0007U) /*!< Chip-Specific event: Listen Off */ -#define RFAL_ANALOG_CONFIG_CHIP_POLL_COMMON (0x0008U) /*!< Chip-Specific event: Poll common */ -#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_COMMON (0x0009U) /*!< Chip-Specific event: Listen common */ - -#define RFAL_ANALOG_CONFIG_UPDATE_LAST (0x00U) /*!< Value indicating Last configuration set during update */ -#define RFAL_ANALOG_CONFIG_UPDATE_MORE (0x01U) /*!< Value indicating More configuration set coming during update */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(id) (RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK & (id)) /*!< Check if id indicates Listen mode */ - -#define RFAL_ANALOG_CONFIG_ID_GET_TECH(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Get the technology of Configuration ID */ -#define RFAL_ANALOG_CONFIG_ID_IS_CHIP(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Check if ID indicates Chip-specific */ -#define RFAL_ANALOG_CONFIG_ID_IS_NFCA(id) (RFAL_ANALOG_CONFIG_TECH_NFCA & (id)) /*!< Check if ID indicates NFC-A */ -#define RFAL_ANALOG_CONFIG_ID_IS_NFCB(id) (RFAL_ANALOG_CONFIG_TECH_NFCB & (id)) /*!< Check if ID indicates NFC-B */ -#define RFAL_ANALOG_CONFIG_ID_IS_NFCF(id) (RFAL_ANALOG_CONFIG_TECH_NFCF & (id)) /*!< Check if ID indicates NFC-F */ -#define RFAL_ANALOG_CONFIG_ID_IS_AP2P(id) (RFAL_ANALOG_CONFIG_TECH_AP2P & (id)) /*!< Check if ID indicates AP2P */ -#define RFAL_ANALOG_CONFIG_ID_IS_NFCV(id) (RFAL_ANALOG_CONFIG_TECH_NFCV & (id)) /*!< Check if ID indicates NFC-V */ - -#define RFAL_ANALOG_CONFIG_ID_GET_BITRATE(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Get Bitrate of Configuration ID */ -#define RFAL_ANALOG_CONFIG_ID_IS_COMMON(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Check if ID indicates common bitrate */ -#define RFAL_ANALOG_CONFIG_ID_IS_106(id) (RFAL_ANALOG_CONFIG_BITRATE_106 & (id)) /*!< Check if ID indicates 106kbits/s */ -#define RFAL_ANALOG_CONFIG_ID_IS_212(id) (RFAL_ANALOG_CONFIG_BITRATE_212 & (id)) /*!< Check if ID indicates 212kbits/s */ -#define RFAL_ANALOG_CONFIG_ID_IS_424(id) (RFAL_ANALOG_CONFIG_BITRATE_424 & (id)) /*!< Check if ID indicates 424kbits/s */ -#define RFAL_ANALOG_CONFIG_ID_IS_848(id) (RFAL_ANALOG_CONFIG_BITRATE_848 & (id)) /*!< Check if ID indicates 848kbits/s */ -#define RFAL_ANALOG_CONFIG_ID_IS_1695(id) (RFAL_ANALOG_CONFIG_BITRATE_1695 & (id)) /*!< Check if ID indicates 1695kbits/s */ -#define RFAL_ANALOG_CONFIG_ID_IS_3390(id) (RFAL_ANALOG_CONFIG_BITRATE_3390 & (id)) /*!< Check if ID indicates 3390kbits/s */ -#define RFAL_ANALOG_CONFIG_ID_IS_6780(id) (RFAL_ANALOG_CONFIG_BITRATE_6780 & (id)) /*!< Check if ID indicates 6780kbits/s */ -#define RFAL_ANALOG_CONFIG_ID_IS_1OF4(id) (RFAL_ANALOG_CONFIG_BITRATE_1OF4 & (id)) /*!< Check if ID indicates 1 out of 4 bitrate */ -#define RFAL_ANALOG_CONFIG_ID_IS_1OF256(id) (RFAL_ANALOG_CONFIG_BITRATE_1OF256 & (id)) /*!< Check if ID indicates 1 out of 256 bitrate */ - -#define RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(id) (RFAL_ANALOG_CONFIG_DIRECTION_MASK & (id)) /*!< Get Direction of Configuration ID */ -#define RFAL_ANALOG_CONFIG_ID_IS_TX(id) (RFAL_ANALOG_CONFIG_TX & (id)) /*!< Check if id indicates TX */ -#define RFAL_ANALOG_CONFIG_ID_IS_RX(id) (RFAL_ANALOG_CONFIG_RX & (id)) /*!< Check if id indicates RX */ - -#define RFAL_ANALOG_CONFIG_CONFIG_NUM(x) (sizeof(x)/sizeof((x)[0])) /*!< Get Analog Config number */ - -/*! Set Analog Config ID value by: Mode, Technology, Bitrate and Direction */ -#define RFAL_ANALOG_CONFIG_ID_SET(mode, tech, br, direction) \ - ( RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(mode) \ - | RFAL_ANALOG_CONFIG_ID_GET_TECH(tech) \ - | RFAL_ANALOG_CONFIG_ID_GET_BITRATE(br) \ - | RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(direction) \ - ) - -/* - ****************************************************************************** - * GLOBAL DATA TYPES - ****************************************************************************** - */ - -typedef uint8_t rfalAnalogConfigMode; /*!< Polling or Listening Mode of Configuration */ -typedef uint8_t rfalAnalogConfigTech; /*!< Technology of Configuration */ -typedef uint8_t rfalAnalogConfigBitrate; /*!< Bitrate of Configuration */ -typedef uint8_t rfalAnalogConfigDirection; /*!< Transmit/Receive direction of Configuration */ - -typedef uint8_t rfalAnalogConfigRegAddr[2]; /*!< Register Address to ST Chip */ -typedef uint8_t rfalAnalogConfigRegMask; /*!< Register Mask Value */ -typedef uint8_t rfalAnalogConfigRegVal; /*!< Register Value */ - -typedef uint16_t rfalAnalogConfigId; /*!< Analog Configuration ID */ -typedef uint16_t rfalAnalogConfigOffset; /*!< Analog Configuration offset address in the table */ -typedef uint8_t rfalAnalogConfigNum; /*!< Number of Analog settings for the respective Configuration ID */ - - -/*! Struct that contain the Register-Mask-Value set. Make sure that the whole structure size is even and unaligned! */ -typedef struct { - rfalAnalogConfigRegAddr addr; /*!< Register Address */ - rfalAnalogConfigRegMask mask; /*!< Register Mask Value */ - rfalAnalogConfigRegVal val; /*!< Register Value */ -} rfalAnalogConfigRegAddrMaskVal; - - -/*! Struct that represents the Analog Configs */ -typedef struct { - uint8_t id[sizeof(rfalAnalogConfigId)]; /*!< Configuration ID */ - rfalAnalogConfigNum num; /*!< Number of Config Sets to follow */ - rfalAnalogConfigRegAddrMaskVal regSet[]; /*!< Register-Mask-Value sets */ /* PRQA S 1060 # MISRA 18.7 - Flexible Array Members are the only meaningful way of denoting a variable length input buffer which follows a fixed header structure. */ -} rfalAnalogConfig; - - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief Initialize the Analog Configuration - * - * Reset the Analog Configuration LUT pointer to reference to default settings. - * - ***************************************************************************** - */ -void rfalAnalogConfigInitialize( void ); - - -/*! - ***************************************************************************** - * \brief Indicate if the current Analog Configuration Table is complete and ready to be used. - * - * \return true if current Analog Configuration Table is complete and ready to be used. - * \return false if current Analog Configuration Table is incomplete - * - ***************************************************************************** - */ -bool rfalAnalogConfigIsReady( void ); - -/*! - ***************************************************************************** - * \brief Write the whole Analog Configuration table in raw format - * - * Writes the Analog Configuration and Look Up Table with the given raw table - * - * NOTE: Function does not check the validity of the given Table contents - * - * \param[in] configTbl: location of config Table to be loaded - * \param[in] configTblSize: size of the config Table to be loaded - * - * \return ERR_NONE : if setting is updated - * \return ERR_PARAM : if configTbl is invalid - * \return ERR_NOMEM : if the given Table is bigger exceeds the max size - * \return ERR_REQUEST : if the update Configuration Id is disabled - * - ***************************************************************************** - */ -ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize ); - -/*! - ***************************************************************************** - * \brief Write the Analog Configuration table with new analog settings. - * - * Writes the Analog Configuration and Look Up Table with the new list of register-mask-value - * and Configuration ID respectively. - * - * NOTE: Function does not check for the validity of the Register Address. - * - * \param[in] more: 0x00 indicates it is last Configuration ID settings; - * 0x01 indicates more Configuration ID setting(s) are coming. - * \param[in] *config: reference to the configuration list of current Configuraiton ID. - * - * \return ERR_PARAM : if Configuration ID or parameter is invalid - * \return ERR_NOMEM : if LUT is full - * \return ERR_REQUEST : if the update Configuration Id is disabled - * \return ERR_NONE : if setting is updated - * - ***************************************************************************** - */ -ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config ); - -/*! - ***************************************************************************** - * \brief Read the whole Analog Configuration table in raw format - * - * Reads the whole Analog Configuration Table in raw format - * - * \param[out] tblBuf: location to the buffer to place the Config Table - * \param[in] tblBufLen: length of the buffer to place the Config Table - * \param[out] configTblSize: Config Table size - * - * \return ERR_PARAM : if configTbl or configTblSize is invalid - * \return ERR_NOMEM : if configTblSize is not enough for the whole table - * \return ERR_NONE : if read is successful - * - ***************************************************************************** - */ -ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize ); - -/*! - ***************************************************************************** - * \brief Read the Analog Configuration table. - * - * Read the Analog Configuration Table - * - * \param[in] configOffset: offset to the next Configuration ID in the List Table to be read. - * \param[out] more: 0x00 indicates it is last Configuration ID settings; - * 0x01 indicates more Configuration ID setting(s) are coming. - * \param[out] config: configuration id, number of configuration sets and register-mask-value sets - * \param[in] numConfig: the remaining configuration settings space available; - * - * \return ERR_NOMEM : if number of Configuration for respective Configuration ID is greater the the remaining configuration setting space available - * \return ERR_NONE : if read is successful - * - ***************************************************************************** - */ -ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig ); - -/*! - ***************************************************************************** - * \brief Set the Analog settings of indicated Configuration ID. - * - * Update the chip with indicated analog settings of indicated Configuration ID. - * - * \param[in] configId: configuration ID - * - * \return ERR_PARAM if Configuration ID is invalid - * \return ERR_INTERNAL if error updating setting to chip - * \return ERR_NONE if new settings is applied to chip - * - ***************************************************************************** - */ -ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId ); - - -#endif /* RFAL_ANALOG_CONFIG_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_analogConfigTbl.h b/Software/Middlewares/ST/rfal/Inc/rfal_analogConfigTbl.h deleted file mode 100644 index 2c4d0a2..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_analogConfigTbl.h +++ /dev/null @@ -1,426 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_analogConfig.h - * - * \author bkam - * - * \brief ST25R3911 Analog Configuration Settings - * - */ - -#ifndef ST25R3911_ANALOGCONFIG_H -#define ST25R3911_ANALOGCONFIG_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_analogConfig.h" -#include "st25r3911_com.h" - -/* - ****************************************************************************** - * DEFINES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -/*! Macro for Configuration Setting with only one register-mask-value set: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1] */ -#define MODE_ENTRY_1_REG(MODE, R0, M0, V0) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 1, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) - -/*! Macro for Configuration Setting with only two register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1] */ -#define MODE_ENTRY_2_REG(MODE, R0, M0, V0, R1, M1, V1) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 2, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) - -/*! Macro for Configuration Setting with only three register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_3_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 3, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - -/*! Macro for Configuration Setting with only four register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_4_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 4, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - -/*! Macro for Configuration Setting with only five register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_5_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 5, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - -/*! Macro for Configuration Setting with only six register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_6_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 6, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - , (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \ - -/*! Macro for Configuration Setting with only seven register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_7_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 7, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - , (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \ - , (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \ - -/*! Macro for Configuration Setting with only eight register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_8_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 8, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - , (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \ - , (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \ - , (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \ - -/*! Macro for Configuration Setting with only nine register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_9_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 9, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - , (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \ - , (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \ - , (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \ - , (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \ - -/*! Macro for Configuration Setting with only ten register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_10_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU),10, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - , (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \ - , (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \ - , (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \ - , (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \ - , (uint8_t)((R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \ - -/*! Macro for Configuration Setting with eleven register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_11_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU),11, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - , (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \ - , (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \ - , (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \ - , (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \ - , (uint8_t)((R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \ - , (uint8_t)((R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \ - -/*! Macro for Configuration Setting with twelve register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_12_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU),12, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - , (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \ - , (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \ - , (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \ - , (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \ - , (uint8_t)((R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \ - , (uint8_t)((R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \ - , (uint8_t)((R11) >> 8), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \ - -/*! Macro for Configuration Setting with thirteen register-mask-value sets: - * - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */ -#define MODE_ENTRY_13_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11, R12, M12, V12) \ - (uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU),13, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \ - , (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \ - , (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \ - , (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \ - , (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \ - , (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \ - , (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \ - , (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \ - , (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \ - , (uint8_t)((R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \ - , (uint8_t)((R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \ - , (uint8_t)((R11) >> 8), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \ - , (uint8_t)((R12) >> 8), (uint8_t)((R12) & 0xFFU), (uint8_t)(M12), (uint8_t)(V12) \ - -/* Setting for approximately 14%: */ -#define AM_MOD_DRIVER_LEVEL_DEFAULT 0xb9 -/* - ****************************************************************************** - * GLOBAL DATA TYPES - ****************************************************************************** - */ -/* PRQA S 3406 1 # MISRA 8.6 - Externally generated table included by the library */ /* PRQA S 1514 1 # MISRA 8.9 - Externally generated table included by the library */ - const uint8_t rfalAnalogConfigDefaultSettings[] = { - //****** Default Analog Configuration for Chip-Specific Reset. ******/ - MODE_ENTRY_10_REG( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_INIT) - , ST25R3911_REG_OP_CONTROL, 0x30, 0x10 /* default to AM */ - , ST25R3911_REG_IO_CONF1, 0x06, 0x06 /* MCUCLK: HF clk off */ - , ST25R3911_REG_IO_CONF1, (ST25R3911_REG_IO_CONF1_mask_out_cl | ST25R3911_REG_IO_CONF1_lf_clk_off), 0x07 /* MCUCLK: LF clk off */ - , ST25R3911_REG_IO_CONF2, 0x18, 0x18 /* pull downs */ - , ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_pm, 0x1U<
© COPYRIGHT 2016 STMicroelectronics
- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_chip.h - * - * \author Gustavo Patricio - * - * \brief RF Chip specific Layer - * - * \warning This layer, which provides direct access to RF chip, should - * only be used for debug purposes and/or advanced features - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-HAL - * \brief RFAL Hardware Abstraction Layer - * @{ - * - * \addtogroup Chip - * \brief RFAL RF Chip Module - * @{ - * - */ - - -#ifndef RFAL_CHIP_H -#define RFAL_CHIP_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" - - -/***************************************************************************** - * RF Chip * - *****************************************************************************/ - -/*! - ***************************************************************************** - * \brief Writes a register on the RF Chip - * - * Checks if the given register is valid and if so, writes the value(s) - * on the RF Chip register - * - * \param[in] reg: register address to be written, or the first if len > 1 - * \param[in] values: pointer with content to be written on the register(s) - * \param[in] len: number of consecutive registers to be written - * - * - * \return ERR_PARAM : Invalid register or bad request - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : Write done with no error - ***************************************************************************** - */ -ReturnCode rfalChipWriteReg( uint16_t reg, const uint8_t* values, uint8_t len ); - -/*! - ***************************************************************************** - * \brief Reads a register on the RF Chip - * - * Checks if the given register is valid and if so, reads the value(s) - * of the RF Chip register(s) - * - * \param[in] reg: register address to be read, or the first if len > 1 - * \param[out] values: pointer where the register(s) read content will be placed - * \param[in] len: number of consecutive registers to be read - * - * \return ERR_PARAM : Invalid register or bad request - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : Read done with no error - ***************************************************************************** - */ -ReturnCode rfalChipReadReg( uint16_t reg, uint8_t* values, uint8_t len ); - -/*! - ***************************************************************************** - * \brief Change a register on the RF Chip - * - * Change the value of the register bits on the RF Chip Test set in the valueMask. - * - * \param[in] reg: register address to be modified - * \param[in] valueMask: mask value of the register bits to be changed - * \param[in] value: register value to be set - * - * \return ERR_PARAM : Invalid register or bad request - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_OK : Change done with no error - ***************************************************************************** - */ -ReturnCode rfalChipChangeRegBits( uint16_t reg, uint8_t valueMask, uint8_t value ); - -/*! - ***************************************************************************** - * \brief Writes a Test register on the RF Chip - * - * Writes the value on the RF Chip Test register - * - * \param[in] reg: register address to be written - * \param[in] value: value to be written on the register - * - * - * \return ERR_PARAM : Invalid register or bad request - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : Write done with no error - ***************************************************************************** - */ -ReturnCode rfalChipWriteTestReg( uint16_t reg, uint8_t value ); - -/*! - ***************************************************************************** - * \brief Reads a Test register on the RF Chip - * - * Reads the value of the RF Chip Test register - * - * \param[in] reg: register address to be read - * \param[out] value: pointer where the register content will be placed - * - * \return ERR_PARAM :Invalid register or bad request - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : Read done with no error - ***************************************************************************** - */ -ReturnCode rfalChipReadTestReg( uint16_t reg, uint8_t* value ); - -/*! - ***************************************************************************** - * \brief Change a Test register on the RF Chip - * - * Change the value of the register bits on the RF Chip Test set in the valueMask. - * - * \param[in] reg: test register address to be modified - * \param[in] valueMask: mask value of the register bits to be changed - * \param[in] value: register value to be set - * - * \return ERR_PARAM : Invalid register or bad request - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_OK : Change done with no error - ***************************************************************************** - */ -ReturnCode rfalChipChangeTestRegBits( uint16_t reg, uint8_t valueMask, uint8_t value ); - -/*! - ***************************************************************************** - * \brief Execute command on the RF Chip - * - * Checks if the given command is valid and if so, executes it on - * the RF Chip - * - * \param[in] cmd: direct command to be executed - * - * \return ERR_PARAM : Invalid command or bad request - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : Direct command executed with no error - ***************************************************************************** - */ -ReturnCode rfalChipExecCmd( uint16_t cmd ); - -/*! - ***************************************************************************** - * \brief Set RFO - * - * Sets the RFO value to be used when the field is on (unmodulated/active) - * - * \param[in] rfo : the RFO value to be used - * - * \return ERR_IO : Internal error - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalChipSetRFO( uint8_t rfo ); - - -/*! - ***************************************************************************** - * \brief Get RFO - * - * Gets the RFO value used used when the field is on (unmodulated/active) - * - * \param[out] result : the current RFO value - * - * \return ERR_IO : Internal error - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalChipGetRFO( uint8_t* result ); - - -/*! - ***************************************************************************** - * \brief Measure Amplitude - * - * Measures the RF Amplitude - * - * \param[out] result : result of RF measurement - * - * \return ERR_IO : Internal error - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalChipMeasureAmplitude( uint8_t* result ); - - -/*! - ***************************************************************************** - * \brief Measure Phase - * - * Measures the Phase - * - * \param[out] result : result of Phase measurement - * - * \return ERR_IO : Internal error - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalChipMeasurePhase( uint8_t* result ); - - -/*! - ***************************************************************************** - * \brief Measure Capacitance - * - * Measures the Capacitance - * - * \param[out] result : result of Capacitance measurement - * - * \return ERR_IO : Internal error - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalChipMeasureCapacitance( uint8_t* result ); - - -/*! - ***************************************************************************** - * \brief Measure Power Supply - * - * Measures the Power Supply - * - * \param[in] param : measurement parameter (chip specific) - * \param[out] result : result of the measurement - * - * \return ERR_IO : Internal error - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalChipMeasurePowerSupply( uint8_t param, uint8_t* result ); - - -#endif /* RFAL_CHIP_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_crc.h b/Software/Middlewares/ST/rfal/Inc/rfal_crc.h deleted file mode 100644 index a6ca124..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_crc.h +++ /dev/null @@ -1,75 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_crc.h - * - * \author Ulrich Herrmann - * - * \brief CRC calculation module - * - */ -/*! - * - */ - -#ifndef RFAL_CRC_H_ -#define RFAL_CRC_H_ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -/*! - ***************************************************************************** - * \brief Calculate CRC according to CCITT standard. - * - * This function takes \a length bytes from \a buf and calculates the CRC - * for this data. The result is returned. - * \note This implementation calculates the CRC with LSB first, i.e. all - * bytes are "read" from right to left. - * - * \param[in] preloadValue : Initial value of CRC calculation. - * \param[in] buf : buffer to calculate the CRC for. - * \param[in] length : size of the buffer. - * - * \return 16 bit long crc value. - * - ***************************************************************************** - */ -extern uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length); - -#endif /* RFAL_CRC_H_ */ - diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_dpo.h b/Software/Middlewares/ST/rfal/Inc/rfal_dpo.h deleted file mode 100644 index 8e7daaa..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_dpo.h +++ /dev/null @@ -1,209 +0,0 @@ - -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * $Revision: $ - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_dpo.h - * - * \author Martin Zechleitner - * - * \brief Dynamic Power adjustment - * - * This module provides an interface to perform the power adjustment dynamically - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-HAL - * \brief RFAL Hardware Abstraction Layer - * @{ - * - * \addtogroup DynamicPower - * \brief RFAL Dynamic Power Module - * @{ - * - */ - - -#ifndef RFAL_DPO_H -#define RFAL_DPO_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_DPO_TABLE_SIZE_MAX 15U /*!< Max DPO table size */ -#define RFAL_DPO_TABLE_PARAMETER 3U /*!< DPO table Parameter length */ - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! DPO table entry struct */ -typedef struct { - uint8_t rfoRes; /*!< Setting for the resistance level of the RFO */ - uint8_t inc; /*!< Threshold for incrementing the output power */ - uint8_t dec; /*!< Threshold for decrementing the output power */ -}rfalDpoEntry; - -/*! Function pointer to methode doing the reference measurement */ -typedef ReturnCode (*rfalDpoMeasureFunc)(uint8_t*); - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - - -/*! - ***************************************************************************** - * \brief Initialize dynamic power table - * - * This function sets the internal dynamic power table to the default - * values stored in rfal_DpoTbl.h - * - ***************************************************************************** - */ -void rfalDpoInitialize( void ); - -/*! - ***************************************************************************** - * \brief Set the measurement methode - * - * This function sets the measurement method used for reference measurement. - * Based on the measurement the power will then be adjusted - * - * \param[in] dpoMeasureFunc: callback of measurement function - * - ***************************************************************************** - */ -void rfalDpoSetMeasureCallback( rfalDpoMeasureFunc dpoMeasureFunc ); - -/*! - ***************************************************************************** - * \brief Write dynamic power table - * - * Load the dynamic power table - * - * \param[in] powerTbl: location of power Table to be loaded - * \param[in] powerTblEntries: number of entries of the power Table to be loaded - * - * \return ERR_NONE : No error - * \return ERR_PARAM : if configTbl is invalid - * \return ERR_NOMEM : if the given Table is bigger exceeds the max size - ***************************************************************************** - */ -ReturnCode rfalDpoTableWrite( rfalDpoEntry* powerTbl, uint8_t powerTblEntries ); - -/*! - ***************************************************************************** - * \brief Dynamic power table Read - * - * Read the dynamic power table - * - * \param[out] tblBuf: location to the rfalDpoEntry[] to place the Table - * \param[in] tblBufEntries: number of entries available in tblBuf to place the power Table - * \param[out] tableEntries: returned number of entries actually written into tblBuf - * - * \return ERR_NONE : No error - * \return ERR_PARAM : if configTbl is invalid or parameters are invalid - ***************************************************************************** - */ -ReturnCode rfalDpoTableRead( rfalDpoEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries ); - -/*! - ***************************************************************************** - * \brief Dynamic power adjust - * - * It measures the current output and adjusts the power accordingly to - * the dynamic power table - * - * \return ERR_NONE : No error - * \return ERR_PARAM : if configTbl is invalid or parameters are invalid - * \return ERR_WRONG_STATE : if the current state is valid for DPO Adjustment - ***************************************************************************** - */ -ReturnCode rfalDpoAdjust( void ); - -/*! - ***************************************************************************** - * \brief Get Current Dynamic power table entry - * - * Return current used DPO power table entry settings - * - * \return ERR_NONE : Current DpoEntry. This includes d_res, inc and dec - * - ***************************************************************************** - */ -rfalDpoEntry* rfalDpoGetCurrentTableEntry(void); - -/*! - ***************************************************************************** - * \brief Dynamic power set enabled state - * - * \param[in] enable: new active state - * - * Set state to enable or disable the Dynamic power adjustment - * - ***************************************************************************** - */ -void rfalDpoSetEnabled( bool enable ); - -/*! - ***************************************************************************** - * \brief Get the Dynamic power enabled state - * - * Get state of the Dynamic power adjustment - * - * \return true : enabled - * \return false : disabled - ***************************************************************************** - */ -bool rfalDpoIsEnabled(void); - -#endif /* RFAL_DPO_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_dpoTbl.h b/Software/Middlewares/ST/rfal/Inc/rfal_dpoTbl.h deleted file mode 100644 index f5c8981..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_dpoTbl.h +++ /dev/null @@ -1,56 +0,0 @@ - -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * $Revision: $ - * LANGUAGE: ISO C99 - */ - - -#ifndef ST25R3911_DYNAMICPOWER_H -#define ST25R3911_DYNAMICPOWER_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_dpo.h" - - -/* - ****************************************************************************** - * GLOBAL VARIABLES - ****************************************************************************** - */ - - /*! Default DPO table */ -const uint8_t rfalDpoDefaultSettings [] = { - 0x00, 255, 200, - 0x01, 210, 150, - 0x02, 160, 100, - 0x03, 110, 50, - 0x0E, 60, 0 -}; - -#endif /* ST25R3911_DYNAMICPOWER_H */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_features.h b/Software/Middlewares/ST/rfal/Inc/rfal_features.h deleted file mode 100644 index 943da90..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_features.h +++ /dev/null @@ -1,115 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Gustavo Patricio - * - * \brief RFAL Features/Capabilities Definition for ST25R3911 - */ - - -#ifndef RFAL_FEATURES_H -#define RFAL_FEATURES_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - -#define RFAL_SUPPORT_MODE_POLL_NFCA true /*!< RFAL Poll NFCA mode support switch */ -#define RFAL_SUPPORT_MODE_POLL_NFCB true /*!< RFAL Poll NFCB mode support switch */ -#define RFAL_SUPPORT_MODE_POLL_NFCF true /*!< RFAL Poll NFCF mode support switch */ -#define RFAL_SUPPORT_MODE_POLL_NFCV true /*!< RFAL Poll NFCV mode support switch */ -#define RFAL_SUPPORT_MODE_POLL_ACTIVE_P2P true /*!< RFAL Poll AP2P mode support switch */ -#define RFAL_SUPPORT_MODE_LISTEN_NFCA false /*!< RFAL Listen NFCA mode support switch */ -#define RFAL_SUPPORT_MODE_LISTEN_NFCB false /*!< RFAL Listen NFCB mode support switch */ -#define RFAL_SUPPORT_MODE_LISTEN_NFCF false /*!< RFAL Listen NFCF mode support switch */ -#define RFAL_SUPPORT_MODE_LISTEN_ACTIVE_P2P true /*!< RFAL Listen AP2P mode support switch */ - -/*******************************************************************************/ -/*! RFAL supported Card Emulation (CE) */ -#define RFAL_SUPPORT_CE ( RFAL_SUPPORT_MODE_LISTEN_NFCA || RFAL_SUPPORT_MODE_LISTEN_NFCB || RFAL_SUPPORT_MODE_LISTEN_NFCF ) - -/*! RFAL supported Reader/Writer (RW) */ -#define RFAL_SUPPORT_RW ( RFAL_SUPPORT_MODE_POLL_NFCA || RFAL_SUPPORT_MODE_POLL_NFCB || RFAL_SUPPORT_MODE_POLL_NFCF || RFAL_SUPPORT_MODE_POLL_NFCV ) - -/*! RFAL support for Active P2P (AP2P) */ -#define RFAL_SUPPORT_AP2P ( RFAL_SUPPORT_MODE_POLL_ACTIVE_P2P || RFAL_SUPPORT_MODE_POLL_ACTIVE_P2P ) - - -/*******************************************************************************/ -#define RFAL_SUPPORT_BR_RW_106 true /*!< RFAL RW 106 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_RW_212 true /*!< RFAL RW 212 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_RW_424 true /*!< RFAL RW 424 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_RW_848 true /*!< RFAL RW 848 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_RW_1695 true /*!< RFAL RW 1695 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_RW_3390 true /*!< RFAL RW 3390 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_RW_6780 false /*!< RFAL RW 6780 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_RW_13560 false /*!< RFAL RW 6780 Bit Rate support switch */ - - -/*******************************************************************************/ -#define RFAL_SUPPORT_BR_AP2P_106 true /*!< RFAL AP2P 106 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_AP2P_212 true /*!< RFAL AP2P 212 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_AP2P_424 true /*!< RFAL AP2P 424 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_AP2P_848 false /*!< RFAL AP2P 848 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_AP2P_1695 false /*!< RFAL AP2P 1695 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_AP2P_3390 false /*!< RFAL AP2P 3390 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_AP2P_6780 false /*!< RFAL AP2P 6780 Bit Rate support switch */ - - -/*******************************************************************************/ -#define RFAL_SUPPORT_BR_CE_A_106 false /*!< RFAL CE A 106 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_CE_A_212 false /*!< RFAL CE A 212 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_CE_A_424 false /*!< RFAL CE A 424 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_CE_A_848 false /*!< RFAL CE A 848 Bit Rate support switch */ - - -/*******************************************************************************/ -#define RFAL_SUPPORT_BR_CE_B_106 false /*!< RFAL CE B 106 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_CE_B_212 false /*!< RFAL CE B 212 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_CE_B_424 false /*!< RFAL CE B 424 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_CE_B_848 false /*!< RFAL CE B 848 Bit Rate support switch */ - - -/*******************************************************************************/ -#define RFAL_SUPPORT_BR_CE_F_212 false /*!< RFAL CE F 212 Bit Rate support switch */ -#define RFAL_SUPPORT_BR_CE_F_424 false /*!< RFAL CE F 424 Bit Rate support switch */ - - -#endif /* RFAL_FEATURES_H */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_iso15693_2.h b/Software/Middlewares/ST/rfal/Inc/rfal_iso15693_2.h deleted file mode 100644 index da64117..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_iso15693_2.h +++ /dev/null @@ -1,202 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_iso15693_2.h - * - * \author Ulrich Herrmann - * - * \brief Implementation of ISO-15693-2 - * - */ -/*! - * - */ - -#ifndef RFAL_ISO_15693_2_H -#define RFAL_ISO_15693_2_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" -#include "st_errno.h" - -/* -****************************************************************************** -* GLOBAL DATATYPES -****************************************************************************** -*/ -/*! Enum holding possible VCD codings */ -typedef enum -{ - ISO15693_VCD_CODING_1_4, - ISO15693_VCD_CODING_1_256 -}iso15693VcdCoding_t; - -/*! Enum holding possible VICC datarates */ - -/*! Configuration parameter used by #iso15693PhyConfigure */ -typedef struct -{ - iso15693VcdCoding_t coding; /*!< desired VCD coding */ - uint32_t speedMode; /*!< 0: normal mode, 1: 2^1 = x2 Fast mode, 2 : 2^2 = x4 mode, 3 : 2^3 = x8 mode - all rx pulse numbers and times are divided by 1,2,4,8 */ -}iso15693PhyConfig_t; - -/*! Parameters how the stream mode should work */ -struct iso15693StreamConfig { - uint8_t useBPSK; /*!< 0: subcarrier, 1:BPSK */ - uint8_t din; /*!< the divider for the in subcarrier frequency: fc/2^din */ - uint8_t dout; /*!< the divider for the in subcarrier frequency fc/2^dout */ - uint8_t report_period_length; /*!< the length of the reporting period 2^report_period_length*/ -}; -/* -****************************************************************************** -* GLOBAL CONSTANTS -****************************************************************************** -*/ - -#define ISO15693_REQ_FLAG_TWO_SUBCARRIERS 0x01U /*!< Flag indication that communication uses two subcarriers */ -#define ISO15693_REQ_FLAG_HIGH_DATARATE 0x02U /*!< Flag indication that communication uses high bitrate */ -#define ISO15693_MASK_FDT_LISTEN (65) /*!< t1min = 308,2us = 4192/fc = 65.5 * 64/fc */ - -/*! t1max = 323,3us = 4384/fc = 68.5 * 64/fc - * 12 = 768/fc unmodulated time of single subcarrior SoF */ -#define ISO15693_FWT (69 + 12) - - - - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -/*! - ***************************************************************************** - * \brief Initialize the ISO15693 phy - * - * \param[in] config : ISO15693 phy related configuration (See #iso15693PhyConfig_t) - * \param[out] needed_stream_config : return a pointer to the stream config - * needed for this iso15693 config. To be used for configure RF chip. - * - * \return ERR_IO : Error during communication. - * \return ERR_NONE : No error. - * - ***************************************************************************** - */ -extern ReturnCode iso15693PhyConfigure(const iso15693PhyConfig_t* config, - const struct iso15693StreamConfig ** needed_stream_config ); - -/*! - ***************************************************************************** - * \brief Return current phy configuration - * - * This function returns current Phy configuration previously - * set by #iso15693PhyConfigure - * - * \param[out] config : ISO15693 phy configuration. - * - * \return ERR_NONE : No error. - * - ***************************************************************************** - */ -extern ReturnCode iso15693PhyGetConfiguration(iso15693PhyConfig_t* config); - -/*! - ***************************************************************************** - * \brief Code an ISO15693 compatible frame - * - * This function takes \a length bytes from \a buffer, perform proper - * encoding and sends out the frame to the ST25R391x. - * - * \param[in] buffer : data to send, modified to adapt flags. - * \param[in] length : number of bytes to send. - * \param[in] sendCrc : If set to true, CRC is appended to the frame - * \param[in] sendFlags: If set to true, flag field is sent according to - * ISO15693. - * \param[in] picopassMode : If set to true, the coding will be according to Picopass - * \param[out] subbit_total_length : Return the complete bytes which need to - * be send for the current coding - * \param[in,out] offset : Set to 0 for first transfer, function will update it to - point to next byte to be coded - * \param[out] outbuf : buffer where the function will store the coded subbit stream - * \param[out] outBufSize : the size of the output buffer - * \param[out] actOutBufSize : the amount of data stored into the buffer at this call - * - * \return ERR_IO : Error during communication. - * \return ERR_AGAIN : Data was not coded all the way. Call function again with a new/emptied buffer - * \return ERR_NO_MEM : In case outBuf is not big enough. Needs to have at - least 5 bytes for 1of4 coding and 65 bytes for 1of256 coding - * \return ERR_NONE : No error. - * - ***************************************************************************** - */ -extern ReturnCode iso15693VCDCode(uint8_t* buffer, uint16_t length, bool sendCrc, bool sendFlags, bool picopassMode, - uint16_t *subbit_total_length, uint16_t *offset, - uint8_t* outbuf, uint16_t outBufSize, uint16_t* actOutBufSize); - - -/*! - ***************************************************************************** - * \brief Receive an ISO15693 compatible frame - * - * This function receives an ISO15693 frame from the ST25R391x, decodes the frame - * and writes the raw data to \a buffer. - * \note Buffer needs to be big enough to hold CRC also (+2 bytes) - * - * \param[in] inBuf : buffer with the hamming coded stream to be decoded - * \param[in] inBufLen : number of bytes to decode (=length of buffer). - * \param[out] outBuf : buffer where received data shall be written to. - * \param[in] outBufLen : Length of output buffer, should be approx twice the size of inBuf - * \param[out] outBufPos : The number of decoded bytes. Could be used in - * extended implementation to allow multiple calls - * \param[out] bitsBeforeCol : in case of ERR_COLLISION this value holds the - * number of bits in the current byte where the collision happened. - * \param[in] ignoreBits : number of bits in the beginning where collisions will be ignored - * \param[in] picopassMode : if set to true, the decoding will be according to Picopass - * - * \return ERR_COLLISION : collision occured, data uncorrect - * \return ERR_CRC : CRC error, data uncorrect - * \return ERR_TIMEOUT : timeout waiting for data. - * \return ERR_NONE : No error. - * - ***************************************************************************** - */ -extern ReturnCode iso15693VICCDecode(const uint8_t *inBuf, - uint16_t inBufLen, - uint8_t* outBuf, - uint16_t outBufLen, - uint16_t* outBufPos, - uint16_t* bitsBeforeCol, - uint16_t ignoreBits, - bool picopassMode ); - -#endif /* RFAL_ISO_15693_2_H */ - diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_isoDep.h b/Software/Middlewares/ST/rfal/Inc/rfal_isoDep.h deleted file mode 100644 index 546d6fe..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_isoDep.h +++ /dev/null @@ -1,866 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_isoDep.h - * - * \author Gustavo Patricio - * - * \brief Implementation of ISO-DEP protocol - * - * This implementation was based on the following specs: - * - ISO/IEC 14443-4 2nd Edition 2008-07-15 - * - NFC Forum Digital Protocol 1.1 2014-01-14 - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup ISO-DEP - * \brief RFAL ISO-DEP Module - * @{ - * - */ - -#ifndef RFAL_ISODEP_H_ -#define RFAL_ISODEP_H_ -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "rfal_nfcb.h" -/* - ****************************************************************************** - * DEFINES - ****************************************************************************** - */ - -#define RFAL_ISODEP_PROLOGUE_SIZE (3U) /*!< Length of Prologue Field for I-Block Format */ - -#define RFAL_ISODEP_PCB_LEN (1U) /*!< PCB length */ -#define RFAL_ISODEP_DID_LEN (1U) /*!< DID length */ -#define RFAL_ISODEP_NAD_LEN (1U) /*!< NAD length */ -#define RFAL_ISODEP_NO_DID (0x00U) /*!< DID value indicating the ISO-DEP layer not to use DID */ -#define RFAL_ISODEP_NO_NAD (0xFFU) /*!< NAD value indicating the ISO-DEP layer not to use NAD */ - -#define RFAL_ISODEP_FWI_MASK (0xF0U) /*!< Mask bits of FWI */ -#define RFAL_ISODEP_FWI_SHIFT (4U) /*!< Shift val of FWI */ -#define RFAL_ISODEP_FWI_DEFAULT (4U) /*!< Default value for FWI Digital 1.0 11.6.2.17 */ -#define RFAL_ISODEP_ADV_FEATURE (0x0FU) /*!< Indicate 256 Bytes FSD and Advanc Proto Feature support:NAD & DID */ - -#define RFAL_ISODEP_DID_MAX (14U) /*!< Maximum DID value */ - -#define RFAL_ISODEP_BRI_MASK (0x07U) /*!< Mask bits for Poll to Listen Send bitrate */ -#define RFAL_ISODEP_BSI_MASK (0x70U) /*!< Mask bits for Listen to Poll Send bitrate */ -#define RFAL_ISODEP_SAME_BITRATE_MASK (0x80U) /*!< Mask bit indicate only same bit rate D for both direction support */ -#define RFAL_ISODEP_BITRATE_RFU_MASK (0x08U) /*!< Mask bit for RFU */ - -/*! Maximum Frame Waiting Time = ((256 * 16/fc) * 2^FWImax) = ((256*16/fc)*2^14) = (67108864)/fc = 2^26 (1/fc) */ -#define RFAL_ISODEP_MAX_FWT ((uint32_t)1U<<26) - - - -#define RFAL_ISODEP_FSDI_DEFAULT RFAL_ISODEP_FSXI_256 /*!< Default Frame Size Integer in Poll mode */ -#define RFAL_ISODEP_FSX_KEEP (0xFFU) /*!< Flag to keep FSX from activation */ -#define RFAL_ISODEP_DEFAULT_FSCI RFAL_ISODEP_FSXI_256 /*!< FSCI default value to be used in Listen Mode */ -#define RFAL_ISODEP_DEFAULT_FSC RFAL_ISODEP_FSX_256 /*!< FSC default value (aligned RFAL_ISODEP_DEFAULT_FSCI) */ -#define RFAL_ISODEP_DEFAULT_SFGI (0U) /*!< SFGI Default value to be used in Listen Mode */ -#define RFAL_ISODEP_DEFAULT_FWI (8U) /*!< Default Listener FWI (Max) Digital 2.0 B7 & B3 */ - -#define RFAL_ISODEP_APDU_MAX_LEN RFAL_ISODEP_FSX_1024 /*!< Max APDU length */ - -#define RFAL_ISODEP_ATTRIB_RES_MBLI_NO_INFO (0x00U) /*!< MBLI indicating no information on its internal input buffer size */ -#define RFAL_ISODEP_ATTRIB_REQ_PARAM1_DEFAULT (0x00U) /*!< Default values of Param 1 of ATTRIB_REQ Digital 1.0 12.6.1.3-5 */ -#define RFAL_ISODEP_ATTRIB_HLINFO_LEN (32U) /*!< Maximum Size of Higher Layer Information */ -#define RFAL_ISODEP_ATS_HB_MAX_LEN (15U) /*!< Maximum length of Historical Bytes Digital 1.1 13.6.2.23 */ -#define RFAL_ISODEP_ATTRIB_REQ_MIN_LEN (9U) /*!< Minimum Length of ATTRIB_REQ command */ -#define RFAL_ISODEP_ATTRIB_RES_MIN_LEN (1U) /*!< Minimum Length of ATTRIB_RES response */ - -#define RFAL_ISODEP_SPARAM_VALUES_MAX_LEN (16U) /*!< Maximum Length of the value field on S(PARAMETERS) */ -#define RFAL_ISODEP_SPARAM_TAG_BLOCKINFO (0xA0U) /*!< S(PARAMETERS) tag Block information */ -#define RFAL_ISODEP_SPARAM_TAG_BRREQ (0xA1U) /*!< S(PARAMETERS) tag Bit rates Request */ -#define RFAL_ISODEP_SPARAM_TAG_BRIND (0xA2U) /*!< S(PARAMETERS) tag Bit rates Indication */ -#define RFAL_ISODEP_SPARAM_TAG_BRACT (0xA3U) /*!< S(PARAMETERS) tag Bit rates Activation */ -#define RFAL_ISODEP_SPARAM_TAG_BRACK (0xA4U) /*!< S(PARAMETERS) tag Bit rates Acknowledgement */ - -#define RFAL_ISODEP_SPARAM_TAG_SUP_PCD2PICC (0x80U) /*!< S(PARAMETERS) tag Supported bit rates from PCD to PICC */ -#define RFAL_ISODEP_SPARAM_TAG_SUP_PICC2PCD (0x81U) /*!< S(PARAMETERS) tag Supported bit rates from PICC to PCD */ -#define RFAL_ISODEP_SPARAM_TAG_SUP_FRAME (0x82U) /*!< S(PARAMETERS) tag Supported framing options PICC to PCD */ -#define RFAL_ISODEP_SPARAM_TAG_SEL_PCD2PICC (0x83U) /*!< S(PARAMETERS) tag Selected bit rate from PCD to PICC */ -#define RFAL_ISODEP_SPARAM_TAG_SEL_PICC2PCD (0x84U) /*!< S(PARAMETERS) tag Selected bit rate from PICC to PCD */ -#define RFAL_ISODEP_SPARAM_TAG_SEL_FRAME (0x85U) /*!< S(PARAMETERS) tag Selected framing options PICC to PCD */ - -#define RFAL_ISODEP_SPARAM_TAG_LEN (1) /*!< S(PARAMETERS) Tag Length */ -#define RFAL_ISODEP_SPARAM_TAG_BRREQ_LEN (0U) /*!< S(PARAMETERS) tag Bit rates Request Length */ -#define RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN (2U) /*!< S(PARAMETERS) bit rates from PCD to PICC Length */ -#define RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN (2U) /*!< S(PARAMETERS) bit rates from PICC to PCD Length */ -#define RFAL_ISODEP_SPARAM_TAG_BRACK_LEN (0U) /*!< S(PARAMETERS) tag Bit rates Acknowledgement Length */ - -#define RFAL_ISODEP_ATS_TA_DPL_212 (0x01U) /*!< ATS TA DSI 212 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_DPL_424 (0x02U) /*!< ATS TA DSI 424 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_DPL_848 (0x04U) /*!< ATS TA DSI 848 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_DLP_212 (0x10U) /*!< ATS TA DSI 212 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_DLP_424 (0x20U) /*!< ATS TA DRI 424 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_DLP_848 (0x40U) /*!< ATS TA DRI 848 kbps support bit mask */ -#define RFAL_ISODEP_ATS_TA_SAME_D (0x80U) /*!< ATS TA same bit both directions bit mask */ -#define RFAL_ISODEP_ATS_TB_FWI_MASK (0xF0U) /*!< Mask bits for FWI (Frame Waiting Integer) in TB byte */ -#define RFAL_ISODEP_ATS_TB_SFGI_MASK (0x0FU) /*!< Mask bits for SFGI (Start-Up Frame Guard Integer) in TB byte */ - -#define RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK (0x10U) /*!< Mask bit for TA presence */ -#define RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK (0x20U) /*!< Mask bit for TB presence */ -#define RFAL_ISODEP_ATS_T0_TC_PRESENCE_MASK (0x40U) /*!< Mask bit for TC presence */ -#define RFAL_ISODEP_ATS_T0_FSCI_MASK (0x0FU) /*!< Mask bit for FSCI presence */ -#define RFAL_ISODEP_ATS_T0_OFFSET (0x01U) /*!< Offset of T0 in ATS Response */ - - -#define RFAL_ISODEP_MAX_I_RETRYS (2U) /*!< Number of retries for a I-Block Digital 1.1 15.2.5.4 */ -#define RFAL_ISODEP_MAX_R_RETRYS (3U) /*!< Number of retries for a R-Block Digital 1.1 A8 - nRETRY ACK/NAK: [2,5] */ -#define RFAL_ISODEP_MAX_S_RETRYS (3U) /*!< Number of retries for a S-Block Digital 1.1 A8 - nRETRY DESELECT: [0,5] WTX[2,5] */ -#define RFAL_ISODEP_RATS_RETRIES (1U) /*!< RATS retries upon fail Digital 1.1 A.6 - [0,1] */ - - -/*! Frame Size for Proximity Card Integer definitions */ -typedef enum -{ - RFAL_ISODEP_FSXI_16 = 0, /*!< Frame Size for Proximity Card Integer with 16 bytes */ - RFAL_ISODEP_FSXI_24 = 1, /*!< Frame Size for Proximity Card Integer with 24 bytes */ - RFAL_ISODEP_FSXI_32 = 2, /*!< Frame Size for Proximity Card Integer with 32 bytes */ - RFAL_ISODEP_FSXI_40 = 3, /*!< Frame Size for Proximity Card Integer with 40 bytes */ - RFAL_ISODEP_FSXI_48 = 4, /*!< Frame Size for Proximity Card Integer with 48 bytes */ - RFAL_ISODEP_FSXI_64 = 5, /*!< Frame Size for Proximity Card Integer with 64 bytes */ - RFAL_ISODEP_FSXI_96 = 6, /*!< Frame Size for Proximity Card Integer with 96 bytes */ - RFAL_ISODEP_FSXI_128 = 7, /*!< Frame Size for Proximity Card Integer with 128 bytes */ - RFAL_ISODEP_FSXI_256 = 8, /*!< Frame Size for Proximity Card Integer with 256 bytes */ - RFAL_ISODEP_FSXI_512 = 9, /*!< Frame Size for Proximity Card Integer with 512 bytes ISO14443-3 Amd2 2012 */ - RFAL_ISODEP_FSXI_1024 = 10, /*!< Frame Size for Proximity Card Integer with 1024 bytes ISO14443-3 Amd2 2012 */ - RFAL_ISODEP_FSXI_2048 = 11, /*!< Frame Size for Proximity Card Integer with 2048 bytes ISO14443-3 Amd2 2012 */ - RFAL_ISODEP_FSXI_4096 = 12 /*!< Frame Size for Proximity Card Integer with 4096 bytes ISO14443-3 Amd2 2012 */ -} rfalIsoDepFSxI; - -/*! Frame Size for Proximity Card definitions */ -typedef enum -{ - RFAL_ISODEP_FSX_16 = 16, /*!< Frame Size for Proximity Card with 16 bytes */ - RFAL_ISODEP_FSX_24 = 24, /*!< Frame Size for Proximity Card with 24 bytes */ - RFAL_ISODEP_FSX_32 = 32, /*!< Frame Size for Proximity Card with 32 bytes */ - RFAL_ISODEP_FSX_40 = 40, /*!< Frame Size for Proximity Card with 40 bytes */ - RFAL_ISODEP_FSX_48 = 48, /*!< Frame Size for Proximity Card with 48 bytes */ - RFAL_ISODEP_FSX_64 = 64, /*!< Frame Size for Proximity Card with 64 bytes */ - RFAL_ISODEP_FSX_96 = 96, /*!< Frame Size for Proximity Card with 96 bytes */ - RFAL_ISODEP_FSX_128 = 128, /*!< Frame Size for Proximity Card with 128 bytes */ - RFAL_ISODEP_FSX_256 = 256, /*!< Frame Size for Proximity Card with 256 bytes */ - RFAL_ISODEP_FSX_512 = 512, /*!< Frame Size for Proximity Card with 512 bytes ISO14443-3 Amd2 2012 */ - RFAL_ISODEP_FSX_1024 = 1024, /*!< Frame Size for Proximity Card with 1024 bytes ISO14443-3 Amd2 2012 */ - RFAL_ISODEP_FSX_2048 = 2048, /*!< Frame Size for Proximity Card with 2048 bytes ISO14443-3 Amd2 2012 */ - RFAL_ISODEP_FSX_4096 = 4096, /*!< Frame Size for Proximity Card with 4096 bytes ISO14443-3 Amd2 2012 */ -} rfalIsoDepFSx; - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL DATA TYPES - ****************************************************************************** - */ - -/*! RATS format Digital 1.1 13.6.1 */ -typedef struct -{ - uint8_t CMD; /*!< RATS command byte: 0xE0 */ - uint8_t PARAM; /*!< Param indicating FSDI and DID */ -} rfalIsoDepRats; - - -/*! ATS response format Digital 1.1 13.6.2 */ -typedef struct -{ - uint8_t TL; /*!< Length Byte, including TL byte itself */ - uint8_t T0; /*!< Format Byte T0 indicating if TA, TB, TC */ - uint8_t TA; /*!< Interface Byte TA(1) */ - uint8_t TB; /*!< Interface Byte TB(1) */ - uint8_t TC; /*!< Interface Byte TC(1) */ - uint8_t HB[RFAL_ISODEP_ATS_HB_MAX_LEN]; /*!< Historical Bytes */ -} rfalIsoDepAts; - - -/*! PPS Request format (Protocol and Parameter Selection) ISO14443-4 5.3 */ -typedef struct -{ - uint8_t PPSS; /*!< Start Byte: [ 1101b | CID[4b] ] */ - uint8_t PPS0; /*!< Parameter 0:[ 000b | PPS1[1n] | 0001b ] */ - uint8_t PPS1; /*!< Parameter 1:[ 0000b | DSI[2b] | DRI[2b] ]*/ -} rfalIsoDepPpsReq; - - -/*! PPS Response format (Protocol and Parameter Selection) ISO14443-4 5.4 */ -typedef struct -{ - uint8_t PPSS; /*!< Start Byte: [ 1101b | CID[4b] ] */ -} rfalIsoDepPpsRes; - - -/*! ATTRIB Command Format Digital 1.1 15.6.1 */ -typedef struct -{ - uint8_t cmd; /*!< ATTRIB_REQ command byte */ - uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFCID0 of the card to be selected */ - struct{ - uint8_t PARAM1; /*!< PARAM1 of ATTRIB command */ - uint8_t PARAM2; /*!< PARAM2 of ATTRIB command */ - uint8_t PARAM3; /*!< PARAM3 of ATTRIB command */ - uint8_t PARAM4; /*!< PARAM4 of ATTRIB command */ - }Param; /*!< Parameter of ATTRIB command */ - uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Higher Layer Information */ -} rfalIsoDepAttribCmd; - - -/*! ATTRIB Response Format Digital 1.1 15.6.2 */ -typedef struct -{ - uint8_t mbliDid; /*!< Contains MBLI and DID */ - uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Higher Layer Information */ -} rfalIsoDepAttribRes; - -/*! S(Parameters) Command Format ISO14443-4 (2016) Table 4 */ -typedef struct -{ - uint8_t tag; /*!< S(PARAMETERS) Tag field */ - uint8_t length; /*!< S(PARAMETERS) Length field */ - uint8_t value[RFAL_ISODEP_SPARAM_VALUES_MAX_LEN]; /*!< S(PARAMETERS) Value field */ -} rfalIsoDepSParameter; - - -/*! Activation info as Poller and Listener for NFC-A and NFC-B */ -typedef union {/* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only of type A or B at a time. Thus no problem can occur. */ - - /*! NFC-A information */ - union {/* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only PCD or PICC at a time. Thus no problem can occur. */ - struct { - rfalIsoDepAts ATS; /*!< ATS response (Poller mode) */ - uint8_t ATSLen; /*!< ATS response length (Poller mode) */ - }Listener; - struct { - rfalIsoDepRats RATS; /*!< RATS request (Listener mode) */ - }Poller; - }A; - - /*! NFC-B information */ - union {/* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only PCD or PICC at a time. Thus no problem can occur. */ - struct{ - rfalIsoDepAttribRes ATTRIB_RES; /*!< ATTRIB_RES (Poller mode) */ - uint8_t ATTRIB_RESLen; /*!< ATTRIB_RES length (Poller mode) */ - }Listener; - struct{ - rfalIsoDepAttribCmd ATTRIB; /*!< ATTRIB request (Listener mode) */ - uint8_t ATTRIBLen; /*!< ATTRIB request length (Listener mode) */ - }Poller; - }B; -}rfalIsoDepActivation; - - -/*! ISO-DEP device Info */ -typedef struct { - uint8_t FWI; /*!< Frame Waiting Integer */ - uint32_t FWT; /*!< Frame Waiting Time (1/fc) */ - uint32_t dFWT; /*!< Delta Frame Waiting Time (1/fc) */ - uint32_t SFGI; /*!< Start-up Frame Guard time Integer */ - uint32_t SFGT; /*!< Start-up Frame Guard Time (ms) */ - uint8_t FSxI; /*!< Frame Size Device/Card Integer (FSDI or FSCI) */ - uint16_t FSx; /*!< Frame Size Device/Card (FSD or FSC) */ - uint32_t MBL; /*!< Maximum Buffer Length (optional for NFC-B) */ - rfalBitRate DSI; /*!< Bit Rate coding from Listener (PICC) to Poller (PCD) */ - rfalBitRate DRI; /*!< Bit Rate coding from Poller (PCD) to Listener (PICC) */ - uint8_t DID; /*!< Device ID */ - uint8_t NAD; /*!< Node ADdress */ - bool supDID; /*!< DID supported flag */ - bool supNAD; /*!< NAD supported flag */ - bool supAdFt; /*!< Advanced Features supported flag */ -} rfalIsoDepInfo; - - -/*! ISO-DEP Device structure */ -typedef struct { - rfalIsoDepActivation activation; /*!< Activation Info */ - rfalIsoDepInfo info; /*!< ISO-DEP (ISO14443-4) device Info */ -} rfalIsoDepDevice; - - -/*! ATTRIB Response parameters */ -typedef struct -{ - uint8_t mbli; /*!< MBLI */ - uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Hi Layer Information */ - uint8_t HLInfoLen; /*!< Hi Layer Information Length */ -} rfalIsoDepAttribResParam; - - -/*! ATS Response parameter */ -typedef struct -{ - uint8_t fsci; /*!< Frame Size of Proximity Card Integer */ - uint8_t fwi; /*!< Frame Waiting Time Integer */ - uint8_t sfgi; /*!< Start-Up Frame Guard Time Integer */ - bool didSupport; /*!< DID Supported */ - uint8_t ta; /*!< Max supported bitrate both direction */ - uint8_t *hb; /*!< Historical Bytes data */ - uint8_t hbLen; /*!< Historical Bytes Length */ -} rfalIsoDepAtsParam; - - -/*! Structure of I-Block Buffer format from caller */ -typedef struct -{ - uint8_t prologue[RFAL_ISODEP_PROLOGUE_SIZE]; /*!< Prologue/SoD buffer */ - uint8_t inf[RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN]; /*!< INF/Payload buffer */ -} rfalIsoDepBufFormat; - - -/*! Structure of APDU Buffer format from caller */ -typedef struct -{ - uint8_t prologue[RFAL_ISODEP_PROLOGUE_SIZE]; /*!< Prologue/SoD buffer */ - uint8_t apdu[RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN]; /*!< APDU/Payload buffer */ -} rfalIsoDepApduBufFormat; - - -/*! Listen Activation Parameters Structure */ -typedef struct -{ - rfalIsoDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */ - uint16_t *rxLen; /*!< Received INF data length in Bytes */ - bool *isRxChaining; /*!< Received data is not complete */ - rfalIsoDepDevice *isoDepDev; /*!< ISO-DEP device info */ -} rfalIsoDepListenActvParam; - - -/*! Structure of parameters used on ISO DEP Transceive */ -typedef struct -{ - rfalIsoDepBufFormat *txBuf; /*!< Transmit Buffer struct reference */ - uint16_t txBufLen; /*!< Transmit Buffer INF field length in Bytes*/ - bool isTxChaining; /*!< Transmit data is not complete */ - rfalIsoDepBufFormat *rxBuf; /*!< Receive Buffer struct reference in Bytes */ - uint16_t *rxLen; /*!< Received INF data length in Bytes */ - bool *isRxChaining; /*!< Received data is not complete */ - uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */ - uint32_t dFWT; /*!< Delta FWT to be used */ - uint16_t ourFSx; /*!< Our device Frame Size (FSD or FSC) */ - uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */ - uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */ -} rfalIsoDepTxRxParam; - - -/*! Structure of parameters used on ISO DEP APDU Transceive */ -typedef struct -{ - rfalIsoDepApduBufFormat *txBuf; /*!< Transmit Buffer struct reference */ - uint16_t txBufLen; /*!< Transmit Buffer INF field length in Bytes*/ - rfalIsoDepApduBufFormat *rxBuf; /*!< Receive Buffer struct reference in Bytes */ - uint16_t *rxLen; /*!< Received INF data length in Bytes */ - rfalIsoDepBufFormat *tmpBuf; /*!< Temp buffer for Rx I-Blocks (internal) */ - uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */ - uint32_t dFWT; /*!< Delta FWT to be used */ - uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */ - uint16_t ourFSx; /*!< Our device Frame Size (FSD or FSC) */ - uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */ -} rfalIsoDepApduTxRxParam; - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - - -/*! - ****************************************************************************** - * \brief Initialize the ISO-DEP protocol - * - * Initialize the ISO-DEP protocol layer with default config - ****************************************************************************** - */ -void rfalIsoDepInitialize( void ); - - -/*! - ****************************************************************************** - * \brief Initialize the ISO-DEP protocol - * - * Initialize the ISO-DEP protocol layer with additional parameters allowing - * to customise the protocol layer for specific behaviours - * - * \param[in] compMode : compliance mode to be performed - * \param[in] maxRetriesR : Number of retries for a R-Block - * \param[in] maxRetriesS : Number of retries for a S-Block - * \param[in] maxRetriesI : Number of retries for a I-Block - * \param[in] maxRetriesRATS : Number of retries for RATS - * - ****************************************************************************** - */ -void rfalIsoDepInitializeWithParams( rfalComplianceMode compMode, uint8_t maxRetriesR, uint8_t maxRetriesS, uint8_t maxRetriesI, uint8_t maxRetriesRATS ); - - -/*! - ***************************************************************************** - * \brief FSxI to FSx - * - * Convert Frame Size for proximity coupling Device Integer (FSxI) to - * Frame Size for proximity coupling Device (FSx) - * - * FSD - maximum frame size for NFC Forum Device in Poll Mode - * FSC - maximum frame size for NFC Forum Device in Listen Mode - * - * FSxI = FSDI or FSCI - * FSx = FSD or FSC - * - * The FSD/FSC value includes the header and CRC - * - * \param[in] FSxI : Frame Size for proximity coupling Device Integer - * - * \return fsx : Frame Size for proximity coupling Device (FSD or FSC) - * - ***************************************************************************** - */ -uint16_t rfalIsoDepFSxI2FSx( uint8_t FSxI ); - - -/*! - ***************************************************************************** - * \brief FWI to FWT - * - * Convert Frame Waiting time Integer (FWI) to Frame Waiting Time (FWT) in - * 1/fc units - * - * \param[in] fwi : Frame Waiting time Integer - * - * \return fwt : Frame Waiting Time in 1/fc units - * - ***************************************************************************** - */ -uint32_t rfalIsoDepFWI2FWT( uint8_t fwi ); - - -/*! - ***************************************************************************** - * \brief Check if the buffer data contains a valid RATS command - * - * Check if it is a well formed RATS command with 2 bytes - * This function does not check the validity of FSDI and DID - * - * \param[in] buf : reference to buffer containing the data to be checked - * \param[in] bufLen : length of data in the buffer in bytes - * - * \return true if the data indicates a RATS command; false otherwise - ***************************************************************************** - */ -bool rfalIsoDepIsRats( const uint8_t *buf, uint8_t bufLen ); - - -/*! - ***************************************************************************** - * \brief Check if the buffer data contains a valid ATTRIB command - * - * Check if it is a well formed ATTRIB command, but does not check the - * validity of the information inside - * - * \param[in] buf : reference to buffer containing the data to be checked - * \param[in] bufLen : length of data in the buffer in bytes - * - * \return true if the data indicates a ATTRIB command; false otherwise - ***************************************************************************** - */ -bool rfalIsoDepIsAttrib( const uint8_t *buf, uint8_t bufLen ); - - -/*! - ***************************************************************************** - * \brief Start Listen Activation Handling - * - * Start Listen Activation Handling and setup to receive first I-block which may - * contain complete or partial APDU after activation is completed - * - * Pass in RATS for T4AT, or ATTRIB for T4BT, to handle ATS or ATTRIB Response respectively - * The Activation Handling handles ATS and ATTRIB Response; and additionally PPS Response - * if a PPS is received for T4AT. - * The method uses the current RFAL state machine to determine if it is expecting RATS or ATTRIB - * - * Activation is completed if PPS Response is sent or if first PDU is received in T4T-A - * Activation is completed if ATTRIB Response is sent in T4T-B - * - * \ref rfalIsoDepListenGetActivationStatus provide status if activation is completed. - * \ref rfalIsoDepStartTransceive shall be called right after activation is completed - * - * \param[in] atsParam : reference to ATS parameters - * \param[in] attribResParam : reference to ATTRIB_RES parameters - * \param[in] buf : reference to buffer containing RATS or ATTRIB - * \param[in] bufLen : length in bytes of the given bufffer - * \param[in] actParam : reference to incoming reception information will be placed - * - * - * \warning Once the Activation has been completed the method - * rfalIsoDepGetTransceiveStatus() must be called. - * If activation has completed due to reception of a data block (not PPS) the - * buffer owned by the caller and passed on actParam must still contain this data. - * The first data will be processed (I-Block or S-DSL) by rfalIsoDepGetTransceiveStatus() - * inform the caller and then for the next transaction use rfalIsoDepStartTransceive() - * - * \return ERR_NONE : RATS/ATTRIB is valid and activation has started - * \return ERR_PARAM : Invalid parameters - * \return ERR_PROTO : Invalid request - * \return ERR_NOTSUPP : Feature not supported - ***************************************************************************** - */ -ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const rfalIsoDepAttribResParam *attribResParam, uint8_t *buf, uint16_t bufLen, rfalIsoDepListenActvParam actParam ); - - -/*! - ***************************************************************************** - * \brief Get the current Activation Status - * - * \return ERR_NONE if Activation is already completed - * \return ERR_BUSY if Activation is ongoing - * \return ERR_LINK_LOSS if Remote Field is turned off - ***************************************************************************** - */ -ReturnCode rfalIsoDepListenGetActivationStatus( void ); - - -/*! - ***************************************************************************** - * \brief Get the ISO-DEP Communication Information - * - * Gets the maximum INF length in bytes based on current Frame Size - * for proximity coupling Device (FSD or FSC) excluding the header and CRC - * - * \return maximum INF length in bytes - ***************************************************************************** - */ -uint16_t rfalIsoDepGetMaxInfLen( void ); - - -/*! - ***************************************************************************** - * \brief ISO-DEP Start Transceive - * - * This method triggers a ISO-DEP Transceive containing a complete or - * partial APDU - * It transmits the given message and handles all protocol retransmitions, - * error handling and control messages - * - * The txBuf contains a complete or partial APDU (INF) to be transmitted - * The Prologue field will be manipulated by the Transceive - * - * If the buffer contains a partial APDU and is not the last block, - * then isTxChaining must be set to true - * - * \param[in] param: reference parameters to be used for the Transceive - * - * \return ERR_PARAM : Bad request - * \return ERR_WRONG_STATE : The module is not in a proper state - * \return ERR_NONE : The Transceive request has been started - ***************************************************************************** - */ -ReturnCode rfalIsoDepStartTransceive( rfalIsoDepTxRxParam param ); - - -/*! - ***************************************************************************** - * \brief Get the Transceive status - * - * Returns the status of the ISO-DEP Transceive - * - * \warning When the other device is performing chaining once a chained - * block is received the error ERR_AGAIN is sent. At this point - * caller must handle the received data immediately. - * When ERR_AGAIN is returned an ACK has already been sent to - * the other device and the next block might be incoming. - * If rfalWorker() is called frequently it will place the next - * block on the given buffer - * - * - * \return ERR_NONE : Transceive has been completed successfully - * \return ERR_BUSY : Transceive is ongoing - * \return ERR_PROTO : Protocol error occurred - * \return ERR_TIMEOUT : Timeout error occurred - * \return ERR_SLEEP_REQ : Deselect has been received and responded - * \return ERR_NOMEM : The received INF does not fit into the - * receive buffer - * \return ERR_LINK_LOSS : Communication is lost because Reader/Writer - * has turned off its field - * \return ERR_AGAIN : received one chaining block, continue to call - * this method to retrieve the remaining blocks - ***************************************************************************** - */ -ReturnCode rfalIsoDepGetTransceiveStatus( void ); - - -/*! - ***************************************************************************** - * \brief ISO-DEP Start APDU Transceive - * - * This method triggers a ISO-DEP Transceive containing a complete APDU - * It transmits the given message and handles all protocol retransmitions, - * error handling and control messages - * - * The txBuf contains a complete APDU to be transmitted - * The Prologue field will be manipulated by the Transceive - * - * \warning the txBuf will be modified during the transmission - * \warning the maximum RF frame which can be received is limited by param.tmpBuf - * - * \param[in] param: reference parameters to be used for the Transceive - * - * \return ERR_PARAM : Bad request - * \return ERR_WRONG_STATE : The module is not in a proper state - * \return ERR_NONE : The Transceive request has been started - ***************************************************************************** - */ -ReturnCode rfalIsoDepStartApduTransceive( rfalIsoDepApduTxRxParam param ); - - -/*! - ***************************************************************************** - * \brief Get the APDU Transceive status - * - * \return ERR_NONE : if Transceive has been completed successfully - * \return ERR_BUSY : if Transceive is ongoing - * \return ERR_PROTO : if a protocol error occurred - * \return ERR_TIMEOUT : if a timeout error occurred - * \return ERR_SLEEP_REQ : if Deselect is received and responded - * \return ERR_NOMEM : if the received INF does not fit into the - * receive buffer - * \return ERR_LINK_LOSS : if communication is lost because Reader/Writer - * has turned off its field - ***************************************************************************** - */ -ReturnCode rfalIsoDepGetApduTransceiveStatus( void ); - -/*! - ***************************************************************************** - * \brief ISO-DEP Send RATS - * - * This sends a RATS to make a NFC-A Listen Device to enter - * ISO-DEP layer (ISO14443-4) and checks if the received ATS is valid - * - * \param[in] FSDI : Frame Size Device Integer to be used - * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID - * \param[out] ats : pointer to place the ATS Response - * \param[out] atsLen : pointer to place the ATS length - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, ATS received - ***************************************************************************** - */ -ReturnCode rfalIsoDepRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats , uint8_t *atsLen ); - - -/*! - ***************************************************************************** - * \brief ISO-DEP Send PPS - * - * This sends a PPS to make a NFC-A Listen Device change the communications - * bit rate from 106kbps to one of the supported bit rates - * Additionally checks if the received PPS response is valid - * - * \param[in] DID : Device ID - * \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD) - * \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC) - * \param[out] ppsRes : pointer to place the PPS Response - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, PPS Response received - ***************************************************************************** - */ -ReturnCode rfalIsoDepPPS( uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes ); - - -/*! - ***************************************************************************** - * \brief ISO-DEP Send ATTRIB - * - * This sends a ATTRIB to make a NFC-B Listen Device to enter - * ISO-DEP layer (ISO14443-4) and checks if the received ATTRIB Response is valid - * - * \param[in] nfcid0 : NFCID0 to be used for the ATTRIB - * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters) - * \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD) - * \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC) - * \param[in] FSDI : PCD's Frame Size to be announced on the ATTRIB - * \param[in] PARAM3 : ATTRIB PARAM1 byte (protocol type) - * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID - * \param[in] HLInfo : pointer to Higher layer INF (NULL if none) - * \param[in] HLInfoLen : Length HLInfo - * \param[in] fwt : Frame Waiting Time to be used (from SENSB_RES) - * \param[out] attribRes : pointer to place the ATTRIB Response - * \param[out] attribResLen : pointer to place the ATTRIB Response length - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, ATTRIB Response received - ***************************************************************************** - */ -ReturnCode rfalIsoDepATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen ); - - -/*! - ***************************************************************************** - * \brief Deselects PICC - * - * This function sends a deselect command to PICC and waits for it`s - * responce in a blocking way - * - * \return ERR_NONE : Deselect successfully sent and acknowledged by PICC - * \return ERR_TIMEOUT: No response rcvd from PICC - * - ***************************************************************************** - */ -ReturnCode rfalIsoDepDeselect( void ); - - -/*! - ***************************************************************************** - * \brief ISO-DEP Poller Handle NFC-A Activation - * - * This performs a NFC-A Activation into ISO-DEP layer (ISO14443-4) with the given - * parameters. It sends RATS and if the higher bit rates are supported by - * both devices it additionally sends PPS - * Once Activated all details of the device are provided on isoDepDev - * - * \param[in] FSDI : Frame Size Device Integer to be used - * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID - * \param[in] maxBR : Max bit rate supported by the Poller - * \param[out] isoDepDev : ISO-DEP information of the activated Listen device - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, activation successful - ***************************************************************************** - */ -ReturnCode rfalIsoDepPollAHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, rfalIsoDepDevice *isoDepDev ); - - -/*! - ***************************************************************************** - * \brief ISO-DEP Poller Handle NFC-B Activation - * - * This performs a NFC-B Activation into ISO-DEP layer (ISO14443-4) with the given - * parameters. It sends ATTRIB and calculates supported higher bit rates of both - * devices and performs activation. - * Once Activated all details of the device are provided on isoDepDev - * - * \param[in] FSDI : Frame Size Device Integer to be used - * \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID - * \param[in] maxBR : Max bit rate supported by the Poller - * \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters) - * \param[in] nfcbDev : pointer to the NFC-B Device containing the SENSB_RES - * \param[in] HLInfo : pointer to Higher layer INF (NULL if none) - * \param[in] HLInfoLen : Length HLInfo - * \param[out] isoDepDev : ISO-DEP information of the activated Listen device - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, activation successful - ***************************************************************************** - */ -ReturnCode rfalIsoDepPollBHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, uint8_t PARAM1, const rfalNfcbListenDevice *nfcbDev, const uint8_t* HLInfo, uint8_t HLInfoLen, rfalIsoDepDevice *isoDepDev ); - - -/*! - ***************************************************************************** - * \brief ISO-DEP Poller Handle S(Parameters) - * - * This checks if PICC supports S(PARAMETERS), retieves PICC's - * capabilities and sets the Bit Rate at the highest supported by both - * devices - * - * \param[out] isoDepDev : ISO-DEP information of the activated Listen device - * \param[in] maxTxBR : Maximum Tx bit rate supported by PCD - * \param[in] maxRxBR : Maximum Rx bit rate supported by PCD - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, S(PARAMETERS) selection successful - ***************************************************************************** - */ -ReturnCode rfalIsoDepPollHandleSParameters( rfalIsoDepDevice *isoDepDev, rfalBitRate maxTxBR, rfalBitRate maxRxBR ); - - -#endif /* RFAL_ISODEP_H_ */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_nfc.h b/Software/Middlewares/ST/rfal/Inc/rfal_nfc.h deleted file mode 100644 index e2cc059..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_nfc.h +++ /dev/null @@ -1,406 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfc.h - * - * \brief RFAL NFC device - * - * This module provides the required features to behave as an NFC Poller - * or Listener device. It grants an easy to use interface for the following - * activities: Technology Detection, Collision Resolution, Activation, - * Data Exchange, and Deactivation - * - * This layer is influenced by (but not fully aligned with) the NFC Forum - * specifications, in particular: Activity 2.0 and NCI 2.0 - * - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup RF - * \brief RFAL RF Abstraction Layer - * @{ - * - */ - -#ifndef RFAL_NFC_H -#define RFAL_NFC_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" -#include "rfal_nfca.h" -#include "rfal_nfcb.h" -#include "rfal_nfcf.h" -#include "rfal_nfcv.h" -#include "rfal_st25tb.h" -#include "rfal_nfcDep.h" -#include "rfal_isoDep.h" - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ -#define RFAL_NFC_RF_BUF_LEN 255U /*!< No technology */ - -#define RFAL_NFC_TECH_NONE 0x0000U /*!< No technology */ -#define RFAL_NFC_POLL_TECH_A 0x0001U /*!< NFC-A technology Flag */ -#define RFAL_NFC_POLL_TECH_B 0x0002U /*!< NFC-B technology Flag */ -#define RFAL_NFC_POLL_TECH_F 0x0004U /*!< NFC-F technology Flag */ -#define RFAL_NFC_POLL_TECH_V 0x0008U /*!< NFC-V technology Flag */ -#define RFAL_NFC_POLL_TECH_AP2P 0x0010U /*!< AP2P technology Flag */ -#define RFAL_NFC_POLL_TECH_ST25TB 0x0020U /*!< ST25TB technology Flag */ -#define RFAL_NFC_LISTEN_TECH_A 0x1000U /*!< NFC-V technology Flag */ -#define RFAL_NFC_LISTEN_TECH_B 0x2000U /*!< NFC-V technology Flag */ -#define RFAL_NFC_LISTEN_TECH_F 0x4000U /*!< NFC-V technology Flag */ -#define RFAL_NFC_LISTEN_TECH_AP2P 0x8000U /*!< NFC-V technology Flag */ - - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - -/*! Checks if a device is currently activated */ -#define rfalNfcIsDevActivated( st ) ( ((st)>= RFAL_NFC_STATE_ACTIVATED) && ((st)= RFAL_NFC_STATE_START_DISCOVERY) && ((st)= 1. - * - * \param[in] disParams : discovery configuration parameters - * - * \return ERR_WRONG_STATE : Incorrect state for this operation - * \return ERR_PARAM : Invalid parameters - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcDiscover( const rfalNfcDiscoverParam *disParams ); - -/*! - ***************************************************************************** - * \brief RFAL NFC Get State - * - * It returns the current state - * - * \return rfalNfcState : the current state - ***************************************************************************** - */ -rfalNfcState rfalNfcGetState( void ); - -/*! - ***************************************************************************** - * \brief RFAL NFC Get Devices Found - * - * It returns the location of the device list and the number of - * devices found. - * - * \param[out] devList : device list location - * \param[out] devCnt : number of devices found - * - * \return ERR_WRONG_STATE : Incorrect state for this operation - * Discovery still ongoing - * \return ERR_PARAM : Invalid parameters - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcGetDevicesFound( rfalNfcDevice **devList, uint8_t *devCnt ); - -/*! - ***************************************************************************** - * \brief RFAL NFC Get Active Device - * - * It returns the location of the device current Active device - * - * \param[out] dev : device info location - * - * \return ERR_WRONG_STATE : Incorrect state for this operation - * No device activated - * \return ERR_PARAM : Invalid parameters - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcGetActiveDevice( rfalNfcDevice **dev ); - -/*! - ***************************************************************************** - * \brief RFAL NFC Select Device - * - * It selects the device to be activated. - * It shall be called when more than one device has been identified to - * indiacte which device shall be actived - * - * \param[in] devIdx : device index to be activated - * - * \return ERR_WRONG_STATE : Incorrect state for this operation - * Not in select state - * \return ERR_PARAM : Invalid parameters - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcSelect( uint8_t devIdx ); - -/*! - ***************************************************************************** - * \brief RFAL NFC Start Data Exchange - * - * After a device has been activated, it starts a data exchange. - * It handles automatically which interface/protocol to be used and acts accordingly. - * - * In Listen mode the first frame/data shall be sent by the Reader/Initiator - * therefore this method must be called first with txDataLen set to zero - * to retrieve the rxData and rcvLen locations. - * - * - * \param[in] txData : data to be transmitted - * \param[in] txDataLen : size of the data to be transmitted - * \param[out] rxData : location of the received data after operation is completed - * \param[out] rvdLen : location of thelength of the received data - * \param[in] fwt : FWT to be used in case of RF interface. - * If ISO-DEP or NFC-DEP interface is used, this will be ignored - * - * \return ERR_WRONG_STATE : Incorrect state for this operation - * \return ERR_PARAM : Invalid parameters - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcDataExchangeStart( uint8_t *txData, uint16_t txDataLen, uint8_t **rxData, uint16_t **rvdLen, uint32_t fwt ); - -/*! - ***************************************************************************** - * \brief RFAL NFC Get Data Exchange Status - * - * Gets current Data Exchange status - * - * \return ERR_NONE : Transceive done with no error - * \return ERR_BUSY : Transceive ongoing - * \return ERR_AGAIN : received one chaining block, copy received data - * and continue to call this method to retrieve the - * remaining blocks - * \return ERR_XXXX : Error occurred - * \return ERR_TIMEOUT : No response - * \return ERR_FRAMING : Framing error detected - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_LINK_LOSS : Link Loss - External Field is Off - * \return ERR_RF_COLLISION : Collision detected - * \return ERR_IO : Internal error - ***************************************************************************** - */ -ReturnCode rfalNfcDataExchangeGetStatus( void ); - -/*! - ***************************************************************************** - * \brief RFAL NFC Deactivate - * - * It triggers the deactivation procedure to terminate communications with - * remote device. At the end the field will be turned off. - * - * \param[in] discovery : TRUE if after deactivation go back into discovery - * : FALSE if after deactivation remain in idle - * - * \return ERR_WRONG_STATE : Incorrect state for this operation - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcDeactivate( bool discovery ); - -#endif /* RFAL_NFC_H */ - - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_nfcDep.h b/Software/Middlewares/ST/rfal/Inc/rfal_nfcDep.h deleted file mode 100644 index 2d68353..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_nfcDep.h +++ /dev/null @@ -1,700 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfcDep.h - * - * \author Gustavo Patricio - * - * \brief Implementation of NFC-DEP protocol - * - * NFC-DEP is also known as NFCIP - Near Field Communication - * Interface and Protocol - * - * This implementation was based on the following specs: - * - NFC Forum Digital 1.1 - * - ECMA 340 3rd Edition 2013 - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup NFC-DEP - * \brief RFAL NFC-DEP Module - * @{ - */ - -#ifndef RFAL_NFCDEP_H_ -#define RFAL_NFCDEP_H_ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" - -/* - ****************************************************************************** - * DEFINES - ****************************************************************************** - */ -#define RFAL_NFCDEP_FRAME_SIZE_MAX_LEN 254U /*!< NFCIP Maximum Frame Size Digital 1.0 Table 91 */ -#define RFAL_NFCDEP_DEPREQ_HEADER_LEN 5U /*!< DEP_REQ header length: CMD_TYPE + CMD_CMD + PBF + DID + NAD */ - -/*! Length NFCIP DEP REQ or RES header (incl LEN) */ -#define RFAL_NFCDEP_DEP_HEADER ( RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN + RFAL_NFCDEP_DEP_PFB_LEN ) -#define RFAL_NFCDEP_HEADER ( RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN ) /*!< NFCIP header length */ -#define RFAL_NFCDEP_SB_LEN 1U /*!< SB length on NFCIP fram for NFC-A */ -#define RFAL_NFCDEP_LEN_LEN 1U /*!< LEN length on NFCIP frame */ -#define RFAL_NFCDEP_CMDTYPE_LEN 1U /*!< Length of the cmd type (REQ | RES) on NFCIP frame */ -#define RFAL_NFCDEP_CMD_LEN 1U /*!< Length of the cmd on NFCIP frame */ -#define RFAL_NFCDEP_DID_LEN 1U /*!< Length of did on NFCIP frame */ -#define RFAL_NFCDEP_DEP_PFB_LEN 1U /*!< Length of the PFB field on NFCIP frame */ - -#define RFAL_NFCDEP_DSL_RLS_LEN_NO_DID (RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN) /*!< Length of DSL_REQ and RLS_REQ with no DID */ -#define RFAL_NFCDEP_DSL_RLS_LEN_DID (RFAL_NFCDEP_DSL_RLS_LEN_NO_DID + RFAL_NFCDEP_DID_LEN) /*!< Length of DSL_REQ and RLS_REQ with DID */ - -#define RFAL_NFCDEP_FS_VAL_MIN 64U /*!< Minimum LR value */ -#define RFAL_NFCDEP_LR_VAL_MASK 0x03U /*!< Bit mask for a LR value */ -#define RFAL_NFCDEP_PP_LR_MASK 0x30U /*!< Bit mask for LR value in PP byte on a ATR REQ/RES */ -#define RFAL_NFCDEP_PP_LR_SHIFT 4U /*!< Position of LR value in PP byte on a ATR REQ/RES */ - -#define RFAL_NFCDEP_DID_MAX 14U /*!< Max DID value Digital 14.6.2.3 */ -#define RFAL_NFCDEP_DID_KEEP 0xFFU /*!< Keep DID value already configured */ -#define RFAL_NFCDEP_DID_NO 0x00U /*!< No DID shall be used */ -#define RFAL_NFCDEP_NAD_NO 0x00U /*!< No NAD shall be used */ - -#define RFAL_NFCDEP_OPER_RTOX_REQ_DIS 0x01U /*!< Operation config: RTOX REQ disable */ -#define RFAL_NFCDEP_OPER_RTOX_REQ_EN 0x00U /*!< Operation config: RTOX REQ enable */ - -#define RFAL_NFCDEP_OPER_ATN_DIS 0x00U /*!< Operation config: ATN disable */ -#define RFAL_NFCDEP_OPER_ATN_EN 0x02U /*!< Operation config: ATN enable */ - -#define RFAL_NFCDEP_OPER_EMPTY_DEP_DIS 0x04U /*!< Operation config: empty DEPs disable */ -#define RFAL_NFCDEP_OPER_EMPTY_DEP_EN 0x00U /*!< Operation config: empty DEPs enable */ - -#define RFAL_NFCDEP_OPER_FULL_MI_DIS 0x00U /*!< Operation config: full chaining DEPs disable */ -#define RFAL_NFCDEP_OPER_FULL_MI_EN 0x08U /*!< Operation config: full chaining DEPs enable */ - - -#define RFAL_NFCDEP_BRS_MAINTAIN 0xC0U /*!< Value signalling that BR is to be maintained (no PSL) */ -#define RFAL_NFCDEP_BRS_Dx_MASK 0x07U /*!< Value signalling that BR is to be maintained (no PSL) */ -#define RFAL_NFCDEP_BRS_DSI_POS 3U /*!< Value signalling that BR is to be maintained (no PSL) */ - -#define RFAL_NFCDEP_WT_DELTA (16U - RFAL_NFCDEP_WT_DELTA_ADJUST) /*!< NFC-DEP dWRT (adjusted) Digital 2.0 B.10 */ -#define RFAL_NFCDEP_WT_DELTA_ADJUST 4U /*!< dWRT value adjustment */ - - -#define RFAL_NFCDEP_ATR_REQ_NFCID3_POS 2U /*!< NFCID3 offset in ATR_REQ frame */ -#define RFAL_NFCDEP_NFCID3_LEN 10U /*!< NFCID3 Length */ - -#define RFAL_NFCDEP_LEN_MIN 3U /*!< Minimum length byte LEN value */ -#define RFAL_NFCDEP_LEN_MAX 255U /*!< Maximum length byte LEN value */ - -#define RFAL_NFCDEP_ATRRES_HEADER_LEN 2U /*!< ATR RES Header Len: CmdType: 0xD5 + Cod: 0x01 */ -#define RFAL_NFCDEP_ATRRES_MIN_LEN 17U /*!< Minimum length for an ATR RES */ -#define RFAL_NFCDEP_ATRRES_MAX_LEN 64U /*!< Maximum length for an ATR RES Digital 1.0 14.6.1 */ -#define RFAL_NFCDEP_ATRREQ_MIN_LEN 16U /*!< Minimum length for an ATR REQ */ -#define RFAL_NFCDEP_ATRREQ_MAX_LEN RFAL_NFCDEP_ATRRES_MAX_LEN /*!< Maximum length for an ATR REQ Digital 1.0 14.6.1 */ - -#define RFAL_NFCDEP_GB_MAX_LEN (RFAL_NFCDEP_ATRREQ_MAX_LEN - RFAL_NFCDEP_ATRREQ_MIN_LEN) /*!< Maximum length the General Bytes on ATR Digital 1.1 16.6.3 */ - -#define RFAL_NFCDEP_WT_INI_DEFAULT RFAL_NFCDEP_WT_INI_MAX /*!< WT Initiator default value Digital 1.0 14.6.3.8 */ -#define RFAL_NFCDEP_WT_INI_MIN 0U /*!< WT Initiator minimum value Digital 1.0 14.6.3.8 */ -#define RFAL_NFCDEP_WT_INI_MAX 14U /*!< WT Initiator maximum value Digital 1.0 14.6.3.8 A.10 */ -#define RFAL_NFCDEP_RWT_INI_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_INI_MAX ) /*!< RWT Initiator maximum value */ - -#define RFAL_NFCDEP_WT_TRG_MAX_D10 8U /*!< WT target max Digital 1.0 14.6.3.8 A.10 */ -#define RFAL_NFCDEP_WT_TRG_MAX_D11 14U /*!< WT target max Digital 1.1 16.6.3.9 A.9 */ -#define RFAL_NFCDEP_WT_TRG_MAX RFAL_NFCDEP_WT_TRG_MAX_D11 /*!< WT target max Digital x.x */ -#define RFAL_NFCDEP_RWT_TRG_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_TRG_MAX ) /*!< RWT Initiator maximum value */ - -/*! Maximum Frame Waiting Time = ((256 * 16/fc)*2^FWImax) = ((256*16/fc)*2^14) = (1048576 / 64)/fc = (100000h*64)/fc */ -#define RFAL_NFCDEP_MAX_FWT ((uint32_t)1U<<20) - -#define RFAL_NFCDEP_WT_MASK 0x0FU /*!< Bit mask for the Wait Time value */ - -#define RFAL_NFCDEP_BR_MASK_106 0x01U /*!< Enable mask bit rate 106 */ -#define RFAL_NFCDEP_BR_MASK_212 0x02U /*!< Enable mask bit rate 242 */ -#define RFAL_NFCDEP_BR_MASK_424 0x04U /*!< Enable mask bit rate 424 */ - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define rfalNfcDepWT2RWT( wt ) ( (uint32_t)1U << (((uint32_t)(wt) & RFAL_NFCDEP_WT_MASK) + 12U) ) /*!< Converts WT value to RWT (1/fc) */ - -/*! Returns the BRS value from the given bit rate */ -#define rfalNfcDepDx2BRS( br ) ( (((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) << RFAL_NFCDEP_BRS_DSI_POS) | ((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) ) - -#define rfalNfcDepBRS2DRI( brs ) (uint8_t)( (uint8_t)(brs) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DRI value from the given BRS byte */ -#define rfalNfcDepBRS2DSI( brs ) (uint8_t)( ((uint8_t)(brs) >> RFAL_NFCDEP_BRS_DSI_POS) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DSI value from the given BRS byte */ - -#define rfalNfcDepPP2LR( PPx ) ( ((uint8_t)(PPx) & RFAL_NFCDEP_PP_LR_MASK ) >> RFAL_NFCDEP_PP_LR_SHIFT) /*!< Returns the LR value from the given PPx byte */ -#define rfalNfcDepLR2PP( LRx ) ( ((uint8_t)(LRx) << RFAL_NFCDEP_PP_LR_SHIFT) & RFAL_NFCDEP_PP_LR_MASK) /*!< Returns the PP byte with the given LRx value */ - -/*! Returns the Frame size value from the given LRx value */ -#define rfalNfcDepLR2FS( LRx ) (uint16_t)(MIN( (RFAL_NFCDEP_FS_VAL_MIN * ((uint16_t)(LRx) + 1U) ), RFAL_NFCDEP_FRAME_SIZE_MAX_LEN )) - -/*! - * Despite DIGITAL 1.0 14.6.2.1 stating that the last two bytes may filled with - * any value, some devices (Samsung Google Nexus) only accept when these are 0 */ -#define rfalNfcDepSetNFCID( dst, src, len ) ST_MEMSET( (dst), 0x00, RFAL_NFCDEP_NFCID3_LEN ); \ - if( (len) > 0U ) {ST_MEMCPY( (dst), (src), (len) );} - -/* - ****************************************************************************** - * GLOBAL ENUMERATIONS - ****************************************************************************** - */ - -/*! Enumeration of NFC-DEP bit rate in ATR Digital 1.0 Table 93 and 94 */ -enum{ - RFAL_NFCDEP_Bx_NO_HIGH_BR = 0x00, /*!< Peer supports no high bit rates */ - RFAL_NFCDEP_Bx_08_848 = 0x01, /*!< Peer also supports 848 */ - RFAL_NFCDEP_Bx_16_1695 = 0x02, /*!< Peer also supports 1695 */ - RFAL_NFCDEP_Bx_32_3390 = 0x04, /*!< Peer also supports 3390 */ - RFAL_NFCDEP_Bx_64_6780 = 0x08 /*!< Peer also supports 6780 */ -}; - -/*! Enumeration of NFC-DEP bit rate Dividor in PSL Digital 1.0 Table 100 */ -enum{ - RFAL_NFCDEP_Dx_01_106 = RFAL_BR_106, /*!< Divisor D = 1 : bit rate = 106 */ - RFAL_NFCDEP_Dx_02_212 = RFAL_BR_212, /*!< Divisor D = 2 : bit rate = 212 */ - RFAL_NFCDEP_Dx_04_424 = RFAL_BR_424, /*!< Divisor D = 4 : bit rate = 424 */ - RFAL_NFCDEP_Dx_08_848 = RFAL_BR_848, /*!< Divisor D = 8 : bit rate = 848 */ - RFAL_NFCDEP_Dx_16_1695 = RFAL_BR_1695, /*!< Divisor D = 16 : bit rate = 1695 */ - RFAL_NFCDEP_Dx_32_3390 = RFAL_BR_3390, /*!< Divisor D = 32 : bit rate = 3390 */ - RFAL_NFCDEP_Dx_64_6780 = RFAL_BR_6780 /*!< Divisor D = 64 : bit rate = 6780 */ -}; - -/*! Enumeration of NFC-DEP Length Reduction (LR) Digital 1.0 Table 91 */ -enum{ - RFAL_NFCDEP_LR_64 = 0x00, /*!< Maximum payload size is 64 bytes */ - RFAL_NFCDEP_LR_128 = 0x01, /*!< Maximum payload size is 128 bytes */ - RFAL_NFCDEP_LR_192 = 0x02, /*!< Maximum payload size is 192 bytes */ - RFAL_NFCDEP_LR_254 = 0x03 /*!< Maximum payload size is 254 bytes */ -}; - -/* - ****************************************************************************** - * GLOBAL DATA TYPES - ****************************************************************************** - */ - -/*! NFC-DEP callback to check if upper layer has deactivation pending */ -typedef bool (* rfalNfcDepDeactCallback)(void); - - -/*! Enumeration of the nfcip communication modes */ -typedef enum{ - RFAL_NFCDEP_COMM_PASSIVE, /*!< Passive communication mode */ - RFAL_NFCDEP_COMM_ACTIVE /*!< Active communication mode */ -} rfalNfcDepCommMode; - - -/*! Enumeration of the nfcip roles */ -typedef enum{ - RFAL_NFCDEP_ROLE_INITIATOR, /*!< Perform as Initiator */ - RFAL_NFCDEP_ROLE_TARGET /*!< Perform as Target */ -} rfalNfcDepRole; - - -/*! Struct that holds all NFCIP configs */ -typedef struct{ - - rfalNfcDepRole role; /*!< Current NFCIP role */ - rfalNfcDepCommMode commMode; /*!< Current NFCIP communication mode */ - uint8_t oper; /*!< Operation config similar to NCI 1.0 Table 81 */ - - uint8_t did; /*!< Current Device ID (DID) */ - uint8_t nad; /*!< Current Node Addressing (NAD) */ - uint8_t bs; /*!< Bit rate in Sending Direction */ - uint8_t br; /*!< Bit rate in Receiving Direction */ - uint8_t nfcid[RFAL_NFCDEP_NFCID3_LEN]; /*!< Pointer to the NFCID to be used */ - uint8_t nfcidLen; /*!< Length of the given NFCID in nfcid */ - uint8_t gb[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Pointer General Bytes (GB) to be used */ - uint8_t gbLen; /*!< Length of the given GB in gb */ - uint8_t lr; /*!< Length Reduction (LR) to be used */ - uint8_t to; /*!< Timeout (TO) to be used */ - uint32_t fwt; /*!< Frame Waiting Time (FWT) to be used */ - uint32_t dFwt; /*!< Delta Frame Waiting Time (dFWT) to be used */ -} rfalNfcDepConfigs; - - -/*! ATR_REQ command Digital 1.1 16.6.2 */ -typedef struct { - uint8_t CMD1; /*!< Command format 0xD4 */ - uint8_t CMD2; /*!< Command Value */ - uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */ - uint8_t DID; /*!< DID */ - uint8_t BSi; /*!< Sending Bitrate for Initiator */ - uint8_t BRi; /*!< Receiving Bitrate for Initiator */ - uint8_t PPi; /*!< Optional Parameters presence indicator */ - uint8_t GBi[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */ -} rfalNfcDepAtrReq; - - -/*! ATR_RES response Digital 1.1 16.6.3 */ -typedef struct { - uint8_t CMD1; /*!< Response Byte 0xD5 */ - uint8_t CMD2; /*!< Command Value */ - uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */ - uint8_t DID; /*!< DID */ - uint8_t BSt; /*!< Sending Bitrate for Initiator */ - uint8_t BRt; /*!< Receiving Bitrate for Initiator */ - uint8_t TO; /*!< Timeout */ - uint8_t PPt; /*!< Optional Parameters presence indicator */ - uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */ -} rfalNfcDepAtrRes; - - -/*! Structure of transmit I-PDU Buffer format from caller */ -typedef struct -{ - uint8_t prologue[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /*!< Prologue space for NFC-DEP header*/ - uint8_t inf[RFAL_NFCDEP_FRAME_SIZE_MAX_LEN]; /*!< INF | Data area of the buffer */ -} rfalNfcDepBufFormat; - - -/*! Activation info as Initiator and Target */ -typedef union { /* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently , device is only initiatior or target a time. No problem can occur. */ - struct { - rfalNfcDepAtrRes ATR_RES; /*!< ATR RES (Initiator mode) */ - uint8_t ATR_RESLen; /*!< ATR RES length (Initiator mode) */ - }Target; /*!< Target */ - struct { - rfalNfcDepAtrReq ATR_REQ; /*!< ATR REQ (Target mode) */ - uint8_t ATR_REQLen; /*!< ATR REQ length (Target mode) */ - }Initiator; /*!< Initiator */ -} rfalNfcDepActivation; - - -/*! NFC-DEP device Info */ -typedef struct { - uint8_t GBLen; /*!< General Bytes length */ - uint8_t WT; /*!< WT to be used (ignored in Listen Mode) */ - uint32_t FWT; /*!< FWT to be used (1/fc)(ignored Listen Mode) */ - uint32_t dFWT; /*!< Delta FWT to be used (1/fc) */ - uint8_t LR; /*!< Length Reduction coding the max payload */ - uint16_t FS; /*!< Frame Size */ - rfalBitRate DSI; /*!< Bit Rate coding from Initiator to Target */ - rfalBitRate DRI; /*!< Bit Rate coding from Target to Initiator */ - uint8_t DID; /*!< Device ID (RFAL_NFCDEP_DID_NO if no DID) */ - uint8_t NAD; /*!< Node ADdress (RFAL_NFCDEP_NAD_NO if no NAD)*/ -} rfalNfcDepInfo; - - -/*! NFC-DEP Device structure */ -typedef struct { - rfalNfcDepActivation activation; /*!< Activation Info */ - rfalNfcDepInfo info; /*!< NFC-DEP device Info */ -} rfalNfcDepDevice; - - -/*! NFCIP Protocol structure for P2P Target - * - * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter - * NCI 1.1 Table 86: NFC-DEP Operation Parameter - * and it's a bit mask composed as: - * [ 0000b - * | Chain SHALL use max. Transport Data Byte[1b] - * | I-PDU with no Transport Data SHALL NOT be sent [1b] - * | NFC-DEP Target SHALL NOT send RTOX request [1b] - * ] - * - */ -typedef struct{ - rfalNfcDepCommMode commMode; /*!< Initiator in Active P2P or Passive P2P*/ - uint8_t operParam; /*!< NFC-DEP Operation Parameter */ - uint8_t* nfcid; /*!< Initiator's NFCID2 or NFCID3 */ - uint8_t nfcidLen; /*!< Initiator's NFCID length (NFCID2/3) */ - uint8_t DID; /*!< Initiator's Device ID DID */ - uint8_t NAD; /*!< Initiator's Node ID NAD */ - uint8_t BS; /*!< Initiator's Bit Rates supported in Tx */ - uint8_t BR; /*!< Initiator's Bit Rates supported in Rx */ - uint8_t LR; /*!< Initiator's Length reduction */ - uint8_t* GB; /*!< Initiator's General Bytes (Gi) */ - uint8_t GBLen; /*!< Initiator's General Bytes length */ -} rfalNfcDepAtrParam; - - -/*! Structure of parameters to be passed in for nfcDepListenStartActivation */ -typedef struct -{ - rfalNfcDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */ - uint16_t *rxLen; /*!< Receive INF data length in bytes */ - bool *isRxChaining; /*!< Received data is not complete */ - rfalNfcDepDevice *nfcDepDev; /*!< NFC-DEP device info */ -} rfalNfcDepListenActvParam; - - -/*! NFCIP Protocol structure for P2P Target - * - * operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter - * NCI 1.1 Table 86: NFC-DEP Operation Parameter - * and it's a bit mask composed as: - * [ 0000b - * | Chain SHALL use max. Transport Data Byte[1b] - * | I-PDU with no Transport Data SHALL NOT be sent [1b] - * | NFC-DEP Target SHALL NOT send RTOX request [1b] - * ] - * - */ -typedef struct{ - rfalNfcDepCommMode commMode; /*!< Target in Active P2P or Passive P2P */ - uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< Target's NFCID3 */ - uint8_t bst; /*!< Target's Bit Rates supported in Tx */ - uint8_t brt; /*!< Target's Bit Rates supported in Rx */ - uint8_t to; /*!< Target's timeout (TO) value */ - uint8_t ppt; /*!< Target's Presence optional Params(PPt)*/ - uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Target's General Bytes (Gt) */ - uint8_t GBtLen; /*!< Target's General Bytes length */ - uint8_t operParam; /*!< NFC-DEP Operation Parameter */ -} rfalNfcDepTargetParam; - - -/*! Structure of parameters to be passed in for nfcDepStartIpduTransceive */ -typedef struct -{ - rfalNfcDepBufFormat *txBuf; /*!< Transmit Buffer struct reference */ - uint16_t txBufLen; /*!< Transmit Buffer INF field length in bytes */ - bool isTxChaining; /*!< Transmit data is not complete */ - rfalNfcDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */ - uint16_t *rxLen; /*!< Receive INF data length */ - bool *isRxChaining; /*!< Received data is not complete */ - uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */ - uint32_t dFWT; /*!< Delta FWT to be used */ - uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */ - uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */ -} rfalNfcDepTxRxParam; - - -/* - * ***************************************************************************** - * GLOBAL VARIABLE DECLARATIONS - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -/*! - ****************************************************************************** - * \brief NFCIP Initialize - * - * This method resets all NFC-DEP inner states, counters and context and sets - * default values - * - ****************************************************************************** - */ -void rfalNfcDepInitialize( void ); - - -/*! - ****************************************************************************** - * \brief Set deactivating callback - * - * Sets the deactivating callback so that nfcip layer can check if upper layer - * has a deactivation pending, and not perform error recovery upon specific - * errors - * - * \param[in] pFunc : method pointer to deactivation flag check - ****************************************************************************** - */ -void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc ); - - -/*! - ****************************************************************************** - * \brief Calculate Response Waiting Time - * - * Calculates the Response Waiting Time (RWT) from the given Waiting Time (WT) - * - * \param[in] wt : the WT value to calculate RWT - * - * \return RWT value in 1/fc - ****************************************************************************** - */ -uint32_t rfalNfcDepCalculateRWT( uint8_t wt ); - - -/*! - ****************************************************************************** - * \brief NFC-DEP Initiator ATR (Attribute Request) - * - * This method configures the NFC-DEP layer with given parameters and then - * sends an ATR to the Target with and checks for a valid response response - * - * \param[in] param : parameters to initialize and compose the ATR - * \param[out] atrRes : location to store the ATR_RES - * \param[out] atrResLen : length of the ATR_RES received - * - * \return ERR_NONE : No error - * \return ERR_TIMEOUT : Timeout occurred - * \return ERR_PROTO : Protocol error occurred - ****************************************************************************** - */ -ReturnCode rfalNfcDepATR( const rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atrRes, uint8_t* atrResLen ); - - -/*! - ****************************************************************************** - * \brief NFC-DEP Initiator PSL (Parameter Selection) - * - * This method sends a PSL to the Target with the given parameters and checks - * for a valid response response - * - * The parameters must be coded according to Digital 1.1 16.7.1 - * - * \param[in] BRS : the selected Bit Rates for Initiator and Target - * \param[in] FSL : the maximum length of Commands and Responses - * - * \return ERR_NONE : No error - * \return ERR_TIMEOUT : Timeout occurred - * \return ERR_PROTO : Protocol error occurred - ****************************************************************************** - */ -ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL ); - - -/*! - ****************************************************************************** - * \brief NFC-DEP Initiator DSL (Deselect) - * - * This method checks if the NFCIP module is configured as initiator and if - * so sends a DSL REQ, waits the target's response and checks it - * - * In case of performing as target no action is taken - * - * \return ERR_NONE : No error - * \return ERR_TIMEOUT : Timeout occurred - * \return ERR_MAX_RERUNS : Timeout occurred - * \return ERR_PROTO : Protocol error occurred - ****************************************************************************** - */ -ReturnCode rfalNfcDepDSL( void ); - - -/*! - ****************************************************************************** - * \brief NFC-DEP Initiator RLS (Release) - * - * This method checks if the NFCIP module is configured as initiator and if - * so sends a RLS REQ, waits target's response and checks it - * - * In case of performing as target no action is taken - * - * \return ERR_NONE : No error - * \return ERR_TIMEOUT : Timeout occurred - * \return ERR_MAX_RERUNS : Timeout occurred - * \return ERR_PROTO : Protocol error occurred - ****************************************************************************** - */ -ReturnCode rfalNfcDepRLS( void ); - - -/*! - ***************************************************************************** - * \brief NFC-DEP Initiator Handle Activation - * - * This performs a Activation into NFC-DEP layer with the given - * parameters. It sends ATR_REQ and if the higher bit rates are supported by - * both devices it additionally sends PSL - * Once Activated all details of the device are provided on nfcDepDev - * - * \param[in] param : required parameters to initialize and send ATR_REQ - * \param[in] desiredBR : Desired bit rate supported by the Poller - * \param[out] nfcDepDev : NFC-DEP information of the activated Listen device - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, activation successful - ***************************************************************************** - */ -ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalBitRate desiredBR, rfalNfcDepDevice* nfcDepDev ); - - -/*! - ****************************************************************************** - * \brief Check if buffer contains valid ATR_REQ - * - * This method checks if the given ATR_REQ is valid - * - * - * \param[in] buf : buffer holding Initiator's received request - * \param[in] bufLen : size of the msg contained on the buf in Bytes - * \param[out] nfcid3 : pointer to where the NFCID3 may be outputed, - * nfcid3 has NFCF_SENSF_NFCID3_LEN as length - * Pass NULL if output parameter not desired - * - * \return true : Valid ATR_REQ received, the ATR_RES has been computed in txBuf - * \return false : Invalid protocol request - * - ****************************************************************************** - */ -bool rfalNfcDepIsAtrReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 ); - - -/*! - ****************************************************************************** - * \brief Check is Target has received ATR - * - * This method checks if the NFCIP module is configured as target and if a - * ATR REQ has been received ( whether is in activation or in data exchange) - * - * \return true : a ATR has already been received - * \return false : no ATR has been received - ****************************************************************************** - */ -bool rfalNfcDepTargetRcvdATR( void ); - -/*! - ***************************************************************************** - * \brief NFCDEP Start Listen Activation Handling - * - * Start Activation Handling and setup to receive first frame which may - * contain complete or partial DEP-REQ after activation is completed - * - * Pass in ATR_REQ for NFC-DEP to handle ATR_RES. The Activation Handling - * handles ATR_RES and PSL_RES if a PSL_REQ is received - * - * Activation is completed if PSL_RES is sent or if first I-PDU is received - * - * \ref rfalNfcDepListenGetActivationStatus() provide status of the - * ongoing activation - * - * \warning nfcDepGetTransceiveStatus() shall be called right after activation - * is completed (i.e. rfalNfcDepListenGetActivationStatus() return ERR_NONE) - * to check for first received frame. - * - * \param[in] param : Target parameters to be used - * \param[in] atrReq : reference to buffer containing ATR_REQ - * \param[in] atrReqLength: Length of ATR_REQ - * \param[out] rxParam : references to buffer, length and chaining indication - * for first complete LLCP to be received - * - * \return ERR_NONE : ATR_REQ is valid and activation ongoing - * \return ERR_PARAM : ATR_REQ or other params are invalid - * \return ERR_LINK_LOSS : Remote Field is turned off - ***************************************************************************** - */ -ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, const uint8_t *atrReq, uint16_t atrReqLength, rfalNfcDepListenActvParam rxParam ); - - -/*! - ***************************************************************************** - * \brief Get the current NFC-DEP Activation Status - * - * \return ERR_NONE : Activation has completed successfully - * \return ERR_BUSY : Activation is ongoing - * \return ERR_LINK_LOSS : Remote Field was turned off - ***************************************************************************** - */ -ReturnCode rfalNfcDepListenGetActivationStatus( void ); - -/*! - ***************************************************************************** - * \brief Start Transceive - * - * Transceives a complete or partial DEP block - * - * The txBuf contains complete or partial of DEP to be transmitted. - * The Prologue field of the I-PDU is handled internally - * - * If the buffer contains partial LLCP and is not the last block, then - * isTxChaining must be set to true - * - * \param[in] param: reference parameters to be used for the Transceive - * - * \return ERR_PARAM : Bad request - * \return ERR_WRONG_STATE : The module is not in a proper state - * \return ERR_NONE : The Transceive request has been started - ***************************************************************************** - */ -ReturnCode rfalNfcDepStartTransceive( rfalNfcDepTxRxParam *param ); - - -/*! - ***************************************************************************** - * \brief Return the Transceive status - * - * Returns the status of the NFC-DEP Transceive - * - * \warning When the other device is performing chaining once a chained - * block is received the error ERR_AGAIN is sent. At this point - * caller must handle the received data immediately. - * When ERR_AGAIN is returned an ACK has already been sent to - * the other device and the next block might be incoming. - * If rfalWorker() is called frequently it will place the next - * block on the given buffer - * - * \return ERR_NONE : Transceive has been completed successfully - * \return ERR_BUSY : Transceive is ongoing - * \return ERR_PROTO : Protocol error occurred - * \return ERR_TIMEOUT : Timeout error occurred - * \return ERR_SLEEP_REQ : Deselect has been received and responded - * \return ERR_NOMEM : The received I-PDU does not fit into the - * receive buffer - * \return ERR_LINK_LOSS : Communication is lost because Reader/Writer - * has turned off its field - * \return ERR_AGAIN : received one chaining block, continue to call - * this method to retrieve the remaining blocks - ***************************************************************************** - */ -ReturnCode rfalNfcDepGetTransceiveStatus( void ); - - -#endif /* RFAL_NFCDEP_H_ */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_nfca.h b/Software/Middlewares/ST/rfal/Inc/rfal_nfca.h deleted file mode 100644 index d834fce..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_nfca.h +++ /dev/null @@ -1,391 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfca.h - * - * \author Gustavo Patricio - * - * \brief Provides several NFC-A convenience methods and definitions - * - * It provides a Poller (ISO14443A PCD) interface and as well as - * some NFC-A Listener (ISO14443A PICC) helpers. - * - * The definitions and helpers methods provided by this module are only - * up to ISO14443-3 layer - * - * - * An usage example is provided here: \ref exampleRfalNfca.c - * \example exampleRfalNfca.c - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup NFC-A - * \brief RFAL NFC-A Module - * @{ - * - */ - - -#ifndef RFAL_NFCA_H -#define RFAL_NFCA_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" -#include "rfal_t1t.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_NFCA_CASCADE_1_UID_LEN 4U /*!< UID length of cascade level 1 only tag */ -#define RFAL_NFCA_CASCADE_2_UID_LEN 7U /*!< UID length of cascade level 2 only tag */ -#define RFAL_NFCA_CASCADE_3_UID_LEN 10U /*!< UID length of cascade level 3 only tag */ - -#define RFAL_NFCA_SENS_RES_PLATFORM_MASK 0x0FU /*!< SENS_RES (ATQA) platform configuration mask Digital 1.1 Table 10 */ -#define RFAL_NFCA_SENS_RES_PLATFORM_T1T 0x0CU /*!< SENS_RES (ATQA) T1T platform configuration Digital 1.1 Table 10 */ - -#define RFAL_NFCA_SEL_RES_CONF_MASK 0x60U /*!< SEL_RES (SAK) platform configuration mask Digital 1.1 Table 19 */ -#define RFAL_NFCA_SEL_RES_CONF_T2T 0x00U /*!< SEL_RES (SAK) T2T configuration Digital 1.1 Table 19 */ -#define RFAL_NFCA_SEL_RES_CONF_T4T 0x20U /*!< SEL_RES (SAK) T4T configuration Digital 1.1 Table 19 */ -#define RFAL_NFCA_SEL_RES_CONF_NFCDEP 0x40U /*!< SEL_RES (SAK) NFC-DEP configuration Digital 1.1 Table 19 */ -#define RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP 0x60U /*!< SEL_RES (SAK) T4T and NFC-DEP configuration Digital 1.1 Table 19 */ - - -/*! NFC-A minimum FDT(listen) = ((n * 128 + (84)) / fc) with n_min = 9 Digital 1.1 6.10.1 - * = (1236)/fc - * Relax with 3etu: (3*128)/fc as with multiple NFC-A cards, response may take longer (JCOP cards) - * = (1236 + 384)/fc = 1620 / fc */ -#define RFAL_NFCA_FDTMIN 1620U -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -/*! Checks if device is a T1T given its SENS_RES */ -#define rfalNfcaIsSensResT1T( sensRes ) ((((rfalNfcaSensRes*)(sensRes))->platformInfo & RFAL_NFCA_SENS_RES_PLATFORM_MASK) == RFAL_NFCA_SENS_RES_PLATFORM_T1T ) - -/*! Checks if device is a T2T given its SENS_RES */ -#define rfalNfcaIsSelResT2T( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T2T ) - -/*! Checks if device is a T4T given its SENS_RES */ -#define rfalNfcaIsSelResT4T( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T ) - -/*! Checks if device supports NFC-DEP protocol given its SENS_RES */ -#define rfalNfcaIsSelResNFCDEP( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_NFCDEP ) - -/*! Checks if device supports ISO-DEP and NFC-DEP protocol given its SENS_RES */ -#define rfalNfcaIsSelResT4TNFCDEP( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP ) - -/*! Checks if a NFC-A listener device supports multiple protocols (ISO-DEP and NFC-DEP) */ -#define rfalNfcaLisDevIsMultiProto( lisDev ) (((rfalNfcaListenDevice*)(lisDev))->type == RFAL_NFCA_T4T_NFCDEP ) - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! NFC-A Listen device types */ -typedef enum { - RFAL_NFCA_T1T = 0x01, /* Device configured for T1T Digital 1.1 Table 9 */ - RFAL_NFCA_T2T = 0x00, /* Device configured for T2T Digital 1.1 Table 19 */ - RFAL_NFCA_T4T = 0x20, /* Device configured for T4T Digital 1.1 Table 19 */ - RFAL_NFCA_NFCDEP = 0x40, /* Device configured for NFC-DEP Digital 1.1 Table 19 */ - RFAL_NFCA_T4T_NFCDEP = 0x60 /* Device configured for NFC-DEP and T4T Digital 1.1 Table 19 */ -} rfalNfcaListenDeviceType; - - -/*! SENS_RES (ATQA) format Digital 1.1 6.6.3 & Table 7 */ -typedef struct -{ - uint8_t anticollisionInfo; /*!< SENS_RES Anticollision Information */ - uint8_t platformInfo; /*!< SENS_RES Platform Information */ -} rfalNfcaSensRes; - - -/*! SDD_REQ (Anticollision) format Digital 1.1 6.7.1 & Table 11 */ -typedef struct -{ - uint8_t selCmd; /*!< SDD_REQ SEL_CMD: cascade Level */ - uint8_t selPar; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/ -} rfalNfcaSddReq; - - -/*! SDD_RES (UID CLn) format Digital 1.1 6.7.2 & Table 15 */ -typedef struct -{ - uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 cascade level NFCID */ - uint8_t bcc; /*!< BCC Exclusive-OR over first 4 bytes of SDD_RES */ -} rfalNfcaSddRes; - - -/*! SEL_REQ (Select) format Digital 1.1 6.8.1 & Table 17 */ -typedef struct -{ - uint8_t selCmd; /*!< SDD_REQ SEL_CMD: cascade Level */ - uint8_t selPar; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/ - uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 data */ - uint8_t bcc; /*!< Checksum calculated as exclusive-OR over the 4 bytes of NFCID1 CLn */ -} rfalNfcaSelReq; - - -/*! SEL_RES (SAK) format Digital 1.1 6.8.2 & Table 19 */ -typedef struct -{ - uint8_t sak; /*!< Select Acknowledge */ -} rfalNfcaSelRes; - - -/*! NFC-A listener device (PICC) struct */ -typedef struct -{ - rfalNfcaListenDeviceType type; /*!< NFC-A Listen device type */ - rfalNfcaSensRes sensRes; /*!< SENS_RES (ATQA) */ - rfalNfcaSelRes selRes; /*!< SEL_RES (SAK) */ - uint8_t nfcId1Len; /*!< NFCID1 Length */ - uint8_t nfcId1[RFAL_NFCA_CASCADE_3_UID_LEN]; /*!< NFCID1 (UID) */ -#ifdef RFAL_FEATURE_T1T - rfalT1TRidRes ridRes; /*!< RID_RES */ -#endif /* RFAL_FEATURE_T1T */ - bool isSleep; /*!< Device sleeping flag */ -} rfalNfcaListenDevice; - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief Initialize NFC-A Poller mode - * - * This methods configures RFAL RF layer to perform as a - * NFC-A Poller/RW (ISO14443A PCD) including all default timings and bit rate - * to 106 kbps - - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcaPollerInitialize( void ); - - -/*! - ***************************************************************************** - * \brief NFC-A Poller Check Presence - * - * This method checks if a NFC-A Listen device (PICC) is present on the field - * by sending an ALL_REQ (WUPA) or SENS_REQ (REQA) - * - * \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ - * \param[out] sensRes : If received, the SENS_RES - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_RF_COLLISION : Collision detected one or more device in the field - * \return ERR_PAR : Parity error detected, one or more device in the field - * \return ERR_CRC : CRC error detected, one or more device in the field - * \return ERR_FRAMING : Framing error detected, one or more device in the field - * \return ERR_PROTO : Protocol error detected, one or more device in the field - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_NONE : No error, one or more device in the field - ***************************************************************************** - */ -ReturnCode rfalNfcaPollerCheckPresence( rfal14443AShortFrameCmd cmd, rfalNfcaSensRes *sensRes ); - - -/*! - ***************************************************************************** - * \brief NFC-A Poller Select - * - * This method selects a NFC-A Listener device (PICC) - * - * \param[in] nfcid1 : Listener device NFCID1 to be selected - * \param[in] nfcidLen : Length of the NFCID1 to be selected - * \param[out] selRes : pointer to place the SEL_RES - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, SEL_RES received - ***************************************************************************** - */ -ReturnCode rfalNfcaPollerSelect( const uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes ); - - -/*! - ***************************************************************************** - * \brief NFC-A Poller Sleep - * - * This method sends a SLP_REQ (HLTA) - * No response is expected afterwards Digital 1.1 6.9.2.1 - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcaPollerSleep( void ); - - -/*! - ***************************************************************************** - * \brief NFC-A Technology Detection - * - * This method performs NFC-A Technology Detection as defined in the spec - * given in the compliance mode - * - * \param[in] compMode : compliance mode to be performed - * \param[out] sensRes : location to store the SENS_RES, if received - * - * When compMode is set to ISO compliance a SLP_REQ (HLTA) is not sent - * after detection. When set to EMV a ALL_REQ (WUPA) is sent instead of - * a SENS_REQ (REQA) - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_NONE : No error, one or more device in the field - ***************************************************************************** - */ -ReturnCode rfalNfcaPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes ); - - -/*! - ***************************************************************************** - * \brief NFC-A Poller Collision Resolution - * - * Collision resolution for one NFC-A Listener device/card (PICC) as - * defined in Activity 1.1 9.3.4 - * - * This method executes anti collision loop and select the device with higher NFCID1 - * - * When devLimit = 0 it is configured to perform collision detection only. Once a collision - * is detected the collision resolution is aborted immidiatly. If only one device is found - * with no collisions, it will properly resolved. - * - * \param[in] devLimit : device limit value (CON_DEVICES_LIMIT) - * \param[out] collPending : pointer to collision pending flag (INT_COLL_PEND) - * \param[out] selRes : location to store the last Select Response from listener device (PICC) - * \param[out] nfcId1 : location to store the NFCID1 (UID), ensure RFAL_NFCA_CASCADE_3_UID_LEN - * \param[out] nfcId1Len : pointer to length of NFCID1 (UID) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_PROTO : Card length invalid - * \return ERR_IGNORE : conDevLimit is 0 and there is a collision - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcaPollerSingleCollisionResolution( uint8_t devLimit, bool *collPending, rfalNfcaSelRes *selRes, uint8_t *nfcId1, uint8_t *nfcId1Len ); - - -/*! - ***************************************************************************** - * \brief NFC-A Poller Full Collision Resolution - * - * Performs a full Collision resolution as defined in Activity 1.0 or 1.1 9.3.4 - * - * \param[in] compMode : compliance mode to be performed - * \param[in] devLimit : device limit value, and size nfcaDevList - * \param[out] nfcaDevList : NFC-A listener device info - * \param[out] devCnt : Devices found counter - * - * When compMode is set to ISO compliance it assumes that the device is - * not sleeping and therefore no ALL_REQ (WUPA) is sent at the beginning. - * - * When compMode is set to NFC compliance an additional ALL_REQ (WUPA) is sent at - * the beginning and a proprietary behaviour also takes place. Once a device has been - * resolved an additional SLP_REQ (HLTA) is sent regardless if there was a collision - * (except if the number of devices found already equals the limit). - * This proprietary behaviour ensures proper activation of certain devices that suffer - * from influence of Type B commands as foreseen in ISO14443-3 5.2.3 - * - * - * When devLimit = 0 it is configured to perform collision detection only. Once a collision - * is detected the collision resolution is aborted immidiatly. If only one device is found - * with no collisions, it will properly resolved. - * - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcaPollerFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt ); - - -/*! - ***************************************************************************** - * \brief NFC-A Listener is SLP_REQ - * - * Checks if the given buffer contains valid NFC-A SLP_REQ (HALT) - * - * \param[in] buf: buffer containing data - * \param[in] bufLen: length of the data in buffer to be checked - * - * \return true if data in buf contains a SLP_REQ ; false otherwise - ***************************************************************************** - */ -bool rfalNfcaListenerIsSleepReq( const uint8_t *buf, uint16_t bufLen ); - -#endif /* RFAL_NFCA_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_nfcb.h b/Software/Middlewares/ST/rfal/Inc/rfal_nfcb.h deleted file mode 100644 index ea4cab0..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_nfcb.h +++ /dev/null @@ -1,398 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfcb.h - * - * \author Gustavo Patricio - * - * \brief Implementation of NFC-B (ISO14443B) helpers - * - * It provides a NFC-B Poller (ISO14443B PCD) interface and - * also provides some NFC-B Listener (ISO14443B PICC) helpers - * - * The definitions and helpers methods provided by this module are only - * up to ISO14443-3 layer (excluding ATTRIB) - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup NFC-B - * \brief RFAL NFC-B Module - * @{ - * - */ - - -#ifndef RFAL_NFCB_H -#define RFAL_NFCB_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_NFCB_FWTSENSB 7680U /*!< NFC-B FWT(SENSB) Digital 2.0 B.3 */ -#define RFAL_NFCB_DFWT 49152U /*!< NFC-B dFWT Delta 2.0 7.9.1.3 & B.3 */ -#define RFAL_NFCB_DTPOLL_10 rfalConvMsTo1fc(20) /*!< NFC-B Delta Tb Poll Digital 1.0 A.2 */ -#define RFAL_NFCB_DTPOLL_20 rfalConvMsTo1fc(17) /*!< NFC-B Delta Tb Poll Digital 2.1 B.3 */ - -#define RFAL_NFCB_AFI 0x00U /*!< NFC-B default Application Family Digital 1.1 7.6.1.1 */ -#define RFAL_NFCB_PARAM 0x00U /*!< NFC-B default SENSB_REQ PARAM */ -#define RFAL_NFCB_CRC_LEN 2U /*!< NFC-B CRC length and CRC_B(AID) Digital 1.1 Table 28 */ -#define RFAL_NFCB_NFCID0_LEN 4U /*!< Length of NFC-B NFCID0 */ -#define RFAL_NFCB_CMD_LEN 1U /*!< Length of NFC-B Command */ - -#define RFAL_NFCB_SENSB_RES_LEN 12U /*!< Standard length of SENSB_RES without SFGI byte */ -#define RFAL_NFCB_SENSB_RES_EXT_LEN 13U /*!< Extended length of SENSB_RES with SFGI byte */ - -#define RFAL_NFCB_SENSB_REQ_ADV_FEATURE 0x20U /*!< Bit mask for Advance Feature in SENSB_REQ */ -#define RFAL_NFCB_SENSB_RES_FSCI_MASK 0x0FU /*!< Bit mask for FSCI value in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_FSCI_SHIFT 4U /*!< Shift for FSCI value in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_PROTO_RFU_MASK 0x08U /*!< Bit mask for Protocol Type RFU in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK 0x03U /*!< Bit mask for Protocol Type TR2 in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_PROTO_TR2_SHIFT 1U /*!< Shift for Protocol Type TR2 in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK 0x01U /*!< Bit mask Protocol Type ISO14443 Compliant in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_FWI_MASK 0x0FU /*!< Bit mask for FWI value in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_FWI_SHIFT 4U /*!< Bit mask for FWI value in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_ADC_MASK 0x0CU /*!< Bit mask for ADC value in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_ADC_ADV_FEATURE_MASK 0x08U /*!< Bit mask for ADC.Advanced Proto Features in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_ADC_PROPRIETARY_MASK 0x04U /*!< Bit mask for ADC.Proprietary Application in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_FO_DID_MASK 0x01U /*!< Bit mask for DID in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_FO_NAD_MASK 0x02U /*!< Bit mask for DID in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_FO_MASK 0x03U /*!< Bit mask for FO value in SENSB_RES (NAD and DID) */ -#define RFAL_NFCB_SENSB_RES_SFGI_MASK 0x0FU /*!< Bit mask for SFGI in SENSB_RES */ -#define RFAL_NFCB_SENSB_RES_SFGI_SHIFT 4U /*!< Shift for SFGI in SENSB_RES */ - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - -/*! Get device's FSCI given its SENSB_RES Digital 1.1 7.6.2 */ -#define rfalNfcbGetFSCI( sensbRes ) ((((rfalNfcbSensbRes*)(sensbRes))->protInfo.FsciProType >> RFAL_NFCB_SENSB_RES_FSCI_SHIFT) & RFAL_NFCB_SENSB_RES_FSCI_MASK ) - -/*! Checks if the given NFC-B device indicates ISO-DEP support */ -#define rfalNfcbIsIsoDepSupported( dev ) ( (((rfalNfcbListenDevice*)(dev))->sensbRes.protInfo.FsciProType & RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK) != 0U ) - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! SENSB_REQ and ALLB_REQ param Digital 1.1 7.6.1 */ -typedef enum -{ - RFAL_NFCB_SENS_CMD_ALLB_REQ = 0x08, /*!< ALLB_REQ (WUPB) */ - RFAL_NFCB_SENS_CMD_SENSB_REQ = 0x00 /*!< SENSB_REQ (REQB) */ -} rfalNfcbSensCmd; - - -/*! Number of Slots (NI) codes used for NFC-B anti collision Digital 1.1 Table 26 */ -typedef enum -{ - RFAL_NFCB_SLOT_NUM_1 = 0, /*!< N=0 : 1 slot */ - RFAL_NFCB_SLOT_NUM_2 = 1, /*!< N=1 : 2 slots */ - RFAL_NFCB_SLOT_NUM_4 = 2, /*!< N=2 : 4 slots */ - RFAL_NFCB_SLOT_NUM_8 = 3, /*!< N=3 : 8 slots */ - RFAL_NFCB_SLOT_NUM_16 = 4 /*!< N=4 : 16 slots */ -}rfalNfcbSlots; - - -/*! SENSB_RES (ATQB) Application Data Format Digital 1.1 Table 28 */ -typedef struct -{ - uint8_t AFI; /*!< Application Family Identifier */ - uint8_t CRC_B[RFAL_NFCB_CRC_LEN]; /*!< CRC_B of AID */ - uint8_t numApps; /*!< Number of Applications */ -} rfalNfcbSensbResAppData; - - -/*! SENSB_RES Protocol Info format Digital 1.1 Table 29 */ -typedef struct -{ - uint8_t BRC; /*!< Bit Rate Capability */ - uint8_t FsciProType; /*!< Frame Size Card Integer [4b] | Protocol Type[4 bits] */ - uint8_t FwiAdcFo; /*!< Frame Waiting Integer [4b] | Application Data Coding [2b] | Frame Options [2b] */ - uint8_t SFGI; /*!< Optional: Start-Up Frame Guard Time Integer[4b] | RFU [4b] */ -} rfalNfcbSensbResProtocolInfo; - - -/*! SENSB_RES format Digital 1.1 7.6.2 */ -typedef struct -{ - uint8_t cmd; /*!< SENSB_RES: 50h */ - uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFC Identifier (PUPI)*/ - rfalNfcbSensbResAppData appData; /*!< Application Data */ - rfalNfcbSensbResProtocolInfo protInfo; /*!< Protocol Information */ -} rfalNfcbSensbRes; - - -/*! NFC-B listener device (PICC) struct */ -typedef struct -{ - uint8_t sensbResLen; /*!< SENSB_RES length */ - rfalNfcbSensbRes sensbRes; /*!< SENSB_RES */ - bool isSleep; /*!< Device sleeping flag */ -}rfalNfcbListenDevice; - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief Initialize NFC-B Poller mode - * - * This methods configures RFAL RF layer to perform as a - * NFC-B Poller/RW (ISO14443B PCD) including all default timings - * - * It sets NFC-B parameters (AFI, PARAM) to default values - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcbPollerInitialize( void ); - - -/*! - ***************************************************************************** - * \brief Set NFC-B Poller parameters - * - * This methods configures RFAL RF layer to perform as a - * NFCA Poller/RW (ISO14443A PCD) including all default timings - * - * Additionally configures NFC-B specific parameters to be used on the - * following communications - * - * \param[in] AFI : Application Family Identifier to be used - * \param[in] PARAM : PARAM to be used, it announces whether Advanced - * Features or Extended SENSB_RES is supported - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcbPollerInitializeWithParams( uint8_t AFI, uint8_t PARAM ); - - -/*! - ***************************************************************************** - * \brief NFC-B Poller Check Presence - * - * This method checks if a NFC-B Listen device (PICC) is present on the field - * by sending an ALLB_REQ (WUPB) or SENSB_REQ (REQB) - * - * \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ - * \param[in] slots : The number of slots to be announced - * \param[out] sensbRes : If received, the SENSB_RES - * \param[out] sensbResLen : If received, the SENSB_RES length - * - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_RF_COLLISION : Collision detected one or more device in the field - * \return ERR_PAR : Parity error detected, one or more device in the field - * \return ERR_CRC : CRC error detected, one or more device in the field - * \return ERR_FRAMING : Framing error detected, one or more device in the field - * \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received - * \return ERR_NONE : No error, SENSB_RES received - ***************************************************************************** - */ -ReturnCode rfalNfcbPollerCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen ); - - -/*! - ***************************************************************************** - * \brief NFC-B Poller Sleep - * - * This function is used to send the SLPB_REQ (HLTB) command to put the PICC with - * the given NFCID0 to state HALT so that they do not reply to further SENSB_REQ - * commands (only to ALLB_REQ) - * - * \param[in] nfcid0 : NFCID of the device to be put to Sleep - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcbPollerSleep( const uint8_t* nfcid0 ); - - -/*! - ***************************************************************************** - * \brief NFC-B Poller Slot Marker - * - * This method selects a NFC-B Slot marker frame - * - * \param[in] slotCode : Slot Code [1-15] - * \param[out] sensbRes : If received, the SENSB_RES - * \param[out] sensbResLen : If received, the SENSB_RES length - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error, SEL_RES received - ***************************************************************************** - */ -ReturnCode rfalNfcbPollerSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen ); - -/*! - ***************************************************************************** - * \brief NFC-B Technology Detection - * - * This method performs NFC-B Technology Detection as defined in the spec - * given in the compliance mode - * - * \param[in] compMode : compliance mode to be performed - * \param[out] sensbRes : location to store the SENSB_RES, if received - * \param[out] sensbResLen : length of the SENSB_RES, if received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_NONE : No error, one or more device in the field - ***************************************************************************** - */ -ReturnCode rfalNfcbPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen ); - -/*! - ***************************************************************************** - * \brief NFC-B Poller Collision Resolution - * - * NFC-B Collision resolution Listener device/card (PICC) as - * defined in Activity 1.1 9.3.5 - * - * This function is used to perform collision resolution for detection in case - * of multiple NFC Forum Devices with Technology B detected. - * Target with valid SENSB_RES will be stored in devInfo and nfcbDevCount incremented. - * - * \param[in] compMode : compliance mode to be performed - * \param[in] devLimit : device limit value, and size nfcbDevList - * \param[out] nfcbDevList : NFC-B listener device info - * \param[out] devCnt : devices found counter - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcbPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt ); - -/*! - ***************************************************************************** - * \brief NFC-B Poller Collision Resolution Slotted - * - * NFC-B Collision resolution Listener device/card (PICC). The sequence can - * be configured to be according to NFC Forum Activity 1.1 9.3.5, ISO10373 - * or EMVCo - * - * This function is used to perform collision resolution for detection in case - * of multiple NFC Forum Devices with Technology B are detected. - * Target with valid SENSB_RES will be stored in devInfo and nfcbDevCount incremented. - * - * This method provides the means to perform a collision resolution loop with specific - * initial and end number of slots. This allows to user to start the loop already with - * greater number of slots, and or limit the end number of slots. At the end a flag - * indicating whether there were collisions pending is returned. - * - * If RFAL_COMPLIANCE_MODE_ISO is used \a initSlots must be set to RFAL_NFCB_SLOT_NUM_1 - * - * - * \param[in] compMode : compliance mode to be performed - * \param[in] devLimit : device limit value, and size nfcbDevList - * \param[in] initSlots : number of slots to open initially - * \param[in] endSlots : number of slots when to stop collision resolution - * \param[out] nfcbDevList : NFC-B listener device info - * \param[out] devCnt : devices found counter - * \param[out] colPending : flag indicating whether collision are still pending - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcbPollerSlottedCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending ); - - -/*! - ***************************************************************************** - * \brief NFC-B TR2 code to FDT - * - * Converts the TR2 code as defined in Digital 1.1 Table 33 Minimum - * TR2 Coding to Frame Delay Time (FDT) in 1/Fc - * - * \param[in] tr2Code : TR2 code as defined in Digital 1.1 Table 33 - * - * \return FDT in 1/Fc - ***************************************************************************** - */ -uint32_t rfalNfcbTR2ToFDT( uint8_t tr2Code ); - - -#endif /* RFAL_NFCB_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_nfcf.h b/Software/Middlewares/ST/rfal/Inc/rfal_nfcf.h deleted file mode 100644 index 936f941..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_nfcf.h +++ /dev/null @@ -1,370 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfcf.h - * - * \author Gustavo Patricio - * - * \brief Implementation of NFC-F Poller (FeliCa PCD) device - * - * The definitions and helpers methods provided by this module are - * aligned with NFC-F (FeliCa - JIS X6319-4) - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup NFC-F - * \brief RFAL NFC-F Module - * @{ - * - */ - - -#ifndef RFAL_NFCF_H -#define RFAL_NFCF_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_NFCF_NFCID2_LEN 8U /*!< NFCID2 (FeliCa IDm) length */ -#define RFAL_NFCF_SENSF_RES_LEN_MIN 16U /*!< SENSF_RES minimum length */ -#define RFAL_NFCF_SENSF_RES_LEN_MAX 18U /*!< SENSF_RES maximum length */ -#define RFAL_NFCF_SENSF_RES_PAD0_LEN 2U /*!< SENSF_RES PAD0 length */ -#define RFAL_NFCF_SENSF_RES_PAD1_LEN 2U /*!< SENSF_RES PAD1 length */ -#define RFAL_NFCF_SENSF_RES_RD_LEN 2U /*!< SENSF_RES Request Data length */ -#define RFAL_NFCF_SENSF_RES_BYTE1 1U /*!< SENSF_RES first byte value */ -#define RFAL_NFCF_SENSF_SC_LEN 2U /*!< Felica SENSF_REQ System Code length */ -#define RFAL_NFCF_SENSF_PARAMS_SC1_POS 0U /*!< System Code byte1 position in the SENSF_REQ */ -#define RFAL_NFCF_SENSF_PARAMS_SC2_POS 1U /*!< System Code byte2 position in the SENSF_REQ */ -#define RFAL_NFCF_SENSF_PARAMS_RC_POS 2U /*!< Request Code position in the SENSF_REQ */ -#define RFAL_NFCF_SENSF_PARAMS_TSN_POS 3U /*!< Time Slot Number position in the SENSF_REQ */ -#define RFAL_NFCF_POLL_MAXCARDS 16U /*!< Max number slots/cards 16 */ - - -#define RFAL_NFCF_CMD_POS 0U /*!< Command/Responce code length */ -#define RFAL_NFCF_CMD_LEN 1U /*!< Command/Responce code length */ -#define RFAL_NFCF_LENGTH_LEN 1U /*!< LEN field length */ -#define RFAL_NFCF_HEADER_LEN (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CMD_LEN) /*!< Header length*/ - - -#define RFAL_NFCF_SENSF_NFCID2_BYTE1_POS 0U /*!< NFCID2 byte1 position */ -#define RFAL_NFCF_SENSF_NFCID2_BYTE2_POS 1U /*!< NFCID2 byte2 position */ - -#define RFAL_NFCF_SENSF_NFCID2_PROT_TYPE_LEN 2U /*!< NFCID2 length for byte 1 and byte 2 indicating NFC-DEP or T3T support */ -#define RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP 0x01U /*!< NFCID2 byte1 NFC-DEP support Digital 1.0 Table 44 */ -#define RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP 0xFEU /*!< NFCID2 byte2 NFC-DEP support Digital 1.0 Table 44 */ - -#define RFAL_NFCF_SYSTEMCODE 0xFFFFU /*!< SENSF_RES Default System Code Digital 1.0 6.6.1.1 */ - -#define RFAL_NFCF_BLOCK_LEN 16U /*!< NFCF T3T Block size T3T 1.0 4.1 */ -#define RFAL_NFCF_CHECKUPDATE_RES_ST1_POS 9U /*!< Check|Update Res Status Flag 1 position T3T 1.0 Table 8 */ -#define RFAL_NFCF_CHECKUPDATE_RES_ST2_POS 10U /*!< Check|Update Res Status Flag 2 position T3T 1.0 Table 8 */ -#define RFAL_NFCF_CHECKUPDATE_RES_NOB_POS 11U /*!< Check|Update Res Number of Blocks position T3T 1.0 Table 8 */ - -#define RFAL_NFCF_STATUS_FLAG_SUCCESS 0x00U /*!< Check response Number of Blocks position T3T 1.0 Table 11 */ -#define RFAL_NFCF_STATUS_FLAG_ERROR 0xFFU /*!< Check response Number of Blocks position T3T 1.0 Table 11 */ - -#define RFAL_NFCF_BLOCKLISTELEM_LEN 0x80U /*!< Block List Element Length bit (2|3 bytes) T3T 1.0 5.6.1 */ - -#define RFAL_NFCF_SERVICECODE_RDONLY 0x000BU /*!< NDEF Service Code as Read-Only T3T 1.0 7.2.1 */ -#define RFAL_NFCF_SERVICECODE_RDWR 0x0009U /*!< NDEF Service Code as Read and Write T3T 1.0 7.2.1 */ - - -/*! NFC-F Felica command set JIS X6319-4 9.1 */ -enum -{ - RFAL_NFCF_CMD_POLLING = 0x00, /*!< SENSF_REQ (Felica Poll/REQC command to identify a card ) */ - RFAL_NFCF_CMD_POLLING_RES = 0x01, /*!< SENSF_RES (Felica Poll/REQC command response ) */ - RFAL_NFCF_CMD_REQUEST_SERVICE = 0x02, /*!< verify the existence of Area and Service */ - RFAL_NFCF_CMD_REQUEST_RESPONSE = 0x04, /*!< verify the existence of a card */ - RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION = 0x06, /*!< read Block Data from a Service that requires no authentication */ - RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION_RES = 0x07, /*!< read Block Data response from a Service with no authentication */ - RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION = 0x08, /*!< write Block Data to a Service that requires no authentication */ - RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION_RES = 0x09, /*!< write Block Data response to a Service with no authentication */ - RFAL_NFCF_CMD_REQUEST_SYSTEM_CODE = 0x0c, /*!< acquire the System Code registered to a card */ - RFAL_NFCF_CMD_AUTHENTICATION1 = 0x10, /*!< authenticate a card */ - RFAL_NFCF_CMD_AUTHENTICATION2 = 0x12, /*!< allow a card to authenticate a Reader/Writer */ - RFAL_NFCF_CMD_READ = 0x14, /*!< read Block Data from a Service that requires authentication */ - RFAL_NFCF_CMD_WRITE = 0x16, /*!< write Block Data to a Service that requires authentication */ -}; - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -/*! Checks if the given NFC-F device indicates NFC-DEP support */ -#define rfalNfcfIsNfcDepSupported( dev ) ( (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE1_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP) && \ - (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE2_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP) ) - - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - - -/*! NFC-F SENSF_RES format Digital 1.1 8.6.2 */ -typedef struct -{ - uint8_t CMD; /*!< Command Code: 01h */ - uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */ - uint8_t PAD0[RFAL_NFCF_SENSF_RES_PAD0_LEN]; /*!< PAD0 */ - uint8_t PAD1[RFAL_NFCF_SENSF_RES_PAD1_LEN]; /*!< PAD1 */ - uint8_t MRTIcheck; /*!< MRTIcheck */ - uint8_t MRTIupdate; /*!< MRTIupdate */ - uint8_t PAD2; /*!< PAD2 */ - uint8_t RD[RFAL_NFCF_SENSF_RES_RD_LEN]; /*!< Request Data */ -} rfalNfcfSensfRes; - - -/*! NFC-F poller device (PCD) struct */ -typedef struct -{ - uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */ -} rfalNfcfPollDevice; - -/*! NFC-F listener device (PICC) struct */ -typedef struct -{ - uint8_t sensfResLen; /*!< SENF_RES length */ - rfalNfcfSensfRes sensfRes; /*!< SENF_RES */ -} rfalNfcfListenDevice; - -typedef uint16_t rfalNfcfServ; /*!< NFC-F Service Code */ - -/*! NFC-F Block List Element (2 or 3 bytes element) T3T 1.0 5.6.1 */ -typedef struct -{ - uint8_t conf; /*!< Access Mode | Serv Code List Order */ - uint16_t blockNum; /*!< Block Number */ -}rfalNfcfBlockListElem; - -/*! Check Update Service list and Block list parameter */ -typedef struct -{ - uint8_t numServ; /*!< Number of Services */ - rfalNfcfServ *servList; /*!< Service Code List */ - uint8_t numBlock; /*!< Number of Blocks */ - rfalNfcfBlockListElem *blockList; /*!< Block Number List */ -}rfalNfcfServBlockListParam; - - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief Initialize NFC-F Poller mode - * - * This methods configures RFAL RF layer to perform as a - * NFC-F Poller/RW (FeliCa PCD) including all default timings - * - * \param[in] bitRate : NFC-F bitrate to be initialize (212 or 424) - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Incorrect bitrate - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcfPollerInitialize( rfalBitRate bitRate ); - - -/*! - ***************************************************************************** - * \brief NFC-F Poller Check Presence - * - * This function sends a Poll/SENSF command according to NFC Activity spec - * It detects if a NCF-F device is within range - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_NONE : No error and some NFC-F device was detected - * - ***************************************************************************** - */ -ReturnCode rfalNfcfPollerCheckPresence( void ); - - -/*! - ***************************************************************************** - * \brief NFC-F Poller Poll - * - * This function sends to all PICCs in field the POLL command with the given - * number of slots. - * - * \param[in] slots : the number of slots to be performed - * \param[in] sysCode : as given in FeliCa poll command - * \param[in] reqCode : FeliCa communication parameters - * \param[out] cardList : Parameter of type rfalFeliCaPollRes which will hold the cards found - * \param[out] devCnt : actual number of cards found - * \param[out] collisions : number of collisions encountered - * - * \warning the list cardList has to be as big as the number of slots for the Poll - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_NONE : No error and some NFC-F device was detected - * - ***************************************************************************** - */ -ReturnCode rfalNfcfPollerPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *cardList, uint8_t *devCnt, uint8_t *collisions ); - - -/*! - ***************************************************************************** - * \brief NFC-F Poller Full Collision Resolution - * - * Performs a full Collision resolution as defined in Activity 1.1 9.3.4 - * - * \param[in] compMode : compliance mode to be performed - * \param[in] devLimit : device limit value, and size nfcaDevList - * \param[out] nfcfDevList : NFC-F listener devices list - * \param[out] devCnt : Devices found counter - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcfPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt ); - - -/*! - ***************************************************************************** - * \brief NFC-F Poller Check/Read - * - * It computes a Check / Read command accoring to T3T 1.0 and JIS X6319-4 and - * sends it to PICC. If sucessfully, the rxBuf will contain the the number of - * blocks in the first byte followed by the blocks data. - * - * \param[in] nfcid2 : nfcid2 of the device - * \param[in] servBlock : parameter containing the list of Services and - * Blocks to be addressed by this command - * \param[out] rxBuf : buffer to place check/read data - * \param[in] rxBufLen : size of the rxBuf - * \param[out] rcvdLen : length of data placed in rxBuf - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_REQUEST : The request was executed with error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcfPollerCheck( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvdLen ); - - -/*! - ***************************************************************************** - * \brief NFC-F Poller Update/Write - * - * It computes a Update / Write command accoring to T3T 1.0 and JIS X6319-4 and - * sends it to PICC. - * - * \param[in] nfcid2 : nfcid2 of the device - * \param[in] servBlock : parameter containing the list of Services and - * Blocks to be addressed by this command - * \param[in] txBuf : buffer where the request will be composed - * \param[in] txBufLen : size of txBuf - * \param[in] blockData : data to written on the given block(s) - * \param[out] rxBuf : buffer to place check/read data - * \param[in] rxBufLen : size of the rxBuf - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_REQUEST : The request was executed with error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalNfcfPollerUpdate( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *txBuf, uint16_t txBufLen, const uint8_t *blockData, uint8_t *rxBuf, uint16_t rxBufLen); - -/*! - ***************************************************************************** - * \brief NFC-F Listener is T3T Request - * - * This method checks if the given data is a valid T3T command (Read or Write) - * and in case a valid request has been received it may output the request's NFCID2 - * - * \param[in] buf : buffer holding Initiator's received command - * \param[in] bufLen : length of received command in bytes - * \param[out] nfcid2 : pointer to where the NFCID2 may be outputed, - * nfcid2 has NFCF_SENSF_NFCID2_LEN as length - * Pass NULL if output parameter not desired - * - * \return true : Valid T3T command (Read or Write) received - * \return false : Invalid protocol request - * - ***************************************************************************** - */ -bool rfalNfcfListenerIsT3TReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid2 ); - - -#endif /* RFAL_NFCF_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_nfcv.h b/Software/Middlewares/ST/rfal/Inc/rfal_nfcv.h deleted file mode 100644 index 36875b1..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_nfcv.h +++ /dev/null @@ -1,772 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfcv.h - * - * \author Gustavo Patricio - * - * \brief Implementation of NFC-V Poller (ISO15693) device - * - * The definitions and helpers methods provided by this module - * are aligned with NFC-V Digital 2.1 - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup NFC-V - * \brief RFAL NFC-V Module - * @{ - * - */ - -#ifndef RFAL_NFCV_H -#define RFAL_NFCV_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_NFCV_UID_LEN 8U /*!< NFC-V UID length */ -#define RFAL_NFCV_MAX_BLOCK_LEN 32U /*!< Max Block size: can be of up to 256 bits ISO 15693 2000 5 */ -#define RFAL_NFCV_BNO_LEN 1U /*!< NFC-V Block Number length */ -#define RFAL_NFCV_CRC_LEN 2U /*!< NFC-V CRC length */ -#define RFAL_NFCV_MAX_GEN_DATA_LEN (RFAL_NFCV_MAX_BLOCK_LEN + RFAL_NFCV_BNO_LEN + RFAL_NFCV_UID_LEN) /*!
© COPYRIGHT 2016 STMicroelectronics
- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_rf.h - * - * \author Gustavo Patricio - * - * \brief RF Abstraction Layer (RFAL) - * - * RFAL (RF Abstraction Layer) provides several functionalities required to - * perform RF/NFC communications.
The RFAL encapsulates the different - * RF ICs (ST25R3911, ST25R391x, etc) into a common and easy to use interface. - * - * It provides interfaces to configure the RF IC, set/get timings, modes, bit rates, - * specific handlings, execute listen mode, etc. - * - * Furthermore it provides a common interface to perform a Transceive operations. - * The Transceive can be executed in a blocking or non blocking way.
- * Additionally few specific Transceive methods are available to cope with the - * specifics of these particular operations. - * - * The most common interfaces are: - *
  rfalInitialize() - *
  rfalSetFDTPoll() - *
  rfalSetFDTListen() - *
  rfalSetGT() - *
  rfalSetBitRate() - *
  rfalSetMode() - *
  rfalFieldOnAndStartGT() - *
  rfalFieldOff() - *
  rfalStartTransceive() - *
  rfalGetTransceiveStatus() - *
  rfalTransceiveBlockingTxRx() - * - * An usage example is provided here: \ref exampleRfalPoller.c - * \example exampleRfalPoller.c - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-HAL - * \brief RFAL Hardware Abstraction Layer - * @{ - * - * \addtogroup RF - * \brief RFAL RF Abstraction Layer - * @{ - * - */ - -#ifndef RFAL_RF_H -#define RFAL_RF_H - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "platform.h" -#include "st_errno.h" -#include "rfal_features.h" - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ -#define RFAL_VERSION (uint32_t)0x02000aU /*!< RFAL Current Version: v2.0.10 */ - -#define RFAL_FWT_NONE 0xFFFFFFFFU /*!< Disabled FWT: Wait forever for a response */ -#define RFAL_GT_NONE RFAL_TIMING_NONE /*!< Disabled GT: No GT will be applied after Field On */ - -#define RFAL_TIMING_NONE 0x00U /*!< Timing disabled | Don't apply */ - -#define RFAL_1FC_IN_4096FC (uint32_t)4096U /*!< Number of 1/fc cycles in one 4096/fc */ -#define RFAL_1FC_IN_512FC (uint32_t)512U /*!< Number of 1/fc cycles in one 512/fc */ -#define RFAL_1FC_IN_64FC (uint32_t)64U /*!< Number of 1/fc cycles in one 64/fc */ -#define RFAL_1FC_IN_8FC (uint32_t)8U /*!< Number of 1/fc cycles in one 8/fc */ -#define RFAL_US_IN_MS (uint32_t)1000U /*!< Number of us in one ms */ -#define RFAL_1MS_IN_1FC (uint32_t)13560U /*!< Number of 1/fc cycles in 1ms */ -#define RFAL_BITS_IN_BYTE (uint16_t)8U /*!< Number of bits in one byte */ - -#define RFAL_CRC_LEN 2U /*!< RF CRC LEN */ - -/*! Default TxRx flags: Tx CRC automatic, Rx CRC removed, NFCIP1 mode off, AGC On, Tx Parity automatic, Rx Parity removed */ -#define RFAL_TXRX_FLAGS_DEFAULT ( (uint32_t)RFAL_TXRX_FLAGS_CRC_TX_AUTO | (uint32_t)RFAL_TXRX_FLAGS_CRC_RX_REMV | (uint32_t)RFAL_TXRX_FLAGS_NFCIP1_OFF | (uint32_t)RFAL_TXRX_FLAGS_AGC_ON | (uint32_t)RFAL_TXRX_FLAGS_PAR_RX_REMV | (uint32_t)RFAL_TXRX_FLAGS_PAR_TX_AUTO | (uint32_t)RFAL_TXRX_FLAGS_NFCV_FLAG_AUTO) - - - -#define RFAL_LM_MASK_NFCA (1U<<(uint8_t)RFAL_MODE_LISTEN_NFCA) /*!< Bitmask for Listen Mode enabling Listen NFCA */ -#define RFAL_LM_MASK_NFCB (1U<<(uint8_t)RFAL_MODE_LISTEN_NFCB) /*!< Bitmask for Listen Mode enabling Listen NFCB */ -#define RFAL_LM_MASK_NFCF (1U<<(uint8_t)RFAL_MODE_LISTEN_NFCF) /*!< Bitmask for Listen Mode enabling Listen NFCF */ -#define RFAL_LM_MASK_ACTIVE_P2P (1U<<(uint8_t)RFAL_MODE_LISTEN_ACTIVE_P2P) /*!< Bitmask for Listen Mode enabling Listen AP2P */ - -#define RFAL_LM_SENS_RES_LEN 2U /*!< NFC-A SENS_RES (ATQA) length */ -#define RFAL_LM_SENSB_RES_LEN 13U /*!< NFC-B SENSB_RES (ATQB) length */ -#define RFAL_LM_SENSF_RES_LEN 19U /*!< NFC-F SENSF_RES length */ -#define RFAL_LM_SENSF_SC_LEN 2U /*!< NFC-F System Code length */ - -#define RFAL_NFCID3_LEN 10U /*!< NFCID3 length */ -#define RFAL_NFCID2_LEN 8U /*!< NFCID2 length */ -#define RFAL_NFCID1_TRIPLE_LEN 10U /*!< NFCID1 length */ -#define RFAL_NFCID1_DOUBLE_LEN 7U /*!< NFCID1 length */ -#define RFAL_NFCID1_SIMPLE_LEN 4U /*!< NFCID1 length */ - - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - -/*! Returns the maximum supported bit rate for RW mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */ -#define rfalGetMaxBrRW() ( ((RFAL_SUPPORT_BR_RW_6780) ? RFAL_BR_6780 : ((RFAL_SUPPORT_BR_RW_3390) ? RFAL_BR_3390 : ((RFAL_SUPPORT_BR_RW_1695) ? RFAL_BR_1695 : ((RFAL_SUPPORT_BR_RW_848) ? RFAL_BR_848 : ((RFAL_SUPPORT_BR_RW_424) ? RFAL_BR_424 : ((RFAL_SUPPORT_BR_RW_212) ? RFAL_BR_212 : RFAL_BR_106 ) ) ) ) ) ) ) - -/*! Returns the maximum supported bit rate for AP2P mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */ -#define rfalGetMaxBrAP2P() ( ((RFAL_SUPPORT_BR_AP2P_848) ? RFAL_BR_848 : ((RFAL_SUPPORT_BR_AP2P_424) ? RFAL_BR_424 : ((RFAL_SUPPORT_BR_AP2P_212) ? RFAL_BR_212 : RFAL_BR_106 ) ) ) ) - -/*! Returns the maximum supported bit rate for CE-A mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */ -#define rfalGetMaxBrCEA() ( ((RFAL_SUPPORT_BR_CE_A_848) ? RFAL_BR_848 : ((RFAL_SUPPORT_BR_CE_A_424) ? RFAL_BR_424 : ((RFAL_SUPPORT_BR_CE_A_212) ? RFAL_BR_212 : RFAL_BR_106 ) ) ) ) - -/*! Returns the maximum supported bit rate for CE-B mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */ -#define rfalGetMaxBrCEB() ( ((RFAL_SUPPORT_BR_CE_B_848) ? RFAL_BR_848 : ((RFAL_SUPPORT_BR_CE_B_424) ? RFAL_BR_424 : ((RFAL_SUPPORT_BR_CE_B_212) ? RFAL_BR_212 : RFAL_BR_106 ) ) ) ) - -/*! Returns the maximum supported bit rate for CE-F mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */ -#define rfalGetMaxBrCEF() ( ((RFAL_SUPPORT_BR_CE_F_424) ? RFAL_BR_424 : RFAL_BR_212 ) ) - - -#define rfalIsModeActiveComm( md ) ( ((md) == RFAL_MODE_POLL_ACTIVE_P2P) || ((md) == RFAL_MODE_LISTEN_ACTIVE_P2P) ) /*!< Checks if mode md is Active Communication */ -#define rfalIsModePassiveComm( md ) ( !rfalIsModeActiveComm(md) ) /*!< Checks if mode md is Passive Communication */ -#define rfalIsModePassiveListen( md ) ( ((md) == RFAL_MODE_LISTEN_NFCA) || ((md) == RFAL_MODE_LISTEN_NFCB) || ((md) == RFAL_MODE_LISTEN_NFCF) ) /*!< Checks if mode md is Passive Listen */ -#define rfalIsModePassivePoll( md ) ( rfalIsModePassiveComm(md) && !rfalIsModePassiveListen(md) ) /*!< Checks if mode md is Passive Poll */ - - -#define rfalConv1fcTo8fc( t ) (uint32_t)( (uint32_t)(t) / RFAL_1FC_IN_8FC ) /*!< Converts the given t from 1/fc to 8/fc */ -#define rfalConv8fcTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1FC_IN_8FC ) /*!< Converts the given t from 8/fc to 1/fc */ - -#define rfalConv1fcTo64fc( t ) (uint32_t)( (uint32_t)(t) / RFAL_1FC_IN_64FC ) /*!< Converts the given t from 1/fc to 64/fc */ -#define rfalConv64fcTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1FC_IN_64FC ) /*!< Converts the given t from 64/fc to 1/fc */ - -#define rfalConv1fcTo512fc( t ) (uint32_t)( (uint32_t)(t) / RFAL_1FC_IN_512FC ) /*!< Converts the given t from 1/fc to 512/fc */ -#define rfalConv512fcTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1FC_IN_512FC ) /*!< Converts the given t from 512/fc to 1/fc */ - -#define rfalConv1fcTo4096fc( t ) (uint32_t)( (uint32_t)(t) / RFAL_1FC_IN_4096FC ) /*!< Converts the given t from 1/fc to 4096/fc */ -#define rfalConv4096fcTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1FC_IN_4096FC ) /*!< Converts the given t from 4096/fc to 1/fc */ - -#define rfalConv1fcToMs( t ) (uint32_t)( (uint32_t)(t) / RFAL_1MS_IN_1FC ) /*!< Converts the given t from 1/fc to ms */ -#define rfalConvMsTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1MS_IN_1FC ) /*!< Converts the given t from ms to 1/fc */ - -#define rfalConv1fcToUs( t ) (uint32_t)( ((uint32_t)(t) * RFAL_US_IN_MS) / RFAL_1MS_IN_1FC) /*!< Converts the given t from 1/fc to us */ -#define rfalConvUsTo1fc( t ) (uint32_t)( ((uint32_t)(t) * RFAL_1MS_IN_1FC) / RFAL_US_IN_MS) /*!< Converts the given t from us to 1/fc */ - -#define rfalConv64fcToMs( t ) (uint32_t)( (uint32_t)(t) / (RFAL_1MS_IN_1FC / RFAL_1FC_IN_64FC) ) /*!< Converts the given t from 64/fc to ms */ -#define rfalConvMsTo64fc( t ) (uint32_t)( (uint32_t)(t) * (RFAL_1MS_IN_1FC / RFAL_1FC_IN_64FC) ) /*!< Converts the given t from ms to 64/fc */ - -#define rfalConvBitsToBytes( n ) (uint16_t)( ((uint16_t)(n)+(RFAL_BITS_IN_BYTE-1U)) / (RFAL_BITS_IN_BYTE) ) /*!< Converts the given n from bits to bytes */ -#define rfalConvBytesToBits( n ) (uint32_t)( (uint32_t)(n) * (RFAL_BITS_IN_BYTE) ) /*!< Converts the given n from bytes to bits */ - - - -/*! Computes a Transceive context \a ctx with default flags and the lengths - * in bytes with the given arguments - * \a ctx : Transceive context to be assigned - * \a tB : txBuf the pointer to the buffer to be sent - * \a tBL : txBuf length in bytes - * \a rB : rxBuf the pointer to the buffer to place the received frame - * \a rBL : rxBuf length in bytes - * \a rBL : rxBuf length in bytes - * \a t : FWT to be used on this transceive in 1/fc - */ -#define rfalCreateByteTxRxContext( ctx, tB, tBL, rB, rBL, rdL, t ) \ - (ctx).txBuf = (uint8_t*)(tB); \ - (ctx).txBufLen = (uint16_t)rfalConvBytesToBits(tBL); \ - (ctx).rxBuf = (uint8_t*)(rB); \ - (ctx).rxBufLen = (uint16_t)rfalConvBytesToBits(rBL); \ - (ctx).rxRcvdLen = (uint16_t*)(rdL); \ - (ctx).flags = (uint32_t)RFAL_TXRX_FLAGS_DEFAULT; \ - (ctx).fwt = (uint32_t)(t); - - -/*! Computes a Transceive context \a ctx using lengths in bytes - * with the given flags and arguments - * \a ctx : Transceive context to be assigned - * \a tB : txBuf the pointer to the buffer to be sent - * \a tBL : txBuf length in bytes - * \a rB : rxBuf the pointer to the buffer to place the received frame - * \a rBL : rxBuf length in bytes - * \a rBL : rxBuf length in bytes - * \a t : FWT to be used on this transceive in 1/fc - */ -#define rfalCreateByteFlagsTxRxContext( ctx, tB, tBL, rB, rBL, rdL, fl, t ) \ - (ctx).txBuf = (uint8_t*)(tB); \ - (ctx).txBufLen = (uint16_t)rfalConvBytesToBits(tBL); \ - (ctx).rxBuf = (uint8_t*)(rB); \ - (ctx).rxBufLen = (uint16_t)rfalConvBytesToBits(rBL); \ - (ctx).rxRcvdLen = (uint16_t*)(rdL); \ - (ctx).flags = (uint32_t)(fl); \ - (ctx).fwt = (uint32_t)(t); - - -#define rfalLogE(...) platformLog(__VA_ARGS__) /*!< Macro for the error log method */ -#define rfalLogW(...) platformLog(__VA_ARGS__) /*!< Macro for the warning log method */ -#define rfalLogI(...) platformLog(__VA_ARGS__) /*!< Macro for the info log method */ -#define rfalLogD(...) platformLog(__VA_ARGS__) /*!< Macro for the debug log method */ - - -/* -****************************************************************************** -* GLOBAL ENUMS -****************************************************************************** -*/ - -/* RFAL Guard Time (GT) default values */ -#define RFAL_GT_NFCA rfalConvMsTo1fc(5U) /*!< GTA Digital 2.0 6.10.4.1 & B.2 */ -#define RFAL_GT_NFCB rfalConvMsTo1fc(5U) /*!< GTB Digital 2.0 7.9.4.1 & B.3 */ -#define RFAL_GT_NFCF rfalConvMsTo1fc(20U) /*!< GTF Digital 2.0 8.7.4.1 & B.4 */ -#define RFAL_GT_NFCV rfalConvMsTo1fc(5U) /*!< GTV Digital 2.0 9.7.5.1 & B.5 */ -#define RFAL_GT_PICOPASS rfalConvMsTo1fc(1U) /*!< GT Picopass */ -#define RFAL_GT_AP2P rfalConvMsTo1fc(5U) /*!< TIRFG Ecma 340 11.1.1 */ -#define RFAL_GT_AP2P_ADJUSTED rfalConvMsTo1fc(5U+25U) /*!< Adjusted GT for greater interoperability (Sony XPERIA P, Nokia N9, Huawei P2) */ - -/* RFAL Frame Delay Time (FDT) Listen default values */ -#define RFAL_FDT_LISTEN_NFCA_POLLER 1172U /*!< FDTA,LISTEN,MIN (n=9) Last bit: Logic "1" - tnn,min/2 Digital 1.1 6.10 ; EMV CCP Spec Book D v2.01 4.8.1.3 */ -#define RFAL_FDT_LISTEN_NFCB_POLLER 1008U /*!< TR0B,MIN Digital 1.1 7.1.3 & A.3 ; EMV CCP Spec Book D v2.01 4.8.1.3 & Table A.5 */ -#define RFAL_FDT_LISTEN_NFCF_POLLER 2672U /*!< TR0F,LISTEN,MIN Digital 1.1 8.7.1.1 & A.4 */ -#define RFAL_FDT_LISTEN_NFCV_POLLER 4310U /*!< FDTV,LISTEN,MIN t1 min Digital 2.1 B.5 ; ISO15693-3 2009 9.1 */ -#define RFAL_FDT_LISTEN_PICOPASS_POLLER 3400U /*!< ISO15693 t1 min - observed adjustment */ -#define RFAL_FDT_LISTEN_AP2P_POLLER 64U /*!< FDT AP2P No actual FDTListen is required as fields switch and collision avoidance */ -#define RFAL_FDT_LISTEN_NFCA_LISTENER 1172U /*!< FDTA,LISTEN,MIN Digital 1.1 6.10 */ -#define RFAL_FDT_LISTEN_NFCB_LISTENER 1024U /*!< TR0B,MIN Digital 1.1 7.1.3 & A.3 ; EMV CCP Spec Book D v2.01 4.8.1.3 & Table A.5 */ -#define RFAL_FDT_LISTEN_NFCF_LISTENER 2688U /*!< TR0F,LISTEN,MIN Digital 1.1 8.7.1.1 & A.4 */ -#define RFAL_FDT_LISTEN_AP2P_LISTENER 64U /*!< FDT AP2P No actual FDTListen exists as fields switch and collision avoidance */ - -/* RFAL Frame Delay Time (FDT) Poll default values */ -#define RFAL_FDT_POLL_NFCA_POLLER 6780U /*!< FDTA,POLL,MIN Digital 1.1 6.10.3.1 & A.2 */ -#define RFAL_FDT_POLL_NFCA_T1T_POLLER 384U /*!< RRDDT1T,MIN,B1 Digital 1.1 10.7.1 & A.5 */ -#define RFAL_FDT_POLL_NFCB_POLLER 6780U /*!< FDTB,POLL,MIN = TR2B,MIN,DEFAULT Digital 1.1 7.9.3 & A.3 ; EMVCo 3.0 FDTB,PCD,MIN Table A.5 */ -#define RFAL_FDT_POLL_NFCF_POLLER 2672U /*!< FDTF,POLL,MIN Digital 1.1 8.7.3 & A.4 */ -#define RFAL_FDT_POLL_NFCV_POLLER 4192U /*!< FDTV,POLL Digital 2.1 9.7.3.1 & B.5 */ -#define RFAL_FDT_POLL_PICOPASS_POLLER 1790U /*!< FDT Max */ -#define RFAL_FDT_POLL_AP2P_POLLER 0U /*!< FDT AP2P No actual FDTPoll exists as fields switch and collision avoidance */ - - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! RFAL modes */ -typedef enum { - RFAL_MODE_NONE = 0, /*!< No mode selected/defined */ - RFAL_MODE_POLL_NFCA = 1, /*!< Mode to perform as NFCA (ISO14443A) Poller (PCD) */ - RFAL_MODE_POLL_NFCA_T1T = 2, /*!< Mode to perform as NFCA T1T (Topaz) Poller (PCD) */ - RFAL_MODE_POLL_NFCB = 3, /*!< Mode to perform as NFCB (ISO14443B) Poller (PCD) */ - RFAL_MODE_POLL_B_PRIME = 4, /*!< Mode to perform as B' Calypso (Innovatron) (PCD) */ - RFAL_MODE_POLL_B_CTS = 5, /*!< Mode to perform as CTS Poller (PCD) */ - RFAL_MODE_POLL_NFCF = 6, /*!< Mode to perform as NFCF (FeliCa) Poller (PCD) */ - RFAL_MODE_POLL_NFCV = 7, /*!< Mode to perform as NFCV (ISO15963) Poller (PCD) */ - RFAL_MODE_POLL_PICOPASS = 8, /*!< Mode to perform as PicoPass / iClass Poller (PCD) */ - RFAL_MODE_POLL_ACTIVE_P2P = 9, /*!< Mode to perform as Active P2P (ISO18092) Initiator */ - RFAL_MODE_LISTEN_NFCA = 10, /*!< Mode to perform as NFCA (ISO14443A) Listener (PICC) */ - RFAL_MODE_LISTEN_NFCB = 11, /*!< Mode to perform as NFCA (ISO14443B) Listener (PICC) */ - RFAL_MODE_LISTEN_NFCF = 12, /*!< Mode to perform as NFCA (ISO15963) Listener (PICC) */ - RFAL_MODE_LISTEN_ACTIVE_P2P = 13 /*!< Mode to perform as Active P2P (ISO18092) Target */ -} rfalMode; - - -/*! RFAL Bit rates */ -typedef enum { - RFAL_BR_106 = 0, /*!< Bit Rate 106 kbit/s (fc/128) */ - RFAL_BR_212 = 1, /*!< Bit Rate 212 kbit/s (fc/64) */ - RFAL_BR_424 = 2, /*!< Bit Rate 424 kbit/s (fc/32) */ - RFAL_BR_848 = 3, /*!< Bit Rate 848 kbit/s (fc/16) */ - RFAL_BR_1695 = 4, /*!< Bit Rate 1695 kbit/s (fc/8) */ - RFAL_BR_3390 = 5, /*!< Bit Rate 3390 kbit/s (fc/4) */ - RFAL_BR_6780 = 6, /*!< Bit Rate 6780 kbit/s (fc/2) */ - RFAL_BR_13560 = 7, /*!< Bit Rate 13560 kbit/s (fc) */ - RFAL_BR_52p97 = 0xEB, /*!< Bit Rate 52.97 kbit/s (fc/256) Fast Mode VICC->VCD */ - RFAL_BR_26p48 = 0xEC, /*!< Bit Rate 26,48 kbit/s (fc/512) NFCV VICC->VCD & VCD->VICC 1of4 */ - RFAL_BR_1p66 = 0xED, /*!< Bit Rate 1,66 kbit/s (fc/8192) NFCV VCD->VICC 1of256 */ - RFAL_BR_KEEP = 0xFF /*!< Value indicating to keep the same previous bit rate */ -} rfalBitRate; - - -/*! RFAL Compliance modes for upper modules */ -typedef enum { - RFAL_COMPLIANCE_MODE_NFC, /*!< Perform with NFC Forum 1.1 compliance */ - RFAL_COMPLIANCE_MODE_EMV, /*!< Perform with EMVCo compliance */ - RFAL_COMPLIANCE_MODE_ISO /*!< Perform with ISO10373 compliance */ -}rfalComplianceMode; - - -/*! RFAL main states flags */ -typedef enum { - RFAL_STATE_IDLE = 0, - RFAL_STATE_INIT = 1, - RFAL_STATE_MODE_SET = 2, - - RFAL_STATE_TXRX = 3, - RFAL_STATE_LM = 4, - RFAL_STATE_WUM = 5 - -} rfalState; - -/*! RFAL transceive states */ -typedef enum { - RFAL_TXRX_STATE_IDLE = 0, - RFAL_TXRX_STATE_INIT = 1, - RFAL_TXRX_STATE_START = 2, - - RFAL_TXRX_STATE_TX_IDLE = 11, - RFAL_TXRX_STATE_TX_WAIT_GT = 12, - RFAL_TXRX_STATE_TX_WAIT_FDT = 13, - RFAL_TXRX_STATE_TX_TRANSMIT = 14, - RFAL_TXRX_STATE_TX_WAIT_WL = 15, - RFAL_TXRX_STATE_TX_RELOAD_FIFO = 16, - RFAL_TXRX_STATE_TX_WAIT_TXE = 17, - RFAL_TXRX_STATE_TX_DONE = 18, - RFAL_TXRX_STATE_TX_FAIL = 19, - - RFAL_TXRX_STATE_RX_IDLE = 81, - RFAL_TXRX_STATE_RX_WAIT_EON = 82, - RFAL_TXRX_STATE_RX_WAIT_RXS = 83, - RFAL_TXRX_STATE_RX_WAIT_RXE = 84, - RFAL_TXRX_STATE_RX_READ_FIFO = 85, - RFAL_TXRX_STATE_RX_ERR_CHECK = 86, - RFAL_TXRX_STATE_RX_READ_DATA = 87, - RFAL_TXRX_STATE_RX_WAIT_EOF = 88, - RFAL_TXRX_STATE_RX_DONE = 89, - RFAL_TXRX_STATE_RX_FAIL = 90, - -} rfalTransceiveState; - - -/*! RFAL transceive flags */ -enum { - RFAL_TXRX_FLAGS_CRC_TX_AUTO = (0U<<0), /*!< CRC will be generated automatic upon transmission */ - RFAL_TXRX_FLAGS_CRC_TX_MANUAL = (1U<<0), /*!< CRC was calculated manually, included in txBuffer */ - RFAL_TXRX_FLAGS_CRC_RX_KEEP = (1U<<1), /*!< Upon Reception keep the CRC in rxBuffer (reflected on rcvd length) */ - RFAL_TXRX_FLAGS_CRC_RX_REMV = (0U<<1), /*!< Upon Reception remove the CRC from rxBuffer */ - RFAL_TXRX_FLAGS_NFCIP1_ON = (1U<<2), /*!< Enable NFCIP1 mode: Add SB(F0) and LEN bytes during Tx and skip SB(F0) byte during Rx */ - RFAL_TXRX_FLAGS_NFCIP1_OFF = (0U<<2), /*!< Disable NFCIP1 mode: do not append protocol bytes while Tx nor skip while Rx */ - RFAL_TXRX_FLAGS_AGC_OFF = (1U<<3), /*!< Disable Automatic Gain Control, improving multiple devices collision detection */ - RFAL_TXRX_FLAGS_AGC_ON = (0U<<3), /*!< Enable Automatic Gain Control, improving single device reception */ - RFAL_TXRX_FLAGS_PAR_RX_KEEP = (1U<<4), /*!< Disable Parity and CRC check and keep the Parity and CRC bits in the received buffer */ - RFAL_TXRX_FLAGS_PAR_RX_REMV = (0U<<0), /*!< Enable Parity check and remove the parity bits from the received buffer */ - RFAL_TXRX_FLAGS_PAR_TX_NONE = (1U<<5), /*!< Disable automatic Parity generation (ISO14443A) and use the one provided in the buffer*/ - RFAL_TXRX_FLAGS_PAR_TX_AUTO = (0U<<5), /*!< Enable automatic Parity generation (ISO14443A) */ - RFAL_TXRX_FLAGS_NFCV_FLAG_MANUAL = (1U<<6), /*!< Disable automatic adaption of flag byte (ISO15693) according to current comm params */ - RFAL_TXRX_FLAGS_NFCV_FLAG_AUTO = (0U<<6), /*!< Enable automatic adaption of flag byte (ISO115693) according to current comm params */ -}; - - -/*! RFAL error handling */ -typedef enum { - RFAL_ERRORHANDLING_NONE = 0, /*!< No special error handling will be performed */ - RFAL_ERRORHANDLING_NFC = 1, /*!< Error handling set to perform as NFC complaint device */ - RFAL_ERRORHANDLING_EMVCO = 2 /*!< Error handling set to perform as EMVCo complaint device */ -} rfalEHandling; - - -/*! Struct that holds all context to be used on a Transceive */ -typedef struct { - uint8_t* txBuf; /*!< (In) Buffer where outgoing message is located */ - uint16_t txBufLen; /*!< (In) Length of the outgoing message in bits */ - - uint8_t* rxBuf; /*!< (Out) Buffer where incoming message will be placed */ - uint16_t rxBufLen; /*!< (In) Maximum length of the incoming message in bits */ - uint16_t* rxRcvdLen; /*!< (Out) Actual received length in bits */ - - uint32_t flags; /*!< (In) TransceiveFlags indication special handling */ - uint32_t fwt; /*!< (In) Frame Waiting Time in 1/fc */ -} rfalTransceiveContext; - - -/*! System callback to indicate an event that requires a system reRun */ -typedef void (* rfalUpperLayerCallback)(void); - -/*! Callback to be executed before a Transceive */ -typedef void (* rfalPreTxRxCallback)(void); - -/*! Callback to be executed after a Transceive */ -typedef void (* rfalPostTxRxCallback)(void); - - -/*******************************************************************************/ -/* ISO14443A */ -/*******************************************************************************/ - -/*! RFAL ISO 14443A Short Frame Command */ -typedef enum -{ - RFAL_14443A_SHORTFRAME_CMD_WUPA = 0x52, /*!< ISO14443A WUPA / NFC-A ALL_REQ */ - RFAL_14443A_SHORTFRAME_CMD_REQA = 0x26 /*!< ISO14443A REQA / NFC-A SENS_REQ */ -} rfal14443AShortFrameCmd; - -/*******************************************************************************/ - - -/*******************************************************************************/ -/* FeliCa */ -/*******************************************************************************/ - -#define RFAL_FELICA_LEN_LEN 1U /*!< FeliCa LEN byte length */ -#define RFAL_FELICA_POLL_REQ_LEN (RFAL_FELICA_LEN_LEN + 1U + 2U + 1U + 1U) /*!< FeliCa Poll Request length (LEN + CMD + SC + RC + TSN) */ -#define RFAL_FELICA_POLL_RES_LEN (RFAL_FELICA_LEN_LEN + 1U + 8U + 8U + 2U) /*!< Maximum FeliCa Poll Response length (LEN + CMD + NFCID2 + PAD + RD) */ -#define RFAL_FELICA_POLL_MAX_SLOTS 16U /*!< Maximum number of slots (TSN) on FeliCa Poll */ - - -/*! NFC-F RC (Request Code) codes NFC Forum Digital 1.1 Table 42 */ -enum -{ - RFAL_FELICA_POLL_RC_NO_REQUEST = 0x00, /*!< RC: No System Code information requested */ - RFAL_FELICA_POLL_RC_SYSTEM_CODE = 0x01, /*!< RC: System Code information requested */ - RFAL_FELICA_POLL_RC_COM_PERFORMANCE = 0x02 /*!< RC: Advanced protocol features supported */ -}; - - -/*! NFC-F TSN (Time Slot Number) codes NFC Forum Digital 1.1 Table 43 */ -typedef enum -{ - RFAL_FELICA_1_SLOT = 0, /*!< TSN with number of Time Slots: 1 */ - RFAL_FELICA_2_SLOTS = 1, /*!< TSN with number of Time Slots: 2 */ - RFAL_FELICA_4_SLOTS = 3, /*!< TSN with number of Time Slots: 4 */ - RFAL_FELICA_8_SLOTS = 7, /*!< TSN with number of Time Slots: 8 */ - RFAL_FELICA_16_SLOTS = 15 /*!< TSN with number of Time Slots: 16 */ -} rfalFeliCaPollSlots; - - -/*! NFCF Poll Response NFC Forum Digital 1.1 Table 44 */ -typedef uint8_t rfalFeliCaPollRes[RFAL_FELICA_POLL_RES_LEN]; - - -/*******************************************************************************/ - - -/*******************************************************************************/ -/* Listen Mode */ -/*******************************************************************************/ - -/*! RFAL Listen Mode NFCID Length */ -typedef enum -{ - RFAL_LM_NFCID_LEN_04 = 4, /*!< Listen mode indicates 4 byte NFCID */ - RFAL_LM_NFCID_LEN_07 = 7, /*!< Listen mode indicates 7 byte NFCID */ - RFAL_LM_NFCID_LEN_10 = 10, /*!< Listen mode indicates 10 byte NFCID */ -} rfalLmNfcidLen; - - -/*! RFAL Listen Mode States */ -typedef enum -{ - RFAL_LM_STATE_NOT_INIT = 0x00, /*!< Not Initialized state */ - RFAL_LM_STATE_POWER_OFF = 0x01, /*!< Power Off state */ - RFAL_LM_STATE_IDLE = 0x02, /*!< Idle state Activity 1.1 5.2 */ - RFAL_LM_STATE_READY_A = 0x03, /*!< Ready A state Activity 1.1 5.3 5.4 & 5.5 */ - RFAL_LM_STATE_READY_B = 0x04, /*!< Ready B state Activity 1.1 5.11 5.12 */ - RFAL_LM_STATE_READY_F = 0x05, /*!< Ready F state Activity 1.1 5.15 */ - RFAL_LM_STATE_ACTIVE_A = 0x06, /*!< Active A state Activity 1.1 5.6 */ - RFAL_LM_STATE_CARDEMU_4A = 0x07, /*!< Card Emulation 4A state Activity 1.1 5.10 */ - RFAL_LM_STATE_CARDEMU_4B = 0x08, /*!< Card Emulation 4B state Activity 1.1 5.14 */ - RFAL_LM_STATE_CARDEMU_3 = 0x09, /*!< Card Emulation 3 state Activity 1.1 5.18 */ - RFAL_LM_STATE_TARGET_A = 0x0A, /*!< Target A state Activity 1.1 5.9 */ - RFAL_LM_STATE_TARGET_F = 0x0B, /*!< Target F state Activity 1.1 5.17 */ - RFAL_LM_STATE_SLEEP_A = 0x0C, /*!< Sleep A state Activity 1.1 5.7 */ - RFAL_LM_STATE_SLEEP_B = 0x0D, /*!< Sleep B state Activity 1.1 5.13 */ - RFAL_LM_STATE_READY_Ax = 0x0E, /*!< Ready A* state Activity 1.1 5.3 5.4 & 5.5 */ - RFAL_LM_STATE_ACTIVE_Ax = 0x0F, /*!< Active A* state Activity 1.1 5.6 */ - RFAL_LM_STATE_SLEEP_AF = 0x10, /*!< Sleep AF state Activity 1.1 5.19 */ -} rfalLmState; - - -/*! RFAL Listen Mode Passive A configs */ -typedef struct -{ - rfalLmNfcidLen nfcidLen; /*!< NFCID Len (00: 4bytes ; 01: 7bytes) */ - uint8_t nfcid[RFAL_NFCID1_TRIPLE_LEN]; /*!< NFCID */ - uint8_t SENS_RES[RFAL_LM_SENS_RES_LEN]; /*!< NFC-106k; SENS_REQ Response */ - uint8_t SEL_RES; /*!< SEL_RES (SAK) with complete NFCID1 (UID) */ -} rfalLmConfPA; - - -/*! RFAL Listen Mode Passive B configs */ -typedef struct -{ - uint8_t SENSB_RES[RFAL_LM_SENSB_RES_LEN]; /*!< SENSF_RES */ -} rfalLmConfPB; - - -/*! RFAL Listen Mode Passive F configs */ -typedef struct -{ - uint8_t SC[RFAL_LM_SENSF_SC_LEN]; /*!< System Code to listen for */ - uint8_t SENSF_RES[RFAL_LM_SENSF_RES_LEN]; /*!< SENSF_RES */ -} rfalLmConfPF; - -/*******************************************************************************/ - - -/*******************************************************************************/ -/* Wake-Up Mode */ -/*******************************************************************************/ - -#define RFAL_WUM_REFERENCE_AUTO 0xFFU /*!< Indicates new reference is set by the driver*/ - -/*! RFAL Wake-Up Mode States */ -typedef enum -{ - RFAL_WUM_STATE_NOT_INIT = 0x00, /*!< Not Initialized state */ - RFAL_WUM_STATE_ENABLED = 0x01, /*!< Wake-Up mode is enabled */ - RFAL_WUM_STATE_ENABLED_WOKE = 0x02, /*!< Wake-Up mode enabled and has received IRQ(s)*/ -} rfalWumState; - -/*! RFAL Wake-Up Period/Timer */ -typedef enum -{ - RFAL_WUM_PERIOD_10MS = 0x00, /*!< Wake-Up timer 10ms */ - RFAL_WUM_PERIOD_20MS = 0x01, /*!< Wake-Up timer 20ms */ - RFAL_WUM_PERIOD_30MS = 0x02, /*!< Wake-Up timer 30ms */ - RFAL_WUM_PERIOD_40MS = 0x03, /*!< Wake-Up timer 40ms */ - RFAL_WUM_PERIOD_50MS = 0x04, /*!< Wake-Up timer 50ms */ - RFAL_WUM_PERIOD_60MS = 0x05, /*!< Wake-Up timer 60ms */ - RFAL_WUM_PERIOD_70MS = 0x06, /*!< Wake-Up timer 70ms */ - RFAL_WUM_PERIOD_80MS = 0x07, /*!< Wake-Up timer 80ms */ - RFAL_WUM_PERIOD_100MS = 0x10, /*!< Wake-Up timer 100ms */ - RFAL_WUM_PERIOD_200MS = 0x11, /*!< Wake-Up timer 200ms */ - RFAL_WUM_PERIOD_300MS = 0x12, /*!< Wake-Up timer 300ms */ - RFAL_WUM_PERIOD_400MS = 0x13, /*!< Wake-Up timer 400ms */ - RFAL_WUM_PERIOD_500MS = 0x14, /*!< Wake-Up timer 500ms */ - RFAL_WUM_PERIOD_600MS = 0x15, /*!< Wake-Up timer 600ms */ - RFAL_WUM_PERIOD_700MS = 0x16, /*!< Wake-Up timer 700ms */ - RFAL_WUM_PERIOD_800MS = 0x17, /*!< Wake-Up timer 800ms */ -} rfalWumPeriod; - - -/*! RFAL Wake-Up Period/Timer */ -typedef enum -{ - RFAL_WUM_AA_WEIGHT_4 = 0x00, /*!< Wake-Up Auto Average Weight 4 */ - RFAL_WUM_AA_WEIGHT_8 = 0x01, /*!< Wake-Up Auto Average Weight 8 */ - RFAL_WUM_AA_WEIGHT_16 = 0x02, /*!< Wake-Up Auto Average Weight 16 */ - RFAL_WUM_AA_WEIGHT_32 = 0x03, /*!< Wake-Up Auto Average Weight 32 */ -} rfalWumAAWeight; - - -/*! RFAL Wake-Up Mode configuration */ -typedef struct -{ - rfalWumPeriod period; /*!< Wake-Up Timer period;how often measurement(s) is performed */ - bool irqTout; /*!< IRQ at every timeout will refresh the measurement(s) */ - bool swTagDetect;/*!< Use SW Tag Detection instead of HW Wake-Up mode */ - - struct{ - bool enabled; /*!< Inductive Amplitude measurement enabled */ - uint8_t delta; /*!< Delta between the reference and measurement to wake-up */ - uint8_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */ - bool autoAvg; /*!< Use the HW Auto Averaging feature */ - bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */ - rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */ - }indAmp; /*!< Inductive Amplitude Configuration */ - struct{ - bool enabled; /*!< Inductive Phase measurement enabled */ - uint8_t delta; /*!< Delta between the reference and measurement to wake-up */ - uint8_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */ - bool autoAvg; /*!< Use the HW Auto Averaging feature */ - bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */ - rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */ - }indPha; /*!< Inductive Phase Configuration */ - struct{ - bool enabled; /*!< Capacitive measurement enabled */ - uint8_t delta; /*!< Delta between the reference and measurement to wake-up */ - uint8_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */ - bool autoAvg; /*!< Use the HW Auto Averaging feature */ - bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */ - rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */ - }cap; /*!< Capacitive Configuration */ -} rfalWakeUpConfig; - - -/*******************************************************************************/ - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - - -/*! - ***************************************************************************** - * \brief RFAL Initialize - * - * Initializes RFAL layer and the ST25R391x - * Ensures that ST25R391x is properly connected and returns error if any problem - * is detected - * - * \warning rfalAnalogConfigInitialize() should be called before so that - * the Analog config table has been previously initialized. - * - * \return ERR_HW_MISMATCH : Expected HW do not match or communication error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalInitialize( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Calibrate - * - * Performs necessary calibration of RF chip in case it is indicated by current - * register settings. E.g. antenna calibration and regulator calibration - * - * \return ERR_WRONG_STATE : RFAL not initialized - * \return ERR_NONE : No error - * - ***************************************************************************** - */ -ReturnCode rfalCalibrate( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Adjust Regulators - * - * Adjusts ST25R391x regulators - * - * \param[out] result : the result of the calibrate antenna in mV - * NULL if result not requested - * - * \return ERR_WRONG_STATE : RFAL not initialized - * \return ERR_NONE : No error - * - ***************************************************************************** - */ -ReturnCode rfalAdjustRegulators( uint16_t* result ); - - -/*! - ***************************************************************************** - * \brief RFAL Set System Callback - * - * Sets a callback for the driver to call when an event has occurred that - * may require the system to be notified - * - * \param[in] pFunc : method pointer for the upper layer callback - * - ***************************************************************************** - */ -void rfalSetUpperLayerCallback( rfalUpperLayerCallback pFunc ); - - -/*! - ***************************************************************************** - * \brief RFAL Set Pre Tx Callback - * - * Sets a callback for the driver to call before a Transceive - * - * \param[in] pFunc : method pointer for the Pre Tx callback - * - ***************************************************************************** - */ -void rfalSetPreTxRxCallback( rfalPreTxRxCallback pFunc ); - -/*! - ***************************************************************************** - * \brief RFAL Set Post Tx Callback - * - * Sets a callback for the driver to call after a Transceive - * - * \param[in] pFunc : method pointer for the Post Tx callback - * - ***************************************************************************** - */ -void rfalSetPostTxRxCallback( rfalPostTxRxCallback pFunc ); - -/*! - ***************************************************************************** - * \brief RFAL Deinitialize - * - * Deinitializes RFAL layer and the ST25R391x - * - * \return ERR_NONE : No error - * - ***************************************************************************** - */ -ReturnCode rfalDeinitialize( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Set Mode - * - * Sets the mode that RFAL will operate on the following communications. - * Proper initializations will be performed on the ST25R391x - * - * \warning bit rate value RFAL_BR_KEEP is not allowed, only in rfalSetBitRate() - * - * \warning the mode will be applied immediately on the RFchip regardless of - * any ongoing operations like Transceive, ListenMode - * - * \param[in] mode : mode for the RFAL/RFchip to perform - * \param[in] txBR : transmit bit rate - * \param[in] rxBR : receive bit rate - * - * \see rfalIsGTDone - * \see rfalMode - * - * \return ERR_WRONG_STATE : RFAL not initialized - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : No error - * - ***************************************************************************** - */ -ReturnCode rfalSetMode( rfalMode mode, rfalBitRate txBR, rfalBitRate rxBR ); - - -/*! - ***************************************************************************** - * \brief RFAL Get Mode - * - * Gets the mode that RFAL is set to operate - * - * \see rfalMode - * - * \return rfalMode : The current RFAL mode - ***************************************************************************** - */ -rfalMode rfalGetMode( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Set Bit Rate - * - * Sets the Tx and Rx bit rates with the given values - * The bit rate change is applied on the RF chip remaining in the same - * mode previous defined with rfalSetMode() - * - * If no mode is defined bit rates will not be applied and an error - * is returned - * - * \param[in] txBR : transmit bit rate - * \param[in] rxBR : receive bit rate - * - * \see rfalSetMode - * \see rfalMode - * \see rfalBitRate - * - * \return ERR_WRONG_STATE : RFAL not initialized - * \return ERR_PARAM : Invalid parameter - * \return ERR_NOT_IMPLEMENTED : Mode not implemented - * \return ERR_NONE : No error - * - ***************************************************************************** - */ -ReturnCode rfalSetBitRate( rfalBitRate txBR, rfalBitRate rxBR ); - - -/*! - ***************************************************************************** - * \brief RFAL Get Bit Rate - * - * Gets the Tx and Rx current bit rates - * - * If RFAL is not initialized or mode not set the bit rates return will - * be invalid RFAL_BR_KEEP - * - * \param[out] txBR : RFAL's current Tx Bit Rate - * \param[out] rxBR : RFAL's current Rx Bit Rate - * - * \see rfalSetBitRate - * \see rfalBitRate - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalGetBitRate( rfalBitRate *txBR, rfalBitRate *rxBR ); - - -/*! - ***************************************************************************** - * \brief Set Error Handling Mode - * - * Sets the error handling mode to be used by the RFAL - * - * \param[in] eHandling : the error handling mode - * - ***************************************************************************** - */ -void rfalSetErrorHandling( rfalEHandling eHandling ); - - -/*! - ***************************************************************************** - * \brief Get Error Handling Mode - * - * Gets the error handling mode currently used by the RFAL - * - * \return rfalEHandling : Current error handling mode - ***************************************************************************** - */ -rfalEHandling rfalGetErrorHandling( void ); - - -/*! - ***************************************************************************** - * \brief Set Observation Mode - * - * Sets ST25R391x observation modes for RF debug purposes - * - * \param[in] txMode : the observation mode to be used during transmission - * \param[in] rxMode : the observation mode to be used during reception - * - * \warning The Observation Mode is an advanced feature and should be set - * according to the documentation of the part number in use. - * Please refer to the corresponding Datasheet or Application Note(s) - ***************************************************************************** - */ -void rfalSetObsvMode( uint8_t txMode, uint8_t rxMode ); - - -/*! - ***************************************************************************** - * \brief Get Observation Mode - * - * Gets ST25R391x the current configured observation modes - * - * \param[in] txMode : the current observation mode configured for transmission - * \param[in] rxMode : the current observation mode configured for reception - * - ***************************************************************************** - */ -void rfalGetObsvMode( uint8_t* txMode, uint8_t* rxMode ); - - -/*! - ***************************************************************************** - * \brief Disable Observation Mode - * - * Disables the ST25R391x observation mode - ***************************************************************************** - */ -void rfalDisableObsvMode( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Set FDT Poll - * - * Sets the Frame Delay Time (FDT) to be used on the following - * communications. - * - * FDT Poll is the minimum time following a Poll Frame during - * which no subsequent Poll Frame can be sent (without a response from - * the Listener in between) - * FDTx,PP,MIN - Digital 1.1 6.10.2 & 7.9.2 & 8.7.2 - * - * \param[in] FDTPoll : Frame Delay Time in 1/fc cycles - * - ***************************************************************************** - */ -void rfalSetFDTPoll( uint32_t FDTPoll ); - - -/*! - ***************************************************************************** - * \brief RFAL Set FDT Poll - * - * Gets the current Frame Delay Time (FDT) - * - * FDT Poll is the minimum time following a Poll Frame during - * which no subsequent Poll Frame can be sent (without a response from - * the Listener in between) - * FDTx,PP,MIN - Digital 1.1 6.10.2 & 7.9.2 & 8.7.2 - * - * \return FDT : current FDT value in 1/fc cycles - * - ***************************************************************************** - */ -uint32_t rfalGetFDTPoll( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Set FDT Listen - * - * Sets the Frame Delay Time (FDT) Listen minimum to be used on the - * following communications. - * - * FDT Listen is the minimum time between a Poll Frame and a Listen Frame - * FDTx,LISTEN,MIN - Digital 1.1 6.10.1 & 7.9.1 & 8.7.1 - * - * \param[in] FDTListen : Frame Delay Time in 1/fc cycles - * - ***************************************************************************** - */ -void rfalSetFDTListen( uint32_t FDTListen ); - - -/*! - ***************************************************************************** - * \brief RFAL Set FDT Listen - * - * Gets the Frame Delay Time (FDT) Listen minimum - * - * FDT Listen is the minimum time between a Poll Frame and a Listen Frame - * FDTx,LISTEN,MIN - Digital 1.1 6.10.1 & 7.9.1 & 8.7.1 - * - * \return FDT : current FDT value in 1/fc cycles - * - ***************************************************************************** - */ -uint32_t rfalGetFDTListen( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Get GT - * - * Gets the current Guard Time (GT) - * - * GT is the minimum time when a device in Listen Mode is exposed to an - * unmodulated carrier - * - * \return GT : Guard Time in 1/fc cycles - * - ***************************************************************************** - */ -uint32_t rfalGetGT( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Set GT - * - * Sets the Guard Time (GT) to be used on the following communications. - * - * GT is the minimum time when a device in Listen Mode is exposed to an - * unmodulated carrier - * - * \param[in] GT : Guard Time in 1/fc cycles - * RFAL_GT_NONE if no GT should be applied - * - ***************************************************************************** - */ -void rfalSetGT( uint32_t GT ); - - -/*! - ***************************************************************************** - * \brief RFAL Is GT expired - * - * Checks whether the GT timer has expired - * - * \return true : GT has expired or not running - * \return false : GT is still running - * - ***************************************************************************** - */ -bool rfalIsGTExpired( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Turn Field On and Start GT - * - * Turns the Field On, performing Initial Collision Avoidance - * - * After Field On, if GT was set before, it starts the GT timer to be - * used on the following communications. - * - * \return ERR_RF_COLLISION : External field detected - * \return ERR_NONE : Field turned On - * - ***************************************************************************** - */ -ReturnCode rfalFieldOnAndStartGT( void ); - - -/*! - ***************************************************************************** - * \brief RFAL Turn Field Off - * - * Turns the Field Off - * - * \return ERR_NONE : Field turned Off - ***************************************************************************** - */ -ReturnCode rfalFieldOff( void ); - - - -/***************************************************************************** - * Transceive * - *****************************************************************************/ - -/*! - ***************************************************************************** - * \brief RFAL Set transceive context - * - * Set the context that will be used for the following Transceive - * Output and input buffers have to be passed and all other details prior to - * the Transceive itself has been started - * - * This method only sets the context, once set rfalWorker has - * to be executed until is done - * - * \param[in] ctx : the context for the following Transceive - * - * \see rfalWorker - * \see rfalGetTransceiveStatus - * - * \return ERR_NONE : Done with no error - * \return ERR_WRONG_STATE : Not initialized properly - * \return ERR_PARAM : Invalid parameter or configuration - ***************************************************************************** - */ -ReturnCode rfalStartTransceive( const rfalTransceiveContext *ctx ); - - -/*! - ***************************************************************************** - * \brief Get Transceive State - * - * Gets current Transceive internal State - * - * \return rfalTransceiveState : the current Transceive internal State - ***************************************************************************** - */ -rfalTransceiveState rfalGetTransceiveState( void ); - - -/*! - ***************************************************************************** - * \brief Get Transceive Status - * - * Gets current Transceive status - * - * \return ERR_NONE : Transceive done with no error - * \return ERR_BUSY : Transceive ongoing - * \return ERR_XXXX : Error occurred - * \return ERR_TIMEOUT : No response - * \return ERR_FRAMING : Framing error detected - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_LINK_LOSS : Link Loss - External Field is Off - * \return ERR_RF_COLLISION : Collision detected - * \return ERR_IO : Internal error - ***************************************************************************** - */ -ReturnCode rfalGetTransceiveStatus( void ); - - -/*! - ***************************************************************************** - * \brief Is Transceive in Tx - * - * Checks if Transceive is in Transmission state - * - * \return true Transmission ongoing - * \return false Not in transmission state - ***************************************************************************** - */ -bool rfalIsTransceiveInTx( void ); - - -/*! - ***************************************************************************** - * \brief Is Transceive in Rx - * - * Checks if Transceive is in Reception state - * - * \return true Transmission done/reception ongoing - * \return false Not in reception state - ***************************************************************************** - */ -bool rfalIsTransceiveInRx( void ); - - -/*! - ***************************************************************************** - * \brief Get Transceive RSSI - * - * Gets the RSSI value of the last executed Transceive in mV - * - * \param[out] rssi : RSSI value - * - * \return ERR_NOTSUPP : Feature not supported - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalGetTransceiveRSSI( uint16_t *rssi ); - - -/*! - ***************************************************************************** - * \brief RFAL Worker - * - * This runs RFAL layer, which drives the actual Transceive procedure - * It MUST be executed frequently in order to execute the RFAL internal - * states and perform the requested operations - * - ***************************************************************************** - */ -void rfalWorker( void ); - - -/***************************************************************************** - * ISO1443A * - *****************************************************************************/ - -/*! - ***************************************************************************** - * \brief Transceives an ISO14443A ShortFrame - * - * Sends REQA to detect if there is any PICC in the field - * - * \param[in] txCmd: Command to be sent: - * 0x52 WUPA / ALL_REQ - * 0x26 REQA / SENS_REQ - * - * \param[in] txCmd : type of short frame to be sent REQA or WUPA - * \param[out] rxBuf : buffer to place the response - * \param[in] rxBufLen : length of rxBuf - * \param[out] rxRcvdLen: received length - * \param[in] fwt : Frame Waiting Time in 1/fc - * - * \warning If fwt is set to RFAL_FWT_NONE it will make endlessly for - * a response, which on a blocking method may not be the - * desired usage - * - * \return ERR_NONE if there is response - * \return ERR_TIMEOUT if there is no response - * \return ERR_COLLISION collision has occurred - * - ***************************************************************************** - */ -ReturnCode rfalISO14443ATransceiveShortFrame( rfal14443AShortFrameCmd txCmd, uint8_t* rxBuf, uint8_t rxBufLen, uint16_t* rxRcvdLen, uint32_t fwt ); - - -/*! - ***************************************************************************** - * \brief Sends an ISO14443A Anticollision Frame - * - * This is use to perform ISO14443A anti-collision. - * \note Anticollision is sent without CRC - * - * - * \param[in] buf : reference to ANTICOLLISION command (with known UID if any) to be sent (also out param) - * reception will be place on this buf after bytesToSend - * \param[in] bytesToSend: reference number of full bytes to be sent (including CMD byte and SEL_PAR) - * if a collision occurs will contain the number of clear bytes - * \param[in] bitsToSend : reference to number of bits (0-7) to be sent; and received (also out param) - * if a collision occurs will indicate the number of clear bits (also out param) - * \param[out] rxLength : reference to the return the received length - * \param[in] fwt : Frame Waiting Time in 1/fc - * - * \return ERR_NONE if there is no error - ***************************************************************************** - */ -ReturnCode rfalISO14443ATransceiveAnticollisionFrame( uint8_t *buf, uint8_t *bytesToSend, uint8_t *bitsToSend, uint16_t *rxLength, uint32_t fwt ); - - -/***************************************************************************** - * FeliCa * - *****************************************************************************/ - -/*! - ***************************************************************************** - * \brief FeliCa Poll - * - * Sends a Poll Request and collects all Poll Responses according to the - * given slots - * - * - * \param[in] slots : number of slots for the Poll Request - * \param[in] sysCode : system code (SC) for the Poll Request - * \param[in] reqCode : request code (RC) for the Poll Request - * \param[out] pollResList : list of all responses - * \param[in] pollResListSize : number of responses that can be placed in pollResList - * \param[out] devicesDetected : number of cards found - * \param[out] collisionsDetected: number of collisions detected - * - * \return ERR_NONE if there is no error - * \return ERR_TIMEOUT if there is no response - ***************************************************************************** - */ -ReturnCode rfalFeliCaPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes* pollResList, uint8_t pollResListSize, uint8_t *devicesDetected, uint8_t *collisionsDetected ); - - -/***************************************************************************** - * ISO15693 * - *****************************************************************************/ - -/*! - ***************************************************************************** - * \brief Sends an ISO15693 Anticollision Frame - * - * This send the Anticollision|Inventory frame (INVENTORY_REQ) - * - * \warning rxBuf must be able to contain the payload and CRC - * - * \param[in] txBuf : Buffer where outgoing message is located - * \param[in] txBufLen : Length of the outgoing message in bytes - * \param[out] rxBuf : Buffer where incoming message will be placed - * \param[in] rxBufLen : Maximum length of the incoming message in bytes - * \param[out] actLen : Actual received length in bits - * - * \return ERR_NONE : Transceive done with no error - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_IO : Internal error - ***************************************************************************** - */ -ReturnCode rfalISO15693TransceiveAnticollisionFrame( uint8_t *txBuf, uint8_t txBufLen, uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen ); - - -/*! - ***************************************************************************** - * \brief Sends an ISO15693 Anticollision EOF - * - * This sends the Anticollision|Inventory EOF used as a slot marker - * - * \warning rxBuf must be able to contain the payload and CRC - * - * \param[out] rxBuf : Buffer where incoming message will be placed - * \param[in] rxBufLen : Maximum length of the incoming message in bytes - * \param[out] actLen : Actual received length in bits - * - * \return ERR_NONE : Transceive done with no error - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_IO : Internal error - ***************************************************************************** - */ -ReturnCode rfalISO15693TransceiveEOFAnticollision( uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen ); - - -/*! - ***************************************************************************** - * \brief Sends an ISO15693 EOF - * - * This is method sends an ISO15693 (EoF) used for a Write operation - * - * \warning rxBuf must be able to contain the payload and CRC - * - * \param[out] rxBuf : Buffer where incoming message will be placed - * \param[in] rxBufLen : Maximum length of the incoming message in bytes - * \param[out] actLen : Actual received length in bytes - * - * \return ERR_NONE : Transceive done with no error - * \return ERR_IO : Internal error - ***************************************************************************** - */ -ReturnCode rfalISO15693TransceiveEOF( uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen ); - - -/*! - ***************************************************************************** - * \brief Transceive Blocking Tx - * - * This is method triggers a Transceive and executes it blocking until the - * Tx has been completed - * - * \param[in] txBuf : Buffer where outgoing message is located - * \param[in] txBufLen : Length of the outgoing message in bytes - * \param[out] rxBuf : Buffer where incoming message will be placed - * \param[in] rxBufLen : Maximum length of the incoming message in bytes - * \param[out] actLen : Actual received length in bits - * \param[in] flags : TransceiveFlags indication special handling - * \param[in] fwt : Frame Waiting Time in 1/fc - * - * \return ERR_NONE : Transceive done with no error - * \return ERR_BUSY : Transceive ongoing - * \return ERR_XXXX : Error occurred - * \return ERR_LINK_LOSS : Link Loss - External Field is Off - * \return ERR_RF_COLLISION : Collision detected - * \return ERR_IO : Internal error - ***************************************************************************** - */ -ReturnCode rfalTransceiveBlockingTx( uint8_t* txBuf, uint16_t txBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t* actLen, uint32_t flags, uint32_t fwt ); - -/*! - ***************************************************************************** - * \brief Transceive Blocking Rx - * - * This is method executes the reception of an ongoing Transceive triggered - * before by rfalTransceiveBlockingTx() - * - * \return ERR_NONE : Transceive done with no error - * \return ERR_BUSY : Transceive ongoing - * \return ERR_XXXX : Error occurred - * \return ERR_TIMEOUT : No response - * \return ERR_FRAMING : Framing error detected - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_LINK_LOSS : Link Loss - External Field is Off - * \return ERR_RF_COLLISION : Collision detected - * \return ERR_IO : Internal error - ***************************************************************************** - */ -ReturnCode rfalTransceiveBlockingRx( void ); - -/*! - ***************************************************************************** - * \brief Transceive Blocking - * - * This is method triggers a Transceive and executes it blocking until it - * has been completed - * - * \param[in] txBuf : Buffer where outgoing message is located - * \param[in] txBufLen : Length of the outgoing message in bytes - * \param[out] rxBuf : Buffer where incoming message will be placed - * \param[in] rxBufLen : Maximum length of the incoming message in bytes - * \param[out] actLen : Actual received length in bytes - * \param[in] flags : TransceiveFlags indication special handling - * \param[in] fwt : Frame Waiting Time in 1/fc - * - * \return ERR_NONE : Transceive done with no error - * \return ERR_BUSY : Transceive ongoing - * \return ERR_XXXX : Error occurred - * \return ERR_TIMEOUT : No response - * \return ERR_FRAMING : Framing error detected - * \return ERR_PAR : Parity error detected - * \return ERR_CRC : CRC error detected - * \return ERR_LINK_LOSS : Link Loss - External Field is Off - * \return ERR_RF_COLLISION : Collision detected - * \return ERR_IO : Internal error - ***************************************************************************** - */ -ReturnCode rfalTransceiveBlockingTxRx( uint8_t* txBuf, uint16_t txBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t* actLen, uint32_t flags, uint32_t fwt ); - - - -/***************************************************************************** - * Listen Mode * - *****************************************************************************/ - -/*! - ***************************************************************************** - * \brief Is external Field On - * - * Checks if external field (other peer/device) is on/detected - * - * \return true External field is On - * \return false No external field is detected - * - ***************************************************************************** - */ -bool rfalIsExtFieldOn( void ); - - -/*! - ***************************************************************************** - * \brief Listen Mode start - * - * Configures RF Chip to go into listen mode enabling the given technologies - * - * - * \param[in] lmMask: mask with the enabled/disabled listen modes - * use: RFAL_LM_MASK_NFCA ; RFAL_LM_MASK_NFCB ; - * RFAL_LM_MASK_NFCF ; RFAL_LM_MASK_ACTIVE_P2P - * \param[in] confA: pointer to Passive A configurations (NULL if disabled) - * \param[in] confB: pointer to Passive B configurations (NULL if disabled) - * \param[in] confF: pointer to Passive F configurations (NULL if disabled) - * \param[in] rxBuf: buffer to place incoming data - * \param[in] rxBufLen: length in bits of rxBuf - * \param[in] rxLen: pointer to write the data length in bits placed into rxBuf - * - * - * \return ERR_PARAM Invalid parameter - * \return ERR_REQUEST Invalid listen mode mask - * \return ERR_NONE Done with no error - * - ***************************************************************************** - */ -ReturnCode rfalListenStart( uint32_t lmMask, const rfalLmConfPA *confA, const rfalLmConfPB *confB, const rfalLmConfPF *confF, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rxLen ); - - -/*! - ***************************************************************************** - * \brief Listen Mode start Sleeping - * - * - ***************************************************************************** - */ -ReturnCode rfalListenSleepStart( rfalLmState sleepSt, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rxLen ); - - -/*! - ***************************************************************************** - * \brief Listen Mode Stop - * - * Disables the listen mode on the RF Chip - * - * \warning the listen mode will be disabled immediately on the RFchip regardless - * of any ongoing operations like Transceive - * - * \return ERR_NONE Done with no error - * - ***************************************************************************** - */ -ReturnCode rfalListenStop( void ); - - -/*! - ***************************************************************************** - * \brief Listen Mode get state - * - * Sets the new state of the Listen Mode and applies the necessary changes - * on the RF Chip - * - * \param[out] dataFlag: indicates that Listen Mode has rcvd data and caller - * must process it. The received message is located - * at the rxBuf passed on rfalListenStart(). - * rfalListenSetState() will clear this flag - * if NULL output parameter will no be written/returned - * \param[out] lastBR: bit rate detected of the last initiator request - * if NULL output parameter will no be written/returned - * - * \return rfalLmState RFAL_LM_STATE_NOT_INIT : LM not initialized properly - * Any Other : LM State - * - ***************************************************************************** - */ -rfalLmState rfalListenGetState( bool *dataFlag, rfalBitRate *lastBR ); - - -/*! - ***************************************************************************** - * \brief Listen Mode set state - * - * Sets the new state of the Listen Mode and applies the necessary changes - * on the RF Chip - * - * \param[in] newSt : New state to go to - * - * \return ERR_WRONG_STATE : Not initialized properly - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : Done with no error - * - ***************************************************************************** - */ -ReturnCode rfalListenSetState( rfalLmState newSt ); - - -/***************************************************************************** - * Wake-Up Mode * - *****************************************************************************/ - -/*! - ***************************************************************************** - * \brief Wake-Up Mode Start - * - * Sets the RF Chip in Low Power Wake-Up Mode according to the given - * configuration. - * - * \param[in] config : Generic Wake-Up configuration provided by lower - * layers. If NULL will automatically configure the - * Wake-Up mode - * - * \return ERR_WRONG_STATE : Not initialized properly - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : Done with no error - * - ***************************************************************************** - */ -ReturnCode rfalWakeUpModeStart( const rfalWakeUpConfig *config ); - - -/*! - ***************************************************************************** - * \brief Wake-Up Has Woke - * - * Returns true if the Wake-Up mode is enabled and it has already received - * the indication from the RF Chip that the surrounding environment has changed - * and flagged at least one wake-Up interrupt - * - * \return true : Wake-Up mode enabled and has received a wake-up IRQ - * \return false : no Wake-Up IRQ has been received - * - ***************************************************************************** - */ -bool rfalWakeUpModeHasWoke( void ); - - -/*! - ***************************************************************************** - * \brief Wake-Up Mode Stop - * - * Stops the Wake-Up Mode - * - * \return ERR_WRONG_STATE : Not initialized properly - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : Done with no error - * - ***************************************************************************** - */ -ReturnCode rfalWakeUpModeStop( void ); - - -#endif /* RFAL_RF_H */ - - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_st25tb.h b/Software/Middlewares/ST/rfal/Inc/rfal_st25tb.h deleted file mode 100644 index 12a18a8..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_st25tb.h +++ /dev/null @@ -1,355 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_st25tb.h - * - * \author Gustavo Patricio - * - * \brief Implementation of ST25TB interface - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup ST25TB - * \brief RFAL ST25TB Module - * @{ - * - */ - - -#ifndef RFAL_ST25TB_H -#define RFAL_ST25TB_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" -#include "rfal_nfcb.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_ST25TB_CHIP_ID_LEN 1U /*!< ST25TB chip ID length */ -#define RFAL_ST25TB_CRC_LEN 2U /*!< ST25TB CRC length */ -#define RFAL_ST25TB_UID_LEN 8U /*!< ST25TB Unique ID length */ -#define RFAL_ST25TB_BLOCK_LEN 4U /*!< ST25TB Data Block length */ - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - - - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ -typedef uint8_t rfalSt25tbUID[RFAL_ST25TB_UID_LEN]; /*!< ST25TB UID type */ -typedef uint8_t rfalSt25tbBlock[RFAL_ST25TB_BLOCK_LEN]; /*!< ST25TB Block type */ - - -/*! ST25TB listener device (PICC) struct */ -typedef struct -{ - uint8_t chipID; /*!< Device's session Chip ID */ - rfalSt25tbUID UID; /*!< Device's UID */ - bool isDeselected; /*!< Device deselect flag */ -}rfalSt25tbListenDevice; - - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief Initialize ST25TB Poller mode - * - * This methods configures RFAL RF layer to perform as a - * ST25TB Poller/RW including all default timings - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerInitialize( void ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Check Presence - * - * This method checks if a ST25TB Listen device (PICC) is present on the field - * by sending an Initiate command - * - * \param[out] chipId : if successfully retrieved, the device's chip ID - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_RF_COLLISION : Collision detected one or more device in the field - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerCheckPresence( uint8_t *chipId ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Collision Resolution - * - * This method performs ST25TB Collision resolution, selects the each device, - * retrieves its UID and then deselects. - * In case only one device is identified the ST25TB device is left in select - * state. - * - * \param[in] devLimit : device limit value, and size st25tbDevList - * \param[out] st25tbDevList : ST35TB listener device info - * \param[out] devCnt : Devices found counter - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_RF_COLLISION : Collision detected one or more device in the field - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt ); - -/*! - ***************************************************************************** - * \brief ST25TB Poller Initiate - * - * This method sends an Initiate command - * - * If a single device responds the chip ID will be retrieved - * - * \param[out] chipId : chip ID of the device - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerInitiate( uint8_t *chipId ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Pcall - * - * This method sends a Pcall command - * If successful the device's chip ID will be retrieved - * - * \param[out] chipId : Chip ID of the device - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerPcall( uint8_t *chipId ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Slot Marker - * - * This method sends a Slot Marker - * - * If a single device responds the chip ID will be retrieved - * - * \param[in] slotNum : Slot Number - * \param[out] chipIdRes : Chip ID of the device - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerSlotMarker( uint8_t slotNum, uint8_t *chipIdRes ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Select - * - * This method sends a ST25TB Select command with the given chip ID. - * - * If the device is already in Selected state and receives an incorrect chip - * ID, it goes into Deselected state - * - * \param[in] chipId : chip ID of the device to be selected - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerSelect( uint8_t chipId ); - - -/*! - ***************************************************************************** - * \brief ST25TB Get UID - * - * This method sends a Get_UID command - * - * If a single device responds the chip UID will be retrieved - * - * \param[out] UID : UID of the found device - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerGetUID( rfalSt25tbUID *UID ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Read Block - * - * This method reads a block of the ST25TB - * - * \param[in] blockAddress : address of the block to be read - * \param[out] blockData : location to place the data read from block - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerReadBlock( uint8_t blockAddress, rfalSt25tbBlock *blockData ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Write Block - * - * This method writes a block of the ST25TB - * - * \param[in] blockAddress : address of the block to be written - * \param[in] blockData : data to be written on the block - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerWriteBlock( uint8_t blockAddress, const rfalSt25tbBlock *blockData ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Completion - * - * This method sends a completion command to the ST25TB. After the - * completion the card no longer will reply to any command. - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerCompletion( void ); - - -/*! - ***************************************************************************** - * \brief ST25TB Poller Reset to Inventory - * - * This method sends a Reset to Inventory command to the ST25TB. - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_TIMEOUT : Timeout error, no listener device detected - * \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalSt25tbPollerResetToInventory( void ); - - -#endif /* RFAL_ST25TB_H */ - -/** - * @} - * - * @} - * - * @} - */ - diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_st25xv.h b/Software/Middlewares/ST/rfal/Inc/rfal_st25xv.h deleted file mode 100644 index 0927e0a..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_st25xv.h +++ /dev/null @@ -1,729 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_st25xv.h - * - * \author Gustavo Patricio - * - * \brief NFC-V ST25 NFC-V Tag specific features - * - * This module provides support for ST's specific features available on - * NFC-V (ISO15693) tag families: ST25D, ST25TV, M24LR - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup ST25xV - * \brief RFAL ST25xV Module - * @{ - * - */ - -#ifndef RFAL_ST25xV_H -#define RFAL_ST25xV_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_nfc.h" -#include "rfal_rf.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - - -#define RFAL_NFCV_BLOCKNUM_M24LR_LEN 2U /*!< Block Number length of MR24LR tags: 16 bits */ -#define RFAL_NFCV_ST_IC_MFG_CODE 0x02 /*!< ST IC Mfg code (used for custom commands) */ - -/*! - ***************************************************************************** - * \brief NFC-V Poller Read Single Block (M24LR) - * - * Reads a Single Block from a M24LR tag which has the number of blocks - * bigger than 256 (M24LR16 ; M24LR64) - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * default: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] blockNum : Number of the block to read (16 bits) - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerM24LRReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Read Single Block (M24LR) - * - * Reads a Single Block from a M24LR tag which has the number of blocks - * bigger than 256 (M24LR16 ; M24LR64) using ST Fast mode - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * default: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] blockNum : Number of the block to read (16 bits) - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerM24LRFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Write Single Block (M24LR) - * - * Writes a Single Block from a M24LR tag which has the number of blocks - * bigger than 256 (M24LR16 ; M24LR64) - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be written - * if not provided Select mode will be used - * \param[in] blockNum : Number of the block to write (16 bits) - * \param[in] wrData : data to be written on the given block - * \param[in] blockLen : number of bytes of a block - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerM24LRWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Read Multiple Blocks (M24LR) - * - * Reads Multiple Blocks from a device from a M24LR tag which has the number of blocks - * bigger than 256 (M24LR16 ; M24LR64) - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] firstBlockNum : first block to be read (16 bits) - * \param[in] numOfBlocks : number of block to read - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerM24LRReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Read Multiple Blocks (M24LR) - * - * Reads Multiple Blocks from a device from a M24LR tag which has the number of blocks - * bigger than 256 (M24LR16 ; M24LR64) using ST Fast mode - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] firstBlockNum : first block to be read (16 bits) - * \param[in] numOfBlocks : number of block to read - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerM24LRFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Read Single Block - * - * Reads a Single Block from a device (VICC) using ST Fast mode - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] blockNum : Number of the block to read - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Read Multiple Blocks - * - * Reads Multiple Blocks from a device (VICC) using ST Fast mode - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] firstBlockNum : first block to be read - * \param[in] numOfBlocks : number of block to read - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Extended Read Single Block - * - * Reads a Single Block from a device (VICC) supporting extended commands using ST Fast mode - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] blockNum : Number of the block to read (16 bits) - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Extended Read Multiple Blocks - * - * Reads Multiple Blocks from a device (VICC) supporting extended commands using ST Fast mode - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] firstBlockNum : first block to be read (16 bits) - * \param[in] numOfBlocks : number of consecutive blocks to read (16 bits) - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastExtReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Read Configuration - * - * Reads static configuration registers at the Pointer address - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] pointer : Pointer address - * \param[out] regValue : Register value - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerReadConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Write Configuration - * - * Writes static configuration registers at the Pointer address - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] pointer : Pointer address - * \param[in] regValue : Register value - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerWriteConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue ); - - -/*! - ***************************************************************************** - * \brief NFC-V Poller Read Dynamic Configuration - * - * Reads dynamic registers at the Pointer address - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] pointer : Pointer address - * \param[out] regValue : Register value - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Write Dynamic Configuration - * - * Writes dynamic registers at the Pointer address - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] pointer : Pointer address - * \param[in] regValue : Register value - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Read Dynamic Configuration - * - * Reads dynamic registers at the Pointer address using ST Fast mode - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] pointer : Pointer address - * \param[out] regValue : Register value - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Write Dynamic Configuration - * - * Writes dynamic registers at the Pointer address using ST Fast mode - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] pointer : Pointer address - * \param[in] regValue : Register value - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Present Password - * - * Sends the Present Password command - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] pwdNum : Password number - * \param[in] pwd : Password - * \param[in] pwdLen : Password length - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerPresentPassword( uint8_t flags, const uint8_t* uid, uint8_t pwdNum, const uint8_t* pwd, uint8_t pwdLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Get Random Number - * - * Returns a 16 bit random number - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerGetRandomNumber( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Read Message length - * - * Sends a Read Message Length message to retrieve the value of MB_LEN_Dyn - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[out] msgLen : Message Length - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerReadMessageLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Read Message length - * - * Sends a Fast Read Message Length message to retrieve the value of MB_LEN_Dyn using ST Fast mode. - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[out] msgLen : Message Length - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastReadMsgLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Read Message - * - * Reads up to 256 bytes in the Mailbox from the location - * specified by MBpointer and sends back their value in the rxBuf response. - * First MailBox location is '00'. When Number of bytes is set to 00h - * and MBPointer is equals to 00h, the MB_LEN bytes of the full message - * are returned. Otherwise, Read Message command returns (Number of Bytes + 1) bytes - * (i.e. 01h returns 2 bytes, FFh returns 256 bytes). - * An error is reported if (Pointer + Nb of bytes + 1) is greater than the message length. - * RF Reading of the last byte of the mailbox message automatically clears b1 - * of MB_CTRL_Dyn HOST_PUT_MSG, and allows RF to put a new message. - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] mbPointer : MPpointer - * \param[in] numBytes : number of bytes - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Read Message - * - * Reads up to 256 bytes in the Mailbox from the location - * specified by MBpointer and sends back their value in the rxBuf response using ST Fast mode. - * First MailBox location is '00'. When Number of bytes is set to 00h - * and MBPointer is equals to 00h, the MB_LEN bytes of the full message - * are returned. Otherwise, Read Message command returns (Number of Bytes + 1) bytes - * (i.e. 01h returns 2 bytes, FFh returns 256 bytes). - * An error is reported if (Pointer + Nb of bytes + 1) is greater than the message length. - * RF Reading of the last byte of the mailbox message automatically clears b1 - * of MB_CTRL_Dyn HOST_PUT_MSG, and allows RF to put a new message. - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] mbPointer : MPpointer - * \param[in] numBytes : number of bytes - * \param[out] rxBuf : buffer to store response (also with RES_FLAGS) - * \param[in] rxBufLen : length of rxBuf - * \param[out] rcvLen : number of bytes received - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Write Message - * - * Sends Write message Command - * - * On receiving the Write Message command, the ST25DVxxx puts the data contained - * in the request into the Mailbox buffer, update the MB_LEN_Dyn register, and - * set bit RF_PUT_MSG in MB_CTRL_Dyn register. It then reports if the write operation was successful - * in the response. The ST25DVxxx Mailbox contains up to 256 data bytes which are filled from the - * first location '00'. MSGlength parameter of the command is the number of - * Data bytes minus 1 (00 for 1 byte of data, FFh for 256 bytes of data). - * Write Message could be executed only when Mailbox is accessible by RF. - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] msgLen : MSGLen number of Data bytes minus 1 - * \param[in] msgData : Message Data - * \param[out] txBuf : buffer to used to build the Write Message command - * \param[in] txBufLen : length of txBuf - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen ); - -/*! - ***************************************************************************** - * \brief NFC-V Poller Fast Write Message - * - * Sends Fast Write message Command using ST Fast mode - * - * On receiving the Write Message command, the ST25DVxxx puts the data contained - * in the request into the Mailbox buffer, update the MB_LEN_Dyn register, and - * set bit RF_PUT_MSG in MB_CTRL_Dyn register. It then reports if the write operation was successful - * in the response. The ST25DVxxx Mailbox contains up to 256 data bytes which are filled from the - * first location '00'. MSGlength parameter of the command is the number of - * Data bytes minus 1 (00 for 1 byte of data, FFh for 256 bytes of data). - * Write Message could be executed only when Mailbox is accessible by RF. - * - * \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option - * for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT - * \param[in] uid : UID of the device to be put to be read - * if not provided Select mode will be used - * \param[in] msgLen : MSGLen number of Data bytes minus 1 - * \param[in] msgData : Message Data - * \param[out] txBuf : buffer to used to build the Write Message command - * \param[in] txBufLen : length of txBuf - * - * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode - * \return ERR_PARAM : Invalid parameters - * \return ERR_IO : Generic internal error - * \return ERR_CRC : CRC error detected - * \return ERR_FRAMING : Framing error detected - * \return ERR_PROTO : Protocol error detected - * \return ERR_TIMEOUT : Timeout error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalST25xVPollerFastWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen ); - -#endif /* RFAL_ST25xV_H */ - -/** - * @} - * - * @} - * - * @} - */ - diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_t1t.h b/Software/Middlewares/ST/rfal/Inc/rfal_t1t.h deleted file mode 100644 index 0f619f9..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_t1t.h +++ /dev/null @@ -1,187 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_t1t.h - * - * \author Gustavo Patricio - * - * \brief Provides NFC-A T1T convenience methods and definitions - * - * This module provides an interface to perform as a NFC-A Reader/Writer - * to handle a Type 1 Tag T1T (Topaz) - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup T1T - * \brief RFAL T1T Module - * @{ - * - */ - - -#ifndef RFAL_T1T_H -#define RFAL_T1T_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ -#define RFAL_T1T_UID_LEN 4 /*!< T1T UID length of cascade level 1 only tag */ -#define RFAL_T1T_HR_LENGTH 2 /*!< T1T HR(Header ROM) length */ - -#define RFAL_T1T_HR0_NDEF_MASK 0xF0 /*!< T1T HR0 NDEF capability mask T1T 1.2 2.2.2 */ -#define RFAL_T1T_HR0_NDEF_SUPPORT 0x10 /*!< T1T HR0 NDEF capable value T1T 1.2 2.2.2 */ - - -/*! NFC-A T1T (Topaz) command set */ -typedef enum -{ - RFAL_T1T_CMD_RID = 0x78, /*!< T1T Read UID */ - RFAL_T1T_CMD_RALL = 0x00, /*!< T1T Read All */ - RFAL_T1T_CMD_READ = 0x01, /*!< T1T Read */ - RFAL_T1T_CMD_WRITE_E = 0x53, /*!< T1T Write with erase (single byte) */ - RFAL_T1T_CMD_WRITE_NE = 0x1A /*!< T1T Write with no erase (single byte) */ -} rfalT1Tcmds; - - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - - -/*! NFC-A T1T (Topaz) RID_RES Digital 1.1 10.6.2 & Table 50 */ -typedef struct -{ - uint8_t hr0; /*!< T1T Header ROM: HR0 */ - uint8_t hr1; /*!< T1T Header ROM: HR1 */ - uint8_t uid[RFAL_T1T_UID_LEN]; /*!< T1T UID */ -} rfalT1TRidRes; - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - - -/*! - ***************************************************************************** - * \brief Initialize NFC-A T1T Poller mode - * - * This methods configures RFAL RF layer to perform as a - * NFC-A T1T Poller/RW (Topaz) including all default timings - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT1TPollerInitialize( void ); - - -/*! - ***************************************************************************** - * \brief NFC-A T1T Poller RID - * - * This method reads the UID of a NFC-A T1T Listener device - * - * - * \param[out] ridRes : pointer to place the RID_RES - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT1TPollerRid( rfalT1TRidRes *ridRes ); - - -/*! - ***************************************************************************** - * \brief NFC-A T1T Poller RALL - * - * This method send a Read All command to a NFC-A T1T Listener device - * - * - * \param[in] uid : the UID of the device to read data - * \param[out] rxBuf : pointer to place the read data - * \param[in] rxBufLen : size of rxBuf - * \param[out] rxRcvdLen : actual received data - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT1TPollerRall( const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxRcvdLen ); - - -/*! - ***************************************************************************** - * \brief NFC-A T1T Poller Write - * - * This method writes the given data on the address of a NFC-A T1T Listener device - * - * - * \param[in] uid : the UID of the device to read data - * \param[in] address : address to write the data - * \param[in] data : the data to be written - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT1TPollerWrite( const uint8_t* uid, uint8_t address, uint8_t data ); - -#endif /* RFAL_T1T_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_t2t.h b/Software/Middlewares/ST/rfal/Inc/rfal_t2t.h deleted file mode 100644 index c153a89..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_t2t.h +++ /dev/null @@ -1,153 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_t2t.h - * - * \author Gustavo Patricio - * - * \brief Provides NFC-A T2T convenience methods and definitions - * - * This module provides an interface to perform as a NFC-A Reader/Writer - * to handle a Type 2 Tag T2T - * - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup T2T - * \brief RFAL T2T Module - * @{ - * - */ - - -#ifndef RFAL_T2T_H -#define RFAL_T2T_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_T2T_BLOCK_LEN 4U /*!< T2T block length */ -#define RFAL_T2T_READ_DATA_LEN (4U * RFAL_T2T_BLOCK_LEN) /*!< T2T READ data length */ -#define RFAL_T2T_WRITE_DATA_LEN RFAL_T2T_BLOCK_LEN /*!< T2T WRITE data length */ - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief NFC-A T2T Poller Read - * - * This method sends a Read command to a NFC-A T2T Listener device - * - * - * \param[in] blockNum : Number of the block to read - * \param[out] rxBuf : pointer to place the read data - * \param[in] rxBufLen : size of rxBuf (RFAL_T2T_READ_DATA_LEN) - * \param[out] rcvLen : actual received data - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT2TPollerRead( uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); - - -/*! - ***************************************************************************** - * \brief NFC-A T2T Poller Write - * - * This method sends a Write command to a NFC-A T2T Listener device - * - * - * \param[in] blockNum : Number of the block to write - * \param[in] wrData : data to be written on the given block - * size must be of RFAL_T2T_WRITE_DATA_LEN - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT2TPollerWrite( uint8_t blockNum, const uint8_t* wrData ); - - -/*! - ***************************************************************************** - * \brief NFC-A T2T Poller Sector Select - * - * This method sends a Sector Select commands to a NFC-A T2T Listener device - * - * \param[in] sectorNum : Sector Number - * - * \return ERR_WRONG_STATE : RFAL not initialized or mode not set - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ - ReturnCode rfalT2TPollerSectorSelect( uint8_t sectorNum ); - -#endif /* RFAL_T2T_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Inc/rfal_t4t.h b/Software/Middlewares/ST/rfal/Inc/rfal_t4t.h deleted file mode 100644 index 0b49339..0000000 --- a/Software/Middlewares/ST/rfal/Inc/rfal_t4t.h +++ /dev/null @@ -1,365 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_t4t.h - * - * \author Gustavo Patricio - * - * \brief Provides convenience methods and definitions for T4T (ISO7816-4) - * - * This module provides an interface to exchange T4T APDUs according to - * NFC Forum T4T and ISO7816-4 - * - * This implementation was based on the following specs: - * - ISO/IEC 7816-4 3rd Edition 2013-04-15 - * - NFC Forum T4T Technical Specification 1.0 2017-08-28 - * - * \addtogroup RFAL - * @{ - * - * \addtogroup RFAL-AL - * \brief RFAL Abstraction Layer - * @{ - * - * \addtogroup T4T - * \brief RFAL T4T Module - * @{ - * - */ - - -#ifndef RFAL_T4T_H -#define RFAL_T4T_H - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "platform.h" -#include "st_errno.h" -#include "rfal_rf.h" -#include "rfal_isoDep.h" - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_T4T_MAX_CAPDU_PROLOGUE_LEN 4U /*!< Command-APDU prologue length (CLA INS P1 P2) */ -#define RFAL_T4T_LE_LEN 1U /*!< Le Expected Response Length (short field coding) */ -#define RFAL_T4T_LC_LEN 1U /*!< Lc Data field length (short field coding) */ -#define RFAL_T4T_MAX_RAPDU_SW1SW2_LEN 2U /*!< SW1 SW2 length */ -#define RFAL_T4T_CLA 0x00U /*!< Class byte (contains 00h because secure message are not used) */ - -#define RFAL_T4T_ISO7816_P1_SELECT_BY_DF_NAME 0x04U /*!< P1 value for Select by name */ -#define RFAL_T4T_ISO7816_P1_SELECT_BY_FILEID 0x00U /*!< P1 value for Select by file identifier */ -#define RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00U /*!< b2b1 P2 value for First or only occurence */ -#define RFAL_T4T_ISO7816_P2_SELECT_RETURN_FCI_TEMPLATE 0x00U /*!< b4b3 P2 value for Return FCI template */ -#define RFAL_T4T_ISO7816_P2_SELECT_NO_RESPONSE_DATA 0x0CU /*!< b4b3 P2 value for No responce data */ - -#define RFAL_T4T_ISO7816_STATUS_COMPLETE 0x9000U /*!< Command completed \ Normal processing - No further qualification*/ - - -/* -****************************************************************************** -* GLOBAL VARIABLES -****************************************************************************** -*/ - - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ -/*! NFC-A T4T Command-APDU structure */ -typedef struct -{ - uint8_t CLA; /*!< Class byte */ - uint8_t INS; /*!< Instruction byte */ - uint8_t P1; /*!< Parameter byte 1 */ - uint8_t P2; /*!< Parameter byte 2 */ - uint8_t Lc; /*!< Data field length */ - bool LcFlag; /*!< Lc flag (append Lc when true) */ - uint8_t Le; /*!< Expected Response Length */ - bool LeFlag; /*!< Le flag (append Le when true) */ - - rfalIsoDepApduBufFormat *cApduBuf; /*!< Command-APDU buffer (Tx) */ - uint16_t *cApduLen; /*!< Command-APDU Length */ -}rfalT4tCApduParam; - -/*! NFC-A T4T Response-APDU structure */ -typedef struct -{ - rfalIsoDepApduBufFormat *rApduBuf; /*!< Response-APDU buffer (Rx) */ - uint16_t rcvdLen; /*!< Full response length */ - uint16_t rApduBodyLen; /*!< Response body length */ - uint16_t statusWord; /*!< R-APDU Status Word SW1|SW2 */ -}rfalT4tRApduParam; - - - -/*! NFC-A T4T command set T4T 1.0 & ISO7816-4 2013 Table 4 */ -typedef enum -{ - RFAL_T4T_INS_SELECT = 0xA4U, /*!< T4T Select */ - RFAL_T4T_INS_READBINARY = 0xB0U, /*!< T4T ReadBinary */ - RFAL_T4T_INS_UPDATEBINARY = 0xD6U, /*!< T4T UpdateBinay */ - RFAL_T4T_INS_READBINARY_ODO = 0xB1U, /*!< T4T ReadBinary using ODO */ - RFAL_T4T_INS_UPDATEBINARY_ODO = 0xD7U /*!< T4T UpdateBinay using ODO */ -} rfalT4tCmds; - -/* -****************************************************************************** -* GLOBAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/*! - ***************************************************************************** - * \brief T4T Compose APDU - * - * This method computes a C-APDU according to NFC Forum T4T and ISO7816-4. - * - * If C-APDU contains data to be sent, it must be placed inside the buffer - * rfalT4tTxRxApduParam.txRx.cApduBuf.apdu and signaled by Lc - * - * To transceive the formed APDU the ISO-DEP layer shall be used - * - * \see rfalIsoDepStartApduTransceive() - * \see rfalIsoDepGetApduTransceiveStatus() - * \see rfalT4TPollerParseRAPDU() - * - * \warning The ISO-DEP module is used to perform the tranceive. Usually - * activation has been done via ISO-DEP activatiavtion. If not - * please call rfalIsoDepInitialize() before. - * - * \param[in,out] apduParam : APDU parameters - * apduParam.cApduLen will contain the APDU length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerComposeCAPDU( rfalT4tCApduParam *apduParam ); - - -/*! - ***************************************************************************** - * \brief T4T Parse R-APDU - * - * This method parses a R-APDU according to NFC Forum T4T and ISO7816-4. - * It will extract the data length and check if the Satus word is expected. - * - * \param[in,out] apduParam : APDU parameters - * apduParam.rApduBodyLen will contain the data length - * apduParam.statusWord will contain the SW1 and SW2 - * - * \return ERR_REQUEST : Status word (SW1 SW2) different from 9000 - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerParseRAPDU( rfalT4tRApduParam *apduParam ); - -/*! - ***************************************************************************** - * \brief T4T Compose Select Application APDU - * - * This method computes a Select Application APDU according to NFC Forum T4T - * - * To transceive the formed APDU the ISO-DEP layer shall be used - * - * \see rfalIsoDepStartApduTransceive() - * \see rfalIsoDepGetApduTransceiveStatus() - * - * \param[out] cApduBuf : buffer where the C-APDU will be placed - * \param[in] aid : Application ID to be used - * \param[in] aidLen : Application ID length - * \param[out] cApduLen : Composed C-APDU length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerComposeSelectAppl( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* aid, uint8_t aidLen, uint16_t *cApduLen ); - -/*! - ***************************************************************************** - * \brief T4T Compose Select File APDU - * - * This method computes a Select File APDU according to NFC Forum T4T - * - * To transceive the formed APDU the ISO-DEP layer shall be used - * - * \see rfalIsoDepStartApduTransceive() - * \see rfalIsoDepGetApduTransceiveStatus() - * - * \param[out] cApduBuf : buffer where the C-APDU will be placed - * \param[in] fid : File ID to be used - * \param[in] fidLen : File ID length - * \param[out] cApduLen : Composed C-APDU length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerComposeSelectFile( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen ); - -/*! - ***************************************************************************** - * \brief T4T Compose Select File APDU for Mapping Version 1 - * - * This method computes a Select File APDU according to NFC Forum T4TOP_v1.0 - * - * To transceive the formed APDU the ISO-DEP layer shall be used - * - * \see rfalIsoDepStartApduTransceive() - * \see rfalIsoDepGetApduTransceiveStatus() - * - * \param[out] cApduBuf : buffer where the C-APDU will be placed - * \param[in] fid : File ID to be used - * \param[in] fidLen : File ID length - * \param[out] cApduLen : Composed C-APDU length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerComposeSelectFileV1Mapping( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen ); - -/*! - ***************************************************************************** - * \brief T4T Compose Read Data APDU - * - * This method computes a Read Data APDU according to NFC Forum T4T - * - * To transceive the formed APDU the ISO-DEP layer shall be used - * - * \see rfalIsoDepStartApduTransceive() - * \see rfalIsoDepGetApduTransceiveStatus() - * - * \param[out] cApduBuf : buffer where the C-APDU will be placed - * \param[in] offset : File offset - * \param[in] expLen : Expected length (Le) - * \param[out] cApduLen : Composed C-APDU length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerComposeReadData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, uint8_t expLen, uint16_t *cApduLen ); - -/*! - ***************************************************************************** - * \brief T4T Compose Read Data ODO APDU - * - * This method computes a Read Data ODO APDU according to NFC Forum T4T - * - * To transceive the formed APDU the ISO-DEP layer shall be used - * - * \see rfalIsoDepStartApduTransceive() - * \see rfalIsoDepGetApduTransceiveStatus() - * - * \param[out] cApduBuf : buffer where the C-APDU will be placed - * \param[in] offset : File offset - * \param[in] expLen : Expected length (Le) - * \param[out] cApduLen : Composed C-APDU length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerComposeReadDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, uint8_t expLen, uint16_t *cApduLen ); - -/*! - ***************************************************************************** - * \brief T4T Compose Write Data APDU - * - * This method computes a Write Data APDU according to NFC Forum T4T - * - * To transceive the formed APDU the ISO-DEP layer shall be used - * - * \see rfalIsoDepStartApduTransceive() - * \see rfalIsoDepGetApduTransceiveStatus() - * - * \param[out] cApduBuf : buffer where the C-APDU will be placed - * \param[in] offset : File offset - * \param[in] data : Data to be written - * \param[in] dataLen : Data length to be written (Lc) - * \param[out] cApduLen : Composed C-APDU length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerComposeWriteData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen ); - -/*! - ***************************************************************************** - * \brief T4T Compose Write Data ODO APDU - * - * This method computes a Write Data ODO sAPDU according to NFC Forum T4T - * - * To transceive the formed APDU the ISO-DEP layer shall be used - * - * \see rfalIsoDepStartApduTransceive() - * \see rfalIsoDepGetApduTransceiveStatus() - * - * \param[out] cApduBuf : buffer where the C-APDU will be placed - * \param[in] offset : File offset - * \param[in] data : Data to be written - * \param[in] dataLen : Data length to be written (Lc) - * \param[out] cApduLen : Composed C-APDU length - * - * \return ERR_PARAM : Invalid parameter - * \return ERR_PROTO : Protocol error - * \return ERR_NONE : No error - ***************************************************************************** - */ -ReturnCode rfalT4TPollerComposeWriteDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen ); - -#endif /* RFAL_T4T_H */ - -/** - * @} - * - * @} - * - * @} - */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_analogConfig.c b/Software/Middlewares/ST/rfal/Src/rfal_analogConfig.c deleted file mode 100644 index 64b646b..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_analogConfig.c +++ /dev/null @@ -1,417 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_analogConfig.c - * - * \author bkam - * - * \brief Funcitons to manage and set analog settings. - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_analogConfig.h" -#include "rfal_chip.h" -#include "st_errno.h" -#include "platform.h" -#include "utils.h" - - -/* Check whether the Default Analog settings are to be used or custom ones */ -#ifdef RFAL_ANALOG_CONFIG_CUSTOM - extern const uint8_t* rfalAnalogConfigCustomSettings; - extern const uint16_t rfalAnalogConfigCustomSettingsLength; -#else - #include "rfal_analogConfigTbl.h" -#endif - -/* - ****************************************************************************** - * DEFINES - ****************************************************************************** - */ - - -#define RFAL_TEST_REG 0x0080U /*!< Test Register indicator */ - -/* - ****************************************************************************** - * MACROS - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL DATA TYPES - ****************************************************************************** - */ - -#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG - static uint8_t gRfalAnalogConfig[RFAL_ANALOG_CONFIG_TBL_SIZE]; /*!< Analog Configuration Settings List */ -#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */ - - -/*! Struct for Analog Config Look Up Table Update */ -typedef struct { - const uint8_t *currentAnalogConfigTbl; /*!< Reference to start of current Analog Configuration */ - uint16_t configTblSize; /*!< Total size of Analog Configuration */ - bool ready; /*!< Indicate if Look Up Table is complete and ready for use */ -} rfalAnalogConfigMgmt; - -static rfalAnalogConfigMgmt gRfalAnalogConfigMgmt; /*!< Analog Configuration LUT management */ - -/* - ****************************************************************************** - * LOCAL TABLES - ****************************************************************************** - */ - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ -static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset ); - -#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG - static void rfalAnalogConfigPtrUpdate( const uint8_t* analogConfigTbl ); -#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */ - -/* - ****************************************************************************** - * GLOBAL VARIABLE DEFINITIONS - ****************************************************************************** - */ - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - -void rfalAnalogConfigInitialize( void ) -{ - /* Use default Analog configuration settings in Flash by default. */ - -/* Check whether the Default Analog settings are to be used or custom ones */ -#ifdef RFAL_ANALOG_CONFIG_CUSTOM - gRfalAnalogConfigMgmt.currentAnalogConfigTbl = (const uint8_t *)&rfalAnalogConfigCustomSettings; - gRfalAnalogConfigMgmt.configTblSize = rfalAnalogConfigCustomSettingsLength; -#else - gRfalAnalogConfigMgmt.currentAnalogConfigTbl = (const uint8_t *)&rfalAnalogConfigDefaultSettings; - gRfalAnalogConfigMgmt.configTblSize = sizeof(rfalAnalogConfigDefaultSettings); -#endif - - gRfalAnalogConfigMgmt.ready = true; -} /* rfalAnalogConfigInitialize() */ - - -bool rfalAnalogConfigIsReady( void ) -{ - return gRfalAnalogConfigMgmt.ready; -} - -ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize ) -{ -#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG - - /* Check if the Configuration Table exceed the Table size */ - if ( configTblSize >= RFAL_ANALOG_CONFIG_TBL_SIZE ) - { - rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */ - return ERR_NOMEM; - } - - /* Check for invalid parameters */ - if( (configTbl == NULL) || (configTblSize == 0U) ) - { - return ERR_PARAM; - } - - /* NOTE: Function does not check for the validity of the Table contents (conf IDs, conf sets, register address) */ - ST_MEMCPY( gRfalAnalogConfig, configTbl, configTblSize ); - - /* Update the total size of configuration settings */ - gRfalAnalogConfigMgmt.configTblSize = configTblSize; - - rfalAnalogConfigPtrUpdate(gRfalAnalogConfig); - return ERR_NONE; - -#else - - // If Analog Configuration Update is to be disabled - NO_WARNING(configTbl); - NO_WARNING(configTblSize); - return ERR_REQUEST; - -#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */ -} - -ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config ) -{ -#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG - - rfalAnalogConfigId configId; - rfalAnalogConfigNum numConfig; - uint8_t configSize; - - if (true == gRfalAnalogConfigMgmt.ready) - { /* First Update to the Configuration list. */ - gRfalAnalogConfigMgmt.ready = false; // invalidate the config List - gRfalAnalogConfigMgmt.configTblSize = 0; // Clear the config List - } - - configId = GETU16(config->id); - - /* Check validity of the Configuration ID. */ - if ( (RFAL_ANALOG_CONFIG_TECH_RFU <= RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) - ||((RFAL_ANALOG_CONFIG_BITRATE_6780 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)) && (RFAL_ANALOG_CONFIG_BITRATE_1OF4 > RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId))) - ||(RFAL_ANALOG_CONFIG_BITRATE_1OF256 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)) - ) - { - rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */ - return ERR_PARAM; - } - - numConfig = config->num; - configSize = (uint8_t)(sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (numConfig * sizeof(rfalAnalogConfigRegAddrMaskVal))); - - /* Check if the Configuration Set exceed the Table size. */ - if ( RFAL_ANALOG_CONFIG_TBL_SIZE <= (gRfalAnalogConfigMgmt.configTblSize + configSize) ) - { - rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */ - return ERR_NOMEM; - } - - /* NOTE: Function does not check for the validity of the Register Address. */ - ST_MEMCPY(&gRfalAnalogConfig[gRfalAnalogConfigMgmt.configTblSize], (const uint8_t*)config, configSize); - - /* Increment the total size of configuration settings. */ - gRfalAnalogConfigMgmt.configTblSize += configSize; - - /* Check if it is the last Analog Configuration to load. */ - if (RFAL_ANALOG_CONFIG_UPDATE_LAST == more) - { /* Update the Analog Configuration to the new settings. */ - rfalAnalogConfigPtrUpdate(gRfalAnalogConfig); - } - - return ERR_NONE; - -#else - - // If Analog Configuration Update is to be disabled - NO_WARNING(config); - NO_WARNING(more); - return ERR_DISABLED; - -#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */ - -} /* rfalAnalogConfigListUpdate() */ - -ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize ) -{ - /* Check if the the current table will fit into the given buffer */ - if( tblBufLen < gRfalAnalogConfigMgmt.configTblSize ) - { - return ERR_NOMEM; - } - - /* Check for invalid parameters */ - if( configTblSize == NULL ) - { - return ERR_PARAM; - } - - /* Copy the whole Table to the given buffer */ - if( gRfalAnalogConfigMgmt.configTblSize > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY( tblBuf, gRfalAnalogConfigMgmt.currentAnalogConfigTbl, gRfalAnalogConfigMgmt.configTblSize ); - } - *configTblSize = gRfalAnalogConfigMgmt.configTblSize; - - return ERR_NONE; -} - -ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig ) -{ - uint16_t configSize; - rfalAnalogConfigOffset offset = *configOffset; - rfalAnalogConfigNum numConfigSet; - - /* Check if the number of register-mask-value settings for the respective Configuration ID will fit into the buffer passed in. */ - if (gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)] > numConfig) - { - return ERR_NOMEM; - } - - /* Get the number of Configuration set */ - numConfigSet = gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)]; - - /* Pass Configuration Register-Mask-Value sets */ - configSize = (sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal))); - ST_MEMCPY( (uint8_t*) config - , &gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset] - , configSize - ); - *configOffset = offset + configSize; - - /* Check if it is the last Analog Configuration in the Table.*/ - *more = (uint8_t)((*configOffset >= gRfalAnalogConfigMgmt.configTblSize) ? RFAL_ANALOG_CONFIG_UPDATE_LAST - : RFAL_ANALOG_CONFIG_UPDATE_MORE); - - return ERR_NONE; -} /* rfalAnalogConfigListRead() */ - - -ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId ) -{ - rfalAnalogConfigOffset configOffset = 0; - rfalAnalogConfigNum numConfigSet; - rfalAnalogConfigRegAddrMaskVal *configTbl; - ReturnCode retCode = ERR_NONE; - rfalAnalogConfigNum i; - - if (true != gRfalAnalogConfigMgmt.ready) - { - return ERR_REQUEST; - } - - /* Search LUT for the specific Configuration ID. */ - while(true) - { - numConfigSet = rfalAnalogConfigSearch(configId, &configOffset); - if( RFAL_ANALOG_CONFIG_LUT_NOT_FOUND == numConfigSet ) - { - break; - } - - configTbl = (rfalAnalogConfigRegAddrMaskVal *)( (uint32_t)gRfalAnalogConfigMgmt.currentAnalogConfigTbl + (uint32_t)configOffset); - /* Increment the offset to the next index to search from. */ - configOffset += (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal)); - - if ((gRfalAnalogConfigMgmt.configTblSize + 1U) < configOffset) - { /* Error check make sure that the we do not access outside the configuration Table Size */ - return ERR_NOMEM; - } - - for ( i = 0; i < numConfigSet; i++) - { - if( (GETU16(configTbl[i].addr) & RFAL_TEST_REG) != 0U ) - { - EXIT_ON_ERR(retCode, rfalChipChangeTestRegBits( (GETU16(configTbl[i].addr) & ~RFAL_TEST_REG), configTbl[i].mask, configTbl[i].val) ); - } - else - { - EXIT_ON_ERR(retCode, rfalChipChangeRegBits( GETU16(configTbl[i].addr), configTbl[i].mask, configTbl[i].val) ); - } - } - - } /* while(found Analog Config Id) */ - - return retCode; - -} /* rfalSetAnalogConfig() */ - -/* - ****************************************************************************** - * LOCAL FUNCTIONS - ****************************************************************************** - */ - -/*! - ***************************************************************************** - * \brief Update the link to Analog Configuration LUT - * - * Update the link to the Analog Configuration LUT for the subsequent search - * of Analog Settings. - * - * \param[in] analogConfigTbl: reference to the start of the new Analog Configuration Table - * - ***************************************************************************** - */ -#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG -static void rfalAnalogConfigPtrUpdate( const uint8_t* analogConfigTbl ) -{ - - gRfalAnalogConfigMgmt.currentAnalogConfigTbl = analogConfigTbl; - gRfalAnalogConfigMgmt.ready = true; - -} /* rfalAnalogConfigPtrUpdate() */ -#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */ - - -/*! - ***************************************************************************** - * \brief Search the Analog Configuration LUT for a specific Configuration ID. - * - * Search the Analog Configuration LUT for the Configuration ID. - * - * \param[in] configId: Configuration ID to search for. - * \param[in] configOffset: Configuration Offset in Table - * - * \return number of Configuration Sets - * \return #RFAL_ANALOG_CONFIG_LUT_NOT_FOUND in case Configuration ID is not found. - ***************************************************************************** - */ -static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset ) -{ - rfalAnalogConfigId foundConfigId; - rfalAnalogConfigId configIdMaskVal; - const uint8_t *configTbl; - const uint8_t *currentConfigTbl; - uint16_t i; - - currentConfigTbl = gRfalAnalogConfigMgmt.currentAnalogConfigTbl; - configIdMaskVal = ((RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_BITRATE_MASK) - |((RFAL_ANALOG_CONFIG_TECH_CHIP == RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) ? (RFAL_ANALOG_CONFIG_TECH_MASK | RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK) : configId) - |((RFAL_ANALOG_CONFIG_NO_DIRECTION == RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId)) ? RFAL_ANALOG_CONFIG_DIRECTION_MASK : configId) - ); - - i = *configOffset; - while (i < gRfalAnalogConfigMgmt.configTblSize) - { - configTbl = ¤tConfigTbl[i]; - foundConfigId = GETU16(configTbl); - if (configId == (foundConfigId & configIdMaskVal)) - { - *configOffset = (uint16_t)(i + sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum)); - return configTbl[sizeof(rfalAnalogConfigId)]; - } - - /* If Config Id does not match, increment to next Configuration Id */ - i += (uint16_t)( sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) - + (configTbl[sizeof(rfalAnalogConfigId)] * sizeof(rfalAnalogConfigRegAddrMaskVal) ) - ); - } /* for */ - - return RFAL_ANALOG_CONFIG_LUT_NOT_FOUND; -} /* rfalAnalogConfigSearch() */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_crc.c b/Software/Middlewares/ST/rfal/Src/rfal_crc.c deleted file mode 100644 index 27384ff..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_crc.c +++ /dev/null @@ -1,86 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_crc.c - * - * \author Oliver Regenfelder - * - * \brief CRC calculation implementation - * - */ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "rfal_crc.h" - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -static uint16_t rfalCrcUpdateCcitt(uint16_t crcSeed, uint8_t dataByte); - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ -uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length) -{ - uint16_t crc = preloadValue; - uint16_t index; - - for (index = 0; index < length; index++) - { - crc = rfalCrcUpdateCcitt(crc, buf[index]); - } - - return crc; -} - -/* -****************************************************************************** -* LOCAL FUNCTIONS -****************************************************************************** -*/ -static uint16_t rfalCrcUpdateCcitt(uint16_t crcSeed, uint8_t dataByte) -{ - uint16_t crc = crcSeed; - uint8_t dat = dataByte; - - dat ^= (uint8_t)(crc & 0xFFU); - dat ^= (dat << 4); - - crc = (crc >> 8)^(((uint16_t) dat) << 8)^(((uint16_t) dat) << 3)^(((uint16_t) dat) >> 4); - - return crc; -} - diff --git a/Software/Middlewares/ST/rfal/Src/rfal_dpo.c b/Software/Middlewares/ST/rfal/Src/rfal_dpo.c deleted file mode 100644 index 95f3b5e..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_dpo.c +++ /dev/null @@ -1,240 +0,0 @@ - -/****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * $Revision: $ - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_dpo.c - * - * \author Martin Zechleitner - * - * \brief Functions to manage and set dynamic power settings. - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_dpoTbl.h" -#include "rfal_dpo.h" -#include "platform.h" -#include "rfal_rf.h" -#include "rfal_chip.h" -#include "utils.h" - - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_DPO - #define RFAL_FEATURE_DPO false /* Dynamic Power Module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_DPO - -/* - ****************************************************************************** - * LOCAL DATA TYPES - ****************************************************************************** - */ - -static bool gRfalDpoIsEnabled = false; -static uint8_t* gRfalCurrentDpo; -static uint8_t gRfalDpoTableEntries; -static uint8_t gRfalDpo[RFAL_DPO_TABLE_SIZE_MAX]; -static uint8_t gRfalDpoTableEntry; -static rfalDpoMeasureFunc gRfalDpoMeasureCallback = NULL; - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ -void rfalDpoInitialize( void ) -{ - /* Use the default Dynamic Power values */ - gRfalCurrentDpo = (uint8_t*) rfalDpoDefaultSettings; - gRfalDpoTableEntries = (sizeof(rfalDpoDefaultSettings) / RFAL_DPO_TABLE_PARAMETER); - - ST_MEMCPY( gRfalDpo, gRfalCurrentDpo, sizeof(rfalDpoDefaultSettings) ); - - /* by default use amplitude measurement */ - gRfalDpoMeasureCallback = rfalChipMeasureAmplitude; - - /* by default DPO is disabled */ - gRfalDpoIsEnabled = false; - - gRfalDpoTableEntry = 0; -} - -void rfalDpoSetMeasureCallback( rfalDpoMeasureFunc pMeasureFunc ) -{ - gRfalDpoMeasureCallback = pMeasureFunc; -} - -/*******************************************************************************/ -ReturnCode rfalDpoTableWrite( rfalDpoEntry* powerTbl, uint8_t powerTblEntries ) -{ - uint8_t entry = 0; - - /* check if the table size parameter is too big */ - if( (powerTblEntries * RFAL_DPO_TABLE_PARAMETER) > RFAL_DPO_TABLE_SIZE_MAX) - { - return ERR_NOMEM; - } - - /* check if the first increase entry is 0xFF */ - if( (powerTblEntries == 0) || (powerTbl == NULL) ) - { - return ERR_PARAM; - } - - /* check if the entries of the dynamic power table are valid */ - for (entry = 0; entry < powerTblEntries; entry++) - { - if(powerTbl[entry].inc < powerTbl[entry].dec) - { - return ERR_PARAM; - } - } - - /* copy the data set */ - ST_MEMCPY( gRfalDpo, powerTbl, (powerTblEntries * RFAL_DPO_TABLE_PARAMETER) ); - gRfalCurrentDpo = gRfalDpo; - gRfalDpoTableEntries = powerTblEntries; - - if(gRfalDpoTableEntry > powerTblEntries) - { - /* is always greater then zero, otherwise we already returned ERR_PARAM */ - gRfalDpoTableEntry = (powerTblEntries - 1); - } - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalDpoTableRead( rfalDpoEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries ) -{ - /* wrong request */ - if( (tblBuf == NULL) || (tblBufEntries < gRfalDpoTableEntries) || (tableEntries == NULL) ) - { - return ERR_PARAM; - } - - /* Copy the whole Table to the given buffer */ - ST_MEMCPY( tblBuf, gRfalCurrentDpo, (tblBufEntries * RFAL_DPO_TABLE_PARAMETER) ); - *tableEntries = gRfalDpoTableEntries; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalDpoAdjust( void ) -{ - uint8_t refValue = 0; - rfalDpoEntry* dpoTable = (rfalDpoEntry*) gRfalCurrentDpo; - - /* Check if the Power Adjustment is disabled and * - * if the callback to the measurement method is properly set */ - if( (gRfalCurrentDpo == NULL) || (!gRfalDpoIsEnabled) || (gRfalDpoMeasureCallback == NULL) ) - { - return ERR_PARAM; - } - - /* Ensure that the current mode is Passive Poller */ - if( !rfalIsModePassivePoll( rfalGetMode() ) ) - { - return ERR_WRONG_STATE; - } - - /* Ensure a proper measure reference value */ - if( ERR_NONE != gRfalDpoMeasureCallback( &refValue ) ) - { - return ERR_IO; - } - - - /* Increase the output power */ - if( refValue >= dpoTable[gRfalDpoTableEntry].inc ) - { - /* the top of the table represents the highest amplitude value*/ - if( gRfalDpoTableEntry == 0 ) - { - /* check if the maximum driver value has been reached */ - return ERR_NONE; - } - /* go up in the table to decrease the driver resistance */ - gRfalDpoTableEntry--; - } - else - { - /* decrease the output power */ - if(refValue <= dpoTable[gRfalDpoTableEntry].dec) - { - /* The bottom is the highest possible value */ - if( (gRfalDpoTableEntry + 1) >= gRfalDpoTableEntries) - { - /* check if the minimum driver value has been reached */ - return ERR_NONE; - } - /* go down in the table to increase the driver resistance */ - gRfalDpoTableEntry++; - } - else - { - /* do not write the driver again with the same value */ - } - } - - /* get the new value for RFO resistance form the table and apply the new RFO resistance setting */ - rfalChipSetRFO( dpoTable[gRfalDpoTableEntry].rfoRes ); - return ERR_NONE; -} - -/*******************************************************************************/ -rfalDpoEntry* rfalDpoGetCurrentTableEntry( void ) -{ - rfalDpoEntry* dpoTable = (rfalDpoEntry*) gRfalCurrentDpo; - return &dpoTable[gRfalDpoTableEntry]; -} - -/*******************************************************************************/ -void rfalDpoSetEnabled( bool enable ) -{ - gRfalDpoIsEnabled = enable; -} - -/*******************************************************************************/ -bool rfalDpoIsEnabled( void ) -{ - return gRfalDpoIsEnabled; -} - -#endif /* RFAL_FEATURE_DPO */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_iso15693_2.c b/Software/Middlewares/ST/rfal/Src/rfal_iso15693_2.c deleted file mode 100644 index 94ea414..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_iso15693_2.c +++ /dev/null @@ -1,534 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_iso15693_2.c - * - * \author Ulrich Herrmann - * - * \brief Implementation of ISO-15693-2 - * - */ - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ -#include "rfal_iso15693_2.h" -#include "rfal_crc.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_NFCV - #define RFAL_FEATURE_NFCV false /* NFC-V module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_NFCV - -/* -****************************************************************************** -* LOCAL MACROS -****************************************************************************** -*/ - -//#define ISO_15693_DEBUG dbgLog -#define ISO_15693_DEBUG(...) /*!< Macro for the log method */ - -/* -****************************************************************************** -* LOCAL DEFINES -****************************************************************************** -*/ -#define ISO15693_DAT_SOF_1_4 0x21 /* LSB constants */ -#define ISO15693_DAT_EOF_1_4 0x04 -#define ISO15693_DAT_00_1_4 0x02 -#define ISO15693_DAT_01_1_4 0x08 -#define ISO15693_DAT_10_1_4 0x20 -#define ISO15693_DAT_11_1_4 0x80 - -#define ISO15693_DAT_SOF_1_256 0x81 -#define ISO15693_DAT_EOF_1_256 0x04 -#define ISO15693_DAT_SLOT0_1_256 0x02 -#define ISO15693_DAT_SLOT1_1_256 0x08 -#define ISO15693_DAT_SLOT2_1_256 0x20 -#define ISO15693_DAT_SLOT3_1_256 0x80 - -#define ISO15693_PHY_DAT_MANCHESTER_1 0xaaaa - -#define ISO15693_PHY_BIT_BUFFER_SIZE 1000 /*!< size of the receiving buffer. Might be adjusted if longer datastreams are expected. */ - - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ -static iso15693PhyConfig_t iso15693PhyConfig; /*!< current phy configuration */ - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -static ReturnCode iso15693PhyVCDCode1Of4(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen); -static ReturnCode iso15693PhyVCDCode1Of256(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen); - - - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ -ReturnCode iso15693PhyConfigure(const iso15693PhyConfig_t* config, const struct iso15693StreamConfig ** needed_stream_config ) -{ - static struct iso15693StreamConfig stream_config = { /* MISRA 8.9 */ - .useBPSK = 0, /* 0: subcarrier, 1:BPSK */ - .din = 5, /* 2^5*fc = 423750 Hz: divider for the in subcarrier frequency */ - .dout = 7, /*!< 2^7*fc = 105937 : divider for the in subcarrier frequency */ - .report_period_length = 3, /*!< 8=2^3 the length of the reporting period */ - }; - - - /* make a copy of the configuration */ - ST_MEMCPY( (uint8_t*)&iso15693PhyConfig, (const uint8_t*)config, sizeof(iso15693PhyConfig_t)); - - if ( config->speedMode <= 3U) - { /* If valid speed mode adjust report period accordingly */ - stream_config.report_period_length = (3U - (uint8_t)config->speedMode); - } - else - { /* If invalid default to normal (high) speed */ - stream_config.report_period_length = 3; - } - - *needed_stream_config = &stream_config; - - return ERR_NONE; -} - -ReturnCode iso15693PhyGetConfiguration(iso15693PhyConfig_t* config) -{ - ST_MEMCPY(config, &iso15693PhyConfig, sizeof(iso15693PhyConfig_t)); - - return ERR_NONE; -} - -ReturnCode iso15693VCDCode(uint8_t* buffer, uint16_t length, bool sendCrc, bool sendFlags, bool picopassMode, - uint16_t *subbit_total_length, uint16_t *offset, - uint8_t* outbuf, uint16_t outBufSize, uint16_t* actOutBufSize) -{ - ReturnCode err = ERR_NONE; - uint8_t eof, sof; - uint8_t transbuf[2]; - uint16_t crc = 0; - ReturnCode (*txFunc)(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen); - uint8_t crc_len; - uint8_t* outputBuf; - uint16_t outputBufSize; - - crc_len = (uint8_t)((sendCrc)?2:0); - - *actOutBufSize = 0; - - if (ISO15693_VCD_CODING_1_4 == iso15693PhyConfig.coding) - { - sof = ISO15693_DAT_SOF_1_4; - eof = ISO15693_DAT_EOF_1_4; - txFunc = iso15693PhyVCDCode1Of4; - *subbit_total_length = ( - ( 1U /* SOF */ - + ((length + (uint16_t)crc_len) * 4U) - + 1U) /* EOF */ - ); - if (outBufSize < 5U) { /* 5 should be safe: enough for sof + 1byte data in 1of4 */ - return ERR_NOMEM; - } - } - else - { - sof = ISO15693_DAT_SOF_1_256; - eof = ISO15693_DAT_EOF_1_256; - txFunc = iso15693PhyVCDCode1Of256; - *subbit_total_length = ( - ( 1U /* SOF */ - + ((length + (uint16_t)crc_len) * 64U) - + 1U) /* EOF */ - ); - - if (*offset != 0U) - { - if (outBufSize < 64U) { /* 64 should be safe: enough a single byte data in 1of256 */ - return ERR_NOMEM; - } - } - else - { - if (outBufSize < 65U) { /* At beginning of a frame we need at least 65 bytes to start: enough for sof + 1byte data in 1of256 */ - return ERR_NOMEM; - } - } - } - - if (length == 0U) - { - *subbit_total_length = 1; - } - - if ((length != 0U) && (0U == *offset) && sendFlags && !picopassMode) - { - /* set high datarate flag */ - buffer[0] |= (uint8_t)ISO15693_REQ_FLAG_HIGH_DATARATE; - /* clear sub-carrier flag - we only support single sub-carrier */ - buffer[0] = (uint8_t)(buffer[0] & ~ISO15693_REQ_FLAG_TWO_SUBCARRIERS); /* MISRA 10.3 */ - } - - outputBuf = outbuf; /* MISRA 17.8: Use intermediate variable */ - outputBufSize = outBufSize; /* MISRA 17.8: Use intermediate variable */ - - /* Send SOF if at 0 offset */ - if ((length != 0U) && (0U == *offset)) - { - *outputBuf = sof; - (*actOutBufSize)++; - outputBufSize--; - outputBuf++; - } - - while ((*offset < length) && (err == ERR_NONE)) - { - uint16_t filled_size; - /* send data */ - err = txFunc(buffer[*offset], outputBuf, outputBufSize, &filled_size); - (*actOutBufSize) += filled_size; - outputBuf = &outputBuf[filled_size]; /* MISRA 18.4: Avoid pointer arithmetic */ - outputBufSize -= filled_size; - if (err == ERR_NONE) { - (*offset)++; - } - } - if (err != ERR_NONE) { - return ERR_AGAIN; - } - - while ((err == ERR_NONE) && sendCrc && (*offset < (length + 2U))) - { - uint16_t filled_size; - if (0U==crc) - { - crc = rfalCrcCalculateCcitt( (uint16_t) ((picopassMode) ? 0xE012U : 0xFFFFU), /* In PicoPass Mode a different Preset Value is used */ - ((picopassMode) ? (buffer + 1U) : buffer), /* CMD byte is not taken into account in PicoPass mode */ - ((picopassMode) ? (length - 1U) : length)); /* CMD byte is not taken into account in PicoPass mode */ - - crc = (uint16_t)((picopassMode) ? crc : ~crc); - } - /* send crc */ - transbuf[0] = (uint8_t)(crc & 0xffU); - transbuf[1] = (uint8_t)((crc >> 8) & 0xffU); - err = txFunc(transbuf[*offset - length], outputBuf, outputBufSize, &filled_size); - (*actOutBufSize) += filled_size; - outputBuf = &outputBuf[filled_size]; /* MISRA 18.4: Avoid pointer arithmetic */ - outputBufSize -= filled_size; - if (err == ERR_NONE) { - (*offset)++; - } - } - if (err != ERR_NONE) { - return ERR_AGAIN; - } - - if ((!sendCrc && (*offset == length)) - || (sendCrc && (*offset == (length + 2U)))) - { - *outputBuf = eof; - (*actOutBufSize)++; - outputBufSize--; - outputBuf++; - } - else - { - return ERR_AGAIN; - } - - return err; -} - -ReturnCode iso15693VICCDecode(const uint8_t *inBuf, - uint16_t inBufLen, - uint8_t* outBuf, - uint16_t outBufLen, - uint16_t* outBufPos, - uint16_t* bitsBeforeCol, - uint16_t ignoreBits, - bool picopassMode ) -{ - ReturnCode err = ERR_NONE; - uint16_t crc; - uint16_t mp; /* Current bit position in manchester bit inBuf*/ - uint16_t bp; /* Current bit position in outBuf */ - - *bitsBeforeCol = 0; - *outBufPos = 0; - - /* first check for valid SOF. Since it starts with 3 unmodulated pulses it is 0x17. */ - if ((inBuf[0] & 0x1fU) != 0x17U) - { - ISO_15693_DEBUG("0x%x\n", iso15693PhyBitBuffer[0]); - return ERR_FRAMING; - } - ISO_15693_DEBUG("SOF\n"); - - if (outBufLen == 0U) - { - return ERR_NONE; - } - - mp = 5; /* 5 bits were SOF, now manchester starts: 2 bits per payload bit */ - bp = 0; - - ST_MEMSET(outBuf,0,outBufLen); - - if (inBufLen == 0U) - { - return ERR_CRC; - } - - for ( ; mp < ((inBufLen * 8U) - 2U); mp+=2U ) - { - bool isEOF = false; - - uint8_t man; - man = (inBuf[mp/8U] >> (mp%8U)) & 0x1U; - man |= ((inBuf[(mp+1U)/8U] >> ((mp+1U)%8U)) & 0x1U) << 1; - if (1U == man) - { - bp++; - } - if (2U == man) - { - outBuf[bp/8U] = (uint8_t)(outBuf[bp/8U] | (1U <<(bp%8U))); /* MISRA 10.3 */ - bp++; - } - if ((bp%8U) == 0U) - { /* Check for EOF */ - ISO_15693_DEBUG("ceof %hhx %hhx\n", inBuf[mp/8U], inBuf[mp/8+1]); - if ( ((inBuf[mp/8U] & 0xe0U) == 0xa0U) - &&(inBuf[(mp/8U)+1U] == 0x03U)) - { /* Now we know that it was 10111000 = EOF */ - ISO_15693_DEBUG("EOF\n"); - isEOF = true; - } - } - if ( ((0U == man) || (3U == man)) && !isEOF ) - { - if (bp >= ignoreBits) - { - err = ERR_RF_COLLISION; - } - else - { - /* ignored collision: leave as 0 */ - bp++; - } - } - if ( (bp >= (outBufLen * 8U)) || (err == ERR_RF_COLLISION) || isEOF ) - { /* Don't write beyond the end */ - break; - } - } - - *outBufPos = (bp / 8U); - *bitsBeforeCol = bp; - - if (err != ERR_NONE) - { - return err; - } - - if ((bp%8U) != 0U) - { - return ERR_CRC; - } - - if (*outBufPos > 2U) - { - /* finally, check crc */ - ISO_15693_DEBUG("Calculate CRC, val: 0x%x, outBufLen: ", *outBuf); - ISO_15693_DEBUG("0x%x ", *outBufPos - 2); - - crc = rfalCrcCalculateCcitt(((picopassMode) ? 0xE012U : 0xFFFFU), outBuf, *outBufPos - 2U); - crc = (uint16_t)((picopassMode) ? crc : ~crc); - - if (((crc & 0xffU) == outBuf[*outBufPos-2U]) && - (((crc >> 8U) & 0xffU) == outBuf[*outBufPos-1U])) - { - err = ERR_NONE; - ISO_15693_DEBUG("OK\n"); - } - else - { - ISO_15693_DEBUG("error! Expected: 0x%x, got ", crc); - ISO_15693_DEBUG("0x%hhx 0x%hhx\n", outBuf[*outBufPos-2], outBuf[*outBufPos-1]); - err = ERR_CRC; - } - } - else - { - err = ERR_CRC; - } - - return err; -} - -/* -****************************************************************************** -* LOCAL FUNCTIONS -****************************************************************************** -*/ -/*! - ***************************************************************************** - * \brief Perform 1 of 4 coding and send coded data - * - * This function takes \a length bytes from \a buffer, perform 1 of 4 coding - * (see ISO15693-2 specification) and sends the data using stream mode. - * - * \param[in] sendSof : send SOF prior to data. - * \param[in] buffer : data to send. - * \param[in] length : number of bytes to send. - * - * \return ERR_IO : Error during communication. - * \return ERR_NONE : No error. - * - ***************************************************************************** - */ -static ReturnCode iso15693PhyVCDCode1Of4(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen) -{ - uint8_t tmp; - ReturnCode err = ERR_NONE; - uint16_t a; - uint8_t* outbuf = outbuffer; - - *outBufLen = 0; - - if (maxOutBufLen < 4U) { - return ERR_NOMEM; - } - - tmp = data; - for (a = 0; a < 4U; a++) - { - switch (tmp & 0x3U) - { - case 0: - *outbuf = ISO15693_DAT_00_1_4; - break; - case 1: - *outbuf = ISO15693_DAT_01_1_4; - break; - case 2: - *outbuf = ISO15693_DAT_10_1_4; - break; - case 3: - *outbuf = ISO15693_DAT_11_1_4; - break; - default: - /* MISRA 16.4: mandatory default statement */ - break; - } - outbuf++; - (*outBufLen)++; - tmp >>= 2; - } - return err; -} - -/*! - ***************************************************************************** - * \brief Perform 1 of 256 coding and send coded data - * - * This function takes \a length bytes from \a buffer, perform 1 of 256 coding - * (see ISO15693-2 specification) and sends the data using stream mode. - * \note This function sends SOF prior to the data. - * - * \param[in] sendSof : send SOF prior to data. - * \param[in] buffer : data to send. - * \param[in] length : number of bytes to send. - * - * \return ERR_IO : Error during communication. - * \return ERR_NONE : No error. - * - ***************************************************************************** - */ -static ReturnCode iso15693PhyVCDCode1Of256(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen) -{ - uint8_t tmp; - ReturnCode err = ERR_NONE; - uint16_t a; - uint8_t* outbuf = outbuffer; - - *outBufLen = 0; - - if (maxOutBufLen < 64U) { - return ERR_NOMEM; - } - - tmp = data; - for (a = 0; a < 64U; a++) - { - switch (tmp) - { - case 0: - *outbuf = ISO15693_DAT_SLOT0_1_256; - break; - case 1: - *outbuf = ISO15693_DAT_SLOT1_1_256; - break; - case 2: - *outbuf = ISO15693_DAT_SLOT2_1_256; - break; - case 3: - *outbuf = ISO15693_DAT_SLOT3_1_256; - break; - default: - *outbuf = 0; - break; - } - outbuf++; - (*outBufLen)++; - tmp -= 4U; - } - - return err; -} - -#endif /* RFAL_FEATURE_NFCV */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_isoDep.c b/Software/Middlewares/ST/rfal/Src/rfal_isoDep.c deleted file mode 100644 index 2048841..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_isoDep.c +++ /dev/null @@ -1,2552 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: NFCC firmware - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_isoDep.c - * - * \author Gustavo Patricio - * - * \brief Implementation of ISO-DEP protocol - * - * This implementation was based on the following specs: - * - ISO/IEC 14443-4 2nd Edition 2008-07-15 - * - NFC Forum Digital Protocol 1.1 2014-01-14 - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - -#include "rfal_isoDep.h" -#include "rfal_rf.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_ISO_DEP - #define RFAL_FEATURE_ISO_DEP false /* ISO-DEP module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_ISO_DEP - -#if ( !RFAL_FEATURE_ISO_DEP_POLL && !RFAL_FEATURE_ISO_DEP_LISTEN ) - #error " RFAL: Invalid ISO-DEP Configuration. Please select at least one mode: Poller and/or Listener. " -#endif - -/* Check for valid I-Block length [RFAL_ISODEP_FSX_16 ; RFAL_ISODEP_FSX_4096]*/ -#if( (RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN > 4096 ) || (RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN < 16) ) - #error " RFAL: Invalid ISO-DEP IBlock Max length. Please change RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN. " -#endif - -/* Check for valid APDU length, It must be n*IBlock */ -#if( (RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN < RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN) || (RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN % RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN) ) - #error " RFAL: Invalid ISO-DEP APDU Max length. Please change RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN. " -#endif - -/* - ****************************************************************************** - * DEFINES - ****************************************************************************** - */ -#define ISODEP_CRC_LEN RFAL_CRC_LEN /*!< ISO1443 CRC Length */ - - -#define ISODEP_PCB_POS (0U) /*!< PCB position on message header*/ -#define ISODEP_SWTX_INF_POS (1U) /*!< INF position in a S-WTX */ - -#define ISODEP_DID_POS (1U) /*!< DID position on message header*/ -#define ISODEP_SWTX_PARAM_LEN (1U) /*!< SWTX parameter length */ - -#define ISODEP_DSL_MAX_LEN ( RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN ) /*!< Deselect Req/Res length */ - -#define ISODEP_PCB_xBLOCK_MASK (0xC0U) /*!< Bit mask for Block type */ -#define ISODEP_PCB_IBLOCK (0x00U) /*!< Bit mask indicating a I-Block */ -#define ISODEP_PCB_RBLOCK (0x80U) /*!< Bit mask indicating a R-Block */ -#define ISODEP_PCB_SBLOCK (0xC0U) /*!< Bit mask indicating a S-Block */ -#define ISODEP_PCB_INVALID (0x40U) /*!< Bit mask of an Invalid PCB */ - -#define ISODEP_HDR_MAX_LEN (RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN + RFAL_ISODEP_NAD_LEN) /*!< Max header length (PCB + DID + NAD) */ - -#define ISODEP_PCB_IB_VALID_MASK (ISODEP_PCB_B6_BIT | ISODEP_PCB_B2_BIT) /*!< Bit mask for the MUST bits on I-Block */ -#define ISODEP_PCB_IB_VALID_VAL (ISODEP_PCB_B2_BIT) /*!< Value for the MUST bits on I-Block */ -#define ISODEP_PCB_RB_VALID_MASK (ISODEP_PCB_B6_BIT | ISODEP_PCB_B3_BIT | ISODEP_PCB_B2_BIT) /*!< Bit mask for the MUST bits on R-Block */ -#define ISODEP_PCB_RB_VALID_VAL (ISODEP_PCB_B6_BIT | ISODEP_PCB_B2_BIT) /*!< Value for the MUST bits on R-Block */ -#define ISODEP_PCB_SB_VALID_MASK (ISODEP_PCB_B3_BIT | ISODEP_PCB_B2_BIT | ISODEP_PCB_B1_BIT) /*!< Bit mask for the MUST bits on I-Block */ -#define ISODEP_PCB_SB_VALID_VAL (ISODEP_PCB_B2_BIT) /*!< Value for the MUST bits on I-Block */ - - -#define ISODEP_PCB_B1_BIT (0x01U) /*!< Bit mask for the RFU S Blocks */ -#define ISODEP_PCB_B2_BIT (0x02U) /*!< Bit mask for the RFU bit2 in I,S,R Blocks */ -#define ISODEP_PCB_B3_BIT (0x04U) /*!< Bit mask for the RFU bit3 in R Blocks */ -#define ISODEP_PCB_B6_BIT (0x20U) /*!< Bit mask for the RFU bit2 in R Blocks */ -#define ISODEP_PCB_CHAINING_BIT (0x10U) /*!< Bit mask for the chaining bit of an ISO DEP I-Block in PCB. */ -#define ISODEP_PCB_DID_BIT (0x08U) /*!< Bit mask for the DID presence bit of an ISO DEP I,S,R Blocks PCB. */ -#define ISODEP_PCB_NAD_BIT (0x04U) /*!< Bit mask for the NAD presence bit of an ISO DEP I,S,R Blocks in PCB */ -#define ISODEP_PCB_BN_MASK (0x01U) /*!< Bit mask for the block number of an ISO DEP I,R Block in PCB */ - -#define ISODEP_SWTX_PL_MASK (0xC0U) /*!< Bit mask for the Power Level bits of the inf byte of an WTX request or response */ -#define ISODEP_SWTX_WTXM_MASK (0x3FU) /*!< Bit mask for the WTXM bits of the inf byte of an WTX request or response */ - - -#define ISODEP_RBLOCK_INF_LEN (0U) /*!< INF length of R-Block Digital 1.1 15.1.3 */ -#define ISODEP_SDSL_INF_LEN (0U) /*!< INF length of S(DSL) Digital 1.1 15.1.3 */ -#define ISODEP_SWTX_INF_LEN (1U) /*!< INF length of S(WTX) Digital 1.1 15.2.2 */ - -#define ISODEP_WTXM_MIN (1U) /*!< Minimum allowed value for the WTXM, Digital 1.0 13.2.2 */ -#define ISODEP_WTXM_MAX (59U) /*!< Maximum allowed value for the WTXM, Digital 1.0 13.2.2 */ - -#define ISODEP_PCB_Sxx_MASK (0x30U) /*!< Bit mask for the S-Block type */ -#define ISODEP_PCB_DESELECT (0x00U) /*!< Bit mask for S-Block indicating Deselect */ -#define ISODEP_PCB_WTX (0x30U) /*!< Bit mask for S-Block indicating Waiting Time eXtension */ - -#define ISODEP_PCB_Rx_MASK (0x10U) /*!< Bit mask for the R-Block type */ -#define ISODEP_PCB_ACK (0x00U) /*!< Bit mask for R-Block indicating ACK */ -#define ISODEP_PCB_NAK (0x10U) /*!< Bit mask for R-Block indicating NAK */ - -/*! Maximum length of control message (no INF) */ -#define ISODEP_CONTROLMSG_BUF_LEN (RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN + RFAL_ISODEP_NAD_LEN + ISODEP_SWTX_PARAM_LEN) - -#define ISODEP_FWT_DEACTIVATION (71680U) /*!< FWT to be used after DESELECT, Digital 1.0 A9 */ -#define ISODEP_MAX_RERUNS (0x0FFFFFFFU)/*!< Maximum rerun retrys for a blocking protocol run*/ - - -#define ISODEP_PCBSBLOCK ( 0x00U | ISODEP_PCB_SBLOCK | ISODEP_PCB_B2_BIT ) /*!< PCB Value of a S-Block */ -#define ISODEP_PCB_SDSL ( ISODEP_PCBSBLOCK | ISODEP_PCB_DESELECT ) /*!< PCB Value of a S-Block with DESELECT */ -#define ISODEP_PCB_SWTX ( ISODEP_PCBSBLOCK | ISODEP_PCB_WTX ) /*!< PCB Value of a S-Block with WTX */ -#define ISODEP_PCB_SPARAMETERS ( ISODEP_PCB_SBLOCK | ISODEP_PCB_WTX ) /*!< PCB Value of a S-Block with PARAMETERS */ - -#define ISODEP_FWI_LIS_MAX_NFC 8U /*!< FWT Listener Max FWIT4ATmax FWIBmax Digital 1.1 A6 & A3 */ -#define ISODEP_FWI_LIS_MAX_EMVCO 7U /*!< FWT Listener Max FWIMAX EMVCo 2.6 A.5 */ -#define ISODEP_FWI_LIS_MAX (uint8_t)((gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV) ? ISODEP_FWI_LIS_MAX_EMVCO : ISODEP_FWI_LIS_MAX_NFC) /*!< FWI Listener Max as NFC / EMVCo */ -#define ISODEP_FWT_LIS_MAX rfalIsoDepFWI2FWT(ISODEP_FWI_LIS_MAX) /*!< FWT Listener Max */ - -#define ISODEP_FWI_MIN_10 (1U) /*!< Minimum value for FWI Digital 1.0 11.6.2.17 */ -#define ISODEP_FWI_MIN_11 (0U) /*!< Default value for FWI Digital 1.1 13.6.2 */ -#define ISODEP_FWI_MAX (14U) /*!< Maximum value for FWI Digital 1.0 11.6.2.17 */ -#define ISODEP_SFGI_MIN (0U) /*!< Default value for FWI Digital 1.1 13.6.2.22 */ -#define ISODEP_SFGI_MAX (14U) /*!< Maximum value for FWI Digital 1.1 13.6.2.22 */ - - -#define RFAL_ISODEP_SPARAM_TVL_HDR_LEN (2U) /*!< S(PARAMETERS) TVL header length: Tag + Len */ -#define RFAL_ISODEP_SPARAM_HDR_LEN (RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_SPARAM_TVL_HDR_LEN) /*!< S(PARAMETERS) header length: PCB + Tag + Len */ - - -/**********************************************************************************************************************/ -/**********************************************************************************************************************/ -#define RFAL_ISODEP_NO_PARAM (0U) /*!< No parameter flag for isoDepHandleControlMsg() */ - -#define RFAL_ISODEP_CMD_RATS (0xE0U) /*!< RATS command Digital 1.1 13.6.1 */ - -#define RFAL_ISODEP_ATS_MIN_LEN (1U) /*!< Minimum ATS length Digital 1.1 13.6.2 */ -#define RFAL_ISODEP_ATS_HDR_LEN (5U) /*!< ATS headerlength Digital 1.1 13.6.2 */ -#define RFAL_ISODEP_ATS_MAX_LEN (RFAL_ISODEP_ATS_HDR_LEN + RFAL_ISODEP_ATS_HB_MAX_LEN) /*!< Maximum ATS length Digital 1.1 13.6.2 */ -#define RFAL_ISODEP_ATS_T0_FSCI_MASK (0x0FU) /*!< ATS T0's FSCI mask Digital 1.1 13.6.2 */ -#define RFAL_ISODEP_ATS_TB_FWI_SHIFT (4U) /*!< ATS TB's FWI shift Digital 1.1 13.6.2 */ -#define RFAL_ISODEP_ATS_FWI_MASK (0x0FU) /*!< ATS TB's FWI shift Digital 1.1 13.6.2 */ - - -#define RFAL_ISODEP_PPS_SB (0xD0U) /*!< PPS REQ PPSS's SB value (no CID) ISO14443-4 5.3 */ -#define RFAL_ISODEP_PPS_MASK (0xF0U) /*!< PPS REQ PPSS's SB mask ISO14443-4 5.3 */ -#define RFAL_ISODEP_PPS_SB_DID_MASK (0x0FU) /*!< PPS REQ PPSS's DID|CID mask ISO14443-4 5.3 */ -#define RFAL_ISODEP_PPS_PPS0_PPS1_PRESENT (0x11U) /*!< PPS REQ PPS0 indicating that PPS1 is present */ -#define RFAL_ISODEP_PPS_PPS1 (0x00U) /*!< PPS REQ PPS1 fixed value ISO14443-4 5.3 */ -#define RFAL_ISODEP_PPS_PPS1_DSI_SHIFT (2U) /*!< PPS REQ PPS1 fixed value ISO14443-4 5.3 */ -#define RFAL_ISODEP_PPS_PPS1_DXI_MASK (0x0FU) /*!< PPS REQ PPS1 fixed value ISO14443-4 5.3 */ -#define RFAL_ISODEP_PPS_RES_LEN (1U) /*!< PPS Response length ISO14443-4 5.4 */ -#define RFAL_ISODEP_PPS_STARTBYTE_POS (0U) /*!< PPS REQ PPSS's byte position ISO14443-4 5.4 */ -#define RFAL_ISODEP_PPS_PPS0_POS (1U) /*!< PPS REQ PPS0's byte position ISO14443-4 5.4 */ -#define RFAL_ISODEP_PPS_PPS1_POS (2U) /*!< PPS REQ PPS1's byte position ISO14443-4 5.4 */ -#define RFAL_ISODEP_PPS0_VALID_MASK (0xEFU) /*!< PPS REQ PPS0 valid coding mask ISO14443-4 5.4 */ - -#define RFAL_ISODEP_CMD_ATTRIB (0x1DU) /*!< ATTRIB command Digital 1.1 14.6.1 */ -#define RFAL_ISODEP_ATTRIB_PARAM2_DSI_SHIFT (6U) /*!< ATTRIB PARAM2 DSI shift Digital 1.1 14.6.1 */ -#define RFAL_ISODEP_ATTRIB_PARAM2_DRI_SHIFT (4U) /*!< ATTRIB PARAM2 DRI shift Digital 1.1 14.6.1 */ -#define RFAL_ISODEP_ATTRIB_PARAM2_DXI_MASK (0xF0U) /*!< ATTRIB PARAM2 DxI mask Digital 1.1 14.6.1 */ -#define RFAL_ISODEP_ATTRIB_PARAM2_FSDI_MASK (0x0FU) /*!< ATTRIB PARAM2 FSDI mask Digital 1.1 14.6.1 */ -#define RFAL_ISODEP_ATTRIB_PARAM4_DID_MASK (0x0FU) /*!< ATTRIB PARAM4 DID mask Digital 1.1 14.6.1 */ -#define RFAL_ISODEP_ATTRIB_HDR_LEN (9U) /*!< ATTRIB REQ header length Digital 1.1 14.6.1 */ - -#define RFAL_ISODEP_ATTRIB_RES_HDR_LEN (1U) /*!< ATTRIB RES header length Digital 1.1 14.6.2 */ -#define RFAL_ISODEP_ATTRIB_RES_DID_MASK (0x0FU) /*!< ATTRIB RES DID mask Digital 1.1 14.6.2 */ -#define RFAL_ISODEP_ATTRIB_RES_MBLI_MASK (0x0FU) /*!< ATTRIB RES MBLI mask Digital 1.1 14.6.2 */ -#define RFAL_ISODEP_ATTRIB_RES_MBLI_SHIFT (4U) /*!< ATTRIB RES MBLI shift Digital 1.1 14.6.2 */ - -#define RFAL_ISODEP_DID_MASK (0x0FU) /*!< ISODEP's DID mask */ -#define RFAL_ISODEP_DID_00 (0U) /*!< ISODEP's DID value 0 */ - -#define RFAL_ISODEP_FSDI_MAX_NFC (8U) /*!< Max FSDI value Digital 2.0 14.6.1.9 & B7 & B8 */ -#define RFAL_ISODEP_FSDI_MAX_EMV (0x0CU) /*!< Max FSDI value EMVCo 3.0 5.7.2.5 */ - -#define RFAL_ISODEP_RATS_PARAM_FSDI_MASK (0xF0U) /*!< Mask bits for FSDI in RATS */ -#define RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT (4U) /*!< Shift for FSDI in RATS */ -#define RFAL_ISODEP_RATS_PARAM_DID_MASK (0x0FU) /*!< Mask bits for DID in RATS */ - -#define RFAL_ISODEP_ATS_TL_OFFSET (0x00U) /*!< Offset of TL on ATS */ -#define RFAL_ISODEP_ATS_TA_OFFSET (0x02U) /*!< Offset of TA if it is present on ATS */ -#define RFAL_ISODEP_ATS_TB_OFFSET (0x03U) /*!< Offset of TB if both TA and TB is present on ATS */ -#define RFAL_ISODEP_ATS_TC_OFFSET (0x04U) /*!< Offset of TC if both TA,TB & TC are present on ATS */ -#define RFAL_ISODEP_ATS_HIST_OFFSET (0x05U) /*!< Offset of Historical Bytes if TA, TB & TC are present on ATS */ -#define RFAL_ISODEP_ATS_TC_ADV_FEAT (0x10U) /*!< Bit mask indicating support for Advanced protocol features: DID & NAD */ -#define RFAL_ISODEP_ATS_TC_DID (0x02U) /*!< Bit mask indicating support for DID */ -#define RFAL_ISODEP_ATS_TC_NAD (0x01U) /*!< Bit mask indicating support for NAD */ - -#define RFAL_ISODEP_PPS0_PPS1_PRESENT (0x11U) /*!< PPS0 byte indicating that PPS1 is present */ -#define RFAL_ISODEP_PPS0_PPS1_NOT_PRESENT (0x01U) /*!< PPS0 byte indicating that PPS1 is NOT present */ -#define RFAL_ISODEP_PPS1_DRI_MASK (0x03U) /*!< PPS1 byte DRI mask bits */ -#define RFAL_ISODEP_PPS1_DSI_MASK (0x0CU) /*!< PPS1 byte DSI mask bits */ -#define RFAL_ISODEP_PPS1_DSI_SHIFT (2U) /*!< PPS1 byte DSI shift */ -#define RFAL_ISODEP_PPS1_DxI_MASK (0x03U) /*!< PPS1 byte DSI/DRS mask bits */ - - -/*! Delta Time for polling during Activation (ATS) : 20ms Digital 1.0 11.7.1.1 & A.7 */ -#define RFAL_ISODEP_T4T_DTIME_POLL_10 rfalConvMsTo1fc(20) - -/*! Delta Time for polling during Activation (ATS) : 16.4ms Digital 1.1 13.8.1.1 & A.6 - * Use 16 ms as testcase T4AT_BI_10_03 sends a frame exactly at the border */ -#define RFAL_ISODEP_T4T_DTIME_POLL_11 216960U - -/*! Activation frame waiting time FWT(act) = 71680/fc (~5286us) Digital 1.1 13.8.1.1 & A.6 */ -#define RFAL_ISODEP_T4T_FWT_ACTIVATION (71680U + RFAL_ISODEP_T4T_DTIME_POLL_11) - - -/*! Delta frame waiting time = 16/fc Digital 1.0 11.7.1.3 & A.7*/ -#define RFAL_ISODEP_DFWT_10 16U - -/*! Delta frame waiting time = 16/fc Digital 2.0 14.8.1.3 & B.7*/ -#define RFAL_ISODEP_DFWT_20 49152U - -/* - ****************************************************************************** - * MACROS - ****************************************************************************** - */ - -#define isoDep_PCBisIBlock( pcb ) ( ((pcb) & (ISODEP_PCB_xBLOCK_MASK | ISODEP_PCB_IB_VALID_MASK)) == (ISODEP_PCB_IBLOCK | ISODEP_PCB_IB_VALID_VAL)) /*!< Checks if pcb is a I-Block */ -#define isoDep_PCBisRBlock( pcb ) ( ((pcb) & (ISODEP_PCB_xBLOCK_MASK | ISODEP_PCB_RB_VALID_MASK)) == (ISODEP_PCB_RBLOCK | ISODEP_PCB_RB_VALID_VAL)) /*!< Checks if pcb is a R-Block */ -#define isoDep_PCBisSBlock( pcb ) ( ((pcb) & (ISODEP_PCB_xBLOCK_MASK | ISODEP_PCB_SB_VALID_MASK)) == (ISODEP_PCB_SBLOCK | ISODEP_PCB_SB_VALID_VAL)) /*!< Checks if pcb is a S-Block */ - -#define isoDep_PCBisChaining( pcb ) ( ((pcb) & ISODEP_PCB_CHAINING_BIT) == ISODEP_PCB_CHAINING_BIT) /*!< Checks if pcb is indicating chaining */ - -#define isoDep_PCBisDeselect( pcb ) ( ((pcb) & ISODEP_PCB_Sxx_MASK) == ISODEP_PCB_DESELECT) /*!< Checks if pcb is indicating DESELECT */ -#define isoDep_PCBisWTX( pcb ) ( ((pcb) & ISODEP_PCB_Sxx_MASK) == ISODEP_PCB_WTX) /*!< Checks if pcb is indicating WTX */ - -#define isoDep_PCBisACK( pcb ) ( ((pcb) & ISODEP_PCB_Rx_MASK) == ISODEP_PCB_ACK) /*!< Checks if pcb is indicating ACK */ -#define isoDep_PCBisNAK( pcb ) ( ((pcb) & ISODEP_PCB_Rx_MASK) == ISODEP_PCB_NAK) /*!< Checks if pcb is indicating ACK */ - -#define isoDep_PCBhasDID( pcb ) ( ((pcb) & ISODEP_PCB_DID_BIT) == ISODEP_PCB_DID_BIT) /*!< Checks if pcb is indicating DID */ -#define isoDep_PCBhasNAD( pcb ) ( ((pcb) & ISODEP_PCB_NAD_BIT) == ISODEP_PCB_NAD_BIT) /*!< Checks if pcb is indicating NAD */ - - -#define isoDep_PCBisIChaining( pcb ) ( isoDep_PCBisIBlock(pcb) && isoDep_PCBisChaining(pcb) ) /*!< Checks if pcb is I-Block indicating chaining*/ - -#define isoDep_PCBisSDeselect( pcb ) ( isoDep_PCBisSBlock(pcb) && isoDep_PCBisDeselect(pcb) ) /*!< Checks if pcb is S-Block indicating DESELECT*/ -#define isoDep_PCBisSWTX( pcb ) ( isoDep_PCBisSBlock(pcb) && isoDep_PCBisWTX(pcb) ) /*!< Checks if pcb is S-Block indicating WTX */ - -#define isoDep_PCBisRACK( pcb ) ( isoDep_PCBisRBlock(pcb) && isoDep_PCBisACK(pcb) ) /*!< Checks if pcb is R-Block indicating ACK */ -#define isoDep_PCBisRNAK( pcb ) ( isoDep_PCBisRBlock(pcb) && isoDep_PCBisNAK(pcb) ) /*!< Checks if pcb is R-Block indicating NAK */ - - -#define isoDep_PCBIBlock( bn ) ( (uint8_t)( 0x00U | ISODEP_PCB_IBLOCK | ISODEP_PCB_B2_BIT | ((bn) & ISODEP_PCB_BN_MASK) )) /*!< Returns an I-Block with the given block number (bn) */ -#define isoDep_PCBIBlockChaining( bn ) ( (uint8_t)(isoDep_PCBIBlock(bn) | ISODEP_PCB_CHAINING_BIT)) /*!< Returns an I-Block with the given block number (bn) indicating chaining */ - -#define isoDep_PCBRBlock( bn ) ( (uint8_t)( 0x00U | ISODEP_PCB_RBLOCK | ISODEP_PCB_B6_BIT | ISODEP_PCB_B2_BIT | ((bn) & ISODEP_PCB_BN_MASK) ) ) /*!< Returns an R-Block with the given block number (bn) */ -#define isoDep_PCBRACK( bn ) ( (uint8_t)( isoDep_PCBRBlock( bn ) | ISODEP_PCB_ACK ) ) /*!< Returns an R-Block with the given block number (bn) indicating ACK */ -#define isoDep_PCBRNAK( bn ) ( (uint8_t)( isoDep_PCBRBlock( bn ) | ISODEP_PCB_NAK ) ) /*!< Returns an R-Block with the given block number (bn) indicating NAK */ - - -#define isoDep_GetBN( pcb ) ( (uint8_t) ((pcb) & ISODEP_PCB_BN_MASK ) ) /*!< Returns the block number (bn) from the given pcb */ -#define isoDep_GetWTXM( inf ) ( (uint8_t) ((inf) & ISODEP_SWTX_WTXM_MASK) ) /*!< Returns the WTX value from the given inf byte */ -#define isoDep_isWTXMValid( wtxm ) (((wtxm) >= ISODEP_WTXM_MIN) && ((wtxm) <= ISODEP_WTXM_MAX)) /*!< Checks if the given wtxm is valid */ - -#define isoDep_WTXMListenerMax( fwt ) ( MIN( (uint8_t)(ISODEP_FWT_LIS_MAX / (fwt)), ISODEP_WTXM_MAX) ) /*!< Calculates the Max WTXM value for the given fwt as a Listener */ - -#define isoDepCalcdSGFT( s ) (384U * ((uint32_t)1U << (s))) /*!< Calculates the dSFGT with given SFGI Digital 1.1 13.8.2.1 & A.6*/ -#define isoDepCalcSGFT( s ) (4096U * ((uint32_t)1U << (s))) /*!< Calculates the SFGT with given SFGI Digital 1.1 13.8.2 */ - -#define isoDep_PCBNextBN( bn ) (((uint8_t)(bn)^0x01U) & ISODEP_PCB_BN_MASK) /*!< Returns the value of the next block number based on bn */ -#define isoDep_PCBPrevBN( bn ) isoDep_PCBNextBN(bn) /*!< Returns the value of the previous block number based on bn */ -#define isoDep_ToggleBN( bn ) ((bn) = (((bn)^0x01U) & ISODEP_PCB_BN_MASK) ) /*!< Toggles the block number value of the given bn */ - -#define isoDep_WTXAdjust( v ) ((v) - ((v)>>3)) /*!< Adjust WTX timer value to a percentage of the total, current 88% */ - - -/*! ISO 14443-4 7.5.6.2 & Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ -#define isoDepReEnableRx( rxB, rxBL, rxL ) rfalTransceiveBlockingTx( NULL, 0, rxB, rxBL, rxL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FWT_NONE ) - -#define isoDepTimerStart( timer, time_ms ) (timer) = platformTimerCreate((uint16_t)(time_ms)) /*!< Configures and starts the WTX timer */ -#define isoDepTimerisExpired( timer ) platformTimerIsExpired( timer ) /*!< Checks WTX timer has expired */ - -/* - ****************************************************************************** - * LOCAL DATA TYPES - ****************************************************************************** - */ - - /*! Internal structure to be used in handling of S(PARAMETRS) only */ -typedef struct -{ - uint8_t pcb; /*!< PCB byte */ - rfalIsoDepSParameter sParam; /*!< S(PARAMETERS) */ -} rfalIsoDepControlMsgSParam; - -/*! Enumeration of the possible control message types */ -typedef enum -{ - ISODEP_R_ACK, /*!< R-ACK Acknowledge */ - ISODEP_R_NAK, /*!< R-NACK Negative acknowledge */ - ISODEP_S_WTX, /*!< S-WTX Waiting Time Extension */ - ISODEP_S_DSL /*!< S-DSL Deselect */ -} rfalIsoDepControlMsg; - -/*! Enumeration of the IsoDep roles */ -typedef enum -{ - ISODEP_ROLE_PCD, /*!< Perform as Reader/PCD */ - ISODEP_ROLE_PICC /*!< Perform as Card/PICC */ -} rfalIsoDepRole; - -/*! ISO-DEP layer states */ -typedef enum -{ - ISODEP_ST_IDLE, /*!< Idle State */ - ISODEP_ST_PCD_TX, /*!< PCD Transmission State */ - ISODEP_ST_PCD_RX, /*!< PCD Reception State */ - ISODEP_ST_PCD_WAIT_DSL, /*!< PCD Wait for DSL response */ - - ISODEP_ST_PICC_ACT_ATS, /*!< PICC has replied to RATS (ATS) */ - ISODEP_ST_PICC_ACT_ATTRIB, /*!< PICC has replied to ATTRIB */ - ISODEP_ST_PICC_RX, /*!< PICC REception State */ - ISODEP_ST_PICC_SWTX, /*!< PICC Waiting Time eXtension */ - ISODEP_ST_PICC_TX, /*!< PICC Transmission State */ -} rfalIsoDepState; - - - - -/*! Holds all ISO-DEP data(counters, buffers, ID, timeouts, frame size) */ -typedef struct{ - rfalIsoDepState state; /*!< ISO-DEP module state */ - rfalIsoDepRole role; /*!< Current ISO-DEP role */ - - uint8_t blockNumber; /*!< Current block number */ - uint8_t did; /*!< Current DID */ - uint8_t nad; /*!< Current DID */ - uint8_t cntIRetrys; /*!< I-Block retry counter */ - uint8_t cntRRetrys; /*!< R-Block retry counter */ - uint8_t cntSRetrys; /*!< S-Block retry counter */ - uint32_t fwt; /*!< Current FWT (Frame Waiting Time) */ - uint32_t dFwt; /*!< Current delta FWT */ - uint16_t fsx; /*!< Current FSx FSC or FSD (max Frame size) */ - bool isTxChaining; /*!< Flag for chaining on Tx */ - bool isRxChaining; /*!< Flag for chaining on Rx */ - uint8_t* txBuf; /*!< Tx buffer pointer */ - uint8_t* rxBuf; /*!< Rx buffer pointer */ - uint16_t txBufLen; /*!< Tx buffer length */ - uint16_t rxBufLen; /*!< Rx buffer length */ - uint8_t txBufInfPos; /*!< Start of payload in txBuf */ - uint8_t rxBufInfPos; /*!< Start of payload in rxBuf */ - - - uint16_t ourFsx; /*!< Our current FSx FSC or FSD (Frame size) */ - uint8_t lastPCB; /*!< Last PCB sent */ - uint8_t lastWTXM; /*!< Last WTXM sent */ - uint8_t atsTA; /*!< TA on ATS */ - uint8_t hdrLen; /*!< Current ISO-DEP length */ - rfalBitRate txBR; /*!< Current Tx Bit Rate */ - rfalBitRate rxBR; /*!< Current Rx Bit Rate */ - uint16_t *rxLen; /*!< Output parameter ptr to Rx length */ - bool *rxChaining; /*!< Output parameter ptr to Rx chaining flag */ - uint32_t WTXTimer; /*!< Timer used for WTX */ - bool lastDID00; /*!< Last PCD block had DID flag (for DID = 0) */ - - bool isTxPending; /*!< Flag pending Block while waiting WTX Ack */ - bool isWait4WTX; /*!< Flag for waiting WTX Ack */ - - uint32_t SFGTTimer; /*!< Timer used for SFGT */ - - uint8_t maxRetriesI; /*!< Number of retries for a I-Block */ - uint8_t maxRetriesS; /*!< Number of retries for a S-Block */ - uint8_t maxRetriesR; /*!< Number of retries for a R-Block */ - uint8_t maxRetriesRATS;/*!< Number of retries for RATS */ - - rfalComplianceMode compMode; /*!< Compliance mode */ - - uint8_t ctrlRxBuf[ISODEP_CONTROLMSG_BUF_LEN]; /*!< Control msg buf */ - uint16_t ctrlRxLen; /*!< Control msg rcvd len (used only for DSL) */ - - - rfalIsoDepListenActvParam actvParam; /*!< Listen Activation context */ - - rfalIsoDepApduTxRxParam APDUParam; /*!< APDU TxRx params */ - uint16_t APDUTxPos; /*!< APDU Tx position */ - uint16_t APDURxPos; /*!< APDU Rx position */ - bool isAPDURxChaining; /*!< APDU Transceive chaining flag */ - -}rfalIsoDep; - - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -static rfalIsoDep gIsoDep; /*!< ISO-DEP Module instance */ - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ -static void isoDepClearCounters( void ); -static ReturnCode isoDepTx( uint8_t pcb, const uint8_t* txBuf, uint8_t *infBuf, uint16_t infLen, uint32_t fwt ); -static ReturnCode isoDepHandleControlMsg( rfalIsoDepControlMsg controlMsg, uint8_t param ); -static void rfalIsoDepApdu2IBLockParam( rfalIsoDepApduTxRxParam apduParam, rfalIsoDepTxRxParam *iBlockParam, uint16_t txPos, uint16_t rxPos ); - -#if RFAL_FEATURE_ISO_DEP_POLL - static ReturnCode isoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsChaining ); - static void rfalIsoDepCalcBitRate(rfalBitRate maxAllowedBR, uint8_t piccBRCapability, rfalBitRate *dsi, rfalBitRate *dri); - static uint32_t rfalIsoDepSFGI2SFGT( uint8_t sfgi ); -#endif -#if RFAL_FEATURE_ISO_DEP_LISTEN - static ReturnCode isoDepDataExchangePICC( void ); - static ReturnCode isoDepReSendControlMsg( void ); -#endif - - - - -/* - ****************************************************************************** - * LOCAL FUNCTIONS - ****************************************************************************** - */ - -/*******************************************************************************/ -static void isoDepClearCounters( void ) -{ - gIsoDep.cntIRetrys = 0; - gIsoDep.cntRRetrys = 0; - gIsoDep.cntSRetrys = 0; -} - -/*******************************************************************************/ -static ReturnCode isoDepTx( uint8_t pcb, const uint8_t* txBuf, uint8_t *infBuf, uint16_t infLen, uint32_t fwt ) -{ - uint8_t *txBlock; - uint16_t txBufLen; - uint8_t computedPcb; - - - txBlock = infBuf; /* Point to beginning of the INF, and go backwards */ - gIsoDep.lastPCB = pcb; /* Store the last PCB sent */ - - - if ( infLen > 0U ) - { - if ( ((uint32_t)infBuf - (uint32_t)txBuf) < gIsoDep.hdrLen ) /* Check that we can fit the header in the given space */ - { - return ERR_NOMEM; - } - } - - - /*******************************************************************************/ - /* Compute optional PCB bits */ - computedPcb = pcb; - if ((gIsoDep.did != RFAL_ISODEP_NO_DID) || ((gIsoDep.did == RFAL_ISODEP_DID_00) && gIsoDep.lastDID00) ) { computedPcb |= ISODEP_PCB_DID_BIT; } - if (gIsoDep.nad != RFAL_ISODEP_NO_NAD) { computedPcb |= ISODEP_PCB_NAD_BIT; } - if ((gIsoDep.isTxChaining) && (isoDep_PCBisIBlock(computedPcb)) ) { computedPcb |= ISODEP_PCB_CHAINING_BIT; } - - - /*******************************************************************************/ - /* Compute Payload on the given txBuf, start by the PCB | DID | NAD | before INF */ - - if (gIsoDep.nad != RFAL_ISODEP_NO_NAD) - { - *(--txBlock) = gIsoDep.nad; /* NAD is optional */ - } - - if ( (gIsoDep.did != RFAL_ISODEP_NO_DID) || ((gIsoDep.did == RFAL_ISODEP_DID_00) && gIsoDep.lastDID00) ) - { - *(--txBlock) = gIsoDep.did; /* DID is optional */ - } - - *(--txBlock) = computedPcb; /* PCB always present */ - - txBufLen = (infLen + (uint16_t)((uint32_t)infBuf - (uint32_t)txBlock)); /* Calculate overall buffer size */ - - if ( txBufLen > (gIsoDep.fsx - ISODEP_CRC_LEN) ) /* Check if msg length violates the maximum frame size FSC */ - { - return ERR_NOTSUPP; - } - - return rfalTransceiveBlockingTx( txBlock, txBufLen, gIsoDep.rxBuf, gIsoDep.rxBufLen, gIsoDep.rxLen, RFAL_TXRX_FLAGS_DEFAULT, ((gIsoDep.role == ISODEP_ROLE_PICC) ? RFAL_FWT_NONE : fwt ) ); -} - -/*******************************************************************************/ -static ReturnCode isoDepHandleControlMsg( rfalIsoDepControlMsg controlMsg, uint8_t param ) -{ - uint8_t pcb; - uint8_t ctrlMsgBuf[ISODEP_CONTROLMSG_BUF_LEN]; - uint8_t infLen; - uint32_t fwtTemp; - - infLen = 0; - fwtTemp = (gIsoDep.fwt + gIsoDep.dFwt); - ST_MEMSET( ctrlMsgBuf, 0x00, ISODEP_CONTROLMSG_BUF_LEN ); - - switch( controlMsg ) - { - /*******************************************************************************/ - case ISODEP_R_ACK: - - if( gIsoDep.cntRRetrys++ > gIsoDep.maxRetriesR ) - { - return ERR_PROTO; - } - - pcb = isoDep_PCBRACK( gIsoDep.blockNumber ); - break; - - /*******************************************************************************/ - case ISODEP_R_NAK: - if( gIsoDep.cntRRetrys++ > gIsoDep.maxRetriesR ) - { - return ERR_TIMEOUT; - } - - pcb = isoDep_PCBRNAK( gIsoDep.blockNumber ); - break; - - /*******************************************************************************/ - case ISODEP_S_WTX: - if( gIsoDep.cntSRetrys++ > gIsoDep.maxRetriesS ) - { - return ERR_PROTO; - } - - /* Check if WTXM is valid */ - if( ! isoDep_isWTXMValid(param) ) - { - return ERR_PROTO; - } - - if( gIsoDep.role == ISODEP_ROLE_PCD ) - { - /* Calculate temp Wait Time eXtension */ - fwtTemp = (gIsoDep.fwt * param); - fwtTemp = MIN( RFAL_ISODEP_MAX_FWT, fwtTemp ); - fwtTemp += gIsoDep.dFwt; - } - - pcb = ISODEP_PCB_SWTX; - ctrlMsgBuf[ RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN + infLen++] = param; - break; - - /*******************************************************************************/ - case ISODEP_S_DSL: - if( gIsoDep.cntSRetrys++ > gIsoDep.maxRetriesS ) - { - return ERR_PROTO; - } - - if( gIsoDep.role == ISODEP_ROLE_PCD ) - { - /* Digital 1.0 - 13.2.7.3 Poller must wait fwtDEACTIVATION */ - fwtTemp = ISODEP_FWT_DEACTIVATION; - gIsoDep.state = ISODEP_ST_PCD_WAIT_DSL; - } - pcb = ISODEP_PCB_SDSL; - break; - - /*******************************************************************************/ - default: - return ERR_INTERNAL; - } - - return isoDepTx( pcb, ctrlMsgBuf, &ctrlMsgBuf[RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN], infLen, fwtTemp ); -} - -#if RFAL_FEATURE_ISO_DEP_LISTEN -/*******************************************************************************/ -static ReturnCode isoDepReSendControlMsg( void ) -{ - if( isoDep_PCBisRACK( gIsoDep.lastPCB ) ) - { - return isoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ); - } - - if( isoDep_PCBisRNAK( gIsoDep.lastPCB ) ) - { - return isoDepHandleControlMsg( ISODEP_R_NAK, RFAL_ISODEP_NO_PARAM ); - } - - if( isoDep_PCBisSDeselect( gIsoDep.lastPCB ) ) - { - return isoDepHandleControlMsg( ISODEP_S_DSL, RFAL_ISODEP_NO_PARAM ); - } - - if( isoDep_PCBisSWTX( gIsoDep.lastPCB ) ) - { - return isoDepHandleControlMsg( ISODEP_S_WTX, gIsoDep.lastWTXM ); - } - return ERR_WRONG_STATE; -} -#endif /* RFAL_FEATURE_ISO_DEP_LISTEN */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - -/*******************************************************************************/ -void rfalIsoDepInitialize( void ) -{ - gIsoDep.state = ISODEP_ST_IDLE; - gIsoDep.role = ISODEP_ROLE_PCD; - gIsoDep.did = RFAL_ISODEP_NO_DID; - gIsoDep.nad = RFAL_ISODEP_NO_NAD; - gIsoDep.blockNumber = 0; - gIsoDep.isTxChaining = false; - gIsoDep.isRxChaining = false; - gIsoDep.lastDID00 = false; - gIsoDep.lastPCB = ISODEP_PCB_INVALID; - gIsoDep.fsx = (uint16_t)RFAL_ISODEP_FSX_16; - gIsoDep.ourFsx = (uint16_t)RFAL_ISODEP_FSX_16; - gIsoDep.hdrLen = RFAL_ISODEP_PCB_LEN; - - gIsoDep.rxLen = NULL; - gIsoDep.rxBuf = NULL; - - gIsoDep.isTxPending = false; - gIsoDep.isWait4WTX = false; - - gIsoDep.compMode = RFAL_COMPLIANCE_MODE_NFC; - gIsoDep.maxRetriesR = RFAL_ISODEP_MAX_R_RETRYS; - gIsoDep.maxRetriesS = RFAL_ISODEP_MAX_S_RETRYS; - gIsoDep.maxRetriesI = RFAL_ISODEP_MAX_I_RETRYS; - gIsoDep.maxRetriesRATS = RFAL_ISODEP_RATS_RETRIES; - - isoDepClearCounters(); -} - - -/*******************************************************************************/ -void rfalIsoDepInitializeWithParams( rfalComplianceMode compMode, uint8_t maxRetriesR, uint8_t maxRetriesS, uint8_t maxRetriesI, uint8_t maxRetriesRATS ) -{ - rfalIsoDepInitialize(); - - gIsoDep.compMode = compMode; - gIsoDep.maxRetriesR = maxRetriesR; - gIsoDep.maxRetriesS = maxRetriesS; - gIsoDep.maxRetriesI = maxRetriesI; - gIsoDep.maxRetriesRATS = maxRetriesRATS; -} - - -#if RFAL_FEATURE_ISO_DEP_POLL -/*******************************************************************************/ -static ReturnCode isoDepDataExchangePCD( uint16_t *outActRxLen, bool *outIsChaining ) -{ - ReturnCode ret; - uint8_t rxPCB; - - /* Check out parameters */ - if( (outActRxLen == NULL) || (outIsChaining == NULL) ) - { - return ERR_PARAM; - } - - *outIsChaining = false; - - /* Calculate header required and check if the buffers InfPositions are suitable */ - gIsoDep.hdrLen = RFAL_ISODEP_PCB_LEN; - if (gIsoDep.did != RFAL_ISODEP_NO_DID) { gIsoDep.hdrLen += RFAL_ISODEP_DID_LEN; } - if (gIsoDep.nad != RFAL_ISODEP_NO_NAD) { gIsoDep.hdrLen += RFAL_ISODEP_NAD_LEN; } - - /* check if there is enough space before the infPos to append ISO-DEP headers on rx and tx */ - if( (gIsoDep.rxBufInfPos < gIsoDep.hdrLen) || (gIsoDep.txBufInfPos < gIsoDep.hdrLen) ) - { - return ERR_PARAM; - } - - /*******************************************************************************/ - /* Wait until SFGT has been fulfilled (as a PCD) */ - if(gIsoDep.SFGTTimer != 0U) - { - if( !isoDepTimerisExpired( gIsoDep.SFGTTimer ) ) - { - return ERR_BUSY; - } - } - /* Once done, clear SFGT timer */ - gIsoDep.SFGTTimer = 0; - - - /*******************************************************************************/ - switch( gIsoDep.state ) - { - /*******************************************************************************/ - case ISODEP_ST_IDLE: - return ERR_NONE; - - /*******************************************************************************/ - case ISODEP_ST_PCD_TX: - ret = isoDepTx( isoDep_PCBIBlock( gIsoDep.blockNumber ), gIsoDep.txBuf, &gIsoDep.txBuf[gIsoDep.txBufInfPos], gIsoDep.txBufLen, (gIsoDep.fwt + gIsoDep.dFwt) ); - switch( ret ) - { - case ERR_NONE: - gIsoDep.state = ISODEP_ST_PCD_RX; - break; - - default: - return ret; - } - /* fall through */ - - /*******************************************************************************/ - case ISODEP_ST_PCD_WAIT_DSL: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - case ISODEP_ST_PCD_RX: - - ret = rfalGetTransceiveStatus(); - switch( ret ) - { - /* Data rcvd with error or timeout -> Send R-NAK */ - case ERR_TIMEOUT: - case ERR_CRC: - case ERR_PAR: - case ERR_FRAMING: /* added to handle test cases scenario TC_POL_NFCB_T4AT_BI_82_x_y & TC_POL_NFCB_T4BT_BI_82_x_y */ - case ERR_INCOMPLETE_BYTE: /* added to handle test cases scenario TC_POL_NFCB_T4AT_BI_82_x_y & TC_POL_NFCB_T4BT_BI_82_x_y */ - - if( gIsoDep.isRxChaining ) - { /* Rule 5 - In PICC chaining when a invalid/timeout occurs -> R-ACK */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); - } - else if( gIsoDep.state == ISODEP_ST_PCD_WAIT_DSL ) - { /* Rule 8 - If s-Deselect response fails MAY retransmit */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_S_DSL, RFAL_ISODEP_NO_PARAM ) ); - } - else - { /* Rule 4 - When a invalid block or timeout occurs -> R-NACK */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_R_NAK, RFAL_ISODEP_NO_PARAM ) ); - } - return ERR_BUSY; - - case ERR_NONE: - break; - - case ERR_BUSY: - return ERR_BUSY; /* Debug purposes */ - - default: - return ret; - } - - /*******************************************************************************/ - /* No error, process incoming msg */ - /*******************************************************************************/ - - (*outActRxLen) = rfalConvBitsToBytes( *outActRxLen ); - - - /* Check rcvd msg length, cannot be less then the expected header */ - if( ((*outActRxLen) < gIsoDep.hdrLen) || ((*outActRxLen) >= gIsoDep.ourFsx) ) - { - return ERR_PROTO; - } - - /* Grab rcvd PCB */ - rxPCB = gIsoDep.rxBuf[ ISODEP_PCB_POS ]; - - - /* EMVCo doesn't allow usage of for CID or NAD EMVCo 2.6 TAble 10.2 */ - if( (gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV) && ( isoDep_PCBhasDID(rxPCB) || isoDep_PCBhasNAD(rxPCB)) ) - { - return ERR_PROTO; - } - - /* If we are expecting DID, check if PCB signals its presence and if device ID match*/ - if( (gIsoDep.did != RFAL_ISODEP_NO_DID) && ( !isoDep_PCBhasDID(rxPCB) || (gIsoDep.did != gIsoDep.rxBuf[ ISODEP_DID_POS ])) ) - { - return ERR_PROTO; - } - - - /*******************************************************************************/ - /* Process S-Block */ - /*******************************************************************************/ - if( isoDep_PCBisSBlock(rxPCB) ) - { - /* Check if is a Wait Time eXtension */ - if( isoDep_PCBisSWTX(rxPCB) ) - { - /* Rule 3 - respond to S-block: get 1st INF byte S(STW): Power + WTXM */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_S_WTX, isoDep_GetWTXM(gIsoDep.rxBuf[gIsoDep.hdrLen]) ) ); - return ERR_BUSY; - } - - /* Check if is a deselect response */ - if( isoDep_PCBisSDeselect(rxPCB) ) - { - if( gIsoDep.state == ISODEP_ST_PCD_WAIT_DSL ) - { - rfalIsoDepInitialize(); /* Session finished reInit vars */ - return ERR_NONE; - } - - /* Deselect response not expected */ - /* fall through to PROTO error */ - } - /* Unexpected S-Block */ - return ERR_PROTO; - } - - /*******************************************************************************/ - /* Process R-Block */ - /*******************************************************************************/ - else if( isoDep_PCBisRBlock(rxPCB) ) - { - if( isoDep_PCBisRACK(rxPCB) ) /* Check if is a R-ACK */ - { - if( isoDep_GetBN(rxPCB) == gIsoDep.blockNumber ) /* Expected block number */ - { - /* Rule B - ACK with expected bn -> Increment block number */ - gIsoDep.blockNumber = isoDep_PCBNextBN( gIsoDep.blockNumber ); - - /* R-ACK only allowed when PCD chaining */ - if( !gIsoDep.isTxChaining ) - { - return ERR_PROTO; - } - - /* Rule 7 - Chaining transaction done, continue chaining */ - isoDepClearCounters(); - return ERR_NONE; /* This block has been transmitted */ - } - else - { - /* Rule 6 - R-ACK with wrong block number retransmit */ - if( gIsoDep.cntIRetrys++ < gIsoDep.maxRetriesI ) - { - gIsoDep.cntRRetrys = 0; /* Clear R counter only */ - gIsoDep.state = ISODEP_ST_PCD_TX; - return ERR_BUSY; - } - return ERR_PROTO; - } - } - else /* Unexcpected R-Block */ - { - return ERR_PROTO; - } - } - - /*******************************************************************************/ - /* Process I-Block */ - /*******************************************************************************/ - else if( isoDep_PCBisIBlock(rxPCB) ) - { - /*******************************************************************************/ - /* is PICC performing chaining */ - if( isoDep_PCBisChaining(rxPCB) ) - { - gIsoDep.isRxChaining = true; - *outIsChaining = true; - - if( isoDep_GetBN(rxPCB) == gIsoDep.blockNumber ) - { - /* Rule B - ACK with correct block number -> Increase Block number */ - isoDep_ToggleBN( gIsoDep.blockNumber ); - - isoDepClearCounters(); /* Clear counters in case R counter is already at max */ - - /* Rule 2 - Send ACK */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); - - /* Received I-Block with chaining, send current data to DH */ - - /* remove ISO DEP header, check is necessary to move the INF data on the buffer */ - *outActRxLen -= gIsoDep.hdrLen; - if( (gIsoDep.hdrLen != gIsoDep.rxBufInfPos) && (*outActRxLen > 0U) ) - { - ST_MEMMOVE( &gIsoDep.rxBuf[gIsoDep.rxBufInfPos], &gIsoDep.rxBuf[gIsoDep.hdrLen], *outActRxLen ); - } - - isoDepClearCounters(); - return ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived */ - } - else - { - /* Rule 5 - PICC chaining invalid I-Block -> R-ACK */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); - } - return ERR_BUSY; - } - - gIsoDep.isRxChaining = false; /* clear PICC chaining flag */ - - if( isoDep_GetBN(rxPCB) == gIsoDep.blockNumber ) - { - /* Rule B - I-Block with correct block number -> Increase Block number */ - isoDep_ToggleBN( gIsoDep.blockNumber ); - - /* I-Block transaction done successfully */ - - /* remove ISO DEP header, check is necessary to move the INF data on the buffer */ - *outActRxLen -= gIsoDep.hdrLen; - if( (gIsoDep.hdrLen != gIsoDep.rxBufInfPos) && (*outActRxLen > 0U) ) - { - ST_MEMMOVE( &gIsoDep.rxBuf[gIsoDep.rxBufInfPos], &gIsoDep.rxBuf[gIsoDep.hdrLen], *outActRxLen ); - } - - gIsoDep.state = ISODEP_ST_IDLE; - isoDepClearCounters(); - return ERR_NONE; - } - else - { - if( (gIsoDep.compMode != RFAL_COMPLIANCE_MODE_ISO) ) - { - /* Invalid Block (not chaining) -> Raise error Digital 1.1 15.2.6.4 EMVCo 2.6 10.3.5.4 */ - return ERR_PROTO; - } - - /* Rule 4 - Invalid Block -> R-NAK */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_R_NAK, RFAL_ISODEP_NO_PARAM ) ); - return ERR_BUSY; - } - } - else /* not S/R/I - Block */ - { - return ERR_PROTO; - } - /* fall through */ - - /*******************************************************************************/ - default: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - /* MISRA 16.4: no empty default (comment will suffice) */ - break; - } - - return ERR_INTERNAL; -} - -/*******************************************************************************/ -ReturnCode rfalIsoDepDeselect( void ) -{ - ReturnCode ret; - uint32_t cntRerun; - bool dummyB; - - /*******************************************************************************/ - /* Check if rx parameters have been set before, otherwise use global variable * - * To cope with a Deselect after RATS\ATTRIB without any I-Block exchanged */ - if( (gIsoDep.rxLen == NULL) || (gIsoDep.rxBuf == NULL) ) - { - /* Using local vars would be safe as rfalIsoDepInitialize will clear the * - * reference to local vars before exiting (no EXIT_ON_ERR), * - * but MISRA 18.6 3217 would be still be flagged. Using static variables */ - gIsoDep.rxLen = &gIsoDep.ctrlRxLen; - gIsoDep.rxBuf = gIsoDep.ctrlRxBuf; - - gIsoDep.rxBufLen = ISODEP_CONTROLMSG_BUF_LEN; - gIsoDep.rxBufInfPos = (RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN); - gIsoDep.txBufInfPos = (RFAL_ISODEP_PCB_LEN + RFAL_ISODEP_DID_LEN); - } - - - /*******************************************************************************/ - /* The Deselect process is being done blocking, Digital 1.0 - 13.2.7.1 MUST wait response and retry*/ - /* Set the maximum reruns while we will wait for a response */ - cntRerun = ISODEP_MAX_RERUNS; - - /* Send DSL request and run protocol until get a response, error or "timeout" */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_S_DSL, RFAL_ISODEP_NO_PARAM )); - do{ - ret = isoDepDataExchangePCD( gIsoDep.rxLen, &dummyB ); - rfalWorker(); - } - while( ((cntRerun--) != 0U) && (ret == ERR_BUSY) ); - - rfalIsoDepInitialize(); - return ((cntRerun == 0U) ? ERR_TIMEOUT : ret); -} - -#endif /* RFAL_FEATURE_ISO_DEP_POLL */ - - -/*******************************************************************************/ -uint32_t rfalIsoDepFWI2FWT( uint8_t fwi ) -{ - uint32_t result; - uint8_t tmpFWI; - - tmpFWI = fwi; - - /* RFU values -> take the default value - * Digital 1.0 11.6.2.17 FWI[1,14] - * Digital 1.1 7.6.2.22 FWI[0,14] - * EMVCo 2.6 Table A.5 FWI[0,14] */ - if( tmpFWI > ISODEP_FWI_MAX ) - { - tmpFWI = RFAL_ISODEP_FWI_DEFAULT; - } - - /* FWT = (256 x 16/fC) x 2^FWI => 2^(FWI+12) Digital 1.1 13.8.1 & 7.9.1 */ - - result = ((uint32_t)1U << (tmpFWI + 12U)); - result = MIN( RFAL_ISODEP_MAX_FWT, result); /* Maximum Frame Waiting Time must be fulfilled */ - - return result; -} - - -/*******************************************************************************/ -uint16_t rfalIsoDepFSxI2FSx( uint8_t FSxI ) -{ - uint16_t fsx; - uint8_t fsi; - - /* Enforce maximum FSxI/FSx allowed - NFC Forum and EMVCo differ */ - fsi = (( gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV ) ? MIN( FSxI, RFAL_ISODEP_FSDI_MAX_EMV ) : MIN( FSxI, RFAL_ISODEP_FSDI_MAX_NFC )); - - switch( fsi ) - { - case (uint8_t)RFAL_ISODEP_FSXI_16: fsx = (uint16_t)RFAL_ISODEP_FSX_16; break; - case (uint8_t)RFAL_ISODEP_FSXI_24: fsx = (uint16_t)RFAL_ISODEP_FSX_24; break; - case (uint8_t)RFAL_ISODEP_FSXI_32: fsx = (uint16_t)RFAL_ISODEP_FSX_32; break; - case (uint8_t)RFAL_ISODEP_FSXI_40: fsx = (uint16_t)RFAL_ISODEP_FSX_40; break; - case (uint8_t)RFAL_ISODEP_FSXI_48: fsx = (uint16_t)RFAL_ISODEP_FSX_48; break; - case (uint8_t)RFAL_ISODEP_FSXI_64: fsx = (uint16_t)RFAL_ISODEP_FSX_64; break; - case (uint8_t)RFAL_ISODEP_FSXI_96: fsx = (uint16_t)RFAL_ISODEP_FSX_96; break; - case (uint8_t)RFAL_ISODEP_FSXI_128: fsx = (uint16_t)RFAL_ISODEP_FSX_128; break; - case (uint8_t)RFAL_ISODEP_FSXI_256: fsx = (uint16_t)RFAL_ISODEP_FSX_256; break; - case (uint8_t)RFAL_ISODEP_FSXI_512: fsx = (uint16_t)RFAL_ISODEP_FSX_512; break; - case (uint8_t)RFAL_ISODEP_FSXI_1024: fsx = (uint16_t)RFAL_ISODEP_FSX_1024; break; - case (uint8_t)RFAL_ISODEP_FSXI_2048: fsx = (uint16_t)RFAL_ISODEP_FSX_2048; break; - case (uint8_t)RFAL_ISODEP_FSXI_4096: fsx = (uint16_t)RFAL_ISODEP_FSX_4096; break; - default: fsx = (uint16_t)RFAL_ISODEP_FSX_256; break; - } - return fsx; -} - - -#if RFAL_FEATURE_ISO_DEP_LISTEN - -/*******************************************************************************/ -bool rfalIsoDepIsRats( const uint8_t *buf, uint8_t bufLen ) -{ - if(buf != NULL) - { - if ((RFAL_ISODEP_CMD_RATS == (uint8_t)*buf) && (sizeof(rfalIsoDepRats) == bufLen)) - { - return true; - } - } - return false; -} - - -/*******************************************************************************/ -bool rfalIsoDepIsAttrib( const uint8_t *buf, uint8_t bufLen ) -{ - if(buf != NULL) - { - if ( (RFAL_ISODEP_CMD_ATTRIB == (uint8_t)*buf) && - (RFAL_ISODEP_ATTRIB_REQ_MIN_LEN <= bufLen) && - ((RFAL_ISODEP_ATTRIB_REQ_MIN_LEN + RFAL_ISODEP_ATTRIB_HLINFO_LEN) >= bufLen) ) - { - return true; - } - } - return false; -} - - - -/*******************************************************************************/ -ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const rfalIsoDepAttribResParam *attribResParam, uint8_t *buf, uint16_t bufLen, rfalIsoDepListenActvParam actParam) -{ - uint8_t *txBuf; - uint8_t bufIt; - uint8_t *buffer = buf; - - /*******************************************************************************/ - bufIt = 0; - txBuf = (uint8_t*)actParam.rxBuf; /* Use the rxBuf as TxBuf as well, the struct enforces a size enough MAX( NFCA_ATS_MAX_LEN, NFCB_ATTRIB_RES_MAX_LEN ) */ - gIsoDep.txBR = RFAL_BR_106; - gIsoDep.rxBR = RFAL_BR_106; - - /* Check for a valid buffer pointer */ - if( buffer == NULL ) - { - return ERR_PARAM; - } - - /*******************************************************************************/ - if( *buffer == RFAL_ISODEP_CMD_RATS ) - { - /* Check ATS parameters */ - if( atsParam == NULL ) - { - return ERR_PARAM; - } - - /* If requested copy RATS to device info */ - if( actParam.isoDepDev != NULL ) - { - ST_MEMCPY( (uint8_t*)&actParam.isoDepDev->activation.A.Poller.RATS, buffer, sizeof(rfalIsoDepRats) ); /* Copy RATS' CMD + PARAM */ - } - - - /*******************************************************************************/ - /* Process RATS */ - buffer++; - gIsoDep.fsx = rfalIsoDepFSxI2FSx( (((*buffer) & RFAL_ISODEP_RATS_PARAM_FSDI_MASK) >> RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT) ); - gIsoDep.did = (*buffer & RFAL_ISODEP_DID_MASK); - - - /*******************************************************************************/ - /* Digital 1.1 13.6.1.8 - DID as to between 0 and 14 */ - if( gIsoDep.did > RFAL_ISODEP_DID_MAX ) - { - return ERR_PROTO; - } - - /* Check if we are configured to support DID */ - if( (gIsoDep.did != RFAL_ISODEP_DID_00) && (!atsParam->didSupport) ) - { - return ERR_NOTSUPP; - } - - - /*******************************************************************************/ - /* Check RFAL supported bit rates */ - if( (!(RFAL_SUPPORT_BR_CE_A_212) && (((atsParam->ta & RFAL_ISODEP_ATS_TA_DPL_212) != 0U) || ((atsParam->ta & RFAL_ISODEP_ATS_TA_DLP_212) != 0U))) || - (!(RFAL_SUPPORT_BR_CE_A_424) && (((atsParam->ta & RFAL_ISODEP_ATS_TA_DPL_424) != 0U) || ((atsParam->ta & RFAL_ISODEP_ATS_TA_DLP_424) != 0U))) || - (!(RFAL_SUPPORT_BR_CE_A_848) && (((atsParam->ta & RFAL_ISODEP_ATS_TA_DPL_848) != 0U) || ((atsParam->ta & RFAL_ISODEP_ATS_TA_DLP_848) != 0U))) ) - { - return ERR_NOTSUPP; - } - - /* Enforce proper FWI configuration */ - if( atsParam->fwi > ISODEP_FWI_LIS_MAX) - { - atsParam->fwi = ISODEP_FWI_LIS_MAX; - } - - gIsoDep.atsTA = atsParam->ta; - gIsoDep.fwt = rfalIsoDepFWI2FWT(atsParam->fwi); - gIsoDep.ourFsx = rfalIsoDepFSxI2FSx(atsParam->fsci); - - - /* Ensure proper/maximum Historical Bytes length */ - atsParam->hbLen = MIN( RFAL_ISODEP_ATS_HB_MAX_LEN, atsParam->hbLen ); - - /*******************************************************************************/ - /* Compute ATS */ - - txBuf[ bufIt++ ] = (RFAL_ISODEP_ATS_HIST_OFFSET + atsParam->hbLen); /* TL */ - txBuf[ bufIt++ ] = ( (RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK | RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK | - RFAL_ISODEP_ATS_T0_TC_PRESENCE_MASK)| atsParam->fsci ); /* T0 */ - txBuf[ bufIt++ ] = atsParam->ta; /* TA */ - txBuf[ bufIt++ ] = ( (atsParam->fwi << RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT) | - (atsParam->sfgi & RFAL_ISODEP_RATS_PARAM_FSDI_MASK) ); /* TB */ - txBuf[ bufIt++ ] = (uint8_t)((atsParam->didSupport) ? RFAL_ISODEP_ATS_TC_DID : 0U); /* TC */ - - if( atsParam->hbLen > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY( &txBuf[bufIt], atsParam->hb, atsParam->hbLen ); /* T1-Tk */ - bufIt += atsParam->hbLen; - } - - gIsoDep.state = ISODEP_ST_PICC_ACT_ATS; - - } - /*******************************************************************************/ - else if( *buffer == RFAL_ISODEP_CMD_ATTRIB ) - { - /* Check ATTRIB parameters */ - if( attribResParam == NULL ) - { - return ERR_PARAM; - } - - /* REMARK: ATTRIB handling */ - NO_WARNING(attribResParam); - NO_WARNING(bufLen); - return ERR_NOT_IMPLEMENTED; - } - else - { - return ERR_PARAM; - } - - gIsoDep.actvParam = actParam; - - - /*******************************************************************************/ - /* If requested copy to ISO-DEP device info */ - if( actParam.isoDepDev != NULL ) - { - actParam.isoDepDev->info.DID = gIsoDep.did; - actParam.isoDepDev->info.FSx = gIsoDep.fsx; - actParam.isoDepDev->info.FWT = gIsoDep.fwt; - actParam.isoDepDev->info.dFWT = 0; - actParam.isoDepDev->info.DSI = gIsoDep.txBR; - actParam.isoDepDev->info.DRI = gIsoDep.rxBR; - } - - return rfalTransceiveBlockingTx( txBuf, bufIt, (uint8_t*)actParam.rxBuf, sizeof( rfalIsoDepBufFormat ), actParam.rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FWT_NONE ); -} - - -/*******************************************************************************/ -ReturnCode rfalIsoDepListenGetActivationStatus( void ) -{ - ReturnCode err; - uint8_t* txBuf; - uint8_t bufIt; - - rfalBitRate dsi; - rfalBitRate dri; - - - /* Check if Activation is running */ - if( gIsoDep.state < ISODEP_ST_PICC_ACT_ATS ) - { - return ERR_WRONG_STATE; - } - - /* Check if Activation has finished already */ - if( gIsoDep.state >= ISODEP_ST_PICC_RX ) - { - return ERR_NONE; - } - - - /*******************************************************************************/ - /* Check for incoming msg */ - err = rfalGetTransceiveStatus(); - switch( err ) - { - /*******************************************************************************/ - case ERR_NONE: - break; - - /*******************************************************************************/ - case ERR_LINK_LOSS: - case ERR_BUSY: - return err; - - /*******************************************************************************/ - case ERR_CRC: - case ERR_PAR: - case ERR_FRAMING: - - /* ISO14443 4 5.6.2.2 2 If ATS has been replied upon a invalid block, PICC disables the PPS responses */ - if( gIsoDep.state == ISODEP_ST_PICC_ACT_ATS ) - { - gIsoDep.state = ISODEP_ST_PICC_RX; - break; - } - /* fall through */ - - /*******************************************************************************/ - default: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - /* ReEnable the receiver and wait for another frame */ - isoDepReEnableRx( (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen ); - - return ERR_BUSY; - } - - - txBuf = (uint8_t*)gIsoDep.actvParam.rxBuf; /* Use the rxBuf as TxBuf as well, the struct enforces a size enough MAX(NFCA_PPS_RES_LEN, ISODEP_DSL_MAX_LEN) */ - dri = RFAL_BR_KEEP; /* The RFAL_BR_KEEP is used to check if PPS with BR change was requested */ - dsi = RFAL_BR_KEEP; /* MISRA 9.1 */ - bufIt = 0; - - - /*******************************************************************************/ - gIsoDep.role = ISODEP_ROLE_PICC; - - /*******************************************************************************/ - if( gIsoDep.state == ISODEP_ST_PICC_ACT_ATS ) - { - /* Check for a PPS ISO 14443-4 5.3 */ - if( ( ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_STARTBYTE_POS] & RFAL_ISODEP_PPS_MASK) == RFAL_ISODEP_PPS_SB ) - { - /* ISO 14443-4 5.3.1 Check if the we are the addressed DID/CID */ - /* ISO 14443-4 5.3.2 Check for a valid PPS0 */ - if( (( ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_STARTBYTE_POS] & RFAL_ISODEP_DID_MASK) != gIsoDep.did) || - (( ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_PPS0_POS] & RFAL_ISODEP_PPS0_VALID_MASK) != RFAL_ISODEP_PPS0_PPS1_NOT_PRESENT) ) - { - /* Invalid DID on PPS request or Invalid PPS0, reEnable the receiver and wait another frame */ - isoDepReEnableRx( (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen ); - - return ERR_BUSY; - } - - /*******************************************************************************/ - /* Check PPS1 presence */ - if( ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_PPS0_POS] == RFAL_ISODEP_PPS0_PPS1_PRESENT ) - { - uint8_t newdri = ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_PPS1_POS] & RFAL_ISODEP_PPS1_DxI_MASK; /* MISRA 10.8 */ - uint8_t newdsi = (((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_PPS1_POS] >> RFAL_ISODEP_PPS1_DSI_SHIFT) & RFAL_ISODEP_PPS1_DxI_MASK; /* MISRA 10.8 */ - /* PRQA S 4342 2 # MISRA 10.5 - Layout of enum rfalBitRate and above masks guarantee no invalid enum values to be created */ - dri = (rfalBitRate) (newdri); - dsi = (rfalBitRate) (newdsi); - - if( (!(RFAL_SUPPORT_BR_CE_A_106) && (( dsi == RFAL_BR_106 ) || ( dri == RFAL_BR_106 ))) || - (!(RFAL_SUPPORT_BR_CE_A_212) && (( dsi == RFAL_BR_212 ) || ( dri == RFAL_BR_212 ))) || - (!(RFAL_SUPPORT_BR_CE_A_424) && (( dsi == RFAL_BR_424 ) || ( dri == RFAL_BR_424 ))) || - (!(RFAL_SUPPORT_BR_CE_A_848) && (( dsi == RFAL_BR_848 ) || ( dri == RFAL_BR_848 ))) ) - { - return ERR_PROTO; - } - } - - /*******************************************************************************/ - /* Compute and send PPS RES / Ack */ - txBuf[ bufIt++ ] = ((uint8_t*)gIsoDep.actvParam.rxBuf)[RFAL_ISODEP_PPS_STARTBYTE_POS]; - - rfalTransceiveBlockingTx( txBuf, bufIt, (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FWT_NONE ); - - /*******************************************************************************/ - /* Exchange the bit rates if requested */ - if( dri != RFAL_BR_KEEP ) - { - rfalSetBitRate( dsi, dri ); /* PRQA S 2880 # MISRA 2.1 - Unreachable code due to configuration option being set/unset above (RFAL_SUPPORT_BR_CE_A_xxx) */ - - gIsoDep.txBR = dsi; /* DSI codes the divisor from PICC to PCD */ - gIsoDep.rxBR = dri; /* DRI codes the divisor from PCD to PICC */ - - - if(gIsoDep.actvParam.isoDepDev != NULL) - { - gIsoDep.actvParam.isoDepDev->info.DSI = dsi; - gIsoDep.actvParam.isoDepDev->info.DRI = dri; - } - } - } - /* Check for a S-Deselect is done on Data Exchange Activity */ - } - - /*******************************************************************************/ - gIsoDep.hdrLen = RFAL_ISODEP_PCB_LEN; - gIsoDep.hdrLen += RFAL_ISODEP_DID_LEN; /* Always assume DID to be aligned with Digital 1.1 15.1.2 and ISO14443 4 5.6.3 #454 */ - gIsoDep.hdrLen += (uint8_t)((gIsoDep.nad != RFAL_ISODEP_NO_NAD) ? RFAL_ISODEP_NAD_LEN : 0U); - - /*******************************************************************************/ - /* Rule C - The PICC block number shall be initialized to 1 at activation */ - gIsoDep.blockNumber = 1; - - /* Activation done, keep the rcvd data in, reMap the activation buffer to the global to be retrieved by the DEP method */ - gIsoDep.rxBuf = (uint8_t*)gIsoDep.actvParam.rxBuf; - gIsoDep.rxBufLen = sizeof( rfalIsoDepBufFormat ); - gIsoDep.rxBufInfPos = (uint8_t)((uint32_t)gIsoDep.actvParam.rxBuf->inf - (uint32_t)gIsoDep.actvParam.rxBuf->prologue); - gIsoDep.rxLen = gIsoDep.actvParam.rxLen; - gIsoDep.rxChaining = gIsoDep.actvParam.isRxChaining; - - gIsoDep.state = ISODEP_ST_PICC_RX; - return ERR_NONE; -} - -#endif /* RFAL_FEATURE_ISO_DEP_LISTEN */ - - -/*******************************************************************************/ -uint16_t rfalIsoDepGetMaxInfLen( void ) -{ - /* Check whether all parameters are valid, otherwise return minimum default value */ - if( (gIsoDep.fsx < (uint16_t)RFAL_ISODEP_FSX_16) || (gIsoDep.fsx > (uint16_t)RFAL_ISODEP_FSX_4096) || (gIsoDep.hdrLen > ISODEP_HDR_MAX_LEN) ) - { - uint16_t isodepFsx16 = (uint16_t)RFAL_ISODEP_FSX_16; /* MISRA 10.1 */ - return (isodepFsx16 - RFAL_ISODEP_PCB_LEN - ISODEP_CRC_LEN); - } - - return (gIsoDep.fsx - gIsoDep.hdrLen - ISODEP_CRC_LEN); -} - - -/*******************************************************************************/ -ReturnCode rfalIsoDepStartTransceive( rfalIsoDepTxRxParam param ) -{ - gIsoDep.txBuf = param.txBuf->prologue; - gIsoDep.txBufInfPos = (uint8_t)((uint32_t)param.txBuf->inf - (uint32_t)param.txBuf->prologue); - gIsoDep.txBufLen = param.txBufLen; - gIsoDep.isTxChaining = param.isTxChaining; - - gIsoDep.rxBuf = param.rxBuf->prologue; - gIsoDep.rxBufInfPos = (uint8_t)((uint32_t)param.rxBuf->inf - (uint32_t)param.rxBuf->prologue); - gIsoDep.rxBufLen = sizeof(rfalIsoDepBufFormat); - - gIsoDep.rxLen = param.rxLen; - gIsoDep.rxChaining = param.isRxChaining; - - - gIsoDep.fwt = param.FWT; - gIsoDep.dFwt = param.dFWT; - gIsoDep.fsx = param.FSx; - gIsoDep.did = param.DID; - - /* Only change the FSx from activation if no to Keep */ - gIsoDep.ourFsx = (( param.ourFSx != RFAL_ISODEP_FSX_KEEP ) ? param.ourFSx : gIsoDep.ourFsx); - - /* Clear inner control params for next dataExchange */ - gIsoDep.isRxChaining = false; - isoDepClearCounters(); - - if(gIsoDep.role == ISODEP_ROLE_PICC) - { - if(gIsoDep.txBufLen > 0U) - { - /* Ensure that an RTOX Ack is not being expected at moment */ - if( !gIsoDep.isWait4WTX ) - { - gIsoDep.state = ISODEP_ST_PICC_TX; - return ERR_NONE; - } - else - { - /* If RTOX Ack is expected, signal a pending Tx to be transmitted right after */ - gIsoDep.isTxPending = true; - } - } - - /* Digital 1.1 15.2.5.1 The first block SHALL be sent by the Reader/Writer */ - gIsoDep.state = ISODEP_ST_PICC_RX; - return ERR_NONE; - } - - gIsoDep.state = ISODEP_ST_PCD_TX; - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalIsoDepGetTransceiveStatus( void ) -{ - if( gIsoDep.role == ISODEP_ROLE_PICC) - { -#if RFAL_FEATURE_ISO_DEP_LISTEN - return isoDepDataExchangePICC(); -#else - return ERR_NOTSUPP; -#endif /* RFAL_FEATURE_ISO_DEP_LISTEN */ - } - else - { -#if RFAL_FEATURE_ISO_DEP_POLL - return isoDepDataExchangePCD( gIsoDep.rxLen, gIsoDep.rxChaining ); -#else - return ERR_NOTSUPP; -#endif /* RFAL_FEATURE_ISO_DEP_POLL */ - } -} - - -#if RFAL_FEATURE_ISO_DEP_LISTEN - -/*******************************************************************************/ -static ReturnCode isoDepDataExchangePICC( void ) -{ - uint8_t rxPCB; - ReturnCode ret; - - switch( gIsoDep.state ) - { - /*******************************************************************************/ - case ISODEP_ST_IDLE: - return ERR_NONE; - - - /*******************************************************************************/ - case ISODEP_ST_PICC_TX: - - ret = isoDepTx( isoDep_PCBIBlock( gIsoDep.blockNumber ), gIsoDep.txBuf, &gIsoDep.txBuf[gIsoDep.txBufInfPos], gIsoDep.txBufLen, RFAL_FWT_NONE ); - - /* Clear pending Tx flag */ - gIsoDep.isTxPending = false; - - switch( ret ) - { - case ERR_NONE: - gIsoDep.state = ISODEP_ST_PICC_RX; - return ERR_BUSY; - - default: - /* MISRA 16.4: no empty default statement (a comment being enough) */ - break; - } - return ret; - - - /*******************************************************************************/ - case ISODEP_ST_PICC_RX: - - ret = rfalGetTransceiveStatus(); - switch( ret ) - { - /*******************************************************************************/ - /* Data rcvd with error or timeout -> mute */ - case ERR_TIMEOUT: - case ERR_CRC: - case ERR_PAR: - case ERR_FRAMING: - - /* Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ - isoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); - - return ERR_BUSY; - - /*******************************************************************************/ - case ERR_LINK_LOSS: - return ret; /* Debug purposes */ - - case ERR_BUSY: - return ret; /* Debug purposes */ - - /*******************************************************************************/ - case ERR_NONE: - *gIsoDep.rxLen = rfalConvBitsToBytes( *gIsoDep.rxLen ); - break; - - /*******************************************************************************/ - default: - return ret; - } - break; - - - /*******************************************************************************/ - case ISODEP_ST_PICC_SWTX: - - if( !isoDepTimerisExpired( gIsoDep.WTXTimer ) ) /* Do nothing until WTX timer has expired */ - { - return ERR_BUSY; - } - - /* Set waiting for WTX Ack Flag */ - gIsoDep.isWait4WTX = true; - - /* Digital 1.1 15.2.2.9 - Calculate the WTXM such that FWTtemp <= FWTmax */ - gIsoDep.lastWTXM = (uint8_t)isoDep_WTXMListenerMax( gIsoDep.fwt ); - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_S_WTX, gIsoDep.lastWTXM ) ); - - gIsoDep.state = ISODEP_ST_PICC_RX; /* Go back to Rx to process WTX ack */ - return ERR_BUSY; - - - /*******************************************************************************/ - default: - return ERR_INTERNAL; - } - - /* ISO 14443-4 7.5.6.2 CE SHALL NOT attempt error recovery -> clear counters */ - isoDepClearCounters(); - - /*******************************************************************************/ - /* No error, process incoming msg */ - /*******************************************************************************/ - - /* Grab rcvd PCB */ - rxPCB = gIsoDep.rxBuf[ ISODEP_PCB_POS ]; - - - /*******************************************************************************/ - /* When DID=0 PCD may or may not use DID, therefore check whether current PCD request - * has DID present to be reflected on max INF length #454 */ - - /* ReCalculate Header Length */ - gIsoDep.hdrLen = RFAL_ISODEP_PCB_LEN; - gIsoDep.hdrLen += (uint8_t)( (isoDep_PCBhasDID(rxPCB)) ? RFAL_ISODEP_DID_LEN : 0U ); - gIsoDep.hdrLen += (uint8_t)( (isoDep_PCBhasNAD(rxPCB)) ? RFAL_ISODEP_NAD_LEN : 0U ); - - /* Store whether last PCD block had DID. for PICC special handling of DID = 0 */ - if( gIsoDep.did == RFAL_ISODEP_DID_00 ) - { - gIsoDep.lastDID00 = ( (isoDep_PCBhasDID(rxPCB)) ? true : false ); - } - - /*******************************************************************************/ - /* Check rcvd msg length, cannot be less then the expected header OR * - * if the rcvd msg exceeds our announced frame size (FSD) */ - if( ((*gIsoDep.rxLen) < gIsoDep.hdrLen) || ((*gIsoDep.rxLen) > (gIsoDep.ourFsx - ISODEP_CRC_LEN)) ) - { - isoDepReEnableRx( (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen ); - return ERR_BUSY; /* ERR_PROTO Ignore this protocol request */ - } - - /* If we are expecting DID, check if PCB signals its presence and if device ID match OR - * If our DID=0 and DID is sent but with an incorrect value */ - if( ((gIsoDep.did != RFAL_ISODEP_DID_00) && ( !isoDep_PCBhasDID(rxPCB) || (gIsoDep.did != gIsoDep.rxBuf[ ISODEP_DID_POS ]))) || - ((gIsoDep.did == RFAL_ISODEP_DID_00) && isoDep_PCBhasDID(rxPCB) && (RFAL_ISODEP_DID_00 != gIsoDep.rxBuf[ ISODEP_DID_POS ]) ) ) - { - isoDepReEnableRx( (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen ); - return ERR_BUSY; /* Ignore a wrong DID request */ - } - - /* If we aren't expecting NAD and it's received */ - if( (gIsoDep.nad == RFAL_ISODEP_NO_NAD) && isoDep_PCBhasNAD(rxPCB) ) - { - isoDepReEnableRx( (uint8_t*)gIsoDep.actvParam.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.actvParam.rxLen ); - return ERR_BUSY; /* Ignore a unexpected NAD request */ - } - - /*******************************************************************************/ - /* Process S-Block */ - /*******************************************************************************/ - if( isoDep_PCBisSBlock(rxPCB) ) - { - /* Check if is a Wait Time eXtension */ - if( isoDep_PCBisSWTX(rxPCB) ) - { - /* Check if we're expecting a S-WTX */ - if( isoDep_PCBisWTX( gIsoDep.lastPCB ) ) - { - /* Digital 1.1 15.2.2.11 S(WTX) Ack with different WTXM -> Protocol Error * - * Power level indication also should be set to 0 */ - if( ( gIsoDep.rxBuf[ gIsoDep.hdrLen ] == gIsoDep.lastWTXM) && ((*gIsoDep.rxLen - gIsoDep.hdrLen) == ISODEP_SWTX_INF_LEN) ) - { - /* Clear waiting for RTOX Ack Flag */ - gIsoDep.isWait4WTX = false; - - /* Check if a Tx is already pending */ - if( gIsoDep.isTxPending ) - { - /* Has a pending Tx, go immediately to TX */ - gIsoDep.state = ISODEP_ST_PICC_TX; - return ERR_BUSY; - } - - /* Set WTX timer */ - isoDepTimerStart( gIsoDep.WTXTimer, isoDep_WTXAdjust( (gIsoDep.lastWTXM * rfalConv1fcToMs( gIsoDep.fwt )) ) ); - - gIsoDep.state = ISODEP_ST_PICC_SWTX; - return ERR_BUSY; - } - } - /* Unexpected/Incorrect S-WTX, fall into reRenable */ - } - - /* Check if is a deselect request */ - if( isoDep_PCBisSDeselect(rxPCB) && ((*gIsoDep.rxLen - gIsoDep.hdrLen) == ISODEP_SDSL_INF_LEN) ) - { - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_S_DSL, RFAL_ISODEP_NO_PARAM ) ); - - rfalIsoDepInitialize(); /* Session finished reInit vars */ - return ERR_SLEEP_REQ; - } - - /* Unexpected S-Block, fall into reRenable */ - } - - /*******************************************************************************/ - /* Process R-Block */ - /*******************************************************************************/ - else if( isoDep_PCBisRBlock(rxPCB) && ((*gIsoDep.rxLen - gIsoDep.hdrLen) == ISODEP_RBLOCK_INF_LEN)) - { - if( isoDep_PCBisRACK(rxPCB) ) /* Check if is a R-ACK */ - { - if( isoDep_GetBN(rxPCB) == gIsoDep.blockNumber ) /* Check block number */ - { - /* Rule 11 - R(ACK) with current bn -> re-transmit */ - if( !isoDep_PCBisIBlock(gIsoDep.lastPCB) ) - { - isoDepReSendControlMsg(); - } - else - { - gIsoDep.state = ISODEP_ST_PICC_TX; - } - - return ERR_BUSY; - } - else - { - if( !gIsoDep.isTxChaining ) - { - /* Rule 13 violation R(ACK) without performing chaining */ - isoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); - return ERR_BUSY; - } - - /* Rule E - R(ACK) with not current bn -> toogle bn */ - isoDep_ToggleBN( gIsoDep.blockNumber ); - - /* This block has been transmitted and acknowledged, perform WTX until next data is provided */ - - /* Rule 9 - PICC is allowed to send an S(WTX) instead of an I-block or an R(ACK) */ - isoDepTimerStart( gIsoDep.WTXTimer, isoDep_WTXAdjust( rfalConv1fcToMs( gIsoDep.fwt )) ); - gIsoDep.state = ISODEP_ST_PICC_SWTX; - - /* Rule 13 - R(ACK) with not current bn -> continue chaining */ - return ERR_NONE; /* This block has been transmitted */ - } - } - else if( isoDep_PCBisRNAK(rxPCB) ) /* Check if is a R-NACK */ - { - if( isoDep_GetBN(rxPCB) == gIsoDep.blockNumber ) /* Check block number */ - { - /* Rule 11 - R(NAK) with current bn -> re-transmit last x-Block */ - if( !isoDep_PCBisIBlock(gIsoDep.lastPCB) ) - { - isoDepReSendControlMsg(); - } - else - { - gIsoDep.state = ISODEP_ST_PICC_TX; - } - - return ERR_BUSY; - } - else - { - /* Rule 12 - R(NAK) with not current bn -> R(ACK) */ - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); - - return ERR_BUSY; - } - } - else - { - /* MISRA 15.7 - Empty else */ - } - - /* Unexpected R-Block, fall into reRenable */ - } - - /*******************************************************************************/ - /* Process I-Block */ - /*******************************************************************************/ - else if( isoDep_PCBisIBlock(rxPCB) ) - { - /* Rule D - When an I-block is received, the PICC shall toggle its block number before sending a block */ - isoDep_ToggleBN( gIsoDep.blockNumber ); - - /*******************************************************************************/ - /* Check if the block number is the one expected */ - /* Check if PCD sent an I-Block instead ACK/NACK when we are chaining */ - if( (isoDep_GetBN(rxPCB) != gIsoDep.blockNumber) || (gIsoDep.isTxChaining) ) - { - /* Remain in the same Block Number */ - isoDep_ToggleBN( gIsoDep.blockNumber ); - - /* ISO 14443-4 7.5.6.2 & Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ - isoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); - return ERR_BUSY; - } - - /*******************************************************************************/ - /* is PCD performing chaining ? */ - if( isoDep_PCBisChaining(rxPCB) ) - { - gIsoDep.isRxChaining = true; - *gIsoDep.rxChaining = true; /* Output Parameter*/ - - EXIT_ON_ERR( ret, isoDepHandleControlMsg( ISODEP_R_ACK, RFAL_ISODEP_NO_PARAM ) ); - - /* Received I-Block with chaining, send current data to DH */ - - /* remove ISO DEP header, check is necessary to move the INF data on the buffer */ - *gIsoDep.rxLen -= gIsoDep.hdrLen; - if( (gIsoDep.hdrLen != gIsoDep.rxBufInfPos) && (*gIsoDep.rxLen > 0U) ) - { - ST_MEMMOVE( &gIsoDep.rxBuf[gIsoDep.rxBufInfPos], &gIsoDep.rxBuf[gIsoDep.hdrLen], *gIsoDep.rxLen ); - } - return ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/ - } - - - /*******************************************************************************/ - /* PCD is not performing chaining */ - gIsoDep.isRxChaining = false; /* clear PCD chaining flag */ - *gIsoDep.rxChaining = false; /* Output Parameter */ - - /* remove ISO DEP header, check is necessary to move the INF data on the buffer */ - *gIsoDep.rxLen -= gIsoDep.hdrLen; - if( (gIsoDep.hdrLen != gIsoDep.rxBufInfPos) && (*gIsoDep.rxLen > 0U) ) - { - ST_MEMMOVE( &gIsoDep.rxBuf[gIsoDep.rxBufInfPos], &gIsoDep.rxBuf[gIsoDep.hdrLen], *gIsoDep.rxLen ); - } - - - /*******************************************************************************/ - /* Reception done, send data back and start WTX timer */ - isoDepTimerStart( gIsoDep.WTXTimer, isoDep_WTXAdjust( rfalConv1fcToMs( gIsoDep.fwt )) ); - - gIsoDep.state = ISODEP_ST_PICC_SWTX; - return ERR_NONE; - } - else - { - /* MISRA 15.7 - Empty else */ - } - - /* Unexpected/Unknown Block */ - /* ISO 14443-4 7.5.6.2 & Digital 1.1 - 15.2.6.2 The CE SHALL NOT attempt error recovery and remains in Rx mode upon Transmission or a Protocol Error */ - isoDepReEnableRx( (uint8_t*)gIsoDep.rxBuf, sizeof( rfalIsoDepBufFormat ), gIsoDep.rxLen ); - - return ERR_BUSY; -} -#endif /* RFAL_FEATURE_ISO_DEP_LISTEN */ - - -#if RFAL_FEATURE_ISO_DEP_POLL - -#if RFAL_FEATURE_NFCA - -/*******************************************************************************/ -ReturnCode rfalIsoDepRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats , uint8_t *atsLen) -{ - uint16_t rcvLen; - ReturnCode ret; - rfalIsoDepRats ratsReq; - - if( ats == NULL ) - { - return ERR_PARAM; - } - - /*******************************************************************************/ - /* Compose RATS */ - ratsReq.CMD = RFAL_ISODEP_CMD_RATS; - ratsReq.PARAM = (((uint8_t)FSDI << RFAL_ISODEP_RATS_PARAM_FSDI_SHIFT) & RFAL_ISODEP_RATS_PARAM_FSDI_MASK) | (DID & RFAL_ISODEP_RATS_PARAM_DID_MASK); - - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&ratsReq, sizeof(rfalIsoDepRats), (uint8_t*)ats, sizeof(rfalIsoDepAts), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ISODEP_T4T_FWT_ACTIVATION ); - - if( ret == ERR_NONE ) - { - /* Check for valid ATS length Digital 1.1 13.6.2.1 & 13.6.2.3 */ - if( (rcvLen < RFAL_ISODEP_ATS_MIN_LEN) || (rcvLen > RFAL_ISODEP_ATS_MAX_LEN) || (ats->TL != rcvLen) ) - { - return ERR_PROTO; - } - - /* Assign our FSx, in case the a Deselect is send without Transceive */ - gIsoDep.ourFsx = rfalIsoDepFSxI2FSx( (uint8_t)FSDI ); - } - - /* Check and assign if ATS length was requested (length also available on TL) */ - if( atsLen != NULL ) - { - *atsLen = (uint8_t)rcvLen; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalIsoDepPPS( uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes ) -{ - uint16_t rcvLen; - ReturnCode ret; - rfalIsoDepPpsReq ppsReq; - - if( (ppsRes == NULL) || (DSI > RFAL_BR_848) || (DRI > RFAL_BR_848) || (DID > RFAL_ISODEP_DID_MAX) ) - { - return ERR_PARAM; - } - - /*******************************************************************************/ - /* Compose PPS Request */ - ppsReq.PPSS = (RFAL_ISODEP_PPS_SB | (DID & RFAL_ISODEP_PPS_SB_DID_MASK)); - ppsReq.PPS0 = RFAL_ISODEP_PPS_PPS0_PPS1_PRESENT; - ppsReq.PPS1 = (RFAL_ISODEP_PPS_PPS1 | ((((uint8_t)DSI<PPSS != ppsReq.PPSS) ) - { - return ERR_PROTO; - } - } - return ret; -} - -#endif /* RFAL_FEATURE_NFCA */ - - -#if RFAL_FEATURE_NFCB - -/*******************************************************************************/ -ReturnCode rfalIsoDepATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen ) -{ - uint16_t rcvLen; - ReturnCode ret; - rfalIsoDepAttribCmd attribCmd; - - - if( (attribRes == NULL) || (attribResLen == NULL) || (DSI > RFAL_BR_848) || (DRI > RFAL_BR_848) || (DID > RFAL_ISODEP_DID_MAX) ) - { - return ERR_NONE; - } - - /*******************************************************************************/ - /* Compose ATTRIB command */ - attribCmd.cmd = RFAL_ISODEP_CMD_ATTRIB; - attribCmd.Param.PARAM1 = PARAM1; - attribCmd.Param.PARAM2 = ( ((((uint8_t)DSI< 0U) ) - { - ST_MEMCPY(attribCmd.HLInfo, HLInfo, MIN(HLInfoLen, RFAL_ISODEP_ATTRIB_HLINFO_LEN) ); - } - - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&attribCmd, (RFAL_ISODEP_ATTRIB_HDR_LEN + MIN((uint16_t)HLInfoLen, RFAL_ISODEP_ATTRIB_HLINFO_LEN)), (uint8_t*)attribRes, sizeof(rfalIsoDepAttribRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, fwt ); - - *attribResLen = (uint8_t)rcvLen; - - if( ret == ERR_NONE ) - { - /* Check a for valid ATTRIB Response Digital 1.1 15.6.2.1 */ - if( (rcvLen < RFAL_ISODEP_ATTRIB_RES_HDR_LEN) || ((attribRes->mbliDid & RFAL_ISODEP_ATTRIB_RES_DID_MASK) != DID) ) - { - return ERR_PROTO; - } - } - - return ret; -} - -#endif /* RFAL_FEATURE_NFCB */ - - -#if RFAL_FEATURE_NFCA - -/*******************************************************************************/ -ReturnCode rfalIsoDepPollAHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, rfalIsoDepDevice *isoDepDev ) -{ - uint8_t RATSretries; - uint8_t msgIt; - ReturnCode ret; - rfalIsoDepPpsRes ppsRes; - - if( isoDepDev == NULL ) - { - return ERR_PARAM; - } - - /* Enable EMD handling according Digital 1.1 4.1.1.1 ; EMVCo 2.6 4.9.2 */ - rfalSetErrorHandling( RFAL_ERRORHANDLING_EMVCO ); - - RATSretries = gIsoDep.maxRetriesRATS; - - /***************************************************************************/ - /* Send RATS */ - do - { - /* Digital 1.1 13.7.1.1 and ISO 14443-4 5.6.1.1 - Upon a failed RATS it may be retransmited [0,1] */ - ret = rfalIsoDepRATS( FSDI, DID, &isoDepDev->activation.A.Listener.ATS, &isoDepDev->activation.A.Listener.ATSLen ); - - /* EMVCo 2.6 9.6.1.1 & 9.6.1.2 If a timeout error is detected retransmit, on transmission error abort */ - if( (gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV) && (ret != ERR_NONE) && (ret != ERR_TIMEOUT) ) - { - break; - } - - platformDelay(1); - } - while( ((RATSretries--) != 0U) && (ret != ERR_NONE) ); - - - - /* Switch between NFC Forum and ISO14443-4 behaviour #595 - * ISO14443-4 5.6.1 If RATS fails, a Deactivation sequence should be performed as defined on clause 8 - * Activity 1.1 9.6 Device Deactivation Activity is to be only performed when there's an active device */ - if( ret != ERR_NONE ) - { - if( gIsoDep.compMode == RFAL_COMPLIANCE_MODE_ISO ) - { - rfalIsoDepDeselect(); - } - return ret; - } - - /*******************************************************************************/ - /* Process ATS Response */ - isoDepDev->info.FWI = RFAL_ISODEP_FWI_DEFAULT; /* Default value EMVCo 2.6 5.7.2.6 */ - isoDepDev->info.SFGI = 0; - isoDepDev->info.MBL = 0; - isoDepDev->info.DSI = RFAL_BR_106; - isoDepDev->info.DRI = RFAL_BR_106; - isoDepDev->info.FSxI = (uint8_t)RFAL_ISODEP_FSXI_32; /* FSC default value is 32 bytes ISO14443-A 5.2.3 */ - - - /*******************************************************************************/ - /* Check for ATS optional fields */ - if( isoDepDev->activation.A.Listener.ATS.TL > RFAL_ISODEP_ATS_MIN_LEN ) - { - msgIt = RFAL_ISODEP_ATS_MIN_LEN; - - /* Format byte T0 is optional, if present assign FSDI */ - isoDepDev->info.FSxI = (isoDepDev->activation.A.Listener.ATS.T0 & RFAL_ISODEP_ATS_T0_FSCI_MASK); - - /* T0 has already been processed, always the same position */ - msgIt++; - - /* Check if TA is present */ - if( (isoDepDev->activation.A.Listener.ATS.T0 & RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK) != 0U ) - { - rfalIsoDepCalcBitRate( maxBR, ((uint8_t*)&isoDepDev->activation.A.Listener.ATS)[msgIt++], &isoDepDev->info.DSI, &isoDepDev->info.DRI ); - } - - /* Check if TB is present */ - if( (isoDepDev->activation.A.Listener.ATS.T0 & RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK) != 0U ) - { - isoDepDev->info.SFGI = ((uint8_t*)&isoDepDev->activation.A.Listener.ATS)[msgIt++]; - isoDepDev->info.FWI = (uint8_t)((isoDepDev->info.SFGI >> RFAL_ISODEP_ATS_TB_FWI_SHIFT) & RFAL_ISODEP_ATS_FWI_MASK); - isoDepDev->info.SFGI &= RFAL_ISODEP_ATS_TB_SFGI_MASK; - } - - /* Check if TC is present */ - if( (isoDepDev->activation.A.Listener.ATS.T0 & RFAL_ISODEP_ATS_T0_TC_PRESENCE_MASK) != 0U ) - { - /* Check for Protocol features support */ - /* Advanced protocol features defined on Digital 1.0 Table 69, removed after */ - isoDepDev->info.supAdFt = (((((uint8_t*)&isoDepDev->activation.A.Listener.ATS)[msgIt] & RFAL_ISODEP_ATS_TC_ADV_FEAT) != 0U) ? true : false); - isoDepDev->info.supDID = (((((uint8_t*)&isoDepDev->activation.A.Listener.ATS)[msgIt] & RFAL_ISODEP_ATS_TC_DID) != 0U) ? true : false); - isoDepDev->info.supNAD = (((((uint8_t*)&isoDepDev->activation.A.Listener.ATS)[msgIt++] & RFAL_ISODEP_ATS_TC_NAD) != 0U) ? true : false); - } - } - - isoDepDev->info.FSx = rfalIsoDepFSxI2FSx(isoDepDev->info.FSxI); - - isoDepDev->info.SFGT = rfalIsoDepSFGI2SFGT( (uint8_t)isoDepDev->info.SFGI ); - isoDepTimerStart( gIsoDep.SFGTTimer, isoDepDev->info.SFGT ); - - isoDepDev->info.FWT = rfalIsoDepFWI2FWT( isoDepDev->info.FWI ); - isoDepDev->info.dFWT = RFAL_ISODEP_DFWT_20; - - isoDepDev->info.DID = ( (isoDepDev->info.supDID) ? DID : RFAL_ISODEP_NO_DID); - isoDepDev->info.NAD = RFAL_ISODEP_NO_NAD; - - - /*******************************************************************************/ - /* If higher bit rates are supported by both devices, send PPS */ - if( (isoDepDev->info.DSI != RFAL_BR_106) || (isoDepDev->info.DRI != RFAL_BR_106) ) - { - /* Wait until SFGT has been fulfilled */ - while( !isoDepTimerisExpired( gIsoDep.SFGTTimer ) ) { /* MISRA 15.6: mandatory brackets */ }; - - ret = rfalIsoDepPPS( isoDepDev->info.DID, isoDepDev->info.DSI, isoDepDev->info.DRI, &ppsRes ); - - if( ret == ERR_NONE ) - { - /* DSI code the divisor from PICC to PCD */ - /* DRI code the divisor from PCD to PICC */ - rfalSetBitRate( isoDepDev->info.DRI, isoDepDev->info.DSI ); - } - else - { - isoDepDev->info.DSI = RFAL_BR_106; - isoDepDev->info.DRI = RFAL_BR_106; - } - } - - /*******************************************************************************/ - /* Store already FS info, rfalIsoDepGetMaxInfLen() may be called before setting TxRx params */ - gIsoDep.fsx = isoDepDev->info.FSx; - gIsoDep.ourFsx = rfalIsoDepFSxI2FSx( (uint8_t)FSDI ); - - return ERR_NONE; -} - -#endif /* RFAL_FEATURE_NFCA */ - -#if RFAL_FEATURE_NFCB - -/*******************************************************************************/ -ReturnCode rfalIsoDepPollBHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, uint8_t PARAM1, const rfalNfcbListenDevice *nfcbDev, const uint8_t* HLInfo, uint8_t HLInfoLen, rfalIsoDepDevice *isoDepDev ) -{ - ReturnCode ret; - uint8_t mbli; - - /***************************************************************************/ - /* Initialize ISO-DEP Device with info from SENSB_RES */ - isoDepDev->info.FWI = ((nfcbDev->sensbRes.protInfo.FwiAdcFo >> RFAL_NFCB_SENSB_RES_FWI_SHIFT) & RFAL_NFCB_SENSB_RES_FWI_MASK); - isoDepDev->info.FWT = rfalIsoDepFWI2FWT( isoDepDev->info.FWI ); - isoDepDev->info.dFWT = RFAL_NFCB_DFWT; - isoDepDev->info.SFGI = (((uint32_t)nfcbDev->sensbRes.protInfo.SFGI >> RFAL_NFCB_SENSB_RES_SFGI_SHIFT) & RFAL_NFCB_SENSB_RES_SFGI_MASK); - isoDepDev->info.SFGT = rfalIsoDepSFGI2SFGT( (uint8_t)isoDepDev->info.SFGI ); - isoDepDev->info.FSxI = ((nfcbDev->sensbRes.protInfo.FsciProType >> RFAL_NFCB_SENSB_RES_FSCI_SHIFT) & RFAL_NFCB_SENSB_RES_FSCI_MASK); - isoDepDev->info.FSx = rfalIsoDepFSxI2FSx(isoDepDev->info.FSxI); - isoDepDev->info.DID = DID; - isoDepDev->info.supDID = ((( nfcbDev->sensbRes.protInfo.FwiAdcFo & RFAL_NFCB_SENSB_RES_FO_DID_MASK ) != 0U) ? true : false); - isoDepDev->info.supNAD = ((( nfcbDev->sensbRes.protInfo.FwiAdcFo & RFAL_NFCB_SENSB_RES_FO_NAD_MASK ) != 0U) ? true : false); - - - /* Check if DID requested is supported by PICC */ - if( (DID != RFAL_ISODEP_NO_DID) && (!isoDepDev->info.supDID) ) - { - return ERR_PARAM; - } - - /* Enable EMD handling according Digital 2.1 4.1.1.1 ; EMVCo 3.0 4.9.2 */ - rfalSetErrorHandling( RFAL_ERRORHANDLING_EMVCO ); - - /***************************************************************************/ - /* Set FDT Poll to be used on upcoming communications */ - if( gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV ) - { - /* Disregard Minimum TR2 returned by PICC, always use FDTb MIN EMVCo 3.0 6.3.2.10 */ - rfalSetFDTPoll( RFAL_FDT_POLL_NFCB_POLLER ); - } - else - { - /* Apply minimum TR2 from SENSB_RES Digital 2.1 7.6.2.23 */ - rfalSetFDTPoll( rfalNfcbTR2ToFDT(((nfcbDev->sensbRes.protInfo.FsciProType >>RFAL_NFCB_SENSB_RES_PROTO_TR2_SHIFT) & RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK)) ); - } - - - /* Calculate max Bit Rate */ - rfalIsoDepCalcBitRate( maxBR, nfcbDev->sensbRes.protInfo.BRC, &isoDepDev->info.DSI, &isoDepDev->info.DRI ); - - /***************************************************************************/ - /* Send ATTRIB Command */ - ret = rfalIsoDepATTRIB( (const uint8_t*)&nfcbDev->sensbRes.nfcid0, - (((nfcbDev->sensbRes.protInfo.FwiAdcFo & RFAL_NFCB_SENSB_RES_ADC_ADV_FEATURE_MASK) != 0U) ? PARAM1 : RFAL_ISODEP_ATTRIB_REQ_PARAM1_DEFAULT), - isoDepDev->info.DSI, - isoDepDev->info.DRI, - FSDI, - (gIsoDep.compMode == RFAL_COMPLIANCE_MODE_EMV) ? RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK : (nfcbDev->sensbRes.protInfo.FsciProType & ( (RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK<info.FWT + isoDepDev->info.dFWT), - &isoDepDev->activation.B.Listener.ATTRIB_RES, - &isoDepDev->activation.B.Listener.ATTRIB_RESLen - ); - - /***************************************************************************/ - /* Process ATTRIB Response */ - if( ret == ERR_NONE ) - { - /* Digital 1.1 14.6.2.3 - Check if received DID match */ - if( (isoDepDev->activation.B.Listener.ATTRIB_RES.mbliDid & RFAL_ISODEP_ATTRIB_RES_DID_MASK) != DID ) - { - return ERR_PROTO; - } - - /* Retrieve MBLI and calculate new FDS/MBL (Maximum Buffer Length) */ - mbli = ((isoDepDev->activation.B.Listener.ATTRIB_RES.mbliDid >> RFAL_ISODEP_ATTRIB_RES_MBLI_SHIFT) & RFAL_ISODEP_ATTRIB_RES_MBLI_MASK); - if( mbli > 0U) - { - /* Digital 1.1 14.6.2 Calculate Maximum Buffer Length MBL = FSC x 2^(MBLI-1) */ - isoDepDev->info.MBL = (isoDepDev->info.FSx * ((uint32_t)1U<<(mbli-1U))); - } - - /* DSI code the divisor from PICC to PCD */ - /* DRI code the divisor from PCD to PICC */ - rfalSetBitRate( isoDepDev->info.DRI, isoDepDev->info.DSI ); - - - if( (nfcbDev->sensbRes.protInfo.FwiAdcFo & RFAL_NFCB_SENSB_RES_ADC_ADV_FEATURE_MASK) != 0U ) - { - /* REMARK: SoF EoF TR0 and TR1 are not passed on to RF layer */ - } - - /* Start the SFGT timer */ - isoDepTimerStart( gIsoDep.SFGTTimer, isoDepDev->info.SFGT ); - } - else - { - isoDepDev->info.DSI = RFAL_BR_106; - isoDepDev->info.DRI = RFAL_BR_106; - } - - /*******************************************************************************/ - /* Store already FS info, rfalIsoDepGetMaxInfLen() may be called before setting TxRx params */ - gIsoDep.fsx = isoDepDev->info.FSx; - gIsoDep.ourFsx = rfalIsoDepFSxI2FSx( (uint8_t)FSDI ); - - return ret; -} - -#endif /* RFAL_FEATURE_NFCB */ - - -/*******************************************************************************/ -ReturnCode rfalIsoDepPollHandleSParameters( rfalIsoDepDevice *isoDepDev, rfalBitRate maxTxBR, rfalBitRate maxRxBR ) -{ - uint8_t it; - uint8_t supPCD2PICC; - uint8_t supPICC2PCD; - uint8_t currenttxBR; - uint8_t currentrxBR; - rfalBitRate txBR; - rfalBitRate rxBR; - uint16_t rcvLen; - ReturnCode ret; - rfalIsoDepControlMsgSParam sParam; - - - if( (isoDepDev == NULL) || (maxTxBR > RFAL_BR_13560) || (maxRxBR > RFAL_BR_13560) ) - { - return ERR_PARAM; - } - - it = 0; - supPICC2PCD = 0x00; - supPCD2PICC = 0x00; - txBR = RFAL_BR_106; - rxBR = RFAL_BR_106; - sParam.pcb = ISODEP_PCB_SPARAMETERS; - - /*******************************************************************************/ - /* Send S(PARAMETERS) - Block Info */ - sParam.sParam.tag = RFAL_ISODEP_SPARAM_TAG_BLOCKINFO; - sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_BRREQ; - sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_BRREQ_LEN; - sParam.sParam.length = it; - - EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&sParam, (RFAL_ISODEP_SPARAM_HDR_LEN + (uint16_t)it), (uint8_t*)&sParam, sizeof(rfalIsoDepControlMsgSParam), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, (isoDepDev->info.FWT + isoDepDev->info.dFWT) )); - - it = 0; - - /*******************************************************************************/ - /* Check S(PARAMETERS) response */ - if( (sParam.pcb != ISODEP_PCB_SPARAMETERS) || (sParam.sParam.tag != RFAL_ISODEP_SPARAM_TAG_BLOCKINFO) || - (sParam.sParam.value[it] != RFAL_ISODEP_SPARAM_TAG_BRIND) || (rcvLen < RFAL_ISODEP_SPARAM_HDR_LEN) || - (rcvLen != ((uint16_t)sParam.sParam.length + RFAL_ISODEP_SPARAM_HDR_LEN)) ) - { - return ERR_PROTO; - } - - /* Retrieve PICC's bit rate PICC capabilities */ - for( it=0; it<(rcvLen-(uint16_t)RFAL_ISODEP_SPARAM_TAG_LEN); it++ ) - { - if( (sParam.sParam.value[it] == RFAL_ISODEP_SPARAM_TAG_SUP_PCD2PICC) && (sParam.sParam.value[it+(uint16_t)RFAL_ISODEP_SPARAM_TAG_LEN] == RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN) ) - { - supPCD2PICC = sParam.sParam.value[it + RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN]; - } - - if( (sParam.sParam.value[it] == RFAL_ISODEP_SPARAM_TAG_SUP_PICC2PCD) && (sParam.sParam.value[it+(uint16_t)RFAL_ISODEP_SPARAM_TAG_LEN] == RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN) ) - { - supPICC2PCD = sParam.sParam.value[it + RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN]; - } - } - - /*******************************************************************************/ - /* Check if requested bit rates are supported by PICC */ - if( (supPICC2PCD == 0x00U) || (supPCD2PICC == 0x00U) ) - { - return ERR_PROTO; - } - - for( it=0; it<=(uint8_t)maxTxBR; it++ ) - { - if( (supPCD2PICC & (0x01U << it)) != 0U ) - { - txBR = (rfalBitRate)it; /* PRQA S 4342 # MISRA 10.5 - Layout of enum rfalBitRate and above clamping of maxTxBR guarantee no invalid enum values to be created */ - } - } - for( it=0; it<=(uint8_t)maxRxBR; it++ ) - { - if( (supPICC2PCD & (0x01U << it)) != 0U ) - { - rxBR = (rfalBitRate)it; /* PRQA S 4342 # MISRA 10.5 - Layout of enum rfalBitRate and above clamping of maxTxBR guarantee no invalid enum values to be created */ - } - } - - it = 0; - currenttxBR = (uint8_t)txBR; - currentrxBR = (uint8_t)rxBR; - - /*******************************************************************************/ - /* Send S(PARAMETERS) - Bit rates Activation */ - sParam.sParam.tag = RFAL_ISODEP_SPARAM_TAG_BLOCKINFO; - sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_BRACT; - sParam.sParam.value[it++] = ( RFAL_ISODEP_SPARAM_TVL_HDR_LEN + RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN + RFAL_ISODEP_SPARAM_TVL_HDR_LEN + RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN); - sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_SEL_PCD2PICC; - sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN; - sParam.sParam.value[it++] = ((uint8_t)0x01U << currenttxBR); - sParam.sParam.value[it++] = 0x00U; - sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_SEL_PICC2PCD; - sParam.sParam.value[it++] = RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN; - sParam.sParam.value[it++] = ((uint8_t)0x01U << currentrxBR); - sParam.sParam.value[it++] = 0x00U; - sParam.sParam.length = it; - - EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&sParam, (RFAL_ISODEP_SPARAM_HDR_LEN + (uint16_t)it), (uint8_t*)&sParam, sizeof(rfalIsoDepControlMsgSParam), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, (isoDepDev->info.FWT + isoDepDev->info.dFWT) )); - - it = 0; - - /*******************************************************************************/ - /* Check S(PARAMETERS) Acknowledge */ - if( (sParam.pcb != ISODEP_PCB_SPARAMETERS) || (sParam.sParam.tag != RFAL_ISODEP_SPARAM_TAG_BLOCKINFO) || - (sParam.sParam.value[it] != RFAL_ISODEP_SPARAM_TAG_BRACK) || (rcvLen < RFAL_ISODEP_SPARAM_HDR_LEN) ) - { - return ERR_PROTO; - } - - EXIT_ON_ERR( ret, rfalSetBitRate( txBR, rxBR ) ); - - isoDepDev->info.DRI = txBR; - isoDepDev->info.DSI = rxBR; - - return ERR_NONE; -} - - -/*******************************************************************************/ -static void rfalIsoDepCalcBitRate( rfalBitRate maxAllowedBR, uint8_t piccBRCapability, rfalBitRate *dsi, rfalBitRate *dri ) -{ - uint8_t driMask; - uint8_t dsiMask; - int8_t i; - bool bitrateFound; - rfalBitRate curMaxBR; - - curMaxBR = maxAllowedBR; - - do - { - bitrateFound = true; - - (*dsi) = RFAL_BR_106; - (*dri) = RFAL_BR_106; - - /* Digital 1.0 5.6.2.5 & 11.6.2.14: A received RFU value of b4 = 1b MUST be interpreted as if b7 to b1 ? 0000000b (only 106 kbits/s in both direction) */ - if( ((RFAL_ISODEP_BITRATE_RFU_MASK & piccBRCapability) != 0U) || (curMaxBR > RFAL_BR_848) ) - { - return; - } - - /***************************************************************************/ - /* Determine Listen->Poll bit rate */ - dsiMask = (piccBRCapability & RFAL_ISODEP_BSI_MASK); - for( i = 2; i >= 0; i-- ) // Check supported bit rate from the highest - { - if (((dsiMask & (0x10U << (uint8_t)i)) != 0U) && (((uint8_t)i+1U) <= (uint8_t)curMaxBR)) - { - uint8_t newdsi = ((uint8_t) i) + 1U; - (*dsi) = (rfalBitRate)newdsi; /* PRQA S 4342 # MISRA 10.5 - Layout of enum rfalBitRate and range of loop variable guarantee no invalid enum values to be created */ - break; - } - } - - /***************************************************************************/ - /* Determine Poll->Listen bit rate */ - driMask = (piccBRCapability & RFAL_ISODEP_BRI_MASK); - for( i = 2; i >= 0; i-- ) /* Check supported bit rate from the highest */ - { - if (((driMask & (0x01U << (uint8_t)i)) != 0U) && (((uint8_t)i+1U) <= (uint8_t)curMaxBR)) - { - uint8_t newdri = ((uint8_t) i) + 1U; - (*dri) = (rfalBitRate)newdri; /* PRQA S 4342 # MISRA 10.5 - Layout of enum rfalBitRate and range of loop variable guarantee no invalid enum values to be created */ - break; - } - } - - /***************************************************************************/ - /* Check if different bit rate is supported */ - - /* Digital 1.0 Table 67: if b8=1b, then only the same bit rate divisor for both directions is supported */ - if( (piccBRCapability & RFAL_ISODEP_SAME_BITRATE_MASK) != 0U ) - { - (*dsi) = MIN((*dsi), (*dri)); - (*dri) = (*dsi); - /* Check that the baudrate is supported */ - if( (RFAL_BR_106 != (*dsi)) && ( !(((dsiMask & (0x10U << ((uint8_t)(*dsi) - 1U))) != 0U) && ((driMask & (0x01U << ((uint8_t)(*dri) - 1U))) != 0U)) ) ) - { - bitrateFound = false; - curMaxBR = (*dsi); /* set allowed bitrate to be lowest and determine bit rate again */ - } - } - } while (!(bitrateFound)); - -} - -/*******************************************************************************/ -static uint32_t rfalIsoDepSFGI2SFGT( uint8_t sfgi ) -{ - uint32_t sfgt; - uint8_t tmpSFGI; - - tmpSFGI = sfgi; - - if (tmpSFGI > ISODEP_SFGI_MAX) - { - tmpSFGI = ISODEP_SFGI_MIN; - } - - if (tmpSFGI != ISODEP_SFGI_MIN) - { - /* If sfgi != 0 wait SFGT + dSFGT Digital 1.1 13.8.2.1 */ - sfgt = isoDepCalcSGFT(sfgi) + isoDepCalcdSGFT(sfgi); - } - /* Otherwise use FDTPoll min Digital 1.1 13.8.2.3*/ - else - { - sfgt = RFAL_FDT_POLL_NFCA_POLLER; - } - - /* Convert carrier cycles to milli seconds */ - return (rfalConv1fcToMs(sfgt) + 1U); -} - -#endif /* RFAL_FEATURE_ISO_DEP_POLL */ - - - /*******************************************************************************/ - static void rfalIsoDepApdu2IBLockParam( rfalIsoDepApduTxRxParam apduParam, rfalIsoDepTxRxParam *iBlockParam, uint16_t txPos, uint16_t rxPos ) -{ - NO_WARNING(rxPos); /* Keep this param for future use */ - - iBlockParam->DID = apduParam.DID; - iBlockParam->FSx = apduParam.FSx; - iBlockParam->ourFSx = apduParam.ourFSx; - iBlockParam->FWT = apduParam.FWT; - iBlockParam->dFWT = apduParam.dFWT; - - if( (apduParam.txBufLen - txPos) > rfalIsoDepGetMaxInfLen() ) - { - iBlockParam->isTxChaining = true; - iBlockParam->txBufLen = rfalIsoDepGetMaxInfLen(); - } - else - { - iBlockParam->isTxChaining = false; - iBlockParam->txBufLen = (apduParam.txBufLen - txPos); - } - - /* TxBuf is moved to the beginning for every I-Block */ - iBlockParam->txBuf = (rfalIsoDepBufFormat*)apduParam.txBuf; /* PRQA S 0310 # MISRA 11.3 - Intentional safe cast to avoiding large buffer duplication */ - iBlockParam->rxBuf = apduParam.tmpBuf; /* Simply using the apdu buffer is not possible because of current ACK handling */ - iBlockParam->isRxChaining = &gIsoDep.isAPDURxChaining; - iBlockParam->rxLen = apduParam.rxLen; -} - - -/*******************************************************************************/ -ReturnCode rfalIsoDepStartApduTransceive( rfalIsoDepApduTxRxParam param ) -{ - rfalIsoDepTxRxParam txRxParam; - - /* Initialize and store APDU context */ - gIsoDep.APDUParam = param; - gIsoDep.APDUTxPos = 0; - gIsoDep.APDURxPos = 0; - - /* Assign current FSx to calculate INF length */ - gIsoDep.ourFsx = param.ourFSx; - gIsoDep.fsx = param.FSx; - - /* Convert APDU TxRxParams to I-Block TxRxParams */ - rfalIsoDepApdu2IBLockParam( gIsoDep.APDUParam, &txRxParam, gIsoDep.APDUTxPos, gIsoDep.APDURxPos ); - - return rfalIsoDepStartTransceive( txRxParam ); -} - - -/*******************************************************************************/ -ReturnCode rfalIsoDepGetApduTransceiveStatus( void ) -{ - ReturnCode ret; - rfalIsoDepTxRxParam txRxParam; - - ret = rfalIsoDepGetTransceiveStatus(); - switch( ret ) - { - /*******************************************************************************/ - case ERR_NONE: - - /* Check if we are still doing chaining on Tx */ - if( gIsoDep.isTxChaining ) - { - /* Add already Tx bytes */ - gIsoDep.APDUTxPos += gIsoDep.txBufLen; - - /* Convert APDU TxRxParams to I-Block TxRxParams */ - rfalIsoDepApdu2IBLockParam( gIsoDep.APDUParam, &txRxParam, gIsoDep.APDUTxPos, gIsoDep.APDURxPos ); - - if( txRxParam.txBufLen > 0U ) /* MISRA 21.18 */ - { - /* Move next I-Block to beginning of APDU Tx buffer */ - ST_MEMCPY( gIsoDep.APDUParam.txBuf->apdu, &gIsoDep.APDUParam.txBuf->apdu[gIsoDep.APDUTxPos], txRxParam.txBufLen ); - } - - rfalIsoDepStartTransceive( txRxParam ); - return ERR_BUSY; - } - - if( *gIsoDep.APDUParam.rxLen > 0U ) /* MISRA 21.18 */ - { - /* Copy packet from tmp buffer to APDU buffer */ - ST_MEMCPY( &gIsoDep.APDUParam.rxBuf->apdu[gIsoDep.APDURxPos], gIsoDep.APDUParam.tmpBuf->inf, *gIsoDep.APDUParam.rxLen ); - gIsoDep.APDURxPos += *gIsoDep.APDUParam.rxLen; - } - - /* APDU TxRx is done */ - break; - - /*******************************************************************************/ - case ERR_AGAIN: - - if( *gIsoDep.APDUParam.rxLen > 0U ) /* MISRA 21.18 */ - { - /* Copy chained packet from tmp buffer to APDU buffer */ - ST_MEMCPY( &gIsoDep.APDUParam.rxBuf->apdu[gIsoDep.APDURxPos], gIsoDep.APDUParam.tmpBuf->inf, *gIsoDep.APDUParam.rxLen ); - gIsoDep.APDURxPos += *gIsoDep.APDUParam.rxLen; - } - - /* Wait for next I-Block */ - return ERR_BUSY; - - /*******************************************************************************/ - default: - return ret; - } - - *gIsoDep.APDUParam.rxLen = gIsoDep.APDURxPos; - - return ERR_NONE; - } - -#endif /* RFAL_FEATURE_ISO_DEP */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_nfc.c b/Software/Middlewares/ST/rfal/Src/rfal_nfc.c deleted file mode 100644 index da4008e..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_nfc.c +++ /dev/null @@ -1,1684 +0,0 @@ -/** - ****************************************************************************** - * - * COPYRIGHT(c) 2017 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/*! \file rfal_nfc.c - * - * \author Gustavo Patricio - * - * \brief RFAL NFC device - * - * This module provides the required features to behave as an NFC Poller - * or Listener device. It grants an easy to use interface for the following - * activities: Technology Detection, Collision Resollution, Activation, - * Data Exchange, and Deactivation - * - * This layer is influenced by (but not fully aligned with) the NFC Forum - * specifications, in particular: Activity 2.0 and NCI 2.0 - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_nfc.h" -#include "utils.h" -#include "rfal_analogConfig.h" - - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ -#define RFAL_NFC_MAX_DEVICES 5U /* Max number of devices supported */ - - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ -#define rfalNfcIsRemDevPoller( tp ) ( ((tp)>= RFAL_NFC_POLL_TYPE_NFCA) && ((tp)<=RFAL_NFC_POLL_TYPE_AP2P ) ) -#define rfalNfcIsRemDevListener( tp ) ( /*((tp)>= RFAL_NFC_LISTEN_TYPE_NFCA) && */ ((tp)<=RFAL_NFC_LISTEN_TYPE_AP2P) ) - -#define rfalNfcNfcNotify( st ) if( gNfcDev.disc.notifyCb != NULL ) gNfcDev.disc.notifyCb( st ) - - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -typedef struct{ - rfalNfcState state; /* Main state */ - uint16_t techsFound; /* Technologies found bitmask */ - uint16_t techs2do; /* Technologies still to be performed */ - rfalBitRate ap2pBR; /* Bit rate to poll for AP2P */ - uint8_t selDevIdx; /* Selected device index */ - rfalNfcDevice *activeDev; /* Active device pointer */ - rfalNfcDiscoverParam disc; /* Discovery parameters pointer */ - rfalNfcDevice devList[RFAL_NFC_MAX_DEVICES]; /*!< Location of device list */ - uint8_t devCnt; /* Decices found counter */ - uint32_t discTmr; /* Discovery Total duration timer */ - ReturnCode dataExErr; /* Last Data Exchange error */ - bool discRestart; /* Restart discover after deactivation flag */ - bool isRxChaining; /* Flag indicating Other device is chaining */ - uint32_t lmMask; /* Listen Mode mask */ - - rfalNfcBuffer txBuf; /* Tx buffer for Data Exchange */ - rfalNfcBuffer rxBuf; /* Rx buffer for Data Exchange */ - uint16_t rxLen; /* Length of received data on Data Exchange */ -}rfalNfc; - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ -static rfalNfc gNfcDev; - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -static ReturnCode rfalNfcPollTechDetetection( void ); -static ReturnCode rfalNfcPollCollResolution( void ); -static ReturnCode rfalNfcPollActivation( uint8_t devIt ); -static ReturnCode rfalNfcDeactivation( void ); - -#if RFAL_FEATURE_NFC_DEP -static ReturnCode rfalNfcNfcDepActivate( rfalNfcDevice *device, rfalNfcDepCommMode commMode, const uint8_t *atrReq, uint16_t atrReqLen ); -#endif /* RFAL_FEATURE_NFC_DEP */ - -#if RFAL_FEATURE_LISTEN_MODE -static ReturnCode rfalNfcListenActivation( void ); -#endif /* RFAL_FEATURE_LISTEN_MODE*/ - - -/*******************************************************************************/ -ReturnCode rfalNfcInitialize( void ) -{ - ReturnCode err; - - gNfcDev.state = RFAL_NFC_STATE_NOTINIT; - - rfalAnalogConfigInitialize(); /* Initialize RFAL's Analog Configs */ - EXIT_ON_ERR( err, rfalInitialize() ); /* Initialize RFAL */ - - gNfcDev.state = RFAL_NFC_STATE_IDLE; /* Go to initialized */ - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcDiscover( const rfalNfcDiscoverParam *disParams ) -{ - /* Check if initialization has been performed */ - if( gNfcDev.state != RFAL_NFC_STATE_IDLE ) - { - return ERR_WRONG_STATE; - } - - /* Check valid parameters */ - if( (disParams == NULL) || (disParams->devLimit > RFAL_NFC_MAX_DEVICES) || (disParams->devLimit == 0U) || - ( ((disParams->techs2Find & RFAL_NFC_POLL_TECH_F) != 0U) && (disParams->nfcfBR != RFAL_BR_212) && (disParams->nfcfBR != RFAL_BR_424) ) || - ( (((disParams->techs2Find & RFAL_NFC_POLL_TECH_AP2P) != 0U) && (disParams->ap2pBR > RFAL_BR_424)) || (disParams->GBLen > RFAL_NFCDEP_GB_MAX_LEN)) ) - { - return ERR_PARAM; - } - - if( (((disParams->techs2Find & RFAL_NFC_POLL_TECH_A) != 0U) && !((bool)RFAL_FEATURE_NFCA)) || - (((disParams->techs2Find & RFAL_NFC_POLL_TECH_B) != 0U) && !((bool)RFAL_FEATURE_NFCB)) || - (((disParams->techs2Find & RFAL_NFC_POLL_TECH_F) != 0U) && !((bool)RFAL_FEATURE_NFCF)) || - (((disParams->techs2Find & RFAL_NFC_POLL_TECH_V) != 0U) && !((bool)RFAL_FEATURE_NFCV)) || - (((disParams->techs2Find & RFAL_NFC_POLL_TECH_ST25TB) != 0U) && !((bool)RFAL_FEATURE_ST25TB)) || - (((disParams->techs2Find & RFAL_NFC_POLL_TECH_AP2P) != 0U) && !((bool)RFAL_FEATURE_NFC_DEP)) || - (((disParams->techs2Find & RFAL_NFC_LISTEN_TECH_A) != 0U) && !((bool)RFAL_FEATURE_NFCA)) || - (((disParams->techs2Find & RFAL_NFC_LISTEN_TECH_B) != 0U) && !((bool)RFAL_FEATURE_NFCB)) || - (((disParams->techs2Find & RFAL_NFC_LISTEN_TECH_F) != 0U) && !((bool)RFAL_FEATURE_NFCF)) || - (((disParams->techs2Find & RFAL_NFC_LISTEN_TECH_AP2P) != 0U) && !((bool)RFAL_FEATURE_NFC_DEP)) ) - { - return ERR_DISABLED; /* PRQA S 2880 # MISRA 2.1 - Unreachable code due to configuration option being set/unset */ - } - - /* Initialize context for discovery */ - gNfcDev.activeDev = NULL; - gNfcDev.techsFound = RFAL_NFC_TECH_NONE; - gNfcDev.devCnt = 0; - gNfcDev.discRestart = true; - gNfcDev.disc = *disParams; - - - /* Calculate Listen Mask */ - gNfcDev.lmMask = 0U; - gNfcDev.lmMask |= (((gNfcDev.disc.techs2Find & RFAL_NFC_LISTEN_TECH_A) != 0U) ? RFAL_LM_MASK_NFCA : 0U); - gNfcDev.lmMask |= (((gNfcDev.disc.techs2Find & RFAL_NFC_LISTEN_TECH_B) != 0U) ? RFAL_LM_MASK_NFCB : 0U); - gNfcDev.lmMask |= (((gNfcDev.disc.techs2Find & RFAL_NFC_LISTEN_TECH_F) != 0U) ? RFAL_LM_MASK_NFCF : 0U); - gNfcDev.lmMask |= (((gNfcDev.disc.techs2Find & RFAL_NFC_LISTEN_TECH_AP2P) != 0U) ? RFAL_LM_MASK_ACTIVE_P2P : 0U); - -#if !RFAL_FEATURE_LISTEN_MODE - /* Check if Listen Mode is supported/Enabled */ - if( gNfcDev.lmMask != 0U ) - { - return ERR_NOTSUPP; - } -#endif - - gNfcDev.state = RFAL_NFC_STATE_START_DISCOVERY; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcDeactivate( bool discovery ) -{ - /* Check for valid state */ - if( gNfcDev.state <= RFAL_NFC_STATE_IDLE ) - { - return ERR_WRONG_STATE; - } - - /* Check if discovery is to continue afterwards */ - if( discovery == true ) - { - /* If so let the state machine continue*/ - gNfcDev.discRestart = discovery; - gNfcDev.state = RFAL_NFC_STATE_DEACTIVATION; - } - else - { - /* Otherwise deactivate immediately and go to IDLE */ - rfalNfcDeactivation(); - gNfcDev.state = RFAL_NFC_STATE_IDLE; - } - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcSelect( uint8_t devIdx ) -{ - /* Check for valid state */ - if( gNfcDev.state != RFAL_NFC_STATE_POLL_SELECT ) - { - return ERR_WRONG_STATE; - } - - gNfcDev.selDevIdx = devIdx; - gNfcDev.state = RFAL_NFC_STATE_POLL_ACTIVATION; - - return ERR_NONE; -} - -/*******************************************************************************/ -rfalNfcState rfalNfcGetState( void ) -{ - return gNfcDev.state; -} - -/*******************************************************************************/ -ReturnCode rfalNfcGetDevicesFound( rfalNfcDevice **devList, uint8_t *devCnt ) -{ - /* Check for valid state */ - if( gNfcDev.state < RFAL_NFC_STATE_POLL_SELECT ) - { - return ERR_WRONG_STATE; - } - - /* Check valid parameters */ - if( (devList == NULL) || (devCnt == NULL) ) - { - return ERR_PARAM; - } - - *devCnt = gNfcDev.devCnt; - *devList = gNfcDev.devList; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcGetActiveDevice( rfalNfcDevice **dev ) -{ - /* Check for valid state */ - if( gNfcDev.state < RFAL_NFC_STATE_ACTIVATED ) - { - return ERR_WRONG_STATE; - } - - /* Check valid parameter */ - if( dev == NULL ) - { - return ERR_PARAM; - } - - /* Check for valid state */ - if( (gNfcDev.devCnt == 0U) || (gNfcDev.activeDev == NULL) ) - { - return ERR_REQUEST; - } - - *dev = gNfcDev.activeDev; - return ERR_NONE; -} - -/*******************************************************************************/ -void rfalNfcWorker( void ) -{ - ReturnCode err; - - rfalWorker(); /* Execute RFAL process */ - - switch( gNfcDev.state ) - { - /*******************************************************************************/ - case RFAL_NFC_STATE_NOTINIT: - case RFAL_NFC_STATE_IDLE: - break; - - /*******************************************************************************/ - case RFAL_NFC_STATE_START_DISCOVERY: - - /* Initialize context for discovery cycle */ - gNfcDev.devCnt = 0; - gNfcDev.selDevIdx = 0; - gNfcDev.techsFound = RFAL_NFC_TECH_NONE; - gNfcDev.techs2do = gNfcDev.disc.techs2Find; - gNfcDev.state = RFAL_NFC_STATE_POLL_TECHDETECT; - - #if RFAL_FEATURE_WAKEUP_MODE - /* Check if Low power Wake-Up is to be performed */ - if( gNfcDev.disc.wakeupEnabled ) - { - /* Initialize Low power Wake-up mode and wait */ - err = rfalWakeUpModeStart( (gNfcDev.disc.wakeupConfigDefault ? NULL : &gNfcDev.disc.wakeupConfig) ); - if( err == ERR_NONE ) - { - gNfcDev.state = RFAL_NFC_STATE_WAKEUP_MODE; - rfalNfcNfcNotify( gNfcDev.state ); /* Notify caller that WU was started */ - } - } - #endif /* RFAL_FEATURE_WAKEUP_MODE */ - break; - - /*******************************************************************************/ - case RFAL_NFC_STATE_WAKEUP_MODE: - - #if RFAL_FEATURE_WAKEUP_MODE - /* Check if the Wake-up mode has woke */ - if( rfalWakeUpModeHasWoke() ) - { - rfalWakeUpModeStop(); /* Disable Wake-up mode */ - gNfcDev.state = RFAL_NFC_STATE_POLL_TECHDETECT; /* Go to Technology detection */ - - rfalNfcNfcNotify( gNfcDev.state ); /* Notify caller that WU has woke */ - } - #endif /* RFAL_FEATURE_WAKEUP_MODE */ - - break; - - /*******************************************************************************/ - case RFAL_NFC_STATE_POLL_TECHDETECT: - - /* Start total duration timer */ - gNfcDev.discTmr = (uint32_t)platformTimerCreate( gNfcDev.disc.totalDuration ); - - err = rfalNfcPollTechDetetection(); /* Perform Technology Detection */ - if( err != ERR_BUSY ) /* Wait until all technologies are performed */ - { - if( ( err != ERR_NONE) || (gNfcDev.techsFound == RFAL_NFC_TECH_NONE) )/* Check if any error occurred or no techs were found */ - { - rfalFieldOff(); - gNfcDev.state = RFAL_NFC_STATE_LISTEN_TECHDETECT; /* Nothing found as poller, go to listener */ - break; - } - - gNfcDev.techs2do = gNfcDev.techsFound; /* Store the found technologies for collision resolution */ - gNfcDev.state = RFAL_NFC_STATE_POLL_COLAVOIDANCE; /* One or more devices found, go to Collision Avoidance */ - } - break; - - - /*******************************************************************************/ - case RFAL_NFC_STATE_POLL_COLAVOIDANCE: - - err = rfalNfcPollCollResolution(); /* Resolve any eventual collision */ - if( err != ERR_BUSY ) /* Wait until all technologies are performed */ - { - if( (err != ERR_NONE) || (gNfcDev.devCnt == 0U) ) /* Check if any error occurred or no devices were found */ - { - gNfcDev.state = RFAL_NFC_STATE_DEACTIVATION; - break; /* Unable to retrieve any device, restart loop */ - } - - /* Check if more than one device has been found */ - if( gNfcDev.devCnt > 1U ) - { - /* If more than one device was found inform upper layer to choose which one to activate */ - if( gNfcDev.disc.notifyCb != NULL ) - { - gNfcDev.state = RFAL_NFC_STATE_POLL_SELECT; - gNfcDev.disc.notifyCb( gNfcDev.state ); - break; - } - } - - /* If only one device or no callback has been set, activate the first device found */ - gNfcDev.selDevIdx = 0U; - gNfcDev.state = RFAL_NFC_STATE_POLL_ACTIVATION; - } - break; - - - /*******************************************************************************/ - case RFAL_NFC_STATE_POLL_ACTIVATION: - - if( rfalNfcPollActivation( gNfcDev.selDevIdx ) != ERR_NONE ) /* Activate selected device */ - { - gNfcDev.state = RFAL_NFC_STATE_DEACTIVATION; /* If Activation failed, restart loop */ - break; - } - - gNfcDev.state = RFAL_NFC_STATE_ACTIVATED; /* Device has been properly activated */ - rfalNfcNfcNotify( gNfcDev.state ); /* Inform upper layer that a device has been activated */ - break; - - - /*******************************************************************************/ - case RFAL_NFC_STATE_DATAEXCHANGE: - - rfalNfcDataExchangeGetStatus(); /* Run the internal state machine */ - - if( gNfcDev.dataExErr != ERR_BUSY ) /* If Dataexchange has terminated */ - { - gNfcDev.state = RFAL_NFC_STATE_DATAEXCHANGE_DONE; /* Go to done state */ - rfalNfcNfcNotify( gNfcDev.state ); /* And notify caller */ - } - if( gNfcDev.dataExErr == ERR_SLEEP_REQ ) /* Check if Listen mode has to go to Sleep */ - { - gNfcDev.state = RFAL_NFC_STATE_LISTEN_SLEEP; /* Go to Listen Sleep state */ - rfalNfcNfcNotify( gNfcDev.state ); /* And notify caller */ - } - break; - - - /*******************************************************************************/ - case RFAL_NFC_STATE_DEACTIVATION: - - rfalNfcDeactivation(); /* Deactivate current device */ - - gNfcDev.state = ((gNfcDev.discRestart) ? RFAL_NFC_STATE_START_DISCOVERY : RFAL_NFC_STATE_IDLE); - rfalNfcNfcNotify( gNfcDev.state ); /* Notify caller */ - break; - - /*******************************************************************************/ - case RFAL_NFC_STATE_LISTEN_TECHDETECT: - - if( platformTimerIsExpired( gNfcDev.discTmr ) ) - { - #if RFAL_FEATURE_LISTEN_MODE - rfalListenStop(); - #else - rfalFieldOff(); - #endif /* RFAL_FEATURE_LISTEN_MODE */ - - gNfcDev.state = RFAL_NFC_STATE_START_DISCOVERY; /* Restart the discovery loop */ - break; - } - - #if RFAL_FEATURE_LISTEN_MODE - err = rfalListenStart( gNfcDev.lmMask, &gNfcDev.disc.lmConfigPA, NULL, &gNfcDev.disc.lmConfigPF, (uint8_t*)&gNfcDev.rxBuf.rfBuf, sizeof(gNfcDev.rxBuf.rfBuf), &gNfcDev.rxLen ); - if( err == ERR_NONE ) - { - gNfcDev.state = RFAL_NFC_STATE_LISTEN_COLAVOIDANCE; /* Wait for listen mode to be activated */ - } - break; - - - /*******************************************************************************/ - case RFAL_NFC_STATE_LISTEN_COLAVOIDANCE: - - if( platformTimerIsExpired( gNfcDev.discTmr ) ) /* Check if the total duration has been reached */ - { - rfalListenStop(); - gNfcDev.state = RFAL_NFC_STATE_START_DISCOVERY; /* Restart the discovery loop */ - break; - } - - /* Check for external field */ - if( rfalListenGetState( NULL, NULL ) >= RFAL_LM_STATE_IDLE ) - { - gNfcDev.state = RFAL_NFC_STATE_LISTEN_ACTIVATION; /* Wait for listen mode to be activated */ - } - break; - - - /*******************************************************************************/ - case RFAL_NFC_STATE_LISTEN_ACTIVATION: - case RFAL_NFC_STATE_LISTEN_SLEEP: - - err = rfalNfcListenActivation(); - if( err != ERR_BUSY ) - { - if( err == ERR_NONE ) - { - gNfcDev.activeDev = gNfcDev.devList; /* Assign the active device to be used further on */ - gNfcDev.devCnt++; - - gNfcDev.state = RFAL_NFC_STATE_ACTIVATED; /* Device has been properly activated */ - rfalNfcNfcNotify( gNfcDev.state ); /* Inform upper layer that a device has been activated */ - } - else - { - rfalListenStop(); - gNfcDev.state = RFAL_NFC_STATE_START_DISCOVERY; /* Restart the discovery loop */ - } - } - #endif /* RFAL_FEATURE_LISTEN_MODE */ - break; - - /*******************************************************************************/ - case RFAL_NFC_STATE_ACTIVATED: - case RFAL_NFC_STATE_POLL_SELECT: - case RFAL_NFC_STATE_DATAEXCHANGE_DONE: - default: - return; - } -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDataExchangeStart( uint8_t *txData, uint16_t txDataLen, uint8_t **rxData, uint16_t **rvdLen, uint32_t fwt ) -{ - ReturnCode err; - rfalTransceiveContext ctx; - - /*******************************************************************************/ - /* The Data Exchange is divided in two different moments, the trigger/Start of * - * the transfer followed by the check until its completion */ - if( (gNfcDev.state >= RFAL_NFC_STATE_ACTIVATED) && (gNfcDev.activeDev != NULL) ) - { - - /*******************************************************************************/ - /* In Listen mode is the Poller that initiates the communicatation */ - /* Assign output parameters and rfalNfcDataExchangeGetStatus will return */ - /* incoming data from Poller/Initiator */ - if( (gNfcDev.state == RFAL_NFC_STATE_ACTIVATED) && rfalNfcIsRemDevPoller( gNfcDev.activeDev->type ) ) - { - if( txDataLen > 0U ) - { - return ERR_WRONG_STATE; - } - - *rvdLen = (uint16_t*)&gNfcDev.rxLen; - *rxData = (uint8_t*)( (gNfcDev.activeDev->rfInterface == RFAL_NFC_INTERFACE_ISODEP) ? gNfcDev.rxBuf.isoDepBuf.inf : - ((gNfcDev.activeDev->rfInterface == RFAL_NFC_INTERFACE_NFCDEP) ? gNfcDev.rxBuf.nfcDepBuf.inf : gNfcDev.rxBuf.rfBuf) ); - return ERR_NONE; - } - - - /*******************************************************************************/ - switch( gNfcDev.activeDev->rfInterface ) /* Check which RF interface shall be used/has been activated */ - { - /*******************************************************************************/ - case RFAL_NFC_INTERFACE_RF: - - rfalCreateByteFlagsTxRxContext( ctx, (uint8_t*)txData, txDataLen, gNfcDev.rxBuf.rfBuf, sizeof(gNfcDev.rxBuf.rfBuf), &gNfcDev.rxLen, RFAL_TXRX_FLAGS_DEFAULT, fwt ); - *rxData = (uint8_t*)gNfcDev.rxBuf.rfBuf; - *rvdLen = (uint16_t*)&gNfcDev.rxLen; - err = rfalStartTransceive( &ctx ); - break; - - #if RFAL_FEATURE_ISO_DEP - /*******************************************************************************/ - case RFAL_NFC_INTERFACE_ISODEP: - { - rfalIsoDepTxRxParam isoDepTxRx; - - if( txDataLen > 0U ) - { - ST_MEMCPY( (uint8_t*)gNfcDev.txBuf.isoDepBuf.inf, txData, txDataLen ); - } - - isoDepTxRx.DID = RFAL_ISODEP_NO_DID; - isoDepTxRx.ourFSx = RFAL_ISODEP_FSX_KEEP; - isoDepTxRx.FSx = gNfcDev.activeDev->proto.isoDep.info.FSx; - isoDepTxRx.dFWT = gNfcDev.activeDev->proto.isoDep.info.dFWT; - isoDepTxRx.FWT = gNfcDev.activeDev->proto.isoDep.info.FWT; - isoDepTxRx.txBuf = &gNfcDev.txBuf.isoDepBuf; - isoDepTxRx.txBufLen = txDataLen; - isoDepTxRx.isTxChaining = false; - isoDepTxRx.rxBuf = &gNfcDev.rxBuf.isoDepBuf; - isoDepTxRx.rxLen = &gNfcDev.rxLen; - isoDepTxRx.isRxChaining = &gNfcDev.isRxChaining; - *rxData = (uint8_t*)gNfcDev.rxBuf.isoDepBuf.inf; - *rvdLen = (uint16_t*)&gNfcDev.rxLen; - - /*******************************************************************************/ - /* Trigger a RFAL ISO-DEP Transceive */ - err = rfalIsoDepStartTransceive( isoDepTxRx ); - break; - } - #endif /* RFAL_FEATURE_ISO_DEP */ - - #if RFAL_FEATURE_NFC_DEP - /*******************************************************************************/ - case RFAL_NFC_INTERFACE_NFCDEP: - { - rfalNfcDepTxRxParam nfcDepTxRx; - - if( txDataLen > 0U) - { - ST_MEMCPY( (uint8_t*)gNfcDev.txBuf.nfcDepBuf.inf, txData, txDataLen ); - } - - nfcDepTxRx.DID = RFAL_NFCDEP_DID_KEEP; - nfcDepTxRx.FSx = rfalNfcDepLR2FS( (uint8_t)rfalNfcDepPP2LR( gNfcDev.activeDev->proto.nfcDep.activation.Target.ATR_RES.PPt ) ); - nfcDepTxRx.dFWT = gNfcDev.activeDev->proto.nfcDep.info.dFWT; - nfcDepTxRx.FWT = gNfcDev.activeDev->proto.nfcDep.info.FWT; - nfcDepTxRx.txBuf = &gNfcDev.txBuf.nfcDepBuf; - nfcDepTxRx.txBufLen = txDataLen; - nfcDepTxRx.isTxChaining = false; - nfcDepTxRx.rxBuf = &gNfcDev.rxBuf.nfcDepBuf; - nfcDepTxRx.rxLen = &gNfcDev.rxLen; - nfcDepTxRx.isRxChaining = &gNfcDev.isRxChaining; - *rxData = (uint8_t*)gNfcDev.rxBuf.nfcDepBuf.inf; - *rvdLen = (uint16_t*)&gNfcDev.rxLen; - - /*******************************************************************************/ - /* Trigger a RFAL NFC-DEP Transceive */ - err = rfalNfcDepStartTransceive( &nfcDepTxRx ); - break; - } - #endif /* RFAL_FEATURE_NFC_DEP */ - - /*******************************************************************************/ - default: - err = ERR_PARAM; - break; - } - - /* If a transceive has succesfully started flag Data Exchange as ongoing */ - if( err == ERR_NONE ) - { - gNfcDev.dataExErr = ERR_BUSY; - gNfcDev.state = RFAL_NFC_STATE_DATAEXCHANGE; - } - - return err; - } - - return ERR_WRONG_STATE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDataExchangeGetStatus( void ) -{ - /*******************************************************************************/ - /* Check if it's the first frame received in Listen mode */ - if( gNfcDev.state == RFAL_NFC_STATE_ACTIVATED ) - { - /* Continue data exchange as normal */ - gNfcDev.dataExErr = ERR_BUSY; - gNfcDev.state = RFAL_NFC_STATE_DATAEXCHANGE; - - /* Check if we performing in T3T CE */ - if( (gNfcDev.activeDev->type == RFAL_NFC_POLL_TYPE_NFCF) && (gNfcDev.activeDev->rfInterface == RFAL_NFC_INTERFACE_RF) ) - { - /* The first frame has been retrieved by rfalListenMode, flag data immediately */ - /* Can only call rfalGetTransceiveStatus() after starting a transceive with rfalStartTransceive */ - gNfcDev.dataExErr = ERR_NONE; - } - } - - - /*******************************************************************************/ - /* Check if we are in we have been placed to sleep, and return last error */ - if( gNfcDev.state == RFAL_NFC_STATE_LISTEN_SLEEP ) - { - return gNfcDev.dataExErr; /* ERR_SLEEP_REQ */ - } - - - /*******************************************************************************/ - /* Check if Data exchange has been started */ - if( (gNfcDev.state != RFAL_NFC_STATE_DATAEXCHANGE) && (gNfcDev.state != RFAL_NFC_STATE_DATAEXCHANGE_DONE) ) - { - return ERR_WRONG_STATE; - } - - /* Check if Data exchange is still ongoing */ - if( gNfcDev.dataExErr == ERR_BUSY ) - { - switch( gNfcDev.activeDev->rfInterface ) - { - /*******************************************************************************/ - case RFAL_NFC_INTERFACE_RF: - gNfcDev.dataExErr = rfalGetTransceiveStatus(); - break; - - #if RFAL_FEATURE_ISO_DEP - /*******************************************************************************/ - case RFAL_NFC_INTERFACE_ISODEP: - gNfcDev.dataExErr = rfalIsoDepGetTransceiveStatus(); - break; - #endif /* RFAL_FEATURE_ISO_DEP */ - - /*******************************************************************************/ - #if RFAL_FEATURE_NFC_DEP - case RFAL_NFC_INTERFACE_NFCDEP: - gNfcDev.dataExErr = rfalNfcDepGetTransceiveStatus(); - break; - #endif /* RFAL_FEATURE_NFC_DEP */ - - /*******************************************************************************/ - default: - gNfcDev.dataExErr = ERR_PARAM; - break; - } - - - #if RFAL_FEATURE_LISTEN_MODE - /*******************************************************************************/ - /* If a Sleep request has been received (Listen Mode) go to sleep immediately */ - if( gNfcDev.dataExErr == ERR_SLEEP_REQ ) - { - EXIT_ON_ERR( gNfcDev.dataExErr, rfalListenSleepStart( RFAL_LM_STATE_SLEEP_A, gNfcDev.rxBuf.rfBuf, sizeof(gNfcDev.rxBuf.rfBuf), &gNfcDev.rxLen ) ); - - /* If set Sleep was succesfull keep restore the Sleep request signal */ - gNfcDev.dataExErr = ERR_SLEEP_REQ; - } - #endif /* RFAL_FEATURE_LISTEN_MODE */ - - } - - return gNfcDev.dataExErr; -} - -/*! - ****************************************************************************** - * \brief Poller Technology Detection - * - * This method implements the Technology Detection / Poll for different - * device technologies. - * - * \return ERR_NONE : Operation completed with no error - * \return ERR_BUSY : Operation ongoing - * \return ERR_XXXX : Error occurred - * - ****************************************************************************** - */ -static ReturnCode rfalNfcPollTechDetetection( void ) -{ - ReturnCode err; - - err = ERR_NONE; - - /* Supress warning when specific RFAL features have been disabled */ - NO_WARNING(err); - - - /*******************************************************************************/ - /* AP2P Technology Detection */ - /*******************************************************************************/ - if( ((gNfcDev.disc.techs2Find & RFAL_NFC_POLL_TECH_AP2P) != 0U) && ((gNfcDev.techs2do & RFAL_NFC_POLL_TECH_AP2P) != 0U) ) - { - gNfcDev.techs2do &= ~RFAL_NFC_POLL_TECH_AP2P; - - #if RFAL_FEATURE_NFC_DEP - - EXIT_ON_ERR( err, rfalSetMode( RFAL_MODE_POLL_ACTIVE_P2P, gNfcDev.disc.ap2pBR, gNfcDev.disc.ap2pBR ) ); - rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); - rfalSetFDTListen( RFAL_FDT_LISTEN_AP2P_POLLER ); - rfalSetFDTPoll( RFAL_TIMING_NONE ); - rfalSetGT( RFAL_GT_AP2P_ADJUSTED ); - EXIT_ON_ERR( err, rfalFieldOnAndStartGT() ); /* Turns the Field On and starts GT timer */ - - err = rfalNfcNfcDepActivate( gNfcDev.devList, RFAL_NFCDEP_COMM_ACTIVE, NULL, 0 );/* Poll for NFC-A devices */ - if( err == ERR_NONE ) - { - gNfcDev.techsFound |= RFAL_NFC_POLL_TECH_AP2P; - - gNfcDev.devList->type = RFAL_NFC_LISTEN_TYPE_AP2P; - gNfcDev.devList->rfInterface = RFAL_NFC_INTERFACE_NFCDEP; - gNfcDev.devCnt++; - - return ERR_NONE; - } - - rfalFieldOff(); - return ERR_BUSY; - - #endif /* RFAL_FEATURE_NFC_DEP */ - } - - - /*******************************************************************************/ - /* Passive NFC-A Technology Detection */ - /*******************************************************************************/ - if( ((gNfcDev.disc.techs2Find & RFAL_NFC_POLL_TECH_A) != 0U) && ((gNfcDev.techs2do & RFAL_NFC_POLL_TECH_A) != 0U) ) - { - gNfcDev.techs2do &= ~RFAL_NFC_POLL_TECH_A; - - #if RFAL_FEATURE_NFCA - { - rfalNfcaSensRes sensRes; - - EXIT_ON_ERR( err, rfalNfcaPollerInitialize() ); /* Initialize RFAL for NFC-A */ - EXIT_ON_ERR( err, rfalFieldOnAndStartGT() ); /* Turns the Field On and starts GT timer */ - - err = rfalNfcaPollerTechnologyDetection( gNfcDev.disc.compMode, &sensRes );/* Poll for NFC-A devices */ - if( err == ERR_NONE ) - { - gNfcDev.techsFound |= RFAL_NFC_POLL_TECH_A; - } - - return ERR_BUSY; - } - - #endif /* RFAL_FEATURE_NFCA */ - } - - - /*******************************************************************************/ - /* Passive NFC-B Technology Detection */ - /*******************************************************************************/ - if( ((gNfcDev.disc.techs2Find & RFAL_NFC_POLL_TECH_B) != 0U) && ((gNfcDev.techs2do & RFAL_NFC_POLL_TECH_B) != 0U) ) - { - gNfcDev.techs2do &= ~RFAL_NFC_POLL_TECH_B; - - #if RFAL_FEATURE_NFCB - { - rfalNfcbSensbRes sensbRes; - uint8_t sensbResLen; - - EXIT_ON_ERR( err, rfalNfcbPollerInitialize() ); /* Initialize RFAL for NFC-B */ - EXIT_ON_ERR( err, rfalFieldOnAndStartGT() ); /* As field is already On only starts GT timer */ - - err = rfalNfcbPollerTechnologyDetection( gNfcDev.disc.compMode, &sensbRes, &sensbResLen ); /* Poll for NFC-B devices */ - if( err == ERR_NONE ) - { - gNfcDev.techsFound |= RFAL_NFC_POLL_TECH_B; - } - - return ERR_BUSY; - } - - #endif /* RFAL_FEATURE_NFCB */ - } - - /*******************************************************************************/ - /* Passive NFC-F Technology Detection */ - /*******************************************************************************/ - if( ((gNfcDev.disc.techs2Find & RFAL_NFC_POLL_TECH_F) != 0U) && ((gNfcDev.techs2do & RFAL_NFC_POLL_TECH_F) != 0U) ) - { - gNfcDev.techs2do &= ~RFAL_NFC_POLL_TECH_F; - - #if RFAL_FEATURE_NFCF - - EXIT_ON_ERR( err, rfalNfcfPollerInitialize( gNfcDev.disc.nfcfBR ) ); /* Initialize RFAL for NFC-F */ - EXIT_ON_ERR( err, rfalFieldOnAndStartGT() ); /* As field is already On only starts GT timer */ - - err = rfalNfcfPollerCheckPresence(); /* Poll for NFC-F devices */ - if( err == ERR_NONE ) - { - gNfcDev.techsFound |= RFAL_NFC_POLL_TECH_F; - } - - return ERR_BUSY; - - #endif /* RFAL_FEATURE_NFCF */ - } - - - /*******************************************************************************/ - /* Passive NFC-V Technology Detection */ - /*******************************************************************************/ - if( ((gNfcDev.disc.techs2Find & RFAL_NFC_POLL_TECH_V) != 0U) && ((gNfcDev.techs2do & RFAL_NFC_POLL_TECH_V) != 0U) ) - { - gNfcDev.techs2do &= ~RFAL_NFC_POLL_TECH_V; - - #if RFAL_FEATURE_NFCV - { - rfalNfcvInventoryRes invRes; - - EXIT_ON_ERR( err, rfalNfcvPollerInitialize() ); /* Initialize RFAL for NFC-V */ - EXIT_ON_ERR( err, rfalFieldOnAndStartGT() ); /* As field is already On only starts GT timer */ - - err = rfalNfcvPollerCheckPresence( &invRes ); /* Poll for NFC-V devices */ - if( err == ERR_NONE ) - { - gNfcDev.techsFound |= RFAL_NFC_POLL_TECH_V; - } - - return ERR_BUSY; - } - - #endif /* RFAL_FEATURE_NFCV */ - } - - - /*******************************************************************************/ - /* Passive Proprietary Technology ST25TB */ - /*******************************************************************************/ - if( ((gNfcDev.disc.techs2Find & RFAL_NFC_POLL_TECH_ST25TB) != 0U) && ((gNfcDev.techs2do & RFAL_NFC_POLL_TECH_ST25TB) != 0U) ) - { - gNfcDev.techs2do &= ~RFAL_NFC_POLL_TECH_ST25TB; - - #if RFAL_FEATURE_ST25TB - - EXIT_ON_ERR( err, rfalSt25tbPollerInitialize() ); /* Initialize RFAL for NFC-V */ - EXIT_ON_ERR( err, rfalFieldOnAndStartGT() ); /* As field is already On only starts GT timer */ - - err = rfalSt25tbPollerCheckPresence( NULL ); /* Poll for ST25TB devices */ - if( err == ERR_NONE ) - { - gNfcDev.techsFound |= RFAL_NFC_POLL_TECH_ST25TB; - } - - #endif /* RFAL_FEATURE_ST25TB */ - } - - return ERR_NONE; -} - -/*! - ****************************************************************************** - * \brief Poller Collision Resolution - * - * This method implements the Collision Resolution on all technologies that - * have been detected before. - * - * \return ERR_NONE : Operation completed with no error - * \return ERR_BUSY : Operation ongoing - * \return ERR_XXXX : Error occurred - * - ****************************************************************************** - */ -static ReturnCode rfalNfcPollCollResolution( void ) -{ - uint8_t i; - uint8_t devCnt; - ReturnCode err; - - err = ERR_NONE; - devCnt = 0; - i = 0; - - /* Supress warning when specific RFAL features have been disabled */ - NO_WARNING(err); - NO_WARNING(devCnt); - NO_WARNING(i); - - /* Check if device limit has been reached */ - if( gNfcDev.devCnt >= gNfcDev.disc.devLimit ) - { - return ERR_NONE; - } - - /*******************************************************************************/ - /* NFC-A Collision Resolution */ - /*******************************************************************************/ -#if RFAL_FEATURE_NFCA - if( ((gNfcDev.techsFound & RFAL_NFC_POLL_TECH_A) != 0U) && ((gNfcDev.techs2do & RFAL_NFC_POLL_TECH_A) != 0U) ) /* If a NFC-A device was found/detected, perform Collision Resolution */ - { - rfalNfcaListenDevice nfcaDevList[RFAL_NFC_MAX_DEVICES]; - - gNfcDev.techs2do &= ~RFAL_NFC_POLL_TECH_A; - - EXIT_ON_ERR( err, rfalNfcaPollerInitialize()); /* Initialize RFAL for NFC-A */ - EXIT_ON_ERR( err, rfalFieldOnAndStartGT() ); /* Ensure GT again as other technologies have also been polled */ - - err = rfalNfcaPollerFullCollisionResolution( gNfcDev.disc.compMode, (gNfcDev.disc.devLimit - gNfcDev.devCnt), nfcaDevList, &devCnt ); - if( (err == ERR_NONE) && (devCnt != 0U) ) - { - for( i=0; i gNfcDev.devCnt ) - { - return ERR_WRONG_STATE; - } - - switch( gNfcDev.devList[devIt].type ) - { - /*******************************************************************************/ - /* AP2P Activation */ - /*******************************************************************************/ - #if RFAL_FEATURE_NFC_DEP - case RFAL_NFC_LISTEN_TYPE_AP2P: - /* Activation has already been perfomed (ATR_REQ) */ - - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].proto.nfcDep.activation.Target.ATR_RES.NFCID3; - gNfcDev.devList[devIt].nfcidLen = RFAL_NFCDEP_NFCID3_LEN; - break; - #endif /* RFAL_FEATURE_NFC_DEP */ - - - /*******************************************************************************/ - /* Passive NFC-A Activation */ - /*******************************************************************************/ - #if RFAL_FEATURE_NFCA - case RFAL_NFC_LISTEN_TYPE_NFCA: - - rfalNfcaPollerInitialize(); - if( gNfcDev.devList[devIt].dev.nfca.isSleep ) /* Check if desired device is in Sleep */ - { - rfalNfcaSensRes sensRes; - rfalNfcaSelRes selRes; - - EXIT_ON_ERR( err, rfalNfcaPollerCheckPresence( RFAL_14443A_SHORTFRAME_CMD_WUPA, &sensRes ) ); /* Wake up all cards */ - EXIT_ON_ERR( err, rfalNfcaPollerSelect( gNfcDev.devList[devIt].dev.nfca.nfcId1, gNfcDev.devList[devIt].dev.nfca.nfcId1Len, &selRes ) ); /* Select specific device */ - } - - /* Set NFCID */ - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].dev.nfca.nfcId1; - gNfcDev.devList[devIt].nfcidLen = gNfcDev.devList[devIt].dev.nfca.nfcId1Len; - - /*******************************************************************************/ - /* Perform protocol specific activation */ - switch( gNfcDev.devList[devIt].dev.nfca.type ) - { - /*******************************************************************************/ - case RFAL_NFCA_T1T: - - /* No further activation needed for T1T (RID already performed) */ - - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].dev.nfca.ridRes.uid; - gNfcDev.devList[devIt].nfcidLen = RFAL_T1T_UID_LEN; - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_RF; - break; - - case RFAL_NFCA_T2T: - - /* No further activation needed for a T2T */ - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_RF; - break; - - - /*******************************************************************************/ - case RFAL_NFCA_T4T: /* Device supports ISO-DEP */ - - #if RFAL_FEATURE_ISO_DEP_POLL - /* Perform ISO-DEP (ISO14443-4) activation: RATS and PPS if supported */ - rfalIsoDepInitialize(); - EXIT_ON_ERR( err, rfalIsoDepPollAHandleActivation( (rfalIsoDepFSxI)RFAL_ISODEP_FSDI_DEFAULT, RFAL_ISODEP_NO_DID, RFAL_BR_424, &gNfcDev.devList[devIt].proto.isoDep ) ); - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_ISODEP; /* NFC-A T4T device activated */ - #else - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_RF; /* No ISO-DEP supported activate using RF interface */ - #endif /* RFAL_FEATURE_ISO_DEP_POLL */ - break; - - - - /*******************************************************************************/ - case RFAL_NFCA_T4T_NFCDEP: /* Device supports both T4T and NFC-DEP */ - case RFAL_NFCA_NFCDEP: /* Device supports NFC-DEP */ - - #if RFAL_FEATURE_NFC_DEP - /* Perform NFC-DEP (P2P) activation: ATR and PSL if supported */ - EXIT_ON_ERR( err, rfalNfcNfcDepActivate( &gNfcDev.devList[devIt], RFAL_NFCDEP_COMM_PASSIVE, NULL, 0 ) ); - - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].proto.nfcDep.activation.Target.ATR_RES.NFCID3; - gNfcDev.devList[devIt].nfcidLen = RFAL_NFCDEP_NFCID3_LEN; - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_NFCDEP; /* NFC-A P2P device activated */ - #else - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_RF; /* No NFC-DEP supported activate using RF interface */ - #endif /* RFAL_FEATURE_NFC_DEP */ - break; - - /*******************************************************************************/ - default: - return ERR_WRONG_STATE; - } - break; - #endif /* RFAL_FEATURE_NFCA */ - - - /*******************************************************************************/ - /* Passive NFC-B Activation */ - /*******************************************************************************/ - #if RFAL_FEATURE_NFCB - case RFAL_NFC_LISTEN_TYPE_NFCB: - - rfalNfcbPollerInitialize(); - if( gNfcDev.devList[devIt].dev.nfcb.isSleep ) /* Check if desired device is in Sleep */ - { - rfalNfcbSensbRes sensbRes; - uint8_t sensbResLen; - - /* Wake up all cards. SENSB_RES may return collision but the NFCID0 is available to explicitly select NFC-B card via ATTRIB; so error will be ignored here */ - rfalNfcbPollerCheckPresence( RFAL_NFCB_SENS_CMD_ALLB_REQ, RFAL_NFCB_SLOT_NUM_1, &sensbRes, &sensbResLen ); - } - - /* Set NFCID */ - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].dev.nfcb.sensbRes.nfcid0; - gNfcDev.devList[devIt].nfcidLen = RFAL_NFCB_NFCID0_LEN; - - #if RFAL_FEATURE_ISO_DEP_POLL - /* Check if device supports ISO-DEP (ISO14443-4) */ - if( (gNfcDev.devList[devIt].dev.nfcb.sensbRes.protInfo.FsciProType & RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK) != 0U ) - { - rfalIsoDepInitialize(); - /* Perform ISO-DEP (ISO14443-4) activation: RATS and PPS if supported */ - EXIT_ON_ERR( err, rfalIsoDepPollBHandleActivation( (rfalIsoDepFSxI)RFAL_ISODEP_FSDI_DEFAULT, RFAL_ISODEP_NO_DID, RFAL_BR_424, 0x00, &gNfcDev.devList[devIt].dev.nfcb, NULL, 0, &gNfcDev.devList[devIt].proto.isoDep ) ); - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_ISODEP; /* NFC-B T4T device activated */ - break; - } - #endif /* RFAL_FEATURE_ISO_DEP_POLL */ - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_RF; /* NFC-B device activated */ - break; - - #endif /* RFAL_FEATURE_NFCB */ - - - /*******************************************************************************/ - /* Passive NFC-F Activation */ - /*******************************************************************************/ - #if RFAL_FEATURE_NFCF - case RFAL_NFC_LISTEN_TYPE_NFCF: - - rfalNfcfPollerInitialize( gNfcDev.disc.nfcfBR ); - - #if RFAL_FEATURE_NFC_DEP - if( rfalNfcfIsNfcDepSupported( &gNfcDev.devList[devIt].dev.nfcf ) ) - { - /* Perform NFC-DEP (P2P) activation: ATR and PSL if supported */ - EXIT_ON_ERR( err, rfalNfcNfcDepActivate( &gNfcDev.devList[devIt], RFAL_NFCDEP_COMM_PASSIVE, NULL, 0 ) ); - - /* Set NFCID */ - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].proto.nfcDep.activation.Target.ATR_RES.NFCID3; - gNfcDev.devList[devIt].nfcidLen = RFAL_NFCDEP_NFCID3_LEN; - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_NFCDEP; /* NFC-F P2P device activated */ - break; - } - #endif /* RFAL_FEATURE_NFC_DEP */ - - /* Set NFCID */ - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].dev.nfcf.sensfRes.NFCID2; - gNfcDev.devList[devIt].nfcidLen = RFAL_NFCF_NFCID2_LEN; - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_RF; /* NFC-F T3T device activated */ - break; - #endif /* RFAL_FEATURE_NFCF */ - - - /*******************************************************************************/ - /* Passive NFC-V Activation */ - /*******************************************************************************/ - #if RFAL_FEATURE_NFCV - case RFAL_NFC_LISTEN_TYPE_NFCV: - - rfalNfcvPollerInitialize(); - - /* No specific activation needed for a T5T */ - - /* Set NFCID */ - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].dev.nfcv.InvRes.UID; - gNfcDev.devList[devIt].nfcidLen = RFAL_NFCV_UID_LEN; - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_RF; /* NFC-V T5T device activated */ - break; - #endif /* RFAL_FEATURE_NFCV */ - - - /*******************************************************************************/ - /* Passive ST25TB Activation */ - /*******************************************************************************/ - #if RFAL_FEATURE_ST25TB - case RFAL_NFC_LISTEN_TYPE_ST25TB: - - rfalSt25tbPollerInitialize(); - - /* No specific activation needed for a ST25TB */ - - /* Set NFCID */ - gNfcDev.devList[devIt].nfcid = gNfcDev.devList[devIt].dev.st25tb.UID; - gNfcDev.devList[devIt].nfcidLen = RFAL_ST25TB_UID_LEN; - - gNfcDev.devList[devIt].rfInterface = RFAL_NFC_INTERFACE_RF; /* ST25TB device activated */ - break; - #endif /* RFAL_FEATURE_ST25TB */ - - /*******************************************************************************/ - default: - return ERR_WRONG_STATE; - } - - gNfcDev.activeDev = &gNfcDev.devList[devIt]; /* Assign active device to be used further on */ - return ERR_NONE; -} - - -/*! - ****************************************************************************** - * \brief Listener Activation - * - * This method handles the listen mode Activation according to the different - * protocols the Reader/Initiator performs - * - * \return ERR_NONE : Operation completed with no error - * \return ERR_BUSY : Operation ongoing - * \return ERR_PROTO : Unexpected frame received - * \return ERR_XXXX : Error occurred - * - ****************************************************************************** - */ -#if RFAL_FEATURE_LISTEN_MODE -static ReturnCode rfalNfcListenActivation( void ) -{ - bool isDataRcvd; - uint8_t hdrLen; - ReturnCode ret; - rfalLmState lmSt; - rfalBitRate bitRate; - - lmSt = rfalListenGetState( &isDataRcvd, &bitRate ); - switch(lmSt) - { - /*******************************************************************************/ - case RFAL_LM_STATE_ACTIVE_A: /* NFC-A CE activation */ - case RFAL_LM_STATE_ACTIVE_Ax: - - if( isDataRcvd ) /* Check if Reader/Initator has sent some data */ - { - /* Set the header length in NFC-A */ - hdrLen = (RFAL_NFCDEP_SB_LEN + RFAL_NFCDEP_LEN_LEN); - - NO_WARNING(hdrLen); /* Supress warning if feature switch is disabled */ - - /* Check if received data is a Sleep request */ - if( rfalNfcaListenerIsSleepReq( gNfcDev.rxBuf.rfBuf, rfalConvBitsToBytes(gNfcDev.rxLen)) ) /* Check if received data is a SLP_REQ */ - { - /* Set the Listen Mode in Sleep state */ - EXIT_ON_ERR( ret, rfalListenSleepStart( RFAL_LM_STATE_SLEEP_A, gNfcDev.rxBuf.rfBuf, sizeof(gNfcDev.rxBuf.rfBuf), &gNfcDev.rxLen ) ); - } - - #if RFAL_FEATURE_ISO_DEP_LISTEN - /* Check if received data is a valid RATS */ - else if( rfalIsoDepIsRats( gNfcDev.rxBuf.rfBuf, (uint8_t)rfalConvBitsToBytes(gNfcDev.rxLen) ) ) - { - rfalIsoDepAtsParam atsParam; - rfalIsoDepListenActvParam rxParam; - - /* Set ATS parameters */ - atsParam.fsci = (uint8_t)RFAL_ISODEP_DEFAULT_FSCI; - atsParam.fwi = RFAL_ISODEP_DEFAULT_FWI; - atsParam.sfgi = RFAL_ISODEP_DEFAULT_SFGI; - atsParam.didSupport = false; - atsParam.ta = RFAL_ISODEP_ATS_TA_SAME_D; - atsParam.hb = NULL; - atsParam.hbLen = 0; - - /* Set Rx parameters */ - rxParam.rxBuf = (rfalIsoDepBufFormat*) &gNfcDev.rxBuf.isoDepBuf; - rxParam.rxLen = &gNfcDev.rxLen; - rxParam.isoDepDev = &gNfcDev.devList->proto.isoDep; - rxParam.isRxChaining = &gNfcDev.isRxChaining; - - rfalListenSetState( RFAL_LM_STATE_CARDEMU_4A ); /* Set next state CE T4T */ - rfalIsoDepInitialize(); /* Initialize ISO-DEP layer to handle ISO14443-a activation / RATS */ - - /* Set ISO-DEP layer to digest RATS and handle activation */ - EXIT_ON_ERR( ret, rfalIsoDepListenStartActivation( &atsParam, NULL, gNfcDev.rxBuf.rfBuf, gNfcDev.rxLen, rxParam ) ); - } - #endif /* RFAL_FEATURE_ISO_DEP_LISTEN */ - - #if RFAL_FEATURE_NFC_DEP - /* Check if received data is a valid ATR_REQ */ - else if( rfalNfcDepIsAtrReq( &gNfcDev.rxBuf.rfBuf[hdrLen], (rfalConvBitsToBytes(gNfcDev.rxLen) - hdrLen), gNfcDev.devList->nfcid ) ) - { - gNfcDev.devList->type = RFAL_NFC_POLL_TYPE_NFCA; - EXIT_ON_ERR( ret, rfalNfcNfcDepActivate( gNfcDev.devList, RFAL_NFCDEP_COMM_PASSIVE, &gNfcDev.rxBuf.rfBuf[hdrLen], (rfalConvBitsToBytes(gNfcDev.rxLen) - hdrLen) ) ); - } - #endif /* RFAL_FEATURE_NFC_DEP */ - - else - { - return ERR_PROTO; - } - } - return ERR_BUSY; - - #if RFAL_FEATURE_ISO_DEP_LISTEN - /*******************************************************************************/ - case RFAL_LM_STATE_CARDEMU_4A: /* T4T ISO-DEP activation */ - - ret = rfalIsoDepListenGetActivationStatus(); - if( ret == ERR_NONE ) - { - gNfcDev.devList->type = RFAL_NFC_POLL_TYPE_NFCA; - gNfcDev.devList->rfInterface = RFAL_NFC_INTERFACE_ISODEP; - gNfcDev.devList->nfcid = NULL; - gNfcDev.devList->nfcidLen = 0; - } - return ret; - #endif /* RFAL_FEATURE_ISO_DEP_LISTEN */ - - /*******************************************************************************/ - case RFAL_LM_STATE_READY_F: /* NFC-F CE activation */ - - if( isDataRcvd ) /* Wait for the first received data */ - { - #if RFAL_FEATURE_NFC_DEP - /* Set the header length in NFC-F */ - hdrLen = RFAL_NFCDEP_LEN_LEN; - - if( rfalNfcDepIsAtrReq( &gNfcDev.rxBuf.rfBuf[hdrLen], (rfalConvBitsToBytes(gNfcDev.rxLen) - hdrLen), gNfcDev.devList->nfcid ) ) - { - gNfcDev.devList->type = RFAL_NFC_POLL_TYPE_NFCF; - EXIT_ON_ERR( ret, rfalNfcNfcDepActivate( gNfcDev.devList, RFAL_NFCDEP_COMM_PASSIVE, &gNfcDev.rxBuf.rfBuf[hdrLen], (rfalConvBitsToBytes(gNfcDev.rxLen) - hdrLen) ) ); - } - else - #endif /* RFAL_FEATURE_NFC_DEP */ - { - rfalListenSetState( RFAL_LM_STATE_CARDEMU_3 ); /* First data already received - set T3T CE */ - } - } - return ERR_BUSY; - - /*******************************************************************************/ - case RFAL_LM_STATE_CARDEMU_3: /* T3T activated */ - - gNfcDev.devList->type = RFAL_NFC_POLL_TYPE_NFCF; - gNfcDev.devList->rfInterface = RFAL_NFC_INTERFACE_RF; - gNfcDev.devList->nfcid = NULL; - gNfcDev.devList->nfcidLen = 0; - - return ERR_NONE; - - #if RFAL_FEATURE_NFC_DEP - /*******************************************************************************/ - case RFAL_LM_STATE_TARGET_A: /* NFC-DEP activation */ - case RFAL_LM_STATE_TARGET_F: - - ret = rfalNfcDepListenGetActivationStatus(); - if( ret == ERR_NONE ) - { - gNfcDev.devList->rfInterface = RFAL_NFC_INTERFACE_NFCDEP; - gNfcDev.devList->nfcidLen = RFAL_NFCDEP_NFCID3_LEN; - } - return ret; - #endif /* RFAL_FEATURE_NFC_DEP */ - - /*******************************************************************************/ - case RFAL_LM_STATE_IDLE: /* AP2P activation */ - if( isDataRcvd ) /* Check if Reader/Initator has sent some data */ - { - - if( (gNfcDev.lmMask & RFAL_LM_MASK_ACTIVE_P2P) != 0U ) /* Check if AP2P is enabled */ - { - - #if RFAL_FEATURE_NFC_DEP - /* Calculate the header length in NFC-A or NFC-F mode*/ - hdrLen = ( (bitRate == RFAL_BR_106) ? (RFAL_NFCDEP_SB_LEN + RFAL_NFCDEP_LEN_LEN) : RFAL_NFCDEP_LEN_LEN ); - - if( rfalNfcDepIsAtrReq( &gNfcDev.rxBuf.rfBuf[hdrLen], (rfalConvBitsToBytes(gNfcDev.rxLen) - hdrLen), NULL) ) - { - gNfcDev.devList->type = RFAL_NFC_POLL_TYPE_AP2P; - EXIT_ON_ERR( ret, rfalNfcNfcDepActivate( gNfcDev.devList, RFAL_NFCDEP_COMM_ACTIVE, &gNfcDev.rxBuf.rfBuf[hdrLen], (rfalConvBitsToBytes(gNfcDev.rxLen) - hdrLen) ) ); - } - else - #endif /* RFAL_FEATURE_NFC_DEP */ - { - return ERR_PROTO; - } - } - } - return ERR_BUSY; - - /*******************************************************************************/ - case RFAL_LM_STATE_READY_A: - case RFAL_LM_STATE_READY_Ax: - case RFAL_LM_STATE_SLEEP_A: - case RFAL_LM_STATE_SLEEP_AF: - return ERR_BUSY; - - /*******************************************************************************/ - case RFAL_LM_STATE_POWER_OFF: - return ERR_LINK_LOSS; - - default: /* Wait for activation */ - break; - } - - return ERR_INTERNAL; -} -#endif /* RFAL_FEATURE_LISTEN_MODE */ - - -/*! - ****************************************************************************** - * \brief Poller NFC DEP Activate - * - * This method performs NFC-DEP Activation - * - * \param[in] device : device info - * \param[in] commMode : communication mode (Passive/Active) - * \param[in] atrReq : received ATR_REQ - * \param[in] atrReqLen : received ATR_REQ size - * - * \return ERR_NONE : Operation completed with no error - * \return ERR_BUSY : Operation ongoing - * \return ERR_XXXX : Error occurred - * - ****************************************************************************** - */ -#if RFAL_FEATURE_NFC_DEP -static ReturnCode rfalNfcNfcDepActivate( rfalNfcDevice *device, rfalNfcDepCommMode commMode, const uint8_t *atrReq, uint16_t atrReqLen ) -{ - rfalNfcDepAtrParam initParam; - - /* If we are in Poll mode */ - if( rfalNfcIsRemDevListener( device->type ) ) - { - /*******************************************************************************/ - /* If Passive F use the NFCID2 retrieved from SENSF */ - if( device->type == RFAL_NFC_LISTEN_TYPE_NFCF ) - { - initParam.nfcid = device->dev.nfcf.sensfRes.NFCID2; - initParam.nfcidLen = RFAL_NFCF_NFCID2_LEN; - } - else - { - initParam.nfcid = gNfcDev.disc.nfcid3; - initParam.nfcidLen = RFAL_NFCDEP_NFCID3_LEN; - } - - initParam.BS = RFAL_NFCDEP_Bx_NO_HIGH_BR; - initParam.BR = RFAL_NFCDEP_Bx_NO_HIGH_BR; - initParam.DID = RFAL_NFCDEP_DID_NO; - initParam.NAD = RFAL_NFCDEP_NAD_NO; - initParam.LR = RFAL_NFCDEP_LR_254; - initParam.GB = gNfcDev.disc.GB; - initParam.GBLen = gNfcDev.disc.GBLen; - initParam.commMode = commMode; - initParam.operParam = (RFAL_NFCDEP_OPER_FULL_MI_EN | RFAL_NFCDEP_OPER_EMPTY_DEP_DIS | RFAL_NFCDEP_OPER_ATN_EN | RFAL_NFCDEP_OPER_RTOX_REQ_EN); - - rfalNfcDepInitialize(); - /* Perform NFC-DEP (P2P) activation: ATR and PSL if supported */ - return rfalNfcDepInitiatorHandleActivation( &initParam, RFAL_BR_424, &device->proto.nfcDep ); - } - - /* If we are in Listen mode */ -#if RFAL_FEATURE_LISTEN_MODE - else if( rfalNfcIsRemDevPoller( device->type ) ) - { - rfalNfcDepListenActvParam actvParams; - rfalNfcDepTargetParam targetParam; - - ST_MEMCPY(targetParam.nfcid3, (uint8_t*)gNfcDev.disc.nfcid3, RFAL_NFCDEP_NFCID3_LEN); - targetParam.bst = RFAL_NFCDEP_Bx_NO_HIGH_BR; - targetParam.brt = RFAL_NFCDEP_Bx_NO_HIGH_BR; - targetParam.to = RFAL_NFCDEP_WT_TRG_MAX; - targetParam.ppt = rfalNfcDepLR2PP(RFAL_NFCDEP_LR_254); - targetParam.GBtLen = 0; - targetParam.operParam = (RFAL_NFCDEP_OPER_FULL_MI_EN | RFAL_NFCDEP_OPER_EMPTY_DEP_DIS | RFAL_NFCDEP_OPER_ATN_EN | RFAL_NFCDEP_OPER_RTOX_REQ_EN); - targetParam.commMode = commMode; - - - /* Set activation buffer (including header) for NFC-DEP */ - actvParams.rxBuf = &gNfcDev.rxBuf.nfcDepBuf; - actvParams.rxLen = &gNfcDev.rxLen; - actvParams.isRxChaining = &gNfcDev.isRxChaining; - actvParams.nfcDepDev = &gNfcDev.devList->proto.nfcDep; - - rfalListenSetState( ((device->type == RFAL_NFC_POLL_TYPE_NFCA) ? RFAL_LM_STATE_TARGET_A : RFAL_LM_STATE_TARGET_F) ); - - rfalNfcDepInitialize(); - /* Perform NFC-DEP (P2P) activation: send ATR_RES and handle activation */ - return rfalNfcDepListenStartActivation( &targetParam, atrReq, atrReqLen, actvParams ); - } -#endif /* RFAL_FEATURE_LISTEN_MODE */ - - else - { - return ERR_INTERNAL; - } -} -#endif /* RFAL_FEATURE_NFC_DEP */ - - -/*! - ****************************************************************************** - * \brief Poller NFC Deactivate - * - * This method Deactivates the device if a deactivation procedure exists - * - * \return ERR_NONE : Operation completed with no error - * \return ERR_BUSY : Operation ongoing - * \return ERR_XXXX : Error occurred - * - ****************************************************************************** - */ -static ReturnCode rfalNfcDeactivation( void ) -{ - /* Check if a device has been activated */ - if( gNfcDev.activeDev != NULL ) - { - switch( gNfcDev.activeDev->rfInterface ) - { - /*******************************************************************************/ - case RFAL_NFC_INTERFACE_RF: - break; /* No specific deactivation to be performed */ - - /*******************************************************************************/ - #if RFAL_FEATURE_ISO_DEP_POLL - case RFAL_NFC_INTERFACE_ISODEP: - rfalIsoDepDeselect(); /* Send a Deselect to device */ - break; - #endif /* RFAL_FEATURE_ISO_DEP_POLL */ - - /*******************************************************************************/ - #if RFAL_FEATURE_NFC_DEP - case RFAL_NFC_INTERFACE_NFCDEP: - rfalNfcDepRLS(); /* Send a Release to device */ - break; - #endif /* RFAL_FEATURE_NFC_DEP */ - - default: - return ERR_REQUEST; - } - } - - #if RFAL_FEATURE_WAKEUP_MODE - rfalWakeUpModeStop(); - #endif /* RFAL_FEATURE_WAKEUP_MODE */ - - #if RFAL_FEATURE_LISTEN_MODE - rfalListenStop(); - #else - rfalFieldOff(); - #endif - - gNfcDev.activeDev = NULL; - return ERR_NONE; -} diff --git a/Software/Middlewares/ST/rfal/Src/rfal_nfcDep.c b/Software/Middlewares/ST/rfal/Src/rfal_nfcDep.c deleted file mode 100644 index c92c877..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_nfcDep.c +++ /dev/null @@ -1,2530 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: NFCC firmware - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfcDep.c - * - * \author Gustavo Patricio - * - * \brief Implementation of NFC-DEP protocol - * - * NFC-DEP is also known as NFCIP - Near Field Communication - * Interface and Protocol - * - * This implementation was based on the following specs: - * - NFC Forum Digital 1.1 - * - ECMA 340 3rd Edition 2013 - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_nfcDep.h" -#include "rfal_nfcf.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_NFC_DEP - #define RFAL_FEATURE_NFC_DEP false /* NFC-DEP module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_NFC_DEP - -/* - ****************************************************************************** - * DEFINES - ****************************************************************************** - */ -#define NFCIP_ATR_RETRY_MAX 2U /*!< Max consecutive retrys of an ATR REQ with transm error*/ - -#define NFCIP_PSLPAY_LEN (2U) /*!< PSL Payload length (BRS + FSL) */ -#define NFCIP_PSLREQ_LEN (3U + RFAL_NFCDEP_LEN_LEN) /*!< PSL REQ length (incl LEN) */ -#define NFCIP_PSLRES_LEN (3U + RFAL_NFCDEP_LEN_LEN) /*!< PSL RES length (incl LEN) */ - -#define NFCIP_ATRREQ_BUF_LEN (RFAL_NFCDEP_ATRREQ_MAX_LEN + RFAL_NFCDEP_LEN_LEN) /*!< ATR REQ max length (incl LEN) */ -#define NFCIP_ATRRES_BUF_LEN (RFAL_NFCDEP_ATRRES_MAX_LEN + RFAL_NFCDEP_LEN_LEN) /*!< ATR RES max length (incl LEN) */ - -#define NFCIP_RLSREQ_LEN (3U + RFAL_NFCDEP_LEN_LEN) /*!< RLS REQ length (incl LEN) */ -#define NFCIP_RLSRES_LEN (3U + RFAL_NFCDEP_LEN_LEN) /*!< RSL RES length (incl LEN) */ -#define NFCIP_RLSRES_MIN (2U + RFAL_NFCDEP_LEN_LEN) /*!< Minimum length for a RLS RES (incl LEN) */ - -#define NFCIP_DSLREQ_LEN (3U + RFAL_NFCDEP_LEN_LEN) /*!< DSL REQ length (incl LEN) */ -#define NFCIP_DSLRES_LEN (3U + RFAL_NFCDEP_LEN_LEN) /*!< DSL RES length (incl LEN) */ -#define NFCIP_DSLRES_MIN (2U + RFAL_NFCDEP_LEN_LEN) /*!< Minimum length for a DSL RES (incl LEN) */ - -#define NFCIP_DSLRES_MAX_LEN (3U + RFAL_NFCDEP_LEN_LEN) /*!< Maximum length for a DSL RES (incl LEN) */ -#define NFCIP_RLSRES_MAX_LEN (3U + RFAL_NFCDEP_LEN_LEN) /*!< Minimum length for a RLS RES (incl LEN) */ -#define NFCIP_TARGET_RES_MAX ( MAX( NFCIP_RLSRES_MAX_LEN, NFCIP_DSLRES_MAX_LEN) ) /*!< Max target control res length */ - - - -#define NFCIP_NO_FWT RFAL_FWT_NONE /*!< No FWT value - Target Mode */ -#define NFCIP_INIT_MIN_RTOX 1U /*!< Minimum RTOX value Digital 1.0 14.8.4.1 */ -#define NFCIP_INIT_MAX_RTOX 59U /*!< Maximum RTOX value Digital 1.0 14.8.4.1 */ - -#define NFCIP_TARG_MIN_RTOX 1U /*!< Minimum target RTOX value Digital 1.0 14.8.4.1 */ -#define NFCIP_TARG_MAX_RTOX 59U /*!< Maximum target RTOX value Digital 1.0 14.8.4.1 */ - -#define NFCIP_TRECOV 1280U /*!< Digital 1.0 A.10 Trecov */ - -#define NFCIP_TIMEOUT_ADJUSTMENT 512U /*!< Timeout Adjustment to compensate timing from end of Tx to end of frame */ -#define NFCIP_RWT_ACTIVATION (0x1000001U + NFCIP_TIMEOUT_ADJUSTMENT) /*!< Digital 2.0 B.10 RWT ACTIVATION 2^24 + RWT Delta + Adjustment*/ -#define NFCIP_RWT_ACM_ACTIVATION (0x200001U + NFCIP_TIMEOUT_ADJUSTMENT) /*!< Digital 2.0 B.10 RWT ACTIVATION 2^21 + RWT Delta + Adjustment*/ - -#define RFAL_NFCDEP_HEADER_PAD (RFAL_NFCDEP_DEPREQ_HEADER_LEN - RFAL_NFCDEP_LEN_MIN) /*!< Difference between expected rcvd header len and max foreseen */ - - -#define NFCIP_MAX_TX_RETRYS (uint8_t)3U /*!< Number of retransmit retyrs */ -#define NFCIP_MAX_TO_RETRYS (uint8_t)3U /*!< Number of retrys for Timeout */ -#define NFCIP_MAX_RTOX_RETRYS (uint8_t)3U /*!< Number of retrys for RTOX */ -#define NFCIP_MAX_NACK_RETRYS (uint8_t)3U /*!< Number of retrys for NACK */ -#define NFCIP_MAX_ATN_RETRYS (uint8_t)3U /*!< Number of retrys for ATN */ - -#define NFCIP_MIN_TXERROR_LEN 4U /*!< Minimum frame length with error to be ignored Digital 1.0 14.12.5.4 */ - -#define NFCIP_REQ (uint8_t)0xD4U /*!= NFCIP_ST_INIT_IDLE) && ((st) <= NFCIP_ST_INIT_RLS) ) /*!< Checks if module is set as Initiator */ -#define nfcipIsTarget( st ) (!nfcipIsInitiator(st)) /*!< Checks if module is set as Target */ - -#define nfcipIsBRAllowed( br, mBR ) (((1U<<(br)) & (mBR)) != 0U) /*!< Checks bit rate is allowed by given mask */ - -#define nfcipIsEmptyDEPEnabled( op ) (!nfcipIsEmptyDEPDisabled(op)) /*!< Checks if empty payload is allowed by operation config NCI 1.0 Table 81 */ -#define nfcipIsEmptyDEPDisabled( op ) (((op) & RFAL_NFCDEP_OPER_EMPTY_DEP_DIS) != 0U) /*!< Checks if empty payload is not allowed by operation config NCI 1.0 Table 81 */ - -#define nfcipIsRTOXReqEnabled( op ) (!nfcipIsRTOXReqDisabled(op)) /*!< Checks if send a RTOX_REQ is allowed by operation config NCI 1.0 Table 81 */ -#define nfcipIsRTOXReqDisabled( op ) (((op) & RFAL_NFCDEP_OPER_RTOX_REQ_DIS) != 0U) /*!< Checks if send a RTOX_REQ is not allowed by operation config NCI 1.0 Table 81 */ - - -/*! Checks if isDeactivating callback is set and calls it, otherwise returns false */ -#define nfcipIsDeactivationPending() ( (gNfcip.isDeactivating == NULL) ? false : gNfcip.isDeactivating() ) - -/*! Returns the RWT Activation according to the current communication mode */ -#define nfcipRWTActivation() ((gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_ACTIVE) ? NFCIP_RWT_ACM_ACTIVATION : NFCIP_RWT_ACTIVATION) - - -#define nfcipRTOXAdjust( v ) ((v) - ((v)>>3)) /*!< Adjust RTOX timer value to a percentage of the total, current 88% */ - -/*******************************************************************************/ - -// timerPollTimeoutValue is necessary after timerCalculateTimeout so that system will wake up upon timer timeout. -#define nfcipTimerStart( timer, time_ms ) (timer) = platformTimerCreate((uint16_t)(time_ms)) /*!< Configures and starts the RTOX timer */ -#define nfcipTimerisExpired( timer ) platformTimerIsExpired( timer ) /*!< Checks RTOX timer has expired */ - -#define nfcipLogE(...) /*!< Macro for the error log method */ -#define nfcipLogW(...) /*!< Macro for the warning log method */ -#define nfcipLogI(...) /*!< Macro for the info log method */ -#define nfcipLogD(...) /*!< Macro for the debug log method */ - - -/*! Digital 1.1 - 16.12.5.2 The Target SHALL NOT attempt any error recovery and remains in Rx mode upon Transmission or a Protocol Error */ -#define nfcDepReEnableRx( rxB, rxBL, rxL ) rfalTransceiveBlockingTx( NULL, 0, (rxB), (rxBL), (rxL), ( RFAL_TXRX_FLAGS_DEFAULT | (uint32_t)RFAL_TXRX_FLAGS_NFCIP1_ON ), RFAL_FWT_NONE ) - -/* - ****************************************************************************** - * LOCAL DATA TYPES - ****************************************************************************** - */ - -/*! Struct that holds all DEP parameters/configs for the following communications */ -typedef struct{ - uint8_t did; /*!< Device ID (DID) to be used */ - - uint8_t* txBuf; /*!< Pointer to the Tx buffer to be sent */ - uint16_t txBufLen; /*!< Length of the data in the txBuf */ - uint8_t txBufPaylPos; /*!< Position inside txBuf where data starts */ - bool txChaining; /*!< Flag indicating chaining on transmission */ - - uint8_t* rxBuf; /*!< Pointer to the Rx buffer for incoming data */ - uint16_t rxBufLen; /*!< Length of the data in the rxBuf */ - uint8_t rxBufPaylPos; /*!< Position inside rxBuf where data is to be placed*/ - - uint32_t fwt; /*!< Frame Waiting Time (FWT) to be used */ - uint32_t dFwt; /*!< Delta Frame Waiting Time (dFWT) to be used */ - uint16_t fsc; /*!< Frame Size (FSC) to be used */ - -} rfalNfcDepDEPParams; - -/*! NFCIP module states */ -typedef enum -{ - NFCIP_ST_IDLE, - NFCIP_ST_INIT_IDLE, - NFCIP_ST_INIT_ATR, - NFCIP_ST_INIT_PSL, - NFCIP_ST_INIT_DEP_IDLE, - NFCIP_ST_INIT_DEP_TX, - NFCIP_ST_INIT_DEP_RX, - NFCIP_ST_INIT_DEP_ATN, - NFCIP_ST_INIT_DSL, - NFCIP_ST_INIT_RLS, - - NFCIP_ST_TARG_WAIT_ATR, - NFCIP_ST_TARG_WAIT_ACTV, - NFCIP_ST_TARG_DEP_IDLE, - NFCIP_ST_TARG_DEP_RX, - NFCIP_ST_TARG_DEP_RTOX, - NFCIP_ST_TARG_DEP_TX, - NFCIP_ST_TARG_DEP_SLEEP -} rfalNfcDepState; - -/*! NFCIP commands (Request, Response) */ -typedef enum{ - NFCIP_CMD_ATR_REQ = 0x00, - NFCIP_CMD_ATR_RES = 0x01, - NFCIP_CMD_WUP_REQ = 0x02, - NFCIP_CMD_WUP_RES = 0x03, - NFCIP_CMD_PSL_REQ = 0x04, - NFCIP_CMD_PSL_RES = 0x05, - NFCIP_CMD_DEP_REQ = 0x06, - NFCIP_CMD_DEP_RES = 0x07, - NFCIP_CMD_DSL_REQ = 0x08, - NFCIP_CMD_DSL_RES = 0x09, - NFCIP_CMD_RLS_REQ = 0x0A, - NFCIP_CMD_RLS_RES = 0x0B -} rfalNfcDepCmd; - - -/*! Struct that holds all NFCIP data */ -typedef struct{ - rfalNfcDepConfigs cfg; /*!< Holds the current configuration to be used */ - - rfalNfcDepState state; /*!< Current state of the NFCIP module */ - uint8_t pni; /*!< Packet Number Information (PNI) counter */ - - uint8_t lastCmd; /*!< Last command sent */ - uint8_t lastPFB; /*!< Last PFB sent */ - uint8_t lastPFBnATN; /*!< Last PFB sent (excluding ATN) */ - uint8_t lastRTOX; /*!< Last RTOX value sent */ - - uint8_t cntTxRetrys; /*!< Retransmissions counter */ - uint8_t cntTORetrys; /*!< Timeouts counter */ - uint8_t cntRTOXRetrys; /*!< RTOX counter */ - uint8_t cntNACKRetrys; /*!< NACK counter */ - uint8_t cntATNRetrys; /*!< Attention (ATN) counter */ - - uint16_t fsc; /*!< Current Frame Size (FSC) to be used */ - bool isTxChaining; /*!< Flag for chaining on Transmission */ - bool isRxChaining; /*!< Flag for chaining on Reception */ - uint8_t* txBuf; /*!< Pointer to the Tx buffer to be sent */ - uint8_t* rxBuf; /*!< Pointer to the Rx buffer for incoming data */ - uint16_t txBufLen; /*!< Length of the data in the txBuf */ - uint16_t rxBufLen; /*!< Length of rxBuf buffer */ - uint16_t* rxRcvdLen; /*!< Length of the data in the rxBuf */ - uint8_t txBufPaylPos; /*!< Position in txBuf where data starts */ - uint8_t rxBufPaylPos; /*!< Position in rxBuf where data is to be placed */ - bool *isChaining; /*!< Flag for chaining on Reception */ - - rfalNfcDepDevice *nfcDepDev; /*!< Pointer to NFC-DEP device info */ - - uint32_t RTOXTimer; /*!< Timer used for RTOX */ - rfalNfcDepDeactCallback isDeactivating; /*!< Deactivating flag check callback */ - - bool isReqPending; /*!< Flag pending REQ from Target activation */ - bool isTxPending; /*!< Flag pending DEP Block while waiting RTOX Ack */ - bool isWait4RTOX; /*!< Flag for waiting RTOX Ack */ -}rfalNfcDep; - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - -static rfalNfcDep gNfcip; /*!< NFCIP module instance */ - - -/* - ****************************************************************************** - * LOCAL FUNCTION PROTOTYPES - ****************************************************************************** - */ - -static ReturnCode nfcipTxRx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint32_t fwt, uint8_t* paylBuf, uint8_t paylBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxActLen ); -static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, uint16_t paylLen, uint8_t pfbData, uint32_t fwt ); -static ReturnCode nfcipDEPControlMsg( uint8_t pfb, uint8_t RTOX ); -static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uint16_t *outActRxLen, bool *outIsChaining ); -static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, bool *outIsChaining ); -static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint8_t *outBRS ); - - -/*! - ****************************************************************************** - * \brief NFCIP Configure - * - * Configures the nfcip layer with the given configurations - * - * \param[in] cfg : nfcip configuration for following communication - ****************************************************************************** - */ -static void nfcipConfig( const rfalNfcDepConfigs * cfg ); - - -/*! - ****************************************************************************** - * \brief Set DEP parameters - * - * This method sets the parameters/configs for following Data Exchange - * Sets the nfcip module state according to the role it is configured - * - * - * \warning To be used only after proper Initiator/Target activation: - * nfcipTargetHandleActivation() or nfcipInitiatorActivate() has - * returned success - * - * This must be called before nfcipRun() in case of Target to pass - * rxBuffer - * - * Everytime some data needs to be transmitted call this to set it and - * call nfcipRun() until done or error - * - * \param[in] DEPParams : the parameters to be used during Data Exchange - ****************************************************************************** - */ -static void nfcipSetDEPParams( rfalNfcDepDEPParams *DEPParams ); - - -/*! - ****************************************************************************** - * \brief NFCIP run protocol - * - * This method handles all the nfcip protocol during Data Exchange (DEP - * requests and responses). - * - * A data exchange cycle is considered a DEP REQ and a DEP RES. - * - * In case of Tx chaining(MI) must signal it with nfcipSetDEPParams() - * In case of Rx chaining(MI) outIsChaining will be set to true and the - * current data returned - * - * \param[out] outActRxLen : data received length - * \param[out] outIsChaining : true if other peer is performing chaining(MI) - * - * \return ERR_NONE : Data exchange cycle completed successfully - * \return ERR_TIMEOUT : Timeout occurred - * \return ERR_PROTO : Protocol error occurred - * \return ERR_AGAIN : Other peer is doing chaining(MI), current block - * was received successfully call again until complete - * - ****************************************************************************** - */ -static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining ); - - -/*! - ****************************************************************************** - * \brief Transmission method - * - * This method checks if the current communication is Active or Passive - * and performs the necessary procedures for each communication type - * - * Transmits the data hold in txBuf - * - * \param[in] txBuf : buffer to transmit - * \param[in] txBufLen : txBuffer capacity - * \param[in] fwt : fwt for current Tx - * - * \return ERR_NONE : No error - ****************************************************************************** - */ -static ReturnCode nfcipDataTx( uint8_t* txBuf, uint16_t txBufLen, uint32_t fwt ); - - -/*! - ****************************************************************************** - * \brief Reception method - * - * This method checks if the current communication is Active or Passive - * and calls the appropriate reception method - * - * Copies incoming data to rxBuf - * - * \param[in] blocking : reception is to be done blocking or non-blocking - * - * \return ERR_BUSY : Busy - * \return ERR_NONE : No error - ****************************************************************************** - */ -static ReturnCode nfcipDataRx( bool blocking ); - - -/* - ****************************************************************************** - * LOCAL FUNCTIONS - ****************************************************************************** - */ - -/*******************************************************************************/ - - -/*******************************************************************************/ -static bool nfcipDxIsSupported( uint8_t Dx, uint8_t BRx, uint8_t BSx ) -{ - uint8_t Bx; - - /* Take the min of the possible bit rates, we'll use one for both directions */ - Bx = MIN(BRx, BSx); - - /* Lower bit rates must be supported for P2P */ - if( (Dx <= (uint8_t)RFAL_NFCDEP_Dx_04_424) ) - { - return true; - } - - if( (Dx == (uint8_t)RFAL_NFCDEP_Dx_08_848) && (Bx >= (uint8_t)RFAL_NFCDEP_Bx_08_848) ) - { - return true; - } - - return false; -} - - -/*******************************************************************************/ -static ReturnCode nfcipTxRx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint32_t fwt, uint8_t* paylBuf, uint8_t paylBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxActLen ) -{ - ReturnCode ret; - - if( (cmd == NFCIP_CMD_DEP_REQ) || (cmd == NFCIP_CMD_DEP_RES) ) /* this method cannot be used for DEPs */ - { - return ERR_PARAM; - } - - /* Assign the global params for this TxRx */ - gNfcip.rxBuf = rxBuf; - gNfcip.rxBufLen = rxBufLen; - gNfcip.rxRcvdLen = rxActLen; - - - /*******************************************************************************/ - /* Transmission */ - /*******************************************************************************/ - if(txBuf != NULL) /* if nothing to Tx, just do Rx */ - { - EXIT_ON_ERR( ret, nfcipTx( cmd, txBuf, paylBuf, paylBufLen, 0, fwt ) ); - } - - /*******************************************************************************/ - /* Reception */ - /*******************************************************************************/ - ret = nfcipDataRx( true ); - if( ret != ERR_NONE ) - { - return ret; - } - - /*******************************************************************************/ - *rxActLen = *rxBuf; /* Use LEN byte instead due to with/without CRC modes */ - return ERR_NONE; /* Tx and Rx completed successfully */ -} - - -/*******************************************************************************/ -static ReturnCode nfcipDEPControlMsg( uint8_t pfb, uint8_t RTOX ) -{ - uint8_t ctrlMsg[20]; - rfalNfcDepCmd depCmd; - uint32_t fwt; - - - /*******************************************************************************/ - /* Calculate Cmd and fwt to be used */ - /*******************************************************************************/ - depCmd = ((gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) ? NFCIP_CMD_DEP_RES : NFCIP_CMD_DEP_REQ); - fwt = ((gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) ? NFCIP_NO_FWT : (nfcip_PFBisSTO( pfb ) ? ( (RTOX*gNfcip.cfg.fwt) + gNfcip.cfg.dFwt) : (gNfcip.cfg.fwt + gNfcip.cfg.dFwt) ) ); - - if( nfcip_PFBisSTO( pfb ) ) - { - ctrlMsg[RFAL_NFCDEP_DEPREQ_HEADER_LEN] = RTOX; - return nfcipTx( depCmd, ctrlMsg, &ctrlMsg[RFAL_NFCDEP_DEPREQ_HEADER_LEN], sizeof(uint8_t), pfb, fwt ); - } - else - { - return nfcipTx( depCmd, ctrlMsg, NULL, 0, pfb, fwt ); - } -} - -/*******************************************************************************/ -static void nfcipClearCounters( void ) -{ - gNfcip.cntATNRetrys = 0; - gNfcip.cntNACKRetrys = 0; - gNfcip.cntTORetrys = 0; - gNfcip.cntTxRetrys = 0; - gNfcip.cntRTOXRetrys = 0; -} - -/*******************************************************************************/ -static ReturnCode nfcipInitiatorHandleDEP( ReturnCode rxRes, uint16_t rxLen, uint16_t *outActRxLen, bool *outIsChaining ) -{ - ReturnCode ret; - uint8_t nfcDepLen; - uint8_t rxMsgIt; - uint8_t rxPFB; - uint8_t rxRTOX; - uint8_t optHdrLen; - - ret = ERR_INTERNAL; - rxMsgIt = 0; - optHdrLen = 0; - - *outActRxLen = 0; - *outIsChaining = false; - - - /*******************************************************************************/ - /* Handle reception errors */ - /*******************************************************************************/ - switch( rxRes ) - { - /*******************************************************************************/ - /* Timeout -> Digital 1.0 14.15.5.6 */ - case ERR_TIMEOUT: - - nfcipLogI( " NFCIP(I) TIMEOUT TORetrys:%d \r\n", gNfcip.cntTORetrys ); - - /* Digital 1.0 14.15.5.6 - If nTO >= Max raise protocol error */ - if( gNfcip.cntTORetrys++ >= NFCIP_MAX_TO_RETRYS ) - { - return ERR_PROTO; - } - - /*******************************************************************************/ - /* Upon Timeout error, if Deactivation is pending, no more error recovery - * will be done #54. - * This is used to address the issue some devices that havea big TO. - * Normally LLCP layer has timeout already, and NFCIP layer is still - * running error handling, retrying ATN/NACKs */ - /*******************************************************************************/ - if( nfcipIsDeactivationPending() ) - { - nfcipLogI( " skipping error recovery due deactivation pending \r\n"); - return ERR_TIMEOUT; - } - - /* Digital 1.0 14.15.5.6 1) If last PDU was NACK */ - if( nfcip_PFBisRNACK(gNfcip.lastPFB) ) - { - /* Digital 1.0 14.15.5.6 2) if NACKs failed raise protocol error */ - if( gNfcip.cntNACKRetrys++ >= NFCIP_MAX_NACK_RETRYS ) - { - return ERR_PROTO; - } - - /* Send NACK */ - nfcipLogI( " NFCIP(I) Sending NACK retry: %d \r\n", gNfcip.cntNACKRetrys ); - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_NACK(gNfcip.pni), 0 ) ); - return ERR_BUSY; - } - - nfcipLogI( " NFCIP(I) Checking if to send ATN ATNRetrys: %d \r\n", gNfcip.cntATNRetrys ); - - /* Digital 1.0 14.15.5.6 3) Otherwise send ATN */ - if( gNfcip.cntATNRetrys++ >= NFCIP_MAX_NACK_RETRYS ) - { - return ERR_PROTO; - } - - /* Send ATN */ - nfcipLogI( " NFCIP(I) Sending ATN \r\n" ); - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_ATN(), 0 ) ); - return ERR_BUSY; - - /*******************************************************************************/ - /* Data rcvd with error -> Digital 1.0 14.12.5.4 */ - case ERR_CRC: - case ERR_PAR: - case ERR_FRAMING: - case ERR_RF_COLLISION: - - nfcipLogI( " NFCIP(I) rx Error: %d \r\n", rxRes ); - - /* Digital 1.0 14.12.5.4 Tx Error with data, ignore */ - if( rxLen < NFCIP_MIN_TXERROR_LEN ) - { - nfcipLogI( " NFCIP(I) Transmission error w data \r\n" ); -#if 0 - if(gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_PASSIVE) - { - nfcipLogI( " NFCIP(I) Transmission error w data -> reEnabling Rx \r\n" ); - nfcipReEnableRxTout( NFCIP_TRECOV ); - return ERR_BUSY; - } -#endif /* 0 */ - } - - /* Digital 1.1 16.12.5.4 if NACKs failed raise Transmission error */ - if( gNfcip.cntNACKRetrys++ >= NFCIP_MAX_NACK_RETRYS ) - { - return ERR_FRAMING; - } - - /* Send NACK */ - nfcipLogI( " NFCIP(I) Sending NACK \r\n" ); - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_NACK(gNfcip.pni), 0 ) ); - return ERR_BUSY; - - case ERR_NONE: - break; - - case ERR_BUSY: - return ERR_BUSY; /* Debug purposes */ - - default: - nfcipLogW( " NFCIP(I) Error: %d \r\n", rxRes ); - return rxRes; - } - - /*******************************************************************************/ - /* Rx OK check if valid DEP PDU */ - /*******************************************************************************/ - - /* Due to different modes on ST25R391x (with/without CRC) use NFC-DEP LEN instead of bytes retrieved */ - nfcDepLen = gNfcip.rxBuf[rxMsgIt++]; - - nfcipLogD( " NFCIP(I) rx OK: %d bytes \r\n", nfcDepLen ); - - /* Digital 1.0 14.15.5.5 Protocol Error */ - if( gNfcip.rxBuf[rxMsgIt++] != NFCIP_RES ) - { - nfcipLogW( " NFCIP(I) error %02X instead of %02X \r\n", gNfcip.rxBuf[--rxMsgIt], NFCIP_RES ); - return ERR_PROTO; - } - - /* Digital 1.0 14.15.5.5 Protocol Error */ - if( gNfcip.rxBuf[rxMsgIt++] != (uint8_t)NFCIP_CMD_DEP_RES ) - { - nfcipLogW( " NFCIP(I) error %02X instead of %02X \r\n", gNfcip.rxBuf[--rxMsgIt], NFCIP_CMD_DEP_RES ); - return ERR_PROTO; - } - - rxPFB = gNfcip.rxBuf[rxMsgIt++]; - - /*******************************************************************************/ - /* Check for valid PFB type */ - if( !(nfcip_PFBisSPDU( rxPFB ) || nfcip_PFBisRPDU( rxPFB ) || nfcip_PFBisIPDU( rxPFB )) ) - { - return ERR_PROTO; - } - - /*******************************************************************************/ - /* Digital 1.0 14.8.2.1 check if DID is expected and match -> Protocol Error */ - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) - { - if( (gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did) || !nfcip_PFBhasDID( rxPFB ) ) - { - return ERR_PROTO; - } - optHdrLen++; /* Inc header optional field cnt*/ - } - else if( nfcip_PFBhasDID( rxPFB ) ) /* DID not expected but rcv */ - { - return ERR_PROTO; - } - else - { - /* MISRA 15.7 - Empty else */ - } - - /*******************************************************************************/ - /* Digital 1.0 14.6.2.8 & 14.6.3.11 NAD must not be used */ - if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) - { - if( (gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.nad) || !nfcip_PFBhasNAD( rxPFB ) ) - { - return ERR_PROTO; - } - optHdrLen++; /* Inc header optional field cnt*/ - } - else if( nfcip_PFBhasNAD( rxPFB ) ) /* NAD not expected but rcv */ - { - return ERR_PROTO; - } - else - { - /* MISRA 15.7 - Empty else */ - } - - /*******************************************************************************/ - /* Process R-PDU */ - /*******************************************************************************/ - if( nfcip_PFBisRPDU( rxPFB ) ) - { - /*******************************************************************************/ - /* R ACK */ - /*******************************************************************************/ - if( nfcip_PFBisRACK( rxPFB ) ) - { - nfcipLogI( " NFCIP(I) Rcvd ACK \r\n" ); - if( gNfcip.pni == nfcip_PBF_PNI( rxPFB ) ) - { - /* 14.12.3.3 R-ACK with correct PNI -> Increment */ - gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - - /* R-ACK while not performing chaining -> Protocol error*/ - if( !gNfcip.isTxChaining ) - { - return ERR_PROTO; - } - - nfcipClearCounters(); - gNfcip.state = NFCIP_ST_INIT_DEP_IDLE; - return ERR_NONE; /* This block has been transmitted */ - } - else /* Digital 1.0 14.12.4.5 ACK with wrong PNI Initiator may retransmit */ - { - if( gNfcip.cntTxRetrys++ >= NFCIP_MAX_TX_RETRYS ) - { - return ERR_PROTO; - } - - /* Extended the MAY in Digital 1.0 14.12.4.5 to only reTransmit if the ACK - * is for the previous DEP, otherwise raise Protocol immediately - * If the PNI difference is more than 1 it is worthless to reTransmit 3x - * and after raise the error */ - - if( nfcip_PNIDec( gNfcip.pni ) == nfcip_PBF_PNI( rxPFB ) ) - { - /* ReTransmit */ - nfcipLogI( " NFCIP(I) Rcvd ACK prev PNI -> reTx \r\n" ); - gNfcip.state = NFCIP_ST_INIT_DEP_TX; - return ERR_BUSY; - } - - nfcipLogI( " NFCIP(I) Rcvd ACK unexpected far PNI -> Error \r\n" ); - return ERR_PROTO; - } - } - else /* Digital 1.0 - 14.12.5.2 Target must never send NACK */ - { - return ERR_PROTO; - } - } - - /*******************************************************************************/ - /* Process S-PDU */ - /*******************************************************************************/ - if( nfcip_PFBisSPDU( rxPFB ) ) - { - nfcipLogI( " NFCIP(I) Rcvd S-PDU \r\n" ); - /*******************************************************************************/ - /* S ATN */ - /*******************************************************************************/ - if( nfcip_PFBisSATN( rxPFB ) ) /* If is a S-ATN */ - { - nfcipLogI( " NFCIP(I) Rcvd ATN \r\n" ); - if( nfcip_PFBisSATN( gNfcip.lastPFB ) ) /* Check if is expected */ - { - gNfcip.cntATNRetrys = 0; /* Clear ATN counter */ - - /* Although spec is not clear NFC Forum Digital test is expecting to - * retransmit upon receiving ATN_RES */ - if( nfcip_PFBisSTO( gNfcip.lastPFBnATN ) ) - { - nfcipLogI( " NFCIP(I) Rcvd ATN -> reTx RTOX_RES \r\n" ); - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_TO(), gNfcip.lastRTOX ) ); - } - else - { - /* ReTransmit ? */ - if( gNfcip.cntTxRetrys++ >= NFCIP_MAX_TX_RETRYS ) - { - return ERR_PROTO; - } - - nfcipLogI( " NFCIP(I) Rcvd ATN -> reTx PNI: %d \r\n", gNfcip.pni ); - gNfcip.state = NFCIP_ST_INIT_DEP_TX; - } - - return ERR_BUSY; - } - else /* Digital 1.0 14.12.4.4 & 14.12.4.8 */ - { - return ERR_PROTO; - } - } - /*******************************************************************************/ - /* S TO */ - /*******************************************************************************/ - else if( nfcip_PFBisSTO( rxPFB ) ) /* If is a S-TO (RTOX) */ - { - nfcipLogI( " NFCIP(I) Rcvd TO \r\n" ); - - rxRTOX = gNfcip.rxBuf[rxMsgIt++]; - - /* Digital 1.1 16.12.4.3 - Initiator MAY stop accepting subsequent RTOX Req * - * - RTOX request to an ATN -> Protocol error */ - if( (gNfcip.cntRTOXRetrys++ > NFCIP_MAX_RTOX_RETRYS) || nfcip_PFBisSATN( gNfcip.lastPFB ) ) - { - return ERR_PROTO; - } - - /* Digital 1.1 16.8.4.1 RTOX must be between [1,59] */ - if( (rxRTOX < NFCIP_INIT_MIN_RTOX) || (rxRTOX > NFCIP_INIT_MAX_RTOX) ) - { - return ERR_PROTO; - } - - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_TO(), rxRTOX ) ); - gNfcip.lastRTOX = rxRTOX; - - return ERR_BUSY; - } - else - { - /* Unexpected S-PDU */ - return ERR_PROTO; /* PRQA S 2880 # MISRA 2.1 - Guard code to prevent unexpected behavior */ - } - } - - /*******************************************************************************/ - /* Process I-PDU */ - /*******************************************************************************/ - if( nfcip_PFBisIPDU( rxPFB ) ) - { - if( gNfcip.pni != nfcip_PBF_PNI( rxPFB ) ) - { - nfcipLogI( " NFCIP(I) Rcvd IPDU wrong PNI curPNI: %d rxPNI: %d \r\n", gNfcip.pni , nfcip_PBF_PNI( rxPFB ) ); - return ERR_PROTO; - } - - nfcipLogD( " NFCIP(I) Rcvd IPDU OK PNI: %d \r\n", gNfcip.pni ); - - /* 14.12.3.3 I-PDU with correct PNI -> Increment */ - gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - - - /* Successful data Exchange */ - nfcipClearCounters(); - *outActRxLen = ((uint16_t)nfcDepLen - RFAL_NFCDEP_DEP_HEADER - (uint16_t)optHdrLen); - - if( (&gNfcip.rxBuf[gNfcip.rxBufPaylPos] != &gNfcip.rxBuf[RFAL_NFCDEP_DEP_HEADER + optHdrLen]) && (*outActRxLen > 0U) ) - { - ST_MEMMOVE( &gNfcip.rxBuf[gNfcip.rxBufPaylPos], &gNfcip.rxBuf[RFAL_NFCDEP_DEP_HEADER + optHdrLen], *outActRxLen ); - } - - /*******************************************************************************/ - /* Check if target is indicating chaining MI */ - /*******************************************************************************/ - if( nfcip_PFBisIMI( rxPFB ) ) - { - gNfcip.isRxChaining = true; - *outIsChaining = true; - - nfcipLogD( " NFCIP(I) Rcvd IPDU OK w MI -> ACK \r\n" ); - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++] ) ); - - return ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/ - } - else - { - gNfcip.isRxChaining = false; - gNfcip.state = NFCIP_ST_INIT_DEP_IDLE; - - ret = ERR_NONE; /* Data exchange done */ - } - } - return ret; -} - - -/*******************************************************************************/ -static ReturnCode nfcipTargetHandleRX( ReturnCode rxRes, uint16_t *outActRxLen, bool *outIsChaining ) -{ - ReturnCode ret; - uint8_t nfcDepLen; - uint8_t rxMsgIt; - uint8_t rxPFB; - uint8_t optHdrLen; - uint8_t resBuf[RFAL_NFCDEP_HEADER_PAD + NFCIP_TARGET_RES_MAX]; - - - ret = ERR_INTERNAL; - rxMsgIt = 0; - optHdrLen = 0; - - *outActRxLen = 0; - *outIsChaining = false; - - - /*******************************************************************************/ - /* Handle reception errors */ - /*******************************************************************************/ - switch( rxRes ) - { - /*******************************************************************************/ - case ERR_NONE: - break; - - case ERR_LINK_LOSS: - nfcipLogW( " NFCIP(T) Error: %d \r\n", rxRes ); - return rxRes; - - case ERR_BUSY: - return ERR_BUSY; /* Debug purposes */ - - case ERR_TIMEOUT: - case ERR_CRC: - case ERR_PAR: - case ERR_FRAMING: - case ERR_PROTO: - default: - /* Digital 1.1 16.12.5.2 The Target MUST NOT attempt any error recovery. * - * The Target MUST always stay in receive mode when a * - * Transmission Error or a Protocol Error occurs. * - * * - * Do not push Transmission/Protocol Errors to upper layer in Listen Mode #766 */ - - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; - } - - /*******************************************************************************/ - /* Rx OK check if valid DEP PDU */ - /*******************************************************************************/ - - /* Due to different modes on ST25R391x (with/without CRC) use NFC-DEP LEN instead of bytes retrieved */ - nfcDepLen = gNfcip.rxBuf[rxMsgIt++]; - - nfcipLogD( " NFCIP(T) rx OK: %d bytes \r\n", nfcDepLen ); - - if( gNfcip.rxBuf[rxMsgIt++] != NFCIP_REQ ) - { - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore bad request */ - } - - - /*******************************************************************************/ - /* Check whether target rcvd a normal DEP or deactivation request */ - /*******************************************************************************/ - switch( gNfcip.rxBuf[rxMsgIt++] ) - { - /*******************************************************************************/ - case (uint8_t)NFCIP_CMD_DEP_REQ: - break; /* Continue to normal DEP processing */ - - /*******************************************************************************/ - case (uint8_t)NFCIP_CMD_DSL_REQ: - - nfcipLogI( " NFCIP(T) rx DSL \r\n" ); - - /* Digital 1.0 14.9.1.2 If DID is used and incorrect ignore it */ - /* [Digital 1.0, 16.9.1.2]: If DID == 0, Target SHALL ignore DSL_REQ with DID */ - if ( (((gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did) || (nfcDepLen != RFAL_NFCDEP_DSL_RLS_LEN_DID)) && (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) ) - || ((gNfcip.cfg.did == RFAL_NFCDEP_DID_NO) && (nfcDepLen != RFAL_NFCDEP_DSL_RLS_LEN_NO_DID)) - ) - { - nfcipLogI( " NFCIP(T) DSL wrong DID, ignoring \r\n" ); - return ERR_BUSY; - } - - nfcipTx( NFCIP_CMD_DSL_RES, resBuf, NULL, 0, 0, NFCIP_NO_FWT ); - - gNfcip.state = NFCIP_ST_TARG_DEP_SLEEP; - return ERR_SLEEP_REQ; - - /*******************************************************************************/ - case (uint8_t)NFCIP_CMD_RLS_REQ: - - nfcipLogI( " NFCIP(T) rx RLS \r\n" ); - - /* Digital 1.0 14.10.1.2 If DID is used and incorrect ignore it */ - /* [Digital 1.0, 16.10.2.2]: If DID == 0, Target SHALL ignore DSL_REQ with DID */ - if ( (((gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did) || (nfcDepLen != RFAL_NFCDEP_DSL_RLS_LEN_DID)) && (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) ) - || ((gNfcip.cfg.did == RFAL_NFCDEP_DID_NO) && (nfcDepLen > RFAL_NFCDEP_DSL_RLS_LEN_NO_DID)) - ) - { - nfcipLogI( " NFCIP(T) RLS wrong DID, ignoring \r\n" ); - return ERR_BUSY; - } - - nfcipTx( NFCIP_CMD_RLS_RES, resBuf, NULL, 0, 0, NFCIP_NO_FWT ); - - gNfcip.state = NFCIP_ST_TARG_DEP_IDLE; - return ERR_RELEASE_REQ; - - /*******************************************************************************/ - /*case NFCIP_CMD_PSL_REQ: PSL must be handled in Activation only */ - /*case NFCIP_CMD_WUP_REQ: WUP not in NFC Forum Digital 1.0 */ - default: - - /* Don't go to NFCIP_ST_TARG_DEP_IDLE state as it needs to ignore this * - * invalid frame, and keep waiting for more frames */ - - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore bad frame */ - } - - /*******************************************************************************/ - - rxPFB = gNfcip.rxBuf[rxMsgIt++]; /* Store rcvd PFB */ - - /*******************************************************************************/ - /* Check for valid PFB type */ - if( !(nfcip_PFBisSPDU( rxPFB ) || nfcip_PFBisRPDU( rxPFB ) || nfcip_PFBisIPDU( rxPFB )) ) - { - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore invalid PFB */ - } - - /*******************************************************************************/ - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) - { - if( !nfcip_PFBhasDID( rxPFB ) ) - { - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore bad/missing DID */ - } - if( gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did ) /* MISRA 13.5 */ - { - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore bad/missing DID */ - } - optHdrLen++; /* Inc header optional field cnt*/ - } - else if( nfcip_PFBhasDID( rxPFB ) ) /* DID not expected but rcv */ - { - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore unexpected DID */ - } - else - { - /* MISRA 15.7 - Empty else */ - } - - - /*******************************************************************************/ - if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) - { - if( (gNfcip.rxBuf[rxMsgIt++] != gNfcip.cfg.did) || !nfcip_PFBhasDID( rxPFB ) ) - { - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore bad/missing DID */ - } - optHdrLen++; /* Inc header optional field cnt*/ - } - else if( nfcip_PFBhasNAD( rxPFB ) ) /* NAD not expected but rcv */ - { - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore unexpected NAD */ - } - else - { - /* MISRA 15.7 - Empty else */ - } - - - /*******************************************************************************/ - /* Process R-PDU */ - /*******************************************************************************/ - if( nfcip_PFBisRPDU( rxPFB ) ) - { - nfcipLogD( " NFCIP(T) Rcvd R-PDU \r\n" ); - /*******************************************************************************/ - /* R ACK */ - /*******************************************************************************/ - if( nfcip_PFBisRACK( rxPFB ) ) - { - nfcipLogI( " NFCIP(T) Rcvd ACK \r\n" ); - if( gNfcip.pni == nfcip_PBF_PNI( rxPFB ) ) - { - /* R-ACK while not performing chaining -> Protocol error */ - if( !gNfcip.isTxChaining ) - { - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore unexpected ACK */ - } - - /* This block has been transmitted and acknowledged, perform RTOX until next data is provided */ - - /* Digital 1.1 16.12.4.7 - If ACK rcvd continue with chaining or an RTOX */ - nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( rfalNfcDepWT2RWT( gNfcip.cfg.to ) )) ); - gNfcip.state = NFCIP_ST_TARG_DEP_RTOX; - - return ERR_NONE; /* This block has been transmitted */ - } - - /* Digital 1.0 14.12.3.4 - If last send was ATN and rx PNI is minus 1 */ - else if( nfcip_PFBisSATN( gNfcip.lastPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB )) ) - { - nfcipLogI( " NFCIP(T) wrong PNI, last was ATN reTx \r\n" ); - /* Spec says to leave current PNI as is, but will be Inc after Tx, remaining the same */ - gNfcip.pni = nfcip_PNIDec( gNfcip.pni ); - - gNfcip.state = NFCIP_ST_TARG_DEP_TX; - return ERR_BUSY; - } - else - { - /* MISRA 15.7 - Empty else */ - } - } - /*******************************************************************************/ - /* R NACK */ - /*******************************************************************************/ - /* ISO 18092 12.6.1.3.3 When rcv NACK if PNI = prev PNI sent -> reTx */ - else if( nfcip_PFBisRNACK( rxPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB ) ) ) - { - nfcipLogI( " NFCIP(T) Rcvd NACK \r\n" ); - - gNfcip.pni = nfcip_PNIDec( gNfcip.pni ); /* Dec so that has the prev PNI */ - - gNfcip.state = NFCIP_ST_TARG_DEP_TX; - return ERR_BUSY; - } - else - { - nfcipLogI( " NFCIP(T) Unexpected R-PDU \r\n" ); - - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore unexpected R-PDU */ - } - } - - /*******************************************************************************/ - /* Process S-PDU */ - /*******************************************************************************/ - if( nfcip_PFBisSPDU( rxPFB ) ) - { - nfcipLogD( " NFCIP(T) Rcvd S-PDU \r\n" ); - - /*******************************************************************************/ - /* S ATN */ - /*******************************************************************************/ - /* ISO 18092 12.6.3 Attention */ - if( nfcip_PFBisSATN( rxPFB ) ) /* If is a S-ATN */ - { - nfcipLogI( " NFCIP(T) Rcvd ATN curPNI: %d \r\n", gNfcip.pni ); - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_ATN(), 0 ) ); - return ERR_BUSY; - } - - /*******************************************************************************/ - /* S TO */ - /*******************************************************************************/ - else if( nfcip_PFBisSTO( rxPFB ) ) /* If is a S-TO (RTOX) */ - { - if( nfcip_PFBisSTO( gNfcip.lastPFBnATN ) ) - { - nfcipLogI( " NFCIP(T) Rcvd TO \r\n" ); - - /* Digital 1.1 16.8.4.6 RTOX value in RES different that in REQ -> Protocol Error */ - if( gNfcip.lastRTOX != gNfcip.rxBuf[rxMsgIt++] ) - { - nfcipLogI( " NFCIP(T) Mismatched RTOX value \r\n" ); - - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore unexpected RTOX value */ - } - - /* Clear waiting for RTOX Ack Flag */ - gNfcip.isWait4RTOX = false; - - /* Check if a Tx is already pending */ - if( gNfcip.isTxPending ) - { - nfcipLogW( " NFCIP(T) Tx pending, go immediately to TX \r\n" ); - - gNfcip.state = NFCIP_ST_TARG_DEP_TX; - return ERR_BUSY; - } - - /* Start RTOX timer and change to check state */ - nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( gNfcip.lastRTOX * rfalNfcDepWT2RWT(gNfcip.cfg.to ) ) ) ); - gNfcip.state = NFCIP_ST_TARG_DEP_RTOX; - - return ERR_BUSY; - } - } - else - { - /* Unexpected S-PDU */ - nfcipLogI( " NFCIP(T) Unexpected S-PDU \r\n" ); /* PRQA S 2880 # MISRA 2.1 - Guard code to prevent unexpected behavior */ - - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore unexpected S-PDU */ - } - } - - /*******************************************************************************/ - /* Process I-PDU */ - /*******************************************************************************/ - if( nfcip_PFBisIPDU( rxPFB ) ) - { - if( gNfcip.pni != nfcip_PBF_PNI( rxPFB ) ) - { - nfcipLogI( " NFCIP(T) Rcvd IPDU wrong PNI curPNI: %d rxPNI: %d \r\n", gNfcip.pni, nfcip_PBF_PNI( rxPFB ) ); - - /* Digital 1.1 16.12.3.4 - If last send was ATN and rx PNI is minus 1 */ - if( nfcip_PFBisSATN(gNfcip.lastPFB ) && (nfcip_PNIDec(gNfcip.pni) == nfcip_PBF_PNI( rxPFB )) ) - { - /* Spec says to leave current PNI as is, but will be Inc after Data Tx, remaining the same */ - gNfcip.pni = nfcip_PNIDec(gNfcip.pni); - - if( nfcip_PFBisIMI( rxPFB ) ) - { - nfcipLogI( " NFCIP(T) PNI = prevPNI && ATN before && chaining -> send ACK \r\n" ); - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++] ) ); - - /* Digital 1.1 16.12.3.4 (...) leave the current PNI unchanged afterwards */ - gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - } - else - { - nfcipLogI( " NFCIP(T) PNI = prevPNI && ATN before -> reTx last I-PDU \r\n" ); - gNfcip.state = NFCIP_ST_TARG_DEP_TX; - } - - return ERR_BUSY; - } - - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - return ERR_BUSY; /* ERR_PROTO - Ignore bad PNI value */ - } - - nfcipLogD( " NFCIP(T) Rcvd IPDU OK PNI: %d \r\n", gNfcip.pni ); - - /*******************************************************************************/ - /* Successful data exchange */ - /*******************************************************************************/ - *outActRxLen = ((uint16_t)nfcDepLen - RFAL_NFCDEP_DEP_HEADER - (uint16_t)optHdrLen); - - nfcipClearCounters(); - - if( (&gNfcip.rxBuf[gNfcip.rxBufPaylPos] != &gNfcip.rxBuf[RFAL_NFCDEP_DEP_HEADER + optHdrLen]) && (*outActRxLen > 0U) ) - { - ST_MEMMOVE( &gNfcip.rxBuf[gNfcip.rxBufPaylPos], &gNfcip.rxBuf[RFAL_NFCDEP_DEP_HEADER + optHdrLen], *outActRxLen ); - } - - - /*******************************************************************************/ - /* Check if Initiator is indicating chaining MI */ - /*******************************************************************************/ - if( nfcip_PFBisIMI( rxPFB ) ) - { - gNfcip.isRxChaining = true; - *outIsChaining = true; - - nfcipLogD( " NFCIP(T) Rcvd IPDU OK w MI -> ACK \r\n" ); - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBRPDU_ACK( gNfcip.pni ), gNfcip.rxBuf[rxMsgIt++] ) ); - - gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - - return ERR_AGAIN; /* Send Again signalling to run again, but some chaining data has arrived*/ - } - else - { - if(gNfcip.isRxChaining) - { - nfcipLogI( " NFCIP(T) Rcvd last IPDU chaining finished \r\n" ); - } - - /*******************************************************************************/ - /* Reception done, send to DH and start RTOX timer */ - /*******************************************************************************/ - nfcipTimerStart( gNfcip.RTOXTimer, nfcipRTOXAdjust( nfcipConv1FcToMs( rfalNfcDepWT2RWT( gNfcip.cfg.to ) )) ); - gNfcip.state = NFCIP_ST_TARG_DEP_RTOX; - - gNfcip.isRxChaining = false; - ret = ERR_NONE; /* Data exchange done */ - } - } - return ret; -} - - -/*******************************************************************************/ -static ReturnCode nfcipTx( rfalNfcDepCmd cmd, uint8_t* txBuf, uint8_t *paylBuf, uint16_t paylLen, uint8_t pfbData, uint32_t fwt ) -{ - uint16_t txBufIt; - uint8_t *txBlock; - uint8_t *payloadBuf; - uint8_t pfb; - - - if( txBuf == NULL ) - { - return ERR_PARAM; - } - - - payloadBuf = paylBuf; /* MISRA 17.8: Use intermediate variable */ - - if( (paylLen == 0U) || (payloadBuf == NULL) ) - { - payloadBuf = (uint8_t*) &txBuf[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /* If not a DEP (no Data) ensure enough space for header */ - } - - - txBufIt = 0; - pfb = pfbData; /* MISRA 17.8: Use intermediate variable */ - - txBlock = payloadBuf; /* Point to beginning of the Data, and go backwards */ - - - gNfcip.lastCmd = (uint8_t)cmd; /* Store last cmd sent */ - gNfcip.lastPFB = NFCIP_PFB_INVALID; /* Reset last pfb sent */ - - /*******************************************************************************/ - /* Compute outgoing NFCIP message */ - /*******************************************************************************/ - switch( cmd ) - { - /*******************************************************************************/ - case NFCIP_CMD_ATR_RES: - case NFCIP_CMD_ATR_REQ: - - rfalNfcDepSetNFCID( payloadBuf, gNfcip.cfg.nfcid, gNfcip.cfg.nfcidLen ); /* NFCID */ - txBufIt += RFAL_NFCDEP_NFCID3_LEN; - - payloadBuf[txBufIt++] = gNfcip.cfg.did; /* DID */ - payloadBuf[txBufIt++] = gNfcip.cfg.bs; /* BS */ - payloadBuf[txBufIt++] = gNfcip.cfg.br; /* BR */ - - if( cmd == NFCIP_CMD_ATR_RES ) - { - payloadBuf[txBufIt++] = gNfcip.cfg.to; /* ATR_RES[ TO ] */ - } - - if( gNfcip.cfg.gbLen > 0U) - { - payloadBuf[txBufIt++] = nfcip_PPwGB( gNfcip.cfg.lr ); /* PP signalling GB */ - ST_MEMCPY( &payloadBuf[txBufIt], gNfcip.cfg.gb, gNfcip.cfg.gbLen ); /* set General Bytes */ - txBufIt += gNfcip.cfg.gbLen; - } - else - { - payloadBuf[txBufIt++] = rfalNfcDepLR2PP( gNfcip.cfg.lr ); /* PP without GB */ - } - - if( (txBufIt + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN) > RFAL_NFCDEP_ATRREQ_MAX_LEN ) /* Check max ATR length (ATR_REQ = ATR_RES)*/ - { - return ERR_PARAM; - } - break; - - /*******************************************************************************/ - case NFCIP_CMD_WUP_REQ: /* ISO 18092 - 12.5.2.1 */ - - rfalNfcDepSetNFCID( (payloadBuf), gNfcip.cfg.nfcid, gNfcip.cfg.nfcidLen ); /* NFCID */ - txBufIt += RFAL_NFCDEP_NFCID3_LEN; - - *(--txBlock) = gNfcip.cfg.did; /* DID */ - break; - - /*******************************************************************************/ - case NFCIP_CMD_WUP_RES: /* ISO 18092 - 12.5.2.2 */ - case NFCIP_CMD_PSL_REQ: - case NFCIP_CMD_PSL_RES: - - *(--txBlock) = gNfcip.cfg.did; /* DID */ - break; - - /*******************************************************************************/ - case NFCIP_CMD_RLS_REQ: - case NFCIP_CMD_RLS_RES: - case NFCIP_CMD_DSL_REQ: - case NFCIP_CMD_DSL_RES: - - /* Digital 1.0 - 14.8.1.1 & 14.9.1.1 & 14.10.1.1 Only add DID if not 0 */ - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) - { - *(--txBlock) = gNfcip.cfg.did; /* DID */ - } - break; - - /*******************************************************************************/ - case NFCIP_CMD_DEP_REQ: - case NFCIP_CMD_DEP_RES: - - /* Compute optional PFB bits */ - if (gNfcip.cfg.did != RFAL_NFCDEP_DID_NO) { pfb |= NFCIP_PFB_DID_BIT; } - if (gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO) { pfb |= NFCIP_PFB_NAD_BIT; } - if ((gNfcip.isTxChaining) && (nfcip_PFBisIPDU(pfb)) ) { pfb |= NFCIP_PFB_MI_BIT; } - - /* Store PFB for future handling */ - gNfcip.lastPFB = pfb; /* store PFB sent */ - - if( !nfcip_PFBisSATN(pfb) ) - { - gNfcip.lastPFBnATN = pfb; /* store last PFB different then ATN */ - } - - - /* Add NAD if it is to be supported */ - if( gNfcip.cfg.nad != RFAL_NFCDEP_NAD_NO ) - { - *(--txBlock) = gNfcip.cfg.nad; /* NAD */ - } - - /* Digital 1.0 - 14.8.1.1 & 14.8.1.1 Only add DID if not 0 */ - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) - { - *(--txBlock) = gNfcip.cfg.did; /* DID */ - } - - *(--txBlock) = pfb; /* PFB */ - - - /* NCI 1.0 - Check if Empty frames are allowed */ - if( (paylLen == 0U) && nfcipIsEmptyDEPDisabled(gNfcip.cfg.oper) && nfcip_PFBisIPDU(pfb) ) - { - return ERR_PARAM; - } - break; - - /*******************************************************************************/ - default: - return ERR_PARAM; - } - - /*******************************************************************************/ - /* Prepend Header */ - /*******************************************************************************/ - *(--txBlock) = (uint8_t)cmd; /* CMD */ - *(--txBlock) = (uint8_t)( nfcipCmdIsReq(cmd) ? NFCIP_REQ : NFCIP_RES ); /* CMDType */ - - - txBufIt += paylLen + (uint16_t)((uint32_t)payloadBuf - (uint32_t)txBlock); /* Calculate overall buffer size */ - - - if( txBufIt > gNfcip.fsc ) /* Check if msg length violates the maximum payload size FSC */ - { - return ERR_NOTSUPP; - } - - /*******************************************************************************/ - return nfcipDataTx( txBlock, txBufIt, fwt ); -} - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - -/*******************************************************************************/ -static void nfcipConfig( const rfalNfcDepConfigs * cfg ) -{ - if (cfg == NULL) - { - return; - } - - ST_MEMCPY(&gNfcip.cfg, cfg, sizeof(rfalNfcDepConfigs)); /* Copy given config to local */ - - gNfcip.cfg.to = MIN( RFAL_NFCDEP_WT_TRG_MAX, gNfcip.cfg.to); /* Ensure proper WT value */ - gNfcip.cfg.did = nfcip_DIDMax( gNfcip.cfg.did ); /* Ensure proper DID value */ - gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); /* Calculate FSC based on given LR */ - - gNfcip.state = ( ( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) ? NFCIP_ST_TARG_WAIT_ATR : NFCIP_ST_INIT_IDLE ); -} - - -/*******************************************************************************/ -static ReturnCode nfcipRun( uint16_t *outActRxLen, bool *outIsChaining ) -{ - ReturnCode ret; - - ret = ERR_SYNTAX; - - nfcipLogD( " NFCIP Run() state: %d \r\n", gNfcip.state ); - - switch( gNfcip.state ) - { - /*******************************************************************************/ - case NFCIP_ST_IDLE: - case NFCIP_ST_INIT_DEP_IDLE: - case NFCIP_ST_TARG_DEP_IDLE: - case NFCIP_ST_TARG_DEP_SLEEP: - return ERR_NONE; - - /*******************************************************************************/ - case NFCIP_ST_INIT_DEP_TX: - - nfcipLogD( " NFCIP(I) Tx PNI: %d txLen: %d \r\n", gNfcip.pni, gNfcip.txBufLen ); - ret = nfcipTx( NFCIP_CMD_DEP_REQ, gNfcip.txBuf, &gNfcip.txBuf[gNfcip.txBufPaylPos], gNfcip.txBufLen, nfcip_PFBIPDU( gNfcip.pni ), (gNfcip.cfg.fwt + gNfcip.cfg.dFwt) ); - - switch( ret ) - { - case ERR_PARAM: - default: - gNfcip.state = NFCIP_ST_INIT_DEP_IDLE; - return ret; - - case ERR_NONE: - gNfcip.state = NFCIP_ST_INIT_DEP_RX; - break; - } - /* fall through */ - - /*******************************************************************************/ - case NFCIP_ST_INIT_DEP_RX: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - ret = nfcipDataRx( false ); - - if( ret != ERR_BUSY ) - { - ret = nfcipInitiatorHandleDEP( ret, *gNfcip.rxRcvdLen, outActRxLen, outIsChaining ); - } - - break; - - /*******************************************************************************/ - case NFCIP_ST_TARG_DEP_RTOX: - - if( !nfcipTimerisExpired( gNfcip.RTOXTimer ) ) /* Do nothing until RTOX timer has expired */ - { - return ERR_BUSY; - } - - /* If we cannot send a RTOX raise a Timeout error so that we do not - * hold the field On forever in AP2P */ - if( nfcipIsRTOXReqDisabled(gNfcip.cfg.oper) ) - { - /* We should reEnable Rx, and measure time between our field Off to - * either report link loss or recover #287 */ - nfcipLogI( " NFCIP(T) RTOX not sent due to config, NOT reenabling Rx \r\n" ); - return ERR_TIMEOUT; - } - - if( gNfcip.cntRTOXRetrys++ > NFCIP_MAX_RTOX_RETRYS ) /* Check maximum consecutive RTOX requests */ - { - return ERR_PROTO; - } - - nfcipLogI( " NFCIP(T) RTOX sent \r\n" ); - - gNfcip.lastRTOX = nfcip_RTOXTargMax(gNfcip.cfg.to); /* Calculate requested RTOX value, and send it */ - EXIT_ON_ERR( ret, nfcipDEPControlMsg( nfcip_PFBSPDU_TO(), gNfcip.lastRTOX ) ); - - /* Set waiting for RTOX Ack Flag */ - gNfcip.isWait4RTOX = true; - - gNfcip.state = NFCIP_ST_TARG_DEP_RX; /* Go back to Rx to process RTOX ack */ - return ERR_BUSY; - - /*******************************************************************************/ - case NFCIP_ST_TARG_DEP_TX: - - nfcipLogD( " NFCIP(T) Tx PNI: %d txLen: %d \r\n", gNfcip.pni, gNfcip.txBufLen ); - ret = nfcipTx( NFCIP_CMD_DEP_RES, gNfcip.txBuf, &gNfcip.txBuf[gNfcip.txBufPaylPos], gNfcip.txBufLen, nfcip_PFBIPDU( gNfcip.pni ), NFCIP_NO_FWT ); - - /* Clear flags */ - gNfcip.isTxPending = false; - gNfcip.isWait4RTOX = false; - - /* Digital 1.0 14.12.3.4 Increment the current PNI after Tx */ - gNfcip.pni = nfcip_PNIInc( gNfcip.pni ); - - switch( ret ) - { - case ERR_PARAM: - default: - gNfcip.state = NFCIP_ST_TARG_DEP_IDLE; /* Upon Tx error, goto IDLE state */ - return ret; - - case ERR_NONE: - gNfcip.state = NFCIP_ST_TARG_DEP_RX; /* All OK, goto Rx state */ - break; - } - /* fall through */ - - /*******************************************************************************/ - case NFCIP_ST_TARG_DEP_RX: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - if( gNfcip.isReqPending ) /* if already has Data should be from a DEP from nfcipTargetHandleActivation() */ - { - nfcipLogD( " NFCIP(T) Skipping Rx Using DEP from Activation \r\n" ); - - gNfcip.isReqPending = false; - ret = ERR_NONE; - } - else - { - ret = nfcipDataRx( false ); - } - - if( ret != ERR_BUSY ) - { - ret = nfcipTargetHandleRX( ret, outActRxLen, outIsChaining ); - } - - break; - - /*******************************************************************************/ - default: - /* MISRA 16.4: no empty default statement (a comment being enough) */ - break; - } - return ret; -} - - -/*******************************************************************************/ -void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc ) -{ - gNfcip.isDeactivating = pFunc; -} - - -/*******************************************************************************/ -void rfalNfcDepInitialize( void ) -{ - nfcipLogD( " NFCIP Ini() \r\n" ); - - gNfcip.state = NFCIP_ST_IDLE; - gNfcip.isDeactivating = NULL; - - gNfcip.isTxPending = false; - gNfcip.isWait4RTOX = false; - gNfcip.isReqPending = false; - - - gNfcip.cfg.oper = (RFAL_NFCDEP_OPER_FULL_MI_DIS | RFAL_NFCDEP_OPER_EMPTY_DEP_EN | RFAL_NFCDEP_OPER_ATN_EN | RFAL_NFCDEP_OPER_RTOX_REQ_EN); - - gNfcip.cfg.did = RFAL_NFCDEP_DID_NO; - gNfcip.cfg.nad = RFAL_NFCDEP_NAD_NO; - - gNfcip.cfg.br = RFAL_NFCDEP_Bx_NO_HIGH_BR; - gNfcip.cfg.bs = RFAL_NFCDEP_Bx_NO_HIGH_BR; - - gNfcip.cfg.lr = RFAL_NFCDEP_LR_254; - gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); - - gNfcip.cfg.gbLen = 0; - - gNfcip.cfg.fwt = RFAL_NFCDEP_MAX_FWT; - gNfcip.cfg.dFwt = RFAL_NFCDEP_MAX_FWT; - - gNfcip.pni = 0; - gNfcip.RTOXTimer = 0; - - nfcipClearCounters(); -} - - -/*******************************************************************************/ -static void nfcipSetDEPParams( rfalNfcDepDEPParams *DEPParams ) -{ - nfcipLogD( " NFCIP SetDEP() txLen: %d \r\n", DEPParams->txBufLen ); - - gNfcip.isTxChaining = DEPParams->txChaining; - gNfcip.txBuf = DEPParams->txBuf; - gNfcip.rxBuf = DEPParams->rxBuf; - gNfcip.txBufLen = DEPParams->txBufLen; - gNfcip.rxBufLen = DEPParams->rxBufLen; - gNfcip.txBufPaylPos = DEPParams->txBufPaylPos; - gNfcip.rxBufPaylPos = DEPParams->rxBufPaylPos; - - if( DEPParams->did != RFAL_NFCDEP_DID_KEEP ) - { - gNfcip.cfg.did = nfcip_DIDMax( DEPParams->did ); - } - - gNfcip.cfg.fwt = DEPParams->fwt; - gNfcip.cfg.dFwt = DEPParams->dFwt; - gNfcip.fsc = DEPParams->fsc; - - - - if(gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) - { - /* If there's any data to be sent go for Tx */ - if(DEPParams->txBufLen > 0U) - { - /* Ensure that an RTOX Ack is not being expected at moment */ - if( !gNfcip.isWait4RTOX ) - { - gNfcip.state = NFCIP_ST_TARG_DEP_TX; - return; - } - else - { - /* If RTOX Ack is expected, signal a pending Tx to be transmitted right after */ - gNfcip.isTxPending = true; - nfcipLogW( " NFCIP(T) Waiting RTOX, queueing outgoing DEP Block \r\n" ); - } - } - - /*Digital 1.0 14.12.4.1 In target mode the first PDU MUST be sent by the Initiator */ - gNfcip.state = NFCIP_ST_TARG_DEP_RX; - return; - } - - /* New data TxRx request clear previous error counters for consecutive TxRx without reseting communication/protocol layer*/ - nfcipClearCounters(); - - gNfcip.state = NFCIP_ST_INIT_DEP_TX; -} - - -/*******************************************************************************/ -bool rfalNfcDepTargetRcvdATR( void ) -{ - return ( (gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET) && nfcipIsTarget(gNfcip.state) && (gNfcip.state > NFCIP_ST_TARG_WAIT_ATR) ); -} - - -/*******************************************************************************/ -bool rfalNfcDepIsAtrReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 ) -{ - uint8_t msgIt; - - msgIt = 0; - - if ( (bufLen < RFAL_NFCDEP_ATRREQ_MIN_LEN) || (bufLen > RFAL_NFCDEP_ATRREQ_MAX_LEN) ) - { - return false; - } - - if ( buf[msgIt++] != NFCIP_REQ ) - { - return false; - } - - if( buf[msgIt++] != (uint8_t)NFCIP_CMD_ATR_REQ ) - { - return false; - } - - /* Output NFID3 if requested */ - if( nfcid3 != NULL ) - { - ST_MEMCPY( nfcid3, &buf[RFAL_NFCDEP_ATR_REQ_NFCID3_POS], RFAL_NFCDEP_NFCID3_LEN ); - } - - return true; -} - - -/*******************************************************************************/ -static ReturnCode nfcipTargetHandleActivation( rfalNfcDepDevice *nfcDepDev, uint8_t *outBRS ) -{ - ReturnCode ret; - uint8_t msgIt; - uint8_t txBuf[RFAL_NFCDEP_HEADER_PAD + NFCIP_PSLRES_LEN]; - - /*******************************************************************************/ - /* Check if we are in correct state */ - /*******************************************************************************/ - if( gNfcip.state != NFCIP_ST_TARG_WAIT_ACTV ) - { - return ERR_WRONG_STATE; - } - - - /*******************************************************************************/ - /* Check required parameters */ - /*******************************************************************************/ - if( outBRS == NULL ) - { - return ERR_PARAM; - } - - /*******************************************************************************/ - /* Wait and process incoming cmd (PSL / DEP) */ - /*******************************************************************************/ - ret = nfcipDataRx( false ); - - if( ret != ERR_NONE ) - { - return ret; - } - - msgIt = 0; - *outBRS = RFAL_NFCDEP_BRS_MAINTAIN; /* set out BRS to be maintained */ - - msgIt++; /* Skip LEN byte */ - - if ( gNfcip.rxBuf[msgIt++] != NFCIP_REQ ) - { - return ERR_PROTO; - } - - if( gNfcip.rxBuf[msgIt] == (uint8_t)NFCIP_CMD_PSL_REQ ) - { - msgIt++; - - if( gNfcip.rxBuf[msgIt++] != gNfcip.cfg.did ) /* Checking DID */ - { - return ERR_PROTO; - } - - nfcipLogI( " NFCIP(T) PSL REQ rcvd \r\n" ); - - *outBRS = gNfcip.rxBuf[msgIt++]; /* assign output BRS value */ - - /* Store FSL(LR) and update current config */ - gNfcip.cfg.lr = (gNfcip.rxBuf[msgIt++] & RFAL_NFCDEP_LR_VAL_MASK); - gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); - - /*******************************************************************************/ - /* Update NFC-DDE Device info */ - if( nfcDepDev != NULL ) - { - /* Update Bitrate info */ - /* PRQA S 4342 2 # MISRA 10.5 - Layout of enum rfalBitRate and definition of rfalNfcDepBRS2DSI guarantee no invalid enum values to be created */ - nfcDepDev->info.DSI = (rfalBitRate)rfalNfcDepBRS2DSI( *outBRS ); /* DSI codes the bit rate from Initiator to Target */ - nfcDepDev->info.DRI = (rfalBitRate)rfalNfcDepBRS2DRI( *outBRS ); /* DRI codes the bit rate from Target to Initiator */ - - /* Update Length Reduction and Frame Size */ - nfcDepDev->info.LR = gNfcip.cfg.lr; - nfcDepDev->info.FS = gNfcip.fsc; - - /* Update PPi byte */ - nfcDepDev->activation.Initiator.ATR_REQ.PPi &= ~RFAL_NFCDEP_PP_LR_MASK; - nfcDepDev->activation.Initiator.ATR_REQ.PPi |= rfalNfcDepLR2PP( gNfcip.cfg.lr ); - } - - EXIT_ON_ERR( ret, nfcipTx( NFCIP_CMD_PSL_RES, txBuf, NULL, 0, 0, NFCIP_NO_FWT ) ); - } - else - { - if( gNfcip.rxBuf[msgIt] == (uint8_t)NFCIP_CMD_DEP_REQ ) - { - msgIt++; - - /*******************************************************************************/ - /* Digital 1.0 14.12.3.1 PNI must be initialized to 0 */ - if( nfcip_PBF_PNI( gNfcip.rxBuf[msgIt] ) != 0U ) - { - return ERR_PROTO; - } - - /*******************************************************************************/ - /* Digital 1.0 14.8.2.1 check if DID is expected and match -> Protocol Error */ - if( nfcip_PFBhasDID( gNfcip.rxBuf[ msgIt] ) ) - { - if( gNfcip.rxBuf[++msgIt] != gNfcip.cfg.did ) - { - return ERR_PROTO; - } - } - else if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) /* DID expected but not rcv */ - { - return ERR_PROTO; - } - else - { - /* MISRA 15.7 - Empty else */ - } - } - - /* Signal Request pending to be digested on normal Handling (DEP_REQ, DSL_REQ, RLS_REQ) */ - gNfcip.isReqPending = true; - } - - gNfcip.state = NFCIP_ST_TARG_DEP_RX; - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepATR( const rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atrRes, uint8_t* atrResLen ) -{ - ReturnCode ret; - rfalNfcDepConfigs cfg; - uint16_t rxLen; - uint8_t msgIt; - uint8_t txBuf[RFAL_NFCDEP_ATRREQ_MAX_LEN]; - uint8_t rxBuf[NFCIP_ATRRES_BUF_LEN]; - - - if( (param == NULL) || (atrRes == NULL) || (atrResLen == NULL) ) - { - return ERR_PARAM; - } - - /*******************************************************************************/ - /* Configure NFC-DEP layer */ - /*******************************************************************************/ - - cfg.did = param->DID; - cfg.nad = param->NAD; - cfg.fwt = RFAL_NFCDEP_MAX_FWT; - cfg.dFwt = RFAL_NFCDEP_MAX_FWT; - cfg.br = param->BR; - cfg.bs = param->BS; - cfg.lr = param->LR; - cfg.to = RFAL_NFCDEP_WT_TRG_MAX; /* Not used in Initiator mode */ - - - cfg.gbLen = param->GBLen; - if( cfg.gbLen > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY( cfg.gb, param->GB, cfg.gbLen ); - } - - cfg.nfcidLen = param->nfcidLen; - if( cfg.nfcidLen > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY( cfg.nfcid, param->nfcid, cfg.nfcidLen ); - } - - cfg.role = RFAL_NFCDEP_ROLE_INITIATOR; - cfg.oper = param->operParam; - cfg.commMode = param->commMode; - - rfalNfcDepInitialize(); - nfcipConfig( &cfg ); - - /*******************************************************************************/ - /* Send ATR_REQ */ - /*******************************************************************************/ - - EXIT_ON_ERR( ret, nfcipTxRx(NFCIP_CMD_ATR_REQ, txBuf, nfcipRWTActivation(), NULL, 0, rxBuf, NFCIP_ATRRES_BUF_LEN, &rxLen ) ); - - - /*******************************************************************************/ - /* ATR sent, check response */ - /*******************************************************************************/ - msgIt = 0; - rxLen = ((uint16_t)rxBuf[msgIt++] - RFAL_NFCDEP_LEN_LEN); /* use LEN byte */ - - if( (rxLen < RFAL_NFCDEP_ATRRES_MIN_LEN) || (rxLen > RFAL_NFCDEP_ATRRES_MAX_LEN) ) /* Checking length: ATR_RES */ - { - return ERR_PROTO; - } - - if( rxBuf[msgIt++] != NFCIP_RES ) /* Checking if is a response*/ - { - return ERR_PROTO; - } - - if( rxBuf[msgIt++] != (uint8_t)NFCIP_CMD_ATR_RES ) /* Checking if is a ATR RES */ - { - return ERR_PROTO; - } - - ST_MEMCPY( (uint8_t*)atrRes, (rxBuf + RFAL_NFCDEP_LEN_LEN), rxLen ); - *atrResLen = (uint8_t)rxLen; - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL ) -{ - ReturnCode ret; - uint16_t rxLen; - uint8_t msgIt; - uint8_t txBuf[NFCIP_PSLREQ_LEN + NFCIP_PSLPAY_LEN]; - uint8_t rxBuf[NFCIP_PSLRES_LEN]; - - msgIt = NFCIP_PSLREQ_LEN; - - txBuf[msgIt++] = BRS; - txBuf[msgIt++] = FSL; - - /*******************************************************************************/ - /* Send PSL REQ and wait for response */ - /*******************************************************************************/ - EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_PSL_REQ, txBuf, nfcipRWTActivation(), &txBuf[NFCIP_PSLREQ_LEN], (msgIt - NFCIP_PSLREQ_LEN), rxBuf, NFCIP_PSLRES_LEN, &rxLen ) ); - - - /*******************************************************************************/ - /* PSL sent, check response */ - /*******************************************************************************/ - msgIt = 0; - rxLen = (uint16_t)(rxBuf[msgIt++]); /* use LEN byte */ - - if( rxLen < NFCIP_PSLRES_LEN ) /* Checking length: LEN + RLS_RES */ - { - return ERR_PROTO; - } - - if( rxBuf[msgIt++] != NFCIP_RES ) /* Checking if is a response */ - { - return ERR_PROTO; - } - - if( rxBuf[msgIt++] != (uint8_t)NFCIP_CMD_PSL_RES ) /* Checking if is a PSL RES */ - { - return ERR_PROTO; - } - - if( rxBuf[msgIt++] != gNfcip.cfg.did ) /* Checking DID */ - { - return ERR_PROTO; - } - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepDSL( void ) -{ - ReturnCode ret; - uint8_t txBuf[ RFAL_NFCDEP_HEADER_PAD + NFCIP_DSLREQ_LEN]; - uint8_t rxBuf[NFCIP_DSLRES_LEN]; - uint8_t rxMsgIt; - uint16_t rxLen = 0; - - if( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET ) - { - return ERR_NONE; /* Target has no deselect procedure */ - } - - /* Repeating a DSL REQ is optional, not doing it */ - EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_DSL_REQ, txBuf, nfcipRWTActivation(), NULL, 0, rxBuf, RFAL_NFCDEP_ATRRES_MAX_LEN, &rxLen ) ); - - /*******************************************************************************/ - rxMsgIt = 0; - - if( rxBuf[rxMsgIt++] < NFCIP_DSLRES_MIN ) /* Checking length: LEN + DSL_RES */ - { - return ERR_PROTO; - } - - if( rxBuf[rxMsgIt++] != NFCIP_RES ) /* Checking if is a response */ - { - return ERR_PROTO; - } - - if( rxBuf[rxMsgIt++] != (uint8_t)NFCIP_CMD_DSL_RES ) /* Checking if is DSL RES */ - { - return ERR_PROTO; - } - - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) - { - if ( rxBuf[rxMsgIt++] != gNfcip.cfg.did ) - { - return ERR_PROTO; - } - } - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepRLS( void ) -{ - ReturnCode ret; - uint8_t txBuf[RFAL_NFCDEP_HEADER_PAD + NFCIP_RLSREQ_LEN]; - uint8_t rxBuf[NFCIP_RLSRES_LEN]; - uint8_t rxMsgIt; - uint16_t rxLen = 0; - - if ( gNfcip.cfg.role == RFAL_NFCDEP_ROLE_TARGET ) /* Target has no release procedure */ - { - return ERR_NONE; - } - - /* Repeating a RLS REQ is optional, not doing it */ - EXIT_ON_ERR( ret, nfcipTxRx( NFCIP_CMD_RLS_REQ, txBuf, nfcipRWTActivation(), NULL, 0, rxBuf, RFAL_NFCDEP_ATRRES_MAX_LEN, &rxLen ) ); - - /*******************************************************************************/ - rxMsgIt = 0; - - if( rxBuf[rxMsgIt++] < NFCIP_RLSRES_MIN ) /* Checking length: LEN + RLS_RES */ - { - return ERR_PROTO; - } - - if( rxBuf[rxMsgIt++] != NFCIP_RES ) /* Checking if is a response */ - { - return ERR_PROTO; - } - - if( rxBuf[rxMsgIt++] != (uint8_t)NFCIP_CMD_RLS_RES ) /* Checking if is RLS RES */ - { - return ERR_PROTO; - } - - if( gNfcip.cfg.did != RFAL_NFCDEP_DID_NO ) - { - if ( rxBuf[rxMsgIt++] != gNfcip.cfg.did ) - { - return ERR_PROTO; - } - } - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalBitRate desiredBR, rfalNfcDepDevice* nfcDepDev ) -{ - ReturnCode ret; - uint8_t maxRetyrs; - uint8_t PSL_BRS; - uint8_t PSL_FSL; - bool sendPSL; - - if( (param == NULL) || (nfcDepDev == NULL) ) - { - return ERR_PARAM; - } - - param->NAD = RFAL_NFCDEP_NAD_NO; /* Digital 1.1 16.6.2.9 Initiator SHALL NOT use NAD */ - maxRetyrs = NFCIP_ATR_RETRY_MAX; - - /*******************************************************************************/ - /* Send ATR REQ and wait for response */ - /*******************************************************************************/ - do{ /* Upon transmission error ATR REQ should be retried */ - - ret = rfalNfcDepATR( param, &nfcDepDev->activation.Target.ATR_RES, &nfcDepDev->activation.Target.ATR_RESLen ); - - if( nfcipIsTransmissionError(ret) ) - { - continue; - } - break; - } - while( (maxRetyrs--) != 0U ); - - if( ret != ERR_NONE ) - { - return ret; - } - - /*******************************************************************************/ - /* Compute NFC-DEP device with ATR_RES */ - /*******************************************************************************/ - nfcDepDev->info.GBLen = (nfcDepDev->activation.Target.ATR_RESLen - RFAL_NFCDEP_ATRRES_MIN_LEN); - nfcDepDev->info.DID = nfcDepDev->activation.Target.ATR_RES.DID; - nfcDepDev->info.NAD = RFAL_NFCDEP_NAD_NO; /* Digital 1.1 16.6.3.11 Initiator SHALL ignore b1 of PPt */ - nfcDepDev->info.LR = rfalNfcDepPP2LR( nfcDepDev->activation.Target.ATR_RES.PPt ); - nfcDepDev->info.FS = rfalNfcDepLR2FS( nfcDepDev->info.LR ); - nfcDepDev->info.WT = (nfcDepDev->activation.Target.ATR_RES.TO & RFAL_NFCDEP_WT_MASK); - nfcDepDev->info.FWT = rfalNfcDepCalculateRWT( nfcDepDev->info.WT ); - nfcDepDev->info.dFWT = RFAL_NFCDEP_WT_DELTA; - - rfalGetBitRate( &nfcDepDev->info.DSI, &nfcDepDev->info.DRI ); - - - - /*******************************************************************************/ - /* Check if a PSL needs to be sent */ - /*******************************************************************************/ - sendPSL = false; - PSL_BRS = rfalNfcDepDx2BRS( nfcDepDev->info.DSI ); /* Set current bit rate divisor on both directions */ - PSL_FSL = nfcDepDev->info.LR; /* Set current Frame Size */ - - - - /* Activity 1.0 9.4.4.15 & 9.4.6.3 NFC-DEP Activation PSL - * Activity 2.0 9.4.4.17 & 9.4.6.6 NFC-DEP Activation PSL - * - * PSL_REQ shall only be sent if desired bit rate is different from current (Activity 1.0) - * PSL_REQ shall be sent to update LR or bit rate (Activity 2.0) - * */ - -#if 0 /* PSL due to LR is disabled, can be enabled if desired*/ - /*******************************************************************************/ - /* Check Frame Size */ - /*******************************************************************************/ - if( gNfcip.cfg.lr < nfcDepDev->info.LR ) /* If our Length reduction is smaller */ - { - sendPSL = true; - - nfcDepDev->info.LR = MIN( nfcDepDev->info.LR, gNfcip.cfg.lr ); - - gNfcip.cfg.lr = nfcDepDev->info.LR; /* Update nfcip LR to be used */ - gNfcip.fsc = rfalNfcDepLR2FS( gNfcip.cfg.lr ); /* Update nfcip FSC to be used */ - - PSL_FSL = gNfcip.cfg.lr; /* Set LR to be sent */ - - nfcipLogI( " NFCIP(I) Frame Size differ, PSL new fsc: %d \r\n", gNfcip.fsc ); - } -#endif - - - /*******************************************************************************/ - /* Check Baud rates */ - /*******************************************************************************/ - if( nfcDepDev->info.DSI != desiredBR ) /* if desired BR is different */ - { - /* || (target->brt != RFAL_NFCDEP_Bx_NO_HIGH_BR) || (target->bst != RFAL_NFCDEP_Bx_NO_HIGH_BR) */ /* if target supports higher BR, must send PSL? */ - if( nfcipDxIsSupported( (uint8_t)desiredBR, nfcDepDev->activation.Target.ATR_RES.BRt, nfcDepDev->activation.Target.ATR_RES.BSt ) ) /* if desired BR is supported */ /* MISRA 13.5 */ - { - sendPSL = true; - PSL_BRS = rfalNfcDepDx2BRS( desiredBR ); - - nfcipLogI( " NFCIP(I) BR differ, PSL BR: 0x%02X \r\n", PSL_BRS ); - } - } - - - /*******************************************************************************/ - if( sendPSL ) - { - /*******************************************************************************/ - /* Send PSL REQ and wait for response */ - /*******************************************************************************/ - EXIT_ON_ERR( ret, rfalNfcDepPSL(PSL_BRS, PSL_FSL) ); - - /* Check if bit rate has been changed */ - if( nfcDepDev->info.DSI != desiredBR ) - { - /* Check if device was in Passive NFC-A and went to higher bit rates, use NFC-F */ - if( (nfcDepDev->info.DSI == RFAL_BR_106) && (gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_PASSIVE) ) - { - - #if RFAL_FEATURE_NFCF - /* If Passive initialize NFC-F module */ - rfalNfcfPollerInitialize( desiredBR ); - #else /* RFAL_FEATURE_NFCF */ - return ERR_NOTSUPP; - #endif /* RFAL_FEATURE_NFCF */ - - } - - nfcDepDev->info.DRI = desiredBR; /* DSI Bit Rate coding from Initiator to Target */ - nfcDepDev->info.DSI = desiredBR; /* DRI Bit Rate coding from Target to Initiator */ - - rfalSetBitRate( nfcDepDev->info.DSI, nfcDepDev->info.DRI ); - } - - - return ERR_NONE; /* PSL has been sent */ - } - - return ERR_NONE; /* No PSL has been sent */ -} - - -/*******************************************************************************/ -uint32_t rfalNfcDepCalculateRWT( uint8_t wt ) -{ - /* Digital 1.0 14.6.3.8 & Digital 1.1 16.6.3.9 */ - /* Digital 1.1 16.6.3.9 treat all RFU values as WT=14 */ - uint8_t responseWaitTime = MIN( RFAL_NFCDEP_WT_INI_MAX, wt ); - - return (uint32_t)rfalNfcDepWT2RWT(responseWaitTime); -} - - - -/*******************************************************************************/ -static ReturnCode nfcipDataTx( uint8_t* txBuf, uint16_t txBufLen, uint32_t fwt ) -{ - return rfalTransceiveBlockingTx( txBuf, txBufLen, gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen, (RFAL_TXRX_FLAGS_DEFAULT | (uint32_t)RFAL_TXRX_FLAGS_NFCIP1_ON), ((fwt == NFCIP_NO_FWT) ? RFAL_FWT_NONE : fwt) ); -} - - -/*******************************************************************************/ -static ReturnCode nfcipDataRx( bool blocking ) -{ - ReturnCode ret; - - /* Perform Rx either blocking or non-blocking */ - if( blocking ) - { - ret = rfalTransceiveBlockingRx(); - } - else - { - ret = rfalGetTransceiveStatus(); - } - - if( ret != ERR_BUSY ) - { - if( gNfcip.rxRcvdLen != NULL ) - { - (*gNfcip.rxRcvdLen) = rfalConvBitsToBytes( *gNfcip.rxRcvdLen ); - - if( (ret == ERR_NONE) && (gNfcip.rxBuf != NULL) ) - { - /* Digital 1.1 16.4.1.3 - Length byte LEN SHALL have a value between 3 and 255 -> otherwise treat as Transmission Error * - * - Ensure that actual received and frame length do match, otherwise treat as Transmission error */ - if( (*gNfcip.rxRcvdLen != (uint16_t)*gNfcip.rxBuf) || (*gNfcip.rxRcvdLen < RFAL_NFCDEP_LEN_MIN) || (*gNfcip.rxRcvdLen > RFAL_NFCDEP_LEN_MAX) ) - { - return ERR_FRAMING; - } - } - } - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, const uint8_t *atrReq, uint16_t atrReqLength, rfalNfcDepListenActvParam rxParam ) -{ - ReturnCode ret; - rfalNfcDepConfigs cfg; - - - if( (param == NULL) || (atrReq == NULL) || (rxParam.rxLen == NULL) ) - { - return ERR_PARAM; - } - - - /*******************************************************************************/ - /* Check whether is a valid ATR_REQ Compute NFC-DEP device */ - if( !rfalNfcDepIsAtrReq( atrReq, atrReqLength, NULL ) ) - { - return ERR_PARAM; - } - - rxParam.nfcDepDev->activation.Initiator.ATR_REQLen = (uint8_t)atrReqLength; /* nfcipIsAtrReq() is already checking Min and Max buffer lengths */ - if( atrReqLength > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY( (uint8_t*)&rxParam.nfcDepDev->activation.Initiator.ATR_REQ, atrReq, atrReqLength ); - } - - rxParam.nfcDepDev->info.GBLen = (uint8_t)(atrReqLength - RFAL_NFCDEP_ATRREQ_MIN_LEN); - rxParam.nfcDepDev->info.DID = rxParam.nfcDepDev->activation.Initiator.ATR_REQ.DID; - rxParam.nfcDepDev->info.NAD = RFAL_NFCDEP_NAD_NO; /* Digital 1.1 16.6.2.9 Initiator SHALL NOT use NAD */ - rxParam.nfcDepDev->info.LR = rfalNfcDepPP2LR( rxParam.nfcDepDev->activation.Initiator.ATR_REQ.PPi ); - rxParam.nfcDepDev->info.FS = rfalNfcDepLR2FS( rxParam.nfcDepDev->info.LR ); - rxParam.nfcDepDev->info.WT = 0; - rxParam.nfcDepDev->info.FWT = NFCIP_NO_FWT; - rxParam.nfcDepDev->info.dFWT = NFCIP_NO_FWT; - - rfalGetBitRate( &rxParam.nfcDepDev->info.DSI, &rxParam.nfcDepDev->info.DRI ); - - - /* Store Device Info location, updated upon a PSL */ - gNfcip.nfcDepDev = rxParam.nfcDepDev; - - - /*******************************************************************************/ - cfg.did = rxParam.nfcDepDev->activation.Initiator.ATR_REQ.DID; - cfg.nad = RFAL_NFCDEP_NAD_NO; - - cfg.fwt = RFAL_NFCDEP_MAX_FWT; - cfg.dFwt = RFAL_NFCDEP_MAX_FWT; - - cfg.br = param->brt; - cfg.bs = param->bst; - - cfg.lr = rfalNfcDepPP2LR(param->ppt); - - cfg.gbLen = param->GBtLen; - if( cfg.gbLen > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY(cfg.gb, param->GBt, cfg.gbLen); - } - - cfg.nfcidLen = RFAL_NFCDEP_NFCID3_LEN; - ST_MEMCPY(cfg.nfcid, param->nfcid3, RFAL_NFCDEP_NFCID3_LEN); - - cfg.to = param->to; - - cfg.role = RFAL_NFCDEP_ROLE_TARGET; - cfg.oper = param->operParam; - cfg.commMode = param->commMode; - - rfalNfcDepInitialize(); - nfcipConfig( &cfg ); - - - /*******************************************************************************/ - /* Reply with ATR RES to Initiator */ - /*******************************************************************************/ - gNfcip.rxBuf = (uint8_t*)rxParam.rxBuf; - gNfcip.rxBufLen = sizeof(rfalNfcDepBufFormat); - gNfcip.rxRcvdLen = rxParam.rxLen; - gNfcip.rxBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN; - gNfcip.isChaining = rxParam.isRxChaining; - gNfcip.txBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN; - - EXIT_ON_ERR( ret, nfcipTx( NFCIP_CMD_ATR_RES, (uint8_t*) gNfcip.rxBuf, NULL, 0, 0, NFCIP_NO_FWT ) ); - - gNfcip.state = NFCIP_ST_TARG_WAIT_ACTV; - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepListenGetActivationStatus( void ) -{ - ReturnCode err; - uint8_t BRS; - - BRS = RFAL_NFCDEP_BRS_MAINTAIN; - - err = nfcipTargetHandleActivation( gNfcip.nfcDepDev, &BRS ); - - switch (err) - { - case ERR_NONE: - - if( BRS != RFAL_NFCDEP_BRS_MAINTAIN ) - { - /* DSI codes the bit rate from Initiator to Target */ - /* DRI codes the bit rate from Target to Initiator */ - - if( gNfcip.cfg.commMode == RFAL_NFCDEP_COMM_ACTIVE ) - { - EXIT_ON_ERR( err, rfalSetMode( RFAL_MODE_LISTEN_ACTIVE_P2P, gNfcip.nfcDepDev->info.DRI, gNfcip.nfcDepDev->info.DSI )); - } - else - { - EXIT_ON_ERR( err, rfalSetMode( ((RFAL_BR_106 == gNfcip.nfcDepDev->info.DRI) ? RFAL_MODE_LISTEN_NFCA : RFAL_MODE_LISTEN_NFCF), gNfcip.nfcDepDev->info.DRI, gNfcip.nfcDepDev->info.DSI )); - } - } - break; - - case ERR_BUSY: - // do nothing - break; - - case ERR_PROTO: - default: - // re-enable receiving of data - nfcDepReEnableRx( gNfcip.rxBuf, gNfcip.rxBufLen, gNfcip.rxRcvdLen ); - break; - } // if (no err) - - return err; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepStartTransceive( rfalNfcDepTxRxParam *param ) -{ - rfalNfcDepDEPParams nfcDepParams; - - nfcDepParams.txBuf = (uint8_t *)param->txBuf; - nfcDepParams.txBufLen = param->txBufLen; - nfcDepParams.txChaining = param->isTxChaining; - nfcDepParams.txBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN; /* position in txBuf where actual outgoing data is located */ - nfcDepParams.did = RFAL_NFCDEP_DID_KEEP; - nfcDepParams.rxBufPaylPos = RFAL_NFCDEP_DEPREQ_HEADER_LEN; - nfcDepParams.rxBuf = (uint8_t *)param->rxBuf; - nfcDepParams.rxBufLen = sizeof(rfalNfcDepBufFormat); - nfcDepParams.fsc = param->FSx; - nfcDepParams.fwt = param->FWT; - nfcDepParams.dFwt = param->dFWT; - - gNfcip.rxRcvdLen = param->rxLen; - gNfcip.isChaining = param->isRxChaining; - - nfcipSetDEPParams(&nfcDepParams); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcDepGetTransceiveStatus( void ) -{ - return nfcipRun( gNfcip.rxRcvdLen, gNfcip.isChaining ); -} - -#endif /* RFAL_FEATURE_NFC_DEP */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_nfca.c b/Software/Middlewares/ST/rfal/Src/rfal_nfca.c deleted file mode 100644 index 03cb2e9..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_nfca.c +++ /dev/null @@ -1,630 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfca.c - * - * \author Gustavo Patricio - * - * \brief Provides several NFC-A convenience methods and definitions - * - * It provides a Poller (ISO14443A PCD) interface and as well as - * some NFC-A Listener (ISO14443A PICC) helpers. - * - * The definitions and helpers methods provided by this module are only - * up to ISO14443-3 layer - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_nfca.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_NFCA - #define RFAL_FEATURE_NFCA false /* NFC-A module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_NFCA - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_NFCA_SLP_FWT rfalConvMsTo1fc(1) /*!< Check 1ms for any modulation ISO14443-3 6.4.3 */ -#define RFAL_NFCA_SLP_CMD 0x50U /*!< SLP cmd (byte1) Digital 1.1 6.9.1 & Table 20 */ -#define RFAL_NFCA_SLP_BYTE2 0x00U /*!< SLP byte2 Digital 1.1 6.9.1 & Table 20 */ -#define RFAL_NFCA_SLP_CMD_POS 0U /*!< SLP cmd position Digital 1.1 6.9.1 & Table 20 */ -#define RFAL_NFCA_SLP_BYTE2_POS 1U /*!< SLP byte2 position Digital 1.1 6.9.1 & Table 20 */ - -#define RFAL_NFCA_SDD_CT 0x88U /*!< Cascade Tag value Digital 1.1 6.7.2 */ -#define RFAL_NFCA_SDD_CT_LEN 1U /*!< Cascade Tag length */ - -#define RFAL_NFCA_SLP_REQ_LEN 2U /*!< SLP_REQ length */ - -#define RFAL_NFCA_SEL_CMD_LEN 1U /*!< SEL_CMD length */ -#define RFAL_NFCA_SEL_PAR_LEN 1U /*!< SEL_PAR length */ -#define RFAL_NFCA_SEL_SELPAR rfalNfcaSelPar(7U, 0U)/*!< SEL_PAR on Select is always with 4 data/nfcid */ -#define RFAL_NFCA_BCC_LEN 1U /*!< BCC length */ - -#define RFAL_NFCA_SDD_REQ_LEN (RFAL_NFCA_SEL_CMD_LEN + RFAL_NFCA_SEL_PAR_LEN) /*!< SDD_REQ length */ -#define RFAL_NFCA_SDD_RES_LEN (RFAL_NFCA_CASCADE_1_UID_LEN + RFAL_NFCA_BCC_LEN) /*!< SDD_RES length */ - -#define RFAL_NFCA_T_RETRANS 5U /*!< t RETRANSMISSION [3, 33]ms EMVCo 2.6 A.5 */ -#define RFAL_NFCA_N_RETRANS 2U /*!< Number of retries EMVCo 2.6 9.6.1.3 */ - - -/*! SDD_REQ (Select) Cascade Levels */ -enum -{ - RFAL_NFCA_SEL_CASCADE_L1 = 0, /*!< SDD_REQ Cascade Level 1 */ - RFAL_NFCA_SEL_CASCADE_L2 = 1, /*!< SDD_REQ Cascade Level 2 */ - RFAL_NFCA_SEL_CASCADE_L3 = 2 /*!< SDD_REQ Cascade Level 3 */ -}; - -/*! SDD_REQ (Select) request Cascade Level command Digital 1.1 Table 15 */ -enum -{ - RFAL_NFCA_CMD_SEL_CL1 = 0x93, /*!< SDD_REQ command Cascade Level 1 */ - RFAL_NFCA_CMD_SEL_CL2 = 0x95, /*!< SDD_REQ command Cascade Level 2 */ - RFAL_NFCA_CMD_SEL_CL3 = 0x97, /*!< SDD_REQ command Cascade Level 3 */ -}; - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ -#define rfalNfcaSelPar( nBy, nbi ) (uint8_t)((((nBy)<<4U) & 0xF0U) | ((nbi)&0x0FU) ) /*!< Calculates SEL_PAR with the bytes/bits to be sent */ -#define rfalNfcaCLn2SELCMD( cl ) (uint8_t)((uint8_t)(RFAL_NFCA_CMD_SEL_CL1) + (2U*(cl))) /*!< Calculates SEL_CMD with the given cascade level */ -#define rfalNfcaNfcidLen2CL( len ) ((len) / 5U) /*!< Calculates cascade level by the NFCID length */ - -/*! Executes the given Tx method (f) and if a Timeout error is detected it retries (rt) times performing a delay of (dl) in between */ -#define rfalNfcaTxRetry( r, f, rt, dl ) \ - { \ - uint8_t rts = (uint8_t)(rt); \ - do { \ - (r)=(f); \ - if (((rt)!=0U) && ((dl)!=0U)) { \ - platformDelay(dl); \ - } \ - } while( ((rts--) != 0U) && ((r)==ERR_TIMEOUT) ); \ - } - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! SLP_REQ (HLTA) format Digital 1.1 6.9.1 & Table 20 */ -typedef struct -{ - uint8_t frame[RFAL_NFCA_SLP_REQ_LEN]; /*!< SLP: 0x50 0x00 */ -} rfalNfcaSlpReq; - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -static uint8_t rfalNfcaCalculateBcc( const uint8_t* buf, uint8_t bufLen ); - - -/* - ****************************************************************************** - * LOCAL FUNCTIONS - ****************************************************************************** - */ - -static uint8_t rfalNfcaCalculateBcc( const uint8_t* buf, uint8_t bufLen ) -{ - uint8_t i; - uint8_t BCC; - - BCC = 0; - - /* BCC is XOR over first 4 bytes of the SDD_RES Digital 1.1 6.7.2 */ - for(i = 0; i < bufLen; i++) - { - BCC ^= buf[i]; - } - - return BCC; -} - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -ReturnCode rfalNfcaPollerInitialize( void ) -{ - ReturnCode ret; - - EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCA, RFAL_BR_106, RFAL_BR_106 ) ); - rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); - - rfalSetGT( RFAL_GT_NFCA ); - rfalSetFDTListen( RFAL_FDT_LISTEN_NFCA_POLLER ); - rfalSetFDTPoll( RFAL_FDT_POLL_NFCA_POLLER ); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcaPollerCheckPresence( rfal14443AShortFrameCmd cmd, rfalNfcaSensRes *sensRes ) -{ - ReturnCode ret; - uint16_t rcvLen; - - /* Digital 1.1 6.10.1.3 For Commands ALL_REQ, SENS_REQ, SDD_REQ, and SEL_REQ, the NFC Forum Device * - * MUST treat receipt of a Listen Frame at a time after FDT(Listen, min) as a Timeour Error */ - - ret = rfalISO14443ATransceiveShortFrame( cmd, (uint8_t*)sensRes, (uint8_t)rfalConvBytesToBits(sizeof(rfalNfcaSensRes)), &rcvLen, RFAL_NFCA_FDTMIN ); - if( (ret == ERR_RF_COLLISION) || (ret == ERR_CRC) || (ret == ERR_NOMEM) || (ret == ERR_FRAMING) || (ret == ERR_PAR) ) - { - ret = ERR_NONE; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcaPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes ) -{ - ReturnCode ret; - - EXIT_ON_ERR( ret, rfalNfcaPollerCheckPresence( ((compMode == RFAL_COMPLIANCE_MODE_EMV) ? RFAL_14443A_SHORTFRAME_CMD_WUPA : RFAL_14443A_SHORTFRAME_CMD_REQA), sensRes ) ); - - /* Send SLP_REQ as Activity 1.1 9.2.3.6 and EMVCo 2.6 9.2.1.3 */ - if( compMode != RFAL_COMPLIANCE_MODE_ISO) - { - rfalNfcaPollerSleep(); - } - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcaPollerSingleCollisionResolution( uint8_t devLimit, bool *collPending, rfalNfcaSelRes *selRes, uint8_t *nfcId1, uint8_t *nfcId1Len ) -{ - uint8_t i; - ReturnCode ret; - rfalNfcaSelReq selReq; - uint16_t bytesRx; - uint8_t bytesTxRx; - uint8_t bitsTxRx; - bool doBacktrack = false; - uint8_t backtrackCnt = 3; - - /* Check parameters */ - if( (collPending == NULL) || (selRes == NULL) || (nfcId1 == NULL) || (nfcId1Len == NULL) ) - { - return ERR_PARAM; - } - - /* Initialize output parameters */ - *collPending = false; /* Activity 1.1 9.3.4.6 */ - *nfcId1Len = 0; - ST_MEMSET( nfcId1, 0x00, RFAL_NFCA_CASCADE_3_UID_LEN ); - - /*******************************************************************************/ - /* Go through all Cascade Levels Activity 1.1 9.3.4 */ - for( i = (uint8_t)RFAL_NFCA_SEL_CASCADE_L1; i <= (uint8_t)RFAL_NFCA_SEL_CASCADE_L3; i++) - { - /* Initialize the SDD_REQ to send for the new cascade level */ - ST_MEMSET( (uint8_t*)&selReq, 0x00, sizeof(rfalNfcaSelReq) ); - selReq.selCmd = rfalNfcaCLn2SELCMD(i); - - bytesTxRx = RFAL_NFCA_SDD_REQ_LEN; - bitsTxRx = 0; - - /*******************************************************************************/ - /* Go through Collision loop */ - do - { - uint8_t collBit = 1; /* standards mandate or recommend collision bit to be set to One. */ - /* Calculate SEL_PAR with the bytes/bits to be sent */ - selReq.selPar = rfalNfcaSelPar(bytesTxRx, bitsTxRx); - - /* Send SDD_REQ (Anticollision frame) - Retry upon timeout EMVCo 2.6 9.6.1.3 */ - rfalNfcaTxRetry( ret, rfalISO14443ATransceiveAnticollisionFrame( (uint8_t*)&selReq, &bytesTxRx, &bitsTxRx, &bytesRx, RFAL_NFCA_FDTMIN ), ((devLimit==0U)?RFAL_NFCA_N_RETRANS:0U), RFAL_NFCA_T_RETRANS ); - - bytesRx = rfalConvBitsToBytes(bytesRx); - - if ((ret == ERR_TIMEOUT) - && (backtrackCnt != 0U) && !doBacktrack - && !((RFAL_NFCA_SDD_REQ_LEN==bytesTxRx) && (0U==bitsTxRx))) - { - /* In multiple card scenarios it may always happen that some - * collisions of a weaker tag go unnoticed. If then a later - * collision is recognized and the strong tag has a 0 at the - * collision position then no tag will respond. Catch this - * corner case and then try with the bit being sent as zero. */ - rfalNfcaSensRes sensRes; - ret = ERR_RF_COLLISION; - rfalNfcaPollerCheckPresence( RFAL_14443A_SHORTFRAME_CMD_REQA, &sensRes ); - /* Algorithm below does a post-increment, decrement to go back to current position */ - if (0U == bitsTxRx) - { - bitsTxRx = 7; - bytesTxRx--; - } - else - { - bitsTxRx--; - } - collBit = (uint8_t)( ((uint8_t*)&selReq)[bytesTxRx] & (1U << bitsTxRx) ); - collBit = (uint8_t)((0U==collBit)?1U:0U); // invert the collision bit - doBacktrack = true; - backtrackCnt--; - } - else - { - doBacktrack = false; - } - - if( ret == ERR_RF_COLLISION ) - { - /* Check received length */ - if( (bytesTxRx + ((bitsTxRx != 0U) ? 1U : 0U)) > (RFAL_NFCA_SDD_RES_LEN + RFAL_NFCA_SDD_REQ_LEN) ) - { - return ERR_PROTO; - } - - if( ((bytesTxRx + ((bitsTxRx != 0U) ? 1U : 0U)) > (RFAL_NFCA_CASCADE_1_UID_LEN + RFAL_NFCA_SDD_REQ_LEN)) && (backtrackCnt != 0U) ) - { /* Collision in BCC: Anticollide only UID part */ - backtrackCnt--; - bytesTxRx = RFAL_NFCA_CASCADE_1_UID_LEN + RFAL_NFCA_SDD_REQ_LEN - 1U; - bitsTxRx = 7; - collBit = (uint8_t)( ((uint8_t*)&selReq)[bytesTxRx] & (1U << bitsTxRx) ); /* Not a real collision, extract the actual bit for the subsequent code */ - } - - if( (devLimit == 0U) && !(*collPending) ) - { - /* Activity 1.0 & 1.1 9.3.4.12: If CON_DEVICES_LIMIT has a value of 0, then - * NFC Forum Device is configured to perform collision detection only */ - *collPending = true; - return ERR_IGNORE; - } - - *collPending = true; - - /* Set and select the collision bit, with the number of bytes/bits successfully TxRx */ - if (collBit != 0U) - { - ((uint8_t*)&selReq)[bytesTxRx] = (uint8_t)(((uint8_t*)&selReq)[bytesTxRx] | (1U << bitsTxRx)); /* MISRA 10.3 */ - } - else - { - ((uint8_t*)&selReq)[bytesTxRx] = (uint8_t)(((uint8_t*)&selReq)[bytesTxRx] & ~(1U << bitsTxRx)); /* MISRA 10.3 */ - } - - bitsTxRx++; - - /* Check if number of bits form a byte */ - if( bitsTxRx == RFAL_BITS_IN_BYTE ) - { - bitsTxRx = 0; - bytesTxRx++; - } - } - }while (ret == ERR_RF_COLLISION); - - - /*******************************************************************************/ - /* Check if Collision loop has failed */ - if( ret != ERR_NONE ) - { - return ret; - } - - - /* If collisions are to be reported check whether the response is complete */ - if( (devLimit == 0U) && (bytesRx != sizeof(rfalNfcaSddRes)) ) - { - return ERR_PROTO; - } - - /* Check if the received BCC match */ - if( selReq.bcc != rfalNfcaCalculateBcc( selReq.nfcid1, RFAL_NFCA_CASCADE_1_UID_LEN ) ) - { - return ERR_PROTO; - } - - /*******************************************************************************/ - /* Anticollision OK, Select this Cascade Level */ - selReq.selPar = RFAL_NFCA_SEL_SELPAR; - - /* Send SEL_REQ (Select command) - Retry upon timeout EMVCo 2.6 9.6.1.3 */ - rfalNfcaTxRetry( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&selReq, sizeof(rfalNfcaSelReq), (uint8_t*)selRes, sizeof(rfalNfcaSelRes), &bytesRx, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCA_FDTMIN ), ((devLimit==0U)?RFAL_NFCA_N_RETRANS:0U), RFAL_NFCA_T_RETRANS ); - - if( ret != ERR_NONE ) - { - return ret; - } - - - /* Ensure proper response length */ - if( bytesRx != sizeof(rfalNfcaSelRes) ) - { - return ERR_PROTO; - } - - /*******************************************************************************/ - /* Check cascade byte, if cascade tag then go next cascade level */ - if( (ret == ERR_NONE) && (*selReq.nfcid1 == RFAL_NFCA_SDD_CT) ) - { - /* Cascade Tag present, store nfcid1 bytes (excluding cascade tag) and continue for next CL */ - ST_MEMCPY( &nfcId1[*nfcId1Len], &((uint8_t*)&selReq.nfcid1)[RFAL_NFCA_SDD_CT_LEN], (RFAL_NFCA_CASCADE_1_UID_LEN - RFAL_NFCA_SDD_CT_LEN) ); - *nfcId1Len += (RFAL_NFCA_CASCADE_1_UID_LEN - RFAL_NFCA_SDD_CT_LEN); - } - else - { - /* UID Selection complete, Stop Cascade Level loop */ - ST_MEMCPY( &nfcId1[*nfcId1Len], (uint8_t*)&selReq.nfcid1, RFAL_NFCA_CASCADE_1_UID_LEN ); - *nfcId1Len += RFAL_NFCA_CASCADE_1_UID_LEN; - return ERR_NONE; - } - } - return ERR_INTERNAL; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcaPollerFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt ) -{ - ReturnCode ret; - bool collPending; - rfalNfcaSensRes sensRes; - uint16_t rcvLen; - - if( (nfcaDevList == NULL) || (devCnt == NULL) ) - { - return ERR_PARAM; - } - - *devCnt = 0; - ret = ERR_NONE; - - /*******************************************************************************/ - /* Send ALL_REQ before Anticollision if a Sleep was sent before Activity 1.1 9.3.4.1 and EMVco 2.6 9.3.2.1 */ - if( compMode != RFAL_COMPLIANCE_MODE_ISO ) - { - ret = rfalISO14443ATransceiveShortFrame( RFAL_14443A_SHORTFRAME_CMD_WUPA, (uint8_t*)&nfcaDevList->sensRes, (uint8_t)rfalConvBytesToBits(sizeof(rfalNfcaSensRes)), &rcvLen, RFAL_NFCA_FDTMIN ); - if(ret != ERR_NONE) - { - if( (compMode == RFAL_COMPLIANCE_MODE_EMV) || ((ret != ERR_RF_COLLISION) && (ret != ERR_CRC) && (ret != ERR_FRAMING) && (ret != ERR_PAR)) ) - { - return ret; - } - } - - /* Check proper SENS_RES/ATQA size */ - if( (ret == ERR_NONE) && (rfalConvBytesToBits(sizeof(rfalNfcaSensRes)) != rcvLen) ) - { - return ERR_PROTO; - } - } - - - #if RFAL_FEATURE_T1T - /*******************************************************************************/ - /* Only check for T1T if previous SENS_RES was received without a transmission * - * error. When collisions occur bits in the SENS_RES may look like a T1T */ - /* If T1T Anticollision is not supported Activity 1.1 9.3.4.3 */ - if( rfalNfcaIsSensResT1T( &nfcaDevList->sensRes ) && (devLimit != 0U) && (ret == ERR_NONE) && (compMode != RFAL_COMPLIANCE_MODE_EMV) ) - { - /* RID_REQ shall be performed with rfalT1TPollerRid() Activity 1.1 9.3.4.24 */ - rfalT1TPollerInitialize(); - EXIT_ON_ERR( ret, rfalT1TPollerRid( &nfcaDevList->ridRes ) ); - - /* T1T doesn't support Anticollision */ - *devCnt = 1; - nfcaDevList->isSleep = false; - nfcaDevList->type = RFAL_NFCA_T1T; - nfcaDevList->nfcId1Len = RFAL_NFCA_CASCADE_1_UID_LEN; - ST_MEMCPY( &nfcaDevList->nfcId1, &nfcaDevList->ridRes.uid, RFAL_NFCA_CASCADE_1_UID_LEN ); - - return ERR_NONE; - } - #endif /* RFAL_FEATURE_T1T */ - - /*******************************************************************************/ - /* Store the SENS_RES from Technology Detection or from WUPA */ - sensRes = nfcaDevList->sensRes; - - if( devLimit > 0U ) /* MISRA 21.18 */ - { - ST_MEMSET( nfcaDevList, 0x00, (sizeof(rfalNfcaListenDevice) * devLimit) ); - } - - /* Restore the prev SENS_RES, assuming that the SENS_RES received is from first device - * When only one device is detected it's not woken up then we'll have no SENS_RES (ATQA) */ - nfcaDevList->sensRes = sensRes; - - - /*******************************************************************************/ - do - { - uint8_t newDeviceType; - - EXIT_ON_ERR( ret, rfalNfcaPollerSingleCollisionResolution( devLimit, &collPending, &nfcaDevList[*devCnt].selRes, (uint8_t*)&nfcaDevList[*devCnt].nfcId1, (uint8_t*)&nfcaDevList[*devCnt].nfcId1Len ) ); - - /* Assign Listen Device */ - newDeviceType = ((uint8_t)nfcaDevList[*devCnt].selRes.sak) & RFAL_NFCA_SEL_RES_CONF_MASK; /* MISRA 10.8 */ - /* PRQA S 4342 1 # MISRA 10.5 - Guaranteed that no invalid enum values are created: see guard_eq_RFAL_NFCA_T2T, .... */ - nfcaDevList[*devCnt].type = (rfalNfcaListenDeviceType) (newDeviceType); - nfcaDevList[*devCnt].isSleep = false; - (*devCnt)++; - - - /* If a collision was detected and device counter is lower than limit Activity 1.1 9.3.4.21 */ - if( (*devCnt < devLimit) && ((collPending) || (compMode != RFAL_COMPLIANCE_MODE_ISO) ) ) - { - /* Put this device to Sleep Activity 1.1 9.3.4.22 */ - rfalNfcaPollerSleep(); - nfcaDevList[(*devCnt - 1U)].isSleep = true; - - - /* Send a new SENS_REQ to check for other cards Activity 1.1 9.3.4.23 */ - ret = rfalNfcaPollerCheckPresence( RFAL_14443A_SHORTFRAME_CMD_REQA, &nfcaDevList[*devCnt].sensRes ); - if( ret == ERR_TIMEOUT ) - { - /* No more devices found, exit */ - collPending = false; - } - else - { - /* Another device found, continue loop */ - collPending = true; - } - } - else - { - /* Exit loop */ - collPending = false; - } - }while( (*devCnt < devLimit) && (collPending) ); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcaPollerSelect( const uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes ) -{ - uint8_t i; - uint8_t cl; - uint8_t nfcidOffset; - uint16_t rxLen; - ReturnCode ret; - rfalNfcaSelReq selReq; - - if( (nfcid1 == NULL) || (nfcidLen > RFAL_NFCA_CASCADE_3_UID_LEN) || (selRes == NULL) ) - { - return ERR_PARAM; - } - - - /* Calculate Cascate Level */ - cl = rfalNfcaNfcidLen2CL( nfcidLen ); - nfcidOffset = 0; - - /*******************************************************************************/ - /* Go through all Cascade Levels Activity 1.1 9.4.4 */ - for( i = RFAL_NFCA_SEL_CASCADE_L1; i <= cl; i++ ) - { - /* Assign SEL_CMD according to the CLn and SEL_PAR*/ - selReq.selCmd = rfalNfcaCLn2SELCMD(i); - selReq.selPar = RFAL_NFCA_SEL_SELPAR; - - /* Compute NFCID/Data on the SEL_REQ command Digital 1.1 Table 18 */ - if( cl != i ) - { - *selReq.nfcid1 = RFAL_NFCA_SDD_CT; - ST_MEMCPY( &selReq.nfcid1[RFAL_NFCA_SDD_CT_LEN], &nfcid1[nfcidOffset], (RFAL_NFCA_CASCADE_1_UID_LEN - RFAL_NFCA_SDD_CT_LEN) ); - nfcidOffset += (RFAL_NFCA_CASCADE_1_UID_LEN - RFAL_NFCA_SDD_CT_LEN); - } - else - { - ST_MEMCPY( selReq.nfcid1, &nfcid1[nfcidOffset], RFAL_NFCA_CASCADE_1_UID_LEN ); - } - - /* Calculate nfcid's BCC */ - selReq.bcc = rfalNfcaCalculateBcc( (uint8_t*)&selReq.nfcid1, sizeof(selReq.nfcid1) ); - - /*******************************************************************************/ - /* Send SEL_REQ */ - EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&selReq, sizeof(rfalNfcaSelReq), (uint8_t*)selRes, sizeof(rfalNfcaSelRes), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCA_FDTMIN ) ); - - /* Ensure proper response length */ - if( rxLen != sizeof(rfalNfcaSelRes) ) - { - return ERR_PROTO; - } - } - - /* REMARK: Could check if NFCID1 is complete */ - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcaPollerSleep( void ) -{ - rfalNfcaSlpReq slpReq; - uint8_t rxBuf; /* dummy buffer, just to perform Rx */ - - slpReq.frame[RFAL_NFCA_SLP_CMD_POS] = RFAL_NFCA_SLP_CMD; - slpReq.frame[RFAL_NFCA_SLP_BYTE2_POS] = RFAL_NFCA_SLP_BYTE2; - - rfalTransceiveBlockingTxRx( (uint8_t*)&slpReq, sizeof(rfalNfcaSlpReq), &rxBuf, sizeof(rxBuf), NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCA_SLP_FWT ); - - /* ISO14443-3 6.4.3 HLTA - If PICC responds with any modulation during 1 ms this response shall be interpreted as not acknowledge - Digital 2.0 6.9.2.1 & EMVCo 3.0 5.6.2.1 - consider the HLTA command always acknowledged - No check to be compliant with NFC and EMVCo, and to improve interoprability (Kovio RFID Tag) - */ - - return ERR_NONE; -} - - -/*******************************************************************************/ -bool rfalNfcaListenerIsSleepReq( const uint8_t *buf, uint16_t bufLen ) -{ - /* Check if length and payload match */ - if( (bufLen != sizeof(rfalNfcaSlpReq)) || (buf[RFAL_NFCA_SLP_CMD_POS] != RFAL_NFCA_SLP_CMD) || (buf[RFAL_NFCA_SLP_BYTE2_POS] != RFAL_NFCA_SLP_BYTE2) ) - { - return false; - } - - return true; -} - -/* If the guards here don't compile then the code above cannot work anymore. */ -extern uint8_t guard_eq_RFAL_NFCA_T2T[((RFAL_NFCA_SEL_RES_CONF_MASK&(uint8_t)RFAL_NFCA_T2T) == (uint8_t)RFAL_NFCA_T2T)?1:(-1)]; -extern uint8_t guard_eq_RFAL_NFCA_T4T[((RFAL_NFCA_SEL_RES_CONF_MASK&(uint8_t)RFAL_NFCA_T4T) == (uint8_t)RFAL_NFCA_T4T)?1:(-1)]; -extern uint8_t guard_eq_RFAL_NFCA_NFCDEP[((RFAL_NFCA_SEL_RES_CONF_MASK&(uint8_t)RFAL_NFCA_NFCDEP) == (uint8_t)RFAL_NFCA_NFCDEP)?1:(-1)]; -extern uint8_t guard_eq_RFAL_NFCA_T4T_NFCDEP[((RFAL_NFCA_SEL_RES_CONF_MASK&(uint8_t)RFAL_NFCA_T4T_NFCDEP) == (uint8_t)RFAL_NFCA_T4T_NFCDEP)?1:(-1)]; -#endif /* RFAL_FEATURE_NFCA */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_nfcb.c b/Software/Middlewares/ST/rfal/Src/rfal_nfcb.c deleted file mode 100644 index 49abebc..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_nfcb.c +++ /dev/null @@ -1,504 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfcb.c - * - * \author Gustavo Patricio - * - * \brief Implementation of NFC-B (ISO14443B) helpers - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_nfcb.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_NFCB - #define RFAL_FEATURE_NFCB false /* NFC-B module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_NFCB - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_NFCB_SENSB_REQ_EXT_SENSB_RES_SUPPORTED 0x10U /*!< Bit mask for Extended SensB Response support in SENSB_REQ */ -#define RFAL_NFCB_SENSB_RES_PROT_TYPE_RFU 0x08U /*!< Bit mask for Protocol Type RFU in SENSB_RES */ -#define RFAL_NFCB_SLOT_MARKER_SC_SHIFT 4U /*!< Slot Code position on SLOT_MARKER APn */ - -#define RFAL_NFCB_SLOTMARKER_SLOTCODE_MIN 1U /*!< SLOT_MARKER Slot Code minimum Digital 1.1 Table 37 */ -#define RFAL_NFCB_SLOTMARKER_SLOTCODE_MAX 16U /*!< SLOT_MARKER Slot Code maximum Digital 1.1 Table 37 */ - -#define RFAL_NFCB_ACTIVATION_FWT (RFAL_NFCB_FWTSENSB + RFAL_NFCB_DTPOLL_20) /*!< FWT(SENSB) + dTbPoll Digital 2.0 7.9.1.3 */ - -/*! Advanced and Extended bit mask in Parameter of SENSB_REQ */ -#define RFAL_NFCB_SENSB_REQ_PARAM (RFAL_NFCB_SENSB_REQ_ADV_FEATURE | RFAL_NFCB_SENSB_REQ_EXT_SENSB_RES_SUPPORTED) - - -/*! NFC-B commands definition */ -enum -{ - RFAL_NFCB_CMD_SENSB_REQ = 0x05, /*!< SENSB_REQ (REQB) & SLOT_MARKER Digital 1.1 Table 24 */ - RFAL_NFCB_CMD_SENSB_RES = 0x50, /*!< SENSB_RES (ATQB) & SLOT_MARKER Digital 1.1 Table 27 */ - RFAL_NFCB_CMD_SLPB_REQ = 0x50, /*!< SLPB_REQ (HLTB command) Digital 1.1 Table 38 */ - RFAL_NFCB_CMD_SLPB_RES = 0x00 /*!< SLPB_RES (HLTB Answer) Digital 1.1 Table 39 */ -}; - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -#define rfalNfcbNI2NumberOfSlots( ni ) (uint8_t)(1U << (ni)) /*!< Converts the Number of slots Identifier to slot number */ - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! ALLB_REQ (WUPB) and SENSB_REQ (REQB) Command Format Digital 1.1 7.6.1 */ -typedef struct -{ - uint8_t cmd; /*!< xxxxB_REQ: 05h */ - uint8_t AFI; /*!< NFC Identifier */ - uint8_t PARAM; /*!< Application Data */ -} rfalNfcbSensbReq; - -/*! SLOT_MARKER Command format Digital 1.1 7.7.1 */ -typedef struct -{ - uint8_t APn; /*!< Slot number 2..16 | 0101b */ -} rfalNfcbSlotMarker; - -/*! SLPB_REQ (HLTB) Command Format Digital 1.1 7.8.1 */ -typedef struct -{ - uint8_t cmd; /*!< SLPB_REQ: 50h */ - uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFC Identifier (PUPI)*/ -} rfalNfcbSlpbReq; - - -/*! SLPB_RES (HLTB) Response Format Digital 1.1 7.8.2 */ -typedef struct -{ - uint8_t cmd; /*!< SLPB_RES: 00h */ -} rfalNfcbSlpbRes; - - -/*! RFAL NFC-B instance */ -typedef struct -{ - uint8_t AFI; /*!< AFI to be used */ - uint8_t PARAM; /*!< PARAM to be used */ -} rfalNfcb; - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -static ReturnCode rfalNfcbCheckSensbRes( const rfalNfcbSensbRes *sensbRes, uint8_t sensbResLen ); - - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ - -static rfalNfcb gRfalNfcb; /*!< RFAL NFC-B Instance */ - - -/* -****************************************************************************** -* LOCAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -static ReturnCode rfalNfcbCheckSensbRes( const rfalNfcbSensbRes *sensbRes, uint8_t sensbResLen ) -{ - /* Check response length */ - if( ( (sensbResLen != RFAL_NFCB_SENSB_RES_LEN) && (sensbResLen != RFAL_NFCB_SENSB_RES_EXT_LEN) ) ) - { - return ERR_PROTO; - } - - /* Check SENSB_RES and Protocol Type Digital 1.1 7.6.2.19 */ - if( ((sensbRes->protInfo.FsciProType & RFAL_NFCB_SENSB_RES_PROT_TYPE_RFU) != 0U) || (sensbRes->cmd != (uint8_t)RFAL_NFCB_CMD_SENSB_RES) ) - { - return ERR_PROTO; - } - return ERR_NONE; -} - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -ReturnCode rfalNfcbPollerInitialize( void ) -{ - ReturnCode ret; - - EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCB, RFAL_BR_106, RFAL_BR_106 ) ); - rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); - - rfalSetGT( RFAL_GT_NFCB ); - rfalSetFDTListen( RFAL_FDT_LISTEN_NFCB_POLLER ); - rfalSetFDTPoll( RFAL_FDT_POLL_NFCB_POLLER ); - - gRfalNfcb.AFI = RFAL_NFCB_AFI; - gRfalNfcb.PARAM = RFAL_NFCB_PARAM; - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcbPollerInitializeWithParams( uint8_t AFI, uint8_t PARAM ) -{ - ReturnCode ret; - - EXIT_ON_ERR( ret, rfalNfcbPollerInitialize() ); - - gRfalNfcb.AFI = AFI; - gRfalNfcb.PARAM = (PARAM & RFAL_NFCB_SENSB_REQ_PARAM); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcbPollerCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen ) -{ - uint16_t rxLen; - ReturnCode ret; - rfalNfcbSensbReq sensbReq; - - - /* Check if the command requested and given the slot number are valid */ - if( ((RFAL_NFCB_SENS_CMD_SENSB_REQ != cmd) && (RFAL_NFCB_SENS_CMD_ALLB_REQ != cmd)) || - (slots > RFAL_NFCB_SLOT_NUM_16) || (sensbRes == NULL) || (sensbResLen == NULL) ) - { - return ERR_PARAM; - } - - *sensbResLen = 0; - ST_MEMSET(sensbRes, 0x00, sizeof(rfalNfcbSensbRes) ); - - /* Compute SENSB_REQ */ - sensbReq.cmd = RFAL_NFCB_CMD_SENSB_REQ; - sensbReq.AFI = gRfalNfcb.AFI; - sensbReq.PARAM = (((uint8_t)gRfalNfcb.PARAM & RFAL_NFCB_SENSB_REQ_PARAM) | (uint8_t)cmd | (uint8_t)slots); - - /* Send SENSB_REQ and disable AGC to detect collisions */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&sensbReq, sizeof(rfalNfcbSensbReq), (uint8_t*)sensbRes, sizeof(rfalNfcbSensbRes), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCB_FWTSENSB ); - - *sensbResLen = (uint8_t)rxLen; - - /* Check if a transmission error was detected */ - if( (ret == ERR_CRC) || (ret == ERR_FRAMING) ) - { - /* Invalidate received frame as an error was detected (CollisionResolution checks if valid) */ - *sensbResLen = 0; - return ERR_NONE; - } - - if( ret == ERR_NONE ) - { - return rfalNfcbCheckSensbRes( sensbRes, *sensbResLen ); - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcbPollerSleep( const uint8_t* nfcid0 ) -{ - uint16_t rxLen; - ReturnCode ret; - rfalNfcbSlpbReq slpbReq; - rfalNfcbSlpbRes slpbRes; - - if( nfcid0 == NULL ) - { - return ERR_PARAM; - } - - /* Compute SLPB_REQ */ - slpbReq.cmd = RFAL_NFCB_CMD_SLPB_REQ; - ST_MEMCPY( slpbReq.nfcid0, nfcid0, RFAL_NFCB_NFCID0_LEN ); - - EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&slpbReq, sizeof(rfalNfcbSlpbReq), (uint8_t*)&slpbRes, sizeof(rfalNfcbSlpbRes), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCB_ACTIVATION_FWT )); - - /* Check SLPB_RES */ - if( (rxLen != sizeof(rfalNfcbSlpbRes)) || (slpbRes.cmd != (uint8_t)RFAL_NFCB_CMD_SLPB_RES) ) - { - return ERR_PROTO; - } - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcbPollerSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen ) -{ - ReturnCode ret; - rfalNfcbSlotMarker slotMarker; - uint16_t rxLen; - - /* Check parameters */ - if( (sensbRes == NULL) || (sensbResLen == NULL) || - (slotCode < RFAL_NFCB_SLOTMARKER_SLOTCODE_MIN) || - (slotCode > RFAL_NFCB_SLOTMARKER_SLOTCODE_MAX) ) - { - return ERR_PARAM; - } - /* Compose and send SLOT_MARKER with disabled AGC to detect collisions */ - slotMarker.APn = ((slotCode << RFAL_NFCB_SLOT_MARKER_SC_SHIFT) | (uint8_t)RFAL_NFCB_CMD_SENSB_REQ); - - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&slotMarker, sizeof(rfalNfcbSlotMarker), (uint8_t*)sensbRes, sizeof(rfalNfcbSensbRes), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCB_ACTIVATION_FWT ); - - *sensbResLen = (uint8_t)rxLen; - - /* Check if a transmission error was detected */ - if( (ret == ERR_CRC) || (ret == ERR_FRAMING) ) - { - return ERR_RF_COLLISION; - } - - if( ret == ERR_NONE ) - { - return rfalNfcbCheckSensbRes( sensbRes, *sensbResLen ); - } - - return ret; -} - - -ReturnCode rfalNfcbPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen ) -{ - NO_WARNING(compMode); - - return rfalNfcbPollerCheckPresence( RFAL_NFCB_SENS_CMD_SENSB_REQ, RFAL_NFCB_SLOT_NUM_1, sensbRes, sensbResLen ); -} - - -/*******************************************************************************/ -ReturnCode rfalNfcbPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt ) -{ - bool colPending; /* dummy */ - return rfalNfcbPollerSlottedCollisionResolution( compMode, devLimit, RFAL_NFCB_SLOT_NUM_1, RFAL_NFCB_SLOT_NUM_16, nfcbDevList, devCnt, &colPending ); -} - - -/*******************************************************************************/ -ReturnCode rfalNfcbPollerSlottedCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending ) -{ - ReturnCode ret; - uint8_t slotsNum; - uint8_t slotCode; - uint8_t curDevCnt; - - - /* Check parameters. In ISO | Activity 1.0 mode the initial slots must be 1 as continuation of Technology Detection */ - if( (nfcbDevList == NULL) || (devCnt == NULL) || (colPending == NULL) || (initSlots > RFAL_NFCB_SLOT_NUM_16) || - (endSlots > RFAL_NFCB_SLOT_NUM_16) || ((compMode == RFAL_COMPLIANCE_MODE_ISO) && (initSlots != RFAL_NFCB_SLOT_NUM_1)) ) - { - return ERR_PARAM; - } - - /* Initialise as no error in case Activity 1.0 where the previous SENSB_RES from technology detection should be used */ - ret = ERR_NONE; - *devCnt = 0; - curDevCnt = 0; - *colPending = false; - - - /* Send ALLB_REQ Activity 1.1 9.3.5.2 and 9.3.5.3 (Symbol 1 and 2) */ - if( compMode != RFAL_COMPLIANCE_MODE_ISO ) - { - ret = rfalNfcbPollerCheckPresence( RFAL_NFCB_SENS_CMD_ALLB_REQ, initSlots, &nfcbDevList->sensbRes, &nfcbDevList->sensbResLen ); - if( (ret != ERR_NONE) && (initSlots == RFAL_NFCB_SLOT_NUM_1) ) - { - return ret; - } - } - - - /* Check if there was a transmission error on WUPB EMVCo 2.6 9.3.3.1 */ - if( (compMode == RFAL_COMPLIANCE_MODE_EMV) && (nfcbDevList->sensbResLen == 0U) ) - { - return ERR_FRAMING; - } - - for( slotsNum = (uint8_t)initSlots; slotsNum <= (uint8_t)endSlots; slotsNum++ ) - { - do { - /* Activity 1.1 9.3.5.23 - Symbol 22 */ - if( (compMode == RFAL_COMPLIANCE_MODE_NFC) && (curDevCnt != 0U) ) - { - rfalNfcbPollerSleep( nfcbDevList[(*devCnt-1U)].sensbRes.nfcid0 ); - nfcbDevList[(*devCnt-1U)].isSleep = true; - } - - /* Send SENSB_REQ with number of slots if not the first Activity 1.1 9.3.5.24 - Symbol 23 */ - if( (slotsNum != (uint8_t)initSlots) || *colPending ) - { - /* PRQA S 4342 1 # MISRA 10.5 - Layout of rfalNfcbSlots and above loop guarantee that no invalid enum values are created. */ - ret = rfalNfcbPollerCheckPresence( RFAL_NFCB_SENS_CMD_SENSB_REQ, (rfalNfcbSlots)slotsNum, &nfcbDevList[*devCnt].sensbRes, &nfcbDevList[*devCnt].sensbResLen ); - } - - /* Activity 1.1 9.3.5.6 - Symbol 5 */ - slotCode = 0; - curDevCnt = 0; - *colPending = false; - - do{ - /* Activity 1.1 9.3.5.26 - Symbol 25 */ - if( slotCode != 0U ) - { - ret = rfalNfcbPollerSlotMarker( slotCode, &nfcbDevList[*devCnt].sensbRes, &nfcbDevList[*devCnt].sensbResLen ); - } - - /* Activity 1.1 9.3.5.7 and 9.3.5.8 - Symbol 6 */ - if( ret != ERR_TIMEOUT ) - { - /* Activity 1.1 9.3.5.8 - Symbol 7 */ - if( (rfalNfcbCheckSensbRes( &nfcbDevList[*devCnt].sensbRes, nfcbDevList[*devCnt].sensbResLen) == ERR_NONE) && (ret == ERR_NONE) ) - { - nfcbDevList[*devCnt].isSleep = false; - - if( compMode == RFAL_COMPLIANCE_MODE_EMV ) - { - (*devCnt)++; - return ret; - } - else if( compMode == RFAL_COMPLIANCE_MODE_ISO ) - { - /* Activity 1.0 9.3.5.8 - Symbol 7 */ - (*devCnt)++; - curDevCnt++; - - /* Activity 1.0 9.3.5.10 - Symbol 9 */ - if( (*devCnt >= devLimit) || (slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1) ) - { - return ret; - } - - /* Activity 1.0 9.3.5.11 - Symbol 10 */ - rfalNfcbPollerSleep( nfcbDevList[*devCnt-1U].sensbRes.nfcid0 ); - nfcbDevList[*devCnt-1U].isSleep = true; - } - else if( compMode == RFAL_COMPLIANCE_MODE_NFC ) - { - /* Activity 1.1 9.3.5.10 and 9.3.5.11 - Symbol 9 and Symbol 11*/ - if(curDevCnt != 0U) - { - rfalNfcbPollerSleep( nfcbDevList[*devCnt-1U].sensbRes.nfcid0 ); - nfcbDevList[*devCnt-1U].isSleep = true; - } - - /* Activity 1.1 9.3.5.12 - Symbol 11 */ - (*devCnt)++; - curDevCnt++; - - /* Activity 1.1 9.3.5.6 - Symbol 13 */ - if( (*devCnt >= devLimit) || (slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1) ) - { - return ret; - } - } - else - { - /* MISRA 15.7 - Empty else */ - } - } - else - { - /* If deviceLimit is set to 0 the NFC Forum Device is configured to perform collision detection only Activity 1.0 and 1.1 9.3.5.5 - Symbol 4 */ - if( (devLimit == 0U) && (slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1) ) - { - return ERR_RF_COLLISION; - } - - /* Activity 1.1 9.3.5.9 - Symbol 8 */ - *colPending = true; - } - } - - /* Activity 1.1 9.3.5.15 - Symbol 14 */ - slotCode++; - } - while( slotCode < rfalNfcbNI2NumberOfSlots(slotsNum) ); - - /* Activity 1.1 9.3.5.17 - Symbol 16 */ - if( !(*colPending) ) - { - return ERR_NONE; - } - - /* Activity 1.1 9.3.5.18 - Symbol 17 */ - } while (curDevCnt != 0U); /* If a collision is detected and card(s) were found on this loop keep the same number of available slots */ - } - - return ERR_NONE; -} - - -/*******************************************************************************/ -uint32_t rfalNfcbTR2ToFDT( uint8_t tr2Code ) -{ - /*******************************************************************************/ - /* MISRA 8.9 An object should be defined at block scope if its identifier only appears in a single function */ - /*! TR2 Table according to Digital 1.1 Table 33 */ - const uint16_t rfalNfcbTr2Table[] = { 1792, 3328, 5376, 9472 }; - /*******************************************************************************/ - - return rfalNfcbTr2Table[ (tr2Code & RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK) ]; -} - -#endif /* RFAL_FEATURE_NFCB */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_nfcf.c b/Software/Middlewares/ST/rfal/Src/rfal_nfcf.c deleted file mode 100644 index e3dd112..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_nfcf.c +++ /dev/null @@ -1,546 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfcf.c - * - * \author Gustavo Patricio - * - * \brief Implementation of NFC-F Poller (FeliCa PCD) device - * - * The definitions and helpers methods provided by this module are - * aligned with NFC-F (FeliCa - JIS X6319-4) - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_nfcf.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_NFCF - #define RFAL_FEATURE_NFCF false /* NFC-F module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_NFCF - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ -#define RFAL_NFCF_SENSF_REQ_LEN_MIN 5U /*!< SENSF_RES minimum length */ - -#define RFAL_NFCF_READ_WO_ENCRYPTION_MIN_LEN 15U /*!< Minimum length for a Check Command T3T 5.4.1 */ -#define RFAL_NFCF_WRITE_WO_ENCRYPTION_MIN_LEN 31U /*!< Minimum length for an Update Command T3T 5.5.1 */ - -#define RFAL_NFCF_CHECK_RES_MIN_LEN 11U /*!< CHECK Response minimum length T3T 1.0 Table 8 */ -#define RFAL_NFCF_UPDATE_RES_MIN_LEN 11U /*!< UPDATE Response minimum length T3T 1.0 Table 8 */ - -#define RFAL_NFCF_CHECK_REQ_MAX_LEN 86U /*!< Max length of a Check request T3T 1.0 Table 7 */ -#define RFAL_NFCF_CHECK_REQ_MAX_SERV 15U /*!< Max Services number on Check request T3T 1.0 5.4.1.5 */ -#define RFAL_NFCF_CHECK_REQ_MAX_BLOCK 15U /*!< Max Blocks number on Check request T3T 1.0 5.4.1.10 */ -#define RFAL_NFCF_UPDATE_REQ_MAX_SERV 15U /*!< Max Services number Update request T3T 1.0 5.4.1.5 */ -#define RFAL_NFCF_UPDATE_REQ_MAX_BLOCK 13U /*!< Max Blocks number on Update request T3T 1.0 5.4.1.10 */ - - -/*! MRT Check | Uupdate = (Tt3t x ((A+1) + n (B+1)) x 4^E) + dRWTt3t T3T 5.8 - Max values used: A = 7 ; B = 7 ; E = 3 ; n = 15 (NFC Forum n = 15, JIS n = 32) -*/ -#define RFAL_NFCF_MRT_CHECK_UPDATE ((4096 * (8 + (15 * 8)) * 64 ) + 16) - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ -#define rfalNfcfSlots2CardNum( s ) ((uint8_t)(s)+1U) /*!< Converts Time Slot Number (TSN) into num of slots */ - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! Structure/Buffer to hold the SENSF_RES with LEN byte prepended */ -typedef struct{ - uint8_t LEN; /*!< NFC-F LEN byte */ - rfalNfcfSensfRes SENSF_RES; /*!< SENSF_RES */ -} rfalNfcfSensfResBuf; - - -/*! Greedy collection for NFCF GRE_POLL_F Activity 1.0 Table 10 */ -typedef struct{ - uint8_t pollFound; /*!< Number of devices found by the Poll */ - uint8_t pollCollision; /*!< Number of collisions detected */ - rfalFeliCaPollRes POLL_F[RFAL_NFCF_POLL_MAXCARDS]; /*!< GRE_POLL_F Activity 1.0 Table 10 */ -} rfalNfcfGreedyF; - - -/*! NFC-F SENSF_REQ format Digital 1.1 8.6.1 */ -typedef struct -{ - uint8_t CMD; /*!< Command code: 00h */ - uint8_t SC[RFAL_NFCF_SENSF_SC_LEN]; /*!< System Code */ - uint8_t RC; /*!< Request Code */ - uint8_t TSN; /*!< Time Slot Number */ -} rfalNfcfSensfReq; - - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ -static rfalNfcfGreedyF gRfalNfcfGreedyF; /*!< Activity's NFCF Greedy collection */ - - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -static void rfalNfcfComputeValidSENF( rfalNfcfListenDevice *outDevInfo, uint8_t *curDevIdx, uint8_t devLimit, bool overwrite, bool *nfcDepFound ); - - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ - -/*******************************************************************************/ -static void rfalNfcfComputeValidSENF( rfalNfcfListenDevice *outDevInfo, uint8_t *curDevIdx, uint8_t devLimit, bool overwrite, bool *nfcDepFound ) -{ - uint8_t tmpIdx; - bool duplicate; - rfalNfcfSensfResBuf *sensfBuf; - rfalNfcfSensfResBuf sensfCopy; - - - /*******************************************************************************/ - /* Go through all responses check if valid and duplicates */ - /*******************************************************************************/ - while( (gRfalNfcfGreedyF.pollFound > 0U) && ((*curDevIdx) < devLimit) ) - { - duplicate = false; - gRfalNfcfGreedyF.pollFound--; - - /* MISRA 11.3 - Cannot point directly into different object type, use local copy */ - ST_MEMCPY( (uint8_t*)&sensfCopy, (uint8_t*)&gRfalNfcfGreedyF.POLL_F[gRfalNfcfGreedyF.pollFound], sizeof(rfalNfcfSensfResBuf) ); - - - /* Point to received SENSF_RES */ - sensfBuf = &sensfCopy; - - - /* Check for devices that are already in device list */ - for( tmpIdx = 0; tmpIdx < (*curDevIdx); tmpIdx++ ) - { - if( ST_BYTECMP( sensfBuf->SENSF_RES.NFCID2, outDevInfo[tmpIdx].sensfRes.NFCID2, RFAL_NFCF_NFCID2_LEN ) == 0 ) - { - duplicate = true; - break; - } - } - - /* If is a duplicate skip this (and not to overwrite)*/ - if(duplicate && !overwrite) - { - continue; - } - - /* Check if response length is OK */ - if( (( sensfBuf->LEN - RFAL_NFCF_HEADER_LEN) < RFAL_NFCF_SENSF_RES_LEN_MIN) || ((sensfBuf->LEN - RFAL_NFCF_HEADER_LEN) > RFAL_NFCF_SENSF_RES_LEN_MAX) ) - { - continue; - } - - /* Check if the response is a SENSF_RES / Polling response */ - if( sensfBuf->SENSF_RES.CMD != (uint8_t)RFAL_NFCF_CMD_POLLING_RES ) - { - continue; - } - - /* Check if is an overwrite request or new device*/ - if(duplicate && overwrite) - { - /* overwrite deviceInfo/GRE_SENSF_RES with SENSF_RES */ - outDevInfo[tmpIdx].sensfResLen = (sensfBuf->LEN - RFAL_NFCF_LENGTH_LEN); - ST_MEMCPY( &outDevInfo[tmpIdx].sensfRes, &sensfBuf->SENSF_RES, outDevInfo[tmpIdx].sensfResLen ); - continue; - } - else - { - /* fill deviceInfo/GRE_SENSF_RES with new SENSF_RES */ - outDevInfo[(*curDevIdx)].sensfResLen = (sensfBuf->LEN - RFAL_NFCF_LENGTH_LEN); - ST_MEMCPY( &outDevInfo[(*curDevIdx)].sensfRes, &sensfBuf->SENSF_RES, outDevInfo[(*curDevIdx)].sensfResLen ); - } - - /* Check if this device supports NFC-DEP and signal it (ACTIVITY 1.1 9.3.6.63) */ - *nfcDepFound = rfalNfcfIsNfcDepSupported( &outDevInfo[(*curDevIdx)] ); - - (*curDevIdx)++; - } -} - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -ReturnCode rfalNfcfPollerInitialize( rfalBitRate bitRate ) -{ - ReturnCode ret; - - if( (bitRate != RFAL_BR_212) && (bitRate != RFAL_BR_424) ) - { - return ERR_PARAM; - } - - EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCF, bitRate, bitRate ) ); - rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); - - rfalSetGT( RFAL_GT_NFCF ); - rfalSetFDTListen( RFAL_FDT_LISTEN_NFCF_POLLER ); - rfalSetFDTPoll( RFAL_FDT_POLL_NFCF_POLLER ); - - return ERR_NONE; -} - - - -/*******************************************************************************/ -ReturnCode rfalNfcfPollerPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *cardList, uint8_t *devCnt, uint8_t *collisions ) -{ - return rfalFeliCaPoll( slots, sysCode, reqCode, cardList, rfalNfcfSlots2CardNum(slots), devCnt, collisions ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcfPollerCheckPresence( void ) -{ - gRfalNfcfGreedyF.pollFound = 0; - gRfalNfcfGreedyF.pollCollision = 0; - - /* ACTIVITY 1.0 & 1.1 - 9.2.3.17 SENSF_REQ must be with number of slots equal to 4 - * SC must be 0xFFFF - * RC must be 0x00 (No system code info required) */ - return rfalFeliCaPoll( RFAL_FELICA_4_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_NO_REQUEST, gRfalNfcfGreedyF.POLL_F, rfalNfcfSlots2CardNum(RFAL_FELICA_4_SLOTS), &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision ); -} - - -/*******************************************************************************/ -ReturnCode rfalNfcfPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt ) -{ - ReturnCode ret; - bool nfcDepFound; - - if( (nfcfDevList == NULL) || (devCnt == NULL) ) - { - return ERR_PARAM; - } - - *devCnt = 0; - nfcDepFound = false; - - - /*******************************************************************************************/ - /* ACTIVITY 1.0 - 9.3.6.3 Copy valid SENSF_RES in GRE_POLL_F into GRE_SENSF_RES */ - /* ACTIVITY 1.0 - 9.3.6.6 The NFC Forum Device MUST remove all entries from GRE_SENSF_RES[]*/ - /* ACTIVITY 1.1 - 9.3.63.59 Populate GRE_SENSF_RES with data from GRE_POLL_F */ - /* */ - /* CON_DEVICES_LIMIT = 0 Just check if devices from Tech Detection exceeds -> always true */ - /* Allow the number of slots open on Technology Detection */ - /*******************************************************************************************/ - rfalNfcfComputeValidSENF( nfcfDevList, devCnt, ((devLimit == 0U) ? rfalNfcfSlots2CardNum( RFAL_FELICA_4_SLOTS ) : devLimit), false, &nfcDepFound ); - - - /*******************************************************************************/ - /* ACTIVITY 1.0 - 9.3.6.4 */ - /* ACTIVITY 1.1 - 9.3.63.60 Check if devices found are lower than the limit */ - /* and send a SENSF_REQ if so */ - /*******************************************************************************/ - if( *devCnt < devLimit ) - { - /* ACTIVITY 1.0 - 9.3.6.5 Copy valid SENSF_RES and then to remove it - * ACTIVITY 1.1 - 9.3.6.65 Copy and filter duplicates - * For now, due to some devices keep generating different nfcid2, we use 1.0 - * Phones detected: Samsung Galaxy Nexus,Samsung Galaxy S3,Samsung Nexus S */ - *devCnt = 0; - - ret = rfalNfcfPollerPoll( RFAL_FELICA_16_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_NO_REQUEST, gRfalNfcfGreedyF.POLL_F, &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision ); - if( ret == ERR_NONE ) - { - rfalNfcfComputeValidSENF( nfcfDevList, devCnt, devLimit, false, &nfcDepFound ); - } - - /*******************************************************************************/ - /* ACTIVITY 1.1 - 9.3.6.63 Check if any device supports NFC DEP */ - /*******************************************************************************/ - if( nfcDepFound && (compMode == RFAL_COMPLIANCE_MODE_NFC) ) - { - ret = rfalNfcfPollerPoll( RFAL_FELICA_16_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_SYSTEM_CODE, gRfalNfcfGreedyF.POLL_F, &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision ); - if( ret == ERR_NONE ) - { - rfalNfcfComputeValidSENF( nfcfDevList, devCnt, devLimit, true, &nfcDepFound ); - } - } - } - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcfPollerCheck( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvdLen ) -{ - uint8_t txBuf[RFAL_NFCF_CHECK_REQ_MAX_LEN]; - uint8_t msgIt; - uint8_t i; - ReturnCode ret; - uint8_t *checkRes; - - /* Check parameters */ - if( (nfcid2 == NULL) || (rxBuf == NULL) || (servBlock == NULL) || - (servBlock->numBlock == 0U) || (servBlock->numBlock > RFAL_NFCF_CHECK_REQ_MAX_BLOCK) || - (servBlock->numServ == 0U) || (servBlock->numServ > RFAL_NFCF_CHECK_REQ_MAX_SERV) || - (rxBufLen < (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CHECK_RES_MIN_LEN)) ) - { - return ERR_PARAM; - } - - msgIt = 0; - - /*******************************************************************************/ - /* Compose CHECK command/request */ - - txBuf[msgIt++] = RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION; /* Command Code */ - - ST_MEMCPY( &txBuf[msgIt], nfcid2, RFAL_NFCF_NFCID2_LEN ); /* NFCID2 */ - msgIt += RFAL_NFCF_NFCID2_LEN; - - txBuf[msgIt++] = servBlock->numServ; /* NoS */ - for( i = 0; i < servBlock->numServ; i++) - { - txBuf[msgIt++] = (uint8_t)((servBlock->servList[i] >> 0U) & 0xFFU); /* Service Code */ - txBuf[msgIt++] = (uint8_t)((servBlock->servList[i] >> 8U) & 0xFFU); - } - - txBuf[msgIt++] = servBlock->numBlock; /* NoB */ - for( i = 0; i < servBlock->numBlock; i++) - { - txBuf[msgIt++] = servBlock->blockList[i].conf; /* Block list element conf (Flag|Access|Service) */ - if( (servBlock->blockList[i].conf & 0x80U) != 0U ) /* Check if 2 or 3 byte block list element */ - { - txBuf[msgIt++] = (uint8_t)(servBlock->blockList[i].blockNum & 0xFFU); /* 1byte Block Num */ - } - else - { - txBuf[msgIt++] = (uint8_t)((servBlock->blockList[i].blockNum >> 0U) & 0xFFU); /* 2byte Block Num */ - txBuf[msgIt++] = (uint8_t)((servBlock->blockList[i].blockNum >> 8U) & 0xFFU); - } - } - - /*******************************************************************************/ - /* Transceive CHECK command/request */ - ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, rxBuf, rxBufLen, rcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCF_MRT_CHECK_UPDATE ); - - if( ret == ERR_NONE ) - { - /* Skip LEN byte */ - checkRes = (rxBuf + RFAL_NFCF_LENGTH_LEN); - - /* Check response length */ - if( *rcvdLen < (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CHECKUPDATE_RES_ST2_POS) ) - { - ret = ERR_PROTO; - } - /* Check for a valid response */ - else if( (checkRes[RFAL_NFCF_CMD_POS] != (uint8_t)RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION_RES) || - (checkRes[RFAL_NFCF_CHECKUPDATE_RES_ST1_POS] != RFAL_NFCF_STATUS_FLAG_SUCCESS) || - (checkRes[RFAL_NFCF_CHECKUPDATE_RES_ST2_POS] != RFAL_NFCF_STATUS_FLAG_SUCCESS) ) - { - ret = ERR_REQUEST; - } - /* CHECK succesfull, remove header */ - else - { - (*rcvdLen) -= (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CHECKUPDATE_RES_NOB_POS); - - if( *rcvdLen > 0U ) - { - ST_MEMMOVE( rxBuf, &checkRes[RFAL_NFCF_CHECKUPDATE_RES_NOB_POS], (*rcvdLen) ); - } - } - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalNfcfPollerUpdate( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *txBuf, uint16_t txBufLen, const uint8_t *blockData, uint8_t *rxBuf, uint16_t rxBufLen ) -{ - uint8_t i; - uint16_t msgIt; - uint16_t rcvdLen; - uint16_t auxLen; - uint8_t *updateRes; - ReturnCode ret; - - /* Check parameters */ - if( (nfcid2 == NULL) || (rxBuf == NULL) || (servBlock == NULL) || (txBuf == NULL) || - (servBlock->numBlock == 0U) || (servBlock->numBlock > RFAL_NFCF_UPDATE_REQ_MAX_BLOCK) || - (servBlock->numServ == 0U) || (servBlock->numServ > RFAL_NFCF_UPDATE_REQ_MAX_SERV) || - (rxBufLen < (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_UPDATE_RES_MIN_LEN)) ) - { - return ERR_PARAM; - } - - /* Calculate required txBuffer lenth */ - auxLen = (uint16_t)( RFAL_NFCF_CMD_LEN + RFAL_NFCF_NFCID2_LEN + ( servBlock->numServ * sizeof(rfalNfcfServ) ) + - (servBlock->numBlock * sizeof(rfalNfcfBlockListElem)) + (uint16_t)((uint16_t)servBlock->numBlock * RFAL_NFCF_BLOCK_LEN) ); - - /* Check whether the provided buffer is sufficient for this request */ - if( txBufLen < auxLen ) - { - return ERR_PARAM; - } - - msgIt = 0; - - /*******************************************************************************/ - /* Compose UPDATE command/request */ - - txBuf[msgIt++] = RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION; /* Command Code */ - - ST_MEMCPY( &txBuf[msgIt], nfcid2, RFAL_NFCF_NFCID2_LEN ); /* NFCID2 */ - msgIt += RFAL_NFCF_NFCID2_LEN; - - txBuf[msgIt++] = servBlock->numServ; /* NoS */ - for( i = 0; i < servBlock->numServ; i++) - { - txBuf[msgIt++] = (uint8_t)((servBlock->servList[i] >> 0U) & 0xFFU); /* Service Code */ - txBuf[msgIt++] = (uint8_t)((servBlock->servList[i] >> 8U) & 0xFFU); - } - - txBuf[msgIt++] = servBlock->numBlock; /* NoB */ - for( i = 0; i < servBlock->numBlock; i++) - { - txBuf[msgIt++] = servBlock->blockList[i].conf; /* Block list element conf (Flag|Access|Service) */ - if( (servBlock->blockList[i].conf & 0x80U) != 0U ) /* Check if 2 or 3 byte block list element */ - { - txBuf[msgIt++] = (uint8_t)(servBlock->blockList[i].blockNum & 0xFFU); /* 1byte Block Num */ - } - else - { - txBuf[msgIt++] = (uint8_t)((servBlock->blockList[i].blockNum >> 0U) & 0xFFU); /* 2byte Block Num */ - txBuf[msgIt++] = (uint8_t)((servBlock->blockList[i].blockNum >> 8U) & 0xFFU); - } - } - - auxLen = ((uint16_t)servBlock->numBlock * RFAL_NFCF_BLOCK_LEN); - ST_MEMCPY( &txBuf[msgIt], blockData, auxLen ); /* Block Data */ - msgIt += auxLen; - - - /*******************************************************************************/ - /* Transceive UPDATE command/request */ - ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, rxBuf, rxBufLen, &rcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCF_MRT_CHECK_UPDATE ); - - if( ret == ERR_NONE ) - { - /* Skip LEN byte */ - updateRes = (rxBuf + RFAL_NFCF_LENGTH_LEN); - - /* Check response length */ - if( rcvdLen < (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CHECKUPDATE_RES_ST2_POS) ) - { - ret = ERR_PROTO; - } - /* Check for a valid response */ - else if( (updateRes[RFAL_NFCF_CMD_POS] != (uint8_t)RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION_RES) || - (updateRes[RFAL_NFCF_CHECKUPDATE_RES_ST1_POS] != RFAL_NFCF_STATUS_FLAG_SUCCESS) || - (updateRes[RFAL_NFCF_CHECKUPDATE_RES_ST2_POS] != RFAL_NFCF_STATUS_FLAG_SUCCESS) ) - { - ret = ERR_REQUEST; - } - else - { - /* MISRA 15.7 - Empty else */ - } - } - - return ret; -} - - - -/*******************************************************************************/ -bool rfalNfcfListenerIsT3TReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid2 ) -{ - /* Check cmd byte */ - switch( *buf ) - { - case RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION: - if( bufLen < RFAL_NFCF_READ_WO_ENCRYPTION_MIN_LEN ) - { - return false; - } - break; - - case RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION: - if( bufLen < RFAL_NFCF_WRITE_WO_ENCRYPTION_MIN_LEN ) - { - return false; - } - break; - - default: - return false; - } - - /* Output NFID2 if requested */ - if( nfcid2 != NULL ) - { - ST_MEMCPY( nfcid2, &buf[RFAL_NFCF_CMD_LEN], RFAL_NFCF_NFCID2_LEN ); - } - - return true; -} - -#endif /* RFAL_FEATURE_NFCF */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_nfcv.c b/Software/Middlewares/ST/rfal/Src/rfal_nfcv.c deleted file mode 100644 index b38c6ba..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_nfcv.c +++ /dev/null @@ -1,874 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_nfcv.c - * - * \author Gustavo Patricio - * - * \brief Implementation of NFC-V Poller (ISO15693) device - * - * The definitions and helpers methods provided by this module are - * aligned with NFC-V (ISO15693) - * - * The definitions and helpers methods provided by this module - * are aligned with NFC-V Digital 2.1 - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_nfcv.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_NFCV - #define RFAL_FEATURE_NFCV false /* NFC-V module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_NFCV - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_NFCV_INV_REQ_FLAG 0x06U /*!< INVENTORY_REQ INV_FLAG Digital 2.1 9.6.1 */ -#define RFAL_NFCV_MASKVAL_MAX_LEN 8U /*!< Mask value max length: 64 bits (UID length) */ -#define RFAL_NFCV_MASKVAL_MAX_1SLOT_LEN 64U /*!< Mask value max length in 1 Slot mode in bits Digital 2.1 9.6.1.6 */ -#define RFAL_NFCV_MASKVAL_MAX_16SLOT_LEN 60U /*!< Mask value max length in 16 Slot mode in bits Digital 2.1 9.6.1.6 */ -#define RFAL_NFCV_MAX_SLOTS 16U /*!< NFC-V max number of Slots */ -#define RFAL_NFCV_INV_REQ_HEADER_LEN 3U /*!< INVENTORY_REQ header length (INV_FLAG, CMD, MASK_LEN) */ -#define RFAL_NFCV_INV_RES_LEN 10U /*!< INVENTORY_RES length */ -#define RFAL_NFCV_WR_MUL_REQ_HEADER_LEN 4U /*!< Write Multiple header length (INV_FLAG, CMD, [UID], BNo, Bno) */ - - -#define RFAL_CMD_LEN 1U /*!< Commandbyte length */ -#define RFAL_NFCV_FLAG_POS 0U /*!< Flag byte position */ -#define RFAL_NFCV_FLAG_LEN 1U /*!< Flag byte length */ -#define RFAL_NFCV_DATASTART_POS 1U /*!< Position of start of data */ -#define RFAL_NFCV_DSFI_LEN 1U /*!< DSFID length */ -#define RFAL_NFCV_SLPREQ_REQ_FLAG 0x22U /*!< SLPV_REQ request flags Digital 2.0 (Candidate) 9.7.1.1 */ - -#define RFAL_NFCV_MAX_COLL_SUPPORTED 16U /*!< Maximum number of collisions supported by the Anticollision loop */ - -#define RFAL_FDT_POLL_MAX rfalConvMsTo1fc(20) /*!< Maximum Wait time FDTV,EOF 20 ms Digital 2.0 B.5 */ - - - -/*! Time from special frame to EOF - * ISO15693 2009 10.4.2 : 20ms - * NFC Forum defines Digital 2.0 9.7.4 : FDTV,EOF = [10 ; 20]ms - */ -#define RFAL_NFCV_FDT_EOF 20U - - - -/*! Time between slots - ISO 15693 defines t3min depending on modulation depth and data rate. - * With only high-bitrate supported, AM modulation and a length of 12 bytes (96bits) for INV_RES we get: - * - ISO t3min = 96/26 ms + 300us = 4 ms - * - NFC Forum defines FDTV,INVENT_NORES = (4394 + 2048)/fc. Digital 2.0 B.5*/ -#define RFAL_NFCV_FDT_V_INVENT_NORES 4U - - - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! NFC-V INVENTORY_REQ format Digital 2.0 9.6.1 */ -typedef struct -{ - uint8_t INV_FLAG; /*!< Inventory Flags */ - uint8_t CMD; /*!< Command code: 01h */ - uint8_t MASK_LEN; /*!< Mask Value Length */ - uint8_t MASK_VALUE[RFAL_NFCV_MASKVAL_MAX_LEN]; /*!< Mask Value */ -} rfalNfcvInventoryReq; - - -/*! NFC-V SLP_REQ format Digital 2.0 (Candidate) 9.7.1 */ -typedef struct -{ - uint8_t REQ_FLAG; /*!< Request Flags */ - uint8_t CMD; /*!< Command code: 02h */ - uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< Mask Value */ -} rfalNfcvSlpvReq; - - -/*! Container for a collision found during Anticollision loop */ -typedef struct -{ - uint8_t maskLen; - uint8_t maskVal[RFAL_NFCV_MASKVAL_MAX_LEN]; -}rfalNfcvCollision; - - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -static ReturnCode rfalNfcvParseError( uint8_t err ); - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ - -/* -****************************************************************************** -* LOCAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -static ReturnCode rfalNfcvParseError( uint8_t err ) -{ - switch(err) - { - case RFAL_NFCV_ERROR_CMD_NOT_SUPPORTED: - case RFAL_NFCV_ERROR_OPTION_NOT_SUPPORTED: - return ERR_NOTSUPP; - - case RFAL_NFCV_ERROR_CMD_NOT_RECOGNIZED: - return ERR_PROTO; - - case RFAL_NFCV_ERROR_WRITE_FAILED: - return ERR_WRITE; - - default: - return ERR_REQUEST; - } -} - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerInitialize( void ) -{ - ReturnCode ret; - - EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCV, RFAL_BR_26p48, RFAL_BR_26p48 ) ); - rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); - - rfalSetGT( RFAL_GT_NFCV ); - rfalSetFDTListen( RFAL_FDT_LISTEN_NFCV_POLLER ); - rfalSetFDTPoll( RFAL_FDT_POLL_NFCV_POLLER ); - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerCheckPresence( rfalNfcvInventoryRes *invRes ) -{ - ReturnCode ret; - - /* INVENTORY_REQ with 1 slot and no Mask Activity 2.0 (Candidate) 9.2.3.32 */ - ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_1, 0, NULL, invRes, NULL ); - - if( (ret == ERR_RF_COLLISION) || (ret == ERR_CRC) || - (ret == ERR_FRAMING) || (ret == ERR_PROTO) ) - { - ret = ERR_NONE; - } - - return ret; -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerInventory( rfalNfcvNumSlots nSlots, uint8_t maskLen, const uint8_t *maskVal, rfalNfcvInventoryRes *invRes, uint16_t* rcvdLen ) -{ - ReturnCode ret; - rfalNfcvInventoryReq invReq; - uint16_t rxLen; - - if( ((maskVal == NULL) && (maskLen != 0U)) || (invRes == NULL) ) - { - return ERR_PARAM; - } - - invReq.INV_FLAG = (RFAL_NFCV_INV_REQ_FLAG | (uint8_t)nSlots); - invReq.CMD = RFAL_NFCV_CMD_INVENTORY; - invReq.MASK_LEN = (uint8_t)MIN( maskLen, ((nSlots == RFAL_NFCV_NUM_SLOTS_1) ? RFAL_NFCV_MASKVAL_MAX_1SLOT_LEN : RFAL_NFCV_MASKVAL_MAX_16SLOT_LEN) ); /* Digital 2.0 9.6.1.6 */ - - if( rfalConvBitsToBytes(invReq.MASK_LEN) > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY( invReq.MASK_VALUE, maskVal, rfalConvBitsToBytes(invReq.MASK_LEN) ); - } - - ret = rfalISO15693TransceiveAnticollisionFrame( (uint8_t*)&invReq, (uint8_t)(RFAL_NFCV_INV_REQ_HEADER_LEN + rfalConvBitsToBytes(invReq.MASK_LEN)), (uint8_t*)invRes, sizeof(rfalNfcvInventoryRes), &rxLen ); - - /* Check for optional output parameter */ - if( rcvdLen != NULL ) - { - *rcvdLen = rxLen; - } - - if( ret == ERR_NONE ) - { - if( rxLen != rfalConvBytesToBits(RFAL_NFCV_INV_RES_LEN + RFAL_NFCV_CRC_LEN) ) - { - return ERR_PROTO; - } - } - - return ret; -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt ) -{ - ReturnCode ret; - uint8_t slotNum; - uint16_t rcvdLen; - uint8_t colIt; - uint8_t colCnt; - uint8_t colPos; - bool colPending; - rfalNfcvCollision colFound[RFAL_NFCV_MAX_COLL_SUPPORTED]; - - - if( (nfcvDevList == NULL) || (devCnt == NULL) ) - { - return ERR_PARAM; - } - - /* Initialize parameters */ - *devCnt = 0; - colIt = 0; - colCnt = 0; - colPending = false; - ST_MEMSET(colFound, 0x00, (sizeof(rfalNfcvCollision)*RFAL_NFCV_MAX_COLL_SUPPORTED) ); - - if( devLimit > 0U ) /* MISRA 21.18 */ - { - ST_MEMSET(nfcvDevList, 0x00, (sizeof(rfalNfcvListenDevice)*devLimit) ); - } - - NO_WARNING(colPending); /* colPending is not exposed externally, in future it might become exposed/ouput parameter */ - - if( compMode == RFAL_COMPLIANCE_MODE_NFC ) - { - /* Send INVENTORY_REQ with one slot Activity 2.0 9.3.7.1 (Symbol 0) */ - ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_1, 0, NULL, &nfcvDevList->InvRes, NULL ); - - if( ret == ERR_TIMEOUT ) /* Exit if no device found Activity 2.0 9.3.7.2 (Symbol 1) */ - { - return ERR_NONE; - } - if( ret == ERR_NONE ) /* Device found without transmission error/collision Activity 2.0 9.3.7.3 (Symbol 2) */ - { - (*devCnt)++; - return ERR_NONE; - } - - /* A Collision has been identified Activity 2.0 9.3.7.2 (Symbol 3) */ - colPending = true; - colCnt = 1; - - /* Check if the Collision Resolution is set to perform only Collision detection Activity 2.0 9.3.7.5 (Symbol 4)*/ - if( devLimit == 0U ) - { - return ERR_RF_COLLISION; - } - - platformDelay(RFAL_NFCV_FDT_V_INVENT_NORES); - - /*******************************************************************************/ - /* Collisions pending, Anticollision loop must be executed */ - /*******************************************************************************/ - } - else - { - /* Advance to 16 slots below without mask. Will give a good chance to identify multiple cards */ - colPending = true; - colCnt = 1; - } - - - /* Execute until all collisions are resolved Activity 2.0 9.3.7.16 (Symbol 17) */ - do - { - /* Activity 2.0 9.3.7.5 (Symbol 6) */ - colPending = false; - slotNum = 0; - - do - { - if( slotNum == 0U ) - { - /* Send INVENTORY_REQ with 16 slots Activity 2.0 9.3.7.7 (Symbol 8) */ - ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_16, colFound[colIt].maskLen, colFound[colIt].maskVal, &nfcvDevList[(*devCnt)].InvRes, &rcvdLen ); - } - else - { - ret = rfalISO15693TransceiveEOFAnticollision( (uint8_t*)&nfcvDevList[(*devCnt)].InvRes, sizeof(rfalNfcvInventoryRes), &rcvdLen ); - } - slotNum++; - - /*******************************************************************************/ - if( ret != ERR_TIMEOUT ) - { - if( rcvdLen < rfalConvBytesToBits(RFAL_NFCV_INV_RES_LEN + RFAL_NFCV_CRC_LEN) ) - { /* If only a partial frame was received make sure the FDT_V_INVENT_NORES is fulfilled */ - platformDelay(RFAL_NFCV_FDT_V_INVENT_NORES); - } - - if( ret == ERR_NONE ) - { - /* Check if the device found is already on the list and its response is a valid INVENTORY_RES */ - if( rcvdLen == rfalConvBytesToBits(RFAL_NFCV_INV_RES_LEN + RFAL_NFCV_CRC_LEN) ) - { - /* Activity 2.0 9.3.7.15 (Symbol 11) */ - (*devCnt)++; - } - } - else /* Treat everything else as collision */ - { - /* Activity 2.0 9.3.7.15 (Symbol 16) */ - colPending = true; - - - /*******************************************************************************/ - /* Ensure that this collision still fits on the container */ - if( colCnt < RFAL_NFCV_MAX_COLL_SUPPORTED ) - { - /* Store this collision on the container to be resolved later */ - /* Activity 2.0 9.3.7.15 (Symbol 16): add the collision information - * (MASK_VAL + SN) to the list containing the collision information */ - ST_MEMCPY(colFound[colCnt].maskVal, colFound[colIt].maskVal, RFAL_NFCV_UID_LEN); - colPos = colFound[colIt].maskLen; - colFound[colCnt].maskVal[(colPos/RFAL_BITS_IN_BYTE)] &= (uint8_t)((1U << (colPos % RFAL_BITS_IN_BYTE)) - 1U); - colFound[colCnt].maskVal[(colPos/RFAL_BITS_IN_BYTE)] |= (uint8_t)((slotNum-1U) << (colPos % RFAL_BITS_IN_BYTE)); - colFound[colCnt].maskVal[((colPos/RFAL_BITS_IN_BYTE)+1U)] = (uint8_t)((slotNum-1U) >> (RFAL_BITS_IN_BYTE - (colPos % RFAL_BITS_IN_BYTE))); - - colFound[colCnt].maskLen = (colFound[colIt].maskLen + 4U); - - colCnt++; - } - } - } - else - { - /* Timeout */ - platformDelay(RFAL_NFCV_FDT_V_INVENT_NORES); - } - - /* Check if devices found have reached device limit Activity 2.0 9.3.7.15 (Symbol 16) */ - if( *devCnt >= devLimit ) - { - return ERR_NONE; - } - } while( slotNum < RFAL_NFCV_MAX_SLOTS ); /* Slot loop */ - colIt++; - } while( colIt < colCnt ); /* Collisions found loop */ - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerSleepCollisionResolution( uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt ) -{ - uint8_t locDevCnt; - ReturnCode ret; - uint8_t i; - - if( (nfcvDevList == NULL) || (devCnt == NULL) ) - { - return ERR_PARAM; - } - - *devCnt = 0; - - do - { - locDevCnt = 0; - ret = rfalNfcvPollerCollisionResolution( RFAL_COMPLIANCE_MODE_ISO, (devLimit - *devCnt), &nfcvDevList[*devCnt], &locDevCnt ); - - for( i = *devCnt; i < (*devCnt + locDevCnt); i++ ) - { - rfalNfcvPollerSleep( 0x00, nfcvDevList[i].InvRes.UID ); - nfcvDevList[i].isSleep = true; - } - *devCnt += locDevCnt; - } - while( (locDevCnt > 0U) && (*devCnt < devLimit) ); - - return ret; -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerSleep( uint8_t flags, const uint8_t* uid ) -{ - ReturnCode ret; - rfalNfcvSlpvReq slpReq; - uint8_t rxBuf; /* dummy buffer, just to perform Rx */ - - if( uid == NULL ) - { - return ERR_PARAM; - } - - /* Compute SLPV_REQ */ - slpReq.REQ_FLAG = (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS); /* Should be with UID according Digital 2.0 (Candidate) 9.7.1.1 */ - slpReq.CMD = RFAL_NFCV_CMD_SLPV; - ST_MEMCPY( slpReq.UID, uid, RFAL_NFCV_UID_LEN ); - - /* NFC Forum device SHALL wait at least FDTVpp to consider the SLPV acknowledged (FDTVpp = FDTVpoll) Digital 2.0 (Candidate) 9.7 9.8.2 */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&slpReq, sizeof(rfalNfcvSlpvReq), &rxBuf, sizeof(rxBuf), NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_NFCV_POLLER ); - if( ret != ERR_TIMEOUT ) - { - return ret; - } - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerSelect( uint8_t flags, const uint8_t* uid ) -{ - uint16_t rcvLen; - rfalNfcvGenericRes res; - - if( uid == NULL ) - { - return ERR_PARAM; - } - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_SELECT, flags, RFAL_NFCV_PARAM_SKIP, uid, NULL, 0U, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t bn; - - bn = blockNum; - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_READ_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, &bn, sizeof(uint8_t), rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, const uint8_t* wrData, uint8_t blockLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_LEN + RFAL_NFCV_MAX_BLOCK_LEN)]; - uint8_t dataLen; - uint16_t rcvLen; - rfalNfcvGenericRes res; - - /* Check for valid parameters */ - if( (blockLen == 0U) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) || (wrData == NULL) ) - { - return ERR_PARAM; - } - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = blockNum; /* Set Block Number (8 bits) */ - ST_MEMCPY( &data[dataLen], wrData, blockLen ); /* Append Block data to write */ - dataLen += blockLen; - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerLockBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum ) -{ - uint16_t rcvLen; - rfalNfcvGenericRes res; - uint8_t bn; - - bn = blockNum; - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_LOCK_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, &bn, sizeof(uint8_t), (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_LEN + RFAL_NFCV_BLOCKNUM_LEN)]; - uint8_t dataLen; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = firstBlockNum; /* Set first Block Number */ - data[dataLen++] = numOfBlocks; /* Set number of blocks to read */ - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_READ_MULTIPLE_BLOCKS, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen ) -{ - ReturnCode ret; - uint16_t rcvLen; - uint16_t reqLen; - rfalNfcvGenericRes res; - uint16_t msgIt; - - /* Calculate required buffer length */ - reqLen = (uint16_t)((uid != NULL) ? (RFAL_NFCV_WR_MUL_REQ_HEADER_LEN + RFAL_NFCV_UID_LEN + wrDataLen) : (RFAL_NFCV_WR_MUL_REQ_HEADER_LEN + wrDataLen)); - - if( (reqLen > txBufLen) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) || ((((uint16_t)numOfBlocks) * (uint16_t)blockLen) != wrDataLen) || (numOfBlocks == 0U) || (wrData == NULL) ) - { - return ERR_PARAM; - } - - msgIt = 0; - - /* Compute Request Command */ - txBuf[msgIt++] = (uint8_t)(flags & (~((uint32_t)RFAL_NFCV_REQ_FLAG_ADDRESS) & ~((uint32_t)RFAL_NFCV_REQ_FLAG_SELECT))); - txBuf[msgIt++] = RFAL_NFCV_CMD_WRITE_MULTIPLE_BLOCKS; - - /* Check if Request is to be sent in Addressed or Selected mode */ - if( uid != NULL ) - { - txBuf[RFAL_NFCV_FLAG_POS] |= (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS; - ST_MEMCPY( &txBuf[msgIt], uid, RFAL_NFCV_UID_LEN ); - msgIt += (uint8_t)RFAL_NFCV_UID_LEN; - } - else - { - txBuf[RFAL_NFCV_FLAG_POS] |= (uint8_t)RFAL_NFCV_REQ_FLAG_SELECT; - } - - txBuf[msgIt++] = firstBlockNum; - txBuf[msgIt++] = (numOfBlocks - 1U); - - if( wrDataLen > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY( &txBuf[msgIt], wrData, wrDataLen ); - msgIt += wrDataLen; - } - - /* Transceive Command */ - ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX ); - - if( ret != ERR_NONE ) - { - return ret; - } - - /* Check if the response minimum length has been received */ - if( rcvLen < (uint8_t)RFAL_NFCV_FLAG_LEN ) - { - return ERR_PROTO; - } - - /* Check if an error has been signalled */ - if( (res.RES_FLAG & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U ) - { - return rfalNfcvParseError( *res.data ); - } - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[RFAL_NFCV_BLOCKNUM_EXTENDED_LEN]; - uint8_t dataLen; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)blockNum; /* TS T5T 1.0 BNo is considered as a multi-byte field. TS T5T 1.0 5.1.1.13 multi-byte field follows [DIGITAL]. [DIGITAL] 9.3.1 A multiple byte field is transmitted LSB first. */ - data[dataLen++] = (uint8_t)((blockNum >> 8U) & 0xFFU); - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_READ_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerExtendedWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_EXTENDED_LEN + RFAL_NFCV_MAX_BLOCK_LEN)]; - uint8_t dataLen; - uint16_t rcvLen; - rfalNfcvGenericRes res; - - /* Check for valid parameters */ - if( (blockLen == 0U) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) ) - { - return ERR_PARAM; - } - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)blockNum; /* TS T5T 1.0 BNo is considered as a multi-byte field. TS T5T 1.0 5.1.1.13 multi-byte field follows [DIGITAL]. [DIGITAL] 9.3.1 A multiple byte field is transmitted LSB first. */ - data[dataLen++] = (uint8_t)((blockNum >> 8U) & 0xFFU); - ST_MEMCPY( &data[dataLen], wrData, blockLen ); /* Append Block data to write */ - dataLen += blockLen; - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_WRITE_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerExtendedLockSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum ) -{ - uint8_t data[RFAL_NFCV_BLOCKNUM_EXTENDED_LEN]; - uint8_t dataLen; - uint16_t rcvLen; - rfalNfcvGenericRes res; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)blockNum; /* TS T5T 1.0 BNo is considered as a multi-byte field. TS T5T 1.0 5.1.1.13 multi-byte field follows [DIGITAL]. [DIGITAL] 9.3.1 A multiple byte field is transmitted LSB first. */ - data[dataLen++] = (uint8_t)((blockNum >> 8U) & 0xFFU); - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_LOCK_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerExtendedReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_EXTENDED_LEN + RFAL_NFCV_BLOCKNUM_EXTENDED_LEN)]; - uint8_t dataLen; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)((firstBlockNum >> 0U) & 0xFFU); - data[dataLen++] = (uint8_t)((firstBlockNum >> 8U) & 0xFFU); - data[dataLen++] = (uint8_t)((numOfBlocks >> 0U) & 0xFFU); - data[dataLen++] = (uint8_t)((numOfBlocks >> 8U) & 0xFFU); - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_READ_MULTIPLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerExtendedWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen ) -{ - ReturnCode ret; - uint16_t rcvLen; - uint16_t reqLen; - rfalNfcvGenericRes res; - uint16_t msgIt; - uint16_t nBlocks; - - /* Calculate required buffer length */ - reqLen = ((uid != NULL) ? (RFAL_NFCV_WR_MUL_REQ_HEADER_LEN + RFAL_NFCV_UID_LEN + wrDataLen) : (RFAL_NFCV_WR_MUL_REQ_HEADER_LEN + wrDataLen) ); - - if( (reqLen > txBufLen) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) || (( (uint16_t)numOfBlocks * (uint16_t)blockLen) != wrDataLen) || (numOfBlocks == 0U) ) - { - return ERR_PARAM; - } - - msgIt = 0; - nBlocks = (numOfBlocks - 1U); - - /* Compute Request Command */ - txBuf[msgIt++] = (uint8_t)(flags & (~((uint32_t)RFAL_NFCV_REQ_FLAG_ADDRESS) & ~((uint32_t)RFAL_NFCV_REQ_FLAG_SELECT))); - txBuf[msgIt++] = RFAL_NFCV_CMD_EXTENDED_WRITE_MULTIPLE_BLOCK; - - /* Check if Request is to be sent in Addressed or Selected mode */ - if( uid != NULL ) - { - txBuf[RFAL_NFCV_FLAG_POS] |= (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS; - ST_MEMCPY( &txBuf[msgIt], uid, RFAL_NFCV_UID_LEN ); - msgIt += (uint8_t)RFAL_NFCV_UID_LEN; - } - else - { - txBuf[RFAL_NFCV_FLAG_POS] |= (uint8_t)RFAL_NFCV_REQ_FLAG_SELECT; - } - - txBuf[msgIt++] = (uint8_t)((firstBlockNum >> 0) & 0xFFU); - txBuf[msgIt++] = (uint8_t)((firstBlockNum >> 8) & 0xFFU); - txBuf[msgIt++] = (uint8_t)((nBlocks >> 0) & 0xFFU); - txBuf[msgIt++] = (uint8_t)((nBlocks >> 8) & 0xFFU); - - if( wrDataLen > 0U ) /* MISRA 21.18 */ - { - ST_MEMCPY( &txBuf[msgIt], wrData, wrDataLen ); - msgIt += wrDataLen; - } - - /* Transceive Command */ - ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX ); - - if( ret != ERR_NONE ) - { - return ret; - } - - /* Check if the response minimum length has been received */ - if( rcvLen < (uint8_t)RFAL_NFCV_FLAG_LEN ) - { - return ERR_PROTO; - } - - /* Check if an error has been signalled */ - if( (res.RES_FLAG & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U ) - { - return rfalNfcvParseError( *res.data ); - } - - return ERR_NONE; -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_GET_SYS_INFO, flags, RFAL_NFCV_PARAM_SKIP, uid, NULL, 0U, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerExtendedGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t requestField, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_GET_SYS_INFO, flags, requestField, uid, NULL, 0U, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalNfcvPollerTransceiveReq( uint8_t cmd, uint8_t flags, uint8_t param, const uint8_t* uid, const uint8_t *data, uint16_t dataLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - ReturnCode ret; - rfalNfcvGenericReq req; - uint8_t msgIt; - rfalBitRate rxBR; - bool fastMode; - - msgIt = 0; - fastMode = false; - - /* Check for valid parameters */ - if( (rxBuf == NULL) || (rcvLen == NULL) || ((dataLen > 0U) && (data == NULL)) || - (dataLen > ((uid != NULL) ? RFAL_NFCV_MAX_GEN_DATA_LEN : (RFAL_NFCV_MAX_GEN_DATA_LEN - RFAL_NFCV_UID_LEN))) ) - { - return ERR_PARAM; - } - - - /* Check if the command is an ST's Fast command */ - if( (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK) || (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_EXTENDED_READ_SINGLE_BLOCK) || - (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS) || (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_EXTENDED_READ_MULTIPLE_BLOCKS) || - (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_WRITE_MESSAGE) || (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_MESSAGE_LENGTH) || - (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_MESSAGE) || (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_DYN_CONFIGURATION) || - (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_WRITE_DYN_CONFIGURATION) ) - { - /* Store current Rx bit rate and move to fast mode */ - rfalGetBitRate( NULL, &rxBR ); - rfalSetBitRate( RFAL_BR_KEEP, RFAL_BR_52p97 ); - - fastMode = true; - } - - - /* Compute Request Command */ - req.REQ_FLAG = (uint8_t)(flags & (~((uint32_t)RFAL_NFCV_REQ_FLAG_ADDRESS) & ~((uint32_t)RFAL_NFCV_REQ_FLAG_SELECT))); - req.CMD = cmd; - - /* Prepend parameter on ceratin proprietary requests: IC Manuf, Parameters */ - if( param != RFAL_NFCV_PARAM_SKIP ) - { - req.payload.data[msgIt++] = param; - } - - /* Check if request is to be sent in Addressed or Selected mode */ - if( uid != NULL ) - { - req.REQ_FLAG |= (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS; - ST_MEMCPY( &req.payload.data[msgIt], uid, RFAL_NFCV_UID_LEN ); - msgIt += RFAL_NFCV_UID_LEN; - } - else - { - req.REQ_FLAG |= (uint8_t)RFAL_NFCV_REQ_FLAG_SELECT; - } - - if( dataLen > 0U ) - { - ST_MEMCPY( &req.payload.data[msgIt], data, dataLen); - msgIt += (uint8_t)dataLen; - } - - /* Transceive Command */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, (RFAL_CMD_LEN + RFAL_NFCV_FLAG_LEN +(uint16_t)msgIt), rxBuf, rxBufLen, rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX ); - - /* If the Option Flag is set in certain commands an EOF needs to be sent after 20ms to retrieve the VICC response ISO15693-3 2009 10.4.2 & 10.4.3 & 10.4.5 */ - if( ((flags & (uint8_t)RFAL_NFCV_REQ_FLAG_OPTION) != 0U) && ((cmd == (uint8_t)RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK) || (cmd == (uint8_t)RFAL_NFCV_CMD_WRITE_MULTIPLE_BLOCKS) || - (cmd == (uint8_t)RFAL_NFCV_CMD_LOCK_BLOCK) || (cmd == (uint8_t)RFAL_NFCV_CMD_EXTENDED_WRITE_SINGLE_BLOCK) || - (cmd == (uint8_t)RFAL_NFCV_CMD_EXTENDED_LOCK_SINGLE_BLOCK) || (cmd == (uint8_t)RFAL_NFCV_CMD_EXTENDED_WRITE_MULTIPLE_BLOCK)) ) - { - ret = rfalISO15693TransceiveEOF( rxBuf, (uint8_t)rxBufLen, rcvLen ); - } - - /* Restore Rx BitRate */ - if( fastMode ) - { - rfalSetBitRate( RFAL_BR_KEEP, rxBR ); - } - - if( ret != ERR_NONE ) - { - return ret; - } - - /* Check if the response minimum length has been received */ - if( (*rcvLen) < (uint8_t)RFAL_NFCV_FLAG_LEN ) - { - return ERR_PROTO; - } - - /* Check if an error has been signalled */ - if( (rxBuf[RFAL_NFCV_FLAG_POS] & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U ) - { - return rfalNfcvParseError( rxBuf[RFAL_NFCV_DATASTART_POS] ); - } - - return ERR_NONE; -} - -#endif /* RFAL_FEATURE_NFCV */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_rfst25r3911.c b/Software/Middlewares/ST/rfal/Src/rfal_rfst25r3911.c deleted file mode 100644 index c9f9979..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_rfst25r3911.c +++ /dev/null @@ -1,3733 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - - -/* - * PROJECT: ST25R3911 firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file - * - * \author Gustavo Patricio - * - * \brief RF Abstraction Layer (RFAL) - * - * RFAL implementation for ST25R3911 - */ - - -/* -****************************************************************************** -* INCLUDES -****************************************************************************** -*/ - -#include "rfal_chip.h" -#include "utils.h" -#include "st25r3911.h" -#include "st25r3911_com.h" -#include "st25r3911_interrupt.h" -#include "rfal_analogConfig.h" -#include "rfal_iso15693_2.h" - -/* - ****************************************************************************** - * ENABLE SWITCHS - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_LISTEN_MODE - #error " RFAL: Module configuration missing. Please enable/disable support for Listen Mode: RFAL_FEATURE_LISTEN_MODE " -#endif - -#ifndef RFAL_FEATURE_WAKEUP_MODE - #error " RFAL: Module configuration missing. Please enable/disable support for Wake-Up Mode: RFAL_FEATURE_WAKEUP_MODE " -#endif - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! Struct that holds all involved on a Transceive including the context passed by the caller */ -typedef struct{ - rfalTransceiveState state; /*!< Current transceive state */ - rfalTransceiveState lastState; /*!< Last transceive state (debug purposes) */ - ReturnCode status; /*!< Current status/error of the transceive */ - bool rxse; /*!< Flag indicating if RXE was received with RXS */ - - rfalTransceiveContext ctx; /*!< The transceive context given by the caller */ -} rfalTxRx; - - -/*! Struct that holds all context for the Listen Mode */ -typedef struct{ - rfalLmState state; /*!< Current Listen Mode state */ - rfalBitRate brDetected; /*!< Last bit rate detected */ - - uint8_t* rxBuf; /*!< Location to store incoming data in Listen Mode */ - uint16_t rxBufLen; /*!< Length of rxBuf */ - uint16_t* rxLen; /*!< Pointer to write the data length placed into rxBuf */ - bool dataFlag; /*!< Listen Mode current Data Flag */ -} rfalLm; - - -/*! Struct that holds all context for the Wake-Up Mode */ -typedef struct{ - rfalWumState state; /*!< Current Wake-Up Mode state */ - rfalWakeUpConfig cfg; /*!< Current Wake-Up Mode context */ -} rfalWum; - - -/*! Struct that holds the timings GT and FDTs */ -typedef struct{ - uint32_t GT; /*!< GT in 1/fc */ - uint32_t FDTListen; /*!< FDTListen in 1/fc */ - uint32_t FDTPoll; /*!< FDTPoll in 1/fc */ -} rfalTimings; - - -/*! Struct that holds the software timers */ -typedef struct{ - uint32_t GT; /*!< RFAL's GT timer */ - uint32_t FWT; /*!< FWT/RWT timer for Active P2P*/ - uint32_t RXE; /*!< Timer between RXS and RXE */ -} rfalTimers; - - -/*! Struct that holds the RFAL's callbacks */ -typedef struct{ - rfalPreTxRxCallback preTxRx; /*!< RFAL's Pre TxRx callback */ - rfalPostTxRxCallback postTxRx; /*!< RFAL's Post TxRx callback */ -} rfalCallbacks; - - -/*! Struct that holds counters to control the FIFO on Tx and Rx */ -typedef struct{ - uint16_t expWL; /*!< The amount of bytes expected to be Tx when a WL interrupt occours */ - uint16_t bytesTotal; /*!< Total bytes to be transmitted OR the total bytes received */ - uint16_t bytesWritten;/*!< Amount of bytes already written on FIFO (Tx) OR read (RX) from FIFO and written on rxBuffer*/ - uint8_t status[ST25R3911_FIFO_STATUS_LEN]; /*!< FIFO Status Registers */ -} rfalFIFO; - - -/*! Struct that holds RFAL's configuration settings */ -typedef struct{ - uint8_t obsvModeTx; /*!< RFAL's config of the ST25R3911's observation mode while Tx */ - uint8_t obsvModeRx; /*!< RFAL's config of the ST25R3911's observation mode while Rx */ - rfalEHandling eHandling; /*!< RFAL's error handling config/mode */ -} rfalConfigs; - - -/*! Struct that holds NFC-F data - Used only inside rfalFelicaPoll() (static to avoid adding it into stack) */ -typedef struct{ - rfalFeliCaPollRes pollResponses[RFAL_FELICA_POLL_MAX_SLOTS]; /* FeliCa Poll response container for 16 slots */ -} rfalNfcfWorkingData; - - -/*! Struct that holds NFC-V current context - * - * 96 bytes is FIFO size of ST25R3911, codingBuffer has to be big enough for coping with maximum response size (Manchester coded) - * - current implementation expects it be written in one bulk into FIFO - * - needs to be above FIFO water level of ST25R3911 (64) - * - 65 is actually 1 byte too much, but ~75us in 1of256 another byte is already gone - * - * - inventory requests responses: 14 bytes - * - Max read single block responses: 32 bytes - * - Read multiple block responses: variable - * - * ISO15693 frame: SOF + Flags + Data + CRC + EOF - */ -typedef struct{ - uint8_t codingBuffer[((2 + 255 + 3)*2)];/*!< Coding buffer, length MUST be above 64: [65; ...] */ - uint16_t nfcvOffset; /*!< Offset needed for ISO15693 coding function */ - rfalTransceiveContext origCtx; /*!< Context provided by user */ - uint16_t ignoreBits; /*!< Number of bits at the beginning of a frame to be ignored when decoding*/ -} rfalNfcvWorkingData; - - -/*! RFAL instance */ -typedef struct{ - rfalState state; /*!< RFAL's current state */ - rfalMode mode; /*!< RFAL's current mode */ - rfalBitRate txBR; /*!< RFAL's current Tx Bit Rate */ - rfalBitRate rxBR; /*!< RFAL's current Rx Bit Rate */ - bool field; /*!< Current field state (On / Off) */ - - rfalConfigs conf; /*!< RFAL's configuration settings */ - rfalTimings timings; /*!< RFAL's timing setting */ - rfalTxRx TxRx; /*!< RFAL's transceive management */ - rfalFIFO fifo; /*!< RFAL's FIFO management */ - rfalTimers tmr; /*!< RFAL's Software timers */ - rfalCallbacks callbacks; /*!< RFAL's callbacks */ - -#if RFAL_FEATURE_LISTEN_MODE - rfalLm Lm; /*!< RFAL's listen mode management */ -#endif /* RFAL_FEATURE_LISTEN_MODE */ - -#if RFAL_FEATURE_WAKEUP_MODE - rfalWum wum; /*!< RFAL's Wake-up mode management */ -#endif /* RFAL_FEATURE_WAKEUP_MODE */ - -#if RFAL_FEATURE_NFCF - rfalNfcfWorkingData nfcfData; /*!< RFAL's working data when supporting NFC-F */ -#endif /* RFAL_FEATURE_NFCF */ - -#if RFAL_FEATURE_NFCV - rfalNfcvWorkingData nfcvData; /*!< RFAL's working data when supporting NFC-V */ -#endif /* RFAL_FEATURE_NFCV */ - -} rfal; - - - -/*! Felica's command set */ -typedef enum -{ - FELICA_CMD_POLLING = 0x00, /*!< Felica Poll/REQC command (aka SENSF_REQ) to identify a card */ - FELICA_CMD_POLLING_RES = 0x01, /*!< Felica Poll/REQC command (aka SENSF_RES) response */ - FELICA_CMD_REQUEST_SERVICE = 0x02, /*!< verify the existence of Area and Service */ - FELICA_CMD_REQUEST_RESPONSE = 0x04, /*!< verify the existence of a card */ - FELICA_CMD_READ_WITHOUT_ENCRYPTION = 0x06, /*!< read Block Data from a Service that requires no authentication */ - FELICA_CMD_WRITE_WITHOUT_ENCRYPTION = 0x08, /*!< write Block Data to a Service that requires no authentication */ - FELICA_CMD_REQUEST_SYSTEM_CODE = 0x0c, /*!< acquire the System Code registered to a card */ - FELICA_CMD_AUTHENTICATION1 = 0x10, /*!< authenticate a card */ - FELICA_CMD_AUTHENTICATION2 = 0x12, /*!< allow a card to authenticate a Reader/Writer */ - FELICA_CMD_READ = 0x14, /*!< read Block Data from a Service that requires authentication */ - FELICA_CMD_WRITE = 0x16, /*!< write Block Data to a Service that requires authentication */ -}t_rfalFeliCaCmd; - -/* -****************************************************************************** -* GLOBAL DEFINES -****************************************************************************** -*/ - -#define RFAL_FIFO_IN_LT_32 32U /*!< Number of bytes in the FIFO when WL interrupt occurs while Tx ( fifo_lt: 0 ) */ -#define RFAL_FIFO_IN_LT_16 16U /*!< Number of bytes in the FIFO when WL interrupt occurs while Tx ( fifo_lt: 1 ) */ - -#define RFAL_FIFO_OUT_LT_32 (ST25R3911_FIFO_DEPTH - RFAL_FIFO_IN_LT_32) /*!< Number of bytes sent/out of the FIFO when WL interrupt occurs while Tx ( fifo_lt: 0 ) */ -#define RFAL_FIFO_OUT_LT_16 (ST25R3911_FIFO_DEPTH - RFAL_FIFO_IN_LT_16) /*!< Number of bytes sent/out of the FIFO when WL interrupt occurs while Tx ( fifo_lt: 1 ) */ - -#define RFAL_FIFO_STATUS_REG1 0U /*!< Location of FIFO status register 1 in local copy */ -#define RFAL_FIFO_STATUS_REG2 1U /*!< Location of FIFO status register 2 in local copy */ -#define RFAL_FIFO_STATUS_INVALID 0xFFU /*!< Value indicating that the local FIFO status in invalid|cleared */ - -#define RFAL_ST25R3911_GPT_MAX_1FC rfalConv8fcTo1fc( 0xFFFFU ) /*!< Max GPT steps in 1fc (0xFFFF steps of 8/fc => 0xFFFF * 590ns = 38,7ms) */ -#define RFAL_ST25R3911_NRT_MAX_1FC rfalConv4096fcTo1fc( 0xFFFFU ) /*!< Max NRT steps in 1fc (0xFFFF steps of 4096/fc => 0xFFFF * 302us = 19.8s ) */ -#define RFAL_ST25R3911_NRT_DISABLED 0U /*!< NRT Disabled: All 0 No-response timer is not started, wait forever */ -#define RFAL_ST25R3911_MRT_MAX_1FC rfalConv64fcTo1fc( 0x00FFU ) /*!< Max MRT steps in 1fc (0x00FF steps of 64/fc => 0x00FF * 4.72us = 1.2ms ) */ -#define RFAL_ST25R3911_MRT_MIN_1FC rfalConv64fcTo1fc( 0x0004U ) /*!< Min MRT steps in 1fc ( 0<=mrt<=4 ; 4 (64/fc) => 0x0004 * 4.72us = 18.88us ) */ -#define RFAL_ST25R3911_GT_MAX_1FC rfalConvMsTo1fc( 5000U ) /*!< Max GT value allowed in 1/fc */ -#define RFAL_ST25R3911_GT_MIN_1FC rfalConvMsTo1fc(RFAL_ST25R3911_SW_TMR_MIN_1MS) /*!< Min GT value allowed in 1/fc */ -#define RFAL_ST25R3911_SW_TMR_MIN_1MS 1U /*!< Min value of a SW timer in ms */ - -#define RFAL_OBSMODE_DISABLE 0x00U /*!< Observation Mode disabled */ - -#define RFAL_NFC_RX_INCOMPLETE_LEN (uint8_t)1U /*!< Threshold value where incoming rx may be considered as incomplete in NFC */ -#define RFAL_EMVCO_RX_MAXLEN (uint8_t)4U /*!< Maximum value where EMVCo to apply special error handling */ -#define RFAL_EMVCO_RX_MINLEN (uint8_t)2U /*!< Minimum value where EMVCo to apply special error handling */ - -#define RFAL_NORXE_TOUT 10U /*!< Timeout to be used on a potential missing RXE - Silicon ST25R3911B Errata #1.1 */ - -#define RFAL_ISO14443A_SDD_RES_LEN 5U /*!< SDD_RES | Anticollision (UID CLn) length - rfalNfcaSddRes */ - -#define RFAL_FELICA_POLL_DELAY_TIME 512U /*!< FeliCa Poll Processing time is 2.417 ms ~512*64/fc Digital 1.1 A4 */ -#define RFAL_FELICA_POLL_SLOT_TIME 256U /*!< FeliCa Poll Time Slot duration is 1.208 ms ~256*64/fc Digital 1.1 A4 */ - -#define RFAL_ISO15693_IGNORE_BITS rfalConvBytesToBits(2U) /*!< Ignore collisions before the UID (RES_FLAG + DSFID) */ - - -/*******************************************************************************/ - -#define RFAL_LM_GT rfalConvUsTo1fc(100U) /*!< Listen Mode Guard Time enforced (GT - Passive; TIRFG - Active) */ -#define RFAL_FDT_POLL_ADJUSTMENT rfalConvUsTo1fc(80U) /*!< FDT Poll adjustment: Time between the expiration of GPT to the actual Tx */ -#define RFAL_FDT_LISTEN_MRT_ADJUSTMENT 64U /*!< MRT jitter adjustment: timeout will be between [ tout ; tout + 64 cycles ] */ -#define RFAL_AP2P_FIELDOFF_TRFW rfalConv8fcTo1fc(64U) /*!< Time after TXE and Field Off in AP2P Trfw: 37.76us -> 64 (8/fc) */ - - -/*! FWT adjustment: - * 64 : NRT jitter between TXE and NRT start */ -#define RFAL_FWT_ADJUSTMENT 64U - -/*! FWT ISO14443A adjustment: - * 512 : Initial 4bit length */ -#define RFAL_FWT_A_ADJUSTMENT 512U - -/*! FWT ISO14443B adjustment: - * 2784 : Adjustment for the SOF and initial byte */ -#define RFAL_FWT_B_ADJUSTMENT 2784U - - -/*! FWT FeliCa 212 adjustment: - * 1024 : Length of the two Sync bytes at 212kbps */ -#define RFAL_FWT_F_212_ADJUSTMENT 1024U - -/*! FWT FeliCa 424 adjustment: - * 512 : Length of the two Sync bytes at 424kbps */ -#define RFAL_FWT_F_424_ADJUSTMENT 512U - - -/*! Time between our field Off and other peer field On : Tadt + (n x Trfw) - * Ecma 340 11.1.2 - Tadt: [56.64 , 188.72] us ; n: [0 , 3] ; Trfw = 37.76 us - * Should be: 189 + (3*38) = 303us ; we'll use a more relaxed setting: 605 us */ -#define RFAL_AP2P_FIELDON_TADTTRFW rfalConvUsTo1fc(605U) - - -/*! FDT Listen adjustment for ISO14443A EMVCo 2.6 4.8.1.3 ; Digital 1.1 6.10 - * - * 276: Time from the rising pulse of the pause of the logic '1' (i.e. the time point to measure the deaftime from), - * to the actual end of the EOF sequence (the point where the MRT starts). Please note that the ST25R391x uses the - * ISO14443-2 definition where the EOF consists of logic '0' followed by sequence Y. - */ -#define RFAL_FDT_LISTEN_A_ADJUSTMENT 276U - - -/*! FDT Listen adjustment for ISO14443B EMVCo 2.6 4.8.1.6 ; Digital 1.1 7.9 - * - * 340: Time from the rising edge of the EoS to the starting point of the MRT timer (sometime after the final high - * part of the EoS is completed). - * - * -64: Adjustment for the TR1PUTMIN. - * The TR1PUTMIN of the ST25R3911 is 1152/fc (72/fs). The EMVCo test case TB0000 measures the TR1PUTMIN. - * It takes the default value of TR1PUTMIN (79/fs) and reduces it by 128/fc in every iteration. - * This results in a TR1PUTMIN of 1136/fc (71/fs) for the second iteration. The ST25R3911 sends a NAK because - * the TR1PUTMIN of the ST25R3911 (72/fs) is higher than 71/fs. - * Therefore the test suite assumes TR1PUTMIN of 1264/fc (79/fs). - * The test cases TB340.0 and TB435.0 uses the TR1PUTMIN to send frames too early. In order to correctly - * recognise these frames as being sent too early (starting inside reader deaf time), the MRT has to be - * increased by at least 64/fc (8/fs). - */ -#define RFAL_FDT_LISTEN_B_ADJUSTMENT (340U - 64U) - - -/*! FDT Listen adjustment for ISO15693 - * ISO15693 2000 8.4 t1 MIN = 4192/fc - * ISO15693 2009 9.1 t1 MIN = 4320/fc - * Digital 2.1 B.5 FDTV,LISTEN,MIN = 4310/fc - * Set FDT Listen one step earlier than on the more recent spec versions for greater interoprability - */ -#define RFAL_FDT_LISTEN_V_ADJUSTMENT 128U - - - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - -#define rfalCalcNumBytes( nBits ) (((uint32_t)(nBits) + 7U) / 8U) /*!< Returns the number of bytes required to fit given the number of bits */ - -#define rfalTimerStart( timer, time_ms ) (timer) = platformTimerCreate((uint16_t)(time_ms)) /*!< Configures and starts the RTOX timer */ -#define rfalTimerisExpired( timer ) platformTimerIsExpired( timer ) /*!< Checks if timer has expired */ - -#define rfalST25R3911ObsModeDisable() st25r3911WriteTestRegister(0x01U, 0x00U) /*!< Disable ST25R3911 Observation mode */ -#define rfalST25R3911ObsModeTx() st25r3911WriteTestRegister(0x01U, gRFAL.conf.obsvModeTx) /*!< Enable Observation mode 0x0A CSI: Digital TX modulation signal CSO: none */ -#define rfalST25R3911ObsModeRx() st25r3911WriteTestRegister(0x01U, gRFAL.conf.obsvModeRx) /*!< Enable Observation mode 0x04 CSI: Digital output of AM channel CSO: Digital output of PM channel */ - - -#define rfalCheckDisableObsMode() if(gRFAL.conf.obsvModeRx != 0U){ rfalST25R3911ObsModeDisable(); } /*!< Checks if the observation mode is enabled, and applies on ST25R3911 */ -#define rfalCheckEnableObsModeTx() if(gRFAL.conf.obsvModeTx != 0U){ rfalST25R3911ObsModeTx(); } /*!< Checks if the observation mode is enabled, and applies on ST25R3911 */ -#define rfalCheckEnableObsModeRx() if(gRFAL.conf.obsvModeRx != 0U){ rfalST25R3911ObsModeRx(); } /*!< Checks if the observation mode is enabled, and applies on ST25R3911 */ - - -#define rfalGetIncmplBits( FIFOStatus2 ) (( (FIFOStatus2) >> 1) & 0x07U) /*!< Returns the number of bits from fifo status */ -#define rfalIsIncompleteByteError( error ) (((error) >= ERR_INCOMPLETE_BYTE) && ((error) <= ERR_INCOMPLETE_BYTE_07)) /*!< Checks if given error is a Incomplete error */ - -#define rfalAdjACBR( b ) (((uint16_t)(b) >= (uint16_t)RFAL_BR_52p97) ? (uint16_t)(b) : ((uint16_t)(b)+1U)) /*!< Adjusts ST25R391x Bit rate to Analog Configuration */ -#define rfalConvBR2ACBR( b ) (((rfalAdjACBR((b)))<din; - streamConf.dout = isoStreamConfig->dout; - streamConf.report_period_length = isoStreamConfig->report_period_length; - streamConf.useBPSK = isoStreamConfig->useBPSK; - st25r3911StreamConfigure(&streamConf); - } - - /* Set Analog configurations for this bit rate */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_POLL_COMMON) ); - rfalSetAnalogConfig( (rfalAnalogConfigId)(RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | rfalConvBR2ACBR(gRFAL.txBR) | RFAL_ANALOG_CONFIG_TX ) ); - rfalSetAnalogConfig( (rfalAnalogConfigId)(RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | rfalConvBR2ACBR(gRFAL.rxBR) | RFAL_ANALOG_CONFIG_RX ) ); - break; - - #endif /* RFAL_FEATURE_NFCV */ - - - /*******************************************************************************/ - case RFAL_MODE_POLL_ACTIVE_P2P: - - /* Set Analog configurations for this bit rate */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_POLL_COMMON) ); - rfalSetAnalogConfig( (rfalAnalogConfigId)(RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | rfalConvBR2ACBR(gRFAL.txBR) | RFAL_ANALOG_CONFIG_TX ) ); - rfalSetAnalogConfig( (rfalAnalogConfigId)(RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | rfalConvBR2ACBR(gRFAL.rxBR) | RFAL_ANALOG_CONFIG_RX ) ); - break; - - /*******************************************************************************/ - case RFAL_MODE_LISTEN_ACTIVE_P2P: - - /* Set Analog configurations for this bit rate */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_LISTEN_COMMON) ); - rfalSetAnalogConfig( (rfalAnalogConfigId)(RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | rfalConvBR2ACBR(gRFAL.txBR) | RFAL_ANALOG_CONFIG_TX ) ); - rfalSetAnalogConfig( (rfalAnalogConfigId)(RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | rfalConvBR2ACBR(gRFAL.rxBR) | RFAL_ANALOG_CONFIG_RX ) ); - break; - - /*******************************************************************************/ - case RFAL_MODE_LISTEN_NFCA: - case RFAL_MODE_LISTEN_NFCB: - case RFAL_MODE_LISTEN_NFCF: - case RFAL_MODE_NONE: - return ERR_WRONG_STATE; - - /*******************************************************************************/ - default: - return ERR_NOT_IMPLEMENTED; - } - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalGetBitRate( rfalBitRate *txBR, rfalBitRate *rxBR ) -{ - if( (gRFAL.state == RFAL_STATE_IDLE) || (gRFAL.mode == RFAL_MODE_NONE) ) - { - return ERR_WRONG_STATE; - } - - if( txBR != NULL ) - { - *txBR = gRFAL.txBR; - } - - if( rxBR != NULL ) - { - *rxBR = gRFAL.rxBR; - } - - return ERR_NONE; -} - - -/*******************************************************************************/ -void rfalSetErrorHandling( rfalEHandling eHandling ) -{ - gRFAL.conf.eHandling = eHandling; -} - - -/*******************************************************************************/ -rfalEHandling rfalGetErrorHandling( void ) -{ - return gRFAL.conf.eHandling; -} - - -/*******************************************************************************/ -void rfalSetFDTPoll( uint32_t FDTPoll ) -{ - gRFAL.timings.FDTPoll = MIN( FDTPoll, RFAL_ST25R3911_GPT_MAX_1FC ); -} - - -/*******************************************************************************/ -uint32_t rfalGetFDTPoll( void ) -{ - return gRFAL.timings.FDTPoll; -} - - -/*******************************************************************************/ -void rfalSetFDTListen( uint32_t FDTListen ) -{ - gRFAL.timings.FDTListen = MIN( FDTListen, RFAL_ST25R3911_MRT_MAX_1FC); -} - -/*******************************************************************************/ -uint32_t rfalGetFDTListen( void ) -{ - return gRFAL.timings.FDTListen; -} - -void rfalSetGT( uint32_t GT ) -{ - gRFAL.timings.GT = MIN( GT, RFAL_ST25R3911_GT_MAX_1FC ); -} - -/*******************************************************************************/ -uint32_t rfalGetGT( void ) -{ - return gRFAL.timings.GT; -} - -/*******************************************************************************/ -bool rfalIsGTExpired( void ) -{ - if( gRFAL.tmr.GT != RFAL_TIMING_NONE ) - { - if( !rfalTimerisExpired( gRFAL.tmr.GT ) ) - { - return false; - } - } - return true; -} - -/*******************************************************************************/ -ReturnCode rfalFieldOnAndStartGT( void ) -{ - ReturnCode ret; - - /* Check if RFAL has been initialized (Oscillator should be running) and also - * if a direct register access has been performed and left the Oscillator Off */ - if( !st25r3911IsOscOn() || (gRFAL.state < RFAL_STATE_INIT) ) - { - return ERR_WRONG_STATE; - } - - ret = ERR_NONE; - - /* Set Analog configurations for Field On event */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_FIELD_ON) ); - - /*******************************************************************************/ - /* Perform collision avoidance and turn field On if not already On */ - if( !st25r3911IsTxEnabled() || !gRFAL.field ) - { - /* Use Thresholds set by AnalogConfig */ - ret = st25r3911PerformCollisionAvoidance( ST25R3911_CMD_RESPONSE_RF_COLLISION_0, ST25R3911_THRESHOLD_DO_NOT_SET, ST25R3911_THRESHOLD_DO_NOT_SET, 0 ); - - gRFAL.field = st25r3911IsTxEnabled(); - - /* Only turn on Receiver and Transmitter if field was successfully turned On */ - if(gRFAL.field) - { - st25r3911TxRxOn(); /* Enable Tx and Rx (Tx is already On) */ - } - } - - /*******************************************************************************/ - /* Start GT timer in case the GT value is set */ - if( (gRFAL.timings.GT != RFAL_TIMING_NONE) ) - { - /* Ensure that a SW timer doesn't have a lower value then the minimum */ - rfalTimerStart( gRFAL.tmr.GT, rfalConv1fcToMs( MAX( (gRFAL.timings.GT), RFAL_ST25R3911_GT_MIN_1FC) ) ); - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalFieldOff( void ) -{ - /* Check whether a TxRx is not yet finished */ - if( gRFAL.TxRx.state != RFAL_TXRX_STATE_IDLE ) - { - rfalCleanupTransceive(); - } - - /* Disable Tx and Rx */ - st25r3911TxRxOff(); - - /* Set Analog configurations for Field Off event */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_FIELD_OFF) ); - gRFAL.field = false; - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalStartTransceive( const rfalTransceiveContext *ctx ) -{ - uint32_t FxTAdj; /* FWT or FDT adjustment calculation */ - - /* Check for valid parameters */ - if( ctx == NULL ) - { - return ERR_PARAM; - } - - /* Ensure that RFAL is already Initialized and the mode has been set */ - if( (gRFAL.state >= RFAL_STATE_MODE_SET) /*&& (gRFAL.TxRx.state == RFAL_TXRX_STATE_INIT )*/ ) - { - /*******************************************************************************/ - /* Check whether the field is already On, otherwise no TXE will be received */ - if( !st25r3911IsTxEnabled() && (!rfalIsModePassiveListen( gRFAL.mode ) && (ctx->txBuf != NULL)) ) - { - return ERR_WRONG_STATE; - } - - gRFAL.TxRx.ctx = *ctx; - - /*******************************************************************************/ - if( gRFAL.timings.FDTListen != RFAL_TIMING_NONE ) - { - /* Calculate MRT adjustment accordingly to the current mode */ - FxTAdj = RFAL_FDT_LISTEN_MRT_ADJUSTMENT; - if(gRFAL.mode == RFAL_MODE_POLL_NFCA) { FxTAdj += (uint32_t)RFAL_FDT_LISTEN_A_ADJUSTMENT; } - if(gRFAL.mode == RFAL_MODE_POLL_NFCA_T1T) { FxTAdj += (uint32_t)RFAL_FDT_LISTEN_A_ADJUSTMENT; } - if(gRFAL.mode == RFAL_MODE_POLL_NFCB) { FxTAdj += (uint32_t)RFAL_FDT_LISTEN_B_ADJUSTMENT; } - if(gRFAL.mode == RFAL_MODE_POLL_NFCV) { FxTAdj += (uint32_t)RFAL_FDT_LISTEN_V_ADJUSTMENT; } - - - /* Set Minimum FDT(Listen) in which PICC is not allowed to send a response */ - st25r3911WriteRegister( ST25R3911_REG_MASK_RX_TIMER, (uint8_t)rfalConv1fcTo64fc( (FxTAdj > gRFAL.timings.FDTListen) ? RFAL_ST25R3911_MRT_MIN_1FC : (gRFAL.timings.FDTListen - FxTAdj) ) ); - } - - /*******************************************************************************/ - /* FDT Poll will be loaded in rfalPrepareTransceive() once the previous was expired */ - - /*******************************************************************************/ - if( rfalIsModePassiveComm( gRFAL.mode ) ) /* Passive Comms */ - { - if( (gRFAL.TxRx.ctx.fwt != RFAL_FWT_NONE) && (gRFAL.TxRx.ctx.fwt != 0U) ) - { - /* Ensure proper timing configuration */ - if( gRFAL.timings.FDTListen >= gRFAL.TxRx.ctx.fwt ) - { - return ERR_PARAM; - } - - FxTAdj = RFAL_FWT_ADJUSTMENT; - if(gRFAL.mode == RFAL_MODE_POLL_NFCA) { FxTAdj += (uint32_t)RFAL_FWT_A_ADJUSTMENT; } - if(gRFAL.mode == RFAL_MODE_POLL_NFCA_T1T) { FxTAdj += (uint32_t)RFAL_FWT_A_ADJUSTMENT; } - if(gRFAL.mode == RFAL_MODE_POLL_NFCB) { FxTAdj += (uint32_t)RFAL_FWT_B_ADJUSTMENT; } - if(gRFAL.mode == RFAL_MODE_POLL_NFCF) - { - FxTAdj += (uint32_t)((gRFAL.txBR == RFAL_BR_212) ? RFAL_FWT_F_212_ADJUSTMENT : RFAL_FWT_F_424_ADJUSTMENT ); - } - - /* Ensure that the given FWT doesn't exceed NRT maximum */ - gRFAL.TxRx.ctx.fwt = MIN( (gRFAL.TxRx.ctx.fwt + FxTAdj), RFAL_ST25R3911_NRT_MAX_1FC ); - - /* Set FWT in the NRT */ - st25r3911SetNoResponseTime_64fcs( rfalConv1fcTo64fc( gRFAL.TxRx.ctx.fwt ) ); - } - else - { - /* Disable NRT, no NRE will be triggered, therefore wait endlessly for Rx */ - st25r3911SetNoResponseTime_64fcs( RFAL_ST25R3911_NRT_DISABLED ); - } - } - else /* Active Comms */ - { - /* Setup NRT timer for rf response RF collision timeout. */ - st25r3911SetNoResponseTime_64fcs( rfalConv1fcTo64fc(RFAL_AP2P_FIELDON_TADTTRFW) ); - - /* In Active Mode No Response Timer cannot be used to measure FWT a SW timer is used instead */ - } - - gRFAL.state = RFAL_STATE_TXRX; - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_IDLE; - gRFAL.TxRx.status = ERR_BUSY; - gRFAL.TxRx.rxse = false; - - #if RFAL_FEATURE_NFCV - /*******************************************************************************/ - if( (RFAL_MODE_POLL_NFCV == gRFAL.mode) || (RFAL_MODE_POLL_PICOPASS == gRFAL.mode) ) - { /* Exchange receive buffer with internal buffer */ - gRFAL.nfcvData.origCtx = gRFAL.TxRx.ctx; - - gRFAL.TxRx.ctx.rxBuf = ((gRFAL.nfcvData.origCtx.rxBuf != NULL) ? gRFAL.nfcvData.codingBuffer : NULL); - gRFAL.TxRx.ctx.rxBufLen = (uint16_t)rfalConvBytesToBits(sizeof(gRFAL.nfcvData.codingBuffer)); - gRFAL.TxRx.ctx.flags = (uint32_t)RFAL_TXRX_FLAGS_CRC_TX_MANUAL - | (uint32_t)RFAL_TXRX_FLAGS_CRC_RX_KEEP - | (uint32_t)RFAL_TXRX_FLAGS_NFCIP1_OFF - | (uint32_t)(gRFAL.nfcvData.origCtx.flags & (uint32_t)RFAL_TXRX_FLAGS_AGC_OFF) - | (uint32_t)RFAL_TXRX_FLAGS_PAR_RX_KEEP - | (uint32_t)RFAL_TXRX_FLAGS_PAR_TX_NONE; - - /* In NFCV a TxRx with a valid txBuf and txBufSize==0 indicates to send an EOF */ - /* Skip logic below that would go directly into receive */ - if ( gRFAL.TxRx.ctx.txBuf != NULL ) - { - return ERR_NONE; - } - } - #endif /* RFAL_FEATURE_NFCV */ - - - /*******************************************************************************/ - /* Check if the Transceive start performing Tx or goes directly to Rx */ - if( (gRFAL.TxRx.ctx.txBuf == NULL) || (gRFAL.TxRx.ctx.txBufLen == 0U) ) - { - /* Clear FIFO, Clear and Enable the Interrupts */ - rfalPrepareTransceive( ); - - /* Disable our field upon a Rx reEnable on AP2P */ - if( rfalIsModeActiveComm(gRFAL.mode) ) - { - st25r3911TxOff(); - } - - /* No Tx done, enable the Receiver */ - st25r3911ExecuteCommand( ST25R3911_CMD_UNMASK_RECEIVE_DATA ); - - /* Start NRT manually, if FWT = 0 (wait endlessly for Rx) chip will ignore anyhow */ - st25r3911ExecuteCommand( ST25R3911_CMD_START_NO_RESPONSE_TIMER ); - - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_IDLE; - } - - return ERR_NONE; - } - - return ERR_WRONG_STATE; -} - - -/*******************************************************************************/ -bool rfalIsTransceiveInTx( void ) -{ - return ( (gRFAL.TxRx.state >= RFAL_TXRX_STATE_TX_IDLE) && (gRFAL.TxRx.state < RFAL_TXRX_STATE_RX_IDLE) ); -} - - -/*******************************************************************************/ -bool rfalIsTransceiveInRx( void ) -{ - return (gRFAL.TxRx.state >= RFAL_TXRX_STATE_RX_IDLE); -} - - -/*******************************************************************************/ -ReturnCode rfalTransceiveBlockingTx( uint8_t* txBuf, uint16_t txBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t* actLen, uint32_t flags, uint32_t fwt ) -{ - ReturnCode ret; - rfalTransceiveContext ctx; - - rfalCreateByteFlagsTxRxContext( ctx, txBuf, txBufLen, rxBuf, rxBufLen, actLen, flags, fwt ); - EXIT_ON_ERR( ret, rfalStartTransceive( &ctx ) ); - - return rfalTransceiveRunBlockingTx(); -} - - -/*******************************************************************************/ -static ReturnCode rfalTransceiveRunBlockingTx( void ) -{ - ReturnCode ret; - - do{ - rfalWorker(); - ret = rfalGetTransceiveStatus(); - } - while( rfalIsTransceiveInTx() && (ret == ERR_BUSY) ); - - if( rfalIsTransceiveInRx() ) - { - return ERR_NONE; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalTransceiveBlockingRx( void ) -{ - ReturnCode ret; - - do{ - rfalWorker(); - ret = rfalGetTransceiveStatus(); - } - while( rfalIsTransceiveInRx() && (ret == ERR_BUSY) ); - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalTransceiveBlockingTxRx( uint8_t* txBuf, uint16_t txBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t* actLen, uint32_t flags, uint32_t fwt ) -{ - ReturnCode ret; - - EXIT_ON_ERR( ret, rfalTransceiveBlockingTx( txBuf, txBufLen, rxBuf, rxBufLen, actLen, flags, fwt ) ); - ret = rfalTransceiveBlockingRx(); - - /* Convert received bits to bytes */ - if( actLen != NULL ) - { - *actLen = rfalConvBitsToBytes(*actLen); - } - - return ret; -} - - -/*******************************************************************************/ -static ReturnCode rfalRunTransceiveWorker( void ) -{ - if( gRFAL.state == RFAL_STATE_TXRX ) - { - /* Run Tx or Rx state machines */ - if( rfalIsTransceiveInTx() ) - { - rfalTransceiveTx(); - return rfalGetTransceiveStatus(); - } - - if( rfalIsTransceiveInRx() ) - { - rfalTransceiveRx(); - return rfalGetTransceiveStatus(); - } - } - return ERR_WRONG_STATE; -} - -/*******************************************************************************/ -rfalTransceiveState rfalGetTransceiveState( void ) -{ - return gRFAL.TxRx.state; -} - -ReturnCode rfalGetTransceiveStatus( void ) -{ - return ((gRFAL.TxRx.state == RFAL_TXRX_STATE_IDLE) ? gRFAL.TxRx.status : ERR_BUSY); -} - - -/*******************************************************************************/ -ReturnCode rfalGetTransceiveRSSI( uint16_t *rssi ) -{ - uint16_t amRSSI; - uint16_t pmRSSI; - - if( rssi == NULL ) - { - return ERR_PARAM; - } - - /* Check if Manual channel is enabled */ - if( st25r3911CheckReg( ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_rx_man, ST25R3911_REG_OP_CONTROL_rx_man ) ) - { - st25r3911GetRSSI( &amRSSI, &pmRSSI ); - - /* Check which channel is selected */ - *rssi = ( st25r3911CheckReg( ST25R3911_REG_RX_CONF1, ST25R3911_REG_RX_CONF1_ch_sel, ST25R3911_REG_RX_CONF1_ch_sel ) ? pmRSSI : amRSSI ); - return ERR_NONE; - } - - *rssi = 0; - return ERR_NOTSUPP; -} - - -/*******************************************************************************/ -void rfalWorker( void ) -{ - platformProtectWorker(); /* Protect RFAL Worker/Task/Process */ - - switch( gRFAL.state ) - { - case RFAL_STATE_TXRX: - rfalRunTransceiveWorker(); - break; - - #if RFAL_FEATURE_LISTEN_MODE - case RFAL_STATE_LM: - rfalRunListenModeWorker(); - break; - #endif /* RFAL_FEATURE_LISTEN_MODE */ - - #if RFAL_FEATURE_WAKEUP_MODE - case RFAL_STATE_WUM: - rfalRunWakeUpModeWorker(); - break; - #endif /* RFAL_FEATURE_WAKEUP_MODE */ - - /* Nothing to be done */ - default: - /* MISRA 16.4: no empty default statement (a comment being enough) */ - break; - } - - platformUnprotectWorker(); /* Unprotect RFAL Worker/Task/Process */ -} - - -/*******************************************************************************/ -static void rfalErrorHandling( void ) -{ - bool rxHasIncParError; - uint8_t fifoBytesToRead; - uint8_t reEnRx[] = { ST25R3911_CMD_CLEAR_FIFO, ST25R3911_CMD_UNMASK_RECEIVE_DATA }; - - - fifoBytesToRead = rfalFIFOStatusGetNumBytes(); - - - /*******************************************************************************/ - /* EMVCo */ - /*******************************************************************************/ - if( gRFAL.conf.eHandling == RFAL_ERRORHANDLING_EMVCO ) - { - /*******************************************************************************/ - /* EMD Handling - NFC Forum Digital 1.1 4.1.1.1 ; EMVCo 2.6 4.9.2 */ - /* ReEnable the receiver on frames with a length < 4 bytes, upon: */ - /* - Collision or Framing error detected */ - /* - Residual bits are detected (hard framing error) */ - /* - Parity error */ - /* - CRC error */ - /*******************************************************************************/ - - /* Check if reception has incompete bytes or parity error */ - rxHasIncParError = ( rfalFIFOStatusIsIncompleteByte() ? true : rfalFIFOStatusIsMissingPar() ); /* MISRA 13.5 */ - - /* In case there are residual bits decrement FIFO bytes */ - if( (fifoBytesToRead > 0U) && rxHasIncParError) - { - fifoBytesToRead--; - } - - if( ( (gRFAL.fifo.bytesTotal + fifoBytesToRead) < RFAL_EMVCO_RX_MAXLEN ) && - ( (gRFAL.TxRx.status == ERR_RF_COLLISION) || (gRFAL.TxRx.status == ERR_FRAMING) || - (gRFAL.TxRx.status == ERR_PAR) || (gRFAL.TxRx.status == ERR_CRC) || - rxHasIncParError ) ) - { - /* Ignore this reception, ReEnable receiver */ - st25r3911ExecuteCommands( reEnRx, sizeof(reEnRx) ); - - rfalFIFOStatusClear(); - gRFAL.fifo.bytesTotal = 0; - gRFAL.TxRx.status = ERR_BUSY; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_WAIT_RXS; - } - return; - } - - /*******************************************************************************/ - /* ISO14443A Mode */ - /*******************************************************************************/ - if( gRFAL.mode == RFAL_MODE_POLL_NFCA ) - { - - /*******************************************************************************/ - /* If we received one incomplete byte (not a block and a incomplete byte at * - * the end) we will raise a specific error ( support for T2T 4 bit ACK / NAK ) * - * Otherwise just leave it as an CRC/FRAMING/PAR error */ - /*******************************************************************************/ - if( (gRFAL.TxRx.status == ERR_PAR) || (gRFAL.TxRx.status == ERR_CRC) ) - { - if( rfalFIFOStatusIsIncompleteByte() && (fifoBytesToRead == RFAL_NFC_RX_INCOMPLETE_LEN) ) - { - st25r3911ReadFifo( (uint8_t*)(gRFAL.TxRx.ctx.rxBuf), fifoBytesToRead ); - if( (gRFAL.TxRx.ctx.rxRcvdLen) != NULL ) - { - *gRFAL.TxRx.ctx.rxRcvdLen = rfalFIFOGetNumIncompleteBits(); - } - - gRFAL.TxRx.status = ERR_INCOMPLETE_BYTE; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - } - } - } - -} - - -/*******************************************************************************/ -static void rfalCleanupTransceive( void ) -{ - /*******************************************************************************/ - /* Transceive flags */ - /*******************************************************************************/ - - /* Restore default settings on NFCIP1 mode, Receiving parity + CRC bits and manual Tx Parity*/ - st25r3911ClrRegisterBits( ST25R3911_REG_ISO14443A_NFC, (ST25R3911_REG_ISO14443A_NFC_no_tx_par | ST25R3911_REG_ISO14443A_NFC_no_rx_par | ST25R3911_REG_ISO14443A_NFC_nfc_f0) ); - - /* Restore AGC enabled */ - st25r3911SetRegisterBits( ST25R3911_REG_RX_CONF2, ST25R3911_REG_RX_CONF2_agc_en ); - - /*******************************************************************************/ - - - - /*******************************************************************************/ - /* Execute Post Transceive Callback */ - /*******************************************************************************/ - if( gRFAL.callbacks.postTxRx != NULL ) - { - gRFAL.callbacks.postTxRx(); - } - /*******************************************************************************/ - -} - - -/*******************************************************************************/ -static void rfalPrepareTransceive( void ) -{ - uint32_t maskInterrupts; - uint8_t reg; - - /*******************************************************************************/ - /* In the EMVCo mode the NRT will continue to run. * - * For the clear to stop it, the EMV mode has to be disabled before */ - st25r3911ClrRegisterBits( ST25R3911_REG_GPT_CONTROL, ST25R3911_REG_GPT_CONTROL_nrt_emv ); - - /* Reset receive logic */ - st25r3911ExecuteCommand( ST25R3911_CMD_CLEAR_FIFO ); - - /* Reset Rx Gain */ - st25r3911ExecuteCommand( ST25R3911_CMD_CLEAR_SQUELCH ); - - - /*******************************************************************************/ - /* FDT Poll */ - /*******************************************************************************/ - if( rfalIsModePassiveComm( gRFAL.mode ) ) /* Passive Comms */ - { - /* In Passive communications General Purpose Timer is used to measure FDT Poll */ - if( gRFAL.timings.FDTPoll != RFAL_TIMING_NONE ) - { - /* Configure GPT to start at RX end */ - st25r3911StartGPTimer_8fcs( (uint16_t)rfalConv1fcTo8fc( MIN( gRFAL.timings.FDTPoll, (gRFAL.timings.FDTPoll - RFAL_FDT_POLL_ADJUSTMENT) ) ), ST25R3911_REG_GPT_CONTROL_gptc_erx ); - } - } - - - /*******************************************************************************/ - /* Execute Pre Transceive Callback */ - /*******************************************************************************/ - if( gRFAL.callbacks.preTxRx != NULL ) - { - gRFAL.callbacks.preTxRx(); - } - /*******************************************************************************/ - - maskInterrupts = ( ST25R3911_IRQ_MASK_FWL | ST25R3911_IRQ_MASK_TXE | - ST25R3911_IRQ_MASK_RXS | ST25R3911_IRQ_MASK_RXE | - ST25R3911_IRQ_MASK_FWL | ST25R3911_IRQ_MASK_NRE | - ST25R3911_IRQ_MASK_PAR | ST25R3911_IRQ_MASK_CRC | - ST25R3911_IRQ_MASK_ERR1 | ST25R3911_IRQ_MASK_ERR2 ); - - - /*******************************************************************************/ - /* Transceive flags */ - /*******************************************************************************/ - - reg = (ST25R3911_REG_ISO14443A_NFC_no_tx_par_off | ST25R3911_REG_ISO14443A_NFC_no_rx_par_off | ST25R3911_REG_ISO14443A_NFC_nfc_f0_off); - - /* Check if NFCIP1 mode is to be enabled */ - if( (gRFAL.TxRx.ctx.flags & (uint8_t)RFAL_TXRX_FLAGS_NFCIP1_ON) != 0U ) - { - reg |= ST25R3911_REG_ISO14443A_NFC_nfc_f0; - } - - /* Check if Parity check is to be skipped and to keep the parity + CRC bits in FIFO */ - if( (gRFAL.TxRx.ctx.flags & (uint8_t)RFAL_TXRX_FLAGS_PAR_RX_KEEP) != 0U ) - { - reg |= ST25R3911_REG_ISO14443A_NFC_no_rx_par; - } - - /* Check if automatic Parity bits is to be disabled */ - if( (gRFAL.TxRx.ctx.flags & (uint8_t)RFAL_TXRX_FLAGS_PAR_TX_NONE) != 0U ) - { - reg |= ST25R3911_REG_ISO14443A_NFC_no_tx_par; - } - - /* Apply current TxRx flags on ISO14443A and NFC 106kb/s Settings Register */ - st25r3911ChangeRegisterBits( ST25R3911_REG_ISO14443A_NFC, (ST25R3911_REG_ISO14443A_NFC_no_tx_par | ST25R3911_REG_ISO14443A_NFC_no_rx_par | ST25R3911_REG_ISO14443A_NFC_nfc_f0), reg ); - - - /* Check if AGC is to be disabled */ - if( (gRFAL.TxRx.ctx.flags & (uint8_t)RFAL_TXRX_FLAGS_AGC_OFF) != 0U ) - { - st25r3911ClrRegisterBits( ST25R3911_REG_RX_CONF2, ST25R3911_REG_RX_CONF2_agc_en ); - } - else - { - st25r3911SetRegisterBits( ST25R3911_REG_RX_CONF2, ST25R3911_REG_RX_CONF2_agc_en ); - } - /*******************************************************************************/ - - - - /*******************************************************************************/ - /* EMVCo NRT mode */ - /*******************************************************************************/ - if( gRFAL.conf.eHandling == RFAL_ERRORHANDLING_EMVCO ) - { - st25r3911SetRegisterBits( ST25R3911_REG_GPT_CONTROL, ST25R3911_REG_GPT_CONTROL_nrt_emv ); - } - else - { - st25r3911ClrRegisterBits( ST25R3911_REG_GPT_CONTROL, ST25R3911_REG_GPT_CONTROL_nrt_emv ); - } - /*******************************************************************************/ - - - - /* In Active comms enable also External Field interrupts */ - if( rfalIsModeActiveComm( gRFAL.mode ) ) - { - maskInterrupts |= ( ST25R3911_IRQ_MASK_EOF | ST25R3911_IRQ_MASK_EON | ST25R3911_IRQ_MASK_CAT | ST25R3911_IRQ_MASK_CAC ); - } - - - /*******************************************************************************/ - /* clear and enable these interrupts */ - st25r3911GetInterrupt( maskInterrupts ); - st25r3911EnableInterrupts( maskInterrupts ); - - /* Clear FIFO status local copy */ - rfalFIFOStatusClear(); -} - -/*******************************************************************************/ -static void rfalTransceiveTx( void ) -{ - volatile uint32_t irqs; - uint16_t tmp; - ReturnCode ret; - - /* Supress warning in case NFC-V feature is disabled */ - ret = ERR_NONE; - NO_WARNING(ret); - - - irqs = ST25R3911_IRQ_MASK_NONE; - - if( gRFAL.TxRx.state != gRFAL.TxRx.lastState ) - { - /* rfalLogD( "RFAL: lastSt: %d curSt: %d \r\n", gRFAL.TxRx.lastState, gRFAL.TxRx.state ); */ - gRFAL.TxRx.lastState = gRFAL.TxRx.state; - } - - switch( gRFAL.TxRx.state ) - { - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_IDLE: - - /* Nothing to do */ - - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_WAIT_GT ; - /* fall through */ - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_WAIT_GT: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - if( !rfalIsGTExpired() ) - { - break; - } - - gRFAL.tmr.GT = RFAL_TIMING_NONE; - - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_WAIT_FDT; - /* fall through */ - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_WAIT_FDT: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - /* Only in Passive communications GPT is used to measure FDT Poll */ - if( rfalIsModePassiveComm( gRFAL.mode ) ) - { - if( st25r3911IsGPTRunning() ) - { - break; - } - } - - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_TRANSMIT; - /* fall through */ - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_TRANSMIT: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - /* Clear FIFO, Clear and Enable the Interrupts */ - rfalPrepareTransceive( ); - - /* Calculate when Water Level Interrupt will be triggered */ - gRFAL.fifo.expWL = (uint16_t)( st25r3911CheckReg( ST25R3911_REG_IO_CONF1, ST25R3911_REG_IO_CONF1_fifo_lt, ST25R3911_REG_IO_CONF1_fifo_lt_16bytes) ? RFAL_FIFO_OUT_LT_16 : RFAL_FIFO_OUT_LT_32 ); - - #if RFAL_FEATURE_NFCV - /*******************************************************************************/ - /* In NFC-V streaming mode, the FIFO needs to be loaded with the coded bits */ - if( (RFAL_MODE_POLL_NFCV == gRFAL.mode) || (RFAL_MODE_POLL_PICOPASS == gRFAL.mode) ) - { - #if 0 - /* Debugging code: output the payload bits by writing into the FIFO and subsequent clearing */ - st25r3911WriteFifo(gRFAL.TxRx.ctx.txBuf, rfalConvBitsToBytes(gRFAL.TxRx.ctx.txBufLen)); - st25r3911ExecuteCommand( ST25R3911_CMD_CLEAR_FIFO ); - #endif - /* Calculate the bytes needed to be Written into FIFO (a incomplete byte will be added as 1byte) */ - gRFAL.nfcvData.nfcvOffset = 0; - ret = iso15693VCDCode(gRFAL.TxRx.ctx.txBuf, rfalConvBitsToBytes(gRFAL.TxRx.ctx.txBufLen), (((gRFAL.nfcvData.origCtx.flags & (uint32_t)RFAL_TXRX_FLAGS_CRC_TX_MANUAL) != 0U)?false:true),(((gRFAL.nfcvData.origCtx.flags & (uint32_t)RFAL_TXRX_FLAGS_NFCV_FLAG_MANUAL) != 0U)?false:true), (RFAL_MODE_POLL_PICOPASS == gRFAL.mode), - &gRFAL.fifo.bytesTotal, &gRFAL.nfcvData.nfcvOffset, gRFAL.nfcvData.codingBuffer, MIN( (uint16_t)ST25R3911_FIFO_DEPTH, (uint16_t)sizeof(gRFAL.nfcvData.codingBuffer) ), &gRFAL.fifo.bytesWritten); - - if( (ret != ERR_NONE) && (ret != ERR_AGAIN) ) - { - gRFAL.TxRx.status = ret; - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_FAIL; - break; - } - /* Set the number of full bytes and bits to be transmitted */ - st25r3911SetNumTxBits( rfalConvBytesToBits(gRFAL.fifo.bytesTotal) ); - - /* Load FIFO with coded bytes */ - /* TODO: check bytesWritten does not exceed 255 */ - st25r3911WriteFifo( gRFAL.nfcvData.codingBuffer, (uint8_t)gRFAL.fifo.bytesWritten ); - - } - /*******************************************************************************/ - else - #endif /* RFAL_FEATURE_NFCV */ - { - /* Calculate the bytes needed to be Written into FIFO (a incomplete byte will be added as 1byte) */ - gRFAL.fifo.bytesTotal = (uint16_t)rfalCalcNumBytes(gRFAL.TxRx.ctx.txBufLen); - - /* Set the number of full bytes and bits to be transmitted */ - st25r3911SetNumTxBits( gRFAL.TxRx.ctx.txBufLen ); - - /* Load FIFO with total length or FIFO's maximum */ - gRFAL.fifo.bytesWritten = MIN( gRFAL.fifo.bytesTotal, ST25R3911_FIFO_DEPTH ); - st25r3911WriteFifo( gRFAL.TxRx.ctx.txBuf, (uint8_t)gRFAL.fifo.bytesWritten ); - } - - /*Check if Observation Mode is enabled and set it on ST25R391x */ - rfalCheckEnableObsModeTx(); - - /*******************************************************************************/ - /* Trigger/Start transmission */ - if( (gRFAL.TxRx.ctx.flags & (uint32_t)RFAL_TXRX_FLAGS_CRC_TX_MANUAL) != 0U ) - { - st25r3911ExecuteCommand( ST25R3911_CMD_TRANSMIT_WITHOUT_CRC ); - } - else - { - st25r3911ExecuteCommand( ST25R3911_CMD_TRANSMIT_WITH_CRC ); - } - - /* Check if a WL level is expected or TXE should come */ - gRFAL.TxRx.state = (( gRFAL.fifo.bytesWritten < gRFAL.fifo.bytesTotal ) ? RFAL_TXRX_STATE_TX_WAIT_WL : RFAL_TXRX_STATE_TX_WAIT_TXE); - break; - - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_WAIT_WL: - - irqs = st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_FWL | ST25R3911_IRQ_MASK_TXE) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - break; /* No interrupt to process */ - } - - if( ((irqs & ST25R3911_IRQ_MASK_FWL) != 0U) && ((irqs & ST25R3911_IRQ_MASK_TXE) == 0U) ) - { - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_RELOAD_FIFO; - } - else - { - gRFAL.TxRx.status = ERR_IO; - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_FAIL; - break; - } - - /* fall through */ - - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_RELOAD_FIFO: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - #if RFAL_FEATURE_NFCV - /*******************************************************************************/ - /* In NFC-V streaming mode, the FIFO needs to be loaded with the coded bits */ - if( (RFAL_MODE_POLL_NFCV == gRFAL.mode) || (RFAL_MODE_POLL_PICOPASS == gRFAL.mode) ) - { - uint16_t maxLen; - - /* Load FIFO with the remaining length or maximum available (which fit on the coding buffer) */ - maxLen = (uint16_t)MIN( (gRFAL.fifo.bytesTotal - gRFAL.fifo.bytesWritten), gRFAL.fifo.expWL); - maxLen = (uint16_t)MIN( maxLen, sizeof(gRFAL.nfcvData.codingBuffer) ); - tmp = 0; - - /* Calculate the bytes needed to be Written into FIFO (a incomplete byte will be added as 1byte) */ - ret = iso15693VCDCode(gRFAL.TxRx.ctx.txBuf, rfalConvBitsToBytes(gRFAL.TxRx.ctx.txBufLen), (((gRFAL.nfcvData.origCtx.flags & (uint32_t)RFAL_TXRX_FLAGS_CRC_TX_MANUAL) != 0U)?false:true), (((gRFAL.nfcvData.origCtx.flags & (uint32_t)RFAL_TXRX_FLAGS_NFCV_FLAG_MANUAL) != 0U)?false:true), (RFAL_MODE_POLL_PICOPASS == gRFAL.mode), - &gRFAL.fifo.bytesTotal, &gRFAL.nfcvData.nfcvOffset, gRFAL.nfcvData.codingBuffer, maxLen, &tmp); - - if( (ret != ERR_NONE) && (ret != ERR_AGAIN) ) - { - gRFAL.TxRx.status = ret; - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_FAIL; - break; - } - - /* Load FIFO with coded bytes */ - /* TODO: check tmp does not exceed 255 */ - st25r3911WriteFifo( gRFAL.nfcvData.codingBuffer, (uint8_t)tmp ); - } - /*******************************************************************************/ - else - #endif /* RFAL_FEATURE_NFCV */ - { - /* Load FIFO with the remaining length or maximum available */ - tmp = MIN( (gRFAL.fifo.bytesTotal - gRFAL.fifo.bytesWritten), gRFAL.fifo.expWL); /* tmp holds the number of bytes written on this iteration */ - /* TODO: check tmp does not exceed 255 */ - st25r3911WriteFifo( &gRFAL.TxRx.ctx.txBuf[gRFAL.fifo.bytesWritten], (uint8_t)tmp ); - } - - /* Update total written bytes to FIFO */ - gRFAL.fifo.bytesWritten += tmp; - - /* Check if a WL level is expected or TXE should come */ - gRFAL.TxRx.state = (( gRFAL.fifo.bytesWritten < gRFAL.fifo.bytesTotal ) ? RFAL_TXRX_STATE_TX_WAIT_WL : RFAL_TXRX_STATE_TX_WAIT_TXE); - break; - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_WAIT_TXE: - - irqs = st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_FWL | ST25R3911_IRQ_MASK_TXE) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - break; /* No interrupt to process */ - } - - - if( (irqs & ST25R3911_IRQ_MASK_TXE) != 0U ) - { - /* In Active comm start SW timer to measure FWT */ - if( rfalIsModeActiveComm( gRFAL.mode) && (gRFAL.TxRx.ctx.fwt != RFAL_FWT_NONE) && (gRFAL.TxRx.ctx.fwt != 0U) ) - { - rfalTimerStart( gRFAL.tmr.FWT, rfalConv1fcToMs( gRFAL.TxRx.ctx.fwt ) ); - } - - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_DONE; - } - else if( (irqs & ST25R3911_IRQ_MASK_FWL) != 0U ) - { - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911 Errata #TBD */ - /* ST25R3911 may send a WL even when all bytes have been written to FIFO */ - /*******************************************************************************/ - break; /* Ignore ST25R3911 FIFO WL if total TxLen is already on the FIFO */ - } - else - { - gRFAL.TxRx.status = ERR_IO; - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_FAIL; - break; - } - - /* fall through */ - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_DONE: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - /* If no rxBuf is provided do not wait/expect Rx */ - if( gRFAL.TxRx.ctx.rxBuf == NULL ) - { - /*Check if Observation Mode was enabled and disable it on ST25R391x */ - rfalCheckDisableObsMode(); - - /* Clean up Transceive */ - rfalCleanupTransceive(); - - gRFAL.TxRx.status = ERR_NONE; - gRFAL.TxRx.state = RFAL_TXRX_STATE_IDLE; - break; - } - - rfalCheckEnableObsModeRx(); - - /* Goto Rx */ - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_IDLE; - break; - - /*******************************************************************************/ - case RFAL_TXRX_STATE_TX_FAIL: - - /* Error should be assigned by previous state */ - if( gRFAL.TxRx.status == ERR_BUSY ) - { - gRFAL.TxRx.status = ERR_SYSTEM; - } - - /*Check if Observation Mode was enabled and disable it on ST25R391x */ - rfalCheckDisableObsMode(); - - /* Clean up Transceive */ - rfalCleanupTransceive(); - - gRFAL.TxRx.state = RFAL_TXRX_STATE_IDLE; - break; - - /*******************************************************************************/ - default: - gRFAL.TxRx.status = ERR_SYSTEM; - gRFAL.TxRx.state = RFAL_TXRX_STATE_TX_FAIL; - break; - } -} - - -/*******************************************************************************/ -static void rfalTransceiveRx( void ) -{ - volatile uint32_t irqs; - uint8_t tmp; - uint8_t aux; - - irqs = ST25R3911_IRQ_MASK_NONE; - - if( gRFAL.TxRx.state != gRFAL.TxRx.lastState ) - { - /* rfalLogD( "RFAL: lastSt: %d curSt: %d \r\n", gRFAL.TxRx.lastState, gRFAL.TxRx.state ); */ - gRFAL.TxRx.lastState = gRFAL.TxRx.state; - } - - switch( gRFAL.TxRx.state ) - { - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_IDLE: - - /* Clear rx counters */ - gRFAL.fifo.bytesWritten = 0; // Total bytes written on RxBuffer - gRFAL.fifo.bytesTotal = 0; // Total bytes in FIFO will now be from Rx - if( gRFAL.TxRx.ctx.rxRcvdLen != NULL ) - { - *gRFAL.TxRx.ctx.rxRcvdLen = 0; - } - - gRFAL.TxRx.state = ( rfalIsModeActiveComm( gRFAL.mode ) ? RFAL_TXRX_STATE_RX_WAIT_EON : RFAL_TXRX_STATE_RX_WAIT_RXS ); - break; - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_WAIT_RXS: - - /*******************************************************************************/ - /* If in Active comm, Check if FWT SW timer has expired */ - if( rfalIsModeActiveComm( gRFAL.mode ) && (gRFAL.TxRx.ctx.fwt != RFAL_FWT_NONE) && (gRFAL.TxRx.ctx.fwt != 0U) ) - { - if( rfalTimerisExpired( gRFAL.tmr.FWT ) ) - { - gRFAL.TxRx.status = ERR_TIMEOUT; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - break; - } - } - - /*******************************************************************************/ - irqs = st25r3911GetInterrupt( ( ST25R3911_IRQ_MASK_RXS | ST25R3911_IRQ_MASK_NRE | ST25R3911_IRQ_MASK_EOF | ST25R3911_IRQ_MASK_RXE) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - break; /* No interrupt to process */ - } - - - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911 Errata #1.7 */ - /* NRE interrupt may be triggered twice */ - /* Ignore NRE if is detected together with no Rx Start */ - /*******************************************************************************/ - - /* Only raise Timeout if NRE is detected with no Rx Start (NRT EMV mode) */ - if( ((irqs & ST25R3911_IRQ_MASK_NRE) != 0U) && ((irqs & ST25R3911_IRQ_MASK_RXS) == 0U) ) - { - gRFAL.TxRx.status = ERR_TIMEOUT; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - break; - } - - /* Only raise Link Loss if EOF is detected with no Rx Start */ - if( ((irqs & ST25R3911_IRQ_MASK_EOF) != 0U) && ((irqs & ST25R3911_IRQ_MASK_RXS) == 0U) ) - { - /* In AP2P a Field On has already occurred - treat this as timeout | mute */ - gRFAL.TxRx.status = ( rfalIsModeActiveComm( gRFAL.mode ) ? ERR_TIMEOUT : ERR_LINK_LOSS ); - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - break; - } - - if( (irqs & ST25R3911_IRQ_MASK_RXS) != 0U ) - { - /* If we got RXS + RXE together, jump directly into RFAL_TXRX_STATE_RX_ERR_CHECK */ - if( (irqs & ST25R3911_IRQ_MASK_RXE) != 0U ) - { - gRFAL.TxRx.rxse = true; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_ERR_CHECK; - break; - } - else - { - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911 Errata #1.1 */ - /* Rarely on corrupted frames I_rxs gets signaled but I_rxe is not signaled */ - /* Use a SW timer to handle an eventual missing RXE */ - rfalTimerStart( gRFAL.tmr.RXE, RFAL_NORXE_TOUT ); - /*******************************************************************************/ - - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_WAIT_RXE; - } - } - else if( (irqs & ST25R3911_IRQ_MASK_RXE) != 0U ) - { - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911 Errata #1.9 */ - /* ST25R3911 may indicate RXE without RXS previously, this happens upon some */ - /* noise or incomplete byte frames with less than 4 bits */ - /*******************************************************************************/ - - gRFAL.TxRx.status = ERR_IO; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - - rfalErrorHandling(); - break; - } - else - { - gRFAL.TxRx.status = ERR_IO; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - break; - } - - /* fall through */ - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_WAIT_RXE: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - irqs = st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_RXE | ST25R3911_IRQ_MASK_FWL | ST25R3911_IRQ_MASK_EOF) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911B Errata #1.1 */ - /* ST25R3911 may indicate RXS without RXE afterwards, this happens rarely on */ - /* corrupted frames. */ - /* SW timer is used to timeout upon a missing RXE */ - if( rfalTimerisExpired( gRFAL.tmr.RXE ) ) - { - gRFAL.TxRx.status = ERR_FRAMING; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - } - /*******************************************************************************/ - - break; /* No interrupt to process */ - } - - if( ((irqs & ST25R3911_IRQ_MASK_FWL) != 0U) && ((irqs & ST25R3911_IRQ_MASK_RXE) == 0U) ) - { - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_READ_FIFO; - break; - } - - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_ERR_CHECK; - /* fall through */ - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_ERR_CHECK: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - /* Retrieve and check for any error irqs */ - irqs |= st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_CRC | ST25R3911_IRQ_MASK_PAR | ST25R3911_IRQ_MASK_ERR1 | ST25R3911_IRQ_MASK_ERR2 | ST25R3911_IRQ_MASK_COL) ); - - if( (irqs & ST25R3911_IRQ_MASK_ERR1) != 0U ) - { - gRFAL.TxRx.status = ERR_FRAMING; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_READ_DATA; - - /* Check if there's a specific error handling for this */ - rfalErrorHandling(); - break; - } - /* Discard Soft Framing errors if not in EMVCo error handling */ - else if( ((irqs & ST25R3911_IRQ_MASK_ERR2) != 0U) && (gRFAL.conf.eHandling == RFAL_ERRORHANDLING_EMVCO) ) - { - gRFAL.TxRx.status = ERR_FRAMING; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_READ_DATA; - - /* Check if there's a specific error handling for this */ - rfalErrorHandling(); - break; - } - else if( (irqs & ST25R3911_IRQ_MASK_PAR) != 0U ) - { - gRFAL.TxRx.status = ERR_PAR; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_READ_DATA; - - /* Check if there's a specific error handling for this */ - rfalErrorHandling(); - break; - } - else if( (irqs & ST25R3911_IRQ_MASK_CRC) != 0U ) - { - gRFAL.TxRx.status = ERR_CRC; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_READ_DATA; - - /* Check if there's a specific error handling for this */ - rfalErrorHandling(); - break; - } - else if( (irqs & ST25R3911_IRQ_MASK_COL) != 0U ) - { - gRFAL.TxRx.status = ERR_RF_COLLISION; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_READ_DATA; - - /* Check if there's a specific error handling for this */ - rfalErrorHandling(); - break; - } - else if( ((irqs & ST25R3911_IRQ_MASK_EOF) != 0U) && ((irqs & ST25R3911_IRQ_MASK_RXE) == 0U) ) - { - gRFAL.TxRx.status = ERR_LINK_LOSS; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - break; - } - else if( ((irqs & ST25R3911_IRQ_MASK_RXE) != 0U) || (gRFAL.TxRx.rxse) ) - { - /* Reception ended without any error indication, * - * check FIFO status for malformed or incomplete frames */ - - /* Check if the reception ends with an incomplete byte (residual bits) */ - if( rfalFIFOStatusIsIncompleteByte() ) - { - gRFAL.TxRx.status = ERR_INCOMPLETE_BYTE; - } - /* Check if the reception ends with missing parity bit */ - else if( rfalFIFOStatusIsMissingPar() ) - { - gRFAL.TxRx.status = ERR_FRAMING; - } - else - { - /* MISRA 15.7 - Empty else */ - } - - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_READ_DATA; - } - else - { - gRFAL.TxRx.status = ERR_IO; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - break; - } - - /* fall through */ - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_READ_DATA: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - tmp = rfalFIFOStatusGetNumBytes(); - - /*******************************************************************************/ - /* Check if CRC should not be placed in rxBuf */ - if( ((gRFAL.TxRx.ctx.flags & (uint32_t)RFAL_TXRX_FLAGS_CRC_RX_KEEP) == 0U) ) - { - /* Check if CRC is being placed into the FIFO and if received frame was bigger than CRC */ - if( st25r3911IsCRCinFIFO() && ((gRFAL.fifo.bytesTotal + tmp) > 0U) ) - { - /* By default CRC will not be placed into the rxBuffer */ - if( ( tmp > (uint8_t)RFAL_CRC_LEN) ) - { - tmp -= (uint8_t)RFAL_CRC_LEN; - } - /* If the CRC was already placed into rxBuffer (due to WL interrupt where CRC was already in FIFO Read) - * cannot remove it from rxBuf. Can only remove it from rxBufLen not indicate the presence of CRC */ - else if(gRFAL.fifo.bytesTotal > (uint16_t)RFAL_CRC_LEN) - { - gRFAL.fifo.bytesTotal -= (uint16_t)RFAL_CRC_LEN; - } - else - { - /* MISRA 15.7 - Empty else */ - } - } - } - - gRFAL.fifo.bytesTotal += tmp; /* add to total bytes counter */ - - /*******************************************************************************/ - /* Check if remaining bytes fit on the rxBuf available */ - if( gRFAL.fifo.bytesTotal > rfalConvBitsToBytes(gRFAL.TxRx.ctx.rxBufLen) ) - { - tmp = (uint8_t)( rfalConvBitsToBytes(gRFAL.TxRx.ctx.rxBufLen) - gRFAL.fifo.bytesWritten); - - gRFAL.TxRx.status = ERR_NOMEM; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - } - - /*******************************************************************************/ - /* Retrieve remaining bytes from FIFO to rxBuf, and assign total length rcvd */ - st25r3911ReadFifo( &gRFAL.TxRx.ctx.rxBuf[gRFAL.fifo.bytesWritten], tmp); - if( (gRFAL.TxRx.ctx.rxRcvdLen != NULL) ) - { - (*gRFAL.TxRx.ctx.rxRcvdLen) = (uint16_t)rfalConvBytesToBits( gRFAL.fifo.bytesTotal ); - if( rfalFIFOStatusIsIncompleteByte() ) - { - (*gRFAL.TxRx.ctx.rxRcvdLen) -= (RFAL_BITS_IN_BYTE - rfalFIFOGetNumIncompleteBits()); - } - } - - #if RFAL_FEATURE_NFCV - /*******************************************************************************/ - /* Decode sub bit stream into payload bits for NFCV, if no error found so far */ - if( ((RFAL_MODE_POLL_NFCV == gRFAL.mode) || (RFAL_MODE_POLL_PICOPASS == gRFAL.mode)) && (gRFAL.TxRx.status == ERR_BUSY) ) - { - ReturnCode ret; - uint16_t offset = 0; - - ret = iso15693VICCDecode(gRFAL.TxRx.ctx.rxBuf, gRFAL.fifo.bytesTotal, - gRFAL.nfcvData.origCtx.rxBuf, rfalConvBitsToBytes(gRFAL.nfcvData.origCtx.rxBufLen), &offset, gRFAL.nfcvData.origCtx.rxRcvdLen, gRFAL.nfcvData.ignoreBits, (RFAL_MODE_POLL_PICOPASS == gRFAL.mode) ); - - if( ((ERR_NONE == ret) || (ERR_CRC == ret)) - && (((uint32_t)RFAL_TXRX_FLAGS_CRC_RX_KEEP & gRFAL.nfcvData.origCtx.flags) == 0U) - && ((*gRFAL.nfcvData.origCtx.rxRcvdLen % RFAL_BITS_IN_BYTE) == 0U) - && (*gRFAL.nfcvData.origCtx.rxRcvdLen >= rfalConvBytesToBits(RFAL_CRC_LEN) ) - ) - { - *gRFAL.nfcvData.origCtx.rxRcvdLen -= (uint16_t)rfalConvBytesToBits(RFAL_CRC_LEN); /* Remove CRC */ - } - - /* Restore original ctx */ - gRFAL.TxRx.ctx = gRFAL.nfcvData.origCtx; - gRFAL.TxRx.status = ((ret != ERR_NONE) ? ret : ERR_BUSY); - } - #endif /* RFAL_FEATURE_NFCV */ - - /*******************************************************************************/ - /* If an error as been marked/detected don't fall into to RX_DONE */ - if( gRFAL.TxRx.status != ERR_BUSY ) - { - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - break; - } - - if( rfalIsModeActiveComm( gRFAL.mode ) ) - { - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_WAIT_EOF; - break; - } - - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_DONE; - /* fall through */ - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_DONE: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - /*Check if Observation Mode was enabled and disable it on ST25R391x */ - rfalCheckDisableObsMode(); - - /* Clean up Transceive */ - rfalCleanupTransceive(); - - - gRFAL.TxRx.status = ERR_NONE; - gRFAL.TxRx.state = RFAL_TXRX_STATE_IDLE; - break; - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_READ_FIFO: - - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911B Errata #1.1 */ - /* ST25R3911 may indicate RXS without RXE afterwards, this happens rarely on */ - /* corrupted frames. */ - /* Re-Start SW timer to handle an eventual missing RXE */ - rfalTimerStart( gRFAL.tmr.RXE, RFAL_NORXE_TOUT ); - /*******************************************************************************/ - - - tmp = rfalFIFOStatusGetNumBytes(); - gRFAL.fifo.bytesTotal += tmp; - - /*******************************************************************************/ - /* Calculate the amount of bytes that still fits in rxBuf */ - aux = (uint8_t)(( gRFAL.fifo.bytesTotal > rfalConvBitsToBytes(gRFAL.TxRx.ctx.rxBufLen) ) ? (rfalConvBitsToBytes(gRFAL.TxRx.ctx.rxBufLen) - gRFAL.fifo.bytesWritten) : tmp); - - /*******************************************************************************/ - /* Retrieve incoming bytes from FIFO to rxBuf, and store already read amount */ - st25r3911ReadFifo( &gRFAL.TxRx.ctx.rxBuf[gRFAL.fifo.bytesWritten], aux); - gRFAL.fifo.bytesWritten += aux; - - /*******************************************************************************/ - /* If the bytes already read were not the full FIFO WL, dump the remaining * - * FIFO so that ST25R391x can continue with reception */ - if( aux < tmp ) - { - st25r3911ReadFifo( NULL, (tmp - aux) ); - } - - rfalFIFOStatusClear(); - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_WAIT_RXE; - break; - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_FAIL: - - /*Check if Observation Mode was enabled and disable it on ST25R391x */ - rfalCheckDisableObsMode(); - - /* Clean up Transceive */ - rfalCleanupTransceive(); - - /* Error should be assigned by previous state */ - if( gRFAL.TxRx.status == ERR_BUSY ) - { - gRFAL.TxRx.status = ERR_SYSTEM; - } - - /*rfalLogD( "RFAL: curSt: %d Error: %d \r\n", gRFAL.TxRx.state, gRFAL.TxRx.status );*/ - gRFAL.TxRx.state = RFAL_TXRX_STATE_IDLE; - break; - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_WAIT_EON: - - irqs = st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_EON | ST25R3911_IRQ_MASK_NRE) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - break; /* No interrupt to process */ - } - - if( (irqs & ST25R3911_IRQ_MASK_EON) != 0U ) - { - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_WAIT_RXS; - } - - if( (irqs & ST25R3911_IRQ_MASK_NRE) != 0U ) - { - /* ST25R3911 uses the NRT to measure other device's Field On max time: Tadt + (n x Trfw) */ - gRFAL.TxRx.status = ERR_LINK_LOSS; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - } - break; - - - /*******************************************************************************/ - case RFAL_TXRX_STATE_RX_WAIT_EOF: - - irqs = st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_CAT | ST25R3911_IRQ_MASK_CAC) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - break; /* No interrupt to process */ - } - - if( (irqs & ST25R3911_IRQ_MASK_CAT) != 0U ) - { - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_DONE; - } - else if( (irqs & ST25R3911_IRQ_MASK_CAC) != 0U ) - { - gRFAL.TxRx.status = ERR_RF_COLLISION; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - } - else - { - gRFAL.TxRx.status = ERR_IO; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - } - break; - - - /*******************************************************************************/ - default: - gRFAL.TxRx.status = ERR_SYSTEM; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_FAIL; - break; - } -} - -/*******************************************************************************/ -static void rfalFIFOStatusUpdate( void ) -{ - if(gRFAL.fifo.status[RFAL_FIFO_STATUS_REG2] == RFAL_FIFO_STATUS_INVALID) - { - st25r3911ReadMultipleRegisters( ST25R3911_REG_FIFO_RX_STATUS1, gRFAL.fifo.status, ST25R3911_FIFO_STATUS_LEN ); - } -} - - -/*******************************************************************************/ -static void rfalFIFOStatusClear( void ) -{ - gRFAL.fifo.status[RFAL_FIFO_STATUS_REG2] = RFAL_FIFO_STATUS_INVALID; -} - - -/*******************************************************************************/ -static uint8_t rfalFIFOStatusGetNumBytes( void ) -{ - rfalFIFOStatusUpdate(); - - return gRFAL.fifo.status[RFAL_FIFO_STATUS_REG1]; - -} - - -/*******************************************************************************/ -static bool rfalFIFOStatusIsIncompleteByte( void ) -{ - rfalFIFOStatusUpdate(); - return ((gRFAL.fifo.status[RFAL_FIFO_STATUS_REG2] & (ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb | ST25R3911_REG_FIFO_RX_STATUS2_fifo_ncp)) != 0U); -} - - -/*******************************************************************************/ -static bool rfalFIFOStatusIsMissingPar( void ) -{ - rfalFIFOStatusUpdate(); - return ((gRFAL.fifo.status[RFAL_FIFO_STATUS_REG2] & ST25R3911_REG_FIFO_RX_STATUS2_np_lb) != 0U); -} - - -/*******************************************************************************/ -static uint8_t rfalFIFOGetNumIncompleteBits( void ) -{ - rfalFIFOStatusUpdate(); - return ((gRFAL.fifo.status[RFAL_FIFO_STATUS_REG2] & ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb) >> ST25R3911_REG_FIFO_RX_STATUS2_shift_fifo_lb); -} - - -#if RFAL_FEATURE_NFCA - -/*******************************************************************************/ -ReturnCode rfalISO14443ATransceiveShortFrame( rfal14443AShortFrameCmd txCmd, uint8_t* rxBuf, uint8_t rxBufLen, uint16_t* rxRcvdLen, uint32_t fwt ) -{ - ReturnCode ret; - uint8_t directCmd; - - /* Check if RFAL is properly initialized */ - if( !st25r3911IsTxEnabled() || (gRFAL.state < RFAL_STATE_MODE_SET) || (( gRFAL.mode != RFAL_MODE_POLL_NFCA ) && ( gRFAL.mode != RFAL_MODE_POLL_NFCA_T1T )) ) - { - return ERR_WRONG_STATE; - } - - /* Check for valid parameters */ - if( (rxBuf == NULL) || (rxRcvdLen == NULL) || (fwt == RFAL_FWT_NONE) ) - { - return ERR_PARAM; - } - - /*******************************************************************************/ - /* Select the Direct Command to be performed */ - switch (txCmd) - { - case RFAL_14443A_SHORTFRAME_CMD_WUPA: - directCmd = ST25R3911_CMD_TRANSMIT_WUPA; - break; - - case RFAL_14443A_SHORTFRAME_CMD_REQA: - directCmd = ST25R3911_CMD_TRANSMIT_REQA; - break; - - default: - return ERR_PARAM; - } - - - /*******************************************************************************/ - /* Enable anti collision to recognise collision in first byte of SENS_REQ */ - st25r3911SetRegisterBits( ST25R3911_REG_ISO14443A_NFC, ST25R3911_REG_ISO14443A_NFC_antcl); - - /* Disable CRC while receiving since ATQA has no CRC included */ - st25r3911SetRegisterBits( ST25R3911_REG_AUX, ST25R3911_REG_AUX_no_crc_rx ); - - - /*******************************************************************************/ - /* Wait for GT and FDT */ - while( !rfalIsGTExpired() ) { /* MISRA 15.6: mandatory brackets */ }; - while( st25r3911IsGPTRunning() ) { /* MISRA 15.6: mandatory brackets */ }; - - gRFAL.tmr.GT = RFAL_TIMING_NONE; - - - /*******************************************************************************/ - /* Prepare for Transceive, Receive only (bypass Tx states) */ - gRFAL.TxRx.ctx.flags = ((uint32_t) RFAL_TXRX_FLAGS_CRC_TX_MANUAL | (uint32_t)RFAL_TXRX_FLAGS_CRC_RX_KEEP ); - gRFAL.TxRx.ctx.rxBuf = rxBuf; - gRFAL.TxRx.ctx.rxBufLen = rxBufLen; - gRFAL.TxRx.ctx.rxRcvdLen = rxRcvdLen; - - /*******************************************************************************/ - /* Load NRT with FWT */ - st25r3911SetNoResponseTime_64fcs( rfalConv1fcTo64fc( MIN( (fwt + RFAL_FWT_ADJUSTMENT + RFAL_FWT_A_ADJUSTMENT), RFAL_ST25R3911_NRT_MAX_1FC ) ) ); - - if( gRFAL.timings.FDTListen != RFAL_TIMING_NONE ) - { - /* Set Minimum FDT(Listen) in which PICC is not allowed to send a response */ - st25r3911WriteRegister( ST25R3911_REG_MASK_RX_TIMER, (uint8_t)rfalConv1fcTo64fc( ((RFAL_FDT_LISTEN_MRT_ADJUSTMENT + RFAL_FDT_LISTEN_A_ADJUSTMENT) > gRFAL.timings.FDTListen) ? RFAL_ST25R3911_MRT_MIN_1FC : (gRFAL.timings.FDTListen - (RFAL_FDT_LISTEN_MRT_ADJUSTMENT + RFAL_FDT_LISTEN_A_ADJUSTMENT)) ) ); - } - - /* In Passive communications General Purpose Timer is used to measure FDT Poll */ - if( gRFAL.timings.FDTPoll != RFAL_TIMING_NONE ) - { - /* Configure GPT to start at RX end */ - st25r3911StartGPTimer_8fcs( (uint16_t)rfalConv1fcTo8fc( MIN( gRFAL.timings.FDTPoll, (gRFAL.timings.FDTPoll - RFAL_FDT_POLL_ADJUSTMENT) ) ), ST25R3911_REG_GPT_CONTROL_gptc_erx ); - } - - /*******************************************************************************/ - rfalPrepareTransceive(); - - /* Also enable bit collision interrupt */ - st25r3911GetInterrupt( ST25R3911_IRQ_MASK_COL ); - st25r3911EnableInterrupts( ST25R3911_IRQ_MASK_COL ); - - /*Check if Observation Mode is enabled and set it on ST25R391x */ - rfalCheckEnableObsModeTx(); - - /*******************************************************************************/ - /* Chip bug: Clear nbtx bits before sending WUPA/REQA - otherwise ST25R3911 will report parity error */ - st25r3911WriteRegister( ST25R3911_REG_NUM_TX_BYTES2, 0); - - /* Send either WUPA or REQA. All affected tags will backscatter ATQA and change to READY state */ - st25r3911ExecuteCommand( directCmd ); - - /* Wait for TXE */ - if( st25r3911WaitForInterruptsTimed( ST25R3911_IRQ_MASK_TXE, (uint16_t)MAX( rfalConv1fcToMs( fwt ), RFAL_ST25R3911_SW_TMR_MIN_1MS ) ) == 0U) - { - ret = ERR_IO; - } - else - { - /*Check if Observation Mode is enabled and set it on ST25R391x */ - rfalCheckEnableObsModeRx(); - - /* Jump into a transceive Rx state for reception (bypass Tx states) */ - gRFAL.state = RFAL_STATE_TXRX; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_IDLE; - gRFAL.TxRx.status = ERR_BUSY; - - /* Execute Transceive Rx blocking */ - ret = rfalTransceiveBlockingRx(); - } - - - /* Disable Collision interrupt */ - st25r3911DisableInterrupts( (ST25R3911_IRQ_MASK_COL) ); - - /* Disable anti collision again */ - st25r3911ClrRegisterBits( ST25R3911_REG_ISO14443A_NFC, ST25R3911_REG_ISO14443A_NFC_antcl ); - - /* ReEnable CRC on Rx */ - st25r3911ClrRegisterBits(ST25R3911_REG_AUX, ST25R3911_REG_AUX_no_crc_rx ); - - return ret; -} - -/*******************************************************************************/ -ReturnCode rfalISO14443ATransceiveAnticollisionFrame( uint8_t *buf, uint8_t *bytesToSend, uint8_t *bitsToSend, uint16_t *rxLength, uint32_t fwt ) -{ - ReturnCode ret; - rfalTransceiveContext ctx; - uint8_t collByte; - uint8_t collData; - - /* Check if RFAL is properly initialized */ - if( (gRFAL.state < RFAL_STATE_MODE_SET) || ( gRFAL.mode != RFAL_MODE_POLL_NFCA ) ) - { - return ERR_WRONG_STATE; - } - - /* Check for valid parameters */ - if( (buf == NULL) || (bytesToSend == NULL) || (bitsToSend == NULL) || (rxLength == NULL) ) - { - return ERR_PARAM; - } - - /*******************************************************************************/ - /* Set speficic Analog Config for Anticolission if needed */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_ANTICOL) ); - - - /*******************************************************************************/ - /* Enable anti collision to recognise collision in first byte of SENS_REQ */ - st25r3911SetRegisterBits( ST25R3911_REG_ISO14443A_NFC, ST25R3911_REG_ISO14443A_NFC_antcl ); - - /* Disable CRC while receiving */ - st25r3911SetRegisterBits( ST25R3911_REG_AUX, ST25R3911_REG_AUX_no_crc_rx ); - - - - /*******************************************************************************/ - /* Prepare for Transceive */ - ctx.flags = ( (uint32_t)RFAL_TXRX_FLAGS_CRC_TX_MANUAL | (uint32_t)RFAL_TXRX_FLAGS_CRC_RX_KEEP | (uint32_t)RFAL_TXRX_FLAGS_AGC_OFF ); /* Disable Automatic Gain Control (AGC) for better detection of collision */ - ctx.txBuf = buf; - ctx.txBufLen = (uint16_t)(rfalConvBytesToBits( *bytesToSend ) + *bitsToSend ); - ctx.rxBuf = &buf[*bytesToSend]; - ctx.rxBufLen = (uint16_t)rfalConvBytesToBits( RFAL_ISO14443A_SDD_RES_LEN ); - ctx.rxRcvdLen = rxLength; - ctx.fwt = fwt; - - rfalStartTransceive( &ctx ); - - /* Additionally enable bit collision interrupt */ - st25r3911GetInterrupt( ST25R3911_IRQ_MASK_COL ); - st25r3911EnableInterrupts( ST25R3911_IRQ_MASK_COL ); - - /*******************************************************************************/ - collByte = 0; - - /* save the collision byte */ - if ((*bitsToSend) > 0U) - { - buf[(*bytesToSend)] <<= (RFAL_BITS_IN_BYTE - (*bitsToSend)); - buf[(*bytesToSend)] >>= (RFAL_BITS_IN_BYTE - (*bitsToSend)); - collByte = buf[(*bytesToSend)]; - } - - - /*******************************************************************************/ - /* Run Transceive blocking */ - ret = rfalTransceiveRunBlockingTx(); - if( ret == ERR_NONE) - { - ret = rfalTransceiveBlockingRx(); - - /*******************************************************************************/ - if ((*bitsToSend) > 0U) - { - buf[(*bytesToSend)] >>= (*bitsToSend); - buf[(*bytesToSend)] <<= (*bitsToSend); - buf[(*bytesToSend)] |= collByte; - } - - if( (ERR_RF_COLLISION == ret) ) - { - /* read out collision register */ - st25r3911ReadRegister( ST25R3911_REG_COLLISION_STATUS, &collData); - - (*bytesToSend) = ((collData >> ST25R3911_REG_COLLISION_STATUS_shift_c_byte) & 0x0FU); // 4-bits Byte information - (*bitsToSend) = ((collData >> ST25R3911_REG_COLLISION_STATUS_shift_c_bit) & 0x07U); // 3-bits bit information - - } - } - - - /*******************************************************************************/ - /* Disable Collision interrupt */ - st25r3911DisableInterrupts( (ST25R3911_IRQ_MASK_COL) ); - - /* Disable anti collision again */ - st25r3911ClrRegisterBits( ST25R3911_REG_ISO14443A_NFC, ST25R3911_REG_ISO14443A_NFC_antcl ); - - /* ReEnable CRC on Rx */ - st25r3911ClrRegisterBits( ST25R3911_REG_AUX, ST25R3911_REG_AUX_no_crc_rx ); - /*******************************************************************************/ - - - /* Restore common Analog configurations for this mode */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX) ); - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX) ); - - return ret; -} - -#endif /* RFAL_FEATURE_NFCA */ - -#if RFAL_FEATURE_NFCV - -/*******************************************************************************/ -ReturnCode rfalISO15693TransceiveAnticollisionFrame( uint8_t *txBuf, uint8_t txBufLen, uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen ) -{ - ReturnCode ret; - rfalTransceiveContext ctx; - - /* Check if RFAL is properly initialized */ - if( (gRFAL.state < RFAL_STATE_MODE_SET) || ( gRFAL.mode != RFAL_MODE_POLL_NFCV ) ) - { - return ERR_WRONG_STATE; - } - - /*******************************************************************************/ - /* Set speficic Analog Config for Anticolission if needed */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_ANTICOL) ); - - - /* Ignoring collisions before the UID (RES_FLAG + DSFID) */ - gRFAL.nfcvData.ignoreBits = (uint16_t)RFAL_ISO15693_IGNORE_BITS; - - /*******************************************************************************/ - /* Prepare for Transceive */ - ctx.flags = ((txBufLen==0U)?(uint32_t)RFAL_TXRX_FLAGS_CRC_TX_MANUAL:(uint32_t)RFAL_TXRX_FLAGS_CRC_TX_AUTO) | (uint32_t)RFAL_TXRX_FLAGS_CRC_RX_KEEP | (uint32_t)RFAL_TXRX_FLAGS_AGC_OFF | ((txBufLen==0U)?(uint32_t)RFAL_TXRX_FLAGS_NFCV_FLAG_MANUAL:(uint32_t)RFAL_TXRX_FLAGS_NFCV_FLAG_AUTO); /* Disable Automatic Gain Control (AGC) for better detection of collision */ - ctx.txBuf = txBuf; - ctx.txBufLen = (uint16_t)rfalConvBytesToBits(txBufLen); - ctx.rxBuf = rxBuf; - ctx.rxBufLen = (uint16_t)rfalConvBytesToBits(rxBufLen); - ctx.rxRcvdLen = actLen; - ctx.fwt = rfalConv64fcTo1fc(ISO15693_FWT); - - rfalStartTransceive( &ctx ); - - /*******************************************************************************/ - /* Run Transceive blocking */ - ret = rfalTransceiveRunBlockingTx(); - if( ret == ERR_NONE) - { - ret = rfalTransceiveBlockingRx(); - } - - /* Restore common Analog configurations for this mode */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX) ); - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX) ); - - gRFAL.nfcvData.ignoreBits = 0; - return ret; -} - -/*******************************************************************************/ -ReturnCode rfalISO15693TransceiveEOFAnticollision( uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen ) -{ - uint8_t dummy; - - return rfalISO15693TransceiveAnticollisionFrame( &dummy, 0, rxBuf, rxBufLen, actLen ); -} - -/*******************************************************************************/ -ReturnCode rfalISO15693TransceiveEOF( uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen ) -{ - ReturnCode ret; - uint8_t dummy; - - /* Check if RFAL is properly initialized */ - if( ( gRFAL.state < RFAL_STATE_MODE_SET ) || ( gRFAL.mode != RFAL_MODE_POLL_NFCV ) ) - { - return ERR_WRONG_STATE; - } - - /*******************************************************************************/ - /* Run Transceive blocking */ - ret = rfalTransceiveBlockingTxRx( &dummy, - 0, - rxBuf, - rxBufLen, - actLen, - ( (uint32_t)RFAL_TXRX_FLAGS_CRC_TX_MANUAL | (uint32_t)RFAL_TXRX_FLAGS_CRC_RX_KEEP |(uint32_t)RFAL_TXRX_FLAGS_AGC_ON ), - rfalConv64fcTo1fc(ISO15693_FWT) ); - return ret; -} - -#endif /* RFAL_FEATURE_NFCV */ - -#if RFAL_FEATURE_NFCF - -/*******************************************************************************/ -ReturnCode rfalFeliCaPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes* pollResList, uint8_t pollResListSize, uint8_t *devicesDetected, uint8_t *collisionsDetected ) -{ - ReturnCode ret; - uint8_t frame[RFAL_FELICA_POLL_REQ_LEN - RFAL_FELICA_LEN_LEN]; // LEN is added by ST25R3911 automatically - uint16_t actLen; - uint8_t frameIdx; - uint8_t devDetected; - uint8_t colDetected; - rfalEHandling curHandling; - uint8_t nbSlots; - - /* Check if RFAL is properly initialized */ - if( (gRFAL.state < RFAL_STATE_MODE_SET) || ( gRFAL.mode != RFAL_MODE_POLL_NFCF ) ) - { - return ERR_WRONG_STATE; - } - - frameIdx = 0; - colDetected = 0; - devDetected = 0; - nbSlots = (uint8_t)slots; - - /*******************************************************************************/ - /* Compute SENSF_REQ frame */ - frame[frameIdx++] = (uint8_t)FELICA_CMD_POLLING; /* CMD: SENF_REQ */ - frame[frameIdx++] = (uint8_t)(sysCode >> 8); /* System Code (SC) */ - frame[frameIdx++] = (uint8_t)(sysCode & 0xFFU); /* System Code (SC) */ - frame[frameIdx++] = reqCode; /* Communication Parameter Request (RC)*/ - frame[frameIdx++] = nbSlots; /* TimeSlot (TSN) */ - - - /*******************************************************************************/ - /* NRT should not stop on reception - Use EMVCo mode to run NRT in nrt_emv * - * ERRORHANDLING_EMVCO has no special handling for NFC-F mode */ - curHandling = gRFAL.conf.eHandling; - rfalSetErrorHandling( RFAL_ERRORHANDLING_EMVCO ); - - /*******************************************************************************/ - /* Run transceive blocking, - * Calculate Total Response Time in(64/fc): - * 512 PICC process time + (n * 256 Time Slot duration) */ - ret = rfalTransceiveBlockingTx( frame, - (uint16_t)frameIdx, - (uint8_t*)gRFAL.nfcfData.pollResponses, - RFAL_FELICA_POLL_RES_LEN, - &actLen, - (RFAL_TXRX_FLAGS_DEFAULT), - rfalConv64fcTo1fc( RFAL_FELICA_POLL_DELAY_TIME + (RFAL_FELICA_POLL_SLOT_TIME * ((uint32_t)nbSlots + 1U)) ) ); - - /*******************************************************************************/ - /* If Tx OK, Wait for all responses, store them as soon as they appear */ - if( ret == ERR_NONE ) - { - bool timeout; - - do - { - ret = rfalTransceiveBlockingRx(); - if( ret == ERR_TIMEOUT ) - { - /* Upon timeout the full Poll Delay + (Slot time)*(nbSlots) has expired */ - timeout = true; - } - else - { - /* Reception done, reEnabled Rx for following Slot */ - st25r3911ExecuteCommand( ST25R3911_CMD_UNMASK_RECEIVE_DATA ); - st25r3911ExecuteCommand( ST25R3911_CMD_CLEAR_SQUELCH ); - - /* If the reception was OK, new device found */ - if( ret == ERR_NONE ) - { - devDetected++; - - /* Overwrite the Transceive context for the next reception */ - gRFAL.TxRx.ctx.rxBuf = (uint8_t*)gRFAL.nfcfData.pollResponses[devDetected]; - } - /* If the reception was not OK, mark as collision */ - else - { - colDetected++; - } - - /* Check whether NRT has expired meanwhile */ - timeout = st25r3911CheckReg( ST25R3911_REG_REGULATOR_RESULT, ST25R3911_REG_REGULATOR_RESULT_nrt_on, 0x00 ); - if( !timeout ) - { - /* Jump again into transceive Rx state for the following reception */ - gRFAL.TxRx.status = ERR_BUSY; - gRFAL.state = RFAL_STATE_TXRX; - gRFAL.TxRx.state = RFAL_TXRX_STATE_RX_IDLE; - } - } - }while( ((nbSlots--) != 0U) && !timeout ); - } - - /*******************************************************************************/ - /* Restore NRT to normal mode - back to previous error handling */ - rfalSetErrorHandling( curHandling ); - - /*******************************************************************************/ - /* Assign output parameters if requested */ - - if( (pollResList != NULL) && (pollResListSize > 0U) && (devDetected > 0U) ) - { - ST_MEMCPY( pollResList, gRFAL.nfcfData.pollResponses, (RFAL_FELICA_POLL_RES_LEN * (uint32_t)MIN(pollResListSize, devDetected) ) ); - } - - if( devicesDetected != NULL ) - { - *devicesDetected = devDetected; - } - - if( collisionsDetected != NULL ) - { - *collisionsDetected = colDetected; - } - - return (( (colDetected != 0U) || (devDetected != 0U)) ? ERR_NONE : ret); -} - -#endif /* RFAL_FEATURE_NFCF */ - - -/***************************************************************************** - * Listen Mode * - *****************************************************************************/ - - - -/*******************************************************************************/ -bool rfalIsExtFieldOn( void ) -{ - return st25r3911IsExtFieldOn(); -} - -#if RFAL_FEATURE_LISTEN_MODE - -/*******************************************************************************/ -ReturnCode rfalListenStart( uint32_t lmMask, const rfalLmConfPA *confA, const rfalLmConfPB *confB, const rfalLmConfPF *confF, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rxLen ) -{ - NO_WARNING(confA); - NO_WARNING(confB); - NO_WARNING(confF); - - - gRFAL.Lm.state = RFAL_LM_STATE_NOT_INIT; - - - /*******************************************************************************/ - if( ((lmMask & RFAL_LM_MASK_NFCA) != 0U) || ((lmMask & RFAL_LM_MASK_NFCB) != 0U) || ((lmMask & RFAL_LM_MASK_NFCF) != 0U) ) - { - return ERR_NOTSUPP; - } - - - /*******************************************************************************/ - if( (lmMask & RFAL_LM_MASK_ACTIVE_P2P) != 0U ) - { - gRFAL.state = RFAL_STATE_LM; - - gRFAL.Lm.rxBuf = rxBuf; - gRFAL.Lm.rxBufLen = rxBufLen; - gRFAL.Lm.rxLen = rxLen; - *gRFAL.Lm.rxLen = 0; - gRFAL.Lm.dataFlag = false; - - /* Disable GPT trigger source */ - st25r3911ChangeRegisterBits( ST25R3911_REG_GPT_CONTROL, ST25R3911_REG_GPT_CONTROL_gptc_mask, ST25R3911_REG_GPT_CONTROL_gptc_no_trigger ); - - /* On Bit Rate Detection Mode ST25R391x will filter incoming frames during MRT time starting on External Field On event, use 512/fc steps */ - st25r3911WriteRegister( ST25R3911_REG_MASK_RX_TIMER, (uint8_t)rfalConv1fcTo512fc( RFAL_LM_GT ) ); - - /* Restore default settings on NFCIP1 mode, Receiving parity + CRC bits and manual Tx Parity*/ - st25r3911ClrRegisterBits( ST25R3911_REG_ISO14443A_NFC, (ST25R3911_REG_ISO14443A_NFC_no_tx_par | ST25R3911_REG_ISO14443A_NFC_no_rx_par | ST25R3911_REG_ISO14443A_NFC_nfc_f0) ); - - /* Enable External Field Detector */ - st25r3911SetRegisterBits( ST25R3911_REG_AUX, ST25R3911_REG_AUX_en_fd ); - - /* Enable Receiver */ - st25r3911ChangeRegisterBits( ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_rx_en, ST25R3911_REG_OP_CONTROL_rx_en ); - - /* Set Analog configurations for generic Listen mode */ - /* Not on SetState(POWER OFF) as otherwise would be applied on every Field Event */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON) ); - - /* Initialize as POWER_OFF and set proper mode in RF Chip */ - rfalListenSetState( RFAL_LM_STATE_POWER_OFF ); - } - else - { - return ERR_REQUEST; /* Listen Start called but no mode was enabled */ - } - - return ERR_NONE; -} - - - -/*******************************************************************************/ -static ReturnCode rfalRunListenModeWorker( void ) -{ - volatile uint32_t irqs; - uint8_t tmp; - - if( gRFAL.state != RFAL_STATE_LM ) - { - return ERR_WRONG_STATE; - } - - switch( gRFAL.Lm.state ) - { - /*******************************************************************************/ - case RFAL_LM_STATE_POWER_OFF: - - irqs = st25r3911GetInterrupt( ( ST25R3911_IRQ_MASK_EON ) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - break; /* No interrupt to process */ - } - - if( (irqs & ST25R3911_IRQ_MASK_EON) != 0U ) - { - rfalListenSetState( RFAL_LM_STATE_IDLE ); - } - else - { - break; - } - /* fall through */ - - - /*******************************************************************************/ - case RFAL_LM_STATE_IDLE: /* PRQA S 2003 # MISRA 16.3 - Intentional fall through */ - - irqs = st25r3911GetInterrupt( ( ST25R3911_IRQ_MASK_NFCT | ST25R3911_IRQ_MASK_RXE | ST25R3911_IRQ_MASK_EOF ) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - break; /* No interrupt to process */ - } - - if( (irqs & ST25R3911_IRQ_MASK_NFCT) != 0U ) - { - /* Retrieve detected bitrate */ - uint8_t newBr; - st25r3911ReadRegister( ST25R3911_REG_NFCIP1_BIT_RATE, &newBr ); - newBr >>= ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate_shift; - - if (newBr > ST25R3911_REG_BIT_RATE_rxrate_424) - { - newBr = ST25R3911_REG_BIT_RATE_rxrate_424; - } - - gRFAL.Lm.brDetected = (rfalBitRate)(newBr); /* PRQA S 4342 # MISRA 10.5 - Guaranteed that no invalid enum values may be created. See also equalityGuard_RFAL_BR_106 ff.*/ - } - if( ((irqs & ST25R3911_IRQ_MASK_RXE) != 0U) && (gRFAL.Lm.brDetected != RFAL_BR_KEEP) ) - { - irqs = st25r3911GetInterrupt( ( ST25R3911_IRQ_MASK_RXE | ST25R3911_IRQ_MASK_EOF | ST25R3911_IRQ_MASK_CRC | ST25R3911_IRQ_MASK_PAR | ST25R3911_IRQ_MASK_ERR2 | ST25R3911_IRQ_MASK_ERR1 ) ); - - if( ((irqs & ST25R3911_IRQ_MASK_CRC) != 0U) || ((irqs & ST25R3911_IRQ_MASK_PAR) != 0U) || ((irqs & ST25R3911_IRQ_MASK_ERR1) != 0U) ) - { - /* nfc_ar may have triggered RF Collision Avoidance, disable it before executing Clear (Stop All activities) */ - st25r3911ClrRegisterBits( ST25R3911_REG_MODE, ST25R3911_REG_MODE_nfc_ar ); - st25r3911ExecuteCommand( ST25R3911_CMD_CLEAR_FIFO ); - st25r3911ExecuteCommand( ST25R3911_CMD_UNMASK_RECEIVE_DATA ); - st25r3911SetRegisterBits( ST25R3911_REG_MODE, ST25R3911_REG_MODE_nfc_ar ); - st25r3911TxOff(); - break; /* A bad reception occurred, remain in same state */ - } - - /* Retrieve received data */ - st25r3911ReadRegister(ST25R3911_REG_FIFO_RX_STATUS1, &tmp); - *gRFAL.Lm.rxLen = tmp; - - st25r3911ReadFifo( gRFAL.Lm.rxBuf, (uint8_t)MIN( *gRFAL.Lm.rxLen, rfalConvBitsToBytes(gRFAL.Lm.rxBufLen) ) ); - - /* Check if the data we got has at least the CRC and remove it, otherwise leave at 0 */ - *gRFAL.Lm.rxLen -= ((*gRFAL.Lm.rxLen > RFAL_CRC_LEN) ? RFAL_CRC_LEN : *gRFAL.Lm.rxLen); - *gRFAL.Lm.rxLen = (uint16_t)rfalConvBytesToBits( *gRFAL.Lm.rxLen ); - gRFAL.Lm.dataFlag = true; - - /*Check if Observation Mode was enabled and disable it on ST25R391x */ - rfalCheckDisableObsMode(); - } - else if( ((irqs & ST25R3911_IRQ_MASK_EOF) != 0U) && (!gRFAL.Lm.dataFlag) ) - { - rfalListenSetState( RFAL_LM_STATE_POWER_OFF ); - } - else - { - /* MISRA 15.7 - Empty else */ - } - break; - - /*******************************************************************************/ - case RFAL_LM_STATE_READY_F: - case RFAL_LM_STATE_READY_A: - case RFAL_LM_STATE_ACTIVE_A: - case RFAL_LM_STATE_ACTIVE_Ax: - case RFAL_LM_STATE_SLEEP_A: - case RFAL_LM_STATE_SLEEP_B: - case RFAL_LM_STATE_SLEEP_AF: - case RFAL_LM_STATE_READY_Ax: - case RFAL_LM_STATE_CARDEMU_4A: - case RFAL_LM_STATE_CARDEMU_4B: - case RFAL_LM_STATE_CARDEMU_3: - return ERR_INTERNAL; - - case RFAL_LM_STATE_TARGET_F: - case RFAL_LM_STATE_TARGET_A: - break; - - /*******************************************************************************/ - default: - return ERR_WRONG_STATE; - } - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalListenStop( void ) -{ - gRFAL.Lm.state = RFAL_LM_STATE_NOT_INIT; - - /*Check if Observation Mode was enabled and disable it on ST25R391x */ - rfalCheckDisableObsMode(); - - /* Disable Receiver and Transmitter */ - rfalFieldOff(); - - /* As there's no Off mode, set default value: ISO14443A with automatic RF Collision Avoidance Off */ - st25r3911WriteRegister( ST25R3911_REG_MODE, (ST25R3911_REG_MODE_om_iso14443a | ST25R3911_REG_MODE_nfc_ar_off) ); - - /* Set Analog configurations for Listen Off event */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_LISTEN_OFF) ); - - return ERR_NONE; -} - - -/*******************************************************************************/ -/* PRQA S 3673 1 # MISRA 8.13 - ST25R3911B does not support Listen mode. Implementation for other chips will modify rxBuf and rxLen */ -ReturnCode rfalListenSleepStart( rfalLmState sleepSt, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rxLen ) -{ - NO_WARNING(sleepSt); - NO_WARNING(rxBuf); - NO_WARNING(rxBufLen); - NO_WARNING(rxLen); - - return ERR_NOTSUPP; -} - - -/*******************************************************************************/ -rfalLmState rfalListenGetState( bool *dataFlag, rfalBitRate *lastBR ) -{ - /* Allow state retrieval even if gRFAL.state != RFAL_STATE_LM so * - * that this Lm state can be used by caller after activation */ - - if( lastBR != NULL ) - { - *lastBR = gRFAL.Lm.brDetected; - } - - if( dataFlag != NULL ) - { - *dataFlag = gRFAL.Lm.dataFlag; - } - - return gRFAL.Lm.state; -} - - -/*******************************************************************************/ -ReturnCode rfalListenSetState( rfalLmState newSt ) -{ - ReturnCode ret; - uint8_t tmp; - rfalLmState newState; - bool reSetState; - - /*rfalLogD( "RFAL: curState: %02X newState: %02X \r\n", gRFAL.Lm.state, newSt );*/ - - /* SetState clears the Data flag */ - gRFAL.Lm.dataFlag = false; - newState = newSt; - ret = ERR_NONE; - - do{ - reSetState = false; - - /*******************************************************************************/ - switch( newState ) - { - /*******************************************************************************/ - case RFAL_LM_STATE_POWER_OFF: - - /*******************************************************************************/ - /* Disable nfc_ar as RF Collision Avoidance timer may have already started */ - st25r3911ClrRegisterBits( ST25R3911_REG_MODE, ST25R3911_REG_MODE_nfc_ar ); - - st25r3911ExecuteCommand( ST25R3911_CMD_CLEAR_FIFO ); - - /* Ensure that our field is Off, as automatic response RF Collision Avoidance may have been triggered */ - st25r3911TxOff(); - - /*******************************************************************************/ - /* Ensure that the NFCIP1 mode is disabled */ - st25r3911ClrRegisterBits( ST25R3911_REG_ISO14443A_NFC, ST25R3911_REG_ISO14443A_NFC_nfc_f0 ); - - - /*******************************************************************************/ - /* Clear and enable required IRQs */ - st25r3911DisableInterrupts( ST25R3911_IRQ_MASK_ALL ); - - - st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_NFCT | ST25R3911_IRQ_MASK_RXS | ST25R3911_IRQ_MASK_CRC | ST25R3911_IRQ_MASK_ERR1 | - ST25R3911_IRQ_MASK_ERR2 | ST25R3911_IRQ_MASK_PAR | ST25R3911_IRQ_MASK_EON | ST25R3911_IRQ_MASK_EOF | ST25R3911_IRQ_MASK_RXE ) ); - - - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911 Errata TDB */ - /* RXS and NFCT are triggered very close (specially in higher bitrates). * - * If the interrupt status register is being read when NFCT is trigerred, the * - * IRQ line might go low and NFCT is not signalled on the status register. * - * For initial bitrate detection, mask RXS, only wait for NFCT and RXE. */ - /*******************************************************************************/ - - st25r3911EnableInterrupts( (ST25R3911_IRQ_MASK_NFCT | ST25R3911_IRQ_MASK_CRC | ST25R3911_IRQ_MASK_ERR1 | - ST25R3911_IRQ_MASK_ERR2 | ST25R3911_IRQ_MASK_PAR | ST25R3911_IRQ_MASK_EON | ST25R3911_IRQ_MASK_EOF | ST25R3911_IRQ_MASK_RXE ) ); - - /*******************************************************************************/ - /* Clear the bitRate previously detected */ - gRFAL.Lm.brDetected = RFAL_BR_KEEP; - - - /*******************************************************************************/ - /* Apply the BitRate detection mode mode */ - st25r3911WriteRegister( ST25R3911_REG_MODE, (ST25R3911_REG_MODE_targ_targ | ST25R3911_REG_MODE_om_bit_rate_detection | ST25R3911_REG_MODE_nfc_ar_on) ); - - - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911 Errata #1.3 */ - /* Even though bitrate is going to be detected the bitrate must be set to * - * 106kbps to get correct 106kbps parity */ - st25r3911WriteRegister( ST25R3911_REG_BIT_RATE, (ST25R3911_REG_BIT_RATE_txrate_106 | ST25R3911_REG_BIT_RATE_rxrate_106) ); - /*******************************************************************************/ - - - /*******************************************************************************/ - /* Check if external Field is already On */ - if( rfalIsExtFieldOn() ) - { - reSetState = true; - newState = RFAL_LM_STATE_IDLE; /* Set IDLE state */ - } - break; - - /*******************************************************************************/ - case RFAL_LM_STATE_IDLE: - - /*******************************************************************************/ - /* In Active P2P the Initiator may: Turn its field On; LM goes into IDLE state; - * Initiator sends an unexpected frame raising a Protocol error; Initiator - * turns its field Off and ST25R3911 performs the automatic RF Collision - * Avoidance keeping our field On; upon a Protocol error upper layer sets - * again the state to IDLE to clear dataFlag and wait for next data. - * - * Ensure that when upper layer calls SetState(IDLE), it restores initial - * configuration and that check whether an external Field is still present */ - - /* nfc_ar may have triggered RF Collision Avoidance, disable it before executing Clear (Stop All activities) */ - st25r3911ClrRegisterBits( ST25R3911_REG_MODE, ST25R3911_REG_MODE_nfc_ar ); - st25r3911ExecuteCommand( ST25R3911_CMD_CLEAR_FIFO ); - st25r3911SetRegisterBits( ST25R3911_REG_MODE, ST25R3911_REG_MODE_nfc_ar ); - - /* Ensure that our field is Off, as automatic response RF Collision Avoidance may have been triggered */ - st25r3911TxOff(); - - - /* Load 2nd/3rd stage gain setting from registers into the receiver */ - st25r3911ExecuteCommand( ST25R3911_CMD_CLEAR_SQUELCH ); - - /*******************************************************************************/ - /* REMARK: Silicon workaround ST25R3911 Errata #1.4 */ - /* Enable; disable; enable mixer to make sure the digital decoder is in * - * high state. This also switches the demodulator to mixer mode. */ - st25r3911ReadRegister( ST25R3911_REG_RX_CONF1, &tmp ); - st25r3911WriteRegister( ST25R3911_REG_RX_CONF1, (tmp | ST25R3911_REG_RX_CONF1_amd_sel) ); - st25r3911WriteRegister( ST25R3911_REG_RX_CONF1, (uint8_t)(tmp & ~ST25R3911_REG_RX_CONF1_amd_sel) ); - st25r3911WriteRegister( ST25R3911_REG_RX_CONF1, (tmp | ST25R3911_REG_RX_CONF1_amd_sel) ); - /*******************************************************************************/ - - /* ReEnable the receiver */ - st25r3911ExecuteCommand( ST25R3911_CMD_UNMASK_RECEIVE_DATA ); - - - /* If external Field is no longer detected go back to POWER_OFF */ - if( !st25r3911IsExtFieldOn() ) - { - reSetState = true; - newState = RFAL_LM_STATE_POWER_OFF; /* Set POWER_OFF state */ - } - - /*******************************************************************************/ - /*Check if Observation Mode is enabled and set it on ST25R391x */ - rfalCheckEnableObsModeRx(); - break; - - /*******************************************************************************/ - case RFAL_LM_STATE_TARGET_A: - case RFAL_LM_STATE_TARGET_F: - /* States not handled by the LM, just keep state context */ - break; - - /*******************************************************************************/ - case RFAL_LM_STATE_READY_F: - case RFAL_LM_STATE_CARDEMU_3: - case RFAL_LM_STATE_READY_Ax: - case RFAL_LM_STATE_READY_A: - case RFAL_LM_STATE_ACTIVE_Ax: - case RFAL_LM_STATE_ACTIVE_A: - case RFAL_LM_STATE_SLEEP_A: - case RFAL_LM_STATE_SLEEP_B: - case RFAL_LM_STATE_SLEEP_AF: - case RFAL_LM_STATE_CARDEMU_4A: - case RFAL_LM_STATE_CARDEMU_4B: - return ERR_NOTSUPP; - - /*******************************************************************************/ - default: - return ERR_WRONG_STATE; - } - } - while( reSetState ); - - gRFAL.Lm.state = newState; - - return ret; -} - -#endif /* RFAL_FEATURE_LISTEN_MODE */ - - -/******************************************************************************* - * Wake-Up Mode * - *******************************************************************************/ - -#if RFAL_FEATURE_WAKEUP_MODE - -/*******************************************************************************/ -ReturnCode rfalWakeUpModeStart( const rfalWakeUpConfig *config ) -{ - uint8_t aux; - uint8_t reg; - uint32_t irqs; - - /* The Wake-Up procedure is explained in detail in Application Note: AN4985 */ - - if( config == NULL ) - { - gRFAL.wum.cfg.period = RFAL_WUM_PERIOD_500MS; - gRFAL.wum.cfg.irqTout = false; - gRFAL.wum.cfg.swTagDetect = false; - - gRFAL.wum.cfg.indAmp.enabled = true; - gRFAL.wum.cfg.indPha.enabled = true; - gRFAL.wum.cfg.cap.enabled = false; - gRFAL.wum.cfg.indAmp.delta = 2U; - gRFAL.wum.cfg.indAmp.reference = RFAL_WUM_REFERENCE_AUTO; - gRFAL.wum.cfg.indAmp.autoAvg = false; - gRFAL.wum.cfg.indPha.delta = 2U; - gRFAL.wum.cfg.indPha.reference = RFAL_WUM_REFERENCE_AUTO; - gRFAL.wum.cfg.indPha.autoAvg = false; - } - else - { - gRFAL.wum.cfg = *config; - } - - - /* Check for valid configuration */ - if( (gRFAL.wum.cfg.cap.enabled && (gRFAL.wum.cfg.indAmp.enabled || gRFAL.wum.cfg.indPha.enabled)) || - (!gRFAL.wum.cfg.cap.enabled && !gRFAL.wum.cfg.indAmp.enabled && !gRFAL.wum.cfg.indPha.enabled) || - gRFAL.wum.cfg.swTagDetect ) - { - return ERR_PARAM; - } - - irqs = ST25R3911_IRQ_MASK_NONE; - - - /* Disable Tx, Rx, External Field Detector and set default ISO14443A mode */ - st25r3911TxRxOff(); - st25r3911ClrRegisterBits( ST25R3911_REG_AUX, ST25R3911_REG_AUX_en_fd ); - st25r3911ChangeRegisterBits(ST25R3911_REG_MODE, (ST25R3911_REG_MODE_targ | ST25R3911_REG_MODE_mask_om), (ST25R3911_REG_MODE_targ_init | ST25R3911_REG_MODE_om_iso14443a) ); - - /* Set Analog configurations for Wake-up On event */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_WAKEUP_ON) ); - - /*******************************************************************************/ - /* Prepare Wake-Up Timer Control Register */ - reg = (uint8_t)(((uint8_t)gRFAL.wum.cfg.period & 0x0FU) << ST25R3911_REG_WUP_TIMER_CONTROL_shift_wut); - reg |= (uint8_t)(((uint8_t)gRFAL.wum.cfg.period < (uint8_t)RFAL_WUM_PERIOD_100MS) ? ST25R3911_REG_WUP_TIMER_CONTROL_wur : 0x00U); - - if(gRFAL.wum.cfg.irqTout) - { - reg |= ST25R3911_REG_WUP_TIMER_CONTROL_wto; - irqs |= ST25R3911_IRQ_MASK_WT; - } - - /*******************************************************************************/ - /* Check if Inductive Amplitude is to be performed */ - if( gRFAL.wum.cfg.indAmp.enabled ) - { - aux = (uint8_t)((gRFAL.wum.cfg.indAmp.delta) << ST25R3911_REG_AMPLITUDE_MEASURE_CONF_shift_am_d); - aux |= (uint8_t)(gRFAL.wum.cfg.indAmp.aaInclMeas ? ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_aam : 0x00U); - aux |= (uint8_t)(((uint8_t)gRFAL.wum.cfg.indAmp.aaWeight << ST25R3911_REG_AMPLITUDE_MEASURE_CONF_shift_am_aew) & ST25R3911_REG_AMPLITUDE_MEASURE_CONF_mask_am_aew); - aux |= (uint8_t)(gRFAL.wum.cfg.indAmp.autoAvg ? ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_ae : 0x00U); - - st25r3911WriteRegister( ST25R3911_REG_AMPLITUDE_MEASURE_CONF, aux ); - - /* Only need to set the reference if not using Auto Average */ - if( !gRFAL.wum.cfg.indAmp.autoAvg ) - { - if( gRFAL.wum.cfg.indAmp.reference == RFAL_WUM_REFERENCE_AUTO ) - { - st25r3911MeasureAmplitude( &gRFAL.wum.cfg.indAmp.reference ); - } - st25r3911WriteRegister( ST25R3911_REG_AMPLITUDE_MEASURE_REF, gRFAL.wum.cfg.indAmp.reference ); - } - - reg |= ST25R3911_REG_WUP_TIMER_CONTROL_wam; - irqs |= ST25R3911_IRQ_MASK_WAM; - } - - /*******************************************************************************/ - /* Check if Inductive Phase is to be performed */ - if( gRFAL.wum.cfg.indPha.enabled ) - { - aux = (uint8_t)((gRFAL.wum.cfg.indPha.delta) << ST25R3911_REG_PHASE_MEASURE_CONF_shift_pm_d); - aux |= (uint8_t)(gRFAL.wum.cfg.indPha.aaInclMeas ? ST25R3911_REG_PHASE_MEASURE_CONF_pm_aam : 0x00U); - aux |= (uint8_t)(((uint8_t)gRFAL.wum.cfg.indPha.aaWeight << ST25R3911_REG_PHASE_MEASURE_CONF_shift_pm_aew) & ST25R3911_REG_PHASE_MEASURE_CONF_mask_pm_aew); - aux |= (uint8_t)(gRFAL.wum.cfg.indPha.autoAvg ? ST25R3911_REG_PHASE_MEASURE_CONF_pm_ae : 0x00U); - - st25r3911WriteRegister( ST25R3911_REG_PHASE_MEASURE_CONF, aux ); - - /* Only need to set the reference if not using Auto Average */ - if( !gRFAL.wum.cfg.indPha.autoAvg ) - { - if( gRFAL.wum.cfg.indPha.reference == RFAL_WUM_REFERENCE_AUTO ) - { - st25r3911MeasurePhase( &gRFAL.wum.cfg.indPha.reference ); - } - st25r3911WriteRegister( ST25R3911_REG_PHASE_MEASURE_REF, gRFAL.wum.cfg.indPha.reference ); - } - - reg |= ST25R3911_REG_WUP_TIMER_CONTROL_wph; - irqs |= ST25R3911_IRQ_MASK_WPH; - } - - /*******************************************************************************/ - /* Check if Capacitive is to be performed */ - if( gRFAL.wum.cfg.cap.enabled ) - { - /*******************************************************************************/ - /* Perform Capacitive sensor calibration */ - - /* Disable Oscillator and Field */ - st25r3911ClrRegisterBits( ST25R3911_REG_OP_CONTROL, (ST25R3911_REG_OP_CONTROL_en | ST25R3911_REG_OP_CONTROL_tx_en) ); - - /* Sensor gain should be configured on Analog Config */ - - /* Perform calibration procedure */ - st25r3911CalibrateCapacitiveSensor( NULL ); - - - /*******************************************************************************/ - aux = (uint8_t)((gRFAL.wum.cfg.cap.delta) << ST25R3911_REG_CAPACITANCE_MEASURE_CONF_shift_cm_d); - aux |= (uint8_t)(gRFAL.wum.cfg.cap.aaInclMeas ? ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_aam : 0x00U); - aux |= (uint8_t)(((uint8_t)gRFAL.wum.cfg.cap.aaWeight << ST25R3911_REG_CAPACITANCE_MEASURE_CONF_shift_cm_aew) & ST25R3911_REG_CAPACITANCE_MEASURE_CONF_mask_cm_aew); - aux |= (uint8_t)(gRFAL.wum.cfg.cap.autoAvg ? ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_ae : 0x00U); - - st25r3911WriteRegister( ST25R3911_REG_CAPACITANCE_MEASURE_CONF, aux ); - - /* Only need to set the reference if not using Auto Average */ - if( !gRFAL.wum.cfg.cap.autoAvg ) - { - if( gRFAL.wum.cfg.indPha.reference == RFAL_WUM_REFERENCE_AUTO ) - { - st25r3911MeasureCapacitance( &gRFAL.wum.cfg.cap.reference ); - } - st25r3911WriteRegister( ST25R3911_REG_CAPACITANCE_MEASURE_REF, gRFAL.wum.cfg.cap.reference ); - } - - reg |= ST25R3911_REG_WUP_TIMER_CONTROL_wcap; - irqs |= ST25R3911_IRQ_MASK_WCAP; - } - - /* Disable and clear all interrupts except Wake-Up IRQs */ - st25r3911DisableInterrupts( ST25R3911_IRQ_MASK_ALL ); - st25r3911GetInterrupt( irqs ); - st25r3911EnableInterrupts( irqs ); - - /* Enable Low Power Wake-Up Mode */ - st25r3911WriteRegister( ST25R3911_REG_WUP_TIMER_CONTROL, reg ); - st25r3911ChangeRegisterBits( ST25R3911_REG_OP_CONTROL, (ST25R3911_REG_OP_CONTROL_en | ST25R3911_REG_OP_CONTROL_wu), ST25R3911_REG_OP_CONTROL_wu ); - - gRFAL.wum.state = RFAL_WUM_STATE_ENABLED; - gRFAL.state = RFAL_STATE_WUM; - - return ERR_NONE; -} - - -/*******************************************************************************/ -bool rfalWakeUpModeHasWoke( void ) -{ - return (gRFAL.wum.state >= RFAL_WUM_STATE_ENABLED_WOKE); -} - - -/*******************************************************************************/ -static void rfalRunWakeUpModeWorker( void ) -{ - uint32_t irqs; - - if( gRFAL.state != RFAL_STATE_WUM ) - { - return; - } - - switch( gRFAL.wum.state ) - { - case RFAL_WUM_STATE_ENABLED: - case RFAL_WUM_STATE_ENABLED_WOKE: - - irqs = st25r3911GetInterrupt( ( ST25R3911_IRQ_MASK_WT | ST25R3911_IRQ_MASK_WAM | ST25R3911_IRQ_MASK_WPH | ST25R3911_IRQ_MASK_WCAP ) ); - if( irqs == ST25R3911_IRQ_MASK_NONE ) - { - break; /* No interrupt to process */ - } - - /*******************************************************************************/ - /* Check and mark which measurement(s) cause interrupt */ - if((irqs & ST25R3911_IRQ_MASK_WAM) != 0U) - { - gRFAL.wum.state = RFAL_WUM_STATE_ENABLED_WOKE; - } - - if((irqs & ST25R3911_IRQ_MASK_WPH) != 0U) - { - gRFAL.wum.state = RFAL_WUM_STATE_ENABLED_WOKE; - } - - if((irqs & ST25R3911_IRQ_MASK_WCAP) != 0U) - { - gRFAL.wum.state = RFAL_WUM_STATE_ENABLED_WOKE; - } - break; - - default: - /* MISRA 16.4: no empty default statement (a comment being enough) */ - break; - } -} - - -/*******************************************************************************/ -ReturnCode rfalWakeUpModeStop( void ) -{ - if( gRFAL.wum.state == RFAL_WUM_STATE_NOT_INIT ) - { - return ERR_WRONG_STATE; - } - - gRFAL.wum.state = RFAL_WUM_STATE_NOT_INIT; - - /* Re-Enable External Field Detector */ - st25r3911SetRegisterBits( ST25R3911_REG_AUX, ST25R3911_REG_AUX_en_fd ); - - /* Disable Wake-Up Mode */ - st25r3911ClrRegisterBits( ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_wu ); - st25r3911DisableInterrupts( (ST25R3911_IRQ_MASK_WT | ST25R3911_IRQ_MASK_WAM | ST25R3911_IRQ_MASK_WPH | ST25R3911_IRQ_MASK_WCAP) ); - - /* Re-Enable the Oscillator */ - st25r3911OscOn(); - - /* Set Analog configurations for Wake-up Off event */ - rfalSetAnalogConfig( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_WAKEUP_OFF) ); - - return ERR_NONE; -} - -#endif /* RFAL_FEATURE_WAKEUP_MODE */ - - -/******************************************************************************* - * RF Chip * - *******************************************************************************/ - -/*******************************************************************************/ -ReturnCode rfalChipWriteReg( uint16_t reg, const uint8_t* values, uint8_t len ) -{ - if( !st25r3911IsRegValid( (uint8_t)reg) ) - { - return ERR_PARAM; - } - - st25r3911WriteMultipleRegisters( (uint8_t)reg, values, len ); - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipReadReg( uint16_t reg, uint8_t* values, uint8_t len ) -{ - if( !st25r3911IsRegValid( (uint8_t)reg) ) - { - return ERR_PARAM; - } - - st25r3911ReadMultipleRegisters( (uint8_t)reg, values, len ); - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipExecCmd( uint16_t cmd ) -{ - if( !st25r3911IsCmdValid( (uint8_t)cmd) ) - { - return ERR_PARAM; - } - - st25r3911ExecuteCommand( (uint8_t) cmd ); - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipWriteTestReg( uint16_t reg, uint8_t value ) -{ - st25r3911WriteTestRegister( (uint8_t)reg, value ); - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipReadTestReg( uint16_t reg, uint8_t* value ) -{ - st25r3911ReadTestRegister( (uint8_t)reg, value ); - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipChangeRegBits( uint16_t reg, uint8_t valueMask, uint8_t value ) -{ - st25r3911ChangeRegisterBits( (uint8_t)reg, valueMask, value ); - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipChangeTestRegBits( uint16_t reg, uint8_t valueMask, uint8_t value ) -{ - st25r3911ChangeTestRegisterBits( (uint8_t)reg, valueMask, value ); - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipSetRFO( uint8_t rfo ) -{ - st25r3911WriteRegister( ST25R3911_REG_RFO_AM_OFF_LEVEL, rfo ); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipGetRFO( uint8_t* result ) -{ - st25r3911ReadRegister(ST25R3911_REG_RFO_AM_ON_LEVEL, result); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipMeasureAmplitude( uint8_t* result ) -{ - st25r3911MeasureAmplitude( result ); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipMeasurePhase( uint8_t* result ) -{ - st25r3911MeasurePhase( result ); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipMeasureCapacitance( uint8_t* result ) -{ - st25r3911MeasureCapacitance( result ); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalChipMeasurePowerSupply( uint8_t param, uint8_t* result ) -{ - *result = st25r3911MeasurePowerSupply( param ); - - return ERR_NONE; -} - - - -/*******************************************************************************/ - -/* All bitrates defined in ST25R3911B registers are nibbles. This rfal code - * up there only works if equality to values of enum rfalBitrate is guaranteed: */ -extern uint8_t equalityGuard_RFAL_BR_106[(ST25R3911_REG_BIT_RATE_rxrate_106==(uint8_t)RFAL_BR_106)?1:(-1)]; -extern uint8_t equalityGuard_RFAL_BR_212[(ST25R3911_REG_BIT_RATE_rxrate_212==(uint8_t)RFAL_BR_212)?1:(-1)]; -extern uint8_t equalityGuard_RFAL_BR_424[(ST25R3911_REG_BIT_RATE_rxrate_424==(uint8_t)RFAL_BR_424)?1:(-1)]; -extern uint8_t equalityGuard_RFAL_BR_848[(ST25R3911_REG_BIT_RATE_rxrate_848==(uint8_t)RFAL_BR_848)?1:(-1)]; -extern uint8_t equalityGuard_RFAL_BR_1695[(ST25R3911_REG_BIT_RATE_rxrate_1695==(uint8_t)RFAL_BR_1695)?1:(-1)]; -extern uint8_t equalityGuard_RFAL_BR_3390[(ST25R3911_REG_BIT_RATE_rxrate_3390==(uint8_t)RFAL_BR_3390)?1:(-1)]; -extern uint8_t equalityGuard_RFAL_BR_6780[(ST25R3911_REG_BIT_RATE_rxrate_6780==(uint8_t)RFAL_BR_6780)?1:(-1)]; diff --git a/Software/Middlewares/ST/rfal/Src/rfal_st25tb.c b/Software/Middlewares/ST/rfal/Src/rfal_st25tb.c deleted file mode 100644 index 41c9430..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_st25tb.c +++ /dev/null @@ -1,551 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_st25tb.c - * - * \author Gustavo Patricio - * - * \brief Implementation of ST25TB interface - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_st25tb.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ -#ifndef RFAL_FEATURE_ST25TB - #define RFAL_FEATURE_ST25TB false /* ST25TB module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_ST25TB - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_ST25TB_CMD_LEN 1U /*!< ST25TB length of a command */ -#define RFAL_ST25TB_SLOTS 16U /*!< ST25TB number of slots */ -#define RFAL_ST25TB_SLOTNUM_MASK 0x0FU /*!< ST25TB Slot Number bit mask on SlotMarker */ -#define RFAL_ST25TB_SLOTNUM_SHIFT 4U /*!< ST25TB Slot Number shift on SlotMarker */ - -#define RFAL_ST25TB_INITIATE_CMD1 0x06U /*!< ST25TB Initiate command byte1 */ -#define RFAL_ST25TB_INITIATE_CMD2 0x00U /*!< ST25TB Initiate command byte2 */ -#define RFAL_ST25TB_PCALL_CMD1 0x06U /*!< ST25TB Pcall16 command byte1 */ -#define RFAL_ST25TB_PCALL_CMD2 0x04U /*!< ST25TB Pcall16 command byte2 */ -#define RFAL_ST25TB_SELECT_CMD 0x0EU /*!< ST25TB Select command */ -#define RFAL_ST25TB_GET_UID_CMD 0x0BU /*!< ST25TB Get UID command */ -#define RFAL_ST25TB_COMPLETION_CMD 0x0FU /*!< ST25TB Completion command */ -#define RFAL_ST25TB_RESET_INV_CMD 0x0CU /*!< ST25TB Reset to Inventory command */ -#define RFAL_ST25TB_READ_BLOCK_CMD 0x08U /*!< ST25TB Read Block command */ -#define RFAL_ST25TB_WRITE_BLOCK_CMD 0x09U /*!< ST25TB Write Block command */ - - -#define RFAL_ST25TB_T0 2157U /*!< ST25TB t0 159 us ST25TB RF characteristics */ -#define RFAL_ST25TB_T1 2048U /*!< ST25TB t1 151 us ST25TB RF characteristics */ - -#define RFAL_ST25TB_FWT (RFAL_ST25TB_T0 + RFAL_ST25TB_T1) /*!< ST25TB FWT = T0 + T1 */ -#define RFAL_ST25TB_TW rfalConvMsTo1fc(7U) /*!< ST25TB TW : Programming time for write max 7ms */ - - -/* - ****************************************************************************** - * GLOBAL MACROS - ****************************************************************************** - */ - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! Initiate Request */ -typedef struct -{ - uint8_t cmd1; /*!< Initiate Request cmd1: 0x06 */ - uint8_t cmd2; /*!< Initiate Request cmd2: 0x00 */ -} rfalSt25tbInitiateReq; - -/*! Pcall16 Request */ -typedef struct -{ - uint8_t cmd1; /*!< Pcal16 Request cmd1: 0x06 */ - uint8_t cmd2; /*!< Pcal16 Request cmd2: 0x04 */ -} rfalSt25tbPcallReq; - - -/*! Select Request */ -typedef struct -{ - uint8_t cmd; /*!< Select Request cmd: 0x0E */ - uint8_t chipId; /*!< Chip ID */ -} rfalSt25tbSelectReq; - -/*! Read Block Request */ -typedef struct -{ - uint8_t cmd; /*!< Select Request cmd: 0x08 */ - uint8_t address; /*!< Block address */ -} rfalSt25tbReadBlockReq; - -/*! Write Block Request */ -typedef struct -{ - uint8_t cmd; /*!< Select Request cmd: 0x09 */ - uint8_t address; /*!< Block address */ - rfalSt25tbBlock data; /*!< Block Data */ -} rfalSt25tbWriteBlockReq; - - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ -/*! - ***************************************************************************** - * \brief ST25TB Poller Do Collision Resolution - * - * This method performs ST25TB Collision resolution loop for each slot - * - * \param[in] devLimit : device limit value, and size st25tbDevList - * \param[out] st25tbDevList : ST35TB listener device info - * \param[out] devCnt : Devices found counter - * - * \return colPending : true if a collision was detected - ***************************************************************************** - */ -static bool rfalSt25tbPollerDoCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt ); - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - - -static bool rfalSt25tbPollerDoCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt ) -{ - uint8_t i; - uint8_t chipId; - ReturnCode ret; - bool col; - - col = false; - - for(i = 0; i < RFAL_ST25TB_SLOTS; i++) - { - platformDelay(1); /* Wait t2: Answer to new request delay */ - - if( i==0U ) - { - /* Step 2: Send Pcall16 */ - ret = rfalSt25tbPollerPcall( &chipId ); - } - else - { - /* Step 3-17: Send Pcall16 */ - ret = rfalSt25tbPollerSlotMarker( i, &chipId ); - } - - if( ret == ERR_NONE ) - { - /* Found another device */ - st25tbDevList[*devCnt].chipID = chipId; - st25tbDevList[*devCnt].isDeselected = false; - - /* Select Device, retrieve its UID */ - ret = rfalSt25tbPollerSelect( chipId ); - - /* By Selecting this device, the previous gets Deselected */ - if( (*devCnt) > 0U ) - { - st25tbDevList[(*devCnt)-1U].isDeselected = true; - } - - if( ERR_NONE == ret ) - { - rfalSt25tbPollerGetUID( &st25tbDevList[*devCnt].UID ); - } - - if( ERR_NONE == ret ) - { - (*devCnt)++; - } - } - else if( (ret == ERR_CRC) || (ret == ERR_FRAMING) ) - { - col = true; - } - else - { - /* MISRA 15.7 - Empty else */ - } - - if( *devCnt >= devLimit ) - { - break; - } - } - return col; -} - - -/* -****************************************************************************** -* LOCAL VARIABLES -****************************************************************************** -*/ - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerInitialize( void ) -{ - return rfalNfcbPollerInitialize(); -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerCheckPresence( uint8_t *chipId ) -{ - ReturnCode ret; - uint8_t chipIdRes; - - chipIdRes = 0x00; - - /* Send Initiate Request */ - ret = rfalSt25tbPollerInitiate( &chipIdRes ); - - /* Check if a transmission error was detected */ - if( (ret == ERR_CRC) || (ret == ERR_FRAMING) ) - { - return ERR_NONE; - } - - /* Copy chip ID if requested */ - if( chipId != NULL ) - { - *chipId = chipIdRes; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerInitiate( uint8_t *chipId ) -{ - ReturnCode ret; - uint16_t rxLen; - rfalSt25tbInitiateReq initiateReq; - uint8_t rxBuf[RFAL_ST25TB_CHIP_ID_LEN + RFAL_ST25TB_CRC_LEN]; /* In case we receive less data that CRC, RF layer will not remove the CRC from buffer */ - - /* Compute Initiate Request */ - initiateReq.cmd1 = RFAL_ST25TB_INITIATE_CMD1; - initiateReq.cmd2 = RFAL_ST25TB_INITIATE_CMD2; - - /* Send Initiate Request */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&initiateReq, sizeof(rfalSt25tbInitiateReq), (uint8_t*)rxBuf, sizeof(rxBuf), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT ); - - /* Check for valid Select Response */ - if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_CHIP_ID_LEN) ) - { - return ERR_PROTO; - } - - /* Copy chip ID if requested */ - if( chipId != NULL ) - { - *chipId = *rxBuf; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerPcall( uint8_t *chipId ) -{ - ReturnCode ret; - uint16_t rxLen; - rfalSt25tbPcallReq pcallReq; - - /* Compute Pcal16 Request */ - pcallReq.cmd1 = RFAL_ST25TB_PCALL_CMD1; - pcallReq.cmd2 = RFAL_ST25TB_PCALL_CMD2; - - /* Send Pcal16 Request */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&pcallReq, sizeof(rfalSt25tbPcallReq), (uint8_t*)chipId, RFAL_ST25TB_CHIP_ID_LEN, &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT ); - - /* Check for valid Select Response */ - if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_CHIP_ID_LEN) ) - { - return ERR_PROTO; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerSlotMarker( uint8_t slotNum, uint8_t *chipIdRes ) -{ - ReturnCode ret; - uint16_t rxLen; - uint8_t slotMarker; - - if( (slotNum == 0U) || (slotNum > 15U) ) - { - return ERR_PARAM; - } - - /* Compute SlotMarker */ - slotMarker = ( ((slotNum & RFAL_ST25TB_SLOTNUM_MASK) << RFAL_ST25TB_SLOTNUM_SHIFT) | RFAL_ST25TB_PCALL_CMD1 ); - - - /* Send SlotMarker */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&slotMarker, RFAL_ST25TB_CMD_LEN, (uint8_t*)chipIdRes, RFAL_ST25TB_CHIP_ID_LEN, &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT ); - - /* Check for valid ChipID Response */ - if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_CHIP_ID_LEN) ) - { - return ERR_PROTO; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerSelect( uint8_t chipId ) -{ - ReturnCode ret; - uint16_t rxLen; - rfalSt25tbSelectReq selectReq; - uint8_t chipIdRes; - - /* Compute Select Request */ - selectReq.cmd = RFAL_ST25TB_SELECT_CMD; - selectReq.chipId = chipId; - - /* Send Select Request */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&selectReq, sizeof(rfalSt25tbSelectReq), (uint8_t*)&chipIdRes, RFAL_ST25TB_CHIP_ID_LEN, &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT ); - - /* Check for valid Select Response */ - if( (ret == ERR_NONE) && ((rxLen != RFAL_ST25TB_CHIP_ID_LEN) || (chipIdRes != chipId)) ) - { - return ERR_PROTO; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerGetUID( rfalSt25tbUID *UID ) -{ - ReturnCode ret; - uint16_t rxLen; - uint8_t getUidReq; - - - /* Compute Get UID Request */ - getUidReq = RFAL_ST25TB_GET_UID_CMD; - - /* Send Select Request */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&getUidReq, RFAL_ST25TB_CMD_LEN, (uint8_t*)UID, sizeof(rfalSt25tbUID), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT ); - - /* Check for valid UID Response */ - if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_UID_LEN) ) - { - return ERR_PROTO; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt ) -{ - - uint8_t chipId; - ReturnCode ret; - bool detected; /* collision or device was detected */ - - if( (st25tbDevList == NULL) || (devCnt == NULL) || (devLimit == 0U) ) - { - return ERR_PARAM; - } - - *devCnt = 0; - - /* Step 1: Send Initiate */ - ret = rfalSt25tbPollerInitiate( &chipId ); - if( ret == ERR_NONE ) - { - /* If only 1 answer is detected */ - st25tbDevList[*devCnt].chipID = chipId; - st25tbDevList[*devCnt].isDeselected = false; - - /* Retrieve its UID and keep it Selected*/ - ret = rfalSt25tbPollerSelect( chipId ); - - if( ERR_NONE == ret ) - { - ret = rfalSt25tbPollerGetUID( &st25tbDevList[*devCnt].UID ); - } - - if( ERR_NONE == ret ) - { - (*devCnt)++; - } - } - /* Always proceed to Pcall16 anticollision as phase differences of tags can lead to no tag recognized, even if there is one */ - if( *devCnt < devLimit ) - { - /* Multiple device responses */ - do - { - detected = rfalSt25tbPollerDoCollisionResolution( devLimit, st25tbDevList, devCnt ); - } - while( (detected == true) && (*devCnt < devLimit) ); - } - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerReadBlock( uint8_t blockAddress, rfalSt25tbBlock *blockData ) -{ - ReturnCode ret; - uint16_t rxLen; - rfalSt25tbReadBlockReq readBlockReq; - - - /* Compute Read Block Request */ - readBlockReq.cmd = RFAL_ST25TB_READ_BLOCK_CMD; - readBlockReq.address = blockAddress; - - /* Send Read Block Request */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&readBlockReq, sizeof(rfalSt25tbReadBlockReq), (uint8_t*)blockData, sizeof(rfalSt25tbBlock), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT ); - - /* Check for valid UID Response */ - if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_BLOCK_LEN) ) - { - return ERR_PROTO; - } - - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerWriteBlock( uint8_t blockAddress, const rfalSt25tbBlock *blockData ) -{ - ReturnCode ret; - uint16_t rxLen; - rfalSt25tbWriteBlockReq writeBlockReq; - rfalSt25tbBlock tmpBlockData; - - - /* Compute Write Block Request */ - writeBlockReq.cmd = RFAL_ST25TB_WRITE_BLOCK_CMD; - writeBlockReq.address = blockAddress; - ST_MEMCPY( &writeBlockReq.data, blockData, RFAL_ST25TB_BLOCK_LEN ); - - /* Send Write Block Request */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&writeBlockReq, sizeof(rfalSt25tbWriteBlockReq), tmpBlockData, RFAL_ST25TB_BLOCK_LEN, &rxLen, RFAL_TXRX_FLAGS_DEFAULT, (RFAL_ST25TB_FWT + RFAL_ST25TB_TW) ); - - /* Check if an unexpected answer was received */ - if( ret == ERR_NONE ) - { - return ERR_PROTO; - } - /* Check there was any error besides Timeout*/ - if( ret != ERR_TIMEOUT ) - { - return ret; - } - - ret = rfalSt25tbPollerReadBlock(blockAddress, &tmpBlockData); - if( ret == ERR_NONE ) - { - if( ST_BYTECMP( &tmpBlockData, blockData, RFAL_ST25TB_BLOCK_LEN ) == 0 ) - { - return ERR_NONE; - } - return ERR_PROTO; - } - return ret; -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerCompletion( void ) -{ - uint8_t completionReq; - - /* Compute Completion Request */ - completionReq = RFAL_ST25TB_COMPLETION_CMD; - - /* Send Completion Request, no response is expected */ - return rfalTransceiveBlockingTxRx( (uint8_t*)&completionReq, RFAL_ST25TB_CMD_LEN, NULL, 0, NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT ); -} - - -/*******************************************************************************/ -ReturnCode rfalSt25tbPollerResetToInventory( void ) -{ - uint8_t resetInvReq; - - /* Compute Completion Request */ - resetInvReq = RFAL_ST25TB_RESET_INV_CMD; - - /* Send Completion Request, no response is expected */ - return rfalTransceiveBlockingTxRx( (uint8_t*)&resetInvReq, RFAL_ST25TB_CMD_LEN, NULL, 0, NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT ); -} - -#endif /* RFAL_FEATURE_ST25TB */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_st25xv.c b/Software/Middlewares/ST/rfal/Src/rfal_st25xv.c deleted file mode 100644 index c835004..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_st25xv.c +++ /dev/null @@ -1,528 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_st25xv.c - * - * \author Gustavo Patricio - * - * \brief NFC-V ST25 NFC-V Tag specific features - * - * This module provides support for ST's specific features available on - * NFC-V (ISO15693) tag families: ST25D, ST25TV, M24LR - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_st25xv.h" -#include "rfal_nfcv.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_ST25xV - #define RFAL_FEATURE_ST25xV false /* ST25xV module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_ST25xV - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_ST25xV_READ_CONFIG_LEN 2U /*!< READ CONFIGURATION length */ -#define RFAL_ST25xV_READ_MSG_LEN_LEN 2U /*!< READ MESSAGE LENGTH length */ -#define RFAL_ST25xV_CONF_POINTER_LEN 1U /*!< READ/WRITE CONFIGURATION Pointer length */ -#define RFAL_ST25xV_CONF_REGISTER_LEN 1U /*!< READ/WRITE CONFIGURATION Register length */ -#define RFAL_ST25xV_PWDNUM_LEN 1U /*!< Password Number length */ -#define RFAL_ST25xV_PWD_LEN 8U /*!< Password length */ -#define RFAL_ST25xV_MBPOINTER_LEN 1U /*!< Read Message MBPointer length */ -#define RFAL_ST25xV_NUMBYTES_LEN 1U /*!< Read Message Number of Bytes length */ - -#define RFAL_ST25TV02K_TBOOT_RF 1U /*!< RF Boot time (Minimum time from carrier generation to first data) */ -#define RFAL_ST25TV02K_TRF_OFF 2U /*!< RF OFF time */ - -#define RFAL_FDT_POLL_MAX rfalConvMsTo1fc(20) /*!< Maximum Wait time FDTV,EOF 20 ms Digital 2.0 B.5 */ -#define RFAL_NFCV_FLAG_POS 0U /*!< Flag byte position */ -#define RFAL_NFCV_FLAG_LEN 1U /*!< Flag byte length */ - - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -static ReturnCode rfalST25xVPollerGenericReadConfiguration(uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue ); -static ReturnCode rfalST25xVPollerGenericWriteConfiguration( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue ); -static ReturnCode rfalST25xVPollerGenericReadMessageLength( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t* msgLen ); -static ReturnCode rfalST25xVPollerGenericReadMessage( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ); -static ReturnCode rfalST25xVPollerGenericWriteMessage( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen ); -/* -****************************************************************************** -* LOCAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -static ReturnCode rfalST25xVPollerGenericReadConfiguration(uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue ) -{ - ReturnCode ret; - uint8_t p; - uint16_t rcvLen; - rfalNfcvGenericRes res; - - if( regValue == NULL ) - { - return ERR_PARAM; - } - - p = pointer; - - ret = rfalNfcvPollerTransceiveReq( cmd, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, &p, sizeof(uint8_t), (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); - if( ret == ERR_NONE ) - { - if( rcvLen < RFAL_ST25xV_READ_CONFIG_LEN ) - { - ret = ERR_PROTO; - } - else - { - *regValue = res.data[0]; - } - } - return ret; -} - -/*******************************************************************************/ -static ReturnCode rfalST25xVPollerGenericWriteConfiguration( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue ) -{ - uint8_t data[RFAL_ST25xV_CONF_POINTER_LEN + RFAL_ST25xV_CONF_REGISTER_LEN]; - uint8_t dataLen; - uint16_t rcvLen; - rfalNfcvGenericRes res; - - dataLen = 0U; - - data[dataLen++] = pointer; - data[dataLen++] = regValue; - - return rfalNfcvPollerTransceiveReq( cmd, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); - -} - -/*******************************************************************************/ -static ReturnCode rfalST25xVPollerGenericReadMessageLength( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t* msgLen ) -{ - ReturnCode ret; - uint16_t rcvLen; - rfalNfcvGenericRes res; - - if( msgLen == NULL ) - { - return ERR_PARAM; - } - - ret = rfalNfcvPollerTransceiveReq( cmd, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, NULL, 0, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); - if( ret == ERR_NONE ) - { - if( rcvLen < RFAL_ST25xV_READ_MSG_LEN_LEN ) - { - ret = ERR_PROTO; - } - else - { - *msgLen = res.data[0]; - } - } - return ret; -} - -/*******************************************************************************/ -static ReturnCode rfalST25xVPollerGenericReadMessage( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[RFAL_ST25xV_MBPOINTER_LEN + RFAL_ST25xV_NUMBYTES_LEN]; - uint8_t dataLen; - - dataLen = 0; - - /* Compute Request Data */ - data[dataLen++] = mbPointer; - data[dataLen++] = numBytes; - - return rfalNfcvPollerTransceiveReq( cmd, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -static ReturnCode rfalST25xVPollerGenericWriteMessage( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen ) -{ - ReturnCode ret; - uint8_t reqFlag; - uint16_t msgIt; - rfalBitRate rxBR; - bool fastMode; - rfalNfcvGenericRes res; - uint16_t rcvLen; - - /* Calculate required Tx buf length: Mfg Code UID MSGLen MSGLen+1 */ - msgIt = (uint16_t)( msgLen + sizeof(flags) + sizeof(cmd) + 1U + ((uid != NULL) ? RFAL_NFCV_UID_LEN : 0U) + 1U + 1U ); - - /* Check for valid parameters */ - if( (txBuf == NULL) || (msgData == NULL) || (msgLen == 0U) || (msgLen == 0xFFU) || (txBufLen < msgIt) ) - { - return ERR_PARAM; - } - - msgIt = 0; - fastMode = false; - - /* Check if the command is an ST's Fast command */ - if( cmd == (uint8_t)RFAL_NFCV_CMD_FAST_WRITE_MESSAGE ) - { - /* Store current Rx bit rate and move to fast mode */ - rfalGetBitRate( NULL, &rxBR ); - rfalSetBitRate( RFAL_BR_KEEP, RFAL_BR_52p97 ); - - fastMode = true; - } - - /* Compute Request Command */ - reqFlag = (uint8_t)(flags & (~((uint32_t)RFAL_NFCV_REQ_FLAG_ADDRESS) & ~((uint32_t)RFAL_NFCV_REQ_FLAG_SELECT))); - reqFlag |= (( uid != NULL ) ? (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS : (uint8_t)RFAL_NFCV_REQ_FLAG_SELECT); - - txBuf[msgIt++] = reqFlag; - txBuf[msgIt++] = cmd; - txBuf[msgIt++] = RFAL_NFCV_ST_IC_MFG_CODE; - - if( uid != NULL ) - { - ST_MEMCPY( &txBuf[msgIt], uid, RFAL_NFCV_UID_LEN ); - msgIt += RFAL_NFCV_UID_LEN; - } - txBuf[msgIt++] = msgLen; - ST_MEMCPY( &txBuf[msgIt], msgData, (uint8_t)(msgLen + 1U) ); /* Message Data contains (MSGLength + 1) bytes */ - msgIt += (uint8_t)(msgLen + 1U); - - /* Transceive Command */ - ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX ); - - - /* Restore Rx BitRate */ - if( fastMode ) - { - rfalSetBitRate( RFAL_BR_KEEP, rxBR ); - } - - if( ret != ERR_NONE ) - { - return ret; - } - - /* Check if the response minimum length has been received */ - if( rcvLen < (uint8_t)RFAL_NFCV_FLAG_LEN ) - { - return ERR_PROTO; - } - - /* Check if an error has been signalled */ - if( (res.RES_FLAG & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U ) - { - return ERR_PROTO; - } - - return ERR_NONE; -} - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerM24LRReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[RFAL_NFCV_BLOCKNUM_M24LR_LEN]; - uint8_t dataLen; - - dataLen = 0; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)blockNum; /* Set M24LR Block Number (16 bits) LSB */ - data[dataLen++] = (uint8_t)(blockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */ - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_READ_SINGLE_BLOCK, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerM24LRWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_M24LR_LEN + RFAL_NFCV_MAX_BLOCK_LEN)]; - uint8_t dataLen; - uint16_t rcvLen; - rfalNfcvGenericRes res; - - /* Check for valid parameters */ - if( (blockLen == 0U) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) || (wrData == NULL) ) - { - return ERR_PARAM; - } - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)blockNum; /* Set M24LR Block Number (16 bits) LSB */ - data[dataLen++] = (uint8_t)(blockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */ - ST_MEMCPY( &data[dataLen], wrData, blockLen ); /* Append Block data to write */ - dataLen += blockLen; - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerM24LRReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_M24LR_LEN + RFAL_NFCV_BLOCKNUM_M24LR_LEN)]; - uint8_t dataLen; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)firstBlockNum; /* Set M24LR Block Number (16 bits) LSB */ - data[dataLen++] = (uint8_t)(firstBlockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */ - data[dataLen++] = numOfBlocks; /* Set number of blocks to read */ - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_READ_MULTIPLE_BLOCKS, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t bn; - - bn = blockNum; - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, &bn, sizeof(uint8_t), rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerM24LRFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[RFAL_NFCV_BLOCKNUM_M24LR_LEN]; - uint8_t dataLen; - - dataLen = 0; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)blockNum; /* Set M24LR Block Number (16 bits) LSB */ - data[dataLen++] = (uint8_t)(blockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */ - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerM24LRFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_M24LR_LEN + RFAL_NFCV_BLOCKNUM_M24LR_LEN)]; - uint8_t dataLen; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)firstBlockNum; /* Set M24LR Block Number (16 bits) LSB */ - data[dataLen++] = (uint8_t)(firstBlockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */ - data[dataLen++] = numOfBlocks; /* Set number of blocks to read */ - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_LEN + RFAL_NFCV_BLOCKNUM_LEN)]; - uint8_t dataLen; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = firstBlockNum; /* Set first Block Number */ - data[dataLen++] = numOfBlocks; /* Set number of blocks to read */ - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[RFAL_NFCV_BLOCKNUM_EXTENDED_LEN]; - uint8_t dataLen; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)blockNum; /* TS T5T 1.0 BNo is considered as a multi-byte field. TS T5T 1.0 5.1.1.13 multi-byte field follows [DIGITAL]. [DIGITAL] 9.3.1 A multiple byte field is transmitted LSB first. */ - data[dataLen++] = (uint8_t)((blockNum >> 8U) & 0xFFU); - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_EXTENDED_READ_SINGLE_BLOCK, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastExtReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - uint8_t data[(RFAL_NFCV_BLOCKNUM_EXTENDED_LEN + RFAL_NFCV_BLOCKNUM_EXTENDED_LEN)]; - uint8_t dataLen; - - dataLen = 0U; - - /* Compute Request Data */ - data[dataLen++] = (uint8_t)((firstBlockNum >> 0U) & 0xFFU); - data[dataLen++] = (uint8_t)((firstBlockNum >> 8U) & 0xFFU); - data[dataLen++] = (uint8_t)((numOfBlocks >> 0U) & 0xFFU); - data[dataLen++] = (uint8_t)((numOfBlocks >> 8U) & 0xFFU); - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_EXTENDED_READ_MULTIPLE_BLOCKS, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerReadConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue ) -{ - return rfalST25xVPollerGenericReadConfiguration(RFAL_NFCV_CMD_READ_CONFIGURATION, flags, uid, pointer, regValue ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerWriteConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue ) -{ - return rfalST25xVPollerGenericWriteConfiguration( RFAL_NFCV_CMD_WRITE_CONFIGURATION, flags, uid, pointer, regValue); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue ) -{ - return rfalST25xVPollerGenericReadConfiguration(RFAL_NFCV_CMD_READ_DYN_CONFIGURATION, flags, uid, pointer, regValue ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue ) -{ - return rfalST25xVPollerGenericWriteConfiguration( RFAL_NFCV_CMD_WRITE_DYN_CONFIGURATION, flags, uid, pointer, regValue); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue ) -{ - return rfalST25xVPollerGenericReadConfiguration(RFAL_NFCV_CMD_FAST_READ_DYN_CONFIGURATION, flags, uid, pointer, regValue ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue ) -{ - return rfalST25xVPollerGenericWriteConfiguration( RFAL_NFCV_CMD_FAST_WRITE_DYN_CONFIGURATION, flags, uid, pointer, regValue); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerPresentPassword( uint8_t flags, const uint8_t* uid, uint8_t pwdNum, const uint8_t *pwd, uint8_t pwdLen) -{ - uint8_t data[RFAL_ST25xV_PWDNUM_LEN + RFAL_ST25xV_PWD_LEN]; - uint8_t dataLen; - uint16_t rcvLen; - rfalNfcvGenericRes res; - - if( (pwdLen > RFAL_ST25xV_PWD_LEN) || (pwd == NULL) ) - { - return ERR_PARAM; - } - - dataLen = 0U; - data[dataLen++] = pwdNum;; - if( pwdLen > 0U ) - { - ST_MEMCPY(&data[dataLen], pwd, pwdLen); - } - dataLen += pwdLen; - - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_PRESENT_PASSWORD, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen ); - -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerGetRandomNumber( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - rfalFieldOff(); - platformDelay(RFAL_ST25TV02K_TRF_OFF); - rfalNfcvPollerInitialize(); - rfalFieldOnAndStartGT(); - platformDelay(RFAL_ST25TV02K_TBOOT_RF); - return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_GET_RANDOM_NUMBER, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, NULL, 0U, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen ) -{ - return rfalST25xVPollerGenericWriteMessage( RFAL_NFCV_CMD_WRITE_MESSAGE, flags, uid, msgLen, msgData, txBuf, txBufLen); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen ) -{ - return rfalST25xVPollerGenericWriteMessage( RFAL_NFCV_CMD_FAST_WRITE_MESSAGE, flags, uid, msgLen, msgData, txBuf, txBufLen); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerReadMessageLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen ) -{ - return rfalST25xVPollerGenericReadMessageLength(RFAL_NFCV_CMD_READ_MESSAGE_LENGTH, flags, uid, msgLen); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastReadMsgLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen ) -{ - return rfalST25xVPollerGenericReadMessageLength(RFAL_NFCV_CMD_FAST_READ_MESSAGE_LENGTH, flags, uid, msgLen); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - return rfalST25xVPollerGenericReadMessage(RFAL_NFCV_CMD_READ_MESSAGE, flags, uid, mbPointer, numBytes, rxBuf, rxBufLen, rcvLen ); -} - -/*******************************************************************************/ -ReturnCode rfalST25xVPollerFastReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) -{ - return rfalST25xVPollerGenericReadMessage(RFAL_NFCV_CMD_FAST_READ_MESSAGE, flags, uid, mbPointer, numBytes, rxBuf, rxBufLen, rcvLen ); -} - -#endif /* RFAL_FEATURE_ST25xV */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_t1t.c b/Software/Middlewares/ST/rfal/Src/rfal_t1t.c deleted file mode 100644 index 995899c..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_t1t.c +++ /dev/null @@ -1,220 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_t1t.c - * - * \author Gustavo Patricio - * - * \brief Provides NFC-A T1T convenience methods and definitions - * - * This module provides an interface to perform as a NFC-A Reader/Writer - * to handle a Type 1 Tag T1T (Topaz) - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ -#include "rfal_t1t.h" -#include "utils.h" - -/* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_T1T - #define RFAL_FEATURE_T1T false /* T1T module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_T1T - -/* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - -#define RFAL_T1T_DRD_READ (1236U*2U) /*!< DRD for Reads with n=9 => 1236/fc ~= 91 us T1T 1.2 4.4.2 */ -#define RFAL_T1T_DRD_WRITE 36052U /*!< DRD for Write with n=281 => 36052/fc ~= 2659 us T1T 1.2 4.4.2 */ -#define RFAL_T1T_DRD_WRITE_E 70996U /*!< DRD for Write/Erase with n=554 => 70996/fc ~= 5236 us T1T 1.2 4.4.2 */ - -#define RFAL_T1T_RID_RES_HR0_VAL 0x10U /*!< HR0 indicating NDEF support Digital 2.0 (Candidate) 11.6.2.1 */ -#define RFAL_T1T_RID_RES_HR0_MASK 0xF0U /*!< HR0 most significant nibble mask */ - -/* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! NFC-A T1T (Topaz) RID_REQ Digital 1.1 10.6.1 & Table 49 */ -typedef struct -{ - uint8_t cmd; /*!< T1T cmd: RID */ - uint8_t add; /*!< ADD: undefined value */ - uint8_t data; /*!< DATA: undefined value */ - uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID-echo: undefined value */ -} rfalT1TRidReq; - - -/*! NFC-A T1T (Topaz) RALL_REQ T1T 1.2 Table 4 */ -typedef struct -{ - uint8_t cmd; /*!< T1T cmd: RALL */ - uint8_t add1; /*!< ADD: 0x00 */ - uint8_t add0; /*!< ADD: 0x00 */ - uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID */ -} rfalT1TRallReq; - - -/*! NFC-A T1T (Topaz) WRITE_REQ T1T 1.2 Table 4 */ -typedef struct -{ - uint8_t cmd; /*!< T1T cmd: RALL */ - uint8_t add; /*!< ADD */ - uint8_t data; /*!< DAT */ - uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID */ -} rfalT1TWriteReq; - - -/*! NFC-A T1T (Topaz) WRITE_RES T1T 1.2 Table 4 */ -typedef struct -{ - uint8_t add; /*!< ADD */ - uint8_t data; /*!< DAT */ -} rfalT1TWriteRes; - -/* -****************************************************************************** -* LOCAL FUNCTION PROTOTYPES -****************************************************************************** -*/ - -/* -****************************************************************************** -* GLOBAL FUNCTIONS -****************************************************************************** -*/ - -ReturnCode rfalT1TPollerInitialize( void ) -{ - ReturnCode ret; - - EXIT_ON_ERR(ret, rfalSetMode( RFAL_MODE_POLL_NFCA_T1T, RFAL_BR_106, RFAL_BR_106 ) ); - rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); - - rfalSetGT( RFAL_GT_NONE ); /* T1T should only be initialized after NFC-A mode, therefore the GT has been fulfilled */ - rfalSetFDTListen( RFAL_FDT_LISTEN_NFCA_POLLER ); /* T1T uses NFC-A FDT Listen with n=9 Digital 1.1 10.7.2 */ - rfalSetFDTPoll( RFAL_FDT_POLL_NFCA_T1T_POLLER ); - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalT1TPollerRid( rfalT1TRidRes *ridRes ) -{ - ReturnCode ret; - rfalT1TRidReq ridReq; - uint16_t rcvdLen; - - if( ridRes == NULL ) - { - return ERR_PARAM; - } - - /* Compute RID command and set Undefined Values to 0x00 Digital 1.1 10.6.1 */ - ST_MEMSET( &ridReq, 0x00, sizeof(rfalT1TRidReq) ); - ridReq.cmd = (uint8_t)RFAL_T1T_CMD_RID; - - EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&ridReq, sizeof(rfalT1TRidReq), (uint8_t*)ridRes, sizeof(rfalT1TRidRes), &rcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_READ ) ); - - /* Check expected RID response length and the HR0 Digital 2.0 (Candidate) 11.6.2.1 */ - if( (rcvdLen != sizeof(rfalT1TRidRes)) || ((ridRes->hr0 & RFAL_T1T_RID_RES_HR0_MASK) != RFAL_T1T_RID_RES_HR0_VAL) ) - { - return ERR_PROTO; - } - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalT1TPollerRall( const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxRcvdLen ) -{ - rfalT1TRallReq rallReq; - - if( (rxBuf == NULL) || (uid == NULL) || (rxRcvdLen == NULL) ) - { - return ERR_PARAM; - } - - /* Compute RALL command and set Add to 0x00 */ - ST_MEMSET( &rallReq, 0x00, sizeof(rfalT1TRallReq) ); - rallReq.cmd = (uint8_t)RFAL_T1T_CMD_RALL; - ST_MEMCPY(rallReq.uid, uid, RFAL_T1T_UID_LEN); - - return rfalTransceiveBlockingTxRx( (uint8_t*)&rallReq, sizeof(rfalT1TRallReq), (uint8_t*)rxBuf, rxBufLen, rxRcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_READ ); -} - - -/*******************************************************************************/ -ReturnCode rfalT1TPollerWrite( const uint8_t* uid, uint8_t address, uint8_t data ) -{ - rfalT1TWriteReq writeReq; - rfalT1TWriteRes writeRes; - uint16_t rxRcvdLen; - ReturnCode err; - - if( uid == NULL ) - { - return ERR_PARAM; - } - - writeReq.cmd = (uint8_t)RFAL_T1T_CMD_WRITE_E; - writeReq.add = address; - writeReq.data = data; - ST_MEMCPY(writeReq.uid, uid, RFAL_T1T_UID_LEN); - - err = rfalTransceiveBlockingTxRx( (uint8_t*)&writeReq, sizeof(rfalT1TWriteReq), (uint8_t*)&writeRes, sizeof(rfalT1TWriteRes), &rxRcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_WRITE_E ); - - if( err == ERR_NONE ) - { - if( (writeReq.add != writeRes.add) || (writeReq.data != writeRes.data) || (rxRcvdLen != sizeof(rfalT1TWriteRes)) ) - { - return ERR_PROTO; - } - } - return err; -} - -#endif /* RFAL_FEATURE_T1T */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_t2t.c b/Software/Middlewares/ST/rfal/Src/rfal_t2t.c deleted file mode 100644 index de80a81..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_t2t.c +++ /dev/null @@ -1,242 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2018 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_t2t.c - * - * \author - * - * \brief Provides NFC-A T2T convenience methods and definitions - * - * This module provides an interface to perform as a NFC-A Reader/Writer - * to handle a Type 2 Tag T2T - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - #include "rfal_t2t.h" - #include "utils.h" - - /* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_T2T - #define RFAL_FEATURE_T2T false /* T2T module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_T2T - - /* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ - #define RFAL_FDT_POLL_READ_MAX rfalConvMsTo1fc(5U) /*!< Maximum Wait time for Read command as defined in TS T2T 1.0 table 18 */ - #define RFAL_FDT_POLL_WRITE_MAX rfalConvMsTo1fc(10U) /*!< Maximum Wait time for Write command as defined in TS T2T 1.0 table 18 */ - #define RFAL_FDT_POLL_SL_MAX rfalConvMsTo1fc(1U) /*!< Maximum Wait time for Sector Select as defined in TS T2T 1.0 table 18 */ - #define RFAL_T2T_ACK_NACK_LEN 1U /*!< Len of NACK in bytes (4 bits) */ - #define RFAL_T2T_ACK 0x0AU /*!< ACK value */ - #define RFAL_T2T_ACK_MASK 0x0FU /*!< ACK value */ - - - #define RFAL_T2T_SECTOR_SELECT_P1_BYTE2 0xFFU /*!< Sector Select Packet 1 byte 2 */ - #define RFAL_T2T_SECTOR_SELECT_P2_RFU_LEN 3U /*!< Sector Select RFU length */ - - - - /* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - -/*! NFC-A T2T command set T2T 1.0 5.1 */ -typedef enum -{ - RFAL_T2T_CMD_READ = 0x30, /*!< T2T Read */ - RFAL_T2T_CMD_WRITE = 0xA2, /*!< T2T Write */ - RFAL_T2T_CMD_SECTOR_SELECT = 0xC2 /*!< T2T Sector Select */ -} rfalT2Tcmds; - - - /*! NFC-A T2T READ T2T 1.0 5.2 and table 11 */ -typedef struct -{ - uint8_t code; /*!< Command code */ - uint8_t blNo; /*!< Block number */ -} rfalT2TReadReq; - - - /*! NFC-A T2T WRITE T2T 1.0 5.3 and table 12 */ -typedef struct -{ - uint8_t code; /*!< Command code */ - uint8_t blNo; /*!< Block number */ - uint8_t data[RFAL_T2T_WRITE_DATA_LEN]; /*!< Data */ -} rfalT2TWriteReq; - - -/*! NFC-A T2T SECTOR SELECT Packet 1 T2T 1.0 5.4 and table 13 */ -typedef struct -{ - uint8_t code; /*!< Command code */ - uint8_t byte2; /*!< Sector Select Packet 1 byte 2 */ -} rfalT2TSectorSelectP1Req; - - -/*! NFC-A T2T SECTOR SELECT Packet 2 T2T 1.0 5.4 and table 13 */ -typedef struct -{ - uint8_t secNo; /*!< Block number */ - uint8_t rfu[RFAL_T2T_SECTOR_SELECT_P2_RFU_LEN]; /*!< Sector Select Packet RFU */ -} rfalT2TSectorSelectP2Req; - - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - - ReturnCode rfalT2TPollerRead( uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen ) - { - ReturnCode ret; - rfalT2TReadReq req; - - if( (rxBuf == NULL) || (rcvLen == NULL) ) - { - return ERR_PARAM; - } - - req.code = (uint8_t)RFAL_T2T_CMD_READ; - req.blNo = blockNum; - - /* Transceive Command */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, sizeof(rfalT2TReadReq), rxBuf, rxBufLen, rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_READ_MAX ); - - /* T2T 1.0 5.2.1.7 The Reader/Writer SHALL treat a NACK in response to a READ Command as a Protocol Error */ - if( (ret == ERR_INCOMPLETE_BYTE) && (*rcvLen == RFAL_T2T_ACK_NACK_LEN) && ((*rxBuf & RFAL_T2T_ACK_MASK) != RFAL_T2T_ACK) ) - { - return ERR_PROTO; - } - return ret; - } - - - /*******************************************************************************/ - ReturnCode rfalT2TPollerWrite( uint8_t blockNum, const uint8_t* wrData ) - { - ReturnCode ret; - rfalT2TWriteReq req; - uint8_t res; - uint16_t rxLen; - - req.code = (uint8_t)RFAL_T2T_CMD_WRITE; - req.blNo = blockNum; - ST_MEMCPY(req.data, wrData, RFAL_T2T_WRITE_DATA_LEN); - - - /* Transceive WRITE Command */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, sizeof(rfalT2TWriteReq), &res, sizeof(uint8_t), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_READ_MAX ); - - /* Check for a valid ACK */ - if( (ret == ERR_INCOMPLETE_BYTE) || (ret == ERR_NONE) ) - { - ret = ERR_PROTO; - - if( (rxLen == RFAL_T2T_ACK_NACK_LEN) && ((res & RFAL_T2T_ACK_MASK) == RFAL_T2T_ACK) ) - { - ret = ERR_NONE; - } - } - - return ret; - } - - - /*******************************************************************************/ - ReturnCode rfalT2TPollerSectorSelect( uint8_t sectorNum ) - { - rfalT2TSectorSelectP1Req p1Req; - rfalT2TSectorSelectP2Req p2Req; - ReturnCode ret; - uint8_t res; - uint16_t rxLen; - - - /* Compute SECTOR SELECT Packet 1 */ - p1Req.code = (uint8_t)RFAL_T2T_CMD_SECTOR_SELECT; - p1Req.byte2 = RFAL_T2T_SECTOR_SELECT_P1_BYTE2; - - /* Transceive SECTOR SELECT Packet 1 */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&p1Req, sizeof(rfalT2TSectorSelectP1Req), &res, sizeof(uint8_t), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_SL_MAX ); - - /* Check and report any transmission error */ - if( (ret != ERR_INCOMPLETE_BYTE) && (ret != ERR_NONE) ) - { - return ret; - } - - /* Ensure that an ACK was received */ - if( (ret != ERR_INCOMPLETE_BYTE) || (rxLen != RFAL_T2T_ACK_NACK_LEN) || ((res & RFAL_T2T_ACK_MASK) != RFAL_T2T_ACK) ) - { - return ERR_PROTO; - } - - - /* Compute SECTOR SELECT Packet 2 */ - p2Req.secNo = sectorNum; - ST_MEMSET( &p2Req.rfu, 0x00, RFAL_T2T_SECTOR_SELECT_P2_RFU_LEN ); - - - /* Transceive SECTOR SELECT Packet 2 */ - ret = rfalTransceiveBlockingTxRx( (uint8_t*)&p2Req, sizeof(rfalT2TSectorSelectP2Req), &res, sizeof(uint8_t), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_SL_MAX ); - - /* T2T 1.0 5.4.1.14 The Reader/Writer SHALL treat any response received before the end of PATT2T,SL,MAX as a Protocol Error */ - if( (ret == ERR_NONE) || (ret == ERR_INCOMPLETE_BYTE) ) - { - return ERR_PROTO; - } - - /* T2T 1.0 5.4.1.13 The Reader/Writer SHALL treat the transmission of the SECTOR SELECT Command Packet 2 as being successful when it receives no response until PATT2T,SL,MAX. */ - if( ret == ERR_TIMEOUT ) - { - return ERR_NONE; - } - - return ret; - } - -#endif /* RFAL_FEATURE_T2T */ diff --git a/Software/Middlewares/ST/rfal/Src/rfal_t4t.c b/Software/Middlewares/ST/rfal/Src/rfal_t4t.c deleted file mode 100644 index 3353f91..0000000 --- a/Software/Middlewares/ST/rfal/Src/rfal_t4t.c +++ /dev/null @@ -1,398 +0,0 @@ - -/****************************************************************************** - * \attention - * - *

© COPYRIGHT 2018 STMicroelectronics

- * - * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * www.st.com/myliberty - * - * 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, - * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * See the License for the specific language governing permissions and - * limitations under the License. - * -******************************************************************************/ - -/* - * PROJECT: ST25R391x firmware - * Revision: - * LANGUAGE: ISO C99 - */ - -/*! \file rfal_t4t.h - * - * \author Gustavo Patricio - * - * \brief Provides convenience methods and definitions for T4T (ISO7816-4) - * - * This module provides an interface to exchange T4T APDUs according to - * NFC Forum T4T and ISO7816-4 - * - * This implementation was based on the following specs: - * - ISO/IEC 7816-4 3rd Edition 2013-04-15 - * - NFC Forum T4T Technical Specification 1.0 2017-08-28 - * - */ - -/* - ****************************************************************************** - * INCLUDES - ****************************************************************************** - */ - #include "rfal_t4t.h" - #include "utils.h" - - /* - ****************************************************************************** - * ENABLE SWITCH - ****************************************************************************** - */ - -#ifndef RFAL_FEATURE_T4T - #define RFAL_FEATURE_T4T false /* T4T module configuration missing. Disabled by default */ -#endif - -#if RFAL_FEATURE_T4T - - /* - ****************************************************************************** - * GLOBAL DEFINES - ****************************************************************************** - */ -#define RFAL_T4T_OFFSET_DO 0x54U /*!< Tag value for offset BER-TLV data object */ -#define RFAL_T4T_LENGTH_DO 0x03U /*!< Len value for offset BER-TLV data object */ -#define RFAL_T4T_DATA_DO 0x53U /*!< Tag value for data BER-TLV data object */ - -#define RFAL_T4T_MAX_LC 255U /*!< Maximum Lc value for short Lc coding */ - /* -****************************************************************************** -* GLOBAL TYPES -****************************************************************************** -*/ - - -/* -****************************************************************************** -* GLOBAL MACROS -****************************************************************************** -*/ - - -/* - ****************************************************************************** - * LOCAL VARIABLES - ****************************************************************************** - */ - - -/* - ****************************************************************************** - * GLOBAL FUNCTIONS - ****************************************************************************** - */ - -/*******************************************************************************/ -ReturnCode rfalT4TPollerComposeCAPDU( rfalT4tCApduParam *apduParam ) -{ - uint8_t hdrLen; - uint16_t msgIt; - - if( (apduParam == NULL) || (apduParam->cApduBuf == NULL) || (apduParam->cApduLen == NULL) ) - { - return ERR_PARAM; - } - - msgIt = 0; - *(apduParam->cApduLen) = 0; - - /*******************************************************************************/ - /* Compute Command-APDU according to the format T4T 1.0 5.1.2 & ISO7816-4 2013 Table 1 */ - - /* Check if Data is present */ - if( apduParam->LcFlag ) - { - if( apduParam->Lc == 0U ) - { - /* Extented field coding not supported */ - return ERR_PARAM; - } - - /* Check whether requested Lc fits */ - if( (uint16_t)apduParam->Lc > (uint16_t)(RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN - RFAL_T4T_LE_LEN) ) - { - return ERR_PARAM; /* PRQA S 2880 # MISRA 2.1 - Unreachable code due to configuration option being set/unset */ - } - - /* Calculate the header length a place the data/body where it should be */ - hdrLen = RFAL_T4T_MAX_CAPDU_PROLOGUE_LEN + RFAL_T4T_LC_LEN; - - /* make sure not to exceed buffer size */ - if( ((uint16_t)hdrLen + (uint16_t)apduParam->Lc + (apduParam->LeFlag ? RFAL_T4T_LC_LEN : 0U)) > RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN ) - { - return ERR_NOMEM; /* PRQA S 2880 # MISRA 2.1 - Unreachable code due to configuration option being set/unset */ - } - ST_MEMMOVE( &apduParam->cApduBuf->apdu[hdrLen], apduParam->cApduBuf->apdu, apduParam->Lc ); - } - - /* Prepend the ADPDU's header */ - apduParam->cApduBuf->apdu[msgIt++] = apduParam->CLA; - apduParam->cApduBuf->apdu[msgIt++] = apduParam->INS; - apduParam->cApduBuf->apdu[msgIt++] = apduParam->P1; - apduParam->cApduBuf->apdu[msgIt++] = apduParam->P2; - - - /* Check if Data field length is to be added */ - if( apduParam->LcFlag ) - { - apduParam->cApduBuf->apdu[msgIt++] = apduParam->Lc; - msgIt += apduParam->Lc; - } - - /* Check if Expected Response Length is to be added */ - if( apduParam->LeFlag ) - { - apduParam->cApduBuf->apdu[msgIt++] = apduParam->Le; - } - - *(apduParam->cApduLen) = msgIt; - - return ERR_NONE; -} - - -/*******************************************************************************/ -ReturnCode rfalT4TPollerParseRAPDU( rfalT4tRApduParam *apduParam ) -{ - if( (apduParam == NULL) || (apduParam->rApduBuf == NULL) ) - { - return ERR_PARAM; - } - - if( apduParam->rcvdLen < RFAL_T4T_MAX_RAPDU_SW1SW2_LEN ) - { - return ERR_PROTO; - } - - apduParam->rApduBodyLen = (apduParam->rcvdLen - (uint16_t)RFAL_T4T_MAX_RAPDU_SW1SW2_LEN); - apduParam->statusWord = GETU16( &apduParam->rApduBuf->apdu[ apduParam->rApduBodyLen ] ); - - /* Check SW1 SW2 T4T 1.0 5.1.3 NOTE */ - if( apduParam->statusWord == RFAL_T4T_ISO7816_STATUS_COMPLETE ) - { - return ERR_NONE; - } - - return ERR_REQUEST; -} - - -/*******************************************************************************/ -ReturnCode rfalT4TPollerComposeSelectAppl( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* aid, uint8_t aidLen, uint16_t *cApduLen ) -{ - rfalT4tCApduParam cAPDU; - - /* CLA INS P1 P2 Lc Data Le */ - /* 00h A4h 00h 00h 07h AID 00h */ - cAPDU.CLA = RFAL_T4T_CLA; - cAPDU.INS = (uint8_t)RFAL_T4T_INS_SELECT; - cAPDU.P1 = RFAL_T4T_ISO7816_P1_SELECT_BY_DF_NAME; - cAPDU.P2 = RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE | RFAL_T4T_ISO7816_P2_SELECT_RETURN_FCI_TEMPLATE; - cAPDU.Lc = aidLen; - cAPDU.Le = 0x00; - cAPDU.LcFlag = true; - cAPDU.LeFlag = true; - cAPDU.cApduBuf = cApduBuf; - cAPDU.cApduLen = cApduLen; - - if( aidLen > 0U ) - { - ST_MEMCPY( cAPDU.cApduBuf->apdu, aid, aidLen ); - } - - return rfalT4TPollerComposeCAPDU( &cAPDU ); -} - - -/*******************************************************************************/ -ReturnCode rfalT4TPollerComposeSelectFile( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen ) -{ - rfalT4tCApduParam cAPDU; - - /* CLA INS P1 P2 Lc Data Le */ - /* 00h A4h 00h 0Ch 02h FID - */ - cAPDU.CLA = RFAL_T4T_CLA; - cAPDU.INS = (uint8_t)RFAL_T4T_INS_SELECT; - cAPDU.P1 = RFAL_T4T_ISO7816_P1_SELECT_BY_FILEID; - cAPDU.P2 = RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE | RFAL_T4T_ISO7816_P2_SELECT_NO_RESPONSE_DATA; - cAPDU.Lc = fidLen; - cAPDU.Le = 0x00; - cAPDU.LcFlag = true; - cAPDU.LeFlag = false; - cAPDU.cApduBuf = cApduBuf; - cAPDU.cApduLen = cApduLen; - - if( fidLen > 0U ) - { - ST_MEMCPY( cAPDU.cApduBuf->apdu, fid, fidLen ); - } - - return rfalT4TPollerComposeCAPDU( &cAPDU ); -} - - -/*******************************************************************************/ -ReturnCode rfalT4TPollerComposeSelectFileV1Mapping( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen ) -{ - rfalT4tCApduParam cAPDU; - - /* CLA INS P1 P2 Lc Data Le */ - /* 00h A4h 00h 00h 02h FID - */ - cAPDU.CLA = RFAL_T4T_CLA; - cAPDU.INS = (uint8_t)RFAL_T4T_INS_SELECT; - cAPDU.P1 = RFAL_T4T_ISO7816_P1_SELECT_BY_FILEID; - cAPDU.P2 = RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE | RFAL_T4T_ISO7816_P2_SELECT_RETURN_FCI_TEMPLATE; - cAPDU.Lc = fidLen; - cAPDU.Le = 0x00; - cAPDU.LcFlag = true; - cAPDU.LeFlag = false; - cAPDU.cApduBuf = cApduBuf; - cAPDU.cApduLen = cApduLen; - - if( fidLen > 0U ) - { - ST_MEMCPY( cAPDU.cApduBuf->apdu, fid, fidLen ); - } - - return rfalT4TPollerComposeCAPDU( &cAPDU ); -} - - -/*******************************************************************************/ -ReturnCode rfalT4TPollerComposeReadData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, uint8_t expLen, uint16_t *cApduLen ) -{ - rfalT4tCApduParam cAPDU; - - /* CLA INS P1 P2 Lc Data Le */ - /* 00h B0h [Offset] - - len */ - cAPDU.CLA = RFAL_T4T_CLA; - cAPDU.INS = (uint8_t)RFAL_T4T_INS_READBINARY; - cAPDU.P1 = (uint8_t)((offset >> 8U) & 0xFFU); - cAPDU.P2 = (uint8_t)((offset >> 0U) & 0xFFU); - cAPDU.Le = expLen; - cAPDU.LcFlag = false; - cAPDU.LeFlag = true; - cAPDU.cApduBuf = cApduBuf; - cAPDU.cApduLen = cApduLen; - - return rfalT4TPollerComposeCAPDU( &cAPDU ); -} - - -/*******************************************************************************/ -ReturnCode rfalT4TPollerComposeReadDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, uint8_t expLen, uint16_t *cApduLen ) -{ - rfalT4tCApduParam cAPDU; - uint8_t dataIt; - - /* CLA INS P1 P2 Lc Data Le */ - /* 00h B1h 00h 00h Lc 54 03 xxyyzz len */ - /* [Offset] */ - cAPDU.CLA = RFAL_T4T_CLA; - cAPDU.INS = (uint8_t)RFAL_T4T_INS_READBINARY_ODO; - cAPDU.P1 = 0x00U; - cAPDU.P2 = 0x00U; - cAPDU.Le = expLen; - cAPDU.LcFlag = true; - cAPDU.LeFlag = true; - cAPDU.cApduBuf = cApduBuf; - cAPDU.cApduLen = cApduLen; - - dataIt = 0U; - cApduBuf->apdu[dataIt++] = RFAL_T4T_OFFSET_DO; - cApduBuf->apdu[dataIt++] = RFAL_T4T_LENGTH_DO; - cApduBuf->apdu[dataIt++] = (uint8_t)(offset >> 16U); - cApduBuf->apdu[dataIt++] = (uint8_t)(offset >> 8U); - cApduBuf->apdu[dataIt++] = (uint8_t)(offset); - cAPDU.Lc = dataIt; - - return rfalT4TPollerComposeCAPDU( &cAPDU ); -} - - -/*******************************************************************************/ -ReturnCode rfalT4TPollerComposeWriteData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen ) -{ - rfalT4tCApduParam cAPDU; - - - /* CLA INS P1 P2 Lc Data Le */ - /* 00h D6h [Offset] len Data - */ - cAPDU.CLA = RFAL_T4T_CLA; - cAPDU.INS = (uint8_t)RFAL_T4T_INS_UPDATEBINARY; - cAPDU.P1 = (uint8_t)((offset >> 8U) & 0xFFU); - cAPDU.P2 = (uint8_t)((offset >> 0U) & 0xFFU); - cAPDU.Lc = dataLen; - cAPDU.LcFlag = true; - cAPDU.LeFlag = false; - cAPDU.cApduBuf = cApduBuf; - cAPDU.cApduLen = cApduLen; - - if( dataLen > 0U ) - { - ST_MEMCPY( cAPDU.cApduBuf->apdu, data, dataLen ); - } - - return rfalT4TPollerComposeCAPDU( &cAPDU ); -} - -/*******************************************************************************/ -ReturnCode rfalT4TPollerComposeWriteDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen ) -{ - rfalT4tCApduParam cAPDU; - uint8_t dataIt; - - /* CLA INS P1 P2 Lc Data Le */ - /* 00h D7h 00h 00h len 54 03 xxyyzz 53 Ld data - */ - /* [offset] [data] */ - cAPDU.CLA = RFAL_T4T_CLA; - cAPDU.INS = (uint8_t)RFAL_T4T_INS_UPDATEBINARY_ODO; - cAPDU.P1 = 0x00U; - cAPDU.P2 = 0x00U; - cAPDU.LcFlag = true; - cAPDU.LeFlag = false; - cAPDU.cApduBuf = cApduBuf; - cAPDU.cApduLen = cApduLen; - - dataIt = 0U; - cApduBuf->apdu[dataIt++] = RFAL_T4T_OFFSET_DO; - cApduBuf->apdu[dataIt++] = RFAL_T4T_LENGTH_DO; - cApduBuf->apdu[dataIt++] = (uint8_t)(offset >> 16U); - cApduBuf->apdu[dataIt++] = (uint8_t)(offset >> 8U); - cApduBuf->apdu[dataIt++] = (uint8_t)(offset); - cApduBuf->apdu[dataIt++] = RFAL_T4T_DATA_DO; - cApduBuf->apdu[dataIt++] = dataLen; - - if( (((uint32_t)dataLen + (uint32_t)dataIt) >= RFAL_T4T_MAX_LC) || (((uint32_t)dataLen + (uint32_t)dataIt) >= RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN) ) - { - return (ERR_NOMEM); - } - - if( dataLen > 0U ) - { - ST_MEMCPY( &cAPDU.cApduBuf->apdu[dataIt], data, dataLen ); - } - dataIt += dataLen; - cAPDU.Lc = dataIt; - - return rfalT4TPollerComposeCAPDU( &cAPDU ); -} - - -#endif /* RFAL_FEATURE_T4T */ diff --git a/Software/Middlewares/ST/rfal/doc/Release_Notes.html b/Software/Middlewares/ST/rfal/doc/Release_Notes.html deleted file mode 100644 index 43fbda7..0000000 --- a/Software/Middlewares/ST/rfal/doc/Release_Notes.html +++ /dev/null @@ -1,303 +0,0 @@ - - - - - - - - - - - - - Release Notes for RFAL Library - - - - - - - - - -
-


-

-
- - - - - - -
- - - - - - - - - -

-
-

Release -Notes for RFAL software Library

-

Copyright -2019 STMicroelectronics

-

-
-

 

- - - - - - -

-
The RFAL Library -(RF Abstraction Layer) provides several functionalities required to perform RF/NFC communications. -The RFAL encapsulates the different RF ICs (ST25R3911, ST25R3916, ST25R95 and future ST25R devices) into a common and easy to use interface.
-
- The technologies currently supported by RFAL are: -
    -
  • NFC-A \ ISO14443A (T1T, T2T, T4TA)
  • -
  • NFC-B \ ISO14443B (T4TB)
  • -
  • NFC-F \ FeliCa (T3T)
  • -
  • NFC-V \ ISO15693 (T5T)
  • -
  • P2P \ ISO18092 (NFCIP1, Passive-Active P2P)
  • -
  • ST25TB (ISO14443-2 Type B with Proprietary Protocol)
  • -
  • PicoPass \ iClass
  • -
  • B' \ Calypso
  • -
  • CTS \ CTM
  • -
-

- The protocols provided by RFAL are: -
    -
  • ISO-DEP (ISO14443-4)
  • -
  • NFC-DEP (ISO18092)
  • -
-
-
-
    -
- -

Update History

-
- -

V2.0.10 / 25-Jun-2019

-

-

Main Changes

-
    -
  • Various improvements on RFAL NFC Higher layer
  • -
  • Added alternative NFC-V anticollision method (non NFC Forum compliant)
  • -
  • Several minor improvements and fixes
  • -
-
- -

V2.0.6 / 10-Apr-2019

-

-

Main Changes

-
    -
  • Several NFC-V interoperability improvements
  • -
  • Extended support for specific features of ST's ISO15693 Tags. New ST25Dx module added
  • -
  • Interrupt handling changed and further protection added
  • -
  • RFAL feature switches have been modified and features are now disabled if omitted
  • -
  • ST25R3916 AAT (Automatic Antenna Tunning) module added
  • -
  • RFAL NFC Higher layer added
  • -
  • Several driver improvements
  • -
-
- -

V2.0.4 / 06-Fev-2019

-

Provided with ST25R3916 DISCO v1.0.0 / EMVCo v1.2.0

-

Main Changes

-
    -
  • Minor improvements on NFC-F module
  • -
  • Several improvements on NFC-V module including support for ST proprietary features
  • -
  • Fixed issue with Delta RWT calculation
  • -
  • Fixed incorrect usage of NFCB dTbPoll / DdFWT
  • -
  • Added compile switch for Listen Mode
  • -
  • Low power Listen Mode support added
  • -
  • Listen Mode aligned to NFC Forum Digital 2.1
  • -
  • Added handling for EMVCo 3.0 static FDTListen
  • -
  • Introduced SW Tag Detection
  • -
-
- -

V2.0.2 / 31-Oct-2018

-

Provided with ST25R3916 DISCO v0.9.4 (binary only)

-

Main Changes

-
    -
  • New T4T module added
  • -
  • Added support for T3T Check and Update commands
  • -
  • Improved NFC-V module and added Write Multiple Blocks support
  • -
  • New rfalWorker protection added for improved control in multi-thread environments
  • -
  • Added support for user defined Analog Config tables
  • -
  • Several driver improvements and protections added
  • -
-
- -

V2.0.0 / 28-Aug-2018

- -

Main Changes

-
    -
  • MISRA C 2012 compliant
  • -
  • ST25R3916 support added
  • -
  • ST25R95 support added
  • -
  • Fix unwanted Field Detector disable when entering Wake-up mode
  • -
  • Extended Analog Config to have specific events
  • -
  • Fixed NFC-DEP potential issue if DID used
  • -
  • Extended NFC-V commands
  • -
  • T2T module added
  • -
  • Improved initial Listen mode handling
  • -
  • Extended Wake-Up mode to support Capacitive measurement
  • -
-
- -

V1.3.6 / 08-May-2018

-

Provided with ST25R3911B DISCO v1.2.0

-

Main Changes

-
    -
  • Added ISO15693 x4 and x8 mode support
  • -
  • Added S(PARAMETERS) support
  • -
  • Interface changes for measurement, Wake-Up and DPO methods
  • -
  • Added further feature switches to enable/disable individual modules
  • -
  • Changed communication protection
  • -
  • Improved NFC-A anti-collision
  • -
  • Several driver improvements
  • -
-
-

V1.3.4 / 07-May-2018

- -

Main Changes

-
    -
  • Fixed NFC-V Read operation in addressed mode
  • -
-
-

V1.3.2 / 31-January-2018

- -

Main Changes

-
    -
  • Modified Wake-Up mode interface
  • -
  • Fixed SFGI calculation in ISO-DEP
  • -
-
-

V1.3.0 / 22-January-2018

- -

Main Changes

-
    -
  • Introduced a new IRQ status handling to read the registers only once
  • -
  • Several changes for supporting Linux platform
  • -
  • SPI Select/Deselect moved to platform.h
  • -
  • Aditional protection of the IRQ status reading, new macros available: platformProtectST25R391xIrqStatus / platformUnprotectST25R391xIrqStatus
  • -
  • Renamed the IRQ Enable/Disable macros to platformProtectST25R391xComm / platformUnprotectST25R391xComm
  • -
  • Renamed SPI pins from chip specific to ST25R391X
  • -
  • Introduced a new option ST25R391X_COM_SINGLETXRX which executes SPI in one single exchange (additional buffer required)
  • -
  • Updated and added errata handlings to latest ST25R3911 Errata version
  • -
  • Fixed inconsitency on Analog settings for NFC-V
  • -
  • Fixed issue on NFC-V 1of256 decoding
  • -
  • Changed the default NFC-A FDT Listen to be more strict
  • -
  • Added Wake-Up mode support
  • -
  • Added RFAL version definition
  • -
-
-

V1.2.0 / 17-August-2017

-

Provided with ST25R3911B Disco v1.1.16

-

Main Changes

-
    -
  • Aligned Technology modules to NFC Activity v1.1 and EMVCo v2.6
  • -
  • Extended NFC-B Collision Resolution allowing user define Slots
  • -
  • Added feature switches to enable/disable individual modules
  • -
  • ISO-DEP Interface changes allowing more user configurations and further EMVCo alignment
  • -
  • Changed ST25TB detection to always perform Anti Collision loop regardeless of the result of the Poll
  • -
  • Fixed FIFO WL handling
  • -
  • Modified FDT Poll handling
  • -
  • changed rfalCalibrate() to not overwrite dynamic configs
  • -
  • Added adjustment for TR1PUTMIN
  • -
- -
-

V1.1.0 / 30-June-2017

-

Provided with ST25R3911B Disco v1.1.12

-

Main Changes

-
    -
  • EMD supression enabled for ST25R3911B
  • -
- -
-

V1.0.0 / 16-May-2017

-

Provided with X-NUCLEO-NFC05A1 v1.0.0

-

Main Changes

-
    -
  • Added support for B', CTS and PicoPass/iClass mode
  • -
  • Several impromvements for NFC-V mode
  • -
  • Improved error detection during NFC-B collision resolution
  • -
  • Extended T1T module
  • -
- -
-

V0.9.0 / 02-March-2017

-

Provided with ST25R3911B Discovery Kit on Embedded World Conference (binary only)

-

Main Changes

- -
- -
-

-
-
-

 

-
- diff --git a/Software/Middlewares/ST/rfal/doc/ST25R3916_MisraComplianceReport.html b/Software/Middlewares/ST/rfal/doc/ST25R3916_MisraComplianceReport.html deleted file mode 100644 index 849cf3c..0000000 --- a/Software/Middlewares/ST/rfal/doc/ST25R3916_MisraComplianceReport.html +++ /dev/null @@ -1,8747 +0,0 @@ - - - - - -PRQA GEP/GCS/GRP Report - - - - -
-
-
-
-
- -This section targets to provide an overview of Guidelines Enforcement Plan (GEP).
-
-This document will only focus on STMicroelectronics NFC RF Abstraction Layer (RFAL).
-
-The project has been designed to comply with the standard ISO/IEC 9899:1999 ([C99]). -
-
-

1. Tools version

-The tool used for MISRA compliance is:
-
-PRQA Framework - v2.2.2
-

-It is composed of the following subcomponents: -

-
    -
  • Component: qacpp

  • -
      Version: 4.2.0
    -
      Target: C++
    -
  • Component: rcma

  • -
      Version: 1.6.0
    -
      Target: C_CPP
    -
  • Component: m3cm

  • -
      Version: 2.3.1
    -
      Target: C
    -
  • Component: qac

  • -
      Version: 9.3.1
    -
      Target: C
    -
      -
    • Options:
    • -
        -d : __schedule_barrier=_ignore_semi
      -
        -namelength : 63
      -
    -
-

2. Configuration

-This section targets to provide the main configuration options used for MISRA compliance.
-
-The project complies to [C99],
-the variables length has been consequently set to a dedicated value (cf 'namelength' option in table above). -
-
-Repository/components:
-
    -
  • MCU target:
  • -
      STM32

    -
  • Parent repository:
  • -
      ST25R3916_nucleo

    -
  • RFAL informations:
  • -
      Path: .../ST25R3916_nucleo/rfal
    -
      Version: v2.0.10
    -
  • Project repositories SHA1:
  • -
      .../ST25R3916_nucleo: 959b80e
    -
      .../ST25R3916_nucleo/common: f953a19
    -
      .../ST25R3916_nucleo/nucleo: 22a04ae
    -
      .../ST25R3916_nucleo/rfal: b566bd2
    -
    -
-

3. Assistance/Enforcement

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GuidelineCategoryDescriptionAssistance/Enforcement Sub Rules
Dir-1.1RequiredAny implementation-defined behaviour on which the output of the program depends shall be documented and understood
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0202 [I] '-' character in '[]' conversion specification is implementation defined.
0284 [I] Multiple character constants have implementation defined values.
0285 [I] Character constant contains character which is not a member of the basic source character set.
0286 [I] String literal contains character which is not a member of the basic source character set.
0287 [I] Header name contains character which is not a member of the basic source character set.
0288 [I] Source file '%s' has comments containing characters which are not members of the basic source character set.
0289 [I] Source file '%s' has preprocessing tokens containing characters which are not members of the basic source character set.
0292 [I] Source file '%s' has comments containing one of the characters '$', '@' or '`'.
0299 [I] Source file '%s' includes #pragma directives containing characters which are not members of the basic source character set.
0314 [I] Cast from a pointer to object type to a pointer to void.
0315 [I] Implicit conversion from a pointer to object type to a pointer to void.
0371 [L] Nesting levels of blocks exceeds 127 - program does not conform strictly to ISO:C99.
0372 [L] More than 63 levels of nested conditional inclusion - program does not conform strictly to ISO:C99.
0375 [L] Nesting of parenthesized expressions exceeds 63 - program does not conform strictly to ISO:C99.
0380 [L] Number of macro definitions exceeds 4095 - program does not conform strictly to ISO:C99.
0388 [L] '#include "%s"' causes nesting to exceed 15 levels - program does not conform strictly to ISO:C99.
0390 [L] Number of members in 'struct' or 'union' exceeds 1023 - program does not conform strictly to ISO:C99.
0391 [L] Number of enumeration constants exceeds 1023 - program does not conform strictly to ISO:C99.
0392 [L] Nesting of 'struct' or 'union' types exceeds 63 - program does not conform strictly to ISO:C99.
0581 [I] Floating-point constant may be too small to be representable.
0634 [I] Bit-fields in this struct/union have not been declared explicitly as unsigned or signed.
2850 Constant: Implicit conversion to a signed integer type of insufficient size.
2851 Definite: Implicit conversion to a signed integer type of insufficient size.
2852 Apparent: Implicit conversion to a signed integer type of insufficient size.
2855 Constant: Casting to a signed integer type of insufficient size.
2856 Definite: Casting to a signed integer type of insufficient size.
2857 Apparent: Casting to a signed integer type of insufficient size.
2860 Constant: Implementation-defined value resulting from left shift operation on expression of signed type.
2861 Definite: Implementation-defined value resulting from left shift operation on expression of signed type.
2862 Apparent: Implementation-defined value resulting from left shift operation on expression of signed type.
2895 Constant: Negative value cast to an unsigned type.
2896 Definite: Negative value cast to an unsigned type.
2897 Apparent: Negative value cast to an unsigned type.
3116 Unrecognized #pragma arguments '%s' This #pragma directive has been ignored.
-
Dir-2.1RequiredAll source files shall compile without any compilation errorsUnassisted

-Remarks:
-Dedicated checks deployed in Jenkins.
Dir-3.1RequiredAll code shall be traceable to documented requirementsUnassisted

-Remarks:
-Limited management of requirements.
Dir-4.1RequiredRun-time failures shall be minimized
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2791 Definite: Right hand operand of shift operator is negative or too large.
2792 Apparent: Right hand operand of shift operator is negative or too large.
2801 Definite: Overflow in signed arithmetic operation.
2802 Apparent: Overflow in signed arithmetic operation.
2811 Definite: Dereference of NULL pointer.
2812 Apparent: Dereference of NULL pointer.
2821 Definite: Arithmetic operation on NULL pointer.
2822 Apparent: Arithmetic operation on NULL pointer.
2831 Definite: Division by zero.
2832 Apparent: Division by zero.
2841 Definite: Dereference of an invalid pointer value.
2842 Apparent: Dereference of an invalid pointer value.
2845 Constant: Maximum number of characters to be written is larger than the target buffer size.
2846 Definite: Maximum number of characters to be written is larger than the target buffer size.
2847 Apparent: Maximum number of characters to be written is larger than the target buffer size.
2871 Infinite loop identified.
2872 This loop, if entered, will never terminate.
2877 This loop will never be executed more than once.
-
Dir-4.10RequiredPrecautions shall be taken in order to prevent the contents of a header file being included more then once
- - - - - -
QacDescription
0883 Include file code is not protected against repeated inclusion
-
Dir-4.11RequiredThe validity of values passed to library functions shall be checkedUnassisted

-Remarks:
-No automated check deployed.
-Manual checks done by developers.
Dir-4.12RequiredDynamic memory allocation shall not be usedUnassisted

-Remarks:
-No memory allocation functions (malloc(), calloc(), realloc()) being called in RFAL.
Dir-4.13AdvisoryFunctions which are designed to provide operations on a resource should be called in an appropriate sequenceUnassisted
Dir-4.14RequiredThe validity of values received from external sources shall be checked
- - - - - -
QacDescription
2956 Definite: Using object '%s' with tainted value.
-
Dir-4.2AdvisoryAll usage of assembly language should be documented
- - - - - - - - - -
QacDescription
1003 [E] '#%s' is a language extension for in-line assembler. All statements located between #asm and #endasm will be ignored.
1006 [E] This in-line assembler construct is a language extension. The code has been ignored.
-
Dir-4.3RequiredAssembly language shall be encapsulated and isolated
- - - - - - - - - -
QacDescription
3006 This function contains a mixture of in-line assembler statements and C statements.
3008 This function contains a mixture of in-line assembler statements and C code.
-
Dir-4.4AdvisorySections of code should not be "commented out"Unassisted
Dir-4.5AdvisoryIdentifiers in the same name space with overlapping visibility should be typographically unambiguousUnassisted
Dir-4.6Advisorytypedefs that indicate size and signedness should be used in place of the basic numerical types
- - - - - -
QacDescription
5209 Use of basic type '%s'.
-
Dir-4.7RequiredIf a function returns error information, then that error information shall be testedUnassisted

-Remarks:
-Dir-4.7 is similar to Rule-17.7 which is currently dismissed.
-This directive is consequently considered as disapplied.
Dir-4.8AdvisoryIf a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hiddenUnassisted
Dir-4.9AdvisoryA function should be used in preference to a function-like macro where they are interchangeable
- - - - - -
QacDescription
3453 A function could probably be used instead of this function-like macro.
-
Rule-1.1RequiredThe program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0232 [C] Value of hex escape sequence is not representable in type 'unsigned char'.
0233 [C] Value of octal escape sequence is not representable in type 'unsigned char'.
0244 [C] Value of character constant is not representable in type 'int'.
0268 [S] Comment open at end of translation unit.
0321 [C] Declaration within 'for' statement defines an identifier '%s' which is not an object.
0322 [C] Illegal storage class specifier used in 'for' statement declaration.
0338 [C] Octal or hex escape sequence value is too large for 'unsigned char' or 'wchar_t' type.
0422 [C] Function call contains fewer arguments than prototype specifies.
0423 [C] Function call contains more arguments than prototype specifies.
0426 [C] Called function has incomplete return type.
0427 [C] Object identifier used as if it were a function or a function pointer identifier.
0429 [C] Function argument is not of arithmetic type.
0430 [C] Function argument is not of compatible 'struct'/'union' type.
0431 [C] Function argument points to a more heavily qualified type.
0432 [C] Function argument is not of compatible pointer type.
0435 [C] The 'struct'/'union' member '%s' does not exist.
0436 [C] Left operand of '.' must be a 'struct' or 'union' object.
0437 [C] Left operand of '->' must be a pointer to a 'struct' or 'union' object.
0446 [C] Operand of ++/-- must have scalar (arithmetic or pointer) type.
0447 [C] Operand of ++/-- must be a modifiable object.
0448 [C] Operand of ++/-- must not be a pointer to an object of unknown size.
0449 [C] Operand of ++/-- must not be a pointer to a function.
0450 [C] An expression of array type cannot be cast.
0451 [C] Subscripting requires a pointer (or array lvalue).
0452 [C] Cannot subscript a pointer to an object of unknown size.
0453 [C] An array subscript must have integral type.
0454 [C] The address-of operator '&' cannot be applied to an object declared with 'register'.
0456 [C] This expression does not have an address - '&' may only be applied to an lvalue or a function designator.
0457 [C] The address-of operator '&' cannot be applied to a bit-field.
0458 [C] Indirection operator '*' requires operand of pointer type.
0460 [C] The keyword static is used in the declaration of the index of an array which is not a function parameter.
0461 [C] The keyword static is used in the declaration of an inner index of a multi-dimensional array.
0462 [C] A type qualifier (const, volatile or restrict) is used in the declaration of the index of an array which is not a function parameter.
0463 [C] A type qualifier (const, volatile or restrict) is used in the declaration of an inner index of a multi-dimensional array.
0466 [C] Unary '+' requires arithmetic operand.
0467 [C] Operand of '!' must have scalar (arithmetic or pointer) type.
0468 [C] Unary '-' requires arithmetic operand.
0469 [C] Bitwise not '~' requires integral operand.
0476 [C] 'sizeof' cannot be applied to a bit-field.
0477 [C] 'sizeof' cannot be applied to a function.
0478 [C] 'sizeof' cannot be applied to an object of unknown size.
0481 [C] Only scalar expressions may be cast to other types.
0482 [C] Expressions may only be cast to 'void' or scalar types.
0483 [C] A pointer to an object of unknown size cannot be the operand of an addition operator.
0484 [C] A pointer to an object of unknown size cannot be the operand of a subtraction operator.
0485 [C] Only integral expressions may be added to pointers.
0486 [C] Only integral expressions and compatible pointers may be subtracted from pointers.
0487 [C] If two pointers are subtracted, they must be pointers that address compatible types.
0493 [C] Type of left operand is not compatible with this operator.
0494 [C] Type of right operand is not compatible with this operator.
0495 [C] Left operand of '%', '<<', '>>', '&', '^' or '|' must have integral type.
0496 [C] Right operand of '%', '<<', '>>', '&', '^' or '|' must have integral type.
0513 [C] Relational operator used to compare pointers to incompatible types.
0514 [C] Relational operator used to compare a pointer with an incompatible operand.
0515 [C] Equality operator used to compare a pointer with an incompatible operand.
0536 [C] First operand of '&&', '||' or '?' must have scalar (arithmetic or pointer) type.
0537 [C] Second operand of '&&' or '||' must have scalar (arithmetic or pointer) type.
0540 [C] 2nd and 3rd operands of conditional operator '?' must have compatible types.
0541 [C] Argument no. %s does not have object type.
0542 [C] Controlling expression must have scalar (arithmetic or pointer) type.
0546 [C] 'enum %s' has unknown content. Use of an enum tag with undefined content is not permitted.
0547 [C] This declaration of tag '%s' conflicts with a previous declaration.
0550 [C] Left operand of '+=' or '-=' is a pointer to an object of unknown size.
0554 [C] 'static %s()' has been declared and called but no definition has been given.
0555 [C] Invalid assignment to object of void type or array type.
0556 [C] Left operand of assignment must be a modifiable object.
0557 [C] Right operand of assignment is not of arithmetic type.
0558 [C] Right operand of '+=' or '-=' must have integral type when left operand is a pointer.
0559 [C] Right operand of '<<=', '>>=', '&=', '|=', '^=' or '%=' must have integral type.
0560 [C] Left operand of '<<=', '>>=', '&=', '|=', '^=' or '%=' must have integral type.
0561 [C] Right operand of assignment is not of compatible 'struct'/'union' type.
0562 [C] Right operand of assignment points to a more heavily qualified type.
0563 [C] Right operand of assignment is not of compatible pointer type.
0564 [C] Left operand of assignment must be an lvalue (it must designate an object).
0565 [C] Left operand of '+=' or '-=' must be of arithmetic or pointer to object type.
0580 [C] Constant is too large to be representable.
0588 [C] Width of bit-field must be an integral constant expression.
0589 [C] Enumeration constant must be an integral constant expression.
0590 [C] Array bound must be an integral constant expression.
0591 [C] A 'case' label must be an integral constant expression.
0605 [C] A declaration must declare a tag or an identifier.
0616 [C] Illegal combination of type specifiers or storage class specifiers.
0619 [C] The identifier '%s' has already been defined in the current scope within the ordinary identifier namespace.
0620 [C] Cannot initialize '%s' because it has unknown size.
0621 [C] The struct/union '%s' cannot be initialized because it has unknown size.
0622 [C] The identifier '%s' has been declared both with and without linkage in the same scope.
0627 [C] '%s' has different type to previous declaration in the same scope.
0628 [C] '%s' has different type to previous declaration at wider scope.
0629 [C] More than one definition of '%s' (with internal linkage).
0631 [C] More than one declaration of '%s' (with no linkage).
0638 [C] Duplicate member name '%s' in 'struct' or 'union'.
0640 [C] '%s' in 'struct' or 'union' type may not have 'void' type.
0641 [C] '%s' in 'struct' or 'union' type may not have function type.
0642 [C] '%s' in 'struct' or 'union' type may not be an array of unknown size.
0643 [C] '%s' in 'struct' or 'union' type may not be a 'struct' or 'union' with unknown content.
0644 [C] Width of bit-field must be no bigger than the width of an 'int'.
0645 [C] A zero width bit-field cannot be given a name.
0646 [C] Enumeration constants must have values representable as 'int's.
0649 [C] K&R style declaration of parameters is not legal after a function header that includes a parameter list.
0650 [C] Illegal storage class specifier on named function parameter.
0651 [C] Missing type specifiers in function declaration.
0653 [C] Duplicate definition of 'struct', 'union' or 'enum' tag '%s'.
0655 [C] Illegal storage class specifier on unnamed function parameter.
0656 [C] Function return type cannot be function or array type, or an incomplete struct/union (for function definition).
0657 [C] Unnamed parameter specified in function definition.
0659 [C] The identifier '%s' was not given in the parameter list.
0664 [C] Parameter specified with type 'void'.
0665 [C] Two parameters have been declared with the same name '%s'.
0669 [C] The restrict qualifier can only be applied to pointer types derived from object or incomplete types.
0671 [C] Initializer for object of arithmetic type is not of arithmetic type.
0673 [C] Initializer points to a more heavily qualified type.
0674 [C] Initializer for pointer is of incompatible type.
0675 [C] Initializer is not of compatible 'struct'/'union' type.
0677 [C] Array size is negative, or unrepresentable.
0682 [C] Initializer for object of a character type is a string literal.
0683 [C] Initializer for object of a character type is a wide string literal.
0684 [C] Too many initializers.
0685 [C] Initializer for any object with static storage duration must be a constant expression.
0690 [C] String literal contains too many characters to initialize object.
0698 [C] String literal used to initialize an object of incompatible type.
0699 [C] String literal used to initialize a pointer of incompatible type.
0708 [C] No definition found for the label '%s' in this function.
0709 [C] Initialization of locally declared 'extern %s' is illegal.
0736 [C] 'case' label does not have unique value within this 'switch' statement.
0737 [C] More than one 'default' label found in 'switch' statement.
0738 [C] Controlling expression in a 'switch' statement must have integral type.
0746 [C] 'return exp;' found in '%s()' whose return type is 'void'.
0747 [C] 'return exp;' found in '%s()' whose return type is qualified 'void'.
0755 [C] 'return' expression is not of arithmetic type.
0756 [C] 'return' expression is not of compatible 'struct'/'union' type.
0757 [C] 'return' expression points to a more heavily qualified type.
0758 [C] 'return' expression is not of compatible pointer type.
0766 [C] 'continue' statement found outside an iteration statement.
0767 [C] 'break' statement found outside a 'switch' or iteration statement.
0768 [C] 'case' or 'default' found outside a 'switch' statement.
0774 [C] 'auto' may not be specified on global declaration of '%s'.
0775 [C] 'register' may not be specified on global declaration of '%s'.
0801 [C] The '##' operator may not be the first token in a macro replacement list.
0802 [C] The '##' operator may not be the last token in a macro replacement list.
0803 [C] The '#' operator may only appear before a macro parameter.
0804 [C] Macro parameter '%s' is not unique.
0811 [C] The glue operator '##' may only appear in a '#define' preprocessing directive.
0812 [C] Header name token '' found outside '#include' preprocessing directive.
0817 [S] Closing quote or bracket '>' missing from include filename.
0818 [Q] Cannot find '%s' - Perhaps the appropriate search path was not given ?
0821 [C] '#include' does not identify a header or source file that can be processed.
0834 [C] Function-like macro '%s()' is being redefined as an object-like macro.
0835 [C] Macro '%s' is being redefined with different parameter names.
0844 [C] Macro '%s' is being redefined with a different replacement list.
0845 [C] Object-like macro '%s' is being redefined as a function-like macro.
0851 [C] More arguments in macro call than specified in definition.
0852 [S] Unable to find the ')' that marks the end of the macro call.
0866 [C] The string literal in a '#line' directive cannot be a 'wide string literal'.
0873 [C] Preprocessing token cannot be converted to an actual token.
0877 [C] '#if' and '#elif' expressions may contain only integral constants.
0940 [C] Illegal usage of a variably modified type.
0941 [C] A variable length array may not be initialized.
0943 [C] Jump to label '%s' is a jump into the scope of an identifier with variably modified type.
0944 [C] The label '%s' is inside the scope of an identifier with variably modified type.
1023 [C] Using '__alignof__' on function types is illegal.
1024 [C] Using '__alignof__' on incomplete types is illegal.
1025 [C] Using '__alignof__' on bit-fields is illegal.
1033 [C] The identifier __VA_ARGS__ may only be used in the replacement list of a variadic macro.
1047 [C] Function is being declared with default argument syntax after a previous call to the function. This is not allowed.
1048 [C] Default argument values are missing for some parameters in this function declaration. This is not allowed.
1050 [C] Nested functions cannot be 'extern' or 'static'.
1061 [C] Structure '%1s' with flexible array member '%2s' cannot be used in the declaration of structure member '%3s'.
1062 [C] Structure '%1s' with flexible array member '%2s' cannot be used in the declaration of array elements.
3236 [C] 'inline' may not be applied to function 'main'.
3237 [C] inline function '%1s' has external linkage and is defining an object, '%2s', with static storage duration.
3238 [C] inline function '%1s' has external linkage and is referring to an object, '%2s', with internal linkage.
3244 [C] 'inline' may only be used in the declaration of a function identifier.
-
Rule-1.2AdvisoryLanguage extensions should not be used
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0240 [E] This file contains the control-M character at the end of a line.
0241 [E] This file contains the control-Z character - was this transferred from a PC?
0246 [E] Binary integer constants are a language extension.
0551 [E] Cast may not operate on the left operand of the assignment operator.
0601 [E] Function 'main()' is not of type 'int (void)' or 'int (int, char *[])'.
0633 [E] Empty structures and unions are a language extension.
0635 [E] Bit-fields in this struct/union have been declared with types other than int, signed int, unsigned int or _Bool.
0660 [E] Defining an unnamed member in a struct or union. This is a language extension.
0662 [E] Accessing a member of an unnamed struct or union member in this way is a language extension.
0830 [E] Unrecognized text encountered after a preprocessing directive.
0831 [E] Use of '\\' in this '#include' line is a PC extension - this usage is non-portable.
0840 [E] Extra tokens at end of #include directive.
0883 Include file code is not protected against repeated inclusion
0899 [E] Unrecognized preprocessing directive has been ignored - assumed to be a language extension.
0981 [E] Redundant semicolon in 'struct' or 'union' member declaration list is a language extension.
1001 [E] '#include %s' is a VMS extension.
1002 [E] '%s' is not a legal identifier in ISO C.
1003 [E] '#%s' is a language extension for in-line assembler. All statements located between #asm and #endasm will be ignored.
1006 [E] This in-line assembler construct is a language extension. The code has been ignored.
1008 [E] '#%s' is not a legal ISO C preprocessing directive.
1012 [E] Use of a C++ reference type ('type &') will be treated as a language extension.
1014 [E] Non-standard type specifier - this will be treated as a language extension.
1015 [E] '%s' is not a legal keyword in ISO C - this will be treated as a language extension.
1019 [E] '@ address' is not supported in ISO C - this will be treated as a language extension.
1020 [E] '__typeof__' is not supported in ISO C, and is treated as a language extension.
1021 [E] A statement expression is not supported in ISO C, and is treated as a language extension.
1022 [E] '__alignof__' is not supported in ISO C, and is treated as a language extension.
1026 [E] The indicated @word construct has been ignored.
1028 [E] Use of the sizeof operator in a preprocessing directive is a language extension.
1029 [E] Whitespace encountered between backslash and new-line has been ignored.
1034 [E] Macro defined with named variable argument list. This is a language extension.
1035 [E] No macro arguments supplied for variable argument list. This is a language extension.
1036 [E] Comma before ## ignored in expansion of variadic macro. This is a language extension.
1037 [E] Arrays of length zero are a language extension.
1038 [E] The sequence ", ##__VA_ARGS__" is a language extension.
1039 [E] Treating array of length one as potentially flexible member.
1041 [E] Empty aggregate initializers are a language extension.
1042 [E] Using I64 or UI64 as an integer constant suffix. This is a language extension.
1043 [E] Defining an anonymous union object. This is a language extension.
1044 [E] Defining an anonymous struct object. This is a language extension.
1045 [E] Use of the #include_next preprocessing directive is a language extension.
1046 [E] Function is being declared with default argument syntax. This is a language extension.
1049 [E] Nested functions are a language extension.
3445 [E] Conditional expression with middle operand omitted is a language extension.
3664 [E] Using a dot operator to access an individual bit is a language extension.
-
Rule-1.3RequiredThere shall be no occurrence of undefined or critical unspecified behaviour
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0160 [U] Using unsupported conversion specifier number %s.
0161 [U] Unknown length modifier used with 'i' or 'd' conversion specifier, number %s.
0162 [U] Unknown length modifier used with 'o' conversion specifier, number %s.
0163 [U] Unknown length modifier used with 'u' conversion specifier, number %s.
0164 [U] Unknown length modifier used with 'x' conversion specifier, number %s.
0165 [U] Unknown length modifier used with 'X' conversion specifier, number %s.
0166 [U] Unknown length modifier used with 'f' conversion specifier, number %s.
0167 [U] Unknown length modifier used with 'e' conversion specifier, number %s.
0168 [U] Unknown length modifier used with 'E' conversion specifier, number %s.
0169 [U] Unknown length modifier used with 'g' conversion specifier, number %s.
0170 [U] Unknown length modifier used with 'G' conversion specifier, number %s.
0171 [U] Unknown length modifier used with 'c' conversion specifier, number %s.
0172 [U] Unknown length modifier used with '%%' conversion specifier, number %s.
0173 [U] Unknown length modifier used with 's' conversion specifier, number %s.
0174 [U] Unknown length modifier used with 'n' conversion specifier, number %s.
0175 [U] Unknown length modifier used with 'p' conversion specifier, number %s.
0176 [U] Incomplete conversion specifier, number %s.
0177 [U] Field width of format conversion specifier exceeds 509 characters.
0178 [U] Precision of format conversion specifier exceeds 509 characters.
0179 [U] Argument type does not match conversion specifier number %s.
0184 [U] Insufficient arguments to satisfy conversion specifier, number %s.
0185 [U] Call contains more arguments than conversion specifiers.
0186 [U] A call to this function must include at least one argument.
0190 [U] Using unsupported conversion specifier number %s.
0191 [U] Unknown length modifier used with 'd/i/n' conversion specifier, number %s.
0192 [U] Unknown length modifier used with 'o' conversion specifier, number %s.
0193 [U] Unknown length modifier used with 'u' conversion specifier, number %s.
0194 [U] Unknown length modifier used with 'x/X' conversion specifier, number %s.
0195 [U] Unknown length modifier used with 'e/E/f/F/g/G' conversion specifier, number %s.
0196 [U] Unknown length modifier used with 's' conversion specifier, number %s.
0197 [U] Unknown length modifier used with 'p' conversion specifier, number %s.
0198 [U] Unknown length modifier used with '%%' conversion specifier, number %s.
0199 [U] Unknown length modifier used with '[' conversion specifier, number %s.
0200 [U] Unknown length modifier used with 'c' conversion specifier, number %s.
0201 [U] Incomplete conversion specifier, number %s.
0203 [U] Value of character prior to '-' in '[]' is greater than following character.
0204 [U] Field width of format conversion specifier exceeds 509 characters.
0206 [U] Argument type does not match conversion specifier number %s.
0207 [U] 'scanf' expects address of objects being stored into.
0208 [U] Same character occurs in scanset more than once.
0235 [U] Unknown escape sequence.
0275 [U] Floating value is out of range for conversion to destination type.
0301 [u] Cast between a pointer to object and a floating type.
0302 [u] Cast between a pointer to function and a floating type.
0304 [U] The address of an array declared 'register' may not be computed.
0307 [u] Cast between a pointer to object and a pointer to function.
0309 [U] Integral type is not large enough to hold a pointer value.
0327 [I] Cast between a pointer to void and an floating type.
0337 [U] String literal has undefined value. This may be a result of using '#' on \\.
0400 [U] '%s' is modified more than once between sequence points - evaluation order unspecified.
0401 [U] '%s' may be modified more than once between sequence points - evaluation order unspecified.
0402 [U] '%s' is modified and accessed between sequence points - evaluation order unspecified.
0403 [U] '%s' may be modified and accessed between sequence points - evaluation order unspecified.
0404 More than one read access to volatile objects between sequence points.
0405 More than one modification of volatile objects between sequence points.
0475 [u] Operand of 'sizeof' is an expression designating a bit-field.
0543 [U] 'void' expressions have no value and may not be used in expressions.
0544 [U] The value of an incomplete 'union' may not be used.
0545 [U] The value of an incomplete 'struct' may not be used.
0602 [U] The identifier '%s' is reserved for use by the library.
0603 [U] The macro identifier '%s' is reserved.
0623 [U] '%s' has incomplete type and no linkage - this is undefined.
0625 [U] '%s' has been declared with both internal and external linkage - the behaviour is undefined.
0626 [U] '%s' has different type to previous declaration (which is no longer in scope).
0630 [U] More than one definition of '%s' (with external linkage).
0632 [U] Tentative definition of '%s' with internal linkage cannot have unknown size.
0636 [U] There are no named members in this 'struct' or 'union'.
0654 [U] Using 'const' or 'volatile' in a function return type is undefined.
0658 [U] Parameter cannot have 'void' type.
0661 [U] '%s()' may not have a storage class specifier of 'static' when declared at block scope.
0667 [U] '%s' is declared as a typedef and may not be redeclared as an object at an inner scope without an explicit type specifier.
0668 [U] '%s' is declared as a typedef and may not be redeclared as a member of a 'struct' or 'union' without an explicit type specifier.
0672 [U] The initializer for a 'struct', 'union' or array is not enclosed in braces.
0676 [u] Array element is of function type. Arrays cannot be constructed from function types.
0678 [u] Array element is array of unknown size. Arrays cannot be constructed from incomplete types.
0680 [u] Array element is 'void' or an incomplete 'struct' or 'union'. Arrays cannot be constructed from incomplete types.
0706 [U] Label '%s' is not unique within this function.
0745 [U] 'return;' found in '%s()', which has been defined with a non-'void' return type.
0777 [U] External identifier does not differ from other identifier(s) (e.g. '%s') within the specified number of significant characters.
0779 [U] Identifier does not differ from other identifier(s) (e.g. '%s') within the specified number of significant characters.
0813 [U] Using any of the characters ' " or /* in '#include <%s>' gives undefined behaviour.
0814 [U] Using the characters ' or /* in '#include "%s"' gives undefined behaviour.
0836 [U] Definition of macro named 'defined'.
0837 [U] Use of '#undef' to remove the operator 'defined'.
0840 [E] Extra tokens at end of #include directive.
0848 [U] Attempting to #undef '%s', which is a predefined macro name.
0853 [U] Macro arguments contain a sequence of tokens that has the form of a preprocessing directive.
0854 [U] Attempting to #define '%s', which is a predefined macro name.
0864 [U] '#line' directive specifies line number which is not in the range 1 to 32767.
0865 [U] '#line' directive is badly formed.
0867 [U] '#line' has not been followed by a line number.
0872 [U] Result of '##' operator is not a legal preprocessing token.
0874 [U] Character string literal and wide character string literal are adjacent.
0885 [U] The token 'defined' is generated in the expansion of this macro.
0887 [U] Use of 'defined' must match either 'defined(identifier)' or 'defined identifier'.
0888 [U] 'defined' requires an identifier as an argument.
0914 [U] Source file does not end with a newline character.
0915 [U] Source file ends with a backslash character followed by a newline.
0942 [U] A * can only be used to specify array size within function prototype scope.
1331 Type or number of arguments doesn't match previous use of the function.
1332 Type or number of arguments doesn't match prototype found later.
1333 Type or number of arguments doesn't match function definition found later.
2800 Constant: Overflow in signed arithmetic operation.
2810 Constant: Dereference of NULL pointer.
2820 Constant: Arithmetic operation on NULL pointer.
2830 Constant: Division by zero.
2840 Constant: Dereference of an invalid pointer value.
3113 [U] 'return' statement includes no expression but function '%s()' is implicitly of type 'int'.
3114 [U] Function '%s()' is implicitly of type 'int' but ends without returning a value.
3239 [U] inline function '%1s' has external linkage, but is not defined within this translation unit.
3311 [u] An earlier jump to this statement will bypass the initialization of local variables.
3312 [u] This goto statement will jump into a previous block and bypass the initialization of local variables.
3319 [U] Function called with number of arguments which differs from number of parameters in definition.
3320 Type of argument no. %s differs from its type in definition of function.
3437 [u] The assert macro has been suppressed to call a function of that name.
3438 [U] #undef'ing the assert macro to call a function of that name causes undefined behaviour.
1509 '%1s' has external linkage and has multiple definitions.
1510 '%1s' has external linkage and has incompatible declarations.
-
Rule-10.1RequiredOperands shall not be of an inappropriate essential type.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
3101 Unary '-' applied to an operand of type unsigned int or unsigned long gives an unsigned result.
3102 Unary '-' applied to an operand whose underlying type is unsigned.
4500 An expression of 'essentially Boolean' type (%1s) is being used as an array subscript.
4501 An expression of 'essentially Boolean' type (%1s) is being used as the %2s operand of this arithmetic operator (%3s).
4502 An expression of 'essentially Boolean' type (%1s) is being used as the %2s operand of this bitwise operator (%3s).
4503 An expression of 'essentially Boolean' type (%1s) is being used as the left-hand operand of this shift operator (%2s).
4504 An expression of 'essentially Boolean' type (%1s) is being used as the right-hand operand of this shift operator (%2s).
4505 An expression of 'essentially Boolean' type (%1s) is being used as the %2s operand of this relational operator (%3s).
4507 An expression of 'essentially Boolean' type (%1s) is being used as the operand of this increment/decrement operator (%2s).
4510 An expression of 'essentially character' type (%1s) is being used as an array subscript.
4511 An expression of 'essentially character' type (%1s) is being used as the %2s operand of this arithmetic operator (%3s).
4512 An expression of 'essentially character' type (%1s) is being used as the %2s operand of this bitwise operator (%3s).
4513 An expression of 'essentially character' type (%1s) is being used as the left-hand operand of this shift operator (%2s).
4514 An expression of 'essentially character' type (%1s) is being used as the right-hand operand of this shift operator (%2s).
4518 An expression of 'essentially character' type (%1s) is being used as the %2s operand of this logical operator (%3s).
4519 An expression of 'essentially character' type (%1s) is being used as the first operand of this conditional operator (%2s).
4521 An expression of 'essentially enum' type (%1s) is being used as the %2s operand of this arithmetic operator (%3s).
4522 An expression of 'essentially enum' type (%1s) is being used as the %2s operand of this bitwise operator (%3s).
4523 An expression of 'essentially enum' type (%1s) is being used as the left-hand operand of this shift operator (%2s).
4524 An expression of 'essentially enum' type (%1s) is being used as the right-hand operand of this shift operator (%2s).
4527 An expression of 'essentially enum' type is being used as the operand of this increment/decrement operator.
4528 An expression of 'essentially enum' type (%1s) is being used as the %2s operand of this logical operator (%3s).
4529 An expression of 'essentially enum' type (%1s) is being used as the first operand of this conditional operator (%2s).
4532 An expression of 'essentially signed' type (%1s) is being used as the %2s operand of this bitwise operator (%3s).
4533 An expression of 'essentially signed' type (%1s) is being used as the left-hand operand of this shift operator (%2s).
4534 An expression of 'essentially signed' type (%1s) is being used as the right-hand operand of this shift operator (%2s).
4538 An expression of 'essentially signed' type (%1s) is being used as the %2s operand of this logical operator (%3s).
4539 An expression of 'essentially signed' type (%1s) is being used as the first operand of this conditional operator (%2s).
4542 A non-negative constant expression of 'essentially signed' type (%1s) is being used as the %2s operand of this bitwise operator (%3s).
4543 A non-negative constant expression of 'essentially signed' type (%1s) is being used as the left-hand operand of this shift operator (%2s).
4548 A non-negative constant expression of 'essentially signed' type (%1s) is being used as the %2s operand of this logical operator (%3s).
4549 A non-negative constant expression of 'essentially signed' type (%1s) is being used as the first operand of this conditional operator (%2s).
4558 An expression of 'essentially unsigned' type (%1s) is being used as the %2s operand of this logical operator (%3s).
4559 An expression of 'essentially unsigned' type (%1s) is being used as the first operand of this conditional operator (%2s).
4568 An expression of 'essentially floating' type (%1s) is being used as the %2s operand of this logical operator (%3s).
4569 An expression of 'essentially floating' type (%1s) is being used as the first operand of this conditional operator (%2s).
-
Rule-10.2RequiredExpressions of essentially character type shall not be used inappropriately in addition and subtraction operations
- - - - - - - - - - - - - - - - - -
QacDescription
1810 An operand of 'essentially character' type is being added to another operand of 'essentially character' type.
1811 An operand of 'essentially character' type is being subtracted from an operand of 'essentially signed' type.
1812 An operand of 'essentially character' type is being subtracted from an operand of 'essentially unsigned' type.
1813 An operand of 'essentially character' type is being balanced with an operand of 'essentially floating' type in this arithmetic operation.
-
Rule-10.3RequiredThe value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0570 This switch case label of 'essential type' '%1s', is not consistent with a controlling expression of essential type '%2s'.
0572 This switch case label of 'essential type' '%1s' is not consistent with a controlling expression which has an essential type of lower rank (%2s).
1257 An integer constant suffixed with L or LL is being converted to a type of lower rank on assignment.
1264 A suffixed floating constant is being converted to a different floating type on assignment.
1265 An unsuffixed floating constant is being converted to a different floating type on assignment.
1266 A floating constant is being converted to integral type on assignment.
1291 An integer constant of 'essentially unsigned' type is being converted to signed type on assignment.
1292 An integer constant of 'essentially signed' type is being converted to type char on assignment.
1293 An integer constant of 'essentially unsigned' type is being converted to type char on assignment.
1294 An integer constant of 'essentially signed' type is being converted to type _Bool on assignment.
1295 An integer constant of 'essentially unsigned' type is being converted to type _Bool on assignment.
1296 An integer constant of 'essentially signed' type is being converted to enum type on assignment.
1297 An integer constant of 'essentially unsigned' type is being converted to enum type on assignment.
1298 An integer constant of 'essentially signed' type is being converted to floating type on assignment.
1299 An integer constant of 'essentially unsigned' type is being converted to floating type on assignment.
2850 Constant: Implicit conversion to a signed integer type of insufficient size.
2890 Constant: Negative value implicitly converted to an unsigned type.
2900 Constant: Positive integer value truncated by implicit conversion to a smaller unsigned type.
4401 An expression of 'essentially Boolean' type (%1s) is being converted to character type, '%2s' on assignment.
4402 An expression of 'essentially Boolean' type (%1s) is being converted to enum type, '%2s' on assignment.
4403 An expression of 'essentially Boolean' type (%1s) is being converted to signed type, '%2s' on assignment.
4404 An expression of 'essentially Boolean' type (%1s) is being converted to unsigned type, '%2s' on assignment.
4405 An expression of 'essentially Boolean' type (%1s) is being converted to floating type, '%2s' on assignment.
4410 An expression of 'essentially character' type (%1s) is being converted to Boolean type, '%2s' on assignment.
4412 An expression of 'essentially character' type (%1s) is being converted to enum type, '%2s' on assignment.
4413 An expression of 'essentially character' type (%1s) is being converted to signed type, '%2s' on assignment.
4414 An expression of 'essentially character' type (%1s) is being converted to unsigned type, '%2s' on assignment.
4415 An expression of 'essentially character' type (%1s) is being converted to floating type, '%2s' on assignment.
4420 An expression of 'essentially enum' type (%1s) is being converted to Boolean type, '%2s' on assignment.
4421 An expression of 'essentially enum' type (%1s) is being converted to character type, '%2s' on assignment.
4422 An expression of 'essentially enum' type (%1s) is being converted to a different enum type, '%2s' on assignment.
4423 An expression of 'essentially enum' type (%1s) is being converted to signed type, '%2s' on assignment.
4424 An expression of 'essentially enum' type (%1s) is being converted to unsigned type, '%2s' on assignment.
4425 An expression of 'essentially enum' type (%1s) is being converted to floating type, '%2s' on assignment.
4430 An expression of 'essentially signed' type (%1s) is being converted to Boolean type, '%2s' on assignment.
4431 An expression of 'essentially signed' type (%1s) is being converted to character type, '%2s' on assignment.
4432 An expression of 'essentially signed' type (%1s) is being converted to enum type, '%2s' on assignment.
4434 A non-constant expression of 'essentially signed' type (%1s) is being converted to unsigned type, '%2s' on assignment.
4435 A non-constant expression of 'essentially signed' type (%1s) is being converted to floating type, '%2s' on assignment.
4437 A constant expression of 'essentially signed' type (%1s) is being converted to floating type, '%2s' on assignment.
4440 An expression of 'essentially unsigned' type (%1s) is being converted to Boolean type, '%2s' on assignment.
4441 An expression of 'essentially unsigned' type (%1s) is being converted to character type, '%2s' on assignment.
4442 An expression of 'essentially unsigned' type (%1s) is being converted to enum type, '%2s' on assignment.
4443 A non-constant expression of 'essentially unsigned' type (%1s) is being converted to a wider signed type, '%2s' on assignment.
4445 An expression of 'essentially unsigned' type (%1s) is being converted to floating type, '%2s' on assignment.
4446 A non-constant expression of 'essentially unsigned' type (%1s) is being converted to signed type, '%2s' on assignment.
4447 A constant expression of 'essentially unsigned' type (%1s) is being converted to signed type, '%2s' on assignment.
4450 An expression of 'essentially floating' type (%1s) is being converted to Boolean type, '%2s' on assignment.
4451 An expression of 'essentially floating' type (%1s) is being converted to character type, '%2s' on assignment.
4452 An expression of 'essentially floating' type (%1s) is being converted to enum type, '%2s' on assignment.
4453 An expression of 'essentially floating' type (%1s) is being converted to signed type, '%2s' on assignment.
4454 An expression of 'essentially floating' type (%1s) is being converted to unsigned type, '%2s' on assignment.
4460 A non-constant expression of 'essentially signed' type (%1s) is being converted to narrower signed type, '%2s' on assignment.
4461 A non-constant expression of 'essentially unsigned' type (%1s) is being converted to narrower unsigned type, '%2s' on assignment.
4462 A non-constant expression of 'essentially floating' type (%1s) is being converted to narrower floating type, '%2s' on assignment.
4463 A constant expression of 'essentially signed' type (%1s) is being converted to narrower signed type, '%2s' on assignment.
4464 A constant expression of 'essentially unsigned' type (%1s) is being converted to narrower unsigned type, '%2s' on assignment.
4465 A constant expression of 'essentially floating' type (%1s) is being converted to narrower floating type, '%2s' on assignment.
-
Rule-10.4RequiredBoth operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
1800 The %1s operand (essential type: '%2s') will be implicitly converted to a floating type, '%3s', in this arithmetic operation.
1802 The %1s operand (essential type: '%2s') will be implicitly converted to a floating type, '%3s', in this relational operation.
1803 The %1s operand (essential type: '%2s') will be implicitly converted to a floating type, '%3s', in this equality operation.
1804 The %1s operand (essential type: '%2s') will be implicitly converted to a floating type, '%3s', in this conditional operation.
1820 The %1s operand is non-constant and 'essentially signed' (%2s) but will be implicitly converted to an unsigned type (%3s) in this arithmetic operation.
1821 The %1s operand is non-constant and 'essentially signed' (%2s) but will be implicitly converted to an unsigned type (%3s) in this bitwise operation.
1822 The %1s operand is non-constant and 'essentially signed' (%2s) but will be implicitly converted to an unsigned type (%3s) in this relational operation.
1823 The %1s operand is non-constant and 'essentially signed' (%2s) but will be implicitly converted to an unsigned type (%3s) in this equality operation.
1824 The %1s operand is non-constant and 'essentially signed' (%2s) but will be implicitly converted to an unsigned type (%3s) in this conditional operation.
1830 The %1s operand is constant, 'essentially signed' (%2s) and negative but will be implicitly converted to an unsigned type (%3s) in this arithmetic operation.
1831 The %1s operand is constant, 'essentially signed' (%2s) and negative but will be implicitly converted to an unsigned type (%3s) in this bitwise operation.
1832 The %1s operand is constant, 'essentially signed' (%2s) and negative but will be implicitly converted to an unsigned type (%3s) in this relational operation.
1833 The %1s operand is constant, 'essentially signed' (%2s) and negative but will be implicitly converted to an unsigned type (%3s) in this equality operation.
1834 The %1s operand is constant, 'essentially signed' (%2s) and negative but will be implicitly converted to an unsigned type (%3s) in this conditional operation.
1840 The %1s operand is constant, 'essentially signed' (%2s) and non-negative but will be implicitly converted to an unsigned type (%3s) in this arithmetic operation.
1841 The %1s operand is constant, 'essentially signed' (%2s) and non-negative but will be implicitly converted to an unsigned type (%3s) in this bitwise operation.
1842 The %1s operand is constant, 'essentially signed' (%2s) and non-negative but will be implicitly converted to an unsigned type (%3s) in this relational operation.
1843 The %1s operand is constant, 'essentially signed' (%2s) and non-negative but will be implicitly converted to an unsigned type (%3s) in this equality operation.
1844 The %1s operand is constant, 'essentially signed' (%2s) and non-negative but will be implicitly converted to an unsigned type (%3s) in this conditional operation.
1850 The %1s operand is 'essentially unsigned' (%2s) but will be implicitly converted to a signed type (%3s) in this arithmetic operation.
1851 The %1s operand is 'essentially unsigned' (%2s) but will be implicitly converted to a signed type (%3s) in this bitwise operation.
1852 The %1s operand is 'essentially unsigned' (%2s) but will be implicitly converted to a signed type (%3s) in this relational operation.
1853 The %1s operand is 'essentially unsigned' (%2s) but will be implicitly converted to a signed type (%3s) in this equality operation.
1854 The %1s operand is 'essentially unsigned' (%2s) but will be implicitly converted to a signed type (%3s) in this conditional operation.
1860 The operands of this arithmetic operator are of different 'essential signedness' but will generate a result of type 'signed int'.
1861 The operands of this bitwise operator are of different 'essential signedness' but will generate a result of type 'signed int'.
1862 The operands of this relational operator are of different 'essential signedness' but will both be promoted to 'signed int' for comparison.
1863 The operands of this equality operator are of different 'essential signedness' but will both be promoted to 'signed int' for comparison.
1864 The 2nd and 3rd operands of this conditional operator are of different 'essential signedness'. The result will be in the promoted type 'signed int'.
1880 The operands of this relational operator are expressions of different 'essential type' categories (%1s and %2s).
1881 The operands of this equality operator are expressions of different 'essential type' categories (%1s and %2s).
1882 The 2nd and 3rd operands of this conditional operator are expressions of different 'essential type' categories (%1s and %2s).
-
Rule-10.5AdvisoryThe value of an expression should not be cast to an inappropriate essential type
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
4301 An expression of 'essentially Boolean' type (%1s) is being cast to character type '%2s'.
4302 An expression of 'essentially Boolean' type (%1s) is being cast to enum type '%2s'.
4303 An expression of 'essentially Boolean' type (%1s) is being cast to signed type '%2s'.
4304 An expression of 'essentially Boolean' type (%1s) is being cast to unsigned type '%2s'.
4305 An expression of 'essentially Boolean' type (%1s) is being cast to floating type '%2s'.
4310 An expression of 'essentially character' type (%1s) is being cast to Boolean type, '%2s'.
4312 An expression of 'essentially character' type (%1s) is being cast to enum type, '%2s'.
4315 An expression of 'essentially character' type (%1s) is being cast to floating type, '%2s'.
4320 An expression of 'essentially enum' type (%1s) is being cast to Boolean type, '%2s'.
4322 An expression of 'essentially enum' type (%1s) is being cast to a different enum type, '%2s'.
4330 An expression of 'essentially signed' type (%1s) is being cast to Boolean type '%2s'.
4332 An expression of 'essentially signed' type (%1s) is being cast to enum type, '%2s'.
4340 An expression of 'essentially unsigned' type (%1s) is being cast to Boolean type '%2s'.
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
4350 An expression of 'essentially floating' type (%1s) is being cast to Boolean type '%2s'.
4351 An expression of 'essentially floating' type (%1s) is being cast to character type '%2s'.
4352 An expression of 'essentially floating' type (%1s) is being cast to enum type, '%2s'.
-
Rule-10.6RequiredThe value of a composite expression shall not be assigned to an object with wider essential type
- - - - - - - - - - - - - - - - - -
QacDescription
4490 A composite expression of 'essentially signed' type (%1s) is being converted to wider signed type, '%2s' on assignment.
4491 A composite expression of 'essentially unsigned' type (%1s) is being converted to wider unsigned type, '%2s' on assignment.
4492 A composite expression of 'essentially floating' type (%1s) is being converted to wider floating type, '%2s' on assignment.
4499 An expression which is the result of a ~ or << operation has been converted to a wider essential type on assignment.
-
Rule-10.7RequiredIf a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type
- - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
1890 A composite expression of 'essentially signed' type (%1s) is being implicitly converted to a wider signed type, '%2s'.
1891 A composite expression of 'essentially unsigned' type (%1s) is being implicitly converted to a wider unsigned type, '%2s'.
1892 A composite expression of 'essentially floating' type (%1s) is being implicitly converted to a wider floating type, '%2s'.
1893 The 2nd and 3rd operands of this conditional operator are both 'essentially signed' ('%1s' and '%2s') but one is a composite expression of a narrower type than the other.
1894 The 2nd and 3rd operands of this conditional operator are both 'essentially unsigned' ('%1s' and '%2s') but one is a composite expression of a narrower type than the other.
1895 The 2nd and 3rd operands of this conditional operator are both 'essentially floating' ('%1s' and '%2s') but one is a composite expression of a narrower type than the other.
-
Rule-10.8RequiredThe value of a composite expression shall not be cast to a different essential type category or a wider essential type
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
4389 A composite expression of 'essentially char' type (%1s) is being cast to a different type category, '%2s'.
4390 A composite expression of 'essentially signed' type (%1s) is being cast to a wider signed type, '%2s'.
4391 A composite expression of 'essentially unsigned' type (%1s) is being cast to a wider unsigned type, '%2s'.
4392 A composite expression of 'essentially floating' type (%1s) is being cast to a wider floating type, '%2s'.
4393 A composite expression of 'essentially signed' type (%1s) is being cast to a different type category, '%2s'.
4394 A composite expression of 'essentially unsigned' type (%1s) is being cast to a different type category, '%2s'.
4395 A composite expression of 'essentially floating' type (%1s) is being cast to a different type category, '%2s'.
4398 An expression which is the result of a ~ or << operation has been cast to a different essential type category.
4399 An expression which is the result of a ~ or << operation has been cast to a wider type.
-
Rule-11.1RequiredConversions shall not be performed between a pointer to a function and any other type
- - - - - - - - - - - - - - - - - -
QacDescription
0302 [u] Cast between a pointer to function and a floating type.
0305 [I] Cast between a pointer to function and an integral type.
0307 [u] Cast between a pointer to object and a pointer to function.
0313 Casting to different function pointer type.
-
Rule-11.2RequiredConversions shall not be performed between a pointer to an incomplete type and any other type
- - - - - - - - - - - - - - - - - -
QacDescription
0308 Non-portable cast involving pointer to an incomplete type.
0323 [u] Cast between a pointer to incomplete type and a floating type.
0324 [u] Cast between a pointer to incomplete type and an integral type.
0325 [u] Cast between a pointer to incomplete type and a pointer to function.
-
Rule-11.3RequiredA cast shall not be performed between a pointer to object type and a pointer to a different object type
- - - - - - - - - -
QacDescription
0310 Casting to different object pointer type.
3305 Pointer cast to stricter alignment.
-
Rule-11.4AdvisoryA conversion should not be performed between a pointer to object and an integer type
- - - - - - - - - - - - - - - - - - - - - -
QacDescription
0303 [I] Cast between a pointer to volatile object and an integral type.
0306 [I] Cast between a pointer to object and an integral type.
0360 An expression of pointer type is being converted to type _Bool on assignment.
0361 An expression of pointer type is being cast to type _Bool.
0362 An expression of essentially Boolean type is being cast to a pointer.
-
Rule-11.5AdvisoryA conversion should not be performed from pointer to void into pointer to object
- - - - - - - - - -
QacDescription
0316 [I] Cast from a pointer to void to a pointer to object type.
0317 [I] Implicit conversion from a pointer to void to a pointer to object type.
-
Rule-11.6RequiredA cast shall not be performed between pointer to void and an arithmetic type
- - - - - - - - - -
QacDescription
0326 [I] Cast between a pointer to void and an integral type.
0327 [I] Cast between a pointer to void and an floating type.
-
Rule-11.7RequiredA cast shall not be performed between pointer to object and a non-integer arithmetic type
- - - - - - - - - -
QacDescription
0301 [u] Cast between a pointer to object and a floating type.
0328 [u] Cast between a pointer to object and an essential type other than signed/unsigned.
-
Rule-11.8RequiredA cast shall not remove any const or volatile qualification from the type pointed to by a pointer
- - - - - - - - - -
QacDescription
0311 Dangerous pointer cast results in loss of const qualification.
0312 Dangerous pointer cast results in loss of volatile qualification.
-
Rule-11.9RequiredThe macro NULL shall be the only permitted form of integer null pointer constant
- - - - - - - - - -
QacDescription
3003 This character constant is being interpreted as a NULL pointer constant.
3004 This integral constant expression is being interpreted as a NULL pointer constant.
-
Rule-12.1AdvisoryThe precedence of operators within expressions should be made explicit
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
3389 Extra parentheses recommended to clarify the ordering of a % operator and another arithmetic operator (* / % + -).
3391 Extra parentheses recommended. A conditional operation is the operand of another conditional operator.
3392 Extra parentheses recommended. A shift, relational or equality operation is the operand of a second identical operator.
3394 Extra parentheses recommended. A shift, relational or equality operation is the operand of a different operator with the same precedence.
3395 Extra parentheses recommended. A * or / operation is the operand of a + or - operator.
3396 Extra parentheses recommended. A binary operation is the operand of a conditional operator.
3397 Extra parentheses recommended. A binary operation is the operand of a binary operator with different precedence.
-
Rule-12.2RequiredThe right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand
- - - - - - - - - - - - - - - - - -
QacDescription
0499 Right operand of shift operator is greater than or equal to the width of the essential type of the left operand.
2790 Constant: Right hand operand of shift operator is negative or too large.
2791 Definite: Right hand operand of shift operator is negative or too large.
2792 Apparent: Right hand operand of shift operator is negative or too large.
-
Rule-12.3AdvisoryThe comma operator should not be used
- - - - - - - - - -
QacDescription
3417 The comma operator has been used outside a 'for' statement.
3418 The comma operator has been used in a 'for' statement.
-
Rule-12.4AdvisoryEvaluation of constant expressions should not lead to unsigned integer wrap-around
- - - - - -
QacDescription
2910 Constant: Wraparound in unsigned arithmetic operation.
-
Rule-12.5MandatoryThe sizeof operator shall not have an operand which is a function parameter declared as 'array of type'
- - - - - -
QacDescription
1321 Operand of sizeof is a function parameter of array type.
-
Rule-13.1RequiredInitializer lists shall not contain persistent side-effects
- - - - - -
QacDescription
3421 Expression with possible side effects is used in an initializer list.
-
Rule-13.2RequiredThe value of an expression and its persistent side-effects shall be the same under all permitted evaluation orders
- - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0400 [U] '%s' is modified more than once between sequence points - evaluation order unspecified.
0401 [U] '%s' may be modified more than once between sequence points - evaluation order unspecified.
0402 [U] '%s' is modified and accessed between sequence points - evaluation order unspecified.
0403 [U] '%s' may be modified and accessed between sequence points - evaluation order unspecified.
0404 More than one read access to volatile objects between sequence points.
0405 More than one modification of volatile objects between sequence points.
-
Rule-13.3AdvisoryA full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator
- - - - - -
QacDescription
3440 Using the value resulting from a ++ or -- operation.
-
Rule-13.4AdvisoryThe result of an assignment operator should not be used
- - - - - - - - - -
QacDescription
3226 The result of an assignment is being used in an arithmetic operation or another assigning operation.
3326 The result of an assignment is being used in a logical operation.
-
Rule-13.5RequiredThe right hand operand of a logical && or || operator shall not contain persistent side effects
- - - - - -
QacDescription
3415 Right hand operand of '&&' or '||' is an expression with possible side effects.
-
Rule-13.6MandatoryThe operand of the sizeof operator shall not contain any expression which has potential side-effects
- - - - - - - - - -
QacDescription
0945 [C99] Operand of sizeof is an expression of variable length array type with side effects.
3307 The operand of 'sizeof' is an expression with implied side effects, but they will not be evaluated.
-
Rule-14.1RequiredA loop counter shall not have essentially floating type
- - - - - - - - - - - - - -
QacDescription
3339 Floating point variable used as 'while' loop control variable.
3340 Floating point variable used as 'for' loop control variable.
3342 Controlling expression of 'for' loop is a floating point comparison.
-
Rule-14.2RequiredA for loop shall be well-formed
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2461 Loop control variable in this 'for' statement, %s, has file scope.
2462 The variable initialized in the first expression of this 'for' statement is not the variable identified as the 'loop control variable' (%s).
2463 The variable incremented in the third expression of this 'for' statement is not the variable identified as the 'loop control variable' (%s).
2464 Loop control variable, %s, modified twice in for-loop header.
2467 Loop control variable in this 'for' statement, %s, is not modified inside loop.
2468 Loop control variable in this 'for' statement, %s, is not modified inside loop but has file scope.
2469 Loop control variable in this 'for' statement, %s, is modified in the body of the loop.
2471 Unable to identify a loop control variable.
2472 More than one possible loop control variable.
-
Rule-14.3RequiredControlling expressions shall not be invariant
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2741 This 'if' controlling expression is a constant expression and its value is 'true'.
2742 This 'if' controlling expression is a constant expression and its value is 'false'.
2990 The value of this loop controlling expression is always 'true'.
2991 The value of this 'if' controlling expression is always 'true'.
2992 The value of this 'if' controlling expression is always 'false'.
2993 The value of this 'do - while' loop controlling expression is always 'false'. The loop will only be executed once.
2994 The value of this 'while' or 'for' loop controlling expression is always 'false'. The loop will not be entered.
2997 The first operand of this conditional operator is always 'true'.
2998 The first operand of this conditional operator is always 'false'.
3493 The first operand of this conditional operator is always constant 'true'.
3494 The first operand of this conditional operator is always constant 'false'.
-
Rule-14.4RequiredThe controlling expression of an if-statement and the controlling expression of an iteration-statement shall have essentially Boolean type
- - - - - -
QacDescription
3344 Controlling expression is not an 'essentially Boolean' expression.
-
Rule-15.1AdvisoryThe goto statement should not be used
- - - - - -
QacDescription
2001 A 'goto' statement has been used.
-
Rule-15.2RequiredThe goto statement shall jump to a label declared later in the same function
- - - - - -
QacDescription
3310 This 'goto' statement involves a backward jump.
-
Rule-15.3RequiredAny label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement
- - - - - -
QacDescription
3327 This goto statement references a label that is declared in a separate block.
-
Rule-15.4AdvisoryThere should be no more than one break or goto statement used to terminate any iteration statement
- - - - - -
QacDescription
0771 More than one 'break' statement has been used to terminate this iteration statement.
-
Rule-15.5AdvisoryA function should have a single point of exit at the end
- - - - - -
QacDescription
2889 This function has more than one 'return' path.
-
Rule-15.6RequiredThe body of an iteration-statement or a selection-statement shall be a compound-statement
- - - - - - - - - - - - - - - - - - - - - -
QacDescription
2212 Body of control statement is not enclosed within braces.
2214 Body of control statement is on the same line and is not enclosed within braces.
2218 Body of switch statement is not enclosed within braces.
2219 Body of switch statement is on the same line and is not enclosed within braces.
3402 Braces are needed to clarify the structure of this 'if'-'if'-'else' statement.
-
Rule-15.7RequiredAll if ... else if constructs shall be terminated with an else statement
- - - - - - - - - -
QacDescription
2004 No concluding 'else' exists in this 'if'-'else'-'if' statement.
2013 This 'if .. else if ' construct 'else' statement is empty.
-
Rule-16.1RequiredAll switch statements shall be well-formed
- - - - - - - - - -
QacDescription
2008 Code statements precede the first label in this 'switch' construct.
3234 Declarations precede the first label in this 'switch' construct.
-
Rule-16.2RequiredA switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement
- - - - - -
QacDescription
2019 'Switch' label is located within a nested code block.
-
Rule-16.3RequiredAn unconditional break statement shall terminate every switch-clause
- - - - - - - - - -
QacDescription
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
2020 Final 'switch' clause does not end with an explicit 'jump' statement.
-
Rule-16.4RequiredEvery switch statement shall have a default label
- - - - - - - - - -
QacDescription
2002 No 'default' label found in this 'switch' statement.
2016 This 'switch' statement 'default' clause is empty.
-
Rule-16.5RequiredA default label shall appear as either the first or the last switch label of a switch statement
- - - - - -
QacDescription
2012 This 'default' label is neither the first nor the last label within the 'switch' block.
-
Rule-16.6RequiredEvery switch statement shall have at least two switch-clauses
- - - - - -
QacDescription
3315 This 'switch' statement is redundant.
-
Rule-16.7RequiredA switch-expression shall not have essentially Boolean type
- - - - - -
QacDescription
0735 Switch expression is of essentially Boolean type.
-
Rule-17.1RequiredThe features of shall not be used
- - - - - - - - - -
QacDescription
5130 Use of standard header file .
1337 Function defined with a variable number of parameters.
-
Rule-17.2RequiredFunctions shall not call themselves, either directly or indirectly
- - - - - - - - - -
QacDescription
3670 Recursive call to function containing this call.
1520 Functions are indirectly recursive.
-
Rule-17.3MandatoryA function shall not be declared implicitly
- - - - - -
QacDescription
3335 No function declaration. Implicit declaration inserted: 'extern int %s();'.
-
Rule-17.4MandatoryAll exit paths from a function with non-void return type shall have an explicit return statement with an expression
- - - - - - - - - - - - - - - - - - - - - -
QacDescription
0745 [U] 'return;' found in '%s()', which has been defined with a non-'void' return type.
2887 Function 'main' ends with an implicit 'return' statement.
2888 This function has been declared with a non-void 'return' type but ends with an implicit 'return ;' statement.
3113 [U] 'return' statement includes no expression but function '%s()' is implicitly of type 'int'.
3114 [U] Function '%s()' is implicitly of type 'int' but ends without returning a value.
-
Rule-17.5AdvisoryThe function argument corresponding to a parameter declared to have an array type shall have an appropriate number of elements
- - - - - - - - - - - - - - - - - -
QacDescription
2781 Definite: Function argument has fewer elements than the array dimension in the parameter declaration for non-inlined call.
2782 Apparent: Function argument has fewer elements than the array dimension in the parameter declaration for non-inlined call.
2783 Suspicious: Function argument has fewer elements than the array dimension in the parameter declaration for non-inlined call.
2784 Possible: Function argument has fewer elements than the array dimension in the parameter declaration for non-inlined call.
-
Rule-17.6MandatoryThe declaration of an array parameter shall not contain the static keyword between the [ ]
- - - - - -
QacDescription
1058 [C99] The keyword 'static' is used in the declaration of a function parameter of array type.
-
Rule-17.7RequiredThe value returned by a function having non-void return type shall be used
- - - - - -
QacDescription
3200 '%s' returns a value which is not being used.
-
Rule-17.8AdvisoryA function parameter should not be modified
- - - - - - - - - - - - - -
QacDescription
1338 The parameter '%s' is being modified.
1339 Evaluating the address of the parameter '%s'.
1340 Storing the address of the parameter '%s' in a constant pointer.
-
Rule-18.1RequiredA pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operand
- - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2840 Constant: Dereference of an invalid pointer value.
2841 Definite: Dereference of an invalid pointer value.
2842 Apparent: Dereference of an invalid pointer value.
2930 Constant: Computing an invalid pointer value.
2931 Definite: Computing an invalid pointer value.
2932 Apparent: Computing an invalid pointer value.
-
Rule-18.2RequiredSubtraction between pointers shall only be applied to pointers that address elements of the same array
- - - - - - - - - - - - - -
QacDescription
2668 Subtraction of a pointer to an array and a pointer to a non array.
2761 Definite: Subtracting pointers that address different objects.
2762 Apparent: Subtracting pointers that address different objects.
-
Rule-18.3RequiredThe relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same object
- - - - - - - - - - - - - -
QacDescription
2669 Comparison of a pointer to an array and a pointer to a non array.
2771 Definite: Comparing pointers that address different objects.
2772 Apparent: Comparing pointers that address different objects.
-
Rule-18.4AdvisoryThe +, -, += and -= operators should not be applied to an expression of pointer type
- - - - - -
QacDescription
0488 Performing pointer arithmetic.
-
Rule-18.5AdvisoryDeclarations should contain no more than two levels of pointer nesting
- - - - - - - - - - - - - - - - - -
QacDescription
3260 Typedef defined with more than 2 levels of indirection.
3261 Member of struct/union defined with more than 2 levels of indirection.
3262 Object defined or declared with more than 2 levels of indirection.
3263 Function defined or declared with a return type which has more than 2 levels of indirection.
-
Rule-18.6RequiredThe address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to exist
- - - - - - - - - - - - - - - - - -
QacDescription
3217 Address of automatic object exported to a pointer with linkage or wider scope.
3225 Address of automatic object exported using a function parameter.
3230 Address of automatic object assigned to local pointer with static storage duration.
4140 Address of automatic object exported in function return value.
-
Rule-18.7RequiredFlexible array members shall not be declared
- - - - - -
QacDescription
1060 [C99] A flexible array member has been declared.
-
Rule-18.8RequiredVariable-length array types shall not be used
- - - - - - - - - -
QacDescription
1051 [C99] A variable length array has been declared.
1052 [C99] A variable length array of unspecified size has been declared.
-
Rule-19.1MandatoryAn object shall not be assigned or copied to an overlapping object
- - - - - - - - - - - - - -
QacDescription
0681 [U] Assignment between two incompatible members of the same union.
2776 Definite: Copy between overlapping objects.
2777 Apparent: Copy between overlapping objects.
-
Rule-19.2AdvisoryThe union keyword should not be used
- - - - - - - - - -
QacDescription
0750 A union type specifier has been defined.
0759 An object of union type has been defined.
-
Rule-2.1RequiredA project shall not contain unreachable code
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0594 Negative 'case' label expression is incompatible with unsigned controlling expression in 'switch' statement.
1460 'Switch' label value, %s, not contained in enum type.
2744 This 'while' or 'for' loop controlling expression is a constant expression and its value is 'false'. The loop will not be entered.
2880 This code is unreachable.
2882 This 'switch' statement will bypass the initialization of local variables.
3219 Static function '%s()' is not used within this translation unit.
1503 The function '%1s' is defined but is not used within this project.
-
Rule-2.2RequiredThere shall be no dead code
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2980 The value of this function parameter is never used before being modified.
2981 This initialization is redundant. The value of this object is never used before being modified.
2982 This assignment is redundant. The value of this object is never used before being modified.
2983 This assignment is redundant. The value of this object is never subsequently used.
2985 This operation is redundant. The value of the result is always that of the left-hand operand.
2986 This operation is redundant. The value of the result is always that of the right-hand operand.
2987 This function call produces no side effects and is redundant.
2995 The result of this logical operation is always 'true'.
2996 The result of this logical operation is always 'false'.
3110 The left-hand operand of this ',' has no side effects.
3112 This statement has no side-effect - it can be removed.
3404 Statement contains a redundant * operator at top level. *p++ means *(p++) not (*p)++.
3422 Statement contains a redundant operator at top level.
3423 Statement contains a redundant cast at top level.
3424 Statement contains a redundant & or | at top level.
3425 One branch of this conditional operation is a redundant expression.
3426 Right hand side of comma expression has no side effect and its value is not used.
3427 Right hand side of logical operator has no side effect and its value is not used.
-
Rule-2.3AdvisoryA project should not contain unused type declarations
- - - - - -
QacDescription
3205 The identifier '%s' is not used and could be removed.
-
Rule-2.4AdvisoryA project should not contain unused tag declarations
- - - - - - - - - -
QacDescription
3213 The tag '%s' is not used and could be removed.
1755 The tag '%1s' is declared but not used within this project.
-
Rule-2.5AdvisoryA project should not contain unused macro declarations
- - - - - -
QacDescription
3214 The macro '%s' is not used and could be removed.
-
Rule-2.6AdvisoryA function should not contain unused label declarations
- - - - - -
QacDescription
3202 The label '%s:' is not used in this function and could be removed.
-
Rule-2.7AdvisoryThere should be no unused parameters in functions
- - - - - -
QacDescription
3206 The parameter '%s' is not used in this function.
-
Rule-20.1Advisory#include directives should only be preceded by preprocessor directives or comments
- - - - - -
QacDescription
5087 Use of #include directive after code fragment.
-
Rule-20.10AdvisoryThe # and ## preprocessor operators should not be used
- - - - - - - - - -
QacDescription
0341 Using the stringify operator '#'.
0342 Using the glue operator '##'.
-
Rule-20.11RequiredA macro parameter immediately following a # operator shall not immediately be followed by a ## operator
- - - - - -
QacDescription
0892 This macro parameter is preceded by '#' and followed by '##'.
-
Rule-20.12RequiredA macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators
- - - - - -
QacDescription
0893 Macro parameter '%s' is inconsistently subject to macro replacement.
-
Rule-20.13RequiredA line whose first token is # shall be a valid preprocessing directive
- - - - - -
QacDescription
3115 Unrecognized preprocessing directive has been ignored because of conditional inclusion directives.
-
Rule-20.14RequiredAll #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related
- - - - - - - - - -
QacDescription
3317 '#if...' not matched by '#endif' in included file. This is probably an error.
3318 '#else'/'#elif'/'#endif' in included file matched '#if...' in parent file. This is probably an error.
-
Rule-20.2RequiredThe ', " or \ characters and the /* or // character sequences shall not occur in a header file name
- - - - - - - - - - - - - -
QacDescription
0813 [U] Using any of the characters ' " or /* in '#include <%s>' gives undefined behaviour.
0814 [U] Using the characters ' or /* in '#include "%s"' gives undefined behaviour.
0831 [E] Use of '\\' in this '#include' line is a PC extension - this usage is non-portable.
-
Rule-20.3RequiredThe #include directive shall be followed by either a or "filename" sequence
- - - - - - - - - - - - - -
QacDescription
0817 [S] Closing quote or bracket '>' missing from include filename.
0821 [C] '#include' does not identify a header or source file that can be processed.
0840 [E] Extra tokens at end of #include directive.
-
Rule-20.4RequiredA macro shall not be defined with the same name as a keyword
- - - - - - - - - -
QacDescription
3439 Macro redefines a keyword.
3468 The name of this macro is a reserved identifier in C90 and a keyword in C99.
-
Rule-20.5Advisory#undef should not be used
- - - - - -
QacDescription
0841 Using '#undef'.
-
Rule-20.6RequiredTokens that look like a preprocessing directive shall not occur within a macro argument
- - - - - -
QacDescription
0853 [U] Macro arguments contain a sequence of tokens that has the form of a preprocessing directive.
-
Rule-20.7RequiredExpressions resulting from the expansion of macro parameters shall be enclosed in parentheses
- - - - - - - - - -
QacDescription
3430 Macro argument expression may require parentheses.
3432 Simple macro argument expression is not parenthesized.
-
Rule-20.8RequiredThe controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1
- - - - - -
QacDescription
0894 '#%s' directive controlling expression does not evaluate to zero or one.
-
Rule-20.9RequiredAll identifiers used in the controlling expression of #if or #elif preprocessing directives shall be #define'd before evaluation
- - - - - -
QacDescription
3332 The macro '%s' used in this '#if' or '#elif' expression is not defined.
-
Rule-21.1Required#define and #undef shall not be used on a reserved identifier or reserved macro name
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0603 [U] The macro identifier '%s' is reserved.
0836 [U] Definition of macro named 'defined'.
0848 [U] Attempting to #undef '%s', which is a predefined macro name.
0854 [U] Attempting to #define '%s', which is a predefined macro name.
4600 The macro '%1s' is also defined in '<%2s>'.
4601 The macro '%1s' is the name of an identifier in '<%2s>'.
4620 The macro '%1s' may also be defined as a macro in '<%2s>'.
4621 The macro '%1s' may also be defined as a typedef in '<%2s>'.
-
Rule-21.10RequiredThe Standard Library time and date functions shall not be used
- - - - - -
QacDescription
5127 Use of standard header file .
-
Rule-21.11RequiredThe standard header file shall not be used
- - - - - -
QacDescription
5131 Use of standard header file .
-
Rule-21.12AdvisoryThe exception handling features of should not be used
- - - - - -
QacDescription
5136 Use of exception handling identifier: feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag or fetestexcept.
-
Rule-21.13MandatoryAny value passed to a function in shall be representable as an unsigned char or be the value EOF
- - - - - - - - - -
QacDescription
2796 Definite: Calling a standard library character handling function with an invalid character value.
2797 Apparent: Calling a standard library character handling function with an invalid character value.
-
Rule-21.14RequiredThe Standard Library function memcmp shall not be used to compare null terminated strings
- - - - - - - - - -
QacDescription
2785 Constant: Null terminated string is being passed as argument to Standard Library function memcmp.
2786 Definite: Null terminated string is being passed as argument to Standard Library function memcmp.
-
Rule-21.15RequiredThe pointer arguments to the Standard Library functions memcpy, memmove and memcmp shall be pointers to qualified or unqualified versions of compatible types
- - - - - - - - - - - - - -
QacDescription
1487 Comparing the representations of objects of different types.
1495 Destination and source objects have incompatible types.
1496 Destination and source objects may have incompatible types.
-
Rule-21.16RequiredThe pointer arguments to the Standard Library function memcpy shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum type
- - - - - - - - - - - - - - - - - - - - - -
QacDescription
1488 Comparison of a struct object representation.
1489 Comparison of a union object representation.
1490 Comparison of a floating point object representation.
1491 Comparison of an object representation.
1497 Comparison of a string object representation.
-
Rule-21.17MandatoryUse of the string handling functions from shall not result in accesses beyond the bounds of the objects referenced by their pointer parameters
- - - - - - - - - -
QacDescription
2835 Constant: Non null terminated string used in a string function.
2836 Definite: Non null terminated string used in a string function.
-
Rule-21.18MandatoryThe size_t argument passed to any function in shall have an appropriate value
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2840 Constant: Dereference of an invalid pointer value.
2841 Definite: Dereference of an invalid pointer value.
2842 Apparent: Dereference of an invalid pointer value.
2865 Constant: Using 0 as size parameter of a function call.
2866 Definite: Using 0 as size parameter of a function call.
2867 Apparent: Using 0 as size parameter of a function call.
2868 Suspicious: Using 0 as size parameter of a function call.
2869 Possible: Using 0 as size parameter of a function call.
-
Rule-21.19MandatoryThe pointers returned by the Standard Library functions lovaleconv, getenv, setlocale or strerror shall only be used as if they have pointer to const-qualified type
- - - - - - - - - - - - - - - - - -
QacDescription
1492 The result of library function '%s' is used to modify the referenced object.
1493 The result of library function '%s' is used as a pointer to a modifiable object.
1494 The result of library function '%s' might be modified.
1498 The string referenced by type 'struct lconv' member '%s' is being modified.
-
Rule-21.2RequiredA reserved identifier or macro name shall not be declared
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
0602 [U] The identifier '%s' is reserved for use by the library.
4602 The identifier '%1s' is declared as a macro in '<%2s>'.
4603 The object/function '%1s'is being defined with the same name as an ordinary identifier defined in '<%2s>'.
4604 The object/function '%1s' is being declared with the same name as an ordinary identifier defined in '<%2s>'.
4605 The typedef '%1s' is also defined in '<%2s>'.
4606 The typedef '%1s' has the same name as another ordinary identifier in '<%2s>'.
4607 The enum constant '%1s' has the same name as another ordinary identifier in '<%2s>'.
4608 The tag '%1s' is also defined in '<%2s>'.
-
Rule-21.20MandatoryThe pointer returned by the Standard Library functions asctime, ctime, gmtime, localtime, localeconv, getenv, setlocale, or strerror shall not be used following a subsequent call to the same function
- - - - - - - - - -
QacDescription
2681 Definite: Using an invalidated value '%s' returned from a Standard Library function.
2682 Apparent: Using an invalidated value '%s' returned from a Standard Library function.
-
Rule-21.3RequiredThe memory allocation and deallocation functions of shall not be used
- - - - - -
QacDescription
5118 Use of memory allocation or deallocation function: calloc, malloc, realloc or free.
-
Rule-21.4RequiredThe standard header file shall not be used
- - - - - -
QacDescription
5132 Use of standard header file .
-
Rule-21.5RequiredThe standard header file shall not be used
- - - - - -
QacDescription
5123 Use of standard header file .
-
Rule-21.6RequiredThe Standard Library input/output functions shall not be used
- - - - - -
QacDescription
5124 The Standard Library input/output functions shall not be used
-
Rule-21.7RequiredThe atof, atoi, atol and atoll functions of shall not be used
- - - - - -
QacDescription
5125 Use of function: atof, atoi, atol or atoll.
-
Rule-21.8RequiredThe library functions abort, exit and system of shall not be used
- - - - - - - - - -
QacDescription
5126 Use of function: abort, exit or system.
5128 Use of function: getenv.
-
Rule-21.9RequiredThe library functions bsearch and qsort of shall not be used
- - - - - -
QacDescription
5135 Use of function: bsearch or qsort.
-
Rule-22.1RequiredAll resources obtained dynamically by means of Standard Library functions shall be explicitly released
- - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2701 Definite: Opened file is not closed.
2702 Apparent: Opened file is not closed.
2706 Definite: Allocated memory is not deallocated.
2707 Apparent: Allocated memory is not deallocated.
2736 Definite: Created resource is not destroyed.
2737 Apparent: Created resource is not destroyed.
-
Rule-22.10RequiredThe value of errno shall only be tested when the last function to be called was an errno-setting-function
- - - - - -
QacDescription
2503 Testing of 'errno' is not immediately preceded by a call to an 'errno' setting function.
-
Rule-22.2MandatoryA block of memory shall only be freed if it was allocated by means of a Standard Library function
- - - - - - - - - -
QacDescription
2721 Definite: Deallocation of non dynamic memory.
2722 Apparent: Deallocation of non dynamic memory.
-
Rule-22.3RequiredThe same file shall not be open for read and write access at the same time on different streams
- - - - - - - - - - - - - -
QacDescription
2691 Definite: The same file will be open with write access and another mode.
2692 Apparent: The same file will be open with write access and another mode.
2693 Suspicious: The same file will be open with write access and another mode.
-
Rule-22.4MandatoryThere shall be no attempt to write to a stream which has been opened as read-only
- - - - - - - - - - - - - -
QacDescription
2686 Definite: Writing to a file opened for reading.
2687 Apparent: Writing to a file opened for reading.
2688 Suspicious: Writing to a file opened for reading.
-
Rule-22.5MandatoryA pointer to a FILE object shall not be dereferenced
- - - - - - - - - -
QacDescription
1485 A pointer to a FILE object is dereferenced.
1486 A pointer to a FILE object is converted to a different type.
-
Rule-22.6MandatoryThe value of a pointer to a FILE shall not be used after the associated stream has been closed
- - - - - - - - - -
QacDescription
2696 Definite: Attempt to access a file which has been closed.
2697 Apparent: Attempt to access a file which has been closed.
-
Rule-22.7RequiredThe macro EOF shall on ly be compared with the unmodified return value from any Standard Library function capable of returning EOF
- - - - - - - - - -
QacDescription
2671 Definite: The value being compared with macro EOF does not originate from an EOF returning function.
2676 Definite: The value originating from an EOF returning function was modified before being compared with macro EOF.
-
Rule-22.8RequiredThe value of errno shall be set to zero prior to a call to an errno-setting-function
- - - - - -
QacDescription
2500 Call to '%s' is not immediately preceded by the zeroing of 'errno'.
-
Rule-22.9RequiredThe value of errno shall be tested against zero after calling an errno-setting-function
- - - - - -
QacDescription
2501 Call to '%s' is not immediately followed by the testing of 'errno'.
-
Rule-3.1RequiredThe character sequences /* and // shall not be used within a comment.
- - - - - -
QacDescription
3108 Nested comments are not recognized in the ISO standard.
-
Rule-3.2RequiredLine-splicing shall not be used in // comments.
- - - - - -
QacDescription
5134 C++ style comment uses line splicing.
-
Rule-4.1RequiredOctal and hexadecimal escape sequences shall be terminated
- - - - - - - - - -
QacDescription
3636 Octal escape sequence '%s' is not terminated.
3637 Hexadecimal escape sequence '%s' is not terminated.
-
Rule-4.2AdvisoryTrigraphs should not be used
- - - - - -
QacDescription
3601 Trigraphs (??x) are an ISO feature.
-
Rule-5.1RequiredExternal identifiers shall be distinct
- - - - - -
QacDescription
0777 [U] External identifier does not differ from other identifier(s) (e.g. '%s') within the specified number of significant characters.
-
Rule-5.2RequiredIdentifiers declared in the same scope and name space shall be distinct
- - - - - -
QacDescription
0779 [U] Identifier does not differ from other identifier(s) (e.g. '%s') within the specified number of significant characters.
-
Rule-5.3RequiredAn identifier declared in an inner scope shall not hide an identifier declared in an outer scope
- - - - - - - - - - - - - -
QacDescription
0795 Identifier matches other identifier(s) (e.g. '%s') in an outer scope within the specified number of significant characters.
2547 This declaration of tag '%s' hides a more global declaration.
3334 This declaration of '%s' hides a more global declaration.
-
Rule-5.4RequiredMacro identifiers shall be distinct
- - - - - - - - - -
QacDescription
0788 This identifier, '%s', is used as both a macro name and a function-like macro parameter name.
0791 [U] Macro identifier does not differ from other macro identifier(s) (e.g. '%s') within the specified number of significant characters.
-
Rule-5.5RequiredIdentifiers shall be distinct from macro names
- - - - - - - - - - - - - - - - - -
QacDescription
0784 Identifier '%s' is also used as a macro name.
0785 Identifier matches other macro name(s) (e.g. '%s') in first 31 characters.
0786 Identifier matches other macro name(s) (e.g. '%s') in first 63 characters.
0787 Identifier does not differ from other macro name(s) (e.g. '%s') within the specified number of significant characters.
-
Rule-5.6RequiredA typedef name shall be a unique identifier
- - - - - - - - - - - - - -
QacDescription
1506 The identifier '%1s' is declared as a typedef and is used elsewhere for a different kind of declaration.
1507 '%1s' is used as a typedef for different types.
1508 The typedef '%1s' is declared in more than one location.
-
Rule-5.7RequiredA tag name shall be a unique identifier
- - - - - - - - - -
QacDescription
2547 This declaration of tag '%s' hides a more global declaration.
1750 '%1s' has multiple definitions.
-
Rule-5.8RequiredIdentifiers that define objects or functions with external linkage shall be unique
- - - - - - - - - - - - - -
QacDescription
1525 Object/function with external linkage has same identifier as another object/function with internal linkage.
1526 Object with no linkage has same identifier as another object/function with external linkage.
1756 External identifier '%1s' shall be unique.
-
Rule-5.9AdvisoryIdentifiers that define objects or functions with internal linkage should be unique
- - - - - - - - - - - - - -
QacDescription
1525 Object/function with external linkage has same identifier as another object/function with internal linkage.
1527 Object/function with internal linkage has same identifier as another object/function with internal linkage.
1528 Object with no linkage has same identifier as another object/function with internal linkage.
-
Rule-6.1RequiredBit-fields shall only be declared with an appropriate type
- - - - - - - - - -
QacDescription
0634 [I] Bit-fields in this struct/union have not been declared explicitly as unsigned or signed.
0635 [E] Bit-fields in this struct/union have been declared with types other than int, signed int, unsigned int or _Bool.
-
Rule-6.2RequiredSingle-bit named bit fields shall not be of a signed type
- - - - - -
QacDescription
3660 Named bit-field consisting of a single bit declared with a signed type.
-
Rule-7.1RequiredOctal constants shall not be used
- - - - - - - - - -
QacDescription
0336 Macro defined as an octal constant.
0339 Octal constant used.
-
Rule-7.2RequiredA "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type
- - - - - -
QacDescription
1281 Integer literal constant is of an unsigned type but does not include a "U" suffix.
-
Rule-7.3RequiredThe lowercase character "l" shall not be used in a literal suffix
- - - - - -
QacDescription
1280 A lowercase letter L (l) has been used in an integer or floating suffix.
-
Rule-7.4RequiredA string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char"
- - - - - - - - - -
QacDescription
0752 String literal passed as argument to function whose parameter is not a 'pointer to const'.
0753 String literal assigned to pointer which is not a 'pointer to const'.
-
Rule-8.1RequiredTypes shall be explicitly specified
- - - - - - - - - - - - - -
QacDescription
2050 The 'int' type specifier has been omitted from a function declaration.
2051 The 'int' type specifier has been omitted from an object declaration.
1525 Object/function with external linkage has same identifier as another object/function with internal linkage.
-
Rule-8.10RequiredAn inline function shall be declared with the static storage class
- - - - - - - - - -
QacDescription
3240 inline function '%s' is being defined with external linkage.
3243 inline function '%s' is also an 'external definition'.
-
Rule-8.11AdvisoryWhen an array with external linkage is declared, its size should be explicitly specified
- - - - - -
QacDescription
3684 Array declared with unknown size.
-
Rule-8.12RequiredWithin an enumerator list, the value of an implicitly-specified enumeration constant shall be unique
- - - - - -
QacDescription
0724 The value of this implicitly-specified enumeration constant is not unique.
-
Rule-8.13AdvisoryA pointer should point to a const-qualified type whenever possible
- - - - - -
QacDescription
3673 The object addressed by the pointer parameter '%s' is not modified and so the pointer could be of type 'pointer to const'.
-
Rule-8.14RequiredThe restrict type qualifier shall not be used
- - - - - -
QacDescription
1057 [C99] The keyword 'restrict' has been used.
-
Rule-8.2RequiredFunction types shall be in prototype form with named parameters
- - - - - - - - - - - - - - - - - - - - - -
QacDescription
1335 Parameter identifiers missing in function prototype declaration.
1336 Parameter identifiers missing in declaration of a function type.
3001 Function has been declared with an empty parameter list.
3002 Defining '%s()' with an identifier list and separate parameter declarations is an obsolescent feature.
3007 "void" has been omitted when defining a function with no parameters.
-
Rule-8.3RequiredAll declarations of an object or function shall use the same names and type qualifiers
- - - - - - - - - - - - - -
QacDescription
0624 Function '%s' is declared using typedefs which are different to those in a previous declaration.
1330 The parameter identifiers in this function declaration differ from those in a previous declaration.
3675 Function parameter declared with type qualification which differs from previous declaration.
-
Rule-8.4RequiredA compatible declaration shall be visible when an object or function with external linkage is defined
- - - - - -
QacDescription
3408 '%s' has external linkage and is being defined without any previous declaration.
-
Rule-8.5RequiredAn external object or function shall be declared once in one and only one file
- - - - - - - - - - - - - -
QacDescription
3449 Multiple declarations of external object or function.
3451 The global identifier '%s' has been declared in more than one file.
1513 Identifier '%1s' with external linkage has separate non-defining declarations in more than one location.
-
Rule-8.6RequiredAn identifier with external linkage shall have exactly one external definition
- - - - - - - - - - - - - - - - - - - - - -
QacDescription
0630 [U] More than one definition of '%s' (with external linkage).
3406 Object/function '%s', with external linkage, has been defined in a header file.
1509 '%1s' has external linkage and has multiple definitions.
1752 The object '%1s' with external linkage is declared but not defined within this project.
1753 The function '%1s' with external linkage is declared but not defined within this project.
-
Rule-8.7AdvisoryFunctions and objects should not be defined with external linkage if they are referenced in only one translation unit
- - - - - - - - - - - - - - - - - -
QacDescription
1504 The object '%1s' is only referenced in the translation unit where it is defined.
1505 The function '%1s' is only referenced in the translation unit where it is defined.
1531 The object '%1s' is referenced in only one translation unit - but not the one in which it is defined.
1532 The function '%1s' is only referenced in one translation unit - but not the one in which it is defined.
-
Rule-8.8RequiredThe static storage class specifier shall be used in all declarations of objects and functions that have internal linkage
- - - - - -
QacDescription
3224 This identifier has previously been declared with internal linkage but is not declared here with the static storage class specifier.
-
Rule-8.9AdvisoryAn object should be defined at block scope if its identifier only appears in a single function
- - - - - - - - - - - - - -
QacDescription
3218 File scope static, '%s', is only accessed in one function.
1514 The object '%1s' is only referenced by function '%2s', in the translation unit where it is defined
1533 The object '%1s' is only referenced by function '%2s'.
-
Rule-9.1MandatoryThe value of an object with automatic storage duration shall not be read before it has been set
- - - - - - - - - - - - - - - - - - - - - -
QacDescription
2883 This 'goto' statement will always bypass the initialization of local variables.
2961 Definite: Using value of uninitialized automatic object '%s'.
2962 Apparent: Using value of uninitialized automatic object '%s'.
2971 Definite: Passing address of uninitialized object '%s' to a function parameter declared as a pointer to const.
2972 Apparent: Passing address of uninitialized object '%s' to a function parameter declared as a pointer to const.
-
Rule-9.2RequiredThe initializer for an aggregate or union shall be enclosed in braces
- - - - - - - - - -
QacDescription
0693 Struct initializer is missing the optional {.
0694 Array initializer is missing the optional {.
-
Rule-9.3RequiredArrays shall not be partially initialized
- - - - - -
QacDescription
0686 Array has fewer initializers than its declared size. Default initialization is applied to the remainder of the array elements.
-
Rule-9.4RequiredAn element of an object shall not be initialized more than once
- - - - - - - - - - - - - -
QacDescription
1397 Array element '%s' has already been initialized.
1398 Structure member '%s' has already been initialized.
1399 A union member has already been initialized.
-
Rule-9.5RequiredWhere designated initializers are used to initialize an array object the size of the array shall be specified explicitly
- - - - - -
QacDescription
3676 Designators are used to initialize an array of unspecified size.
-
-
-
- -This section targets to provide an overview of Guidelines Recategorization Plan. -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GuidelineDescriptionCategoryRevised Category
Dir-1.1Any implementation-defined behaviour on which the output of the program depends shall be documented and understoodRequiredRequired
Dir-2.1All source files shall compile without any compilation errorsRequiredDisapplied
Dir-3.1All code shall be traceable to documented requirementsRequiredDisapplied
Dir-4.1Run-time failures shall be minimizedRequiredRequired
Dir-4.10Precautions shall be taken in order to prevent the contents of a header file being included more then onceRequiredRequired
Dir-4.11The validity of values passed to library functions shall be checkedRequiredDisapplied
Dir-4.12Dynamic memory allocation shall not be usedRequiredDisapplied
Dir-4.13Functions which are designed to provide operations on a resource should be called in an appropriate sequenceAdvisoryDisapplied
Dir-4.14The validity of values received from external sources shall be checkedRequiredRequired
Dir-4.2All usage of assembly language should be documentedAdvisoryAdvisory
Dir-4.3Assembly language shall be encapsulated and isolatedRequiredRequired
Dir-4.4Sections of code should not be "commented out"AdvisoryDisapplied
Dir-4.5Identifiers in the same name space with overlapping visibility should be typographically unambiguousAdvisoryDisapplied
Dir-4.6typedefs that indicate size and signedness should be used in place of the basic numerical typesAdvisoryAdvisory
Dir-4.7If a function returns error information, then that error information shall be testedRequiredDisapplied
Dir-4.8If a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hiddenAdvisoryDisapplied
Dir-4.9A function should be used in preference to a function-like macro where they are interchangeableAdvisoryDisapplied
Rule-1.1The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limitsRequiredRequired
Rule-1.2Language extensions should not be usedAdvisoryAdvisory
Rule-1.3There shall be no occurrence of undefined or critical unspecified behaviourRequiredRequired
Rule-10.1Operands shall not be of an inappropriate essential type.RequiredRequired
Rule-10.2Expressions of essentially character type shall not be used inappropriately in addition and subtraction operationsRequiredRequired
Rule-10.3The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.RequiredRequired
Rule-10.4Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type categoryRequiredRequired
Rule-10.5The value of an expression should not be cast to an inappropriate essential typeAdvisoryAdvisory
Rule-10.6The value of a composite expression shall not be assigned to an object with wider essential typeRequiredRequired
Rule-10.7If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential typeRequiredRequired
Rule-10.8The value of a composite expression shall not be cast to a different essential type category or a wider essential typeRequiredRequired
Rule-11.1Conversions shall not be performed between a pointer to a function and any other typeRequiredRequired
Rule-11.2Conversions shall not be performed between a pointer to an incomplete type and any other typeRequiredRequired
Rule-11.3A cast shall not be performed between a pointer to object type and a pointer to a different object typeRequiredRequired
Rule-11.4A conversion should not be performed between a pointer to object and an integer typeAdvisoryAdvisory
Rule-11.5A conversion should not be performed from pointer to void into pointer to objectAdvisoryAdvisory
Rule-11.6A cast shall not be performed between pointer to void and an arithmetic typeRequiredRequired
Rule-11.7A cast shall not be performed between pointer to object and a non-integer arithmetic typeRequiredRequired
Rule-11.8A cast shall not remove any const or volatile qualification from the type pointed to by a pointerRequiredRequired
Rule-11.9The macro NULL shall be the only permitted form of integer null pointer constantRequiredDisapplied
Rule-12.1The precedence of operators within expressions should be made explicitAdvisoryAdvisory
Rule-12.2The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operandRequiredRequired
Rule-12.3The comma operator should not be usedAdvisoryAdvisory
Rule-12.4Evaluation of constant expressions should not lead to unsigned integer wrap-aroundAdvisoryAdvisory
Rule-12.5The sizeof operator shall not have an operand which is a function parameter declared as 'array of type'MandatoryMandatory
Rule-13.1Initializer lists shall not contain persistent side-effectsRequiredRequired
Rule-13.2The value of an expression and its persistent side-effects shall be the same under all permitted evaluation ordersRequiredRequired
Rule-13.3A full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operatorAdvisoryDisapplied
Rule-13.4The result of an assignment operator should not be usedAdvisoryAdvisory
Rule-13.5The right hand operand of a logical && or || operator shall not contain persistent side effectsRequiredRequired
Rule-13.6The operand of the sizeof operator shall not contain any expression which has potential side-effectsMandatoryMandatory
Rule-14.1A loop counter shall not have essentially floating typeRequiredRequired
Rule-14.2A for loop shall be well-formedRequiredRequired
Rule-14.3Controlling expressions shall not be invariantRequiredRequired
Rule-14.4The controlling expression of an if-statement and the controlling expression of an iteration-statement shall have essentially Boolean typeRequiredRequired
Rule-15.1The goto statement should not be usedAdvisoryAdvisory
Rule-15.2The goto statement shall jump to a label declared later in the same functionRequiredRequired
Rule-15.3Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statementRequiredRequired
Rule-15.4There should be no more than one break or goto statement used to terminate any iteration statementAdvisoryAdvisory
Rule-15.5A function should have a single point of exit at the endAdvisoryDisapplied
Rule-15.6The body of an iteration-statement or a selection-statement shall be a compound-statementRequiredRequired
Rule-15.7All if ... else if constructs shall be terminated with an else statementRequiredRequired
Rule-16.1All switch statements shall be well-formedRequiredRequired
Rule-16.2A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statementRequiredRequired
Rule-16.3An unconditional break statement shall terminate every switch-clauseRequiredRequired
Rule-16.4Every switch statement shall have a default labelRequiredRequired
Rule-16.5A default label shall appear as either the first or the last switch label of a switch statementRequiredRequired
Rule-16.6Every switch statement shall have at least two switch-clausesRequiredRequired
Rule-16.7A switch-expression shall not have essentially Boolean typeRequiredRequired
Rule-17.1The features of shall not be usedRequiredRequired
Rule-17.2Functions shall not call themselves, either directly or indirectlyRequiredRequired
Rule-17.3A function shall not be declared implicitlyMandatoryMandatory
Rule-17.4All exit paths from a function with non-void return type shall have an explicit return statement with an expressionMandatoryMandatory
Rule-17.5The function argument corresponding to a parameter declared to have an array type shall have an appropriate number of elementsAdvisoryAdvisory
Rule-17.6The declaration of an array parameter shall not contain the static keyword between the [ ]MandatoryMandatory
Rule-17.7The value returned by a function having non-void return type shall be usedRequiredDisapplied
Rule-17.8A function parameter should not be modifiedAdvisoryAdvisory
Rule-18.1A pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operandRequiredRequired
Rule-18.2Subtraction between pointers shall only be applied to pointers that address elements of the same arrayRequiredRequired
Rule-18.3The relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same objectRequiredRequired
Rule-18.4The +, -, += and -= operators should not be applied to an expression of pointer typeAdvisoryAdvisory
Rule-18.5Declarations should contain no more than two levels of pointer nestingAdvisoryAdvisory
Rule-18.6The address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to existRequiredRequired
Rule-18.7Flexible array members shall not be declaredRequiredRequired
Rule-18.8Variable-length array types shall not be usedRequiredRequired
Rule-19.1An object shall not be assigned or copied to an overlapping objectMandatoryMandatory
Rule-19.2The union keyword should not be usedAdvisoryAdvisory
Rule-2.1A project shall not contain unreachable codeRequiredRequired
Rule-2.2There shall be no dead codeRequiredRequired
Rule-2.3A project should not contain unused type declarationsAdvisoryDisapplied
Rule-2.4A project should not contain unused tag declarationsAdvisoryAdvisory
Rule-2.5A project should not contain unused macro declarationsAdvisoryDisapplied
Rule-2.6A function should not contain unused label declarationsAdvisoryAdvisory
Rule-2.7There should be no unused parameters in functionsAdvisoryAdvisory
Rule-20.1#include directives should only be preceded by preprocessor directives or commentsAdvisoryAdvisory
Rule-20.10The # and ## preprocessor operators should not be usedAdvisoryAdvisory
Rule-20.11A macro parameter immediately following a # operator shall not immediately be followed by a ## operatorRequiredRequired
Rule-20.12A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operatorsRequiredRequired
Rule-20.13A line whose first token is # shall be a valid preprocessing directiveRequiredRequired
Rule-20.14All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are relatedRequiredRequired
Rule-20.2The ', " or \ characters and the /* or // character sequences shall not occur in a header file nameRequiredRequired
Rule-20.3The #include directive shall be followed by either a or "filename" sequenceRequiredRequired
Rule-20.4A macro shall not be defined with the same name as a keywordRequiredRequired
Rule-20.5#undef should not be usedAdvisoryAdvisory
Rule-20.6Tokens that look like a preprocessing directive shall not occur within a macro argumentRequiredRequired
Rule-20.7Expressions resulting from the expansion of macro parameters shall be enclosed in parenthesesRequiredRequired
Rule-20.8The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1RequiredRequired
Rule-20.9All identifiers used in the controlling expression of #if or #elif preprocessing directives shall be #define'd before evaluationRequiredRequired
Rule-21.1#define and #undef shall not be used on a reserved identifier or reserved macro nameRequiredRequired
Rule-21.10The Standard Library time and date functions shall not be usedRequiredRequired
Rule-21.11The standard header file shall not be usedRequiredRequired
Rule-21.12The exception handling features of should not be usedAdvisoryAdvisory
Rule-21.13Any value passed to a function in shall be representable as an unsigned char or be the value EOFMandatoryMandatory
Rule-21.14The Standard Library function memcmp shall not be used to compare null terminated stringsRequiredRequired
Rule-21.15The pointer arguments to the Standard Library functions memcpy, memmove and memcmp shall be pointers to qualified or unqualified versions of compatible typesRequiredRequired
Rule-21.16The pointer arguments to the Standard Library function memcpy shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum typeRequiredRequired
Rule-21.17Use of the string handling functions from shall not result in accesses beyond the bounds of the objects referenced by their pointer parametersMandatoryMandatory
Rule-21.18The size_t argument passed to any function in shall have an appropriate valueMandatoryMandatory
Rule-21.19The pointers returned by the Standard Library functions lovaleconv, getenv, setlocale or strerror shall only be used as if they have pointer to const-qualified typeMandatoryMandatory
Rule-21.2A reserved identifier or macro name shall not be declaredRequiredRequired
Rule-21.20The pointer returned by the Standard Library functions asctime, ctime, gmtime, localtime, localeconv, getenv, setlocale, or strerror shall not be used following a subsequent call to the same functionMandatoryMandatory
Rule-21.3The memory allocation and deallocation functions of shall not be usedRequiredRequired
Rule-21.4The standard header file shall not be usedRequiredRequired
Rule-21.5The standard header file shall not be usedRequiredRequired
Rule-21.6The Standard Library input/output functions shall not be usedRequiredRequired
Rule-21.7The atof, atoi, atol and atoll functions of shall not be usedRequiredRequired
Rule-21.8The library functions abort, exit and system of shall not be usedRequiredRequired
Rule-21.9The library functions bsearch and qsort of shall not be usedRequiredRequired
Rule-22.1All resources obtained dynamically by means of Standard Library functions shall be explicitly releasedRequiredRequired
Rule-22.10The value of errno shall only be tested when the last function to be called was an errno-setting-functionRequiredRequired
Rule-22.2A block of memory shall only be freed if it was allocated by means of a Standard Library functionMandatoryMandatory
Rule-22.3The same file shall not be open for read and write access at the same time on different streamsRequiredRequired
Rule-22.4There shall be no attempt to write to a stream which has been opened as read-onlyMandatoryMandatory
Rule-22.5A pointer to a FILE object shall not be dereferencedMandatoryMandatory
Rule-22.6The value of a pointer to a FILE shall not be used after the associated stream has been closedMandatoryMandatory
Rule-22.7The macro EOF shall on ly be compared with the unmodified return value from any Standard Library function capable of returning EOFRequiredRequired
Rule-22.8The value of errno shall be set to zero prior to a call to an errno-setting-functionRequiredRequired
Rule-22.9The value of errno shall be tested against zero after calling an errno-setting-functionRequiredRequired
Rule-3.1The character sequences /* and // shall not be used within a comment.RequiredRequired
Rule-3.2Line-splicing shall not be used in // comments.RequiredRequired
Rule-4.1Octal and hexadecimal escape sequences shall be terminatedRequiredRequired
Rule-4.2Trigraphs should not be usedAdvisoryAdvisory
Rule-5.1External identifiers shall be distinctRequiredRequired
Rule-5.2Identifiers declared in the same scope and name space shall be distinctRequiredRequired
Rule-5.3An identifier declared in an inner scope shall not hide an identifier declared in an outer scopeRequiredRequired
Rule-5.4Macro identifiers shall be distinctRequiredRequired
Rule-5.5Identifiers shall be distinct from macro namesRequiredRequired
Rule-5.6A typedef name shall be a unique identifierRequiredRequired
Rule-5.7A tag name shall be a unique identifierRequiredRequired
Rule-5.8Identifiers that define objects or functions with external linkage shall be uniqueRequiredRequired
Rule-5.9Identifiers that define objects or functions with internal linkage should be uniqueAdvisoryAdvisory
Rule-6.1Bit-fields shall only be declared with an appropriate typeRequiredRequired
Rule-6.2Single-bit named bit fields shall not be of a signed typeRequiredRequired
Rule-7.1Octal constants shall not be usedRequiredRequired
Rule-7.2A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned typeRequiredRequired
Rule-7.3The lowercase character "l" shall not be used in a literal suffixRequiredRequired
Rule-7.4A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char"RequiredRequired
Rule-8.1Types shall be explicitly specifiedRequiredRequired
Rule-8.10An inline function shall be declared with the static storage classRequiredRequired
Rule-8.11When an array with external linkage is declared, its size should be explicitly specifiedAdvisoryAdvisory
Rule-8.12Within an enumerator list, the value of an implicitly-specified enumeration constant shall be uniqueRequiredRequired
Rule-8.13A pointer should point to a const-qualified type whenever possibleAdvisoryAdvisory
Rule-8.14The restrict type qualifier shall not be usedRequiredRequired
Rule-8.2Function types shall be in prototype form with named parametersRequiredRequired
Rule-8.3All declarations of an object or function shall use the same names and type qualifiersRequiredRequired
Rule-8.4A compatible declaration shall be visible when an object or function with external linkage is definedRequiredRequired
Rule-8.5An external object or function shall be declared once in one and only one fileRequiredRequired
Rule-8.6An identifier with external linkage shall have exactly one external definitionRequiredRequired
Rule-8.7Functions and objects should not be defined with external linkage if they are referenced in only one translation unitAdvisoryDisapplied
Rule-8.8The static storage class specifier shall be used in all declarations of objects and functions that have internal linkageRequiredRequired
Rule-8.9An object should be defined at block scope if its identifier only appears in a single functionAdvisoryAdvisory
Rule-9.1The value of an object with automatic storage duration shall not be read before it has been setMandatoryMandatory
Rule-9.2The initializer for an aggregate or union shall be enclosed in bracesRequiredRequired
Rule-9.3Arrays shall not be partially initializedRequiredRequired
Rule-9.4An element of an object shall not be initialized more than onceRequiredRequired
Rule-9.5Where designated initializers are used to initialize an array object the size of the array shall be specified explicitlyRequiredRequired
-
-
- -This section targets to provide an overview of Guidelines Compliance Summary. -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GuidelineCategoryDescriptionCompliance
Dir-1.1RequiredAny implementation-defined behaviour on which the output of the program depends shall be documented and understoodCompliant

with deviations:
-
- - - - - - - - - - - - - -
QacDescription
0292 [I] Source file '%s' has comments containing one of the characters '$', '@' or '`'.
0315 [I] Implicit conversion from a pointer to object type to a pointer to void.
0380 [L] Number of macro definitions exceeds 4095 - program does not conform strictly to ISO:C99.
-
Dir-2.1RequiredAll source files shall compile without any compilation errorsDisapplied
Dir-3.1RequiredAll code shall be traceable to documented requirementsDisapplied
Dir-4.1RequiredRun-time failures shall be minimizedCompliant
Dir-4.10RequiredPrecautions shall be taken in order to prevent the contents of a header file being included more then onceCompliant
Dir-4.11RequiredThe validity of values passed to library functions shall be checkedDisapplied
Dir-4.12RequiredDynamic memory allocation shall not be usedDisapplied
Dir-4.13AdvisoryFunctions which are designed to provide operations on a resource should be called in an appropriate sequenceDisapplied
Dir-4.14RequiredThe validity of values received from external sources shall be checkedCompliant
Dir-4.2AdvisoryAll usage of assembly language should be documentedCompliant
Dir-4.3RequiredAssembly language shall be encapsulated and isolatedCompliant
Dir-4.4AdvisorySections of code should not be "commented out"Disapplied
Dir-4.5AdvisoryIdentifiers in the same name space with overlapping visibility should be typographically unambiguousDisapplied
Dir-4.6Advisorytypedefs that indicate size and signedness should be used in place of the basic numerical typesCompliant
Dir-4.7RequiredIf a function returns error information, then that error information shall be testedDisapplied
Dir-4.8AdvisoryIf a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hiddenDisapplied
Dir-4.9AdvisoryA function should be used in preference to a function-like macro where they are interchangeableDisapplied
Rule-1.1RequiredThe program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limitsCompliant
Rule-1.2AdvisoryLanguage extensions should not be usedCompliant
Rule-1.3RequiredThere shall be no occurrence of undefined or critical unspecified behaviourCompliant
Rule-10.1RequiredOperands shall not be of an inappropriate essential type.Compliant
Rule-10.2RequiredExpressions of essentially character type shall not be used inappropriately in addition and subtraction operationsCompliant
Rule-10.3RequiredThe value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.Compliant
Rule-10.4RequiredBoth operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type categoryCompliant
Rule-10.5AdvisoryThe value of an expression should not be cast to an inappropriate essential typeCompliant
Rule-10.6RequiredThe value of a composite expression shall not be assigned to an object with wider essential typeCompliant
Rule-10.7RequiredIf a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential typeCompliant
Rule-10.8RequiredThe value of a composite expression shall not be cast to a different essential type category or a wider essential typeCompliant
Rule-11.1RequiredConversions shall not be performed between a pointer to a function and any other typeCompliant
Rule-11.2RequiredConversions shall not be performed between a pointer to an incomplete type and any other typeCompliant
Rule-11.3RequiredA cast shall not be performed between a pointer to object type and a pointer to a different object typeCompliant
Rule-11.4AdvisoryA conversion should not be performed between a pointer to object and an integer typeCompliant

with deviations:
-
- - - - - -
QacDescription
0306 [I] Cast between a pointer to object and an integral type.
-
Rule-11.5AdvisoryA conversion should not be performed from pointer to void into pointer to objectCompliant
Rule-11.6RequiredA cast shall not be performed between pointer to void and an arithmetic typeCompliant
Rule-11.7RequiredA cast shall not be performed between pointer to object and a non-integer arithmetic typeCompliant
Rule-11.8RequiredA cast shall not remove any const or volatile qualification from the type pointed to by a pointerCompliant
Rule-11.9RequiredThe macro NULL shall be the only permitted form of integer null pointer constantDisapplied
Rule-12.1AdvisoryThe precedence of operators within expressions should be made explicitCompliant
Rule-12.2RequiredThe right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operandCompliant
Rule-12.3AdvisoryThe comma operator should not be usedCompliant
Rule-12.4AdvisoryEvaluation of constant expressions should not lead to unsigned integer wrap-aroundCompliant
Rule-12.5MandatoryThe sizeof operator shall not have an operand which is a function parameter declared as 'array of type'Compliant
Rule-13.1RequiredInitializer lists shall not contain persistent side-effectsCompliant
Rule-13.2RequiredThe value of an expression and its persistent side-effects shall be the same under all permitted evaluation ordersCompliant
Rule-13.3AdvisoryA full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operatorDisapplied
Rule-13.4AdvisoryThe result of an assignment operator should not be usedCompliant
Rule-13.5RequiredThe right hand operand of a logical && or || operator shall not contain persistent side effectsCompliant
Rule-13.6MandatoryThe operand of the sizeof operator shall not contain any expression which has potential side-effectsCompliant
Rule-14.1RequiredA loop counter shall not have essentially floating typeCompliant
Rule-14.2RequiredA for loop shall be well-formedCompliant
Rule-14.3RequiredControlling expressions shall not be invariantCompliant

with deviations:
-
- - - - - - - - - - - - - - - - - - - - - -
QacDescription
2991 The value of this 'if' controlling expression is always 'true'.
2992 The value of this 'if' controlling expression is always 'false'.
2998 The first operand of this conditional operator is always 'false'.
3493 The first operand of this conditional operator is always constant 'true'.
3494 The first operand of this conditional operator is always constant 'false'.
-
Rule-14.4RequiredThe controlling expression of an if-statement and the controlling expression of an iteration-statement shall have essentially Boolean typeCompliant
Rule-15.1AdvisoryThe goto statement should not be usedCompliant
Rule-15.2RequiredThe goto statement shall jump to a label declared later in the same functionCompliant
Rule-15.3RequiredAny label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statementCompliant
Rule-15.4AdvisoryThere should be no more than one break or goto statement used to terminate any iteration statementCompliant
Rule-15.5AdvisoryA function should have a single point of exit at the endDisapplied
Rule-15.6RequiredThe body of an iteration-statement or a selection-statement shall be a compound-statementCompliant
Rule-15.7RequiredAll if ... else if constructs shall be terminated with an else statementCompliant
Rule-16.1RequiredAll switch statements shall be well-formedCompliant
Rule-16.2RequiredA switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statementCompliant
Rule-16.3RequiredAn unconditional break statement shall terminate every switch-clauseCompliant
Rule-16.4RequiredEvery switch statement shall have a default labelCompliant
Rule-16.5RequiredA default label shall appear as either the first or the last switch label of a switch statementCompliant
Rule-16.6RequiredEvery switch statement shall have at least two switch-clausesCompliant
Rule-16.7RequiredA switch-expression shall not have essentially Boolean typeCompliant
Rule-17.1RequiredThe features of shall not be usedCompliant
Rule-17.2RequiredFunctions shall not call themselves, either directly or indirectlyCompliant
Rule-17.3MandatoryA function shall not be declared implicitlyCompliant
Rule-17.4MandatoryAll exit paths from a function with non-void return type shall have an explicit return statement with an expressionCompliant
Rule-17.5AdvisoryThe function argument corresponding to a parameter declared to have an array type shall have an appropriate number of elementsCompliant
Rule-17.6MandatoryThe declaration of an array parameter shall not contain the static keyword between the [ ]Compliant
Rule-17.7RequiredThe value returned by a function having non-void return type shall be usedDisapplied
Rule-17.8AdvisoryA function parameter should not be modifiedCompliant
Rule-18.1RequiredA pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operandCompliant
Rule-18.2RequiredSubtraction between pointers shall only be applied to pointers that address elements of the same arrayCompliant
Rule-18.3RequiredThe relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same objectCompliant
Rule-18.4AdvisoryThe +, -, += and -= operators should not be applied to an expression of pointer typeCompliant
Rule-18.5AdvisoryDeclarations should contain no more than two levels of pointer nestingCompliant
Rule-18.6RequiredThe address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to existCompliant
Rule-18.7RequiredFlexible array members shall not be declaredCompliant
Rule-18.8RequiredVariable-length array types shall not be usedCompliant
Rule-19.1MandatoryAn object shall not be assigned or copied to an overlapping objectCompliant
Rule-19.2AdvisoryThe union keyword should not be usedCompliant
Rule-2.1RequiredA project shall not contain unreachable codeCompliant

with deviations:
-
- - - - - -
QacDescription
1503 The function '%1s' is defined but is not used within this project.
-
Rule-2.2RequiredThere shall be no dead codeCompliant

with deviations:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2982 This assignment is redundant. The value of this object is never used before being modified.
2983 This assignment is redundant. The value of this object is never subsequently used.
2985 This operation is redundant. The value of the result is always that of the left-hand operand.
2986 This operation is redundant. The value of the result is always that of the right-hand operand.
2995 The result of this logical operation is always 'true'.
2996 The result of this logical operation is always 'false'.
3112 This statement has no side-effect - it can be removed.
-
Rule-2.3AdvisoryA project should not contain unused type declarationsDisapplied
Rule-2.4AdvisoryA project should not contain unused tag declarationsCompliant
Rule-2.5AdvisoryA project should not contain unused macro declarationsDisapplied
Rule-2.6AdvisoryA function should not contain unused label declarationsCompliant
Rule-2.7AdvisoryThere should be no unused parameters in functionsCompliant
Rule-20.1Advisory#include directives should only be preceded by preprocessor directives or commentsCompliant
Rule-20.10AdvisoryThe # and ## preprocessor operators should not be usedCompliant
Rule-20.11RequiredA macro parameter immediately following a # operator shall not immediately be followed by a ## operatorCompliant
Rule-20.12RequiredA macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operatorsCompliant
Rule-20.13RequiredA line whose first token is # shall be a valid preprocessing directiveCompliant
Rule-20.14RequiredAll #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are relatedCompliant
Rule-20.2RequiredThe ', " or \ characters and the /* or // character sequences shall not occur in a header file nameCompliant
Rule-20.3RequiredThe #include directive shall be followed by either a or "filename" sequenceCompliant
Rule-20.4RequiredA macro shall not be defined with the same name as a keywordCompliant
Rule-20.5Advisory#undef should not be usedCompliant
Rule-20.6RequiredTokens that look like a preprocessing directive shall not occur within a macro argumentCompliant
Rule-20.7RequiredExpressions resulting from the expansion of macro parameters shall be enclosed in parenthesesCompliant
Rule-20.8RequiredThe controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1Compliant
Rule-20.9RequiredAll identifiers used in the controlling expression of #if or #elif preprocessing directives shall be #define'd before evaluationCompliant
Rule-21.1Required#define and #undef shall not be used on a reserved identifier or reserved macro nameCompliant
Rule-21.10RequiredThe Standard Library time and date functions shall not be usedCompliant
Rule-21.11RequiredThe standard header file shall not be usedCompliant
Rule-21.12AdvisoryThe exception handling features of should not be usedCompliant
Rule-21.13MandatoryAny value passed to a function in shall be representable as an unsigned char or be the value EOFCompliant
Rule-21.14RequiredThe Standard Library function memcmp shall not be used to compare null terminated stringsCompliant
Rule-21.15RequiredThe pointer arguments to the Standard Library functions memcpy, memmove and memcmp shall be pointers to qualified or unqualified versions of compatible typesCompliant
Rule-21.16RequiredThe pointer arguments to the Standard Library function memcpy shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum typeCompliant
Rule-21.17MandatoryUse of the string handling functions from shall not result in accesses beyond the bounds of the objects referenced by their pointer parametersCompliant
Rule-21.18MandatoryThe size_t argument passed to any function in shall have an appropriate valueCompliant
Rule-21.19MandatoryThe pointers returned by the Standard Library functions lovaleconv, getenv, setlocale or strerror shall only be used as if they have pointer to const-qualified typeCompliant
Rule-21.2RequiredA reserved identifier or macro name shall not be declaredCompliant
Rule-21.20MandatoryThe pointer returned by the Standard Library functions asctime, ctime, gmtime, localtime, localeconv, getenv, setlocale, or strerror shall not be used following a subsequent call to the same functionCompliant
Rule-21.3RequiredThe memory allocation and deallocation functions of shall not be usedCompliant
Rule-21.4RequiredThe standard header file shall not be usedCompliant
Rule-21.5RequiredThe standard header file shall not be usedCompliant
Rule-21.6RequiredThe Standard Library input/output functions shall not be usedCompliant
Rule-21.7RequiredThe atof, atoi, atol and atoll functions of shall not be usedCompliant
Rule-21.8RequiredThe library functions abort, exit and system of shall not be usedCompliant

with deviations:
-
- - - - - -
QacDescription
5128 Use of function: getenv.
-
Rule-21.9RequiredThe library functions bsearch and qsort of shall not be usedCompliant
Rule-22.1RequiredAll resources obtained dynamically by means of Standard Library functions shall be explicitly releasedCompliant
Rule-22.10RequiredThe value of errno shall only be tested when the last function to be called was an errno-setting-functionCompliant
Rule-22.2MandatoryA block of memory shall only be freed if it was allocated by means of a Standard Library functionCompliant
Rule-22.3RequiredThe same file shall not be open for read and write access at the same time on different streamsCompliant
Rule-22.4MandatoryThere shall be no attempt to write to a stream which has been opened as read-onlyCompliant
Rule-22.5MandatoryA pointer to a FILE object shall not be dereferencedCompliant
Rule-22.6MandatoryThe value of a pointer to a FILE shall not be used after the associated stream has been closedCompliant
Rule-22.7RequiredThe macro EOF shall on ly be compared with the unmodified return value from any Standard Library function capable of returning EOFCompliant
Rule-22.8RequiredThe value of errno shall be set to zero prior to a call to an errno-setting-functionCompliant
Rule-22.9RequiredThe value of errno shall be tested against zero after calling an errno-setting-functionCompliant
Rule-3.1RequiredThe character sequences /* and // shall not be used within a comment.Compliant
Rule-3.2RequiredLine-splicing shall not be used in // comments.Compliant
Rule-4.1RequiredOctal and hexadecimal escape sequences shall be terminatedCompliant
Rule-4.2AdvisoryTrigraphs should not be usedCompliant
Rule-5.1RequiredExternal identifiers shall be distinctCompliant
Rule-5.2RequiredIdentifiers declared in the same scope and name space shall be distinctCompliant
Rule-5.3RequiredAn identifier declared in an inner scope shall not hide an identifier declared in an outer scopeCompliant
Rule-5.4RequiredMacro identifiers shall be distinctCompliant
Rule-5.5RequiredIdentifiers shall be distinct from macro namesCompliant
Rule-5.6RequiredA typedef name shall be a unique identifierCompliant
Rule-5.7RequiredA tag name shall be a unique identifierCompliant
Rule-5.8RequiredIdentifiers that define objects or functions with external linkage shall be uniqueCompliant
Rule-5.9AdvisoryIdentifiers that define objects or functions with internal linkage should be uniqueCompliant
Rule-6.1RequiredBit-fields shall only be declared with an appropriate typeCompliant
Rule-6.2RequiredSingle-bit named bit fields shall not be of a signed typeCompliant
Rule-7.1RequiredOctal constants shall not be usedCompliant
Rule-7.2RequiredA "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned typeCompliant
Rule-7.3RequiredThe lowercase character "l" shall not be used in a literal suffixCompliant
Rule-7.4RequiredA string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char"Compliant
Rule-8.1RequiredTypes shall be explicitly specifiedCompliant
Rule-8.10RequiredAn inline function shall be declared with the static storage classCompliant
Rule-8.11AdvisoryWhen an array with external linkage is declared, its size should be explicitly specifiedCompliant
Rule-8.12RequiredWithin an enumerator list, the value of an implicitly-specified enumeration constant shall be uniqueCompliant
Rule-8.13AdvisoryA pointer should point to a const-qualified type whenever possibleCompliant
Rule-8.14RequiredThe restrict type qualifier shall not be usedCompliant
Rule-8.2RequiredFunction types shall be in prototype form with named parametersCompliant
Rule-8.3RequiredAll declarations of an object or function shall use the same names and type qualifiersCompliant
Rule-8.4RequiredA compatible declaration shall be visible when an object or function with external linkage is definedCompliant
Rule-8.5RequiredAn external object or function shall be declared once in one and only one fileCompliant
Rule-8.6RequiredAn identifier with external linkage shall have exactly one external definitionCompliant
Rule-8.7AdvisoryFunctions and objects should not be defined with external linkage if they are referenced in only one translation unitDisapplied
Rule-8.8RequiredThe static storage class specifier shall be used in all declarations of objects and functions that have internal linkageCompliant
Rule-8.9AdvisoryAn object should be defined at block scope if its identifier only appears in a single functionCompliant
Rule-9.1MandatoryThe value of an object with automatic storage duration shall not be read before it has been setCompliant
Rule-9.2RequiredThe initializer for an aggregate or union shall be enclosed in bracesCompliant
Rule-9.3RequiredArrays shall not be partially initializedCompliant
Rule-9.4RequiredAn element of an object shall not be initialized more than onceCompliant
Rule-9.5RequiredWhere designated initializers are used to initialize an array object the size of the array shall be specified explicitlyCompliant
-
-
- -This section targets to provide an overview of Deviation Permits.
-All the rules corresponding to the deviation permits are disabled inside PRQA and will not cause any violation or deviation in the Deviation records section below. -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GuidelineCategoryDescriptionRatioSub RulesCharacteristicsReason
Dir-1.1RequiredAny implementation-defined behaviour on which the output of the program depends shall be documented and understood3/34
- - - - - - - - - - - - - -
QacDescription
0292 [I] Source file '%s' has comments containing one of the characters '$', '@' or '`'.
0315 [I] Implicit conversion from a pointer to object type to a pointer to void.
0380 [L] Number of macro definitions exceeds 4095 - program does not conform strictly to ISO:C99.
-
Maintainability / Analysability0292: Invalid characters in comments: Doxygen comments are used.
-0315: Library string.h functions (memcpy, etc.) are used and trigger this implicit conversion.
-0380: Already CMSIS and STM32HAL trigger this.
-
Dir-4.9AdvisoryA function should be used in preference to a function-like macro where they are interchangeable1/1
- - - - - -
QacDescription
3453 A function could probably be used instead of this function-like macro.
-
Performance / Resource utilizationSuppressed due to code optimization and efficiency.
Rule-11.4AdvisoryA conversion should not be performed between a pointer to object and an integer type1/5
- - - - - -
QacDescription
0306 [I] Cast between a pointer to object and an integral type.
-
Maintainability / ModifiabilityUsing STM32 HAL already creates many violations. Also needed to do pointer arithmetic, calculating offsets inside a buffer.
Rule-11.9RequiredThe macro NULL shall be the only permitted form of integer null pointer constant1/2
- - - - - -
QacDescription
3004 This integral constant expression is being interpreted as a NULL pointer constant.
-
Keil stddef.h: "define NULL 0" causes violations. PRQA acknowledged this as a false positive.
Rule-13.3AdvisoryA full expression containing an increment (++) or decrement (--) operator should have no other potential side effects other than that caused by the increment or decrement operator1/1
- - - - - -
QacDescription
3440 Using the value resulting from a ++ or -- operation.
-
Maintainability / AnalysabilityRFAL uses the increment often for building buffers (array[i++] = 42; ...). Splitting this would decrease readability.
Rule-14.3RequiredControlling expressions shall not be invariant6/11
- - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
3440 Using the value resulting from a ++ or -- operation.
2991 The value of this 'if' controlling expression is always 'true'.
2992 The value of this 'if' controlling expression is always 'false'.
2998 The first operand of this conditional operator is always 'false'.
3493 The first operand of this conditional operator is always constant 'true'.
3494 The first operand of this conditional operator is always constant 'false'.
-
Portability / AdaptabilityRFAL is configurable through compile time switches. This causes some ifs to have invariant conditions at the used configuration. Suppress 14.3 for if statements.
Rule-15.5AdvisoryA function should have a single point of exit at the end1/1
- - - - - -
QacDescription
2889 This function has more than one 'return' path.
-
Maintainability / AnalysabilitySuppressed due to readability and simplicity of code logic.
Rule-17.7RequiredThe value returned by a function having non-void return type shall be used1/1
- - - - - -
QacDescription
3200 '%s' returns a value which is not being used.
-
Maintainability / AnalysabilityTreating the return codes of functions in all places without exception handling would makes the code hard to read and maintain. Error checking has been reduced to the places where needed.
Rule-2.1RequiredA project shall not contain unreachable code1/7
- - - - - -
QacDescription
1503 The function '%1s' is defined but is not used within this project.
-
Maintainability / ModularityRFAL provides many functions - some are not used within the checked project.
Rule-2.2RequiredThere shall be no dead code7/18
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
QacDescription
2982 This assignment is redundant. The value of this object is never used before being modified.
2983 This assignment is redundant. The value of this object is never subsequently used.
2985 This operation is redundant. The value of the result is always that of the left-hand operand.
2986 This operation is redundant. The value of the result is always that of the right-hand operand.
2996 The result of this logical operation is always 'false'.
2997 The first operand of this conditional operator is always 'true'.
3112 This statement has no side-effect - it can be removed.
-
Usability / User error protectionAll the violations were checked and fixing the violation would deteriorate robustness: Removing checks which are unnecessary at the given position, removing trailing iterator increment, etc.
Rule-2.3AdvisoryA project should not contain unused type declarations1/1
- - - - - -
QacDescription
3205 The identifier '%s' is not used and could be removed.
-
Compatibility / InteroperabilityRFAL defines enums for all identifiers available in NFC Forum - some are unused.
Rule-2.5AdvisoryA project should not contain unused macro declarations1/1
- - - - - -
QacDescription
3214 The macro '%s' is not used and could be removed.
-
Compatibility / InteroperabilityRFAL defines macros for all identifiers of NFC Forum and RF chip register map - some are not used.
Rule-8.7AdvisoryFunctions and objects should not be defined with external linkage if they are referenced in only one translation unit4/4
- - - - - - - - - - - - - - - - - -
QacDescription
1504 The object '%1s' is only referenced in the translation unit where it is defined.
1505 The function '%1s' is only referenced in the translation unit where it is defined.
1531 The object '%1s' is referenced in only one translation unit - but not the one in which it is defined.
1532 The function '%1s' is only referenced in one translation unit - but not the one in which it is defined.
-
Maintainability / ModularityRFAL defines functions which could be called by the user but are not called in the current project.
-
-
- -This section targets to provide an overview of Deviation Records. -
-
-
- -

File: .../ST25R3916_nucleo/rfal/source/rfal_isoDep.c

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LinesCountSuppressed QacsComment
1292-12921
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
2286-22861
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Layout of enum rfalBitRate and above clamping of maxTxBR guarantee no invalid enum values to be created
1332-13342
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Layout of enum rfalBitRate and above masks guarantee no invalid enum values to be created
2460-24601
- - - - -
0310 Casting to different object pointer type.
-
MISRA 11.3 - Intentional safe cast to avoiding large buffer duplication
2369-23691
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Layout of enum rfalBitRate and range of loop variable guarantee no invalid enum values to be created
2293-22931
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Layout of enum rfalBitRate and above clamping of maxTxBR guarantee no invalid enum values to be created
962-9621
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
2382-23821
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Layout of enum rfalBitRate and range of loop variable guarantee no invalid enum values to be created
744-7441
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
-

File: .../ST25R3916_nucleo/rfal/source/rfal_nfc.c

-
- - - - - - - - - -
LinesCountSuppressed QacsComment
172-1721
- - - - -
2880 This code is unreachable.
-
MISRA 2.1 - Unreachable code due to configuration option being set/unset
-

File: .../ST25R3916_nucleo/rfal/source/rfal_nfcDep.c

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LinesCountSuppressed QacsComment
1879-18812
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Layout of enum rfalBitRate and definition of rfalNfcDepBRS2DSI guarantee no invalid enum values to be created
1574-15741
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
1646-16461
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
887-8871
- - - - -
2880 This code is unreachable.
-
MISRA 2.1 - Guard code to prevent unexpected behavior
1254-12541
- - - - -
2880 This code is unreachable.
-
MISRA 2.1 - Guard code to prevent unexpected behavior
-

File: .../ST25R3916_nucleo/rfal/source/rfal_nfca.c

-
- - - - - - - - - -
LinesCountSuppressed QacsComment
495-4961
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Guaranteed that no invalid enum values are created: see guard_eq_RFAL_NFCA_T2T, ....
-

File: .../ST25R3916_nucleo/rfal/source/rfal_nfcb.c

-
- - - - - - - - - -
LinesCountSuppressed QacsComment
391-3921
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Layout of rfalNfcbSlots and above loop guarantee that no invalid enum values are created.
-

File: .../ST25R3916_nucleo/rfal/source/st25r3916/rfal_rfst25r3916.c

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LinesCountSuppressed QacsComment
2293-22931
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
1998-19981
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
1803-18031
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
3312-33121
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Guaranteed that no invalid enum values may be created. See also equalityGuard_RFAL_BR_106 ff.
226-2261
- - - - -
0750 A union type specifier has been defined.
-
MISRA 19.2 - Both members are of the same type, just different names. Thus no problem can occur.
1924-19241
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
1819-18191
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
3511-35111
- - - - -
4342 An expression of 'essentially unsigned' type (%1s) is being cast to enum type '%2s'.
-
MISRA 10.5 - Guaranteed that no invalid enum values may be created. See also equalityGuard_RFAL_BR_106 ff.
2206-22061
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
1789-17891
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
2131-21311
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
3056-30561
- - - - -
0759 An object of union type has been defined.
-
MISRA 19.2 - Allocating Union where members are of the same type, just different names. Thus no problem can occur.
3292-32921
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
2396-23961
- - - - -
2003 The preceding 'switch' clause is not empty and does not end with a 'jump' statement. Execution will fall through.
-
MISRA 16.3 - Intentional fall through
1474-14741
- - - - -
5209 Use of basic type '%s'.
-
MISRA 4.9 - External function (sqrt()) requires double
-
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileRequiredAdvisoryTotal
.../ST25R3916_nucleo/rfal/include/rfal_nfcv.h011
.../ST25R3916_nucleo/rfal/include/rfal_nfc.h033
.../ST25R3916_nucleo/rfal/include/rfal_nfcDep.h011
.../ST25R3916_nucleo/rfal/include/rfal_analogConfig.h101
.../ST25R3916_nucleo/rfal/include/rfal_isoDep.h011
.../ST25R3916_nucleo/rfal/source/rfal_isoDep.c4610
.../ST25R3916_nucleo/rfal/source/rfal_nfcb.c011
.../ST25R3916_nucleo/rfal/source/rfal_nfca.c011
.../ST25R3916_nucleo/rfal/source/rfal_nfc.c101
.../ST25R3916_nucleo/rfal/source/rfal_nfcDep.c426
.../ST25R3916_nucleo/rfal/source/st25r3916/rfal_analogConfigTbl.h112
.../ST25R3916_nucleo/rfal/source/st25r3916/rfal_rfst25r3916.c10515
Total212243
-
-
- - -There are no duplicated suppressions. - -

File: .../ST25R3916_nucleo/rfal/source/rfal_isoDep.c

-
- - - - - - - -
LineUnused QacsComment
1355
- - - - -
2880 This code is unreachable.
-
MISRA 2.1 - Unreachable code due to configuration option being set/unset above (RFAL_SUPPORT_BR_CE_A_xxx)
-
-
- -There are no continuous suppressions by file. -
-
- -Active Diagnostics refers to diagnostics that are not suppressed (note: no suppressed diagnostics have been taken into account for the calculation of information in this document). -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FilesActive DiagnosticsViolated RulesViolation CountCompliance Index
.../ST25R3916_nucleo/rfal/include/rfal_analogConfig.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_chip.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_isoDep.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_nfc.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_nfcDep.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_nfca.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_nfcb.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_nfcf.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_nfcv.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_rf.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_st25tb.h000100.00
.../ST25R3916_nucleo/rfal/include/rfal_t1t.h000100.00
.../ST25R3916_nucleo/rfal/source/rfal_analogConfig.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_crc.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_crc.h000100.00
.../ST25R3916_nucleo/rfal/source/rfal_iso15693_2.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_iso15693_2.h000100.00
.../ST25R3916_nucleo/rfal/source/rfal_isoDep.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_nfc.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_nfcDep.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_nfca.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_nfcb.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_nfcf.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_nfcv.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_st25tb.c000100.00
.../ST25R3916_nucleo/rfal/source/rfal_t1t.c000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/rfal_analogConfigTbl.h000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/rfal_features.h000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/rfal_rfst25r3916.c000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25R3916_irq.h000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25r3916.c000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25r3916.h000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25r3916_com.c000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25r3916_com.h000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25r3916_irq.c000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25r3916_irq.h000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25r3916_led.c000100.00
.../ST25R3916_nucleo/rfal/source/st25r3916/st25r3916_led.h000100.00
Total000100.00
- -

-Nota: Calculation of Compliance Index
-The Compliance Index is the percentage of groups which have no messages in them.
-For each file it is calculated as follows:
-
-( Ntotal - Nerror ) / Ntotal x 100
-
-Ntotal is the total number of enforced rules (i.e. the number of rules that have at least one message mapped to it directly).
-Nerror is the number of rules for which messages appear in that file.
-The File Compliance Index is the mean of all the individual file compliances.
- -
-
-
-
- - diff --git a/Software/Middlewares/ST/rfal/doc/_htmresc/st_logo.png b/Software/Middlewares/ST/rfal/doc/_htmresc/st_logo.png deleted file mode 100644 index 8b80057..0000000 Binary files a/Software/Middlewares/ST/rfal/doc/_htmresc/st_logo.png and /dev/null differ diff --git a/Software/Middlewares/ST/rfal/doc/rfal.chm b/Software/Middlewares/ST/rfal/doc/rfal.chm deleted file mode 100644 index a16f086..0000000 Binary files a/Software/Middlewares/ST/rfal/doc/rfal.chm and /dev/null differ diff --git a/Software/fab-reader2/.cargo/config.toml b/Software/fab-reader2/.cargo/config.toml new file mode 100644 index 0000000..a7859d5 --- /dev/null +++ b/Software/fab-reader2/.cargo/config.toml @@ -0,0 +1,34 @@ +[build] +# Uncomment the relevant target for your chip here (ESP32, ESP32-S2, ESP32-S3 or ESP32-C3) +#target = "xtensa-esp32-espidf" +target = "xtensa-esp32s2-espidf" +#target = "xtensa-esp32s3-espidf" +#target = "riscv32imc-esp-espidf" + +[target.xtensa-esp32-espidf] +linker = "ldproxy" + +[target.xtensa-esp32s2-espidf] +linker = "ldproxy" + +[target.xtensa-esp32s3-espidf] +linker = "ldproxy" + +[target.riscv32imc-esp-espidf] +linker = "ldproxy" + +# Future - necessary for the experimental "native build" of esp-idf-sys with ESP32C3 +# See also https://github.com/ivmarkov/embuild/issues/16 +rustflags = ["-C", "default-linker-libraries"] + +[unstable] + +build-std = ["std", "panic_abort"] +#build-std-features = ["panic_immediate_abort"] # Required for older ESP-IDF versions without a realpath implementation + +[env] +# Note: these variables are not used when using pio builder +# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF stable (v4.4) +ESP_IDF_VERSION = { value = "branch:release/v4.4" } +# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF master (mainline) +#ESP_IDF_VERSION = { value = "master" } diff --git a/Software/fab-reader2/.gitignore b/Software/fab-reader2/.gitignore new file mode 100644 index 0000000..2312b39 --- /dev/null +++ b/Software/fab-reader2/.gitignore @@ -0,0 +1,136 @@ +# Created by https://www.toptal.com/developers/gitignore/api/rust, +# Edit at https://www.toptal.com/developers/gitignore?templates=rust, + +.embuild + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +### CLion ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### CLion Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +# End of https://www.toptal.com/developers/gitignore/api/clion + diff --git a/Software/fab-reader2/.idea/.gitignore b/Software/fab-reader2/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Software/fab-reader2/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Software/fab-reader2/.idea/fab-reader2.iml b/Software/fab-reader2/.idea/fab-reader2.iml new file mode 100644 index 0000000..2ffb146 --- /dev/null +++ b/Software/fab-reader2/.idea/fab-reader2.iml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/fab-reader2/Cargo.toml b/Software/fab-reader2/Cargo.toml new file mode 100644 index 0000000..91a1a29 --- /dev/null +++ b/Software/fab-reader2/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "fab-reader2" +version = "0.1.0" +authors = ["Kai Jan Kriegel "] +edition = "2021" +resolver = "2" + +[profile.release] +opt-level = "s" + +[profile.dev] +debug = true # Symbols are nice and they don't increase the size on Flash +opt-level = "z" + +[features] +pio = ["esp-idf-sys/pio"] + +[dependencies] +esp-idf-sys = { version = "0.31.6", features = ["binstart"] } +esp-idf-hal = "0.38.1" +anyhow = "1.0.58" +embedded-hal = { version ="0.2.7", features = ["unproven"] } +embedded-svc = "0.22.1" +pervasive_epd = { path = "pervasive_epd" } +embedded-graphics = "0.7.1" +st25r3911b = { path = "st25r3911b" } + + +[build-dependencies] +embuild = "0.29" +anyhow = "1" diff --git a/Software/fab-reader2/build.rs b/Software/fab-reader2/build.rs new file mode 100644 index 0000000..4dd5e1f --- /dev/null +++ b/Software/fab-reader2/build.rs @@ -0,0 +1,5 @@ +// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641 +fn main() -> anyhow::Result<()> { + embuild::build::CfgArgs::output_propagated("ESP_IDF")?; + embuild::build::LinkArgs::output_propagated("ESP_IDF") +} diff --git a/Software/fab-reader2/pervasive_epd/Cargo.toml b/Software/fab-reader2/pervasive_epd/Cargo.toml new file mode 100644 index 0000000..e520d47 --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "pervasive_epd" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +embedded-hal = "0.2.7" +embedded-graphics-core = "0.3.3" diff --git a/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/command.rs b/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/command.rs new file mode 100644 index 0000000..552ed43 --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/command.rs @@ -0,0 +1,39 @@ +//! SPI Commands for the Pervasive Displays E2266CS0Cx E-Ink Displays +use crate::traits; + +/// E2266CS0Cx commands +/// +/// More information can be found in the [specification](https://www.waveshare.com/w/upload/d/d8/2.7inch-e-paper-b-specification.pdf) +#[allow(dead_code)] +#[derive(Copy, Clone)] +#[repr(u8)] +pub(crate) enum Command { + /// Set Resolution, LUT selection, BWR pixels, gate scan direction, source shift direction, booster switch, soft reset + PanelSetting = 0x00, + + PowerOff = 0x02, + PowerOn = 0x04, + + /// This command starts transmitting data and write them into SRAM. + DataTransmission1 = 0x10, + + /// After this command is issued, driver will refresh display (data/VCOM) according to SRAM data and LUT. + DisplayRefresh = 0x12, + + /// This command starts transmitting data and write them into SRAM. + DataTransmission2 = 0x13, + + /// Set the ambient Temperatue + /// + InputTemperature = 0xe5, + + /// Activate the set Temperature + ActiveTemperature = 0xe0, +} + +impl traits::Command for Command { + /// Returns the address of the command + fn address(self) -> u8 { + self as u8 + } +} \ No newline at end of file diff --git a/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/graphics.rs b/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/graphics.rs new file mode 100644 index 0000000..7c03e5b --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/graphics.rs @@ -0,0 +1,62 @@ +use crate::E2266CS0Cx::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH}; +use crate::graphics::{Display, DisplayRotation}; +use embedded_graphics_core::pixelcolor::BinaryColor; +use embedded_graphics_core::prelude::*; + +/// Display with Fullsize buffer for use with the 2in9 EPD +/// +/// Can also be manuall constructed: +/// `buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT]` +pub struct DisplayE2266CS0Cx { + buffer: [u8; WIDTH as usize * HEIGHT as usize / 8], + rotation: DisplayRotation, +} + +impl Default for DisplayE2266CS0Cx { + fn default() -> Self { + DisplayE2266CS0Cx { + buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); + WIDTH as usize * HEIGHT as usize / 8], + rotation: DisplayRotation::default(), + } + } +} + +impl DrawTarget for DisplayE2266CS0Cx { + type Color = BinaryColor; + type Error = core::convert::Infallible; + + fn draw_iter(&mut self, pixels: I) -> Result<(), Self::Error> + where + I: IntoIterator>, + { + for pixel in pixels { + self.draw_helper(WIDTH, HEIGHT, pixel)?; + } + Ok(()) + } +} + +impl OriginDimensions for DisplayE2266CS0Cx { + fn size(&self) -> Size { + Size::new(WIDTH, HEIGHT) + } +} + +impl Display for DisplayE2266CS0Cx { + fn buffer(&self) -> &[u8] { + &self.buffer + } + + fn get_mut_buffer(&mut self) -> &mut [u8] { + &mut self.buffer + } + + fn set_rotation(&mut self, rotation: DisplayRotation) { + self.rotation = rotation; + } + + fn rotation(&self) -> DisplayRotation { + self.rotation + } +} \ No newline at end of file diff --git a/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/mod.rs b/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/mod.rs new file mode 100644 index 0000000..2fb3573 --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/src/E2266CS0Cx/mod.rs @@ -0,0 +1,204 @@ +mod command; + +/// Width of E2266CS0Cx in pixels +pub const WIDTH: u32 = 152; +/// Height of E2266CS0Cx in pixels +pub const HEIGHT: u32 = 296; +/// Default Background Color (white) +pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White; +const IS_BUSY_LOW: bool = true; + +use std::io::repeat; +use embedded_hal::{ + blocking::{delay::*, spi::Write}, + digital::v2::*, +}; +use crate::buffer_len; + +use command::Command; + +use crate::color::Color; + +use crate::traits::*; + +use crate::interface::DisplayInterface; + +mod graphics; + +/// E2266CS0Cx driver +/// +pub struct E2266CS0Cx { + /// SPI + interface: DisplayInterface, + /// Color + background_color: Color, +} + +impl E2266CS0Cx + where + SPI: Write, + CS: OutputPin, + BUSY: InputPin, + DC: OutputPin, + RST: OutputPin, + DELAY: DelayMs, +{ + fn init(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { + self.interface.reset(delay, 10); + + // soft-reset + self.interface + .cmd_with_data(spi, Command::PanelSetting, &[0x0E])?; + + delay.delay_ms(5); + + let temperature = 25 as i8; // We assume this for now, we should probably measure this. + + // Set temperature + self.interface + .cmd_with_data(spi, Command::InputTemperature, &temperature.to_ne_bytes())?; + + // Activate temperature + self.interface + .cmd_with_data(spi, Command::ActiveTemperature, &[0x02])?; + + // Set PanelSettings + self.interface + .cmd_with_data(spi, Command::PanelSetting, &[0xCF, 0x8D])?; + Ok(()) + } +} + +impl PervasiveDisplay +for E2266CS0Cx + where + SPI: Write, + CS: OutputPin, + BUSY: InputPin, + DC: OutputPin, + RST: OutputPin, + DELAY: DelayMs, +{ + type DisplayColor = Color; + fn width(&self) -> u32 { + WIDTH + } + + fn height(&self) -> u32 { + HEIGHT + } + + fn new( + spi: &mut SPI, + cs: CS, + busy: BUSY, + dc: DC, + rst: RST, + delay: &mut DELAY, + ) -> Result { + let interface = DisplayInterface::new(cs, busy, dc, rst); + + let mut epd = E2266CS0Cx { + interface, + background_color: DEFAULT_BACKGROUND_COLOR, + }; + + epd.init(spi, delay)?; + + Ok(epd) + } + + fn power_off(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { + self.wait_until_idle(); + self.interface + .cmd(spi, Command::PowerOff)?; + Ok(()) + } + + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> { + self.wait_until_idle(); + self.init(spi, delay)?; + Ok(()) + } + + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + _delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.wait_until_idle(); + + // Transmit display data + self.interface + .cmd_with_data(spi, Command::DataTransmission1, buffer)?; + + // Transmit WIDTH * HEIGHT bytes of 0x00 + self.interface + .cmd(spi, Command::DataTransmission2)?; + self.interface + .data_x_times(spi, 0x00, buffer_len(WIDTH as usize, HEIGHT as usize) as u32)?; + Ok(()) + } + + fn display_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { + self.wait_until_idle(); + // Power on DC/DC converter + self.interface.cmd(spi, Command::PowerOn)?; + + self.wait_until_idle(); + + // Refresh the Display + self.interface.cmd(spi, Command::DisplayRefresh)?; + + self.wait_until_idle(); + Ok(()) + } + + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error> { + self.update_frame(spi, buffer, delay)?; + self.display_frame(spi, delay)?; + Ok(()) + } + + fn clear_frame(&mut self, spi: &mut SPI, _delay: &mut DELAY) -> Result<(), SPI::Error> { + self.wait_until_idle(); + + // clear the ram with the background color + let color = self.background_color.get_byte_value(); + + self.update_frame(spi, &[0x00; buffer_len(WIDTH as usize, HEIGHT as usize)], _delay)?; + Ok(()) + } + + fn set_background_color(&mut self, background_color: Color) { + self.background_color = background_color; + } + + fn background_color(&self) -> &Color { + &self.background_color + } + + fn is_busy(&self) -> bool { + self.interface.is_busy(IS_BUSY_LOW) + } +} + +impl E2266CS0Cx + where + SPI: Write, + CS: OutputPin, + BUSY: InputPin, + DC: OutputPin, + RST: OutputPin, + DELAY: DelayMs, +{ + fn wait_until_idle(&mut self) { + let _ = self.interface.wait_until_idle(IS_BUSY_LOW); + } +} \ No newline at end of file diff --git a/Software/fab-reader2/pervasive_epd/src/color.rs b/Software/fab-reader2/pervasive_epd/src/color.rs new file mode 100644 index 0000000..cf6cb26 --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/src/color.rs @@ -0,0 +1,79 @@ +//! B/W Color for EPDs + +use embedded_graphics_core::pixelcolor::BinaryColor; +use embedded_graphics_core::pixelcolor::PixelColor; + +pub use BinaryColor::Off as White; +pub use BinaryColor::On as Black; + +/// When trying to parse u8 to one of the color types +#[derive(Debug, PartialEq, Eq)] +pub struct OutOfColorRangeParseError(u8); +impl core::fmt::Display for OutOfColorRangeParseError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "Outside of possible Color Range: {}", self.0) + } +} + +impl OutOfColorRangeParseError { + fn _new(size: u8) -> OutOfColorRangeParseError { + OutOfColorRangeParseError(size) + } +} + +/// Only for the Black/White-Displays +#[derive(Clone, Copy, PartialEq, Debug)] +pub enum Color { + /// Black color + Black, + /// White color + White, +} + +//TODO: Rename get_bit_value to bit() and get_byte_value to byte() ? + +impl Color { + /// Get the color encoding of the color for one bit + pub fn get_bit_value(self) -> u8 { + match self { + Color::White => 0u8, + Color::Black => 1u8, + } + } + + /// Gets a full byte of black or white pixels + pub fn get_byte_value(self) -> u8 { + match self { + Color::White => 0x00, + Color::Black => 0xff, + } + } + + /// Parses from u8 to Color + fn from_u8(val: u8) -> Self { + match val { + 1 => Color::Black, + 0 => Color::White, + e => panic!( + "DisplayColor only parses 0 and 1 (Black and White) and not `{}`", + e + ), + } + } + + /// Returns the inverse of the given color. + /// + /// Black returns White and White returns Black + pub fn inverse(self) -> Color { + match self { + Color::White => Color::Black, + Color::Black => Color::White, + } + } +} + +impl From for Color { + fn from(value: u8) -> Self { + Color::from_u8(value) + } +} \ No newline at end of file diff --git a/Software/fab-reader2/pervasive_epd/src/graphics.rs b/Software/fab-reader2/pervasive_epd/src/graphics.rs new file mode 100644 index 0000000..269bad7 --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/src/graphics.rs @@ -0,0 +1,244 @@ +//! Graphics Support for EPDs + +use crate::buffer_len; +use crate::color::Color; +use embedded_graphics_core::pixelcolor::BinaryColor; +use embedded_graphics_core::prelude::*; + +/// Displayrotation +#[derive(Clone, Copy)] +pub enum DisplayRotation { + /// No rotation + Rotate0, + /// Rotate by 90 degrees clockwise + Rotate90, + /// Rotate by 180 degrees clockwise + Rotate180, + /// Rotate 270 degrees clockwise + Rotate270, +} + +impl Default for DisplayRotation { + fn default() -> Self { + DisplayRotation::Rotate0 + } +} + + +/// Necessary traits for all displays to implement for drawing +/// +/// Adds support for: +/// - Drawing (With the help of DrawTarget/Embedded Graphics) +/// - Rotations +/// - Clearing +pub trait Display: DrawTarget { + /// Clears the buffer of the display with the chosen background color + fn clear_buffer(&mut self, background_color: Color) { + for elem in self.get_mut_buffer().iter_mut() { + *elem = background_color.get_byte_value(); + } + } + + /// Returns the buffer + fn buffer(&self) -> &[u8]; + + /// Returns a mutable buffer + fn get_mut_buffer(&mut self) -> &mut [u8]; + + /// Sets the rotation of the display + fn set_rotation(&mut self, rotation: DisplayRotation); + + /// Get the current rotation of the display + fn rotation(&self) -> DisplayRotation; + + /// Helperfunction for the Embedded Graphics draw trait + /// + /// Becomes uneccesary when const_generics become stablised + fn draw_helper( + &mut self, + width: u32, + height: u32, + pixel: Pixel, + ) -> Result<(), Self::Error> { + let rotation = self.rotation(); + let buffer = self.get_mut_buffer(); + + let Pixel(point, color) = pixel; + if outside_display(point, width, height, rotation) { + return Ok(()); + } + + // Give us index inside the buffer and the bit-position in that u8 which needs to be changed + let (index, bit) = find_position(point.x as u32, point.y as u32, width, height, rotation); + let index = index as usize; + + // "Draw" the Pixel on that bit + match color { + // Black + BinaryColor::On => { + buffer[index] &= !bit; + } + // White + BinaryColor::Off => { + buffer[index] |= bit; + } + } + Ok(()) + } +} + + +/// A variable Display without a predefined buffer +/// +/// The buffer can be created as following: +/// buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value(); WIDTH / 8 * HEIGHT] +/// If WIDTH is not a multiple of 8, don't forget to round it up (ie. (WIDTH + 7) / 8) +/// +/// Example: +/// ```rust,no_run +/// # use epd_waveshare::epd2in9::DEFAULT_BACKGROUND_COLOR; +/// # use epd_waveshare::prelude::*; +/// # use epd_waveshare::graphics::VarDisplay; +/// # use epd_waveshare::color::Black; +/// # use embedded_graphics::prelude::*; +/// # use embedded_graphics::primitives::{Circle, Line, PrimitiveStyle}; +/// let width = 128; +/// let height = 296; +/// +/// let mut buffer = [DEFAULT_BACKGROUND_COLOR.get_byte_value(); 128 / 8 * 296]; +/// let mut display = VarDisplay::new(width, height, &mut buffer); +/// +/// display.set_rotation(DisplayRotation::Rotate90); +/// +/// let _ = Line::new(Point::new(0, 120), Point::new(0, 295)) +/// .into_styled(PrimitiveStyle::with_stroke(Black, 1)) +/// .draw(&mut display); +/// ``` +pub struct VarDisplay<'a> { + width: u32, + height: u32, + rotation: DisplayRotation, + buffer: &'a mut [u8], //buffer: Box//[u8; 15000] +} + +impl<'a> VarDisplay<'a> { + /// Create a new variable sized display. + /// + /// Buffersize must be at least (width + 7) / 8 * height bytes. + pub fn new(width: u32, height: u32, buffer: &'a mut [u8]) -> VarDisplay<'a> { + let len = buffer.len() as u32; + assert!(buffer_len(width as usize, height as usize) >= len as usize); + VarDisplay { + width, + height, + rotation: DisplayRotation::default(), + buffer, + } + } +} + +impl<'a> DrawTarget for VarDisplay<'a> { + type Color = BinaryColor; + type Error = core::convert::Infallible; + + fn draw_iter(&mut self, pixels: I) -> Result<(), Self::Error> + where + I: IntoIterator>, + { + for pixel in pixels { + self.draw_helper(self.width, self.height, pixel)?; + } + Ok(()) + } +} + +impl<'a> OriginDimensions for VarDisplay<'a> { + fn size(&self) -> Size { + Size::new(self.width, self.height) + } +} + +impl<'a> Display for VarDisplay<'a> { + fn buffer(&self) -> &[u8] { + self.buffer + } + + fn get_mut_buffer(&mut self) -> &mut [u8] { + self.buffer + } + + fn set_rotation(&mut self, rotation: DisplayRotation) { + self.rotation = rotation; + } + + fn rotation(&self) -> DisplayRotation { + self.rotation + } +} + +// Checks if a pos is outside the defined display +fn outside_display(p: Point, width: u32, height: u32, rotation: DisplayRotation) -> bool { + if p.x < 0 || p.y < 0 { + return true; + } + let (x, y) = (p.x as u32, p.y as u32); + match rotation { + DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => { + if x >= width || y >= height { + return true; + } + } + DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => { + if y >= width || x >= height { + return true; + } + } + } + false +} + +fn find_rotation(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> (u32, u32) { + let nx; + let ny; + match rotation { + DisplayRotation::Rotate0 => { + nx = x; + ny = y; + } + DisplayRotation::Rotate90 => { + nx = width - 1 - y; + ny = x; + } + DisplayRotation::Rotate180 => { + nx = width - 1 - x; + ny = height - 1 - y; + } + DisplayRotation::Rotate270 => { + nx = y; + ny = height - 1 - x; + } + } + (nx, ny) +} + +#[rustfmt::skip] +//returns index position in the u8-slice and the bit-position inside that u8 +fn find_oct_position(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> (u32, bool) { + let (nx, ny) = find_rotation(x, y, width, height, rotation); + ( + /* what byte address is this? */ + nx / 2 + (width / 2) * ny, + /* is this the lower nibble (within byte)? */ + (nx & 0x1) == 0, + ) +} + +#[rustfmt::skip] +//returns index position in the u8-slice and the bit-position inside that u8 +fn find_position(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> (u32, u8) { + let (nx, ny) = find_rotation(x, y, width, height, rotation); + ( + nx / 8 + ((width + 7) / 8) * ny, + 0x80 >> (nx % 8), + ) +} \ No newline at end of file diff --git a/Software/fab-reader2/pervasive_epd/src/interface.rs b/Software/fab-reader2/pervasive_epd/src/interface.rs new file mode 100644 index 0000000..55e5351 --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/src/interface.rs @@ -0,0 +1,183 @@ +use crate::traits::Command; +use core::marker::PhantomData; +use embedded_hal::{ + blocking::{delay::*, spi::Write}, + digital::v2::*, +}; + +/// The Connection Interface of all (?) Waveshare EPD-Devices +/// +pub(crate) struct DisplayInterface { + /// SPI + _spi: PhantomData, + /// DELAY + _delay: PhantomData, + /// CS for SPI + cs: CS, + /// Low for busy, Wait until display is ready! + busy: BUSY, + /// Data/Command Control Pin (High for data, Low for command) + dc: DC, + /// Pin for Resetting + rst: RST, +} + +impl DisplayInterface + where + SPI: Write, + CS: OutputPin, + BUSY: InputPin, + DC: OutputPin, + RST: OutputPin, + DELAY: DelayMs, +{ + pub fn new(cs: CS, busy: BUSY, dc: DC, rst: RST) -> Self { + DisplayInterface { + _spi: PhantomData::default(), + _delay: PhantomData::default(), + cs, + busy, + dc, + rst, + } + } + + /// Basic function for sending [Commands](Command). + /// + /// Enables direct interaction with the device with the help of [data()](DisplayInterface::data()) + pub(crate) fn cmd(&mut self, spi: &mut SPI, command: T) -> Result<(), SPI::Error> { + // low for commands + let _ = self.dc.set_low(); + + // Transfer the command over spi + self.write(spi, &[command.address()]) + } + + /// Basic function for sending an array of u8-values of data over spi + /// + /// Enables direct interaction with the device with the help of [command()](Epd4in2::command()) + pub(crate) fn data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> { + // high for data + let _ = self.dc.set_high(); + + for val in data.iter().copied() { + // Transfer data one u8 at a time over spi + self.write(spi, &[val])?; + } + + Ok(()) + } + + /// Basic function for sending [Commands](Command) and the data belonging to it. + /// + /// TODO: directly use ::write? cs wouldn't needed to be changed twice than + pub(crate) fn cmd_with_data( + &mut self, + spi: &mut SPI, + command: T, + data: &[u8], + ) -> Result<(), SPI::Error> { + self.cmd(spi, command)?; + self.data(spi, data) + } + + /// Basic function for sending the same byte of data (one u8) multiple times over spi + /// + /// Enables direct interaction with the device with the help of [command()](ConnectionInterface::command()) + pub(crate) fn data_x_times( + &mut self, + spi: &mut SPI, + val: u8, + repetitions: u32, + ) -> Result<(), SPI::Error> { + // high for data + let _ = self.dc.set_high(); + // Transfer data (u8) over spi + for _ in 0..repetitions { + self.write(spi, &[val])?; + } + Ok(()) + } + + // spi write helper/abstraction function + fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> { + // activate spi with cs low + let _ = self.cs.set_low(); + + // transfer spi data + // Be careful!! Linux has a default limit of 4096 bytes per spi transfer + // see https://raspberrypi.stackexchange.com/questions/65595/spi-transfer-fails-with-buffer-size-greater-than-4096 + if cfg!(target_os = "linux") { + for data_chunk in data.chunks(4096) { + spi.write(data_chunk)?; + } + } else { + spi.write(data)?; + } + + // deactivate spi with cs high + let _ = self.cs.set_high(); + + Ok(()) + } + + /// Waits until device isn't busy anymore (busy == HIGH) + /// + /// This is normally handled by the more complicated commands themselves, + /// but in the case you send data and commands directly you might need to check + /// if the device is still busy + /// + /// is_busy_low + /// + /// - TRUE for epd4in2, epd2in13, epd2in7, epd5in83, epd7in5 + /// - FALSE for epd2in9, epd1in54 (for all Display Type A ones?) + /// + /// Most likely there was a mistake with the 2in9 busy connection + /// //TODO: use the #cfg feature to make this compile the right way for the certain types + pub(crate) fn wait_until_idle(&mut self, is_busy_low: bool) { + // //tested: worked without the delay for all tested devices + // //self.delay_ms(1); + while self.is_busy(is_busy_low) { + // //tested: REMOVAL of DELAY: it's only waiting for the signal anyway and should continue work asap + // //old: shorten the time? it was 100 in the beginning + // //self.delay_ms(5); + } + } + + /// Checks if device is still busy + /// + /// This is normally handled by the more complicated commands themselves, + /// but in the case you send data and commands directly you might need to check + /// if the device is still busy + /// + /// is_busy_low + /// + /// - TRUE for epd4in2, epd2in13, epd2in7, epd5in83, epd7in5 + /// - FALSE for epd2in9, epd1in54 (for all Display Type A ones?) + /// + /// Most likely there was a mistake with the 2in9 busy connection + /// //TODO: use the #cfg feature to make this compile the right way for the certain types + pub(crate) fn is_busy(&self, is_busy_low: bool) -> bool { + (is_busy_low && self.busy.is_low().unwrap_or(false)) + || (!is_busy_low && self.busy.is_high().unwrap_or(false)) + } + + /// Resets the device. + /// + /// Often used to awake the module from deep sleep. See [Epd4in2::sleep()](Epd4in2::sleep()) + /// + /// The timing of keeping the reset pin low seems to be important and different per device. + /// Most displays seem to require keeping it low for 10ms, but the 7in5_v2 only seems to reset + /// properly with 2ms + pub(crate) fn reset(&mut self, delay: &mut DELAY, duration: u8) { + let _ = self.rst.set_high(); + delay.delay_ms(5); + + let _ = self.rst.set_low(); + delay.delay_ms(duration); + let _ = self.rst.set_high(); + //TODO: the upstream libraries always sleep for 200ms here + // 10ms works fine with just for the 7in5_v2 but this needs to be validated for other devices + delay.delay_ms(5); + } +} diff --git a/Software/fab-reader2/pervasive_epd/src/lib.rs b/Software/fab-reader2/pervasive_epd/src/lib.rs new file mode 100644 index 0000000..a7f7879 --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/src/lib.rs @@ -0,0 +1,38 @@ +mod interface; +mod traits; +pub mod color; +pub mod graphics; + +pub mod E2266CS0Cx; + +pub mod prelude { + pub use crate::color::Color; + pub use crate::traits::PervasiveDisplay; + + pub use crate::SPI_MODE; + + pub use crate::graphics::{Display, DisplayRotation}; +} + + +/// Computes the needed buffer length. Takes care of rounding up in case width +/// is not divisible by 8. +/// +/// unused +/// bits width +/// <----><------------------------> +/// \[XXXXX210\]\[76543210\]...\[76543210\] ^ +/// \[XXXXX210\]\[76543210\]...\[76543210\] | height +/// \[XXXXX210\]\[76543210\]...\[76543210\] v +pub const fn buffer_len(width: usize, height: usize) -> usize { + (width + 7) / 8 * height +} + +use embedded_hal::spi::{Mode, Phase, Polarity}; + +/// SPI mode - +/// For more infos see [Requirements: SPI](index.html#spi) +pub const SPI_MODE: Mode = Mode { + phase: Phase::CaptureOnFirstTransition, + polarity: Polarity::IdleLow, +}; \ No newline at end of file diff --git a/Software/fab-reader2/pervasive_epd/src/traits.rs b/Software/fab-reader2/pervasive_epd/src/traits.rs new file mode 100644 index 0000000..b509681 --- /dev/null +++ b/Software/fab-reader2/pervasive_epd/src/traits.rs @@ -0,0 +1,92 @@ +use embedded_hal::{ + blocking::{delay::*, spi::Write}, + digital::v2::*, +}; + +/// All commands need to have this trait which gives the address of the command +/// which needs to be send via SPI with activated CommandsPin (Data/Command Pin in CommandMode) +pub(crate) trait Command { + fn address(self) -> u8; +} + +pub trait PervasiveDisplay + where + SPI: Write, + CS: OutputPin, + BUSY: InputPin, + DC: OutputPin, + RST: OutputPin, + DELAY: DelayMs, +{ + /// The Color Type used by the Display + type DisplayColor; + /// Creates a new driver from a SPI peripheral, CS Pin, Busy InputPin, DC + /// + /// This already initialises the device. + fn new( + spi: &mut SPI, + cs: CS, + busy: BUSY, + dc: DC, + rst: RST, + delay: &mut DELAY, + ) -> Result + where + Self: Sized; + + /// Let the device enter deep-sleep mode to save power. + /// + /// The deep sleep mode returns to standby with a hardware reset. + fn power_off(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; + + /// Wakes the device up from sleep + /// + /// Also reintialises the device if necessary. + fn wake_up(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; + + /// Sets the backgroundcolor for various commands like [clear_frame](WaveshareDisplay::clear_frame) + fn set_background_color(&mut self, color: Self::DisplayColor); + + /// Get current background color + fn background_color(&self) -> &Self::DisplayColor; + + /// Get the width of the display + fn width(&self) -> u32; + + /// Get the height of the display + fn height(&self) -> u32; + + /// Transmit a full frame to the SRAM of the EPD + fn update_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error>; + + + /// Displays the frame data from SRAM + /// + /// This function waits until the device isn`t busy anymore + fn display_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; + + /// Provide a combined update&display and save some time (skipping a busy check in between) + fn update_and_display_frame( + &mut self, + spi: &mut SPI, + buffer: &[u8], + delay: &mut DELAY, + ) -> Result<(), SPI::Error>; + + /// Clears the frame buffer on the EPD with the declared background color + /// + /// The background color can be changed with [`WaveshareDisplay::set_background_color`] + fn clear_frame(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>; + + /// Checks if the display is busy transmitting data + /// + /// This is normally handled by the more complicated commands themselves, + /// but in the case you send data and commands directly you might need to check + /// if the device is still busy + fn is_busy(&self) -> bool; +} \ No newline at end of file diff --git a/Software/fab-reader2/rust-toolchain.toml b/Software/fab-reader2/rust-toolchain.toml new file mode 100644 index 0000000..2e27578 --- /dev/null +++ b/Software/fab-reader2/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "esp" \ No newline at end of file diff --git a/Software/fab-reader2/sdkconfig.defaults b/Software/fab-reader2/sdkconfig.defaults new file mode 100644 index 0000000..3ca3b5d --- /dev/null +++ b/Software/fab-reader2/sdkconfig.defaults @@ -0,0 +1,10 @@ +# Rust often needs a bit of an extra main task stack size compared to C (the default is 3K) +CONFIG_ESP_MAIN_TASK_STACK_SIZE=7000 + +# Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default). +# This allows to use 1 ms granuality for thread sleeps (10 ms by default). +#CONFIG_FREERTOS_HZ=1000 + +# Workaround for https://github.com/espressif/esp-idf/issues/7631 +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n +#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n diff --git a/Software/fab-reader2/src/main.rs b/Software/fab-reader2/src/main.rs new file mode 100644 index 0000000..d6c2834 --- /dev/null +++ b/Software/fab-reader2/src/main.rs @@ -0,0 +1,132 @@ +use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use std::thread; +use std::time::Duration; + +use embedded_hal::blocking::i2c::Operation; +use embedded_hal::digital::v2::OutputPin; + +use esp_idf_sys::esp_sleep_pd_domain_t_ESP_PD_DOMAIN_VDDSDIO; +use esp_idf_sys::EspError; + +use esp_idf_hal::{delay, gpio}; +use esp_idf_hal::gpio::{GpioPin, Unknown}; +use esp_idf_hal::prelude::*; +use esp_idf_hal::spi; + +use anyhow::Result; +use embedded_graphics::{Drawable, mono_font}; +use embedded_graphics::mono_font::iso_8859_15::FONT_10X20; +use embedded_graphics::mono_font::MonoTextStyle; +use embedded_graphics::pixelcolor::BinaryColor; +use embedded_graphics::prelude::Point; +use embedded_graphics::text::Text; + +use pervasive_epd::E2266CS0Cx; +use pervasive_epd::graphics::{Display, VarDisplay}; +use pervasive_epd::prelude::*; + +fn main() -> Result<()> { + // Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once, + // or else some patches to the runtime implemented by esp-idf-sys might not link properly. + esp_idf_sys::link_patches(); + + let peripherals = Peripherals::take().unwrap(); + let pins = peripherals.pins; + + // EPD related pins + let epd_cs = pins.gpio38.into_output()?; + let epd_busy = pins.gpio41.into_input()?; + let epd_dc = pins.gpio39.into_output()?; + let epd_rst = pins.gpio40.into_output()?; + let mut epd_bs = pins.gpio42.into_output()?; + epd_bs.set_low()?; + + // generic outputs + let mut buzzer = pins.gpio16.into_output()?; + + // ui switches inputs + let mut sw1 = pins.gpio12.into_input(); + let mut sw2 = pins.gpio13.into_input(); + let mut sw3 = pins.gpio14.into_input(); + let mut sw4 = pins.gpio21.into_input(); + + // SPI Bus + let sclk = pins.gpio5.into_output()?; + let sdo = pins.gpio6.into_output()?; + let sdi = pins.gpio7.into_input()?; + let spi = peripherals.spi3; + let config = ::default().baudrate(10.MHz().into()); + let mut spi_master = spi::Master::::new( + spi, + spi::Pins { + sclk, + sdo, + sdi: Some(sdi), + cs: Option::>::None, + }, + config, + )?; + + // Setup EPD + let mut epd = E2266CS0Cx::E2266CS0Cx::new( + &mut spi_master, + epd_cs, + epd_busy, + epd_dc, + epd_rst, + &mut delay::Ets, + ) + .unwrap(); + // Use display graphics from embedded-graphics + let mut buffer = vec![ + E2266CS0Cx::DEFAULT_BACKGROUND_COLOR.get_byte_value(); + E2266CS0Cx::WIDTH as usize / 8 * E2266CS0Cx::HEIGHT as usize + ]; + let mut display = VarDisplay::new(E2266CS0Cx::WIDTH, E2266CS0Cx::HEIGHT, &mut buffer); + + let style = MonoTextStyle::new(&FONT_10X20, BinaryColor::On); + + // Create a text at position (20, 30) and draw it using the previously defined style + Text::new("FabReader2!", Point::new(20, 30), style).draw(&mut display)?; + + // Display updated frame + epd.update_and_display_frame(&mut spi_master, &display.buffer(), &mut delay::Ets)?; + + println!("Hello, world!"); + + loop { + buzzer.set_high()?; + // we are using thread::sleep here to make sure the watchdog isn't triggered + thread::sleep(Duration::from_secs(1)); + + buzzer.set_low()?; + thread::sleep(Duration::from_secs(1)); + } + + #[allow(unreachable_code)] + Ok(()) +} + +fn deep_sleep(wakeup_pin_num: u8) -> Result<()> { + let bitmask: u64 = 0b01 << wakeup_pin_num - 1; + + // Configure RTC for wakeup if the given pin goes high + EspError::convert(unsafe { + esp_idf_sys::esp_sleep_enable_ext1_wakeup( + bitmask, + esp_idf_sys::esp_sleep_ext1_wakeup_mode_t_ESP_EXT1_WAKEUP_ANY_HIGH, + ) + })?; + // Power down flash + EspError::convert(unsafe { + esp_idf_sys::esp_sleep_pd_config( + esp_sleep_pd_domain_t_ESP_PD_DOMAIN_VDDSDIO, + esp_idf_sys::esp_sleep_pd_option_t_ESP_PD_OPTION_OFF, + ) + })?; + //Go into deep sleep + unsafe { + esp_idf_sys::esp_deep_sleep_start(); + } + Ok(()) +} diff --git a/Software/fab-reader2/st25r3911b/Cargo.toml b/Software/fab-reader2/st25r3911b/Cargo.toml new file mode 100644 index 0000000..3246593 --- /dev/null +++ b/Software/fab-reader2/st25r3911b/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "st25r3911b" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +embedded-hal = { version ="0.2.7", features = ["unproven"] } +embedded-svc = "0.22.1" +esp-idf-svc = { version = "0.42.1", features = ["alloc" ] } +esp-idf-hal = "0.38.1" +anyhow = "1.0.65" + +[build-dependencies] +anyhow = "1.0.65" +embuild = "0.30.3" \ No newline at end of file diff --git a/Software/fab-reader2/st25r3911b/FIXME b/Software/fab-reader2/st25r3911b/FIXME new file mode 100644 index 0000000..e69de29 diff --git a/Software/fab-reader2/st25r3911b/src/analogConfig.rs b/Software/fab-reader2/st25r3911b/src/analogConfig.rs new file mode 100644 index 0000000..5c50c6f --- /dev/null +++ b/Software/fab-reader2/st25r3911b/src/analogConfig.rs @@ -0,0 +1,145 @@ +use crate::constants::*; +use crate::Register; + +/* Helpers */ +// Register Helpers for 1 to 13 sets +const fn MODE_ENTRY_1_REG(mode: u32, r0: u32, m0: u8, v0: u8) -> [u8; 7] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 1, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0] +} + +const fn MODE_ENTRY_2_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8) -> [u8; 9] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 2, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1] +} + +const fn MODE_ENTRY_3_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8) -> [u8; 11] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 3, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2] +} + +const fn MODE_ENTRY_4_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8) -> [u8; 13] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 4, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3] +} + +const fn MODE_ENTRY_5_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8) -> [u8; 15] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 5, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4] +} + +const fn MODE_ENTRY_6_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8, r5: u32, m5: u8, v5: u8) -> [u8; 17] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 6, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4, (r5 << 8) as u8, (r5 & 0xFF) as u8, m5, v5] +} + +const fn MODE_ENTRY_7_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8, r5: u32, m5: u8, v5: u8, r6: u32, m6: u8, v6: u8) -> [u8; 19] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 7, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4, (r5 << 8) as u8, (r5 & 0xFF) as u8, m5, v5, (r6 << 8) as u8, (r6 & 0xFF) as u8, m6, v6] +} + +const fn MODE_ENTRY_8_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8, r5: u32, m5: u8, v5: u8, r6: u32, m6: u8, v6: u8, r7: u32, m7: u8, v7: u8) -> [u8; 21] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 8, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4, (r5 << 8) as u8, (r5 & 0xFF) as u8, m5, v5, (r6 << 8) as u8, (r6 & 0xFF) as u8, m6, v6, (r7 << 8) as u8, (r7 & 0xFF) as u8, m7, v7] +} + +const fn MODE_ENTRY_9_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8, r5: u32, m5: u8, v5: u8, r6: u32, m6: u8, v6: u8, r7: u32, m7: u8, v7: u8, r8: u32, m8: u8, v8: u8) -> [u8; 23] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 9, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4, (r5 << 8) as u8, (r5 & 0xFF) as u8, m5, v5, (r6 << 8) as u8, (r6 & 0xFF) as u8, m6, v6, (r7 << 8) as u8, (r7 & 0xFF) as u8, m7, v7, (r8 << 8) as u8, (r8 & 0xFF) as u8, m8, v8] +} + +const fn MODE_ENTRY_10_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8, r5: u32, m5: u8, v5: u8, r6: u32, m6: u8, v6: u8, r7: u32, m7: u8, v7: u8, r8: u32, m8: u8, v8: u8, r9: u32, m9: u8, v9: u8) -> [u8; 25] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 10, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4, (r5 << 8) as u8, (r5 & 0xFF) as u8, m5, v5, (r6 << 8) as u8, (r6 & 0xFF) as u8, m6, v6, (r7 << 8) as u8, (r7 & 0xFF) as u8, m7, v7, (r8 << 8) as u8, (r8 & 0xFF) as u8, m8, v8, (r9 << 8) as u8, (r9 & 0xFF) as u8, m9, v9] +} + +const fn MODE_ENTRY_11_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8, r5: u32, m5: u8, v5: u8, r6: u32, m6: u8, v6: u8, r7: u32, m7: u8, v7: u8, r8: u32, m8: u8, v8: u8, r9: u32, m9: u8, v9: u8, r10: u32, m10: u8, v10: u8) -> [u8; 27] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 11, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4, (r5 << 8) as u8, (r5 & 0xFF) as u8, m5, v5, (r6 << 8) as u8, (r6 & 0xFF) as u8, m6, v6, (r7 << 8) as u8, (r7 & 0xFF) as u8, m7, v7, (r8 << 8) as u8, (r8 & 0xFF) as u8, m8, v8, (r9 << 8) as u8, (r9 & 0xFF) as u8, m9, v9, (r10 << 8) as u8, (r10 & 0xFF) as u8, m10, v10] +} + +const fn MODE_ENTRY_12_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8, r5: u32, m5: u8, v5: u8, r6: u32, m6: u8, v6: u8, r7: u32, m7: u8, v7: u8, r8: u32, m8: u8, v8: u8, r9: u32, m9: u8, v9: u8, r10: u32, m10: u8, v10: u8, r11: u32, m11: u8, v11: u8) -> [u8; 29] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 12, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4, (r5 << 8) as u8, (r5 & 0xFF) as u8, m5, v5, (r6 << 8) as u8, (r6 & 0xFF) as u8, m6, v6, (r7 << 8) as u8, (r7 & 0xFF) as u8, m7, v7, (r8 << 8) as u8, (r8 & 0xFF) as u8, m8, v8, (r9 << 8) as u8, (r9 & 0xFF) as u8, m9, v9, (r10 << 8) as u8, (r10 & 0xFF) as u8, m10, v10, (r11 << 8) as u8, (r11 & 0xFF) as u8, m11, v11] +} + +const fn MODE_ENTRY_13_REG(mode: u32, r0: u32, m0: u8, v0: u8, r1: u32, m1: u8, v1: u8, r2: u32, m2: u8, v2: u8, r3: u32, m3: u8, v3: u8, r4: u32, m4: u8, v4: u8, r5: u32, m5: u8, v5: u8, r6: u32, m6: u8, v6: u8, r7: u32, m7: u8, v7: u8, r8: u32, m8: u8, v8: u8, r9: u32, m9: u8, v9: u8, r10: u32, m10: u8, v10: u8, r11: u32, m11: u8, v11: u8, r12: u32, m12: u8, v12: u8) -> [u8; 31] { + [(mode << 8) as u8, (mode & 0xFF) as u8, 13, (r0 << 8) as u8, (r0 & 0xFF) as u8, m0, v0, (r1 << 8) as u8, (r1 & 0xFF) as u8, m1, v1, (r2 << 8) as u8, (r2 & 0xFF) as u8, m2, v2, (r3 << 8) as u8, (r3 & 0xFF) as u8, m3, v3, (r4 << 8) as u8, (r4 & 0xFF) as u8, m4, v4, (r5 << 8) as u8, (r5 & 0xFF) as u8, m5, v5, (r6 << 8) as u8, (r6 & 0xFF) as u8, m6, v6, (r7 << 8) as u8, (r7 & 0xFF) as u8, m7, v7, (r8 << 8) as u8, (r8 & 0xFF) as u8, m8, v8, (r9 << 8) as u8, (r9 & 0xFF) as u8, m9, v9, (r10 << 8) as u8, (r10 & 0xFF) as u8, m10, v10, (r11 << 8) as u8, (r11 & 0xFF) as u8, m11, v11, (r12 << 8) as u8, (r12 & 0xFF) as u8, m12, v12] +} + +const AM_MOD_DRIVER_LEVEL_DEFAULT: u8 = 0xb9; + +const ANALOG_CONFIG_LUT_SIZE: u32 = 87; /*!< Maximum number of Configuration IDs in the Loop Up Table */ +const ANALOG_CONFIG_LUT_NOT_FOUND: u32 = 0xFF; /*!< Index value indicating no Configuration IDs found */ + +const ANALOG_CONFIG_TBL_SIZE: u32 = 1024; /*!< Maximum number of Register-Mask-Value in the Setting List */ + + +const ANALOG_CONFIG_POLL_LISTEN_MODE_MASK: u32 = 0x8000; /*!< Mask bit of Poll Mode in Analog Configuration ID */ +const ANALOG_CONFIG_TECH_MASK: u32 = 0x7F00; /*!< Mask bits for Technology in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_MASK: u32 = 0x00F0; /*!< Mask bits for Bit rate in Analog Configuration ID */ +const ANALOG_CONFIG_DIRECTION_MASK: u32 = 0x0003; /*!< Mask bits for Direction in Analog Configuration ID */ +const ANALOG_CONFIG_CHIP_SPECIFIC_MASK: u32 = 0x00FF; /*!< Mask bits for Chip Specific Technology */ + +const ANALOG_CONFIG_POLL_LISTEN_MODE_SHIFT: u32 = 15; /*!< Shift value of Poll Mode in Analog Configuration ID */ +const ANALOG_CONFIG_TECH_SHIFT: u32 = 8; /*!< Shift value for Technology in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_SHIFT: u32 = 4; /*!< Shift value for Technology in Analog Configuration ID */ +const ANALOG_CONFIG_DIRECTION_SHIFT: u32 = 0; /*!< Shift value for Direction in Analog Configuration ID */ + +const ANALOG_CONFIG_POLL: u32 = 0x0000; /*!< Poll Mode bit setting in Analog Configuration ID */ +const ANALOG_CONFIG_LISTEN: u32 = 0x8000; /*!< Listen Mode bit setting in Analog Configuration ID */ + +const ANALOG_CONFIG_TECH_CHIP: u32 = 0x0000; /*!< Chip-Specific bit setting in Analog Configuration ID */ +const ANALOG_CONFIG_TECH_NFCA: u32 = 0x0100; /*!< NFC-A Technology bits setting in Analog Configuration ID */ +const ANALOG_CONFIG_TECH_NFCB: u32 = 0x0200; /*!< NFC-B Technology bits setting in Analog Configuration ID */ +const ANALOG_CONFIG_TECH_NFCF: u32 = 0x0400; /*!< NFC-F Technology bits setting in Analog Configuration ID */ +const ANALOG_CONFIG_TECH_AP2P: u32 = 0x0800; /*!< AP2P Technology bits setting in Analog Configuration ID */ +const ANALOG_CONFIG_TECH_NFCV: u32 = 0x1000; /*!< NFC-V Technology bits setting in Analog Configuration ID */ +const ANALOG_CONFIG_TECH_RFU: u32 = 0x2000; /*!< RFU for Technology bits */ + +const ANALOG_CONFIG_BITRATE_COMMON: u32 = 0x0000; /*!< Common settings for all bit rates in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_106: u32 = 0x0010; /*!< 106kbits/s settings in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_212: u32 = 0x0020; /*!< 212kbits/s settings in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_424: u32 = 0x0030; /*!< 424kbits/s settings in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_848: u32 = 0x0040; /*!< 848kbits/s settings in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_1695: u32 = 0x0050; /*!< 1695kbits/s settings in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_3390: u32 = 0x0060; /*!< 3390kbits/s settings in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_6780: u32 = 0x0070; /*!< 6780kbits/s settings in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_1OF4: u32 = 0x00C0; /*!< 1 out of 4 for NFC-V setting in Analog Configuration ID */ +const ANALOG_CONFIG_BITRATE_1OF256: u32 = 0x00D0; /*!< 1 out of 256 for NFC-V setting in Analog Configuration ID */ + +const ANALOG_CONFIG_NO_DIRECTION: u32 = 0x0000; /*!< No direction setting in Analog Conf ID (Chip Specific only) */ +const ANALOG_CONFIG_TX: u32 = 0x0001; /*!< Transmission bit setting in Analog Configuration ID */ +const ANALOG_CONFIG_RX: u32 = 0x0002; /*!< Reception bit setting in Analog Configuration ID */ +const ANALOG_CONFIG_ANTICOL: u32 = 0x0003; /*!< Anticollision setting in Analog Configuration ID */ + +const ANALOG_CONFIG_CHIP_INIT: u32 = 0x0000; /*!< Chip-Specific event: Startup;Reset;Initialize */ +const ANALOG_CONFIG_CHIP_DEINIT: u32 = 0x0001; /*!< Chip-Specific event: Deinitialize */ +const ANALOG_CONFIG_CHIP_FIELD_ON: u32 = 0x0002; /*!< Chip-Specific event: Field On */ +const ANALOG_CONFIG_CHIP_FIELD_OFF: u32 = 0x0003; /*!< Chip-Specific event: Field Off */ +const ANALOG_CONFIG_CHIP_WAKEUP_ON: u32 = 0x0004; /*!< Chip-Specific event: Wake-up On */ +const ANALOG_CONFIG_CHIP_WAKEUP_OFF: u32 = 0x0005; /*!< Chip-Specific event: Wake-up Off */ +const ANALOG_CONFIG_CHIP_LISTEN_ON: u32 = 0x0006; /*!< Chip-Specific event: Listen On */ +const ANALOG_CONFIG_CHIP_LISTEN_OFF: u32 = 0x0007; /*!< Chip-Specific event: Listen Off */ +const ANALOG_CONFIG_CHIP_POLL_COMMON: u32 = 0x0008; /*!< Chip-Specific event: Poll common */ +const ANALOG_CONFIG_CHIP_LISTEN_COMMON: u32 = 0x0009; /*!< Chip-Specific event: Listen common */ + +const ANALOG_CONFIG_UPDATE_LAST: u32 = 0x00; /*!< Value indicating Last configuration set during update */ +const ANALOG_CONFIG_UPDATE_MORE: u32 = 0x01; /*!< Value indicating More configuration set coming during update */ + + +pub(crate) struct AnalogConfigMgmt { + config_tbl: Box<[u8]>, + ready: bool, +} + +impl AnalogConfigMgmt { + pub fn new_default() -> Self { + Self { + config_tbl: vec![ + //****** Default Analog Configuration for Chip-Specific Reset. ******/ + MODE_ENTRY_10_REG(ANALOG_CONFIG_TECH_CHIP | ANALOG_CONFIG_CHIP_INIT, + Register::OperationControl, 0x30, 0x10, //Default to AM + Register::IOConfiguration1, 0x06, 0x06, //MCUCLK: HF clk off + Register::IOConfiguration1, IOConfiguration1Bits::mask_out_cl | IOConfiguration1Bits::lf_clk_off, 0x07, // MCUCLK: LF clk off + Register::IOConfiguration2, 0x18, 0x18, // pull downs + Register::ReceiverConfiguration4, ReceiverConfiguration4Bits::mask_rg2_pm, 0x1 << ReceiverConfiguration4Bits::shift_rg2_pm, //increase digitizer windows for PM + Register::AnntenaCalibrationTarget, 0xFF, 0x80, // 90 deg, + Register::AnntenaCalibrationControl, 0xF8, 0x00, // trim value from calibrate antenna + Register::AMModulationDepthControl, AMModulationDepthControlConstans::am_s, AMModulationDepthControlConstans::am_s, // AM modulated level is defined by RFO AM Modulated Level Def Reg, fixed setting, no automatic adjustment + Register::ExternalFieldDetectorThreshold, EXT_FIELD_DET_TRG_MASK, ExternalFieldDetectorThresholdTrgVoltage::trg_75mV, + Register::ExternalFieldDetectorThreshold, EXT_FIELD_DET_RFE_MASK, ExternalFieldDetectorThresholdRfeVoltage::rfe_75mV + ) + ].into_boxed_slice(), + ready: true, + } + } +} \ No newline at end of file diff --git a/Software/fab-reader2/st25r3911b/src/constants.rs b/Software/fab-reader2/st25r3911b/src/constants.rs new file mode 100644 index 0000000..2b7e538 --- /dev/null +++ b/Software/fab-reader2/st25r3911b/src/constants.rs @@ -0,0 +1,412 @@ +use std::time::Duration; + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub(crate) enum Register { + IOConfiguration1 = 0x00, + IOConfiguration2 = 0x01, + OperationControl = 0x02, + ModeDefinition = 0x03, + BitRateDefinition = 0x04, + ISO14443ANFCSettings = 0x05, + ISO14443BSettings1 = 0x06, + ISO14443BFeliCaSettings = 0x07, + StreamModeDefinition = 0x08, + AuxDefinition = 0x09, + ReceiverConfiguration1 = 0x0A, + ReceiverConfiguration2 = 0x0B, + ReceiverConfiguration3 = 0x0C, + ReceiverConfiguration4 = 0x0D, + MaskReceiveTimer = 0x0E, + NoResponseTimer1 = 0x0F, + NoResponseTimer2 = 0x10, + GeneralPurposeNoResponseTimerControl = 0x11, + GeneralPurposeTimer1 = 0x12, + GeneralPurposeTimer2 = 0x13, + MaskMainInterrupt = 0x14, + MaskTimerNFCInterrupt = 0x15, + MaskErrorWakeUpInterrupt = 0x16, + MainInterruptStatus = 0x17, + TimerNFCInterruptStatus = 0x18, + ErrorWakeUpInterruptStatus = 0x19, + FIFOStatus1 = 0x1A, + FIFOStatus2 = 0x1B, + CollisionStatus = 0x1C, + NoOfTransmittedBytes1 = 0x1D, + NoOfTransmittedBytes2 = 0x1E, + NFCIPBitRateDetectionStatus = 0x1F, + ADCOutput = 0x20, + AnntenaCalibrationControl = 0x21, + AnntenaCalibrationTarget = 0x22, + AnntenaCalibrationStatus = 0x23, + AMModulationDepthControl = 0x24, + AMModulationDepthStatus = 0x25, + RFOAMModulationLevelDefinition = 0x26, + RFONormalLevelDefinition = 0x27, + ExternalFieldDetectorThreshold = 0x29, + RegulatorVoltageControl = 0x2A, + RegulatorTimerStatus = 0x2B, + RSSIStatus = 0x2C, + GainReductionState = 0x2D, + CapacitiveSensorControl = 0x2E, + CapacitiveSensorStatus = 0x2F, + AuxStatus = 0x30, + WakeUpTimerControl = 0x31, + AmplitudeMeasurementConfiguration = 0x32, + AmplitudeMeasurementReference = 0x33, + AmplitudeMeasurementAutoAveragingStatus = 0x34, + AmplitudeMeasurementStatus = 0x35, + PhaseMeasurementConfiguration = 0x36, + PhaseMeasurementReference = 0x37, + PhaseMeasurementAutoAveragingStatus = 0x38, + PhaseMeasurementStatus = 0x39, + CapacitanceMeasurementConfiguration = 0x3A, + CapacitanceMeasurementReference = 0x3B, + CapacitanceMeasurementAutoAveragingStatus = 0x3C, + CapacitanceMeasurementStatus = 0x3D, + ICIdentity = 0x3F, + InvalidRegister = 0xFF, +} + +impl From for Register { + fn from(value: u8) -> Self { + match value { + 0x00 => Register::IOConfiguration1, + 0x01 => Register::IOConfiguration2, + 0x02 => Register::OperationControl, + 0x03 => Register::ModeDefinition, + 0x04 => Register::BitRateDefinition, + 0x05 => Register::ISO14443ANFCSettings, + 0x06 => Register::ISO14443BSettings1, + 0x07 => Register::ISO14443BFeliCaSettings, + 0x08 => Register::StreamModeDefinition, + 0x09 => Register::AuxDefinition, + 0x0A => Register::ReceiverConfiguration1, + 0x0B => Register::ReceiverConfiguration2, + 0x0C => Register::ReceiverConfiguration3, + 0x0D => Register::ReceiverConfiguration4, + 0x0E => Register::MaskReceiveTimer, + 0x0F => Register::NoResponseTimer1, + 0x10 => Register::NoResponseTimer2, + 0x11 => Register::GeneralPurposeNoResponseTimerControl, + 0x12 => Register::GeneralPurposeTimer1, + 0x13 => Register::GeneralPurposeTimer2, + 0x14 => Register::MaskMainInterrupt, + 0x15 => Register::MaskTimerNFCInterrupt, + 0x16 => Register::MaskErrorWakeUpInterrupt, + 0x17 => Register::MainInterruptStatus, + 0x18 => Register::TimerNFCInterruptStatus, + 0x19 => Register::ErrorWakeUpInterruptStatus, + 0x1A => Register::FIFOStatus1, + 0x1B => Register::FIFOStatus2, + 0x1C => Register::CollisionStatus, + 0x1D => Register::NoOfTransmittedBytes1, + 0x1E => Register::NoOfTransmittedBytes2, + 0x1F => Register::NFCIPBitRateDetectionStatus, + 0x20 => Register::ADCOutput, + 0x21 => Register::AnntenaCalibrationControl, + 0x22 => Register::AnntenaCalibrationTarget, + 0x23 => Register::AnntenaCalibrationStatus, + 0x24 => Register::AMModulationDepthControl, + 0x25 => Register::AMModulationDepthStatus, + 0x26 => Register::RFOAMModulationLevelDefinition, + 0x27 => Register::RFONormalLevelDefinition, + 0x29 => Register::ExternalFieldDetectorThreshold, + 0x2A => Register::RegulatorVoltageControl, + 0x2B => Register::RegulatorTimerStatus, + 0x2C => Register::RSSIStatus, + 0x2D => Register::GainReductionState, + 0x2E => Register::CapacitiveSensorControl, + 0x2F => Register::CapacitiveSensorStatus, + 0x30 => Register::AuxStatus, + 0x31 => Register::WakeUpTimerControl, + 0x32 => Register::AmplitudeMeasurementConfiguration, + 0x33 => Register::AmplitudeMeasurementReference, + 0x34 => Register::AmplitudeMeasurementAutoAveragingStatus, + 0x35 => Register::AmplitudeMeasurementStatus, + 0x36 => Register::PhaseMeasurementConfiguration, + 0x37 => Register::PhaseMeasurementReference, + 0x38 => Register::PhaseMeasurementAutoAveragingStatus, + 0x39 => Register::PhaseMeasurementStatus, + 0x3A => Register::CapacitanceMeasurementConfiguration, + 0x3B => Register::CapacitanceMeasurementReference, + 0x3C => Register::CapacitanceMeasurementAutoAveragingStatus, + 0x3D => Register::CapacitanceMeasurementStatus, + 0x3F => Register::ICIdentity, + 40_u8 | 62_u8 | 64_u8..=u8::MAX => Register::InvalidRegister, + } + } +} + +impl Register { + /// Get register address + pub fn addr(self) -> u8 { + self as u8 + } +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum OperationControlBits { + Wu = 1 << 2, + TxEn = 1 << 3, + RxMan = 1 << 4, + RxChn = 1 << 5, + RxEn = 1 << 6, + En = 1 << 7, +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum RegulatorControlBits { + ShiftMpsv = 1, + MpsvVdd = 0 << 1, + MpsvVspA = 1 << 1, + MpsvVspD = 2 << 1, + MpsvVspRf = 3 << 1, + ShiftRege = 3, + RegS = 1 << 7, +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum RegulatorControlMask { + Mpsv = 3 << 1, + Rege = 0xf << 3, +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum IOConfiguration2Bits { + SlowUp = 1 << 0, + Io18 = 1 << 2, + MisoPd1 = 1 << 3, + MisoPd2 = 1 << 4, + VspdOff = 1 << 6, + Sup3V = 1 << 7, +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum IOConfiguration1Bits { + lf_clk_off = 1 << 0, + out_cl0 = 1 << 1, + out_cl1 = 1 << 2, + mask_out_cl = 3 << 1, + osc = 1 << 3, + rfo2 = 1 << 6, + single = 1 << 7, +} + +const FIFO_LT: u8 = 1 << 4; + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum IOConfiguration1FIFOLt { + fifo_lt_32bytes = 0 << 4, + fifo_lt_16bytes = 1 << 4, +} + +const FIFO_LR: u8 = 1 << 5; + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum IOConfiguration1FIFOLr { + fifo_lr_64bytes = 0 << 5, + fifo_lr_80bytes = 1 << 5, +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum ReceiverConfiguration4Bits { + shift_rg2_pm = 0, + mask_rg2_pm = 0xf < 0, + rg2_pm0 = 1 << 0, + rg2_pm1 = 1 << 1, + rg2_pm2 = 1 << 2, + rg2_pm3 = 1 << 3, + shift_rg2_am = 4, + mask_rg2_am = 0xf << 4, + rg2_am0 = 1 << 4, + rg2_am1 = 1 << 5, + rg2_am2 = 1 << 6, + rg2_am3 = 1 << 7, +} + +const AM_MOD_DEPTH_CONTROL_MASK: u8 = 0x3f << 1; +const AM_MOD_DEPTH_CONTROL_SHIFT: u8 = 1; + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum AMModulationDepthControlConstans { + mod_8percent = 0xb << 1, + mod_10percent = 0xe << 1, + mod_14percent = 0x14 << 1, + mod_20percent = 0x20 << 1, + mod_25percent = 0x2a << 1, + mod_30percent = 0x37 << 1, + mod_33percent = 0x3f << 1, + am_s = 1 << 7, +} + +pub const EXT_FIELD_DET_RFE_MASK: u8 = 0x0f; + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum ExternalFieldDetectorThresholdRfe { +rfe_t0 = 1<<0 , +rfe_t1 = 1<<1 , +rfe_t2 = 1<<2 , +rfe_t3 = 1<<3 , +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum ExternalFieldDetectorThresholdRfeVoltage { + rfe_75mV = 0x00<<0 , + rfe_105mV = 0x01<<0 , + rfe_150mV = 0x02<<0 , + rfe_205mV = 0x03<<0 , + rfe_290mV = 0x04<<0 , + rfe_400mV = 0x05<<0 , + rfe_560mV = 0x06<<0 , + rfe_800mV = 0x07<<0 , + rfe_25mV = 0x08<<0 , + rfe_33mV = 0x09<<0 , + rfe_47mV = 0x0A<<0 , + rfe_64mV = 0x0B<<0 , + rfe_90mV = 0x0C<<0 , + rfe_125mV = 0x0D<<0 , + rfe_175mV = 0x0E<<0 , + rfe_250mV = 0x0F<<0 , +} + +pub const EXT_FIELD_DET_TRG_MASK: u8 = 0x07<<4; + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum ExternalFieldDetectorThresholdTrg { + trg_l0 = 1<<4 , + trg_l1 = 1<<5 , + trg_l2 = 1<<6 , +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum ExternalFieldDetectorThresholdTrgVoltage { + trg_75mV = 0x00<<4 , + trg_105mV = 0x01<<4 , + trg_150mV = 0x02<<4 , + trg_205mV = 0x03<<4 , + trg_290mV = 0x04<<4 , + trg_400mV = 0x05<<4 , + trg_560mV = 0x06<<4 , + trg_800mV = 0x07<<4 , +} + +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum ICIdentityBits { + V2 = 0x09, + IcType = 1 << 3, + MaskIcType = 0x1F << 3, + ShiftIcType = 3, + MaskIcRev = 7, +} + +/* ST25R3911 direct commands */ +#[repr(u8)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub(crate) enum DirectCmd { + /*< Puts the chip in default state (same as after power-up) */ + SetDefault = 0xC1, + /*< Stops all activities and clears FIFO */ + ClearFifo = 0xC2, + /*< Transmit with CRC */ + TransmitWithCrc = 0xC4, + /* Transmit without CRC */ + TransmitWithoutCrc = 0xC5, + /* Transmit REQA */ + TransmitReqa = 0xC6, + /* Transmit WUPA */ + TransmitWupa = 0xC7, + /* NFC transmit with Initial RF Collision Avoidance */ + InitialRfCollision = 0xC8, + /* NFC transmit with Response RF Collision Avoidance */ + ResponseRfCollisionN = 0xC9, + /* NFC transmit with Response RF Collision Avoidance with n=0 */ + ResponseRfCollision0 = 0xCA, + /* NFC switch to normal NFC mode */ + NormalNfcMode = 0xCB, + /* Analog Preset */ + AnalogPreset = 0xCC, + /* Mask recive data */ + MaskReceiveData = 0xD0, + /* Unmask recive data */ + UnmaskReceiveData = 0xD1, + /* Measure singal amplitude on RFI inputs */ + MeasureAmplitude = 0xD3, + /* Squelch */ + Squelch = 0xD4, + /* Clear Squelch */ + ClearSquelch = 0xD5, + /* Adjust regulators */ + AdjustRegulators = 0xD6, + /* Calibrate modulation depth */ + CalibrateModulation = 0xD7, + /* Calibrate antenna */ + CalibrateAntenna = 0xD8, + /* Measure phase between RFO and RFI signal */ + MeasurePhase = 0xD9, + /* clear RSSI bits and restart the measurement */ + ClearRssi = 0xDA, + /* Transparent mode */ + TransparentMode = 0xDC, + /* Calibrate the capacitive sensor */ + CalibrateCSensor = 0xDD, + /* Measure capacitance */ + MeasureCapacitance = 0xDE, + /* Measure power supply voltage */ + MeasureVdd = 0xDF, + /* Start the general purpose timer */ + StartGpTimer = 0xE0, + /* Start the wake-up timer */ + StartWupTimer = 0xE1, + /* Start the mask-receive timer */ + StartMaskReceiveTimer = 0xE2, + /* Start the no-repsonse timer */ + StartNoResponseTimer = 0xE3, + /* Clear Test register */ + TestCleara = 0xFA, + /* Clear Test register */ + TestClearb = 0xFB, + /* Enable R/W access to the test registers */ + TestAccess = 0xFC, + /* Load data from the poly fuses to RAM */ + LoadPprom = 0xFD, + /* Fuse poly fuses with data from the RAM */ + FusePprom = 0xFE, +} + +impl DirectCmd { + /// Get DirectCmd address + pub fn addr(self) -> u8 { + self as u8 + } +} + +#[repr(u32)] +#[derive(PartialEq, Clone, Copy, Debug)] +pub(crate) enum OperationMode { + WriteMode = 0, + ReadMode = 1u32 << 6, + FifoLoad = 2u32 << 6, + FifoRead = 0xBF, + CmdMode = 3u32 << 6, +} + +pub(crate) const FifoDepth: u32 = 96; +pub(crate) const CmdLen: u32 = 1; +pub(crate) const BufLen: u32 = CmdLen + FifoDepth; + +pub(crate) const OscStableTimeout: Duration = Duration::from_millis(5); \ No newline at end of file diff --git a/Software/fab-reader2/st25r3911b/src/interface.rs b/Software/fab-reader2/st25r3911b/src/interface.rs new file mode 100644 index 0000000..b738a14 --- /dev/null +++ b/Software/fab-reader2/st25r3911b/src/interface.rs @@ -0,0 +1,113 @@ +use std::time::Duration; +use embedded_hal::{ + digital::v2::*, +}; +use embedded_hal::blocking::spi::{Transfer, Write}; +use anyhow::Result; +use crate::Error; + +use crate::constants::*; + +pub(crate) struct Interface { + /// SPI + spi: SPI, + /// CS for SPI + cs: CS, + /// Low for busy + irq: IRQ, +} + +impl Interface + where + SPI: Write + Transfer, + CS: OutputPin, + IRQ: InputPin, +{ + pub fn new(spi: SPI, cs: CS, irq: IRQ) -> Self { + Interface { + spi, + cs, + irq, + } + } + + pub fn execute_cmd(&mut self, command: DirectCmd) -> Result<(), Error> { + // FIXME: Aquire Lock to Protect Comms with ST25R3911 + self.cs.set_low(); + + self.spi.write(&[command.addr() | OperationMode::CmdMode as u8])?; //FIXME: make this more generic + + self.cs.set_high(); + // FIXME: Release Lock to Protect Comms with ST25R3911 + Ok(()) + } + + pub fn write_register(&mut self, register: Register, value: u8) -> Result<(), Error> { + // FIXME: Aquire Lock to Protect Comms with ST25R3911 + self.cs.set_low(); + + self.spi.write(&[register.addr() | OperationMode::WriteMode as u8, value])?; //FIXME: make this more generic + + self.cs.set_high(); + // FIXME: Release Lock to Protect Comms with ST25R3911 + Ok(()) + } + + pub fn read_register(&mut self, register: Register) -> Result> { + // FIXME: Aquire Lock to Protect Comms with ST25R3911 + self.cs.set_low(); + + let mut buf = [register.addr() | OperationMode::ReadMode as u8, 0x00]; + + let value = self.spi.transfer(&mut buf)?; //FIXME: make this more generic + + + self.cs.set_high(); + // FIXME: Release Lock to Protect Comms with ST25R3911 + Ok(value[1]) + } + + pub fn modify_register(&mut self, register: Register, clr_mask: u8, set_mask: u8) -> Result<(), Error> { + let mut tmp = self.read_register(register)?; + tmp &= !clr_mask; + tmp |= set_mask; + self.write_register(register, tmp)?; + Ok(()) + } + + pub fn change_register_bits(&mut self, register: Register, mask: u8, value: u8) -> Result<(), Error> { + self.modify_register(register, mask, value & mask) + } + + pub fn clr_register_bits(&mut self, register: Register, mask: u8) -> Result<(), Error> { + let tmp = self.read_register(register)? & !mask; + self.write_register(register, tmp) + } + + pub fn set_register_bits(&mut self, register: Register, mask: u8) -> Result<(), Error> { + let tmp = self.read_register(register)? | mask; + self.write_register(register, tmp) + } + + pub fn check_register(&mut self, register: Register, mask: u8, value: u8) -> Result> { + let tmp = self.read_register(register)?; + Ok((tmp & mask) == value) + } + + pub fn read_multiple_registers(&mut self, register: Register, length: u8) -> Result, Error> { + // FIXME: Aquire Lock to Protect Comms with ST25R3911 + self.cs.set_low(); + + let cmd = register.addr() | OperationMode::ReadMode as u8; + + self.spi.write(&[cmd])?; //FIXME: make this more generic + + let mut buf = vec![0; length as usize]; + let value = self.spi.transfer(&mut buf)?; //FIXME: make this more generic + + + self.cs.set_high(); + // FIXME: Release Lock to Protect Comms with ST25R3911 + Ok(value.into()) + } +} \ No newline at end of file diff --git a/Software/fab-reader2/st25r3911b/src/interrupts.rs b/Software/fab-reader2/st25r3911b/src/interrupts.rs new file mode 100644 index 0000000..a58bc1d --- /dev/null +++ b/Software/fab-reader2/st25r3911b/src/interrupts.rs @@ -0,0 +1,108 @@ +#[repr(u32)] +pub enum IRQMask { + /* Main interrupt register. */ + + /* No ST25R3911 interrupt source */ + None = 0, + /* All ST25R3911 interrupt sources */ + All = 0xFFFFFF, + /* ST25R3911 oscillator stable interrupt */ + Osc = 0x80, + /* ST25R3911 FIFO water level interrupt */ + Fwl = 0x40, + /* ST25R3911 start of receive interrupt */ + Rxs = 0x20, + /* ST25R3911 end of receive interrupt */ + Rxe = 0x10, + /* ST25R3911 end of transmission interrupt */ + Txe = 0x08, + /* ST25R3911 bit collision interrupt */ + Col = 0x04, + + /* Timer and NFC interrupt register. */ + + /* ST25R3911 termination of direct command interrupt */ + Dct = 0x8000, + /* ST25R3911 no-response timer expired interrupt */ + Nre = 0x4000, + /* ST25R3911 general purpose timer expired interrupt */ + Gpe = 0x2000, + /* ST25R3911 external field on interrupt */ + Eon = 0x1000, + /* ST25R3911 external field off interrupt */ + Eof = 0x0800, + /* ST25R3911 collision during RF collision avoidance interrupt */ + Cac = 0x0400, + /* ST25R3911 minimum guard time expired interrupt */ + Cat = 0x0200, + /* ST25R3911 initiator bit rate recognized interrupt */ + Nfct = 0x0100, + + /* Error and wake-up interrupt register. */ + + /* ST25R3911 CRC error interrupt */ + Crc = 0x800000, + /* ST25R3911 parity error interrupt */ + Par = 0x400000, + /* ST25R3911 soft framing error interrupt */ + Err2 = 0x200000, + /* ST25R3911 hard framing error interrupt */ + Err1 = 0x100000, + /* ST25R3911 wake-up interrupt */ + Wt = 0x080000, + /* ST25R3911 wake-up due to amplitude interrupt */ + Wam = 0x040000, + /* ST25R3911 wake-up due to phase interrupt */ + Wph = 0x020000, + /* ST25R3911 wake-up due to capacitance measurement */ + Wcap = 0x010000, + + + /* additional interrupts in ST25R3911_REG_IRQ_TIMER_NFC */ + Tim = 0x02, + /* additional interrupts in ST25R3911_REG_IRQ_ERROR_WUP */ + Err = 0x01, +} + +type InterruptCallback = fn(); + +pub struct Interrupt { + prevCallback: Option, + callback: Option, + status: u32, + mask: u32, +} + +//FIXME: Protect Status when writing + +impl Interrupt { + pub fn new() -> Self { + Interrupt { + prevCallback: None, + callback: None, + status: 0, + mask: 0, + } + } + pub fn modifyMask(&mut self, clr_mask: u32, set_mask: u32) { + self.mask = (self.mask & !clr_mask) | set_mask; + } + pub fn status(&self) -> u32 { + self.status + } + pub fn mask(&self) -> u32 { + self.mask + } + pub fn set_prevCallback(&mut self, prevCallback: Option) { + self.prevCallback = prevCallback; + } + pub fn set_callback(&mut self, callback: Option) { + self.callback = callback; + } + pub fn set_status(&mut self, status: u32) { + self.status = status; + } + pub fn set_mask(&mut self, mask: u32) { + self.mask = mask; + } +} \ No newline at end of file diff --git a/Software/fab-reader2/st25r3911b/src/lib.rs b/Software/fab-reader2/st25r3911b/src/lib.rs new file mode 100644 index 0000000..f6ade36 --- /dev/null +++ b/Software/fab-reader2/st25r3911b/src/lib.rs @@ -0,0 +1,188 @@ +use std::time::Duration; +use embedded_hal::blocking::spi::{Transfer, Write}; +use embedded_hal::digital::v2::OutputPin; +use embedded_hal::digital::v2::InputPin; + +use embedded_svc::timer::*; + +mod interface; +mod interrupts; +mod constants; +mod analogConfig; + +use crate::interface::Interface; +use crate::interrupts::{Interrupt, IRQMask}; +use crate::constants::{DirectCmd, ICIdentityBits, IOConfiguration2Bits, OperationControlBits, OscStableTimeout, Register, RegulatorControlBits, RegulatorControlMask}; + +/// Error +#[derive(Debug)] +pub enum Error { + /// SPI error + Spi(E), + InvalidRegister, + InvalidChipId, +} + +impl From for Error { + fn from(e: E) -> Self { + Error::Spi(e) + } +} + +struct ST25R3911B { + interface: Interface, + interrupt: Interrupt, + timer: TIMER, +} + +impl ST25R3911B + where + SPI: Write + Transfer, + CS: OutputPin, + IRQ: InputPin, + TIMER: TimerService, Error: From<::Error>, Error: From, +{ + pub fn new(spi: SPI, cs: CS, irq: IRQ, timer_service: TIMER) -> Self { + Self { + interface: Interface::new(spi, cs, irq), + interrupt: Interrupt::new(), + timer: timer_service, + } + } + + pub(crate) fn get_interrupt(&mut self, mask: IRQMask) -> Result> { + let irqs = self.interrupt.status() & mask as u32; + if irqs != IRQMask::None as u32 { + self.interrupt.set_status(self.interrupt.status() & !irqs); + } + Ok(irqs) + } + + pub(crate) fn modify_interrupts(&mut self, clr_mask: u32, set_mask: u32) -> Result<(), Error> { + self.interrupt.modifyMask(clr_mask, set_mask); + + for i in 0..2 { + if (self.interrupt.mask() >> (i * 8)) & 0xFF != 0 { + self.interface.write_register((Register::MaskMainInterrupt as u8 + i).into(), ((self.interrupt.mask() << (i * 8)) & 0xFF) as u8)?; + } + } + Ok(()) + } + + pub(crate) fn enable_interrupts(&mut self, mask: u32) -> Result<(), Error> { + self.modify_interrupts(mask, 0) + } + + pub(crate) fn disable_interrupts(&mut self, mask: u32) -> Result<(), Error> { + self.modify_interrupts(0, mask) + } + + pub(crate) fn clear_interrupts(&mut self) -> Result<(), Error> { + self.interface.read_multiple_registers(Register::MainInterruptStatus, 2)?; + self.interrupt.set_status(0); + Ok(()) + } + + pub(crate) fn wait_for_interrupts_timed(&mut self, mask: u32, timeout: Duration) -> Result> { + let mut irqs = 0; + let mut timer = self.timer.timer(|| {})?; + + timer.after(timeout); + let mut status = self.interrupt.status() & mask; + while timer.is_scheduled()? || !timeout.is_zero() && (status == 0) { + status = self.interrupt.status() & mask; + } + + status = self.interrupt.status() & mask; + + //protect irq status + self.interrupt.set_status(!status); + + Ok(12) + } + + pub(crate) fn execute_cmd_and_get_result(&mut self, command: DirectCmd, result_register: Register, sleeptime: Duration) -> Result> { + self.enable_interrupts(IRQMask::Dct as u32)?; + self.get_interrupt(IRQMask::Dct)?; + self.interface.execute_cmd(command)?; + self.wait_for_interrupts_timed(IRQMask::Dct as u32, sleeptime)?; + self.disable_interrupts(IRQMask::Dct as u32)?; + + self.interface.read_register(result_register) + } + + pub(crate) fn osc_on(&mut self) -> Result<(), Error> { + if !self.interface.check_register(Register::OperationControl, OperationControlBits::En as u8, OperationControlBits::En as u8)? { //FIXME: use traits for stuff that we cast to u8 + /* Clear any eventual previous oscillator IRQ */ + self.get_interrupt(IRQMask::Osc)?; + + /* enable oscillator frequency stable interrupt */ + self.enable_interrupts(IRQMask::Osc as u32)?; + + /* enable oscillator and regulator output */ + self.interface.modify_register(Register::OperationControl, 0x00, OperationControlBits::En as u8)?; + + /* wait for the oscillator interrupt */ + self.wait_for_interrupts_timed(IRQMask::Osc as u32, OscStableTimeout)?; + self.disable_interrupts(IRQMask::Osc as u32)?; + } + Ok(()) + } + + pub(crate) fn measure_powersupply(&mut self, mpsv: RegulatorControlBits) -> Result> { + self.interface.change_register_bits(Register::RegulatorVoltageControl, RegulatorControlMask::Mpsv as u8, mpsv as u8); + self.execute_cmd_and_get_result(DirectCmd::MeasureVdd, Register::ADCOutput, Duration::from_millis(10)) + } + + pub(crate) fn measure_voltage(&mut self, mpsv: RegulatorControlBits) -> Result> { + let result = self.measure_powersupply(mpsv)?; + let mut mV = result as u16 * 23; + mV += ((result as u16 * 438) + 500) / 1000; + Ok(mV) + } + + pub(crate) fn tx_rx_on(&mut self) -> Result<(), Error> { + self.interface.set_register_bits(Register::OperationControl, OperationControlBits::TxEn as u8 | OperationControlBits::RxEn as u8) + } + + pub(crate) fn tx_rx_off(&mut self) -> Result<(), Error> { + self.interface.clr_register_bits(Register::OperationControl, OperationControlBits::TxEn as u8 | OperationControlBits::RxEn as u8) + } + + pub fn init(&mut self) -> Result<(), Error> { + /* first, reset the st25r3911 */ + self.interface.execute_cmd(DirectCmd::SetDefault)?; + + /* Set Operation Control Register to default value */ + self.interface.write_register(Register::OperationControl, 0x00)?; + + /* enable pull downs on miso line */ + self.interface.modify_register(Register::IOConfiguration2, 0x00, IOConfiguration2Bits::MisoPd1 as u8 | IOConfiguration2Bits::MisoPd2 as u8)?; + + /* after reset all interrupts are enabled. so disable them at first */ + self.disable_interrupts(IRQMask::All as u32)?; + /* and clear them, just to be sure... */ + self.clear_interrupts()?; + + self.osc_on()?; + + /* Measure vdd and set sup3V bit accordingly */ + let vdd_mV = self.measure_voltage(RegulatorControlBits::MpsvVdd)?; + + self.interface.modify_register(Register::IOConfiguration2, IOConfiguration2Bits::Sup3V as u8, if vdd_mV < 3600 { IOConfiguration2Bits::Sup3V as u8 } else { 0 })?; + + /* Make sure Transmitter and Receiver are disabled */ + self.tx_rx_off()?; + Ok(()) + } + + pub fn check_chip_id(&mut self) -> Result> { + let chip_id = self.interface.read_register(Register::ICIdentity)?; + if (chip_id & ICIdentityBits::IcType as u8) != ICIdentityBits::IcType as u8 { + return Err(Error::InvalidChipId); + } + + Ok(chip_id & ICIdentityBits::MaskIcRev as u8) + } +} + diff --git a/Software/fab-reader2/st25r3911b/src/traits.rs b/Software/fab-reader2/st25r3911b/src/traits.rs new file mode 100644 index 0000000..e69de29