Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PD fault module #243

Merged
merged 7 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libraries/codegen/boards/power_distribution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@
length: 8
pd_fault:
length: 8
pd_status:
id: 1
target:
centre_console:
watchdog: 0
signals:
fault_bitset:
length: 8
10 changes: 10 additions & 0 deletions libraries/ms-common/inc/exported_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ typedef enum {
EE_PWR_SEL_FAULT_AUX_OVERVOLTAGE_BIT,
} PowerSelectFaultMasks;

typedef enum {
EE_PD_STATUS_FAULT_BITSET_AUX_FAULT_BIT = 0,
EE_PD_STATUS_FAULT_BITSET_DCDC_FAULT_BIT,
NUM_EE_PD_STATUS_FAULT_BITSET_BITS,
} PdStatusFaultBitsetMasks;

#define EE_PWR_SEL_FAULT_PWR_SUPPLY_OVERCURRENT_MASK \
(1 << EE_PWR_SEL_FAULT_PWR_SUPPLY_OVERCURRENT_BIT)

Expand All @@ -119,6 +125,10 @@ typedef enum {

#define EE_PWR_SEL_FAULT_AUX_OVERVOLTAGE_MASK (1 << EE_PWR_SEL_FAULT_AUX_OVERVOLTAGE_BIT)

#define EE_PD_STATUS_FAULT_BITSET_AUX_FAULT_MASK (1 << EE_PD_STATUS_FAULT_BITSET_AUX_FAULT_BIT)

#define EE_PD_STATUS_FAULT_BITSET_DCDC_FAULT_MASK (1 << EE_PD_STATUS_FAULT_BITSET_DCDC_FAULT_BIT)

// BMS SIGNALS
typedef enum EEBatteryHeartbeatFaultSource {
EE_BPS_FAULT_SOURCE_KILLSWITCH = 0,
Expand Down
9 changes: 9 additions & 0 deletions projects/power_distribution/inc/pd_fault.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "status.h"

/*
* @brief Checks for PD fault states and updates fault bitset CAN message
* @return STATUS_CODE_OK on success or appropriate error code
*/
StatusCode check_pd_fault(void);
13 changes: 13 additions & 0 deletions projects/power_distribution/inc/pin_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,16 @@
#define MUX_SEL_INFOTAINMENT_DISPLAY_BMS 13 // aka main display
#define MUX_SEL_FAN_1_2 14
#define MUX_SEL_UV_VBAT 15

// Fault pin addresses
// GPIO
#define AUX_FAULT_GPIO_1 \
{ .port = GPIO_PORT_B, .pin = 3 }
#define AUX_FAULT_GPIO_2 \
{ .port = GPIO_PORT_B, .pin = 4 }
#define DCDC_FAULT_GPIO_1 \
{ .port = GPIO_PORT_A, .pin = 15 }
#define DCDC_FAULT_GPIO_2 \
{ .port = GPIO_PORT_B, .pin = 5 }
#define DCDC_FAULT_GPIO_3 \
{ .port = GPIO_PORT_A, .pin = 6 }
2 changes: 2 additions & 0 deletions projects/power_distribution/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void run_medium_cycle() {
fsm_run_cycle(lights);
wait_tasks(1);

adc_run();

run_can_tx_cycle();
wait_tasks(1);
}
Expand Down
60 changes: 60 additions & 0 deletions projects/power_distribution/src/pd_fault.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "pd_fault.h"

#include "adc.h"
#include "exported_enums.h"
#include "gpio.h"
#include "pin_defs.h"
#include "power_distribution_setters.h"

static uint8_t s_fault_bitset = 0;

// Fault pin address definitions
static const GpioAddress aux_fault_gpio_1 = AUX_FAULT_GPIO_1;
static const GpioAddress aux_fault_gpio_2 = AUX_FAULT_GPIO_2;
static const GpioAddress dcdc_fault_gpio_1 = DCDC_FAULT_GPIO_1;
static const GpioAddress dcdc_fault_gpio_2 = DCDC_FAULT_GPIO_2;
static const GpioAddress dcdc_fault_gpio_3 = DCDC_FAULT_GPIO_3;

elbertchen1 marked this conversation as resolved.
Show resolved Hide resolved
static void prv_set_fault_bit(uint8_t mask, bool condition) {
if (condition) {
s_fault_bitset |= mask;
} else {
s_fault_bitset &= ~(mask);
}
}

static StatusCode prv_check_aux_fault(void) {
GpioState aux_gpio_1_state;
GpioState aux_gpio_2_state;
status_ok_or_return(gpio_get_state(&aux_fault_gpio_1, &aux_gpio_1_state));
status_ok_or_return(gpio_get_state(&aux_fault_gpio_2, &aux_gpio_2_state));

bool aux_fault = (aux_gpio_1_state == GPIO_STATE_LOW || aux_gpio_2_state == GPIO_STATE_LOW);
prv_set_fault_bit(EE_PD_STATUS_FAULT_BITSET_AUX_FAULT_MASK, aux_fault);

return STATUS_CODE_OK;
}

static StatusCode prv_check_dcdc_fault(void) {
GpioState dcdc_gpio_1_state;
GpioState dcdc_gpio_2_state;
GpioState dcdc_gpio_3_state;
status_ok_or_return(gpio_get_state(&dcdc_fault_gpio_1, &dcdc_gpio_1_state));
status_ok_or_return(gpio_get_state(&dcdc_fault_gpio_2, &dcdc_gpio_2_state));
status_ok_or_return(gpio_get_state(&dcdc_fault_gpio_3, &dcdc_gpio_3_state));

bool dcdc_fault = (dcdc_gpio_1_state == GPIO_STATE_LOW || dcdc_gpio_2_state == GPIO_STATE_LOW ||
dcdc_gpio_3_state == GPIO_STATE_HIGH);
prv_set_fault_bit(EE_PD_STATUS_FAULT_BITSET_DCDC_FAULT_MASK, dcdc_fault);

return STATUS_CODE_OK;
}

StatusCode check_pd_fault() {
elbertchen1 marked this conversation as resolved.
Show resolved Hide resolved
status_ok_or_return(prv_check_aux_fault());
status_ok_or_return(prv_check_dcdc_fault());

set_pd_status_fault_bitset(s_fault_bitset);

return STATUS_CODE_OK;
}