Browse Source

Konfigurationen in externe config.h ausgelagert

Heinrich Blatt 8 tháng trước cách đây
mục cha
commit
7a3ef5c37a

+ 2 - 6
main_target.c

@@ -5,9 +5,7 @@
 #include <stdio.h>
 #include "src/interfaces/i2c_target.h"
 #include "src/interfaces/i2c_controller.h"
-
-
-#define DELAY_CYCLE  (50000000)
+#include "src/config.h"
 
 volatile bool mcu_CommandPending= false;
 
@@ -129,11 +127,9 @@ int main(void)
             } else {
                 battery_slotmgr.disable(slot);
             }
-
-            
         }
         
-        delay_cycles(DELAY_CYCLE);
+        delay_cycles(MAINLOOP_DELAY);
         
     }
 }

+ 3 - 18
src/battery_data/battery.h

@@ -5,30 +5,15 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include "ti/driverlib/dl_timerg.h"
-//define macro to be used by multiple files in the program witout the variable being overwritten
-//for testing
-#define NUM_SLOTS (1)
-
-
-//Battery Tolerance
-// how much tolerance do we allow if we charge / discharge before we 
-// trigger the control loop to adjust the value
-#define BATTERY_CURRENT_THRESHOLD (5)
-
-// for i2c communication to know battery health
-#define SOV_THRESHOLD_MV (6000)
-#define HOV_THRESHOLD_MV (8000)
-
-#define TEMPERATURE_MAX_C (60)
+#include "src/config.h"
 
 //Battery Discharge Safety Check
 typedef enum{
     SLOT_STATE_OK= 0x00,
     SLOT_STATE_SOV= 0x01,
-    SLOT_STATE_HOV= 0x02,
+    SLOT_ERR_HOV= (0x02 | 0x80),
 
-    SLOT_WARN_OVERTEMPERATURE = 0x03,
-    SLOT_ERR_OVERTEMPERATURE= (0x04 | 0x80), // first bit indicates complete error
+    SLOT_ERR_OVERTEMPERATURE= (0x03 | 0x80), // first bit indicates complete error
 
     // Control error states
     SLOT_WARN_LOWER_DAC_NOT_POSSIBLE=0x10,

+ 53 - 0
src/config.h

@@ -0,0 +1,53 @@
+// globals definition
+
+//------------------------
+// Configuration section
+
+// How many slots do we currently support?
+// use 1 for debugging, 4 for production
+#define NUM_SLOTS 1
+
+//Battery Tolerance
+// how much tolerance do we allow if we charge / discharge before we 
+// trigger the control loop to adjust the value
+#define BATTERY_CURRENT_THRESHOLD 5
+
+// Mainloop sleep time
+// Time to sleep between two mainloop intervals
+// We have a 32 MHz clock
+// debugging e.g. 32000000*5 -> 5s
+// 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*5)
+
+//------------
+// Section for configuring error tresholds
+//------------
+
+// soft overvoltage treshold before getting into the soft overvoltage state
+#define SOV_THRESHOLD_MV 6000
+
+// hard overvoltage treshold for getting into the hard overvoltage state (error)
+#define HOV_THRESHOLD_MV 8000
+
+// define the temperature error state
+#define OVERTEMPERATURE_TRESHOLD 43
+
+//------------
+// Section for configuring i2c values
+//------------
+// dac address
+#define DAC_TARGET_ADDRESS 0x60
+
+// ADC base address
+// it is assumed the slots are ADC ADC_TARGET_BASE_ADDRESS slot 0, 
+// ADC_TARGET_BASE_ADDRESS+1 slot 1, etc.
+#define ADC_TARGET_BASE_ADDRESS 0x68
+
+
+// Packet buffer sizes for RX and TX for the
+// controller mode only
+// (target for the other MCU is treated differently)
+#define I2C_TX_MAX_PACKET_SIZE 5
+#define I2C_RX_MAX_PACKET_SIZE 5  

+ 1 - 4
src/interfaces/i2c_controller.h

@@ -24,10 +24,7 @@ Reference:
 
 #include <stdint.h>
 #include <stdbool.h>
-
-//Maximum packet sizes
-#define I2C_TX_MAX_PACKET_SIZE (4)  
-#define I2C_RX_MAX_PACKET_SIZE (4)  
+#include "src/config.h"
 
 typedef struct {
     volatile bool complete;

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

@@ -4,7 +4,6 @@
 #include <stdint.h>
 #include <stdbool.h>
 
-#define ADC_TARGET_BASE_ADDRESS (0x68)
 #define ADC_VREF_MV (2048)
 
 typedef struct {

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

@@ -5,6 +5,7 @@
 #include "src/battery_data/battery.h"
 #include <stdint.h>
 #include <stdio.h>
+#include "src/config.h"
 
 
 // The device updates all DAC analog output(vout) at the same time

+ 1 - 1
src/peripherals/dac/dac.h

@@ -2,8 +2,8 @@
 #include "ti/driverlib/dl_i2c.h"
 #include "ti_msp_dl_config.h"
 #include <stdbool.h>
+#include "src/config.h"
 
-#define DAC_TARGET_ADDRESS (0x60)
 #define DAC_VREF_MV 2048
 #define MAX_DAC_VALUE 4095