Skip to content

Commit

Permalink
i somehow didn't commit the new code whoops
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Mar 16, 2024
1 parent 6b78ce5 commit f9fa1c9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
42 changes: 22 additions & 20 deletions Core/Inc/pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ int8_t write_fan_battbox(pdu_t* pdu, bool status);

/* Function to Read the Status of Fuses from PDU */
typedef enum {
FUSE_PUMP,
FUSE_FAN_RADIATOR,
FUSE_FAN_BATTBOX,
FUSE_MC,
FUSE_LVBOX,
FUSE_DASHBOARD,
FUSE_BRAKELIGHT,
FUSE_BRB,
MAX_FUSES
FUSE_BATTBOX = 4,
FUSE_LVBOX = 5,
FUSE_FAN_RADIATOR = 6,
FUSE_MC = 7,
FUSE_FAN_BATTBOX = 8,
FUSE_PUMP = 9,
FUSE_DASHBOARD = 10,
FUSE_BRAKELIGHT = 11,
FUSE_BRB = 12,
MAX_FUSES = 9
} fuse_t;

int8_t read_fuse(pdu_t* pdu, fuse_t fuse, bool* status);
Expand All @@ -42,17 +43,18 @@ int8_t read_tsms_sense(pdu_t* pdu, bool* status);

/* Functions to Read Status of Various Stages of Shutdown Loop */
typedef enum {
CKPT_BRB_CLR, /* Cockpit BRB */
SIDE_BRB_CLR, /* Side BRB */
INTERTIA_SW_OK, /* Inertia Switch */
BOTS_OK, /* Brake Over Travel Switch */
BPSD_OK, /* Brake System Plausbility Device */
IMD_OK, /* Insulation Monitoring Device */
BMS_OK, /* Battery Management System (Shepherd) */
TSMS, /* Tractive System Main Switch */
HVD_INTLK_OK, /* HVD Interlock */
HVC_INTLK_OK, /* HV C Interlock*/
MAX_SHUTDOWN_STAGES
CKPT_BRB_CLR = 0, /* Cockpit BRB */
BMS_OK = 2, /* Battery Management System (Shepherd) */
INTERTIA_SW_OK = 3, /* Inertia Switch */
SPARE_GPIO1_OK = 4,
IMD_OK = 5, /* Insulation Monitoring Device */
BPSD_OK = 8, /* Brake System Plausbility Device */
BOTS_OK = 13, /* Brake Over Travel Switch */
HVD_INTLK_OK = 14, /* HVD Interlock */
HVC_INTLK_OK = 15, /* HV C Interlock*/
SIDE_BRB_CLR, /* Side BRB */
TSMS, /* Tractive System Main Switch */
MAX_SHUTDOWN_STAGES = 9
} shutdown_stage_t;

int8_t read_shutdown(pdu_t* pdu, shutdown_stage_t stage, bool* status);
Expand Down
15 changes: 9 additions & 6 deletions Core/Src/pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pdu_t* init_pdu(I2C_HandleTypeDef* hi2c)

/* Initialize Control GPIO Expander */
pdu->ctrl_expander = malloc(sizeof(max7314_t));
pdu->ctrl_expander->dev_addr = 0x24;
assert(pdu->ctrl_expander);
if (max7314_init(pdu->ctrl_expander, pdu->hi2c)) {
free(pdu->ctrl_expander);
Expand Down Expand Up @@ -69,7 +70,7 @@ int8_t write_pump(pdu_t* pdu, bool status)
return stat;

// write pump over i2c
max7314_set_pin_state(pdu->ctrl_expander, PUMP_CTRL, (max7314_pin_states_t) status);
max7314_set_pin_state(pdu->ctrl_expander, PUMP_CTRL, status);

osMutexRelease(pdu->mutex);
return 0;
Expand All @@ -85,7 +86,7 @@ int8_t write_fan_radiator(pdu_t* pdu, bool status)
return stat;

// write radiator over i2c
max7314_set_pin_state(pdu->ctrl_expander, RADFAN_CTRL, (max7314_pin_states_t) status);
max7314_set_pin_state(pdu->ctrl_expander, RADFAN_CTRL, status);

osMutexRelease(pdu->mutex);
return 0;
Expand All @@ -101,7 +102,7 @@ int8_t write_brakelight(pdu_t* pdu, bool status)
return stat;

// write brakelight over i2c
max7314_set_pin_state(pdu->ctrl_expander, BRKLIGHT_CTRL, (max7314_pin_states_t) status);
max7314_set_pin_state(pdu->ctrl_expander, BRKLIGHT_CTRL, status);

osMutexRelease(pdu->mutex);
return 0;
Expand All @@ -117,7 +118,7 @@ int8_t write_fan_battbox(pdu_t* pdu, bool status)
return stat;

// write fan over i2c
max7314_set_pin_state(pdu->ctrl_expander, BATBOXFAN_CTRL, (max7314_pin_states_t) status);
max7314_set_pin_state(pdu->ctrl_expander, BATBOXFAN_CTRL, status);

osMutexRelease(pdu->mutex);
return 0;
Expand All @@ -132,8 +133,8 @@ int8_t read_fuse(pdu_t* pdu, fuse_t fuse, bool* status)
if (stat)
return stat;

// figure out which fuse to use
// write fan over i2c
max7314_read_pin_state(pdu->ctrl_expander, fuse, status);

osMutexRelease(pdu->mutex);
return 0;
Expand All @@ -149,6 +150,8 @@ int8_t read_tsms_sense(pdu_t* pdu, bool* status)
return stat;

// read pin over i2c
uint8_t tsms_pin = 14;
max7314_read_pin_state(pdu->ctrl_expander, tsms_pin, status);

osMutexRelease(pdu->mutex);
return 0;
Expand All @@ -163,8 +166,8 @@ int8_t read_shutdown(pdu_t* pdu, shutdown_stage_t stage, bool* status)
if (stat)
return stat;

// figure out which pin to read
// read pin over i2c
max7314_read_pin_state(pdu->ctrl_expander, stage, status);

osMutexRelease(pdu->mutex);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Embedded-Base

0 comments on commit f9fa1c9

Please sign in to comment.