void can_sjw_set_default(struct can_bittiming *bt)
{ if (bt->sjw) return;
/* If user space provides no sjw, use sane default of phase_seg2 / 2 */
bt->sjw = max(1U, min(bt->phase_seg1, bt->phase_seg2 / 2));
}
int can_sjw_check(conststruct net_device *dev, conststruct can_bittiming *bt, conststruct can_bittiming_const *btc, struct netlink_ext_ack *extack)
{ if (bt->sjw > btc->sjw_max) {
NL_SET_ERR_MSG_FMT(extack, "sjw: %u greater than max sjw: %u",
bt->sjw, btc->sjw_max); return -EINVAL;
}
if (bt->sjw > bt->phase_seg1) {
NL_SET_ERR_MSG_FMT(extack, "sjw: %u greater than phase-seg1: %u",
bt->sjw, bt->phase_seg1); return -EINVAL;
}
if (bt->sjw > bt->phase_seg2) {
NL_SET_ERR_MSG_FMT(extack, "sjw: %u greater than phase-seg2: %u",
bt->sjw, bt->phase_seg2); return -EINVAL;
}
return 0;
}
/* Checks the validity of the specified bit-timing parameters prop_seg, * phase_seg1, phase_seg2 and sjw and tries to determine the bitrate * prescaler value brp. You can find more information in the header * file linux/can/netlink.h.
*/ staticint can_fixup_bittiming(conststruct net_device *dev, struct can_bittiming *bt, conststruct can_bittiming_const *btc, struct netlink_ext_ack *extack)
{ constunsignedint tseg1 = bt->prop_seg + bt->phase_seg1; conststruct can_priv *priv = netdev_priv(dev);
u64 brp64; int err;
if (tseg1 < btc->tseg1_min) {
NL_SET_ERR_MSG_FMT(extack, "prop-seg + phase-seg1: %u less than tseg1-min: %u",
tseg1, btc->tseg1_min); return -EINVAL;
} if (tseg1 > btc->tseg1_max) {
NL_SET_ERR_MSG_FMT(extack, "prop-seg + phase-seg1: %u greater than tseg1-max: %u",
tseg1, btc->tseg1_max); return -EINVAL;
} if (bt->phase_seg2 < btc->tseg2_min) {
NL_SET_ERR_MSG_FMT(extack, "phase-seg2: %u less than tseg2-min: %u",
bt->phase_seg2, btc->tseg2_min); return -EINVAL;
} if (bt->phase_seg2 > btc->tseg2_max) {
NL_SET_ERR_MSG_FMT(extack, "phase-seg2: %u greater than tseg2-max: %u",
bt->phase_seg2, btc->tseg2_max); return -EINVAL;
}
can_sjw_set_default(bt);
err = can_sjw_check(dev, bt, btc, extack); if (err) return err;
for (i = 0; i < bitrate_const_cnt; i++) { if (bt->bitrate == bitrate_const[i]) return 0;
}
NL_SET_ERR_MSG_FMT(extack, "bitrate %u bps not supported",
bt->brp);
return -EINVAL;
}
int can_get_bittiming(conststruct net_device *dev, struct can_bittiming *bt, conststruct can_bittiming_const *btc, const u32 *bitrate_const, constunsignedint bitrate_const_cnt, struct netlink_ext_ack *extack)
{ /* Depending on the given can_bittiming parameter structure the CAN * timing parameters are calculated based on the provided bitrate OR * alternatively the CAN timing parameters (tq, prop_seg, etc.) are * provided directly which are then checked and fixed up.
*/ if (!bt->tq && bt->bitrate && btc) return can_calc_bittiming(dev, bt, btc, extack); if (bt->tq && !bt->bitrate && btc) return can_fixup_bittiming(dev, bt, btc, extack); if (!bt->tq && bt->bitrate && bitrate_const) return can_validate_bitrate(dev, bt, bitrate_const,
bitrate_const_cnt, extack);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.