Procházet zdrojové kódy

* i2c-target speicher-optimiert
* battery.c: debug level angepasst
* config.h: adc delay time angepasst

Heinrich Blatt před 7 měsíci
rodič
revize
ede0a220f9
3 změnil soubory, kde provedl 9 přidání a 11 odebrání
  1. 2 2
      src/battery_data/battery.c
  2. 4 4
      src/config.h
  3. 3 5
      src/interfaces/i2c_target.c

+ 2 - 2
src/battery_data/battery.c

@@ -96,7 +96,7 @@ static void batteryslots_read_state(uint8_t slot) {
         // read channel 1 (current reading on charge)
         bare_voltage = read_adc_channel(slot, 1);
         battery_slots[slot].measurement.current = bare_voltage*10/1000; // current comes in microvolts
-#ifdef DEBUG_TRACE_CTRL
+#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 {
@@ -111,7 +111,7 @@ static void batteryslots_read_state(uint8_t slot) {
 
         // calculate the result
         battery_slots[slot].measurement.current = (int16_t)(hi_power/battery_slots[slot].measurement.voltage)*-1;
-#ifdef DEBUG_TRACE_CTRL
+#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
     }

+ 4 - 4
src/config.h

@@ -19,7 +19,7 @@
 // production e.g. 320000 (10ms) (Validate that this is really the case!)
 // should be large for debugging, (e.g. )
 // small for production
-#define MAINLOOP_DELAY (32000000*2)
+#define MAINLOOP_DELAY (3200000)
 
 // i2c address for acting as target
 // (based on the GPIO 1 integer is added)
@@ -47,13 +47,13 @@
 #define DEBUG_CTRL 1
 
 // printf trace: put also the transition messages
-#define DEBUG_TRACE_CTRL 1
+//#define DEBUG_TRACE_CTRL 1
 
 // printf i2c errors
 #define DEBUG_I2C_ERR 1
 
 // printf i2c traffic (tx)
-#define DEBUG_I2C_TX 1
+//#define DEBUG_I2C_TX 1
 
 // printf target i2c interrupts (where the mcu is the i2c target)
 #define DEBUG_TARGET 1
@@ -88,7 +88,7 @@
 // ensure that the measurement is ready. (set the define to 0 if it should be one-shot)
 // (it could be the case that the channel is switched and wrong data is fetched)
 #define ADC_MEASUREMENT_IS_CONTINUOUS 1
-#define ADC_CONTINUOUS_DELAY_CYCLES (32000) // 32000 is 1ms (32MHz clock)
+#define ADC_CONTINUOUS_DELAY_CYCLES (320000) // 32000 is 1ms (32MHz clock)
 
 // Packet buffer sizes for RX and TX for the
 // controller mode only

+ 3 - 5
src/interfaces/i2c_target.c

@@ -50,14 +50,12 @@ void mcu_i2c_handle(I2C_Regs *i2c) {
             return;
         }
 
-        // Copying the memory block from battery_measure struct to tx_buffer:
-        // @todo check if this memcpy is even needed, probably 
-        // &battery_slots[slot].measurement can be directly used as buffer for DL_I2C_fillTargetTXFIFO
-        memcpy(tx_buffer, &battery_slots[slot].measurement, sizeof(BatteryMeasurement));
-        DL_I2C_fillTargetTXFIFO(i2c, tx_buffer, sizeof(BatteryMeasurement));
+        DL_I2C_fillTargetTXFIFO(i2c, &battery_slots[slot].measurement, sizeof(BatteryMeasurement));
+
 #ifdef DEBUG_TARGET
         printf("Battery Measurement Sent to MCU. \n");
 #endif
+        printf("");
         DL_I2C_flushTargetTXFIFO(i2c);
   
     } else if (receivedCommand == CMD_SET_CURRENT) {