Commit 87de2c8e008a36e529fa4bd15c51663af20466f3

Authored by Arkadiusz Materek
1 parent a8aac1b7

Initial implementation

.cproject 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2 +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
  3 + <storageModule moduleId="org.eclipse.cdt.core.settings">
  4 + <cconfiguration id="com.ifx.xmc4000.appDebug.550260580">
  5 + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.ifx.xmc4000.appDebug.550260580" moduleId="org.eclipse.cdt.core.settings" name="Eval Release">
  6 + <externalSettings/>
  7 + <extensions>
  8 + <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
  9 + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  10 + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  11 + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  12 + <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  13 + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
  14 + <extension id="com.ifx.xmc4000.errorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  15 + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  16 + </extensions>
  17 + </storageModule>
  18 + <storageModule moduleId="cdtBuildSystem" version="4.0.0">
  19 + <configuration artifactName="${ProjName}" buildArtefactType="com.ifx.xmc4000.appBuildArtefactType" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=com.ifx.xmc4000.appBuildArtefactType,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser;com.ifx.xmc4000.errorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GmakeErrorParser" id="com.ifx.xmc4000.appDebug.550260580" name="Eval Release" parent="com.ifx.xmc4000.appDebug" postannouncebuildStep="" postbuildStep="" preannouncebuildStep="" prebuildStep="">
  20 + <folderInfo id="com.ifx.xmc4000.appDebug.550260580." name="/" resourcePath="">
  21 + <toolChain errorParsers="" id="com.ifx.xmc4000.appDebug.toolChain.1600624109" name="ARM-GCC Application" superClass="com.ifx.xmc4000.appDebug.toolChain">
  22 + <option id="com.ifx.xmc4000.option.debugging.level.827209593" name="Debug level" superClass="com.ifx.xmc4000.option.debugging.level"/>
  23 + <option id="com.ifx.xmc4000.option.targetPath.366502638" name="Target Path" superClass="com.ifx.xmc4000.option.targetPath" value="/DeviceRoot/Microcontrollers/XMC1000/XMC1200 Series/XMC1200-T038x0200" valueType="string"/>
  24 + <option id="com.ifx.xmc4000.option.target.processor.560571156" name="Processor" superClass="com.ifx.xmc4000.option.target.processor" value="org.eclipse.cdt.cross.arm.gnu.base.option.mcpu.cortex-m0" valueType="enumerated"/>
  25 + <option id="com.ifx.xmc4000.option.target.fpu.248966573" name="Fpu (-mfpu)" superClass="com.ifx.xmc4000.option.target.fpu" value="org.eclipse.cdt.cross.arm.gnu.base.option.mfpu.none" valueType="enumerated"/>
  26 + <option id="com.ifx.xmc4000.option.targetName.1695145695" name="Target Name" superClass="com.ifx.xmc4000.option.targetName" value="XMC1200-T038x0200" valueType="string"/>
  27 + <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="com.ifx.xmc4000.targetPlatform.1546410275" isAbstract="false" name="Windows Platform" osList="win32" superClass="com.ifx.xmc4000.targetPlatform"/>
  28 + <builder buildPath="${workspace_loc:/DALI}/Debug" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="com.ifx.XMC4000.toolchainBuilder.392958902" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="XMC Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ifx.XMC4000.toolchainBuilder"/>
  29 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-gcc&quot;" commandLinePattern="${CCACHE} ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="com.ifx.xmc4000.errorParser" id="com.ifx.xmc4000.appDebug.compiler.960276584" name="ARM-GCC C Compiler" superClass="com.ifx.xmc4000.appDebug.compiler">
  30 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.optimization.level.1912712792" name="Optimization level" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.base.option.optimization.level.more" valueType="enumerated"/>
  31 + <option id="com.ifx.xmc4000.compiler.option.misc.mfloat.499017469" name="Floating point" superClass="com.ifx.xmc4000.compiler.option.misc.mfloat" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  32 + <option id="com.ifx.xmc4000.compiler.option.include.paths.1567142076" name="Include paths (-I)" superClass="com.ifx.xmc4000.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
  33 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Infineon/Libraries/XMCLib/inc}&quot;"/>
  34 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Infineon/Libraries/CMSIS/Include}&quot;"/>
  35 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Infineon/Libraries/CMSIS/Infineon/XMC1200_series/Include}&quot;"/>
  36 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Infineon/Libraries}&quot;"/>
  37 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
  38 + </option>
  39 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.preprocessor.def.354991351" name="Defined symbols (-D)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
  40 + <listOptionValue builtIn="false" value="CPU_CLOCK=32000000"/>
  41 + <listOptionValue builtIn="false" value="XMC1200_T038x0200"/>
  42 + </option>
  43 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.warnings.toerrors.1068316666" name="Warnings as errors (-Werror)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.warnings.toerrors" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  44 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.misc.unsignedbitfields.969448410" name="Bitfields are unsigned (-funsigned-bitfields)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.misc.unsignedbitfields" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  45 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.optimization.shortenums.259621136" name="Short enumerations (-fshort-enums)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.optimization.shortenums" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  46 + <inputType id="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.c.compiler.base.input.1333981597" superClass="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.c.compiler.base.input"/>
  47 + </tool>
  48 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-g++&quot;" commandLinePattern="${CCACHE} ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="com.ifx.xmc4000.errorParser" id="com.ifx.xmc4000.appDebug.cppcompiler.1231286522" name="ARM-GCC C++ Compiler" superClass="com.ifx.xmc4000.appDebug.cppcompiler">
  49 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.optimization.level.1216220166" name="Optimization level" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.base.option.optimization.level.more" valueType="enumerated"/>
  50 + <option id="com.ifx.xmc4000.cppcompiler.option.misc.mfloat.1108064296" name="Floating point" superClass="com.ifx.xmc4000.cppcompiler.option.misc.mfloat" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  51 + <option id="com.ifx.xmc4000.cppcompiler.option.include.paths.586936895" name="Include paths (-I)" superClass="com.ifx.xmc4000.cppcompiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
  52 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Infineon/Libraries/XMCLib/inc}&quot;"/>
  53 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Infineon/Libraries/CMSIS/Include}&quot;"/>
  54 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Infineon/Libraries/CMSIS/Infineon/XMC1200_series/Include}&quot;"/>
  55 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Infineon/Libraries}&quot;"/>
  56 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/src}&quot;"/>
  57 + </option>
  58 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.std.1620428162" name="Language standard" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.std" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.std.gnucpp0x" valueType="enumerated"/>
  59 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.toerrors.1812260213" name="Warnings as errors (-Werror)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.toerrors" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  60 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.preprocessor.def.2047885031" name="Defined symbols (-D)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
  61 + <listOptionValue builtIn="false" value="CPU_CLOCK=32000000"/>
  62 + <listOptionValue builtIn="false" value="XMC1200_T038x0200"/>
  63 + </option>
  64 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.preprocessor.nostdincpp.1226141936" name="Do not search system C++ directories (-nostdinc++)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.preprocessor.nostdincpp" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  65 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.optimization.shortenums.370293187" name="Short enumerations (-fshort-enums)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.optimization.shortenums" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  66 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.unsignedbitfields.1638440264" name="Bitfields are unsigned (-funsigned-bitfields)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.unsignedbitfields" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  67 + <inputType id="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.cpp.compiler.base.input.1425660654" superClass="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.cpp.compiler.base.input"/>
  68 + </tool>
  69 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-gcc&quot;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GCCErrorParser" id="com.ifx.xmc4000.appDebug.assembler.713477867" name="ARM-GCC Assembler" superClass="com.ifx.xmc4000.appDebug.assembler">
  70 + <option id="com.ifx.xmc4000.assembler.option.misc.mfloat.1476540206" name="Floating point" superClass="com.ifx.xmc4000.assembler.option.misc.mfloat" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  71 + <option id="com.ifx.xmc4000.assembler.option.include.paths.1607163161" name="Include paths (-I)" superClass="com.ifx.xmc4000.assembler.option.include.paths" valueType="includePath">
  72 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries/XMCLib/inc&quot;"/>
  73 + </option>
  74 + <option id="org.eclipse.cdt.cross.arm.gnu.assembler.option.preprocessor.def.1170298475" name="Defined symbols (-D)" superClass="org.eclipse.cdt.cross.arm.gnu.assembler.option.preprocessor.def" valueType="definedSymbols">
  75 + <listOptionValue builtIn="false" value="XMC1200_T038x0200"/>
  76 + </option>
  77 + <option id="org.eclipse.cdt.cross.arm.gnu.assembler.option.warnings.toerrors.1485630971" name="Warnings as errors (-Werror)" superClass="org.eclipse.cdt.cross.arm.gnu.assembler.option.warnings.toerrors" value="true" valueType="boolean"/>
  78 + <inputType id="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.assembler.base.input.782158771" superClass="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.assembler.base.input"/>
  79 + </tool>
  80 + <tool id="com.ifx.xmc4000.appDebug.linker.1153888047" name="ARM-GCC C Linker" superClass="com.ifx.xmc4000.appDebug.linker">
  81 + <option id="com.ifx.xmc4000.appLinker.option.misc.fpu.372245068" name="Fpu (-mfpu)" superClass="com.ifx.xmc4000.appLinker.option.misc.fpu" value="No floating point hardware available" valueType="enumerated"/>
  82 + <option id="com.ifx.xmc4000.appLinker.option.misc.mfloat.1341921756" name="Floating point" superClass="com.ifx.xmc4000.appLinker.option.misc.mfloat" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  83 + <inputType id="com.ifx.xmc4000.appLinker.inputType.1229941142" name="ARM-GCC for XMC Linker Input Type" superClass="com.ifx.xmc4000.appLinker.inputType">
  84 + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
  85 + <additionalInput kind="additionalinput" paths="$(LIBS)"/>
  86 + </inputType>
  87 + </tool>
  88 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-g++&quot;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT} ${INPUTS}" errorParsers="" id="com.ifx.xmc4000.appDebug.cpplinker.1280723967" name="ARM-GCC C++ Linker" superClass="com.ifx.xmc4000.appDebug.cpplinker">
  89 + <option id="com.ifx.xmc4000.appCppLinker.option.misc.fpu.428895397" name="Fpu (-mfpu)" superClass="com.ifx.xmc4000.appCppLinker.option.misc.fpu" value="org.eclipse.cdt.cross.arm.gnu.base.option.mfpu.none" valueType="enumerated"/>
  90 + <option id="com.ifx.xmc4000.appCppLinker.option.misc.mfloat.611533962" name="Floating point" superClass="com.ifx.xmc4000.appCppLinker.option.misc.mfloat" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  91 + <inputType id="com.ifx.xmc4000.appCppLinker.inputType.552326242" name="ARM-GCC for XMC Linker Input Type" superClass="com.ifx.xmc4000.appCppLinker.inputType">
  92 + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
  93 + <additionalInput kind="additionalinput" paths="$(LIBS)"/>
  94 + </inputType>
  95 + </tool>
  96 + <tool id="com.ifx.xmc4000.libLinker.653110245" name="ARM-GCC Archiver" superClass="com.ifx.xmc4000.libLinker"/>
  97 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-objcopy&quot;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="" id="com.ifx.xmc4000.appDebug.createflash.182577608" name="ARM-GCC Create Flash Image" superClass="com.ifx.xmc4000.appDebug.createflash"/>
  98 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-objdump&quot;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="" id="com.ifx.xmc4000.appDebug.createlisting.854131061" name="ARM-GCC Create Listing" superClass="com.ifx.xmc4000.appDebug.createlisting"/>
  99 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-size&quot;" commandLinePattern="${COMMAND} ${INPUTS} ${FLAGS}" errorParsers="" id="com.ifx.xmc4000.printsize.1873412354" name="ARM-GCC Print Size" superClass="com.ifx.xmc4000.printsize"/>
  100 + </toolChain>
  101 + </folderInfo>
  102 + </configuration>
  103 + </storageModule>
  104 + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
  105 + <storageModule moduleId="ilg.gnuarmeclipse.managedbuild.packs"/>
  106 + </cconfiguration>
  107 + <cconfiguration id="com.ifx.xmc4000.appDebug.550260580.971189960">
  108 + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="com.ifx.xmc4000.appDebug.550260580.971189960" moduleId="org.eclipse.cdt.core.settings" name="Eval Debug">
  109 + <externalSettings/>
  110 + <extensions>
  111 + <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
  112 + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  113 + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  114 + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  115 + <extension id="org.eclipse.cdt.core.MakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  116 + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
  117 + <extension id="com.ifx.xmc4000.errorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  118 + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
  119 + </extensions>
  120 + </storageModule>
  121 + <storageModule moduleId="cdtBuildSystem" version="4.0.0">
  122 + <configuration artifactName="${ProjName}" buildArtefactType="com.ifx.xmc4000.appBuildArtefactType" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=com.ifx.xmc4000.appBuildArtefactType,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.GASErrorParser;com.ifx.xmc4000.errorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GmakeErrorParser" id="com.ifx.xmc4000.appDebug.550260580.971189960" name="Eval Debug" parent="com.ifx.xmc4000.appDebug" postannouncebuildStep="" postbuildStep="" preannouncebuildStep="" prebuildStep="">
  123 + <folderInfo id="com.ifx.xmc4000.appDebug.550260580.971189960." name="/" resourcePath="">
  124 + <toolChain errorParsers="" id="com.ifx.xmc4000.appDebug.toolChain.1504650639" name="ARM-GCC Application" superClass="com.ifx.xmc4000.appDebug.toolChain">
  125 + <option id="com.ifx.xmc4000.option.debugging.level.1312934237" name="Debug level" superClass="com.ifx.xmc4000.option.debugging.level" value="org.eclipse.cdt.cross.arm.gnu.base.option.debugging.level.default" valueType="enumerated"/>
  126 + <option id="com.ifx.xmc4000.option.targetPath.2114856219" name="Target Path" superClass="com.ifx.xmc4000.option.targetPath" value="/DeviceRoot/Microcontrollers/XMC1000/XMC1200 Series/XMC1200-T038x0200" valueType="string"/>
  127 + <option id="com.ifx.xmc4000.option.target.processor.1462873041" name="Processor" superClass="com.ifx.xmc4000.option.target.processor" value="org.eclipse.cdt.cross.arm.gnu.base.option.mcpu.cortex-m0" valueType="enumerated"/>
  128 + <option id="com.ifx.xmc4000.option.target.fpu.2111225020" name="Fpu (-mfpu)" superClass="com.ifx.xmc4000.option.target.fpu" value="org.eclipse.cdt.cross.arm.gnu.base.option.mfpu.none" valueType="enumerated"/>
  129 + <option id="com.ifx.xmc4000.option.targetName.1279421155" name="Target Name" superClass="com.ifx.xmc4000.option.targetName" value="XMC1200-T038x0200" valueType="string"/>
  130 + <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="com.ifx.xmc4000.targetPlatform.1429668911" isAbstract="false" name="Windows Platform" osList="win32" superClass="com.ifx.xmc4000.targetPlatform"/>
  131 + <builder buildPath="${workspace_loc:/DALI}/Debug" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="com.ifx.XMC4000.toolchainBuilder.579414810" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="XMC Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ifx.XMC4000.toolchainBuilder"/>
  132 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-gcc&quot;" commandLinePattern="${CCACHE} ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="com.ifx.xmc4000.errorParser" id="com.ifx.xmc4000.appDebug.compiler.1060836931" name="ARM-GCC C Compiler" superClass="com.ifx.xmc4000.appDebug.compiler">
  133 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.optimization.level.1226740984" name="Optimization level" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.base.option.optimization.level.debugging" valueType="enumerated"/>
  134 + <option id="com.ifx.xmc4000.compiler.option.misc.mfloat.977401333" name="Floating point" superClass="com.ifx.xmc4000.compiler.option.misc.mfloat" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  135 + <option id="com.ifx.xmc4000.compiler.option.include.paths.1016308973" name="Include paths (-I)" superClass="com.ifx.xmc4000.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
  136 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries/XMCLib/inc&quot;"/>
  137 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries/CMSIS/Include&quot;"/>
  138 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries/CMSIS/Infineon/XMC1200_series/Include&quot;"/>
  139 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries&quot;"/>
  140 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/src&quot;"/>
  141 + </option>
  142 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.preprocessor.def.91794738" name="Defined symbols (-D)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
  143 + <listOptionValue builtIn="false" value="CPU_CLOCK=32000000"/>
  144 + <listOptionValue builtIn="false" value="XMC1200_T038x0200"/>
  145 + </option>
  146 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.warnings.toerrors.1701168972" name="Warnings as errors (-Werror)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.warnings.toerrors" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  147 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.misc.unsignedbitfields.1660069779" name="Bitfields are unsigned (-funsigned-bitfields)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.misc.unsignedbitfields" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  148 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.optimization.shortenums.718105207" name="Short enumerations (-fshort-enums)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.optimization.shortenums" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  149 + <option id="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.warnings.extrawarn.409761526" name="Extra warnings (-Wextra)" superClass="org.eclipse.cdt.cross.arm.gnu.c.compiler.option.warnings.extrawarn" useByScannerDiscovery="false" value="false" valueType="boolean"/>
  150 + <inputType id="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.c.compiler.base.input.213717796" superClass="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.c.compiler.base.input"/>
  151 + </tool>
  152 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-g++&quot;" commandLinePattern="${CCACHE} ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="com.ifx.xmc4000.errorParser" id="com.ifx.xmc4000.appDebug.cppcompiler.1775595162" name="ARM-GCC C++ Compiler" superClass="com.ifx.xmc4000.appDebug.cppcompiler">
  153 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.optimization.level.939719289" name="Optimization level" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.base.option.optimization.level.debugging" valueType="enumerated"/>
  154 + <option id="com.ifx.xmc4000.cppcompiler.option.misc.mfloat.190490599" name="Floating point" superClass="com.ifx.xmc4000.cppcompiler.option.misc.mfloat" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  155 + <option id="com.ifx.xmc4000.cppcompiler.option.include.paths.2141753093" name="Include paths (-I)" superClass="com.ifx.xmc4000.cppcompiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
  156 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries/XMCLib/inc&quot;"/>
  157 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries/CMSIS/Include&quot;"/>
  158 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries/CMSIS/Infineon/XMC1200_series/Include&quot;"/>
  159 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries&quot;"/>
  160 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/src&quot;"/>
  161 + </option>
  162 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.std.1053469166" name="Language standard" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.std" useByScannerDiscovery="false" value="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.std.gnucpp0x" valueType="enumerated"/>
  163 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.toerrors.2103391273" name="Warnings as errors (-Werror)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.toerrors" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  164 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.preprocessor.def.1564220828" name="Defined symbols (-D)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
  165 + <listOptionValue builtIn="false" value="CPU_CLOCK=32000000"/>
  166 + <listOptionValue builtIn="false" value="XMC1200_T038x0200"/>
  167 + </option>
  168 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.preprocessor.nostdincpp.1743927048" name="Do not search system C++ directories (-nostdinc++)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.preprocessor.nostdincpp" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  169 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.optimization.shortenums.561358169" name="Short enumerations (-fshort-enums)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.optimization.shortenums" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  170 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.unsignedbitfields.2135372860" name="Bitfields are unsigned (-funsigned-bitfields)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.misc.unsignedbitfields" useByScannerDiscovery="false" value="true" valueType="boolean"/>
  171 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.extrawarn.49004751" name="Extra warnings (-Wextra)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.extrawarn" useByScannerDiscovery="false" value="false" valueType="boolean"/>
  172 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.abi.621942759" name="ABI warnings (-Wabi)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.abi" useByScannerDiscovery="false" value="false" valueType="boolean"/>
  173 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.pedantic.error.1733576804" name="Pedantic warnings as errors (-pedantic-errors)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.pedantic.error" useByScannerDiscovery="false" value="false" valueType="boolean"/>
  174 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.nowarn.1929906052" name="Inhibit all warnings (-w)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.nowarn" useByScannerDiscovery="false" value="false" valueType="boolean"/>
  175 + <option id="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.effc.1068391274" name="Effective C++ warnings (-Weffc++)" superClass="org.eclipse.cdt.cross.arm.gnu.cpp.compiler.option.warnings.effc" useByScannerDiscovery="false" value="false" valueType="boolean"/>
  176 + <inputType id="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.cpp.compiler.base.input.509330887" superClass="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.cpp.compiler.base.input"/>
  177 + </tool>
  178 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-gcc&quot;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GCCErrorParser" id="com.ifx.xmc4000.appDebug.assembler.1713706833" name="ARM-GCC Assembler" superClass="com.ifx.xmc4000.appDebug.assembler">
  179 + <option id="com.ifx.xmc4000.assembler.option.misc.mfloat.1965865746" name="Floating point" superClass="com.ifx.xmc4000.assembler.option.misc.mfloat" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  180 + <option id="com.ifx.xmc4000.assembler.option.include.paths.771508811" name="Include paths (-I)" superClass="com.ifx.xmc4000.assembler.option.include.paths" valueType="includePath">
  181 + <listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}}/Infineon/Libraries/XMCLib/inc&quot;"/>
  182 + </option>
  183 + <option id="org.eclipse.cdt.cross.arm.gnu.assembler.option.preprocessor.def.1099294366" name="Defined symbols (-D)" superClass="org.eclipse.cdt.cross.arm.gnu.assembler.option.preprocessor.def" valueType="definedSymbols">
  184 + <listOptionValue builtIn="false" value="XMC1200_T038x0200"/>
  185 + </option>
  186 + <option id="org.eclipse.cdt.cross.arm.gnu.assembler.option.warnings.toerrors.127111375" name="Warnings as errors (-Werror)" superClass="org.eclipse.cdt.cross.arm.gnu.assembler.option.warnings.toerrors" value="true" valueType="boolean"/>
  187 + <inputType id="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.assembler.base.input.107930045" superClass="org.eclipse.cdt.cross.arm.gnu.sourcery.windows.assembler.base.input"/>
  188 + </tool>
  189 + <tool id="com.ifx.xmc4000.appDebug.linker.2021849963" name="ARM-GCC C Linker" superClass="com.ifx.xmc4000.appDebug.linker">
  190 + <option id="com.ifx.xmc4000.appLinker.option.misc.fpu.1161173668" name="Fpu (-mfpu)" superClass="com.ifx.xmc4000.appLinker.option.misc.fpu" value="No floating point hardware available" valueType="enumerated"/>
  191 + <option id="com.ifx.xmc4000.appLinker.option.misc.mfloat.2143713686" name="Floating point" superClass="com.ifx.xmc4000.appLinker.option.misc.mfloat" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  192 + <inputType id="com.ifx.xmc4000.appLinker.inputType.1191340419" name="ARM-GCC for XMC Linker Input Type" superClass="com.ifx.xmc4000.appLinker.inputType">
  193 + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
  194 + <additionalInput kind="additionalinput" paths="$(LIBS)"/>
  195 + </inputType>
  196 + </tool>
  197 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-g++&quot;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT} ${INPUTS}" errorParsers="" id="com.ifx.xmc4000.appDebug.cpplinker.1864217912" name="ARM-GCC C++ Linker" superClass="com.ifx.xmc4000.appDebug.cpplinker">
  198 + <option id="com.ifx.xmc4000.appCppLinker.option.misc.fpu.633447446" name="Fpu (-mfpu)" superClass="com.ifx.xmc4000.appCppLinker.option.misc.fpu" value="org.eclipse.cdt.cross.arm.gnu.base.option.mfpu.none" valueType="enumerated"/>
  199 + <option id="com.ifx.xmc4000.appCppLinker.option.misc.mfloat.1672585048" name="Floating point" superClass="com.ifx.xmc4000.appCppLinker.option.misc.mfloat" value="org.eclipse.cdt.cross.arm.gnu.base.option.other.mfloat.soft" valueType="enumerated"/>
  200 + <inputType id="com.ifx.xmc4000.appCppLinker.inputType.1893756751" name="ARM-GCC for XMC Linker Input Type" superClass="com.ifx.xmc4000.appCppLinker.inputType">
  201 + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
  202 + <additionalInput kind="additionalinput" paths="$(LIBS)"/>
  203 + </inputType>
  204 + </tool>
  205 + <tool id="com.ifx.xmc4000.libLinker.237958219" name="ARM-GCC Archiver" superClass="com.ifx.xmc4000.libLinker"/>
  206 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-objcopy&quot;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="" id="com.ifx.xmc4000.appDebug.createflash.960165856" name="ARM-GCC Create Flash Image" superClass="com.ifx.xmc4000.appDebug.createflash"/>
  207 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-objdump&quot;" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="" id="com.ifx.xmc4000.appDebug.createlisting.56516569" name="ARM-GCC Create Listing" superClass="com.ifx.xmc4000.appDebug.createlisting"/>
  208 + <tool command="&quot;${ARM_GCC_HOME}/bin/arm-none-eabi-size&quot;" commandLinePattern="${COMMAND} ${INPUTS} ${FLAGS}" errorParsers="" id="com.ifx.xmc4000.printsize.1208862890" name="ARM-GCC Print Size" superClass="com.ifx.xmc4000.printsize"/>
  209 + </toolChain>
  210 + </folderInfo>
  211 + </configuration>
  212 + </storageModule>
  213 + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
  214 + <storageModule moduleId="ilg.gnuarmeclipse.managedbuild.packs"/>
  215 + </cconfiguration>
  216 + </storageModule>
  217 + <storageModule moduleId="cdtBuildSystem" version="4.0.0">
  218 + <project id="DALI.com.ifx.xmc4000.appProject.369332093" name="ARM-GCC Application" projectType="com.ifx.xmc4000.appProject"/>
  219 + </storageModule>
  220 + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
  221 + <storageModule moduleId="org.eclipse.cdt.core.language.mapping">
  222 + <project-mappings/>
  223 + </storageModule>
  224 + <storageModule moduleId="refreshScope" versionNumber="2">
  225 + <configuration configurationName="Release Tests"/>
  226 + <configuration configurationName="Target Debug"/>
  227 + <configuration configurationName="Debug Tests"/>
  228 + <configuration configurationName="Eval Release"/>
  229 + <configuration configurationName="Eval Debug"/>
  230 + <configuration configurationName="Test-Bccu"/>
  231 + <configuration configurationName="Release">
  232 + <resource resourceType="PROJECT" workspacePath="/DALI"/>
  233 + </configuration>
  234 + <configuration configurationName="Debug">
  235 + <resource resourceType="PROJECT" workspacePath="/DALI"/>
  236 + </configuration>
  237 + </storageModule>
  238 + <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
  239 + <storageModule moduleId="scannerConfiguration">
  240 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
  241 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appDebug.550260580;com.ifx.xmc4000.appDebug.550260580.;com.ifx.xmc4000.appDebug.assembler.713477867;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.assembler.base.input.782158771">
  242 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileC"/>
  243 + </scannerConfigBuildInfo>
  244 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appRelease.1395815384;com.ifx.xmc4000.appRelease.1395815384.;com.ifx.xmc4000.appRelease.assembler.658421174;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.assembler.base.input.148518789">
  245 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileC"/>
  246 + </scannerConfigBuildInfo>
  247 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appDebug.550260580;com.ifx.xmc4000.appDebug.550260580.;com.ifx.xmc4000.appDebug.compiler.960276584;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.c.compiler.base.input.1333981597">
  248 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileC"/>
  249 + </scannerConfigBuildInfo>
  250 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appDebug.550260580.971189960;com.ifx.xmc4000.appDebug.550260580.971189960.;com.ifx.xmc4000.appDebug.assembler.1713706833;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.assembler.base.input.107930045">
  251 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileC"/>
  252 + </scannerConfigBuildInfo>
  253 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appRelease.1395815384.767415880;com.ifx.xmc4000.appRelease.1395815384.767415880.;com.ifx.xmc4000.appRelease.cppcompiler.310069151;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.cpp.compiler.base.input.283479190">
  254 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileCPP"/>
  255 + </scannerConfigBuildInfo>
  256 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appRelease.1395815384.767415880;com.ifx.xmc4000.appRelease.1395815384.767415880.;com.ifx.xmc4000.appRelease.compiler.347678369;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.c.compiler.base.input.1253571741">
  257 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileC"/>
  258 + </scannerConfigBuildInfo>
  259 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appRelease.1395815384.767415880;com.ifx.xmc4000.appRelease.1395815384.767415880.;com.ifx.xmc4000.appRelease.assembler.58251276;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.assembler.base.input.1827691777">
  260 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileC"/>
  261 + </scannerConfigBuildInfo>
  262 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appRelease.1395815384;com.ifx.xmc4000.appRelease.1395815384.;com.ifx.xmc4000.appRelease.cppcompiler.1366607853;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.cpp.compiler.base.input.988219551">
  263 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileCPP"/>
  264 + </scannerConfigBuildInfo>
  265 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appDebug.550260580.971189960;com.ifx.xmc4000.appDebug.550260580.971189960.;com.ifx.xmc4000.appDebug.cppcompiler.1775595162;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.cpp.compiler.base.input.509330887">
  266 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileCPP"/>
  267 + </scannerConfigBuildInfo>
  268 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appRelease.1395815384;com.ifx.xmc4000.appRelease.1395815384.;com.ifx.xmc4000.appRelease.compiler.1548533470;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.c.compiler.base.input.303731508">
  269 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileC"/>
  270 + </scannerConfigBuildInfo>
  271 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appDebug.550260580;com.ifx.xmc4000.appDebug.550260580.;com.ifx.xmc4000.appDebug.cppcompiler.1231286522;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.cpp.compiler.base.input.1425660654">
  272 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileCPP"/>
  273 + </scannerConfigBuildInfo>
  274 + <scannerConfigBuildInfo instanceId="com.ifx.xmc4000.appDebug.550260580.971189960;com.ifx.xmc4000.appDebug.550260580.971189960.;com.ifx.xmc4000.appDebug.compiler.1060836931;org.eclipse.cdt.cross.arm.gnu.sourcery.windows.c.compiler.base.input.213717796">
  275 + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.cross.arm.gnu.ARM_CS_GCCWinManagedMakePerProjectProfileC"/>
  276 + </scannerConfigBuildInfo>
  277 + </storageModule>
  278 +</cproject>
... ...
.gitignore 0 → 100644
.project 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<projectDescription>
  3 + <name>DALI</name>
  4 + <comment></comment>
  5 + <projects>
  6 + </projects>
  7 + <buildSpec>
  8 + <buildCommand>
  9 + <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
  10 + <triggers>clean,full,incremental,</triggers>
  11 + <arguments>
  12 + </arguments>
  13 + </buildCommand>
  14 + <buildCommand>
  15 + <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
  16 + <triggers>full,incremental,</triggers>
  17 + <arguments>
  18 + </arguments>
  19 + </buildCommand>
  20 + </buildSpec>
  21 + <natures>
  22 + <nature>org.eclipse.cdt.core.cnature</nature>
  23 + <nature>com.ifx.xmc4000.xmc4000Nature</nature>
  24 + <nature>com.dave.common.daveBenchNature</nature>
  25 + <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
  26 + <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
  27 + <nature>org.eclipse.cdt.core.ccnature</nature>
  28 + </natures>
  29 +</projectDescription>
... ...
.settings/com.dave.mbs.xc800.prefs 0 → 100644
  1 +ACTIVE_CONFIG_NAME=Debug
  2 +AppCompatibilitySet=1
  3 +DEVICE_DESC=Package\= TSSOP38 \nROM\= 200 KB Flash \nRAM\= 16 KB RAM \nInOut\= 34 digital I/O \nADC\= 12 ADC Channels, 12-bit, Analog-to-Digital Converter \nTimed_InOut\= 6 Timer, 4 CAPCOM channels \nSerial\= 2 USIC channels \nSHS\= 2 Sample and Hold Sequencer \nCOMP\= Comparator Control Unit \nTouch\= Touch and LED matrix control \nBCCU\= Brightness and Color Control Unit \n
  4 +DEVICE_NAME=XMC1200-T038x0200
  5 +DEVICE_PACKAGE=TSSOP38
  6 +DEVICE_PACK_VERSION=2.0.0
  7 +DEVICE_PATH=/DeviceRoot/Microcontrollers/XMC1000/XMC1200 Series/XMC1200-T038x0200
  8 +FLASH_SIZE=200
  9 +MBS_PROVIDER_ID_KEY=com.dave.mbs.xmc4000.xmc4000MbsFactory
  10 +SOFTWARE_ID=XMC1.2.00.T038.ALL
  11 +TEMPLATE_KEY=com.ifx.xmc4000.appEmptyMainTemplate
  12 +eclipse.preferences.version=1
  13 +minDaveVersion=4.1.2
... ...
.settings/language.settings.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2 +<project>
  3 + <configuration id="com.ifx.xmc4000.appDebug.550260580" name="Eval Release">
  4 + <extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
  5 + <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
  6 + <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
  7 + <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-775048151425109940" id="com.ifx.xmc4000.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings XMC" parameter="${COMMAND} ${FLAGS} -E -P -v -dM &quot;${INPUTS}&quot;" prefer-non-shared="true">
  8 + <language-scope id="org.eclipse.cdt.core.gcc"/>
  9 + <language-scope id="org.eclipse.cdt.core.g++"/>
  10 + </provider>
  11 + </extension>
  12 + </configuration>
  13 + <configuration id="com.ifx.xmc4000.appDebug.550260580.971189960" name="Eval Debug">
  14 + <extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
  15 + <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
  16 + <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
  17 + <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-775048151425109940" id="com.ifx.xmc4000.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings XMC" parameter="${COMMAND} ${FLAGS} -E -P -v -dM &quot;${INPUTS}&quot;" prefer-non-shared="true">
  18 + <language-scope id="org.eclipse.cdt.core.gcc"/>
  19 + <language-scope id="org.eclipse.cdt.core.g++"/>
  20 + </provider>
  21 + </extension>
  22 + </configuration>
  23 +</project>
