Chrysler: cleanup + prep for Ram HD (#1012)

* Chrysler: cleanup + prep for Ram HD

* prefix with chrysler
This commit is contained in:
Adeeb Shihadeh 2022-08-08 21:16:28 -07:00 committed by GitHub
parent b27e1476a7
commit e30f7e8fc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 49 deletions

View File

@ -10,54 +10,69 @@ const int CHRYSLER_RAM_STANDSTILL_THRSLD = 3; // about 1m/s changed from wheel
const int CHRYSLER_RAM_MAX_RATE_UP = 6;
const int CHRYSLER_RAM_MAX_RATE_DOWN = 6;
typedef struct {
const int EPS_2;
const int ESP_1;
const int ESP_8;
const int ECM_5;
const int DAS_3;
const int DAS_6;
const int LKAS_COMMAND;
const int CRUISE_BUTTONS;
} ChryslerAddrs;
// CAN messages for Chrysler/Jeep platforms
#define EPS_2 544 // EPS driver input torque
#define ESP_1 320 // Brake pedal and vehicle speed
#define ESP_8 284 // Brake pedal and vehicle speed
#define ECM_5 559 // Throttle position sensor
#define DAS_3 500 // ACC engagement states from DASM
#define DAS_6 678 // LKAS HUD and auto headlight control from DASM
#define LKAS_COMMAND 658 // LKAS controls from DASM
#define CRUISE_BUTTONS 571 // Cruise control buttons
const ChryslerAddrs CHRYSLER_ADDRS = {
.EPS_2 = 544, // EPS driver input torque
.ESP_1 = 320, // Brake pedal and vehicle speed
.ESP_8 = 284, // Brake pedal and vehicle speed
.ECM_5 = 559, // Throttle position sensor
.DAS_3 = 500, // ACC engagement states from DASM
.DAS_6 = 678, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 658, // LKAS controls from DASM
.CRUISE_BUTTONS = 571, // Cruise control buttons
};
// CAN messages for the 5h gen RAM DT platform
#define EPS_2_RAM 49 // EPS driver input torque
#define ESP_1_RAM 131 // Brake pedal and vehicle speed
#define ESP_8_RAM 121 // Brake pedal and vehicle speed
#define ECM_5_RAM 157 // Throttle position sensor
#define DAS_3_RAM 153 // ACC engagement states from DASM
#define DAS_6_RAM 250 // LKAS HUD and auto headlight control from DASM
#define LKAS_COMMAND_RAM 166 // LKAS controls from DASM
#define CRUISE_BUTTONS_RAM 177 // Cruise control buttons
const ChryslerAddrs CHRYSLER_RAM_DT_ADDRS = {
.EPS_2 = 49, // EPS driver input torque
.ESP_1 = 131, // Brake pedal and vehicle speed
.ESP_8 = 121, // Brake pedal and vehicle speed
.ECM_5 = 157, // Throttle position sensor
.DAS_3 = 153, // ACC engagement states from DASM
.DAS_6 = 250, // LKAS HUD and auto headlight control from DASM
.LKAS_COMMAND = 166, // LKAS controls from DASM
.CRUISE_BUTTONS = 177, // Cruise control buttons
};
const CanMsg CHRYSLER_TX_MSGS[] = {
{CRUISE_BUTTONS, 0, 3},
{LKAS_COMMAND, 0, 6},
{DAS_6, 0, 8},
{CHRYSLER_ADDRS.CRUISE_BUTTONS, 0, 3},
{CHRYSLER_ADDRS.LKAS_COMMAND, 0, 6},
{CHRYSLER_ADDRS.DAS_6, 0, 8},
};
const CanMsg CHRYSLER_RAM_TX_MSGS[] = {
{CRUISE_BUTTONS_RAM, 2, 3},
{LKAS_COMMAND_RAM, 0, 8},
{DAS_6_RAM, 0, 8},
{CHRYSLER_RAM_DT_ADDRS.CRUISE_BUTTONS, 2, 3},
{CHRYSLER_RAM_DT_ADDRS.LKAS_COMMAND, 0, 8},
{CHRYSLER_RAM_DT_ADDRS.DAS_6, 0, 8},
};
AddrCheckStruct chrysler_addr_checks[] = {
{.msg = {{EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, // EPS module
{.msg = {{ESP_1, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // brake pressed
{.msg = {{CHRYSLER_ADDRS.EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, // EPS module
{.msg = {{CHRYSLER_ADDRS.ESP_1, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // brake pressed
//{.msg = {{ESP_8, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}}}, // vehicle Speed
{.msg = {{514, 0, 8, .check_checksum = false, .max_counter = 0U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{ECM_5, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // gas pedal
{.msg = {{DAS_3, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // cruise state
{.msg = {{CHRYSLER_ADDRS.ECM_5, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // gas pedal
{.msg = {{CHRYSLER_ADDRS.DAS_3, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // cruise state
};
#define CHRYSLER_ADDR_CHECK_LEN (sizeof(chrysler_addr_checks) / sizeof(chrysler_addr_checks[0]))
AddrCheckStruct chrysler_ram_addr_checks[] = {
{.msg = {{EPS_2_RAM, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, // EPS module
{.msg = {{ESP_1_RAM, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // brake pressed
{.msg = {{ESP_8_RAM, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // vehicle Speed
{.msg = {{ECM_5_RAM, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // gas pedal
{.msg = {{DAS_3_RAM, 2, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // cruise state
{.msg = {{CHRYSLER_RAM_DT_ADDRS.EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}}, // EPS module
{.msg = {{CHRYSLER_RAM_DT_ADDRS.ESP_1, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // brake pressed
{.msg = {{CHRYSLER_RAM_DT_ADDRS.ESP_8, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // vehicle Speed
{.msg = {{CHRYSLER_RAM_DT_ADDRS.ECM_5, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // gas pedal
{.msg = {{CHRYSLER_RAM_DT_ADDRS.DAS_3, 2, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}}, // cruise state
};
#define CHRYSLER_RAM_ADDR_CHECK_LEN (sizeof(chrysler_ram_addr_checks) / sizeof(chrysler_ram_addr_checks[0]))
@ -66,6 +81,7 @@ addr_checks chrysler_rx_checks = {chrysler_addr_checks, CHRYSLER_ADDR_CHECK_LEN}
const uint32_t CHRYSLER_PARAM_RAM_DT = 1U; // set for Ram DT platform
bool chrysler_ram = false;
const ChryslerAddrs *chrysler_addrs = &CHRYSLER_ADDRS;
static uint32_t chrysler_get_checksum(CANPacket_t *to_push) {
int checksum_byte = GET_LEN(to_push) - 1U;
@ -121,16 +137,14 @@ static int chrysler_rx_hook(CANPacket_t *to_push) {
if (valid) {
// Measured EPS torque
const int eps_2 = chrysler_ram ? EPS_2_RAM : EPS_2;
if ((bus == 0) && (addr == eps_2)) {
if ((bus == 0) && (addr == chrysler_addrs->EPS_2)) {
int torque_meas_new = ((GET_BYTE(to_push, 4) & 0x7U) << 8) + GET_BYTE(to_push, 5) - 1024U;
update_sample(&torque_meas, torque_meas_new);
}
// enter controls on rising edge of ACC, exit controls on ACC off
const int das_3 = chrysler_ram ? DAS_3_RAM : DAS_3;
const int das_3_bus = chrysler_ram ? 2 : 0;
if ((bus == das_3_bus) && (addr == das_3)) {
if ((bus == das_3_bus) && (addr == chrysler_addrs->DAS_3)) {
int cruise_engaged = GET_BIT(to_push, 21U) == 1U;
if (cruise_engaged && !cruise_engaged_prev) {
controls_allowed = 1;
@ -143,7 +157,7 @@ static int chrysler_rx_hook(CANPacket_t *to_push) {
// TODO: use the same message for both
// update speed
if (chrysler_ram && (bus == 0) && (addr == ESP_8_RAM)) {
if (chrysler_ram && (bus == 0) && (addr == chrysler_addrs->ESP_8)) {
vehicle_speed = (((GET_BYTE(to_push, 4) & 0x3U) << 8) + GET_BYTE(to_push, 5))*0.0078125;
vehicle_moving = (int)vehicle_speed > CHRYSLER_RAM_STANDSTILL_THRSLD;
}
@ -155,19 +169,16 @@ static int chrysler_rx_hook(CANPacket_t *to_push) {
}
// exit controls on rising edge of gas press
const int ecm_5 = chrysler_ram ? ECM_5_RAM : ECM_5;
if ((bus == 0) && (addr == ecm_5)) {
if ((bus == 0) && (addr == chrysler_addrs->ECM_5)) {
gas_pressed = GET_BYTE(to_push, 0U) != 0U;
}
// exit controls on rising edge of brake press
const int esp_1 = chrysler_ram ? ESP_1_RAM : ESP_1;
if ((bus == 0) && (addr == esp_1)) {
if ((bus == 0) && (addr == chrysler_addrs->ESP_1)) {
brake_pressed = ((GET_BYTE(to_push, 0U) & 0xFU) >> 2U) == 1U;
}
const int lkas_command = chrysler_ram ? LKAS_COMMAND_RAM : LKAS_COMMAND;
generic_rx_checks((bus == 0) && (addr == lkas_command));
generic_rx_checks((bus == 0) && (addr == chrysler_addrs->LKAS_COMMAND));
}
return valid;
}
@ -185,8 +196,7 @@ static int chrysler_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
}
// STEERING
const int lkas_addr = chrysler_ram ? LKAS_COMMAND_RAM : LKAS_COMMAND;
if (tx && (addr == lkas_addr)) {
if (tx && (addr == chrysler_addrs->LKAS_COMMAND)) {
int start_byte = chrysler_ram ? 1 : 0;
int desired_torque = ((GET_BYTE(to_send, start_byte) & 0x7U) << 8) | GET_BYTE(to_send, start_byte + 1);
desired_torque -= 1024;
@ -236,7 +246,7 @@ static int chrysler_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
}
// FORCE CANCEL: only the cancel button press is allowed
if ((addr == CRUISE_BUTTONS) || (addr == CRUISE_BUTTONS_RAM)) {
if (addr == chrysler_addrs->CRUISE_BUTTONS) {
const bool is_cancel = GET_BYTE(to_send, 0) == 1U;
const bool is_resume = GET_BYTE(to_send, 0) == 0x10U;
const bool allowed = is_cancel || (is_resume && controls_allowed);
@ -258,8 +268,7 @@ static int chrysler_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
}
// forward all messages from camera except LKAS messages
const bool is_lkas = (!chrysler_ram && ((addr == LKAS_COMMAND) || (addr == DAS_6))) ||
(chrysler_ram && ((addr == LKAS_COMMAND_RAM) || (addr == DAS_6_RAM)));
const bool is_lkas = ((addr == chrysler_addrs->LKAS_COMMAND) || (addr == chrysler_addrs->DAS_6));
if ((bus_num == 2) && !is_lkas){
bus_fwd = 0;
}
@ -271,8 +280,10 @@ static const addr_checks* chrysler_init(uint16_t param) {
chrysler_ram = GET_FLAG(param, CHRYSLER_PARAM_RAM_DT);
if (chrysler_ram) {
chrysler_addrs = &CHRYSLER_RAM_DT_ADDRS;
chrysler_rx_checks = (addr_checks){chrysler_ram_addr_checks, CHRYSLER_RAM_ADDR_CHECK_LEN};
} else {
chrysler_addrs = &CHRYSLER_ADDRS;
chrysler_rx_checks = (addr_checks){chrysler_addr_checks, CHRYSLER_ADDR_CHECK_LEN};
}

View File

@ -1,6 +1,10 @@
env = Environment(
CC='clang',
CXX='clang++',
CC='gcc',
CFLAGS=[
'-nostdlib',
'-fno-builtin',
'-std=gnu11',
],
CPPPATH=[".", "../../board"],
)