Skip to content

Commit

Permalink
drivers: can: move can_set_bitrate() to can_common.c
Browse files Browse the repository at this point in the history
Move the can_set_bitrate() function to can_common.c as it is getting
quite long for a static inline function.

Signed-off-by: Henrik Brix Andersen <[email protected]>
  • Loading branch information
henrikbrixandersen authored and MaureenHelm committed Mar 15, 2022
1 parent 0bae208 commit 58ff3f0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
46 changes: 46 additions & 0 deletions drivers/can/can_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,49 @@ int can_calc_prescaler(const struct device *dev, struct can_timing *timing,

return core_clock % (ts * timing->prescaler);
}

int can_set_bitrate(const struct device *dev, uint32_t bitrate, uint32_t bitrate_data)
{
struct can_timing timing;
#ifdef CONFIG_CAN_FD_MODE
struct can_timing timing_data;
#endif
uint32_t max_bitrate;
int ret;

ret = can_get_max_bitrate(dev, &max_bitrate);
if (ret == -ENOSYS) {
/* Maximum bitrate unknown */
max_bitrate = 0;
} else if (ret < 0) {
return ret;
}

if ((max_bitrate > 0) && (bitrate > max_bitrate)) {
return -ENOTSUP;
}

ret = can_calc_timing(dev, &timing, bitrate, 875);
if (ret < 0) {
return -EINVAL;
}

timing.sjw = CAN_SJW_NO_CHANGE;

#ifdef CONFIG_CAN_FD_MODE
if ((max_bitrate > 0) && (bitrate_data > max_bitrate)) {
return -ENOTSUP;
}

ret = can_calc_timing_data(dev, &timing_data, bitrate_data, 875);
if (ret < 0) {
return -EINVAL;
}

timing_data.sjw = CAN_SJW_NO_CHANGE;

return can_set_timing(dev, &timing, &timing_data);
#else /* CONFIG_CAN_FD_MODE */
return can_set_timing(dev, &timing, NULL);
#endif /* !CONFIG_CAN_FD_MODE */
}
48 changes: 1 addition & 47 deletions include/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,53 +791,7 @@ static inline int z_impl_can_set_mode(const struct device *dev, enum can_mode mo
* @retval -EINVAL bitrate cannot be met.
* @retval -EIO General input/output error, failed to set bitrate.
*/
static inline int can_set_bitrate(const struct device *dev,
uint32_t bitrate,
uint32_t bitrate_data)
{
struct can_timing timing;
#ifdef CONFIG_CAN_FD_MODE
struct can_timing timing_data;
#endif
uint32_t max_bitrate;
int ret;

ret = can_get_max_bitrate(dev, &max_bitrate);
if (ret == -ENOSYS) {
/* Maximum bitrate unknown */
max_bitrate = 0;
} else if (ret < 0) {
return ret;
}

if ((max_bitrate > 0) && (bitrate > max_bitrate)) {
return -ENOTSUP;
}

ret = can_calc_timing(dev, &timing, bitrate, 875);
if (ret < 0) {
return -EINVAL;
}

timing.sjw = CAN_SJW_NO_CHANGE;

#ifdef CONFIG_CAN_FD_MODE
if ((max_bitrate > 0) && (bitrate_data > max_bitrate)) {
return -ENOTSUP;
}

ret = can_calc_timing_data(dev, &timing_data, bitrate_data, 875);
if (ret < 0) {
return -EINVAL;
}

timing_data.sjw = CAN_SJW_NO_CHANGE;

return can_set_timing(dev, &timing, &timing_data);
#else /* CONFIG_CAN_FD_MODE */
return can_set_timing(dev, &timing, NULL);
#endif /* !CONFIG_CAN_FD_MODE */
}
int can_set_bitrate(const struct device *dev, uint32_t bitrate, uint32_t bitrate_data);

/** @} */

Expand Down

0 comments on commit 58ff3f0

Please sign in to comment.