initial work on rust firmware for fabreader2

This commit is contained in:
Kai Jan Kriegel 2022-09-24 04:54:28 +02:00
parent 35dd3c120f
commit abd2ae5932
145 changed files with 2591 additions and 69263 deletions

View File

@ -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": {

172
Software/.cproject Normal file
View File

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.350035902">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.350035902" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.350035902" name="Debug" parent="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug">
<folderInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.350035902." name="/" resourcePath="">
<toolChain id="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.debug.1623223213" name="MCU ARM GCC" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.debug">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu.311204759" name="MCU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu" value="STM32L476RGTx" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.1600480122" name="CPU" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" value="0" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.1582730708" name="Core" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" value="0" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.1532913111" name="Floating-point unit" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.fpv4-sp-d16" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.1165351529" name="Floating-point ABI" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.869905098" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" value="NUCLEO-L476RG" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1176691904" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.5 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || NUCLEO-L476RG || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L4xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32L476xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || " valueType="string"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.831529341" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
<builder buildPath="${workspace_loc:/FabReader2}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1136346002" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.1430370275" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel.823315697" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel.value.g3" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.definedsymbols.1719027220" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.definedsymbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="DEBUG"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.input.890181254" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.input"/>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.170490292" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.1248483508" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g3" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.1362308830" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.568343496" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="DEBUG"/>
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
<listOptionValue builtIn="false" value="STM32L476xx"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths.640294965" name="Include paths (-I)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths" valueType="includePath">
<listOptionValue builtIn="false" value="../Core/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32L4xx/Include"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1871531359" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.197973334" name="MCU G++ Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel.420705807" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel.value.g3" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level.1432315120" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level"/>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.161300461" name="MCU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script.691926596" name="Linker Script (-T)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script" value="${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld}" valueType="string"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input.151827016" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.529046719" name="MCU G++ Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.archiver.138543232" name="MCU GCC Archiver" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.archiver"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.size.1457626227" name="MCU Size" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.size"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objdump.listfile.1136149749" name="MCU Output Converter list file" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objdump.listfile"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.hex.1698911198" name="MCU Output Converter Hex" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.hex"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.binary.1788040187" name="MCU Output Converter Binary" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.binary"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.verilog.374568986" name="MCU Output Converter Verilog" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.verilog"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.srec.1404769303" name="MCU Output Converter Motorola S-rec" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.srec"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.symbolsrec.1567378406" name="MCU Output Converter Motorola S-rec with symbols" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.symbolsrec"/>
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
<cconfiguration id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.426466017">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.426466017" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.426466017" name="Release" parent="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release">
<folderInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.426466017." name="/" resourcePath="">
<toolChain id="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.release.2111470417" name="MCU ARM GCC" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.exe.release">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu.261888890" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_mcu" value="STM32L476RGTx" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.1189393525" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" value="0" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.1268326624" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" value="0" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.1805642375" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.fpu.value.fpv4-sp-d16" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.435689275" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.floatabi.value.hard" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1496339202" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" value="NUCLEO-L476RG" valueType="string"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1183985804" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.5 || Release || false || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.option.toolchain.value.workspace || NUCLEO-L476RG || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc | ../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L4xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32L476xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || || None || " valueType="string"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.1821935989" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
<builder buildPath="${workspace_loc:/FabReader2}/Release" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1252414683" managedBuildOn="true" name="Gnu Make Builder.Release" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.289890033" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel.1518045979" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.option.debuglevel.value.g0" valueType="enumerated"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.input.1469644572" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.input"/>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.397481823" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.519723219" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g0" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.1991794860" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.os" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.1372741921" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USE_HAL_DRIVER"/>
<listOptionValue builtIn="false" value="STM32L476xx"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths.1584590218" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths" valueType="includePath">
<listOptionValue builtIn="false" value="../Core/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32L4xx/Include"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.619832432" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.1101242134" name="MCU G++ Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel.158988989" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.debuglevel.value.g0" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level.507973328" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.optimization.level.value.os" valueType="enumerated"/>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.1817036671" name="MCU GCC Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker">
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script.303626991" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.option.script" value="${workspace_loc:/${ProjName}/STM32L476RGTX_FLASH.ld}" valueType="string"/>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input.1966836885" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker.404015313" name="MCU G++ Linker" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.linker"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.archiver.159424688" name="MCU GCC Archiver" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.archiver"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.size.2108995416" name="MCU Size" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.size"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objdump.listfile.859955339" name="MCU Output Converter list file" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objdump.listfile"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.hex.1942104795" name="MCU Output Converter Hex" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.hex"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.binary.77733832" name="MCU Output Converter Binary" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.binary"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.verilog.1558653335" name="MCU Output Converter Verilog" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.verilog"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.srec.647748505" name="MCU Output Converter Motorola S-rec" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.srec"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.symbolsrec.246107179" name="MCU Output Converter Motorola S-rec with symbols" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.symbolsrec"/>
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
</sourceEntries>
</configuration>
</storageModule>
</cconfiguration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.pathentry"/>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="FabReader2.null.573066195" name="FabReader2"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.426466017;com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.release.426466017.;com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.397481823;com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.619832432">
<autodiscovery enabled="false" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.350035902;com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.350035902.;com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.170490292;com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1871531359">
<autodiscovery enabled="false" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
</cproject>

25
Software/.mxproject Normal file
View File

@ -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;

0
Software/.osx.project Normal file
View File

32
Software/.project Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>FabReader2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUCubeProjectNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature</nature>
<nature>com.st.stm32cube.ide.mcu.MCURootProjectNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>

View File

