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

Pd cc bms mci changes (new boards + new fsm) #275

Merged
merged 16 commits into from
May 4, 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: 4 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ if PLATFORM == 'arm' and TARGET:
# flash the MCU using openocd
def flash_run_target(target, source, env):
serialData = flash_run(project_bin)
while True:
line: str = serialData.readline().decode("utf-8")
print(line, end='')
#while True:
# line: str = serialData.readline().decode("utf-8")
# print(line, end='')

AlwaysBuild(Command('#/flash', project_bin, flash_run_target))
AlwaysBuild(Command('#/flash', project_bin, flash_run_target))
8 changes: 0 additions & 8 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,3 @@ if [ "$GIT_AUTHOR_NAME" = "vagrant" ] || [ "$GIT_AUTHOR_EMAIL" = "vagrant@midsun
echo "https://uwmidsun.atlassian.net/wiki/spaces/ELEC/pages/60260353/Module+1+Setup"
exit 1
fi

echo "Automatically formatting and linting"
scons format lint && git add .

if [ $? -ne 0 ]; then
echo "Code must be properly formatted before commiting!"
exit 1
fi
74 changes: 44 additions & 30 deletions libraries/codegen/boards/centre_console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,47 @@
# - 30-63: Data messages (usually not actionable by an onboard device)

---
Messages:
cc_power_control:
id: 8
target:
power_distribution:
watchdog: 0
critical: true
signals:
power_event: # (POWER_EV_NONE | POWER_EV_BTN | POWER_EV_BTN_AND_BRAKE)
length: 8
hazard_enabled:
length: 8

drive_output:
id: 9
target:
motor_controller:
watchdog: 0
critical: true
signals:
target_velocity:
length: 32
drive_state:
length: 8
cruise_control:
length: 8
regen_braking:
length: 8
precharge:
length: 8
Messages:
cc_info:
id: 9
target:
motor_controller:
watchdog: 3
power_distribution:
watchdog: 3
critical: true
signals:
target_velocity:
length: 32
drive_state:
length: 8
cruise_control:
length: 8
regen_braking:
length: 8
hazard_enabled:
length: 8
cc_pedal:
id: 18
target:
motor_controller:
watchdog: 0
power_distribution:
watchdog: 0
signals:
throttle_output:
length: 32
brake_output:
length: 8
cc_steering:
id: 21
target:
power_distribution:
watchdog: 0
motor_controller:
watchdog: 0
signals:
input_cc:
length: 8 # (cc_toggle | cc_increse | cc_decrease)
input_lights:
length: 8
2 changes: 2 additions & 0 deletions libraries/codegen/boards/motor_controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
target:
centre_console:
watchdog: 0
power_distribution:
watchdog: 0
signals:
velocity_l:
length: 16
Expand Down
4 changes: 0 additions & 4 deletions libraries/codegen/boards/new_can.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
transmit_msg1:
id: 0
target:
centre_console:
watchdog: 3
new_can:
watchdog: 3
critical: true
Expand All @@ -25,8 +23,6 @@
transmit_msg2:
id: 1
target:
centre_console:
watchdog: 0
new_can:
watchdog: 0
critical: true
Expand Down
30 changes: 4 additions & 26 deletions libraries/codegen/boards/power_distribution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@

---
Messages:
uv_cutoff_notification:
id: 45
target:
telemetry:
watchdog: 0
signals:
signal1:
length: 8
current_measurement:
id: 54
target:
Expand Down Expand Up @@ -56,30 +48,16 @@
signals:
signal1:
length: 8
power_info:
id: 3
pd_status:
id: 1
target:
centre_console:
watchdog: 0
watchdog: 3
critical: true
signals:
power_state:
length: 8
pd_fault:
length: 8
pd_status:
id: 1
target:
centre_console:
watchdog: 0
signals:
fault_bitset:
length: 8
bms_relays:
id: 10
target:
bms_carrier:
watchdog: 0
signals:
relays_state:
bps_persist:
length: 8
14 changes: 3 additions & 11 deletions libraries/ms-common/inc/exported_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

// Common Defines
typedef enum {
EE_RELAY_STATE_OPEN = 0,
EE_RELAY_STATE_CLOSE,
EE_RELAY_STATE_CLOSE = 0,
EE_RELAY_STATE_FAULT,
NUM_EE_RELAY_STATES,
} EERelayState;
Expand All @@ -44,14 +43,6 @@ typedef enum SteeringInfoDigitalMask {
#define EE_STEERING_CC_TOGGLE_MASK (1 << EE_STEERING_CC_TOGGLE_BIT)

// CENTRE CONSOLE SIGNALS
// Drive Output
typedef enum {
EE_CC_PWR_CTL_EVENT_NONE = 0,
EE_CC_PWR_CTL_EVENT_BTN,
EE_CC_PWR_CTL_EVENT_BTN_AND_BRAKE,
NUM_EE_CC_PWR_CTL_EVENTS,
} CentreConsoleCCPwrEvent;

typedef enum {
EE_DRIVE_OUTPUT_CC_OFF_STATE = 0, // Cruise control enabled,
EE_DRIVE_OUTPUT_CC_ON_STATE, // Cruise control disabled
Expand Down Expand Up @@ -80,8 +71,9 @@ typedef enum {
// POWER DISTRIBUTION (TODO)
typedef enum {
EE_POWER_OFF_STATE = 0,
EE_POWER_ON_STATE,
EE_POWER_PRECHARGE_STATE,
EE_POWER_DRIVE_STATE,
EE_POWER_FAULT_STATE
} PowerDistributionPowerState;

typedef enum {
Expand Down
28 changes: 18 additions & 10 deletions libraries/ms-drivers/inc/ltc6811.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ static_assert(sizeof(LtcAfeConfigRegisterData) == 6, "LtcAfeConfigRegisterData m

// COMM Register, refer to LTC6803 datasheet page 31, Table 15
typedef struct {
uint16_t icom0 : 4;
uint16_t d0 : 8;
uint16_t fcom0 : 4;
uint8_t icom0 : 4;
uint8_t d0 : 8;
uint8_t fcom0 : 4;

uint16_t icom1 : 4;
uint16_t d1 : 8;
uint16_t fcom1 : 4;
uint8_t icom1 : 4;
uint8_t d1 : 8;
uint8_t fcom1 : 4;

uint16_t icom2 : 4;
uint16_t d2 : 8;
uint16_t fcom2 : 4;
uint8_t icom2 : 4;
uint8_t d2 : 8;
uint8_t fcom2 : 4;
} _PACKED LtcAfeCommRegisterData;
static_assert(sizeof(LtcAfeCommRegisterData) == 6, "LtcAfeCommRegisterData must be 6 bytes");

Expand Down Expand Up @@ -116,7 +116,7 @@ typedef struct {
LtcAfeWriteDeviceConfigPacket devices[LTC_AFE_MAX_CELLS_PER_DEVICE];
} _PACKED LtcAfeWriteConfigPacket;
#define SIZEOF_LTC_AFE_WRITE_CONFIG_PACKET(devices) \
(LTC6811_CMD_SIZE + (devices) * sizeof(LtcAfeWriteConfigPacket))
(LTC6811_CMD_SIZE + (devices) * sizeof(LtcAfeWriteDeviceConfigPacket))

typedef union {
uint16_t voltages[3];
Expand Down Expand Up @@ -187,6 +187,10 @@ static_assert(sizeof(LtcAfeAuxRegisterGroupPacket) == 8,

#define LTC6811_STCOMM_RESERVED (1 << 0) | (1 << 1) | (1 << 5) | (1 << 8) | (1 << 9) | (1 << 10)

#define LTC6811_WRPWM_RESERVED (1 << 5)

#define LTC6811_RDPWM_RESERVED (1 << 5) | (1 << 2)

// command bits
// see Table 40 (p. 62)
#define LTC6811_GPIO1_PD_ON (0 << 3)
Expand Down Expand Up @@ -216,6 +220,7 @@ static_assert(sizeof(LtcAfeAuxRegisterGroupPacket) == 8,
#define LTC6811_SWTRD (1 << 1)

#define LTC6811_ADAX_GPIO1 0x01
#define LTC6811_ADAX_GPIO4 0x04
#define LTC6811_ADAX_MODE_FAST (0 << 8) | (1 << 7)

#define LTC6811_ICOM_CSBM_LOW (1 << 3)
Expand All @@ -224,3 +229,6 @@ static_assert(sizeof(LtcAfeAuxRegisterGroupPacket) == 8,

#define LTC6811_FCOM_CSBM_LOW (0 << 0)
#define LTC6811_FCOM_CSBM_HIGH (1 << 3) | (1 << 0)

// see Table 17 (p. 38)
#define LTC6811_PWMC_DC_100 (0xF)
6 changes: 3 additions & 3 deletions libraries/ms-drivers/inc/ltc_afe.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#include "status.h"

// This is an arbitrary limitation, can be increased/decreased if needed
#define LTC_AFE_MAX_DEVICES 5
#define LTC_AFE_MAX_DEVICES 3
// This is a device limitation
#define LTC_AFE_MAX_CELLS_PER_DEVICE 12
#define LTC_AFE_MAX_THERMISTORS_PER_DEVICE 8
#define LTC_AFE_MAX_CELLS (LTC_AFE_MAX_DEVICES * LTC_AFE_MAX_CELLS_PER_DEVICE)
#define LTC_AFE_MAX_THERMISTORS LTC_AFE_MAX_CELLS
#define LTC_AFE_MAX_THERMISTORS (LTC_AFE_MAX_DEVICES * LTC_AFE_MAX_THERMISTORS_PER_DEVICE)

#if defined(__GNUC__)
#define _PACKED __attribute__((packed))
Expand Down Expand Up @@ -76,7 +77,6 @@ typedef struct LtcAfeStorage {
uint16_t aux_index;
uint16_t retry_count;
uint16_t device_cell;
uint32_t timer_start;

uint16_t cell_voltages[LTC_AFE_MAX_CELLS];
uint16_t aux_voltages[LTC_AFE_MAX_THERMISTORS];
Expand Down
7 changes: 6 additions & 1 deletion libraries/ms-drivers/inc/ltc_afe_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
// represent whether we should monitor the cell input for the given device.
StatusCode ltc_afe_impl_init(LtcAfeStorage *afe, const LtcAfeSettings *settings);

// Write an LTC config based on the given storage settings
StatusCode ltc_afe_impl_write_config(LtcAfeStorage *afe);

// Triggers a conversion. Note that we need to wait for the conversions to complete before the
// readback will be valid.
StatusCode ltc_afe_impl_trigger_cell_conv(LtcAfeStorage *afe);
Expand All @@ -25,7 +28,9 @@ StatusCode ltc_afe_impl_trigger_aux_conv(LtcAfeStorage *afe, uint8_t device_cell
// Reads converted voltages from the AFE into the storage result arrays.
StatusCode ltc_afe_impl_read_cells(LtcAfeStorage *afe);
StatusCode ltc_afe_impl_read_aux(LtcAfeStorage *afe, uint8_t device_cell);

// Mark cell for discharging (takes effect after config is re-written)
// |cell| should be [0, LTC_AFE_MAX_CELLS)
StatusCode ltc_afe_impl_toggle_cell_discharge(LtcAfeStorage *afe, uint16_t cell, bool discharge);

// Sets the duty cycle to the same value for all cells on all afes
StatusCode ltc_afe_impl_set_discharge_pwm_cycle(LtcAfeStorage *afe, uint8_t duty_cycle);
Loading
Loading