Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
9 changes: 8 additions & 1 deletion .vscode/settings.json
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please fix the tests

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@
"--compile-commands-dir=build_fw_dev",
// "--compile-commands-dir=build_fw_test",
"--query-driver=/usr/local/bin/arm-none-eabi-gcc"
]
],
"files.associations": {
"io_efuses.h": "c",
"io_efuse.h": "c",
"io_efuse_datatypes.h": "c",
"app_vehicledynamicsconstants.h": "c",
"app_loadswitches.h": "c"
}
}
13 changes: 11 additions & 2 deletions firmware/quintuna/VC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ list(APPEND IO_SRCS
"${SHARED_IO_INCLUDE_DIR}/io_canLogging.c"
"${SHARED_IO_INCLUDE_DIR}/io_led.c"
"${SHARED_IO_INCLUDE_DIR}/io_time.c"
"${SHARED_IO_INCLUDE_DIR}/io_loadswitch.c"
"${SHARED_IO_INCLUDE_DIR}/io_efuse/io_efuse.c"
"${SHARED_IO_INCLUDE_DIR}/io_efuse/io_efuse_ST_VND5/io_efuse_ST_VND5.c"
"${SHARED_IO_INCLUDE_DIR}/io_efuse/io_efuse_TI_TPS25/io_efuse_TI_TPS25.c"
"${SHARED_IO_INCLUDE_DIR}/io_potentiometer.c"
"${SHARED_IO_INCLUDE_DIR}/io_bootHandler.c"
"${SHARED_IO_INCLUDE_DIR}/io_imu.c"
)
set(IO_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/io" "${SHARED_IO_INCLUDE_DIR}" "${SHARED_IO_INCLUDE_QUINTUNA_DIR}")
set(IO_INCLUDE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}/src/io"
"${SHARED_IO_INCLUDE_DIR}"
"${SHARED_IO_INCLUDE_DIR}/io_efuse"
"${SHARED_IO_INCLUDE_DIR}/io_efuse/io_efuse_TI_TPS25"
"${SHARED_IO_INCLUDE_DIR}/io_efuse/io_efuse_ST_VND5"
"${SHARED_IO_INCLUDE_QUINTUNA_DIR}"
)