@ -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($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>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 $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")

View File

@ -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($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>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 $<TARGET_FILE:$${PROJECT_NAME}.elf> $${HEX_FILE}
COMMAND $${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:$${PROJECT_NAME}.elf> $${BIN_FILE}
COMMENT "Building $${HEX_FILE}
Building $${BIN_FILE}")

View File

@ -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****/

View File

@ -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****/

View File

@ -1,96 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -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****/

View File

@ -1,247 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -1,201 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 <stdint.h>
#include <stdbool.h>
#include <limits.h>
#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 */

View File

@ -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****/

View File

@ -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****/

View File

@ -1,651 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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****/

View File

@ -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 <BR>
* T4T_VNo : Indicates the Mapping Version <BR>
* MLe high : Max R-APDU size <BR>
* MLc high : Max C-APDU size <BR>
* NDEF FCI T: Indicates the NDEF-File_Ctrl_TLV <BR>
* NDEF FCI L: The length of the V-field <BR>
* NDEF FCI V1: NDEF File Identifier <BR>
* NDEF FCI V2: NDEF File size <BR>
* NDEF FCI V3: NDEF Read AC <BR>
* NDEF FCI V4: NDEF Write AC <BR>
*/
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 <BR>
* NDEF Header: MB,ME,SR,Well known Type <BR>
* NDEF type length <BR>
* NDEF payload length <BR>
* NDEF Type : URI <BR>
* NDEF URI abreviation field : http://www. <BR>
* NDEF URI string : st.com/st25r <BR>
* NDEF URI string : st.com/st25-demo <BR>
*/
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 <BR>
* Nbr : Indicates the number of blocks that can be read <BR>
* Nbw : Indicates the number of blocks that can be written <BR>
* NmaxB : Indicates the maximum number of blocks available for NDEF data <BR>
* WriteFlag : Indicates whether a previous NDEF write procedure has finished or not <BR>
* RWFlag : Indicates data can be updated or not <BR>
* Ln : Is the size of the actual stored NDEF data in bytes <BR>
* Checksum : allows the Reader/Writer to check whether the Attribute Data are correct <BR>
*/
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****/

View File

@ -1,157 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 <string.h>
#include <stdarg.h>
#include <stdio.h>
/*
******************************************************************************
* 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 */
}

View File

@ -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****/

File diff suppressed because it is too large Load Diff

View File

@ -1,721 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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: <Not displayed>\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(" <No chunk payload buffer>\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);
}

View File

@ -1,105 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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****/

View File

@ -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****/

View File

@ -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 <sys/stat.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
/* 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;
}

View File

@ -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 <errno.h>
#include <stdint.h>
/**
* 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;
}

View File

@ -1,109 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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****/

View File

@ -1,177 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="File-List" href="Library_files/filelist.xml">
<link rel="Edit-Time-Data" href="Library_files/editdata.mso">
<!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]-->
<title>Release Notes for ST25R3911 Driver</title>
<!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>STMicroelectronics</o:Author> <o:LastAuthor>STMicroelectronics</o:LastAuthor> <o:Revision>37</o:Revision> <o:TotalTime>136</o:TotalTime> <o:Created>2009-02-27T19:26:00Z</o:Created> <o:LastSaved>2009-03-01T17:56:00Z</o:LastSaved> <o:Pages>1</o:Pages> <o:Words>522</o:Words> <o:Characters>2977</o:Characters> <o:Company>STMicroelectronics</o:Company> <o:Lines>24</o:Lines> <o:Paragraphs>6</o:Paragraphs> <o:CharactersWithSpaces>3493</o:CharactersWithSpaces> <o:Version>11.6568</o:Version> </o:DocumentProperties> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:Zoom>110</w:Zoom> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
h2
{mso-style-next:Normal;
margin-top:12.0pt;
margin-right:0in;
margin-bottom:3.0pt;
margin-left:0in;
mso-pagination:widow-orphan;
page-break-after:avoid;
mso-outline-level:2;
font-size:14.0pt;
font-family:Arial;
font-weight:bold;
font-style:italic;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:blue;
text-decoration:underline;
text-underline:single;}
p
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="5122"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]-->
<meta content="MCD Application Team" name="author">
</head><body link="blue" vlink="blue">
<div class="Section1">
<p class="MsoNormal"><span style="font-family: Arial;"><o:p><br>
</o:p></span></p>
<div align="center">
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900">
<tbody>
<tr>
<td style="padding: 0cm;" valign="top">
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900">
<tbody>
<tr>
<td style="vertical-align: top;">
<p class="MsoNormal"><span style="font-size: 8pt; font-family: Arial; color: blue;"><a href="../../../../Release_Notes.html">Back to Release page</a><o:p></o:p></span></p>
</td>
</tr>
<tr style="">
<td style="padding: 1.5pt;">
<h1 style="margin-bottom: 18pt; text-align: center;" align="center"><span style="font-size: 20pt; font-family: Verdana; color: rgb(51, 102, 255);">Release
Notes for ST25R3911 driver </span><span style="font-size: 20pt; font-family: Verdana;"><o:p></o:p></span></h1>
<p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;">Copyright
2017 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;"><img alt="" id="_x0000_i1025" src="../../../../_htmresc/st_logo.png" style="border: 0px solid ; width: 86px; height: 65px;"></span><span style="font-size: 10pt;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-family: Arial; display: none;"><o:p>&nbsp;</o:p></span></p>
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900">
<tbody>
<tr style="">
<td style="padding: 0cm;" valign="top"> <span style="font-family: &quot;Times New Roman&quot;;"></span>
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update
History</span></h2>
<span style="font-size: 10pt; font-family: Verdana;"></span>
<span style="font-size: 10pt; font-family: Verdana;"></span>
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0
/ 15-March-2017</span></h3>
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
Changes<o:p></o:p></span></u></b></p>
<span style="font-size: 10pt; font-family: Verdana;"></span>
<span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span> <span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span> <span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span> <span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<ul style="list-style-type: square;">
<li><span style="font-size: 10pt; font-family: Verdana;">First
official release.</span><span style="color: rgb(0, 0, 0); font-family: Verdana; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span></li>
</ul>
<span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span><br>
</h2>
<div style="text-align: justify;"><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistribution
and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:</span><br>
</font>
<ol>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistributions
of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></font></li>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">the
documentation and/or other materials provided with the distribution.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></font></li>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Neither the
name of STMicroelectronics nor the names of its contributors may be
used to endorse or promote products derived </span><br>
</font> </li>
</ol>
<font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from this software without specific prior written permission.</span><br>
<span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span><br>
<span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">THIS
SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.</span></font> </div>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"><o:p></o:p></span></p>
<b><span style="font-size: 10pt; font-family: Verdana; color: black;"></span></b>
<div class="MsoNormal" style="text-align: center;" align="center"><span style="color: black;">
<hr align="center" size="2" width="100%"></span></div>
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt; text-align: center;" align="center"><span style="font-size: 10pt; font-family: Verdana; color: black;">For
complete documentation on </span><span style="font-size: 10pt; font-family: Verdana;">STM32<span style="color: black;">&nbsp;Microcontrollers
visit </span><u><span style="color: blue;"><a href="http://www.st.com/internet/mcu/class/1734.jsp" target="_blank">www.st.com/STM32</a></span></u></span><span style="font-size: 10pt; font-family: Verdana;"><a target="_blank" href="http://www.st.com/internet/mcu/family/141.jsp"><u><span style="color: blue;"></span></u></a></span><span style="font-size: 10pt; font-family: Verdana;"><u><span style="color: blue;"></span></u></span><span style="color: black;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size: 10pt;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body></html>

View File