... ...
.settings/properties.index 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<com.ifx.xmc4000.appDebug.550260580_memory>
  3 +<details IMemento.internal.id="0" enable="Yes" endAddress="0x100329FF" memModelType="ROM" modelName="FLASH" startAddress="0x10001000"/>
  4 +<details IMemento.internal.id="1" enable="Yes" endAddress="0x20003FFF" memModelType="RAM" modelName="SRAM " startAddress="0x20000000"/>
  5 +</com.ifx.xmc4000.appDebug.550260580_memory>
0 6 \ No newline at end of file
... ...
README.md
1 1 # dali_slave
2   -Implementation of DALI slave.
  2 +Implementation of DALI slave using C++ 11.
  3 +
  4 +Requirements:
  5 +* DAVE4
  6 +* Infineon libraries "Infineon/Libraries"
  7 +* LED Lighting Application Kit
3 8 \ No newline at end of file
... ...
linker_script.ld 0 → 100644
  1 +/**
  2 + * @file XMC1200x0200.ld
  3 + * @date 2015-07-07
  4 + *
  5 + * @cond
  6 + *********************************************************************************************************************
  7 + * Linker file for the GNU C Compiler v1.7
  8 + * Supported devices: XMC1200-T038F0200
  9 + * XMC1201-T038F0200
  10 + * XMC1201-Q040F0200
  11 + *
  12 + * Copyright (c) 2015, Infineon Technologies AG
  13 + * All rights reserved.
  14 + *
  15 + * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
  16 + * following conditions are met:
  17 + *
  18 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
  19 + * disclaimer.
  20 + *
  21 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
  22 + * disclaimer in the documentation and/or other materials provided with the distribution.
  23 + *
  24 + * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
  25 + * products derived from this software without specific prior written permission.
  26 + *
  27 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  28 + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  32 + * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34 + *
  35 + * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
  36 + * Infineon Technologies AG dave@infineon.com).
  37 + *********************************************************************************************************************
  38 + *
  39 + * Change History
  40 + * --------------
  41 + *
  42 + * 2015-07-07:
  43 + * - Product splitting
  44 + * - Copyright notice update
  45 + *
  46 + * @endcond
  47 + *
  48 + */
  49 +
  50 +OUTPUT_FORMAT("elf32-littlearm")
  51 +OUTPUT_ARCH(arm)
  52 +ENTRY(Reset_Handler)
  53 +
  54 +MEMORY
  55 +{
  56 + FLASH(RX) : ORIGIN = 0x10001000, LENGTH = 0x31a00
  57 + SRAM(!RX) : ORIGIN = 0x20000000, LENGTH = 0x4000
  58 +}
  59 +
  60 +stack_size = 1536;
  61 +
  62 +SECTIONS
  63 +{
  64 + /* TEXT section */
  65 +
  66 + .text :
  67 + {
  68 + sText = .;
  69 + KEEP(*(.reset));
  70 + *(.text .text.* .gnu.linkonce.t.*);
  71 +
  72 + /* ARM <->THUMB interworking */
  73 + *(.glue*)
  74 + *(.v4*)
  75 + *(.vfp11_veneer)
  76 +
  77 + /* C++ Support */
  78 + KEEP(*(.init))
  79 + __preinit_array_start = .;
  80 + KEEP (*(.preinit_array))
  81 + __preinit_array_end = .;
  82 + __init_array_start = .;
  83 + KEEP (*(SORT(.init_array.*)))
  84 + KEEP (*(.init_array))
  85 + __init_array_end = .;
  86 + KEEP (*crtbegin.o(.ctors))
  87 + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
  88 + KEEP (*(SORT(.ctors.*)))
  89 + KEEP (*crtend.o(.ctors))
  90 + KEEP(*(.fini))
  91 + __fini_array_start = .;
  92 + KEEP (*(.fini_array))
  93 + KEEP (*(SORT(.fini_array.*)))
  94 + __fini_array_end = .;
  95 +
  96 + KEEP (*crtbegin.o(.dtors))
  97 + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
  98 + KEEP (*(SORT(.dtors.*)))
  99 + KEEP (*crtend.o(.dtors))
  100 +
  101 + /* Exception handling support */
  102 + __extab_start = .;
  103 + *(.ARM.extab* .gnu.linkonce.armextab.*)
  104 + . = ALIGN(4);
  105 + __extab_end = ABSOLUTE(.);
  106 + } > FLASH
  107 +
  108 + /* Exception handling, exidx needs a dedicated section */
  109 + .ARM.exidx :
  110 + {
  111 + __exidx_start = .;
  112 + *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  113 + . = ALIGN(4);
  114 + __exidx_end = ABSOLUTE(.);
  115 + } > FLASH
  116 +
  117 + /* CONST data section */
  118 + .rodata :
  119 + {
  120 + *(.rodata .rodata.*)
  121 + *(.gnu.linkonce.r*)
  122 + } > FLASH
  123 +
  124 + . = ALIGN(16);
  125 +
  126 + /* End of RO-DATA and start of LOAD region for the veneers */
  127 + eROData = . ;
  128 +
  129 + /* DSRAM layout (Lowest to highest)*/
  130 + /* Veneer <-> Stack <-> DATA <-> BSS <-> HEAP */
  131 +
  132 + .VENEER_Code ABSOLUTE(0x2000000C): AT(eROData)
  133 + {
  134 + VeneerStart = .;
  135 + KEEP(*(.XmcVeneerCode));
  136 + . = ALIGN(4);
  137 + VeneerEnd = .;
  138 + } > SRAM
  139 +
  140 + VeneerSize = ABSOLUTE(VeneerEnd) - ABSOLUTE(VeneerStart);
  141 +
  142 + /* Dummy section for stack */
  143 + Stack (NOLOAD) : AT(0)
  144 + {
  145 + . = ALIGN(8);
  146 + . = . + stack_size;
  147 + __initial_sp = .;
  148 + } > SRAM
  149 +
  150 + /* Standard DATA and user defined DATA/BSS/CONST sections */
  151 + DataLoadAddr = eROData + VeneerSize;
  152 + .data : AT(DataLoadAddr)
  153 + {
  154 + __data_start = .;
  155 + * (.data);
  156 + * (.data*);
  157 + *(*.data);
  158 + *(.gnu.linkonce.d*)
  159 + . = ALIGN(4);
  160 + __data_end = .;
  161 + } > SRAM
  162 + __data_size = __data_end - __data_start;
  163 +
  164 + .ram_code : AT(DataLoadAddr + __data_size)
  165 + {
  166 + __ram_code_start = .;
  167 + /* functions with __attribute__ ((section (".ram_code")))*/
  168 + *(.ram_code)
  169 + . = ALIGN(4);
  170 + __ram_code_end = .;
  171 + } > SRAM
  172 + __ram_code_load = LOADADDR (.ram_code);
  173 + __ram_code_size = __ram_code_end - __ram_code_start;
  174 +
  175 + /* BSS section */
  176 + .bss (NOLOAD) :
  177 + {
  178 + __bss_start = .;
  179 + * (.bss);
  180 + * (.bss*);
  181 + * (COMMON);
  182 + *(.gnu.linkonce.b*)
  183 + . = ALIGN(4);
  184 + __bss_end = .;
  185 + . = ALIGN(8);
  186 + Heap_Bank1_Start = .;
  187 + } > SRAM
  188 + __bss_size = __bss_end - __bss_start;
  189 +
  190 + /* .no_init section */
  191 + .no_init 0x20003FFC (NOLOAD) :
  192 + {
  193 + Heap_Bank1_End = .;
  194 + * (.no_init);
  195 + } > SRAM
  196 +
  197 + /* Heap - Bank1*/
  198 + Heap_Bank1_Size = Heap_Bank1_End - Heap_Bank1_Start;
  199 +
  200 + /DISCARD/ :
  201 + {
  202 + *(.comment)
  203 + }
  204 +
  205 + .stab 0 (NOLOAD) : { *(.stab) }
  206 + .stabstr 0 (NOLOAD) : { *(.stabstr) }
  207 +
  208 + /* DWARF 1 */
  209 + .debug 0 : { *(.debug) }
  210 + .line 0 : { *(.line) }
  211 +
  212 + /* GNU DWARF 1 extensions */
  213 + .debug_srcinfo 0 : { *(.debug_srcinfo) }
  214 + .debug_sfnames 0 : { *(.debug_sfnames) }
  215 +
  216 + /* DWARF 1.1 and DWARF 2 */
  217 + .debug_aranges 0 : { *(.debug_aranges) }
  218 + .debug_pubnames 0 : { *(.debug_pubnames) }
  219 + .debug_pubtypes 0 : { *(.debug_pubtypes) }
  220 +
  221 + /* DWARF 2 */
  222 + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
  223 + .debug_abbrev 0 : { *(.debug_abbrev) }
  224 + .debug_line 0 : { *(.debug_line) }
  225 + .debug_frame 0 : { *(.debug_frame) }
  226 + .debug_str 0 : { *(.debug_str) }
  227 + .debug_loc 0 : { *(.debug_loc) }
  228 + .debug_macinfo 0 : { *(.debug_macinfo) }
  229 +
  230 + /* DWARF 2.1 */
  231 + .debug_ranges 0 : { *(.debug_ranges) }
  232 +
  233 + /* SGI/MIPS DWARF 2 extensions */
  234 + .debug_weaknames 0 : { *(.debug_weaknames) }
  235 + .debug_funcnames 0 : { *(.debug_funcnames) }
  236 + .debug_typenames 0 : { *(.debug_typenames) }
  237 + .debug_varnames 0 : { *(.debug_varnames) }
  238 +
  239 + /* Build attributes */
  240 + .build_attributes 0 : { *(.ARM.attributes) }
  241 +}
... ...
src/dali/commands.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_COMMANDS_HPP_
  12 +#define DALI_COMMANDS_HPP_
  13 +
  14 +#include <stdint.h>
  15 +
  16 +namespace dali {
  17 +
  18 +enum class Command {
  19 + // Power control commands
  20 + OFF = 0,
  21 + UP = 1,
  22 + DOWN = 2,
  23 + STEP_UP = 3,
  24 + STEP_DOWN = 4,
  25 + RECALL_MAX_LEVEL = 5,
  26 + RECALL_MIN_LEVEL = 6,
  27 + STEP_DOWN_AND_OFF = 7,
  28 + ON_AND_STEP_UP = 8,
  29 +
  30 + ENABLE_DAPC_SEQUENCE = 9,
  31 +
  32 + GO_TO_SCENE_0 = 16,
  33 + GO_TO_SCENE_1 = 17,
  34 + GO_TO_SCENE_2 = 18,
  35 + GO_TO_SCENE_3 = 19,
  36 + GO_TO_SCENE_4 = 20,
  37 + GO_TO_SCENE_5 = 21,
  38 + GO_TO_SCENE_6 = 22,
  39 + GO_TO_SCENE_7 = 23,
  40 + GO_TO_SCENE_8 = 24,
  41 + GO_TO_SCENE_9 = 25,
  42 + GO_TO_SCENE_A = 26,
  43 + GO_TO_SCENE_B = 27,
  44 + GO_TO_SCENE_C = 28,
  45 + GO_TO_SCENE_D = 29,
  46 + GO_TO_SCENE_E = 30,
  47 + GO_TO_SCENE_F = 31,
  48 + RESET = 32,
  49 + STORE_ACTUAL_LEVEL_IN_DTR = 33,
  50 + STORE_DTR_AS_MAX_LEVEL = 42,
  51 + STORE_DTR_AS_MIN_LEVEL = 43,
  52 + STORE_DTR_AS_SYS_FAIL_LEVEL = 44,
  53 + STORE_DTR_AS_POWER_ON_LEVEL = 45,
  54 + STORE_DTR_AS_FADE_TIME = 46,
  55 + STORE_DTR_AS_FADE_RATE = 47,
  56 + STORE_DTR_AS_SCENE_0 = 64,
  57 + STORE_DTR_AS_SCENE_1 = 65,
  58 + STORE_DTR_AS_SCENE_2 = 66,
  59 + STORE_DTR_AS_SCENE_3 = 67,
  60 + STORE_DTR_AS_SCENE_4 = 68,
  61 + STORE_DTR_AS_SCENE_5 = 69,
  62 + STORE_DTR_AS_SCENE_6 = 70,
  63 + STORE_DTR_AS_SCENE_7 = 71,
  64 + STORE_DTR_AS_SCENE_8 = 72,
  65 + STORE_DTR_AS_SCENE_9 = 73,
  66 + STORE_DTR_AS_SCENE_A = 74,
  67 + STORE_DTR_AS_SCENE_B = 75,
  68 + STORE_DTR_AS_SCENE_C = 76,
  69 + STORE_DTR_AS_SCENE_D = 77,
  70 + STORE_DTR_AS_SCENE_E = 78,
  71 + STORE_DTR_AS_SCENE_F = 79,
  72 + REMOVE_FROM_SCENE_0 = 80, // to 95
  73 + REMOVE_FROM_SCENE_1 = 81,
  74 + REMOVE_FROM_SCENE_2 = 82,
  75 + REMOVE_FROM_SCENE_3 = 83,
  76 + REMOVE_FROM_SCENE_4 = 84,
  77 + REMOVE_FROM_SCENE_5 = 85,
  78 + REMOVE_FROM_SCENE_6 = 86,
  79 + REMOVE_FROM_SCENE_7 = 87,
  80 + REMOVE_FROM_SCENE_8 = 88,
  81 + REMOVE_FROM_SCENE_9 = 89,
  82 + REMOVE_FROM_SCENE_A = 90,
  83 + REMOVE_FROM_SCENE_B = 91,
  84 + REMOVE_FROM_SCENE_C = 92,
  85 + REMOVE_FROM_SCENE_D = 93,
  86 + REMOVE_FROM_SCENE_E = 94,
  87 + REMOVE_FROM_SCENE_F = 95,
  88 + ADD_TO_GROUP_0 = 96,
  89 + ADD_TO_GROUP_1 = 97,
  90 + ADD_TO_GROUP_2 = 98,
  91 + ADD_TO_GROUP_3 = 99,
  92 + ADD_TO_GROUP_4 = 100,
  93 + ADD_TO_GROUP_5 = 101,
  94 + ADD_TO_GROUP_6 = 102,
  95 + ADD_TO_GROUP_7 = 103,
  96 + ADD_TO_GROUP_8 = 104,
  97 + ADD_TO_GROUP_9 = 105,
  98 + ADD_TO_GROUP_A = 106,
  99 + ADD_TO_GROUP_B = 107,
  100 + ADD_TO_GROUP_C = 108,
  101 + ADD_TO_GROUP_D = 109,
  102 + ADD_TO_GROUP_E = 110,
  103 + ADD_TO_GROUP_F = 111,
  104 + REMOVE_FROM_GROUP_0 = 112,
  105 + REMOVE_FROM_GROUP_1 = 113,
  106 + REMOVE_FROM_GROUP_2 = 114,
  107 + REMOVE_FROM_GROUP_3 = 115,
  108 + REMOVE_FROM_GROUP_4 = 116,
  109 + REMOVE_FROM_GROUP_5 = 117,
  110 + REMOVE_FROM_GROUP_6 = 118,
  111 + REMOVE_FROM_GROUP_7 = 119,
  112 + REMOVE_FROM_GROUP_8 = 120,
  113 + REMOVE_FROM_GROUP_9 = 121,
  114 + REMOVE_FROM_GROUP_A = 122,
  115 + REMOVE_FROM_GROUP_B = 123,
  116 + REMOVE_FROM_GROUP_C = 124,
  117 + REMOVE_FROM_GROUP_D = 125,
  118 + REMOVE_FROM_GROUP_E = 126,
  119 + REMOVE_FROM_GROUP_F = 127,
  120 + STORE_DTR_AS_SHORT_ADDR = 128,
  121 + ENABLE_WRITE_MEMORY = 129,
  122 +
  123 + // Query commands
  124 + QUERY_STATUS = 144,
  125 + QUERY_CONTROL_GEAR = 145,
  126 + QUERY_LAMP_FAILURE = 146,
  127 + QUERY_LAMP_POWER_ON = 147,
  128 + QUERY_LIMIT_ERROR = 148,
  129 + QUERY_RESET_STATE = 149,
  130 + QUERY_MISSING_SHORT_ADDR = 150,
  131 + QUERY_VERSION_NUMBER = 151,
  132 + QUERY_CONTENT_DTR = 152,
  133 + QUERY_DEVICE_TYPE = 153,
  134 + QUERY_PHISICAL_MIN_LEVEL = 154,
  135 + QUERY_POWER_FAILURE = 155,
  136 + QUERY_CONTENT_DTR1 = 156,
  137 + QUERY_CONTENT_DTR2 = 157,
  138 +
  139 + QUERY_ACTUAL_LEVEL = 160,
  140 + QUERY_MAX_LEVEL = 161,
  141 + QUERY_MIN_LEVEL = 162,
  142 + QUERY_POWER_ON_LEVEL = 163,
  143 + QUERY_SYS_FAILURE_LEVEL = 164,
  144 + QUERY_FADE_TIME_OR_RATE = 165,
  145 + QUERY_SCENE_0_LEVEL = 176, // to 191
  146 + QUERY_SCENE_1_LEVEL = 177,
  147 + QUERY_SCENE_2_LEVEL = 178,
  148 + QUERY_SCENE_3_LEVEL = 179,
  149 + QUERY_SCENE_4_LEVEL = 180,
  150 + QUERY_SCENE_5_LEVEL = 181,
  151 + QUERY_SCENE_6_LEVEL = 182,
  152 + QUERY_SCENE_7_LEVEL = 183,
  153 + QUERY_SCENE_8_LEVEL = 184,
  154 + QUERY_SCENE_9_LEVEL = 185,
  155 + QUERY_SCENE_A_LEVEL = 186,
  156 + QUERY_SCENE_B_LEVEL = 187,
  157 + QUERY_SCENE_C_LEVEL = 188,
  158 + QUERY_SCENE_D_LEVEL = 189,
  159 + QUERY_SCENE_E_LEVEL = 190,
  160 + QUERY_SCENE_F_LEVEL = 191,
  161 + QUERY_GROUPS_L = 192,
  162 + QUERY_GROUPS_H = 193,
  163 + QUERY_RANDOM_ADDR_H = 194,
  164 + QUERY_RANDOM_ADDR_M = 195,
  165 + QUERY_RANDOM_ADDR_L = 196,
  166 + READ_MEMORY_LOCATION = 197,
  167 +
  168 + QUERY_EXTENDED_VERSION_NUMBER = 255,
  169 +
  170 + // Special commands
  171 + _SPECIAL_COMMAND = 1024, // not for use
  172 +
  173 + DIRECT_POWER_CONTROL = _SPECIAL_COMMAND,
  174 + TERMINATE = _SPECIAL_COMMAND + 161, // 256
  175 + DATA_TRANSFER_REGISTER = _SPECIAL_COMMAND + 163, // 257
  176 + INITIALISE = _SPECIAL_COMMAND + 165, // 258
  177 + RANDOMISE = _SPECIAL_COMMAND + 167, // 259
  178 + COMPARE = _SPECIAL_COMMAND + 169, // 260
  179 + WITHDRAW = _SPECIAL_COMMAND + 171, // 261
  180 + SEARCHADDRH = _SPECIAL_COMMAND + 177, // 264
  181 + SEARCHADDRM = _SPECIAL_COMMAND + 179, // 265
  182 + SEARCHADDRL = _SPECIAL_COMMAND + 181, // 266,
  183 + PROGRAM_SHORT_ADDRESS = _SPECIAL_COMMAND + 183, // 267
  184 + VERIFY_SHORT_ADDRESS = _SPECIAL_COMMAND + 185, // 268
  185 + QUERY_SHORT_ADDRESS = _SPECIAL_COMMAND + 187, // 269
  186 + PHYSICAL_SELECTION = _SPECIAL_COMMAND + 189, // 270
  187 + ENABLE_DEVICE_TYPE_X = _SPECIAL_COMMAND + 193, // 272
  188 + DATA_TRANSFER_REGISTER_1 = _SPECIAL_COMMAND + 195, // 273
  189 + DATA_TRANSFER_REGISTER_2 = _SPECIAL_COMMAND + 197, // 274
  190 + WRITE_MEMORY_LOCATION = _SPECIAL_COMMAND + 199, // 275
  191 +
  192 + INVALID = 0xffff,
  193 +};
  194 +
  195 +}
  196 +// namespace dali
  197 +
  198 +#endif // DALI_COMMANDS_HPP_
... ...
src/dali/config.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_CONFIG_H_
  12 +#define DALI_CONFIG_H_
  13 +
  14 +#define DALI_VERSION 1
  15 +#define DALI_DEVICE_TYPE 8
  16 +
  17 +#define DALI_BANKS 3
  18 +#define DALI_BANK0_ADDR 0 // Bank 0 (16 bytes) according to 62386-102
  19 +#define DALI_BANK1_ADDR 16 // Bank 1 (16 bytes) according to 62386-102
  20 +#define DALI_BANK2_ADDR 32 // Bank 2 (28 bytes) data 62386-102 (26 bytes)
  21 +#define DALI_BANK3_ADDR 60
  22 +
  23 +#define DALI_PHISICAL_MIN_LEVEL 1
  24 +
  25 +#endif // DALI_CONFIG_H_
... ...
src/dali/controller/bus.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "bus.hpp"
  12 +
  13 +#include <dali/config.hpp>
  14 +
  15 +namespace dali {
  16 +namespace controller {
  17 +namespace {
  18 +
  19 +const uint64_t kCommandRepeatTimeout = 100;
  20 +
  21 +}
  22 +
  23 +Bus::Bus(IBus* bus) :
  24 + mBus(bus),
  25 + mState(IBus::IBusState::UNKNOWN),
  26 + mListener(nullptr),
  27 + mLastCommand(Command::INVALID),
  28 + mCommandRepeatCount(0),
  29 + mLastCommandTimeMs(0) {
  30 + mBus->registerClient(this);
  31 +}
  32 +
  33 +Bus::~Bus() {
  34 + mBus->unregisterClient(this);
  35 +}
  36 +
  37 +void Bus::setListener(Listener* listener) {
  38 + mListener = listener;
  39 +}
  40 +
  41 +void Bus::onDataReceived(uint64_t timeMs, uint16_t data) {
  42 + Command command;
  43 + uint8_t param;
  44 + if (filterAddress(data, &command, &param) != Status::OK) {
  45 + return; // Status::INVALID;
  46 + }
  47 + if (command != Command::INVALID) { // should be always true
  48 + if (mLastCommand == Command::INVALID) {
  49 + mCommandRepeatCount = 0;
  50 + mLastCommandTimeMs = timeMs;
  51 + Status status = mListener->handleCommand(mCommandRepeatCount, command, param);
  52 + if (status == Status::REPEAT_REQUIRED) {
  53 + mLastCommand = command;
  54 + return; // Status::OK;
  55 + } else {
  56 + mLastCommand = Command::INVALID;
  57 + return; // status;
  58 + }
  59 + } else if (mLastCommand == command) {
  60 + if (timeMs - mLastCommandTimeMs < kCommandRepeatTimeout) {
  61 + mCommandRepeatCount++;
  62 + } else {
  63 + mLastCommand = Command::INVALID;
  64 + mCommandRepeatCount = 0;
  65 + }
  66 + mLastCommandTimeMs = timeMs;
  67 + Status status = mListener->handleCommand(mCommandRepeatCount, command, param);
  68 + if (status == Status::REPEAT_REQUIRED) {
  69 + mLastCommand = command;
  70 + return; // Status::OK;
  71 + } else {
  72 + mLastCommand = Command::INVALID;
  73 + return; // status;
  74 + }
  75 + } else { // (mLastCommand != Command::INVALID) || (mLastCommand != cmd)
  76 + mLastCommand = Command::INVALID;
  77 + mCommandRepeatCount = 0;
  78 + if (timeMs - mLastCommandTimeMs < kCommandRepeatTimeout) {
  79 + mLastCommandTimeMs = timeMs;
  80 + mListener->handleIgnoredCommand(command, param);
  81 + } else {
  82 + mLastCommandTimeMs = timeMs;
  83 + Status status = mListener->handleCommand(mCommandRepeatCount, command, param);
  84 + if (status == Status::REPEAT_REQUIRED) {
  85 + mLastCommand = command;
  86 + return; // Status::OK;
  87 + } else {
  88 + return; // status;
  89 + }
  90 + }
  91 + }
  92 + }
  93 + return; // Status::INVALID;
  94 +}
  95 +
  96 +void Bus::onBusStateChanged(IBus::IBusState state) {
  97 + if (mState != state) {
  98 + mState = state;
  99 + if (state == IBus::IBusState::DISCONNECTED) {
  100 + mListener->onBusDisconnected();
  101 + }
  102 + }
  103 +}
  104 +
  105 +Status Bus::sendAck(uint8_t ack) {
  106 + return mBus->sendAck(ack);
  107 +}
  108 +
  109 +Status Bus::filterAddress(uint16_t data, Command* command, uint8_t* param) {
  110 + *param = (uint8_t) (data & 0xff);
  111 + *command = Command::INVALID;
  112 + uint8_t addr = (uint8_t) (data >> 8);
  113 + bool cmdBitSet = ((addr & 0x01) != 0);
  114 + if ((addr & 0xfe) == 0xfe) {
  115 + // Broadcast
  116 + if (cmdBitSet) {
  117 + *command = (Command) *param;
  118 + *param = 0xff;
  119 + } else {
  120 + *command = Command::DIRECT_POWER_CONTROL;
  121 + }
  122 + } else if ((addr & 0x80) == 0) {
  123 + // Short address
  124 + addr >>= 1;
  125 + uint8_t myAddr = mListener->getShortAddr() >> 1;
  126 + if (cmdBitSet) {
  127 + *command = (Command) *param;
  128 + *param = 0xff;
  129 + } else {
  130 + *command = Command::DIRECT_POWER_CONTROL;
  131 + }
  132 + if (addr != myAddr) {
  133 + return Status::INVALID;
  134 + }
  135 + } else if ((addr & 0x60) == 0) {
  136 + // Group address
  137 + uint8_t group = (addr >> 1) & 0x0f;
  138 + uint16_t groups = mListener->getGroups();
  139 + if (cmdBitSet) {
  140 + *command = (Command) *param;
  141 + *param = 0xff;
  142 + } else {
  143 + *command = Command::DIRECT_POWER_CONTROL;
  144 + }
  145 + if ((groups & (1 << group)) == 0) {
  146 + return Status::INVALID;
  147 + }
  148 + } else {
  149 + *command = (Command) ((uint16_t) Command::_SPECIAL_COMMAND + addr);
  150 + if (*command == Command::INITIALISE) {
  151 + uint8_t myAddr = mListener->getShortAddr() >> 1;
  152 + switch (*param) {
  153 + case 0x00: // All control gear shall react
  154 + break;
  155 + case 0xff: // Control gear without short address shall react
  156 + if (myAddr <= DALI_ADDR_MAX) {
  157 + return Status::INVALID;
  158 + }
  159 + break;
  160 + default: // Control gear with the address AAAAAAb shall react
  161 + if (myAddr != (*param >> 1)) {
  162 + return Status::INVALID;
  163 + }
  164 + break;
  165 + }
  166 + }
  167 + }
  168 + return Status::OK;
  169 +}
  170 +
  171 +} // namespace controller
  172 +}// namespace dali
... ...
src/dali/controller/bus.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_BUS_CONTROLLER_H_
  12 +#define DALI_BUS_CONTROLLER_H_
  13 +
  14 +#include <dali/dali.hpp>
  15 +
  16 +namespace dali {
  17 +namespace controller {
  18 +
  19 +class Bus: public IBus::IBusClient {
  20 +public:
  21 +
  22 + class Listener {
  23 + public:
  24 + virtual uint8_t getShortAddr() = 0;
  25 + virtual uint16_t getGroups() = 0;
  26 + virtual Status handleCommand(uint16_t repeat, Command cmd, uint8_t param) = 0;
  27 + virtual Status handleIgnoredCommand(Command cmd, uint8_t param) = 0;
  28 + virtual void onBusDisconnected() = 0;
  29 + };
  30 +
  31 + explicit Bus(IBus* bus);
  32 + virtual ~Bus();
  33 +
  34 + void setListener(Listener* listener);
  35 +
  36 + void onDataReceived(uint64_t timeMs, uint16_t data) override;
  37 + void onBusStateChanged(IBus::IBusState state) override;
  38 +
  39 + Status sendAck(uint8_t ack);
  40 + uint64_t getLastCommandTimeMs() {
  41 + return mLastCommandTimeMs;
  42 + }
  43 +
  44 +private:
  45 + Bus(const Bus& other) = delete;
  46 + Bus& operator=(const Bus&) = delete;
  47 +
  48 + Status filterAddress(uint16_t data, Command* command, uint8_t* param);
  49 +
  50 + IBus* const mBus;
  51 + IBus::IBusState mState;
  52 + Listener* mListener;
  53 + Command mLastCommand;
  54 + uint16_t mCommandRepeatCount;
  55 + uint64_t mLastCommandTimeMs;
  56 +};
  57 +
  58 +} // namespace controller
  59 +} // namespace dali
  60 +
  61 +#endif // DALI_BUS_CONTROLLER_H_
