first submission

This commit is contained in:
qiyongshuang
2023-02-01 14:19:13 +08:00
parent d534aad004
commit b79c6ac80d
3711 changed files with 745432 additions and 2 deletions
@@ -0,0 +1,164 @@
<?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="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" moduleId="org.eclipse.cdt.core.settings" name="obj">
<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 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="${cross_rm} -rf" description="" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" name="obj" parent="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release">
<folderInfo id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074." name="/" resourcePath="">
<toolChain id="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release.231146001" name="RISC-V Cross GCC" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash.1311852988" name="Create flash image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting.1983282875" name="Create extended listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize.1000761142" name="Print size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.514997414" name="Optimization Level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.size" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength.1008570639" name="Message length (-fmessage-length=0)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar.467272439" name="'char' is signed (-fsigned-char)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections.2047756949" name="Function sections (-ffunction-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections.207613650" name="Data sections (-fdata-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.1204865254" name="Debug level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level" useByScannerDiscovery="true"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format.867779652" name="Debug format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format" useByScannerDiscovery="true"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base.1900297968" name="Architecture" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.arch.rv32i" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer.387605487" name="Integer ABI" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.abi.integer.ilp32" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply.1509705449" name="Multiply extension (RVM)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed.1038505275" name="Compressed extension (RVC)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name.1218760634" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name" useByScannerDiscovery="false" value="GNU MCU RISC-V GCC" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix.103341323" name="Prefix" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix" useByScannerDiscovery="false" value="riscv-none-embed-" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c.487601824" name="C compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c" useByScannerDiscovery="false" value="gcc" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp.1062130429" name="C++ compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp" useByScannerDiscovery="false" value="g++" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar.1194282993" name="Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar" useByScannerDiscovery="false" value="ar" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy.1529355265" name="Hex/Bin converter" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy" useByScannerDiscovery="false" value="objcopy" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump.1053750745" name="Listing generator" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump" useByScannerDiscovery="false" value="objdump" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size.1441326233" name="Size command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size" useByScannerDiscovery="false" value="size" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make.550105535" name="Build command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make" useByScannerDiscovery="false" value="make" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm.719280496" name="Remove command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm" useByScannerDiscovery="false" value="rm" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id.226017994" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id" useByScannerDiscovery="false" value="512258282" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.fp.962468442" name="Floating point ABI" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.fp" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.abi.fp.none" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.codemodel.1959388532" name="Code model" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.codemodel" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.codemodel.any" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic.605693333" name="Atomic extension (RVA)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon.1559601407" name="No common unitialized (-fno-common)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw.1333590068" name="Extra Compressed extension (RVXW)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw" value="true" valueType="boolean"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform.1944008784" isAbstract="false" osList="all" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform"/>
<builder buildPath="${workspace_loc:/adv_vendor}/obj" id="ilg.gnumcueclipse.managedbuild.cross.riscv.builder.1421508906" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.builder"/>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.1244756189" name="GNU RISC-V Cross Assembler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor.1692176068" name="Use preprocessor" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths.1034038285" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths" useByScannerDiscovery="true" valueType="includePath"/>
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input.126366858" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187" name="GNU RISC-V Cross C Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths.1567947810" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/SRC/Core}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/SRC/Startup}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/SRC/Debug}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/SRC/Peripheral/inc}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/APP/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Profile/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/MESH_LIB}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/HAL/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/LIB}&quot;"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.2020844713" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.gnu99" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols">
<listOptionValue builtIn="false" value="BLE_MEMHEAP_SIZE=4096"/>
<listOptionValue builtIn="false" value="CH32V20x_D8W"/>
<listOptionValue builtIn="false" value="BLE_MAC=0"/>
<listOptionValue builtIn="false" value="HAL_KEY=1"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files.288896968" name="Include files (-include)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files" useByScannerDiscovery="true" valueType="includeFiles"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly.1594987158" name="Preprocess only (-E)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.nostdinc.698774408" name="Do not search system directories (-nostdinc)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.nostdinc" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler.1610882921" name="GNU RISC-V Cross C++ Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler"/>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.1620074387" name="GNU RISC-V Cross C Linker" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections.194760422" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths.2057340378" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths" useByScannerDiscovery="false" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;../&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/MESH_LIB}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/LIB}&quot;"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile.1390103472" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile" useByScannerDiscovery="false" valueType="stringList">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/HAL/Link.ld}&quot;"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart.913830613" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs.16994550" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.libs.1767384605" name="Libraries (-l)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.libs" useByScannerDiscovery="false" valueType="libs">
<listOptionValue builtIn="false" value="wchble"/>
<listOptionValue builtIn="false" value="m"/>
<listOptionValue builtIn="false" value="MESH"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.2019601568" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList">
<listOptionValue builtIn="false" value="--print-memory-usage"/>
</option>
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input.1859223768" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker.1947503520" name="GNU RISC-V Cross C++ Linker" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections.1689063433" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections" value="true" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths.1029177148" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;../LD&quot;"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile.1751226764" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile" valueType="stringList">
<listOptionValue builtIn="false" value="Link.ld"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart.642896175" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano.1540675679" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano" value="true" valueType="boolean"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver.1292785366" name="GNU RISC-V Cross Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver"/>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash.1801165667" name="GNU RISC-V Cross Create Flash Image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash"/>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting.1356766765" name="GNU RISC-V Cross Create Listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source.2052761852" name="Display source (--source|-S)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders.439659821" name="Display all headers (--all-headers|-x)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle.67111865" name="Demangle names (--demangle|-C)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers.1549373929" name="Display line numbers (--line-numbers|-l)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide.1298918921" name="Wide lines (--wide|-w)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble.626066923" name="Disassemble (--disassemble|-d)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble" useByScannerDiscovery="false" value="false" valueType="boolean"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize.712424314" name="GNU RISC-V Cross Print Size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format.1404031980" name="Size format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format" useByScannerDiscovery="false"/>
</tool>
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="APP"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="HAL"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="LIB"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MESH_LIB"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Profile"/>
<entry excluding="Startup/startup_ch32v20x_D8.S|Startup/startup_ch32v20x_D6.S|Ld/" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="SRC"/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="ilg.gnumcueclipse.managedbuild.packs"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="999.ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf.275846018" projectType="ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1375371130;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.1473381709">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject>
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<projectDescription>
<name>adv_vendor_self_provision</name>
<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>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>HAL</name>
<type>2</type>
<locationURI>PARENT-2-PROJECT_LOC/HAL</locationURI>
</link>
<link>
<name>LIB</name>
<type>2</type>
<locationURI>PARENT-2-PROJECT_LOC/LIB</locationURI>
</link>
<link>
<name>MESH_LIB</name>
<type>2</type>
<locationURI>PARENT-1-PROJECT_LOC/MESH_LIB</locationURI>
</link>
<link>
<name>SRC</name>
<type>2</type>
<locationURI>PARENT-3-PROJECT_LOC/SRC</locationURI>
</link>
</linkedResources>
<filteredResources>
<filter>
<id>1616659439929</id>
<name/>
<type>22</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-*.wvproj</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,771 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : app.c
* Author : WCH
* Version : V1.1
* Date : 2022/01/18
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
#include "CONFIG.h"
#include "MESH_LIB.h"
#include "app_vendor_model_srv.h"
#include "app.h"
#include "HAL.h"
/*********************************************************************
* GLOBAL TYPEDEFS
*/
#define ADV_TIMEOUT K_MINUTES(10)
#define SELENCE_ADV_ON 0x01
#define SELENCE_ADV_OF 0x00
#define APP_DELETE_LOCAL_NODE_DELAY 3200
// shall not less than APP_DELETE_LOCAL_NODE_DELAY
#define APP_DELETE_NODE_INFO_DELAY 3200
/*********************************************************************
* GLOBAL TYPEDEFS
*/
static uint8_t MESH_MEM[1024 * 2] = {0};
extern const ble_mesh_cfg_t app_mesh_cfg;
extern const struct device app_dev;
static uint8_t App_TaskID = 0; // Task ID for internal task/event processing
static uint16_t App_ProcessEvent(uint8_t task_id, uint16_t events);
static uint8_t dev_uuid[16] = {0}; // 此设备的UUID
uint8_t MACAddr[6]; // 此设备的mac
static const uint8_t self_prov_net_key[16] = {
0x00, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0x00, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
};
static const uint8_t self_prov_dev_key[16] = {
0x00, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0x00, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
};
static const uint8_t self_prov_app_key[16] = {
0x00, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
0x00, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
};
const uint16_t self_prov_net_idx = 0x0000; // 自配网所用的net key
const uint16_t self_prov_app_idx = 0x0001; // 自配网所用的app key
const uint32_t self_prov_iv_index = 0x00000000; // 自配网的iv_index
const uint16_t self_prov_addr = 0x0001; // 自配网的自身主元素地址
const uint8_t self_prov_flags = 0x00; // 是否处于key更新状态,默认为否
const uint16_t vendor_sub_addr = 0xC001; // 配置自定义模型的订阅group地址
uint16_t delete_node_info_address=0;
#if(!CONFIG_BLE_MESH_PB_GATT)
NET_BUF_SIMPLE_DEFINE_STATIC(rx_buf, 65);
#endif /* !PB_GATT */
/*********************************************************************
* LOCAL FUNCION
*/
static void cfg_srv_rsp_handler( const cfg_srv_status_t *val );
static void link_open(bt_mesh_prov_bearer_t bearer);
static void link_close(bt_mesh_prov_bearer_t bearer, uint8_t reason);
static void prov_complete(uint16_t net_idx, uint16_t addr, uint8_t flags, uint32_t iv_index);
static void cfg_cli_rsp_handler(const cfg_cli_status_t *val);
static void vendor_model_srv_rsp_handler(const vendor_model_srv_status_t *val);
static int vendor_model_srv_send(uint16_t addr, uint8_t *pData, uint16_t len);
static void prov_reset(void);
static struct bt_mesh_cfg_srv cfg_srv = {
.relay = BLE_MESH_RELAY_ENABLED,
.beacon = BLE_MESH_BEACON_ENABLED,
#if(CONFIG_BLE_MESH_FRIEND)
.frnd = BLE_MESH_FRIEND_ENABLED,
#endif
#if(CONFIG_BLE_MESH_PROXY)
.gatt_proxy = BLE_MESH_GATT_PROXY_ENABLED,
#endif
/* 默认TTL为3 */
.default_ttl = 3,
/* 底层发送数据重试7次,每次间隔10ms(不含内部随机数) */
.net_transmit = BLE_MESH_TRANSMIT(7, 10),
/* 底层转发数据重试7次,每次间隔10ms(不含内部随机数) */
.relay_retransmit = BLE_MESH_TRANSMIT(7, 10),
.handler = cfg_srv_rsp_handler,
};
/* Attention on */
void app_prov_attn_on(struct bt_mesh_model *model)
{
APP_DBG("app_prov_attn_on");
}
/* Attention off */
void app_prov_attn_off(struct bt_mesh_model *model)
{
APP_DBG("app_prov_attn_off");
}
const struct bt_mesh_health_srv_cb health_srv_cb = {
.attn_on = app_prov_attn_on,
.attn_off = app_prov_attn_off,
};
static struct bt_mesh_health_srv health_srv = {
.cb = &health_srv_cb,
};
BLE_MESH_HEALTH_PUB_DEFINE(health_pub, 8);
struct bt_mesh_cfg_cli cfg_cli = {
.handler = cfg_cli_rsp_handler,
};
uint16_t cfg_srv_keys[CONFIG_MESH_MOD_KEY_COUNT_DEF] = {BLE_MESH_KEY_UNUSED};
uint16_t cfg_srv_groups[CONFIG_MESH_MOD_GROUP_COUNT_DEF] = {BLE_MESH_ADDR_UNASSIGNED};
uint16_t cfg_cli_keys[CONFIG_MESH_MOD_KEY_COUNT_DEF] = {BLE_MESH_KEY_UNUSED};
uint16_t cfg_cli_groups[CONFIG_MESH_MOD_GROUP_COUNT_DEF] = {BLE_MESH_ADDR_UNASSIGNED};
uint16_t health_srv_keys[CONFIG_MESH_MOD_KEY_COUNT_DEF] = {BLE_MESH_KEY_UNUSED};
uint16_t health_srv_groups[CONFIG_MESH_MOD_GROUP_COUNT_DEF] = {BLE_MESH_ADDR_UNASSIGNED};
// root模型加载
static struct bt_mesh_model root_models[] = {
BLE_MESH_MODEL_CFG_SRV(cfg_srv_keys, cfg_srv_groups, &cfg_srv),
BLE_MESH_MODEL_CFG_CLI(cfg_cli_keys, cfg_cli_groups, &cfg_cli),
BLE_MESH_MODEL_HEALTH_SRV(health_srv_keys, health_srv_groups, &health_srv, &health_pub),
};
struct bt_mesh_vendor_model_srv vendor_model_srv = {
.srv_tid.trans_tid = 0xFF,
.handler = vendor_model_srv_rsp_handler,
};
uint16_t vnd_model_srv_keys[CONFIG_MESH_MOD_KEY_COUNT_DEF] = {BLE_MESH_KEY_UNUSED};
uint16_t vnd_model_srv_groups[CONFIG_MESH_MOD_GROUP_COUNT_DEF] = {BLE_MESH_ADDR_UNASSIGNED};
// 自定义模型加载
struct bt_mesh_model vnd_models[] = {
BLE_MESH_MODEL_VND_CB(CID_WCH, BLE_MESH_MODEL_ID_WCH_SRV, vnd_model_srv_op, NULL, vnd_model_srv_keys,
vnd_model_srv_groups, &vendor_model_srv, NULL),
};
// 模型组成 elements
static struct bt_mesh_elem elements[] = {
{
/* Location Descriptor (GATT Bluetooth Namespace Descriptors) */
.loc = (0),
.model_count = ARRAY_SIZE(root_models),
.models = (root_models),
.vnd_model_count = ARRAY_SIZE(vnd_models),
.vnd_models = (vnd_models),
}
};
// elements 构成 Node Composition
const struct bt_mesh_comp app_comp = {
.cid = 0x07D7, // WCH 公司id
.elem = elements,
.elem_count = ARRAY_SIZE(elements),
};
// 配网参数和回调
static const struct bt_mesh_prov app_prov = {
.uuid = dev_uuid,
.link_open = link_open,
.link_close = link_close,
.complete = prov_complete,
.reset = prov_reset,
};
// 配网者管理的节点,第0个为自己,第1,2依次为配网顺序的节点
node_t app_nodes[1] = {0};
app_mesh_manage_t app_mesh_manage;
/*********************************************************************
* GLOBAL TYPEDEFS
*/
/*********************************************************************
* @fn prov_enable
*
* @brief 使能配网功能
*
* @return none
*/
static void prov_enable(void)
{
if(bt_mesh_is_provisioned())
{
return;
}
// Make sure we're scanning for provisioning inviations
bt_mesh_scan_enable();
// Enable unprovisioned beacon sending
bt_mesh_beacon_enable();
if(CONFIG_BLE_MESH_PB_GATT)
{
bt_mesh_proxy_prov_enable();
}
}
/*********************************************************************
* @fn link_open
*
* @brief 配网时后的link打开回调
*
* @param bearer - 当前link是PB_ADV还是PB_GATT
*
* @return none
*/
static void link_open(bt_mesh_prov_bearer_t bearer)
{
APP_DBG("");
}
/*********************************************************************
* @fn link_close
*
* @brief 配网后的link关闭回调
*
* @param bearer - 当前link是PB_ADV还是PB_GATT
* @param reason - link关闭原因
*
* @return none
*/
static void link_close(bt_mesh_prov_bearer_t bearer, uint8_t reason)
{
if(reason != CLOSE_REASON_SUCCESS)
APP_DBG("reason %x", reason);
}
/*********************************************************************
* @fn node_cfg_process
*
* @brief 找一个空闲的节点,执行配置流程
*
* @param node - 空节点指针
* @param net_idx - 网络key编号
* @param addr - 网络地址
* @param num_elem - 元素数量
*
* @return node_t / NULL
*/
static node_t *node_cfg_process(node_t *node, uint16_t net_idx, uint16_t addr, uint8_t num_elem)
{
node = app_nodes;
node->net_idx = net_idx;
node->node_addr = addr;
node->elem_count = num_elem;
return node;
}
/*********************************************************************
* @fn prov_complete
*
* @brief 配网完成回调
*
* @param net_idx - 网络key的index
* @param addr - link关闭原因网络地址
* @param flags - 是否处于key refresh状态
* @param iv_index - 当前网络iv的index
*
* @return none
*/
static void prov_complete(uint16_t net_idx, uint16_t addr, uint8_t flags, uint32_t iv_index)
{
int err;
node_t *node;
APP_DBG("");
node = node_cfg_process(node, net_idx, addr, ARRAY_SIZE(elements));
if(!node)
{
APP_DBG("Unable allocate node object");
return;
}
// 如果未配置过网络信息,则退出回调后,执行配置本地网络信息流程
if( vnd_models[0].keys[0] == BLE_MESH_KEY_UNUSED )
{
tmos_start_task(App_TaskID, APP_NODE_EVT, 160);
}
}
/*********************************************************************
* @fn prov_reset
*
* @brief 复位配网功能回调
*
* @param none
*
* @return none
*/
static void prov_reset(void)
{
APP_DBG("");
prov_enable();
}
/*********************************************************************
* @fn cfg_local_net_info
*
* @brief 配置本地网络信息,由于是自配网,所以直接设置自身的密钥和订阅地址
*
* @param none
*
* @return none
*/
static void cfg_local_net_info(void)
{
uint8_t status;
// 本地直接添加应用密钥
status = bt_mesh_app_key_set(app_nodes->net_idx, self_prov_app_idx, self_prov_app_key, FALSE);
if( status )
{
APP_DBG("Unable set app key");
}
APP_DBG("lcoal app key added");
// 绑定应用密钥到沁恒自定义模型
vnd_models[0].keys[0] = (uint16_t)self_prov_app_idx;
bt_mesh_store_mod_bind(&vnd_models[0]);
APP_DBG("lcoal app key binded");
// 本地添加订阅地址
vnd_models[0].groups[0] = (uint16_t)vendor_sub_addr;
bt_mesh_store_mod_sub(&vnd_models[0]);
APP_DBG("lcoal sub addr added");
}
/*********************************************************************
* @fn cfg_srv_rsp_handler
*
* @brief config 模型服务回调
*
* @param val - 回调参数,包括命令类型、配置命令执行状态
*
* @return none
*/
static void cfg_srv_rsp_handler( const cfg_srv_status_t *val )
{
if(val->cfgHdr.status)
{
// 配置命令执行不成功
APP_DBG("warning opcode 0x%02x", val->cfgHdr.opcode);
return;
}
if(val->cfgHdr.opcode == OP_APP_KEY_ADD)
{
APP_DBG("App Key Added");
}
else if(val->cfgHdr.opcode == OP_MOD_APP_BIND)
{
APP_DBG("Vendor Model Binded");
}
else if(val->cfgHdr.opcode == OP_MOD_SUB_ADD)
{
APP_DBG("Vendor Model Subscription Set");
}
else
{
APP_DBG("Unknow opcode 0x%02x", val->cfgHdr.opcode);
}
}
/*********************************************************************
* @fn cfg_cli_rsp_handler
*
* @brief 收到cfg命令的应答回调
*
* @param val - 回调参数,包含命令类型和返回数据
*
* @return none
*/
static void cfg_cli_rsp_handler(const cfg_cli_status_t *val)
{
APP_DBG("opcode 0x%04x",val->cfgHdr.opcode);
if(val->cfgHdr.status == 0xFF)
{
APP_DBG("Opcode 0x%04x, timeout", val->cfgHdr.opcode);
}
}
/*********************************************************************
* @fn vendor_model_srv_rsp_handler
*
* @brief 自定义模型服务回调
*
* @param val - 回调参数,包括消息类型、数据内容、长度、来源地址
*
* @return none
*/
static void vendor_model_srv_rsp_handler(const vendor_model_srv_status_t *val)
{
if(val->vendor_model_srv_Hdr.status)
{
// 有应答数据传输 超时未收到应答
APP_DBG("Timeout opcode 0x%02x", val->vendor_model_srv_Hdr.opcode);
return;
}
if(val->vendor_model_srv_Hdr.opcode == OP_VENDOR_MESSAGE_TRANSPARENT_MSG)
{
// 收到透传数据
APP_DBG("len %d, data 0x%02x from 0x%04x", val->vendor_model_srv_Event.trans.len,
val->vendor_model_srv_Event.trans.pdata[0],
val->vendor_model_srv_Event.trans.addr);
tmos_memcpy(&app_mesh_manage, val->vendor_model_srv_Event.trans.pdata, val->vendor_model_srv_Event.trans.len);
switch(app_mesh_manage.data.buf[0])
{
// 判断是否为删除命令
case CMD_DELETE_NODE:
{
if(val->vendor_model_srv_Event.trans.len != DELETE_NODE_DATA_LEN)
{
APP_DBG("Delete node data err!");
return;
}
uint8_t status;
APP_DBG("receive delete cmd, send ack and start delete node delay");
app_mesh_manage.delete_node_ack.cmd = CMD_DELETE_NODE_ACK;
status = vendor_model_srv_send(val->vendor_model_srv_Event.trans.addr,
app_mesh_manage.data.buf, DELETE_NODE_ACK_DATA_LEN);
if(status)
{
APP_DBG("send ack failed %d", status);
}
// 即将删除自身,先发送CMD_DELETE_NODE_INFO命令
APP_DBG("send to all node to let them delete stored info ");
app_mesh_manage.delete_node_info.cmd = CMD_DELETE_NODE_INFO;
status = vendor_model_srv_send(BLE_MESH_ADDR_ALL_NODES,
app_mesh_manage.data.buf, DELETE_NODE_INFO_DATA_LEN);
if(status)
{
APP_DBG("send ack failed %d", status);
}
tmos_start_task(App_TaskID, APP_DELETE_LOCAL_NODE_EVT, APP_DELETE_LOCAL_NODE_DELAY);
break;
}
// 判断是否为应用层自定义删除命令应答
case CMD_DELETE_NODE_ACK:
{
if(val->vendor_model_srv_Event.trans.len != DELETE_NODE_ACK_DATA_LEN)
{
APP_DBG("Delete node ack data err!");
return;
}
tmos_stop_task(App_TaskID, APP_DELETE_NODE_TIMEOUT_EVT);
APP_DBG("Delete node complete");
break;
}
// 判断是否为有节点被删除,需要删除存储的节点信息
case CMD_DELETE_NODE_INFO:
{
if(val->vendor_model_srv_Event.trans.len != DELETE_NODE_INFO_DATA_LEN)
{
APP_DBG("Delete node info data err!");
return;
}
delete_node_info_address = val->vendor_model_srv_Event.trans.addr;
tmos_start_task(App_TaskID, APP_DELETE_NODE_INFO_EVT, APP_DELETE_NODE_INFO_DELAY);
break;
}
}
}
else if(val->vendor_model_srv_Hdr.opcode == OP_VENDOR_MESSAGE_TRANSPARENT_WRT)
{
// 收到write数据
APP_DBG("len %d, data 0x%02x from 0x%04x", val->vendor_model_srv_Event.write.len,
val->vendor_model_srv_Event.write.pdata[0],
val->vendor_model_srv_Event.write.addr);
}
else if(val->vendor_model_srv_Hdr.opcode == OP_VENDOR_MESSAGE_TRANSPARENT_IND)
{
// 发送的indicate已收到应答
}
else
{
APP_DBG("Unknow opcode 0x%02x", val->vendor_model_srv_Hdr.opcode);
}
}
/*********************************************************************
* @fn vendor_model_srv_send
*
* @brief 通过厂商自定义模型发送数据
*
* @param addr - 需要发送的目的地址
* pData - 需要发送的数据指针
* len - 需要发送的数据长度
*
* @return 参考Global_Error_Code
*/
static int vendor_model_srv_send(uint16_t addr, uint8_t *pData, uint16_t len)
{
struct send_param param = {
.app_idx = vnd_models[0].keys[0], // 此消息使用的app key,如无特定则使用第0个key
.addr = addr, // 此消息发往的目的地地址,例程为发往订阅地址,包括自己
.trans_cnt = 0x01, // 此消息的用户层发送次数
.period = K_MSEC(400), // 此消息重传的间隔,建议不小于(200+50*TTL)ms,若数据较大则建议加长
.rand = (0), // 此消息发送的随机延迟
.tid = vendor_srv_tid_get(), // tid,每个独立消息递增循环,srv使用128~191
.send_ttl = BLE_MESH_TTL_DEFAULT, // ttl,无特定则使用默认值
};
// return vendor_message_srv_indicate(&param, pData, len); // 调用自定义模型服务的有应答指示函数发送数据,默认超时2s
return vendor_message_srv_send_trans(&param, pData, len); // 或者调用自定义模型服务的透传函数发送数据,只发送,无应答机制
}
/*********************************************************************
* @fn keyPress
*
* @brief 按键回调
*
* @param keys - 按键类型
*
* @return none
*/
void keyPress(uint8_t keys)
{
APP_DBG("%d", keys);
switch(keys)
{
default:
{
// 向订阅地址发送数据
if(1)
{
int status;
uint8_t data[8] = {0, 1, 2, 3, 4, 5, 6, 7};
status = vendor_model_srv_send(vendor_sub_addr, data, 8);
if(status)
{
APP_DBG("send failed %d", status);
}
}
// 发送删除节点命令,通过应用层自定协议删除,这里假设删除地址为0x0002的节点
if(0)
{
int status;
uint16_t delete_addr = 0x0002;
APP_DBG("delete node 0x%04x",delete_addr);
app_mesh_manage.delete_node.cmd = CMD_DELETE_NODE;
app_mesh_manage.delete_node.addr[0] = delete_addr&0xFF;
app_mesh_manage.delete_node.addr[1] = (delete_addr>>8)&0xFF;
status = vendor_model_srv_send(delete_addr, app_mesh_manage.data.buf, DELETE_NODE_DATA_LEN);
if(status)
{
APP_DBG("delete failed %d", status);
}
else
{
// 定时三秒,未收到应答就超时
tmos_start_task(App_TaskID, APP_DELETE_NODE_TIMEOUT_EVT, 4800);
}
}
break;
}
}
}
/*********************************************************************
* @fn blemesh_on_sync
*
* @brief 同步mesh参数,启用对应功能,不建议修改
*
* @return none
*/
void blemesh_on_sync(void)
{
int err;
mem_info_t info;
if(tmos_memcmp(VER_MESH_LIB, VER_MESH_FILE, strlen(VER_MESH_FILE)) == FALSE)
{
PRINT("head file error...\n");
while(1);
}
info.base_addr = MESH_MEM;
info.mem_len = ARRAY_SIZE(MESH_MEM);
#if(CONFIG_BLE_MESH_FRIEND)
friend_init_register(bt_mesh_friend_init, friend_state);
#endif /* FRIEND */
#if(CONFIG_BLE_MESH_LOW_POWER)
lpn_init_register(bt_mesh_lpn_init, lpn_state);
#endif /* LPN */
FLASH_GetMACAddress(MACAddr);
tmos_memcpy(dev_uuid, MACAddr, 6);
err = bt_mesh_cfg_set(&app_mesh_cfg, &app_dev, MACAddr, &info);
if(err)
{
APP_DBG("Unable set configuration (err:%d)", err);
return;
}
hal_rf_init();
err = bt_mesh_comp_register(&app_comp);
#if(CONFIG_BLE_MESH_RELAY)
bt_mesh_relay_init();
#endif /* RELAY */
#if(CONFIG_BLE_MESH_PROXY || CONFIG_BLE_MESH_PB_GATT)
#if(CONFIG_BLE_MESH_PROXY)
bt_mesh_proxy_beacon_init_register((void *)bt_mesh_proxy_beacon_init);
gatts_notify_register(bt_mesh_gatts_notify);
proxy_gatt_enable_register(bt_mesh_proxy_gatt_enable);
#endif /* PROXY */
#if(CONFIG_BLE_MESH_PB_GATT)
proxy_prov_enable_register(bt_mesh_proxy_prov_enable);
#endif /* PB_GATT */
bt_mesh_proxy_init();
#endif /* PROXY || PB-GATT */
#if(CONFIG_BLE_MESH_PROXY_CLI)
bt_mesh_proxy_client_init(cli); //待添加
#endif /* PROXY_CLI */
bt_mesh_prov_retransmit_init();
#if(!CONFIG_BLE_MESH_PB_GATT)
adv_link_rx_buf_register(&rx_buf);
#endif /* !PB_GATT */
err = bt_mesh_prov_init(&app_prov);
bt_mesh_mod_init();
bt_mesh_net_init();
bt_mesh_trans_init();
bt_mesh_beacon_init();
bt_mesh_adv_init();
#if((CONFIG_BLE_MESH_PB_GATT) || (CONFIG_BLE_MESH_PROXY) || (CONFIG_BLE_MESH_OTA))
bt_mesh_conn_adv_init();
#endif /* PROXY || PB-GATT || OTA */
#if(CONFIG_BLE_MESH_SETTINGS)
bt_mesh_settings_init();
#endif /* SETTINGS */
#if(CONFIG_BLE_MESH_PROXY_CLI)
bt_mesh_proxy_cli_adapt_init();
#endif /* PROXY_CLI */
#if((CONFIG_BLE_MESH_PROXY) || (CONFIG_BLE_MESH_PB_GATT) || \
(CONFIG_BLE_MESH_PROXY_CLI) || (CONFIG_BLE_MESH_OTA))
bt_mesh_adapt_init();
#endif /* PROXY || PB-GATT || PROXY_CLI || OTA */
if(err)
{
APP_DBG("Initializing mesh failed (err %d)", err);
return;
}
APP_DBG("Bluetooth initialized");
#if(CONFIG_BLE_MESH_SETTINGS)
settings_load();
#endif /* SETTINGS */
if(bt_mesh_is_provisioned())
{
APP_DBG("Mesh network restored from flash");
}
else
{
err = bt_mesh_provision(self_prov_net_key, self_prov_net_idx, self_prov_flags,
self_prov_iv_index, self_prov_addr, self_prov_dev_key);
if(err)
{
APP_DBG("Self Privisioning (err %d)", err);
return;
}
}
APP_DBG("Mesh initialized");
}
/*********************************************************************
* @fn App_Init
*
* @brief 应用层初始化
*
* @return none
*/
void App_Init()
{
App_TaskID = TMOS_ProcessEventRegister(App_ProcessEvent);
vendor_model_srv_init(vnd_models);
blemesh_on_sync();
HAL_KeyInit();
HalKeyConfig(keyPress);
}
/*********************************************************************
* @fn App_ProcessEvent
*
* @brief 应用层事件处理函数
*
* @param task_id - The TMOS assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*
* @return events not processed
*/
static uint16_t App_ProcessEvent(uint8_t task_id, uint16_t events)
{
// 节点配置任务事件处理
if(events & APP_NODE_EVT)
{
cfg_local_net_info();
return (events ^ APP_NODE_EVT);
}
if(events & APP_DELETE_NODE_TIMEOUT_EVT)
{
// 通过应用层自定协议删除超时,可添加其他流程
APP_DBG("Delete node failed ");
return (events ^ APP_DELETE_NODE_TIMEOUT_EVT);
}
if(events & APP_DELETE_LOCAL_NODE_EVT)
{
// 收到删除命令,删除自身网络信息
APP_DBG("Delete local node");
// 复位自身网络状态
bt_mesh_reset();
return (events ^ APP_DELETE_LOCAL_NODE_EVT);
}
if(events & APP_DELETE_NODE_INFO_EVT)
{
// 删除已存储的被删除节点的信息
bt_mesh_delete_node_info(delete_node_info_address,app_comp.elem_count);
APP_DBG("Delete stored node info complete");
return (events ^ APP_DELETE_NODE_INFO_EVT);
}
// Discard unknown events
return 0;
}
/******************************** endfile @ main ******************************/
@@ -0,0 +1,106 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : main.c
* Author : WCH
* Version : V1.2
* Date : 2022/06/22
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
/* Header file contains */
#include "CONFIG.h"
#include "MESH_LIB.h"
#include "HAL.h"
#include "app_mesh_config.h"
#include "app.h"
/*********************************************************************
* GLOBAL TYPEDEFS
*/
__attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
#if(defined(BLE_MAC)) && (BLE_MAC == TRUE)
const uint8_t MacAddr[6] = {0x84, 0xC2, 0xE4, 0x03, 0x02, 0x02};
#endif
/*********************************************************************
* @fn bt_mesh_lib_init
*
* @brief mesh ¿â³õʼ»¯
*
* @return state
*/
uint8_t bt_mesh_lib_init(void)
{
uint8_t ret;
if(tmos_memcmp(VER_MESH_LIB, VER_MESH_FILE, strlen(VER_MESH_FILE)) == FALSE)
{
PRINT("mesh head file error...\n");
while(1);
}
ret = RF_RoleInit();
#if((CONFIG_BLE_MESH_PROXY) || \
(CONFIG_BLE_MESH_PB_GATT) || \
(CONFIG_BLE_MESH_OTA))
ret = GAPRole_PeripheralInit();
#endif /* PROXY || PB-GATT || OTA */
#if(CONFIG_BLE_MESH_PROXY_CLI)
ret = GAPRole_CentralInit();
#endif /* CONFIG_BLE_MESH_PROXY_CLI */
MeshTimer_Init();
MeshDeamon_Init();
ble_sm_alg_ecc_init();
#if(CONFIG_BLE_MESH_IV_UPDATE_TEST)
bt_mesh_iv_update_test(TRUE);
#endif
return ret;
}
/*********************************************************************
* @fn Main_Circulation
*
* @brief Main loop
*
* @return none
*/
__attribute__((section(".highcode")))
__attribute__((noinline))
void Main_Circulation(void)
{
while(1)
{
TMOS_SystemProcess();
}
}
/*********************************************************************
* @fn main
*
* @brief Main function
*
* @return none
*/
int main(void)
{
Delay_Init();
#ifdef DEBUG
USART_Printf_Init( 115200 );
#endif
PRINT("%s\n", VER_LIB);
WCHBLE_Init();
HAL_Init();
bt_mesh_lib_init();
App_Init();
Main_Circulation();
}
/******************************** endfile @ main ******************************/
@@ -0,0 +1,182 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : app_mesh_config.c
* Author : WCH
* Version : V1.2
* Date : 2022/06/22
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
/* Header file contains */
#include "CONFIG.h"
#include "app_mesh_config.h"
#include "MESH_LIB.h"
/*********************************************************************
* GLOBAL TYPEDEFS
*/
const ble_mesh_cfg_t app_mesh_cfg = {
.common_cfg.adv_buf_count = CONFIG_MESH_ADV_BUF_COUNT_DEF,
.common_cfg.rpl_count = CONFIG_MESH_RPL_COUNT_DEF,
.common_cfg.allow_rpl_cycle = CONFIG_MESH_ALLOW_RPL_CYCLE,
.common_cfg.allow_same_addr = CONFIG_MESH_ALLOW_SAME_ADDR,
.common_cfg.ivu_divider = CONFIG_MESH_IVU_DIVIDER_DEF,
.common_cfg.mod_key_count = CONFIG_MESH_MOD_KEY_COUNT_DEF,
.common_cfg.mod_group_count = CONFIG_MESH_MOD_GROUP_COUNT_DEF,
.proxy_cfg.pxyfilter_count = CONFIG_MESH_PROXY_FILTER_DEF,
.net_cfg.msgcache_count = CONFIG_MESH_MSG_CACHE_DEF,
.net_cfg.subnet_count = CONFIG_MESH_SUBNET_COUNT_DEF,
.net_cfg.appkey_count = CONFIG_MESH_APPKEY_COUNT_DEF,
.net_cfg.unseg_length = CONFIG_MESH_UNSEG_LENGTH_DEF,
.net_cfg.txseg_max = CONFIG_MESH_TX_SEG_DEF,
.net_cfg.txseg_count = CONFIG_MESH_TX_SEG_COUNT_DEF,
.net_cfg.rxseg_count = CONFIG_MESH_RX_SEG_COUNT_DEF,
.net_cfg.rxsdu_max = CONFIG_MESH_RX_SDU_DEF,
.net_cfg.label_count = CONFIG_MESH_LABEL_COUNT_DEF,
.store_cfg.seq_store_rate = CONFIG_MESH_SEQ_STORE_RATE_DEF,
.store_cfg.rpl_store_rate = CONFIG_MESH_RPL_STORE_RATE_DEF,
.store_cfg.store_rate = CONFIG_MESH_STORE_RATE_DEF,
.friend_cfg.frndseg_rx = CONFIG_MESH_FRIEND_SEG_RX_COUNT_DEF,
.friend_cfg.frndsub_size = CONFIG_MESH_FRIEND_SUB_SIZE_DEF,
.friend_cfg.frndlpn_count = CONFIG_MESH_FRIEND_LPN_COUNT_DEF,
.friend_cfg.frndqueue_size = CONFIG_MESH_QUEUE_SIZE_DEF,
.friend_cfg.frndrecv_win = CONFIG_MESH_FRIEND_RECV_WIN_DEF,
.lpn_cfg.lpnmin_size = CONFIG_MESH_LPN_REQ_QUEUE_SIZE_DEF,
.lpn_cfg.lpnrssi_factor = 0,
.lpn_cfg.lpnrecv_factor = 0,
.lpn_cfg.lpnpoll_interval = CONFIG_MESH_LPN_POLLINTERVAL_DEF,
.lpn_cfg.lpnpoll_timeout = CONFIG_MESH_LPN_POLLTIMEOUT_DEF,
.lpn_cfg.lpnrecv_delay = CONFIG_MESH_LPN_RECV_DELAY_DEF,
.lpn_cfg.lpnretry_timeout = CONFIG_MESH_RETRY_TIMEOUT_DEF,
.prov_cfg.node_count = CONFIG_MESH_PROV_NODE_COUNT_DEF,
.rf_cfg.rf_accessAddress = CONFIG_MESH_RF_ACCESSADDRESS,
.rf_cfg.rf_channel_37 = CONFIG_MESH_RF_CHANNEL_37,
.rf_cfg.rf_channel_38 = CONFIG_MESH_RF_CHANNEL_38,
.rf_cfg.rf_channel_39 = CONFIG_MESH_RF_CHANNEL_39,
};
/*********************************************************************
* @fn read_flash
*
* @brief read flash
*
* @param offset - 地址偏移
* @param data - 数据指针
* @param len - 长度
*
* @return always success
*/
int read_flash(int offset, void *data, unsigned int len)
{
tmos_memcpy(data, (uint8_t*)offset, len);
return 0;
}
/*********************************************************************
* @fn write_flash
*
* @brief write flash
*
* @param offset - 地址偏移
* @param data - 数据指针
* @param len - 长度
*
* @return state
*/
int write_flash(int offset, const void *data, unsigned int len)
{
FLASH_Status status = FLASH_COMPLETE;
__attribute__((aligned(4))) uint8_t vec[64]={0};
uint8_t i;
if(len > sizeof(vec))
{
return -E2BIG;
}
memcpy(vec, data, len);
FLASH_Unlock();
for( i=0; i<(len+1)/2; i++)
{
status = FLASH_ProgramHalfWord(offset+i*2,vec[i*2]|(vec[i*2+1]<<8));
if( status != FLASH_COMPLETE )
{
return -ETIMEDOUT;
}
}
FLASH_Lock();
return NOERR;
}
/*********************************************************************
* @fn erase_flash
*
* @brief erase flash
*
* @param offset - 地址偏移
* @param len - 长度
*
* @return state
*/
int erase_flash(int offset, unsigned int len)
{
FLASH_Status status = FLASH_COMPLETE;
if(len != 4096)
{
return -EINVAL;
}
FLASH_Unlock();
status = FLASH_ErasePage(offset);
FLASH_Lock();
if(status == FLASH_COMPLETE)
{
return NOERR;
}
else
{
return -ETIMEDOUT;
}
}
/*********************************************************************
* @fn flash_write_protection
*
* @brief no used
*
* @param enable - no uesd
*
* @return always success
*/
int flash_write_protection(BOOL enable)
{
return 0;
}
const struct device app_dev = {
.api = {
.read = read_flash,
.write = write_flash,
.erase = erase_flash,
.write_protection = flash_write_protection,
},
.info = {
.nvs_sector_cnt = CONFIG_MESH_SECTOR_COUNT_DEF,
.nvs_write_size = sizeof(int),
.nvs_sector_size = CONFIG_MESH_SECTOR_SIZE_DEF,
.nvs_store_baddr = CONFIG_MESH_NVS_ADDR_DEF,
},
};
/******************************** endfile @ main ******************************/
@@ -0,0 +1,747 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : app_vendor_model_srv.c
* Author : WCH
* Version : V1.1
* Date : 2022/01/18
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/******************************************************************************/
#include "CONFIG.h"
#include "app_mesh_config.h"
#include "app_vendor_model_srv.h"
/*********************************************************************
* GLOBAL TYPEDEFS
*/
// 应用层最大发送长度,不分包最大为CONFIG_MESH_UNSEG_LENGTH_DEF,分包最大为CONFIG_MESH_TX_SEG_DEF*BLE_MESH_APP_SEG_SDU_MAX-8(依据RAM使用情况决定)
#define APP_MAX_TX_SIZE MAX(CONFIG_MESH_UNSEG_LENGTH_DEF, CONFIG_MESH_TX_SEG_DEF *BLE_MESH_APP_SEG_SDU_MAX - 8)
static uint8_t vendor_model_srv_TaskID = 0; // Task ID for internal task/event processing
static uint8_t srv_send_tid = 128;
static int32_t srv_msg_timeout = K_SECONDS(2); //有应答的数据传输超时时间,默认2秒
static struct net_buf ind_buf;
static struct bt_mesh_indicate indicate = {
.buf = &ind_buf,
};
static struct net_buf srv_trans_buf;
static struct bt_mesh_trans srv_trans = {
.buf = &srv_trans_buf,
};
static struct bt_mesh_vendor_model_srv *vendor_model_srv;
static void ind_reset(struct bt_mesh_indicate *ind, int err);
static uint16_t vendor_model_srv_ProcessEvent(uint8_t task_id, uint16_t events);
static void ind_reset(struct bt_mesh_indicate *ind, int err);
static void adv_srv_trans_send(void);
/*********************************************************************
* @fn read_led_state
*
* @brief 获取当前灯状态.
*
* @param led_pin - 引脚.
*
* @return 灯状态
*/
BOOL read_led_state(uint32_t led_pin)
{
return (GPIO_ReadOutputDataBit(MSG_GPIO, led_pin) > 0) ? 0 : 1;
}
/*********************************************************************
* @fn set_led_state
*
* @brief 设置当前灯状态.
*
* @param led_pin - 引脚.
* @param on - 状态.
*
* @return none
*/
void set_led_state(uint32_t led_pin, BOOL on)
{
RCC_APB2PeriphClockCmd(MSG_PCENR, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = led_pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(MSG_GPIO, &GPIO_InitStructure);
on ? GPIO_WriteBit(MSG_GPIO, led_pin, Bit_RESET) : GPIO_WriteBit(MSG_GPIO, led_pin, Bit_SET);
}
/*********************************************************************
* @fn toggle_led_state
*
* @brief 翻转当前灯状态
*
* @param led_pin - 引脚.
*
* @return none
*/
void toggle_led_state(uint32_t led_pin)
{
RCC_APB2PeriphClockCmd(MSG_PCENR, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = led_pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_WriteBit(MSG_GPIO, led_pin, Bit_SET-GPIO_ReadOutputDataBit(MSG_GPIO, led_pin));
}
/*********************************************************************
* @fn vendor_srv_tid_get
*
* @brief TID selection method
*
* @return TID
*/
uint8_t vendor_srv_tid_get(void)
{
srv_send_tid++;
if(srv_send_tid > 191)
srv_send_tid = 128;
return srv_send_tid;
}
/*********************************************************************
* @fn vendor_model_srv_reset
*
* @brief 复位厂商模型服务,取消所有正在发送的流程
*
* @return none
*/
static void vendor_model_srv_reset(void)
{
APP_DBG("");
vendor_model_srv->op_pending = 0U;
vendor_model_srv->op_req = 0U;
if(indicate.buf->__buf)
{
ind_reset(&indicate, -ECANCELED);
}
if(srv_trans.buf->__buf)
{
vendor_message_srv_trans_reset();
}
tmos_stop_task(vendor_model_srv_TaskID, VENDOR_MODEL_SRV_RSP_TIMEOUT_EVT);
tmos_stop_task(vendor_model_srv_TaskID, VENDOR_MODEL_SRV_INDICATE_EVT);
}
/*********************************************************************
* @fn vendor_model_srv_rsp_recv
*
* @brief 调用应用层传入的回调
*
* @param val - 回调参数,包括消息类型、数据内容、长度、来源地址
* @param statu - 状态
*
* @return none
*/
static void vendor_model_srv_rsp_recv(vendor_model_srv_status_t *val,
uint8_t status)
{
if(vendor_model_srv == NULL || (!vendor_model_srv->op_req))
{
return;
}
val->vendor_model_srv_Hdr.opcode = vendor_model_srv->op_req;
val->vendor_model_srv_Hdr.status = status;
vendor_model_srv_reset();
if(vendor_model_srv->handler)
{
vendor_model_srv->handler(val);
}
}
/*********************************************************************
* @fn vendor_model_srv_wait
*
* @brief 默认两秒超时后通知应用层
*
* @return 参考BLE_LIB err code
*/
static int vendor_model_srv_wait(void)
{
int err;
err = tmos_start_task(vendor_model_srv_TaskID,
VENDOR_MODEL_SRV_RSP_TIMEOUT_EVT, srv_msg_timeout);
return err;
}
/*********************************************************************
* @fn vendor_model_srv_prepare
*
* @brief 预发送,记录当前消息类型
*
* @param op_req - 发出去的消息类型
* @param op - 期待收到的消息类型
*
* @return 错误码
*/
static int vendor_model_srv_prepare(uint32_t op_req, uint32_t op)
{
if(!vendor_model_srv)
{
APP_DBG("No available Configuration Client context!");
return -EINVAL;
}
if(vendor_model_srv->op_pending)
{
APP_DBG("Another synchronous operation pending");
return -EBUSY;
}
vendor_model_srv->op_req = op_req;
vendor_model_srv->op_pending = op;
return 0;
}
/*********************************************************************
* @fn vendor_srv_sync_handler
*
* @brief 通知应用层当前op_code超时了
*
* @return none
*/
static void vendor_srv_sync_handler(void)
{
vendor_model_srv_status_t vendor_model_srv_status;
tmos_memset(&vendor_model_srv_status, 0,
sizeof(vendor_model_srv_status_t));
ind_reset(&indicate, -ETIMEDOUT);
vendor_model_srv_rsp_recv(&vendor_model_srv_status, 0xFF);
}
/*********************************************************************
* @fn vendor_message_srv_confirm
*
* @brief 发送vendor_message_srv_confirm - 该消息用于Vendor Model Server回复给Vendor Model Client,
* 用于表示已收到Vendor Model Client发出的 Write
*
* @param model - 模型参数.
* @param ctx - 数据参数.
* @param buf - 数据内容.
*
* @return none
*/
static void vendor_message_srv_confirm(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
{
NET_BUF_SIMPLE_DEFINE(msg, APP_MAX_TX_SIZE + 8);
uint8_t recv_tid;
int err;
recv_tid = net_buf_simple_pull_u8(buf);
APP_DBG("tid 0x%02x ", recv_tid);
/* Init indication opcode */
bt_mesh_model_msg_init(&msg, OP_VENDOR_MESSAGE_TRANSPARENT_CFM);
/* Add tid field */
net_buf_simple_add_u8(&msg, recv_tid);
err = bt_mesh_model_send(model, ctx, &msg, NULL, NULL);
if(err)
{
APP_DBG("#mesh-onoff STATUS: send status failed: %d", err);
}
}
/*********************************************************************
* @fn vendor_message_srv_trans
*
* @brief 收到透传数据
*
* @param model - 模型参数.
* @param ctx - 数据参数.
* @param buf - 数据内容.
*
* @return none
*/
static void vendor_message_srv_trans(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
{
vendor_model_srv_status_t vendor_model_srv_status;
uint8_t *pData = buf->data;
uint16_t len = buf->len;
if((pData[0] != vendor_model_srv->srv_tid.trans_tid) ||
(ctx->addr != vendor_model_srv->srv_tid.trans_addr))
{
vendor_model_srv->srv_tid.trans_tid = pData[0];
vendor_model_srv->srv_tid.trans_addr = ctx->addr;
// 开头为tid
pData++;
len--;
vendor_model_srv_status.vendor_model_srv_Hdr.opcode =
OP_VENDOR_MESSAGE_TRANSPARENT_MSG;
vendor_model_srv_status.vendor_model_srv_Hdr.status = 0;
vendor_model_srv_status.vendor_model_srv_Event.trans.pdata = pData;
vendor_model_srv_status.vendor_model_srv_Event.trans.len = len;
vendor_model_srv_status.vendor_model_srv_Event.trans.addr = ctx->addr;
if(vendor_model_srv->handler)
{
vendor_model_srv->handler(&vendor_model_srv_status);
}
}
}
/*********************************************************************
* @fn vendor_message_srv_write
*
* @brief 收到write 数据,随后应答vendor_message_srv_confirm
*
* @param model - 模型参数.
* @param ctx - 数据参数.
* @param buf - 数据内容.
*
* @return none
*/
static void vendor_message_srv_write(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
{
vendor_model_srv_status_t vendor_model_srv_status;
uint8_t *pData = buf->data;
uint16_t len = buf->len;
if((pData[0] != vendor_model_srv->srv_tid.write_tid) ||
(ctx->addr != vendor_model_srv->srv_tid.write_addr) )
{
vendor_model_srv->srv_tid.write_tid = pData[0];
vendor_model_srv->srv_tid.write_addr = ctx->addr;
// 开头为tid
pData++;
len--;
vendor_model_srv_status.vendor_model_srv_Hdr.opcode =
OP_VENDOR_MESSAGE_TRANSPARENT_WRT;
vendor_model_srv_status.vendor_model_srv_Hdr.status = 0;
vendor_model_srv_status.vendor_model_srv_Event.write.pdata = pData;
vendor_model_srv_status.vendor_model_srv_Event.write.len = len;
vendor_model_srv_status.vendor_model_srv_Event.write.addr = ctx->addr;
if(vendor_model_srv->handler)
{
vendor_model_srv->handler(&vendor_model_srv_status);
}
}
vendor_message_srv_confirm(model, ctx, buf);
}
/*********************************************************************
* @fn vendor_message_srv_ack
*
* @brief 收到vendor_message_srv_ack - 该消息用于Vendor Model Client回复给Vendor Model Server,
* 用于表示已收到Vendor Model Server发出的Indication
*
* @param model - 模型参数.
* @param ctx - 数据参数.
* @param buf - 数据内容.
*
* @return none
*/
static void vendor_message_srv_ack(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
{
uint8_t recv_tid;
vendor_model_srv_status_t vendor_model_srv_status;
recv_tid = net_buf_simple_pull_u8(buf);
APP_DBG("src: 0x%04x dst: 0x%04x tid 0x%02x rssi: %d", ctx->addr,
ctx->recv_dst, recv_tid, ctx->recv_rssi);
if(indicate.param.tid == recv_tid)
{
ind_reset(&indicate, 0);
vendor_model_srv_rsp_recv(&vendor_model_srv_status, 0);
}
}
// opcode 对应的处理函数
const struct bt_mesh_model_op vnd_model_srv_op[] = {
{OP_VENDOR_MESSAGE_TRANSPARENT_MSG, 0, vendor_message_srv_trans},
{OP_VENDOR_MESSAGE_TRANSPARENT_WRT, 0, vendor_message_srv_write},
{OP_VENDOR_MESSAGE_TRANSPARENT_ACK, 0, vendor_message_srv_ack},
BLE_MESH_MODEL_OP_END,
};
/*********************************************************************
* @fn vendor_message_srv_indicate
*
* @brief indicate,有应答传输数据通道
*
* @param param - 发送参数.
* @param pData - 数据指针.
* @param len - 数据长度,最大为(APP_MAX_TX_SIZE).
*
* @return 参考Global_Error_Code
*/
int vendor_message_srv_indicate(struct send_param *param, uint8_t *pData,
uint16_t len)
{
if(!param->addr)
return -EINVAL;
if(indicate.buf->__buf)
return -EBUSY;
if(len > (APP_MAX_TX_SIZE))
return -EINVAL;
indicate.buf->__buf = tmos_msg_allocate(len + 8);
if(!(indicate.buf->__buf))
{
APP_DBG("No enough space!");
return -ENOMEM;
}
indicate.buf->size = len + 4;
/* Init indication opcode */
bt_mesh_model_msg_init(&(indicate.buf->b),
OP_VENDOR_MESSAGE_TRANSPARENT_IND);
/* Add tid field */
net_buf_simple_add_u8(&(indicate.buf->b), param->tid);
net_buf_simple_add_mem(&(indicate.buf->b), pData, len);
memcpy(&indicate.param, param, sizeof(struct send_param));
vendor_model_srv_prepare(OP_VENDOR_MESSAGE_TRANSPARENT_IND,
OP_VENDOR_MESSAGE_TRANSPARENT_ACK);
tmos_start_task(vendor_model_srv_TaskID, VENDOR_MODEL_SRV_INDICATE_EVT,
param->rand);
vendor_model_srv_wait();
return 0;
}
/*********************************************************************
* @fn vendor_message_srv_send_trans
*
* @brief send_trans,透传数据通道
*
* @param param - 发送参数.
* @param pData - 数据指针.
* @param len - 数据长度,最大为(APP_MAX_TX_SIZE).
*
* @return 参考Global_Error_Code
*/
int vendor_message_srv_send_trans(struct send_param *param, uint8_t *pData,
uint16_t len)
{
if(!param->addr)
return -EINVAL;
if(srv_trans.buf->__buf)
return -EBUSY;
if(len > (APP_MAX_TX_SIZE))
return -EINVAL;
srv_trans.buf->__buf = tmos_msg_allocate(len + 8);
if(!(srv_trans.buf->__buf))
{
APP_DBG("No enough space!");
return -ENOMEM;
}
srv_trans.buf->size = len + 4;
/* Init indication opcode */
bt_mesh_model_msg_init(&(srv_trans.buf->b),
OP_VENDOR_MESSAGE_TRANSPARENT_MSG);
/* Add tid field */
net_buf_simple_add_u8(&(srv_trans.buf->b), param->tid);
net_buf_simple_add_mem(&(srv_trans.buf->b), pData, len);
memcpy(&srv_trans.param, param, sizeof(struct send_param));
if(param->rand)
{
// 延迟发送
tmos_start_task(vendor_model_srv_TaskID, VENDOR_MODEL_SRV_TRANS_EVT,
param->rand);
}
else
{
// 直接发送
adv_srv_trans_send();
}
return 0;
}
/*********************************************************************
* @fn vendor_message_srv_trans_reset
*
* @brief 取消发送trans数据的任务,释放缓存
*
* @return none
*/
void vendor_message_srv_trans_reset(void)
{
tmos_msg_deallocate(srv_trans.buf->__buf);
srv_trans.buf->__buf = NULL;
tmos_stop_task(vendor_model_srv_TaskID, VENDOR_MODEL_SRV_TRANS_EVT);
}
/*********************************************************************
* @fn ind_reset
*
* @brief 调用indicate发送完成回调,释放缓存
*
* @param ind - 需要释放的indicate.
* @param err - 错误状态.
*
* @return none
*/
static void ind_reset(struct bt_mesh_indicate *ind, int err)
{
if(ind->param.cb && ind->param.cb->end)
{
ind->param.cb->end(err, ind->param.cb_data);
}
tmos_msg_deallocate(ind->buf->__buf);
ind->buf->__buf = NULL;
}
/*********************************************************************
* @fn ind_start
*
* @brief 发送 indicate 开始回调
*
* @param duration - 此次发送持续的时长(ms).
* @param err - 错误状态.
* @param cb_data - 错误状态发送时填写的回调参数.
*
* @return none
*/
static void ind_start(uint16_t duration, int err, void *cb_data)
{
struct bt_mesh_indicate *ind = cb_data;
if(ind->buf->__buf == NULL)
{
return;
}
if(err)
{
APP_DBG("Unable send indicate (err:%d)", err);
tmos_start_task(vendor_model_srv_TaskID, VENDOR_MODEL_SRV_INDICATE_EVT,
K_MSEC(100));
return;
}
}
/*********************************************************************
* @fn ind_end
*
* @brief 发送 indicate 结束回调
*
* @param err - 错误状态.
* @param cb_data - 错误状态发送时填写的回调参数.
*
* @return none
*/
static void ind_end(int err, void *cb_data)
{
struct bt_mesh_indicate *ind = cb_data;
if(ind->buf->__buf == NULL)
{
return;
}
tmos_start_task(vendor_model_srv_TaskID, VENDOR_MODEL_SRV_INDICATE_EVT,
ind->param.period);
}
// 发送 indicate 回调结构体
const struct bt_mesh_send_cb ind_cb = {
.start = ind_start,
.end = ind_end,
};
/*********************************************************************
* @fn adv_ind_send
*
* @brief 发送 indicate
*
* @return none
*/
static void adv_ind_send(void)
{
int err;
NET_BUF_SIMPLE_DEFINE(msg, APP_MAX_TX_SIZE + 8);
struct bt_mesh_msg_ctx ctx = {
.net_idx = indicate.param.net_idx ? indicate.param.net_idx : BLE_MESH_KEY_ANY,
.app_idx = indicate.param.app_idx ? indicate.param.app_idx : vendor_model_srv->model->keys[0],
.addr = indicate.param.addr,
};
if(indicate.buf->__buf == NULL)
{
APP_DBG("NULL buf");
return;
}
if(indicate.param.trans_cnt == 0)
{
// APP_DBG("indicate.buf.trans_cnt over");
ind_reset(&indicate, -ETIMEDOUT);
return;
}
indicate.param.trans_cnt--;
ctx.send_ttl = indicate.param.send_ttl;
net_buf_simple_add_mem(&msg, indicate.buf->data, indicate.buf->len);
err = bt_mesh_model_send(vendor_model_srv->model, &ctx, &msg, &ind_cb,
&indicate);
if(err)
{
APP_DBG("Unable send model message (err:%d)", err);
ind_reset(&indicate, err);
return;
}
}
/*********************************************************************
* @fn adv_srv_trans_send
*
* @brief 发送 透传 srv_trans
*
* @return none
*/
static void adv_srv_trans_send(void)
{
int err;
NET_BUF_SIMPLE_DEFINE(msg, APP_MAX_TX_SIZE + 8);
struct bt_mesh_msg_ctx ctx = {
.net_idx = srv_trans.param.net_idx ? srv_trans.param.net_idx : BLE_MESH_KEY_ANY,
.app_idx = srv_trans.param.app_idx ? srv_trans.param.app_idx : vendor_model_srv->model->keys[0],
.addr = srv_trans.param.addr,
};
if(srv_trans.buf->__buf == NULL)
{
APP_DBG("NULL buf");
return;
}
if(srv_trans.param.trans_cnt == 0)
{
// APP_DBG("srv_trans.buf.trans_cnt over");
tmos_msg_deallocate(srv_trans.buf->__buf);
srv_trans.buf->__buf = NULL;
return;
}
srv_trans.param.trans_cnt--;
ctx.send_ttl = srv_trans.param.send_ttl;
net_buf_simple_add_mem(&msg, srv_trans.buf->data, srv_trans.buf->len);
err = bt_mesh_model_send(vendor_model_srv->model, &ctx, &msg, NULL, NULL);
if(err)
{
APP_DBG("Unable send model message (err:%d)", err);
tmos_msg_deallocate(srv_trans.buf->__buf);
srv_trans.buf->__buf = NULL;
return;
}
if(srv_trans.param.trans_cnt == 0)
{
// APP_DBG("srv_trans.buf.trans_cnt over");
tmos_msg_deallocate(srv_trans.buf->__buf);
srv_trans.buf->__buf = NULL;
return;
}
// 重传
tmos_start_task(vendor_model_srv_TaskID, VENDOR_MODEL_SRV_TRANS_EVT,
srv_trans.param.period);
}
/*********************************************************************
* @fn vendor_model_srv_init
*
* @brief 厂商模型初始化
*
* @param model - 指向厂商模型结构体
*
* @return always SUCCESS
*/
int vendor_model_srv_init(struct bt_mesh_model *model)
{
vendor_model_srv = model->user_data;
vendor_model_srv->model = model;
vendor_model_srv_TaskID = TMOS_ProcessEventRegister(
vendor_model_srv_ProcessEvent);
return 0;
}
/*********************************************************************
* @fn vendor_model_srv_ProcessEvent
*
* @brief 厂商模型事件处理函数
*
* @param task_id - The TMOS assigned task ID.
* @param events - events to process. This is a bit map and can
* contain more than one event.
*
* @return events not processed
*/
static uint16_t vendor_model_srv_ProcessEvent(uint8_t task_id, uint16_t events)
{
if(events & VENDOR_MODEL_SRV_INDICATE_EVT)
{
adv_ind_send();
return (events ^ VENDOR_MODEL_SRV_INDICATE_EVT);
}
if(events & VENDOR_MODEL_SRV_RSP_TIMEOUT_EVT)
{
vendor_srv_sync_handler();
return (events ^ VENDOR_MODEL_SRV_RSP_TIMEOUT_EVT);
}
if(events & VENDOR_MODEL_SRV_TRANS_EVT)
{
adv_srv_trans_send();
return (events ^ VENDOR_MODEL_SRV_TRANS_EVT);
}
// Discard unknown events
return 0;
}
/******************************** endfile @ main ******************************/
@@ -0,0 +1,74 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_it.c
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : Main Interrupt Service Routines.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ch32v20x_it.h"
#include "CONFIG.h"
/*********************************************************************
* LOCAL FUNCTIONS
*/
void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void BB_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void LLE_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
/*********************************************************************
* @fn NMI_Handler
*
* @brief This function handles NMI exception.
*
* @return None
*/
void NMI_Handler(void)
{
}
/*********************************************************************
* @fn HardFault_Handler
*
* @brief This function handles Hard Fault exception.
*
* @return None
*/
void HardFault_Handler(void)
{
while(1)
{
}
}
/*********************************************************************
* @fn BB_IRQHandler
*
* @brief BB Interrupt for BLE.
*
* @return None
*/
void BB_IRQHandler(void)
{
BB_IRQLibHandler();
}
/*********************************************************************
* @fn LLE_IRQHandler
*
* @brief LLE Interrupt for BLE.
*
* @return None
*/
void LLE_IRQHandler(void)
{
LLE_IRQLibHandler();
}
@@ -0,0 +1,102 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : app.h
* Author : WCH
* Version : V1.1
* Date : 2021/11/18
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef app_H
#define app_H
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
#define APP_NODE_EVT (1 << 0)
#define APP_DELETE_NODE_TIMEOUT_EVT (1 << 1)
#define APP_DELETE_LOCAL_NODE_EVT (1 << 2)
#define APP_DELETE_NODE_INFO_EVT (1 << 3)
#define CMD_PROVISION 0xA1
#define CMD_DELETE_NODE 0xA2
#define CMD_DELETE_NODE_ACK 0x82
#define CMD_DELETE_NODE_INFO 0xA3
#define CMD_LOCAL_RESET 0xAF
#define PERIPHERAL_CMD_LEN 1
#define PROVISION_NET_KEY_LEN 16
#define ADDRESS_LEN 2
// 通过ble接收到的配网参数,包含 1字节命令码+16字节网络密钥+2字节网络地址
#define PROVISION_DATA_LEN (PERIPHERAL_CMD_LEN + PROVISION_NET_KEY_LEN + ADDRESS_LEN)
// 删除节点命令,包含 1字节命令码+2字节需要删除的节点地址
#define DELETE_NODE_DATA_LEN (PERIPHERAL_CMD_LEN + ADDRESS_LEN)
// 删除节点命令应答,包含 1字节命令码
#define DELETE_NODE_ACK_DATA_LEN (PERIPHERAL_CMD_LEN)
// 删除存储的节点信息命令,包含 1字节命令码
#define DELETE_NODE_INFO_DATA_LEN (PERIPHERAL_CMD_LEN)
// 本地复位命令,包含 1字节命令码
#define LOCAL_RESET_DATA_LEN (PERIPHERAL_CMD_LEN)
/******************************************************************************/
typedef struct
{
uint16_t node_addr;
uint16_t elem_count;
uint16_t net_idx;
uint16_t retry_cnt : 12,
fixed : 1,
blocked : 1;
} node_t;
typedef union
{
struct
{
uint8_t cmd; /* 命令码 CMD_PROVISION */
uint8_t net_key[PROVISION_NET_KEY_LEN]; /* 后续数据长度 */
uint8_t addr[ADDRESS_LEN]; /* 擦除地址 */
} provision; /* 配网命令 */
struct
{
uint8_t cmd; /* 命令码 CMD_DELETE_NODE */
uint8_t addr[ADDRESS_LEN]; /* 擦除地址 */
} delete_node; /* 删除节点命令 */
struct
{
uint8_t cmd; /* 命令码 CMD_DELETE_NODE_ACK */
} delete_node_ack; /* 删除节点命令应答 */
struct
{
uint8_t cmd; /* 命令码 CMD_DELETE_NODE_INFO */
} delete_node_info; /* 删除存储的节点信息命令 */
struct
{
uint8_t cmd; /* 命令码 CMD_LOCAL_RESET */
} local_reset; /* 本地恢复出厂设置命令 */
struct
{
uint8_t buf[20]; /* 接收数据包*/
} data;
}app_mesh_manage_t;
void App_Init(void);
/******************************************************************************/
/******************************************************************************/
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,219 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : app_mesh_config.h
* Author : WCH
* Version : V1.1
* Date : 2021/11/18
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef APP_MESH_CONFIG_H
#define APP_MESH_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/**************************功能配置,建议直接参考不同例程*****************************/
// relay功能
#define CONFIG_BLE_MESH_RELAY 1
// 代理功能
#define CONFIG_BLE_MESH_PROXY 0
// GATT层配网功能
#define CONFIG_BLE_MESH_PB_GATT 0
// FLASH存储功能
#define CONFIG_BLE_MESH_SETTINGS 1
// 朋友节点功能
#define CONFIG_BLE_MESH_FRIEND 0
// 低功耗节点功能
#define CONFIG_BLE_MESH_LOW_POWER 0
// config模型客户端功能
#define CONFIG_BLE_MESH_CFG_CLI 1
// health模型客户端功能
#define CONFIG_BLE_MESH_HLTH_CLI 0
/************************************参数配置******************************************/
// Net数据缓存个数
#define CONFIG_MESH_ADV_BUF_COUNT_MIN (6)
#define CONFIG_MESH_ADV_BUF_COUNT_DEF (10)
#define CONFIG_MESH_ADV_BUF_COUNT_MAX (256)
// RPL数据缓存个数,需不小于配网发起者支持的配网设备节点个数
#define CONFIG_MESH_RPL_COUNT_MIN (6)
#define CONFIG_MESH_RPL_COUNT_DEF (20)
#define CONFIG_MESH_RPL_COUNT_MAX (128)
// RPL缓存循环使用,开启后网络中节点数量不受RPL限制,但NVS将不存储RPL数据
#define CONFIG_MESH_ALLOW_RPL_CYCLE (TRUE)
// IV Update State Timer 基于96H的分频系数
#define CONFIG_MESH_IVU_DIVIDER_MIN (1)
#define CONFIG_MESH_IVU_DIVIDER_DEF (96)
#define CONFIG_MESH_IVU_DIVIDER_MAX (96)
// 代理黑白名单功能存储个数
#define CONFIG_MESH_PROXY_FILTER_MIN (2)
#define CONFIG_MESH_PROXY_FILTER_DEF (5)
#define CONFIG_MESH_PROXY_FILTER_MAX (20)
// 消息贮存个数
#define CONFIG_MESH_MSG_CACHE_MIN (3)
#define CONFIG_MESH_MSG_CACHE_DEF (20)
#define CONFIG_MESH_MSG_CACHE_MAX (20)
// 子网络个数
#define CONFIG_MESH_SUBNET_COUNT_MIN (1)
#define CONFIG_MESH_SUBNET_COUNT_DEF (1)
#define CONFIG_MESH_SUBNET_COUNT_MAX (4)
// APP key个数
#define CONFIG_MESH_APPKEY_COUNT_MIN (1)
#define CONFIG_MESH_APPKEY_COUNT_DEF (3)
#define CONFIG_MESH_APPKEY_COUNT_MAX (5)
// 可存储的模型密钥数量
#define CONFIG_MESH_MOD_KEY_COUNT_MIN (1)
#define CONFIG_MESH_MOD_KEY_COUNT_DEF (1)
#define CONFIG_MESH_MOD_KEY_COUNT_MAX (3)
// 可存储的订阅地址数量
#define CONFIG_MESH_MOD_GROUP_COUNT_MIN (1)
#define CONFIG_MESH_MOD_GROUP_COUNT_DEF (6)
#define CONFIG_MESH_MOD_GROUP_COUNT_MAX (64)
// 是否允许一个网络中存在同地址的节点(使能后分包功能不可用)
#define CONFIG_MESH_ALLOW_SAME_ADDR (FALSE)
// 不分包消息支持的长度(超过此长度则需要分包,默认值为7,注意同网络里所有设备配置需统一)
#define CONFIG_MESH_UNSEG_LENGTH_MIN (7)
#define CONFIG_MESH_UNSEG_LENGTH_DEF (221)
#define CONFIG_MESH_UNSEG_LENGTH_MAX (221)
// 每个消息的最大分包数
#define CONFIG_MESH_TX_SEG_MIN (2)
#define CONFIG_MESH_TX_SEG_DEF (8)
#define CONFIG_MESH_TX_SEG_MAX (32)
// 允许同时存在的分包消息的最大发送个数
#define CONFIG_MESH_TX_SEG_COUNT_MIN (1)
#define CONFIG_MESH_TX_SEG_COUNT_DEF (2)
#define CONFIG_MESH_TX_SEG_COUNT_MAX (4)
// 允许同时存在的分包消息的最大接收个数
#define CONFIG_MESH_RX_SEG_COUNT_MIN (1)
#define CONFIG_MESH_RX_SEG_COUNT_DEF (2)
#define CONFIG_MESH_RX_SEG_COUNT_MAX (4)
// 每个接收的分包消息的最大字节数
#define CONFIG_MESH_RX_SDU_MIN (12)
#define CONFIG_MESH_RX_SDU_DEF (192)
#define CONFIG_MESH_RX_SDU_MAX (384)
// 虚拟地址个数
#define CONFIG_MESH_LABEL_COUNT_MIN (1)
#define CONFIG_MESH_LABEL_COUNT_DEF (2)
#define CONFIG_MESH_LABEL_COUNT_MAX (4)
// NVS存储使用扇区个数
#define CONFIG_MESH_SECTOR_COUNT_MIN (2)
#define CONFIG_MESH_SECTOR_COUNT_DEF (3)
// NVS存储扇区大小
#define CONFIG_MESH_SECTOR_SIZE_DEF (4096)
// NVS存储首地址
#define CONFIG_MESH_NVS_ADDR_DEF (448*1024+0x08000000)
// RPL更新超过多少次后存储
#define CONFIG_MESH_RPL_STORE_RATE_MIN (5)
#define CONFIG_MESH_RPL_STORE_RATE_DEF (60)
#define CONFIG_MESH_RPL_STORE_RATE_MAX (3600)
// SEQ更新超过多少次后存储
#define CONFIG_MESH_SEQ_STORE_RATE_MIN (5)
#define CONFIG_MESH_SEQ_STORE_RATE_DEF (60)
#define CONFIG_MESH_SEQ_STORE_RATE_MAX (3600)
// 其他信息更新后存储的超时时长(s)
#define CONFIG_MESH_STORE_RATE_MIN (2)
#define CONFIG_MESH_STORE_RATE_DEF (2)
#define CONFIG_MESH_STORE_RATE_MAX (5)
// 朋友节点支持的每个消息的分包个数
#define CONFIG_MESH_FRIEND_SEG_RX_COUNT_MIN (1)
#define CONFIG_MESH_FRIEND_SEG_RX_COUNT_DEF (2)
#define CONFIG_MESH_FRIEND_SEG_RX_COUNT_MAX (4)
// 朋友节点支持的订阅个数
#define CONFIG_MESH_FRIEND_SUB_SIZE_MIN (1)
#define CONFIG_MESH_FRIEND_SUB_SIZE_DEF (4)
#define CONFIG_MESH_FRIEND_SUB_SIZE_MAX (8)
// 朋友节点支持的低功耗节点个数
#define CONFIG_MESH_FRIEND_LPN_COUNT_MIN (1)
#define CONFIG_MESH_FRIEND_LPN_COUNT_DEF (1)
#define CONFIG_MESH_FRIEND_LPN_COUNT_MAX (4)
// 朋友节点存储的消息队列大小
#define CONFIG_MESH_QUEUE_SIZE_MIN (2)
#define CONFIG_MESH_QUEUE_SIZE_DEF (4)
#define CONFIG_MESH_QUEUE_SIZE_MAX (30)
// 朋友节点接收窗口大小(ms)
#define CONFIG_MESH_FRIEND_RECV_WIN_MIN (1)
#define CONFIG_MESH_FRIEND_RECV_WIN_DEF (30)
#define CONFIG_MESH_FRIEND_RECV_WIN_MAX (255)
// 低功耗节点的请求消息队列大小
#define CONFIG_MESH_LPN_REQ_QUEUE_SIZE_MIN (2)
#define CONFIG_MESH_LPN_REQ_QUEUE_SIZE_DEF (2)
#define CONFIG_MESH_LPN_REQ_QUEUE_SIZE_MAX (20)
// 低功耗节点的请求消息间隔(100ms)
#define CONFIG_MESH_LPN_POLLINTERVAL_MIN (1)
#define CONFIG_MESH_LPN_POLLINTERVAL_DEF (80)
#define CONFIG_MESH_LPN_POLLINTERVAL_MAX (3455999)
// 低功耗节点的请求消息超时时长(100ms)
#define CONFIG_MESH_LPN_POLLTIMEOUT_MIN (10)
#define CONFIG_MESH_LPN_POLLTIMEOUT_DEF (300)
#define CONFIG_MESH_LPN_POLLTIMEOUT_MAX (3455999)
// 低功耗节点支持的接收延迟(ms)
#define CONFIG_MESH_LPN_RECV_DELAY_MIN (10)
#define CONFIG_MESH_LPN_RECV_DELAY_DEF (100)
#define CONFIG_MESH_LPN_RECV_DELAY_MAX (255)
// 朋友关系重建等待时长(s)
#define CONFIG_MESH_RETRY_TIMEOUT_MIN (3)
#define CONFIG_MESH_RETRY_TIMEOUT_DEF (10)
#define CONFIG_MESH_RETRY_TIMEOUT_MAX (60)
// 配网发起者支持的配网设备节点个数
#define CONFIG_MESH_PROV_NODE_COUNT_DEF (0)
// ADV_RF配置
#define CONFIG_MESH_RF_ACCESSADDRESS (0x8E89BED6)
#define CONFIG_MESH_RF_CHANNEL_37 (37)
#define CONFIG_MESH_RF_CHANNEL_38 (38)
#define CONFIG_MESH_RF_CHANNEL_39 (39)
#define APP_DBG(X...) \
if(1) \
{ \
PRINT("APP_DBG %s> ", __FUNCTION__); \
PRINT(X); \
PRINT("\n"); \
}
/******************************************************************************/
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,241 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : app_vendor_model_srv.h
* Author : WCH
* Version : V1.1
* Date : 2021/11/18
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef app_vendor_model_srv_H
#define app_vendor_model_srv_H
#ifdef __cplusplus
extern "C" {
#endif
#include "MESH_LIB.h"
#define MSG_PIN GPIO_Pin_14
#define MSG_PCENR RCC_APB2Periph_GPIOB
#define MSG_GPIO GPIOB
#define CID_WCH 0x07D7
#define OP_VENDOR_MESSAGE_TRANSPARENT_CFM BLE_MESH_MODEL_OP_3(0xCB, CID_WCH)
#define OP_VENDOR_MESSAGE_TRANSPARENT_WRT BLE_MESH_MODEL_OP_3(0xCC, CID_WCH)
#define OP_VENDOR_MESSAGE_TRANSPARENT_ACK BLE_MESH_MODEL_OP_3(0xCD, CID_WCH)
#define OP_VENDOR_MESSAGE_TRANSPARENT_IND BLE_MESH_MODEL_OP_3(0xCE, CID_WCH)
#define OP_VENDOR_MESSAGE_TRANSPARENT_MSG BLE_MESH_MODEL_OP_3(0xCF, CID_WCH)
#define BLE_MESH_MODEL_ID_WCH_SRV 0x0000
#define BLE_MESH_MODEL_ID_WCH_CLI 0x0001
#define VENDOR_MODEL_SRV_TRANS_EVT (1 << 0)
#define VENDOR_MODEL_SRV_RSP_TIMEOUT_EVT (1 << 1)
#define VENDOR_MODEL_SRV_INDICATE_EVT (1 << 2)
/**
* @brief 发送数据的开始和结束回调函数定义
*/
struct bt_adv_trans_cb
{
void (*start)(int err, void *cb_data);
void (*end)(int err, void *cb_data);
};
/**
* @brief 发送参数结构体
*/
struct send_param
{
uint16_t net_idx;
uint16_t app_idx;
uint16_t addr;
uint8_t tid;
uint8_t trans_cnt;
int32_t period;
int32_t rand;
uint8_t send_ttl;
void *cb_data;
const struct bt_adv_trans_cb *cb;
};
/**
* @brief indicate 发送缓存
*/
struct bt_mesh_indicate
{
struct send_param param;
struct net_buf *buf;
};
/**
* @brief trans 发送缓存
*/
struct bt_mesh_trans
{
struct send_param param;
struct net_buf *buf;
};
/**
* @brief write 发送缓存
*/
struct bt_mesh_write
{
struct send_param param;
struct net_buf *buf;
};
/**
* @brief write 回调结构体
*/
struct bt_mesh_vendor_model_write
{
uint8_t *pdata;
uint16_t len;
uint16_t addr;
};
/**
* @brief srv_trans 回调结构体
*/
struct bt_mesh_vendor_model_srv_trans
{
uint8_t *pdata;
uint16_t len;
uint16_t addr;
};
/**
* @brief Event header
*/
struct vendor_model_srv_EventHdr
{
uint8_t status;
uint32_t opcode;
};
/**
* @brief Server event union
*/
union vendor_model_srv_Event_t
{
struct bt_mesh_vendor_model_srv_trans trans;
struct bt_mesh_vendor_model_write write;
};
/**
* @brief Server event struct
*/
typedef struct
{
struct vendor_model_srv_EventHdr vendor_model_srv_Hdr;
union vendor_model_srv_Event_t vendor_model_srv_Event;
} vendor_model_srv_status_t;
typedef void (*vendor_model_srv_rsp_handler_t)(const vendor_model_srv_status_t *val);
/**
* @brief 记录当前发送数据包的tid
*/
struct vendor_model_srv_tid
{
uint8_t trans_tid;
uint16_t trans_addr;
uint8_t write_tid;
uint16_t write_addr;
};
/**
* @brief Mesh vendor_model_srv Model Context
*/
struct bt_mesh_vendor_model_srv
{
struct bt_mesh_model *model;
uint32_t op_req;
uint32_t op_pending;
struct vendor_model_srv_tid srv_tid;
vendor_model_srv_rsp_handler_t handler;
};
extern const struct bt_mesh_model_op vnd_model_srv_op[];
/**
* @brief 读取led状态
*
* @param led_pin - 引脚
*
* @return led状态
*/
BOOL read_led_state(uint32_t led_pin);
/**
* @brief 设置led状态
*
* @param led_pin - 引脚
* @param on - 状态
*/
void set_led_state(uint32_t led_pin, BOOL on);
/**
* @brief 翻转led状态
*
* @param led_pin - 引脚
*/
void toggle_led_state(uint32_t led_pin);
/**
* @brief indicate,有应答传输数据通道
*
* @param param - 发送参数.
* @param pData - 数据指针.
* @param len - 数据长度,最大为(APP_MAX_TX_SIZE).
*
* @return 参考Global_Error_Code
*/
int vendor_message_srv_indicate(struct send_param *param, uint8_t *pData, uint16_t len);
/**
* @brief send_trans,透传数据通道
*
* @param param - 发送参数.
* @param pData - 数据指针.
* @param len - 数据长度,最大为(APP_MAX_TX_SIZE).
*
* @return 参考Global_Error_Code
*/
int vendor_message_srv_send_trans(struct send_param *param, uint8_t *pData, uint16_t len);
/**
* @brief TID selection method
*
* @return TID
*/
uint8_t vendor_srv_tid_get(void);
/**
* @brief 复位厂商模型服务,取消所有正在发送的流程
*/
void vendor_message_srv_trans_reset(void);
/**
* @brief 厂商模型初始化
*
* @param model - 指向厂商模型结构体
*
* @return always SUCCESS
*/
int vendor_model_srv_init(struct bt_mesh_model *model);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,37 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_conf.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : Library configuration file.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V20x_CONF_H
#define __CH32V20x_CONF_H
#include "ch32v20x_adc.h"
#include "ch32v20x_bkp.h"
#include "ch32v20x_can.h"
#include "ch32v20x_crc.h"
#include "ch32v20x_dbgmcu.h"
#include "ch32v20x_dma.h"
#include "ch32v20x_exti.h"
#include "ch32v20x_flash.h"
#include "ch32v20x_gpio.h"
#include "ch32v20x_i2c.h"
#include "ch32v20x_iwdg.h"
#include "ch32v20x_pwr.h"
#include "ch32v20x_rcc.h"
#include "ch32v20x_rtc.h"
#include "ch32v20x_spi.h"
#include "ch32v20x_tim.h"
#include "ch32v20x_usart.h"
#include "ch32v20x_wwdg.h"
#include "ch32v20x_it.h"
#include "ch32v20x_misc.h"
#endif /* __CH32V20x_CONF_H */
@@ -0,0 +1,18 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_it.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : This file contains the headers of the interrupt handlers.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V20x_IT_H
#define __CH32V20x_IT_H
#include "debug.h"
#endif /* __CH32V20x_IT_H */
@@ -0,0 +1,31 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : system_ch32v20x.h
* Author : WCH
* Version : V1.0.0
* Date : 2022/06/16
* Description : CH32V20x Device Peripheral Access Layer System Header File.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __SYSTEM_ch32v20x_H
#define __SYSTEM_ch32v20x_H
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */
/* System_Exported_Functions */
extern void SystemInit(void);
extern void SystemCoreClockUpdate(void);
#ifdef __cplusplus
}
#endif
#endif /*__CH32V20x_SYSTEM_H */
@@ -0,0 +1,989 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : system_ch32v20x.c
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : CH32V20x Device Peripheral Access Layer System Source File.
* For HSE = 32Mhz (CH32V208x/CH32V203RBT6)
* For HSE = 8Mhz (other CH32V203x)
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "ch32v20x.h"
/*
* Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after
* reset the HSI is used as SYSCLK source).
* If none of the define below is enabled, the HSI is used as System clock source.
*/
//#define SYSCLK_FREQ_HSE HSE_VALUE
//#define SYSCLK_FREQ_48MHz_HSE 48000000
//#define SYSCLK_FREQ_56MHz_HSE 56000000
//#define SYSCLK_FREQ_72MHz_HSE 72000000
#define SYSCLK_FREQ_96MHz_HSE 96000000
//#define SYSCLK_FREQ_120MHz_HSE 120000000
//#define SYSCLK_FREQ_144MHz_HSE 144000000
//#define SYSCLK_FREQ_HSI HSI_VALUE
//#define SYSCLK_FREQ_48MHz_HSI 48000000
//#define SYSCLK_FREQ_56MHz_HSI 56000000
//#define SYSCLK_FREQ_72MHz_HSI 72000000
//#define SYSCLK_FREQ_96MHz_HSI 96000000
//#define SYSCLK_FREQ_120MHz_HSI 120000000
//#define SYSCLK_FREQ_144MHz_HSI 144000000
/* Clock Definitions */
#ifdef SYSCLK_FREQ_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_48MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_56MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_72MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_96MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_120MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_144MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_48MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_56MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_72MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_96MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_120MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_144MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSI; /* System Clock Frequency (Core Clock) */
#else
uint32_t SystemCoreClock = HSI_VALUE; /* System Clock Frequency (Core Clock) */
#endif
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
/* system_private_function_proto_types */
static void SetSysClock(void);
#ifdef SYSCLK_FREQ_HSE
static void SetSysClockToHSE( void );
#elif defined SYSCLK_FREQ_48MHz_HSE
static void SetSysClockTo48_HSE( void );
#elif defined SYSCLK_FREQ_56MHz_HSE
static void SetSysClockTo56_HSE( void );
#elif defined SYSCLK_FREQ_72MHz_HSE
static void SetSysClockTo72_HSE( void );
#elif defined SYSCLK_FREQ_96MHz_HSE
static void SetSysClockTo96_HSE( void );
#elif defined SYSCLK_FREQ_120MHz_HSE
static void SetSysClockTo120_HSE( void );
#elif defined SYSCLK_FREQ_144MHz_HSE
static void SetSysClockTo144_HSE( void );
#elif defined SYSCLK_FREQ_48MHz_HSI
static void SetSysClockTo48_HSI( void );
#elif defined SYSCLK_FREQ_56MHz_HSI
static void SetSysClockTo56_HSI( void );
#elif defined SYSCLK_FREQ_72MHz_HSI
static void SetSysClockTo72_HSI( void );
#elif defined SYSCLK_FREQ_96MHz_HSI
static void SetSysClockTo96_HSI( void );
#elif defined SYSCLK_FREQ_120MHz_HSI
static void SetSysClockTo120_HSI( void );
#elif defined SYSCLK_FREQ_144MHz_HSI
static void SetSysClockTo144_HSI( void );
#endif
/*********************************************************************
* @fn SystemInit
*
* @brief Setup the microcontroller system Initialize the Embedded Flash Interface,
* the PLL and update the SystemCoreClock variable.
*
* @return none
*/
void SystemInit (void)
{
RCC->CTLR |= (uint32_t)0x00000001;
RCC->CFGR0 &= (uint32_t)0xF8FF0000;
RCC->CTLR &= (uint32_t)0xFEF6FFFF;
RCC->CTLR &= (uint32_t)0xFFFBFFFF;
RCC->CFGR0 &= (uint32_t)0xFF80FFFF;
RCC->INTR = 0x009F0000;
SetSysClock();
}
/*********************************************************************
* @fn SystemCoreClockUpdate
*
* @brief Update SystemCoreClock variable according to Clock Register Values.
*
* @return none
*/
void SystemCoreClockUpdate (void)
{
uint32_t tmp = 0, pllmull = 0, pllsource = 0, Pll_6_5 = 0;
tmp = RCC->CFGR0 & RCC_SWS;
switch (tmp)
{
case 0x00:
SystemCoreClock = HSI_VALUE;
break;
case 0x04:
SystemCoreClock = HSE_VALUE;
break;
case 0x08:
pllmull = RCC->CFGR0 & RCC_PLLMULL;
pllsource = RCC->CFGR0 & RCC_PLLSRC;
pllmull = ( pllmull >> 18) + 2;
if(pllmull == 17) pllmull = 18;
if (pllsource == 0x00)
{
if(EXTEN->EXTEN_CTR & EXTEN_PLL_HSI_PRE){
SystemCoreClock = HSI_VALUE * pllmull;
}
else{
SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
}
}
else
{
#if defined (CH32V20x_D8W)
if((RCC->CFGR0 & (3<<22)) == (3<<22))
{
SystemCoreClock = ((HSE_VALUE>>1)) * pllmull;
}
else
#endif
if ((RCC->CFGR0 & RCC_PLLXTPRE) != (uint32_t)RESET)
{
#if defined (CH32V20x_D8) || defined (CH32V20x_D8W)
SystemCoreClock = ((HSE_VALUE>>2) >> 1) * pllmull;
#else
SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
#endif
}
else
{
#if defined (CH32V20x_D8) || defined (CH32V20x_D8W)
SystemCoreClock = (HSE_VALUE>>2) * pllmull;
#else
SystemCoreClock = HSE_VALUE * pllmull;
#endif
}
}
if(Pll_6_5 == 1) SystemCoreClock = (SystemCoreClock / 2);
break;
default:
SystemCoreClock = HSI_VALUE;
break;
}
tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)];
SystemCoreClock >>= tmp;
}
/*********************************************************************
* @fn SetSysClock
*
* @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClock(void)
{
#ifdef SYSCLK_FREQ_HSE
SetSysClockToHSE();
#elif defined SYSCLK_FREQ_48MHz_HSE
SetSysClockTo48_HSE();
#elif defined SYSCLK_FREQ_56MHz_HSE
SetSysClockTo56_HSE();
#elif defined SYSCLK_FREQ_72MHz_HSE
SetSysClockTo72_HSE();
#elif defined SYSCLK_FREQ_96MHz_HSE
SetSysClockTo96_HSE();
#elif defined SYSCLK_FREQ_120MHz_HSE
SetSysClockTo120_HSE();
#elif defined SYSCLK_FREQ_144MHz_HSE
SetSysClockTo144_HSE();
#elif defined SYSCLK_FREQ_48MHz_HSI
SetSysClockTo48_HSI();
#elif defined SYSCLK_FREQ_56MHz_HSI
SetSysClockTo56_HSI();
#elif defined SYSCLK_FREQ_72MHz_HSI
SetSysClockTo72_HSI();
#elif defined SYSCLK_FREQ_96MHz_HSI
SetSysClockTo96_HSI();
#elif defined SYSCLK_FREQ_120MHz_HSI
SetSysClockTo120_HSI();
#elif defined SYSCLK_FREQ_144MHz_HSI
SetSysClockTo144_HSI();
#endif
/* If none of the define above is enabled, the HSI is used as System clock
* source (default after reset)
*/
}
#ifdef SYSCLK_FREQ_HSE
/*********************************************************************
* @fn SetSysClockToHSE
*
* @brief Sets HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockToHSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
/* Select HSE as system clock source
* CH32V20x_D6 (HSE=8MHZ)
* CH32V20x_D8 (HSE=32MHZ)
* CH32V20x_D8W (HSE=32MHZ)
*/
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_HSE;
/* Wait till HSE is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x04)
{
}
}
else
{
/* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_48MHz_HSE
/*********************************************************************
* @fn SetSysClockTo48_HSE
*
* @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo48_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 6 = 48 MHz (HSE=8MHZ)
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 6 = 48 MHz (HSE=32MHZ)
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 6 = 48 MHz (HSE=32MHZ)
*/
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL6);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_56MHz_HSE
/*********************************************************************
* @fn SetSysClockTo56_HSE
*
* @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo56_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 7 = 56 MHz (HSE=8MHZ)
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 7 = 56 MHz (HSE=32MHZ)
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 7 = 56 MHz (HSE=32MHZ)
*/
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL7);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_72MHz_HSE
/*********************************************************************
* @fn SetSysClockTo72_HSE
*
* @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo72_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 9 = 72 MHz (HSE=8MHZ)
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 9 = 72 MHz (HSE=32MHZ)
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 9 = 72 MHz (HSE=32MHZ)
*/
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL9);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_96MHz_HSE
/*********************************************************************
* @fn SetSysClockTo96_HSE
*
* @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo96_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 12 = 96 MHz (HSE=8MHZ)
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 12 = 96 MHz (HSE=32MHZ)
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 12 = 96 MHz (HSE=32MHZ)
*/
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL12);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_120MHz_HSE
/*********************************************************************
* @fn SetSysClockTo120_HSE
*
* @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo120_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if(HSEStatus == (uint32_t)0x01)
{
#if defined (CH32V20x_D8W)
RCC->CFGR0 |= (uint32_t)(3<<22);
/* HCLK = SYSCLK/2 */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV2;
#else
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
#endif
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 15 = 120 MHz (HSE=8MHZ)
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 15 = 120 MHz (HSE=32MHZ)
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/2 * 15 = 240 MHz (HSE=32MHZ)
*/
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL15);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_144MHz_HSE
/*********************************************************************
* @fn SetSysClockTo144_HSE
*
* @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo144_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* CH32V20x_D6-PLL configuration: PLLCLK = HSE * 18 = 144 MHz (HSE=8MHZ)
* CH32V20x_D8-PLL configuration: PLLCLK = HSE/4 * 18 = 144 MHz (HSE=32MHZ)
* CH32V20x_D8W-PLL configuration: PLLCLK = HSE/4 * 18 = 144 MHz (HSE=32MHZ)
*/
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL18);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_48MHz_HSI
/*********************************************************************
* @fn SetSysClockTo48_HSI
*
* @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo48_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 6 = 48 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL6);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_56MHz_HSI
/*********************************************************************
* @fn SetSysClockTo56_HSI
*
* @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo56_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 7 = 48 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL7);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_72MHz_HSI
/*********************************************************************
* @fn SetSysClockTo72_HSI
*
* @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo72_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 9 = 72 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL9);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_96MHz_HSI
/*********************************************************************
* @fn SetSysClockTo96_HSI
*
* @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo96_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 12 = 96 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL12);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_120MHz_HSI
/*********************************************************************
* @fn SetSysClockTo120_HSI
*
* @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo120_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 15 = 120 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL15);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_144MHz_HSI
/*********************************************************************
* @fn SetSysClockTo144_HSI
*
* @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo144_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 18 = 144 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL18);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#endif