@ -1,655 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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, &reg);
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_BIT_RATE_shift_txrate;
}
}
st25r3911WriteRegister(ST25R3911_REG_BIT_RATE, reg);
return ERR_NONE;
}
uint8_t st25r3911MeasurePowerSupply( uint8_t mpsv )
{
uint8_t result;
/* Set the source of direct command: Measure Power Supply Voltage */
st25r3911ChangeRegisterBits( ST25R3911_REG_REGULATOR_CONTROL, ST25R3911_REG_REGULATOR_CONTROL_mask_mpsv, mpsv );
/* Execute command: Measure Power Supply Voltage */
st25r3911ExecuteCommandAndGetResult( ST25R3911_CMD_MEASURE_VDD, ST25R3911_REG_AD_RESULT, 10, &result);
return result;
}
uint16_t st25r3911MeasureVoltage(uint8_t mpsv)
{
uint8_t result;
uint16_t mV;
result = st25r3911MeasurePowerSupply( mpsv );
mV = ((uint16_t)result) * 23U;
mV += ((((uint16_t)result) * 438U) + 500U) / 1000U;
return mV;
}
uint8_t st25r3911GetNumFIFOLastBits(void)
{
uint8_t reg;
st25r3911ReadRegister( ST25R3911_REG_FIFO_RX_STATUS2, &reg );
return ((reg & ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb) >> 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, &regVal );
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, &regDump[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;
}

View File

@ -1,601 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*
* @}
*/

View File

@ -1,457 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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
******************************************************************************
*/

View File

@ -1,816 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*
* @}
*/

View File

@ -1,249 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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;
}

View File

@ -1,250 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*
* @}
*/

View File

@ -1,165 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -1,121 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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);
}

View File

@ -1,128 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 );

View File

@ -1,111 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 <string.h>
/*
******************************************************************************
* 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 */

View File

@ -1,180 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="File-List" href="Library_files/filelist.xml">
<link rel="Edit-Time-Data" href="Library_files/editdata.mso"><!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--><title>Release Notes for X-NUCLEO-NFC03A1 STM32 Expansion Board</title><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>STMicroelectronics</o:Author> <o:LastAuthor>STMicroelectronics</o:LastAuthor> <o:Revision>37</o:Revision> <o:TotalTime>136</o:TotalTime> <o:Created>2009-02-27T19:26:00Z</o:Created> <o:LastSaved>2009-03-01T17:56:00Z</o:LastSaved> <o:Pages>1</o:Pages> <o:Words>522</o:Words> <o:Characters>2977</o:Characters> <o:Company>STMicroelectronics</o:Company> <o:Lines>24</o:Lines> <o:Paragraphs>6</o:Paragraphs> <o:CharactersWithSpaces>3493</o:CharactersWithSpaces> <o:Version>11.6568</o:Version> </o:DocumentProperties> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:Zoom>110</w:Zoom> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
h2
{mso-style-next:Normal;
margin-top:12.0pt;
margin-right:0in;
margin-bottom:3.0pt;
margin-left:0in;
mso-pagination:widow-orphan;
page-break-after:avoid;
mso-outline-level:2;
font-size:14.0pt;
font-family:Arial;
font-weight:bold;
font-style:italic;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:blue;
text-decoration:underline;
text-underline:single;}
p
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="5122"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]-->
<meta content="MCD Application Team" name="author"></head><body link="blue" vlink="blue">
<div class="Section1">
<p class="MsoNormal"><span style="font-family: Arial;"><o:p><br>
</o:p></span></p>
<div align="center">
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900">
<tbody>
<tr>
<td style="padding: 0cm;" valign="top">
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900">
<tbody>
<tr>
<td style="vertical-align: top;">
<p class="MsoNormal"><span style="font-size: 8pt; font-family: Arial; color: blue;"><a href="../../../Release_Notes.html">Back to Release page</a><o:p></o:p></span></p>
</td>
</tr>
<tr style="">
<td style="padding: 1.5pt;">
<h1 style="margin-bottom: 18pt; text-align: center;" align="center"><span style="font-size: 20pt; font-family: Verdana; color: rgb(51, 102, 255);">Release
Notes for X-NUCLEO-NFC05A1 STM32 Expansion Board</span><span style="font-size: 20pt; font-family: Verdana;"><o:p></o:p></span></h1>
<p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;">Copyright
2017 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;"><img alt="" id="_x0000_i1025" src="../../../_htmresc/st_logo.png" style="border: 0px solid ; width: 86px; height: 65px;"></span><span style="font-size: 10pt;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-family: Arial; display: none;"><o:p>&nbsp;</o:p></span></p>
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900">
<tbody>
<tr style="">
<td style="padding: 0cm;" valign="top">
<span style="font-family: &quot;Times New Roman&quot;;"></span>
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update
History</span></h2>
<span style="font-size: 10pt; font-family: Verdana;"></span>
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0
/ 15-March-2017</span></h3>
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
Changes<o:p></o:p></span></u></b></p>
<span style="font-size: 10pt; font-family: Verdana;"></span>
<span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<ul style="list-style-type: square;">
<li><span style="font-size: 10pt; font-family: Verdana;">First
official release.</span><span style="color: rgb(0, 0, 0); font-family: Verdana; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span></li>
</ul>
<span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span><br>
</h2>
<div style="text-align: justify;"><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistribution
and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:</span><br>
</font>
<ol>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistributions
of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></font></li>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">the
documentation and/or other materials provided with the distribution.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></font></li>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Neither the
name of STMicroelectronics nor the names of its contributors may be
used to endorse or promote products derived </span><br>
</font> </li>
</ol>
<font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from this software without specific prior written permission.</span><br>
<span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span><br>
<span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">THIS
SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.</span></font> </div>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"><o:p></o:p></span></p>
<b><span style="font-size: 10pt; font-family: Verdana; color: black;"></span></b>
<div class="MsoNormal" style="text-align: center;" align="center"><span style="color: black;">
<hr align="center" size="2" width="100%"></span></div>
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt; text-align: center;" align="center"><span style="font-size: 10pt; font-family: Verdana; color: black;">For
complete documentation on </span><span style="font-size: 10pt; font-family: Verdana;">STM32<span style="color: black;">&nbsp;Microcontrollers
visit </span><u><span style="color: blue;"><a href="http://www.st.com/internet/mcu/class/1734.jsp" target="_blank">www.st.com/STM32</a></span></u></span><span style="font-size: 10pt; font-family: Verdana;"><a target="_blank" href="http://www.st.com/internet/mcu/family/141.jsp"><u><span style="color: blue;"></span></u></a></span><span style="font-size: 10pt; font-family: Verdana;"><u><span style="color: blue;"></span></u></span><span style="color: black;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size: 10pt;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body></html>

View File

@ -1,145 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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);
}
}

View File

@ -1,81 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -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 */

File diff suppressed because it is too large Load Diff

View File