... ...
src/dali/controller/initialization.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "initialization.hpp"
  12 +
  13 +#include "bus.hpp"
  14 +#include "memory.hpp"
  15 +
  16 +namespace dali {
  17 +namespace controller {
  18 +
  19 +Initialization::Initialization(ITimer* timer, Memory* memoryController) :
  20 + mTimer(timer),
  21 + mMemoryController(memoryController),
  22 + mInitializeTime(0),
  23 + mInitialized(false),
  24 + mWithdraw(false),
  25 + mSelected(Selection::NONE) {
  26 +}
  27 +
  28 +Status Initialization::initialize(uint8_t param) {
  29 + checkOperatingTimeout();
  30 +
  31 + if (!mInitialized) {
  32 + mInitialized = true;
  33 + operatingTimeStart();
  34 + return Status::OK;
  35 + } else {
  36 + return Status::INVALID_STATE;
  37 + }
  38 +}
  39 +
  40 +Status Initialization::randomize() {
  41 + checkOperatingTimeout();
  42 +
  43 + uint32_t randomAddr = mTimer->randomize();
  44 + randomAddr &= 0x00ffffff;
  45 + mMemoryController->setRandomAddr(randomAddr);
  46 + return Status::OK;
  47 +}
  48 +
  49 +Status Initialization::compare() {
  50 + checkOperatingTimeout();
  51 +
  52 + if (mInitialized) {
  53 + switch (mSelected) {
  54 + case Selection::NONE:
  55 + case Selection::SELECTED: {
  56 + if (mWithdraw) {
  57 + return Status::INVALID;
  58 + }
  59 + uint32_t searchAddr = mMemoryController->getSearchAddr();
  60 + uint32_t randomAddr = mMemoryController->getRandomAddr();
  61 + if (randomAddr <= searchAddr) {
  62 + return Status::OK;
  63 + }
  64 + return Status::INVALID;
  65 + }
  66 +
  67 + default:
  68 + return Status::INVALID_STATE;
  69 + }
  70 + }
  71 + return Status::INVALID_STATE;
  72 +}
  73 +
  74 +Status Initialization::withdraw() {
  75 + checkOperatingTimeout();
  76 +
  77 + if (mInitialized) {
  78 + switch (mSelected) {
  79 + case Selection::NONE:
  80 + case Selection::SELECTED: {
  81 + uint32_t searchAddr = mMemoryController->getSearchAddr();
  82 + uint32_t randomAddr = mMemoryController->getRandomAddr();
  83 + if (searchAddr == randomAddr) {
  84 + mWithdraw = true;
  85 + }
  86 + return Status::OK;
  87 + }
  88 +
  89 + default:
  90 + return Status::INVALID_STATE;
  91 + }
  92 + }
  93 + return Status::INVALID_STATE;
  94 +}
  95 +
  96 +Status Initialization::searchAddrH(uint8_t addr) {
  97 + checkOperatingTimeout();
  98 +
  99 + if (mInitialized) {
  100 + return setSearchAddr(addr, 16);
  101 + }
  102 + return Status::INVALID_STATE;
  103 +}
  104 +
  105 +Status Initialization::searchAddrM(uint8_t addr) {
  106 + checkOperatingTimeout();
  107 +
  108 + if (mInitialized) {
  109 + return setSearchAddr(addr, 8);
  110 + }
  111 + return Status::INVALID_STATE;
  112 +}
  113 +
  114 +Status Initialization::searchAddrL(uint8_t addr) {
  115 + checkOperatingTimeout();
  116 +
  117 + if (mInitialized) {
  118 + return setSearchAddr(addr, 0);
  119 + }
  120 + return Status::INVALID_STATE;
  121 +}
  122 +
  123 +Status Initialization::programShortAddr(uint8_t addr) {
  124 + checkOperatingTimeout();
  125 +
  126 + if ((addr != DALI_MASK) && ((addr >> 1) > DALI_ADDR_MAX)) {
  127 + return Status::ERROR;
  128 + }
  129 +
  130 + if (mInitialized) {
  131 + switch (mSelected) {
  132 + case Selection::NONE:
  133 + case Selection::SELECTED: {
  134 + uint32_t searchAddr = mMemoryController->getSearchAddr();
  135 + uint32_t randomAddr = mMemoryController->getRandomAddr();
  136 + if (searchAddr == randomAddr) {
  137 + return mMemoryController->setShortAddr(addr);
  138 + }
  139 + return Status::OK;
  140 + }
  141 +
  142 + case Selection::PHYSICAL_SELECTED:
  143 + return mMemoryController->setShortAddr(addr);
  144 +
  145 + default:
  146 + return Status::INVALID_STATE;
  147 + }
  148 + }
  149 + return Status::INVALID_STATE;
  150 +}
  151 +
  152 +Status Initialization::verifySortAddr(uint8_t addr) {
  153 + checkOperatingTimeout();
  154 +
  155 + if (mInitialized) {
  156 + uint8_t myAddr = mMemoryController->getShortAddr();
  157 + if (myAddr == addr) {
  158 + return Status::OK;
  159 + }
  160 + return Status::INVALID;
  161 + }
  162 + return Status::INVALID_STATE;
  163 +}
  164 +
  165 +Status Initialization::queryShortAddr(uint8_t* addr) {
  166 + checkOperatingTimeout();
  167 +
  168 + if (mInitialized) {
  169 + switch (mSelected) {
  170 + case Selection::NONE:
  171 + case Selection::SELECTED: {
  172 + uint32_t searchAddr = mMemoryController->getSearchAddr();
  173 + uint32_t randomAddr = mMemoryController->getRandomAddr();
  174 + if (searchAddr == randomAddr) {
  175 + *addr = mMemoryController->getShortAddr();
  176 + return Status::OK;
  177 + }
  178 + return Status::INVALID;
  179 + }
  180 +
  181 + case Selection::PHYSICAL_SELECTED: {
  182 + *addr = mMemoryController->getShortAddr();
  183 + return Status::OK;
  184 + }
  185 +
  186 + default:
  187 + return Status::INVALID_STATE;
  188 + }
  189 + }
  190 + return Status::INVALID_STATE;
  191 +}
  192 +
  193 +Status Initialization::physicalSelection() {
  194 + checkOperatingTimeout();
  195 +
  196 + if (mInitialized) {
  197 + switch (mSelected) {
  198 + case Selection::NONE:
  199 + mSelected = Selection::SELECTED;
  200 + break;
  201 +
  202 + case Selection::PHYSICAL_SELECTED:
  203 + mSelected = Selection::SELECTED;
  204 + break;
  205 +
  206 + default:
  207 + mSelected = Selection::NONE;
  208 + break;
  209 + }
  210 + return Status::OK;
  211 + }
  212 + return Status::INVALID_STATE;
  213 +}
  214 +
  215 +Status Initialization::terminate() {
  216 + if (mInitialized) {
  217 + operatingTimeStop();
  218 + mInitialized = false;
  219 + mWithdraw = false;
  220 + mSelected = Selection::NONE;
  221 + return Status::OK;
  222 + }
  223 + return Status::INVALID_STATE;
  224 +}
  225 +
  226 +void Initialization::reset() {
  227 + checkOperatingTimeout();
  228 + // TODO check what should be reset
  229 + mSelected = Selection::NONE;
  230 + mWithdraw = false;
  231 +}
  232 +
  233 +void Initialization::onLampStateChnaged(ILamp::ILampState state) {
  234 + switch (state) {
  235 + case ILamp::ILampState::DISCONNECTED:
  236 + if (mSelected == Selection::SELECTED) {
  237 + mSelected = Selection::PHYSICAL_SELECTED;
  238 + }
  239 + break;
  240 +
  241 + case ILamp::ILampState::OK:
  242 + if (mSelected == Selection::PHYSICAL_SELECTED) {
  243 + mSelected = Selection::SELECTED;
  244 + }
  245 + break;
  246 +
  247 + default:
  248 + break;
  249 + }
  250 +}
  251 +
  252 +Status Initialization::setSearchAddr(uint8_t addr, uint8_t offset) {
  253 + uint32_t searchAddr = mMemoryController->getSearchAddr();
  254 + searchAddr &= ~((uint32_t) 0xff << offset);
  255 + searchAddr |= (uint32_t) addr << offset;
  256 + mMemoryController->setSearchAddr(searchAddr);
  257 + return Status::OK;
  258 +}
  259 +
  260 +void Initialization::operatingTimeStart() {
  261 + mInitializeTime = mTimer->getTime();
  262 + mInitializeTime += 1000 * 60 * 60 * 15; // 15min
  263 +}
  264 +
  265 +void Initialization::operatingTimeStop() {
  266 + mInitializeTime = 0;
  267 +}
  268 +
  269 +void Initialization::checkOperatingTimeout() {
  270 + if ((mInitializeTime != 0) && (mTimer->getTime() > mInitializeTime)) {
  271 + terminate();
  272 + }
  273 +}
  274 +
  275 +} // namespace controller
  276 +} // namespace dali
... ...
src/dali/controller/initialization.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_CONFIGURATION_CONTROLER_H_
  12 +#define DALI_CONFIGURATION_CONTROLER_H_
  13 +
  14 +#include <dali/dali.hpp>
  15 +
  16 +namespace dali {
  17 +namespace controller {
  18 +
  19 +class Memory;
  20 +class Bus;
  21 +
  22 +class Initialization {
  23 +public:
  24 + explicit Initialization(ITimer* timer, Memory* memoryController);
  25 + virtual ~Initialization() {}
  26 +
  27 + Status initialize(uint8_t param);
  28 + Status randomize();
  29 + Status compare();
  30 + Status withdraw();
  31 + Status searchAddrH(uint8_t addr);
  32 + Status searchAddrM(uint8_t addr);
  33 + Status searchAddrL(uint8_t addr);
  34 + Status programShortAddr(uint8_t addr);
  35 + Status verifySortAddr(uint8_t addr);
  36 + Status queryShortAddr(uint8_t* addr);
  37 + Status physicalSelection();
  38 + Status terminate();
  39 + void reset();
  40 +
  41 + void onLampStateChnaged(ILamp::ILampState state);
  42 +
  43 +private:
  44 + Initialization(const Initialization& other) = delete;
  45 + Initialization& operator=(const Initialization&) = delete;
  46 +
  47 + enum class Selection {
  48 + NONE, SELECTED, PHYSICAL_SELECTED
  49 + };
  50 +
  51 + Status setSearchAddr(uint8_t addr, uint8_t offset);
  52 +
  53 + void operatingTimeStart();
  54 + void operatingTimeStop();
  55 + void checkOperatingTimeout();
  56 +
  57 + ITimer* const mTimer;
  58 + Memory* const mMemoryController;
  59 + uint64_t mInitializeTime;
  60 + bool mInitialized;
  61 + bool mWithdraw;
  62 + Selection mSelected;
  63 +};
  64 +
  65 +} // namespace controller
  66 +} // namespace dali
  67 +
  68 +#endif // DALI_CONFIGURATION_CONTROLER_H_
... ...
src/dali/controller/lamp.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "lamp.hpp"
  12 +
  13 +#include "lamp_helper.hpp"
  14 +
  15 +#define DAPC_TIME_MS 200
  16 +
  17 +namespace dali {
  18 +namespace controller {
  19 +
  20 +Lamp::Lamp(ILamp* lamp, Memory* memoryController)
  21 + : mLamp(lamp)
  22 + , mMemoryController(memoryController)
  23 + , mLampState(ILamp::ILampState::OK)
  24 + , mListener(nullptr)
  25 + , mIsPowerSet(false)
  26 + , mLimitError(false)
  27 + , mDapcTime(0)
  28 + , mConstPower(DALI_MASK) {
  29 + mLamp->registerClient(this);
  30 + setLevel(mMemoryController->getPhisicalMinLevel(), 0);
  31 +}
  32 +
  33 +Lamp::~Lamp() {
  34 + mLamp->unregisterClient(this);
  35 +}
  36 +
  37 +void Lamp::onReset() {
  38 + setLevel(mMemoryController->getMaxLevel(), 0);
  39 + mIsPowerSet = true;
  40 +}
  41 +
  42 +bool Lamp::isPowerOn() {
  43 + return (mLamp->getLevel() > 0);
  44 +}
  45 +
  46 +bool Lamp::isFailure() {
  47 + switch (mLampState) {
  48 + case ILamp::ILampState::DISCONNECTED:
  49 + case ILamp::ILampState::OVERHEAT:
  50 + return true;
  51 + default:
  52 + return false;
  53 + }
  54 +}
  55 +
  56 +bool Lamp::isFading() {
  57 + return mLamp->isFading();
  58 +}
  59 +
  60 +bool Lamp::isLimitError() {
  61 + return mLimitError;
  62 +}
  63 +
  64 +bool Lamp::isPowerSet() {
  65 + return mIsPowerSet;
  66 +}
  67 +
  68 +uint8_t Lamp::getLevel() {
  69 + if (mLampState == ILamp::ILampState::OK) {
  70 + return driver2level(mLamp->getLevel(), mMemoryController->getMinLevel());
  71 + }
  72 + return mMemoryController->getActualLevel();
  73 +}
  74 +
  75 +Status Lamp::setLevel(uint8_t level, uint32_t fadeTime) {
  76 + mLimitError = false;
  77 +
  78 + Status status = Status::OK;
  79 + if (level != DALI_MASK) {
  80 + uint8_t minLevel = mMemoryController->getMinLevel();
  81 + uint8_t maxLevel = mMemoryController->getMaxLevel();
  82 +
  83 + if ((level != 0) && (level < minLevel)) {
  84 + mLimitError = true;
  85 + level = minLevel;
  86 + }
  87 + if (level > maxLevel) {
  88 + mLimitError = true;
  89 + level = maxLevel;
  90 + }
  91 +
  92 + mLamp->setLevel(level2driver(level), fadeTime);
  93 + status = mMemoryController->setActualLevel(level);
  94 + }
  95 + return status;
  96 +}
  97 +
  98 +uint32_t Lamp::getFadeTime() {
  99 + return kFadeTime[mMemoryController->getFadeTime()];
  100 +}
  101 +
  102 +uint32_t Lamp::getFadeRate() {
  103 + return kFadeTime[mMemoryController->getFadeRate()];
  104 +}
  105 +
  106 +Status Lamp::abortFading() {
  107 + if (mLamp->isFading()) {
  108 + mLamp->abortFading();
  109 + uint8_t level = driver2level(mLamp->getLevel(), mMemoryController->getMinLevel());
  110 + return mMemoryController->setActualLevel(level);
  111 + }
  112 + return Status::OK;
  113 +}
  114 +
  115 +void Lamp::setListener(Listener* listener) {
  116 + mListener = listener;
  117 +}
  118 +
  119 +void Lamp::notifyPowerDown() {
  120 + mLamp->setLevel(0, 0);
  121 +}
  122 +
  123 +Status Lamp::powerDirect(uint8_t level, uint64_t time) {
  124 + if (level == DALI_MASK) {
  125 + mLamp->abortFading();
  126 + return Status::OK;
  127 + }
  128 + if (time - mDapcTime <= DAPC_TIME_MS) {
  129 + return dapcSequence(level, time);
  130 + }
  131 + onPowerCommand();
  132 + return setLevel(level, getFadeTime());
  133 +}
  134 +
  135 +Status Lamp::powerOff() {
  136 + onPowerCommand();
  137 + return setLevel(0, 0);
  138 +}
  139 +
  140 +Status Lamp::powerScene(uint8_t scene) {
  141 + uint8_t level = mMemoryController->getLevelForScene(scene);
  142 + if (level == DALI_MASK) {
  143 + level = mMemoryController->getActualLevel();
  144 + }
  145 + onPowerCommand();
  146 + return setLevel(level, getFadeTime());
  147 +}
  148 +
  149 +Status Lamp::powerUp() {
  150 + onPowerCommand();
  151 + uint8_t fade = mMemoryController->getFadeRate();
  152 + uint8_t steps = kStepsFor200FadeRate[fade];
  153 + uint8_t level = getLevel();
  154 + uint8_t maxLevel = mMemoryController->getMaxLevel();
  155 + if ((int16_t) level + steps > (int16_t) maxLevel) {
  156 + level = maxLevel;
  157 + } else {
  158 + level += steps;
  159 + }
  160 + return setLevel(level, kFadeTime[fade]);
  161 +}
  162 +
  163 +Status Lamp::powerDown() {
  164 + onPowerCommand();
  165 + uint8_t fade = mMemoryController->getFadeRate();
  166 + uint8_t steps = kStepsFor200FadeRate[fade];
  167 + uint8_t level = getLevel();
  168 + uint8_t minLevel = mMemoryController->getMinLevel();
  169 + if ((int16_t) level - steps < (int16_t) minLevel) {
  170 + level = minLevel;
  171 + } else {
  172 + level -= steps;
  173 + }
  174 + return setLevel(level, kFadeTime[fade]);
  175 +}
  176 +
  177 +Status Lamp::powerStepUp() {
  178 + onPowerCommand();
  179 + uint8_t level = getLevel();
  180 + uint8_t maxLevel = mMemoryController->getMaxLevel();
  181 + if (level >= maxLevel) {
  182 + level = maxLevel;
  183 + } else {
  184 + level++;
  185 + }
  186 + return setLevel(level, 0);
  187 +}
  188 +
  189 +Status Lamp::powerStepDown() {
  190 + onPowerCommand();
  191 + uint8_t level = getLevel();
  192 + uint8_t minLevel = mMemoryController->getMinLevel();
  193 + if (level <= minLevel) {
  194 + level = minLevel;
  195 + } else {
  196 + level--;
  197 + }
  198 + return setLevel(level, 0);
  199 +}
  200 +
  201 +Status Lamp::powerOnAndStepUp() {
  202 + onPowerCommand();
  203 + uint8_t level = getLevel();
  204 + if (level == 0) {
  205 + level = mMemoryController->getMinLevel();
  206 + } else {
  207 + uint8_t maxLevel = mMemoryController->getMaxLevel();
  208 + if (level >= maxLevel) {
  209 + level = maxLevel;
  210 + } else {
  211 + level++;
  212 + }
  213 + }
  214 + return setLevel(level, 0);
  215 +}
  216 +
  217 +Status Lamp::powerStepDownAndOff() {
  218 + onPowerCommand();
  219 + uint8_t level = getLevel();
  220 + uint8_t minLevel = mMemoryController->getMinLevel();
  221 + if (level <= minLevel) {
  222 + level = 0;
  223 + } else {
  224 + level--;
  225 + }
  226 + return setLevel(level, 0);
  227 +}
  228 +
  229 +Status Lamp::powerRecallMinLevel() {
  230 + onPowerCommand();
  231 + return setLevel(mMemoryController->getMinLevel(), 0);
  232 +}
  233 +
  234 +Status Lamp::powerRecallMaxLevel() {
  235 + onPowerCommand();
  236 + return setLevel(mMemoryController->getMaxLevel(), 0);
  237 +}
  238 +
  239 +Status Lamp::powerRecallOnLevel() {
  240 + if (mIsPowerSet) {
  241 + return Status::INVALID;
  242 + }
  243 + uint8_t level = mMemoryController->getPowerOnLevel();
  244 + if (level == DALI_MASK) {
  245 + level = mMemoryController->getActualLevel();
  246 + }
  247 + return setLevel(level, 0);
  248 +}
  249 +
  250 +Status Lamp::powerRecallFaliureLevel() {
  251 + // TODO change mIsPowerSet if called before power on?
  252 + uint8_t level = mMemoryController->getFaliureLevel();
  253 + if (level == DALI_MASK) {
  254 + level = mMemoryController->getActualLevel();
  255 + }
  256 + return setLevel(level, 0);
  257 +}
  258 +
  259 +Status Lamp::enableDapcSequence(uint64_t time) {
  260 + mDapcTime = time;
  261 + return Status::OK;
  262 +}
  263 +
  264 +Status Lamp::dapcSequence(uint8_t level, uint64_t time) {
  265 + onPowerCommand();
  266 + mDapcTime = time;
  267 + uint8_t actualLevel = getLevel();
  268 + if (actualLevel == 0) {
  269 + // If the actual arc power level is zero, the new level shall be adopted without fading.
  270 + return setLevel(level, 0);
  271 + }
  272 + int16_t deltaLevel = (int32_t) level - actualLevel;
  273 + if (deltaLevel < 0)
  274 + deltaLevel = -deltaLevel;
  275 + if (deltaLevel == 0)
  276 + return Status::OK;
  277 + // deltaLevel should change in 200ms
  278 + int32_t fadeTime = (uint32_t) DALI_LEVEL_MAX * DAPC_TIME_MS / deltaLevel;
  279 + return setLevel(level, (uint32_t) fadeTime);
  280 +}
  281 +
  282 +void Lamp::onPowerCommand() {
  283 + mDapcTime = 0;
  284 + mIsPowerSet = true;
  285 +}
  286 +
  287 +void Lamp::onLampStateChnaged(ILamp::ILampState state) {
  288 + mLampState = state;
  289 + mListener->onLampStateChnaged(state);
  290 +}
  291 +
  292 +} // namespace controller
  293 +} // namespace dali
... ...
src/dali/controller/lamp.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_LAMP_CONTROLLER_HPP_
  12 +#define DALI_LAMP_CONTROLLER_HPP_
  13 +
  14 +#include <dali/dali.hpp>
  15 +
  16 +#include "memory.hpp"
  17 +
  18 +namespace dali {
  19 +namespace controller {
  20 +
  21 +class Lamp: public ILamp::ILampClient {
  22 +public:
  23 +
  24 + class Listener {
  25 + public:
  26 + virtual void onLampStateChnaged(ILamp::ILampState state) = 0;
  27 + };
  28 +
  29 + explicit Lamp(ILamp* lamp, Memory* memoryController);
  30 + virtual ~Lamp();
  31 +
  32 +// >>> used only in controller namespace
  33 + void onReset();
  34 + bool isPowerOn();
  35 + bool isFailure();
  36 + bool isFading();
  37 + bool isLimitError();
  38 + bool isPowerSet();
  39 +
  40 + uint8_t getLevel();
  41 + Status setLevel(uint8_t level, uint32_t fadeTime);
  42 + uint32_t getFadeTime();
  43 + uint32_t getFadeRate();
  44 +
  45 + Status abortFading();
  46 +// <<< used only in controller namespace
  47 +
  48 + void setListener(Listener* listener);
  49 + void notifyPowerDown();
  50 +
  51 + Status powerDirect(uint8_t level, uint64_t time);
  52 + Status powerOff();
  53 + Status powerScene(uint8_t scene);
  54 + Status powerUp();
  55 + Status powerDown();
  56 + Status powerStepUp();
  57 + Status powerStepDown();
  58 + Status powerOnAndStepUp();
  59 + Status powerStepDownAndOff();
  60 + Status powerRecallMinLevel();
  61 + Status powerRecallMaxLevel();
  62 + Status powerRecallOnLevel();
  63 + Status powerRecallFaliureLevel();
  64 + Status enableDapcSequence(uint64_t time);
  65 +
  66 +private:
  67 + Lamp(const Lamp& other) = delete;
  68 + Lamp& operator=(const Lamp&) = delete;
  69 +
  70 + Status dapcSequence(uint8_t level, uint64_t time);
  71 +
  72 + void onPowerCommand();
  73 +
  74 + // ILamp::ILampClient
  75 + void onLampStateChnaged(ILamp::ILampState state) override;
  76 +
  77 + ILamp* const mLamp;
  78 + Memory* const mMemoryController;
  79 + ILamp::ILampState mLampState;
  80 + Listener* mListener;
  81 + bool mIsPowerSet;
  82 + bool mLimitError;
  83 + uint64_t mDapcTime;
  84 + uint8_t mConstPower;
  85 +};
  86 +
  87 +} // namespace controller
  88 +} // namespace dali
  89 +
  90 +#endif // DALI_LAMP_CONTROLLER_HPP_
... ...
src/dali/controller/lamp_helper.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "lamp_helper.hpp"
  12 +
  13 +#define DAPC_TIME_MS 200
  14 +
  15 +namespace dali {
  16 +namespace controller {
  17 +namespace {
  18 +
  19 +const uint16_t kLevel2driver[256] = {
  20 + 0,
  21 + 66,
  22 + 67,
  23 + 69,
  24 + 71,
  25 + 73,
  26 + 75,
  27 + 77,
  28 + 79,
  29 + 82,
  30 + 84,
  31 + 86,
  32 + 88,
  33 + 91,
  34 + 93,
  35 + 96,
  36 + 99,
  37 + 101,
  38 + 104,
  39 + 107,
  40 + 110,
  41 + 113,
  42 + 116,
  43 + 119,
  44 + 123,
  45 + 126,
  46 + 130,
  47 + 133,
  48 + 137,
  49 + 141,
  50 + 145,
  51 + 149,
  52 + 153,
  53 + 157,
  54 + 161,
  55 + 166,
  56 + 170,
  57 + 175,
  58 + 180,
  59 + 185,
  60 + 190,
  61 + 195,
  62 + 201,
  63 + 206,
  64 + 212,
  65 + 218,
  66 + 224,
  67 + 230,
  68 + 236,
  69 + 243,
  70 + 250,
  71 + 257,
  72 + 264,
  73 + 271,
  74 + 279,
  75 + 286,
  76 + 294,
  77 + 302,
  78 + 311,
  79 + 319,
  80 + 328,
  81 + 337,
  82 + 347,
  83 + 356,
  84 + 366,
  85 + 376,
  86 + 387,
  87 + 397,
  88 + 408,
  89 + 420,
  90 + 431,
  91 + 443,
  92 + 455,
  93 + 468,
  94 + 481,
  95 + 494,
  96 + 508,
  97 + 522,
  98 + 536,
  99 + 551,
  100 + 567,
  101 + 582,
  102 + 598,
  103 + 615,
  104 + 632,
  105 + 649,
  106 + 667,
  107 + 686,
  108 + 705,
  109 + 724,
  110 + 744,
  111 + 765,
  112 + 786,
  113 + 808,
  114 + 830,
  115 + 853,
  116 + 877,
  117 + 901,
  118 + 926,
  119 + 952,
  120 + 978,
  121 + 1005,
  122 + 1033,
  123 + 1062,
  124 + 1091,
  125 + 1121,
  126 + 1152,
  127 + 1184,
  128 + 1217,
  129 + 1251,
  130 + 1285,
  131 + 1321,
  132 + 1357,
  133 + 1395,
  134 + 1434,
  135 + 1473,
  136 + 1514,
  137 + 1556,
  138 + 1599,
  139 + 1643,
  140 + 1689,
  141 + 1735,
  142 + 1783,
  143 + 1833,
  144 + 1884,
  145 + 1936,
  146 + 1989,
  147 + 2044,
  148 + 2101,
  149 + 2159,
  150 + 2219,
  151 + 2280,
  152 + 2343,
  153 + 2408,
  154 + 2475,
  155 + 2543,
  156 + 2614,
  157 + 2686,
  158 + 2760,
  159 + 2837,
  160 + 2915,
  161 + 2996,
  162 + 3079,
  163 + 3164,
  164 + 3252,
  165 + 3342,
  166 + 3434,
  167 + 3529,
  168 + 3627,
  169 + 3728,
  170 + 3831,
  171 + 3937,
  172 + 4046,
  173 + 4158,
  174 + 4273,
  175 + 4391,
  176 + 4513,
  177 + 4637,
  178 + 4766,
  179 + 4898,
  180 + 5033,
  181 + 5173,
  182 + 5316,
  183 + 5463,
  184 + 5614,
  185 + 5770,
  186 + 5929,
  187 + 6093,
  188 + 6262,
  189 + 6435,
  190 + 6614,
  191 + 6797,
  192 + 6985,
  193 + 7178,
  194 + 7377,
  195 + 7581,
  196 + 7791,
  197 + 8006,
  198 + 8228,
  199 + 8456,
  200 + 8690,
  201 + 8930,
  202 + 9178,
  203 + 9432,
  204 + 9693,
  205 + 9961,
  206 + 10237,
  207 + 10520,
  208 + 10811,
  209 + 11110,
  210 + 11418,
  211 + 11734,
  212 + 12059,
  213 + 12393,
  214 + 12736,
  215 + 13088,
  216 + 13450,
  217 + 13823,
  218 + 14205,
  219 + 14598,
  220 + 15003,
  221 + 15418,
  222 + 15845,
  223 + 16283,
  224 + 16734,
  225 + 17197,
  226 + 17673,
  227 + 18162,
  228 + 18665,
  229 + 19182,
  230 + 19712,
  231 + 20258,
  232 + 20819,
  233 + 21395,
  234 + 21987,
  235 + 22596,
  236 + 23221,
  237 + 23864,
  238 + 24525,
  239 + 25203,
  240 + 25901,
  241 + 26618,
  242 + 27355,
  243 + 28112,
  244 + 28890,
  245 + 29690,
  246 + 30512,
  247 + 31356,
  248 + 32224,
  249 + 33116,
  250 + 34033,
  251 + 34975,
  252 + 35943,
  253 + 36938,
  254 + 37960,
  255 + 39011,
  256 + 40090,
  257 + 41200,
  258 + 42341,
  259 + 43513,
  260 + 44717,
  261 + 45955,
  262 + 47227,
  263 + 48534,
  264 + 49877,
  265 + 51258,
  266 + 52677,
  267 + 54135,
  268 + 55633,
  269 + 57173,
  270 + 58756,
  271 + 60382,
  272 + 62053,
  273 + 63771,
  274 + 65535,
  275 + 0,
  276 +};
  277 +} // namespace
  278 +
  279 +const uint32_t kFadeTime[16] = { // fade times from 0 to 254 in milliseconds
  280 + 0, // 0
  281 + 707, // 1
  282 + 1000, // 2
  283 + 1414, // 3
  284 + 2000, // 4
  285 + 2828, // 5
  286 + 4000, // 6
  287 + 5657, // 7
  288 + 8000, // 8
  289 + 11314, // 9
  290 + 16000, // 10
  291 + 22627, // 11
  292 + 32000, // 12
  293 + 45255, // 13
  294 + 64000, // 14
  295 + 90510, // 15
  296 +};
  297 +
  298 +const uint8_t kStepsFor200FadeRate[16] = { 1, 72, 51, 36, 25, 18, 13, 9, 6, 4, 3, 2, 2, 1, 1, 1 };
  299 +
  300 +uint16_t level2driver(uint8_t level) {
  301 + return kLevel2driver[level];
  302 +}
  303 +
  304 +uint8_t driver2level(uint16_t driverLevel, uint8_t minLevel) {
  305 + if (driverLevel < kLevel2driver[minLevel]) {
  306 + return 0;
  307 + }
  308 + uint16_t a = minLevel;
  309 + uint16_t b = DALI_LEVEL_MAX;
  310 + while (true) {
  311 + uint16_t m = (a + b) / 2;
  312 + uint16_t v = kLevel2driver[m];
  313 + if (driverLevel == v) {
  314 + return m;
  315 + } else if (driverLevel < v) {
  316 + b = m;
  317 + if (b - a <= 1) {
  318 + uint16_t av = driverLevel - kLevel2driver[a];
  319 + uint16_t bv = v - driverLevel;
  320 + if (av < bv) {
  321 + return a;
  322 + } else {
  323 + return b;
  324 + }
  325 + }
  326 + } else {
  327 + a = m;
  328 + if (b - a <= 1) {
  329 + uint16_t av = driverLevel - v;
  330 + uint16_t bv = kLevel2driver[b] - driverLevel;
  331 + if (av < bv) {
  332 + return a;
  333 + } else {
  334 + return b;
  335 + }
  336 + }
  337 + }
  338 + }
  339 +}
  340 +} // namespace controller
  341 +} // namespace dali
... ...
src/dali/controller/lamp_helper.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_LAMP_CONTROLLER_CONSTS_HPP_
  12 +#define DALI_LAMP_CONTROLLER_CONSTS_HPP_
  13 +
  14 +#include <dali/dali.hpp>
  15 +
  16 +namespace dali {
  17 +namespace controller {
  18 +
  19 +uint16_t level2driver(uint8_t level);
  20 +uint8_t driver2level(uint16_t driverLevel, uint8_t minLevel);
  21 +
  22 +extern const uint32_t kFadeTime[16];
  23 +extern const uint8_t kStepsFor200FadeRate[16];
  24 +
  25 +} // namespace controller
  26 +} // namespace dali
  27 +
  28 +#endif // DALI_LAMP_CONTROLLER_CONSTS_HPP_
