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;