diff --git a/libraries/codegen/boards/bms_carrier.yaml b/libraries/codegen/boards/bms_carrier.yaml index 0a6d3efc8..7c4b4b3a6 100644 --- a/libraries/codegen/boards/bms_carrier.yaml +++ b/libraries/codegen/boards/bms_carrier.yaml @@ -10,15 +10,19 @@ --- Messages: - bps_heartbeat: + battery_status: id: 0 target: centre_console: watchdog: 0 critical: true signals: + batt_perc: + length: 16 status: length: 8 + fault: + length: 8 battery_vt: id: 30 @@ -35,9 +39,6 @@ length: 16 temperature: length: 16 - # This field will change - batt_perc: - length: 16 battery_aggregate_vc: id: 33 diff --git a/libraries/codegen/boards/centre_console.yaml b/libraries/codegen/boards/centre_console.yaml index a56dc5bdc..ff6e9b833 100644 --- a/libraries/codegen/boards/centre_console.yaml +++ b/libraries/codegen/boards/centre_console.yaml @@ -10,87 +10,19 @@ --- Messages: - set_bms_power: - id: 4 + cc_power_control: + id: 8 target: power_distribution: watchdog: 0 critical: true signals: - bms_power_on_notification: + power_event: # (POWER_EV_NONE | POWER_EV_BTN | POWER_EV_BTN_AND_BRAKE) length: 8 - - set_power_state: - id: 5 - target: - power_distribution: - watchdog: 0 - critical: true - signals: - turn_on_everything_notification: + hazard_enabled: length: 8 - set_relay_states: - id: 1 - target: - bms_carrier: - watchdog: 0 - motor_controller: - watchdog: 0 - solar_5_mppts: - watchdog: 0 - solar_6_mppts: - watchdog: 0 - critical: true - signals: - relay_mask: - length: 16 - relay_state: - length: 16 - - power_on_main_sequence: - id: 6 - target: - motor_controller: - watchdog: 0 - pedal: - watchdog: 0 - power_distribution: - watchdog: 0 - critical: true - signals: - sequence: - length: 16 - - power_off_main_sequence: - id: 7 - target: - motor_controller: - watchdog: 0 - pedal: - watchdog: 0 - power_distribution: - watchdog: 0 - critical: true - signals: - sequence: - length: 16 - - power_on_aux_sequence: - id: 8 - target: - motor_controller: - watchdog: 0 - pedal: - watchdog: 0 - power_distribution: - watchdog: 0 - critical: true - signals: - sequence: - length: 16 - - drive_output: + drive_output: id: 9 target: motor_controller: @@ -106,81 +38,4 @@ regen_braking: length: 8 precharge: - length: 8 - - set_ebrake_state: - id: 10 - target: - centre_console: - watchdog: 0 - critical: true - signals: - ebrake_state: - length: 8 - - ready_to_drive: - id: 13 - target: - telemetry: - watchdog: 0 - signals: - ready_state: - length: 8 - - begin_precharge: - id: 28 - target: - motor_controller: - watchdog: 0 - signals: - signal1: - length: 8 - - hazard: - id: 32 - target: - centre_console: - watchdog: 0 - signals: - state: - length: 8 - - discharge_precharge: - id: 31 - target: - motor_controller: - watchdog: 0 - signals: - signal1: - length: 8 - - state_transition_fault: - id: 34 - target: - telemetry: - watchdog: 0 - signals: - state_machine: - length: 16 - fault_reason: - length: 16 - - allow_charging: - id: 49 - target: - charger: - watchdog: 0 - signals: - signal1: - length: 8 - - power_info: - id: 47 - target: - power_distribution: - watchdog: 0 - signals: - hazard_state: - length: 8 - power_state: - length: 8 + length: 8 \ No newline at end of file diff --git a/libraries/codegen/boards/power_distribution.yaml b/libraries/codegen/boards/power_distribution.yaml index 6daae64ff..e8f3f4188 100644 --- a/libraries/codegen/boards/power_distribution.yaml +++ b/libraries/codegen/boards/power_distribution.yaml @@ -56,3 +56,14 @@ signals: signal1: length: 8 + power_info: + id: 3 + target: + centre_console: + watchdog: 0 + critical: true + signals: + power_state: + length: 8 + pd_fault: + length: 8 diff --git a/libraries/codegen/boards/solar_sense.yaml b/libraries/codegen/boards/solar_sense.yaml index da4f66b3c..36ecbb047 100644 --- a/libraries/codegen/boards/solar_sense.yaml +++ b/libraries/codegen/boards/solar_sense.yaml @@ -139,4 +139,13 @@ length: 16 temp_6: length: 16 + + solar_info: + id: 29 + target: + centre_console: + watchdog: 0 + signals: + solar_fault: + length: 8 \ No newline at end of file diff --git a/libraries/ms-common/inc/exported_enums.h b/libraries/ms-common/inc/exported_enums.h index a47756635..dcaa3beee 100644 --- a/libraries/ms-common/inc/exported_enums.h +++ b/libraries/ms-common/inc/exported_enums.h @@ -1,4 +1,195 @@ #pragma once +#include + +// This file stores enums and defines which are exported between projects to allow both +// sides to use the same enums when sending and receiving CAN Messages over the +// primary network. These will typically take a value of either a STATE (value represents +// one of range of value) or a MASK (value represents a bit position in the field) +// To make things easier all enums in this file must follow a +// slightly modified naming convention. +// +// Example: +// typedef enum { +// EE___ = 0, +// // ... +// NUM_EE___, +// } + +// Common Defines +typedef enum { + EE_RELAY_STATE_OPEN = 0, + EE_RELAY_STATE_CLOSE, + NUM_EE_RELAY_STATES, +} EERelayState; + +// STEERING SIGNALS +// Signals for analog inputs received at the steering board +typedef enum SteeringInfoAnalog { + EE_STEERING_LIGHTS_OFF_STATE = 0, // Turn lights off + EE_STEERING_LIGHTS_RIGHT_STATE, // Right Turn Signal + EE_STEERING_LIGHTS_LEFT_STATE, // Left Turn Signal + NUM_EE_STEERING_LIGHTS, +} SteeringInfoAnalog; + +// Signals for digital inputs sent from the steering board +typedef enum SteeringInfoDigitalMask { + EE_STEERING_CC_DECREASE_BIT = 0, // Signal to decrease cruise control speed + EE_STEERING_CC_INCREASE_BIT, // Signal to increase cruise control speed + EE_STEERING_CC_TOGGLE_BIT, // Toggle cruise control on/off +} SteeringInfoDigitalMask; + +#define EE_STEERING_CC_INCREASE_MASK (1 << EE_STEERING_CC_INCREASE_BIT) +#define EE_STEERING_CC_DECREASE_MASK (1 << EE_STEERING_CC_DECREASE_BIT) +#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 + NUM_EE_DRIVE_OUTPUT_CC_STATES, +} CentreConsoleCCState; + +typedef enum { + EE_DRIVE_OUTPUT_REGEN_OFF_STATE = 0, // Regen Braking enabled, + EE_DRIVE_OUTPUT_REGEN_ON_STATE, // Regen Braking disabled + NUM_EE_DRIVE_OUTPUT_REGEN_STATES, +} CentreConsoleRegenState; + +typedef enum { + EE_DRIVE_OUTPUT_NEUTRAL_STATE = 0, + EE_DRIVE_OUTPUT_DRIVE_STATE, + EE_DRIVE_OUTPUT_REVERSE_STATE, + NUM_EE_DRIVE_OUTPUT_STATES, +} CentreConsoleDriveState; + +typedef enum { + EE_DRIVE_FSM_BEGIN_PRECHARGE_OFF = 0, // Begin precharge signal off + EE_DRIVE_FSM_BEGIN_PRECHARGE_ON, // Begin precharge signal on + NUM_DRIVE_FSM_BEGIN_PRECHARGE_STATES, +} CentreConsoleBeginPrechargeState; + +// POWER DISTRIBUTION (TODO) +typedef enum { + EE_POWER_OFF_STATE = 0, + EE_POWER_ON_STATE, + EE_POWER_DRIVE_STATE, +} PowerDistributionPowerState; + +typedef enum { + EE_PWR_SEL_STATUS_PWR_SUPPLY_MASK = 0, // Mask for bit indicating power supply status + EE_PWR_SEL_STATUS_DCDC_MASK, // Mask for bit indicating dcdc status + EE_PWR_SEL_STATUS_AUX_MASK, // Mask for bit indicating aux status + NUM_EE_PWR_SEL_STATUS_MASKS, +} PowerSelectStatusMasks; + +typedef enum { + EE_PWR_SEL_FAULT_PWR_SUPPLY_OVERCURRENT_BIT = 0, + EE_PWR_SEL_FAULT_PWR_SUPPY_OVERVOLTAGE_BIT, + EE_PWR_SEL_FAULT_DCDC_OVERTEMP_BIT, + EE_PWR_SEL_FAULT_DCDC_OVERCURRENT_BIT, + EE_PWR_SEL_FAULT_DCDC_OVERVOLTAGE_BIT, + EE_PWR_SEL_FAULT_AUX_OVERTEMP_BIT, + EE_PWR_SEL_FAULT_AUX_OVERCURRENT_BIT, + EE_PWR_SEL_FAULT_AUX_OVERVOLTAGE_BIT, +} PowerSelectFaultMasks; + +#define EE_PWR_SEL_FAULT_PWR_SUPPLY_OVERCURRENT_MASK \ + (1 << EE_PWR_SEL_FAULT_PWR_SUPPLY_OVERCURRENT_BIT) + +#define EE_PWR_SEL_FAULT_PWR_SUPPY_OVERVOLTAGE_MASK \ + (1 << EE_PWR_SEL_FAULT_PWR_SUPPY_OVERVOLTAGE_BIT) + +#define EE_PWR_SEL_FAULT_DCDC_OVERTEMP_MASK (1 << EE_PWR_SEL_FAULT_DCDC_OVERTEMP_BIT) + +#define EE_PWR_SEL_FAULT_DCDC_OVERCURRENT_MASK (1 << EE_PWR_SEL_FAULT_DCDC_OVERCURRENT_BIT) + +#define EE_PWR_SEL_FAULT_DCDC_OVERVOLTAGE_MASK (1 << EE_PWR_SEL_FAULT_DCDC_OVERVOLTAGE_MASK) + +#define EE_PWR_SEL_FAULT_AUX_OVERTEMP_MASK (1 << EE_PWR_SEL_FAULT_AUX_OVERTEMP_BIT) + +#define EE_PWR_SEL_FAULT_AUX_OVERCURRENT_MASK (1 << EE_PWR_SEL_FAULT_AUX_OVERCURRENT_BIT) + +#define EE_PWR_SEL_FAULT_AUX_OVERVOLTAGE_MASK (1 << EE_PWR_SEL_FAULT_AUX_OVERVOLTAGE_BIT) + +// BMS SIGNALS +typedef enum EEBatteryHeartbeatFaultSource { + EE_BPS_FAULT_SOURCE_KILLSWITCH = 0, + EE_BPS_FAULT_SOURCE_AFE_CELL, + EE_BPS_FAULT_SOURCE_AFE_TEMP, + EE_BPS_FAULT_SOURCE_AFE_FSM, + EE_BPS_FAULT_SOURCE_RELAY, + EE_BPS_FAULT_SOURCE_CURRENT_SENSE, + EE_BPS_FAULT_SOURCE_ACK_TIMEOUT, + NUM_EE_BPS_FAULT_SOURCES, +} EEBatteryHeartbeatFaultSource; + +// Battery heartbeat bitset representing fault reason +typedef uint8_t EEBatteryHeartbeatState; +#define EE_BPS_STATE_OK 0x0 +#define EE_BPS_STATE_FAULT_KILLSWITCH (1 << EE_BPS_FAULT_SOURCE_KILLSWITCH) +#define EE_BPS_STATE_FAULT_AFE_CELL (1 << EE_BPS_FAULT_SOURCE_AFE_CELL) +#define EE_BPS_STATE_FAULT_AFE_TEMP (1 << EE_BPS_FAULT_SOURCE_AFE_TEMP) +#define EE_BPS_STATE_FAULT_AFE_FSM (1 << EE_BPS_FAULT_SOURCE_AFE_FSM) +#define EE_BPS_STATE_FAULT_RELAY (1 << EE_BPS_FAULT_SOURCE_RELAY) +#define EE_BPS_STATE_FAULT_CURRENT_SENSE (1 << EE_BPS_FAULT_SOURCE_CURRENT_SENSE) +#define EE_BPS_STATE_FAULT_ACK_TIMEOUT (1 << EE_BPS_FAULT_SOURCE_ACK_TIMEOUT) + +// SOLAR SENSE SIGNALS (TODO) +typedef enum EESolarFault { + // An MCP3427 is faulting too much, data is the solar DataPoint associated with the faulty MCP3427 + EE_SOLAR_FAULT_MCP3427 = 0, + + // An MPPT had an overcurrent, the least significant 4 bits of data is the index of the MPPT + // that faulted, the most significant 4 bits is a 4-bit bitmask of which branches faulted. + EE_SOLAR_FAULT_MPPT_OVERCURRENT, + + // An MPPT had an overvoltage or overtemperature, data is the index of the MPPT that faulted + EE_SOLAR_FAULT_MPPT_OVERVOLTAGE, + EE_SOLAR_FAULT_MPPT_OVERTEMPERATURE, + + // The current from the whole array is over the threshold. No data. + EE_SOLAR_FAULT_OVERCURRENT, + + // The current from the whole array is negative, so we aren't charging. No data. + EE_SOLAR_FAULT_NEGATIVE_CURRENT, + + // The sum of the sensed voltages is over the threshold. No data. + EE_SOLAR_FAULT_OVERVOLTAGE, + + // The temperature of any array thermistor is over our threshold. Data is the index of the too-hot + // thermistor. + EE_SOLAR_FAULT_OVERTEMPERATURE, + + // The temperature of the fan is over the threshold. No data. + EE_SOLAR_FAULT_FAN_OVERTEMPERATURE, + + // Fan failure detected. No data. + EE_SOLAR_FAULT_FAN_FAIL, + + // Relay failure to open + EE_SOLAR_RELAY_OPEN_ERROR, + + NUM_EE_SOLAR_FAULTS, +} EESolarFault; + +typedef enum EESolarRelayOpenErrorReason { + // The drv120 relay has signaled that overtemp/undervolt lockout conditions have been triggered + EE_SOLAR_RELAY_ERROR_DRV120, + // The drv120 relay has not opened or the current has exceeded + EE_SOLAR_RELAY_ERROR_CURRENT_EXCEEDED_NOT_OPEN, + // The drv120 relay's current has not been set + EE_RELAY_ERROR_CURRENT_NEVER_SET, + + NUM_EE_SOLAR_RELAY_OPEN_ERROR_REASON +} EESolarRelayOpenErrorReason; enum GlobalErrorCode { NO_ERROR = 0, diff --git a/projects/bms_carrier/inc/exported_enums.h b/projects/bms_carrier/inc/exported_enums.h deleted file mode 100644 index df07049d3..000000000 --- a/projects/bms_carrier/inc/exported_enums.h +++ /dev/null @@ -1,210 +0,0 @@ -#pragma once - -// This file stores enums which are exported between projects to allow both -// sides to use the same enums when sending and receiving CAN Messages over the -// primary network. To make things easier all enums in this file must follow a -// slightly modified naming convention. -// -// Example: -// typedef enum { -// EE___ = 0, -// // ... -// NUM_EE___, -// } EE - -typedef enum { - EE_CONSOLE_FAULT_AREA_DRIVE_FSM = 0, - EE_CONSOLE_FAULT_AREA_POWER_MAIN, - EE_CONSOLE_FAULT_AREA_POWER_OFF, - EE_CONSOLE_FAULT_AREA_POWER_AUX, - EE_CONSOLE_FAULT_AREA_BPS_HEARTBEAT, - NUM_EE_CONSOLE_FAULT_AREAS -} EEConsoleFaultArea; - -typedef enum { - EE_DRIVE_FSM_STEP_MCI_RELAY_STATE = 0, - EE_DRIVE_FSM_STEP_PRECHARGE_TIMEOUT, - EE_DRIVE_FSM_STEP_EBRAKE_STATE, - EE_DRIVE_FSM_STEP_MCI_OUTPUT, - NUM_EE_DRIVE_FSM_STEPS -} EEDriveFsmStep; - -typedef enum { - EE_POWER_MAIN_SEQUENCE_CONFIRM_AUX_STATUS = 0, - EE_POWER_MAIN_SEQUENCE_TURN_ON_DRIVER_BMS, - EE_POWER_MAIN_SEQUENCE_CONFIRM_BATTERY_STATUS, - EE_POWER_MAIN_SEQUENCE_CLOSE_BATTERY_RELAYS, - EE_POWER_MAIN_SEQUENCE_CONFIRM_DCDC, - EE_POWER_MAIN_SEQUENCE_TURN_ON_EVERYTHING, - NUM_EE_POWER_MAIN_SEQUENCES -} EEPowerMainSequence; - -typedef enum { - EE_POWER_OFF_SEQUENCE_DISCHARGE_PRECHARGE = 0, - EE_POWER_OFF_SEQUENCE_TURN_OFF_EVERYTHING, - EE_POWER_OFF_SEQUENCE_OPEN_BATTERY_RELAYS, - NUM_EE_POWER_OFF_SEQUENCES -} EEPowerOffSequence; - -typedef enum { - EE_POWER_AUX_SEQUENCE_CONFIRM_AUX_STATUS = 0, - EE_POWER_AUX_SEQUENCE_TURN_ON_EVERYTHING, - NUM_EE_POWER_AUX_SEQUENCES -} EEPowerAuxSequence; - -typedef enum { - EE_CHARGER_SET_RELAY_STATE_OPEN = 0, - EE_CHARGER_SET_RELAY_STATE_CLOSE, - NUM_EE_CHARGER_SET_RELAY_STATES, -} EEChargerSetRelayState; - -typedef enum { - EE_CHARGER_CONN_STATE_DISCONNECTED = 0, - EE_CHARGER_CONN_STATE_CONNECTED, - NUM_EE_CHARGER_CONN_STATES, -} EEChargerConnState; - -typedef enum { - EE_DRIVE_OUTPUT_OFF = 0, - EE_DRIVE_OUTPUT_DRIVE, - EE_DRIVE_OUTPUT_REVERSE, - NUM_EE_DRIVE_OUTPUTS, -} EEDriveOutput; - -typedef enum { - EE_RELAY_ID_BATTERY = 0, - EE_RELAY_ID_MOTOR_CONTROLLER, - EE_RELAY_ID_SOLAR, - NUM_EE_RELAY_IDS, -} EERelayId; - -// Light type to be used with a SYSTEM_CAN_MESSAGE_LIGHTS_STATE message. -typedef enum EELightType { - EE_LIGHT_TYPE_DRL = 0, - EE_LIGHT_TYPE_BRAKES, - EE_LIGHT_TYPE_STROBE, - EE_LIGHT_TYPE_SIGNAL_RIGHT, - EE_LIGHT_TYPE_SIGNAL_LEFT, - EE_LIGHT_TYPE_SIGNAL_HAZARD, - EE_LIGHT_TYPE_HIGH_BEAMS, - EE_LIGHT_TYPE_LOW_BEAMS, - NUM_EE_LIGHT_TYPES, -} EELightType; - -// Light state to be used with a SYSTEM_CAN_MESSAGE_LIGHTS message. -typedef enum EELightState { - EE_LIGHT_STATE_OFF = 0, // - EE_LIGHT_STATE_ON, // - NUM_EE_LIGHT_STATES, // -} EELightState; - -// Horn state, used with a SYSTEM_CAN_MESSAGE_HORN message. -typedef enum EEHornState { - EE_HORN_STATE_OFF = 0, // - EE_HORN_STATE_ON, // - NUM_EE_HORN_STATES, // -} EEHornState; - -typedef enum { - EE_RELAY_STATE_OPEN = 0, - EE_RELAY_STATE_CLOSE, - NUM_EE_RELAY_STATES, -} EERelayState; - -// For battery heartbeat -typedef enum EEBatteryHeartbeatFaultSource { - EE_BPS_FAULT_SOURCE_KILLSWITCH = 0, - EE_BPS_FAULT_SOURCE_AFE_CELL, - EE_BPS_FAULT_SOURCE_AFE_TEMP, - EE_BPS_FAULT_SOURCE_AFE_FSM, - EE_BPS_FAULT_SOURCE_RELAY, - EE_BPS_FAULT_SOURCE_CURRENT_SENSE, - EE_BPS_FAULT_SOURCE_ACK_TIMEOUT, - NUM_EE_BPS_FAULT_SOURCES, -} EEBatteryHeartbeatFaultSource; - -// Battery heartbeat bitset representing fault reason -typedef uint8_t EEBatteryHeartbeatState; -#define EE_BPS_STATE_OK 0x0 -#define EE_BPS_STATE_FAULT_KILLSWITCH (1 << EE_BPS_FAULT_SOURCE_KILLSWITCH) -#define EE_BPS_STATE_FAULT_AFE_CELL (1 << EE_BPS_FAULT_SOURCE_AFE_CELL) -#define EE_BPS_STATE_FAULT_AFE_TEMP (1 << EE_BPS_FAULT_SOURCE_AFE_TEMP) -#define EE_BPS_STATE_FAULT_AFE_FSM (1 << EE_BPS_FAULT_SOURCE_AFE_FSM) -#define EE_BPS_STATE_FAULT_RELAY (1 << EE_BPS_FAULT_SOURCE_RELAY) -#define EE_BPS_STATE_FAULT_CURRENT_SENSE (1 << EE_BPS_FAULT_SOURCE_CURRENT_SENSE) -#define EE_BPS_STATE_FAULT_ACK_TIMEOUT (1 << EE_BPS_FAULT_SOURCE_ACK_TIMEOUT) - -typedef enum { - EE_DRIVE_STATE_DRIVE = 0, - EE_DRIVE_STATE_NEUTRAL, - EE_DRIVE_STATE_REVERSE, - EE_DRIVE_STATE_PARKING, - NUM_EE_DRIVE_STATES, -} EEDriveState; - -typedef enum { - EE_CRUISE_CONTROL_COMMAND_TOGGLE = 0, - EE_CRUISE_CONTROL_COMMAND_INCREASE, - EE_CRUISE_CONTROL_COMMAND_DECREASE, - NUM_EE_CRUISE_CONTROL_COMMANDS -} EECruiseControl; - -#define EE_PEDAL_VALUE_DENOMINATOR ((1 << 12)) - -typedef enum EEChargerFault { - EE_CHARGER_FAULT_HARDWARE_FAILURE = 0, - EE_CHARGER_FAULT_OVER_TEMP, - EE_CHARGER_FAULT_WRONG_VOLTAGE, - EE_CHARGER_FAULT_POLARITY_FAILURE, - EE_CHARGER_FAULT_COMMUNICATION_TIMEOUT, - EE_CHARGER_FAULT_CHARGER_OFF, - NUM_EE_CHARGER_FAULTS, -} EEChargerFault; - -typedef enum EESolarFault { - // An MCP3427 is faulting too much, data is the solar DataPoint associated with the faulty MCP3427 - EE_SOLAR_FAULT_MCP3427 = 0, - - // An MPPT had an overcurrent, the least significant 4 bits of data is the index of the MPPT - // that faulted, the most significant 4 bits is a 4-bit bitmask of which branches faulted. - EE_SOLAR_FAULT_MPPT_OVERCURRENT, - - // An MPPT had an overvoltage or overtemperature, data is the index of the MPPT that faulted - EE_SOLAR_FAULT_MPPT_OVERVOLTAGE, - EE_SOLAR_FAULT_MPPT_OVERTEMPERATURE, - - // The current from the whole array is over the threshold. No data. - EE_SOLAR_FAULT_OVERCURRENT, - - // The current from the whole array is negative, so we aren't charging. No data. - EE_SOLAR_FAULT_NEGATIVE_CURRENT, - - // The sum of the sensed voltages is over the threshold. No data. - EE_SOLAR_FAULT_OVERVOLTAGE, - - // The temperature of any array thermistor is over our threshold. Data is the index of the too-hot - // thermistor. - EE_SOLAR_FAULT_OVERTEMPERATURE, - - // The temperature of the fan is over the threshold. No data. - EE_SOLAR_FAULT_FAN_OVERTEMPERATURE, - - // Fan failure detected. No data. - EE_SOLAR_FAULT_FAN_FAIL, - - // Relay failure to open - EE_SOLAR_RELAY_OPEN_ERROR, - - NUM_EE_SOLAR_FAULTS, -} EESolarFault; - -typedef enum EESolarRelayOpenErrorReason { - // The drv120 relay has signaled that overtemp/undervolt lockout conditions have been triggered - EE_SOLAR_RELAY_ERROR_DRV120, - // The drv120 relay has not opened or the current has exceeded - EE_SOLAR_RELAY_ERROR_CURRENT_EXCEEDED_NOT_OPEN, - // The drv120 relay's current has not been set - EE_RELAY_ERROR_CURRENT_NEVER_SET, - - NUM_EE_SOLAR_RELAY_OPEN_ERROR_REASON -} EESolarRelayOpenErrorReason; diff --git a/projects/centre_console/inc/cc_buttons.h b/projects/centre_console/inc/cc_buttons.h index 0602f0b96..c96e1a13c 100644 --- a/projects/centre_console/inc/cc_buttons.h +++ b/projects/centre_console/inc/cc_buttons.h @@ -4,13 +4,19 @@ #include "i2c.h" #include "pca9555_gpio_expander.h" #include "pca9555_gpio_expander_defs.h" -#include "power_fsm.h" +#include "update_dashboard.h" #define PCA9555_REG_DEFAULT 0xFF -#define DRIVE_BTN_MASK 0x01 -#define POWER_BTN_MASK 0x02 -#define NEUTRAL_BTN_MASK 0x04 -#define REVERSE_BTN_MASK 0x08 +// Masks for button inputs based on a 16-bit pca9555 register value +typedef enum ConsoleButtonMask { + REGEN_BTN_MASK = 0x040, // 0_6 + HAZARD_BTN_MASK = 0x080, // 0_7 + DRIVE_BTN_MASK = 0x100, // 1_0 + POWER_BTN_MASK = 0x200, // 1_1 + NEUTRAL_BTN_MASK = 0x400, // 1_2 + REVERSE_BTN_MASK = 0x800, // 1_3 +} ConsoleButtonMask; StatusCode get_button_press(void); +StatusCode init_cc_buttons(Task *cc_master_task); diff --git a/projects/centre_console/inc/cc_displays.h b/projects/centre_console/inc/cc_displays.h deleted file mode 100644 index f6f62af97..000000000 --- a/projects/centre_console/inc/cc_displays.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "log.h" -// #include "seg_display.h" - -// Updates the 3 centre console displays with new values and will be called in the slow cycle -void cc_displays_update(void); diff --git a/projects/centre_console/inc/cc_hw_defs.h b/projects/centre_console/inc/cc_hw_defs.h index d90d08e16..ced6341f5 100644 --- a/projects/centre_console/inc/cc_hw_defs.h +++ b/projects/centre_console/inc/cc_hw_defs.h @@ -1,16 +1,27 @@ #pragma once // Definitions for all HW components on Centre Console -// TODO(mitchellostler): Update with actual addresses once schematic complete - // I/O expander connected to backlights +#define CC_IO_EXP_ADDR 0x20 #define CC_IO_EXP_I2C_PORT NUM_I2C_PORTS #define CC_IO_EXP_SDA \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } #define CC_IO_EXP_SCL \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } +// Centre Console LEDs +#define HAZARD_LED_ADDR \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } +#define LEFT_LED_ADDR \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO1_7 } +#define RIGHT_LED_ADDR \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO1_6 } +#define CRUISE_LED_ADDR \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } +#define REGEN_LED_ADDR \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_5 } + // Button Inputs and backlit LEDS -#define CC_BTN_PUSH_START \ +#define CC_BTN_POWER \ { .port = NUM_GPIO_PORTS - 1, .pin = GPIO_PINS_PER_PORT - 1 } #define CC_BTN_STATE_DRIVE \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } @@ -24,52 +35,21 @@ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } // LEDs for backlights on buttons -#define CC_LED_PUSH_START \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } +#define CC_LED_POWER \ + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } #define CC_LED_STATE_DRIVE \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } #define CC_LED_STATE_NEUTRAL \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } #define CC_LED_STATE_REVERSE \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } #define CC_LED_STATE_REVERSE \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define CC_LED_DRL_LIGHTS \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } #define CC_LED_REGEN_BRAKE \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } - -// Warning/indicator LEDS -#define CC_LED_TURN_SIGNAL_LEFT \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define CC_LED_TURN_SIGNAL_RIGHT \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define CC_LED_BPS_FAULT_INDICATOR \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } + { .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_4 } // Seven Segment display GPIO Addresses -// BATT display (V) -#define BATT_DISPLAY_BCD_A \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define BATT_DISPLAY_BCD_B \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define BATT_DISPLAY_BCD_C \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define BATT_DISPLAY_BCD_D \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define BATT_DISPLAY_DIGIT_SEL_1 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define BATT_DISPLAY_DIGIT_SEL_2 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } -#define BATT_DISPLAY_DIGIT_SEL_3 \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } - -// Speedometer PWM config -#define SPDMTR_PWM_TIMER NUM_PWM_TIMERS -#define SPDMTR_PWM_PIN \ - { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } - -// Seven Segment Display GPIO Addresses for Centre Console +// Cruise Control #define CC_DISP1 \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } #define CC_DISP2 \ @@ -86,6 +66,13 @@ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } #define CC_DISP8 \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } +#define CC_DISPLAY \ + { \ + .A = CC_DISP1, .B = CC_DISP2, .C = CC_DISP3, .D = CC_DISP4, .DP = CC_DISP5, .D1 = CC_DISP6, \ + .D2 = CC_DISP7, .D3 = CC_DISP8 \ + } + +// Speed #define SPD_DISP1 \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } #define SPD_DISP2 \ @@ -102,6 +89,13 @@ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } #define SPD_DISP8 \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } +#define SPD_DISPLAY \ + { \ + .A = CC_DISP1, .B = CC_DISP2, .C = CC_DISP3, .D = CC_DISP4, .DP = CC_DISP5, .D1 = CC_DISP6, \ + .D2 = CC_DISP7, .D3 = CC_DISP8 \ + } + +// Battery #define BATT_DISP1 \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } #define BATT_DISP2 \ @@ -118,3 +112,8 @@ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } #define BATT_DISP8 \ { .port = NUM_GPIO_PORTS, .pin = GPIO_PINS_PER_PORT } +#define BATT_DISPLAY \ + { \ + .A = BATT_DISP1, .B = BATT_DISP2, .C = BATT_DISP3, .D = BATT_DISP4, .DP = BATT_DISP5, \ + .D1 = BATT_DISP6, .D2 = BATT_DISP7, .D3 = BATT_DISP8 \ + } diff --git a/projects/centre_console/inc/drive_fsm.h b/projects/centre_console/inc/drive_fsm.h index e49c3b526..8f4f53db9 100644 --- a/projects/centre_console/inc/drive_fsm.h +++ b/projects/centre_console/inc/drive_fsm.h @@ -1,20 +1,16 @@ #pragma once #include "delay.h" +#include "exported_enums.h" #include "fsm.h" -#include "fsm_shared_mem.h" #include "gpio.h" #include "gpio_it.h" #include "log.h" #include "notify.h" #include "task.h" -#define NUM_DRIVE_STATES 4 -#define NUM_DRIVE_TRANSITIONS 8 - -#define BEGIN_PRECHARGE_SIGNAL 2 -#define PRECHARGE_STATE_COMPLETE 2 -#define NUMBER_OF_CYCLES_TO_WAIT 10 +#define NUM_DRIVE_STATES 3 +#define NUM_DRIVE_TRANSITIONS 4 DECLARE_FSM(drive); @@ -22,7 +18,6 @@ typedef enum driveState { NEUTRAL = 0, DRIVE, REVERSE, - DO_PRECHARGE, // turn on precharge and get ack } driveState; typedef enum driveEvents { @@ -41,4 +36,6 @@ typedef enum driveEvents { #define REVERSE_GPIO_ADDR \ { .port = GPIO_PORT_A, .pin = 7 } +StateId get_drive_state(void); + StatusCode init_drive_fsm(void); diff --git a/projects/centre_console/inc/fsm_shared_mem.h b/projects/centre_console/inc/fsm_shared_mem.h deleted file mode 100644 index 68af544fd..000000000 --- a/projects/centre_console/inc/fsm_shared_mem.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include "fsm.h" -#include "fsm_shared_mem.h" -#include "log.h" -#include "semaphore.h" - -typedef struct FSMStorage { - StateId power_state; - StatusCode power_error_code; - StatusCode drive_error_code; - Mutex mutex; -} FSMStorage; - -// Initialize fsm shared memory -void fsm_shared_mem_init(); - -// Set Power FSM state in shared memory -void fsm_shared_mem_set_power_state(StateId state); - -// Get Power FSM state -StateId fsm_shared_mem_get_power_state(); - -// Set Power FSM Error Code -void fsm_shared_mem_set_power_error_code(StatusCode code); - -// Get Power FSM Error Code -StatusCode fsm_shared_mem_get_power_error_code(); - -// Set Drive FSM Error Code -void fsm_shared_mem_set_drive_error_code(StatusCode code); - -// Get Drive FSM Error Code -StatusCode fsm_shared_mem_get_drive_error_code(); diff --git a/projects/centre_console/inc/power_fsm.h b/projects/centre_console/inc/power_fsm.h deleted file mode 100644 index bb1104771..000000000 --- a/projects/centre_console/inc/power_fsm.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "delay.h" -#include "fsm.h" -#include "fsm_shared_mem.h" -#include "gpio.h" -#include "log.h" -#include "power_fsm_sequence.h" -#include "task.h" - -#define NUM_POWER_STATES 14 -#define NUM_POWER_TRANSITIONS 36 - -#define START_BUTTON_EVENT 0 - -DECLARE_FSM(power); - -typedef enum PowerFsmStateId { - POWER_FSM_STATE_OFF = 0, - // -> MAIN Sequence - POWER_FSM_CONFIRM_AUX_STATUS, - POWER_FSM_SEND_PD_BMS, - POWER_FSM_CONFIRM_BATTERY_STATUS, - POWER_FSM_CLOSE_BATTERY_RELAYS, - POWER_FSM_CONFIRM_DC_DC, - POWER_FSM_TURN_ON_EVERYTHING, - POWER_FSM_POWER_MAIN_COMPLETE, - POWER_FSM_STATE_MAIN, - // -> AUX Sequence - // Confirm aux status - // Turn on everything - POWER_FSM_STATE_AUX, - // -> FAULT Sequence (none) - POWER_FSM_STATE_FAULT, - // -> OFF Sequence - POWER_FSM_DISCHARGE_PRECHARGE, - POWER_FSM_TURN_OFF_EVERYTHING, - POWER_FSM_OPEN_RELAYS -} PowerFsmStateId; - -typedef struct PowerFsmContext { - PowerFsmStateId latest_state; - PowerFsmStateId target_state; -} PowerFsmContext; - -extern PowerFsmContext power_context; - -StatusCode init_power_fsm(PowerFsmStateId inital_state); diff --git a/projects/centre_console/inc/power_fsm_can_data.h b/projects/centre_console/inc/power_fsm_can_data.h deleted file mode 100644 index 78963be40..000000000 --- a/projects/centre_console/inc/power_fsm_can_data.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -// Aux battery status bits -// https://uwmidsun.atlassian.net/wiki/spaces/ELEC/pages/3149398021/FWXV+Power+Select+Design -#define AUX_STATUS_BITS 0x04 -#define AUX_FAULT_BITS 0xE0 - -// PD messages (Todo) -#define PD_FAULT 0x00 - -// BMS send power notification (Todo) -#define SET_BMS_POWER_NOTIFY 0x01 - -// BPS hearbeat success message (Todo) -#define BPS_HEARTBEAT 0x00 - -// Relay setters (Todo) -#define SET_CLOSE_RELAY_STATE_MASK 0x01 -#define SET_CLOSE_RELAY_STATE_STATE 0x01 - -// Relay closed status (Todo) -#define CLOSE_HV_STATUS 0x01 -#define CLOSE_GND_STATUS 0x01 - -// DCDC status bits -// https://uwmidsun.atlassian.net/wiki/spaces/ELEC/pages/3149398021/FWXV+Power+Select+Design -#define DCDC_STATUS_BITS 0x02 -#define DCDC_FAULT_BITS 0x1C - -// PD send turn on everything notification (Todo) -#define SET_TURN_ON_EVERYTHING_NOTIFICATION 0x00 - -// MCI send ready to drive (Todo) -#define SET_READY_TO_DRIVE 0x01 - -// MCI set discharge precharge (Todo) -#define SET_DISCHARGE_PRECHARGE 0x01 - -// MCI precharge completed -#define PRECHARGE_COMPLETED_NOTIFCIATION 0x01 - -// Relay setters (Todo) -#define SET_OPEN_RELAY_STATE_MASK 0x00 -#define SET_OPEN_RELAY_STATE_STATE 0x00 - -// Relay open status (Todo) -#define OPEN_HV_STATUS 0x01 -#define OPEN_GND_STATUS 0x01 diff --git a/projects/centre_console/inc/power_fsm_sequence.h b/projects/centre_console/inc/power_fsm_sequence.h deleted file mode 100644 index d0933fd2a..000000000 --- a/projects/centre_console/inc/power_fsm_sequence.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "fsm.h" - -// Tell power select to check any aux faults before enabling power -void power_fsm_confirm_aux_status_output(void *context); -void power_fsm_confirm_aux_status_input(Fsm *fsm, void *context); - -// Tell Power distribution to power on BMS board -void power_fsm_send_pd_bms_output(void *context); -void power_fsm_send_pd_bms_input(Fsm *fsm, void *context); - -// Confirms battery checks, waits for ack -void power_fsm_confirm_battery_status_output(void *context); -void power_fsm_confirm_battery_status_input(Fsm *fsm, void *context); - -// Transmits to BMS to close relays -void power_fsm_close_battery_relays_output(void *context); -void power_fsm_close_battery_relays_input(Fsm *fsm, void *context); - -// Power Select confirms DCDC -void power_fsm_confirm_dc_dc_output(void *context); -void power_fsm_confirm_dc_dc_input(Fsm *fsm, void *context); - -// Power Distribution enables all boards -void power_fsm_turn_on_everything_output(void *context); -void power_fsm_turn_on_everything_input(Fsm *fsm, void *context); - -// Sends “ready to drive” to MCI -void power_fsm_power_main_complete_output(void *context); -void power_fsm_power_main_complete_input(Fsm *fsm, void *context); - -// Send message to MCI to discharge precharge -void power_fsm_discharge_precharge_output(void *context); -void power_fsm_discharge_precharge_input(Fsm *fsm, void *context); - -// Tell Power distribution to turn off the relevant boards -void power_fsm_turn_off_everything_output(void *context); -void power_fsm_turn_off_everything_input(Fsm *fsm, void *context); - -// Tell BMS to open the relays -void power_fsm_open_relays_output(void *context); -void power_fsm_open_relays_input(Fsm *fsm, void *context); diff --git a/projects/centre_console/inc/update_dashboard.h b/projects/centre_console/inc/update_dashboard.h new file mode 100644 index 000000000..17606ddf4 --- /dev/null +++ b/projects/centre_console/inc/update_dashboard.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +#include "exported_enums.h" +#include "status.h" + +typedef enum MainTaskBtnEvents { + POWER_BUTTON_EVENT = 0, + REGEN_BUTTON_EVENT, + HAZARD_BUTTON_EVENT, +} MainTaskBtnEvents; + +// Initializes outputs for dashboard. Must be called after scheduler start +StatusCode dashboard_init(); + +// Updates indicators based on notification value and CAN messages +void update_indicators(uint32_t notif); + +// Updates cruise control values based on inputs from steering +void monitor_cruise_control(void); + +// Update 7-seg displays +void update_displays(void); + +// Update drive output based +void update_drive_output(uint32_t notif); diff --git a/projects/centre_console/src/cc_buttons.c b/projects/centre_console/src/cc_buttons.c index 3ef7638f4..062525548 100644 --- a/projects/centre_console/src/cc_buttons.c +++ b/projects/centre_console/src/cc_buttons.c @@ -1,33 +1,46 @@ #include "cc_buttons.h" +static Task *cc_notify_task = NULL; + // Notifies drive/power task of button press event StatusCode get_button_press(void) { - uint8_t pca9555_reg_val = 0; // TODO: Migrate this read to PCA9555 - i2c_read_reg(I2C_PORT_1, PCA9555_I2C_ADDR, INPUT1, &pca9555_reg_val, 1); + uint16_t pca9555_reg_val = 0; + i2c_read_reg(I2C_PORT_1, PCA9555_I2C_ADDR, INPUT0, (uint8_t *)&pca9555_reg_val, 2); if (pca9555_reg_val == PCA9555_REG_DEFAULT) { // No button pressed return STATUS_CODE_OK; + } + if ((~(pca9555_reg_val)®EN_BTN_MASK) != 0) { + LOG_DEBUG("REGEN PRESSED\n"); + notify(cc_notify_task, REGEN_BUTTON_EVENT); + } + if ((~(pca9555_reg_val)&HAZARD_BTN_MASK) != 0) { + LOG_DEBUG("HAZARD PRESSED\n"); + notify(cc_notify_task, HAZARD_BUTTON_EVENT); + } + if ((~(pca9555_reg_val)&POWER_BTN_MASK) != 0) { + LOG_DEBUG("POWER PRESSED\n"); + notify(cc_notify_task, POWER_BUTTON_EVENT); + } - } else if ((~(pca9555_reg_val)&DRIVE_BTN_MASK) != 0) { + if ((~(pca9555_reg_val)&DRIVE_BTN_MASK) != 0) { LOG_DEBUG("DRIVE PRESSED\n"); notify(drive, DRIVE_BUTTON_EVENT); - - } else if ((~(pca9555_reg_val)&NEUTRAL_BTN_MASK) != 0) { + } + if ((~(pca9555_reg_val)&NEUTRAL_BTN_MASK) != 0) { LOG_DEBUG("NEUT PRESSED\n"); notify(drive, NEUTRAL_BUTTON_EVENT); - - } else if ((~(pca9555_reg_val)&REVERSE_BTN_MASK) != 0) { + } + if ((~(pca9555_reg_val)&REVERSE_BTN_MASK) != 0) { LOG_DEBUG("REV PRESSED\n"); notify(drive, REVERSE_BUTTON_EVENT); - - } else if ((~(pca9555_reg_val)&POWER_BTN_MASK) != 0) { - LOG_DEBUG("POWER PRESSED\n"); - notify(power, START_BUTTON_EVENT); - - } else { - return STATUS_CODE_OUT_OF_RANGE; } return STATUS_CODE_OK; } + +StatusCode init_cc_buttons(Task *task) { + cc_notify_task = task; + return STATUS_CODE_OK; +} diff --git a/projects/centre_console/src/cc_displays.c b/projects/centre_console/src/cc_displays.c deleted file mode 100644 index e2f92c9f1..000000000 --- a/projects/centre_console/src/cc_displays.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "cc_displays.h" - -#include "can.h" -#include "cc_hw_defs.h" -#include "centre_console_getters.h" -#include "centre_console_setters.h" -#include "centre_console_tx_structs.h" -#include "gpio.h" -#include "log.h" -#include "seg_display.h" - -// Multiplication Factor to convert CAN Velocity in 100 * m/s to kph -#define CONVERT_VELOCITY_TO_SPEED 0.018 - -SegDisplay cc_display = { .A = CC_DISP1, - .B = CC_DISP2, - .C = CC_DISP3, - .D = CC_DISP4, - .DP = CC_DISP5, - .D1 = CC_DISP6, - .D2 = CC_DISP7, - .D3 = CC_DISP8 }; -SegDisplay speed_display = { .A = SPD_DISP1, - .B = SPD_DISP2, - .C = SPD_DISP3, - .D = SPD_DISP4, - .DP = SPD_DISP5, - .D1 = SPD_DISP6, - .D2 = SPD_DISP7, - .D3 = SPD_DISP8 }; -SegDisplay batt_perc_display = { .A = BATT_DISP1, - .B = BATT_DISP2, - .C = BATT_DISP3, - .D = BATT_DISP4, - .DP = BATT_DISP5, - .D1 = BATT_DISP6, - .D2 = BATT_DISP7, - .D3 = BATT_DISP8 }; - -void cc_displays_update(void) { - seg_display_init(&cc_display); - seg_display_init(&speed_display); - seg_display_init(&batt_perc_display); - // Read data from CAN structs and update displays with those values - // TODO: Get this value from the source when we have the cruise_control value - uint8_t cruise_control_val = g_tx_struct.drive_output_cruise_control; - // Convert motor_velocity value to speed by averaging the right and left, dividing by 100, and - // multiplying by 3.6 to get kph - float speed_val = (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) * - CONVERT_VELOCITY_TO_SPEED; - uint16_t batt_perc_val = get_battery_vt_batt_perc(); - seg_display_set_int(&cc_display, cruise_control_val); - if (speed_val >= 100) { - seg_display_set_int(&speed_display, (int)speed_val); - } else { - seg_display_set_float(&speed_display, speed_val); - } - seg_display_set_int(&batt_perc_display, batt_perc_val); -} diff --git a/projects/centre_console/src/cc_indicators.c b/projects/centre_console/src/cc_indicators.c deleted file mode 100644 index 5542ebc14..000000000 --- a/projects/centre_console/src/cc_indicators.c +++ /dev/null @@ -1,67 +0,0 @@ -#include "can.h" -#include "gpio.h" -#include "log.h" -#include "pca9555_gpio_expander.h" -#include "power_fsm.h" -#include "seg_display.h" - -#define NUM_DRIVE_LED 5 - -typedef enum DriveLeds { - HAZARD_LED = 0, - LEFT_LED, - RIGHT_LED, - CRUISE_LED, - REGEN_LED, -} DriveLeds; - -static Pca9555GpioAddress s_drive_btn_leds[NUM_DRIVE_LED] = { - [HAZARD_LED] = { .i2c_address = 0x20, .pin = PCA9555_PIN_IO0_4 }, - [LEFT_LED] = { .i2c_address = 0x20, .pin = PCA9555_PIN_IO1_7 }, - [RIGHT_LED] = { .i2c_address = 0x20, .pin = PCA9555_PIN_IO1_6 }, - [CRUISE_LED] = { .i2c_address = 0x20, .pin = PCA9555_PIN_IO0_4 }, - [REGEN_LED] = { .i2c_address = 0x20, .pin = PCA9555_PIN_IO0_5 } -}; - -StatusCode update_indicators(bool cruise_control_toggle, bool hazard_info, - bool regen_braking_toggle, bool left_signal_toggle, - bool right_signal_toggle) { - // BOOL PARAMETERS - // Cruise control: cruise_control_toggle - // regen braking: regen_braking toggle - // Left signal: left_signal_toggle - // Right Signal: tight_signal_toggle - // Hazard: hazard_info - - if (cruise_control_toggle) { - pca9555_gpio_set_state(&s_drive_btn_leds[CRUISE_LED], PCA9555_GPIO_STATE_HIGH); - } else { - pca9555_gpio_set_state(&s_drive_btn_leds[CRUISE_LED], PCA9555_GPIO_STATE_LOW); - } - - if (hazard_info) { - pca9555_gpio_set_state(&s_drive_btn_leds[HAZARD_LED], PCA9555_GPIO_STATE_HIGH); - } else { - pca9555_gpio_set_state(&s_drive_btn_leds[HAZARD_LED], PCA9555_GPIO_STATE_LOW); - } - - if (regen_braking_toggle) { - pca9555_gpio_set_state(&s_drive_btn_leds[REGEN_LED], PCA9555_GPIO_STATE_HIGH); - } else { - pca9555_gpio_set_state(&s_drive_btn_leds[REGEN_LED], PCA9555_GPIO_STATE_LOW); - } - - if (left_signal_toggle) { - pca9555_gpio_set_state(&s_drive_btn_leds[LEFT_LED], PCA9555_GPIO_STATE_HIGH); - } else { - pca9555_gpio_set_state(&s_drive_btn_leds[LEFT_LED], PCA9555_GPIO_STATE_LOW); - } - - if (right_signal_toggle) { - pca9555_gpio_set_state(&s_drive_btn_leds[RIGHT_LED], PCA9555_GPIO_STATE_HIGH); - } else { - pca9555_gpio_set_state(&s_drive_btn_leds[RIGHT_LED], PCA9555_GPIO_STATE_LOW); - } - - return STATUS_CODE_OK; -} diff --git a/projects/centre_console/src/cc_monitor.c b/projects/centre_console/src/cc_monitor.c deleted file mode 100644 index 26dcb4675..000000000 --- a/projects/centre_console/src/cc_monitor.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "cc_monitor.h" - -#include "cc_hw_defs.h" -#include "centre_console_getters.h" -#include "centre_console_setters.h" -#include "drive_fsm.h" -#include "pca9555_gpio_expander.h" - -// Multiplication factor to convert CAN motor velocity (cm/s) into drive output velocity (mm/s) -#define CONVERT_VELOCITY 5 - -// Multiplication factor to convert CAN drive output velocity to kph -#define CONVERT_VELOCITY_TO_KPH 0.0036 - -#define TEMP_I2C_ADDRESS 0x55 -Pca9555GpioAddress cc_light = { .i2c_address = TEMP_I2C_ADDRESS, .pin = PCA9555_PIN_IO0_0 }; -Pca9555GpioAddress cc_regen_brake_light = { .i2c_address = TEMP_I2C_ADDRESS, - .pin = PCA9555_PIN_IO0_1 }; -Event TEMP_REGEN_BRAKE_EVENT_PRESSED = 0; - -static LocalState state; - -void set_local_state() { - state.cc_enabled = g_tx_struct.drive_output_cruise_control; - state.drive_state = g_tx_struct.drive_output_drive_state; - state.target_velocity = g_tx_struct.drive_output_target_velocity; - state.regen_braking = g_tx_struct.drive_output_regen_braking; -} - -void update_state() { - if (get_pedal_output_brake_output()) { - state.cc_enabled = false; - return; - } - - // Check for regen brake event - uint32_t master_task_notif; - notify_get(&master_task_notif); - if (notify_check_event(&master_task_notif, TEMP_REGEN_BRAKE_EVENT_PRESSED)) { - state.regen_braking = !state.regen_braking; - if (state.regen_braking) { - pca9555_gpio_set_state(&cc_regen_brake_light, PCA9555_GPIO_STATE_LOW); - } - } - - // Check steering message for cc event (toggle/increase/decrease) - uint8_t cc_info = get_steering_info_input_cc(); - - if (cc_info & STEERING_CC_TOGGLE_MASK) { - if (!state.cc_enabled) { - // Store recent speed from MCI as initial cruise control speed - unsigned int convert_velocity = CONVERT_VELOCITY; - float converted_val = - (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) * CONVERT_VELOCITY; - state.target_velocity = (unsigned int)converted_val; - - state.cc_enabled = true; - pca9555_gpio_set_state(&cc_light, PCA9555_GPIO_STATE_HIGH); - } else { - state.target_velocity = 0; - - state.cc_enabled = false; - pca9555_gpio_set_state(&cc_light, PCA9555_GPIO_STATE_LOW); - } - } else if (cc_info & STEERING_CC_INCREASE_SPEED_MASK) { - state.target_velocity = - ((state.target_velocity * CONVERT_VELOCITY_TO_KPH) + 1) / CONVERT_VELOCITY_TO_KPH; - } else if (cc_info & STEERING_CC_DECREASE_SPEED_MASK) { - state.target_velocity = - ((state.target_velocity * CONVERT_VELOCITY_TO_KPH) - 1) / CONVERT_VELOCITY_TO_KPH; - } -} - -void update_drive_output() { - set_drive_output_drive_state(state.drive_state); - set_drive_output_cruise_control(state.cc_enabled); - set_drive_output_target_velocity(state.target_velocity); - set_drive_output_regen_braking(state.regen_braking); -} - -void monitor_cruise_control() { - set_local_state(); - - if (state.drive_state != DRIVE) { - return; - } else { - update_state(); - } - update_drive_output(); -} diff --git a/projects/centre_console/src/drive_fsm.c b/projects/centre_console/src/drive_fsm.c index 74007ef6b..7d98c3acb 100644 --- a/projects/centre_console/src/drive_fsm.c +++ b/projects/centre_console/src/drive_fsm.c @@ -3,20 +3,17 @@ #include "cc_buttons.h" #include "centre_console_getters.h" #include "centre_console_setters.h" -#include "fsm_shared_mem.h" -#include "power_fsm.h" FSM(drive, NUM_DRIVE_STATES); #define NUM_DRIVE_FSM_BUTTONS 3 -#define NUM_DRIVE_FSM_EVENTS 3 - -StateId next_state = NEUTRAL; static uint32_t notification = 0; static Event drive_fsm_event; -static uint8_t cycles_counter = 0; +static uint8_t power_received_counter = 0; + +static uint8_t power_state_main_flag = 0; // Flag for the first turn on of the power state typedef enum DriveLeds { DRIVE_LED = 0, @@ -30,32 +27,14 @@ static Pca9555GpioAddress s_drive_btn_leds[NUM_DRIVE_FSM_BUTTONS] = { [REVERSE_LED] = { .i2c_address = 0x20, .pin = PCA9555_PIN_IO0_0 }, }; -static void prv_start_sequence(Fsm *fsm, int precharge_state) { - if (precharge_state == PRECHARGE_STATE_COMPLETE) { - fsm_transition(fsm, next_state); - } else { - fsm_transition(fsm, DO_PRECHARGE); - } -} - -static bool prv_speed_is_positive(void) { - // Speed is in cm/s - // Need to use type cast int16_t since motor values are uint16 for CAN - int left_wheel_speed = (int16_t)get_motor_velocity_velocity_l(); // needs to be got from MCI - int right_wheel_speed = (int16_t)get_motor_velocity_velocity_r(); // needs to be got from MCI - - // Tolerance of 135cm/s which is about 3mph (about 5km/h) - return (left_wheel_speed >= -135 && right_wheel_speed >= -135) ? true : false; -} - -static bool prv_speed_is_negative(void) { +static bool prv_speed_is_zero(void) { // Speed is in cm/s // Need to use type cast int16_t since motor values are uint16 for CAN int left_wheel_speed = (int16_t)get_motor_velocity_velocity_l(); // needs to be got from MCI int right_wheel_speed = (int16_t)get_motor_velocity_velocity_r(); // needs to be got from MCI - // Tolerance of 135cm/s which is about 3mph (about 5km/h) - return (left_wheel_speed <= 135 && right_wheel_speed <= 135) ? true : false; + // No Tolerance + return (left_wheel_speed == 0 && right_wheel_speed == 0) ? true : false; } /** @@ -63,23 +42,31 @@ static bool prv_speed_is_negative(void) { * @return Transitions to DO_PRECHARGE, DRIVE, OR REVERSE */ static void prv_neutral_input(Fsm *fsm, void *context) { - StatusCode power_error_state = fsm_shared_mem_get_power_error_code(); + StatusCode power_error_state = get_power_info_pd_fault(); + + StateId power_state = get_power_info_power_state(); + uint8_t received_power_state = get_received_power_info(); - StateId power_state = fsm_shared_mem_get_power_state(); - int precharge_state = get_mc_status_precharge_status(); // needs to be got from MCI + if (power_state == EE_POWER_DRIVE_STATE && power_state_main_flag == 0) { + power_state_main_flag = 1; + pca9555_gpio_set_state(&s_drive_btn_leds[NEUTRAL_LED], PCA9555_GPIO_STATE_HIGH); + } else if (power_state == EE_POWER_ON_STATE) { + power_state_main_flag = 0; + pca9555_gpio_set_state(&s_drive_btn_leds[NEUTRAL_LED], PCA9555_GPIO_STATE_LOW); + } if (notify_get(¬ification) == STATUS_CODE_OK && power_error_state == STATUS_CODE_OK) { while (event_from_notification(¬ification, &drive_fsm_event) == STATUS_CODE_INCOMPLETE) { - if (drive_fsm_event == DRIVE_BUTTON_EVENT && power_state == POWER_FSM_STATE_MAIN && - prv_speed_is_positive()) { - next_state = DRIVE; + bool can_transition = power_state == EE_POWER_DRIVE_STATE && received_power_state == true && + prv_speed_is_zero(); + if (drive_fsm_event == DRIVE_BUTTON_EVENT && can_transition) { pca9555_gpio_set_state(&s_drive_btn_leds[NEUTRAL_LED], PCA9555_GPIO_STATE_LOW); - prv_start_sequence(fsm, precharge_state); - } else if (drive_fsm_event == REVERSE_BUTTON_EVENT && power_state == POWER_FSM_STATE_MAIN && - prv_speed_is_negative()) { - next_state = REVERSE; + fsm_transition(fsm, DRIVE); + break; + } else if (drive_fsm_event == REVERSE_BUTTON_EVENT && can_transition) { pca9555_gpio_set_state(&s_drive_btn_leds[NEUTRAL_LED], PCA9555_GPIO_STATE_LOW); - prv_start_sequence(fsm, precharge_state); + fsm_transition(fsm, REVERSE); + break; } } } @@ -90,64 +77,39 @@ static void prv_neutral_output(void *context) { } /** - * Do Precharge state - * @return Transitions to DRIVE OR REVERSE + * Drive state + * @return Transitions to NEUTRAL */ -void prv_do_precharge_input(Fsm *fsm, void *context) { - StatusCode power_error_state = fsm_shared_mem_get_power_error_code(); - if (power_error_state != STATUS_CODE_OK) { - next_state = NEUTRAL; - fsm_transition(fsm, NEUTRAL); - } - - StateId power_state = fsm_shared_mem_get_power_state(); - if (power_state != POWER_FSM_STATE_MAIN) { - next_state = NEUTRAL; - fsm_transition(fsm, NEUTRAL); - } - - if (get_mc_status_precharge_status() == PRECHARGE_STATE_COMPLETE) { - fsm_transition(fsm, next_state); +static void prv_drive_input(Fsm *fsm, void *context) { + uint8_t received_power_state = get_received_power_info(); + if (received_power_state) { + power_received_counter = 0; } else { - set_begin_precharge_signal1(BEGIN_PRECHARGE_SIGNAL); + power_received_counter++; } - cycles_counter++; - if (cycles_counter == NUMBER_OF_CYCLES_TO_WAIT) { - // this is a fail case | going back to neutral - fsm_shared_mem_set_drive_error_code(STATUS_CODE_TIMEOUT); - next_state = NEUTRAL; + if (power_received_counter > 3) { + // Did not receive power state for 3 cycles + power_received_counter = 0; + pca9555_gpio_set_state(&s_drive_btn_leds[DRIVE_LED], PCA9555_GPIO_STATE_LOW); fsm_transition(fsm, NEUTRAL); } -} -void prv_do_precharge_output(void *context) { - set_begin_precharge_signal1(BEGIN_PRECHARGE_SIGNAL); - cycles_counter = 0; -} -/** - * Drive state - * @return Transitions to NEUTRAL - */ -static void prv_drive_input(Fsm *fsm, void *context) { - StatusCode power_error_state = fsm_shared_mem_get_power_error_code(); + StatusCode power_error_state = get_power_info_pd_fault(); if (power_error_state != STATUS_CODE_OK) { - next_state = NEUTRAL; pca9555_gpio_set_state(&s_drive_btn_leds[DRIVE_LED], PCA9555_GPIO_STATE_LOW); fsm_transition(fsm, NEUTRAL); } - StateId power_state = fsm_shared_mem_get_power_state(); - if (power_state != POWER_FSM_STATE_MAIN) { - next_state = NEUTRAL; + StateId power_state = get_power_info_power_state(); + if (power_state != EE_POWER_DRIVE_STATE) { pca9555_gpio_set_state(&s_drive_btn_leds[DRIVE_LED], PCA9555_GPIO_STATE_LOW); fsm_transition(fsm, NEUTRAL); } if (notify_get(¬ification) == STATUS_CODE_OK) { while (event_from_notification(¬ification, &drive_fsm_event) == STATUS_CODE_INCOMPLETE) { - if (drive_fsm_event == NEUTRAL_BUTTON_EVENT) { - next_state = NEUTRAL; + if (drive_fsm_event == NEUTRAL_BUTTON_EVENT && prv_speed_is_zero()) { pca9555_gpio_set_state(&s_drive_btn_leds[DRIVE_LED], PCA9555_GPIO_STATE_LOW); fsm_transition(fsm, NEUTRAL); } @@ -158,7 +120,6 @@ static void prv_drive_input(Fsm *fsm, void *context) { static void prv_drive_output(void *context) { pca9555_gpio_set_state(&s_drive_btn_leds[DRIVE_LED], PCA9555_GPIO_STATE_HIGH); set_drive_output_drive_state(DRIVE); - fsm_shared_mem_set_drive_error_code(STATUS_CODE_OK); } /** @@ -166,24 +127,35 @@ static void prv_drive_output(void *context) { * @return Transitions to NEUTRAL */ static void prv_reverse_input(Fsm *fsm, void *context) { - StatusCode power_error_state = fsm_shared_mem_get_power_error_code(); + uint8_t received_power_state = get_received_power_info(); + if (received_power_state) { + power_received_counter = 0; + } else { + power_received_counter++; + } + + if (power_received_counter > 3) { + // Did not receive power state for 3 cycles + power_received_counter = 0; + pca9555_gpio_set_state(&s_drive_btn_leds[REVERSE_LED], PCA9555_GPIO_STATE_LOW); + fsm_transition(fsm, NEUTRAL); + } + + StatusCode power_error_state = get_power_info_pd_fault(); if (power_error_state != STATUS_CODE_OK) { - next_state = NEUTRAL; - pca9555_gpio_set_state(&s_drive_btn_leds[DRIVE_LED], PCA9555_GPIO_STATE_LOW); + pca9555_gpio_set_state(&s_drive_btn_leds[REVERSE_LED], PCA9555_GPIO_STATE_LOW); fsm_transition(fsm, NEUTRAL); } - StateId power_state = fsm_shared_mem_get_power_state(); - if (power_state != POWER_FSM_STATE_MAIN) { - next_state = NEUTRAL; - pca9555_gpio_set_state(&s_drive_btn_leds[DRIVE_LED], PCA9555_GPIO_STATE_LOW); + StateId power_state = get_power_info_power_state(); + if (power_state != EE_POWER_DRIVE_STATE) { + pca9555_gpio_set_state(&s_drive_btn_leds[REVERSE_LED], PCA9555_GPIO_STATE_LOW); fsm_transition(fsm, NEUTRAL); } if (notify_get(¬ification) == STATUS_CODE_OK) { while (event_from_notification(¬ification, &drive_fsm_event) == STATUS_CODE_INCOMPLETE) { - if (drive_fsm_event == NEUTRAL_BUTTON_EVENT) { - next_state = NEUTRAL; + if (drive_fsm_event == NEUTRAL_BUTTON_EVENT && prv_speed_is_zero()) { pca9555_gpio_set_state(&s_drive_btn_leds[REVERSE_LED], PCA9555_GPIO_STATE_LOW); fsm_transition(fsm, NEUTRAL); } @@ -193,7 +165,6 @@ static void prv_reverse_input(Fsm *fsm, void *context) { static void prv_reverse_output(void *context) { pca9555_gpio_set_state(&s_drive_btn_leds[REVERSE_LED], PCA9555_GPIO_STATE_HIGH); set_drive_output_drive_state(REVERSE); - fsm_shared_mem_set_drive_error_code(STATUS_CODE_OK); } // Declare states in state list @@ -201,23 +172,10 @@ static FsmState s_drive_state_list[NUM_DRIVE_STATES] = { STATE(NEUTRAL, prv_neutral_input, prv_neutral_output), STATE(DRIVE, prv_drive_input, prv_drive_output), STATE(REVERSE, prv_reverse_input, prv_reverse_output), - STATE(DO_PRECHARGE, prv_do_precharge_input, prv_do_precharge_output), }; // Declares transition for state machine, must match those in input functions static bool s_drive_transitions[NUM_DRIVE_STATES][NUM_DRIVE_STATES] = { - // NEUTRAL -> SEQ - TRANSITION(NEUTRAL, DO_PRECHARGE), - - // SEQ -> DRIVE - TRANSITION(DO_PRECHARGE, DRIVE), - - // SEQ -> REVERSE - TRANSITION(DO_PRECHARGE, REVERSE), - - // SEQ -> NEUTRAL (for failure case) - TRANSITION(DO_PRECHARGE, NEUTRAL), - // NEUTRAL -> DRIVE TRANSITION(NEUTRAL, DRIVE), @@ -231,6 +189,10 @@ static bool s_drive_transitions[NUM_DRIVE_STATES][NUM_DRIVE_STATES] = { TRANSITION(REVERSE, NEUTRAL), }; +StateId get_drive_state(void) { + return drive_fsm->curr_state; +} + StatusCode init_drive_fsm(void) { // Add gpio init pins // Add gpio register interrupts diff --git a/projects/centre_console/src/fsm_shared_mem.c b/projects/centre_console/src/fsm_shared_mem.c deleted file mode 100644 index 8ad2136da..000000000 --- a/projects/centre_console/src/fsm_shared_mem.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "fsm_shared_mem.h" - -// mutex protect the FSMStorage using the semaphore.h library - -#define MUTEX_BLOCK_TIME_MS 100 - -static FSMStorage cc_storage = { 0 }; - -// initialize the FSMStorage struct -void fsm_shared_mem_init() { - if (mutex_init(&cc_storage.mutex) != STATUS_CODE_OK) { - LOG_DEBUG("mutex init failed\n"); - return; - } - // cc_storage.power_state hard coded to POWER_FSM_STATE_OFF - cc_storage.power_state = 0; - cc_storage.power_error_code = STATUS_CODE_OK; - cc_storage.drive_error_code = STATUS_CODE_OK; -} - -// set power_state -void fsm_shared_mem_set_power_state(StateId state) { - mutex_lock(&cc_storage.mutex, MUTEX_BLOCK_TIME_MS); - cc_storage.power_state = state; - mutex_unlock(&cc_storage.mutex); -} - -// read power_state from FSMStorage -StateId fsm_shared_mem_get_power_state() { - mutex_lock(&cc_storage.mutex, MUTEX_BLOCK_TIME_MS); - StateId state = cc_storage.power_state; - mutex_unlock(&cc_storage.mutex); - return state; -} - -// set power error_code -void fsm_shared_mem_set_power_error_code(StatusCode code) { - mutex_lock(&cc_storage.mutex, MUTEX_BLOCK_TIME_MS); - cc_storage.power_error_code = code; - mutex_unlock(&cc_storage.mutex); -} - -// read power error_code from FSMStorage -StatusCode fsm_shared_mem_get_power_error_code() { - mutex_lock(&cc_storage.mutex, MUTEX_BLOCK_TIME_MS); - StatusCode error = cc_storage.power_error_code; - mutex_unlock(&cc_storage.mutex); - return error; -} - -// set drive error_code -void fsm_shared_mem_set_drive_error_code(StatusCode code) { - mutex_lock(&cc_storage.mutex, MUTEX_BLOCK_TIME_MS); - cc_storage.drive_error_code = code; - mutex_unlock(&cc_storage.mutex); -} - -// read drive error_code from FSMStorage -StatusCode fsm_shared_mem_get_drive_error_code() { - mutex_lock(&cc_storage.mutex, MUTEX_BLOCK_TIME_MS); - StatusCode error = cc_storage.drive_error_code; - mutex_unlock(&cc_storage.mutex); - return error; -} diff --git a/projects/centre_console/src/main.c b/projects/centre_console/src/main.c index 1c1f4eed4..1662e1ac3 100644 --- a/projects/centre_console/src/main.c +++ b/projects/centre_console/src/main.c @@ -7,10 +7,8 @@ #include "delay.h" #include "drive_fsm.h" #include "fsm.h" -#include "fsm_shared_mem.h" #include "log.h" #include "master_task.h" -#include "power_fsm.h" #include "tasks.h" #ifdef MS_PLATFORM_X86 @@ -34,8 +32,10 @@ const CanSettings can_settings = { }; void pre_loop_init() { + Task *cc_buttons_master_task = get_master_task(); + init_cc_buttons(cc_buttons_master_task); init_drive_fsm(); - init_power_fsm(POWER_FSM_STATE_OFF); + dashboard_init(); } void run_fast_cycle() { @@ -45,10 +45,16 @@ void run_fast_cycle() { void run_medium_cycle() { run_can_rx_cycle(); wait_tasks(1); - fsm_run_cycle(drive); - fsm_run_cycle(power); + + uint32_t notif = 0; + notify_get(¬if); + update_indicators(notif); monitor_cruise_control(); - wait_tasks(2); + update_displays(); + fsm_run_cycle(drive); + wait_tasks(1); + + update_drive_output(notif); run_can_tx_cycle(); wait_tasks(1); } @@ -67,7 +73,6 @@ int main() { can_init(&s_can_storage, &can_settings); LOG_DEBUG("Welcome to TEST! \n"); - fsm_shared_mem_init(); init_master_task(); diff --git a/projects/centre_console/src/power_fsm.c b/projects/centre_console/src/power_fsm.c deleted file mode 100644 index 34b9600df..000000000 --- a/projects/centre_console/src/power_fsm.c +++ /dev/null @@ -1,191 +0,0 @@ -#include "power_fsm.h" - -#include "cc_hw_defs.h" -#include "centre_console_getters.h" -#include "delay.h" -#include "fsm_shared_mem.h" -#include "gpio_it.h" -#include "log.h" -#include "power_fsm_sequence.h" -#include "task.h" - -// Todo(Bafran): Update to real value -#define BRAKE_THRES 0x0F - -static const GpioAddress s_btn_start = CC_BTN_PUSH_START; -static FSMStorage shared_mem; - -PowerFsmContext power_context = { 0 }; - -FSM(power, NUM_POWER_STATES); - -static void prv_power_fsm_off_input(Fsm *fsm, void *context) { - // Start button pressed - uint32_t notifications = 0; - notify_get(¬ifications); - if (notifications & (1 << START_BUTTON_EVENT)) { - // Brake is pressed (any non-zero value) - if (get_pedal_output_brake_output()) { - power_context.target_state = POWER_FSM_STATE_MAIN; - } else { - power_context.target_state = POWER_FSM_STATE_AUX; - } - fsm_transition(fsm, POWER_FSM_CONFIRM_AUX_STATUS); - } - return; -} - -static void prv_power_fsm_main_input(Fsm *fsm, void *context) { - uint32_t notifications = 0; - notify_get(¬ifications); - // Assuming that pressing start again means we're turning off - if (notifications & (1 << START_BUTTON_EVENT)) { - power_context.target_state = POWER_FSM_STATE_OFF; - fsm_transition(fsm, POWER_FSM_DISCHARGE_PRECHARGE); - } - return; -} - -static void prv_power_fsm_aux_input(Fsm *fsm, void *context) { - uint32_t notifications = 0; - notify_get(¬ifications); - // If start button && brake are pressed - if (notifications & (1 << START_BUTTON_EVENT) && get_pedal_output_brake_output()) { - power_context.target_state = POWER_FSM_STATE_MAIN; - fsm_transition(fsm, POWER_FSM_SEND_PD_BMS); - } else if (notifications & (1 << START_BUTTON_EVENT)) { - power_context.target_state = POWER_FSM_STATE_OFF; - fsm_transition(fsm, POWER_FSM_DISCHARGE_PRECHARGE); - } - return; -} - -static void prv_power_fsm_fault_input(Fsm *fsm, void *context) { - return; -} - -static void prv_power_fsm_off_output(void *context) { - power_context.latest_state = POWER_FSM_STATE_OFF; - fsm_shared_mem_set_power_state(POWER_FSM_STATE_OFF); - fsm_shared_mem_set_power_error_code(STATUS_CODE_OK); - LOG_DEBUG("CENTRE CONSOLE POWER FSM OFF STATE\n"); -} - -static void prv_power_fsm_main_output(void *context) { - power_context.latest_state = POWER_FSM_STATE_MAIN; - fsm_shared_mem_set_power_state(POWER_FSM_STATE_MAIN); - fsm_shared_mem_set_power_error_code(STATUS_CODE_OK); - LOG_DEBUG("CENTRE CONSOLE POWER FSM MAIN STATE\n"); -} - -static void prv_power_fsm_aux_output(void *context) { - power_context.latest_state = POWER_FSM_STATE_AUX; - fsm_shared_mem_set_power_state(POWER_FSM_STATE_AUX); - fsm_shared_mem_set_power_error_code(STATUS_CODE_OK); - LOG_DEBUG("CENTRE CONSOLE POWER FSM AUX STATE\n"); -} - -static void prv_power_fsm_fault_output(void *context) { - power_context.latest_state = POWER_FSM_STATE_FAULT; - fsm_shared_mem_set_power_state(POWER_FSM_STATE_FAULT); - fsm_shared_mem_set_power_error_code(STATUS_CODE_OK); - LOG_DEBUG("CENTRE CONSOLE POWER FSM FAULT STATE\n"); -} - -// Declare states in state lists -static FsmState s_power_fsm_states[NUM_POWER_STATES] = { - STATE(POWER_FSM_STATE_OFF, prv_power_fsm_off_input, prv_power_fsm_off_output), - STATE(POWER_FSM_STATE_MAIN, prv_power_fsm_main_input, prv_power_fsm_main_output), - STATE(POWER_FSM_STATE_AUX, prv_power_fsm_aux_input, prv_power_fsm_aux_output), - STATE(POWER_FSM_STATE_FAULT, prv_power_fsm_fault_input, prv_power_fsm_fault_output), - - // -> MAIN Sequence - STATE(POWER_FSM_CONFIRM_AUX_STATUS, power_fsm_confirm_aux_status_input, - power_fsm_confirm_aux_status_output), - STATE(POWER_FSM_SEND_PD_BMS, power_fsm_send_pd_bms_input, power_fsm_send_pd_bms_output), - STATE(POWER_FSM_CONFIRM_BATTERY_STATUS, power_fsm_confirm_battery_status_input, - power_fsm_confirm_battery_status_output), - STATE(POWER_FSM_CLOSE_BATTERY_RELAYS, power_fsm_close_battery_relays_input, - power_fsm_close_battery_relays_output), - STATE(POWER_FSM_CONFIRM_DC_DC, power_fsm_confirm_dc_dc_input, power_fsm_confirm_dc_dc_output), - STATE(POWER_FSM_TURN_ON_EVERYTHING, power_fsm_turn_on_everything_input, - power_fsm_turn_on_everything_output), - STATE(POWER_FSM_POWER_MAIN_COMPLETE, power_fsm_power_main_complete_input, - power_fsm_power_main_complete_output), - - // -> AUX Sequence - // Confirm aux status - // Turn on everything - - // -> OFF Sequence - STATE(POWER_FSM_DISCHARGE_PRECHARGE, power_fsm_discharge_precharge_input, - power_fsm_discharge_precharge_output), - STATE(POWER_FSM_TURN_OFF_EVERYTHING, power_fsm_turn_off_everything_input, - power_fsm_turn_off_everything_output), - STATE(POWER_FSM_OPEN_RELAYS, power_fsm_open_relays_input, power_fsm_open_relays_output), -}; - -static bool s_power_transitions[NUM_POWER_STATES][NUM_POWER_STATES] = { - // Transitions for OFF state - TRANSITION(POWER_FSM_STATE_OFF, POWER_FSM_STATE_FAULT), - // Transitions for MAIN state - TRANSITION(POWER_FSM_STATE_MAIN, POWER_FSM_STATE_FAULT), - // Transitions for AUX state - TRANSITION(POWER_FSM_STATE_AUX, POWER_FSM_STATE_FAULT), - - // Sequence into OFF state - TRANSITION(POWER_FSM_STATE_MAIN, POWER_FSM_DISCHARGE_PRECHARGE), - TRANSITION(POWER_FSM_STATE_AUX, POWER_FSM_DISCHARGE_PRECHARGE), - TRANSITION(POWER_FSM_DISCHARGE_PRECHARGE, POWER_FSM_TURN_OFF_EVERYTHING), - TRANSITION(POWER_FSM_TURN_OFF_EVERYTHING, POWER_FSM_OPEN_RELAYS), - TRANSITION(POWER_FSM_OPEN_RELAYS, POWER_FSM_STATE_OFF), - - // Sequence into MAIN state - TRANSITION(POWER_FSM_STATE_OFF, POWER_FSM_CONFIRM_AUX_STATUS), - TRANSITION(POWER_FSM_STATE_AUX, POWER_FSM_SEND_PD_BMS), - TRANSITION(POWER_FSM_CONFIRM_AUX_STATUS, POWER_FSM_SEND_PD_BMS), - TRANSITION(POWER_FSM_SEND_PD_BMS, POWER_FSM_CONFIRM_BATTERY_STATUS), - TRANSITION(POWER_FSM_CONFIRM_BATTERY_STATUS, POWER_FSM_CLOSE_BATTERY_RELAYS), - TRANSITION(POWER_FSM_CLOSE_BATTERY_RELAYS, POWER_FSM_CONFIRM_DC_DC), - TRANSITION(POWER_FSM_CONFIRM_DC_DC, POWER_FSM_TURN_ON_EVERYTHING), - TRANSITION(POWER_FSM_TURN_ON_EVERYTHING, POWER_FSM_POWER_MAIN_COMPLETE), - TRANSITION(POWER_FSM_POWER_MAIN_COMPLETE, POWER_FSM_STATE_MAIN), - - // Sequence into AUX state - TRANSITION(POWER_FSM_CONFIRM_AUX_STATUS, POWER_FSM_TURN_ON_EVERYTHING), - TRANSITION(POWER_FSM_TURN_ON_EVERYTHING, POWER_FSM_STATE_AUX), - - // Failures when attempting OFF -> MAIN state - // Failures when attempting OFF -> AUX - TRANSITION(POWER_FSM_CONFIRM_AUX_STATUS, POWER_FSM_STATE_OFF), - TRANSITION(POWER_FSM_SEND_PD_BMS, POWER_FSM_STATE_OFF), - TRANSITION(POWER_FSM_CONFIRM_BATTERY_STATUS, POWER_FSM_STATE_OFF), - TRANSITION(POWER_FSM_CLOSE_BATTERY_RELAYS, POWER_FSM_STATE_OFF), - TRANSITION(POWER_FSM_CONFIRM_DC_DC, POWER_FSM_STATE_OFF), - TRANSITION(POWER_FSM_TURN_ON_EVERYTHING, POWER_FSM_STATE_OFF), - TRANSITION(POWER_FSM_POWER_MAIN_COMPLETE, POWER_FSM_STATE_OFF), - - // Failures when attempting AUX -> MAIN state - TRANSITION(POWER_FSM_CONFIRM_BATTERY_STATUS, POWER_FSM_STATE_AUX), - TRANSITION(POWER_FSM_SEND_PD_BMS, POWER_FSM_STATE_AUX), - TRANSITION(POWER_FSM_CLOSE_BATTERY_RELAYS, POWER_FSM_STATE_AUX), - TRANSITION(POWER_FSM_CONFIRM_DC_DC, POWER_FSM_STATE_AUX), - TRANSITION(POWER_FSM_POWER_MAIN_COMPLETE, POWER_FSM_STATE_AUX), -}; - -StatusCode init_power_fsm(PowerFsmStateId inital_state) { - // Assuming GPIOs have already been initialized in main - // fsm_shared_mem_init(); - power_context.latest_state = 0; - power_context.target_state = 0; - fsm_init(power, s_power_fsm_states, s_power_transitions, inital_state, NULL); - - // Start button interrupt - InterruptSettings it_settings = { - .priority = INTERRUPT_PRIORITY_NORMAL, - .type = INTERRUPT_TYPE_INTERRUPT, - .edge = INTERRUPT_EDGE_RISING, // Todo (Bafran): Double check if this is normally open - }; - gpio_it_register_interrupt(&s_btn_start, &it_settings, START_BUTTON_EVENT, power); - return STATUS_CODE_OK; -} diff --git a/projects/centre_console/src/power_fsm_sequence.c b/projects/centre_console/src/power_fsm_sequence.c deleted file mode 100644 index 5186a2b1e..000000000 --- a/projects/centre_console/src/power_fsm_sequence.c +++ /dev/null @@ -1,239 +0,0 @@ -#include "power_fsm_sequence.h" - -#include "centre_console_getters.h" -#include "centre_console_setters.h" -#include "log.h" -#include "power_fsm.h" -#include "power_fsm_can_data.h" - -#define CYCLES_TIMEOUT 3 - -#define FSM_CHECK_DATA_RECV(fsm, context, data_recv) \ - do { \ - if (!data_recv) { \ - if (s_cycle_timeout == 0) { \ - fsm_transition(fsm, context.latest_state); \ - s_cycle_timeout = CYCLES_TIMEOUT; \ - } \ - s_cycle_timeout--; \ - return; \ - } \ - } while (0) - -#define FSM_TRANSITION_AND_RESET(fsm, state_id) \ - do { \ - fsm_transition(fsm, state_id); \ - s_cycle_timeout = CYCLES_TIMEOUT; \ - } while (0) - -// Number of cyces to wait before falling back to stable state -static uint8_t s_cycle_timeout = CYCLES_TIMEOUT; - -// Input/outputs for going into MAIN - -void power_fsm_confirm_aux_status_output(void *context) { - LOG_DEBUG("Transitioned to confirm aux status\n"); -} - -void power_fsm_confirm_aux_status_input(Fsm *fsm, void *context) { - FSM_CHECK_DATA_RECV(fsm, power_context, get_received_power_select_status()); - - uint8_t status = get_power_select_status_status(); - uint8_t fault = get_power_select_status_fault(); - - // Status bit 2 is AUX, fault bits 5,6,7 are AUX - if ((status & AUX_STATUS_BITS) && !(fault & AUX_FAULT_BITS)) { - // Transition to next state - if (power_context.target_state == POWER_FSM_STATE_MAIN) { - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_SEND_PD_BMS); - } else { - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_TURN_ON_EVERYTHING); - } - } else { - // Transition to last stable state - FSM_TRANSITION_AND_RESET(fsm, power_context.latest_state); - } - return; -} - -void power_fsm_send_pd_bms_output(void *context) { - set_set_bms_power_bms_power_on_notification(SET_BMS_POWER_NOTIFY); - LOG_DEBUG("Transitioned to send pd bms\n"); -} - -void power_fsm_send_pd_bms_input(Fsm *fsm, void *context) { - // = (PowerFsmContext *)context; - FSM_CHECK_DATA_RECV(fsm, power_context, get_received_pd_fault()); - - uint8_t pd_fault = get_pd_fault_fault_data(); - - if (pd_fault == PD_FAULT) { - // Reset cycle counter - s_cycle_timeout = CYCLES_TIMEOUT; - // Transition to next state - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_CONFIRM_BATTERY_STATUS); - } else if (s_cycle_timeout == 0) { - // Transition to last stable state - FSM_TRANSITION_AND_RESET(fsm, power_context.latest_state); - } else { - s_cycle_timeout--; - } - - return; -} - -void power_fsm_confirm_battery_status_output(void *context) { - LOG_DEBUG("Transitioned to confirm battery status\n"); -} - -void power_fsm_confirm_battery_status_input(Fsm *fsm, void *context) { - FSM_CHECK_DATA_RECV(fsm, power_context, get_received_bps_heartbeat()); - - uint8_t status = get_bps_heartbeat_status(); - - if (status == BPS_HEARTBEAT) { - // Reset cycle counter - s_cycle_timeout = CYCLES_TIMEOUT; - // Transition to next state - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_CLOSE_BATTERY_RELAYS); - } else if (s_cycle_timeout == 0) { - // Transition to last stable state - FSM_TRANSITION_AND_RESET(fsm, power_context.latest_state); - } else { - s_cycle_timeout--; - } - - return; -} - -void power_fsm_close_battery_relays_output(void *context) { - set_set_relay_states_relay_mask(SET_CLOSE_RELAY_STATE_MASK); - set_set_relay_states_relay_state(SET_CLOSE_RELAY_STATE_STATE); - LOG_DEBUG("Transitioned to close battery relays\n"); -} - -void power_fsm_close_battery_relays_input(Fsm *fsm, void *context) { - FSM_CHECK_DATA_RECV(fsm, power_context, get_received_battery_relay_state()); - - uint8_t hv_status = get_battery_relay_state_hv(); - uint8_t gnd_status = get_battery_relay_state_gnd(); - - // If both relays are closed, transition to next sequence state - if (hv_status == CLOSE_HV_STATUS && gnd_status == CLOSE_GND_STATUS) { - // Transition to next state - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_CONFIRM_DC_DC); - } else { - // Transition to last stable state - FSM_TRANSITION_AND_RESET(fsm, power_context.latest_state); - } - return; -} - -void power_fsm_confirm_dc_dc_output(void *context) { - LOG_DEBUG("Transitioned to confirm dc dc\n"); -} - -void power_fsm_confirm_dc_dc_input(Fsm *fsm, void *context) { - FSM_CHECK_DATA_RECV(fsm, power_context, get_received_power_select_status()); - - uint8_t status = get_power_select_status_status(); - uint8_t fault = get_power_select_status_fault(); - - // Status bit 1 is DCDC, fault bits 2, 3, 4 are DCDC - if ((status & DCDC_STATUS_BITS) && !(fault & DCDC_FAULT_BITS)) { - // Transition to next state - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_TURN_ON_EVERYTHING); - } else { - // Transition to last stable state - FSM_TRANSITION_AND_RESET(fsm, power_context.latest_state); - } - - return; -} - -void power_fsm_turn_on_everything_output(void *context) { - set_set_power_state_turn_on_everything_notification(SET_TURN_ON_EVERYTHING_NOTIFICATION); - LOG_DEBUG("Transitioned to turn on everything\n"); -} - -void power_fsm_turn_on_everything_input(Fsm *fsm, void *context) { - // No checks here, only "Turn on everything" message gets sent in the output function - if (power_context.target_state == POWER_FSM_STATE_MAIN) { - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_POWER_MAIN_COMPLETE); - } else { - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_STATE_AUX); - } - return; -} - -void power_fsm_power_main_complete_output(void *context) { - set_ready_to_drive_ready_state(SET_READY_TO_DRIVE); - LOG_DEBUG("Transitioned to power main complete\n"); -} - -void power_fsm_power_main_complete_input(Fsm *fsm, void *context) { - // No checks here, only "Ready to drive" message gets sent in the output function - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_STATE_MAIN); - return; -} - -// Input/outputs for going into AUX - -// Confirm aux status -// Turn on everything - -// Input/outputs for going into OFF - -void power_fsm_discharge_precharge_output(void *context) { - set_discharge_precharge_signal1(SET_DISCHARGE_PRECHARGE); - LOG_DEBUG("Transitioned to discharge precharge\n"); -} - -void power_fsm_discharge_precharge_input(Fsm *fsm, void *context) { - FSM_CHECK_DATA_RECV(fsm, power_context, get_received_precharge_completed()); - - uint8_t precharge = get_precharge_completed_notification(); - - if (precharge == PRECHARGE_COMPLETED_NOTIFCIATION) { - // Transition to next state - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_TURN_OFF_EVERYTHING); - } else { - // Transition to last stable state - FSM_TRANSITION_AND_RESET(fsm, power_context.latest_state); - } - - return; -} - -void power_fsm_turn_off_everything_output(void *context) { - set_set_power_state_turn_on_everything_notification(SET_TURN_ON_EVERYTHING_NOTIFICATION); - LOG_DEBUG("Transitioned to turn off everything\n"); -} - -void power_fsm_turn_off_everything_input(Fsm *fsm, void *context) { - // No checks here, only "Turn off everything" message gets sent in the output function - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_OPEN_RELAYS); - return; -} - -void power_fsm_open_relays_output(void *context) { - set_set_relay_states_relay_mask(SET_OPEN_RELAY_STATE_MASK); - set_set_relay_states_relay_state(SET_OPEN_RELAY_STATE_STATE); - LOG_DEBUG("Transitioned to open relays\n"); -} - -void power_fsm_open_relays_input(Fsm *fsm, void *context) { - uint8_t hv_status = get_battery_relay_state_hv(); - uint8_t gnd_status = get_battery_relay_state_gnd(); - - // If both relays are open, transition to next sequence state - if (hv_status == OPEN_HV_STATUS && gnd_status == OPEN_GND_STATUS) { - // Transition to next state - FSM_TRANSITION_AND_RESET(fsm, POWER_FSM_STATE_OFF); - } else { - // Transition to last stable state - FSM_TRANSITION_AND_RESET(fsm, power_context.latest_state); - } - - return; -} diff --git a/projects/centre_console/src/update_dashboard.c b/projects/centre_console/src/update_dashboard.c new file mode 100644 index 000000000..33174d8f6 --- /dev/null +++ b/projects/centre_console/src/update_dashboard.c @@ -0,0 +1,183 @@ +#include "update_dashboard.h" + +#include "cc_hw_defs.h" +#include "centre_console_getters.h" +#include "centre_console_setters.h" +#include "drive_fsm.h" +#include "pca9555_gpio_expander.h" +#include "seg_display.h" + +// Multiplication factor to convert CAN motor velocity (cm/s) into drive output velocity (mm/s) +#define CONVERT_VELOCITY 5 + +// Multiplication factor to convert CAN drive output velocity to kph +#define CONVERT_VELOCITY_TO_KPH 0.0036 + +// Multiplication Factor to convert CAN Velocity in 100 * m/s to kph +#define CONVERT_VELOCITY_TO_SPEED 0.018 + +static SegDisplay cc_display = CC_DISPLAY; +static SegDisplay speed_display = SPD_DISPLAY; +SegDisplay batt_perc_display = BATT_DISPLAY; + +// Centre Console State Variables +static uint8_t s_drive_state; +static bool s_cc_enabled; +static bool s_regen_braking; +static uint32_t s_target_velocity; +static uint32_t s_last_power_state = EE_POWER_OFF_STATE; +static uint8_t s_last_lights_state = EE_STEERING_LIGHTS_OFF_STATE; + +typedef enum DriveLeds { + HAZARD_LED = 0, + REGEN_LED, + POWER_LED, + LEFT_LED, + RIGHT_LED, + CRUISE_LED, + NUM_DRIVE_LED, +} DriveLeds; + +static Pca9555GpioAddress s_output_leds[NUM_DRIVE_LED] = { + [POWER_LED] = CC_LED_POWER, [HAZARD_LED] = HAZARD_LED_ADDR, [LEFT_LED] = LEFT_LED_ADDR, + [RIGHT_LED] = RIGHT_LED_ADDR, [CRUISE_LED] = CRUISE_LED_ADDR, [REGEN_LED] = REGEN_LED_ADDR +}; + +void update_indicators(uint32_t notif) { + // Update hazard light + if (notify_check_event(¬if, HAZARD_BUTTON_EVENT)) { + if (s_regen_braking) { + s_regen_braking = false; + pca9555_gpio_set_state(&s_output_leds[HAZARD_LED], PCA9555_GPIO_STATE_LOW); + } else { + s_regen_braking = false; + pca9555_gpio_set_state(&s_output_leds[HAZARD_LED], PCA9555_GPIO_STATE_HIGH); + } + } + + // Update regen light + if (notify_check_event(¬if, REGEN_BUTTON_EVENT)) { + if (s_regen_braking) { + s_regen_braking = false; + pca9555_gpio_set_state(&s_output_leds[REGEN_LED], PCA9555_GPIO_STATE_LOW); + } else { + s_regen_braking = false; + pca9555_gpio_set_state(&s_output_leds[REGEN_LED], PCA9555_GPIO_STATE_HIGH); + } + } + + // Update power btn light if power_state has changed + if (get_power_info_power_state() != s_last_power_state) { + if (get_power_info_power_state() == EE_POWER_ON_STATE || + get_power_info_power_state() == EE_POWER_DRIVE_STATE) { + pca9555_gpio_set_state(&s_output_leds[POWER_LED], PCA9555_GPIO_STATE_HIGH); + } else { + pca9555_gpio_set_state(&s_output_leds[POWER_LED], PCA9555_GPIO_STATE_HIGH); + } + s_last_power_state = get_power_info_power_state(); + } + + // Update left/right LED + if (get_steering_info_input_lights() != s_last_lights_state) { + switch (get_steering_info_input_lights()) { + case EE_STEERING_LIGHTS_OFF_STATE: + pca9555_gpio_set_state(&s_output_leds[LEFT_LED], PCA9555_GPIO_STATE_LOW); + pca9555_gpio_set_state(&s_output_leds[RIGHT_LED], PCA9555_GPIO_STATE_LOW); + break; + case EE_STEERING_LIGHTS_LEFT_STATE: + pca9555_gpio_set_state(&s_output_leds[LEFT_LED], PCA9555_GPIO_STATE_HIGH); + break; + case EE_STEERING_LIGHTS_RIGHT_STATE: + pca9555_gpio_set_state(&s_output_leds[RIGHT_LED], PCA9555_GPIO_STATE_HIGH); + break; + default: + break; + } + } +} + +void monitor_cruise_control() { + // Check steering message for cc event (toggle/increase/decrease) + // Update cc enabled based on brake/cc toggle + uint8_t cc_info = get_steering_info_input_cc(); + bool new_cc_state = s_cc_enabled; + if (get_drive_state() != DRIVE || get_pedal_output_brake_output()) { + new_cc_state = false; + } else { + if (cc_info & EE_STEERING_CC_TOGGLE_MASK) { + new_cc_state = !s_cc_enabled; + } + } + + // If a state change has occurred update values and indicator LED + if (new_cc_state != s_cc_enabled) { + if (s_cc_enabled) { + // Store recent speed from MCI as initial cruise control speed + unsigned int convert_velocity = CONVERT_VELOCITY; + float converted_val = + (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) * CONVERT_VELOCITY; + s_target_velocity = (unsigned int)converted_val; + pca9555_gpio_set_state(&s_output_leds[CRUISE_LED], PCA9555_GPIO_STATE_HIGH); + } else { + s_target_velocity = 0; + pca9555_gpio_set_state(&s_output_leds[CRUISE_LED], PCA9555_GPIO_STATE_LOW); + } + } + + // Allow for updates to cruise control value if it is enabled + if (s_cc_enabled) { + if (cc_info & EE_STEERING_CC_INCREASE_MASK) { + s_target_velocity = + ((s_target_velocity * CONVERT_VELOCITY_TO_KPH) + 1) / CONVERT_VELOCITY_TO_KPH; + } + if (cc_info & EE_STEERING_CC_DECREASE_MASK) { + s_target_velocity = + ((s_target_velocity * CONVERT_VELOCITY_TO_KPH) - 1) / CONVERT_VELOCITY_TO_KPH; + } + } +} + +void update_displays(void) { + seg_display_init(&cc_display); + seg_display_init(&speed_display); + seg_display_init(&batt_perc_display); + + // Read data from CAN structs and update displays with those values + float speed_kph = + (get_motor_velocity_velocity_l() + get_motor_velocity_velocity_r()) * CONVERT_VELOCITY; + uint16_t batt_perc_val = get_battery_status_batt_perc(); + seg_display_set_int(&cc_display, s_target_velocity); + if (speed_kph >= 100) { + seg_display_set_int(&speed_display, (int)speed_kph); + } else { + seg_display_set_float(&speed_display, speed_kph); + } + seg_display_set_int(&batt_perc_display, batt_perc_val); +} + +void update_drive_output(uint32_t notif) { + if (notify_check_event(¬if, POWER_BUTTON_EVENT)) { + if (get_pedal_output_brake_output()) { + set_cc_power_control_power_event(EE_CC_PWR_CTL_EVENT_BTN_AND_BRAKE); + } else { + set_cc_power_control_power_event(EE_CC_PWR_CTL_EVENT_BTN); + } + } else { + set_cc_power_control_power_event(EE_CC_PWR_CTL_EVENT_NONE); + } + set_drive_output_drive_state(s_drive_state); + set_drive_output_cruise_control(s_cc_enabled); + set_drive_output_target_velocity(s_target_velocity); + set_drive_output_regen_braking(s_regen_braking); +} + +StatusCode dashboard_init(void) { + Pca9555GpioSettings settings = { + .direction = PCA9555_GPIO_DIR_OUT, + .state = PCA9555_GPIO_STATE_LOW, + }; + for (int i = 0; i < NUM_DRIVE_LED; i++) { + status_ok_or_return(pca9555_gpio_init_pin(&s_output_leds[i], &settings)); + } + return STATUS_CODE_OK; +} diff --git a/projects/centre_console/test/test_drive_fsm.c b/projects/centre_console/test/test_drive_fsm.c index dbf2896fd..0d775afbd 100644 --- a/projects/centre_console/test/test_drive_fsm.c +++ b/projects/centre_console/test/test_drive_fsm.c @@ -1,9 +1,7 @@ #include "centre_console_getters.h" #include "centre_console_setters.h" #include "drive_fsm.h" -#include "fsm_shared_mem.h" #include "i2c.h" -#include "power_fsm.h" #include "task_test_helpers.h" #include "unity.h" @@ -29,13 +27,10 @@ void prepare_test() { wait_tasks(1); TEST_ASSERT_EQUAL(NEUTRAL, g_tx_struct.drive_output_drive_state); TEST_ASSERT_EQUAL(NEUTRAL, drive_fsm->curr_state); -} -// All neutral transitions -void neutral_to_precharge() { - fsm_run_cycle(drive); - wait_tasks(1); - TEST_ASSERT_EQUAL(DO_PRECHARGE, drive_fsm->curr_state); + g_rx_struct.power_info_pd_fault = STATUS_CODE_OK; + g_rx_struct.power_info_power_state = EE_POWER_DRIVE_STATE; + g_rx_struct.received_power_info = true; } void neutral_to_drive() { @@ -52,23 +47,6 @@ void neutral_to_reverse() { TEST_ASSERT_EQUAL(REVERSE, drive_fsm->curr_state); } -// All precharge transitions -void precharge_to_drive() { - g_rx_struct.mc_status_precharge_status = 2; // precharge status is complete - fsm_run_cycle(drive); - wait_tasks(1); - TEST_ASSERT_EQUAL(DRIVE, g_tx_struct.drive_output_drive_state); - TEST_ASSERT_EQUAL(DRIVE, drive_fsm->curr_state); -} - -void precharge_to_reverse() { - g_rx_struct.mc_status_precharge_status = 2; // precharge status is complete - fsm_run_cycle(drive); - wait_tasks(1); - TEST_ASSERT_EQUAL(REVERSE, g_tx_struct.drive_output_drive_state); - TEST_ASSERT_EQUAL(REVERSE, drive_fsm->curr_state); -} - // All drive transitions void drive_to_neutral() { fsm_run_cycle(drive); @@ -116,15 +94,10 @@ void test_neutral_to_drive(void) { LOG_DEBUG("T1: Testing Neutral to Drive\n"); prepare_test(); - // Starting sub test 1 neutral to drive: (Neutral->DoPrecharge->Drive) - LOG_DEBUG("T1.1: (Neutral->DoPrecharge->Drive)\n"); + // Starting sub test 1 neutral to dive: (Neutral->Drive) + LOG_DEBUG("T1.1: (Neutral->Drive)\n"); notify(drive, DRIVE_BUTTON_EVENT); - fsm_shared_mem_set_power_state(POWER_FSM_STATE_MAIN); - g_rx_struct.motor_velocity_velocity_l = 1; - g_rx_struct.motor_velocity_velocity_r = 1; - g_rx_struct.mc_status_precharge_status = 1; // precharge status is not complete - neutral_to_precharge(); - precharge_to_drive(); + neutral_to_drive(); // Starting sub test 2 drive idle LOG_DEBUG("T1.2: Drive idle\n"); @@ -139,19 +112,38 @@ void test_neutral_to_drive(void) { LOG_DEBUG("T1.4: Neutral idle\n"); idle_neutral(); - // Starting sub test 5 neutral to drive: (Neutral->Drive) (no precharge) - LOG_DEBUG("T1.5: (Neutral->Drive) (no precharge)\n"); + // Starting sub test 5 drive to neutral: (Drive->Neutral) (fault when power error state + // is not STATUS_CODE_OK) + LOG_DEBUG("T1.5: (Drive->Neutral) (fault when power error state is not STATUS_CODE_OK)\n"); + notify(drive, DRIVE_BUTTON_EVENT); + neutral_to_drive(); + g_rx_struct.power_info_pd_fault = STATUS_CODE_UNKNOWN; // set test value + drive_to_neutral(); + g_rx_struct.power_info_pd_fault = STATUS_CODE_OK; // reset test value for next test + + // Starting sub test 6 drive to neutral: (Drive->Neutral) (fault when power state is + // not main) + LOG_DEBUG("T1.6: (Drive->Neutral) (fault when power state is not main)\n"); notify(drive, DRIVE_BUTTON_EVENT); - fsm_shared_mem_set_power_state(POWER_FSM_STATE_MAIN); - g_rx_struct.motor_velocity_velocity_l = 1; - g_rx_struct.motor_velocity_velocity_r = 1; - g_rx_struct.mc_status_precharge_status = 2; // precharge status is not complete neutral_to_drive(); + g_rx_struct.power_info_power_state = EE_POWER_OFF_STATE; // set test value + drive_to_neutral(); + g_rx_struct.power_info_power_state = EE_POWER_DRIVE_STATE; // reset test value for next test - // Starting sub test 6 drive to neutral: (Drive->Neutral) (fault when power state is not - // main) - fsm_shared_mem_set_power_state(POWER_FSM_STATE_OFF); + // Starting sub test 7 drive to neutral: (Drive->Neutral) (fault when we don't + // receive power state message) + LOG_DEBUG("T1.7: (Drive->Neutral) (fault when we don't receive power state message)\n"); + notify(drive, DRIVE_BUTTON_EVENT); + neutral_to_drive(); + g_rx_struct.received_power_info = false; // set test value + fsm_run_cycle(drive); + wait_tasks(1); + fsm_run_cycle(drive); + wait_tasks(1); + fsm_run_cycle(drive); + wait_tasks(1); drive_to_neutral(); + g_rx_struct.received_power_info = true; // reset test value for next test } TEST_IN_TASK @@ -159,15 +151,10 @@ void test_neutral_to_reverse() { LOG_DEBUG("T2: Testing Neutral to Reverse\n"); prepare_test(); - // Starting sub test 1 neutral to reverse: (Neutral->DoPrecharge->Reverse) - LOG_DEBUG("T2.1: (Neutral->DoPrecharge->Reverse)\n"); + // Starting sub test 1 neutral to reverse: (Neutral->Reverse) + LOG_DEBUG("T2.1: (Neutral->Reverse)\n"); notify(drive, REVERSE_BUTTON_EVENT); - fsm_shared_mem_set_power_state(POWER_FSM_STATE_MAIN); - g_rx_struct.motor_velocity_velocity_l = (uint16_t)-1; - g_rx_struct.motor_velocity_velocity_r = (uint16_t)-1; - g_rx_struct.mc_status_precharge_status = 1; // precharge status is not complete - neutral_to_precharge(); - precharge_to_reverse(); + neutral_to_reverse(); // Starting sub test 2 reverse idle LOG_DEBUG("T2.2: Reverse idle\n"); @@ -178,78 +165,36 @@ void test_neutral_to_reverse() { notify(drive, NEUTRAL_BUTTON_EVENT); reverse_to_neutral(); - // Starting sub test 4 neutral to reverse: (Neutral->Reverse) (no precharge) - LOG_DEBUG("T2.4: (Neutral->Reverse) (no precharge)\n"); + // Starting sub test 4 reverse to neutral: (Reverse->Neutral) (fault when power error state + // is not STATUS_CODE_OK) + LOG_DEBUG("T2.4: (Reverse->Neutral) (fault when power error state is not STATUS_CODE_OK)\n"); notify(drive, REVERSE_BUTTON_EVENT); - fsm_shared_mem_set_power_state(POWER_FSM_STATE_MAIN); - g_rx_struct.motor_velocity_velocity_l = (uint16_t)-1; - g_rx_struct.motor_velocity_velocity_l = (uint16_t)-1; - g_rx_struct.motor_velocity_velocity_r = (uint16_t)-1; - g_rx_struct.mc_status_precharge_status = 2; // precharge status is not complete neutral_to_reverse(); + g_rx_struct.power_info_pd_fault = STATUS_CODE_UNKNOWN; // set test value + reverse_to_neutral(); + g_rx_struct.power_info_pd_fault = STATUS_CODE_OK; // reset test value for next test // Starting sub test 5 reverse to neutral: (Reverse->Neutral) (fault when power state is // not main) LOG_DEBUG("T2.5: (Reverse->Neutral) (fault when power state is not main)\n"); - fsm_shared_mem_set_power_state(POWER_FSM_STATE_OFF); + notify(drive, REVERSE_BUTTON_EVENT); + neutral_to_reverse(); + g_rx_struct.power_info_power_state = EE_POWER_OFF_STATE; // set test value reverse_to_neutral(); -} - -TEST_IN_TASK -void test_precharge() { - LOG_DEBUG("T3: Testing Precharge\n"); - prepare_test(); + g_rx_struct.power_info_power_state = EE_POWER_DRIVE_STATE; // reset test value for next test - // Starting sub test 1 neutral to precharge: (Neutral->DoPrecharge) - LOG_DEBUG("T3.1: (Neutral->DoPrecharge)\n"); - notify(drive, DRIVE_BUTTON_EVENT); - fsm_shared_mem_set_power_state(POWER_FSM_STATE_MAIN); - g_rx_struct.motor_velocity_velocity_l = 1; - g_rx_struct.motor_velocity_velocity_r = 1; - g_rx_struct.mc_status_precharge_status = 1; // precharge status is not complete - neutral_to_precharge(); - - // Starting sub test 2 checking if precharge request goes through - LOG_DEBUG("T3.2: Precharge request goes through\n"); + // Starting sub test 6 reverse to neutral: (Reverse->Neutral) (fault when we don't + // receive power state message) + LOG_DEBUG("T2.6: (Reverse->Neutral) (fault when we don't receive power state message)\n"); + notify(drive, REVERSE_BUTTON_EVENT); + neutral_to_reverse(); + g_rx_struct.received_power_info = false; // set test value fsm_run_cycle(drive); wait_tasks(1); - TEST_ASSERT_EQUAL(BEGIN_PRECHARGE_SIGNAL, g_tx_struct.begin_precharge_signal1); - - // Starting sub test 3 checking if precharge times out and appropriate error code is set - LOG_DEBUG("T3.3: Precharge times out and appropriate error code is set\n"); - for (int i = 0; i < NUMBER_OF_CYCLES_TO_WAIT - 1; i++) { - fsm_run_cycle(drive); - wait_tasks(1); - } - TEST_ASSERT_EQUAL(NEUTRAL, g_tx_struct.drive_output_drive_state); - TEST_ASSERT_EQUAL(NEUTRAL, drive_fsm->curr_state); - TEST_ASSERT_EQUAL(STATUS_CODE_TIMEOUT, fsm_shared_mem_get_drive_error_code()); - - // Starting sub test 4 checking if error code is reset when going to drive - LOG_DEBUG("T3.4: Error code is reset when going to drive\n"); - notify(drive, DRIVE_BUTTON_EVENT); - fsm_shared_mem_set_power_state(POWER_FSM_STATE_MAIN); - g_rx_struct.motor_velocity_velocity_l = 1; - g_rx_struct.motor_velocity_velocity_r = 1; - g_rx_struct.mc_status_precharge_status = 1; // precharge status is not complete - neutral_to_precharge(); - precharge_to_drive(); - TEST_ASSERT_EQUAL(STATUS_CODE_OK, fsm_shared_mem_get_drive_error_code()); - notify(drive, NEUTRAL_BUTTON_EVENT); - drive_to_neutral(); - - // Starting sub test 5 checking if precharge fails on invalid power state - LOG_DEBUG("T3.5: Precharge fails on invalid power state\n"); - notify(drive, DRIVE_BUTTON_EVENT); - fsm_shared_mem_set_power_state(POWER_FSM_STATE_MAIN); - g_rx_struct.motor_velocity_velocity_l = 1; - g_rx_struct.motor_velocity_velocity_r = 1; - g_rx_struct.mc_status_precharge_status = 1; // precharge status is not complete - neutral_to_precharge(); - - fsm_shared_mem_set_power_state(POWER_FSM_STATE_OFF); fsm_run_cycle(drive); wait_tasks(1); - TEST_ASSERT_EQUAL(NEUTRAL, g_tx_struct.drive_output_drive_state); - TEST_ASSERT_EQUAL(NEUTRAL, drive_fsm->curr_state); + fsm_run_cycle(drive); + wait_tasks(1); + reverse_to_neutral(); + g_rx_struct.received_power_info = true; // reset test value for next test } diff --git a/projects/centre_console/test/test_power_fsm.c b/projects/centre_console/test/test_power_fsm.c deleted file mode 100644 index bac5ecaa0..000000000 --- a/projects/centre_console/test/test_power_fsm.c +++ /dev/null @@ -1,163 +0,0 @@ -#include "cc_hw_defs.h" -#include "centre_console_getters.h" -#include "centre_console_setters.h" -#include "power_fsm.h" -#include "power_fsm_can_data.h" -#include "power_fsm_sequence.h" -#include "task_test_helpers.h" -#include "unity.h" - -#define PEDAL_PRESSED 0xFF -#define PEDAL_RELEASED 0x00 - -static const GpioAddress s_btn_start = CC_BTN_PUSH_START; - -void setup_test(void) { - log_init(); - gpio_init_pin(&s_btn_start, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH); -} - -void teardown_test(void) {} - -TEST_IN_TASK -void test_off_to_main(void) { - init_power_fsm(POWER_FSM_STATE_OFF); - - // Stay in off with no inputs - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_STATE_OFF); - - // Transition to CONFIRM_AUX_STATUS - g_rx_struct.pedal_output_brake_output = PEDAL_PRESSED; - g_rx_struct.received_pedal_output = true; - notify(power, START_BUTTON_EVENT); - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_CONFIRM_AUX_STATUS); - - // Transition to POWER_FSM_SEND_PD_BMS - g_rx_struct.power_select_status_status = AUX_STATUS_BITS; - g_rx_struct.power_select_status_fault = 0x00; // Not a fault - g_rx_struct.received_power_select_status = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_SEND_PD_BMS); - - // Transition to POWER_FSM_CONFIRM_BATTERY_STATUS - g_rx_struct.pd_fault_fault_data = PD_FAULT; - g_rx_struct.received_pd_fault = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_CONFIRM_BATTERY_STATUS); - - // Transition to POWER_FSM_CLOSE_BATTERY_RELAYS - g_rx_struct.bps_heartbeat_status = BPS_HEARTBEAT; - g_rx_struct.received_bps_heartbeat = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_CLOSE_BATTERY_RELAYS); - TEST_ASSERT_EQUAL(g_tx_struct.set_relay_states_relay_mask, SET_CLOSE_RELAY_STATE_MASK); - TEST_ASSERT_EQUAL(g_tx_struct.set_relay_states_relay_state, SET_CLOSE_RELAY_STATE_STATE); - - // Transition to POWER_FSM_CONFIRM_DC_DC - g_rx_struct.battery_relay_state_hv = CLOSE_HV_STATUS; - g_rx_struct.battery_relay_state_gnd = CLOSE_GND_STATUS; - g_rx_struct.received_battery_relay_state = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_CONFIRM_DC_DC); - - // Transition to POWER_FSM_TURN_ON_EVERYTHING - g_rx_struct.power_select_status_status = DCDC_STATUS_BITS; - g_rx_struct.power_select_status_fault = 0x00; // No fault - g_rx_struct.received_power_select_status = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_TURN_ON_EVERYTHING); - TEST_ASSERT_EQUAL(g_tx_struct.set_power_state_turn_on_everything_notification, - SET_TURN_ON_EVERYTHING_NOTIFICATION); - - // Transition to POWER_FSM_POWER_MAIN_COMPLETE - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_POWER_MAIN_COMPLETE); - TEST_ASSERT_EQUAL(g_tx_struct.ready_to_drive_ready_state, SET_READY_TO_DRIVE); - - // Transition to POWER_FSM_STATE_MAIN - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_STATE_MAIN); -} - -TEST_IN_TASK -void test_off_to_aux(void) { - init_power_fsm(POWER_FSM_STATE_OFF); - - // Transition to CONFIRM_AUX_STATUS - notify(power, START_BUTTON_EVENT); - // Brake is not pressed - g_rx_struct.pedal_output_brake_output = PEDAL_RELEASED; - g_rx_struct.received_pedal_output = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_CONFIRM_AUX_STATUS); - - // Transition to POWER_FSM_TURN_ON_EVERYTHING - g_rx_struct.power_select_status_status = AUX_STATUS_BITS; - g_rx_struct.power_select_status_fault = 0x00; // No fault - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_TURN_ON_EVERYTHING); - TEST_ASSERT_EQUAL(g_tx_struct.set_power_state_turn_on_everything_notification, - SET_TURN_ON_EVERYTHING_NOTIFICATION); -} - -TEST_IN_TASK -void test_aux_to_main(void) { - init_power_fsm(POWER_FSM_STATE_AUX); - - // Transition to POWER_FSM_SEND_PD_BMS - notify(power, START_BUTTON_EVENT); - g_rx_struct.pedal_output_brake_output = PEDAL_PRESSED; - g_rx_struct.received_pedal_output = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_SEND_PD_BMS); - - // If we've gotten this far, the rest of the transitions are already tested in test_off_to_main -} - -TEST_IN_TASK -void test_power_to_off(void) { - init_power_fsm(POWER_FSM_STATE_MAIN); - - // Transition to POWER_FSM_DISCHARGE_PRECHARGE - notify(power, START_BUTTON_EVENT); - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_DISCHARGE_PRECHARGE); - TEST_ASSERT_EQUAL(g_tx_struct.discharge_precharge_signal1, SET_DISCHARGE_PRECHARGE); - - // Transition to POWER_FSM_TURN_OFF_EVERYTHING - g_rx_struct.precharge_completed_notification = PRECHARGE_COMPLETED_NOTIFCIATION; - g_rx_struct.received_precharge_completed = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_TURN_OFF_EVERYTHING); - - // Transition to POWER_FSM_OPEN_RELAYS - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_OPEN_RELAYS); - TEST_ASSERT_EQUAL(g_tx_struct.set_relay_states_relay_mask, SET_OPEN_RELAY_STATE_MASK); - TEST_ASSERT_EQUAL(g_tx_struct.set_relay_states_relay_state, SET_OPEN_RELAY_STATE_STATE); - - // Transition to POWER_FSM_STATE_OFF - g_rx_struct.battery_relay_state_hv = OPEN_HV_STATUS; - g_rx_struct.battery_relay_state_gnd = OPEN_GND_STATUS; - g_rx_struct.received_battery_relay_state = true; - fsm_run_cycle(power); - wait_tasks(1); - TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_STATE_OFF); -} diff --git a/projects/power_distribution/src/lights_fsm.c b/projects/power_distribution/src/lights_fsm.c index 103efc677..a965fface 100644 --- a/projects/power_distribution/src/lights_fsm.c +++ b/projects/power_distribution/src/lights_fsm.c @@ -56,8 +56,8 @@ static void prv_lights_signal_blinker(SoftTimerId id) { static void prv_init_state_input(Fsm *fsm, void *context) { // can transition to LEFT, RIGHT, HAZARD - EELightType light_event = get_steering_info_input_lights(); // can msg id = 682 = 0x2AA - HazardStatus hazard_status = get_power_info_hazard_state(); // can msg id = 1026 = 0x5E2 + EELightType light_event = get_steering_info_input_lights(); + HazardStatus hazard_status = get_cc_power_control_hazard_enabled(); if (hazard_status == HAZARD_ON) { fsm_transition(fsm, HAZARD); @@ -77,7 +77,7 @@ static void prv_init_state_output(void *context) { static void prv_left_signal_input(Fsm *fsm, void *context) { // can transition to INIT, RIGHT, HAZARD EELightType light_event = get_steering_info_input_lights(); - HazardStatus hazard_status = get_power_info_hazard_state(); + HazardStatus hazard_status = get_cc_power_control_hazard_enabled(); if (hazard_status == HAZARD_ON) { fsm_transition(fsm, HAZARD); @@ -101,7 +101,7 @@ static void prv_left_signal_output(void *context) { static void prv_right_signal_input(Fsm *fsm, void *context) { // can transition to INIT, LEFT, HAZARD EELightType light_event = get_steering_info_input_lights(); - HazardStatus hazard_status = get_power_info_hazard_state(); + HazardStatus hazard_status = get_cc_power_control_hazard_enabled(); if (hazard_status == HAZARD_ON) { fsm_transition(fsm, HAZARD); @@ -125,7 +125,7 @@ static void prv_right_signal_output(void *context) { static void prv_hazard_input(Fsm *fsm, void *context) { // can transition to INIT, BPS_FAULT EELightType light_event = get_steering_info_input_lights(); - HazardStatus hazard_status = get_power_info_hazard_state(); + HazardStatus hazard_status = get_cc_power_control_hazard_enabled(); if (hazard_status == HAZARD_ON) { return;