@@ -84,6 +84,7 @@ struct req_info {
8484 __u32 restart_ms ;
8585 struct can_ctrlmode * ctrlmode ;
8686 struct can_bittiming * bittiming ;
87+ struct can_bittiming * dbittiming ;
8788};
8889
8990/**
@@ -648,6 +649,12 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name,
648649 sizeof (struct can_bittiming ));
649650 }
650651
652+ if (req_info -> dbittiming != NULL ) {
653+ addattr_l (& req .n , 1024 , IFLA_CAN_DATA_BITTIMING ,
654+ req_info -> dbittiming ,
655+ sizeof (struct can_bittiming ));
656+ }
657+
651658 if (req_info -> ctrlmode != NULL ) {
652659 addattr_l (& req .n , 1024 , IFLA_CAN_CTRLMODE ,
653660 req_info -> ctrlmode ,
@@ -916,6 +923,59 @@ int can_set_bittiming(const char *name, struct can_bittiming *bt)
916923 return set_link (name , 0 , & req_info );
917924}
918925
926+ /**
927+ * @ingroup extern
928+ * can_set_data_bittiming - setup the bittiming for CAN FD Data transmission.
929+ *
930+ * @param name name of the can device. This is the netdev name, as ifconfig -a shows
931+ * in your system. usually it contains prefix "can" and the numer of the can
932+ * line. e.g. "can0"
933+ * @param bt pointer to a can_bittiming struct
934+ *
935+ * This sets the bittiming of the can device for the data transmission if CAN FD is enabled. This is for advantage usage. In
936+ * normal cases you should use can_set_bitrate to simply define the bitrate and
937+ * let the driver automatically calculate the bittiming. You will only need this
938+ * function if you wish to define the bittiming in expert mode with fully
939+ * manually defined timing values.
940+ * You have to define the bittiming struct yourself. a can_bittiming struct
941+ * consists of:
942+ *
943+ * @code
944+ * struct can_bittiming {
945+ * __u32 bitrate;
946+ * __u32 sample_point;
947+ * __u32 tq;
948+ * __u32 prop_seg;
949+ * __u32 phase_seg1;
950+ * __u32 phase_seg2;
951+ * __u32 sjw;
952+ * __u32 brp;
953+ * }
954+ * @endcode
955+ *
956+ * to define a customized bittiming, you have to define tq, prop_seq,
957+ * phase_seg1, phase_seg2 and sjw. See http://www.can-cia.org/index.php?id=88
958+ * for more information about bittiming and synchronizations on can bus.
959+ *
960+ * @return 0 if success
961+ * @return -1 if failed
962+ */
963+
964+ int can_set_canfd_bittiming (const char * name , struct can_bittiming * bt , struct can_bittiming * dbt )
965+ {
966+ struct can_ctrlmode ctrl = {
967+ .mask = CAN_CTRLMODE_FD ,
968+ .flags = CAN_CTRLMODE_FD ,
969+ };
970+ struct req_info req_info = {
971+ .bittiming = bt ,
972+ .dbittiming = dbt ,
973+ .ctrlmode = & ctrl
974+ };
975+
976+ return set_link (name , 0 , & req_info );
977+ }
978+
919979/**
920980 * @ingroup extern
921981 * can_set_bitrate - setup the bitrate.
0 commit comments