|
66 | 66 | #define GET_BERR_COUNTER 7 |
67 | 67 | #define GET_XSTATS 8 |
68 | 68 | #define GET_LINK_STATS 9 |
| 69 | +#define GET_DATA_BITTIMING 10 |
| 70 | +#define GET_DATA_BITTIMING_CONST 11 |
69 | 71 |
|
70 | 72 | struct get_req { |
71 | 73 | struct nlmsghdr n; |
@@ -529,7 +531,26 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) |
529 | 531 | fprintf(stderr, "no berr_counter data found\n"); |
530 | 532 |
|
531 | 533 | break; |
| 534 | + case GET_DATA_BITTIMING: |
| 535 | + if (can_attr[IFLA_CAN_DATA_BITTIMING]) { |
| 536 | + memcpy(res, |
| 537 | + RTA_DATA(can_attr[IFLA_CAN_DATA_BITTIMING]), |
| 538 | + sizeof(struct can_bittiming)); |
| 539 | + ret = 0; |
| 540 | + } else |
| 541 | + fprintf(stderr, "no bittiming data found\n"); |
| 542 | + |
| 543 | + break; |
| 544 | + case GET_DATA_BITTIMING_CONST: |
| 545 | + if (can_attr[IFLA_CAN_DATA_BITTIMING_CONST]) { |
| 546 | + memcpy(res, |
| 547 | + RTA_DATA(can_attr[IFLA_CAN_DATA_BITTIMING_CONST]), |
| 548 | + sizeof(struct can_bittiming_const)); |
| 549 | + ret = 0; |
| 550 | + } else |
| 551 | + fprintf(stderr, "no bittiming_const data found\n"); |
532 | 552 |
|
| 553 | + break; |
533 | 554 | default: |
534 | 555 | fprintf(stderr, "unknown acquire mode\n"); |
535 | 556 | } |
@@ -1034,6 +1055,42 @@ int can_set_bitrate_samplepoint(const char *name, __u32 bitrate, |
1034 | 1055 | return can_set_bittiming(name, &bt); |
1035 | 1056 | } |
1036 | 1057 |
|
| 1058 | +/** |
| 1059 | + * @ingroup extern |
| 1060 | + * can_set_canfd_bitrates_samplepoint - setup the bitrate. |
| 1061 | + * |
| 1062 | + * @param name name of the can device. This is the netdev name, as ifconfig -a shows |
| 1063 | + * in your system. usually it contains prefix "can" and the numer of the can |
| 1064 | + * line. e.g. "can0" |
| 1065 | + * @param bitrate bitrate of the can bus |
| 1066 | + * @param sample_point sample point value |
| 1067 | + * @param dbitrate dbitrate of the can bus |
| 1068 | + * @param dsample_point dsample point value |
| 1069 | + * |
| 1070 | + * This one is similar to can_set_bitrate, only you can additionally set up the |
| 1071 | + * time point for sampling (sample point) customly instead of using the |
| 1072 | + * CIA recommended value. sample_point can be a value between 0 and 999. |
| 1073 | + * |
| 1074 | + * @return 0 if success |
| 1075 | + * @return -1 if failed |
| 1076 | + */ |
| 1077 | +int can_set_canfd_bitrates_samplepoint(const char *name, __u32 bitrate, |
| 1078 | + __u32 sample_point, __u32 dbitrate, __u32 dsample_point) |
| 1079 | +{ |
| 1080 | + struct can_bittiming bt; |
| 1081 | + struct can_bittiming dbt; |
| 1082 | + |
| 1083 | + memset(&bt, 0, sizeof(bt)); |
| 1084 | + bt.bitrate = bitrate; |
| 1085 | + bt.sample_point = sample_point; |
| 1086 | + |
| 1087 | + memset(&dbt, 0, sizeof(dbt)); |
| 1088 | + dbt.bitrate = dbitrate; |
| 1089 | + dbt.sample_point = dsample_point; |
| 1090 | + |
| 1091 | + return can_set_canfd_bittiming(name, &bt, &dbt); |
| 1092 | +} |
| 1093 | + |
1037 | 1094 | /** |
1038 | 1095 | * @ingroup extern |
1039 | 1096 | * can_get_state - get the current state of the device |
@@ -1112,6 +1169,27 @@ int can_get_bittiming(const char *name, struct can_bittiming *bt) |
1112 | 1169 | return get_link(name, GET_BITTIMING, bt); |
1113 | 1170 | } |
1114 | 1171 |
|
| 1172 | +/** |
| 1173 | + * @ingroup extern |
| 1174 | + * can_get_data_bittiming - get the current bittimnig configuration. |
| 1175 | + * |
| 1176 | + * @param name name of the can device. This is the netdev name, as ifconfig -a shows |
| 1177 | + * in your system. usually it contains prefix "can" and the numer of the can |
| 1178 | + * line. e.g. "can0" |
| 1179 | + * @param dbt pointer to the bittiming struct. |
| 1180 | + * |
| 1181 | + * This one stores the current bittiming configuration. |
| 1182 | + * |
| 1183 | + * Please see can_set_bittiming for more information about bit timing. |
| 1184 | + * |
| 1185 | + * @return 0 if success |
| 1186 | + * @return -1 if failed |
| 1187 | + */ |
| 1188 | +int can_get_data_bittiming(const char *name, struct can_bittiming *dbt) |
| 1189 | +{ |
| 1190 | + return get_link(name, GET_DATA_BITTIMING, dbt); |
| 1191 | +} |
| 1192 | + |
1115 | 1193 | /** |
1116 | 1194 | * @ingroup extern |
1117 | 1195 | * can_get_ctrlmode - get the current control mode. |
@@ -1192,6 +1270,42 @@ int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc) |
1192 | 1270 | return get_link(name, GET_BITTIMING_CONST, btc); |
1193 | 1271 | } |
1194 | 1272 |
|
| 1273 | +/** |
| 1274 | + * @ingroup extern |
| 1275 | + * can_get_data_bittiming_const - get the current bittimnig constant. |
| 1276 | + * |
| 1277 | + * @param name name of the can device. This is the netdev name, as ifconfig -a shows |
| 1278 | + * in your system. usually it contains prefix "can" and the numer of the can |
| 1279 | + * line. e.g. "can0" |
| 1280 | + * @param dbtc pointer to the bittiming constant struct. |
| 1281 | + * |
| 1282 | + * This one stores the hardware dependent bittiming constant. The |
| 1283 | + * can_bittiming_const struct consists: |
| 1284 | + * |
| 1285 | + * @code |
| 1286 | + * struct can_bittiming_const { |
| 1287 | + * char name[16]; |
| 1288 | + * __u32 tseg1_min; |
| 1289 | + * __u32 tseg1_max; |
| 1290 | + * __u32 tseg2_min; |
| 1291 | + * __u32 tseg2_max; |
| 1292 | + * __u32 sjw_max; |
| 1293 | + * __u32 brp_min; |
| 1294 | + * __u32 brp_max; |
| 1295 | + * __u32 brp_inc; |
| 1296 | + * }; |
| 1297 | + * @endcode |
| 1298 | + * |
| 1299 | + * The information in this struct is used to calculate the bus bit timing |
| 1300 | + * automatically. |
| 1301 | + * |
| 1302 | + * @return 0 if success |
| 1303 | + * @return -1 if failed |
| 1304 | + */ |
| 1305 | +int can_get_data_bittiming_const(const char *name, struct can_bittiming_const *dbtc) |
| 1306 | +{ |
| 1307 | + return get_link(name, GET_BITTIMING_CONST, dbtc); |
| 1308 | +} |
1195 | 1309 |
|
1196 | 1310 | /** |
1197 | 1311 | * @ingroup extern |
|
0 commit comments