Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable misra-c2012-10.6 #1890

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,14 @@ static void chrysler_rx_hook(const CANPacket_t *to_push) {
}

// enter controls on rising edge of ACC, exit controls on ACC off
const int das_3_bus = (chrysler_platform == CHRYSLER_PACIFICA) ? 0 : 2;
int das_bus_init = -1;
if (chrysler_platform == CHRYSLER_PACIFICA) {
das_bus_init = 0;
} else {
das_bus_init = 2;
}

const int das_3_bus = das_bus_init;
if ((bus == das_3_bus) && (addr == chrysler_addrs->DAS_3)) {
bool cruise_engaged = GET_BIT(to_push, 21U);
pcm_cruise_check(cruise_engaged);
Expand Down Expand Up @@ -219,7 +226,13 @@ static bool chrysler_tx_hook(const CANPacket_t *to_send) {

// STEERING
if (addr == chrysler_addrs->LKAS_COMMAND) {
int start_byte = (chrysler_platform == CHRYSLER_PACIFICA) ? 0 : 1;
int start_byte = -1;
if (chrysler_platform == CHRYSLER_PACIFICA) {
start_byte = 0;
} else {
start_byte = 1;
}

int desired_torque = ((GET_BYTE(to_send, start_byte) & 0x7U) << 8) | GET_BYTE(to_send, start_byte + 1);
desired_torque -= 1024;

Expand Down
9 changes: 7 additions & 2 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,13 @@ static void honda_rx_hook(const CANPacket_t *to_push) {
}
}
}

int bus_rdr_car = (honda_hw == HONDA_BOSCH) ? 0 : 2; // radar bus, car side
int bus_rdr_car = -1;
if (honda_hw == HONDA_BOSCH) {
bus_rdr_car = 0;
} else {
bus_rdr_car = 2;
}

bool stock_ecu_detected = false;

// If steering controls messages are received on the destination bus, it's an indication
Expand Down
35 changes: 31 additions & 4 deletions board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,14 @@ static void hyundai_canfd_rx_hook(const CANPacket_t *to_push) {
int bus = GET_BUS(to_push);
int addr = GET_ADDR(to_push);

const int pt_bus = hyundai_canfd_hda2 ? 1 : 0;
int pt_bus_init = -1;
if (hyundai_canfd_hda2) {
pt_bus_init = 1;
} else {
pt_bus_init = 0;
}

const int pt_bus = pt_bus_init;
const int scc_bus = hyundai_camera_scc ? 2 : pt_bus;

if (bus == pt_bus) {
Expand All @@ -168,7 +175,14 @@ static void hyundai_canfd_rx_hook(const CANPacket_t *to_push) {
}

// cruise buttons
const int button_addr = hyundai_canfd_alt_buttons ? 0x1aa : 0x1cf;
int button_addr_init = -1;
if (hyundai_canfd_alt_buttons) {
button_addr_init = 0x1aa;
} else {
button_addr_init = 0x1cf;
}

const int button_addr = button_addr_init;
if (addr == button_addr) {
bool main_button = false;
int cruise_button = 0;
Expand Down Expand Up @@ -220,7 +234,14 @@ static void hyundai_canfd_rx_hook(const CANPacket_t *to_push) {
if (hyundai_longitudinal) {
// on HDA2, ensure ADRV ECU is still knocked out
// on others, ensure accel msg is blocked from camera
const int stock_scc_bus = hyundai_canfd_hda2 ? 1 : 0;
int stock_scc_bus_init = -1;
if (hyundai_canfd_hda2) {
stock_scc_bus_init = 1;
} else {
stock_scc_bus_init = 0;
}

const int stock_scc_bus = stock_scc_bus_init;
stock_ecu_detected = stock_ecu_detected || ((addr == 0x1a0) && (bus == stock_scc_bus));
}
generic_rx_checks(stock_ecu_detected);
Expand Down Expand Up @@ -294,7 +315,13 @@ static int hyundai_canfd_fwd_hook(int bus_num, int addr) {
}
if (bus_num == 2) {
// LKAS for HDA2, LFA for HDA1
int hda2_lfa_block_addr = hyundai_canfd_hda2_alt_steering ? 0x362 : 0x2a4;
int hda2_lfa_block_addr = -1;
if (hyundai_canfd_hda2_alt_steering) {
hda2_lfa_block_addr = 0x362;
} else {
hda2_lfa_block_addr = 0x2a4;
}

bool is_lkas_msg = ((addr == hyundai_canfd_hda2_get_lkas_addr()) || (addr == hda2_lfa_block_addr)) && hyundai_canfd_hda2;
bool is_lfa_msg = ((addr == 0x12a) && !hyundai_canfd_hda2);

Expand Down
8 changes: 7 additions & 1 deletion board/safety/safety_subaru.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ static uint32_t subaru_compute_checksum(const CANPacket_t *to_push) {

static void subaru_rx_hook(const CANPacket_t *to_push) {
const int bus = GET_BUS(to_push);
const int alt_main_bus = subaru_gen2 ? SUBARU_ALT_BUS : SUBARU_MAIN_BUS;
int alt_main_bus_init = -1;
if (subaru_gen2) {
alt_main_bus_init = SUBARU_ALT_BUS;
} else {
alt_main_bus_init = SUBARU_MAIN_BUS;
}
const int alt_main_bus = alt_main_bus_init;

int addr = GET_ADDR(to_push);
if ((addr == MSG_SUBARU_Steering_Torque) && (bus == SUBARU_MAIN_BUS)) {
Expand Down
15 changes: 13 additions & 2 deletions board/safety/safety_tesla.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ static void tesla_rx_hook(const CANPacket_t *to_push) {
}

if (bus == 2) {
int das_control_addr = (tesla_powertrain ? 0x2bf : 0x2b9);
int das_control_addr = -1;
if (tesla_powertrain) {
das_control_addr = 0x2bf;
} else {
das_control_addr = 0x2b9;
}

if (tesla_longitudinal && (addr == das_control_addr)) {
// "AEB_ACTIVE"
tesla_stock_aeb = ((GET_BYTE(to_push, 2) & 0x03U) == 1U);
Expand Down Expand Up @@ -184,7 +190,12 @@ static int tesla_fwd_hook(int bus_num, int addr) {

if(bus_num == 2) {
// Autopilot to chassis/PT
int das_control_addr = (tesla_powertrain ? 0x2bf : 0x2b9);
int das_control_addr = -1;
if (tesla_powertrain) {
das_control_addr = 0x2bf;
} else {
das_control_addr = 0x2b9;
}

bool block_msg = false;
if (!tesla_powertrain && (addr == 0x488)) {
Expand Down
7 changes: 6 additions & 1 deletion board/safety/safety_volkswagen_pq.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ static uint32_t volkswagen_pq_compute_checksum(const CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);
int len = GET_LEN(to_push);
uint8_t checksum = 0U;
int checksum_byte = (addr == MSG_MOTOR_5) ? 7 : 0;
int checksum_byte = -1;
if (addr == MSG_MOTOR_5) {
checksum_byte = 7;
} else {
checksum_byte = 0;
}

// Simple XOR over the payload, except for the byte where the checksum lives.
for (int i = 0; i < len; i++) {
Expand Down
1 change: 0 additions & 1 deletion tests/misra/suppressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ misra-c2012-1.2 # this is from the extensions (e.g. __typeof__) used in the MIN
misra-c2012-2.5
misra-c2012-8.7
misra-c2012-8.4
misra-c2012-10.6
misra-c2012-21.15