Skip to content

Commit

Permalink
nsh_syscmds: update rptun_ping to rpmsg_ping, add cmd_rpmsg.
Browse files Browse the repository at this point in the history
To support rpmsg ioctl, add cmd_rpmsg function, and update rptun ping to rpmsg ping.
depends on apache/nuttx#11618

Signed-off-by: wangyongrong <[email protected]>
  • Loading branch information
wyr-7 committed Jan 30, 2024
1 parent c699b05 commit ceafad1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 34 deletions.
5 changes: 5 additions & 0 deletions nshlib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ config NSH_DISABLE_ROUTE
depends on FS_PROCFS && NET_ROUTE && !FS_PROCFS_EXCLUDE_NET && !FS_PROCFS_EXCLUDE_ROUTE
default DEFAULT_SMALL

config NSH_DISABLE_RPMSG
bool "Disable rpmsg"
default DEFAULT_SMALL
depends on RPMSG

config NSH_DISABLE_RPTUN
bool "Disable rptun"
default DEFAULT_SMALL
Expand Down
4 changes: 4 additions & 0 deletions nshlib/nsh.h
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,10 @@ int cmd_switchboot(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
FAR char **argv);
#endif

#if defined(CONFIG_RPMSG) && !defined(CONFIG_NSH_DISABLE_RPMSG)
int cmd_rpmsg(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
#endif

#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
#endif
Expand Down
6 changes: 6 additions & 0 deletions nshlib/nsh_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,12 @@ static const struct cmdmap_s g_cmdmap[] =
#endif
#endif

#if defined(CONFIG_RPMSG) && !defined(CONFIG_NSH_DISABLE_RPMSG)
CMD_MAP("rpmsg", cmd_rpmsg, 2, 7,
"<panic|dump|ping> <path|all>"
" [value|times length ack sleep]"),
#endif

#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
CMD_MAP("rptun", cmd_rptun, 2, 7,
"<start|stop|reset|panic|dump|ping> <path|all>"
Expand Down
100 changes: 66 additions & 34 deletions nshlib/nsh_syscmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,42 +510,42 @@ int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
#endif

/****************************************************************************
* Name: cmd_rptun
* Name: cmd_rpmsg
****************************************************************************/

#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl,
#if defined(CONFIG_RPMSG) && !defined(CONFIG_NSH_DISABLE_RPMSG)
static int cmd_rpmsg_once(FAR struct nsh_vtbl_s *vtbl,
FAR const char *path, FAR char **argv)
{
#ifdef CONFIG_RPTUN_PING
struct rptun_ping_s ping;
#ifdef CONFIG_RPMSG_PING
struct rpmsg_ping_s ping;
#endif
unsigned long val = 0;
int cmd;
int fd;

if (strcmp(argv[1], "start") == 0)
{
cmd = RPTUNIOC_START;
cmd = RPMSGIOC_START;

Check failure on line 529 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_START' undeclared (first use in this function); did you mean 'RPTUNIOC_START'?

Check failure on line 529 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_START' undeclared (first use in this function); did you mean 'RPTUNIOC_START'?

Check failure on line 529 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_START' undeclared (first use in this function); did you mean 'RPTUNIOC_START'?

Check failure on line 529 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_START' undeclared (first use in this function); did you mean 'RPTUNIOC_START'?
}
else if (strcmp(argv[1], "stop") == 0)
{
cmd = RPTUNIOC_STOP;
cmd = RPMSGIOC_STOP;

Check failure on line 533 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_STOP' undeclared (first use in this function); did you mean 'RPTUNIOC_STOP'?

Check failure on line 533 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_STOP' undeclared (first use in this function); did you mean 'RPTUNIOC_STOP'?

Check failure on line 533 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_STOP' undeclared (first use in this function); did you mean 'RPTUNIOC_STOP'?

Check failure on line 533 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_STOP' undeclared (first use in this function); did you mean 'RPTUNIOC_STOP'?
}
else if (strcmp(argv[1], "reset") == 0)
{
val = atoi(argv[3]);
cmd = RPTUNIOC_RESET;
cmd = RPMSGIOC_RESET;

Check failure on line 538 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_RESET' undeclared (first use in this function); did you mean 'RPTUNIOC_RESET'?

Check failure on line 538 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_RESET' undeclared (first use in this function); did you mean 'RPTUNIOC_RESET'?

Check failure on line 538 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_RESET' undeclared (first use in this function); did you mean 'RPTUNIOC_RESET'?

Check failure on line 538 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_RESET' undeclared (first use in this function); did you mean 'RPTUNIOC_RESET'?
}
else if (strcmp(argv[1], "panic") == 0)
{
cmd = RPTUNIOC_PANIC;
cmd = RPMSGIOC_PANIC;

Check failure on line 542 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_PANIC' undeclared (first use in this function); did you mean 'RPTUNIOC_PANIC'?

Check failure on line 542 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_PANIC' undeclared (first use in this function); did you mean 'RPTUNIOC_PANIC'?

Check failure on line 542 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_PANIC' undeclared (first use in this function); did you mean 'RPTUNIOC_PANIC'?

Check failure on line 542 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_PANIC' undeclared (first use in this function); did you mean 'RPTUNIOC_PANIC'?
}
else if (strcmp(argv[1], "dump") == 0)
{
cmd = RPTUNIOC_DUMP;
cmd = RPMSGIOC_DUMP;

Check failure on line 546 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_DUMP' undeclared (first use in this function); did you mean 'RPTUNIOC_DUMP'?

Check failure on line 546 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (sim-02)

'RPMSGIOC_DUMP' undeclared (first use in this function); did you mean 'RPTUNIOC_DUMP'?

Check failure on line 546 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_DUMP' undeclared (first use in this function); did you mean 'RPTUNIOC_DUMP'?

Check failure on line 546 in nshlib/nsh_syscmds.c

View workflow job for this annotation

GitHub Actions / Linux (arm-05)

'RPMSGIOC_DUMP' undeclared (first use in this function); did you mean 'RPTUNIOC_DUMP'?
}
#ifdef CONFIG_RPTUN_PING
#ifdef CONFIG_RPMSG_PING
else if (strcmp(argv[1], "ping") == 0)
{
if (argv[3] == 0 || argv[4] == 0 ||
Expand All @@ -560,7 +560,7 @@ static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl,
ping.ack = atoi(argv[5]);
ping.sleep = atoi(argv[6]);

cmd = RPTUNIOC_PING;
cmd = RPMSGIOC_PING;
val = (unsigned long)&ping;
}
#endif
Expand All @@ -584,7 +584,7 @@ static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl,
return cmd;
}

static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
static int cmd_rpmsg_recursive(FAR struct nsh_vtbl_s *vtbl,
FAR const char *dirpath,
FAR struct dirent *entryp,
FAR void *pvarg)
Expand All @@ -600,36 +600,68 @@ static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
path = nsh_getdirpath(vtbl, dirpath, entryp->d_name);
if (path)
{
ret = cmd_rptun_once(vtbl, path, pvarg);
ret = cmd_rpmsg_once(vtbl, path, pvarg);
free(path);
}

return ret;
}

int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
static int cmd_rpmsg_help(FAR struct nsh_vtbl_s *vtbl, int argc,
FAR char **argv)
{
nsh_output(vtbl, "%s <panic|dump> <path>\n", argv[0]);
nsh_output(vtbl, "%s ping <path> <times> <length> <ack> "
"<period(ms)>\n\n", argv[0]);
nsh_output(vtbl, "<times> Times of rptun ping.\n");
nsh_output(vtbl, "<length> The length of each ping packet.\n");
nsh_output(vtbl, "<ack> Whether the peer acknowlege or "
"check data.\n");
nsh_output(vtbl, " 0 - No acknowledge and check.\n");
nsh_output(vtbl, " 1 - Acknowledge, no data check.\n");
nsh_output(vtbl, " 2 - Acknowledge and data check.\n");
nsh_output(vtbl, "<period(ms)> ping period (ms) \n");
nsh_output(vtbl, "<path> Rpmsg device path.\n\n");
return OK;
}

int cmd_rpmsg(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
if (argc >= 2 && strcmp(argv[1], "-h") == 0)
{
nsh_output(vtbl, "usage:\n");
nsh_output(vtbl, " rptun <start|stop|reset|panic|dump> <path> "
"<value>\n");
nsh_output(vtbl, " rptun <reset> <path> <resetvalue>\n");
#ifdef CONFIG_RPTUN_PING
nsh_output(vtbl, " rptun ping <path> <times> <length> <ack> "
"<period(ms)>\n\n");
nsh_output(vtbl, " <path> Rptun device path.\n");
nsh_output(vtbl, " <times> Times of rptun ping.\n");
nsh_output(vtbl, " <length> The length of each ping packet.\n");
nsh_output(vtbl, " <ack> Whether the peer acknowlege or "
"check data.\n");
nsh_output(vtbl, " 0 - No acknowledge and check.\n");
nsh_output(vtbl, " 1 - Acknowledge, no data check.\n");
nsh_output(vtbl, " 2 - Acknowledge and data check.\n");
nsh_output(vtbl, " <period(ms)> ping period (ms) \n\n");
nsh_output(vtbl, "usage:\n\n");
return cmd_rpmsg_help(vtbl, argc, argv);
}

if (argc < 3)
{
nsh_output(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}

if (strcmp(argv[2], "all") == 0)
{
return nsh_foreach_direntry(vtbl, "rpmsg", "/dev/rpmsg",
cmd_rpmsg_recursive, argv);
}

return cmd_rpmsg_once(vtbl, argv[2], argv);
}
#endif

return OK;
/****************************************************************************
* Name: cmd_rptun
****************************************************************************/

#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
if (argc >= 2 && strcmp(argv[1], "-h") == 0)
{
nsh_output(vtbl, "usage:\n\n");
nsh_output(vtbl, "rptun <start|stop> <path>\n");
nsh_output(vtbl, "rptun <reset> <path> <resetvalue>\n");
return cmd_rpmsg_help(vtbl, argc, argv);
}

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

return cmd_rptun_once(vtbl, argv[2], argv);
return cmd_rpmsg_once(vtbl, argv[2], argv);
}
#endif

Expand Down

0 comments on commit ceafad1

Please sign in to comment.