Skip to content

Commit 32f269a

Browse files
wyr-7xiaoxiang781216
authored andcommitted
nsh_syscmds: update rptun_ping to rpmsg_ping, add cmd_rpmsg.
To support rpmsg ioctl, add cmd_rpmsg function, and update rptun ping to rpmsg ping. depends on apache/nuttx#11618 Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
1 parent b43340b commit 32f269a

File tree

4 files changed

+81
-34
lines changed

4 files changed

+81
-34
lines changed

nshlib/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,11 @@ config NSH_DISABLE_ROUTE
569569
depends on FS_PROCFS && NET_ROUTE && !FS_PROCFS_EXCLUDE_NET && !FS_PROCFS_EXCLUDE_ROUTE
570570
default DEFAULT_SMALL
571571

572+
config NSH_DISABLE_RPMSG
573+
bool "Disable rpmsg"
574+
default DEFAULT_SMALL
575+
depends on RPMSG
576+
572577
config NSH_DISABLE_RPTUN
573578
bool "Disable rptun"
574579
default DEFAULT_SMALL

nshlib/nsh.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,10 @@ int cmd_switchboot(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
11411141
FAR char **argv);
11421142
#endif
11431143

1144+
#if defined(CONFIG_RPMSG) && !defined(CONFIG_NSH_DISABLE_RPMSG)
1145+
int cmd_rpmsg(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
1146+
#endif
1147+
11441148
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
11451149
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
11461150
#endif

nshlib/nsh_command.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ static const struct cmdmap_s g_cmdmap[] =
523523
#endif
524524
#endif
525525

526+
#if defined(CONFIG_RPMSG) && !defined(CONFIG_NSH_DISABLE_RPMSG)
527+
CMD_MAP("rpmsg", cmd_rpmsg, 2, 7,
528+
"<panic|dump|ping> <path|all>"
529+
" [value|times length ack sleep]"),
530+
#endif
531+
526532
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
527533
CMD_MAP("rptun", cmd_rptun, 2, 7,
528534
"<start|stop|reset|panic|dump|ping> <path|all>"

nshlib/nsh_syscmds.c

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -510,42 +510,42 @@ int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
510510
#endif
511511

512512
/****************************************************************************
513-
* Name: cmd_rptun
513+
* Name: cmd_rpmsg
514514
****************************************************************************/
515515

516-
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
517-
static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl,
516+
#if defined(CONFIG_RPMSG) && !defined(CONFIG_NSH_DISABLE_RPMSG)
517+
static int cmd_rpmsg_once(FAR struct nsh_vtbl_s *vtbl,
518518
FAR const char *path, FAR char **argv)
519519
{
520-
#ifdef CONFIG_RPTUN_PING
521-
struct rptun_ping_s ping;
520+
#ifdef CONFIG_RPMSG_PING
521+
struct rpmsg_ping_s ping;
522522
#endif
523523
unsigned long val = 0;
524524
int cmd;
525525
int fd;
526526

527527
if (strcmp(argv[1], "start") == 0)
528528
{
529-
cmd = RPTUNIOC_START;
529+
cmd = RPMSGIOC_START;
530530
}
531531
else if (strcmp(argv[1], "stop") == 0)
532532
{
533-
cmd = RPTUNIOC_STOP;
533+
cmd = RPMSGIOC_STOP;
534534
}
535535
else if (strcmp(argv[1], "reset") == 0)
536536
{
537537
val = atoi(argv[3]);
538-
cmd = RPTUNIOC_RESET;
538+
cmd = RPMSGIOC_RESET;
539539
}
540540
else if (strcmp(argv[1], "panic") == 0)
541541
{
542-
cmd = RPTUNIOC_PANIC;
542+
cmd = RPMSGIOC_PANIC;
543543
}
544544
else if (strcmp(argv[1], "dump") == 0)
545545
{
546-
cmd = RPTUNIOC_DUMP;
546+
cmd = RPMSGIOC_DUMP;
547547
}
548-
#ifdef CONFIG_RPTUN_PING
548+
#ifdef CONFIG_RPMSG_PING
549549
else if (strcmp(argv[1], "ping") == 0)
550550
{
551551
if (argv[3] == 0 || argv[4] == 0 ||
@@ -560,7 +560,7 @@ static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl,
560560
ping.ack = atoi(argv[5]);
561561
ping.sleep = atoi(argv[6]);
562562

563-
cmd = RPTUNIOC_PING;
563+
cmd = RPMSGIOC_PING;
564564
val = (unsigned long)&ping;
565565
}
566566
#endif
@@ -584,7 +584,7 @@ static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl,
584584
return cmd;
585585
}
586586

587-
static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
587+
static int cmd_rpmsg_recursive(FAR struct nsh_vtbl_s *vtbl,
588588
FAR const char *dirpath,
589589
FAR struct dirent *entryp,
590590
FAR void *pvarg)
@@ -600,36 +600,68 @@ static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
600600
path = nsh_getdirpath(vtbl, dirpath, entryp->d_name);
601601
if (path)
602602
{
603-
ret = cmd_rptun_once(vtbl, path, pvarg);
603+
ret = cmd_rpmsg_once(vtbl, path, pvarg);
604604
free(path);
605605
}
606606

607607
return ret;
608608
}
609609

610-
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
610+
static int cmd_rpmsg_help(FAR struct nsh_vtbl_s *vtbl, int argc,
611+
FAR char **argv)
612+
{
613+
nsh_output(vtbl, "%s <panic|dump> <path>\n", argv[0]);
614+
nsh_output(vtbl, "%s ping <path> <times> <length> <ack> "
615+
"<period(ms)>\n\n", argv[0]);
616+
nsh_output(vtbl, "<times> Times of rptun ping.\n");
617+
nsh_output(vtbl, "<length> The length of each ping packet.\n");
618+
nsh_output(vtbl, "<ack> Whether the peer acknowlege or "
619+
"check data.\n");
620+
nsh_output(vtbl, " 0 - No acknowledge and check.\n");
621+
nsh_output(vtbl, " 1 - Acknowledge, no data check.\n");
622+
nsh_output(vtbl, " 2 - Acknowledge and data check.\n");
623+
nsh_output(vtbl, "<period(ms)> ping period (ms) \n");
624+
nsh_output(vtbl, "<path> Rpmsg device path.\n\n");
625+
return OK;
626+
}
627+
628+
int cmd_rpmsg(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
611629
{
612630
if (argc >= 2 && strcmp(argv[1], "-h") == 0)
613631
{
614-
nsh_output(vtbl, "usage:\n");
615-
nsh_output(vtbl, " rptun <start|stop|reset|panic|dump> <path> "
616-
"<value>\n");
617-
nsh_output(vtbl, " rptun <reset> <path> <resetvalue>\n");
618-
#ifdef CONFIG_RPTUN_PING
619-
nsh_output(vtbl, " rptun ping <path> <times> <length> <ack> "
620-
"<period(ms)>\n\n");
621-
nsh_output(vtbl, " <path> Rptun device path.\n");
622-
nsh_output(vtbl, " <times> Times of rptun ping.\n");
623-
nsh_output(vtbl, " <length> The length of each ping packet.\n");
624-
nsh_output(vtbl, " <ack> Whether the peer acknowlege or "
625-
"check data.\n");
626-
nsh_output(vtbl, " 0 - No acknowledge and check.\n");
627-
nsh_output(vtbl, " 1 - Acknowledge, no data check.\n");
628-
nsh_output(vtbl, " 2 - Acknowledge and data check.\n");
629-
nsh_output(vtbl, " <period(ms)> ping period (ms) \n\n");
632+
nsh_output(vtbl, "usage:\n\n");
633+
return cmd_rpmsg_help(vtbl, argc, argv);
634+
}
635+
636+
if (argc < 3)
637+
{
638+
nsh_output(vtbl, g_fmtargrequired, argv[0]);
639+
return ERROR;
640+
}
641+
642+
if (strcmp(argv[2], "all") == 0)
643+
{
644+
return nsh_foreach_direntry(vtbl, "rpmsg", "/dev/rpmsg",
645+
cmd_rpmsg_recursive, argv);
646+
}
647+
648+
return cmd_rpmsg_once(vtbl, argv[2], argv);
649+
}
630650
#endif
631651

632-
return OK;
652+
/****************************************************************************
653+
* Name: cmd_rptun
654+
****************************************************************************/
655+
656+
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
657+
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
658+
{
659+
if (argc >= 2 && strcmp(argv[1], "-h") == 0)
660+
{
661+
nsh_output(vtbl, "usage:\n\n");
662+
nsh_output(vtbl, "rptun <start|stop> <path>\n");
663+
nsh_output(vtbl, "rptun <reset> <path> <resetvalue>\n");
664+
return cmd_rpmsg_help(vtbl, argc, argv);
633665
}
634666

635667
if (argc < 3)
@@ -641,10 +673,10 @@ int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
641673
if (strcmp(argv[2], "all") == 0)
642674
{
643675
return nsh_foreach_direntry(vtbl, "rptun", "/dev/rptun",
644-
cmd_rptun_recursive, argv);
676+
cmd_rpmsg_recursive, argv);
645677
}
646678

647-
return cmd_rptun_once(vtbl, argv[2], argv);
679+
return cmd_rpmsg_once(vtbl, argv[2], argv);
648680
}
649681
#endif
650682

0 commit comments

Comments
 (0)