... ...
src/dali/controller/memory.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "memory.hpp"
  12 +
  13 +#include <string.h>
  14 +
  15 +#define DATA_FIELD_OFFSET(type, field) ((uintptr_t) &(((type *) 0)->field))
  16 +#define TEMP_FIELD_OFFSET(type, field) ((uintptr_t) &(((type *) 0)->field))
  17 +
  18 +#define LONG_ADDR_MASK 0x00ffffff
  19 +
  20 +#define INVALID_BANK_ADDR 0xffffffff
  21 +
  22 +namespace dali {
  23 +namespace controller {
  24 +
  25 +Memory::Memory(IMemory* memory) :
  26 + mMemory(memory),
  27 + mData((Data*) memory->data(DALI_BANK2_ADDR, sizeof(Data))),
  28 + mTemp((Temp*) memory->tempData(0, sizeof(Temp)))
  29 +{
  30 + resetRam(true);
  31 +
  32 + for (uint8_t i = 0; i < DALI_BANKS; ++i) {
  33 + mBankData[i] = mMemory->data(getBankAddr(i), getBankSize(i));
  34 + if ((uintptr_t) mBankData[i] == INVALID_BANK_ADDR) {
  35 + mBankData[i] = nullptr;
  36 + }
  37 + resetBankIfNeeded(i);
  38 + }
  39 +
  40 + if (mData != nullptr) {
  41 + if (!isDataValid()) {
  42 + resetData(true);
  43 + }
  44 + }
  45 + if (mTemp != nullptr) {
  46 + if (!isTempValid()) {
  47 + resetTemp();
  48 + }
  49 + }
  50 + setSearchAddr(LONG_ADDR_MASK);
  51 +}
  52 +
  53 +Status Memory::readMemory(uint8_t* data) {
  54 + uint8_t bank = mRam.dtr1;
  55 + uint8_t addr = mRam.dtr;
  56 +
  57 + Status status = Status::OK;
  58 + if (bankRead(bank, addr++, data) != Status::OK) {
  59 + status = Status::ERROR;
  60 + }
  61 + if (bankRead(bank, addr, &mRam.dtr2) != Status::OK) {
  62 + // ignore status
  63 + }
  64 + if (status == Status::OK) {
  65 + mRam.dtr++;
  66 + }
  67 + return status;
  68 +}
  69 +
  70 +Status Memory::writeMemory(uint8_t data) {
  71 + uint8_t bank = mRam.dtr1;
  72 + uint8_t addr = mRam.dtr;
  73 +
  74 + Status status = bankWrite(bank, addr, data, false);
  75 + if (status == Status::OK) {
  76 + mRam.dtr++;
  77 + }
  78 + return status;
  79 +}
  80 +
  81 +uint8_t Memory::getPhisicalMinLevel() {
  82 + return mData->phisicalMinLevel;
  83 +}
  84 +
  85 +Status Memory::setPhisicalMinLevel(uint8_t level) {
  86 + return writeData8(DATA_FIELD_OFFSET(Data, phisicalMinLevel), level);
  87 +}
  88 +
  89 +uint8_t Memory::getShortAddr() {
  90 + return mData->shortAddr;
  91 +}
  92 +
  93 +Status Memory::setShortAddr(uint8_t addr) {
  94 + addr |= 0x01; // normalize address
  95 + return writeData8(DATA_FIELD_OFFSET(Data, shortAddr), addr);
  96 +}
  97 +
  98 +uint8_t Memory::getMinLevel() {
  99 + return mData->minLevel;
  100 +}
  101 +
  102 +Status Memory::setMinLevel(uint8_t level) {
  103 + return writeData8(DATA_FIELD_OFFSET(Data, minLevel), level);
  104 +}
  105 +
  106 +uint8_t Memory::getMaxLevel() {
  107 + return mData->maxLevel;
  108 +}
  109 +
  110 +Status Memory::setMaxLevel(uint8_t level) {
  111 + return writeData8(DATA_FIELD_OFFSET(Data, maxLevel), level);
  112 +}
  113 +
  114 +uint8_t Memory::getPowerOnLevel() {
  115 + return mData->powerOnLevel;
  116 +}
  117 +
  118 +Status Memory::setPowerOnLevel(uint8_t level) {
  119 + return writeData8(DATA_FIELD_OFFSET(Data, powerOnLevel), level);
  120 +}
  121 +
  122 +uint8_t Memory::getFaliureLevel() {
  123 + return mData->failureLevel;
  124 +}
  125 +
  126 +Status Memory::setFaliureLevel(uint8_t level) {
  127 + return writeData8(DATA_FIELD_OFFSET(Data, failureLevel), level);
  128 +}
  129 +
  130 +uint8_t Memory::getFadeTime() {
  131 + return mData->fadeTime;
  132 +}
  133 +
  134 +Status Memory::setFadeTime(uint8_t fadeTime) {
  135 + return writeData8(DATA_FIELD_OFFSET(Data, fadeTime), fadeTime);
  136 +}
  137 +
  138 +uint8_t Memory::getFadeRate() {
  139 + return mData->fadeRate;
  140 +}
  141 +
  142 +Status Memory::setFadeRate(uint8_t fadeRate) {
  143 + return writeData8(DATA_FIELD_OFFSET(Data, fadeRate), fadeRate);
  144 +}
  145 +
  146 +uint8_t Memory::getLevelForScene(uint8_t scene) {
  147 + if (scene > DALI_SCENE_MAX) {
  148 + return DALI_MASK;
  149 + }
  150 + return mData->scene[scene];
  151 +}
  152 +
  153 +Status Memory::setLevelForScene(uint8_t scene, uint8_t level) {
  154 + if (scene > DALI_SCENE_MAX) {
  155 + return Status::ERROR;
  156 + }
  157 + return writeData8(DATA_FIELD_OFFSET(Data, scene[scene]), level);
  158 +}
  159 +
  160 +uint16_t Memory::getGroups() {
  161 + return mData->groups;
  162 +}
  163 +
  164 +uint8_t Memory::getGroupsL() {
  165 + return mData->groups;
  166 +}
  167 +
  168 +uint8_t Memory::getGroupsH() {
  169 + return mData->groups >> 8;
  170 +}
  171 +
  172 +Status Memory::setGroups(uint16_t groups) {
  173 + return writeData16(DATA_FIELD_OFFSET(Data, groups), groups);
  174 +}
  175 +
  176 +
  177 +uint32_t Memory::getSearchAddr() {
  178 + return mRam.searchAddr;
  179 +}
  180 +
  181 +Status Memory::setSearchAddr(uint32_t searchAddr) {
  182 + mRam.searchAddr = searchAddr & LONG_ADDR_MASK;
  183 + return Status::OK;
  184 +}
  185 +
  186 +uint32_t Memory::getRandomAddr() {
  187 + return mTemp->randomAddr;
  188 +}
  189 +
  190 +Status Memory::setRandomAddr(uint32_t randomAddr) {
  191 + randomAddr &= LONG_ADDR_MASK;
  192 + return writeTemp32(TEMP_FIELD_OFFSET(Temp, randomAddr), randomAddr);
  193 +}
  194 +
  195 +uint8_t Memory::getActualLevel() {
  196 + return mTemp->actualLevel;
  197 +}
  198 +
  199 +Status Memory::setActualLevel(uint8_t level) {
  200 + return writeTemp8(TEMP_FIELD_OFFSET(Temp, actualLevel), level);
  201 +}
  202 +
  203 +bool Memory::isDataValid() {
  204 + // check ranges of values
  205 + if ((mData->phisicalMinLevel == 0) || (mData->phisicalMinLevel == DALI_MASK))
  206 + return false;
  207 + if (mData->fadeRate < DALI_FADE_RATE_MIN || mData->fadeRate > DALI_FADE_RATE_MAX)
  208 + return false;
  209 + if (mData->fadeTime < DALI_FADE_TIME_MIN || mData->fadeTime > DALI_FADE_TIME_MAX)
  210 + return false;
  211 + if (mData->shortAddr != DALI_MASK && (mData->shortAddr >> 1) > DALI_ADDR_MAX)
  212 + return false;
  213 + if (mData->minLevel > mData->maxLevel)
  214 + return false;
  215 + return true;
  216 +}
  217 +
  218 +bool Memory::isTempValid() {
  219 + if (mTemp->randomAddr > LONG_ADDR_MASK)
  220 + return false;
  221 + return true;
  222 +}
  223 +
  224 +bool Memory::isReset() {
  225 + if (mData->powerOnLevel != DALI_LEVEL_MAX)
  226 + return false;
  227 + if (mData->failureLevel != DALI_LEVEL_MAX)
  228 + return false;
  229 + if (mData->minLevel != getPhisicalMinLevel())
  230 + return false;
  231 + if (mData->maxLevel != DALI_LEVEL_MAX)
  232 + return false;
  233 + if (mData->fadeRate != DALI_FADE_RATE_DEFAULT)
  234 + return false;
  235 +
  236 + if (mData->fadeTime != DALI_FADE_TIME_DEFAULT)
  237 + return false;
  238 + // skip checking mData->shortAddr
  239 + if (mData->groups != 0)
  240 + return false;
  241 + for (uint16_t i = 0; i <= DALI_SCENE_MAX; i++) {
  242 + if (mData->scene[i] != DALI_MASK)
  243 + return false;
  244 + }
  245 + if (mTemp->randomAddr != LONG_ADDR_MASK)
  246 + return false;
  247 + return true;
  248 +}
  249 +
  250 +Status Memory::reset() {
  251 + resetRam(false);
  252 + resetData(false);
  253 + resetTemp();
  254 + return Status::OK;
  255 +}
  256 +
  257 +void Memory::resetRam(bool initialize) {
  258 + if (initialize) {
  259 + mRam.dtr = DALI_MASK;
  260 + mRam.dtr1 = DALI_MASK;
  261 + mRam.dtr2 = DALI_MASK;
  262 + }
  263 + mRam.searchAddr = LONG_ADDR_MASK;
  264 +}
  265 +
  266 +void Memory::resetData(bool initialize) {
  267 + if (initialize) {
  268 + setPhisicalMinLevel(DALI_PHISICAL_MIN_LEVEL);
  269 + }
  270 + setPowerOnLevel(DALI_LEVEL_MAX);
  271 + setFaliureLevel(DALI_LEVEL_MAX);
  272 + setMinLevel(getPhisicalMinLevel());
  273 + setMaxLevel(DALI_LEVEL_MAX);
  274 + setFadeRate(DALI_FADE_RATE_DEFAULT);
  275 + setFadeTime(DALI_FADE_TIME_DEFAULT);
  276 + if (initialize) {
  277 + setShortAddr(DALI_MASK);
  278 + }
  279 + setGroups(0);
  280 + for (size_t i = 0; i < 16; i++) {
  281 + setLevelForScene(i, DALI_MASK);
  282 + }
  283 +}
  284 +
  285 +void Memory::resetTemp() {
  286 + setRandomAddr(LONG_ADDR_MASK);
  287 + setActualLevel(DALI_MASK);
  288 +}
  289 +
  290 +Status Memory::internalBankWrite(uint8_t bank, uint8_t addr, uint8_t* data, uint8_t size) {
  291 + Status status = Status::OK;
  292 + const uint8_t* bankData = mBankData[bank];
  293 + uint8_t crc = bankData[1];
  294 +
  295 + const uintptr_t bankAddr = getBankAddr(bank);
  296 + const uint16_t endAddr = (uint16_t)addr + size;
  297 + for (; addr < endAddr; ++addr, ++data) {
  298 + crc += bankData[addr];
  299 + crc -= *data;
  300 +
  301 + if (mMemory->dataWrite(bankAddr + addr, data, 1) != 1) {
  302 + status = Status::ERROR;
  303 + }
  304 + }
  305 +
  306 + if (mMemory->dataWrite(bankAddr + 1, &crc, 1) != 1) {
  307 + status = Status::ERROR;
  308 + }
  309 +
  310 + return status;
  311 +}
  312 +
  313 +size_t Memory::getBankSize(uint8_t bank) {
  314 + switch (bank) {
  315 + case 0:
  316 + return DALI_BANK1_ADDR - DALI_BANK0_ADDR;
  317 + case 1:
  318 + return DALI_BANK2_ADDR - DALI_BANK1_ADDR;
  319 + case 2:
  320 + return DALI_BANK3_ADDR - DALI_BANK2_ADDR;
  321 + default:
  322 + return 0;
  323 + }
  324 +}
  325 +
  326 +uintptr_t Memory::getBankAddr(uint8_t bank) {
  327 + switch (bank) {
  328 + case 0: // read only
  329 + return DALI_BANK0_ADDR;
  330 + case 1:
  331 + return DALI_BANK1_ADDR;
  332 + case 2:
  333 + return DALI_BANK2_ADDR;
  334 + default:
  335 + return INVALID_BANK_ADDR;
  336 + }
  337 +}
  338 +
  339 +Status Memory::bankWrite(uint8_t bank, uint8_t addr, uint8_t data, bool force) {
  340 + uint8_t size = getBankSize(bank);
  341 + if (size < 3 && addr > size) {
  342 + return Status::ERROR;
  343 + }
  344 + if (!force && !isBankAddrWritable(bank, addr)) {
  345 + return Status::INVALID;
  346 + }
  347 + return internalBankWrite(bank, addr, &data, sizeof(uint8_t));
  348 +}
  349 +
  350 +Status Memory::bankRead(uint8_t bank, uint8_t addr, uint8_t* data) {
  351 + uint8_t size = getBankSize(bank);
  352 + if (addr + 1 > size) {
  353 + return Status::ERROR;
  354 + }
  355 + uintptr_t bankAddr = getBankAddr(bank);
  356 + if (bankAddr == INVALID_BANK_ADDR) {
  357 + return Status::ERROR;
  358 + }
  359 + const uint8_t* bankData = mMemory->data(bankAddr + addr, 1);
  360 + if (bankData == nullptr) {
  361 + return dali::Status::ERROR;
  362 + }
  363 + *data = *bankData;
  364 + return Status::OK;
  365 +}
  366 +
  367 +bool Memory::isBankAddrWritable(uint8_t bank, uint8_t addr) {
  368 + if (bank == 0) {
  369 + // read only
  370 + return false;
  371 + }
  372 +
  373 + uintptr_t bankAddr = getBankAddr(bank);
  374 + if (bankAddr != INVALID_BANK_ADDR) {
  375 + if (addr < 2) {
  376 + return false;
  377 + }
  378 + if (addr == 2) {
  379 + return true;
  380 + }
  381 + const uint8_t* bankData = mMemory->data(bankAddr + 2, 1);
  382 + if ((bankData == nullptr) || (*bankData != 0x55)) {
  383 + return false;
  384 + }
  385 + return true;
  386 + }
  387 + return false;
  388 +}
  389 +
  390 +void Memory::resetBankIfNeeded(uint8_t bank) {
  391 + if ((bank >= DALI_BANKS) || (mBankData[bank] == nullptr)) {
  392 + return;
  393 + }
  394 + const size_t bankSize = getBankSize(bank);
  395 +
  396 + bool reset = false;
  397 + const uint8_t* bankData = mBankData[bank];
  398 + if (bankData[0] != (uint8_t) (bankSize - 1)) {
  399 + reset = true;
  400 + }
  401 + if (!reset) {
  402 + uint8_t checksum = 0;
  403 + ++bankData;
  404 + for (uint8_t i = 1; i < bankSize; ++i, ++bankData) {
  405 + checksum += *bankData;
  406 + }
  407 + reset = (checksum != 0);
  408 + }
  409 +
  410 + if (reset) {
  411 + uintptr_t bankAddr = getBankAddr(bank);
  412 + uint8_t temp = bankSize - 1; // size
  413 + mMemory->dataWrite(bankAddr, &temp, 1);
  414 + temp = 0 - (0xff * (bankSize - 2)); // crc
  415 + mMemory->dataWrite(bankAddr + 1, &temp, 1);
  416 + temp = 0xff; // reset data
  417 + for (uint8_t i = 2; i < bankSize; ++i) {
  418 + mMemory->dataWrite(bankAddr + i, &temp, 1);
  419 + }
  420 +
  421 + if (bank == 0) {
  422 + uint8_t banks = DALI_BANKS - 1;
  423 + internalBankWrite(0, 0x02, &banks, 1);
  424 + }
  425 + }
  426 +}
  427 +
  428 +} // namespace controller
  429 +} // namespace dali
... ...
src/dali/controller/memory.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_MEMORY_CONTROLLER_HPP_
  12 +#define DALI_MEMORY_CONTROLLER_HPP_
  13 +
  14 +#include <dali/dali.hpp>
  15 +
  16 +namespace dali {
  17 +namespace controller {
  18 +
  19 +class Memory {
  20 +public:
  21 + explicit Memory(IMemory* memory);
  22 + virtual ~Memory() {};
  23 +
  24 + uint8_t getDTR() {
  25 + return mRam.dtr;
  26 + }
  27 +
  28 + void setDTR(uint8_t value) {
  29 + mRam.dtr = value;
  30 + }
  31 +
  32 + uint8_t getDTR1() {
  33 + return mRam.dtr1;
  34 + }
  35 +
  36 + void setDTR1(uint8_t value) {
  37 + mRam.dtr1 = value;
  38 + }
  39 +
  40 + uint8_t getDTR2() {
  41 + return mRam.dtr2;
  42 + }
  43 +
  44 + void setDTR2(uint8_t value) {
  45 + mRam.dtr2 = value;
  46 + }
  47 +
  48 + Status readMemory(uint8_t* data);
  49 + Status writeMemory(uint8_t data);
  50 +
  51 + uint8_t getPhisicalMinLevel();
  52 + Status setPhisicalMinLevel(uint8_t level);
  53 +
  54 + uint8_t getShortAddr();
  55 + Status setShortAddr(uint8_t addr);
  56 +
  57 + uint8_t getMinLevel();
  58 + Status setMinLevel(uint8_t level);
  59 +
  60 + uint8_t getMaxLevel();
  61 + Status setMaxLevel(uint8_t level);
  62 +
  63 + uint8_t getPowerOnLevel();
  64 + Status setPowerOnLevel(uint8_t level);
  65 +
  66 + uint8_t getFaliureLevel();
  67 + Status setFaliureLevel(uint8_t level);
  68 +
  69 + uint8_t getFadeTime();
  70 + Status setFadeTime(uint8_t fadeTime);
  71 +
  72 + uint8_t getFadeRate();
  73 + Status setFadeRate(uint8_t fadeRate);
  74 +
  75 + uint8_t getLevelForScene(uint8_t scene);
  76 + Status setLevelForScene(uint8_t scene, uint8_t level);
  77 +
  78 + uint16_t getGroups();
  79 + uint8_t getGroupsL();
  80 + uint8_t getGroupsH();
  81 + Status setGroups(uint16_t groups);
  82 +
  83 + uint32_t getSearchAddr();
  84 + Status setSearchAddr(uint32_t searchAddr);
  85 +
  86 + uint32_t getRandomAddr();
  87 + Status setRandomAddr(uint32_t randomAddr);
  88 +
  89 + uint8_t getActualLevel();
  90 + Status setActualLevel(uint8_t level);
  91 +
  92 + bool isValid() {
  93 + return isDataValid() && isTempValid();
  94 + }
  95 +
  96 + bool isReset();
  97 + Status reset();
  98 +
  99 + uint16_t uint16FromDtrAndDtr1() {
  100 + return ((uint16_t) mRam.dtr1 << 8) | mRam.dtr;
  101 + }
  102 +
  103 +private:
  104 + Memory(const Memory& other) = delete;
  105 + Memory& operator=(const Memory&) = delete;
  106 +
  107 + typedef struct __attribute__((__packed__)) {
  108 + uint32_t randomAddr;
  109 + uint8_t actualLevel;
  110 + uint8_t reversed1;
  111 + uint8_t reversed2;
  112 + uint8_t reversed3;
  113 + } Temp;
  114 +
  115 + typedef struct __attribute__((__packed__)) {
  116 + uint8_t size; // BANK mandatory field
  117 + uint8_t crc; // BANK mandatory field
  118 + uint8_t phisicalMinLevel;
  119 + uint8_t powerOnLevel;
  120 + uint8_t failureLevel;
  121 + uint8_t minLevel;
  122 + uint8_t maxLevel;
  123 + uint8_t fadeRate;
  124 + uint8_t fadeTime;
  125 + uint8_t shortAddr;
  126 + uint16_t groups;
  127 + uint8_t scene[16];
  128 + } Data;
  129 +
  130 + typedef struct {
  131 + uint8_t dtr;
  132 + uint8_t dtr1;
  133 + uint8_t dtr2;
  134 + uint32_t searchAddr;
  135 + } Ram;
  136 +
  137 + Status internalBankWrite(uint8_t bank, uint8_t addr, uint8_t* data, uint8_t size);
  138 +
  139 + Status writeTemp(uintptr_t addr, uint8_t* data, size_t size) {
  140 + return mMemory->tempWrite(addr, data, size) == size ? Status::OK : Status::ERROR;
  141 + }
  142 +
  143 + Status writeTemp8(uintptr_t addr, uint8_t data) {
  144 + return mMemory->tempWrite(addr, &data, sizeof(uint8_t)) == sizeof(uint8_t) ? Status::OK : Status::ERROR;
  145 + }
  146 +
  147 + Status writeTemp16(uintptr_t addr, uint16_t data) {
  148 + return mMemory->tempWrite(addr, (uint8_t*) &data, sizeof(uint16_t)) == sizeof(uint16_t) ? Status::OK : Status::ERROR;
  149 + }
  150 +
  151 + Status writeTemp32(uintptr_t addr, uint32_t data) {
  152 + return mMemory->tempWrite(addr, (uint8_t*) &data, sizeof(uint32_t)) == sizeof(uint32_t) ? Status::OK : Status::ERROR;
  153 + }
  154 +
  155 + Status writeData8(uintptr_t addr, uint8_t data) {
  156 + return internalBankWrite(2, addr, &data, sizeof(uint8_t));
  157 + }
  158 +
  159 + Status writeData16(uintptr_t addr, uint16_t data) {
  160 + return internalBankWrite(2, addr, (uint8_t*)&data, sizeof(uint16_t));
  161 + }
  162 +
  163 + Status writeData32(uintptr_t addr, uint32_t data) {
  164 + return internalBankWrite(2, addr, (uint8_t*)&data, sizeof(uint16_t));
  165 + }
  166 +
  167 + Status writeData(uintptr_t addr, uint8_t* data, size_t size) {
  168 + return internalBankWrite(2, addr, data, size);
  169 + }
  170 +
  171 + Status bankWrite(uint8_t bank, uint8_t addr, uint8_t data, bool force);
  172 + Status bankRead(uint8_t bank, uint8_t addr, uint8_t* data);
  173 +
  174 +
  175 + bool isDataValid();
  176 + bool isTempValid();
  177 + void resetRam(bool initialize);
  178 + void resetData(bool initialize);
  179 + void resetTemp();
  180 +
  181 + size_t getBankSize(uint8_t bank);
  182 + uintptr_t getBankAddr(uint8_t bank);
  183 + bool isBankAddrWritable(uint8_t bank, uint8_t addr);
  184 + void resetBankIfNeeded(uint8_t bank);
  185 +
  186 + IMemory* const mMemory;
  187 + Ram mRam;
  188 + const uint8_t* mBankData[DALI_BANKS];
  189 + const Data* mData;
  190 + const Temp* mTemp;
  191 +};
  192 +
  193 +} // namespace controller
  194 +} // namespace dali
  195 +
  196 +#endif // DALI_MEMORY_CONTROLLER_HPP_
... ...
src/dali/controller/query_store.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "query_store.hpp"
  12 +
  13 +namespace dali {
  14 +namespace controller {
  15 +
  16 +QueryStore::QueryStore(Memory* memory, Lamp* lamp) :
  17 + mMemoryController(memory), mLampController(lamp) {
  18 +}
  19 +
  20 +Status QueryStore::reset() {
  21 + Status status = mMemoryController->reset();
  22 + mLampController->onReset();
  23 + return status;
  24 +}
  25 +
  26 +Status QueryStore::storeActualLevelInDtr() {
  27 + mMemoryController->setDTR(mLampController->getLevel());
  28 + return Status::OK;
  29 +}
  30 +
  31 +Status QueryStore::storeDtrAsMaxLevel() {
  32 + uint8_t minLevel = mMemoryController->getMinLevel();
  33 + uint8_t maxLevel = mMemoryController->getDTR();
  34 + if (maxLevel < minLevel) {
  35 + maxLevel = minLevel;
  36 + }
  37 + if (maxLevel > DALI_LEVEL_MAX) {
  38 + maxLevel = DALI_LEVEL_MAX;
  39 + }
  40 + Status status = mMemoryController->setMaxLevel(maxLevel);
  41 +
  42 + uint8_t level = mMemoryController->getActualLevel();
  43 + if ((level != 0) && (level > maxLevel)) {
  44 + mLampController->setLevel(maxLevel, 0);
  45 + }
  46 + return status;
  47 +}
  48 +
  49 +Status QueryStore::storeDtrAsMinLevel() {
  50 + uint8_t minLevel = mMemoryController->getDTR();
  51 + uint8_t maxLevel = mMemoryController->getMaxLevel();
  52 + if (minLevel > maxLevel) {
  53 + minLevel = maxLevel;
  54 + }
  55 + uint8_t phiscalMinLevel = mMemoryController->getPhisicalMinLevel();
  56 + if (minLevel < phiscalMinLevel) {
  57 + minLevel = phiscalMinLevel;
  58 + }
  59 + Status status = mMemoryController->setMinLevel(minLevel);
  60 +
  61 + uint8_t level = mMemoryController->getActualLevel();
  62 + if ((level != 0) && (level < minLevel)) {
  63 + mLampController->setLevel(minLevel, 0);
  64 + }
  65 + return status;
  66 +}
  67 +
  68 +Status QueryStore::storeDtrAsFailureLevel() {
  69 + return mMemoryController->setFaliureLevel(mMemoryController->getDTR());
  70 +}
  71 +
  72 +Status QueryStore::storePowerOnLevel() {
  73 + return mMemoryController->setPowerOnLevel(mMemoryController->getDTR());
  74 +}
  75 +
  76 +Status QueryStore::storeDtrAsFadeTime() {
  77 + uint8_t fadeTime = mMemoryController->getDTR();
  78 + if (fadeTime < DALI_FADE_TIME_MIN) {
  79 + fadeTime = DALI_FADE_TIME_MIN;
  80 + }
  81 + if (fadeTime > DALI_FADE_TIME_MAX) {
  82 + fadeTime = DALI_FADE_TIME_MAX;
  83 + }
  84 + return mMemoryController->setFadeTime(fadeTime);
  85 +}
  86 +
  87 +Status QueryStore::storeDtrAsFadeRate() {
  88 + uint8_t fadeRate = mMemoryController->getDTR();
  89 + if (fadeRate < DALI_FADE_RATE_MIN) {
  90 + fadeRate = DALI_FADE_RATE_MIN;
  91 + }
  92 + if (fadeRate > DALI_FADE_RATE_MAX) {
  93 + fadeRate = DALI_FADE_RATE_MAX;
  94 + }
  95 + return mMemoryController->setFadeRate(fadeRate);
  96 +}
  97 +
  98 +Status QueryStore::storeDtrAsScene(uint8_t scene) {
  99 + return mMemoryController->setLevelForScene(scene, mMemoryController->getDTR());
  100 +}
  101 +
  102 +Status QueryStore::removeFromScene(uint8_t scene) {
  103 + return mMemoryController->setLevelForScene(scene, DALI_MASK);
  104 +}
  105 +
  106 +Status QueryStore::addToGroup(uint8_t group) {
  107 + if (group > DALI_GROUP_MAX) {
  108 + return Status::ERROR;
  109 + }
  110 + uint16_t groups = mMemoryController->getGroups();
  111 + groups |= 1 << group;
  112 + return mMemoryController->setGroups(groups);
  113 +}
  114 +
  115 +Status QueryStore::removeFromGroup(uint8_t group) {
  116 + if (group > DALI_GROUP_MAX) {
  117 + return Status::ERROR;
  118 + }
  119 + uint16_t groups = mMemoryController->getGroups();
  120 + groups &= ~(1 << group);
  121 + return mMemoryController->setGroups(groups);
  122 +}
  123 +
  124 +Status QueryStore::storeDtrAsShortAddr() {
  125 + uint8_t addr = mMemoryController->getDTR();
  126 + if ((addr != DALI_MASK) && ((addr >> 1) > DALI_ADDR_MAX)) {
  127 + return Status::ERROR;
  128 + }
  129 + return mMemoryController->setShortAddr(addr);
  130 +}
  131 +
  132 +uint8_t QueryStore::queryStatus() {
  133 + uint8_t status = 0;
  134 +
  135 + if (!isMemoryValid()) { // FIXME this should be false but for debug purpose is checked
  136 + status |= (1 << 0);
  137 + }
  138 + if (queryLampFailure()) {
  139 + status |= (1 << 1);
  140 + }
  141 + if (queryLampPowerOn()) {
  142 + status |= (1 << 2);
  143 + }
  144 + if (queryLampLimitError()) {
  145 + status |= (1 << 3);
  146 + }
  147 + if (queryIsFading()) {
  148 + status |= (1 << 4);
  149 + }
  150 + if (queryResetState()) {
  151 + status |= (1 << 5);
  152 + }
  153 + if (queryMissingShortAddr()) {
  154 + status |= (1 << 6);
  155 + }
  156 + if (!queryLampPowerSet()) {
  157 + status |= (1 << 7);
  158 + }
  159 + return status;
  160 +}
  161 +
  162 +bool QueryStore::queryLampFailure() {
  163 + return mLampController->isFailure();
  164 +}
  165 +
  166 +bool QueryStore::queryLampPowerOn() {
  167 + return mLampController->isPowerOn();
  168 +}
  169 +
  170 +bool QueryStore::queryLampLimitError() {
  171 + return mLampController->isLimitError();
  172 +}
  173 +
  174 +bool QueryStore::queryIsFading() {
  175 + return mLampController->isFading();
  176 +}
  177 +
  178 +bool QueryStore::queryResetState() {
  179 + return mMemoryController->isReset();
  180 +}
  181 +
  182 +bool QueryStore::queryMissingShortAddr() {
  183 + return mMemoryController->getShortAddr() == DALI_MASK;
  184 +}
  185 +
  186 +bool QueryStore::queryLampPowerSet() {
  187 + return mLampController->isPowerSet();
  188 +}
  189 +
  190 +uint8_t QueryStore::queryActualLevel() {
  191 + return mLampController->getLevel();
  192 +}
  193 +
  194 +uint8_t QueryStore::queryMaxLevel() {
  195 + return mMemoryController->getMaxLevel();
  196 +}
  197 +
  198 +uint8_t QueryStore::queryMinLevel() {
  199 + return mMemoryController->getMinLevel();
  200 +}
  201 +
  202 +uint8_t QueryStore::queryPowerOnLevel() {
  203 + return mMemoryController->getPowerOnLevel();
  204 +}
  205 +
  206 +uint8_t QueryStore::queryFaliureLevel() {
  207 + return mMemoryController->getFaliureLevel();
  208 +}
  209 +
  210 +uint8_t QueryStore::queryFadeRateOrTime() {
  211 + uint8_t fadeRate = mMemoryController->getFadeRate();
  212 + uint8_t fadeTime = mMemoryController->getFadeTime();
  213 + return (fadeTime << 4) | fadeRate;
  214 +}
  215 +
  216 +uint8_t QueryStore::queryLevelForScene(uint8_t scene) {
  217 + return mMemoryController->getLevelForScene(scene);
  218 +}
  219 +
  220 +uint8_t QueryStore::queryGroupsL() {
  221 + return mMemoryController->getGroupsL();
  222 +}
  223 +
  224 +uint8_t QueryStore::queryGroupsH() {
  225 + return mMemoryController->getGroupsH();
  226 +}
  227 +
  228 +uint8_t QueryStore::queryRandomAddrH() {
  229 + return (uint8_t) ((mMemoryController->getRandomAddr() >> 16) & 0xff);
  230 +}
  231 +
  232 +uint8_t QueryStore::queryRandomAddrM() {
  233 + return (uint8_t) ((mMemoryController->getRandomAddr() >> 8) & 0xff);
  234 +}
  235 +
  236 +uint8_t QueryStore::queryRandomAddrL() {
  237 + return (uint8_t) ((mMemoryController->getRandomAddr() >> 0) & 0xff);
  238 +}
  239 +
  240 +bool QueryStore::isMemoryValid() {
  241 + return mMemoryController->isValid();
  242 +}
  243 +
  244 +} // namespace controller
  245 +} // namespace dali
... ...
src/dali/controller/query_store.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_CONTROLLER_QUERY_HPP_
  12 +#define DALI_CONTROLLER_QUERY_HPP_
  13 +
  14 +#include "lamp.hpp"
  15 +#include "memory.hpp"
  16 +
  17 +namespace dali {
  18 +namespace controller {
  19 +
  20 +class QueryStore {
  21 +
  22 +public:
  23 + explicit QueryStore(Memory* memory, Lamp* lamp);
  24 + virtual ~QueryStore() {};
  25 +
  26 + Status reset();
  27 + Status storeActualLevelInDtr();
  28 + Status storeDtrAsMaxLevel();
  29 + Status storeDtrAsMinLevel();
  30 + Status storeDtrAsFailureLevel();
  31 + Status storePowerOnLevel();
  32 + Status storeDtrAsFadeTime();
  33 + Status storeDtrAsFadeRate();
  34 + Status storeDtrAsScene(uint8_t scene);
  35 + Status removeFromScene(uint8_t scene);
  36 + Status addToGroup(uint8_t group);
  37 + Status removeFromGroup(uint8_t group);
  38 + Status storeDtrAsShortAddr();
  39 + uint8_t queryStatus();
  40 + bool queryLampFailure();
  41 + bool queryLampPowerOn();
  42 + bool queryLampLimitError();
  43 + bool queryIsFading();
  44 + bool queryResetState();
  45 + bool queryMissingShortAddr();
  46 + bool queryLampPowerSet();
  47 + uint8_t queryActualLevel();
  48 + uint8_t queryMaxLevel();
  49 + uint8_t queryMinLevel();
  50 + uint8_t queryPowerOnLevel();
  51 + uint8_t queryFaliureLevel();
  52 + uint8_t queryFadeRateOrTime();
  53 + uint8_t queryLevelForScene(uint8_t scene);
  54 + uint8_t queryGroupsL();
  55 + uint8_t queryGroupsH();
  56 + uint8_t queryRandomAddrH();
  57 + uint8_t queryRandomAddrM();
  58 + uint8_t queryRandomAddrL();
  59 +
  60 +private:
  61 + bool isMemoryValid();
  62 +
  63 + QueryStore(const QueryStore& other) = delete;
  64 + QueryStore& operator=(const QueryStore&) = delete;
  65 +
  66 + Memory* const mMemoryController;
  67 + Lamp* const mLampController;
  68 +};
  69 +
  70 +} // namespace controller
  71 +} // namespace dali
  72 +
  73 +#endif // DALI_CONTROLLER_QUERY_HPP_
... ...
src/dali/dali.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_DALI_HPP_
  12 +#define DALI_DALI_HPP_
  13 +
  14 +#include "config.hpp"
  15 +#include "commands.hpp"
  16 +
  17 +#include <stddef.h>
  18 +#include <stdint.h>
  19 +#include <stdlib.h>
  20 +#include <string.h>
  21 +
  22 +#define DALI_MASK 255
  23 +
  24 +#define DALI_LEVEL_MAX 254
  25 +#define DALI_LEVEL_DEFAULT 254
  26 +
  27 +#define DALI_FADE_TIME_MIN 0
  28 +#define DALI_FADE_TIME_MAX 15
  29 +#define DALI_FADE_TIME_DEFAULT 0
  30 +
  31 +#define DALI_FADE_RATE_MIN 1
  32 +#define DALI_FADE_RATE_MAX 15
  33 +#define DALI_FADE_RATE_DEFAULT 7
  34 +
  35 +#define DALI_SCENE_MAX 15
  36 +#define DALI_GROUP_MAX 15
  37 +#define DALI_ADDR_MAX 63
  38 +#define DALI_ACK_YES DALI_MASK
  39 +
  40 +namespace dali {
  41 +
  42 +enum class Status {
  43 + OK, ERROR, INVALID, INVALID_STATE, REPEAT_REQUIRED
  44 +};
  45 +
  46 +class IMemory {
  47 +public:
  48 + class IMemoryClient {
  49 + public:
  50 + virtual void onBankReset(uint8_t bank) = 0;
  51 + };
  52 +
  53 + virtual size_t dataSize() = 0;
  54 + virtual size_t dataWrite(uintptr_t addr, const uint8_t* data, size_t size) = 0;
  55 + virtual const uint8_t* data(uintptr_t addr, size_t size) = 0;
  56 +
  57 + virtual size_t tempSize() = 0;
  58 + virtual size_t tempWrite(uintptr_t addr, const uint8_t* data, size_t size) = 0;
  59 + virtual const uint8_t* tempData(uintptr_t addr, size_t size) = 0;
  60 +};
  61 +
  62 +class ILamp {
  63 +public:
  64 + enum class ILampState {
  65 + OK, DISCONNECTED, OVERHEAT
  66 + };
  67 +
  68 + class ILampClient {
  69 + public:
  70 + virtual void onLampStateChnaged(ILampState state) = 0;
  71 + };
  72 +
  73 + virtual Status registerClient(ILampClient* c) = 0;
  74 + virtual Status unregisterClient(ILampClient* c) = 0;
  75 + virtual void setLevel(uint16_t level, uint32_t fadeTime) = 0;
  76 + virtual uint16_t getLevel() = 0;
  77 + virtual bool isFading() = 0;
  78 + virtual void abortFading() = 0;
  79 +};
  80 +
  81 +class IBus {
  82 +public:
  83 + enum class IBusState {
  84 + UNKNOWN, DISCONNECTED, CONNECTED
  85 + };
  86 +
  87 + class IBusClient {
  88 + public:
  89 + virtual void onDataReceived(uint64_t timeMs, uint16_t data) = 0;
  90 + virtual void onBusStateChanged(IBusState state);
  91 + };
  92 +
  93 + virtual Status registerClient(IBusClient* c) = 0;
  94 + virtual Status unregisterClient(IBusClient* c) = 0;
  95 + virtual Status sendAck(uint8_t ack) = 0;
  96 +};
  97 +
  98 +class ITimer {
  99 +public:
  100 + class ITimerTask {
  101 + public:
  102 + virtual void timerTaskRun() = 0;
  103 + };
  104 +
  105 + virtual uint64_t getTime() = 0;
  106 + virtual Status schedule(ITimerTask* task, uint32_t delay, uint32_t period) = 0;
  107 + virtual void cancel(ITimerTask* task) = 0;
  108 + virtual uint32_t randomize() = 0;
  109 +};
  110 +
  111 +} // namespace dali
  112 +
  113 +#endif // DALI_DALI_HPP_
  114 +
