int up_wdginitialize(void) { #if (defined(CONFIG_SAM34_WDT) && !defined(CONFIG_WDT_DISABLE_ON_RESET)) int fd; int ret; /* Initialize tha register the watchdog timer device */ wdgvdbg("Initializing Watchdog driver...\n"); sam_wdtinitialize(CONFIG_WATCHDOG_DEVPATH); /* Open the watchdog device */ wdgvdbg("Opening.\n"); fd = open(CONFIG_WATCHDOG_DEVPATH, O_RDONLY); if (fd < 0) { wdgdbg("open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, errno); goto errout; } /* Set the watchdog timeout */ wdgvdbg("Timeout = %d.\n", CONFIG_WDT_TIMEOUT); ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)CONFIG_WDT_TIMEOUT); if (ret < 0) { wdgdbg("ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno); goto errout_with_dev; } /* Set the watchdog minimum time */ wdgvdbg("MinTime = %d.\n", CONFIG_WDT_MINTIME); ret = ioctl(fd, WDIOC_MINTIME, (unsigned long)CONFIG_WDT_MINTIME); if (ret < 0) { wdgdbg("ioctl(WDIOC_MINTIME) failed: %d\n", errno); goto errout_with_dev; } /* Start Kicker task */ #if defined(CONFIG_WDT_THREAD) sched_lock(); int taskid = KERNEL_THREAD(CONFIG_WDT_THREAD_NAME, CONFIG_WDT_THREAD_PRIORITY, CONFIG_WDT_THREAD_STACKSIZE, (main_t)wdog_daemon, (FAR char * const *)NULL); ASSERT(taskid > 0); sched_unlock(); #endif return OK; errout_with_dev: close(fd); errout: return ERROR; #else return -ENODEV; #endif }
int sam_watchdog_initialize(void) { #if (defined(CONFIG_SAM34_WDT) && !defined(CONFIG_WDT_DISABLE_ON_RESET)) FAR struct file filestruct; int ret; /* Initialize tha register the watchdog timer device */ wdinfo("Initializing Watchdog driver...\n"); sam_wdtinitialize(CONFIG_WATCHDOG_DEVPATH); /* Open the watchdog device */ wdinfo("Opening.\n"); ret = file_open(&filestruct, CONFIG_WATCHDOG_DEVPATH, O_RDONLY); if (ret < 0) { wderr("ERROR: open %s failed: %d\n", CONFIG_WATCHDOG_DEVPATH, ret); goto errout; } /* Set the watchdog timeout */ wdinfo("Timeout = %d.\n", CONFIG_WDT_TIMEOUT); ret = file_ioctl(&filestruct, WDIOC_SETTIMEOUT, (unsigned long)CONFIG_WDT_TIMEOUT); if (ret < 0) { wderr("ERROR: ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno); goto errout_with_dev; } /* Set the watchdog minimum time */ wdinfo("MinTime = %d.\n", CONFIG_WDT_MINTIME); ret = file_ioctl(&filestruct, WDIOC_MINTIME, (unsigned long)CONFIG_WDT_MINTIME); if (ret < 0) { wderr("ERROR: ioctl(WDIOC_MINTIME) failed: %d\n", errno); goto errout_with_dev; } /* Start Kicker task */ #if defined(CONFIG_WDT_THREAD) sched_lock(); int taskid = kthread_create(CONFIG_WDT_THREAD_NAME, CONFIG_WDT_THREAD_PRIORITY, CONFIG_WDT_THREAD_STACKSIZE, (main_t)wdog_daemon, (FAR char * const *)NULL); DEBUGASSERT(taskid > 0); UNUSED(taskid); sched_unlock(); #endif return OK; errout_with_dev: file_close(&filestruct); errout: return ret; #else return -ENODEV; #endif }