Skip to content

Commit

Permalink
Enable CAN loop delay compensation
Browse files Browse the repository at this point in the history
This is necessary to support r4.5 and newer boards which use a CAN
transceiver with higher delay.
  • Loading branch information
jpieper committed Jan 25, 2023
1 parent 2f5c0ca commit 59b4d2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fw/fdcan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 9 additions & 0 deletions fw/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 59b4d2a

Please sign in to comment.