... ...
src/dali/slave.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "slave.hpp"
  12 +
  13 +namespace dali {
  14 +
  15 +// static
  16 +Slave* Slave::create(IMemory* memoryDriver, ILamp* lampDriver, IBus* busDriver, ITimer* timer) {
  17 + controller::Memory* memory = new controller::Memory(memoryDriver);
  18 + controller::Lamp* lamp = new controller::Lamp(lampDriver, memory);
  19 + controller::QueryStore* queryStore = new controller::QueryStore(memory, lamp);
  20 + controller::Bus* bus = new controller::Bus(busDriver);
  21 + controller::Initialization* initialization = new controller::Initialization(timer, memory);
  22 +
  23 + return new Slave(memory, lamp, queryStore, bus, initialization);
  24 +}
  25 +
  26 +Slave::Slave(controller::Memory* memory, controller::Lamp* lamp, controller::QueryStore* queryStore,
  27 + controller::Bus* bus, controller::Initialization* initialization) :
  28 + mMemoryController(memory), mLampController(lamp), mQueryStoreController(queryStore),
  29 + mBusController(bus), mInitializationController(initialization),
  30 + mMemoryWriteEnabled(false), mDeviceType(0xff) {
  31 + mLampController->setListener(this);
  32 + mBusController->setListener(this);
  33 +}
  34 +
  35 +Slave::~Slave() {
  36 + mBusController->setListener(nullptr);
  37 + mLampController->setListener(nullptr);
  38 + delete mInitializationController;
  39 + delete mBusController;
  40 + delete mQueryStoreController;
  41 + delete mLampController;
  42 + delete mMemoryController;
  43 +}
  44 +
  45 +void Slave::notifyPowerUp() {
  46 + mLampController->powerRecallOnLevel();
  47 +}
  48 +
  49 +void Slave::notifyPowerDown() {
  50 + mLampController->notifyPowerDown();
  51 +}
  52 +
  53 +void Slave::onLampStateChnaged(ILamp::ILampState state) {
  54 + mInitializationController->onLampStateChnaged(state);
  55 +}
  56 +
  57 +uint8_t Slave::getShortAddr() {
  58 + return mMemoryController->getShortAddr();
  59 +}
  60 +
  61 +uint16_t Slave::getGroups() {
  62 + return mMemoryController->getGroups();
  63 +}
  64 +
  65 +void Slave::onBusDisconnected() {
  66 + mLampController->powerRecallFaliureLevel();
  67 +}
  68 +
  69 +Status Slave::handleHandleDaliDeviceTypeCommand(uint16_t repeat, Command cmd, uint8_t param, uint8_t device_type) {
  70 + return Status::INVALID;
  71 +}
  72 +
  73 +Status Slave::handleCommand(uint16_t repeatCount, Command cmd, uint8_t param) {
  74 + // check memory write
  75 + switch (cmd) {
  76 + case Command::ENABLE_WRITE_MEMORY:
  77 + case Command::WRITE_MEMORY_LOCATION:
  78 + break;
  79 +
  80 + case Command::ENABLE_DEVICE_TYPE_X:
  81 + mDeviceType = param;
  82 + return Status::OK;
  83 +
  84 + default:
  85 + mMemoryWriteEnabled = false;
  86 + }
  87 +
  88 + Status status = internalHandleDaliDT8Command(repeatCount, cmd, param);
  89 + if (status != Status::REPEAT_REQUIRED) {
  90 + mDeviceType = 0xff;
  91 + }
  92 + return status;
  93 +}
  94 +
  95 +Status Slave::handleIgnoredCommand(Command cmd, uint8_t param) {
  96 + mDeviceType = 0xff;
  97 + return Status::INVALID;
  98 +}
  99 +
  100 +Status Slave::internalHandleDaliDT8Command(uint16_t repeatCount, Command cmd, uint8_t param) {
  101 +
  102 + // handle commands
  103 + switch (cmd) {
  104 +
  105 + case Command::OFF:
  106 + return mLampController->powerOff();
  107 +
  108 + case Command::UP:
  109 + return mLampController->powerUp();
  110 +
  111 + case Command::DOWN:
  112 + return mLampController->powerDown();
  113 +
  114 + case Command::STEP_UP:
  115 + return mLampController->powerStepUp();
  116 +
  117 + case Command::STEP_DOWN:
  118 + return mLampController->powerStepDown();
  119 +
  120 + case Command::RECALL_MAX_LEVEL:
  121 + return mLampController->powerRecallMaxLevel();
  122 +
  123 + case Command::RECALL_MIN_LEVEL:
  124 + return mLampController->powerRecallMinLevel();
  125 +
  126 + case Command::STEP_DOWN_AND_OFF:
  127 + return mLampController->powerStepDownAndOff();
  128 +
  129 + case Command::ON_AND_STEP_UP:
  130 + return mLampController->powerOnAndStepUp();
  131 +
  132 + case Command::ENABLE_DAPC_SEQUENCE:
  133 + return mLampController->enableDapcSequence(mBusController->getLastCommandTimeMs());
  134 +
  135 + case Command::GO_TO_SCENE_0:
  136 + case Command::GO_TO_SCENE_1:
  137 + case Command::GO_TO_SCENE_2:
  138 + case Command::GO_TO_SCENE_3:
  139 + case Command::GO_TO_SCENE_4:
  140 + case Command::GO_TO_SCENE_5:
  141 + case Command::GO_TO_SCENE_6:
  142 + case Command::GO_TO_SCENE_7:
  143 + case Command::GO_TO_SCENE_8:
  144 + case Command::GO_TO_SCENE_9:
  145 + case Command::GO_TO_SCENE_A:
  146 + case Command::GO_TO_SCENE_B:
  147 + case Command::GO_TO_SCENE_C:
  148 + case Command::GO_TO_SCENE_D:
  149 + case Command::GO_TO_SCENE_E:
  150 + case Command::GO_TO_SCENE_F:
  151 + return mLampController->powerScene(((uint8_t) cmd) & 0x0f);
  152 +
  153 + case Command::RESET:
  154 + if (repeatCount == 0) {
  155 + return Status::REPEAT_REQUIRED;
  156 + }
  157 + mInitializationController->reset();
  158 + mQueryStoreController->reset();
  159 + return Status::OK;
  160 +
  161 + case Command::STORE_ACTUAL_LEVEL_IN_DTR:
  162 + if (repeatCount == 0) {
  163 + return Status::REPEAT_REQUIRED;
  164 + }
  165 + return mQueryStoreController->storeActualLevelInDtr();
  166 +
  167 + case Command::STORE_DTR_AS_MAX_LEVEL:
  168 + if (repeatCount == 0) {
  169 + return Status::REPEAT_REQUIRED;
  170 + }
  171 + return mQueryStoreController->storeDtrAsMaxLevel();
  172 +
  173 + case Command::STORE_DTR_AS_MIN_LEVEL:
  174 + if (repeatCount == 0) {
  175 + return Status::REPEAT_REQUIRED;
  176 + }
  177 + return mQueryStoreController->storeDtrAsMinLevel();
  178 +
  179 + case Command::STORE_DTR_AS_SYS_FAIL_LEVEL:
  180 + if (repeatCount == 0) {
  181 + return Status::REPEAT_REQUIRED;
  182 + }
  183 + return mQueryStoreController->storeDtrAsFailureLevel();
  184 +
  185 + case Command::STORE_DTR_AS_POWER_ON_LEVEL:
  186 + if (repeatCount == 0) {
  187 + return Status::REPEAT_REQUIRED;
  188 + }
  189 + return mQueryStoreController->storePowerOnLevel();
  190 +
  191 + case Command::STORE_DTR_AS_FADE_TIME:
  192 + if (repeatCount == 0) {
  193 + return Status::REPEAT_REQUIRED;
  194 + }
  195 + return mQueryStoreController->storeDtrAsFadeTime();
  196 +
  197 + case Command::STORE_DTR_AS_FADE_RATE:
  198 + if (repeatCount == 0) {
  199 + return Status::REPEAT_REQUIRED;
  200 + }
  201 + return mQueryStoreController->storeDtrAsFadeRate();
  202 +
  203 + case Command::STORE_DTR_AS_SCENE_0:
  204 + case Command::STORE_DTR_AS_SCENE_1:
  205 + case Command::STORE_DTR_AS_SCENE_2:
  206 + case Command::STORE_DTR_AS_SCENE_3:
  207 + case Command::STORE_DTR_AS_SCENE_4:
  208 + case Command::STORE_DTR_AS_SCENE_5:
  209 + case Command::STORE_DTR_AS_SCENE_6:
  210 + case Command::STORE_DTR_AS_SCENE_7:
  211 + case Command::STORE_DTR_AS_SCENE_8:
  212 + case Command::STORE_DTR_AS_SCENE_9:
  213 + case Command::STORE_DTR_AS_SCENE_A:
  214 + case Command::STORE_DTR_AS_SCENE_B:
  215 + case Command::STORE_DTR_AS_SCENE_C:
  216 + case Command::STORE_DTR_AS_SCENE_D:
  217 + case Command::STORE_DTR_AS_SCENE_E:
  218 + case Command::STORE_DTR_AS_SCENE_F:
  219 + if (repeatCount == 0) {
  220 + return Status::REPEAT_REQUIRED;
  221 + }
  222 + return mQueryStoreController->storeDtrAsScene(((uint8_t) cmd) & 0x0f);
  223 +
  224 + case Command::REMOVE_FROM_SCENE_0:
  225 + case Command::REMOVE_FROM_SCENE_1:
  226 + case Command::REMOVE_FROM_SCENE_2:
  227 + case Command::REMOVE_FROM_SCENE_3:
  228 + case Command::REMOVE_FROM_SCENE_4:
  229 + case Command::REMOVE_FROM_SCENE_5:
  230 + case Command::REMOVE_FROM_SCENE_6:
  231 + case Command::REMOVE_FROM_SCENE_7:
  232 + case Command::REMOVE_FROM_SCENE_8:
  233 + case Command::REMOVE_FROM_SCENE_9:
  234 + case Command::REMOVE_FROM_SCENE_A:
  235 + case Command::REMOVE_FROM_SCENE_B:
  236 + case Command::REMOVE_FROM_SCENE_C:
  237 + case Command::REMOVE_FROM_SCENE_D:
  238 + case Command::REMOVE_FROM_SCENE_E:
  239 + case Command::REMOVE_FROM_SCENE_F:
  240 + if (repeatCount == 0) {
  241 + return Status::REPEAT_REQUIRED;
  242 + }
  243 + return mQueryStoreController->removeFromScene(((uint8_t) cmd) & 0x0f);
  244 +
  245 + case Command::ADD_TO_GROUP_0:
  246 + case Command::ADD_TO_GROUP_1:
  247 + case Command::ADD_TO_GROUP_2:
  248 + case Command::ADD_TO_GROUP_3:
  249 + case Command::ADD_TO_GROUP_4:
  250 + case Command::ADD_TO_GROUP_5:
  251 + case Command::ADD_TO_GROUP_6:
  252 + case Command::ADD_TO_GROUP_7:
  253 + case Command::ADD_TO_GROUP_8:
  254 + case Command::ADD_TO_GROUP_9:
  255 + case Command::ADD_TO_GROUP_A:
  256 + case Command::ADD_TO_GROUP_B:
  257 + case Command::ADD_TO_GROUP_C:
  258 + case Command::ADD_TO_GROUP_D:
  259 + case Command::ADD_TO_GROUP_E:
  260 + case Command::ADD_TO_GROUP_F:
  261 + if (repeatCount == 0) {
  262 + return Status::REPEAT_REQUIRED;
  263 + }
  264 + return mQueryStoreController->addToGroup(((uint8_t) cmd) & 0x0f);
  265 +
  266 + case Command::REMOVE_FROM_GROUP_0:
  267 + case Command::REMOVE_FROM_GROUP_1:
  268 + case Command::REMOVE_FROM_GROUP_2:
  269 + case Command::REMOVE_FROM_GROUP_3:
  270 + case Command::REMOVE_FROM_GROUP_4:
  271 + case Command::REMOVE_FROM_GROUP_5:
  272 + case Command::REMOVE_FROM_GROUP_6:
  273 + case Command::REMOVE_FROM_GROUP_7:
  274 + case Command::REMOVE_FROM_GROUP_8:
  275 + case Command::REMOVE_FROM_GROUP_9:
  276 + case Command::REMOVE_FROM_GROUP_A:
  277 + case Command::REMOVE_FROM_GROUP_B:
  278 + case Command::REMOVE_FROM_GROUP_C:
  279 + case Command::REMOVE_FROM_GROUP_D:
  280 + case Command::REMOVE_FROM_GROUP_E:
  281 + case Command::REMOVE_FROM_GROUP_F:
  282 + if (repeatCount == 0) {
  283 + return Status::REPEAT_REQUIRED;
  284 + }
  285 + return mQueryStoreController->removeFromGroup(((uint8_t) cmd) & 0x0f);
  286 +
  287 + case Command::STORE_DTR_AS_SHORT_ADDR:
  288 + if (repeatCount == 0) {
  289 + return Status::REPEAT_REQUIRED;
  290 + }
  291 + return mQueryStoreController->storeDtrAsShortAddr();
  292 +
  293 + case Command::ENABLE_WRITE_MEMORY:
  294 + if (repeatCount == 0) {
  295 + return Status::REPEAT_REQUIRED;
  296 + }
  297 + mMemoryWriteEnabled = true;
  298 + return Status::OK;
  299 +
  300 + case Command::QUERY_STATUS:
  301 + return sendAck(mQueryStoreController->queryStatus());
  302 +
  303 + case Command::QUERY_CONTROL_GEAR:
  304 + return sendAck(DALI_ACK_YES);
  305 +
  306 + case Command::QUERY_LAMP_FAILURE:
  307 + if (mQueryStoreController->queryLampFailure()) {
  308 + return sendAck(DALI_ACK_YES);
  309 + }
  310 + return Status::OK;
  311 +
  312 + case Command::QUERY_LAMP_POWER_ON:
  313 + if (mQueryStoreController->queryLampPowerOn()) {
  314 + return sendAck(DALI_ACK_YES);
  315 + }
  316 + return Status::OK;
  317 +
  318 + case Command::QUERY_LIMIT_ERROR:
  319 + if (mQueryStoreController->queryLampLimitError()) {
  320 + return sendAck(DALI_ACK_YES);
  321 + }
  322 + return Status::OK;
  323 +
  324 + case Command::QUERY_RESET_STATE:
  325 + if (mQueryStoreController->queryResetState()) {
  326 + return sendAck(DALI_ACK_YES);
  327 + }
  328 + return Status::OK;
  329 +
  330 + case Command::QUERY_MISSING_SHORT_ADDR: {
  331 + if (mQueryStoreController->queryMissingShortAddr()) {
  332 + return sendAck(DALI_ACK_YES);
  333 + }
  334 + return Status::OK;
  335 + }
  336 +
  337 + case Command::QUERY_VERSION_NUMBER:
  338 + return sendAck(DALI_VERSION);
  339 +
  340 + case Command::QUERY_CONTENT_DTR:
  341 + return sendAck(mMemoryController->getDTR());
  342 +
  343 + case Command::QUERY_DEVICE_TYPE:
  344 + return sendAck(DALI_DEVICE_TYPE);
  345 +
  346 + case Command::QUERY_PHISICAL_MIN_LEVEL:
  347 + return sendAck(mMemoryController->getPhisicalMinLevel());
  348 +
  349 + case Command::QUERY_POWER_FAILURE:
  350 + if (!mQueryStoreController->queryLampPowerSet()) {
  351 + return sendAck(DALI_ACK_YES);
  352 + }
  353 + return Status::OK;
  354 +
  355 + case Command::QUERY_CONTENT_DTR1:
  356 + return sendAck(mMemoryController->getDTR1());
  357 +
  358 + case Command::QUERY_CONTENT_DTR2:
  359 + return sendAck(mMemoryController->getDTR2());
  360 +
  361 + case Command::QUERY_ACTUAL_LEVEL:
  362 + return sendAck(mQueryStoreController->queryActualLevel());
  363 +
  364 + case Command::QUERY_MAX_LEVEL:
  365 + return sendAck(mQueryStoreController->queryMaxLevel());
  366 +
  367 + case Command::QUERY_MIN_LEVEL:
  368 + return sendAck(mQueryStoreController->queryMinLevel());
  369 +
  370 + case Command::QUERY_POWER_ON_LEVEL:
  371 + return sendAck(mQueryStoreController->queryPowerOnLevel());
  372 +
  373 + case Command::QUERY_SYS_FAILURE_LEVEL:
  374 + return sendAck(mQueryStoreController->queryFaliureLevel());
  375 +
  376 + case Command::QUERY_FADE_TIME_OR_RATE:
  377 + return sendAck(mQueryStoreController->queryFadeRateOrTime());
  378 +
  379 + case Command::QUERY_SCENE_0_LEVEL:
  380 + case Command::QUERY_SCENE_1_LEVEL:
  381 + case Command::QUERY_SCENE_2_LEVEL:
  382 + case Command::QUERY_SCENE_3_LEVEL:
  383 + case Command::QUERY_SCENE_4_LEVEL:
  384 + case Command::QUERY_SCENE_5_LEVEL:
  385 + case Command::QUERY_SCENE_6_LEVEL:
  386 + case Command::QUERY_SCENE_7_LEVEL:
  387 + case Command::QUERY_SCENE_8_LEVEL:
  388 + case Command::QUERY_SCENE_9_LEVEL:
  389 + case Command::QUERY_SCENE_A_LEVEL:
  390 + case Command::QUERY_SCENE_B_LEVEL:
  391 + case Command::QUERY_SCENE_C_LEVEL:
  392 + case Command::QUERY_SCENE_D_LEVEL:
  393 + case Command::QUERY_SCENE_E_LEVEL:
  394 + case Command::QUERY_SCENE_F_LEVEL:
  395 + return sendAck(mQueryStoreController->queryLevelForScene(((uint8_t) cmd) & 0xf));
  396 +
  397 + case Command::QUERY_GROUPS_L:
  398 + return sendAck(mQueryStoreController->queryGroupsL());
  399 +
  400 + case Command::QUERY_GROUPS_H:
  401 + return sendAck(mQueryStoreController->queryGroupsH());
  402 +
  403 + case Command::QUERY_RANDOM_ADDR_H:
  404 + return sendAck(mQueryStoreController->queryRandomAddrH());
  405 +
  406 + case Command::QUERY_RANDOM_ADDR_M:
  407 + return sendAck(mQueryStoreController->queryRandomAddrM());
  408 +
  409 + case Command::QUERY_RANDOM_ADDR_L:
  410 + return sendAck(mQueryStoreController->queryRandomAddrL());
  411 +
  412 + case Command::READ_MEMORY_LOCATION: {
  413 + uint8_t data = 0;
  414 + if (mMemoryController->readMemory(&data) != Status::OK) {
  415 + return Status::ERROR;
  416 + }
  417 + return sendAck(data);
  418 + }
  419 +
  420 + // extended commands
  421 +
  422 + case Command::DIRECT_POWER_CONTROL:
  423 + return mLampController->powerDirect(param, mBusController->getLastCommandTimeMs());
  424 +
  425 + case Command::TERMINATE:
  426 + return mInitializationController->terminate();
  427 +
  428 + case Command::DATA_TRANSFER_REGISTER:
  429 + mMemoryController->setDTR(param);
  430 + return Status::OK;
  431 +
  432 + case Command::INITIALISE:
  433 + if (repeatCount == 0) {
  434 + return Status::REPEAT_REQUIRED;
  435 + }
  436 + return mInitializationController->initialize(param);
  437 +
  438 + case Command::RANDOMISE:
  439 + if (repeatCount == 0) {
  440 + return Status::REPEAT_REQUIRED;
  441 + }
  442 + return mInitializationController->randomize();
  443 +
  444 + case Command::COMPARE: {
  445 + Status status = mInitializationController->compare();
  446 + if (status == Status::OK) {
  447 + return mBusController->sendAck(DALI_ACK_YES);
  448 + }
  449 + return status;
  450 + }
  451 + case Command::WITHDRAW:
  452 + return mInitializationController->withdraw();
  453 +
  454 + case Command::SEARCHADDRH:
  455 + return mInitializationController->searchAddrH(param);
  456 +
  457 + case Command::SEARCHADDRM:
  458 + return mInitializationController->searchAddrM(param);
  459 +
  460 + case Command::SEARCHADDRL:
  461 + return mInitializationController->searchAddrL(param);
  462 +
  463 + case Command::PROGRAM_SHORT_ADDRESS:
  464 + return mInitializationController->programShortAddr(param);
  465 +
  466 + case Command::VERIFY_SHORT_ADDRESS: {
  467 + Status status = mInitializationController->verifySortAddr(param);
  468 + if (status == Status::OK) {
  469 + return mBusController->sendAck(DALI_ACK_YES);
  470 + }
  471 + return status;
  472 + }
  473 + case Command::QUERY_SHORT_ADDRESS: {
  474 + uint8_t shortAddr;
  475 + Status status = mInitializationController->queryShortAddr(&shortAddr);
  476 + if (status == Status::OK) {
  477 + return mBusController->sendAck(shortAddr);
  478 + }
  479 + return status;
  480 + }
  481 + case Command::PHYSICAL_SELECTION:
  482 + return mInitializationController->physicalSelection();
  483 +
  484 + case Command::DATA_TRANSFER_REGISTER_1:
  485 + mMemoryController->setDTR1(param);
  486 + return Status::OK;
  487 +
  488 + case Command::DATA_TRANSFER_REGISTER_2:
  489 + mMemoryController->setDTR2(param);
  490 + return Status::OK;
  491 +
  492 + case Command::WRITE_MEMORY_LOCATION:
  493 + if (!mMemoryWriteEnabled) {
  494 + return Status::ERROR;
  495 + }
  496 + switch (mMemoryController->writeMemory(param)) {
  497 + case Status::OK:
  498 + return sendAck(param);
  499 + default:
  500 + return Status::ERROR;
  501 + }
  502 +
  503 + default:
  504 + return handleHandleDaliDeviceTypeCommand(repeatCount, cmd, param, mDeviceType);
  505 + }
  506 +}
  507 +
  508 +}
  509 +// namespace dali
... ...
src/dali/slave.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef DALI_SLAVE_H_
  12 +#define DALI_SLAVE_H_
  13 +
  14 +#include <dali/dali.hpp>
  15 +#include <dali/controller/bus.hpp>
  16 +#include <dali/controller/initialization.hpp>
  17 +#include <dali/controller/lamp.hpp>
  18 +#include <dali/controller/memory.hpp>
  19 +#include <dali/controller/query_store.hpp>
  20 +
  21 +namespace dali {
  22 +
  23 +class Slave: public controller::Bus::Listener, controller::Lamp::Listener {
  24 +public:
  25 + static Slave* create(IMemory* memoryDriver, ILamp* lampDriver, IBus* busDriver, ITimer* timer);
  26 +
  27 + virtual ~Slave();
  28 +
  29 + void notifyPowerUp();
  30 + void notifyPowerDown();
  31 +
  32 +private:
  33 + Slave(const Slave& other) = delete;
  34 + Slave& operator=(const Slave&) = delete;
  35 +
  36 + // LampController::Listener
  37 + void onLampStateChnaged(ILamp::ILampState state) override;
  38 +
  39 + // BusController::BusController
  40 + uint8_t getShortAddr() override;
  41 + uint16_t getGroups() override;
  42 + void onBusDisconnected() override;
  43 + Status handleCommand(uint16_t repeat, Command cmd, uint8_t param) override;
  44 + Status handleIgnoredCommand(Command cmd, uint8_t param) override;
  45 + Status internalHandleDaliDT8Command(uint16_t repeat, Command cmd, uint8_t param);
  46 +
  47 + Status sendAck(uint8_t ack) {
  48 + return mBusController->sendAck(ack);
  49 + }
  50 +
  51 + Status handleHandleDaliDeviceTypeCommand(uint16_t repeat, Command cmd, uint8_t param, uint8_t device_type);
  52 +
  53 + Slave(controller::Memory* memory, controller::Lamp* lamp, controller::QueryStore* queryStore,
  54 + controller::Bus* busDriver, controller::Initialization* initializationController);
  55 +
  56 + controller::Memory* const mMemoryController;
  57 + controller::Lamp* const mLampController;
  58 + controller::QueryStore* const mQueryStoreController;
  59 + controller::Bus* const mBusController;
  60 + controller::Initialization* const mInitializationController;
  61 + bool mMemoryWriteEnabled;
  62 + uint8_t mDeviceType;
  63 +};
  64 +
  65 +} // namespace dali
  66 +
  67 +#endif // DALI_SLAVE_H_
... ...
src/util/manchester.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "manchester.hpp"
  12 +
  13 +uint32_t manchesterEncode16(uint16_t data) {
  14 + uint32_t result = 0xffffffff;
  15 + for (uint8_t i = 0; i < 8; ++i) {
  16 + result <<= 2;
  17 + if (data & 0x80) {
  18 + result |= 1;
  19 + } else {
  20 + result |= 2;
  21 + }
  22 + data <<= 1;
  23 + }
  24 + return result;
  25 +}
  26 +
  27 +uint32_t manchesterEncode32(uint16_t data) {
  28 + uint32_t result = 0xffffffff;
  29 + for (uint8_t i = 0; i < 16; ++i) {
  30 + result <<= 2;
  31 + if (data & 0x8000) {
  32 + result |= 1;
  33 + } else {
  34 + result |= 2;
  35 + }
  36 + data <<= 1;
  37 + }
  38 + return result;
  39 +}
  40 +
  41 +uint32_t manchesterEncode16Inv(uint16_t data) {
  42 + uint32_t result = 0xffffffff;
  43 + for (uint8_t i = 0; i < 8; ++i) {
  44 + result <<= 2;
  45 + if (data & 0x01) {
  46 + result |= 2;
  47 + } else {
  48 + result |= 1;
  49 + }
  50 + data >>= 1;
  51 + }
  52 + return result;
  53 +}
  54 +
  55 +uint32_t manchesterEncode32Inv(uint16_t data) {
  56 + uint32_t result = 0xffffffff;
  57 + for (uint8_t i = 0; i < 16; ++i) {
  58 + result <<= 2;
  59 + if (data & 0x01) {
  60 + result |= 2;
  61 + } else {
  62 + result |= 1;
  63 + }
  64 + data >>= 1;
  65 + }
  66 + return result;
  67 +}
  68 +
  69 +uint16_t manchesterDecode32(uint32_t data) {
  70 + uint16_t result = 0x00000000;
  71 + for (uint8_t i = 0; i < 16; i++) {
  72 + uint16_t x = data >> 30;
  73 + switch (x) {
  74 + case 1:
  75 + result <<= 1;
  76 + result |= 1;
  77 + data <<= 2;
  78 + break;
  79 +
  80 + case 2:
  81 + result <<= 1;
  82 + data <<= 2;
  83 + break;
  84 +
  85 + default:
  86 + return 0xffff;
  87 + }
  88 + }
  89 + return result;
  90 +}
  91 +
  92 +uint16_t manchesterDecode16(uint32_t data) {
  93 + uint16_t result = 0x0000;
  94 + for (uint8_t i = 0; i < 8; i++) {
  95 + uint16_t x = (data & 0xffff) >> 14;
  96 + switch (x) {
  97 + case 1:
  98 + result <<= 1;
  99 + result |= 1;
  100 + data <<= 2;
  101 + break;
  102 +
  103 + case 2:
  104 + result <<= 1;
  105 + data <<= 2;
  106 + break;
  107 +
  108 + default:
  109 + return 0xffff;
  110 + }
  111 + }
  112 + return result;
  113 +}
... ...
src/util/manchester.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef UTIL_MANCHESTER_HPP_
  12 +#define UTIL_MANCHESTER_HPP_
  13 +
  14 +#include <stdint.h>
  15 +
  16 +uint32_t manchesterEncode16(uint16_t data);
  17 +uint32_t manchesterEncode32(uint16_t data);
  18 +uint32_t manchesterEncode16Inv(uint16_t data);
  19 +uint32_t manchesterEncode32Inv(uint16_t data);
  20 +uint16_t manchesterDecode32(uint32_t data);
  21 +uint16_t manchesterDecode16(uint32_t data);
  22 +
  23 +#endif // UTIL_MANCHESTER_HPP_
