From 2279eeb0a7b689ccab17216b9aceea8d353b9a53 Mon Sep 17 00:00:00 2001 From: saramonteiro Date: Mon, 26 Oct 2020 09:49:20 -0300 Subject: [PATCH] Examples/WDT: Added argument to select devname --- examples/watchdog/watchdog_main.c | 59 +++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/examples/watchdog/watchdog_main.c b/examples/watchdog/watchdog_main.c index 312f6072a..37e989346 100644 --- a/examples/watchdog/watchdog_main.c +++ b/examples/watchdog/watchdog_main.c @@ -53,6 +53,12 @@ #include "watchdog.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define DEVNAME_SIZE 16 + /**************************************************************************** * Private Types ****************************************************************************/ @@ -62,6 +68,7 @@ struct wdog_example_s uint32_t pingtime; uint32_t pingdelay; uint32_t timeout; + char devname[DEVNAME_SIZE]; }; /**************************************************************************** @@ -74,17 +81,21 @@ struct wdog_example_s static void wdog_help(void) { - printf("Usage: wdog [-h] [-d ] [-t ]\n"); - printf("\nInitialize the watchdog to the . Start the watchdog\n"); - printf("timer. Ping for the watchdog for seconds, then let it expire.\n"); + printf("Usage: wdog [-h] [-d ]\ + [-t ]\n"); + printf("\nInitialize the watchdog to the . Start the watchdog\n"); + printf("timer. Ping for the watchdog for seconds\n"); + printf("then let it expire.\n"); printf("\nOptions include:\n"); - printf(" [-d ] = Selects the time in milliseconds. Default: %d\n", - CONFIG_EXAMPLES_WATCHDOG_PINGDELAY); - printf(" [-p ] = Selects the time in milliseconds.\n"); + printf("Default: %d\n", CONFIG_EXAMPLES_WATCHDOG_PINGTIME); + printf(" [-i ] = Selects the watchdog timer instance.\n"); + printf("Default: %s\n", CONFIG_EXAMPLES_WATCHDOG_DEVPATH); + printf(" [-p pingtime = CONFIG_EXAMPLES_WATCHDOG_PINGTIME; wdog->pingdelay = CONFIG_EXAMPLES_WATCHDOG_PINGDELAY; wdog->timeout = CONFIG_EXAMPLES_WATCHDOG_TIMEOUT; + strcpy(wdog->devname, CONFIG_EXAMPLES_WATCHDOG_DEVPATH); for (index = 1; index < argc; ) { @@ -160,6 +174,12 @@ static void parse_args(FAR struct wdog_example_s *wdog, int argc, FAR char **arg index += nargs; break; + case 'i': + nargs = arg_string(&argv[index], &string); + strcpy(wdog->devname, string); + index += nargs; + break; + case 'p': nargs = arg_decimal(&argv[index], &value); if (value < 1 || value > INT_MAX) @@ -220,11 +240,11 @@ int main(int argc, FAR char *argv[]) /* Open the watchdog device for reading */ - fd = open(CONFIG_EXAMPLES_WATCHDOG_DEVPATH, O_RDONLY); + fd = open(wdog.devname, O_RDONLY); if (fd < 0) { printf("wdog_main: open %s failed: %d\n", - CONFIG_EXAMPLES_WATCHDOG_DEVPATH, errno); + wdog.devname, errno); goto errout; } @@ -260,8 +280,8 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_DEBUG_WATCHDOG ret = ioctl(fd, WDIOC_GETSTATUS, (unsigned long)&status); - if (ret < 0) - { + if (ret < 0) + { printf("wdog_main: ioctl(WDIOC_GETSTATUS) failed: %d\n", errno); goto errout_with_dev; } @@ -273,8 +293,8 @@ int main(int argc, FAR char *argv[]) /* Then ping */ ret = ioctl(fd, WDIOC_KEEPALIVE, 0); - if (ret < 0) - { + if (ret < 0) + { printf("wdog_main: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno); goto errout_with_dev; } @@ -297,11 +317,12 @@ int main(int argc, FAR char *argv[]) #ifdef CONFIG_DEBUG_WATCHDOG ret = ioctl(fd, WDIOC_GETSTATUS, (unsigned long)&status); - if (ret < 0) - { + if (ret < 0) + { printf("wdog_main: ioctl(WDIOC_GETSTATUS) failed: %d\n", errno); goto errout_with_dev; } + printf("wdog_main: flags=%08x timeout=%d timeleft=%d\n", status.flags, status.timeout, status.timeleft); #endif