diff --git a/board/drivers/can_common.h b/board/drivers/can_common.h index db77617e..bc9adde7 100644 --- a/board/drivers/can_common.h +++ b/board/drivers/can_common.h @@ -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); diff --git a/board/drivers/gmlan_alt.h b/board/drivers/gmlan_alt.h index a4377a67..2dbc381b 100644 --- a/board/drivers/gmlan_alt.h +++ b/board/drivers/gmlan_alt.h @@ -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; } } diff --git a/board/drivers/interrupts.h b/board/drivers/interrupts.h index 79c87ccc..d4c72be1 100644 --- a/board/drivers/interrupts.h +++ b/board/drivers/interrupts.h @@ -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; diff --git a/board/drivers/usb.h b/board/drivers/usb.h index dec7ba81..1872dd52 100644 --- a/board/drivers/usb.h +++ b/board/drivers/usb.h @@ -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; } diff --git a/board/main_comms.h b/board/main_comms.h index 096f7b1a..c0d5c516 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -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 diff --git a/board/safety.h b/board/safety.h index 50669e3b..1e952440 100644 --- a/board/safety.h +++ b/board/safety.h @@ -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); diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index d1e4dd21..82a5d9cd 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -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; } diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 3881db74..78bbb7f0 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -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; diff --git a/board/safety/safety_hyundai_canfd.h b/board/safety/safety_hyundai_canfd.h index 0744a6e2..fb6ccf55 100644 --- a/board/safety/safety_hyundai_canfd.h +++ b/board/safety/safety_hyundai_canfd.h @@ -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; diff --git a/board/safety/safety_hyundai_common.h b/board/safety/safety_hyundai_common.h index 2c89bfb7..54ea0f02 100644 --- a/board/safety/safety_hyundai_common.h +++ b/board/safety/safety_hyundai_common.h @@ -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); diff --git a/board/safety/safety_nissan.h b/board/safety/safety_nissan.h index 23177273..c2406260 100644 --- a/board/safety/safety_nissan.h +++ b/board/safety/safety_nissan.h @@ -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 } diff --git a/board/safety/safety_subaru_preglobal.h b/board/safety/safety_subaru_preglobal.h index 1549d595..1047814a 100644 --- a/board/safety/safety_subaru_preglobal.h +++ b/board/safety/safety_subaru_preglobal.h @@ -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 } diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index f6bfc080..50c00b38 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -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; } diff --git a/board/safety_declarations.h b/board/safety_declarations.h index 39dcabf9..64b55f20 100644 --- a/board/safety_declarations.h +++ b/board/safety_declarations.h @@ -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; diff --git a/board/stm32h7/llfdcan.h b/board/stm32h7/llfdcan.h index cdce0c44..4bb6d3d0 100644 --- a/board/stm32h7/llfdcan.h +++ b/board/stm32h7/llfdcan.h @@ -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)<