@ -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 <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
\page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/**
\ingroup Cortex_M0
@{
*/
/* 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
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/* following defines should be used for structure members */
#define __IM volatile const /*! Defines 'read only' structure member permissions */
#define __OM volatile /*! Defines 'write only' structure member permissions */
#define __IOM volatile /*! Defines 'read / write' structure member permissions */
/*@} end of group Cortex_M0 */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
******************************************************************************/
/**
\defgroup CMSIS_core_register Defines and Type Definitions
\brief Type definitions and defines for Cortex-M processor based devices.
*/
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_CORE Status and Control Registers
\brief Core Register type definitions.
@{
*/
/**
\brief Union type to access the Application Program Status Register (APSR).
*/
typedef union
{
struct
{
uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} APSR_Type;
/* APSR Register Definitions */
#define APSR_N_Pos 31U /*!< APSR: N Position */
#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
#define APSR_Z_Pos 30U /*!< APSR: Z Position */
#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
#define APSR_C_Pos 29U /*!< APSR: C Position */
#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
#define APSR_V_Pos 28U /*!< APSR: V Position */
#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
/**
\brief Union type to access the Interrupt Program Status Register (IPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} IPSR_Type;
/* IPSR Register Definitions */
#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
/**
\brief Union type to access the Special-Purpose Program Status Registers (xPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} xPSR_Type;
/* xPSR Register Definitions */
#define xPSR_N_Pos 31U /*!< xPSR: N Position */
#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
#define xPSR_C_Pos 29U /*!< xPSR: C Position */
#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
#define xPSR_V_Pos 28U /*!< xPSR: V Position */
#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
/**
\brief Union type to access the Control Registers (CONTROL).
*/
typedef union
{
struct
{
uint32_t _reserved0:1; /*!< bit: 0 Reserved */
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} CONTROL_Type;
/* CONTROL Register Definitions */
#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
/*@} end of group CMSIS_CORE */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
\brief Type definitions for the NVIC Registers
@{
*/
/**
\brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
typedef struct
{
__IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31U];
__IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t 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 <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0UL); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM0_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */

View File

@ -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 <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
\page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/**
\ingroup Cortex-M0+
@{
*/
/* 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
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/* following defines should be used for structure members */
#define __IM volatile const /*! Defines 'read only' structure member permissions */
#define __OM volatile /*! Defines 'write only' structure member permissions */
#define __IOM volatile /*! Defines 'read / write' structure member permissions */
/*@} end of group Cortex-M0+ */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
- 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 <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0UL); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM0PLUS_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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 <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
\page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/**
\ingroup 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
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/* following defines should be used for structure members */
#define __IM volatile const /*! Defines 'read only' structure member permissions */
#define __OM volatile /*! Defines 'write only' structure member permissions */
#define __IOM volatile /*! Defines 'read / write' structure member permissions */
/*@} end of group 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 <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0UL); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_SC000_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -1,86 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -1,196 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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:
* <br>&nbsp; ndefMessageReset()
* <br>&nbsp; ndefMessageAppend()
* <br>&nbsp; ndefMessageEncode()
* <br>&nbsp; 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 */
/**
* @}
*
*/

View File

@ -1,412 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
*/

View File

@ -1,161 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
*/

View File

@ -1,330 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
*/

View File

@ -1,203 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
*/

View File

@ -1,366 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
*/

View File

@ -1,594 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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.
* <br>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:
* <br>&nbsp; ndefPollerContextInitialization()
* <br>&nbsp; ndefPollerNdefDetect()
* <br>&nbsp; ndefPollerReadRawMessage()
* <br>&nbsp; ndefPollerWriteRawMessage()
* <br>&nbsp; ndefPollerTagFormat()
* <br>&nbsp; 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 */
/**
* @}
*
*/

View File

@ -1,340 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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
* <br>&nbsp; ndefT2TPollerContextInitialization()
* <br>&nbsp; ndefT2TPollerNdefDetect()
* <br>&nbsp; ndefT2TPollerReadRawMessage()
* <br>&nbsp; ndefT2TPollerWriteRawMessage()
* <br>&nbsp; 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 */
/**
* @}
*/

View File

@ -1,339 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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
* <br>&nbsp; ndefT3TPollerContextInitialization()
* <br>&nbsp; ndefT3TPollerNdefDetect()
* <br>&nbsp; ndefT3TPollerReadRawMessage()
* <br>&nbsp; ndefT3TPollerWriteRawMessage()
* <br>&nbsp; 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 */
/**
* @}
*/

View File

@ -1,485 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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
* <br>&nbsp; ndefT4TPollerContextInitialization()
* <br>&nbsp; ndefT4TPollerNdefDetect()
* <br>&nbsp; ndefT4TPollerReadRawMessage()
* <br>&nbsp; ndefT4TPollerWriteRawMessage()
* <br>&nbsp; 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 */
/**
* @}
*/

View File

@ -1,412 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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
* <br>&nbsp; ndefT5TPollerContextInitialization()
* <br>&nbsp; ndefT5TPollerNdefDetect()
* <br>&nbsp; ndefT5TPollerReadRawMessage()
* <br>&nbsp; ndefT5TPollerWriteRawMessage()
* <br>&nbsp; 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 */
/**
* @}
*/

View File

@ -1,299 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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;
}

View File

@ -1,627 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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;
}

View File

@ -1,512 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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;
}

View File

@ -1,321 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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;
}

View File

@ -1,766 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,588 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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;
}

View File

@ -1,835 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -1,912 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -1,933 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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 */

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -1,278 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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****/

View File

@ -1,174 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2019 STMicroelectronics</center></h2>
*
* 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****/

View File

