From 84d3f0b1fb35cb7d95f7e00ed556ac9d870fbed3 Mon Sep 17 00:00:00 2001 From: Luke Oxley Date: Thu, 1 Feb 2024 10:38:21 -0500 Subject: [PATCH] Abox HIL and DAQ (#89) --- .vscode/launch.json | 6 ++--- common/daq/daq_config.json | 12 ++++++++-- source/a_box/daq/daq.c | 10 ++++++++ source/a_box/daq/daq.h | 10 +++++++- source/a_box/main.c | 25 +++++++++++++------- source/a_box/main.h | 47 +++++++++++++++----------------------- source/a_box/tmu/tmu.c | 22 +++++++++++------- source/a_box/tmu/tmu.h | 3 +++ 8 files changed, 85 insertions(+), 50 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index aab6837d..96ad7bae 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -177,7 +177,7 @@ }, { "name": "A_Box", "cwd": "${workspaceRoot}", - "executable": "./output/precharge/precharge.elf", + "executable": "./output/a_box/a_box.elf", "request": "launch", "type": "cortex-debug", "servertype": "openocd", @@ -189,9 +189,9 @@ ], "debuggerArgs": [ "-d", - "${workspaceFolder}/source/precharge" + "${workspaceFolder}/source/a_box" ], - // "preLaunchTask": "build", + "preLaunchTask": "build", "runToEntryPoint": "main" }, { "name": "Driveline Front", diff --git a/common/daq/daq_config.json b/common/daq/daq_config.json index c22b6bb2..601d17c2 100644 --- a/common/daq/daq_config.json +++ b/common/daq/daq_config.json @@ -41,11 +41,19 @@ }, { "node_name":"a_box", - "includes":"#include \"orion.h\"", + "includes":"#include \"orion.h\"\n#include \"tmu.h\"\n#include \"main.h\"", "variables": [ {"var_name":"charge_request_user", "access_phrase":"charge_request_user", "read_only": false, "type":"uint8_t", "length": 1}, {"var_name":"user_charge_current_request", "access_phrase":"user_charge_current_request", "read_only": false, "type":"uint16_t", "length": 16}, - {"var_name":"user_charge_voltage_request", "access_phrase":"user_charge_voltage_request", "read_only": false, "type":"uint16_t", "length": 16} + {"var_name":"user_charge_voltage_request", "access_phrase":"user_charge_voltage_request", "read_only": false, "type":"uint16_t", "length": 16}, + {"var_name":"tmu_daq_override", "access_phrase": "tmu_daq_override", "read_only": false, "type":"uint8_t", "length": 1}, + {"var_name":"tmu_daq_therm", "access_phrase": "tmu_daq_therm", "read_only": false, "type": "uint8_t", "length":4}, + {"var_name":"tmu_1", "access_phrase": "adc_readings.tmu_1", "read_only": true, "type": "uint16_t", "length": 12, "unit": "12-bit adc"}, + {"var_name":"tmu_2", "access_phrase": "adc_readings.tmu_2", "read_only": true, "type": "uint16_t", "length": 12, "unit": "12-bit adc"}, + {"var_name":"tmu_3", "access_phrase": "adc_readings.tmu_3", "read_only": true, "type": "uint16_t", "length": 12, "unit": "12-bit adc"}, + {"var_name":"tmu_4", "access_phrase": "adc_readings.tmu_4", "read_only": true, "type": "uint16_t", "length": 12, "unit": "12-bit adc"}, + {"var_name":"bms_daq_override", "access_phrase": "bms_daq_override", "read_only": false, "type":"uint8_t", "length": 1}, + {"var_name":"bms_daq_stat", "access_phrase": "bms_daq_stat", "read_only": false, "type": "uint8_t", "length":1} ], "files":[] }, diff --git a/source/a_box/daq/daq.c b/source/a_box/daq/daq.c index d2b3ba77..51b000de 100644 --- a/source/a_box/daq/daq.c +++ b/source/a_box/daq/daq.c @@ -15,6 +15,8 @@ // BEGIN AUTO VAR INCLUDES #include "orion.h" +#include "tmu.h" +#include "main.h" // END AUTO VAR INCLUDES // BEGIN AUTO VAR DEFS @@ -22,6 +24,14 @@ daq_variable_t tracked_vars[NUM_VARS] = { {.is_read_only=0, .bit_length=1, .read_var_a=&charge_request_user, .write_var_a=&charge_request_user, }, {.is_read_only=0, .bit_length=16, .read_var_a=&user_charge_current_request, .write_var_a=&user_charge_current_request, }, {.is_read_only=0, .bit_length=16, .read_var_a=&user_charge_voltage_request, .write_var_a=&user_charge_voltage_request, }, + {.is_read_only=0, .bit_length=1, .read_var_a=&tmu_daq_override, .write_var_a=&tmu_daq_override, }, + {.is_read_only=0, .bit_length=4, .read_var_a=&tmu_daq_therm, .write_var_a=&tmu_daq_therm, }, + {.is_read_only=1, .bit_length=12, .read_var_a=&adc_readings.tmu_1, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=12, .read_var_a=&adc_readings.tmu_2, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=12, .read_var_a=&adc_readings.tmu_3, .write_var_a=NULL, }, + {.is_read_only=1, .bit_length=12, .read_var_a=&adc_readings.tmu_4, .write_var_a=NULL, }, + {.is_read_only=0, .bit_length=1, .read_var_a=&bms_daq_override, .write_var_a=&bms_daq_override, }, + {.is_read_only=0, .bit_length=1, .read_var_a=&bms_daq_stat, .write_var_a=&bms_daq_stat, }, }; // END AUTO VAR DEFS diff --git a/source/a_box/daq/daq.h b/source/a_box/daq/daq.h index 86079d93..9838bdcf 100644 --- a/source/a_box/daq/daq.h +++ b/source/a_box/daq/daq.h @@ -19,13 +19,21 @@ #define DAQ_UPDATE_PERIOD 15 // ms // BEGIN AUTO VAR COUNT -#define NUM_VARS 3 +#define NUM_VARS 11 // END AUTO VAR COUNT // BEGIN AUTO VAR IDs #define DAQ_ID_CHARGE_REQUEST_USER 0 #define DAQ_ID_USER_CHARGE_CURRENT_REQUEST 1 #define DAQ_ID_USER_CHARGE_VOLTAGE_REQUEST 2 +#define DAQ_ID_TMU_DAQ_OVERRIDE 3 +#define DAQ_ID_TMU_DAQ_THERM 4 +#define DAQ_ID_TMU_1 5 +#define DAQ_ID_TMU_2 6 +#define DAQ_ID_TMU_3 7 +#define DAQ_ID_TMU_4 8 +#define DAQ_ID_BMS_DAQ_OVERRIDE 9 +#define DAQ_ID_BMS_DAQ_STAT 10 // END AUTO VAR IDs // BEGIN AUTO FILE STRUCTS diff --git a/source/a_box/main.c b/source/a_box/main.c index e4e1a833..c44b11e8 100644 --- a/source/a_box/main.c +++ b/source/a_box/main.c @@ -32,7 +32,7 @@ GPIOInitConfig_t gpio_config[] = { GPIO_INIT_CANTX_PA12, // Status and HV Monitoring - GPIO_INIT_OUTPUT(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, GPIO_OUTPUT_LOW_SPEED), + GPIO_INIT_OUTPUT_OPEN_DRAIN(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_INPUT(IMD_HS_PWM_GPIO_Port, IMD_HS_PWM_Pin, GPIO_INPUT_OPEN_DRAIN), GPIO_INIT_INPUT(IMD_LS_PWM_GPIO_Port, IMD_LS_PWM_Pin, GPIO_INPUT_OPEN_DRAIN), GPIO_INIT_INPUT(IMD_STATUS_GPIO_Port, IMD_STATUS_Pin, GPIO_INPUT_OPEN_DRAIN), @@ -48,10 +48,10 @@ GPIOInitConfig_t gpio_config[] = { GPIO_INIT_OUTPUT(MUX_B_Port, MUX_B_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_OUTPUT(MUX_C_Port, MUX_C_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_OUTPUT(MUX_D_Port, MUX_D_Pin, GPIO_OUTPUT_LOW_SPEED), - GPIO_INIT_ANALOG(MUX_1_OUT_Port, MUX_1_OUT_Pin), - GPIO_INIT_ANALOG(MUX_2_OUT_Port, MUX_2_OUT_Pin), - GPIO_INIT_ANALOG(MUX_3_OUT_Port, MUX_3_OUT_Pin), - GPIO_INIT_ANALOG(MUX_4_OUT_Port, MUX_4_OUT_Pin), + GPIO_INIT_ANALOG(TMU_1_Port, TMU_1_Pin), + GPIO_INIT_ANALOG(TMU_2_Port, TMU_2_Pin), + GPIO_INIT_ANALOG(TMU_3_Port, TMU_3_Pin), + GPIO_INIT_ANALOG(TMU_4_Port, TMU_4_Pin), // Board Temp Measurement GPIO_INIT_ANALOG(BOARD_TEMP_Port, BOARD_TEMP_Pin), @@ -88,6 +88,9 @@ extern uint8_t orion_error; q_handle_t q_tx_can; q_handle_t q_rx_can; +bool bms_daq_override = false; +bool bms_daq_stat = false; + void PHAL_FaultHandler(); extern void HardFault_Handler(); @@ -179,6 +182,9 @@ int main (void) initCANParse(&q_rx_can); orionInit(); + bms_daq_override = false; + bms_daq_stat = false; + if (daqInit(&q_tx_can)) HardFault_Handler(); @@ -221,7 +227,7 @@ void preflightChecks(void) switch (state++) { case 0 : - if (!initTMU(&tmu)) { + if (initTMU(&tmu)) { PHAL_FaultHandler(); } @@ -296,12 +302,15 @@ void monitorStatus() // PHAL_writeGPIO(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, !bms_err); - PHAL_writeGPIO(ERROR_LED_GPIO_Port, ERROR_LED_Pin, bms_err); + if (bms_daq_override | tmu_daq_override) PHAL_toggleGPIO(ERROR_LED_GPIO_Port, ERROR_LED_Pin); + else PHAL_writeGPIO(ERROR_LED_GPIO_Port, ERROR_LED_Pin, bms_err); readTemps(&tmu); setFault(ID_IMD_FAULT, imd_err); - PHAL_writeGPIO(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, bms_err | imd_err); + uint8_t stat = bms_err | imd_err; + if (bms_daq_override) stat = bms_daq_stat; + PHAL_writeGPIO(BMS_STATUS_GPIO_Port, BMS_STATUS_Pin, stat); } void monitorTherm() { diff --git a/source/a_box/main.h b/source/a_box/main.h index 53992d83..e1e11c69 100644 --- a/source/a_box/main.h +++ b/source/a_box/main.h @@ -8,26 +8,13 @@ #define FAULT_NODE_NAME NODE_A_BOX -// SPI Accel -#define SPI_SCLK_GPIO_Port (GPIOA) -#define SPI_SCLK_Pin (5) -#define SPI_MISO_GPIO_Port (GPIOA) -#define SPI_MISO_Pin (6) -#define SPI_MOSI_GPIO_Port (GPIOA) -#define SPI_MOSI_Pin (7) -#define SPI_CS_ACEL_GPIO_Port (GPIOA) -#define SPI_CS_ACEL_Pin (3) -#define SPI_CS_GYRO_GPIO_Port (GPIOA) -#define SPI_CS_GYRO_Pin (2) -#define SPI_CS_TMU_GPIO_Port (GPIOD) -#define SPI_CS_TMU_GPIO_Pin (15) - - // Current Sense -#define I_SENSE_CH1_GPIO_Port (GPIOA) // ADC12_IN5 +#define I_SENSE_CH1_GPIO_Port (GPIOA) #define I_SENSE_CH1_Pin (0) -#define I_SENSE_CH2_GPIO_Port (GPIOA) // ADC12_IN6 +#define I_SENSE_CH1_ADC_CHNL (0) +#define I_SENSE_CH2_GPIO_Port (GPIOA) #define I_SENSE_CH2_Pin (1) +#define I_SENSE_CH2_ADC_CHNL (1) // BMS Status @@ -43,9 +30,9 @@ // IMD Data #define IMD_HS_PWM_GPIO_Port (GPIOB) -#define IMD_HS_PWM_Pin (6) -#define IMD_LS_PWM_GPIO_Port (GPIOB) -#define IMD_LS_PWM_Pin (7) +#define IMD_HS_PWM_Pin (3) +#define IMD_LS_PWM_GPIO_Port (GPIOA) +#define IMD_LS_PWM_Pin (15) #define IMD_STATUS_GPIO_Port (GPIOB) #define IMD_STATUS_Pin (5) @@ -70,14 +57,14 @@ #define MUX_D_Pin (6) //TMU Mux Output Pins -#define MUX_1_OUT_Port (GPIOC) -#define MUX_1_OUT_Pin (0) -#define MUX_2_OUT_Port (GPIOC) -#define MUX_2_OUT_Pin (1) -#define MUX_3_OUT_Port (GPIOC) -#define MUX_3_OUT_Pin (2) -#define MUX_4_OUT_Port (GPIOC) -#define MUX_4_OUT_Pin (3) +#define TMU_1_Port (GPIOC) +#define TMU_1_Pin (0) +#define TMU_2_Port (GPIOC) +#define TMU_2_Pin (1) +#define TMU_3_Port (GPIOC) +#define TMU_3_Pin (2) +#define TMU_4_Port (GPIOC) +#define TMU_4_Pin (3) // Board Temp #define BOARD_TEMP_Port (GPIOB) @@ -86,6 +73,7 @@ // 5V Monitoring #define VSENSE_5V_Port (GPIOA) #define VSENSE_5V_Pin (7) +#define VSENSE_5V_ADC_CHNL (7) // ADC Channels #define TMU_1_ADC_CHANNEL (10) @@ -105,4 +93,7 @@ typedef struct }__attribute__((packed)) ADCReadings_t; volatile extern ADCReadings_t adc_readings; +extern bool bms_daq_override; +extern bool bms_daq_stat; + #endif diff --git a/source/a_box/tmu/tmu.c b/source/a_box/tmu/tmu.c index 0ec55073..bef5cc78 100644 --- a/source/a_box/tmu/tmu.c +++ b/source/a_box/tmu/tmu.c @@ -10,6 +10,8 @@ extern q_handle_t q_tx_can; //uint8_t curr_therm; uint8_t num_bad1, num_bad2, num_bad3, num_bad4; bool overtemp = false; +bool tmu_daq_override = false; +uint8_t tmu_daq_therm = 0; //Function defs not needed by any other file void resistance_to_temp(float resistance, uint16_t *temp); @@ -25,10 +27,12 @@ bool initTMU(tmu_handle_t *tmu) { num_bad2 = 0; num_bad3 = 0; num_bad4 = 0; - PHAL_writeGPIO(MUX_1_OUT_Port, MUX_1_OUT_Pin, 0); - PHAL_writeGPIO(MUX_2_OUT_Port, MUX_2_OUT_Pin, 0); - PHAL_writeGPIO(MUX_3_OUT_Port, MUX_3_OUT_Pin, 0); - PHAL_writeGPIO(MUX_4_OUT_Port, MUX_4_OUT_Pin, 0); + tmu_daq_override = false; + tmu_daq_therm = 0; + PHAL_writeGPIO(MUX_A_Port, MUX_A_Pin, 0); + PHAL_writeGPIO(MUX_B_Port, MUX_B_Pin, 0); + PHAL_writeGPIO(MUX_C_Port, MUX_C_Pin, 0); + PHAL_writeGPIO(MUX_D_Port, MUX_D_Pin, 0); return false; } @@ -185,10 +189,12 @@ void readTemps(tmu_handle_t *tmu) { } - PHAL_writeGPIO(MUX_1_OUT_Port, MUX_1_OUT_Pin, (curr_therm & 0x1)); - PHAL_writeGPIO(MUX_2_OUT_Port, MUX_2_OUT_Pin, (curr_therm & 0x2)); - PHAL_writeGPIO(MUX_3_OUT_Port, MUX_3_OUT_Pin, (curr_therm & 0x4)); - PHAL_writeGPIO(MUX_4_OUT_Port, MUX_4_OUT_Pin, (curr_therm & 0x8)); + uint8_t therm = curr_therm; + if (tmu_daq_override) therm = tmu_daq_therm; + PHAL_writeGPIO(MUX_A_Port, MUX_A_Pin, (therm & 0x1)); + PHAL_writeGPIO(MUX_B_Port, MUX_B_Pin, (therm & 0x2)); + PHAL_writeGPIO(MUX_C_Port, MUX_C_Pin, (therm & 0x4)); + PHAL_writeGPIO(MUX_D_Port, MUX_D_Pin, (therm & 0x8)); } diff --git a/source/a_box/tmu/tmu.h b/source/a_box/tmu/tmu.h index 2fc9f667..ecc78590 100644 --- a/source/a_box/tmu/tmu.h +++ b/source/a_box/tmu/tmu.h @@ -73,6 +73,9 @@ typedef struct { int16_t tmu3[16]; int16_t tmu4[16]; } tmu_handle_t; +extern bool tmu_daq_override; +extern uint8_t tmu_daq_therm; + void readTemps(tmu_handle_t *tmu); bool initTMU(tmu_handle_t *tmu);