Bläddra i källkod

ADC Readings implementiert

Heinrich Blatt 5 månader sedan
förälder
incheckning
138786b457

+ 1 - 1
.ccsproject

@@ -10,7 +10,7 @@
 	<ignoreDefaultCCSSettings value="true"/>
 	<templateProperties value="id=empty_mspm0l1304_nortos_ticlang.projectspec.empty_mspm0l1304_nortos_ticlang,buildProfile=release,isHybrid=true"/>
 	<activeTargetConfiguration value="targetConfigs/MSPM0L1304.ccxml"/>
-	<isTargetConfigurationManual value="false"/>
+	<isTargetConfigurationManual value="true"/>
 	<sourceLookupPath value="${COM_TI_MSPM0_SDK_INSTALL_DIR}/source/ti/driverlib"/>
 	<origin value="/home/ngosh/ti/mspm0_sdk_2_04_00_06/examples/nortos/CUSTOM_BOARD/driverlib/empty_mspm0l1304/ticlang/empty_mspm0l1304_nortos_ticlang.projectspec"/>
 	<filesToOpen value="empty_mspm0l1304.syscfg,README.md"/>

+ 34 - 34
.cproject

@@ -15,8 +15,8 @@
             <storageModule moduleId="cdtBuildSystem" version="4.0.0">
                 <configuration artifactExtension="out" artifactName="${ProjName}" buildProperties="" cleanCommand="${CG_CLEAN_CMD}" description="" id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.321921122" name="Debug" parent="com.ti.ccstudio.buildDefinitions.TMS470.Debug">
                     <folderInfo id="com.ti.ccstudio.buildDefinitions.TMS470.Debug.321921122." name="/" resourcePath="">
-                        <toolChain id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.DebugToolchain.630004681" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.DebugToolchain" targetTool="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.linkerDebug.1137492946">
-                            <option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.1652573558" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
+                        <toolChain id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.DebugToolchain.1055189967" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.DebugToolchain" targetTool="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.linkerDebug.1293255821">
+                            <option id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.463282700" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
                                 <listOptionValue value="DEVICE_CONFIGURATION_ID=Cortex M.MSPM0L1304"/>
                                 <listOptionValue value="DEVICE_CORE_ID="/>
                                 <listOptionValue value="DEVICE_ENDIANNESS=little"/>
@@ -27,17 +27,17 @@
                                 <listOptionValue value="PRODUCT_MACRO_IMPORTS={&quot;MSPM0-SDK&quot;:[&quot;${COM_TI_MSPM0_SDK_INCLUDE_PATH}&quot;,&quot;${COM_TI_MSPM0_SDK_LIBRARY_PATH}&quot;,&quot;${COM_TI_MSPM0_SDK_LIBRARIES}&quot;,&quot;${COM_TI_MSPM0_SDK_SYMBOLS}&quot;,&quot;${COM_TI_MSPM0_SDK_SYSCONFIG_MANIFEST}&quot;],&quot;sysconfig&quot;:[&quot;${SYSCONFIG_TOOL_INCLUDE_PATH}&quot;,&quot;${SYSCONFIG_TOOL_LIBRARY_PATH}&quot;,&quot;${SYSCONFIG_TOOL_LIBRARIES}&quot;,&quot;${SYSCONFIG_TOOL_SYMBOLS}&quot;,&quot;${SYSCONFIG_TOOL_SYSCONFIG_MANIFEST}&quot;]}"/>
                                 <listOptionValue value="OUTPUT_TYPE=executable"/>
                             </option>
-                            <option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.432611712" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="TICLANG_4.0.0.LTS" valueType="string"/>
-                            <targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.targetPlatformDebug.683305228" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.targetPlatformDebug"/>
-                            <builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.builderDebug.1070277094" name="GNU Make.Debug" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.builderDebug"/>
-                            <tool id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.compilerDebug.379884657" name="Arm Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.compilerDebug">
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MARCH.1225926116" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MARCH" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MARCH.thumbv6m" valueType="enumerated"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MCPU.1844740802" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MCPU" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MCPU.cortex-m0plus" valueType="enumerated"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MFLOAT_ABI.1662746020" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MFLOAT_ABI" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MFLOAT_ABI.soft" valueType="enumerated"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.ENDIAN_NESS__BIG_LITTLE.1796712665" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.ENDIAN_NESS__BIG_LITTLE" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.ENDIAN_NESS__BIG_LITTLE.MLITTLE_ENDIAN" valueType="enumerated"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.SELECT_PROCESSOR_MODE__ARM_THUMB.1203608164" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.SELECT_PROCESSOR_MODE__ARM_THUMB" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.SELECT_PROCESSOR_MODE__ARM_THUMB.MTHUMB" valueType="enumerated"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL.1051342874" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL.2" valueType="enumerated"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.INCLUDE_PATH.409563250" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.INCLUDE_PATH" valueType="includePath">
+                            <option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.1679534875" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="TICLANG_4.0.0.LTS" valueType="string"/>
+                            <targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.targetPlatformDebug.607702945" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.targetPlatformDebug"/>
+                            <builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.builderDebug.46842174" name="GNU Make.Debug" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.builderDebug"/>
+                            <tool id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.compilerDebug.352685287" name="Arm Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.compilerDebug">
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MARCH.1168360659" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MARCH" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MARCH.thumbv6m" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MCPU.57425248" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MCPU" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MCPU.cortex-m0plus" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MFLOAT_ABI.715897896" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MFLOAT_ABI" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MFLOAT_ABI.soft" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.ENDIAN_NESS__BIG_LITTLE.777806377" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.ENDIAN_NESS__BIG_LITTLE" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.ENDIAN_NESS__BIG_LITTLE.MLITTLE_ENDIAN" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.SELECT_PROCESSOR_MODE__ARM_THUMB.50635340" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.SELECT_PROCESSOR_MODE__ARM_THUMB" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.SELECT_PROCESSOR_MODE__ARM_THUMB.MTHUMB" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL.1926459268" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL.2" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.INCLUDE_PATH.1781915810" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.INCLUDE_PATH" valueType="includePath">
                                     <listOptionValue value="${COM_TI_MSPM0_SDK_INCLUDE_PATH}"/>
                                     <listOptionValue value="${SYSCONFIG_TOOL_INCLUDE_PATH}"/>
                                     <listOptionValue value="${PROJECT_ROOT}"/>
@@ -45,46 +45,46 @@
                                     <listOptionValue value="${COM_TI_MSPM0_SDK_INSTALL_DIR}/source/third_party/CMSIS/Core/Include"/>
                                     <listOptionValue value="${COM_TI_MSPM0_SDK_INSTALL_DIR}/source"/>
                                 </option>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.DEFINE.186791723" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.DEFINE" valueType="definedSymbols">
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.DEFINE.1884937961" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.DEFINE" valueType="definedSymbols">
                                     <listOptionValue value="${COM_TI_MSPM0_SDK_SYMBOLS}"/>
                                     <listOptionValue value="${SYSCONFIG_TOOL_SYMBOLS}"/>
                                 </option>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.GENERATE_DWARF_DEBUG.1460981436" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.GENERATE_DWARF_DEBUG" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.GENERATE_DWARF_DEBUG.GDWARF_3" valueType="enumerated"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.CMD_FILE.621050892" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.CMD_FILE" valueType="stringList">
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.GENERATE_DWARF_DEBUG.1091799283" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.GENERATE_DWARF_DEBUG" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.GENERATE_DWARF_DEBUG.GDWARF_3" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.CMD_FILE.1702980974" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.CMD_FILE" valueType="stringList">
                                     <listOptionValue value="syscfg/device.opt"/>
                                 </option>
                             </tool>
-                            <tool id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.linkerDebug.1137492946" name="Arm Linker" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.linkerDebug">
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.MAP_FILE.1012182218" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.MAP_FILE" value="${ProjName}.map" valueType="string"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.OUTPUT_FILE.786825655" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.OUTPUT_FILE" value="${ProjName}.out" valueType="string"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.HEAP_SIZE.1728456418" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.HEAP_SIZE" value="0x120" valueType="string"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.LIBRARY.574131281" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.LIBRARY" valueType="libs">
+                            <tool id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.linkerDebug.1293255821" name="Arm Linker" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.exe.linkerDebug">
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.MAP_FILE.1744240217" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.MAP_FILE" value="${ProjName}.map" valueType="string"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.OUTPUT_FILE.51525291" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.OUTPUT_FILE" value="${ProjName}.out" valueType="string"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.HEAP_SIZE.1250706824" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.HEAP_SIZE" value="0x120" valueType="string"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.LIBRARY.641320316" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.LIBRARY" valueType="libs">
                                     <listOptionValue value="${COM_TI_MSPM0_SDK_LIBRARIES}"/>
                                     <listOptionValue value="${SYSCONFIG_TOOL_LIBRARIES}"/>
                                     <listOptionValue value="device.cmd.genlibs"/>
                                     <listOptionValue value="libc.a"/>
                                 </option>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.SEARCH_PATH.380806143" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.SEARCH_PATH" valueType="libPaths">
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.SEARCH_PATH.1451794253" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.SEARCH_PATH" valueType="libPaths">
                                     <listOptionValue value="${COM_TI_MSPM0_SDK_LIBRARY_PATH}"/>
                                     <listOptionValue value="${SYSCONFIG_TOOL_LIBRARY_PATH}"/>
                                     <listOptionValue value="${COM_TI_MSPM0_SDK_INSTALL_DIR}/source"/>
                                     <listOptionValue value="${PROJECT_BUILD_DIR}/syscfg"/>
                                     <listOptionValue value="${CG_TOOL_ROOT}/lib"/>
                                 </option>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.REREAD_LIBS.1374713835" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.REREAD_LIBS" value="false" valueType="boolean"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DIAG_WRAP.266243495" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DIAG_WRAP" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DIAG_WRAP.off" valueType="enumerated"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DISPLAY_ERROR_NUMBER.1121404874" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DISPLAY_ERROR_NUMBER" value="true" valueType="boolean"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.VERBOSE_DIAGNOSTICS.956171569" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.VERBOSE_DIAGNOSTICS" value="true" valueType="boolean"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.ABSOLUTE_EXE.444307112" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.ABSOLUTE_EXE" value="true" valueType="boolean"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.XML_LINK_INFO.1943004326" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.XML_LINK_INFO" value="${ProjName}_linkInfo.xml" valueType="string"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.REREAD_LIBS.458324077" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.REREAD_LIBS" value="false" valueType="boolean"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DIAG_WRAP.391299250" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DIAG_WRAP" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DIAG_WRAP.off" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DISPLAY_ERROR_NUMBER.602006217" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.DISPLAY_ERROR_NUMBER" value="true" valueType="boolean"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.VERBOSE_DIAGNOSTICS.310800156" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.VERBOSE_DIAGNOSTICS" value="true" valueType="boolean"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.ABSOLUTE_EXE.1950609655" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.ABSOLUTE_EXE" value="true" valueType="boolean"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.XML_LINK_INFO.1905950867" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.linkerID.XML_LINK_INFO" value="${ProjName}_linkInfo.xml" valueType="string"/>
                             </tool>
