Lines Matching +full:- +full:- +full:can +full:- +full:if

5  * SPDX-License-Identifier: Apache-2.0
12 #include <zephyr/drivers/can.h>
36 /* zephyr-keep-sorted-start */
38 CAN_SHELL_MODE_MAPPING("listen-only", CAN_MODE_LISTENONLY),
40 CAN_SHELL_MODE_MAPPING("manual-recovery", CAN_MODE_MANUAL_RECOVERY),
42 CAN_SHELL_MODE_MAPPING("one-shot", CAN_MODE_ONE_SHOT),
43 CAN_SHELL_MODE_MAPPING("triple-sampling", CAN_MODE_3_SAMPLES),
44 /* zephyr-keep-sorted-stop */
73 return DEVICE_API_IS(can, dev) && device_is_ready(dev); in can_device_check()
88 uint8_t nbytes = can_dlc_to_bytes(frame->dlc); in can_shell_print_frame()
98 shell_fprintf_normal(sh, "(%05d) ", frame->timestamp); in can_shell_print_frame()
101 shell_fprintf_normal(sh, "%s ", dev->name); in can_shell_print_frame()
106 (frame->flags & CAN_FRAME_BRS) == 0 ? '-' : 'B', in can_shell_print_frame()
107 (frame->flags & CAN_FRAME_ESI) == 0 ? '-' : 'P'); in can_shell_print_frame()
110 /* CAN ID */ in can_shell_print_frame()
112 (frame->flags & CAN_FRAME_IDE) != 0 ? 0 : 5, "", in can_shell_print_frame()
113 (frame->flags & CAN_FRAME_IDE) != 0 ? 8 : 3, in can_shell_print_frame()
114 (frame->flags & CAN_FRAME_IDE) != 0 ? in can_shell_print_frame()
115 frame->id & CAN_EXT_ID_MASK : frame->id & CAN_STD_ID_MASK); in can_shell_print_frame()
119 (frame->flags & CAN_FRAME_FDF) != 0 ? "" : " ", in can_shell_print_frame()
120 (frame->flags & CAN_FRAME_FDF) != 0 ? 2 : 1, in can_shell_print_frame()
124 if ((frame->flags & CAN_FRAME_RTR) != 0) { in can_shell_print_frame()
128 shell_fprintf_normal(sh, "%02x ", frame->data[i]); in can_shell_print_frame()
143 if (can_shell_tx_msgq_sh == NULL) { in can_shell_tx_msgq_poll_submit()
150 if (err != 0) { in can_shell_tx_msgq_poll_submit()
163 if (event.error == 0) { in can_shell_tx_msgq_triggered_work_handler()
164 shell_print(can_shell_tx_msgq_sh, "CAN frame #%u successfully sent", in can_shell_tx_msgq_triggered_work_handler()
167 shell_error(can_shell_tx_msgq_sh, "failed to send CAN frame #%u (err %d)", in can_shell_tx_msgq_triggered_work_handler()
186 if (err != 0) { in can_shell_tx_callback()
187 LOG_ERR("CAN shell tx event queue full"); in can_shell_tx_callback()
203 if (err != 0) { in can_shell_rx_callback()
204 LOG_ERR("CAN shell rx event queue full"); in can_shell_rx_callback()
212 if (can_shell_rx_msgq_sh == NULL) { in can_shell_rx_msgq_poll_submit()
219 if (err != 0) { in can_shell_rx_msgq_poll_submit()
242 return "error-active"; in can_shell_state_to_string()
244 return "error-warning"; in can_shell_state_to_string()
246 return "error-passive"; in can_shell_state_to_string()
248 return "bus-off"; in can_shell_state_to_string()
263 if ((cap & BIT(bit)) == 0) { in can_shell_print_extended_modes()
269 if (BIT(bit) == can_shell_mode_map[i].mode) { in can_shell_print_extended_modes()
275 if (i == ARRAY_SIZE(can_shell_mode_map)) { in can_shell_print_extended_modes()
287 if (!can_device_check(dev)) { in cmd_can_start()
289 return -ENODEV; in cmd_can_start()
295 if (err != 0) { in cmd_can_start()
296 shell_error(sh, "failed to start CAN controller (err %d)", err); in cmd_can_start()
308 if (!can_device_check(dev)) { in cmd_can_stop()
310 return -ENODEV; in cmd_can_stop()
316 if (err != 0) { in cmd_can_stop()
317 shell_error(sh, "failed to stop CAN controller (err %d)", err); in cmd_can_stop()
339 if (!can_device_check(dev)) { in cmd_can_show()
341 return -ENODEV; in cmd_can_show()
345 if (err != 0) { in cmd_can_show()
346 shell_error(sh, "failed to get CAN core clock (err %d)", err); in cmd_can_show()
353 if (max_std_filters < 0 && max_std_filters != -ENOSYS) { in cmd_can_show()
354 shell_error(sh, "failed to get maximum standard (11-bit) filters (err %d)", err); in cmd_can_show()
359 if (max_ext_filters < 0 && max_ext_filters != -ENOSYS) { in cmd_can_show()
360 shell_error(sh, "failed to get maximum extended (29-bit) filters (err %d)", err); in cmd_can_show()
365 if (err != 0) { in cmd_can_show()
366 shell_error(sh, "failed to get CAN controller capabilities (err %d)", err); in cmd_can_show()
371 if (err != 0) { in cmd_can_show()
372 shell_error(sh, "failed to get CAN controller state (%d)", err); in cmd_can_show()
398 timing_min->sjw, timing_max->sjw, in cmd_can_show()
399 timing_min->prop_seg, timing_max->prop_seg, in cmd_can_show()
400 timing_min->phase_seg1, timing_max->phase_seg1, in cmd_can_show()
401 timing_min->phase_seg2, timing_max->phase_seg2, in cmd_can_show()
402 timing_min->prescaler, timing_max->prescaler); in cmd_can_show()
404 if (IS_ENABLED(CONFIG_CAN_FD_MODE) && (cap & CAN_MODE_FD) != 0) { in cmd_can_show()
410 timing_min->sjw, timing_max->sjw, in cmd_can_show()
411 timing_min->prop_seg, timing_max->prop_seg, in cmd_can_show()
412 timing_min->phase_seg1, timing_max->phase_seg1, in cmd_can_show()
413 timing_min->phase_seg2, timing_max->phase_seg2, in cmd_can_show()
414 timing_min->prescaler, timing_max->prescaler); in cmd_can_show()
418 shell_print(sh, "transceiver: %s", phy != NULL ? phy->name : "passive/none"); in cmd_can_show()
444 if (!can_device_check(dev)) { in cmd_can_bitrate_set()
446 return -ENODEV; in cmd_can_bitrate_set()
450 if (*endptr != '\0') { in cmd_can_bitrate_set()
452 return -EINVAL; in cmd_can_bitrate_set()
455 if (argc >= 4) { in cmd_can_bitrate_set()
457 if (*endptr != '\0') { in cmd_can_bitrate_set()
459 return -EINVAL; in cmd_can_bitrate_set()
463 if (err < 0) { in cmd_can_bitrate_set()
470 if (argc >= 5) { in cmd_can_bitrate_set()
471 /* Overwrite calculated default SJW with user-provided value */ in cmd_can_bitrate_set()
473 if (*endptr != '\0') { in cmd_can_bitrate_set()
475 return -EINVAL; in cmd_can_bitrate_set()
480 "(+/- %d.%d%%), sjw %d", in cmd_can_bitrate_set()
489 if (err != 0) { in cmd_can_bitrate_set()
497 if (err != 0) { in cmd_can_bitrate_set()
515 if (!can_device_check(dev)) { in cmd_can_dbitrate_set()
517 return -ENODEV; in cmd_can_dbitrate_set()
521 if (*endptr != '\0') { in cmd_can_dbitrate_set()
523 return -EINVAL; in cmd_can_dbitrate_set()
526 if (argc >= 4) { in cmd_can_dbitrate_set()
528 if (*endptr != '\0') { in cmd_can_dbitrate_set()
530 return -EINVAL; in cmd_can_dbitrate_set()
534 if (err < 0) { in cmd_can_dbitrate_set()
541 if (argc >= 5) { in cmd_can_dbitrate_set()
542 /* Overwrite calculated default SJW with user-provided value */ in cmd_can_dbitrate_set()
544 if (*endptr != '\0') { in cmd_can_dbitrate_set()
546 return -EINVAL; in cmd_can_dbitrate_set()
551 "(+/- %d.%d%%), sjw %d", in cmd_can_dbitrate_set()
560 if (err != 0) { in cmd_can_dbitrate_set()
568 if (err != 0) { in cmd_can_dbitrate_set()
582 timing->sjw = (uint32_t)strtoul(argv[2], &endptr, 10); in can_shell_parse_timing()
583 if (*endptr != '\0') { in can_shell_parse_timing()
585 return -EINVAL; in can_shell_parse_timing()
588 timing->prop_seg = (uint32_t)strtoul(argv[3], &endptr, 10); in can_shell_parse_timing()
589 if (*endptr != '\0') { in can_shell_parse_timing()
591 return -EINVAL; in can_shell_parse_timing()
594 timing->phase_seg1 = (uint32_t)strtoul(argv[4], &endptr, 10); in can_shell_parse_timing()
595 if (*endptr != '\0') { in can_shell_parse_timing()
597 return -EINVAL; in can_shell_parse_timing()
600 timing->phase_seg2 = (uint32_t)strtoul(argv[5], &endptr, 10); in can_shell_parse_timing()
601 if (*endptr != '\0') { in can_shell_parse_timing()
603 return -EINVAL; in can_shell_parse_timing()
606 timing->prescaler = (uint32_t)strtoul(argv[6], &endptr, 10); in can_shell_parse_timing()
607 if (*endptr != '\0') { in can_shell_parse_timing()
609 return -EINVAL; in can_shell_parse_timing()
621 if (!can_device_check(dev)) { in cmd_can_timing_set()
623 return -ENODEV; in cmd_can_timing_set()
627 if (err < 0) { in cmd_can_timing_set()
636 if (err != 0) { in cmd_can_timing_set()
650 if (!can_device_check(dev)) { in cmd_can_dtiming_set()
652 return -ENODEV; in cmd_can_dtiming_set()
656 if (err < 0) { in cmd_can_dtiming_set()
665 if (err != 0) { in cmd_can_dtiming_set()
683 if (!can_device_check(dev)) { in cmd_can_mode_set()
685 return -ENODEV; in cmd_can_mode_set()
691 if (strcmp(argv[i], can_shell_mode_map[j].name) == 0) { in cmd_can_mode_set()
697 if (j == ARRAY_SIZE(can_shell_mode_map)) { in cmd_can_mode_set()
698 /* Symbolic name not found, use raw mode if hex number */ in cmd_can_mode_set()
700 if (*endptr == '\0') { in cmd_can_mode_set()
706 return -EINVAL; in cmd_can_mode_set()
713 if (err != 0) { in cmd_can_mode_set()
735 if (!can_device_check(dev)) { in cmd_can_send()
737 return -ENODEV; in cmd_can_send()
746 while (argidx < argc && strncmp(argv[argidx], "-", 1) == 0) { in cmd_can_send()
747 if (strcmp(argv[argidx], "--") == 0) { in cmd_can_send()
750 } else if (strcmp(argv[argidx], "-e") == 0) { in cmd_can_send()
754 } else if (strcmp(argv[argidx], "-r") == 0) { in cmd_can_send()
757 } else if (strcmp(argv[argidx], "-f") == 0) { in cmd_can_send()
760 } else if (strcmp(argv[argidx], "-b") == 0) { in cmd_can_send()
770 /* Parse CAN ID */ in cmd_can_send()
771 if (argidx >= argc) { in cmd_can_send()
772 shell_error(sh, "missing CAN ID parameter"); in cmd_can_send()
778 if (*endptr != '\0') { in cmd_can_send()
779 shell_error(sh, "failed to parse CAN ID"); in cmd_can_send()
780 return -EINVAL; in cmd_can_send()
783 if (val > id_mask) { in cmd_can_send()
784 shell_error(sh, "CAN ID 0x%0*x out of range", in cmd_can_send()
787 return -EINVAL; in cmd_can_send()
792 nbytes = argc - argidx; in cmd_can_send()
793 if (nbytes > ARRAY_SIZE(frame.data)) { in cmd_can_send()
795 return -EINVAL; in cmd_can_send()
803 if (*endptr != '\0') { in cmd_can_send()
805 return -EINVAL; in cmd_can_send()
808 if (val > 0xff) { in cmd_can_send()
810 return -EINVAL; in cmd_can_send()
817 if (err != 0) { in cmd_can_send()
823 shell_print(sh, "enqueuing CAN frame #%u with %s (%d-bit) CAN ID 0x%0*x, " in cmd_can_send()
824 "RTR %d, CAN FD %d, BRS %d, DLC %d", frame_no, in cmd_can_send()
834 if (err != 0) { in cmd_can_send()
835 shell_error(sh, "failed to enqueue CAN frame #%u (err %d)", frame_no, err); in cmd_can_send()
852 if (!can_device_check(dev)) { in cmd_can_filter_add()
854 return -ENODEV; in cmd_can_filter_add()
862 while (argidx < argc && strncmp(argv[argidx], "-", 1) == 0) { in cmd_can_filter_add()
863 if (strcmp(argv[argidx], "--") == 0) { in cmd_can_filter_add()
866 } else if (strcmp(argv[argidx], "-e") == 0) { in cmd_can_filter_add()
877 /* Parse CAN ID */ in cmd_can_filter_add()
878 if (argidx >= argc) { in cmd_can_filter_add()
879 shell_error(sh, "missing CAN ID parameter"); in cmd_can_filter_add()
885 if (*endptr != '\0') { in cmd_can_filter_add()
886 shell_error(sh, "failed to parse CAN ID"); in cmd_can_filter_add()
887 return -EINVAL; in cmd_can_filter_add()
890 if (val > id_mask) { in cmd_can_filter_add()
891 shell_error(sh, "CAN ID 0x%0*x out of range", in cmd_can_filter_add()
894 return -EINVAL; in cmd_can_filter_add()
899 if (argidx < argc) { in cmd_can_filter_add()
900 /* Parse CAN ID mask */ in cmd_can_filter_add()
902 if (*endptr != '\0') { in cmd_can_filter_add()
903 shell_error(sh, "failed to parse CAN ID mask"); in cmd_can_filter_add()
904 return -EINVAL; in cmd_can_filter_add()
907 if (val > id_mask) { in cmd_can_filter_add()
908 shell_error(sh, "CAN ID mask 0x%0*x out of range", in cmd_can_filter_add()
911 return -EINVAL; in cmd_can_filter_add()
921 if (err != 0) { in cmd_can_filter_add()
925 shell_print(sh, "adding filter with %s (%d-bit) CAN ID 0x%0*x, CAN ID mask 0x%0*x", in cmd_can_filter_add()
932 if (err < 0) { in cmd_can_filter_add()
948 if (!can_device_check(dev)) { in cmd_can_filter_remove()
950 return -ENODEV; in cmd_can_filter_remove()
955 if (*endptr != '\0') { in cmd_can_filter_remove()
957 return -EINVAL; in cmd_can_filter_remove()
974 if (!can_device_check(dev)) { in cmd_can_recover()
976 return -ENODEV; in cmd_can_recover()
979 if (argc >= 3) { in cmd_can_recover()
982 if (*endptr != '\0') { in cmd_can_recover()
984 return -EINVAL; in cmd_can_recover()
994 if (err != 0) { in cmd_can_recover()
995 shell_error(sh, "failed to recover CAN controller from bus-off (err %d)", err); in cmd_can_recover()
1006 entry->syntax = (dev != NULL) ? dev->name : NULL; in cmd_can_device_name()
1007 entry->handler = NULL; in cmd_can_device_name()
1008 entry->help = NULL; in cmd_can_device_name()
1009 entry->subcmd = NULL; in cmd_can_device_name()
1020 if (idx < ARRAY_SIZE(can_shell_mode_map)) { in cmd_can_mode()
1021 entry->syntax = can_shell_mode_map[idx].name; in cmd_can_mode()
1024 entry->syntax = NULL; in cmd_can_mode()
1027 entry->handler = NULL; in cmd_can_mode()
1028 entry->help = NULL; in cmd_can_mode()
1029 entry->subcmd = &dsub_can_mode; in cmd_can_mode()
1036 entry->syntax = (dev != NULL) ? dev->name : NULL; in cmd_can_device_name_mode()
1037 entry->handler = NULL; in cmd_can_device_name_mode()
1038 entry->help = NULL; in cmd_can_device_name_mode()
1039 entry->subcmd = &dsub_can_mode; in cmd_can_device_name_mode()
1047 "Usage: can filter add <device> [-e] <CAN ID> [CAN ID mask]\n"
1048 "-e use extended (29-bit) CAN ID/CAN ID mask\n",
1052 "Usage: can filter remove <device> <filter_id>",
1059 "Start CAN controller\n"
1060 "Usage: can start <device>",
1063 "Stop CAN controller\n"
1064 "Usage: can stop <device>",
1067 "Show CAN controller information\n"
1068 "Usage: can show <device>",
1071 "Set CAN controller bitrate (sample point and SJW optional)\n"
1072 "Usage: can bitrate <device> <bitrate> [sample point] [sjw]",
1076 "Set CAN controller data phase bitrate (sample point and SJW optional)\n"
1077 "Usage: can dbitrate <device> <data phase bitrate> [sample point] [sjw]",
1080 "Set CAN controller timing\n"
1081 "Usage: can timing <device> <sjw> <prop_seg> <phase_seg1> <phase_seg2> <prescaler>",
1085 "Set CAN controller data phase timing\n"
1086 "Usage: can dtiming <device> <sjw> <prop_seg> <phase_seg1> <phase_seg2> <prescaler>",
1089 "Set CAN controller mode\n"
1090 "Usage: can mode <device> <mode> [mode] [mode] [...]",
1093 "Enqueue a CAN frame for sending\n"
1094 "Usage: can send <device> [-e] [-r] [-f] [-b] <CAN ID> [data] [...]\n"
1095 "-e use extended (29-bit) CAN ID\n"
1096 "-r send Remote Transmission Request (RTR) frame\n"
1097 "-f use CAN FD frame format\n"
1098 "-b use CAN FD Bit Rate Switching (BRS)",
1101 "CAN rx filter commands\n"
1102 "Usage: can filter <add|remove> <device> ...",
1106 "Manually recover CAN controller from bus-off state\n"
1107 "Usage: can recover <device> [timeout ms]",
1112 SHELL_CMD_REGISTER(can, &sub_can_cmds, "CAN controller commands", NULL);