From fd226de0a40e4c587c0cbb88b5c86d6bc73c12bf Mon Sep 17 00:00:00 2001 From: Igor Biletskyy Date: Fri, 16 Sep 2022 21:56:48 -0700 Subject: [PATCH] board struct: add has_canfd (#1072) * add * gate this * and this * forgot white --- board/boards/black.h | 1 + board/boards/board_declarations.h | 1 + board/boards/dos.h | 1 + board/boards/grey.h | 1 + board/boards/pedal.h | 1 + board/boards/red.h | 1 + board/boards/red_v2.h | 1 + board/boards/uno.h | 1 + board/boards/white.h | 1 + board/drivers/can_common.h | 3 +++ board/main_comms.h | 2 +- 11 files changed, 13 insertions(+), 1 deletion(-) diff --git a/board/boards/black.h b/board/boards/black.h index 293a48dd9b..27fc3d5974 100644 --- a/board/boards/black.h +++ b/board/boards/black.h @@ -187,6 +187,7 @@ const board board_black = { .has_hw_gmlan = false, .has_obd = true, .has_lin = false, + .has_canfd = false, .has_rtc_battery = false, .fan_max_rpm = 0U, .init = black_init, diff --git a/board/boards/board_declarations.h b/board/boards/board_declarations.h index 1a9f9ac56f..b6216da8de 100644 --- a/board/boards/board_declarations.h +++ b/board/boards/board_declarations.h @@ -21,6 +21,7 @@ struct board { const bool has_hw_gmlan; const bool has_obd; const bool has_lin; + const bool has_canfd; const bool has_rtc_battery; const uint16_t fan_max_rpm; board_init init; diff --git a/board/boards/dos.h b/board/boards/dos.h index 55fe8f42be..d0b00ef045 100644 --- a/board/boards/dos.h +++ b/board/boards/dos.h @@ -202,6 +202,7 @@ const board board_dos = { .has_hw_gmlan = false, .has_obd = true, .has_lin = false, + .has_canfd = false, .has_rtc_battery = true, .fan_max_rpm = 6500U, .init = dos_init, diff --git a/board/boards/grey.h b/board/boards/grey.h index fa5e67d259..29deb99136 100644 --- a/board/boards/grey.h +++ b/board/boards/grey.h @@ -41,6 +41,7 @@ const board board_grey = { .has_hw_gmlan = true, .has_obd = false, .has_lin = true, + .has_canfd = false, .has_rtc_battery = false, .fan_max_rpm = 0U, .init = grey_init, diff --git a/board/boards/pedal.h b/board/boards/pedal.h index ccd36b89b9..62830cfbaf 100644 --- a/board/boards/pedal.h +++ b/board/boards/pedal.h @@ -79,6 +79,7 @@ const board board_pedal = { .has_hw_gmlan = false, .has_obd = false, .has_lin = false, + .has_canfd = false, .has_rtc_battery = false, .fan_max_rpm = 0U, .init = pedal_init, diff --git a/board/boards/red.h b/board/boards/red.h index 2d17f8c618..9691ed5c6c 100644 --- a/board/boards/red.h +++ b/board/boards/red.h @@ -179,6 +179,7 @@ const board board_red = { .has_hw_gmlan = false, .has_obd = true, .has_lin = false, + .has_canfd = true, .has_rtc_battery = false, .fan_max_rpm = 0U, .init = red_init, diff --git a/board/boards/red_v2.h b/board/boards/red_v2.h index d9373aa635..3eef77e0f6 100644 --- a/board/boards/red_v2.h +++ b/board/boards/red_v2.h @@ -122,6 +122,7 @@ const board board_red_v2 = { .has_hw_gmlan = false, .has_obd = true, .has_lin = false, + .has_canfd = true, .has_rtc_battery = true, .fan_max_rpm = 0U, .init = red_v2_init, diff --git a/board/boards/uno.h b/board/boards/uno.h index 1115c5f8b3..c2573681e8 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -251,6 +251,7 @@ const board board_uno = { .has_hw_gmlan = false, .has_obd = true, .has_lin = false, + .has_canfd = false, .has_rtc_battery = true, .fan_max_rpm = 5100U, .init = uno_init, diff --git a/board/boards/white.h b/board/boards/white.h index 266370afe1..961e0eaa16 100644 --- a/board/boards/white.h +++ b/board/boards/white.h @@ -243,6 +243,7 @@ const board board_white = { .has_hw_gmlan = true, .has_obd = false, .has_lin = true, + .has_canfd = false, .has_rtc_battery = false, .fan_max_rpm = 0U, .init = white_init, diff --git a/board/drivers/can_common.h b/board/drivers/can_common.h index 2d1e9da535..b27c118c36 100644 --- a/board/drivers/can_common.h +++ b/board/drivers/can_common.h @@ -168,6 +168,9 @@ bus_config_t bus_config[] = { void can_init_all(void) { bool ret = true; for (uint8_t i=0U; i < CAN_CNT; i++) { + if (!current_board->has_canfd) { + bus_config[i].can_data_speed = 0U; + } can_clear(can_queues[i]); ret &= can_init(i); } diff --git a/board/main_comms.h b/board/main_comms.h index 7da17cab69..25468f223f 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -538,7 +538,7 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { break; // **** 0xde: set CAN FD data bitrate case 0xf9: - if (req->param1 < CAN_CNT) { + if ((req->param1 < CAN_CNT) && current_board->has_canfd) { // TODO: add sanity check, ideally check if value is correct (from array of correct values) bus_config[req->param1].can_data_speed = req->param2; bus_config[req->param1].canfd_enabled = (req->param2 >= bus_config[req->param1].can_speed);