@ -1,334 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,426 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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<<ST25R3911_REG_RX_CONF4_shift_rg2_pm /* increase digitizer window for PM */
, ST25R3911_REG_ANT_CAL_TARGET, 0xFF, 0x80 /* 90degrees */
, ST25R3911_REG_ANT_CAL_CONTROL, 0xF8, 0x00 /* trim value from calibrate antenna */
, ST25R3911_REG_AM_MOD_DEPTH_CONTROL, ST25R3911_REG_AM_MOD_DEPTH_CONTROL_am_s, ST25R3911_REG_AM_MOD_DEPTH_CONTROL_am_s /* AM modulated level is defined by RFO AM Modulated Level Def Reg, fixed setting, no automatic adjustment */
, ST25R3911_REG_FIELD_THRESHOLD, ST25R3911_REG_FIELD_THRESHOLD_mask_trg, ST25R3911_REG_FIELD_THRESHOLD_trg_75mV
, ST25R3911_REG_FIELD_THRESHOLD, ST25R3911_REG_FIELD_THRESHOLD_mask_rfe, ST25R3911_REG_FIELD_THRESHOLD_rfe_75mV
)
//****** Default Analog Configuration for Poll NFC-A Tx. ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, 0xf0 /* Used for 848 TX: very high AM to keep wave shapes */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM! */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, 0xf0 /* Used for 848 TX: very high AM to keep wave shapes */
)
//****** Default Analog Configuration for Poll NFC-A Rx. ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, 0xff, 0x18
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x2U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, 0x00 /* rx_tol Off */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x00
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x04
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x22
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x22
)
//****** Default Analog Configuration for Poll NFC-B Tx. ******/
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
//****** Default Analog Configuration for Poll NFC-B Rx. ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, 0xff, 0x18
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x04
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x04
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x22
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x22
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_1695 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x6c
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_3390 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x6c
)
//****** Default Analog Configuration for Poll NFC-F Tx. ******/
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
//****** Default Analog Configuration for Poll NFC-F Common bitrate Rx. ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, 0xff, 0x18
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x13 /* dev. from data sheet: lp 300kKz */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x0b /* dev. from data sheet: lp 600kHz */
)
//****** Default Analog Configuration for Poll NFC-V Common bitrate Tx ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00
)
//****** Default Analog Configuration for Poll NFC-V Common bitrate Rx ******/
, MODE_ENTRY_4_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x0c /* use filter settings from table 9: "Recommended for 424/484 kHz sub-carrier" */
, ST25R3911_REG_RX_CONF3, 0xff, 0x18
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
)
//****** Default Analog Configuration for Poll AP2P Common bitrate Tx. ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
//****** Default Analog Configuration for Poll AP2P Common bitrate Rx. ******/
, MODE_ENTRY_4_REG( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x45
, ST25R3911_REG_RX_CONF3, (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc), (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
)
, MODE_ENTRY_4_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x45
, ST25R3911_REG_RX_CONF3, (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc), (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0xc0
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0x00
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0x00
)
//****** Default Analog Configuration for Listen AP2P Common bitrate Tx. ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
)
//****** Default Analog Configuration for Listen AP2P Common bitrate Rx. ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x45
, ST25R3911_REG_RX_CONF3, (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc), (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc)
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0xc0
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0x00
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0x00
)
};
#endif /* ST25R3911_ANALOGCONFIG_H */

View File

@ -1,296 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,75 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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_ */

View File

@ -1,209 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,56 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -1,115 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -1,202 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */

View File

