mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
enable misra-c2012-10.3 (#1852)
* enable misra-c2012-10.3 * fix that * cleanup * little more * one more --------- Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
@@ -28,8 +28,8 @@ extern int can_live;
|
||||
extern int pending_can_live;
|
||||
|
||||
// must reinit after changing these
|
||||
extern int can_loopback;
|
||||
extern int can_silent;
|
||||
extern bool can_loopback;
|
||||
|
||||
// Ignition detected from CAN meessages
|
||||
bool ignition_can = false;
|
||||
@@ -40,8 +40,8 @@ uint32_t ignition_can_cnt = 0U;
|
||||
|
||||
int can_live = 0;
|
||||
int pending_can_live = 0;
|
||||
int can_loopback = 0;
|
||||
int can_silent = ALL_CAN_SILENT;
|
||||
bool can_loopback = false;
|
||||
|
||||
// ******************* functions prototypes *********************
|
||||
bool can_init(uint8_t can_number);
|
||||
|
||||
@@ -26,14 +26,14 @@ int do_bitstuff(char *out, const char *in, int in_len) {
|
||||
bit_cnt++;
|
||||
if (bit_cnt == 5) {
|
||||
// 5 in a row the same, do stuff
|
||||
last_bit = !bit;
|
||||
last_bit = !bit ? 1 : 0;
|
||||
out[j] = last_bit;
|
||||
j++;
|
||||
bit_cnt = 1;
|
||||
}
|
||||
} else {
|
||||
// this is a new bit
|
||||
last_bit = bit;
|
||||
last_bit = (int)bit;
|
||||
bit_cnt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ void interrupt_timer_handler(void) {
|
||||
// Calculate interrupt load
|
||||
// The bootstub does not have the FPU enabled, so can't do float operations.
|
||||
#if !defined(BOOTSTUB)
|
||||
interrupt_load = ((busy_time + idle_time) > 0U) ? ((float) busy_time) / (busy_time + idle_time) : 0.0f;
|
||||
interrupt_load = ((busy_time + idle_time) > 0U) ? ((float) (((float) busy_time) / (busy_time + idle_time))) : 0.0f;
|
||||
#endif
|
||||
idle_time = 0U;
|
||||
busy_time = 0U;
|
||||
|
||||
@@ -461,12 +461,12 @@ void usb_reset(void) {
|
||||
USBx_OUTEP(0)->DOEPTSIZ = USB_OTG_DOEPTSIZ_STUPCNT | (USB_OTG_DOEPTSIZ_PKTCNT & (1UL << 19)) | (3U << 3);
|
||||
}
|
||||
|
||||
char to_hex_char(int a) {
|
||||
char to_hex_char(uint8_t a) {
|
||||
char ret;
|
||||
if (a < 10) {
|
||||
if (a < 10U) {
|
||||
ret = '0' + a;
|
||||
} else {
|
||||
ret = 'a' + (a - 10);
|
||||
ret = 'a' + (a - 10U);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
|
||||
break;
|
||||
// **** 0xe5: set CAN loopback (for testing)
|
||||
case 0xe5:
|
||||
can_loopback = (req->param1 > 0U);
|
||||
can_loopback = req->param1 > 0U;
|
||||
can_init_all();
|
||||
break;
|
||||
// **** 0xe6: set custom clock source period
|
||||
|
||||
@@ -94,8 +94,8 @@ bool get_longitudinal_allowed(void) {
|
||||
// Given a CRC-8 poly, generate a static lookup table to use with a fast CRC-8
|
||||
// algorithm. Called at init time for safety modes using CRC-8.
|
||||
void gen_crc_lookup_table_8(uint8_t poly, uint8_t crc_lut[]) {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
uint8_t crc = i;
|
||||
for (uint16_t i = 0U; i <= 0xFFU; i++) {
|
||||
uint8_t crc = (uint8_t)i;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
if ((crc & 0x80U) != 0U) {
|
||||
crc = (uint8_t)((crc << 1) ^ poly);
|
||||
|
||||
@@ -204,7 +204,7 @@ static int gm_fwd_hook(int bus_num, int addr) {
|
||||
// block lkas message and acc messages if gm_cam_long, forward all others
|
||||
bool is_lkas_msg = (addr == 0x180);
|
||||
bool is_acc_msg = (addr == 0x315) || (addr == 0x2CB) || (addr == 0x370);
|
||||
int block_msg = is_lkas_msg || (is_acc_msg && gm_cam_long);
|
||||
bool block_msg = is_lkas_msg || (is_acc_msg && gm_cam_long);
|
||||
if (!block_msg) {
|
||||
bus_fwd = 0;
|
||||
}
|
||||
|
||||
@@ -114,11 +114,11 @@ static uint32_t honda_compute_checksum(const CANPacket_t *to_push) {
|
||||
uint8_t checksum = 0U;
|
||||
unsigned int addr = GET_ADDR(to_push);
|
||||
while (addr > 0U) {
|
||||
checksum += (addr & 0xFU); addr >>= 4;
|
||||
checksum += (uint8_t)(addr & 0xFU); addr >>= 4;
|
||||
}
|
||||
for (int j = 0; j < len; j++) {
|
||||
uint8_t byte = GET_BYTE(to_push, j);
|
||||
checksum += (byte & 0xFU) + (byte >> 4U);
|
||||
checksum += (uint8_t)(byte & 0xFU) + (byte >> 4U);
|
||||
if (j == (len - 1)) {
|
||||
checksum -= (byte & 0xFU); // remove checksum in message
|
||||
}
|
||||
@@ -465,8 +465,8 @@ static int honda_bosch_fwd_hook(int bus_num, int addr) {
|
||||
bus_fwd = 2;
|
||||
}
|
||||
if (bus_num == 2) {
|
||||
int is_lkas_msg = (addr == 0xE4) || (addr == 0xE5) || (addr == 0x33D) || (addr == 0x33DA) || (addr == 0x33DB);
|
||||
int is_acc_msg = ((addr == 0x1C8) || (addr == 0x30C)) && honda_bosch_radarless && honda_bosch_long;
|
||||
bool is_lkas_msg = (addr == 0xE4) || (addr == 0xE5) || (addr == 0x33D) || (addr == 0x33DA) || (addr == 0x33DB);
|
||||
bool is_acc_msg = ((addr == 0x1C8) || (addr == 0x30C)) && honda_bosch_radarless && honda_bosch_long;
|
||||
bool block_msg = is_lkas_msg || is_acc_msg;
|
||||
if (!block_msg) {
|
||||
bus_fwd = 0;
|
||||
|
||||
@@ -170,7 +170,7 @@ static void hyundai_canfd_rx_hook(const CANPacket_t *to_push) {
|
||||
// cruise buttons
|
||||
const int button_addr = hyundai_canfd_alt_buttons ? 0x1aa : 0x1cf;
|
||||
if (addr == button_addr) {
|
||||
int main_button = 0;
|
||||
bool main_button = false;
|
||||
int cruise_button = 0;
|
||||
if (addr == 0x1cf) {
|
||||
cruise_button = GET_BYTE(to_push, 2) & 0x7U;
|
||||
|
||||
@@ -45,7 +45,7 @@ void hyundai_common_init(uint16_t param) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void hyundai_common_cruise_state_check(const int cruise_engaged) {
|
||||
void hyundai_common_cruise_state_check(const bool cruise_engaged) {
|
||||
// some newer HKG models can re-enable after spamming cancel button,
|
||||
// so keep track of user button presses to deny engagement if no interaction
|
||||
|
||||
@@ -62,9 +62,8 @@ void hyundai_common_cruise_state_check(const int cruise_engaged) {
|
||||
}
|
||||
}
|
||||
|
||||
void hyundai_common_cruise_buttons_check(const int cruise_button, const int main_button) {
|
||||
if ((cruise_button == HYUNDAI_BTN_RESUME) || (cruise_button == HYUNDAI_BTN_SET) || (cruise_button == HYUNDAI_BTN_CANCEL) ||
|
||||
(main_button != 0)) {
|
||||
void hyundai_common_cruise_buttons_check(const int cruise_button, const bool main_button) {
|
||||
if ((cruise_button == HYUNDAI_BTN_RESUME) || (cruise_button == HYUNDAI_BTN_SET) || (cruise_button == HYUNDAI_BTN_CANCEL) || main_button) {
|
||||
hyundai_last_button_interaction = 0U;
|
||||
} else {
|
||||
hyundai_last_button_interaction = MIN(hyundai_last_button_interaction + 1U, HYUNDAI_PREV_BUTTON_SAMPLES);
|
||||
|
||||
@@ -129,7 +129,7 @@ static int nissan_fwd_hook(int bus_num, int addr) {
|
||||
int bus_fwd = -1;
|
||||
|
||||
if (bus_num == 0) {
|
||||
int block_msg = (addr == 0x280); // CANCEL_MSG
|
||||
bool block_msg = (addr == 0x280); // CANCEL_MSG
|
||||
if (!block_msg) {
|
||||
bus_fwd = 2; // ADAS
|
||||
}
|
||||
@@ -137,7 +137,7 @@ static int nissan_fwd_hook(int bus_num, int addr) {
|
||||
|
||||
if (bus_num == 2) {
|
||||
// 0x169 is LKAS, 0x2b1 LKAS_HUD, 0x4cc LKAS_HUD_INFO_MSG
|
||||
int block_msg = ((addr == 0x169) || (addr == 0x2b1) || (addr == 0x4cc));
|
||||
bool block_msg = ((addr == 0x169) || (addr == 0x2b1) || (addr == 0x4cc));
|
||||
if (!block_msg) {
|
||||
bus_fwd = 0; // V-CAN
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ static int subaru_preglobal_fwd_hook(int bus_num, int addr) {
|
||||
}
|
||||
|
||||
if (bus_num == SUBARU_PG_CAM_BUS) {
|
||||
int block_msg = ((addr == MSG_SUBARU_PG_ES_Distance) || (addr == MSG_SUBARU_PG_ES_LKAS));
|
||||
bool block_msg = ((addr == MSG_SUBARU_PG_ES_Distance) || (addr == MSG_SUBARU_PG_ES_LKAS));
|
||||
if (!block_msg) {
|
||||
bus_fwd = SUBARU_PG_MAIN_BUS; // Main CAN
|
||||
}
|
||||
|
||||
@@ -394,10 +394,10 @@ static int toyota_fwd_hook(int bus_num, int addr) {
|
||||
if (bus_num == 2) {
|
||||
// block stock lkas messages and stock acc messages (if OP is doing ACC)
|
||||
// in TSS2, 0x191 is LTA which we need to block to avoid controls collision
|
||||
int is_lkas_msg = ((addr == 0x2E4) || (addr == 0x412) || (addr == 0x191));
|
||||
bool is_lkas_msg = ((addr == 0x2E4) || (addr == 0x412) || (addr == 0x191));
|
||||
// in TSS2 the camera does ACC as well, so filter 0x343
|
||||
int is_acc_msg = (addr == 0x343);
|
||||
int block_msg = is_lkas_msg || (is_acc_msg && !toyota_stock_longitudinal);
|
||||
bool is_acc_msg = (addr == 0x343);
|
||||
bool block_msg = is_lkas_msg || (is_acc_msg && !toyota_stock_longitudinal);
|
||||
if (!block_msg) {
|
||||
bus_fwd = 0;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
uint32_t GET_BYTES(const CANPacket_t *msg, int start, int len) {
|
||||
uint32_t ret = 0U;
|
||||
for (int i = 0; i < len; i++) {
|
||||
const uint8_t shift = i * 8;
|
||||
const uint32_t shift = i * 8;
|
||||
ret |= (((uint32_t)msg->data[start + i]) << shift);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -112,10 +112,10 @@ bool llcan_set_speed(FDCAN_GlobalTypeDef *FDCANx, uint32_t speed, uint32_t data_
|
||||
}
|
||||
|
||||
// Set the nominal bit timing values
|
||||
uint16_t tq = CAN_QUANTA(speed, prescaler);
|
||||
uint16_t sp = CAN_SP_NOMINAL;
|
||||
uint8_t seg1 = CAN_SEG1(tq, sp);
|
||||
uint8_t seg2 = CAN_SEG2(tq, sp);
|
||||
uint32_t tq = CAN_QUANTA(speed, prescaler);
|
||||
uint32_t sp = CAN_SP_NOMINAL;
|
||||
uint32_t seg1 = CAN_SEG1(tq, sp);
|
||||
uint32_t seg2 = CAN_SEG2(tq, sp);
|
||||
uint8_t sjw = MIN(127U, seg2);
|
||||
|
||||
FDCANx->NBTP = (((sjw & 0x7FU)-1U)<<FDCAN_NBTP_NSJW_Pos) | (((seg1 & 0xFFU)-1U)<<FDCAN_NBTP_NTSEG1_Pos) | (((seg2 & 0x7FU)-1U)<<FDCAN_NBTP_NTSEG2_Pos) | (((prescaler & 0x1FFU)-1U)<<FDCAN_NBTP_NBRP_Pos);
|
||||
|
||||
@@ -24,5 +24,4 @@ misra-c2012-2.5
|
||||
misra-c2012-8.7
|
||||
misra-c2012-8.4
|
||||
misra-c2012-10.6
|
||||
misra-c2012-10.3
|
||||
misra-c2012-21.15
|
||||
|
||||
Reference in New Issue
Block a user