... ...
src/xmc1200/bccu.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "bccu.hpp"
  12 +
  13 +#include "bccu_config.h"
  14 +#include "clock.hpp"
  15 +
  16 +#define LINPRES_MAX 1023
  17 +#define LINPRES_MAGIC 8192
  18 +
  19 +#define DIMMING_MAX 1023
  20 +#define DIMMING_MAGIC_UP 20479
  21 +#define DIMMING_MAGIC_DOWN 20734
  22 +#define DIMMING_MAGIC ((DIMMING_MAGIC_UP + DIMMING_MAGIC_DOWN) / 2)
  23 +
  24 +#define MSEC_PER_SEC 1000
  25 +
  26 +namespace xmc {
  27 +namespace {
  28 +
  29 +BCCU_Type* const BCCU = BCCU0;
  30 +
  31 +BCCU_DE_Type* const BCCU_DEs[] = { BCCU0_DE0, BCCU0_DE1, BCCU0_DE2 };
  32 +
  33 +BCCU_CH_Type* const BCCU_CHs[] = {
  34 + BCCU0_CH0,
  35 + BCCU0_CH1,
  36 + BCCU0_CH2,
  37 + BCCU0_CH3,
  38 + BCCU0_CH4,
  39 + BCCU0_CH5,
  40 + BCCU0_CH6,
  41 + BCCU0_CH7,
  42 + BCCU0_CH8, };
  43 +
  44 +uint16_t calculateDimmingPrescaller(uint32_t timeMs, uint32_t magic) {
  45 + uint32_t dclk_ps = BCCU->GLOBCLK & BCCU_GLOBCLK_DCLK_PS_Msk;
  46 + dclk_ps >>= BCCU_GLOBCLK_DCLK_PS_Pos;
  47 +
  48 + uint32_t prescaler = ((uint32_t) (CPU_CLOCK / MSEC_PER_SEC) * timeMs / dclk_ps + magic / 2) / magic;
  49 + if (prescaler > DIMMING_MAX) {
  50 + return 0;
  51 + }
  52 + return (uint16_t) prescaler;
  53 +}
  54 +
  55 +uint16_t calculateLinearPrescaller(uint32_t timeMs) {
  56 + uint32_t fclk_ps = BCCU->GLOBCLK & BCCU_GLOBCLK_FCLK_PS_Msk;
  57 + fclk_ps >>= BCCU_GLOBCLK_FCLK_PS_Pos;
  58 +
  59 + uint32_t prescaler = ((uint32_t) (CPU_CLOCK / MSEC_PER_SEC) * timeMs / fclk_ps + LINPRES_MAGIC / 2) / LINPRES_MAGIC;
  60 + if (prescaler > LINPRES_MAX) {
  61 + return 0;
  62 + }
  63 + return (uint16_t) prescaler;
  64 +}
  65 +
  66 +bool gBccuConfigured = false;
  67 +
  68 +void configureBccuGlobal() {
  69 + if (gBccuConfigured) {
  70 + return;
  71 + }
  72 +
  73 + XMC_BCCU_GlobalInit(BCCU, &kBCCUGlobalConfig);
  74 + BCCU->CHTRIG = 0;
  75 +
  76 +#ifdef XMC_BCCU_CH0_PIN
  77 + XMC_GPIO_SetMode(XMC_BCCU_CH0_PIN, XMC_BCCU_CH0_PIN_MODE);
  78 +#endif
  79 +#ifdef XMC_BCCU_CH1_PIN
  80 + XMC_GPIO_SetMode(XMC_BCCU_CH1_PIN, XMC_BCCU_CH1_PIN_MODE);
  81 +#endif
  82 +#ifdef XMC_BCCU_CH2_PIN
  83 + XMC_GPIO_SetMode(XMC_BCCU_CH2_PIN, XMC_BCCU_CH2_PIN_MODE);
  84 +#endif
  85 +#ifdef XMC_BCCU_CH3_PIN
  86 + XMC_GPIO_SetMode(XMC_BCCU_CH3_PIN, XMC_BCCU_CH3_PIN_MODE);
  87 +#endif
  88 +#ifdef XMC_BCCU_CH4_PIN
  89 + XMC_GPIO_SetMode(XMC_BCCU_CH4_PIN, XMC_BCCU_CH4_PIN_MODE);
  90 +#endif
  91 +#ifdef XMC_BCCU_CH5_PIN
  92 + XMC_GPIO_SetMode(XMC_BCCU_CH5_PIN, XMC_BCCU_CH5_PIN_MODE);
  93 +#endif
  94 +#ifdef XMC_BCCU_CH6_PIN
  95 + XMC_GPIO_SetMode(XMC_BCCU_CH6_PIN, XMC_BCCU_CH6_PIN_MODE);
  96 +#endif
  97 +#ifdef XMC_BCCU_CH7_PIN
  98 + XMC_GPIO_SetMode(XMC_BCCU_CH7_PIN, XMC_BCCU_CH7_PIN_MODE);
  99 +#endif
  100 +#ifdef XMC_BCCU_CH8_PIN
  101 + XMC_GPIO_SetMode(XMC_BCCU_CH8_PIN, XMC_BCCU_CH8_PIN_MODE);
  102 +#endif
  103 +
  104 + gBccuConfigured = true;
  105 +}
  106 +
  107 +void configureBccuDimmingEngine(BCCU_DE_Type* BCCU_DE) {
  108 + configureBccuGlobal();
  109 +
  110 + XMC_BCCU_DIM_Init(BCCU_DE, &kBCCUDimmingConfig);
  111 + XMC_BCCU_DIM_SetTargetDimmingLevel(BCCU_DE, 0);
  112 +}
  113 +
  114 +void configureBccuChannel(BCCU_CH_Type* BCCU_CH, Bccu::DimmingEngine engine,
  115 + const XMC_BCCU_CH_CONFIG_t* channelConfig) {
  116 + XMC_BCCU_CH_Init(BCCU_CH, channelConfig);
  117 + XMC_BCCU_CH_SelectDimEngine(BCCU_CH, (XMC_BCCU_CH_DIMMING_SOURCE_t) engine);
  118 +}
  119 +
  120 +} // namespace
  121 +
  122 +Bccu::Bccu(DimmingEngine de, uint32_t engineMask, uint32_t channelsMask) :
  123 + BCCU_DE(BCCU_DEs[de]), mEngineMask(engineMask), mChannelsMask(channelsMask), mLastFadeTime(0), mLastChangeTime(0) {
  124 +}
  125 +
  126 +void Bccu::enable() {
  127 + XMC_BCCU_ConcurrentEnableChannels(BCCU, mChannelsMask);
  128 + for (uint16_t i = 0; i < 9; ++i) {
  129 + if (mChannelsMask & (1 << i)) {
  130 + BCCU_CH_Type* BCCU_CH = BCCU_CHs[i];
  131 + XMC_BCCU_CH_SetLinearWalkPrescaler(BCCU_CH, 0);
  132 + XMC_BCCU_CH_SetTargetIntensity(BCCU_CH, 0);
  133 + }
  134 + }
  135 + XMC_BCCU_ConcurrentStartLinearWalk(BCCU, mChannelsMask);
  136 + XMC_BCCU_ConcurrentEnableDimmingEngine(BCCU, mEngineMask);
  137 + XMC_BCCU_ConcurrentStartDimming(BCCU, mEngineMask);
  138 +}
  139 +
  140 +void Bccu::disable() {
  141 + XMC_BCCU_ConcurrentAbortLinearWalk(BCCU, mChannelsMask);
  142 + XMC_BCCU_ConcurrentDisableChannels(BCCU, mChannelsMask);
  143 +
  144 + XMC_BCCU_ConcurrentAbortDimming(BCCU, mEngineMask);
  145 + XMC_BCCU_DIM_SetTargetDimmingLevel(BCCU_DE, 0);
  146 + XMC_BCCU_ConcurrentStartDimming(BCCU, mEngineMask);
  147 + while (isFading()) {
  148 + }
  149 + XMC_BCCU_ConcurrentDisableDimmingEngine(BCCU, mEngineMask);
  150 +}
  151 +
  152 +void Bccu::setLevel(uint16_t level, uint32_t fadeTime) {
  153 + // ASSERT(fadeTime < 2^31)
  154 + if (isFading()) {
  155 + abortFading();
  156 + }
  157 + uint32_t up = getLevel() > level ? 1 : -1;
  158 + int32_t _fadeTime = up * (int32_t) fadeTime;
  159 + if (mLastFadeTime != _fadeTime) {
  160 + mLastFadeTime = _fadeTime;
  161 + uint32_t prescaler = calculateDimmingPrescaller(fadeTime, up ? DIMMING_MAGIC_UP : DIMMING_MAGIC_DOWN);
  162 + XMC_BCCU_DIM_SetDimDivider(BCCU_DE, prescaler);
  163 + }
  164 + XMC_BCCU_DIM_SetTargetDimmingLevel(BCCU_DE, level);
  165 + XMC_BCCU_ConcurrentStartDimming(BCCU, mEngineMask);
  166 +}
  167 +
  168 +uint16_t Bccu::getLevel() {
  169 + return XMC_BCCU_DIM_ReadDimmingLevel(BCCU_DE);
  170 +}
  171 +
  172 +bool Bccu::isFading() {
  173 + return (BCCU->DESTRCON & mEngineMask) != 0;
  174 +}
  175 +
  176 +void Bccu::abortFading() {
  177 + XMC_BCCU_ConcurrentAbortDimming(BCCU, mEngineMask);
  178 +}
  179 +
  180 +bool Bccu::isColorChanging() {
  181 + return (BCCU->CHSTRCON & mChannelsMask) != 0;
  182 +}
  183 +
  184 +void Bccu::abortColorChanging() {
  185 + XMC_BCCU_ConcurrentAbortLinearWalk(BCCU, mChannelsMask);
  186 +}
  187 +
  188 +BccuLampRGB::BccuLampRGB(DimmingEngine de, Channel r, Channel g, Channel b, const XMC_BCCU_CH_CONFIG_t* channelConfigR,
  189 + const XMC_BCCU_CH_CONFIG_t* channelConfigG, const XMC_BCCU_CH_CONFIG_t* channelConfigB) :
  190 + Bccu(de, (1 << de), ((1 << r) | (1 << g) | (1 << b))), BCCU_CH_R(BCCU_CHs[r]), BCCU_CH_G(BCCU_CHs[g]),
  191 + BCCU_CH_B(BCCU_CHs[b]) {
  192 + configureBccuDimmingEngine(BCCU_DE);
  193 + configureBccuChannel(BCCU_CH_R, de, channelConfigR);
  194 + configureBccuChannel(BCCU_CH_G, de, channelConfigG);
  195 + configureBccuChannel(BCCU_CH_B, de, channelConfigB);
  196 +}
  197 +
  198 +void BccuLampRGB::setColor(uint16_t r, uint16_t g, uint16_t b, uint32_t changeTime) {
  199 + if (isColorChanging()) {
  200 + abortColorChanging();
  201 + }
  202 + if (mLastChangeTime != (int32_t) changeTime) {
  203 + mLastChangeTime = (int32_t) changeTime;
  204 + uint32_t prescaler = calculateLinearPrescaller(changeTime);
  205 + XMC_BCCU_CH_SetLinearWalkPrescaler(BCCU_CH_R, prescaler);
  206 + XMC_BCCU_CH_SetLinearWalkPrescaler(BCCU_CH_G, prescaler);
  207 + XMC_BCCU_CH_SetLinearWalkPrescaler(BCCU_CH_B, prescaler);
  208 + }
  209 +
  210 + XMC_BCCU_CH_SetTargetIntensity(BCCU_CH_R, r);
  211 + XMC_BCCU_CH_SetTargetIntensity(BCCU_CH_G, g);
  212 + XMC_BCCU_CH_SetTargetIntensity(BCCU_CH_B, b);
  213 +
  214 + XMC_BCCU_ConcurrentStartLinearWalk(BCCU, mChannelsMask);
  215 +}
  216 +
  217 +uint16_t BccuLampRGB::getColorR() {
  218 + return XMC_BCCU_CH_ReadIntensity(BCCU_CH_R);
  219 +}
  220 +
  221 +uint16_t BccuLampRGB::getColorG() {
  222 + return XMC_BCCU_CH_ReadIntensity(BCCU_CH_G);
  223 +}
  224 +
  225 +uint16_t BccuLampRGB::getColorB() {
  226 + return XMC_BCCU_CH_ReadIntensity(BCCU_CH_B);
  227 +}
  228 +
  229 +} // namespace xmc
... ...
src/xmc1200/bccu.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_LAMP_HPP_
  12 +#define XMC_LAMP_HPP_
  13 +
  14 +#include <xmc_bccu.h>
  15 +
  16 +namespace xmc {
  17 +
  18 +class Bccu {
  19 +public:
  20 +
  21 + typedef enum {
  22 + DE0 = 0, // BCCU Dimming Engine 0
  23 + DE1 = 1, // BCCU Dimming Engine 1
  24 + DE2 = 2, // BCCU Dimming Engine 2
  25 + } DimmingEngine;
  26 +
  27 + typedef enum {
  28 + CH0 = 0, // BCCU Channel 0
  29 + CH1 = 1, // BCCU Channel 1
  30 + CH2 = 2, // BCCU Channel 2
  31 + CH3 = 3, // BCCU Channel 3
  32 + CH4 = 4, // BCCU Channel 4
  33 + CH5 = 5, // BCCU Channel 5
  34 + CH6 = 6, // BCCU Channel 6
  35 + CH7 = 7, // BCCU Channel 7
  36 + CH8 = 8, // BCCU Channel 8
  37 + } Channel;
  38 +
  39 + Bccu(DimmingEngine de, uint32_t engineMask, uint32_t channelsMask);
  40 +
  41 + void enable();
  42 + void disable();
  43 +
  44 + void setLevel(uint16_t level, uint32_t fadeTime);
  45 + uint16_t getLevel();
  46 +
  47 + bool isFading();
  48 + void abortFading();
  49 + bool isColorChanging();
  50 + void abortColorChanging();
  51 +
  52 +protected:
  53 + BCCU_DE_Type* const BCCU_DE;
  54 + const uint32_t mEngineMask;
  55 + const uint32_t mChannelsMask;
  56 + int32_t mLastFadeTime; // not unsigned because up/down are different
  57 + int32_t mLastChangeTime;
  58 +};
  59 +
  60 +
  61 +class BccuLampRGB: public Bccu {
  62 +public:
  63 + BccuLampRGB(DimmingEngine de, Channel r, Channel g, Channel b, const XMC_BCCU_CH_CONFIG_t* channelConfigR,
  64 + const XMC_BCCU_CH_CONFIG_t* channelConfigG, const XMC_BCCU_CH_CONFIG_t* channelConfigB);
  65 +
  66 + ~BccuLampRGB() {
  67 + disable();
  68 + }
  69 +
  70 + void setColor(uint16_t R, uint16_t G, uint16_t B, uint32_t changeTime);
  71 + uint16_t getColorR();
  72 + uint16_t getColorG();
  73 + uint16_t getColorB();
  74 +
  75 +private:
  76 + BCCU_CH_Type* BCCU_CH_R;
  77 + BCCU_CH_Type* BCCU_CH_G;
  78 + BCCU_CH_Type* BCCU_CH_B;
  79 +};
  80 +
  81 +}// namespace xmc
  82 +
  83 +#endif // XMC_LAMP_HPP_
... ...
src/xmc1200/bccu_config.c 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "bccu_config.h"
  12 +
  13 +const XMC_BCCU_GLOBAL_CONFIG_t kBCCUGlobalConfig = {
  14 + trig_mode: XMC_BCCU_TRIGMODE0,
  15 + trig_delay: XMC_BCCU_TRIGDELAY_NO_DELAY,
  16 + maxzero_at_output: 256,
  17 + fclk_ps: 346,
  18 + bclk_sel: XMC_BCCU_BCLK_MODE_NORMAL,
  19 + dclk_ps: 154,
  20 + global_dimlevel: 0,
  21 +};
  22 +
  23 +const XMC_BCCU_DIM_CONFIG_t kBCCUDimmingConfig = {
  24 + dim_div: 0,
  25 + dither_en: 0,
  26 + cur_sel: XMC_BCCU_DIM_CURVE_FINE,
  27 +};
  28 +
  29 +const XMC_BCCU_CH_CONFIG_t kLampBCCUChannelConfig = {
  30 + pack_thresh: 3,
  31 + pack_en: 0,
  32 + dim_sel: XMC_BCCU_CH_DIMMING_SOURCE_GLOBAL,
  33 + dim_bypass: XMC_BCCU_CH_DIMMING_ENGINE_BYPASS_DISABLE,
  34 + gate_en: XMC_BCCU_CH_GATING_FUNC_DISABLE,
  35 + flick_wd_en: XMC_BCCU_CH_FLICKER_WD_EN,
  36 + trig_edge: XMC_BCCU_CH_TRIG_EDGE_PASS_TO_ACT,
  37 + force_trig_en: 0,
  38 + pack_offcmp_lev: 55,
  39 + pack_oncmp_lev: 55,
  40 + pack_offcnt_val: 0,
  41 + pack_oncnt_val: 0,
  42 +};
... ...
src/xmc1200/bccu_config.h 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_LAMP_CONFIG_H_
  12 +#define XMC_LAMP_CONFIG_H_
  13 +
  14 +
  15 +#include <xmc_bccu.h>
  16 +#include <xmc_gpio.h>
  17 +
  18 +// remove unused pins
  19 +#define XMC_BCCU_CH0_PIN P0_4
  20 +#define XMC_BCCU_CH0_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1
  21 +
  22 +#define XMC_BCCU_CH1_PIN P0_5
  23 +#define XMC_BCCU_CH1_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1
  24 +
  25 +#define XMC_BCCU_CH2_PIN P0_6
  26 +#define XMC_BCCU_CH2_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1
  27 +
  28 +#define XMC_BCCU_CH3_PIN P0_7
  29 +#define XMC_BCCU_CH3_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1
  30 +
  31 +#define XMC_BCCU_CH4_PIN P0_8
  32 +#define XMC_BCCU_CH4_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1
  33 +
  34 +#define XMC_BCCU_CH5_PIN P0_9
  35 +#define XMC_BCCU_CH5_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1
  36 +
  37 +#define XMC_BCCU_CH6_PIN P0_10
  38 +#define XMC_BCCU_CH6_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1
  39 +
  40 +#define XMC_BCCU_CH7_PIN P0_11
  41 +#define XMC_BCCU_CH7_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1
  42 +
  43 +#define XMC_BCCU_CH8_PIN P0_1
  44 +#define XMC_BCCU_CH8_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT6
  45 +
  46 +#ifdef __cplusplus
  47 +extern "C" {
  48 +#endif
  49 +
  50 +extern const XMC_BCCU_GLOBAL_CONFIG_t kBCCUGlobalConfig;
  51 +extern const XMC_BCCU_DIM_CONFIG_t kBCCUDimmingConfig;
  52 +extern const XMC_BCCU_CH_CONFIG_t kLampBCCUChannelConfig;
  53 +
  54 +#ifdef __cplusplus
  55 +} // extern "C"
  56 +#endif
  57 +
  58 +#endif // XMC_LAMP_CONFIG_H_
... ...
src/xmc1200/clock.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "clock.hpp"
  12 +
  13 +#include <xmc_scu.h>
  14 +#include <xmc1_scu.h>
  15 +
  16 +namespace xmc {
  17 +
  18 +void Clock::init(Clock::Frequency freq) {
  19 + XMC_SCU_CLOCK_CONFIG_t config;
  20 + config.pclk_src = XMC_SCU_CLOCK_PCLKSRC_MCLK;
  21 + config.rtc_src = XMC_SCU_CLOCK_RTCCLKSRC_DCO2;
  22 + config.fdiv = 0;
  23 + config.idiv = freq;
  24 + XMC_SCU_CLOCK_Init(&config);
  25 +}
  26 +
  27 +uint32_t Clock::freq(void) {
  28 + return SystemCoreClock;
  29 +}
  30 +
  31 +} // namespace xmc
... ...
src/xmc1200/clock.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_CLK_HPP_
  12 +#define XMC_CLK_HPP_
  13 +
  14 +#include <stdint.h>
  15 +
  16 +namespace xmc {
  17 +
  18 +class Clock {
  19 +public:
  20 +
  21 + typedef enum {
  22 + FREQ_32MHZ = 0x01,
  23 + FREQ_16MHZ = 0x02,
  24 + FREQ_10_67MHZ = 0x03,
  25 + FREQ_8MHZ = 0x04,
  26 + FREQ_126KHZ = 0xFE,
  27 + FREQ_125_5KHZ = 0xFF,
  28 + } Frequency;
  29 +
  30 + // Initializes SCU Clock registers based on user configuration
  31 + static void init(Frequency freq);
  32 +
  33 + // Returns current clock frequency
  34 + static uint32_t freq(void);
  35 +
  36 +};
  37 +// class Clock
  38 +
  39 +}// namespace xmc
  40 +
  41 +#endif // XMC_CLK_HPP_