@ -1,866 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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_ */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,406 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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_DEACTIVATION) )
/*! Checks if a device is in discovery */
#define rfalNfcIsInDiscovery( st ) ( ((st)>= RFAL_NFC_STATE_START_DISCOVERY) && ((st)<RFAL_NFC_STATE_ACTIVATED) )
/*
******************************************************************************
* GLOBAL ENUMS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! Main state */
typedef enum{
RFAL_NFC_STATE_NOTINIT = 0, /*!< Not Initialized state */
RFAL_NFC_STATE_IDLE = 1, /*!< Initialize state */
RFAL_NFC_STATE_START_DISCOVERY = 2, /*!< Start Discovery loop state */
RFAL_NFC_STATE_WAKEUP_MODE = 3, /*!< Wake-Up state */
RFAL_NFC_STATE_POLL_TECHDETECT = 10, /*!< Technology Detection state */
RFAL_NFC_STATE_POLL_COLAVOIDANCE = 11, /*!< Collision Avoidance state */
RFAL_NFC_STATE_POLL_SELECT = 12, /*!< Wait for Selection state */
RFAL_NFC_STATE_POLL_ACTIVATION = 13, /*!< Activation state */
RFAL_NFC_STATE_LISTEN_TECHDETECT = 20, /*!< Listen Tech Detect */
RFAL_NFC_STATE_LISTEN_COLAVOIDANCE = 21, /*!< Listen Collision Avoidance */
RFAL_NFC_STATE_LISTEN_ACTIVATION = 22, /*!< Listen Activation state */
RFAL_NFC_STATE_LISTEN_SLEEP = 23, /*!< Listen Sleep state */
RFAL_NFC_STATE_ACTIVATED = 30, /*!< Activated state */
RFAL_NFC_STATE_DATAEXCHANGE = 31, /*!< Data Exchange Start state */
RFAL_NFC_STATE_DATAEXCHANGE_DONE = 33, /*!< Data Exchange terminated */
RFAL_NFC_STATE_DEACTIVATION = 34 /*!< Deactivation state */
}rfalNfcState;
/*! Device type */
typedef enum{
RFAL_NFC_LISTEN_TYPE_NFCA = 0, /*!< NFC-A Listener device type */
RFAL_NFC_LISTEN_TYPE_NFCB = 1, /*!< NFC-B Listener device type */
RFAL_NFC_LISTEN_TYPE_NFCF = 2, /*!< NFC-F Listener device type */
RFAL_NFC_LISTEN_TYPE_NFCV = 3, /*!< NFC-V Listener device type */
RFAL_NFC_LISTEN_TYPE_ST25TB = 4, /*!< ST25TB Listener device type */
RFAL_NFC_LISTEN_TYPE_AP2P = 5, /*!< AP2P Listener device type */
RFAL_NFC_POLL_TYPE_NFCA = 10, /*!< NFC-A Poller device type */
RFAL_NFC_POLL_TYPE_NFCB = 11, /*!< NFC-B Poller device type */
RFAL_NFC_POLL_TYPE_NFCF = 12, /*!< NFC-F Poller device type */
RFAL_NFC_POLL_TYPE_NFCV = 13, /*!< NFC-V Poller device type */
RFAL_NFC_POLL_TYPE_AP2P = 15 /*!< AP2P Poller device type */
}rfalNfcDevType;
/*! Device interface */
typedef enum{
RFAL_NFC_INTERFACE_RF = 0, /*!< RF Frame interface */
RFAL_NFC_INTERFACE_ISODEP = 1, /*!< ISO-DEP interface */
RFAL_NFC_INTERFACE_NFCDEP = 2 /*!< NFC-DEP interface */
}rfalNfcRfInterface;
/*! Device struct containing all its details */
typedef struct{
rfalNfcDevType type; /*!< Device's type */
union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one technology at a time */
rfalNfcaListenDevice nfca; /*!< NFC-A Listen Device instance */
rfalNfcbListenDevice nfcb; /*!< NFC-B Listen Device instance */
rfalNfcfListenDevice nfcf; /*!< NFC-F Listen Device instance */
rfalNfcvListenDevice nfcv; /*!< NFC-V Listen Device instance */
rfalSt25tbListenDevice st25tb; /*!< ST25TB Listen Device instance*/
}dev; /*!< Device's instance */
uint8_t *nfcid; /*!< Device's NFCID */
uint8_t nfcidLen; /*!< Device's NFCID length */
rfalNfcRfInterface rfInterface; /*!< Device's interface */
union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one protocol at a time */
rfalIsoDepDevice isoDep; /*!< ISO-DEP instance */
rfalNfcDepDevice nfcDep; /*!< NFC-DEP instance */
}proto; /*!< Device's protocol */
}rfalNfcDevice;
/*! Discovery parameters */
typedef struct{
rfalComplianceMode compMode; /*!< Compliancy mode to be used */
uint16_t techs2Find; /*!< Technologies to search for */
uint16_t totalDuration; /*!< Duration of a whole Poll + Listen cycle */
uint8_t devLimit; /*!< Max number of devices */
rfalBitRate nfcfBR; /*!< Bit rate to poll for NFC-F */
uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 to be used on the ATR_REQ/ATR_RES */
uint8_t GB[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General bytes to be used on the ATR-REQ */
uint8_t GBLen; /*!< Length of the General Bytes */
rfalBitRate ap2pBR; /*!< Bit rate to poll for AP2P */
rfalLmConfPA lmConfigPA; /*!< Configuration for Passive Listen mode NFC-A */
rfalLmConfPF lmConfigPF; /*!< Configuration for Passive Listen mode NFC-A */
void (*notifyCb)( rfalNfcState st ); /*!< Callback to Notify upper layer */
bool wakeupEnabled; /*!< Enable Wake-Up mode before polling */
bool wakeupConfigDefault; /*!< Wake-Up mode default configuration */
rfalWakeUpConfig wakeupConfig; /*!< Wake-Up mode configuration */
}rfalNfcDiscoverParam;
/*! Buffer union, only one interface is used at a time */
typedef union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one interface at a time */
uint8_t rfBuf[RFAL_NFC_RF_BUF_LEN]; /*!< RF buffer */
rfalIsoDepBufFormat isoDepBuf; /*!< ISO-DEP Tx buffer format (with header/prologue) */
rfalNfcDepBufFormat nfcDepBuf; /*!< NFC-DEP Rx buffer format (with header/prologue) */
}rfalNfcBuffer;
/*******************************************************************************/
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief RFAL NFC Worker
*
* It runs the internal state machine and runs the RFAL RF worker.
*****************************************************************************
*/
void rfalNfcWorker( void );
/*!
*****************************************************************************
* \brief RFAL NFC Initialize
*
* It initializes this module and its dependencies
*
* \return ERR_WRONG_STATE : Incorrect state for this operation
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcInitialize( void );
/*!
*****************************************************************************
* \brief RFAL NFC Discovery
*
* It set the device in Discovery state.
* In discovery it will Poll and/or Listen for the technologies configured,
* and perform Wake-up mode if configured to do so.
*
* The device list passed on disParams must not be empty.
* The number of devices on the list is indicated by the devLimit and shall
* be at >= 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,700 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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_ */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,391 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,398 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,370 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,772 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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) /*!<Max data */
#define RFAL_NFCV_BLOCKNUM_LEN 1U /*!< Block Number length on normal commands: 8 bits */
#define RFAL_NFCV_BLOCKNUM_EXTENDED_LEN 2U /*!< Block Number length on extended commands: 16 bits */
#define RFAL_NFCV_PARAM_SKIP 0U /*!< Skip proprietary Param Request */
/*! NFC-V RequestFlags ISO15693 2000 7.3.1 */
enum{
RFAL_NFCV_REQ_FLAG_DEFAULT = 0x02U, /*!< Default Request Flags */
RFAL_NFCV_REQ_FLAG_SUB_CARRIER = 0x01U, /*!< Sub Carrier flag */
RFAL_NFCV_REQ_FLAG_DATA_RATE = 0x02U, /*!< Data Rate flag */
RFAL_NFCV_REQ_FLAG_INVENTORY = 0x04U, /*!< Inventory flag */
RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT = 0x08U, /*!< Protocol Extension flag */
RFAL_NFCV_REQ_FLAG_SELECT = 0x10U, /*!< Select flag */
RFAL_NFCV_REQ_FLAG_ADDRESS = 0x20U, /*!< Address flag */
RFAL_NFCV_REQ_FLAG_OPTION = 0x40U, /*!< Option flag */
RFAL_NFCV_REQ_FLAG_RFU = 0x80U, /*!< RFU flag */
RFAL_NFCV_REQ_FLAG_AFI = 0x10U, /*!< AFI flag */
RFAL_NFCV_REQ_FLAG_NB_SLOTS = 0x20U, /*!< Number of Slots flag */
};
/*! NFC-V Response Flags ISO15693 2000 7.4.1 */
enum{
RFAL_NFCV_RES_FLAG_ERROR = 0x01U, /*!< Error flag */
RFAL_NFCV_RES_FLAG_RFU1 = 0x02U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_RFU2 = 0x04U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_EXTENSION = 0x08U, /*!< Extension flag */
RFAL_NFCV_RES_FLAG_RFU3 = 0x10U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_RFU4 = 0x20U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_RFU5 = 0x40U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_RFU6 = 0x80U /*!< RFU flag */
};
/*! NFC-V Error code ISO15693 2000 7.4.2 */
enum{
RFAL_NFCV_ERROR_CMD_NOT_SUPPORTED = 0x01U, /*!< The command is not supported, code is not recognised */
RFAL_NFCV_ERROR_CMD_NOT_RECOGNIZED = 0x02U, /*!< The command is not recognised, format error occurred */
RFAL_NFCV_ERROR_OPTION_NOT_SUPPORTED = 0x03U, /*!< The option is not supported */
RFAL_NFCV_ERROR_UNKNOWN = 0x0FU, /*!< Unknown error */
RFAL_NFCV_ERROR_BLOCK_NOT_AVALIABLE = 0x10U, /*!< The specified block is not available */
RFAL_NFCV_ERROR_BLOCK_ALREDY_LOCKED = 0x11U, /*!< The specified block is already locked */
RFAL_NFCV_ERROR_BLOCK_LOCKED = 0x12U, /*!< The specified block is locked */
RFAL_NFCV_ERROR_WRITE_FAILED = 0x13U, /*!< The specified block was not successfully programmed */
RFAL_NFCV_ERROR_BLOCK_FAILED = 0x14U /*!< The specified block was not successfully locked */
};
/*! NFC-V command set ISO15693 2000 9.1 */
enum
{
RFAL_NFCV_CMD_INVENTORY = 0x01U, /*!< INVENTORY_REQ (Inventory) command */
RFAL_NFCV_CMD_SLPV = 0x02U, /*!< SLPV_REQ (Stay quiet) command */
RFAL_NFCV_CMD_READ_SINGLE_BLOCK = 0x20U, /*!< Read single block command */
RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK = 0x21U, /*!< Write single block command */
RFAL_NFCV_CMD_LOCK_BLOCK = 0x22U, /*!< Lock block command */
RFAL_NFCV_CMD_READ_MULTIPLE_BLOCKS = 0x23U, /*!< Read multiple blocks command */
RFAL_NFCV_CMD_WRITE_MULTIPLE_BLOCKS = 0x24U, /*!< Write multiple blocks command */
RFAL_NFCV_CMD_SELECT = 0x25U, /*!< Select command */
RFAL_NFCV_CMD_RESET_TO_READY = 0x26U, /*!< Reset To Ready command */
RFAL_NFCV_CMD_GET_SYS_INFO = 0x2BU, /*!< Get System Information command */
RFAL_NFCV_CMD_EXTENDED_READ_SINGLE_BLOCK = 0x30U, /*!< Extended read single block command */
RFAL_NFCV_CMD_EXTENDED_WRITE_SINGLE_BLOCK = 0x31U, /*!< Extended write single block command */
RFAL_NFCV_CMD_EXTENDED_LOCK_SINGLE_BLOCK = 0x32U, /*!< Extended lock single block command */
RFAL_NFCV_CMD_EXTENDED_READ_MULTIPLE_BLOCK = 0x33U, /*!< Extended read multiple block command */
RFAL_NFCV_CMD_EXTENDED_WRITE_MULTIPLE_BLOCK = 0x34U, /*!< Extended read multiple block command */
RFAL_NFCV_CMD_EXTENDED_GET_SYS_INFO = 0x3BU /*!< Extended Get System Information command */
};
/*! ST25TV/ST25DV command set */
enum
{
RFAL_NFCV_CMD_READ_CONFIGURATION = 0xA0U, /*!< Read configuration command */
RFAL_NFCV_CMD_WRITE_CONFIGURATION = 0xA1U, /*!< Write configuration command */
RFAL_NFCV_CMD_SET_EAS = 0xA2U, /*!< Set EAS command */
RFAL_NFCV_CMD_RESET_EAS = 0xA3U, /*!< Reset EAS command */
RFAL_NFCV_CMD_LOCK_EAS = 0xA4U, /*!< Lock EAS command */
RFAL_NFCV_CMD_ENABLE_EAS = 0xA5U, /*!< Enable EAS command */
RFAL_NFCV_CMD_KILL = 0xA6U, /*!< Kill command */
RFAL_NFCV_CMD_WRITE_EAS_ID = 0xA7U, /*!< Write EAS ID command */
RFAL_NFCV_CMD_WRITE_EAS_CONFIG = 0xA8U, /*!< Write EAS CONFIG command */
RFAL_NFCV_CMD_MANAGE_GPO = 0xA9U, /*!< Manage GPO command */
RFAL_NFCV_CMD_WRITE_MESSAGE = 0xAAU, /*!< Write Message command */
RFAL_NFCV_CMD_READ_MESSAGE_LENGTH = 0xABU, /*!< Read Message Length command */
RFAL_NFCV_CMD_READ_MESSAGE = 0xACU, /*!< Read Message command */
RFAL_NFCV_CMD_READ_DYN_CONFIGURATION = 0xADU, /*!< Read Dynamic Configuration command */
RFAL_NFCV_CMD_WRITE_DYN_CONFIGURATION = 0xAEU, /*!< Write Dynamic Configuration command */
RFAL_NFCV_CMD_WRITE_PASSWORD = 0xB1U, /*!< Write Kill Password / Write Password command */
RFAL_NFCV_CMD_LOCK_KILL = 0xB2U, /*!< Lock Kill command */
RFAL_NFCV_CMD_PRESENT_PASSWORD = 0xB3U, /*!< Present Password command */
RFAL_NFCV_CMD_GET_RANDOM_NUMBER = 0xB4U, /*!< Get Random Number command */
RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK = 0xC0U, /*!< Fast Read single block command */
RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS = 0xC3U, /*!< Fast Read multiple blocks command */
RFAL_NFCV_CMD_FAST_EXTENDED_READ_SINGLE_BLOCK = 0xC4U, /*!< Fast Extended Read single block command */
RFAL_NFCV_CMD_FAST_EXTENDED_READ_MULTIPLE_BLOCKS = 0xC5U, /*!< Fast Extended Read multiple blocks command */
RFAL_NFCV_CMD_FAST_WRITE_MESSAGE = 0xCAU, /*!< Fast Write Message */
RFAL_NFCV_CMD_FAST_READ_MESSAGE_LENGTH = 0xCBU, /*!< Fast Read Message Length */
RFAL_NFCV_CMD_FAST_READ_MESSAGE = 0xCCU, /*!< Fast Read Message */
RFAL_NFCV_CMD_FAST_READ_DYN_CONFIGURATION = 0xCDU, /*!< Fast Read Dynamic configuration */
RFAL_NFCV_CMD_FAST_WRITE_DYN_CONFIGURATION = 0xCEU /*!< Fast Write Dynamic Configuration */
};
/*! ISO 15693 Get System info parameter request field ISO15693 2018 Table 94 */
enum
{
RFAL_NFCV_SYSINFO_DFSID = 0x01U, /*!< Get System info DFSID flag */
RFAL_NFCV_SYSINFO_AFI = 0x02U, /*!< Get System info AFI flag */
RFAL_NFCV_SYSINFO_MEMSIZE = 0x04U, /*!< Get System info MEMSIZE flag */
RFAL_NFCV_SYSINFO_ICREF = 0x08U, /*!< Get System info ICREF flag */
RFAL_NFCV_SYSINFO_MOI = 0x10U, /*!< Get System info MOI flag */
RFAL_NFCV_SYSINFO_CMDLIST = 0x20U, /*!< Get System info CMDLIST flag */
RFAL_NFCV_SYSINFO_CSI = 0x40U, /*!< Get System info CSI flag */
RFAL_NFCV_SYSINFO_REQ_ALL = 0x7FU /*!< Get System info request of all parameters */
};
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-V Number of slots Digital 2.0 9.6.1 */
typedef enum
{
RFAL_NFCV_NUM_SLOTS_1 = 0x20, /*!< Number of slots: 1 */
RFAL_NFCV_NUM_SLOTS_16 = 0x00, /*!< Number of slots: 16 */
} rfalNfcvNumSlots;
/*! NFC-V INVENTORY_RES format Digital 2.0 9.6.2 */
typedef struct
{
uint8_t RES_FLAG; /*!< Response Flags */
uint8_t DSFID; /*!< Data Storage Format Identifier */
uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< NFC-V device UID */
uint8_t crc[RFAL_CRC_LEN]; /*!< CRC */
} rfalNfcvInventoryRes;
/*! NFC-V Generic Req format */
typedef struct
{
uint8_t REQ_FLAG; /*!< Request Flags */
uint8_t CMD; /*!< Command code */
union { /* PRQA S 0750 # MISRA 19.2 - Both members are of the same type, just different names. Thus no problem can occur. */
uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< Mask Value */
uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */
}payload; /*!< Payload */
} rfalNfcvGenericReq;
/*! NFC-V Generic Response format */
typedef struct
{
uint8_t RES_FLAG; /*!< Response Flags */
uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */
} rfalNfcvGenericRes;
/*! NFC-V listener device (VICC) struct */
typedef struct
{
rfalNfcvInventoryRes InvRes; /*!< INVENTORY_RES */
bool isSleep; /*!< Device sleeping flag */
} rfalNfcvListenDevice;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize NFC-V Poller mode
*
* This methods configures RFAL RF layer to perform as a
* NFC-F Poller/RW (ISO15693) including all default timings
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Incorrect bitrate
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerInitialize( void );
/*!
*****************************************************************************
* \brief NFC-V Poller Check Presence
*
* This method checks if a NFC-V Listen device (VICC) is present on the field
* by sending an Inventory (INVENTORY_REQ)
*
* \param[out] invRes : If received, the INVENTORY_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, no listener device detectedd
* \return ERR_NONE : No error, one or more device in the field
*****************************************************************************
*/
ReturnCode rfalNfcvPollerCheckPresence( rfalNfcvInventoryRes *invRes );
/*!
*****************************************************************************
* \brief NFC-F Poller Poll
*
* This function sends to all VICCs in field the INVENTORY command with the
* given number of slots
*
* If more than one slot is used the following EOF need to be handled
* by the caller using rfalISO15693TransceiveEOFAnticollision()
*
* \param[in] nSlots : Number of Slots to be sent (1 or 16)
* \param[in] maskLen : Number bits on the Mask value
* \param[in] maskVal : location of the Mask value
* \param[out] invRes : location to place the INVENTORY_RES
* \param[out] rcvdLen : number of bits received (without collision)
*
* \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
* \return ERR_CRC : CRC error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerInventory( rfalNfcvNumSlots nSlots, uint8_t maskLen, const uint8_t *maskVal, rfalNfcvInventoryRes *invRes, uint16_t* rcvdLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Full Collision Resolution
*
* Performs a full Collision resolution as defined in Activity 2.0 9.3.7
* Once done, the devCnt will indicate how many (if any) devices have
* been identified and their details are contained on nfcvDevList
*
* \param[in] compMode : compliance mode to be performed
* \param[in] devLimit : device limit value, and size nfcaDevList
* \param[out] nfcvDevList : NFC-v listener devices list
* \param[out] devCnt : Devices found counter
*
* When compMode is set to ISO the function immediately goes to 16 slots improving
* chances to detect more than only one strong card.
*
* \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 rfalNfcvPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief NFC-V Poller Full Collision Resolution With Sleep
*
* Performs a full Collision resolution which is different from Activity 2.0 9.3.7.
* The implementation uses SLPV (StayQuiet) command to make sure all cards are found.
* Once done, the devCnt will indicate how many (if any) devices have
* been identified and their details are contained on nfcvDevList
*
* \param[in] devLimit : device limit value, and size nfcaDevList
* \param[out] nfcvDevList : NFC-v 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 rfalNfcvPollerSleepCollisionResolution( uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief NFC-V Poller Sleep
*
* This function is used to send the SLPV_REQ (Stay Quiet) command to put the VICC
* with the given UID to state QUIET so that they do not reply to more Inventory
*
* \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 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 rfalNfcvPollerSleep( uint8_t flags, const uint8_t* uid );
/*!
*****************************************************************************
* \brief NFC-V Poller Select
*
* Selects a device (VICC) by its UID
*
* \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 Selected
*
* \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 rfalNfcvPollerSelect( uint8_t flags, const uint8_t* uid );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Single Block
*
* Reads a Single Block from a device (VICC)
*
* \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 rfalNfcvPollerReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Write Single Block
*
* Writes a Single Block from a device (VICC)
*
* \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
* \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 rfalNfcvPollerWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, const uint8_t* wrData, uint8_t blockLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Multiple Blocks
*
* Reads Multiple Blocks from a device (VICC)
*
* \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 rfalNfcvPollerReadMultipleBlocks( 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 Write Multiple Blocks
*
* Reads Multiple Blocks from a device (VICC)
* In order to not limit the length of the Write multiple command, a buffer
* must be provided where the request will be composed and then sent.
*
* \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 write
* \param[in] numOfBlocks : number of consecutive blocks to write
* \param[in] txBuf : buffer where the request will be composed
* \param[in] txBufLen : length of txBuf
* \param[in] blockLen : number of bytes of a block
* \param[in] wrData : data to be written
* \param[in] wrDataLen : length of the data do be written. Must be
* aligned with number of blocks to write and
* the size 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 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 );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Lock Single Block
*
* Blocks a Single Block from a device (VICC) supporting extended commands
*
* \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
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to be locked
*
* \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 rfalNfcvPollerLockBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Lock Single Block
*
* Blocks a Single Block from a device (VICC) supporting extended commands
*
* \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
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to be locked (16 bits)
*
* \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 rfalNfcvPollerExtendedLockSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Read Single Block
*
* Reads a Single Block from a device (VICC) supporting extended commands
*
* \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 rfalNfcvPollerExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Write Single Block
*
* Writes a Single Block from a device (VICC) supporting extended commands
*
* \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
* 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 rfalNfcvPollerExtendedWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Read Multiple Blocks
*
* Reads Multiple Blocks from a device (VICC) supporting extended commands
*
* \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 rfalNfcvPollerExtendedReadMultipleBlocks( 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 Extended Write Multiple Blocks
*
* Writes Multiple Blocks from a device (VICC) supporting extended commands
* In order to not limit the length of the Write multiple command, a buffer
* must be provided where the request will be composed and then sent.
*
* \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 write (16 bits)
* \param[in] numOfBlocks : number of consecutive blocks to write (16 bits)
* \param[in] txBuf : buffer where the request will be composed
* \param[in] txBufLen : length of txBuf
* \param[in] blockLen : number of bytes of a block
* \param[in] wrData : data to be written
* \param[in] wrDataLen : length of the data do be written. Must be
* aligned with number of blocks to write and
* the size 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 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 );
/*!
*****************************************************************************
* \brief NFC-V Get System Information
*
* Sends Get System Information 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[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 rfalNfcvPollerGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Extended Get System Information
*
* Sends Extended Get System Information 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] requestField : Get System info parameter request field
* \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 rfalNfcvPollerExtendedGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t requestField, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Transceive Request
*
* Performs a generic transceive with an ISO15693 tag
*
* \param[in] cmd : NFC-V command
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] param : Prepend parameter on certain proprietary requests
* For default commands skip: RFAL_NFCV_PARAM_SKIP
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] data : command parameters append after UID
* \param[in] dataLen : command parameters Len
* \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 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 );
#endif /* RFAL_NFCV_H */
/**
* @}
*
* @}
*
* @}
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,355 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,729 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,187 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,153 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,365 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,417 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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 = &currentConfigTbl[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() */

View File

@ -1,86 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* 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;
}

Some files were not shown because too many files have changed in this diff Show More