file(GLOB_RECURSE HW_SRCS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/hw/*.c")
list(APPEND HW_SRCS
Expand Down
9 changes: 5 additions & 4 deletions firmware/quintuna/VC/src/app/app_loadswitches.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#include <stddef.h>
#include <assert.h>

#include "io_loadswitch.h"
#include "app_canTx.h"
#include "io_loadswitches.h"
#include "io_efuses.h"

static void (*const efuse_enabled_can_setters[NUM_EFUSE_CHANNELS])(bool) = {
[EFUSE_CHANNEL_F_INV] = app_canTx_VC_FrontInvertersStatus_set,
Expand Down Expand Up @@ -35,12 +34,14 @@ void app_efuse_broadcast(void)
// run through each efuse, and broadcast the channel status and current
for (int efuse = 0; efuse < NUM_EFUSE_CHANNELS; efuse += 1)
{
const bool enabled = io_loadswitch_isChannelEnabled(efuse_channels[efuse]);
const float current = io_loadswitch_getChannelCurrent(efuse_channels[efuse]);
const bool enabled = io_efuse_isChannelEnabled(efuse_channels[efuse]);
const float current = io_efuse_getChannelCurrent(efuse_channels[efuse]);

assert(efuse_enabled_can_setters[efuse] != NULL);
efuse_enabled_can_setters[efuse](enabled);
assert(efuse_current_can_setters[efuse] != NULL);
efuse_current_can_setters[efuse](current);
}
}

// void app_loadswitch_enableFa
2 changes: 1 addition & 1 deletion firmware/quintuna/VC/src/app/app_loadswitches.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <stdbool.h>
#include "io_loadswitches.h"
#include "io_efuses.h"

void app_efuse_broadcast(void);
89 changes: 13 additions & 76 deletions firmware/quintuna/VC/src/app/app_powerManager.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "app_powerManager.h"

#include "app_timer.h"
#include "io_loadswitches.h"
#include "io_efuses.h"
#include "app_canAlerts.h"

#include <stdbool.h>
Expand All @@ -12,27 +12,9 @@
static PowerManagerConfig power_manager_state;
static TimerChannel sequencing_timer;

typedef union
{
const ST_LoadSwitch *st;
const TI_LoadSwitch *ti;
} LoadSwitch;

typedef struct
{
LoadSwitch loadswitch;
uint8_t retry_num;
} RetryProtocol;

static RetryProtocol efuses_retry_state[NUM_EFUSE_CHANNELS] = {
[EFUSE_CHANNEL_F_INV] = { .loadswitch.st = &inv_rsm_loadswitch, .retry_num = 0 },
[EFUSE_CHANNEL_RSM] = { .loadswitch.st = &inv_rsm_loadswitch, .retry_num = 0 },
[EFUSE_CHANNEL_BMS] = { .loadswitch.st = &inv_bms_loadswitch, .retry_num = 0 },
[EFUSE_CHANNEL_R_INV] = { .loadswitch.st = &inv_bms_loadswitch, .retry_num = 0 },
[EFUSE_CHANNEL_DAM] = { .loadswitch.st = &front_loadswitch, .retry_num = 0 },
[EFUSE_CHANNEL_FRONT] = { .loadswitch.st = &front_loadswitch, .retry_num = 0 },
[EFUSE_CHANNEL_RL_PUMP] = { .loadswitch.ti = &rl_pump_loadswitch, .retry_num = 0 },
[EFUSE_CHANNEL_R_RAD] = { .loadswitch.st = &rad_fan_loadswitch, .retry_num = 0 }
static uint8_t efuses_retry_num[NUM_EFUSE_CHANNELS] = {
[EFUSE_CHANNEL_F_INV] = 0, [EFUSE_CHANNEL_RSM] = 0, [EFUSE_CHANNEL_BMS] = 0, [EFUSE_CHANNEL_R_INV] = 0,
[EFUSE_CHANNEL_DAM] = 0, [EFUSE_CHANNEL_FRONT] = 0, [EFUSE_CHANNEL_RL_PUMP] = 0, [EFUSE_CHANNEL_R_RAD] = 0
};

void app_powerManager_updateConfig(const PowerManagerConfig new_power_manager_config)
Expand All @@ -44,51 +26,6 @@ void app_powerManager_updateConfig(const PowerManagerConfig new_power_manager_co
power_manager_state.efuse_configs[EFUSE_CHANNEL_R_RAD].efuse_enable = !app_canAlerts_VC_Info_PcmUnderVoltage_get();
}

static bool STLoadswitch_Status(const ST_LoadSwitch *loadswitch)
{
assert(loadswitch->efuse1 != NULL && loadswitch->efuse2 != NULL);

// Checking if ther is an overtemperature/short to ground condition
float vsenseh_efuse1 = io_loadswitch_getChannelCurrent(loadswitch->efuse1) / ADC_VOLTAGE_TO_CURRENT_A;
float vsenseh_efuse2 = io_loadswitch_getChannelCurrent(loadswitch->efuse2) / ADC_VOLTAGE_TO_CURRENT_A;

if (io_loadswitch_isChannelEnabled(loadswitch->efuse1) && vsenseh_efuse1 >= 3.0f)
{
return false;
}

if (io_loadswitch_isChannelEnabled(loadswitch->efuse2) && vsenseh_efuse2 >= 3.0f)
{
return false;
}

// Checking if there is a short to VBAT condition
io_STloadswitch_reset_set(loadswitch, true);

if (!io_loadswitch_isChannelEnabled(loadswitch->efuse1) && vsenseh_efuse1 > 3.0f)
{
return false;
}

if (!io_loadswitch_isChannelEnabled(loadswitch->efuse2) && vsenseh_efuse2 > 3.0f)
{
return false;
}

// reset the stby reset gpio to low
io_STloadswitch_reset_set(loadswitch, false);
return true;
}

static bool is_efuse_ok(const uint8_t current_efuse_sequence)
{
if (EFUSE_CHANNEL_RL_PUMP <= current_efuse_sequence)
{
return io_TILoadswitch_pgood(efuses_retry_state[current_efuse_sequence].loadswitch.ti);
}
return STLoadswitch_Status(efuses_retry_state[current_efuse_sequence].loadswitch.st);
}

void app_powerManager_EfuseProtocolTick_100Hz(void)
{
switch (app_timer_updateAndGetState(&sequencing_timer))
Expand All @@ -103,21 +40,23 @@ void app_powerManager_EfuseProtocolTick_100Hz(void)
// TODO: what the fuck
__attribute__((fallthrough));
case TIMER_STATE_IDLE:
for (LoadswitchChannel current_efuse_sequence = 0;
for (EfuseChannel current_efuse_sequence = 0;
current_efuse_sequence < NUM_EFUSE_CHANNELS &&
app_timer_updateAndGetState(&sequencing_timer) == TIMER_STATE_IDLE;
current_efuse_sequence++)
{
const Efuse *channel = efuse_channels[current_efuse_sequence];

// check if the efuse is supposed to be on or off
const bool desired_efuse_state = power_manager_state.efuse_configs[current_efuse_sequence].efuse_enable;
if (io_loadswitch_isChannelEnabled(efuse_channels[current_efuse_sequence]) == desired_efuse_state)
if (io_efuse_isChannelEnabled(channel) == desired_efuse_state)
{
// efuse is fine
continue;
}

// todo check this when incrementing the efuse failure
if (efuses_retry_state[current_efuse_sequence].retry_num >
if (efuses_retry_num[current_efuse_sequence] >
power_manager_state.efuse_configs[current_efuse_sequence].max_retry)
{
// todo over the retry limit activities
Expand All @@ -128,14 +67,14 @@ void app_powerManager_EfuseProtocolTick_100Hz(void)
if (desired_efuse_state == false)
{
// case 1: on and trying to turn off
io_loadswitch_setChannel(efuse_channels[current_efuse_sequence], desired_efuse_state);
io_efuse_setChannel(channel, desired_efuse_state);
continue;
}
// case 2: off and trying to turn on
// we update the efuse blown status here because this only shows up when we want it on
if (!is_efuse_ok(current_efuse_sequence)) // todo remove this state?
if (!io_efuse_ok(channel)) // todo remove this state?
{
efuses_retry_state[current_efuse_sequence].retry_num++;
efuses_retry_num[current_efuse_sequence]++;
}

// If we dont know the if the efuse is blown check if it is however if we know its already blown
Expand All @@ -147,9 +86,7 @@ void app_powerManager_EfuseProtocolTick_100Hz(void)
app_timer_init(&sequencing_timer, efuse_retry_timeout);
app_timer_restart(&sequencing_timer);
}
io_loadswitch_setChannel(
efuse_channels[current_efuse_sequence],
power_manager_state.efuse_configs[current_efuse_sequence].efuse_enable);
io_efuse_setChannel(channel, power_manager_state.efuse_configs[current_efuse_sequence].efuse_enable);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion firmware/quintuna/VC/src/app/app_powerManager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <stdint.h>
#include "io_loadswitches.h"
#include "io_efuses.h"

typedef struct
{
Expand Down
9 changes: 4 additions & 5 deletions firmware/quintuna/VC/src/app/app_pumpControl.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "app_pumpControl.h"
#include "io_loadswitch.h"
#include "io_efuses.h"
#include "io_time.h"
#include "io_loadswitches.h"
#include <app_canTx.h>

#define SLOPE (0.5f)
Expand Down Expand Up @@ -40,11 +39,11 @@ static void pumpControl_stopFlow(void)
void app_pumpControl_MonitorPumps(void)
{
time += 10;
const bool pumps_ok = io_TILoadswitch_pgood(&rl_pump_loadswitch);

const bool pumps_enabled = io_loadswitch_isChannelEnabled(efuse_channels[EFUSE_CHANNEL_RL_PUMP]);
const bool pumps_ok = io_efuse_pgood(&rl_pump_efuse);
const bool pumps_enabled = io_efuse_isChannelEnabled(&rl_pump_efuse);

bool ramp_up_pumps = pumps_ok && pumps_enabled;
const bool ramp_up_pumps = pumps_ok && pumps_enabled;

if (ramp_up_pumps)
pumpControl_rampUp();
Expand Down
1 change: 0 additions & 1 deletion firmware/quintuna/VC/src/app/states/app_hvInitState.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "app_timer.h"
#include "app_canAlerts.h"
#include "app_warningHandling.h"
#include "io_loadswitches.h"
#include "app_canTx.h"
#include "app_canRx.h"
#include "app_canUtils.h"
Expand Down
1 change: 0 additions & 1 deletion firmware/quintuna/VC/src/app/states/app_hvState.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "app_powerManager.h"
#include "app_startSwitch.h"
#include "app_warningHandling.h"
#include "io_loadswitches.h"
#include <app_canAlerts.h>
#include <app_canTx.h>
#include <app_canRx.h>
Expand Down
62 changes: 62 additions & 0 deletions firmware/quintuna/VC/src/io/io_efuses.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "hw_adcs.h"
#include "hw_gpios.h"
#include "hw_i2cs.h"
#include "io_efuses.h"
#include "io_efuse/io_efuse_ST_VND5/io_efuse_ST_VND5.h"
#include "io_efuse/io_efuse_TI_TPS25/io_efuse_TI_TPS25.h"

static ST_VND5_Efuse f_inv_ST_VND5_Efuse = { .stby_reset_gpio = &fr_stby_inv };
static ST_VND5_Efuse rsm_ST_VND5_Efuse = { .stby_reset_gpio = &fr_stby_inv };
static ST_VND5_Efuse bms_ST_VND5_Efuse = { .stby_reset_gpio = &fr_stby_front };
static ST_VND5_Efuse r_inv_ST_VND5_Efuse = { .stby_reset_gpio = &fr_stby_front };
static ST_VND5_Efuse dam_ST_VND5_Efuse = { .stby_reset_gpio = &fr_stby_rear };
static ST_VND5_Efuse front_ST_VND5_Efuse = { .stby_reset_gpio = &fr_stby_rear };
static TI_TPS25_Efuse rl_pump_TI_TPS25_Efuse = { .pgood = &rl_pump_pgood };
static ST_VND5_Efuse r_rad_fan_ST_VND5_Efuse = { .stby_reset_gpio = &fr_stby_rad };

const Efuse f_inv_efuse = { .enable_gpio = &f_inv_en,
.sns_adc_channel = &inv_f_pwr_i_sns,
.st_vnd5 = &f_inv_ST_VND5_Efuse,
.efuse_functions = &ST_VND5_Efuse_functions };

const Efuse rsm_efuse = { .enable_gpio = &rsm_en,
.sns_adc_channel = &rsm_i_sns,
.st_vnd5 = &f_inv_ST_VND5_Efuse,
.efuse_functions = &ST_VND5_Efuse_functions };

const Efuse bms_efuse = { .enable_gpio = &bms_en,
.sns_adc_channel = &bms_i_sns,
.st_vnd5 = &bms_ST_VND5_Efuse,
.efuse_functions = &ST_VND5_Efuse_functions };

const Efuse r_inv_efuse = { .enable_gpio = &r_inv_en,
.sns_adc_channel = &inv_r_pwr_i_sns,
.st_vnd5 = &r_inv_ST_VND5_Efuse,
.efuse_functions = &ST_VND5_Efuse_functions };

const Efuse dam_efuse = { .enable_gpio = &dam_en,
.sns_adc_channel = &dam_i_sns,
.st_vnd5 = &dam_ST_VND5_Efuse,
.efuse_functions = &ST_VND5_Efuse_functions };

const Efuse front_efuse = { .enable_gpio = &front_en,
.sns_adc_channel = &front_i_sns,
.st_vnd5 = &front_ST_VND5_Efuse,
.efuse_functions = &ST_VND5_Efuse_functions };

const Efuse rl_pump_efuse = { .enable_gpio = &rl_pump_en,
.sns_adc_channel = &pump_rl_pwr_i_sns,
.ti_tps25 = &rl_pump_TI_TPS25_Efuse,
.efuse_functions = &TI_TPS25_Efuse_functions };

const Efuse r_rad_fan_efuse = { .enable_gpio = &rr_rad_fan_en,
.sns_adc_channel = &r_rad_fan_i_sns,
.st_vnd5 = &r_rad_fan_ST_VND5_Efuse,
.efuse_functions = &TI_TPS25_Efuse_functions };

const Efuse *const efuse_channels[NUM_EFUSE_CHANNELS] = {
[EFUSE_CHANNEL_F_INV] = &f_inv_efuse, [EFUSE_CHANNEL_RSM] = &rsm_efuse,
[EFUSE_CHANNEL_BMS] = &bms_efuse, [EFUSE_CHANNEL_R_INV] = &r_inv_efuse,
[EFUSE_CHANNEL_DAM] = &dam_efuse, [EFUSE_CHANNEL_FRONT] = &front_efuse,
[EFUSE_CHANNEL_RL_PUMP] = &rl_pump_efuse, [EFUSE_CHANNEL_R_RAD] = &r_rad_fan_efuse
};
37 changes: 37 additions & 0 deletions firmware/quintuna/VC/src/io/io_efuses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "io_efuse/io_efuse.h"

typedef enum
{
// INV_RSM loadswitch
EFUSE_CHANNEL_F_INV = 0u,
EFUSE_CHANNEL_RSM,

// INV_BMS loadswitch
EFUSE_CHANNEL_BMS,
EFUSE_CHANNEL_R_INV,

// Front loadswitch
EFUSE_CHANNEL_DAM,
EFUSE_CHANNEL_FRONT,

// TI loadswitches
EFUSE_CHANNEL_RL_PUMP,

// Radiator Fan loadswitches
EFUSE_CHANNEL_R_RAD,

NUM_EFUSE_CHANNELS
} EfuseChannel;

extern const Efuse *const efuse_channels[NUM_EFUSE_CHANNELS];

extern const Efuse f_inv_efuse;
extern const Efuse rsm_efuse;
extern const Efuse bms_efuse;
extern const Efuse r_inv_efuse;
extern const Efuse dam_efuse;
extern const Efuse front_efuse;
extern const Efuse rl_pump_efuse;
extern const Efuse r_rad_fan_efuse;
Loading
Loading