-                            <tool id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.465545696" name="Arm Hex Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex">
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.ENTRYPOINT.947978690" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.ENTRYPOINT" value="main" valueType="string"/>
-                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.OUTPUT_FORMAT.208454576" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.OUTPUT_FORMAT" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.OUTPUT_FORMAT.TI_TXT" valueType="enumerated"/>
+                            <tool id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.1187560248" name="Arm Hex Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex">
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.ENTRYPOINT.1348684056" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.ENTRYPOINT" value="main" valueType="string"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.OUTPUT_FORMAT.1854108095" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.OUTPUT_FORMAT" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.hex.OUTPUT_FORMAT.TI_TXT" valueType="enumerated"/>
                             </tool>
-                            <tool id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.objcopy.1301045432" name="Arm Objcopy Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.objcopy"/>
-                            <tool id="com.ti.ccstudio.buildDefinitions.sysConfig.277147194" name="SysConfig" superClass="com.ti.ccstudio.buildDefinitions.sysConfig">
-                                <option id="com.ti.ccstudio.buildDefinitions.sysConfig.PRODUCTS.732286544" superClass="com.ti.ccstudio.buildDefinitions.sysConfig.PRODUCTS" valueType="stringList">
+                            <tool id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.objcopy.336752860" name="Arm Objcopy Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.objcopy"/>
+                            <tool id="com.ti.ccstudio.buildDefinitions.sysConfig.212848186" name="SysConfig" superClass="com.ti.ccstudio.buildDefinitions.sysConfig">
+                                <option id="com.ti.ccstudio.buildDefinitions.sysConfig.PRODUCTS.1276670730" superClass="com.ti.ccstudio.buildDefinitions.sysConfig.PRODUCTS" valueType="stringList">
                                     <listOptionValue value="${COM_TI_MSPM0_SDK_SYSCONFIG_MANIFEST}"/>
                                     <listOptionValue value="${SYSCONFIG_TOOL_SYSCONFIG_MANIFEST}"/>
                                 </option>

+ 2 - 0
.settings/org.eclipse.core.resources.prefs

@@ -12,6 +12,8 @@ encoding//Debug/src/peripherals/adc/subdir_rules.mk=UTF-8
 encoding//Debug/src/peripherals/adc/subdir_vars.mk=UTF-8
 encoding//Debug/src/peripherals/dac/subdir_rules.mk=UTF-8
 encoding//Debug/src/peripherals/dac/subdir_vars.mk=UTF-8
+encoding//Debug/src/peripherals/subdir_rules.mk=UTF-8
+encoding//Debug/src/peripherals/subdir_vars.mk=UTF-8
 encoding//Debug/src/peripherals/temp/subdir_rules.mk=UTF-8
 encoding//Debug/src/peripherals/temp/subdir_vars.mk=UTF-8
 encoding//Debug/subdir_rules.mk=UTF-8

+ 20 - 78
main_target.c

@@ -5,70 +5,11 @@
 //#include "ti/driverlib/dl_i2c.h"
 #include <stdio.h>
 #include "src/interfaces/i2c_target.h"
-#include "src/interfaces/i2c_controller.h"
 #include "src/config.h"
+#include "src/peripherals/adc.h"
 
 int8_t handle_read_pending_slot = -1;
 
