diff --git a/Autogen/CAN/Doc/GRCAN.CANdo b/Autogen/CAN/Doc/GRCAN.CANdo index 2041234c9..fff052888 100644 --- a/Autogen/CAN/Doc/GRCAN.CANdo +++ b/Autogen/CAN/Doc/GRCAN.CANdo @@ -560,7 +560,7 @@ Message ID: data type: u4 Torque Map: bit_start: 36 - comment: The torque map selected; torque map is the mapping of the throttle to the torque sent to each motor. 0 is max current amps, 1 is 50 / 100 / 150 / 200 / 250 / 275, 2 and later is tbd + comment: The torque map selected; torque map is the mapping of the throttle to the torque sent to each motor. 0 is max current amps, 1 is 100 / 200 / 250 / 300 / 325 / 350 Amps, 2 and later is tbd data type: u4 Max Cell Temp: bit_start: 40 @@ -668,7 +668,7 @@ Message ID: units: Volts scaled min: 0 scaled max: 655.35 - map equation: "0.01x" + map equation: "0.1x" Accumulator Current: bit_start: 32 comment: Current output of accumulator diff --git a/Autogen/CAN/Doc/GRCAN_Charger.dbc b/Autogen/CAN/Doc/GRCAN_Charger.dbc index 5cef85a39..9d7f15ec7 100644 --- a/Autogen/CAN/Doc/GRCAN_Charger.dbc +++ b/Autogen/CAN/Doc/GRCAN_Charger.dbc @@ -41,7 +41,7 @@ BO_ 2550588916 ACU_Charger_Control_to_Charger: 5 ACU BO_ 2150631170 ACU_ACU_Status_1_to_CCU: 8 ACU SG_ Accumulator_Voltage : 0|16@1+ (0.01,0) [0|655.35] "Volts" CCU - SG_ TS_Voltage : 16|16@1+ (0.01,0) [0|655.35] "Volts" CCU + SG_ TS_Voltage : 16|16@1+ (0.1,0) [0|655.35] "Volts" CCU SG_ Accumulator_Current : 32|16@1- (0.01,0) [-327.68|327.67] "Amps" CCU SG_ Accumulator_SOC : 48|8@1+ (0.3921568627,0) [0|100] "%" CCU SG_ GLV_SOC : 56|8@1+ (0.3921568627,0) [0|100] "%" CCU diff --git a/Autogen/CAN/Doc/GRCAN_Primary.dbc b/Autogen/CAN/Doc/GRCAN_Primary.dbc index 5979cc4f0..c1ca89636 100644 --- a/Autogen/CAN/Doc/GRCAN_Primary.dbc +++ b/Autogen/CAN/Doc/GRCAN_Primary.dbc @@ -45,7 +45,7 @@ BO_ 2150629890 ACU_Ping_to_ECU: 4 ACU BO_ 2150631170 ACU_ACU_Status_1_to_ECU: 8 ACU SG_ Accumulator_Voltage : 0|16@1+ (0.01,0) [0|655.35] "Volts" ECU - SG_ TS_Voltage : 16|16@1+ (0.01,0) [0|655.35] "Volts" ECU + SG_ TS_Voltage : 16|16@1+ (0.1,0) [0|655.35] "Volts" ECU SG_ Accumulator_Current : 32|16@1- (0.01,0) [-327.68|327.67] "Amps" ECU SG_ Accumulator_SOC : 48|8@1+ (0.3921568627,0) [0|100] "%" ECU SG_ GLV_SOC : 56|8@1+ (0.3921568627,0) [0|100] "%" ECU @@ -515,7 +515,7 @@ CM_ SG_ 2149581568 Ping_Group_1 "[Byte 1 / Bits 8-15] ECU ping targets 8: ACU (1 CM_ SG_ 2149581568 Ping_Group_2 "[Byte 2 / Bits 16-23] ECU ping targets 16: Suspension FL (1: OK, 0: Timeout) 17: Suspension FR (1: OK, 0: Timeout) 18: Suspension RL (1: OK, 0: Timeout) 19: Suspension RR (1: OK, 0: Timeout) 20: InboardFloor FL (1: OK, 0: Timeout) 21: InboardFloor FR (1: OK, 0: Timeout) 22: InboardFloor RL (1: OK, 0: Timeout) 23: InboardFloor RR (1: OK, 0: Timeout)"; CM_ SG_ 2149581568 Ping_Group_3 "[Byte 3 / Bits 24-31] ECU ping targets 24: TireTemp FL (1: OK, 0: Timeout) 25: TireTemp FR (1: OK, 0: Timeout) 26: TireTemp RL (1: OK, 0: Timeout) 27: TireTemp RR (1: OK, 0: Timeout) 28: BrakeTemp FL (1: OK, 0: Timeout) 29: BrakeTemp FR (1: OK, 0: Timeout) 30: BrakeTemp RL (1: OK, 0: Timeout) 31: BrakeTemp RR (1: OK, 0: Timeout)"; CM_ SG_ 2149581568 Power_Level "Controls the AC current limits to each of the inverters Discrete Mapping, actual current values described by the torque map"; -CM_ SG_ 2149581568 Torque_Map "The torque map selected; torque map is the mapping of the throttle to the torque sent to each motor. 0 is max current amps, 1 is 50 / 100 / 150 / 200 / 250 / 275, 2 and later is tbd"; +CM_ SG_ 2149581568 Torque_Map "The torque map selected; torque map is the mapping of the throttle to the torque sent to each motor. 0 is max current amps, 1 is 100 / 200 / 250 / 300 / 325 / 350 Amps, 2 and later is tbd"; CM_ SG_ 2149581568 Max_Cell_Temp "the Temp of the hottest cell of the accumulator"; CM_ SG_ 2149581568 Accumulator_State_of_Chg "% charged of the Accumulator"; CM_ SG_ 2149581568 GLV_State_of_Chg "% charged of the Low Voltage Bat"; diff --git a/Autogen/CAN/Inc/GRCAN_MSG_DATA.h b/Autogen/CAN/Inc/GRCAN_MSG_DATA.h index c00113345..5d5b185d2 100644 --- a/Autogen/CAN/Inc/GRCAN_MSG_DATA.h +++ b/Autogen/CAN/Inc/GRCAN_MSG_DATA.h @@ -53,8 +53,8 @@ See diagram in StateMachine.h (Byte 0) */ 31: BrakeTemp RR (1: OK, 0: Timeout) (Byte 3) */ uint8_t ping_group_3; /** Controls the AC current limits to each of the inverters -Discrete Mapping, actual current values described by the torque map The torque map selected; torque map is the mapping of the throttle to the torque sent to each motor. 0 is max current amps, 1 is 50 -/ 100 / 150 / 200 / 250 / 275, 2 and later is tbd (Byte 4) */ +Discrete Mapping, actual current values described by the torque map The torque map selected; torque map is the mapping of the throttle to the torque sent to each motor. 0 is max current amps, 1 is 100 +/ 200 / 250 / 300 / 325 / 350 Amps, 2 and later is tbd (Byte 4) */ uint8_t power_level_torque_map; /** the Temp of the hottest cell of the accumulator (Byte 5) */ uint8_t max_cell_temp; diff --git a/CCU/Application/Src/StateUtils.c b/CCU/Application/Src/StateUtils.c index ecded1836..04ec028da 100644 --- a/CCU/Application/Src/StateUtils.c +++ b/CCU/Application/Src/StateUtils.c @@ -89,7 +89,7 @@ void VCP_Oneliner(const CCU_StateData *state_data) length = snprintf(buffer, sizeof(buffer), " | IR+ %s", state_data->IR_PLUS ? "Closed" : "Open"); VCP_Send(buffer, length); - length = snprintf(buffer, sizeof(buffer), " | %huV", state_data->Accumulator_Voltage / 100); + length = snprintf(buffer, sizeof(buffer), " | %huV", state_data->Accumulator_Voltage / 10); VCP_Send(buffer, length); length = snprintf(buffer, sizeof(buffer), " | SOC %hu%%", (uint8_t)(state_data->Accumulator_SOC * 20.0f / 51.0f)); diff --git a/ECU/Application/Inc/CANdler.h b/ECU/Application/Inc/CANdler.h index 048243634..47cb01326 100644 --- a/ECU/Application/Inc/CANdler.h +++ b/ECU/Application/Inc/CANdler.h @@ -2,6 +2,7 @@ #include #include "GRCAN_BUS_ID.h" +#include "GRCAN_CUSTOM_ID.h" #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" #include "StateData.h" @@ -11,4 +12,6 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE_ID sender_id, uint8_t *data, uint32_t data_length); +void ECU_CAN_DTI_MessageHandler(ECU_StateData *state_data, GRCAN_CUSTOM_ID id, uint8_t *data, uint32_t data_length); + #endif diff --git a/ECU/Application/Inc/Lights.h b/ECU/Application/Inc/Lights.h index 37e3b6626..08fa9658c 100644 --- a/ECU/Application/Inc/Lights.h +++ b/ECU/Application/Inc/Lights.h @@ -12,6 +12,8 @@ * * @return void */ +void BrakeLightControl(ECU_StateData *stateLump); +void dashLights(ECU_StateData *stateLump); void lightControl(ECU_StateData *stateData); #endif diff --git a/ECU/Application/Inc/StateData.h b/ECU/Application/Inc/StateData.h index 97992394a..0cd60783f 100644 --- a/ECU/Application/Inc/StateData.h +++ b/ECU/Application/Inc/StateData.h @@ -116,9 +116,7 @@ typedef volatile struct ECU_StateData { bool ir_minus; bool acu_software_latch; - bool bms_light; - bool imd_light; - bool tssi_fault; + bool SDC_startup_condition; bool enable_regen; diff --git a/ECU/Application/Inc/StateUtils.h b/ECU/Application/Inc/StateUtils.h index c258b6676..955b0a520 100644 --- a/ECU/Application/Inc/StateUtils.h +++ b/ECU/Application/Inc/StateUtils.h @@ -14,10 +14,10 @@ uint32_t MillisecondsSinceBoot(void); #define MAX_APPS_IMPLAUSIBLE_TIME_MS 100 #define MAX_BUZZER_TIME_MS 1000 -#define REGEN_MIN_SPEED_MPH 3.106856f // MPH +#define REGEN_MIN_SPEED_MPH 3.106856f // 5 KPH -#define MAX_CURRENT_AMPS 300.0f // Determined by Ryan -#define MAX_REVERSE_CURRENT_AMPS 20.0f // TODO: Change as appropriate +#define MAX_CURRENT_AMPS 375.0f // Determined by Ryan +#define MAX_REVERSE_CURRENT_AMPS 30.0f // TODO: Change as appropriate #define ECU_STATUS_MSG_PERIOD_MILLIS (1000) #define TRACTIVE_SYSTEM_MAX_PERMITTED_DISCHARGE_TIME_MILLIS (5000) @@ -74,7 +74,6 @@ bool PressingBrake(volatile const ECU_StateData *stateData); float CalcBrakePressure(volatile const ECU_StateData *stateData); float CalcAccPedalTravel(volatile const ECU_StateData *stateData); bool APPS_Plausible(volatile const ECU_StateData *stateData); -bool vehicle_is_moving(volatile const ECU_StateData *stateData); /* Disable inverter for both DTI and Custom */ void disable_inverter(void); void Send_VCP_APPS(const ECU_StateData *stateData, uint16_t apps1_raw, uint16_t apps2_raw); diff --git a/ECU/Application/Src/CANdler.c b/ECU/Application/Src/CANdler.c index 0fb46ba4e..cd1bd97d7 100644 --- a/ECU/Application/Src/CANdler.c +++ b/ECU/Application/Src/CANdler.c @@ -1,8 +1,10 @@ #include "CANdler.h" +#include #include #include "GRCAN_BUS_ID.h" +#include "GRCAN_CUSTOM_ID.h" #include "GRCAN_MSG_ID.h" #include "GRCAN_NODE_ID.h" #include "Logomatic.h" @@ -10,7 +12,13 @@ #include "StateData.h" #include "bitManipulations.h" -#define WHEEL_RPM_TO_MPH_RATIO 0.0476f +#define WHEEL_RADIUS_INCHES 8.0f +#define WHEEL_CIRCUMFERENCE_INCHES (2.0f * (float)M_PI * WHEEL_RADIUS_INCHES) +#define WHEEL_RPM_TO_MPH_RATIO (WHEEL_CIRCUMFERENCE_INCHES / 63360.0f * 60.0f) +#define NUM_MOTOR_POLE_PAIRS 10 +#define DRIVEN_SPROCKET_TEETH 51.0f +#define DRIVING_SPROCKET_TEETH 19.0f +#define GEAR_RATIO (51.0f / 19.0f) void ReportBadMessageLength(GRCAN_BUS_ID bus_id, GRCAN_MSG_ID msg_id, GRCAN_NODE_ID sender_id) { @@ -63,7 +71,7 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA GRCAN_ACU_STATUS_1_MSG *acu_status_1 = (GRCAN_ACU_STATUS_1_MSG *)data; state_data->tractivebattery_soc = acu_status_1->accumulator_soc; state_data->glv_soc = acu_status_1->glv_soc; - state_data->ts_voltage = acu_status_1->ts_voltage * 0.01f; + state_data->ts_voltage = acu_status_1->ts_voltage * 0.1f; break; case GRCAN_ACU_STATUS_2: @@ -156,3 +164,22 @@ void ECU_CAN_MessageHandler(ECU_StateData *state_data, GRCAN_BUS_ID bus_id, GRCA break; } } + +void ECU_CAN_DTI_MessageHandler(ECU_StateData *state_data, GRCAN_CUSTOM_ID id, uint8_t *data, uint32_t data_length) +{ + switch (id) { + case DTI_DATA_1_CAN_ID: + if (data_length != 8) { + ReportBadMessageLength(GRCAN_BUS_PRIMARY, (GRCAN_MSG_ID)id, GRCAN_DTI_Inv); + break; + } + int32_t erpm = ((uint32_t)data[0] << 24) | ((uint32_t)data[1] << 16) | ((uint32_t)data[2] << 8) | ((uint32_t)data[3]); + state_data->vehicle_speed_mph = (float)erpm * WHEEL_RPM_TO_MPH_RATIO / (NUM_MOTOR_POLE_PAIRS * GEAR_RATIO); + break; + + default: + // don't really gaf + // ReportUnhandledMessage(GRCAN_BUS_PRIMARY, (GRCAN_MSG_ID)id, GRCAN_DTI_Inv); + break; + } +} diff --git a/ECU/Application/Src/CANutils.c b/ECU/Application/Src/CANutils.c index 5b1765cc9..0e340fee8 100644 --- a/ECU/Application/Src/CANutils.c +++ b/ECU/Application/Src/CANutils.c @@ -132,7 +132,7 @@ void SendECUAnalogDataOverCAN(const ECU_StateData *stateData) uint32_t millis_since_boot = MillisecondsSinceBoot(); static uint32_t last_can_tcm_request_millis = 0; - if (millis_since_boot - last_can_tcm_request_millis > 100) { + if (millis_since_boot - last_can_tcm_request_millis > 30) { GRCAN_ECU_ANALOG_DATA_MSG message = {.bspd_signal = stateData->bspd_signal, .bse_signal = stateData->bse_signal, .apps_1_signal = stateData->APPS1_Signal, diff --git a/ECU/Application/Src/Lights.c b/ECU/Application/Src/Lights.c index 3e0e7c31d..c86bb1efe 100644 --- a/ECU/Application/Src/Lights.c +++ b/ECU/Application/Src/Lights.c @@ -13,14 +13,19 @@ void BrakeLightControl(ECU_StateData *stateLump) { + static uint32_t brake_light_start_millis; + if (PressingBrake(stateLump)) { + brake_light_start_millis = MillisecondsSinceBoot(); + } + + if (MillisecondsSinceBoot() - brake_light_start_millis < 100) { LL_GPIO_SetOutputPin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin); } else { LL_GPIO_ResetOutputPin(BRAKE_LIGHT_GPIO_Port, BRAKE_LIGHT_Pin); } } -static bool SDCStartupCondition = true; // prevent false positive TSSI on startup // PRECONDITION: IMD assumed to give valid readings before this is run void TSSILightControl(ECU_StateData *stateLump) { @@ -30,16 +35,16 @@ void TSSILightControl(ECU_StateData *stateLump) bool redCar; // if we are before SDC is reset, don't red car unless there is an active failure - if (SDCStartupCondition) { + if (stateLump->SDC_startup_condition) { redCar = false; SDC_Level bms = bmsLevel(stateLump); SDC_Level imd = imdLevel(stateLump); if (bms == SDC_OK && imd == SDC_OK) { - SDCStartupCondition = false; + stateLump->SDC_startup_condition = false; } else if (bms == SDC_ONGOING_FAILURE || imd == SDC_ONGOING_FAILURE) { - SDCStartupCondition = false; + stateLump->SDC_startup_condition = false; redCar = true; } } else { @@ -143,8 +148,13 @@ void dashLights(ECU_StateData *stateLump) GRCAN_DASH_CONFIG_MSG message = {.led_latch_flags = (bms_nonlatch << 5) | (imd_nonlatch << 4) | (bspd_nonlatch << 3) | (bms_latch << 2) | (imd_latch << 1) | (bspd_latch << 0)}; */ - GRCAN_DASH_CONFIG_MSG message = {.led_latch_flags = (!bspdFailure(stateLump) << 5) | (!imdFailure(stateLump) << 4) | (!bmsFailure(stateLump) << 3) | (bspdFailure(stateLump) << 2) | - (imdFailure(stateLump) << 1) | (bmsFailure(stateLump) << 0)}; + GRCAN_DASH_CONFIG_MSG message; + if (stateLump->SDC_startup_condition) { + message = (GRCAN_DASH_CONFIG_MSG){.led_latch_flags = (true << 5) | (true << 4) | (true << 3) | (false << 2) | (false << 1) | (false << 0)}; + } else { + message = (GRCAN_DASH_CONFIG_MSG){.led_latch_flags = (!bspdFailure(stateLump) << 5) | (!imdFailure(stateLump) << 4) | (!bmsFailure(stateLump) << 3) | (bspdFailure(stateLump) << 2) | + (imdFailure(stateLump) << 1) | (bmsFailure(stateLump) << 0)}; + } message.led_latch_flags = ~message.led_latch_flags; // not to spec, needed as of the current iteration of the dash panel code ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Dash_Panel, GRCAN_DASH_CONFIG, &message, sizeof(message)); diff --git a/ECU/Application/Src/StateTicks.c b/ECU/Application/Src/StateTicks.c index 18d3cf616..cc86939a4 100644 --- a/ECU/Application/Src/StateTicks.c +++ b/ECU/Application/Src/StateTicks.c @@ -31,8 +31,8 @@ ECU_StateData stateLump = { .ecu_state = GR_GLV_ON, // Assume ACU good at boot .acu_software_latch = 1, - // Startup at just above minimum power - .powerlevel = 1, + // Startup at minimum power + .powerlevel = 0, // See CANdo specification .torquemap = 1, // APPS Deadzone @@ -59,7 +59,8 @@ ECU_StateData stateLump = { .apps_2_max = 1926, // Regen .regen_strength = 2, - .enable_regen = false}; + .enable_regen = false, + .SDC_startup_condition = true}; static uint32_t millis_since_boot; void ECU_State_Tick(void) @@ -233,12 +234,11 @@ void ECU_Drive_Active(ECU_StateData *stateData) LL_GPIO_ResetOutputPin(RTD_CONTROL_GPIO_Port, RTD_CONTROL_Pin); } else { LL_GPIO_SetOutputPin(RTD_CONTROL_GPIO_Port, RTD_CONTROL_Pin); - // LOGOMATIC("buzz!\n"); } if (stateData->rtd_button_pressed) { stateData->ecu_state = GR_PRECHARGE_COMPLETE; - if (vehicle_is_moving(stateData)) { + if (stateData->vehicle_speed_mph > 0) { LOGOMATIC("Warning: Vehicle is moving during state transition.\n"); } return; @@ -260,29 +260,29 @@ void ECU_Drive_Active(ECU_StateData *stateData) if (stateData->apps_bse_violation || !apps_plausible) { torque_request = 0; - } else if (stateData->enable_regen && PressingBrake(stateData) && 0 > REGEN_MIN_SPEED_MPH) { // stateData->vehicle_speed_mph + } else if (stateData->enable_regen && PressingBrake(stateData) && stateData->vehicle_speed_mph > REGEN_MIN_SPEED_MPH) { torque_request = -MIN_WITH_TYPES(CalcBrakePressure(stateData) / 5000.0f * stateData->regen_strength, 1.0f) * MAX_REVERSE_CURRENT_AMPS; } else { uint16_t max_current = 0; // Chosen max current for different power level / torque maps switch (stateData->powerlevel) { case 0: - max_current = 50; + max_current = 325; break; case 1: - max_current = 100; + max_current = 325; break; case 2: - max_current = 150; + max_current = 325; break; case 3: - max_current = 200; + max_current = 325; break; case 4: - max_current = 250; + max_current = 325; break; case 5: - max_current = 275; + max_current = 325; break; default: LOGOMATIC("Invalid power level: %d. Defaulting to no current.\n", stateData->powerlevel); diff --git a/ECU/Application/Src/StateUtils.c b/ECU/Application/Src/StateUtils.c index 8a2a17f8a..85929bafb 100644 --- a/ECU/Application/Src/StateUtils.c +++ b/ECU/Application/Src/StateUtils.c @@ -140,7 +140,7 @@ bool PressingBrake(volatile const ECU_StateData *stateData) } #endif - return (stateData->Brake_F_Signal > stateData->brake_f_min) || (stateData->Brake_R_Signal > stateData->brake_r_min); + return stateData->bse_signal > stateData->brake_bse_min; } float CalcBrakePressure(volatile const ECU_StateData *stateData) @@ -149,9 +149,7 @@ float CalcBrakePressure(volatile const ECU_StateData *stateData) return 0; #endif - float psi_front = stateData->Brake_F_Signal / 4096.0f * 5000.0f; - float psi_rear = stateData->Brake_R_Signal / 4096.0f * 5000.0f; - return fmaxf(psi_front, psi_rear); + return ((float)stateData->bse_signal - 654.09f) * 5000.0f / 2614.73f; } // TODO: reconsider deadzone @@ -175,15 +173,9 @@ bool APPS_Plausible(volatile const ECU_StateData *stateData) return error < 0.1f; } -bool vehicle_is_moving(volatile const ECU_StateData *stateData) -{ - const float tolerance = 0.1f; // In MPH - return stateData->vehicle_speed_mph > tolerance; -} - void disable_inverter(void) { - GRCAN_INV_CMD_MSG inverter_msg = {.drive_enable = 0, .field_weakening = 0, .rpm_limit = 0, .set_ac_current = 0, .set_dc_current = 0}; + GRCAN_INV_CMD_MSG inverter_msg = {.drive_enable = 0, .field_weakening = 0, .rpm_limit = 0, .set_ac_current = 32768, .set_dc_current = 32768}; ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_GR_Inv, GRCAN_INV_CMD, &inverter_msg, sizeof(inverter_msg)); ECU_CAN_Send_DTI(DTI_CONTROL_12_CAN_ID, &inverter_msg.drive_enable, 1); } diff --git a/ECU/Core/Src/main.c b/ECU/Core/Src/main.c index 9ad6a31bb..aa8f6f89b 100644 --- a/ECU/Core/Src/main.c +++ b/ECU/Core/Src/main.c @@ -298,7 +298,11 @@ void ADC_Configure(void) void CAN1_rx_callback(uint32_t ID, void *data, uint32_t size) { - ECU_CAN_MessageHandler(&stateLump, GRCAN_BUS_PRIMARY, (0x000FFF00 & ID) >> 8, (0xFF00000 & ID) >> 20, data, size); + if ((ID & 0x1FFFC0FF) == 0x00000016) { + ECU_CAN_DTI_MessageHandler(&stateLump, ID, data, size); + } else { + ECU_CAN_MessageHandler(&stateLump, GRCAN_BUS_PRIMARY, (0x000FFF00 & ID) >> 8, (0xFF00000 & ID) >> 20, data, size); + } } void CAN2_rx_callback(uint32_t ID, void *data, uint32_t size) @@ -327,7 +331,7 @@ void CAN_Configure(void) canCfg.hal_fdcan_init.DataTimeSeg1 = 9; // Updated for 160MHz: 160 MHz/((1+9+10)*1) = 8 Mbps canCfg.hal_fdcan_init.DataTimeSeg2 = 10; canCfg.hal_fdcan_init.StdFiltersNbr = 0; - canCfg.hal_fdcan_init.ExtFiltersNbr = 1; + canCfg.hal_fdcan_init.ExtFiltersNbr = 3; canCfg.rx_callback = NULL; canCfg.rx_interrupt_priority = 15; // TODO: Maybe make these not hardcoded @@ -392,10 +396,19 @@ void CAN_Configure(void) fdcan_primary_filter_all.FilterID1 = GRCAN_ALL & 0xFF; fdcan_primary_filter_all.FilterID2 = 0x000000FF; + FDCAN_FilterTypeDef fdcan_primary_filter_dti = {0}; + fdcan_primary_filter_ecu.IdType = FDCAN_EXTENDED_ID; + fdcan_primary_filter_ecu.FilterIndex = 2; + fdcan_primary_filter_ecu.FilterType = FDCAN_FILTER_MASK; + fdcan_primary_filter_ecu.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; + fdcan_primary_filter_ecu.FilterID1 = 0x00000016; + fdcan_primary_filter_ecu.FilterID2 = 0x1FFFC0FF; + stateLump.primary_can = can_init(&canCfg); can_add_filter(stateLump.primary_can, &fdcan_primary_filter_ecu); can_add_filter(stateLump.primary_can, &fdcan_primary_filter_all); + can_add_filter(stateLump.primary_can, &fdcan_primary_filter_dti); // CAN2 ====================================================== canCfg.fdcan_instance = FDCAN2; @@ -485,6 +498,16 @@ int main(void) LOGOMATIC("Boot completed at %lu ms\n", MillisecondsSinceBoot()); while (MillisecondsSinceBoot() < 5000) { // Notes per Andrey and Ryan + BrakeLightControl(&stateLump); + // GRCAN_DASH_CONFIG_MSG message = {.led_latch_flags = (!bspdFailure(stateLump) << 5) | (!imdFailure(stateLump) << 4) | (!bmsFailure(stateLump) << 3) | (bspdFailure(stateLump) << 2) | + // (imdFailure(stateLump) << 1) | (bmsFailure(stateLump) << 0)}; + + GRCAN_DASH_CONFIG_MSG message = {.led_latch_flags = (true << 5) | (true << 4) | (true << 3) | (false << 2) | (false << 1) | (false << 0)}; + + message.led_latch_flags = ~message.led_latch_flags; // not to spec, needed as of the current iteration of the dash panel code + + ECU_CAN_Send(GRCAN_BUS_PRIMARY, GRCAN_Dash_Panel, GRCAN_DASH_CONFIG, &message, sizeof(message)); + LL_mDelay(1); ADC_UpdateAnalogValues_EMA(ADC_buffers, NUM_SIGNALS, adc_alpha, ADC_outputs); write_adc_values_to_state_data(); diff --git a/ECU/Test/Src/StateTicksTest.c b/ECU/Test/Src/StateTicksTest.c index 5fbedb3fc..75a3b4112 100644 --- a/ECU/Test/Src/StateTicksTest.c +++ b/ECU/Test/Src/StateTicksTest.c @@ -163,7 +163,7 @@ int main(void) stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_min; LOGOMATIC("Press brake: STAY IN GLV ON\n"); - stateLumpTest.Brake_F_Signal = stateLumpTest.brake_f_min + 69; + stateLumpTest.bse_signal = stateLumpTest.brake_bse_min + 69; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_GLV_ON) { LOGOMATIC("0.2 Failure: ecu state not in GLV ON\n"); @@ -175,7 +175,7 @@ int main(void) } LOGOMATIC("Release brake: STAY IN GLV ON\n"); - stateLumpTest.Brake_F_Signal = 0; + stateLumpTest.bse_signal = 0; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_GLV_ON) { LOGOMATIC("0.2 Failure: ecu state not in GLV ON\n"); @@ -256,7 +256,7 @@ int main(void) // ## Step 0.7 ## // ########################## LOGOMATIC("Press and release the RTD button WHILE pressing the brake\n"); - stateLumpTest.Brake_F_Signal = stateLumpTest.brake_f_min + 69; + stateLumpTest.bse_signal = stateLumpTest.brake_bse_min + 69; LOGOMATIC("Press RTD\n"); stateLumpTest.rtd_button_press_interrupt = true; ECU_Pseudo_State_Tick(&stateLumpTest); @@ -275,7 +275,7 @@ int main(void) // ## Step 0.8 ## // ########################## LOGOMATIC("Release Brakes -> STAY IN DRIVE ACTIVE\n"); - stateLumpTest.Brake_F_Signal = 0; + stateLumpTest.bse_signal = 0; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { LOGOMATIC("0.8 Failure: ecu state not in drive active\n"); @@ -324,7 +324,7 @@ int main(void) LOGOMATIC("Press Throttle and Brake -> STAY IN DRIVE ACTIVE\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_max; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_max; - stateLumpTest.Brake_F_Signal = stateLumpTest.brake_f_min + 69; + stateLumpTest.bse_signal = stateLumpTest.brake_bse_min + 69; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { LOGOMATIC("0.11 Failure: ecu state not in drive active\n"); @@ -341,7 +341,7 @@ int main(void) LOGOMATIC("Release Throttle and Brake-> STAY IN DRIVE ACTIVE\n"); stateLumpTest.APPS1_Signal = stateLumpTest.apps_1_min; stateLumpTest.APPS2_Signal = stateLumpTest.apps_2_min; - stateLumpTest.Brake_F_Signal = 0; + stateLumpTest.bse_signal = 0; ECU_Pseudo_State_Tick(&stateLumpTest); if (stateLumpTest.ecu_state != GR_DRIVE_ACTIVE) { LOGOMATIC("0.12 Failure: ecu state not in drive active\n");