From 59b4d2aec473c17b5c7ab96429e352d552f45f65 Mon Sep 17 00:00:00 2001 From: Josh Pieper Date: Thu, 8 Dec 2022 10:35:34 -0500 Subject: [PATCH] Enable CAN loop delay compensation This is necessary to support r4.5 and newer boards which use a CAN transceiver with higher delay. --- fw/fdcan.cc | 14 ++++++++++++++ fw/fdcan.h | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/fw/fdcan.cc b/fw/fdcan.cc index 1517021..a8f9e13 100644 --- a/fw/fdcan.cc +++ b/fw/fdcan.cc @@ -273,6 +273,20 @@ void FDCan::Reset(const Options& options) { mbed_die(); } + if (options.delay_compensation) { + if (HAL_FDCAN_ConfigTxDelayCompensation( + &can, options.tdc_offset, options.tdc_filter) != HAL_OK) { + mbed_die(); + } + if (HAL_FDCAN_EnableTxDelayCompensation(&can) != HAL_OK) { + mbed_die(); + } + } else { + if (HAL_FDCAN_DisableTxDelayCompensation(&can) != HAL_OK) { + mbed_die(); + } + } + if (HAL_FDCAN_Start(&can) != HAL_OK) { mbed_die(); } diff --git a/fw/fdcan.h b/fw/fdcan.h index 5afa3f4..4c16c38 100644 --- a/fw/fdcan.h +++ b/fw/fdcan.h @@ -70,6 +70,15 @@ class FDCan { bool restricted_mode = false; bool bus_monitor = false; + // We for now default to use compensation that is appropriate for + // the TCAN1057 with its longer delay: + // + // start - 13 / 85Mhz ~= 152ns + // min - 1 / 85Mhz ~= 12ns + bool delay_compensation = true; + uint32_t tdc_offset = 13; + uint32_t tdc_filter = 1; + FilterAction global_std_action = FilterAction::kAccept; FilterAction global_ext_action = FilterAction::kAccept; FilterAction global_remote_std_action = FilterAction::kAccept;