-void I2C_controller_INST_IRQHandler(void) {
-  switch (DL_I2C_getPendingInterrupt(I2C_controller_INST)) { 
-    
-    case DL_I2C_IIDX_CONTROLLER_START:
-        controllerRxPackage.count = 0;
-        
-        DL_I2C_flushControllerTXFIFO(I2C_controller_INST);
-        break;
-
-    case DL_I2C_IIDX_CONTROLLER_RXFIFO_TRIGGER:
-        /* Store bytes received from target in Rx Msg Buffer */
-        while (DL_I2C_isControllerRXFIFOEmpty(I2C_controller_INST) != true) {
-            if (controllerRxPackage.count < controllerRxPackage.len) {
-                controllerRxPackage.packet[controllerRxPackage.count] =
-                    DL_I2C_receiveControllerData(I2C_controller_INST);
-                    ;
-                controllerRxPackage.count++;
-
-            } else {
-                /* Ignore and remove from FIFO if the buffer is full */
-                DL_I2C_receiveControllerData(I2C_controller_INST);
-            }
-        }
-            if (controllerRxPackage.count >= controllerRxPackage.len) {
-            controllerRxPackage.complete = true;
-            DL_I2C_enableInterrupt(I2C_controller_INST,
-                                    DL_I2C_INTERRUPT_CONTROLLER_STOP);
-            }
-        break;
-    /*TRANSMIT data to ADC*/
-    case DL_I2C_IIDX_CONTROLLER_TXFIFO_TRIGGER:
-        if (controllerTxPackage.count < controllerTxPackage.len) {
-            DL_I2C_fillControllerTXFIFO(I2C_controller_INST,
-                                        &controllerTxPackage.packet[controllerTxPackage.count],
-                                        (controllerTxPackage.len - controllerTxPackage.count));
-            controllerTxPackage.count++;
-        } else {
-            /*Prevent overflow and just ignore data*/
-            DL_I2C_fillTargetTXFIFO(I2C_controller_INST, (uint8_t[]){0x00}, 1);
-            controllerTxPackage.complete = true;
-        }
-        if(controllerTxPackage.count >= controllerTxPackage.len){
-            controllerTxPackage.complete= true;
-        }
-        break;
-    /*STOP condition*/
-    case DL_I2C_IIDX_CONTROLLER_STOP:
-        controllerTxPackage.complete = true;
-        controllerRxPackage.complete = true;
-        break;
-    case DL_I2C_IIDX_CONTROLLER_ARBITRATION_LOST:
-        break;
-    case DL_I2C_IIDX_CONTROLLER_NACK:
-        break;
-    default:
-        break;
-    }
-}
-
 /**** Interrupt for Pi to MCU ****/
 void I2C_target_INST_IRQHandler(void) {
 
@@ -101,32 +42,33 @@ int main(void)
 
 {   
     SYSCFG_DL_init();
-    NVIC_EnableIRQ(I2C_controller_INST_INT_IRQN);
     NVIC_EnableIRQ(I2C_target_INST_INT_IRQN);
+    NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);
 
-    battery_slotmgr.init();
+    slot_init();
 
     initialize_target_address();
 
+    DL_ADC12_startConversion(ADC12_0_INST);
+    DL_ADC12_enableConversions(ADC12_0_INST);
+
     while (1) {
 
-        for(uint8_t slot= 0; slot< NUM_SLOTS; slot++){
-            if (handle_read_pending_slot != -1) {
-                mcu_i2c_handle_read(I2C_target_INST, handle_read_pending_slot);
-                handle_read_pending_slot = -1;
-            }
-        
-            // step 1: update the voltage readings
-            battery_slotmgr.read_state(slot);
+        if (handle_read_pending_slot != -1) {
+            mcu_i2c_handle_read(I2C_target_INST);
+            handle_read_pending_slot = -1;
+        }
+    
+        // step 1: update the voltage readings
+        slot_read_state();
 
-            // step 2: control loop to adjust the dac / adc values,
-            // but only if no error happens
-            // (0x80 is the error flag of the state)
-            if ((*battery_slots[slot].state & 0x80) == 0) {
-                battery_slotmgr.adjust_current(slot);
-            } else {
-                battery_slotmgr.disable(slot);
-            }
+        // step 2: control loop to adjust the dac / adc values,
+        // but only if no error happens
+        // (0x80 is the error flag of the state)
+        if ((*slot.state & 0x80) == 0) {
+            slot_adjust_current();
+        } else {
+            slot_disable();
         }
     }
 }

+ 62 - 84
main_target.syscfg

@@ -1,136 +1,111 @@
 /**
  * These arguments were used when this file was generated. They will be automatically applied on subsequent loads
  * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments.
- * @cliArgs --device "MSPM0L130X" --part "Default" --package "SOT-16(DYY)" --product "mspm0_sdk@2.04.00.06"
- * @v2CliArgs --device "MSPM0L1304" --package "SOT-16(DYY)" --product "mspm0_sdk@2.04.00.06"
+ * @cliArgs --device "MSPM0L130X" --part "Default" --package "VSSOP-20(DGS20)" --product "mspm0_sdk@2.04.00.06"
+ * @v2CliArgs --device "MSPM0L1304" --package "VSSOP-20(DGS20)" --product "mspm0_sdk@2.04.00.06"
  * @versions {"tool":"1.22.0+3893"}
  */
 
 /**
  * Import the modules used in this configuration.
  */
+const ADC12         = scripting.addModule("/ti/driverlib/ADC12", {}, false);
+const ADC121        = ADC12.addInstance();
 const Board         = scripting.addModule("/ti/driverlib/Board");
+const COMP          = scripting.addModule("/ti/driverlib/COMP", {}, false);
+const COMP1         = COMP.addInstance();
 const GPIO          = scripting.addModule("/ti/driverlib/GPIO", {}, false);
 const GPIO1         = GPIO.addInstance();
 const I2C           = scripting.addModule("/ti/driverlib/I2C", {}, false);
 const I2C1          = I2C.addInstance();
-const I2C2          = I2C.addInstance();
+const OPA           = scripting.addModule("/ti/driverlib/OPA", {}, false);
+const OPA1          = OPA.addInstance();
 const PWM           = scripting.addModule("/ti/driverlib/PWM", {}, false);
 const PWM1          = PWM.addInstance();
-const PWM2          = PWM.addInstance();
-const PWM3          = PWM.addInstance();
-const PWM4          = PWM.addInstance();
 const SYSCTL        = scripting.addModule("/ti/driverlib/SYSCTL");
+const VREF          = scripting.addModule("/ti/driverlib/VREF");
 const ProjectConfig = scripting.addModule("/ti/project_config/ProjectConfig");
 
 /**
  * Write custom configuration values to the imported modules.
  */
+ADC121.$name               = "ADC12_0";
+ADC121.enabledInterrupts   = ["DL_ADC12_INTERRUPT_MEM0_RESULT_LOADED"];
+ADC121.sampClkDiv          = "DL_ADC12_CLOCK_DIVIDE_8";
+ADC121.powerDownMode       = "DL_ADC12_POWER_DOWN_MODE_MANUAL";
+ADC121.sampleTime0         = "125 us";
+ADC121.peripheral.$assign  = "ADC0";
+ADC121.adcPin0Config.$name = "ti_driverlib_gpio_GPIOPinGeneric4";
+
+Board.configureVDDA               = true;
 Board.peripheral.$assign          = "DEBUGSS";
 Board.peripheral.swclkPin.$assign = "PA20";
 Board.peripheral.swdioPin.$assign = "PA19";
 
-GPIO1.$name                         = "GPIOS";
+COMP1.$name         = "COMP_0";
+COMP1.vSource       = "DL_COMP_REF_SOURCE_VREF_DAC";
+COMP1.controlSelect = "DL_COMP_DAC_CONTROL_SW";
+
+GPIO1.$name                         = "ADDR";
+GPIO1.associatedPins.create(2);
+GPIO1.associatedPins[0].$name       = "A0";
 GPIO1.associatedPins[0].direction   = "INPUT";
-GPIO1.associatedPins[0].$name       = "ADDR";
-GPIO1.associatedPins[0].pin.$assign = "PA24/OPA0.IN0-";
+GPIO1.associatedPins[0].pin.$assign = "PA4";
+GPIO1.associatedPins[1].$name       = "A1";
+GPIO1.associatedPins[1].direction   = "INPUT";
+GPIO1.associatedPins[1].pin.$assign = "PA11";
 
-I2C1.$name                             = "I2C_controller";
-I2C1.basicEnableController             = true;
-I2C1.intController                     = ["ARBITRATION_LOST","NACK","RXFIFO_TRIGGER","RX_DONE","TXFIFO_TRIGGER","TX_DONE"];
-I2C1.peripheral.$assign                = "I2C1";
-I2C1.peripheral.sdaPin.$assign         = "PA18";
-I2C1.peripheral.sclPin.$assign         = "PA17/OPA1.IN0-";
-I2C1.sdaPinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric0";
+I2C1.$name                             = "I2C_target";
+I2C1.basicEnableTarget                 = true;
+I2C1.intTarget                         = ["RXFIFO_TRIGGER","START","STOP","TXFIFO_TRIGGER"];
+I2C1.basicTargetAddress                = 0x48;
+I2C1.enableTimeoutA                    = true;
+I2C1.timeoutACount                     = 125;
+I2C1.enableTimeoutB                    = true;
+I2C1.timeoutBCount                     = 125;
+I2C1.intGeneric                        = ["TIMEOUT_A","TIMEOUT_B"];
+I2C1.peripheral.$assign                = "I2C0";
+I2C1.peripheral.sdaPin.$assign         = "PA0";
+I2C1.peripheral.sclPin.$assign         = "PA1/NRST";
 I2C1.sdaPinConfig.hideOutputInversion  = scripting.forceWrite(false);
 I2C1.sdaPinConfig.onlyInternalResistor = scripting.forceWrite(false);
 I2C1.sdaPinConfig.passedPeripheralType = scripting.forceWrite("Digital");
+I2C1.sdaPinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric2";
 I2C1.sdaPinConfig.enableConfig         = true;
-I2C1.sdaPinConfig.internalResistor     = "PULL_UP";
-I2C1.sclPinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric1";
 I2C1.sclPinConfig.hideOutputInversion  = scripting.forceWrite(false);
 I2C1.sclPinConfig.onlyInternalResistor = scripting.forceWrite(false);
 I2C1.sclPinConfig.passedPeripheralType = scripting.forceWrite("Digital");
+I2C1.sclPinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric3";
 I2C1.sclPinConfig.enableConfig         = true;
-I2C1.sclPinConfig.internalResistor     = "PULL_UP";
 
-I2C2.$name                             = "I2C_target";
-I2C2.basicEnableTarget                 = true;
-I2C2.intTarget                         = ["RXFIFO_TRIGGER","START","STOP","TXFIFO_TRIGGER"];
-I2C2.basicTargetAddress                = 0x48;
-I2C2.enableTimeoutA                    = true;
-I2C2.timeoutACount                     = 125;
-I2C2.enableTimeoutB                    = true;
-I2C2.timeoutBCount                     = 125;
-I2C2.intGeneric                        = ["TIMEOUT_A","TIMEOUT_B"];
-I2C2.peripheral.sdaPin.$assign         = "PA0";
-I2C2.peripheral.sclPin.$assign         = "PA1/NRST";
-I2C2.sdaPinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric2";
-I2C2.sdaPinConfig.hideOutputInversion  = scripting.forceWrite(false);
-I2C2.sdaPinConfig.onlyInternalResistor = scripting.forceWrite(false);
-I2C2.sdaPinConfig.passedPeripheralType = scripting.forceWrite("Digital");
-I2C2.sdaPinConfig.enableConfig         = true;
-I2C2.sclPinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric3";
-I2C2.sclPinConfig.hideOutputInversion  = scripting.forceWrite(false);
-I2C2.sclPinConfig.onlyInternalResistor = scripting.forceWrite(false);
-I2C2.sclPinConfig.passedPeripheralType = scripting.forceWrite("Digital");
-I2C2.sclPinConfig.enableConfig         = true;
+OPA1.$name                     = "OPA_0";
+OPA1.cfg0PSELChannel           = "DAC_OUT";
+OPA1.cfg0NSELChannel           = "RTAP";
+OPA1.cfg0Gain                  = "N1_P2";
+OPA1.cfg0OutputPin             = "ENABLED";
+OPA1.peripheral.$assign        = "OPA0";
+OPA1.peripheral.OutPin.$assign = "PA22";
+OPA1.OutPinConfig.$name        = "ti_driverlib_gpio_GPIOPinGeneric0";
 
-PWM1.timerCount                         = 320;
 PWM1.ccIndex                            = [1];
-PWM1.$name                              = "PWM_3";
+PWM1.timerCount                         = 320;
+PWM1.$name                              = "PWM";
 PWM1.peripheral.$assign                 = "TIMG0";
 PWM1.peripheral.ccp1Pin.$assign         = "PA6";
 PWM1.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
 PWM1.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
 PWM1.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
 PWM1.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
-PWM1.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric11";
-PWM1.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC0";
+PWM1.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric10";
+PWM1.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC3";
 PWM1.PWM_CHANNEL_1.invert               = true;
 
-PWM2.ccIndex                            = [1];
-PWM2.$name                              = "PWM_2";
-PWM2.timerCount                         = 320;
-PWM2.peripheral.$assign                 = "TIMG1";
-PWM2.peripheral.ccp1Pin.$assign         = "PA2";
-PWM2.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
-PWM2.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
-PWM2.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
-PWM2.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
-PWM2.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric6";
-PWM2.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC1";
-PWM2.PWM_CHANNEL_1.invert               = true;
-
-PWM3.ccIndex                            = [1];
-PWM3.$name                              = "PWM_1";
-PWM3.timerCount                         = 320;
-PWM3.peripheral.$assign                 = "TIMG2";
-PWM3.peripheral.ccp1Pin.$assign         = "PA22";
-PWM3.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
-PWM3.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
-PWM3.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
-PWM3.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
-PWM3.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric8";
-PWM3.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC2";
-PWM3.PWM_CHANNEL_1.invert               = true;
-
-PWM4.ccIndex                            = [1];
-PWM4.$name                              = "PWM_0";
-PWM4.timerCount                         = 320;
-PWM4.peripheral.$assign                 = "TIMG4";
-PWM4.peripheral.ccp1Pin.$assign         = "PA25";
-PWM4.ccp1PinConfig.direction            = scripting.forceWrite("OUTPUT");
-PWM4.ccp1PinConfig.hideOutputInversion  = scripting.forceWrite(false);
-PWM4.ccp1PinConfig.onlyInternalResistor = scripting.forceWrite(false);
-PWM4.ccp1PinConfig.passedPeripheralType = scripting.forceWrite("Digital");
-PWM4.ccp1PinConfig.$name                = "ti_driverlib_gpio_GPIOPinGeneric10";
-PWM4.PWM_CHANNEL_1.$name                = "ti_driverlib_pwm_PWMTimerCC3";
-PWM4.PWM_CHANNEL_1.invert               = true;
-
 SYSCTL.disableNRSTPin     = true;
 SYSCTL.peripheral.$assign = "SYSCTL";
 
+VREF.basicMode              = ["DL_VREF_ENABLE_DISABLE"];
+VREF.vrefPosPinConfig.$name = "ti_driverlib_gpio_GPIOPinGeneric1";
+
 ProjectConfig.migrationCondition = true;
 
 /**
@@ -138,4 +113,7 @@ ProjectConfig.migrationCondition = true;
  * version of the tool will not impact the pinmux you originally saw.  These lines can be completely deleted in order to
  * re-solve from scratch.
  */
-I2C2.peripheral.$suggestSolution = "I2C0";
+ADC121.peripheral.adcPin0.$suggestSolution  = "PA27";
+COMP1.peripheral.$suggestSolution           = "COMP0";
+VREF.peripheral.$suggestSolution            = "VREF";
+VREF.peripheral.vrefPosPin.$suggestSolution = "PA23";

+ 55 - 158
src/battery_data/battery.c

@@ -1,229 +1,126 @@
 #include "battery.h"
 #include "ti/driverlib/dl_i2c.h"
 #include "ti/driverlib/dl_timerg.h"
+#include "ti/driverlib/dl_comp.h"
 #include "ti_msp_dl_config.h"
-#include "src/peripherals/dac/dac.h"
-#include "src/peripherals/adc/adc.h"
-#include "src/interfaces/i2c_controller.h"
-// we need the itnerface for the ADC_TARGET_BASE_ADDRESS constant
-// refactor this somewhen to a general constants file
-#include "src/peripherals/adc/adc_interface.h"
-#include "src/peripherals/temp/tmp1075.h"
 #include "src/config.h"
 
-BatterySlot battery_slots[NUM_SLOTS];
+BatterySlot slot;
 
-static void set_dac(uint8_t slot, uint16_t value) {
-    battery_slots[slot].dac_value = value;
-    DAC_SingleWrite(slot, value);
+static void set_dac(uint16_t value) {
+    slot.dac_value = value;
+    DL_COMP_setDACCode0(COMP_0_INST, value);
 }
-static void set_pwm(uint8_t slot, uint16_t value) {
-    battery_slots[slot].pwm_value = value;
-    DL_TimerG_setCaptureCompareValue(battery_slots[slot].timer, value, DL_TIMER_CC_1_INDEX);
-    if (value > 0 && !DL_TimerG_isRunning(battery_slots[slot].timer)) {
-        DL_TimerG_startCounter(battery_slots[slot].timer);
+static void set_pwm(uint16_t value) {
+    slot.pwm_value = value;
+    DL_TimerG_setCaptureCompareValue(PWM_INST, value, DL_TIMER_CC_1_INDEX);
+    if (value > 0 && !DL_TimerG_isRunning(PWM_INST)) {
+        DL_TimerG_startCounter(PWM_INST);
     }
-    if (value == 0 && DL_TimerG_isRunning(battery_slots[slot].timer)) {
-        DL_TimerG_stopCounter(battery_slots[slot].timer);
+    if (value == 0 && DL_TimerG_isRunning(PWM_INST)) {
+        DL_TimerG_stopCounter(PWM_INST);
     }
 }
-static void batteryslots_disable(uint8_t slot) {
-    if (battery_slots[slot].dac_value != 0) {
-        set_dac(slot, 0);
+void slot_disable() {
+    if (slot.dac_value != 0) {
+        set_dac(0);
     }
-    if (battery_slots[slot].pwm_value != 0) {
-        set_pwm(slot, 0);
+    if (slot.pwm_value != 0) {
+        set_pwm(0);
     }
 }
 
 /*Initialize battery array and default parameters*/
-static void batteryslots_init() {
+void slot_init() {
 
-    // initialize data structures
-    battery_slots[0].timer = PWM_0_INST;
-    battery_slots[0].adc_addr = ADC_TARGET_BASE_ADDRESS;
-    battery_slots[1].timer = PWM_1_INST;
-    battery_slots[1].adc_addr = ADC_TARGET_BASE_ADDRESS+4;
-    battery_slots[2].timer = PWM_2_INST;
-    battery_slots[2].adc_addr = ADC_TARGET_BASE_ADDRESS+2;
-    battery_slots[3].timer = PWM_3_INST;
-    battery_slots[3].adc_addr = ADC_TARGET_BASE_ADDRESS+6;
+    slot.measurement.state = SLOT_STATE_OK;
+    // convinience trick:
+    // with that we can set *battery_slots[i].state = SLOT_STATE_* or SLOT_ERR_*
+    // like e.g. *battery_slots[i].state = SLOT_ERR_OVERTEMPERATURE
+    slot.state = &slot.measurement.state;
 
-    for(uint8_t i=0; i< NUM_SLOTS; i++){
+    slot.measurement.voltage = 0;
+    slot.measurement.current = 0;
+    slot.measurement.temperature = 0;
+    slot.set_current = 0;
 
-        battery_slots[i].measurement.state = SLOT_STATE_OK;
-        // convinience trick:
-        // with that we can set *battery_slots[i].state = SLOT_STATE_* or SLOT_ERR_*
-        // like e.g. *battery_slots[i].state = SLOT_ERR_OVERTEMPERATURE
-        battery_slots[i].state = &battery_slots[i].measurement.state;
-
-        battery_slots[i].measurement.voltage = 0;
-        battery_slots[i].measurement.current = 0;
-        battery_slots[i].measurement.temperature = 0;
-        battery_slots[i].set_current = 0;
-
-        set_pwm(i, 0);
-        set_dac(i, 0);
-        delay_cycles(PWM_INITIALIZATION_DELAY);
-    }
-
-    
-    /*if (!i2c_discover(DAC_TARGET_ADDRESS)) {
-        // there is only 1 DAC for all 4 slots
-        for(uint8_t i=0; i< NUM_SLOTS; i++) {
-            *battery_slots[i].state = SLOT_ERR_NO_DAC;
-        }
-        // Error state - no I2C on bus - we cannot continue.
-        return;
-    }
-
-    for(uint8_t i=0; i< NUM_SLOTS; i++){
-
-        set_dac(i, 0);
-        
-        if (!i2c_discover(ADC_TARGET_BASE_ADDRESS+i)) {
-            // this automatically translates to the other addresses
-            *battery_slots[i].state = SLOT_ERR_NO_ADC1+i;
-        }
-    }*/
+    set_pwm(0);
+    set_dac(0);
 }
-static void batteryslots_read_state(uint8_t slot) {
-    /*
-     * Strategy:
-     * 1. updateADCReading calls the ADC function that does the control loop for getting the values
-     * 2. the updateADCReading also calls internally the HAL to send the i2c commands,
-     *    construct the configuration byte and calculate the values (voltage, current)
-     * 3. the adc updates the battery slot value directly
-     */
- 
-    // step 1: read channel 0 (voltage reading of the cell)
-    uint16_t bare_voltage = read_adc_channel(slot, 0);
-    if (bare_voltage == 0xffff) {
-        // the voltage reading is invalid -> ignore this cycle.
-        return;
-    }
-    battery_slots[slot].measurement.voltage = bare_voltage*(56+100)/56; // We have that voltage divider
-
-    // DAC branch: we can calculate the current based on the shunt
-    if (battery_slots[slot].set_current >= 0) {
-        // read channel 1 (current reading on charge)
-        bare_voltage = read_adc_channel(slot, 1);
-        if (bare_voltage == 0xffff) {
-            // the voltage reading is invalid -> ignore this cycle.
-            return;
-        }
-        battery_slots[slot].measurement.current = bare_voltage*10/1000; // current comes on a 0.1 ohms shunt
-#ifdef DEBUG_CTRL
-        printf("Slot %d voltage: %d mV and %d mA (dac shunt)\n", slot, battery_slots[slot].measurement.voltage, battery_slots[slot].measurement.current);
-#endif
-    } else {
-        // we are in PWM mode, the shunt is on the high side
-        // read channel 2 (voltage reading on 5V side)
-        bare_voltage = read_adc_channel(slot, 2);
-        if (bare_voltage == 0xffff) {
-            // the voltage reading is invalid -> ignore this cycle.
-            return;
-        }
-        uint16_t shunt_current = 10*bare_voltage/1000;
-
-        // read channel 3 (current reading after step conversion, 5V side)
-        bare_voltage = read_adc_channel(slot, 3);
-        if (bare_voltage == 0xffff) {
-            // the voltage reading is invalid -> ignore this cycle.
-            return;
-        }
-        uint16_t hi_voltage = bare_voltage*(56+100)/56;
-
-        uint32_t hi_power = shunt_current*hi_voltage;
-
-        // calculate the result
-        battery_slots[slot].measurement.current = (int16_t)(hi_power/battery_slots[slot].measurement.voltage)*-1;
-#ifdef DEBUG_CTRL
-        printf("Slot %d voltage: %d mV and %d mA (pwm shunt) (hi side voltage: %d mV, hi side current: %d mA)\n", slot, battery_slots[slot].measurement.voltage, battery_slots[slot].measurement.current, hi_voltage, shunt_current);
-#endif
-    }
-
-    battery_slots[slot].measurement.temperature = read_temperature(slot);
+void slot_read_state() {
+   ;
 }
 
-static void batteryslots_adjust_current(uint8_t slot) {
+void slot_adjust_current() {
 
-    if (battery_slots[slot].set_current > 0) {
+    if (slot.set_current > 0) {
         // positive current -> charge (with DAC)
 
-        if (battery_slots[slot].pwm_value != 0) {
+        if (slot.pwm_value != 0) {
             // seems like we switched from a charging before
             // -> disable DAC before getting active
-            set_pwm(slot, 0);
+            set_pwm(0);
         }
 
-        if (battery_slots[slot].set_current + BATTERY_CURRENT_THRESHOLD < battery_slots[slot].measurement.current) {
+        if (slot.set_current + BATTERY_CURRENT_THRESHOLD < slot.measurement.current) {
             // we are outside of the tolerance band
             // exceeded to the upper limit
             // -> update dac value, decrease the voltage
-            if (battery_slots[slot].dac_value-1 >= 0) {
-                set_dac(slot, --battery_slots[slot].dac_value);
+            if (slot.dac_value-1 >= 0) {
+                set_dac(--slot.dac_value);
             }
             else {
                 // we want to give more current, but we can't ?!
-                *battery_slots[slot].state = SLOT_WARN_LOWER_DAC_NOT_POSSIBLE;
+                *slot.state = SLOT_WARN_LOWER_DAC_NOT_POSSIBLE;
             }
-        } else if (battery_slots[slot].set_current - BATTERY_CURRENT_THRESHOLD > battery_slots[slot].measurement.current) {
+        } else if (slot.set_current - BATTERY_CURRENT_THRESHOLD > slot.measurement.current) {
             // we are outside of the tolerance band
             // exceeded to the upplowerer limit
             // -> update dac value, increase the voltage
-            if (battery_slots[slot].dac_value+1 <= MAX_DAC_VALUE) {
-                set_dac(slot, ++battery_slots[slot].dac_value);
+            if (slot.dac_value+1 <= MAX_DAC_VALUE) {
+                set_dac(++slot.dac_value);
             }
             else {
                 // we want to give more current, but we can't ?!
-                *battery_slots[slot].state = SLOT_WARN_HIGHER_DAC_NOT_POSSIBLE;
+                *slot.state = SLOT_WARN_HIGHER_DAC_NOT_POSSIBLE;
             }
         }
         // no else statement here: we are ok, since we are in the tolerance measure
-    } else if (battery_slots[slot].set_current < 0) {
+    } else if (slot.set_current < 0) {
         // negative current -> discharge (with PWM)
-        if (battery_slots[slot].dac_value != 0) {
+        if (slot.dac_value != 0) {
             // seems like we switched from a charging before
             // -> disable DAC before getting active
-            set_dac(slot, 0);
+            set_dac(0);
         }
 
-        if (battery_slots[slot].set_current + BATTERY_CURRENT_THRESHOLD < battery_slots[slot].measurement.current) {
+        if (slot.set_current + BATTERY_CURRENT_THRESHOLD < slot.measurement.current) {
             // we are outside of the tolerance band
             // exceeded to the upper limit
             // -> update pwm value, decrease the voltage
 
-            if (battery_slots[slot].pwm_value+1 <= MAX_PWM_CYCLE) {
+            if (slot.pwm_value+1 <= MAX_PWM_CYCLE) {
                 // pwm is inverse to the DAC since dragging more current means more negative
-                set_pwm(slot, ++battery_slots[slot].pwm_value);
+                set_pwm(++slot.pwm_value);
             }
             else {
                 // we want to give more current, but we can't ?!
-                *battery_slots[slot].state = SLOT_WARN_HIGHER_PWM_NOT_POSSIBLE;
+                *slot.state = SLOT_WARN_HIGHER_PWM_NOT_POSSIBLE;
             }
-        } else if (battery_slots[slot].set_current - BATTERY_CURRENT_THRESHOLD > battery_slots[slot].measurement.current) {
+        } else if (slot.set_current - BATTERY_CURRENT_THRESHOLD > slot.measurement.current) {
             // we are outside of the tolerance band
             // exceeded to the upplowerer limit
             // -> update pwm value, increase the voltage
-            if (battery_slots[slot].pwm_value-1 >= 0) {
-                set_pwm(slot, --battery_slots[slot].pwm_value);
+            if (slot.pwm_value-1 >= 0) {
+                set_pwm(--slot.pwm_value);
             }
             else {
                 // we want to give more current, but we can't ?!
-                *battery_slots[slot].state = SLOT_WARN_LOWER_PWM_NOT_POSSIBLE;
+                *slot.state = SLOT_WARN_LOWER_PWM_NOT_POSSIBLE;
             }
         }
     } else {
         // we have 0 -> stop charging and discharging
-        batteryslots_disable(slot);
+        slot_disable();
     }
 }
-
-BatterySlotManager battery_slotmgr = {
-    .init = batteryslots_init,
-    .read_state = batteryslots_read_state,
-    .adjust_current = batteryslots_adjust_current,
-    .disable = batteryslots_disable
-};
-

+ 5 - 15
src/battery_data/battery.h

@@ -22,12 +22,6 @@ typedef enum: uint8_t{
     SLOT_WARN_LOWER_PWM_NOT_POSSIBLE=0x13,
     SLOT_WARN_HIGHER_PWM_NOT_POSSIBLE=0x14,
 
-    // I2C Slave Error states
-    SLOT_ERR_NO_DAC =  (0x20 | 0x80),
-    SLOT_ERR_NO_ADC1 = (0x21 | 0x80),
-    SLOT_ERR_NO_ADC2 = (0x22 | 0x80),
-    SLOT_ERR_NO_ADC3 = (0x23 | 0x80),
-    SLOT_ERR_NO_ADC4 = (0x24 | 0x80),
     SLOT_ERR_CONFIGBYTE = (0x25 | 0x80),
     SLOT_ERR_DAC_WRITE_FAILED= (0x26 | 0x80)
 } SlotState;
@@ -53,15 +47,11 @@ typedef struct {
 } BatterySlot;
 
 //global battery array declaration: extending visiblity of the variable to multiple source files: variable declaration
-extern BatterySlot battery_slots[NUM_SLOTS];
+extern BatterySlot slot;
 
-typedef struct {
-    void (*init)();
-    void (*read_state)(uint8_t slot_id);
-    void (*adjust_current)(uint8_t slot_id);
-    void (*disable)(uint8_t slot_id);
-} BatterySlotManager;
-
-extern BatterySlotManager battery_slotmgr;
+void slot_init(void);
+void slot_read_state(void);
+void slot_adjust_current(void);
+void slot_disable(void);
 
 #endif

+ 2 - 4
src/config.h

@@ -3,10 +3,6 @@
 //------------------------
 // Configuration section
 
-// How many slots do we currently support?
-// use 1 for debugging, 4 for production
-#define NUM_SLOTS 4
-
 //Battery Tolerance
 // how much tolerance do we allow if we charge / discharge before we 
 // trigger the control loop to adjust the value
@@ -33,6 +29,8 @@
 // PWM Define max CC period
 #define MAX_PWM_CYCLE 320
 
+#define MAX_DAC_VALUE 4096
+
 //------------
 // Section for configuring debugging outputs
 //------------

+ 0 - 144
src/interfaces/i2c_controller.c

@@ -1,144 +0,0 @@
-/*
- * This file implements Hardware Abstraction Layer (HAL) to make the I2C
- * communication of MSPM0 SDK compatible with ADC (MCP3426/7/8) and DAC
- * (MCP34728)
- */
-#include "src/interfaces/i2c_controller.h"
-#include "ti/driverlib/dl_i2c.h"
-#include "ti_msp_dl_config.h"
-#include <stdio.h>
-
-/*
-static function is for implementing Data Hiding, access to the static function
-is restricted to the file where they are declared const keyword for
-'i2c_addr' and 'Data_length' makes the variable immutable. const uint8_t *
-const Data: means the pointer to the variable and the value of Data is immutable
-*/
-
-I2CRxPackage controllerRxPackage;
-I2CTxPackage controllerTxPackage;
-
-static bool msp_i2c_write(uint8_t const i2c_addr) {
-    // Flush any stale data in TX FIFO:
-    DL_I2C_flushControllerTXFIFO(I2C_controller_INST);
-
-    // **Check if the I2C bus is stuck before WRITE
-    if (DL_I2C_getControllerStatus(I2C_controller_INST) &
-        DL_I2C_CONTROLLER_STATUS_ERROR) {
-#ifdef DEBUG_I2C_ERR
-        printf("I2C Communication: Bus is stuck!\n");
-#endif
-        DL_I2C_resetControllerTransfer(I2C_controller_INST); 
-        return false; 
-    }
-    
-    // **Wait for I2C Bus to be Free**
-    uint32_t n_cycles = 0;
-    while ((DL_I2C_getControllerStatus(I2C_controller_INST) &
-            DL_I2C_CONTROLLER_STATUS_BUSY_BUS) && n_cycles++ < MAX_I2C_WAIT_RX)
-        ;
-    if (n_cycles == MAX_I2C_WAIT_RX) {
-        printf("Error in reading from I2C Bus: Bus is not getting ready before transmit start\n");
-        DL_I2C_resetControllerTransfer(I2C_controller_INST); 
-        return false;
-    }
-
-    // **Start I2C Write Transaction**
-    DL_I2C_startControllerTransfer(I2C_controller_INST, i2c_addr,
-                                  DL_I2C_CONTROLLER_DIRECTION_TX, controllerTxPackage.len);
-
-    // **Load Configuration Byte into TX FIFO**
-    DL_I2C_fillControllerTXFIFO(I2C_controller_INST, controllerTxPackage.packet, controllerTxPackage.len);
-#ifdef DEBUG_I2C_TX
-    for (uint8_t i = 0; i < controllerTxPackage.len; i++) {
-        printf("Sending 0x%02X\n", controllerTxPackage.packet[i]);
-    }
-#endif
-
-    n_cycles = 0;
-    while ((DL_I2C_getControllerStatus(I2C_controller_INST) &
-            DL_I2C_CONTROLLER_STATUS_BUSY_BUS) && n_cycles++ < MAX_I2C_WAIT_RX)
-        ;
-    if (n_cycles == MAX_I2C_WAIT_RX) {
-        printf("Error in reading from I2C Bus: Bus is not getting ready after transmit data\n");
-        DL_I2C_resetControllerTransfer(I2C_controller_INST); 
-        return false;
-    }
-    
-    // **Check if the target address is incorrect
-    
-    if (DL_I2C_getControllerStatus(I2C_controller_INST) & DL_I2C_CONTROLLER_STATUS_ADDR_ACK) {
-#ifdef DEBUG_I2C_ERR
-        printf("I2C Write Error: Target Address not acknowledged!\n");
-#endif
-      return false;
-    }
-
-    // **Check for any WRITE error
-    if (DL_I2C_getControllerStatus(I2C_controller_INST) & DL_I2C_CONTROLLER_STATUS_ERROR) {
-#ifdef DEBUG_I2C_ERR
-        printf("I2C Write Error: Bus error after sending data.\n");
-#endif
-        return false;
-    }
-
-    return true;
-}
-
-static bool msp_i2c_read(uint8_t const i2c_addr) {
-
-  
-    // Flush any stale data in TX FIFO:
-    DL_I2C_flushControllerRXFIFO(I2C_controller_INST);
-    
-    uint32_t n_cycles = 0;
-    while ((DL_I2C_getControllerStatus(I2C_controller_INST) &
-            DL_I2C_CONTROLLER_STATUS_BUSY_BUS) && n_cycles++ < MAX_I2C_WAIT_RX)
-        ;
-    if (n_cycles == MAX_I2C_WAIT_RX) {
-        printf("Error in reading from I2C Bus: Bus is not getting ready before transmit start\n");
-    }
-
-    DL_I2C_startControllerTransfer(I2C_controller_INST, i2c_addr,
-                                    DL_I2C_CONTROLLER_DIRECTION_RX, controllerRxPackage.len);
-
-    n_cycles = 0;
-    while ((DL_I2C_getControllerStatus(I2C_controller_INST) &
-            DL_I2C_CONTROLLER_STATUS_BUSY_BUS) && n_cycles++ < MAX_I2C_WAIT_RX)
-        ;
-    if (n_cycles == MAX_I2C_WAIT_RX) {
-        printf("Error in reading from I2C Bus: Bus is not getting ready after transmit start\n");
-    }
-        
-    DL_I2C_enableInterrupt(I2C_controller_INST,
-                            DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
-    
-    
-    return true;
-}
-
-/**
- * this function discovers on the i2c bus the devices from the address
- * to ensure all relevant bus participants are present
- */
- bool i2c_discover(uint8_t i2c_addr) {
-    if (DL_I2C_getControllerStatus(I2C_controller_INST) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS) {
-        DL_I2C_disableController(I2C_controller_INST);  // Disable I2C
-        DL_I2C_enableController(I2C_controller_INST);   // Re-enable I2C
-    }
-#ifdef DEBUG_I2C_TX
-    printf("Scanning 0x%02X\n", i2c_addr);
-#endif
-    DL_I2C_startControllerTransfer(I2C_controller_INST, i2c_addr, DL_I2C_CONTROLLER_DIRECTION_RX, 1);
-    delay_cycles(5000);
-    uint32_t i2c_status = DL_I2C_getControllerStatus(I2C_controller_INST);
-    bool found = !(DL_I2C_getControllerStatus(I2C_controller_INST) & DL_I2C_CONTROLLER_STATUS_ERROR);
-    DL_I2C_disableController(I2C_controller_INST);
-    DL_I2C_enableController(I2C_controller_INST);
-    return found;
-}
-
-I2C_Interface i2c_hal = {
-    .write = msp_i2c_write,
-    .read = msp_i2c_read,
-};

+ 0 - 58
src/interfaces/i2c_controller.h

@@ -1,58 +0,0 @@
-/*
-* This file is an interface file for I2C communication between MCU (Controller) and other peripherals (Target): i2c_hal.c
-* Context:
-* Our current functions in ADC and DAC are tightly coupled with I2C communication. 
-* Need a communication mechanism to isolate the flow of the ADC function from Asynchronous calls.
-* Decision:
-* i2c_controller is a header file which defines what the I2C peripheral does:
-* - i2c READ
-* - i2c WRITE
-* - i2c start controller transfer
-* - i2c enable interrupt
-* - i2c bus wait
-* Consequences:
-* Cleaner platform independent file
-
-Reference:
-- https://www.embeddedrelated.com/showarticle/1596.php
-- https://www.beningo.com/5-tips-for-designing-an-interface-in-c/
-- https://iot.sites.arm.com/open-iot-sdk/libraries/mcu-driver-hal/mcu-driver-hal/pwmout__api_8h_source.html
-*/
-
-#ifndef I2C_INTERFACE_H_
-#define I2C_INTERFACE_H_
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "src/config.h"
-
-typedef struct {
-    volatile bool complete;
-    uint8_t packet[I2C_RX_MAX_PACKET_SIZE];
-    uint8_t count;
-    uint8_t len;
-} I2CRxPackage;
-
-extern I2CRxPackage controllerRxPackage;
-
-typedef struct {
-    volatile bool complete;
-    uint8_t packet[I2C_TX_MAX_PACKET_SIZE];
-    uint8_t count;
-    uint8_t len;
-} I2CTxPackage;
-extern I2CTxPackage controllerTxPackage;
-
-bool i2c_discover(uint8_t i2c_addr);
-
-/*
-* Since C does not allows to add functions in typedef struct, however a function pointer can be included in Structure in C. This interface provides a standard features of i2c_hal
-*/
-typedef struct{
-    bool (*write)(uint8_t const TARGET_ADDRESS);
-    bool (*read) (uint8_t const TARGET_ADDRESS);
-} I2C_Interface;
-
-extern I2C_Interface i2c_hal;
-
-#endif

+ 12 - 16
src/interfaces/i2c_target.c

@@ -4,15 +4,14 @@ https://stackoverflow.com/questions/246127/why-is-volatile-needed-in-c
 */
 
 #include "i2c_target.h"
-#include "src/battery_data/battery.h"
+
 #include "ti/driverlib/dl_i2c.h"
 #include <stdio.h>
 #include <string.h>
-#include "src/peripherals/dac/dac.h"
 #include <inttypes.h>
 #include "src/config.h"
 #include "ti_msp_dl_config.h"
-#include "src/peripherals/temp/tmp1075.h"
+#include "src/battery_data/battery.h"
 
 /**
  * Dynamic addressing function
@@ -23,9 +22,11 @@ https://stackoverflow.com/questions/246127/why-is-volatile-needed-in-c
  */
 void initialize_target_address() {
     uint8_t add = 0;
-    if (DL_GPIO_readPins(GPIOS_PORT, GPIOS_ADDR_PIN)) {
+    if (DL_GPIO_readPins(ADDR_PORT, ADDR_A0_PIN)) {
         add = 1;
-        addr_offset = 4;
+    }
+    if (DL_GPIO_readPins(ADDR_PORT, ADDR_A1_PIN)) {
+        add = 2;
     }
     DL_I2C_setTargetOwnAddress(I2C_target_INST, I2C_TARGET_BASE_ADDRESS+add);
     DL_I2C_enableTargetOwnAddress(I2C_target_INST);
@@ -42,25 +43,20 @@ int8_t mcu_i2c_handle(I2C_Regs *i2c) {
         
     uint8_t receivedByte = DL_I2C_receiveTargetData(i2c);
     uint8_t receivedCommand = (receivedByte & 0x0F);
-    uint8_t slot = ((receivedByte & 0xF0) >> 4);
 
     if (receivedCommand == CMD_GET_MEASUREMENT) {
         DL_I2C_flushTargetTXFIFO(i2c);
-        DL_I2C_fillTargetTXFIFO(i2c, (uint8_t *)&battery_slots[slot].measurement, 8);
+        DL_I2C_fillTargetTXFIFO(i2c, (uint8_t *)&slot.measurement, 8);
     } else if (receivedCommand == CMD_SET_CURRENT) {
-        return slot;
+        return 0;
     } else if (receivedCommand == CMD_CLEAR_ERR) {
-        if (slot > NUM_SLOTS) {
-            DL_I2C_flushTargetTXFIFO(i2c);
-            return -1;
-        }
-        *battery_slots[slot].state = SLOT_STATE_OK;
+        *slot.state = SLOT_STATE_OK;
     }
     DL_I2C_flushTargetRXFIFO(i2c);
     return -1;
 }
 
-void mcu_i2c_handle_read(I2C_Regs *i2c, uint8_t slot) {
+void mcu_i2c_handle_read(I2C_Regs *i2c) {
     // Read incoming bytes from the Controller:
         uint8_t rx_index = 0;
         uint8_t rx_buffer[2] = {0x00, 0x00};
@@ -80,10 +76,10 @@ void mcu_i2c_handle_read(I2C_Regs *i2c, uint8_t slot) {
             rx_index = 0;
             return;
         }
-        battery_slots[slot].set_current = *((int16_t*)(&rx_buffer[0]));
+        slot.set_current = *((int16_t*)(&rx_buffer[0]));
         
 #ifdef DEBUG_TARGET
-        printf("Slot id: %d, Current: %d mA (Bytes 0x%02X 0x%02X)\n", slot, battery_slots[slot].set_current, rx_buffer[0], rx_buffer[1]);
+        printf("Current: %d mA (Bytes 0x%02X 0x%02X)\n", slot.set_current, rx_buffer[0], rx_buffer[1]);
 #endif
         /*
         // This code is for debugging:

+ 1 - 1
src/interfaces/i2c_target.h

@@ -16,5 +16,5 @@ typedef enum{
 void initialize_target_address();
 
 int8_t mcu_i2c_handle(I2C_Regs *i2c);
-void mcu_i2c_handle_read(I2C_Regs *i2c, uint8_t slot);
+void mcu_i2c_handle_read(I2C_Regs *i2c);
 #endif

+ 58 - 0
src/peripherals/adc.c

@@ -0,0 +1,58 @@
+
+#include "adc.h"
+
+#include "ti/driverlib/dl_adc12.h"
+#include "ti_msp_dl_config.h"
+#include "src/battery_data/battery.h"
+
+// A0 PA27
+// A1 PA26
+// A2 PA25
+// A3 PA24
+// A4 PA16
+const uint8_t measurement_channels[4] = {
+    DL_ADC12_INPUT_CHAN_0,
+    DL_ADC12_INPUT_CHAN_1,
+    DL_ADC12_INPUT_CHAN_2,
+    DL_ADC12_INPUT_CHAN_3
+};
+
+uint8_t ch=0;
+
+uint16_t measurement_results[4] = {
+    0,
+    0,
+    0,
+    0
+};
+
+void ADC12_0_INST_IRQHandler(void)
+{
+    uint32_t irqval = DL_ADC12_getPendingInterrupt(ADC12_0_INST);
+    printf("irqval: %d", irqval);
+    switch (irqval) {
+        case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
+            measurement_results[ch] = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0)*3300/4096;
+            if (ch == 1) {
+                slot.measurement.voltage = (measurement_results[1]-measurement_results[0])*(56+100)/56;
+            }
+            if (++ch == 4) {
+                ch = 0;
+            }
+            DL_ADC12_stopConversion(ADC12_0_INST);
+            DL_ADC12_configConversionMem(ADC12_0_INST, 
+                                         ADC12_0_ADCMEM_0,
+                                         measurement_channels[ch], 
+                                         DL_ADC12_REFERENCE_VOLTAGE_VDDA, 
+                                         DL_ADC12_SAMPLE_TIMER_SOURCE_SCOMP0, 
+                                         DL_ADC12_AVERAGING_MODE_ENABLED,
+                                         DL_ADC12_BURN_OUT_SOURCE_DISABLED, 
+                                         DL_ADC12_TRIGGER_MODE_AUTO_NEXT, 
+                                         DL_ADC12_WINDOWS_COMP_MODE_DISABLED);
+            DL_ADC12_enableConversions(ADC12_0_INST);
+            DL_ADC12_startConversion(ADC12_0_INST);
+            break;
+        default:
+            break;
+    }
+}

+ 4 - 0
src/peripherals/adc.h

@@ -0,0 +1,4 @@
+#ifndef ADC_H
+#define ADC_H
+
+#endif

+ 0 - 66
src/peripherals/adc/adc.c

@@ -1,66 +0,0 @@
-#include "src/battery_data/battery.h"
-#include "src/peripherals/adc/adc.h"
-#include <stdint.h>
-#include <stdio.h>
-#include "src/peripherals/adc/adc_interface.h"
-#include "src/interfaces/i2c_controller.h"
-#include "src/config.h"
-
-
-//static ADC_Params adc_params;
-static ADC_MeasurementState adc_state = ADC_STATE_CONFIGURE;
-
-
-uint16_t read_adc_channel(uint8_t slot, uint8_t channel) {
-  //printf("Slot: %d, Channel: %d\n", slot, channel);
-  ADC_Params adc_params= {0}; 
-  uint16_t adc_voltage = 0;
-  while (adc_state != ADC_STATE_DONE) {
-    switch (adc_state) {
-        
-        case ADC_STATE_CONFIGURE:
-            adc_params.channel = channel;
-            adc_params.continuous = ADC_MEASUREMENT_IS_CONTINUOUS;
-            
-            adc_params.gain = 1;
-            adc_params.resolution = 12;
-            if (channel == 1 || channel == 2) {
-                adc_params.factor = 1000;
-            } else {
-                adc_params.factor = 1;
-            }
-
-            //printf("Config: Memory address of batteries: %p\n", &batteries[0]);
-            if (!adc_hal.configure(slot, &adc_params)) {
-                return 0xffff;
-            }
-            if (adc_params.continuous != 1) {
-                // in one shot mode we wait first to get the result
-                adc_state = ADC_STATE_WAIT;
-            } else {
-                // in continuous mode we can directly read
-                adc_state = ADC_STATE_READ;
-                delay_cycles(ADC_CONTINUOUS_DELAY_CYCLES_VOLTAGES);
-            }
-            break;
-
-        case ADC_STATE_WAIT:
-            if(adc_hal.is_ready(slot, &adc_params)){
-                adc_state = ADC_STATE_READ;
-            }
-            break;
-
-        case ADC_STATE_READ:
-            adc_voltage = adc_hal.read_voltage(slot, &adc_params);
-            adc_state = ADC_STATE_DONE;
-            break;
-        default:
-            channel = 0;
-            adc_state = ADC_STATE_CONFIGURE;
-            break;
-    }
-  }
-
-  adc_state = ADC_STATE_CONFIGURE;
-  return adc_voltage;
-}

+ 0 - 17
src/peripherals/adc/adc.h

@@ -1,17 +0,0 @@
-
-#ifndef ADC_H_
-#include "ti/driverlib/dl_i2c.h"
-#include "ti_msp_dl_config.h"
-#include "src/battery_data/battery.h"
-
-//ADC states
-typedef enum{
-    ADC_STATE_CONFIGURE,
-    ADC_STATE_WAIT,
-    ADC_STATE_READ,
-    ADC_STATE_DONE
-}ADC_MeasurementState;
-
-uint16_t read_adc_channel(uint8_t slot, uint8_t channel); //belongs to battery module
-
-#endif

+ 0 - 229
src/peripherals/adc/adc_hal.c

@@ -1,229 +0,0 @@
-/*
-This adc file will handle:
-- packet configuration: bool
-- adc ready flag: bool
-- adc_read_raw: int_16
-
-Function to read ADC DATA: This function simply retrieves the ADC raw digital
-output as 16-bit signed integer.
-* The value returned is not yet converted to VOLTAGE.
-* adc_data[2]: Buffer with an array of size 2, to store two bytes of ADC data.
-*             Since, the ADC output consists of two 8-bit bytes:
-*             - adc_data[0] (MSB)
-*             - adc_data[1] (LSB)
-* Next, we verify if the the I2C bus is busy using the function in the
-driverlib: DL_I2C_get ControllerStatus
-*       - Prevents collisions by ensuring no two I2C device is using the same
-bus before initializing.
-* BEGIN I2C READ operation to request 2 bytes from the ADC->
-DL_I2C_startControllerTransfer()
-* Parameters:
-    - I2C_controller_INST: Refererence to the I2C instance bring used.
-    - DEF_TARGET_ADDR_ADC: Address of the ADC
-    - DL_I2C_CONTROLLER_DIRECTION_RX: Indicates that we want to receive the data
-from ADC
-    - 2: Specifies that we expect 2 bytes from the ADC
-* WAIT for the data to be received: (DL_I2C_getControllerStatus())
-    - Waits until the ADC sends the data over I2C.
-    - Ensures that the data transfer is complete before proceeding.
-* READ the two bytes of ADc Data:
-    - adc_data[0] : MSB
-    - adc_data[1] : LSB
-    - adc_data[2] : config_bytes
-    ADC sends its 16-bit value in two parts over 8-bit I2C data frames.
-* COMBINE the two bytes into 16-bit Integer:
-    - Shifts the MSB(first byte) left by 8 bits to make space for LSB.
-    - Performs a bitwise OR operation to combine MSB and LSB into a single
-16-bit number.
-* PRINT HEXADEC and DECIMAL format for DEBUGGING.
-* Output code is in binary and is proportional to the Input Voltage and PGA
-settings.
-* From the datasheet:
-https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/22226a.pdf
-    - Equation 4.4 is being used to convert the output codes to input voltage
-
-* The ACK bits after conversion is issued by the Master, when the device
-receives a READ command, it outputs two data bytes followed by a configuration
-register in 16 bit conversion mode the MSB(=sign bit) of the first data type is
-D15.
-*/
-
-
-#include "src/interfaces/i2c_controller.h"
-#include "src/peripherals/adc/adc_interface.h"
-#include "ti_msp_dl_config.h"
-#include <stdio.h>
-#include "src/battery_data/battery.h"
-#include "src/config.h"
-
-/*
-* Creating Configuartion Register as mentioned in the datasheet: https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/22226a.pdf
-* Under section 5.2 Configuration Register
-* The function is private to ADC and is can only be called in this file
-*/
-static uint8_t construct_config_byte(ADC_Params *params) {
-
-    uint8_t config = 0;
-    
-    config |= ((params->channel) << 5); // Channel Selection (Bits 6-5)
-    
-    if (params->continuous == 1) {
-        config |= (1 << 4); // Continous mode
-    } else {
-        // One-Shot mode
-        // Bit set to zero, BUT the Ready bit needs to be set to start meausrement
-        // (read/not write bit)
-        config |= (1 << 7);
-    }
-    
-    switch (params->resolution) {
-        
-        case 12:
-            config |= (0b00 << 2);
-            break;
-        case 14:
-            config |= (0b01 << 2);
-            break;
-        case 16:
-            config |= (0b10 << 2);
-            break;
-        default:
-            //printf("ERROR: Invalid Resolution!\n");
-            return 0;
-    }
-    
-    switch (params->gain) {
-        
-        case 1:
-            config |= (0b00);
-            break;
-        case 2:
-            config |= (0b01);
-            break;
-        case 4:
-            config |= (0b10);
-            break;
-        case 8:
-            config |= (0b11);
-            break;
-        default:
-            //printf("ERROR: Invalid Gain!\n");
-            return 0;
-    }
-
-    return config;
-}
-
-/* Tansmit Data from MCU to ADC:  Function to SET configuration to ADC over
- * I2C*/
-
-static bool adc_configure(uint8_t slot_id, ADC_Params *params) {
-    controllerTxPackage.packet[0] = construct_config_byte(params);
-
-    // Wait for I2C Bus to be Free**
-    uint32_t n_cycles = 0;
-    while ((DL_I2C_getControllerStatus(I2C_controller_INST) &
-            DL_I2C_CONTROLLER_STATUS_BUSY_BUS) && n_cycles++ < MAX_I2C_WAIT_RX)
-        ;
-    if (n_cycles == MAX_I2C_WAIT_RX) {
-        printf("Error in reading from I2C Bus: Bus is not getting ready on config byte\n");
-    }
-    if(controllerTxPackage.packet[0] == 0xFF){
-        // this clause can only happen if the internal memory management is messed up?!
-        // the config function should take care that this is never the case
-#ifdef DEBUG_ADC
-        printf("[ADC] Unable to send config bytes\n");
-#endif
-        *battery_slots[slot_id].state = SLOT_ERR_CONFIGBYTE;
-        return false;
-    } 
-    // Prepare TX Buffer
-    controllerTxPackage.len = 1;
-    controllerTxPackage.count = 0;
-    controllerTxPackage.complete = false;
-    i2c_hal.write(battery_slots[slot_id].adc_addr);
-    
-    n_cycles = 0;
-    while(!controllerTxPackage.complete && n_cycles++ < MAX_I2C_WAIT_RX);
-    if (n_cycles == MAX_I2C_WAIT_RX) {
-#ifdef DEBUG_ADC
-        printf("[ADC] No Response to the config byte!\n");
-#endif
-        return false;
-    }
-    return true;
-}
-
-
-/*
-READY BIT:
-    This bit is the data ready flag. In read mode, this bit indicates if the
-output register has been updated with a latest conversion result. In One-Shot
-Conversion mode, writing this bit to “1” initiates a new conversion.
-
-    1= Output Register has not been updated
-    0= Output Register has been updated
-
-*/
-
-static bool adc_is_ready(uint8_t slot_id, ADC_Params *params) {
-    uint8_t adc_address = battery_slots[slot_id].adc_addr;
-    controllerRxPackage.len = 3;
-    controllerRxPackage.count = 0;
-    controllerRxPackage.complete = false;
-
-    i2c_hal.read(adc_address);
-    // Ready bit is bit 7
-    while(!controllerRxPackage.complete);
-    uint8_t config_adc_byte = controllerRxPackage.packet[2];
-    bool ready = (config_adc_byte & 0x80) == 1;
-    return ready;
-}
-
-
-static int16_t read_adc_raw_data(uint8_t slot_id, ADC_Params *params) {
-
-    // Buffer for ADC data (MSB, LSB, Config Byte)
-    uint32_t raw_adc = 0;
-
-    controllerRxPackage.len = 3;
-    controllerRxPackage.count = 0;
-    controllerRxPackage.complete = false;
-    
-    i2c_hal.read(battery_slots[slot_id].adc_addr);
-    uint32_t n_cycles = 0;
-    while(!controllerRxPackage.complete && n_cycles++ < MAX_I2C_WAIT_RX);
-    if (n_cycles == MAX_I2C_WAIT_RX) {
-        return 0xffff;
-    }
-    uint8_t msb = controllerRxPackage.packet[0];
-    uint8_t lsb = controllerRxPackage.packet[1];
-    uint8_t config_adc_byte = controllerRxPackage.packet[2];
-
-    uint32_t max_adc_val = 0;
-
-    switch (params->resolution) {
-        case 12: // 12-bit
-            raw_adc = ((msb & 0b00001111) << 8) | lsb;
-            max_adc_val = 4096;
-            break;
-        case 14: // 14-bit
-            raw_adc = ((msb & 0b00111111) << 8) | lsb;
-            max_adc_val = 16384;
-            break;
-        case 16: // 16-bit
-            raw_adc = ((msb & 0b11111111) << 8) | lsb;
-            max_adc_val = 65536;
-            break;
-        default:
-            //printf("Error: Unknown ADC Resolution!\n");
-            break;
-    }
-    return raw_adc * params->factor * 2048 / (max_adc_val/2) / params->gain;;
-}
-
-ADC_Interface adc_hal= {
-    .configure= adc_configure,
-    .read_voltage = read_adc_raw_data,
-    .is_ready= adc_is_ready,
-};

+ 0 - 26
src/peripherals/adc/adc_interface.h

@@ -1,26 +0,0 @@
-#ifndef ADC_INTERFACE_H_
-#define ADC_INTERFACE_H_
-
-#include <stdint.h>
-#include <stdbool.h>
-
-#define ADC_VREF_MV (2048)
-
-typedef struct {
-    uint8_t channel;
-    uint8_t resolution;
-    bool continuous;
-    uint8_t gain;
-    uint16_t factor;
-} ADC_Params;
-
-// 14.04: added pointer for ADC_Params
-typedef struct {
-    bool (*configure)(uint8_t slot_id, ADC_Params *params);
-    int16_t (*read_voltage)(uint8_t slot_id, ADC_Params *params);
-    bool (*is_ready)(uint8_t slot_id, ADC_Params *params);
-} ADC_Interface;
-
-extern ADC_Interface adc_hal;
-
-#endif

+ 0 - 33
src/peripherals/dac/dac.c

@@ -1,33 +0,0 @@
-#include "dac.h"
-#include "src/interfaces/i2c_controller.h"
-#include "ti/driverlib/dl_i2c.h"
-#include "ti_msp_dl_config.h"
-#include "src/battery_data/battery.h"
-#include <stdint.h>
-#include <stdio.h>
-#include "src/config.h"
-
-bool DAC_SingleWrite(uint8_t slot, uint16_t channel_value) {
-    if(channel_value > MAX_DAC_VALUE) {
-#ifdef DEBUG_DAC
-        printf("DAC Error: channel_value out of range. Must be between 0 and %d\n", MAX_DAC_VALUE);
-#endif
-        *battery_slots[slot].state = SLOT_WARN_DAC_INVALID_VALUE;
-        return false;
-    }
-    controllerTxPackage.len = 3;
-    controllerTxPackage.packet[0] = (0b01000000 | slot << 1);
-    controllerTxPackage.packet[1] = (0x10) | ((channel_value >> 8) & 0x0F);
-    controllerTxPackage.packet[2] = (channel_value & 0xFF);
-
-    // Write data to DAC
-    if (!i2c_hal.write(DAC_TARGET_ADDRESS)) {
-#ifdef DEBUG_DAC
-        printf("I2C DAC Write Error: Failed to write to DAC.\n");
-#endif
-        *battery_slots[slot].state = SLOT_ERR_DAC_WRITE_FAILED;
-        return false;
-    }
-
-    return true;
-}

+ 0 - 13
src/peripherals/dac/dac.h

@@ -1,13 +0,0 @@
-#ifndef DAC_H_
-#define DAC_H_
-#include "ti/driverlib/dl_i2c.h"
-#include "ti_msp_dl_config.h"
-#include <stdbool.h>
-#include "src/config.h"
-
-#define DAC_VREF_MV 2048
-#define MAX_DAC_VALUE 4095
-
-bool DAC_SingleWrite(uint8_t slot, uint16_t channel_value);
-
-#endif

+ 0 - 0
src/peripherals/temp.c


+ 0 - 0
src/peripherals/temp.h


+ 0 - 40
src/peripherals/temp/tmp1075.c

@@ -1,40 +0,0 @@
-
-#include "src/peripherals/temp/tmp1075.h"
-
-#include "src/interfaces/i2c_controller.h"
-
-#include <stdio.h>
-
-/**
- * Read Temperature
- * of a former initalized TMP1075 sensor
- */
-
-volatile uint8_t addr_offset = 0;
-
-uint16_t read_temperature(uint8_t slot) {
-
-    // Prepare TX Buffer
-    controllerTxPackage.len = 1;
-    controllerTxPackage.count = 0;
-    controllerTxPackage.complete = false;
-    controllerTxPackage.packet[0] = 0x00;
-    i2c_hal.write(TMP1075_BASE_ADDRESS + slot + addr_offset);
-
-    controllerRxPackage.len = 3;
-    controllerRxPackage.count = 0;
-    controllerRxPackage.complete = false;
-    i2c_hal.read(TMP1075_BASE_ADDRESS + slot + addr_offset);
-
-    while(!controllerRxPackage.complete);
-    uint16_t byte1 = controllerRxPackage.packet[0];
-    uint8_t byte2 = controllerRxPackage.packet[1];
-    
-    uint16_t temp = ((byte1 << 4) | (byte2 >> 4)) * 62.5;
-
-#ifdef DEBUG_TEMPERATURE
-    printf("Temperatur von slot %d: 0x%02X 0x%02X -> %d \n", slot, byte1, byte2, temp);
-#endif
-
-    return temp;
-}

+ 0 - 12
src/peripherals/temp/tmp1075.h

@@ -1,12 +0,0 @@
-#ifndef TMP1075_H_
-#define TMP1075_H_
-
-#include <stdint.h>
-
-#define TMP1075_BASE_ADDRESS 0x48
-
-uint16_t read_temperature(uint8_t slot);
-
-extern volatile uint8_t addr_offset;
-
-#endif