From a746c8807773172160a061b6efa32bc0fa513364 Mon Sep 17 00:00:00 2001 From: Ernest Tang Date: Tue, 28 May 2024 17:41:26 +0000 Subject: [PATCH] Implemented BPS fault indicator --- projects/bms_carrier/inc/bms.h | 1 + projects/power_distribution/inc/outputs.h | 1 + projects/power_distribution/inc/pd_fault.h | 3 +++ projects/power_distribution/src/main.c | 2 ++ .../power_distribution/src/output_config.c | 5 ++++- projects/power_distribution/src/pd_fault.c | 21 +++++++++++++++++++ .../power_distribution/src/power_seq_fsm.c | 3 +++ 7 files changed, 35 insertions(+), 1 deletion(-) diff --git a/projects/bms_carrier/inc/bms.h b/projects/bms_carrier/inc/bms.h index f141e52f6..4fa9074e1 100644 --- a/projects/bms_carrier/inc/bms.h +++ b/projects/bms_carrier/inc/bms.h @@ -43,4 +43,5 @@ typedef enum { BMS_FAULT_UNDERVOLTAGE, BMS_FAULT_KILLSWITCH, BMS_FAULT_RELAY_CLOSE_FAILED, + BMS_FAULT_DISCONNECTED } BmsFault; diff --git a/projects/power_distribution/inc/outputs.h b/projects/power_distribution/inc/outputs.h index 137d8ec57..0bff854ea 100644 --- a/projects/power_distribution/inc/outputs.h +++ b/projects/power_distribution/inc/outputs.h @@ -65,6 +65,7 @@ typedef enum { OUTPUT_GROUP_POWER_OFF, OUTPUT_GROUP_POWER_DRIVE, OUTPUT_GROUP_POWER_FAULT, + OUTPUT_GROUP_BPS, NUM_OUTPUT_GROUPS, } OutputGroup; diff --git a/projects/power_distribution/inc/pd_fault.h b/projects/power_distribution/inc/pd_fault.h index 41360365f..7b9e32611 100644 --- a/projects/power_distribution/inc/pd_fault.h +++ b/projects/power_distribution/inc/pd_fault.h @@ -3,8 +3,11 @@ #include #include "status.h" + +#define BPS_FAULT_LIGHT_PERIOD_MS 500 // Signal blink frequency of 1Hz /* * @brief Checks for PD fault states and updates fault bitset CAN message * @return STATUS_CODE_OK on success or appropriate error code */ uint8_t check_pd_fault(void); +StatusCode init_bps_fault(void); diff --git a/projects/power_distribution/src/main.c b/projects/power_distribution/src/main.c index 52869a792..223b76bcb 100644 --- a/projects/power_distribution/src/main.c +++ b/projects/power_distribution/src/main.c @@ -10,6 +10,7 @@ #include "log.h" #include "master_task.h" #include "output_current_sense.h" +#include "pd_fault.h" #include "pin_defs.h" #include "power_seq_fsm.h" #include "tasks.h" @@ -64,6 +65,7 @@ int main() { // set_medium_cycle_count(2); // adjust medium cycle count to run once per 500ms init_power_seq(); init_lights(); + init_bps_fault(); LOG_DEBUG("Welcome to PD!\n"); init_master_task(); diff --git a/projects/power_distribution/src/output_config.c b/projects/power_distribution/src/output_config.c index 37fb728f0..e50a319d4 100644 --- a/projects/power_distribution/src/output_config.c +++ b/projects/power_distribution/src/output_config.c @@ -322,9 +322,11 @@ static OutputGroupDef s_output_group_power_drive = { .num_outputs = 9, DRIVER_FAN, REAR_CAM_LCD } }; static OutputGroupDef s_output_group_power_fault = { - .num_outputs = 5, .outputs = { CENTER_CONSOLE, BMS_DCDC, PEDAL, STEERING, BPS_LIGHT } + .num_outputs = 4, .outputs = { CENTER_CONSOLE, BMS_DCDC, PEDAL, STEERING } }; +static OutputGroupDef s_output_group_bps = { .num_outputs = 1, .outputs = { BPS_LIGHT } }; + static OutputGroupDef s_output_group_test = { .num_outputs = 2, .outputs = { STEERING, PEDAL } }; const OutputGroupDef *g_output_group_map[NUM_OUTPUT_GROUPS] = { @@ -336,4 +338,5 @@ const OutputGroupDef *g_output_group_map[NUM_OUTPUT_GROUPS] = { [OUTPUT_GROUP_POWER_OFF] = &s_output_group_power_off, [OUTPUT_GROUP_POWER_DRIVE] = &s_output_group_power_drive, [OUTPUT_GROUP_POWER_FAULT] = &s_output_group_power_fault, + [OUTPUT_GROUP_BPS] = &s_output_group_bps, }; diff --git a/projects/power_distribution/src/pd_fault.c b/projects/power_distribution/src/pd_fault.c index 80657e444..c78306358 100644 --- a/projects/power_distribution/src/pd_fault.c +++ b/projects/power_distribution/src/pd_fault.c @@ -4,10 +4,15 @@ #include "exported_enums.h" #include "gpio.h" #include "log.h" +#include "outputs.h" #include "pin_defs.h" +#include "power_distribution_getters.h" #include "power_distribution_setters.h" +#include "soft_timer.h" static uint8_t s_fault_bitset = 0; +static OutputState bps_light_state = OUTPUT_STATE_OFF; +static SoftTimer bps_timer; // Fault pin address definitions static const GpioAddress aux_valid1 = AUX_VALID1; @@ -43,9 +48,25 @@ static bool prv_check_dcdc_fault(void) { return (dcdc_valid1_state == GPIO_STATE_HIGH || dcdc_valid2_state == GPIO_STATE_HIGH); } +static void prv_lights_bps_fault(SoftTimerId id) { + if (get_battery_status_fault() || g_tx_struct.pd_status_bps_persist) { + bps_light_state ^= 1; + pd_set_output_group(OUTPUT_GROUP_BPS, bps_light_state); + } else { + bps_light_state = 0; + pd_set_output_group(OUTPUT_GROUP_BPS, bps_light_state); + } + soft_timer_start(&bps_timer); +} + uint8_t check_pd_fault(void) { prv_set_fault_bit(EE_PD_STATUS_FAULT_BITSET_AUX_FAULT_MASK, prv_check_aux_fault()); prv_set_fault_bit(EE_PD_STATUS_FAULT_BITSET_DCDC_FAULT_MASK, prv_check_dcdc_fault()); set_pd_status_fault_bitset(s_fault_bitset); return s_fault_bitset; } + +StatusCode init_bps_fault(void) { + soft_timer_init_and_start(BPS_FAULT_LIGHT_PERIOD_MS, prv_lights_bps_fault, &bps_timer); + return STATUS_CODE_OK; +} diff --git a/projects/power_distribution/src/power_seq_fsm.c b/projects/power_distribution/src/power_seq_fsm.c index abf2a940b..37e0689b0 100644 --- a/projects/power_distribution/src/power_seq_fsm.c +++ b/projects/power_distribution/src/power_seq_fsm.c @@ -93,6 +93,9 @@ static void prv_fault_state_output(void *context) { s_bps_storage.fault_bitset = get_battery_status_fault(); s_bps_storage.vehicle_speed = (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) / 2; + if (s_bps_storage.fault_bitset == 0) { + s_bps_storage.fault_bitset = (1 << 10); // BMS NOT CONNECTED + } persist_commit(&s_persist); pd_set_active_output_group(OUTPUT_GROUP_POWER_FAULT); set_pd_status_bps_persist(s_bps_storage.fault_bitset);