You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/09/27 21:18:26 UTC
[incubator-nuttx-apps] 01/03: Added timer device path as a CLI
option
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 32f193a7e27658a27e4f0cd6071b936ab75516a3
Author: saramonteiro <sa...@gmail.com>
AuthorDate: Wed Sep 16 17:19:07 2020 -0300
Added timer device path as a CLI option
---
examples/timer/timer_main.c | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/examples/timer/timer_main.c b/examples/timer/timer_main.c
index a60ca9b..ee4a23e 100644
--- a/examples/timer/timer_main.c
+++ b/examples/timer/timer_main.c
@@ -45,13 +45,15 @@
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
-
+#include <string.h>
#include <nuttx/timers/timer.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+#define DEVNAME_SIZE 11
+
#ifndef CONFIG_EXAMPLES_TIMER_DEVNAME
# define CONFIG_EXAMPLES_TIMER_DEVNAME "/dev/timer0"
#endif
@@ -73,6 +75,10 @@
#endif
/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
* Private Functions
****************************************************************************/
@@ -142,16 +148,37 @@ int main(int argc, FAR char *argv[])
int ret;
int fd;
int i;
+ int opt;
+ char devname[DEVNAME_SIZE];
+ strcpy(devname, CONFIG_EXAMPLES_TIMER_DEVNAME);
+
+ while ((opt = getopt(argc, argv, ":d:")) != -1)
+ {
+ switch (opt)
+ {
+ case 'd':
+ strcpy(devname, optarg);
+ break;
+ case ':':
+ fprintf(stderr, "ERROR: Option needs a value\n");
+ exit(EXIT_FAILURE);
+ default: /* '?' */
+ fprintf(stderr, "Usage: %s [-d /dev/timerx]\n",
+ argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
/* Open the timer device */
- printf("Open %s\n", CONFIG_EXAMPLES_TIMER_DEVNAME);
+ printf("Open %s\n", devname);
- fd = open(CONFIG_EXAMPLES_TIMER_DEVNAME, O_RDONLY);
+ fd = open(devname, O_RDONLY);
if (fd < 0)
{
fprintf(stderr, "ERROR: Failed to open %s: %d\n",
- CONFIG_EXAMPLES_TIMER_DEVNAME, errno);
+ devname, errno);
return EXIT_FAILURE;
}