From 5bc65bb54e3094b30943ea55006b9dcd527263c2 Mon Sep 17 00:00:00 2001 From: Siddharth Purohit Date: Mon, 17 May 2021 23:05:29 +0530 Subject: [PATCH] AP_HAL: set CANFrame max data length based on CANFD availability --- libraries/AP_HAL/CANIface.h | 9 ++++++++- libraries/AP_HAL/board/chibios.h | 6 ------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/AP_HAL/CANIface.h b/libraries/AP_HAL/CANIface.h index be0950802e..8246168da9 100644 --- a/libraries/AP_HAL/CANIface.h +++ b/libraries/AP_HAL/CANIface.h @@ -19,6 +19,7 @@ #include #include "AP_HAL_Namespace.h" +#include "AP_HAL_Boards.h" class ExpandingString; @@ -32,8 +33,13 @@ struct AP_HAL::CANFrame { static const uint32_t FlagRTR = 1U << 30; ///< Remote transmission request static const uint32_t FlagERR = 1U << 29; ///< Error frame +#if HAL_CANFD_SUPPORTED + static const uint8_t NonFDCANMaxDataLen = 8; static const uint8_t MaxDataLen = 64; - +#else + static const uint8_t NonFDCANMaxDataLen = 8; + static const uint8_t MaxDataLen = 8; +#endif uint32_t id; ///< CAN ID with flags (above) union { uint8_t data[MaxDataLen]; @@ -138,6 +144,7 @@ struct AP_HAL::CANFrame { } return 64; } + static uint8_t dataLengthToDlc(uint8_t data_length) { if (data_length <= 8) { return data_length; diff --git a/libraries/AP_HAL/board/chibios.h b/libraries/AP_HAL/board/chibios.h index 34b5726af2..fa3e48511e 100644 --- a/libraries/AP_HAL/board/chibios.h +++ b/libraries/AP_HAL/board/chibios.h @@ -128,9 +128,3 @@ #ifndef HAL_BOARD_STORAGE_DIRECTORY #define HAL_BOARD_STORAGE_DIRECTORY "/APM" #endif - -#if defined(STM32H7XX) || defined(STM32G4) -#define HAL_CANFD_SUPPORTED 1 -# else -#define HAL_CANFD_SUPPORTED 0 -#endif