Browse Source

* Add dynamic adressing support (based on gpio 13, including sysconfig)
* memory optimization: Compiler compression level increased to 2, else it would not fit into memory

Heinrich Blatt 7 months ago
parent
commit
576e1bf255
6 changed files with 41 additions and 10 deletions
  1. 1 1
      .cproject
  2. 2 0
      main_target.c
  3. 14 7
      main_target.syscfg
  4. 5 1
      src/config.h
  5. 17 1
      src/interfaces/i2c_target.c
  6. 2 0
      src/interfaces/i2c_target.h

+ 1 - 1
.cproject

@@ -36,7 +36,7 @@
                                 <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.MFLOAT_ABI.1390698216" 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.938260042" 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.1905157192" 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.1841069767" superClass="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL" value="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL.0" valueType="enumerated"/>
+                                <option id="com.ti.ccstudio.buildDefinitions.TMS470_TICLANG_4.0.compilerID.OPT_LEVEL.1841069767" 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.1072446908" 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}"/>

+ 2 - 0
main_target.c

@@ -104,6 +104,8 @@ int main(void)
     battery_slotmgr.init();
     NVIC_EnableIRQ(I2C_controller_INST_INT_IRQN);
     NVIC_EnableIRQ(I2C_target_INST_INT_IRQN);
+
+    initialize_target_address();
     
     while (1) {
 

+ 14 - 7
main_target.syscfg

@@ -9,6 +9,8 @@
 /**
  * Import the modules used in this configuration.
  */
+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();
@@ -20,6 +22,15 @@ const ProjectConfig = scripting.addModule("/ti/project_config/ProjectConfig");
 /**
  * Write custom configuration values to the imported modules.
  */
+GPIO1.$name                       = "GPIOS";
+GPIO1.associatedPins[0].direction = "INPUT";
+GPIO1.associatedPins[0].$name     = "ADDR";
+
+const Board                       = scripting.addModule("/ti/driverlib/Board", {}, false);
+Board.peripheral.$assign          = "DEBUGSS";
+Board.peripheral.swclkPin.$assign = "PA20";
+Board.peripheral.swdioPin.$assign = "PA19";
+
 I2C1.$name                             = "I2C_controller";
 I2C1.basicEnableController             = true;
 I2C1.intController                     = ["ARBITRATION_LOST","NACK","RXFIFO_TRIGGER","RX_DONE","TXFIFO_TRIGGER","TX_DONE"];
@@ -39,11 +50,6 @@ I2C1.sclPinConfig.passedPeripheralType = scripting.forceWrite("Digital");
 I2C1.sclPinConfig.enableConfig         = true;
 I2C1.sclPinConfig.internalResistor     = "PULL_UP";
 
-const Board                       = scripting.addModule("/ti/driverlib/Board", {}, false);
-Board.peripheral.$assign          = "DEBUGSS";
-Board.peripheral.swclkPin.$assign = "PA20";
-Board.peripheral.swdioPin.$assign = "PA19";
-
 I2C2.$name                             = "I2C_target";
 I2C2.basicEnableTarget                 = true;
 I2C2.basicTargetAddress                = 0x48;
@@ -80,5 +86,6 @@ 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";
-PWM1.peripheral.$suggestSolution = "TIMG1";
+GPIO1.associatedPins[0].pin.$suggestSolution = "PA2";
+I2C2.peripheral.$suggestSolution             = "I2C0";
+PWM1.peripheral.$suggestSolution             = "TIMG1";

+ 5 - 1
src/config.h

@@ -21,6 +21,10 @@
 // small for production
 #define MAINLOOP_DELAY (32000000*5)
 
+// i2c address for acting as target
+// (based on the GPIO 1 integer is added)
+#define I2C_TARGET_BASE_ADDRESS 0x48
+
 //------------
 // Section for configuring debugging outputs
 //------------
@@ -60,7 +64,7 @@
 #define OVERTEMPERATURE_TRESHOLD 43
 
 //------------
-// Section for configuring i2c values
+// Section for configuring i2c master values
 //------------
 // dac address
 #define DAC_TARGET_ADDRESS 0x60

+ 17 - 1
src/interfaces/i2c_target.c

@@ -1,7 +1,6 @@
 /*
 References:
 https://stackoverflow.com/questions/246127/why-is-volatile-needed-in-c
-
 */
 
 #include "i2c_target.h"
@@ -11,6 +10,23 @@ https://stackoverflow.com/questions/246127/why-is-volatile-needed-in-c
 #include <string.h>
 #include "src/peripherals/dac/dac.h"
 #include <inttypes.h>
+#include "src/config.h"
+#include "ti_msp_dl_config.h"
+
+/**
+ * Dynamic addressing function
+ * 1. set resistor to pullup
+ * 2. measure gpio:
+ *   is it up, set the address +0, else set it +1
+ * 3. disable the pullup again, so there is no current wasted
+ */
+void initialize_target_address() {
+    uint8_t add = 0;
+    if (DL_GPIO_readPins(GPIOS_PORT, GPIOS_ADDR_PIN)) {
+        add = 1;
+    }
+    DL_I2C_setTargetAddress(I2C_target_INST, I2C_TARGET_BASE_ADDRESS+add);
+}
 
 /*Function to Rx and Tx data from Target to Controller*/
 // The code has multiple i2c instances (multiple MCUs connected) from which we

+ 2 - 0
src/interfaces/i2c_target.h

@@ -14,5 +14,7 @@ typedef enum{
     CMD_CELAR_ERR= 0x08
 }mcu_I2C_command;
 
+void initialize_target_address();
+
 void mcu_i2c_handle(I2C_Regs *i2c);
 #endif