Skip to content

Commit

Permalink
drivers: can: add utility macro for calculating TDC offset
Browse files Browse the repository at this point in the history
Add a utility macro for calculating the Transmitter Delay Compensation
(TDC) Offset using the sample point and CAN core clock prescaler specified
by a set of data phase timing parameters.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
(cherry picked from commit a363126)
  • Loading branch information
henrikbrixandersen authored and jhedberg committed Apr 4, 2024
1 parent 927ab29 commit ee3fab4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/zephyr/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,23 @@ typedef void (*can_state_change_callback_t)(const struct device *dev,
* For internal driver use only, skip these in public documentation.
*/

/**
* @brief Calculate Transmitter Delay Compensation Offset from data phase timing parameters.
*
* Calculates the TDC Offset in minimum time quanta (mtq) using the sample point and CAN core clock
* prescaler specified by a set of data phase timing parameters.
*
* The result is clamped to the minimum/maximum supported TDC Offset values provided.
*
* @param _timing_data Pointer to data phase timing parameters.
* @param _tdco_min Minimum supported TDC Offset value in mtq.
* @param _tdco_max Maximum supported TDC Offset value in mtq.
* @return Calculated TDC Offset value in mtq.
*/
#define CAN_CALC_TDCO(_timing_data, _tdco_min, _tdco_max) \
CLAMP((1U + _timing_data->prop_seg + _timing_data->phase_seg1) * _timing_data->prescaler, \
_tdco_min, _tdco_max)

/**
* @brief Callback API upon setting CAN bus timing
* See @a can_set_timing() for argument description
Expand Down

0 comments on commit ee3fab4

Please sign in to comment.