... ...
src/xmc1200/dali/bus.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "bus.hpp"
  12 +
  13 +#include "bus_config.h"
  14 +#include "timer.hpp"
  15 +
  16 +#include <util/manchester.hpp>
  17 +
  18 +using namespace ::dali;
  19 +
  20 +namespace dali {
  21 +namespace xmc {
  22 +
  23 +namespace {
  24 +
  25 +#define PULSE_GLITCH 500
  26 +
  27 +#define PULSE_TIME (13333)
  28 +#define PULSE_TIME_MIN (8000)
  29 +#define PULSE_TIME_MAX (18000)
  30 +
  31 +#define PULSE_TIME_SHORT_MIN PULSE_TIME_MIN
  32 +#define PULSE_TIME_SHORT_MAX PULSE_TIME_MAX
  33 +#define PULSE_TIME_LONG_MIN (PULSE_TIME_MIN * 2)
  34 +#define PULSE_TIME_LONG_MAX (PULSE_TIME_MAX * 2)
  35 +
  36 +#define INVALID32 0xffffffffL
  37 +#define INVALID16 0xffff
  38 +
  39 +enum class RxState {
  40 + IDLE, START_LOW, START_HIGHT, DATA_LOW, DATA_HIGHT, HAVE_DATA, ERROR
  41 +};
  42 +
  43 +uint8_t gRxDataBit = 0;
  44 +volatile RxState gRxState;
  45 +volatile uint32_t gRxData32 = INVALID32;
  46 +volatile uint32_t gRxDataTmp;
  47 +uint16_t gTxData = INVALID16;
  48 +volatile uint64_t gBusLowTime = 0;
  49 +
  50 +#define BUS_TIME_CONNECTED 0xffffffffffffffffUL
  51 +
  52 +#define MAX_CLIENTS 1
  53 +
  54 +IBus::IBusState gBusState = IBus::IBusState::UNKNOWN;
  55 +IBus::IBusClient* gClients[MAX_CLIENTS];
  56 +
  57 +void onRisingEdge(uint16_t timer) {
  58 + gBusLowTime = BUS_TIME_CONNECTED;
  59 +
  60 + if (timer == 0) {
  61 + return;
  62 + }
  63 +
  64 + if (timer <= PULSE_GLITCH) {
  65 + return;
  66 + }
  67 +
  68 + bool longPulse;
  69 + if ((timer >= PULSE_TIME_SHORT_MIN) && (timer <= PULSE_TIME_SHORT_MAX)) {
  70 + longPulse = false;
  71 + } else if ((timer >= PULSE_TIME_LONG_MIN) && (timer <= PULSE_TIME_LONG_MAX)) {
  72 + longPulse = true;
  73 + } else {
  74 + gRxState = RxState::ERROR;
  75 + return;
  76 + }
  77 +
  78 + switch (gRxState) {
  79 + case RxState::START_LOW: // 2: check first half of start bit
  80 + if (longPulse) {
  81 + gRxState = RxState::ERROR;
  82 + return;
  83 + }
  84 + gRxState = RxState::START_HIGHT;
  85 + return;
  86 +
  87 + case RxState::DATA_LOW:
  88 + gRxState = RxState::DATA_HIGHT;
  89 + if (longPulse) {
  90 + gRxDataBit += 2;
  91 + gRxDataTmp <<= 2;
  92 + } else {
  93 + gRxDataBit += 1;
  94 + gRxDataTmp <<= 1;
  95 + }
  96 + return;
  97 +
  98 + default:
  99 + return;
  100 + }
  101 +}
  102 +
  103 +void onFallingEdge(uint16_t timer) {
  104 + gBusLowTime = Timer::getTimeMs();
  105 +
  106 + if (timer == 0) {
  107 + gRxState = RxState::START_LOW;
  108 + return;
  109 + }
  110 +
  111 + if (timer <= PULSE_GLITCH) {
  112 + return;
  113 + }
  114 +
  115 + bool longPulse;
  116 + if ((timer >= PULSE_TIME_SHORT_MIN) && (timer <= PULSE_TIME_SHORT_MAX)) {
  117 + longPulse = false;
  118 + } else if ((timer >= PULSE_TIME_LONG_MIN) && (timer <= PULSE_TIME_LONG_MAX)) {
  119 + longPulse = true;
  120 + } else {
  121 + gRxState = RxState::ERROR;
  122 + return;
  123 + }
  124 +
  125 + switch (gRxState) {
  126 + case RxState::START_HIGHT:
  127 + gRxState = RxState::DATA_LOW;
  128 + if (longPulse) {
  129 + gRxDataBit = 1;
  130 + gRxDataTmp = 1;
  131 + } else {
  132 + gRxDataBit = 0;
  133 + gRxDataTmp = 0;
  134 + }
  135 + return;
  136 +
  137 + case RxState::DATA_HIGHT:
  138 + gRxState = RxState::DATA_LOW;
  139 + if (longPulse) {
  140 + gRxDataBit += 2;
  141 + gRxDataTmp <<= 2;
  142 + gRxDataTmp |= 3;
  143 + } else {
  144 + gRxDataBit += 1;
  145 + gRxDataTmp <<= 1;
  146 + gRxDataTmp |= 1;
  147 + }
  148 + return;
  149 +
  150 + default:
  151 + return;
  152 + }
  153 +}
  154 +
  155 +void onTimeOut() {
  156 + if (gRxState == RxState::ERROR) {
  157 + gRxDataBit = -1; // prevent unexpected data
  158 + }
  159 +
  160 + gRxState = RxState::IDLE;
  161 + gRxData32 = INVALID32;
  162 +
  163 + switch (gRxDataBit) {
  164 + case 32:
  165 + gRxData32 = gRxDataTmp;
  166 + break;
  167 +
  168 + case 32 - 1:
  169 + gRxData32 = gRxDataTmp;
  170 + gRxData32 <<= 1;
  171 + gRxData32 |= 1;
  172 + break;
  173 + }
  174 +}
  175 +
  176 +} // namespace
  177 +
  178 +//static
  179 +Bus* Bus::getInstance() {
  180 + static Bus gBus;
  181 + return &gBus;
  182 +}
  183 +
  184 +Bus::Bus() {
  185 + Bus::initRx();
  186 + Bus::initTx();
  187 +}
  188 +
  189 +Bus::~Bus() {
  190 +// TODO clean up
  191 +}
  192 +
  193 +Status Bus::registerClient(IBusClient* c) {
  194 + for (uint16_t i = 0; i < MAX_CLIENTS; ++i) {
  195 + if (gClients[i] == nullptr) {
  196 + gClients[i] = c;
  197 + c->onBusStateChanged(gBusState);
  198 + return Status::OK;
  199 + }
  200 + }
  201 + return Status::ERROR;
  202 +}
  203 +
  204 +Status Bus::unregisterClient(IBusClient* c) {
  205 + for (uint16_t i = 0; i < MAX_CLIENTS; ++i) {
  206 + if (gClients[i] == c) {
  207 + gClients[i] = nullptr;
  208 + return Status::OK;
  209 + }
  210 + }
  211 + return Status::ERROR;
  212 +}
  213 +
  214 +Status Bus::sendAck(uint8_t ack) {
  215 + Bus::tx(ack);
  216 + return Status::OK;
  217 +}
  218 +
  219 +void Bus::runSlice() {
  220 + uint16_t data;
  221 + uint64_t time = Timer::getTimeMs();
  222 +
  223 + __disable_irq();
  224 + uint64_t busLowTime = gBusLowTime;
  225 + __enable_irq();
  226 +
  227 + if (busLowTime == BUS_TIME_CONNECTED) {
  228 + if (gBusState != IBus::IBusState::CONNECTED) {
  229 + onBusStateChanged(IBus::IBusState::CONNECTED);
  230 + }
  231 + } else {
  232 + if (time - busLowTime >= 500) {
  233 + if (gBusState != IBus::IBusState::DISCONNECTED) {
  234 + onBusStateChanged(IBus::IBusState::DISCONNECTED);
  235 + }
  236 + }
  237 + }
  238 +
  239 + if (Bus::checkRxTx(time, &data)) {
  240 + onDataReceived(time, data);
  241 + }
  242 +}
  243 +
  244 +// static
  245 +void Bus::onDataReceived(uint64_t time, uint16_t data) {
  246 + for (uint8_t i = 0; i < MAX_CLIENTS; ++i) {
  247 + if (gClients[i] != nullptr) {
  248 + gClients[i]->onDataReceived(time, data);
  249 + }
  250 + }
  251 +}
  252 +
  253 +// static
  254 +void Bus::onBusStateChanged(IBusState state) {
  255 + gBusState = state;
  256 +
  257 + for (uint8_t i = 0; i < MAX_CLIENTS; ++i) {
  258 + if (gClients[i] != nullptr) {
  259 + gClients[i]->onBusStateChanged(state);
  260 + }
  261 + }
  262 +}
  263 +
  264 +//static
  265 +void Bus::initRx() {
  266 + XMC_GPIO_SetMode(CCU40_RX_PIN, DALI_XMC_CCU40_RX_PIN_MODE);
  267 +
  268 + XMC_CCU4_Init(CCU40, XMC_CCU4_SLICE_MCMS_ACTION_TRANSFER_PR_CR);
  269 + XMC_CCU4_StartPrescaler(CCU40);
  270 + XMC_CCU4_SetModuleClock(CCU40, XMC_CCU4_CLOCK_SCU);
  271 +
  272 + XMC_CCU4_SLICE_CaptureInit(CCU40_SLICE, &kDaliRxCCU4CaptureConfig);
  273 +
  274 + XMC_CCU4_SLICE_SetTimerPeriodMatch(CCU40_SLICE, 65535);
  275 + XMC_CCU4_EnableShadowTransfer(CCU40, CCU40_SLICE_SHADDOW_TRANSFER);
  276 +
  277 + XMC_CCU4_SLICE_Capture0Config(CCU40_SLICE, XMC_CCU4_SLICE_EVENT_0);
  278 + XMC_CCU4_SLICE_Capture1Config(CCU40_SLICE, XMC_CCU4_SLICE_EVENT_1);
  279 + XMC_CCU4_SLICE_ConfigureEvent(CCU40_SLICE, XMC_CCU4_SLICE_EVENT_0, &kDaliRxCCU4CaptureRisingConfig);
  280 + XMC_CCU4_SLICE_ConfigureEvent(CCU40_SLICE, XMC_CCU4_SLICE_EVENT_1, &kDaliRxCCU4CaptureFallingConfig);
  281 +
  282 + XMC_CCU4_SLICE_EnableEvent(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
  283 + XMC_CCU4_SLICE_EnableEvent(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_EVENT0);
  284 + XMC_CCU4_SLICE_EnableEvent(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_EVENT1);
  285 +
  286 + XMC_CCU4_SLICE_SetInterruptNode(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH, XMC_CCU4_SLICE_SR_ID_1);
  287 + XMC_CCU4_SLICE_SetInterruptNode(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_EVENT0, XMC_CCU4_SLICE_SR_ID_2);
  288 + XMC_CCU4_SLICE_SetInterruptNode(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_EVENT1, XMC_CCU4_SLICE_SR_ID_3);
  289 +
  290 + NVIC_SetPriority(CCU40_1_IRQn, 2);
  291 + NVIC_SetPriority(CCU40_2_IRQn, 3);
  292 + NVIC_SetPriority(CCU40_3_IRQn, 3);
  293 + NVIC_EnableIRQ(CCU40_1_IRQn);
  294 + NVIC_EnableIRQ(CCU40_2_IRQn);
  295 + NVIC_EnableIRQ(CCU40_3_IRQn);
  296 +
  297 + XMC_CCU4_EnableClock(CCU40, CCU40_SLICE_NUMBER);
  298 +}
  299 +
  300 +//static
  301 +bool Bus::checkRxTx(uint64_t time, uint16_t* data) {
  302 + static uint64_t gLastDataTime = 0;
  303 + bool rxResult = false;
  304 + __disable_irq();
  305 + uint32_t rxData32 = gRxData32;
  306 + gRxData32 = INVALID32;
  307 + __enable_irq();
  308 + if (rxData32 != INVALID32) {
  309 + gLastDataTime = time;
  310 +
  311 + *data = manchesterDecode32(rxData32);
  312 + rxResult = true;
  313 + }
  314 +
  315 + if (gTxData != INVALID16) {
  316 + uint64_t dTime = time - gLastDataTime;
  317 + if (dTime > 3) {
  318 + if (gRxState == RxState::IDLE) {
  319 + uint16_t tmpTxData = gTxData;
  320 + gTxData = INVALID16;
  321 + uint32_t txData = manchesterEncode16Inv(tmpTxData);
  322 + txData <<= 1;
  323 + txData |= 0x01;
  324 + XMC_UART_CH_Transmit(DALI_UART_CH, (uint16_t) (txData & 0xffff));
  325 + XMC_UART_CH_Transmit(DALI_UART_CH, (uint16_t) (txData >> 16));
  326 + } else {
  327 + gTxData = INVALID16;
  328 + }
  329 + }
  330 + }
  331 + return rxResult;
  332 +}
  333 +
  334 +// static
  335 +void Bus::initTx() {
  336 + XMC_UART_CH_Init(DALI_UART_CH, &kDaliTxUARTConfig);
  337 + XMC_USIC_CH_TXFIFO_Configure(DALI_UART_CH, 0, XMC_USIC_CH_FIFO_DISABLED, 0);
  338 + XMC_UART_CH_Start(DALI_UART_CH);
  339 + XMC_GPIO_SetMode(DALI_UART_TX_PIN, DALI_UART_TX_PIN_MODE);
  340 +}
  341 +
  342 +// static
  343 +void Bus::tx(uint8_t data) {
  344 + if (gTxData == INVALID16) {
  345 + gTxData = data;
  346 + }
  347 +}
  348 +
  349 +extern "C" {
  350 +
  351 +void CCU40_1_IRQHandler(void) {
  352 + XMC_CCU4_SLICE_ClearEvent(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);
  353 + onTimeOut();
  354 +}
  355 +
  356 +void CCU40_2_IRQHandler(void) {
  357 + uint32_t time0 = XMC_CCU4_SLICE_GetCaptureRegisterValue(CCU40_SLICE, 0);
  358 + uint32_t time1 = XMC_CCU4_SLICE_GetCaptureRegisterValue(CCU40_SLICE, 1);
  359 + XMC_CCU4_SLICE_ClearEvent(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_EVENT0);
  360 + XMC_CCU4_SLICE_StartTimer(CCU40_SLICE);
  361 + if (time0 & CCU4_CC4_CV_FFL_Msk) {
  362 + onRisingEdge(time0 & CCU4_CC4_CV_CAPTV_Msk);
  363 + } else if (time1 & CCU4_CC4_CV_FFL_Msk) {
  364 + onRisingEdge(time1 & CCU4_CC4_CV_CAPTV_Msk);
  365 + }
  366 +}
  367 +
  368 +void CCU40_3_IRQHandler(void) {
  369 + uint32_t time0 = XMC_CCU4_SLICE_GetCaptureRegisterValue(CCU40_SLICE, 2);
  370 + uint32_t time1 = XMC_CCU4_SLICE_GetCaptureRegisterValue(CCU40_SLICE, 3);
  371 + XMC_CCU4_SLICE_ClearEvent(CCU40_SLICE, XMC_CCU4_SLICE_IRQ_ID_EVENT1);
  372 + XMC_CCU4_SLICE_StartTimer(CCU40_SLICE);
  373 + if (time0 & CCU4_CC4_CV_FFL_Msk) {
  374 + onFallingEdge(time0 & CCU4_CC4_CV_CAPTV_Msk);
  375 + } else if (time1 & CCU4_CC4_CV_FFL_Msk) {
  376 + onFallingEdge(time1 & CCU4_CC4_CV_CAPTV_Msk);
  377 + }
  378 +}
  379 +
  380 +} // extern "C"
  381 +
  382 +} // namespace xmc
  383 +} // namespace dali
  384 +
... ...
src/xmc1200/dali/bus.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_DALI_BUS_HPP_
  12 +#define XMC_DALI_BUS_HPP_
  13 +
  14 +#include <dali/dali.hpp>
  15 +
  16 +namespace dali {
  17 +namespace xmc {
  18 +
  19 +class Bus: public dali::IBus {
  20 +public:
  21 + static Bus* getInstance();
  22 +
  23 + dali::Status registerClient(IBusClient* c) override;
  24 + dali::Status unregisterClient(IBusClient* c) override;
  25 + dali::Status sendAck(uint8_t ack) override;
  26 +
  27 + static void runSlice();
  28 +
  29 +private:
  30 + Bus();
  31 + Bus(const Bus& other) = delete;
  32 + Bus& operator=(const Bus&) = delete;
  33 +
  34 + ~Bus();
  35 +
  36 + static void onDataReceived(uint64_t timeMs, uint16_t data);
  37 + static void onBusStateChanged(IBusState state);
  38 +
  39 + static void initRx();
  40 + static bool checkRxTx(uint64_t time, uint16_t* data);
  41 +
  42 + static void initTx();
  43 + static void tx(uint8_t data);
  44 +};
  45 +
  46 +} // namespace xmc
  47 +} // namespace dali
  48 +
  49 +#endif // XMC_DALI_BUS_HPP_
... ...
src/xmc1200/dali/bus_config.c 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "bus_config.h"
  12 +
  13 +const XMC_UART_CH_CONFIG_t kDaliTxUARTConfig = {
  14 + baudrate: 2400,
  15 + data_bits: 0,
  16 + frame_length: 19,
  17 + stop_bits: 2,
  18 + oversampling: 0,
  19 + parity_mode: XMC_USIC_CH_PARITY_MODE_NONE
  20 +};
  21 +
  22 +const XMC_CCU4_SLICE_EVENT_CONFIG_t kDaliRxCCU4CaptureRisingConfig = {
  23 + mapped_input: CCU40_SLICE_INPUT,
  24 + edge: XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_RISING_EDGE,
  25 + level: XMC_CCU4_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH,
  26 + duration: XMC_CCU4_SLICE_EVENT_FILTER_7_CYCLES
  27 +};
  28 +
  29 +const XMC_CCU4_SLICE_EVENT_CONFIG_t kDaliRxCCU4CaptureFallingConfig = {
  30 + mapped_input: CCU40_SLICE_INPUT,
  31 + edge: XMC_CCU4_SLICE_EVENT_EDGE_SENSITIVITY_FALLING_EDGE,
  32 + level: XMC_CCU4_SLICE_EVENT_LEVEL_SENSITIVITY_ACTIVE_HIGH,
  33 + duration: XMC_CCU4_SLICE_EVENT_FILTER_7_CYCLES
  34 +};
  35 +
  36 +const XMC_CCU4_SLICE_CAPTURE_CONFIG_t kDaliRxCCU4CaptureConfig = {
  37 + tc: (1 << CCU4_CC4_TC_CMOD_Pos) | (1 << CCU4_CC4_TC_CLST_Pos) | (3 << CCU4_CC4_TC_CAPC_Pos) | (1 << CCU4_CC4_TC_CCS_Pos) | (1 << CCU4_CC4_TC_TSSM_Pos),
  38 + prescaler_initval: 0,
  39 + float_limit: 0,
  40 + timer_concatenation: 0
  41 +};
... ...
src/xmc1200/dali/bus_config.h 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_DALI_BUS_CONFIG_H_
  12 +#define XMC_DALI_BUS_CONFIG_H_
  13 +
  14 +#include <xmc_uart.h>
  15 +#include <xmc_ccu4.h>
  16 +#include <xmc_gpio.h>
  17 +
  18 +// UART configuration - used for DALI TX
  19 +# define DALI_UART_CH XMC_USIC0_CH0
  20 +# define DALI_UART_TX_PIN_MODE XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2
  21 +# define DALI_UART_TX_PIN P1_5
  22 +
  23 +extern const XMC_UART_CH_CONFIG_t kDaliTxUARTConfig;
  24 +
  25 +// CCU4 configuration - used for DALI TX
  26 +# define CCU40_SLICE CCU40_CC42
  27 +# define CCU40_SLICE_NUMBER 2
  28 +# define CCU40_SLICE_INPUT XMC_CCU4_SLICE_INPUT_C
  29 +# define CCU40_SLICE_SHADDOW_TRANSFER XMC_CCU4_SHADOW_TRANSFER_SLICE_2
  30 +# define CCU40_RX_PIN P0_2
  31 +# define DALI_XMC_CCU40_RX_PIN_MODE XMC_GPIO_MODE_INPUT_PULL_DOWN
  32 +
  33 +extern const XMC_CCU4_SLICE_EVENT_CONFIG_t kDaliRxCCU4CaptureRisingConfig;
  34 +extern const XMC_CCU4_SLICE_EVENT_CONFIG_t kDaliRxCCU4CaptureFallingConfig;
  35 +extern const XMC_CCU4_SLICE_CAPTURE_CONFIG_t kDaliRxCCU4CaptureConfig;
  36 +
  37 +#endif // XMC_DALI_BUS_CONFIG_H_
... ...
src/xmc1200/dali/lamp.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "lamp.hpp"
  12 +
  13 +#include <xmc1200/bccu_config.h>
  14 +
  15 +using namespace xmc;
  16 +
  17 +namespace dali {
  18 +namespace xmc {
  19 +
  20 +// LED1
  21 +#define LED1_RED Bccu::CH0
  22 +#define LED1_GREEN Bccu::CH7
  23 +#define LED1_BLUE Bccu::CH8
  24 +
  25 +#define LED1_ENGINE Bccu::DE0
  26 +
  27 +// LED2
  28 +#define LED2_RED Bccu::CH1
  29 +#define LED2_GREEN Bccu::CH2
  30 +#define LED2_BLUE Bccu::CH3
  31 +
  32 +#define LED2_ENGINE Bccu::DE1
  33 +
  34 +// LED3
  35 +#define LED3_RED Bccu::CH4
  36 +#define LED3_GREEN Bccu::CH5
  37 +#define LED3_BLUE Bccu::CH6
  38 +
  39 +#define LED3_ENGINE Bccu::DE2
  40 +
  41 +//static
  42 +#define DRIVER_MAX 4096
  43 +#define DALI_MAX 65536
  44 +
  45 +inline uint16_t dali2driver(uint16_t level) {
  46 + uint32_t result = ((uint32_t) level * DRIVER_MAX + DALI_MAX / 2) / DALI_MAX;
  47 + return result < DRIVER_MAX ? result : DRIVER_MAX - 1;
  48 +}
  49 +
  50 +inline uint16_t driver2dali(uint16_t intensivity) {
  51 + uint32_t result = ((uint32_t) intensivity * DALI_MAX + DRIVER_MAX / 2) / DRIVER_MAX;
  52 + return result < DALI_MAX ? result : DALI_MAX - 1;
  53 +}
  54 +
  55 +//static
  56 +LampRGB* LampRGB::getInstance() {
  57 + static LampRGB gDaliLamp1(LED1_ENGINE, LED1_RED, LED1_GREEN, LED1_BLUE, &kLampBCCUChannelConfig);
  58 + return &gDaliLamp1;
  59 +}
  60 +
  61 +LampRGB::LampRGB(Bccu::DimmingEngine de, Bccu::Channel r, Bccu::Channel g, Bccu::Channel b, const XMC_BCCU_CH_CONFIG_t* channelConfig) :
  62 + mLamp(de, r, g, b, channelConfig, channelConfig, channelConfig), mLevel(0) {
  63 + memset(mClients, 0, sizeof(mClients));
  64 + mLamp.enable();
  65 + mLamp.setColor(DRIVER_MAX - 1, DRIVER_MAX - 1, DRIVER_MAX - 1, 0);
  66 +}
  67 +
  68 +LampRGB::~LampRGB() {
  69 + mLamp.disable();
  70 +}
  71 +
  72 +Status LampRGB::registerClient(ILampClient* c) {
  73 + for (uint16_t i = 0; i < kMaxClients; ++i) {
  74 + if (mClients[i] == nullptr) {
  75 + mClients[i] = c;
  76 + return Status::OK;
  77 + }
  78 + }
  79 + return Status::ERROR;
  80 +}
  81 +
  82 +Status LampRGB::unregisterClient(ILampClient* c) {
  83 + for (uint16_t i = 0; i < kMaxClients; ++i) {
  84 + if (mClients[i] == c) {
  85 + mClients[i] = nullptr;
  86 + return Status::OK;
  87 + }
  88 + }
  89 + return Status::ERROR;
  90 +}
  91 +
  92 +void LampRGB::setLevel(uint16_t level, uint32_t fadeTime) {
  93 + mLevel = level;
  94 + mLamp.setLevel(dali2driver(level), fadeTime);
  95 +}
  96 +
  97 +uint16_t LampRGB::getLevel() {
  98 + if (mLamp.isFading()) {
  99 + return driver2dali(mLamp.getLevel());
  100 + }
  101 + return mLevel;
  102 +}
  103 +
  104 +bool LampRGB::isFading() {
  105 + return mLamp.isFading();
  106 +}
  107 +
  108 +void LampRGB::abortFading() {
  109 + if (mLamp.isFading()) {
  110 + mLamp.abortFading();
  111 + mLevel = driver2dali(mLamp.getLevel());
  112 + }
  113 +}
  114 +
  115 +void LampRGB::waitForFade() {
  116 + while (mLamp.isFading()) {
  117 + }
  118 +}
  119 +
  120 +void LampRGB::onLampStateChnaged(ILampState state) {
  121 + for (uint16_t i = 0; i < kMaxClients; ++i) {
  122 + if (mClients[i] != nullptr) {
  123 + mClients[i]->onLampStateChnaged(state);
  124 + }
  125 + }
  126 +}
  127 +
  128 +} // namespace xmc
  129 +} // namespace dali
... ...
src/xmc1200/dali/lamp.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_DALI_LAMP_HPP_
  12 +#define XMC_DALI_LAMP_HPP_
  13 +
  14 +#include <dali/dali.hpp>
  15 +#include <xmc1200/bccu.hpp>
  16 +
  17 +namespace dali {
  18 +namespace xmc {
  19 +
  20 +class LampRGB: public dali::ILamp {
  21 +public:
  22 +
  23 + static LampRGB* getInstance();
  24 +
  25 + dali::Status registerClient(ILampClient* c) override;
  26 + dali::Status unregisterClient(ILampClient* c) override;
  27 + void setLevel(uint16_t level, uint32_t fadeTime) override;
  28 + uint16_t getLevel() override;
  29 + bool isFading() override;
  30 + void abortFading() override;
  31 + void waitForFade();
  32 +
  33 + bool isOff() {
  34 + return getLevel() == 0;
  35 + }
  36 +
  37 +private:
  38 + LampRGB(::xmc::Bccu::DimmingEngine de, ::xmc::Bccu::Channel r, ::xmc::Bccu::Channel g, ::xmc::Bccu::Channel b, const XMC_BCCU_CH_CONFIG_t* channelConfig);
  39 + LampRGB(const LampRGB&) = delete;
  40 + LampRGB& operator=(const LampRGB&) = delete;
  41 +
  42 + ~LampRGB();
  43 +
  44 + void onLampStateChnaged(ILampState state);
  45 +
  46 + static const uint8_t kMaxClients = 1;
  47 +
  48 + ILampClient* mClients[kMaxClients];
  49 + ::xmc::BccuLampRGB mLamp;
  50 + uint16_t mLevel;
  51 +};
  52 +
  53 +
  54 +} // namespace xmc
  55 +} // namespace dali
  56 +
  57 +#endif // XMC_DALI_LAMP_HPP_
... ...
src/xmc1200/dali/memory.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "memory.hpp"
  12 +
  13 +#include "memory_config.hpp"
  14 +#include "timer.hpp"
  15 +
  16 +namespace dali {
  17 +namespace xmc {
  18 +namespace {
  19 +
  20 +#define FLASH_MEMORY_OFFSET 4
  21 +#define FLASH_MEMORY_SIZE (XMC_FLASH_BYTES_PER_PAGE - FLASH_MEMORY_OFFSET)
  22 +
  23 +class FlashMemory {
  24 +public:
  25 + FlashMemory(uint32_t* pageAddrA, uint32_t* pageAddrB, size_t words) :
  26 + mPageAddrA(pageAddrA), mPageAddrB(pageAddrB), mWords(words + 1), mState(State::UINTIALIZED) {
  27 + mData = new uint32_t[mWords];
  28 + }
  29 +
  30 + ~FlashMemory() {
  31 + delete mData;
  32 + }
  33 +
  34 + size_t write(uintptr_t addr, const uint8_t* data, size_t size) {
  35 + if (mState == State::UINTIALIZED) {
  36 + return 0;
  37 + }
  38 + FlashMetaData* metaData = (FlashMetaData*) mData;
  39 + uint8_t* writeData = (uint8_t*) mData + addr + FLASH_MEMORY_OFFSET;
  40 + bool changed = false;
  41 + for (size_t i = 0; i < size; ++i, ++writeData, ++data) {
  42 + if (*writeData != *data) {
  43 + changed = true;
  44 + }
  45 + // update checksum
  46 + metaData->crc16 += *writeData;
  47 + metaData->crc16 -= *data;
  48 + // store data
  49 + *writeData = *data;
  50 + }
  51 + if (changed) {
  52 + switch (mState) {
  53 + case State::SYNCHORONIZED_A:
  54 + case State::DATA_MODIFIED_A:
  55 + mState = State::DATA_MODIFIED_A;
  56 + break;
  57 +
  58 + case State::SYNCHORONIZED_B:
  59 + case State::DATA_MODIFIED_B:
  60 + mState = State::DATA_MODIFIED_B;
  61 + break;
  62 +
  63 + default:
  64 + break;
  65 + }
  66 + }
  67 + return size;
  68 + }
  69 +
  70 + size_t read(uintptr_t addr, uint8_t* data, size_t size) {
  71 + uint8_t* readData = (uint8_t*) mData + addr + FLASH_MEMORY_OFFSET;
  72 + memcpy(data, (uint8_t*) readData, size);
  73 + return size;
  74 + }
  75 +
  76 + const uint8_t* getData(uintptr_t addr) {
  77 + return (uint8_t*) mData + addr + FLASH_MEMORY_OFFSET;
  78 + }
  79 +
  80 + void erase() {
  81 + erasePage(mPageAddrA);
  82 + erasePage(mPageAddrB);
  83 + }
  84 +
  85 + void synchronize(bool emergency) {
  86 + switch (mState) {
  87 + case State::SYNCHORONIZED_A:
  88 + case State::SYNCHORONIZED_B:
  89 + // do nothing
  90 + break;
  91 +
  92 + case State::DATA_MODIFIED_A: {
  93 + const FlashMetaData* metaDataB = (FlashMetaData*) mPageAddrB;
  94 + if (metaDataB->metaData == 0xffffffff) { // fast check erased
  95 + synchronizePages(mPageAddrB, emergency ? nullptr : mPageAddrA);
  96 + mState = State::SYNCHORONIZED_B;
  97 + } else {
  98 + const FlashMetaData* metaDataA = (FlashMetaData*) mPageAddrA;
  99 + if (metaDataA->metaData == 0xffffffff) { // fast check erased
  100 + synchronizePages(mPageAddrA, emergency ? nullptr : mPageAddrB);
  101 + mState = State::SYNCHORONIZED_A;
  102 + } else {
  103 + // retry next time
  104 + erasePage(mPageAddrB);
  105 + }
  106 + }
  107 + break;
  108 + }
  109 + case State::DATA_MODIFIED_B: {
  110 + const FlashMetaData* metaDataA = (FlashMetaData*) mPageAddrA;
  111 + if (metaDataA->metaData == 0xffffffff) { // fast check erased
  112 + synchronizePages(mPageAddrA, emergency ? nullptr : mPageAddrB);
  113 + mState = State::SYNCHORONIZED_A;
  114 + } else {
  115 + const FlashMetaData* metaDataB = (FlashMetaData*) mPageAddrB;
  116 + if (metaDataB->metaData == 0xffffffff) { // fast check erased
  117 + synchronizePages(mPageAddrB, emergency ? nullptr : mPageAddrA);
  118 + mState = State::SYNCHORONIZED_B;
  119 + } else {
  120 + // retry next time
  121 + erasePage(mPageAddrA);
  122 + }
  123 + }
  124 + break;
  125 + }
  126 + case State::UINTIALIZED:
  127 + default: {
  128 + initialize();
  129 + break;
  130 + }
  131 + } // switch (mState)
  132 + }
  133 +
  134 +private:
  135 +
  136 + enum class ReadState {
  137 + INVALID, ERASED, OK
  138 + };
  139 +
  140 + enum class State {
  141 + UINTIALIZED, SYNCHORONIZED_A, SYNCHORONIZED_B, DATA_MODIFIED_A, DATA_MODIFIED_B,
  142 + };
  143 +
  144 + typedef union {
  145 + struct {
  146 + uint32_t crc16 :16;
  147 + uint32_t index :16;
  148 + };
  149 + uint32_t metaData;
  150 + } FlashMetaData;
  151 +
  152 + void writePage(uint32_t* flash) {
  153 + const size_t blocks = mWords / (XMC_FLASH_WORDS_PER_PAGE / XMC_FLASH_BLOCKS_PER_PAGE);
  154 + uint32_t* data = mData;
  155 + FlashMetaData* metaDataA = (FlashMetaData*) data;
  156 + metaDataA->index--;
  157 + for (uint16_t j = 0; j < blocks; j++) {
  158 + __disable_irq();
  159 +
  160 + NVM->NVMPROG &= (uint16_t) (~(uint16_t) NVM_NVMPROG_ACTION_Msk);
  161 + NVM->NVMPROG |= (uint16_t) (NVM_NVMPROG_RSTVERR_Msk | NVM_NVMPROG_RSTECC_Msk);
  162 + NVM->NVMPROG |= (uint16_t) ((uint32_t) 0xa1 << NVM_NVMPROG_ACTION_Pos);
  163 +
  164 + for (uint16_t i = 0; i < XMC_FLASH_WORDS_PER_BLOCK; ++i, ++data, ++flash) {
  165 + *flash = *data;
  166 + }
  167 +
  168 + while (XMC_FLASH_IsBusy() == true) {
  169 + }
  170 +
  171 + NVM->NVMPROG &= (uint16_t) (~(uint16_t) NVM_NVMPROG_ACTION_Msk);
  172 +
  173 + __enable_irq();
  174 + }
  175 + }
  176 +
  177 + bool verifyPage(uint32_t* flash) {
  178 + uint32_t* data = mData;
  179 + for (uint16_t i = 0; i < mWords; ++i, ++data, ++flash) {
  180 + if (*flash != *data) {
  181 + return false;
  182 + }
  183 + }
  184 + return true;
  185 + }
  186 +
  187 + ReadState readPage(uint32_t* flash, uint32_t* data) {
  188 + const FlashMetaData* metaData = (FlashMetaData*) flash;
  189 + uint16_t crc16 = metaData->crc16;
  190 + *data++ = *flash++;
  191 + ReadState state = ReadState::ERASED;
  192 + for (uint16_t i = 1; i < mWords; ++i, ++data, ++flash) {
  193 + uint32_t word = *flash;
  194 + crc16 += (word >> 24) & 0xff;
  195 + crc16 += (word >> 16) & 0xff;
  196 + crc16 += (word >> 8) & 0xff;
  197 + crc16 += (word >> 0) & 0xff;
  198 + if (word != 0xffffffff) {
  199 + state = ReadState::INVALID;
  200 + }
  201 + *data = word;
  202 + }
  203 + if (crc16 == 0) {
  204 + state = ReadState::OK;
  205 + }
  206 + return state;
  207 + }
  208 +
  209 + void erasePage(uint32_t* flash) {
  210 + __disable_irq();
  211 + XMC_FLASH_ErasePage(flash);
  212 + __enable_irq();
  213 + }
  214 +
  215 + void initialize() {
  216 + uint32_t dataB[mWords];
  217 +
  218 + ReadState readStateA = readPage(mPageAddrA, mData);
  219 + ReadState readStateB = readPage(mPageAddrB, dataB);
  220 +
  221 + switch (readStateA) {
  222 + case ReadState::ERASED: {
  223 +
  224 + switch (readStateB) {
  225 + case ReadState::ERASED:
  226 + mData[0] = (0 - (0xff * (mWords - 1) * sizeof(uint32_t))) | 0xffff0000;
  227 + mState = State::SYNCHORONIZED_A;
  228 + break;
  229 +
  230 + case ReadState::INVALID:
  231 + erasePage(mPageAddrB);
  232 + mData[0] = (0 - (0xff * (mWords - 1) * sizeof(uint32_t))) | 0xffff0000;
  233 + mState = State::SYNCHORONIZED_B;
  234 + break;
  235 +
  236 + case ReadState::OK:
  237 + memcpy(mData, dataB, mWords * sizeof(uint32_t));
  238 + mData[0] |= 0xffff0000;
  239 + mState = State::SYNCHORONIZED_B;
  240 + break;
  241 + }
  242 +
  243 + break;
  244 + }
  245 +
  246 + case ReadState::OK: {
  247 +
  248 + switch (readStateB) {
  249 + case ReadState::ERASED:
  250 + mData[0] |= 0xffff0000;
  251 + mState = State::SYNCHORONIZED_A;
  252 + break;
  253 +
  254 + case ReadState::INVALID:
  255 + erasePage(mPageAddrB);
  256 + mData[0] |= 0xffff0000;
  257 + mState = State::SYNCHORONIZED_A;
  258 + break;
  259 +
  260 + case ReadState::OK: {
  261 + FlashMetaData* metaDataA = (FlashMetaData*) mData;
  262 + FlashMetaData* metaDataB = (FlashMetaData*) dataB;
  263 + if (metaDataA->index < metaDataB->index) {
  264 + erasePage(mPageAddrB);
  265 + mState = State::SYNCHORONIZED_A;
  266 + } else {
  267 + erasePage(mPageAddrA);
  268 + memcpy(mData, dataB, mWords * sizeof(uint32_t));
  269 + mState = State::SYNCHORONIZED_B;
  270 + }
  271 +
  272 + break;
  273 + }
  274 + }
  275 +
  276 + break;
  277 + }
  278 +
  279 + case ReadState::INVALID: {
  280 + erasePage(mPageAddrA);
  281 +
  282 + switch (readStateB) {
  283 + case ReadState::ERASED:
  284 + mData[0] = (0 - (0xff * (mWords - 1) * sizeof(uint32_t))) | 0xffff0000;
  285 + memset(&mData[1], 0xff, mWords * sizeof(uint32_t));
  286 + mState = State::SYNCHORONIZED_A;
  287 + break;
  288 +
  289 + case ReadState::INVALID:
  290 + erasePage(mPageAddrB);
  291 +
  292 + mData[0] = (0 - (0xff * (mWords - 1) * sizeof(uint32_t))) | 0xffff0000;
  293 + memset(&mData[1], 0xff, mWords * sizeof(uint32_t));
  294 + mState = State::SYNCHORONIZED_A;
  295 + break;
  296 +
  297 + case ReadState::OK:
  298 + memcpy(mData, dataB, mWords * sizeof(uint32_t));
  299 + mData[0] |= 0xffff0000;
  300 + mState = State::SYNCHORONIZED_B;
  301 + break;
  302 + }
  303 +
  304 + break;
  305 + }
  306 +
  307 + } // switch (readStateA)
  308 + }
  309 +
  310 + void synchronizePages(uint32_t* writePageAddr, uint32_t* erasePageAddr) {
  311 + writePage(writePageAddr);
  312 + if (verifyPage(writePageAddr)) {
  313 + if (erasePageAddr != nullptr) {
  314 + erasePage(erasePageAddr);
  315 + }
  316 + }
  317 + }
  318 +
  319 + uint32_t* const mPageAddrA;
  320 + uint32_t* const mPageAddrB;
  321 + const size_t mWords;
  322 + uint32_t* mData;
  323 + State mState;
  324 +};
  325 +
  326 +#define TEMP_SIZE 32
  327 +
  328 +FlashMemory gDataMemory((uint32_t*) (XMC_DALI_FLASH_START + XMC_DALI_FLASH_SIZE - XMC_FLASH_BYTES_PER_PAGE * 4),
  329 + (uint32_t*) (XMC_DALI_FLASH_START + XMC_DALI_FLASH_SIZE - XMC_FLASH_BYTES_PER_PAGE * 3),
  330 + FLASH_MEMORY_SIZE / sizeof(uint32_t));
  331 +} // namespace
  332 +
  333 +//static
  334 +Memory* Memory::getInstance() {
  335 + static Memory gMemory1(&gDataMemory, FLASH_MEMORY_SIZE - TEMP_SIZE, FLASH_MEMORY_SIZE - TEMP_SIZE);
  336 + return &gMemory1;
  337 +}
  338 +
  339 +Memory::Memory(void* handle, size_t dataSize, uintptr_t tempAddr) :
  340 + mHandle(handle), mTempAddr(tempAddr) {
  341 + ((FlashMemory*) handle)->synchronize(false);
  342 +}
  343 +
  344 +size_t Memory::dataSize() {
  345 + return FLASH_MEMORY_SIZE;
  346 +}
  347 +
  348 +size_t Memory::dataWrite(uintptr_t addr, const uint8_t* data, size_t size) {
  349 + if (addr + size > FLASH_MEMORY_SIZE) {
  350 + return 0;
  351 + }
  352 + return ((FlashMemory*) mHandle)->write(addr, data, size);
  353 +}
  354 +
  355 +const uint8_t* Memory::data(uintptr_t addr, size_t size) {
  356 + if (addr + size > FLASH_MEMORY_SIZE) {
  357 + return nullptr;
  358 + }
  359 + return ((FlashMemory*) mHandle)->getData(addr);
  360 +}
  361 +
  362 +size_t Memory::tempSize() {
  363 + return TEMP_SIZE;
  364 +}
  365 +
  366 +size_t Memory::tempWrite(uintptr_t addr, const uint8_t* data, size_t size) {
  367 + if (addr + size > TEMP_SIZE) {
  368 + return 0;
  369 + }
  370 + return ((FlashMemory*) mHandle)->write(mTempAddr + addr, data, size);
  371 +}
  372 +
  373 +const uint8_t* Memory::tempData(uintptr_t addr, size_t size) {
  374 + if (addr + size > TEMP_SIZE) {
  375 + return nullptr;
  376 + }
  377 + return ((FlashMemory*) mHandle)->getData(mTempAddr + addr);
  378 +}
  379 +
  380 +//static
  381 +void Memory::synchronize(bool emergency) {
  382 + gDataMemory.synchronize(emergency);
  383 +}
  384 +
  385 +//static
  386 +void Memory::erase(bool temp) {
  387 + gDataMemory.erase();
  388 +}
  389 +
  390 +}
  391 +// namespace xmc
  392 +}// namespace dali
... ...
src/xmc1200/dali/memory.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_DALI_MEMORY_H_
  12 +#define XMC_DALI_MEMORY_H_
  13 +
  14 +#include <dali/dali.hpp>
  15 +
  16 +#include <xmc_flash.h>
  17 +#include <xmc1_flash.h>
  18 +
  19 +namespace dali {
  20 +namespace xmc {
  21 +
  22 +class Memory: public dali::IMemory {
  23 +public:
  24 + static Memory* getInstance();
  25 +
  26 + size_t dataSize() override;
  27 + size_t dataWrite(uintptr_t addr, const uint8_t* data, size_t size) override;
  28 + const uint8_t* data(uintptr_t addr, size_t size) override;
  29 +
  30 + size_t tempSize() override;
  31 + size_t tempWrite(uintptr_t addr, const uint8_t* data, size_t size) override;
  32 + const uint8_t* tempData(uintptr_t addr, size_t size) override;
  33 +
  34 + static void synchronize(bool temp);
  35 + static void erase(bool temp);
  36 +
  37 +private:
  38 + Memory(void* handle, size_t dataSize, uintptr_t tempAddr);
  39 + Memory(const Memory& other) = delete;
  40 + Memory& operator=(const Memory&) = delete;
  41 +
  42 + const void* mHandle;
  43 + const uintptr_t mTempAddr;
  44 +};
  45 +
  46 +} // namespace xmc
  47 +} // namespace dali
  48 +
  49 +#endif // XMC_DALI_MEMORY_H_
... ...
src/xmc1200/dali/memory_config.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_DALI_MEMORY_CONFIG_H_
  12 +#define XMC_DALI_MEMORY_CONFIG_H_
  13 +
  14 +# define XMC_DALI_FLASH_START 0x10001000
  15 +# define XMC_DALI_FLASH_SIZE 0x32000
  16 +
  17 +#endif // XMC_DALI_MEMORY_CONFIG_H_
... ...
src/xmc1200/dali/timer.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#include "timer.hpp"
  12 +
  13 +#include <xmc_prng.h>
  14 +
  15 +namespace dali {
  16 +namespace xmc {
  17 +
  18 +namespace {
  19 +
  20 +const uint16_t* kUniqeChipId = (uint16_t*) 0x10000FF0; // 8 elements
  21 +
  22 +#define MAX_TASKS (3)
  23 +#define TICKS_PER_SECOND 1000
  24 +
  25 +typedef struct {
  26 + dali::ITimer::ITimerTask* task;
  27 + uint64_t time;
  28 + uint32_t period;
  29 +} TaskInfo;
  30 +
  31 +TaskInfo gTasks[MAX_TASKS];
  32 +volatile uint64_t gSystemTimeMs;
  33 +
  34 +}
  35 +
  36 +//static
  37 +Timer* Timer::getInstance() {
  38 + static Timer gDaliTimer;
  39 + return &gDaliTimer;
  40 +}
  41 +
  42 +Timer::Timer() {
  43 + XMC_PRNG_INIT_t prngConfig;
  44 + prngConfig.key_words[0] = kUniqeChipId[3];
  45 + prngConfig.key_words[1] = kUniqeChipId[4];
  46 + prngConfig.key_words[2] = kUniqeChipId[5];
  47 + prngConfig.key_words[3] = kUniqeChipId[6];
  48 + prngConfig.key_words[4] = kUniqeChipId[7];
  49 + prngConfig.block_size = XMC_PRNG_RDBS_WORD;
  50 + XMC_PRNG_Init(&prngConfig);
  51 +
  52 + SysTick_Config(SystemCoreClock / TICKS_PER_SECOND);
  53 +}
  54 +
  55 +Timer::~Timer() {
  56 + WR_REG(SysTick->CTRL, SysTick_CTRL_ENABLE_Msk, SysTick_CTRL_ENABLE_Pos, 0);
  57 +
  58 + XMC_PRNG_DeInit();
  59 +}
  60 +
  61 +dali::Status Timer::schedule(ITimerTask* task, uint32_t delay, uint32_t period) {
  62 + for (uint8_t i = 0; i < MAX_TASKS; ++i) {
  63 + TaskInfo* taskInfo = &gTasks[i];
  64 + if (taskInfo->task == nullptr) {
  65 + taskInfo->task = task;
  66 + taskInfo->time = gSystemTimeMs + delay;
  67 + taskInfo->period = period;
  68 + return dali::Status::OK;
  69 + }
  70 + }
  71 + return dali::Status::ERROR;
  72 +}
  73 +
  74 +void Timer::cancel(ITimerTask* task) {
  75 + for (uint8_t i = 0; i < MAX_TASKS; ++i) {
  76 + TaskInfo* taskInfo = &gTasks[i];
  77 + if (taskInfo->task == task) {
  78 + taskInfo->task = nullptr;
  79 + }
  80 + }
  81 +}
  82 +
  83 +uint32_t Timer::randomize() {
  84 + return ((uint32_t) XMC_PRNG_GetPseudoRandomNumber() << 8) + (uint32_t) gSystemTimeMs;
  85 +}
  86 +
  87 +// static
  88 +uint64_t Timer::getTimeMs() {
  89 + return gSystemTimeMs;
  90 +}
  91 +
  92 +// static
  93 +uint16_t Timer::freq() {
  94 + return TICKS_PER_SECOND;
  95 +}
  96 +
  97 +// static
  98 +void Timer::runSlice() {
  99 + for (uint8_t i = 0; i < MAX_TASKS; ++i) {
  100 + TaskInfo* taskInfo = &gTasks[i];
  101 +
  102 + if (taskInfo->task != nullptr) {
  103 + if (taskInfo->time <= gSystemTimeMs) {
  104 + taskInfo->task->timerTaskRun();
  105 + if (taskInfo->period != 0) {
  106 + taskInfo->time += taskInfo->period;
  107 + } else {
  108 + taskInfo->task = nullptr;
  109 + }
  110 + }
  111 + }
  112 + }
  113 +}
  114 +
  115 +extern "C" {
  116 +
  117 +void SysTick_Handler(void) {
  118 + gSystemTimeMs += 1000 / TICKS_PER_SECOND;
  119 +}
  120 +
  121 +} // extern "C"
  122 +
  123 +} // namespace xmc
  124 +} // namespace dali
... ...
src/xmc1200/dali/timer.hpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#ifndef XMC_DALI_TIMER_H_
  12 +#define XMC_DALI_TIMER_H_
  13 +
  14 +#include <dali/dali.hpp>
  15 +
  16 +namespace dali {
  17 +namespace xmc {
  18 +
  19 +class Timer: public dali::ITimer {
  20 +public:
  21 + static Timer* getInstance();
  22 +
  23 + uint64_t getTime() override {
  24 + return getTimeMs();
  25 + }
  26 + dali::Status schedule(ITimerTask* task, uint32_t delay, uint32_t period) override;
  27 + void cancel(ITimerTask* task) override;
  28 + uint32_t randomize() override;
  29 +
  30 + static uint64_t getTimeMs();
  31 + static uint16_t freq();
  32 + static void runSlice();
  33 +
  34 +private:
  35 + Timer();
  36 + Timer(const Timer& other) = delete;
  37 + Timer& operator=(const Timer&) = delete;
  38 +
  39 + ~Timer();
  40 +};
  41 +
  42 +} // namespace xmc
  43 +} // namespace dali
  44 +
  45 +#endif // XMC_DALI_TIMER_H_
... ...
src/xmc1200/main.cpp 0 → 100644
  1 +/*
  2 + * Copyright (c) 2015-2016, Arkadiusz Materek (arekmat@poczta.fm)
  3 + *
  4 + * Licensed under GNU General Public License 3.0 or later.
  5 + *
  6 + * This program is distributed in the hope that it will be useful,
  7 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9 + */
  10 +
  11 +#if (CPU_CLOCK == 32000000)
  12 +#define XMC_CPU_FREQ xmc::Clock::FREQ_32MHZ
  13 +#elif (CPU_CLOCK == 16000000)
  14 +#define XMC_CPU_FREQ xmc::Clock::FREQ_16MHZ
  15 +#else
  16 +#error Unsupported CPU clock
  17 +#endif
  18 +
  19 +#include <dali/slave.hpp>
  20 +
  21 +#include <xmc1200/clock.hpp>
  22 +#include <xmc1200/dali/bus.hpp>
  23 +#include <xmc1200/dali/lamp.hpp>
  24 +#include <xmc1200/dali/memory.hpp>
  25 +#include <xmc1200/dali/timer.hpp>
  26 +
  27 +#include <xmc_gpio.h>
  28 +#include <xmc_scu.h>
  29 +
  30 +dali::Slave* gSlave;
  31 +
  32 +void waitForInterrupt() {
  33 + __WFI();
  34 +}
  35 +
  36 +void initPowerDetector() {
  37 + XMC_SCU_SUPPLYMONITOR_t config;
  38 + config.ext_supply_threshold = 0b10;
  39 + config.ext_supply_monitor_speed = 0b00;
  40 + config.enable_prewarning_int = true;
  41 + config.enable_vdrop_int = false;
  42 + config.enable_vclip_int = false;
  43 + config.enable_at_init = true;
  44 +
  45 + XMC_SCU_SupplyMonitorInit(&config);
  46 + NVIC_EnableIRQ(SCU_1_IRQn);
  47 +}
  48 +
  49 +void onPowerUp() {
  50 + gSlave->notifyPowerUp();
  51 +}
  52 +
  53 +void onPowerDown() {
  54 + gSlave->notifyPowerDown();
  55 + dali::xmc::Memory::synchronize(true);
  56 +}
  57 +
  58 +class PowerOnTimerTask: public dali::ITimer::ITimerTask {
  59 +public:
  60 +
  61 + void timerTaskRun() override {
  62 + onPowerUp();
  63 + }
  64 +};
  65 +
  66 +PowerOnTimerTask gPowerOnTimerTask;
  67 +
  68 +volatile bool gEmergencyMemorySynchronise;
  69 +
  70 +int main(void) {
  71 + xmc::Clock::init(XMC_CPU_FREQ);
  72 +
  73 +
  74 + initPowerDetector();
  75 +
  76 + dali::xmc::Timer* daliTimer = dali::xmc::Timer::getInstance();
  77 + dali::xmc::Bus* daliBus = dali::xmc::Bus::getInstance();
  78 +
  79 + dali::xmc::Memory* daliMemory1 = dali::xmc::Memory::getInstance();
  80 + dali::xmc::LampRGB* daliLamp1 = dali::xmc::LampRGB::getInstance();
  81 + gSlave = dali::Slave::create(daliMemory1, daliLamp1, daliBus, daliTimer);
  82 +
  83 + daliTimer->schedule(&gPowerOnTimerTask, 600, 0);
  84 +
  85 + XMC_GPIO_SetMode(XMC_GPIO_PORT0, 0, XMC_GPIO_MODE_OUTPUT_PUSH_PULL);
  86 + XMC_GPIO_SetOutputHigh(XMC_GPIO_PORT0, 0);
  87 +
  88 + while (true) {
  89 + waitForInterrupt(); // Interrupts are triggered by SysTick 1kHz and from CCU4 (DALI RX) up to 2,4Khz
  90 + if (gEmergencyMemorySynchronise) {
  91 + gEmergencyMemorySynchronise = false;
  92 + onPowerDown();
  93 + }
  94 + dali::xmc::Timer::runSlice();
  95 + dali::xmc::Bus::runSlice();
  96 + }
  97 + return 0;
  98 +}
  99 +
  100 +extern "C" {
  101 +
  102 +void HardFault_Handler(void) {
  103 + XMC_SCU_RESET_AssertMasterReset();
  104 +}
  105 +
  106 +void SCU_1_IRQHandler(void) {
  107 + if (SCU_INTERRUPT->SRRAW & SCU_INTERRUPT_SRRAW_VDDPI_Msk) {
  108 + SCU_INTERRUPT->SRCLR = SCU_INTERRUPT_SRCLR_VDDPI_Msk;
  109 + gEmergencyMemorySynchronise = true;
  110 + }
  111 +}
  112 +
  113 +} // extern "C"
  114 +
... ...
src/xmc1200/startup_XMC1200.S 0 → 100644
  1 +/******************************************************************************
  2 + * @file startup_XMC1200.s
  3 + * @brief CMSIS Core Device Startup File for
  4 + * Infineon XMC1200 Device Series
  5 + * @version V1.13
  6 + * @date Dec 2014
  7 + *
  8 + * Copyright (C) 2014 Infineon Technologies AG. All rights reserved.
  9 + *
  10 + *
  11 + * @par
  12 + * Infineon Technologies AG (Infineon) is supplying this software for use with
  13 + * Infineon's microcontrollers. This file can be freely distributed
  14 + * within development tools that are supporting such microcontrollers.
  15 + *
  16 + * @par
  17 + * THIS SOFTWARE IS PROVIDED AS IS. NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  18 + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  19 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  20 + * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  21 + * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  22 + *
  23 + ******************************************************************************/
  24 +
  25 +/********************** Version History ***************************************
  26 + * V1.0, Oct, 02, 2012 PKB:Startup file for XMC1
  27 + * V1.1, Oct, 19, 2012 PKB:ERU and MATH interrupt handlers
  28 + * V1.2, Nov, 02, 2012 PKB:Renamed AllowPLLInitByStartup to AllowClkInitByStartup
  29 + * V1.3, Dec, 11, 2012 PKB:Attributes of .XmcVeneerCode section changed
  30 + * V1.4, Dec, 13, 2012 PKB:Removed unwanted interrupts/veneers
  31 + * V1.5, Jan, 26, 2013 PKB:Corrected the SSW related entries
  32 + * V1.6, Feb, 13, 2013 PKB:Relative path to Device_Data.h
  33 + * V1.7, Feb, 19, 2013 PKB:Included XMC1100_SCU.inc
  34 + * V1.8, Jan, 24, 2014 PKB:Removed AllowClkInitStartup and DAVE Extended init
  35 + * V1.9, Feb, 05, 2014 PKB:Removed redundant alignment code from copy+clear funcs
  36 + * V1.10, Feb, 14, 2014 PKB:Added software_init_hook and hardware_init_hook
  37 + * V1.11, May, 06, 2014 JFT:__COPY_FLASH2RAM to initialize ram
  38 + * Added ram_code section initialization
  39 + * V1.12, Sep, 29, 2014 JFT:One single default handler
  40 + * Device_Data.h not included, user may use CLKVAL1_SSW
  41 + * and CLKVAL2_SSW.
  42 + * software_init_hook and hardware_init_hook removed
  43 + * Misc optimizations
  44 + * V1.13, Dec, 11,2014 JFT:Default clocking changed, MCLK=32MHz and PCLK=64MHz
  45 + ******************************************************************************/
  46 +
  47 +/*****************************************************************************
  48 + * <h> Clock system handling by SSW
  49 + * <h> CLK_VAL1 Configuration
  50 + * <o0.0..7> FDIV Fractional Divider Selection
  51 + * <o0.8..15> IDIV Divider Selection (limited to 1-16)
  52 + * <0=> Divider is bypassed
  53 + * <1=> MCLK = 32 MHz
  54 + * <2=> MCLK = 16 MHz
  55 + * <3=> MCLK = 10.67 MHz
  56 + * <4=> MCLK = 8 MHz
  57 + * <254=> MCLK = 126 kHz
  58 + * <255=> MCLK = 125.5 kHz
  59 + * <o0.16> PCLKSEL PCLK Clock Select
  60 + * <0=> PCLK = MCLK
  61 + * <1=> PCLK = 2 x MCLK
  62 + * <o0.17..19> RTCCLKSEL RTC Clock Select
  63 + * <0=> 32.768kHz standby clock
  64 + * <1=> 32.768kHz external clock from ERU0.IOUT0
  65 + * <2=> 32.768kHz external clock from ACMP0.OUT
  66 + * <3=> 32.768kHz external clock from ACMP1.OUT
  67 + * <4=> 32.768kHz external clock from ACMP2.OUT
  68 + * <5=> Reserved
  69 + * <6=> Reserved
  70 + * <7=> Reserved
  71 + * <o0.31> do not move CLK_VAL1 to SCU_CLKCR[0..19]
  72 + * </h>
  73 + *****************************************************************************/
  74 +#define CLKVAL1_SSW 0x00010100
  75 +
  76 +/*****************************************************************************
  77 + * <h> CLK_VAL2 Configuration
  78 + * <o0.0> disable VADC and SHS Gating
  79 + * <o0.1> disable CCU80 Gating
  80 + * <o0.2> disable CCU40 Gating
  81 + * <o0.3> disable USIC0 Gating
  82 + * <o0.4> disable BCCU0 Gating
  83 + * <o0.5> disable LEDTS0 Gating
  84 + * <o0.6> disable LEDTS1 Gating
  85 + * <o0.7> disable POSIF0 Gating
  86 + * <o0.8> disable MATH Gating
  87 + * <o0.9> disable WDT Gating
  88 + * <o0.10> disable RTC Gating
  89 + * <o0.31> do not move CLK_VAL2 to SCU_CGATCLR0[0..10]
  90 + * </h>
  91 + *****************************************************************************/
  92 +#define CLKVAL2_SSW 0x80000000
  93 +
  94 +/* A macro to define vector table entries */
  95 +.macro Entry Handler
  96 + .long \Handler
  97 +.endm
  98 +
  99 +/* A couple of macros to ease definition of the various handlers */
  100 +.macro Insert_ExceptionHandler Handler_Func
  101 + .weak \Handler_Func
  102 + .thumb_set \Handler_Func, Default_handler
  103 +.endm
  104 +
  105 +/* ================== START OF VECTOR TABLE DEFINITION ====================== */
  106 +/* Vector Table - This is indirectly branched to through the veneers */
  107 + .syntax unified
  108 + .cpu cortex-m0
  109 +
  110 + .section ".reset"
  111 +
  112 + .align 2
  113 +
  114 + .globl __Vectors
  115 + .type __Vectors, %object
  116 +__Vectors:
  117 + .long __initial_sp /* Top of Stack */
  118 + .long Reset_Handler /* Reset Handler */
  119 +/*
  120 + * All entries below are redundant for M0, but are retained because they can
  121 + * in the future be directly ported to M0 Plus devices.
  122 + */
  123 + .long 0 /* Reserved */
  124 + Entry HardFault_Handler /* Hard Fault Handler */
  125 + .long CLKVAL1_SSW /* Reserved */
  126 + .long CLKVAL2_SSW /* Reserved */
  127 +#ifdef RETAIN_VECTOR_TABLE
  128 + .long 0 /* Reserved */
  129 + .long 0 /* Reserved */
  130 + .long 0 /* Reserved */
  131 + .long 0 /* Reserved */
  132 + .long 0 /* Reserved */
  133 + Entry SVC_Handler /* SVCall Handler */
  134 + .long 0 /* Reserved */
  135 + .long 0 /* Reserved */
  136 + Entry PendSV_Handler /* PendSV Handler */
  137 + Entry SysTick_Handler /* SysTick Handler */
  138 +
  139 + /* Interrupt Handlers for Service Requests (SR) from XMC1200 Peripherals */
  140 + Entry SCU_0_IRQHandler /* Handler name for SR SCU_0 */
  141 + Entry SCU_1_IRQHandler /* Handler name for SR SCU_1 */
  142 + Entry SCU_2_IRQHandler /* Handler name for SR SCU_2 */
  143 + Entry ERU0_0_IRQHandler /* Handler name for SR ERU0_0 */
  144 + Entry ERU0_1_IRQHandler /* Handler name for SR ERU0_1 */
  145 + Entry ERU0_2_IRQHandler /* Handler name for SR ERU0_2 */
  146 + Entry ERU0_3_IRQHandler /* Handler name for SR ERU0_3 */
  147 + .long 0 /* Not Available */
  148 + .long 0 /* Not Available */
  149 + Entry USIC0_0_IRQHandler /* Handler name for SR USIC0_0 */
  150 + Entry USIC0_1_IRQHandler /* Handler name for SR USIC0_1 */
  151 + Entry USIC0_2_IRQHandler /* Handler name for SR USIC0_2 */
  152 + Entry USIC0_3_IRQHandler /* Handler name for SR USIC0_3 */
  153 + Entry USIC0_4_IRQHandler /* Handler name for SR USIC0_4 */
  154 + Entry USIC0_5_IRQHandler /* Handler name for SR USIC0_5 */
  155 + Entry VADC0_C0_0_IRQHandler /* Handler name for SR VADC0_C0_0 */
  156 + Entry VADC0_C0_1_IRQHandler /* Handler name for SR VADC0_C0_1 */
  157 + Entry VADC0_G0_0_IRQHandler /* Handler name for SR VADC0_G0_0 */
  158 + Entry VADC0_G0_1_IRQHandler /* Handler name for SR VADC0_G0_1 */
  159 + Entry VADC0_G1_0_IRQHandler /* Handler name for SR VADC0_G1_0 */
  160 + Entry VADC0_G1_1_IRQHandler /* Handler name for SR VADC0_G1_1 */
  161 + Entry CCU40_0_IRQHandler /* Handler name for SR CCU40_0 */
  162 + Entry CCU40_1_IRQHandler /* Handler name for SR CCU40_1 */
  163 + Entry CCU40_2_IRQHandler /* Handler name for SR CCU40_2 */
  164 + Entry CCU40_3_IRQHandler /* Handler name for SR CCU40_3 */
  165 + .long 0 /* Not Available */
  166 + .long 0 /* Not Available */
  167 + .long 0 /* Not Available */
  168 + .long 0 /* Not Available */
  169 + Entry LEDTS0_0_IRQHandler /* Handler name for SR LEDTS0_0 */
  170 + Entry LEDTS1_0_IRQHandler /* Handler name for SR LEDTS1_0 */
  171 + Entry BCCU0_0_IRQHandler /* Handler name for SR BCCU0_0 */
  172 +#endif
  173 +
  174 + .size __Vectors, . - __Vectors
  175 +/* ================== END OF VECTOR TABLE DEFINITION ======================= */
  176 +
  177 +/* ================== START OF VECTOR ROUTINES ============================= */
  178 +
  179 + .thumb
  180 + .align 1
  181 +
  182 +/* Reset Handler */
  183 + .thumb_func
  184 + .globl Reset_Handler
  185 + .type Reset_Handler, %function
  186 +Reset_Handler:
  187 +/* Initialize interrupt veneer */
  188 + ldr r1, =eROData
  189 + ldr r2, =VeneerStart
  190 + ldr r3, =VeneerEnd
  191 + bl __copy_data
  192 +
  193 + ldr r0, =SystemInit
  194 + blx r0
  195 +
  196 +/* Initialize data */
  197 + ldr r1, =DataLoadAddr
  198 + ldr r2, =__data_start
  199 + ldr r3, =__data_end
  200 + bl __copy_data
  201 +
  202 +/* RAM code */
  203 + ldr r1, =__ram_code_load
  204 + ldr r2, =__ram_code_start
  205 + ldr r3, =__ram_code_end
  206 + bl __copy_data
  207 +
  208 +/* Define __SKIP_BSS_CLEAR to disable zeroing uninitialzed data in startup.
  209 + * The BSS section is specified by following symbols
  210 + * __bss_start__: start of the BSS section.
  211 + * __bss_end__: end of the BSS section.
  212 + *
  213 + * Both addresses must be aligned to 4 bytes boundary.
  214 + */
  215 +#ifndef __SKIP_BSS_CLEAR
  216 + ldr r1, =__bss_start
  217 + ldr r2, =__bss_end
  218 +
  219 + movs r0, 0
  220 +
  221 + subs r2, r1
  222 + ble .L_loop3_done
  223 +
  224 +.L_loop3:
  225 + subs r2, #4
  226 + str r0, [r1, r2]
  227 + bgt .L_loop3
  228 +.L_loop3_done:
  229 +#endif /* __SKIP_BSS_CLEAR */
  230 +
  231 +#ifndef __SKIP_LIBC_INIT_ARRAY
  232 + ldr r0, =__libc_init_array
  233 + blx r0
  234 +#endif
  235 +
  236 + ldr r0, =main
  237 + blx r0
  238 +
  239 + .thumb_func
  240 + .type __copy_data, %function
  241 +__copy_data:
  242 +/* The ranges of copy from/to are specified by following symbols
  243 + * r1: start of the section to copy from.
  244 + * r2: start of the section to copy to
  245 + * r3: end of the section to copy to
  246 + *
  247 + * All addresses must be aligned to 4 bytes boundary.
  248 + * Uses r0
  249 + */
  250 + subs r3, r2
  251 + ble .L_loop_done
  252 +
  253 +.L_loop:
  254 + subs r3, #4
  255 + ldr r0, [r1,r3]
  256 + str r0, [r2,r3]
  257 + bgt .L_loop
  258 +
  259 +.L_loop_done:
  260 + bx lr
  261 +
  262 + .pool
  263 + .size Reset_Handler,.-Reset_Handler
  264 +/* ======================================================================== */
  265 +/* ========== START OF EXCEPTION HANDLER DEFINITION ======================== */
  266 +
  267 + .align 1
  268 +
  269 + .thumb_func
  270 + .weak Default_handler
  271 + .type Default_handler, %function
  272 +Default_handler:
  273 + b .
  274 + .size Default_handler, . - Default_handler
  275 +
  276 + Insert_ExceptionHandler HardFault_Handler
  277 + Insert_ExceptionHandler SVC_Handler
  278 + Insert_ExceptionHandler PendSV_Handler
  279 + Insert_ExceptionHandler SysTick_Handler
  280 +
  281 + Insert_ExceptionHandler SCU_0_IRQHandler
  282 + Insert_ExceptionHandler SCU_1_IRQHandler
  283 + Insert_ExceptionHandler SCU_2_IRQHandler
  284 + Insert_ExceptionHandler ERU0_0_IRQHandler
  285 + Insert_ExceptionHandler ERU0_1_IRQHandler
  286 + Insert_ExceptionHandler ERU0_2_IRQHandler
  287 + Insert_ExceptionHandler ERU0_3_IRQHandler
  288 + Insert_ExceptionHandler VADC0_C0_0_IRQHandler
  289 + Insert_ExceptionHandler VADC0_C0_1_IRQHandler
  290 + Insert_ExceptionHandler VADC0_G0_0_IRQHandler
  291 + Insert_ExceptionHandler VADC0_G0_1_IRQHandler
  292 + Insert_ExceptionHandler VADC0_G1_0_IRQHandler
  293 + Insert_ExceptionHandler VADC0_G1_1_IRQHandler
  294 + Insert_ExceptionHandler CCU40_0_IRQHandler
  295 + Insert_ExceptionHandler CCU40_1_IRQHandler
  296 + Insert_ExceptionHandler CCU40_2_IRQHandler
  297 + Insert_ExceptionHandler CCU40_3_IRQHandler
  298 + Insert_ExceptionHandler USIC0_0_IRQHandler
  299 + Insert_ExceptionHandler USIC0_1_IRQHandler
  300 + Insert_ExceptionHandler USIC0_2_IRQHandler
  301 + Insert_ExceptionHandler USIC0_3_IRQHandler
  302 + Insert_ExceptionHandler USIC0_4_IRQHandler
  303 + Insert_ExceptionHandler USIC0_5_IRQHandler
  304 + Insert_ExceptionHandler LEDTS0_0_IRQHandler
  305 + Insert_ExceptionHandler LEDTS1_0_IRQHandler
  306 + Insert_ExceptionHandler BCCU0_0_IRQHandler
  307 +
  308 +/* ======================================================================== */
  309 +
  310 +/* ==================VENEERS VENEERS VENEERS VENEERS VENEERS=============== */
  311 + .section ".XmcVeneerCode","ax",%progbits
  312 +
  313 + .align 1
  314 +
  315 + .globl HardFault_Veneer
  316 +HardFault_Veneer:
  317 + LDR R0, =HardFault_Handler
  318 + MOV PC,R0
  319 + .long 0
  320 + .long 0
  321 + .long 0
  322 + .long 0
  323 + .long 0
  324 + .long 0
  325 + .long 0
  326 +/* ======================================================================== */
  327 + .globl SVC_Veneer
  328 +SVC_Veneer:
  329 + LDR R0, =SVC_Handler
  330 + MOV PC,R0
  331 + .long 0
  332 + .long 0
  333 +/* ======================================================================== */
  334 + .globl PendSV_Veneer
  335 +PendSV_Veneer:
  336 + LDR R0, =PendSV_Handler
  337 + MOV PC,R0
  338 +/* ======================================================================== */
  339 + .globl SysTick_Veneer
  340 +SysTick_Veneer:
  341 + LDR R0, =SysTick_Handler
  342 + MOV PC,R0
  343 +/* ======================================================================== */
  344 + .globl SCU_0_Veneer
  345 +SCU_0_Veneer:
  346 + LDR R0, =SCU_0_IRQHandler
  347 + MOV PC,R0
  348 +/* ======================================================================== */
  349 + .globl SCU_1_Veneer
  350 +SCU_1_Veneer:
  351 + LDR R0, =SCU_1_IRQHandler
  352 + MOV PC,R0
  353 +/* ======================================================================== */
  354 + .globl SCU_2_Veneer
  355 +SCU_2_Veneer:
  356 + LDR R0, =SCU_2_IRQHandler
  357 + MOV PC,R0
  358 +/* ======================================================================== */
  359 + .globl SCU_3_Veneer
  360 +SCU_3_Veneer:
  361 + LDR R0, =ERU0_0_IRQHandler
  362 + MOV PC,R0
  363 +/* ======================================================================== */
  364 + .globl SCU_4_Veneer
  365 +SCU_4_Veneer:
  366 + LDR R0, =ERU0_1_IRQHandler
  367 + MOV PC,R0
  368 +/* ======================================================================== */
  369 + .globl SCU_5_Veneer
  370 +SCU_5_Veneer:
  371 + LDR R0, =ERU0_2_IRQHandler
  372 + MOV PC,R0
  373 +/* ======================================================================== */
  374 + .globl SCU_6_Veneer
  375 +SCU_6_Veneer:
  376 + LDR R0, =ERU0_3_IRQHandler
  377 + MOV PC,R0
  378 + .long 0
  379 + .long 0
  380 +/* ======================================================================== */
  381 + .globl USIC0_0_Veneer
  382 +USIC0_0_Veneer:
  383 + LDR R0, =USIC0_0_IRQHandler
  384 + MOV PC,R0
  385 +/* ======================================================================== */
  386 + .globl USIC0_1_Veneer
  387 +USIC0_1_Veneer:
  388 + LDR R0, =USIC0_1_IRQHandler
  389 + MOV PC,R0
  390 +/* ======================================================================== */
  391 + .globl USIC0_2_Veneer
  392 +USIC0_2_Veneer:
  393 + LDR R0, =USIC0_2_IRQHandler
  394 + MOV PC,R0
  395 +/* ======================================================================== */
  396 + .globl USIC0_3_Veneer
  397 +USIC0_3_Veneer:
  398 + LDR R0, =USIC0_3_IRQHandler
  399 + MOV PC,R0
  400 +/* ======================================================================== */
  401 + .globl USIC0_4_Veneer
  402 +USIC0_4_Veneer:
  403 + LDR R0, =USIC0_4_IRQHandler
  404 + MOV PC,R0
  405 +/* ======================================================================== */
  406 + .globl USIC0_5_Veneer
  407 +USIC0_5_Veneer:
  408 + LDR R0, =USIC0_5_IRQHandler
  409 + MOV PC,R0
  410 +/* ======================================================================== */
  411 + .globl VADC0_C0_0_Veneer
  412 +VADC0_C0_0_Veneer:
  413 + LDR R0, =VADC0_C0_0_IRQHandler
  414 + MOV PC,R0
  415 +/* ======================================================================== */
  416 + .globl VADC0_C0_1_Veneer
  417 +VADC0_C0_1_Veneer:
  418 + LDR R0, =VADC0_C0_1_IRQHandler
  419 + MOV PC,R0
  420 +/* ======================================================================== */
  421 + .globl VADC0_G0_0_Veneer
  422 +VADC0_G0_0_Veneer:
  423 + LDR R0, =VADC0_G0_0_IRQHandler
  424 + MOV PC,R0
  425 +/* ======================================================================== */
  426 + .globl VADC0_G0_1_Veneer
  427 +VADC0_G0_1_Veneer:
  428 + LDR R0, =VADC0_G0_1_IRQHandler
  429 + MOV PC,R0
  430 +/* ======================================================================== */
  431 + .globl VADC0_G1_0_Veneer
  432 +VADC0_G1_0_Veneer:
  433 + LDR R0, =VADC0_G1_0_IRQHandler
  434 + MOV PC,R0
  435 +/* ======================================================================== */
  436 + .globl VADC0_G1_1_Veneer
  437 +VADC0_G1_1_Veneer:
  438 + LDR R0, =VADC0_G1_1_IRQHandler
  439 + MOV PC,R0
  440 +/* ======================================================================== */
  441 + .globl CCU40_0_Veneer
  442 +CCU40_0_Veneer:
  443 + LDR R0, =CCU40_0_IRQHandler
  444 + MOV PC,R0
  445 +/* ======================================================================== */
  446 + .globl CCU40_1_Veneer
  447 +CCU40_1_Veneer:
  448 + LDR R0, =CCU40_1_IRQHandler
  449 + MOV PC,R0
  450 +/* ======================================================================== */
  451 + .globl CCU40_2_Veneer
  452 +CCU40_2_Veneer:
  453 + LDR R0, =CCU40_2_IRQHandler
  454 + MOV PC,R0
  455 +/* ======================================================================== */
  456 + .globl CCU40_3_Veneer
  457 +CCU40_3_Veneer:
  458 + LDR R0, =CCU40_3_IRQHandler
  459 + MOV PC,R0
  460 + .long 0
  461 + .long 0
  462 + .long 0
  463 + .long 0
  464 +/* ======================================================================== */
  465 + .globl LEDTS0_0_Veneer
  466 +LEDTS0_0_Veneer:
  467 + LDR R0, =LEDTS0_0_IRQHandler
  468 + MOV PC,R0
  469 +/* ======================================================================== */
  470 + .globl LEDTS1_0_Veneer
  471 +LEDTS1_0_Veneer:
  472 + LDR R0, =LEDTS1_0_IRQHandler
  473 + MOV PC,R0
  474 +/* ======================================================================== */
  475 + .globl BCCU0_0_Veneer
  476 +BCCU0_0_Veneer:
  477 + LDR R0, =BCCU0_0_IRQHandler
  478 + MOV PC,R0
  479 +
  480 +/* ======================================================================== */
  481 +/* ======================================================================== */
  482 +
  483 +/* ============= END OF INTERRUPT HANDLER DEFINITION ======================== */
  484 +
  485 + .end
... ...
src/xmc1200/system_XMC1200.c 0 → 100644
  1 +/******************************************************************************
  2 + * @file system_XMC1200.c
  3 + * @brief Device specific initialization for the XMC1200-Series according
  4 + * to CMSIS
  5 + * @version V1.7
  6 + * @date 11 Dec 2014
  7 + *
  8 + * @note
  9 + * Copyright (C) 2012-2014 Infineon Technologies AG. All rights reserved.
  10 +
  11 + *
  12 + * @par
  13 + * Infineon Technologies AG (Infineon) is supplying this software for use with
  14 + * Infineon’s microcontrollers.
  15 + *
  16 + * This file can be freely distributed within development tools that are
  17 + * supporting such microcontrollers.
  18 + *
  19 + *
  20 + * @par
  21 + * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  22 + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  23 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  24 + * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
  25 + * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  26 + *
  27 + ******************************************************************************/
  28 +/*
  29 + * *************************** Change history ********************************
  30 + * V1.2, 13 Dec 2012, PKB : Created change history table
  31 + * V1.3, 20 Dec 2012, PKB : Fixed SystemCoreClock computation
  32 + * V1.4, 02 Feb 2013, PKB : SCU_CLOCK -> SCU_CLK
  33 + * V1.5, 27 Nov 2013, DNE : Comments added in SystemInit function for MCLK support
  34 + * V1.6, 19 Feb 2014, JFT : Fixed SystemCoreClock when FDIV != 0
  35 + * V1.7, 11 Dec 2014, JFT : SystemCoreClockSetup, SystemCoreSetup as weak functions
  36 + */
  37 +
  38 +/*******************************************************************************
  39 + * HEADER FILES
  40 + *******************************************************************************/
  41 +
  42 +#include <XMC1200.h>
  43 +#include "system_XMC1200.h"
  44 +
  45 +/*******************************************************************************
  46 + * MACROS
  47 + *******************************************************************************/
  48 +
  49 +/* Define WEAK attribute */
  50 +#if !defined(__WEAK)
  51 +#if defined ( __CC_ARM )
  52 +#define __WEAK __attribute__ ((weak))
  53 +#elif defined ( __ICCARM__ )
  54 +#define __WEAK __weak
  55 +#elif defined ( __GNUC__ )
  56 +#define __WEAK __attribute__ ((weak))
  57 +#elif defined ( __TASKING__ )
  58 +#define __WEAK __attribute__ ((weak))
  59 +#endif
  60 +#endif
  61 +
  62 +#define DCO1_FREQUENCY (64000000U)
  63 +
  64 +/*******************************************************************************
  65 + * GLOBAL VARIABLES
  66 + *******************************************************************************/
  67 +
  68 +#if defined ( __CC_ARM )
  69 +uint32_t SystemCoreClock __attribute__((at(0x20003FFC)));
  70 +#elif defined ( __ICCARM__ )
  71 +__no_init uint32_t SystemCoreClock;
  72 +#elif defined ( __GNUC__ )
  73 +uint32_t SystemCoreClock __attribute__((section(".no_init")));
  74 +#elif defined ( __TASKING__ )
  75 +uint32_t SystemCoreClock __at( 0x20003FFC );
  76 +#endif
  77 +
  78 +/*******************************************************************************
  79 + * API IMPLEMENTATION
  80 + *******************************************************************************/
  81 +
  82 +__WEAK void SystemInit(void)
  83 +{
  84 + SystemCoreSetup();
  85 + SystemCoreClockSetup();
  86 +}
  87 +
  88 +__WEAK void SystemCoreSetup(void)
  89 +{
  90 +}
  91 +
  92 +__WEAK void SystemCoreClockSetup(void)
  93 +{
  94 + /* Clock setup done during SSW using the CLOCK_VAL1 and CLOCK_VAL2 defined in vector table */
  95 + SystemCoreClockUpdate();
  96 +}
  97 +
  98 +__WEAK void SystemCoreClockUpdate(void)
  99 +{
  100 + static uint32_t IDIV, FDIV;
  101 +
  102 + IDIV = ((SCU_CLK->CLKCR) & SCU_CLK_CLKCR_IDIV_Msk) >> SCU_CLK_CLKCR_IDIV_Pos;
  103 + FDIV = ((SCU_CLK->CLKCR) & SCU_CLK_CLKCR_FDIV_Msk) >> SCU_CLK_CLKCR_FDIV_Pos;
  104 +
  105 + if (IDIV != 0)
  106 + {
  107 + /* Fractional divider is enabled and used */
  108 + SystemCoreClock = ((DCO1_FREQUENCY << 6U) / ((IDIV << 8) + FDIV)) << 1U;
  109 + }
  110 + else
  111 + {
  112 + /* Fractional divider bypassed. Simply divide DCO_DCLK by 2 */
  113 + SystemCoreClock = DCO1_FREQUENCY >> 1U;
  114 + }
  115 +}
... ...