mkiiskila closed pull request #1510: shell; add ls_dev command to list OS 
devices.
URL: https://github.com/apache/mynewt-core/pull/1510
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/kernel/os/include/os/os_dev.h b/kernel/os/include/os/os_dev.h
index c05f6f251f..1dc8f27cea 100644
--- a/kernel/os/include/os/os_dev.h
+++ b/kernel/os/include/os/os_dev.h
@@ -253,6 +253,14 @@ int os_dev_close(struct os_dev *dev);
  */
 void os_dev_reset(void);
 
+/**
+ * Walk through all devices, calling callback for every device.
+ *
+ * @param walk_func Function to call
+ * @aparm arg       Argument to pass to walk_func
+ */
+void os_dev_walk(int (*walk_func)(struct os_dev *, void *), void *arg);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/kernel/os/src/os_dev.c b/kernel/os/src/os_dev.c
index 9c10ed160f..1c8db39ad2 100644
--- a/kernel/os/src/os_dev.c
+++ b/kernel/os/src/os_dev.c
@@ -320,3 +320,15 @@ os_dev_reset(void)
     STAILQ_INIT(&g_os_dev_list);
 }
 
+void
+os_dev_walk(int (*walk_func)(struct os_dev *, void *), void *arg)
+{
+    struct os_dev *dev;
+
+    STAILQ_FOREACH(dev, &g_os_dev_list, od_next) {
+        if (walk_func(dev, arg)) {
+            break;
+        }
+    }
+}
+
diff --git a/sys/shell/src/shell_os.c b/sys/shell/src/shell_os.c
index 08a5fde23e..3c325f8e00 100644
--- a/sys/shell/src/shell_os.c
+++ b/sys/shell/src/shell_os.c
@@ -174,6 +174,22 @@ shell_os_reset_cmd(int argc, char **argv)
     return 0;
 }
 
+static int
+shell_os_ls_dev(struct os_dev *dev, void *arg)
+{
+    console_printf("%4d %3x %s\n",
+                   dev->od_open_ref, dev->od_flags, dev->od_name);
+    return 0;
+}
+
+int
+shell_os_ls_dev_cmd(int argc, char **argv)
+{
+    console_printf("%4s %3s %s\n", "ref", "flg", "name");
+    os_dev_walk(shell_os_ls_dev, NULL);
+    return 0;
+}
+
 #if MYNEWT_VAL(SHELL_CMD_HELP)
 static const struct shell_param tasks_params[] = {
     {"", "task name"},
@@ -220,6 +236,10 @@ static const struct shell_cmd_help reset_help = {
     .usage = NULL,
     .params = reset_params,
 };
+
+static const struct shell_cmd_help ls_dev_help = {
+    .summary = "list OS devices"
+};
 #endif
 
 static const struct shell_cmd os_commands[] = {
@@ -249,6 +269,13 @@ static const struct shell_cmd os_commands[] = {
         .sc_cmd_func = shell_os_reset_cmd,
 #if MYNEWT_VAL(SHELL_CMD_HELP)
         .help = &reset_help,
+#endif
+    },
+    {
+        .sc_cmd = "lsdev",
+        .sc_cmd_func = shell_os_ls_dev_cmd,
+#if MYNEWT_VAL(SHELL_CMD_HELP)
+        .help = &ls_dev_help,
 #endif
     },
     { NULL, NULL, NULL },


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to