Пример #1
0
void board_initialize(void)
{
#if (defined(CONFIG_SAM34_WDT) && !defined(CONFIG_WDT_DISABLE_ON_RESET))
  /* Configure watchdog timer and enable kicker kernel thread. */

  DEBUGASSERT(up_wdginitialize() >= 0);
#endif

#ifndef CONFIG_ARCH_LEDS
  /* Initialize user led */

  sam_ledinit();
#endif

#ifdef CONFIG_TIMER
  /* Registers the timers and starts any async processes (which may include the scheduler) */

  sam_timerinitialize();
#endif

}
Пример #2
0
int wdog_main(int argc, char *argv[])
{
  struct wdog_example_s wdog;
#ifdef CONFIG_DEBUG_WATCHDOG
  struct watchdog_status_s status;
#endif
  long elapsed;
  int fd;
  int ret;

  /* Parse the command line */

  parse_args(&wdog, argc, argv);

  /* Initialization of the WATCHDOG hardware is performed by logic external to
   * this test.
   */

  ret = up_wdginitialize();
  if (ret != OK)
    {
      message("wdog_main: up_wdginitialize failed: %d\n", ret);
      goto errout;
    }

  /* Open the watchdog device for reading */

  fd = open(CONFIG_EXAMPLES_WATCHDOG_DEVPATH, O_RDONLY);
  if (fd < 0)
    {
      message("wdog_main: open %s failed: %d\n",
              CONFIG_EXAMPLES_WATCHDOG_DEVPATH, errno);
      goto errout;
    }

  /* Set the watchdog timeout */

  ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)wdog.timeout);
  if (ret < 0)
    {
      message("wdog_main: ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno);
      goto errout_with_dev;
    }

  /* Then start the watchdog timer. */

  ret = ioctl(fd, WDIOC_START, 0);
  if (ret < 0)
    {
      message("wdog_main: ioctl(WDIOC_START) failed: %d\n", errno);
      goto errout_with_dev;
    }

  /* Then ping */

  for (elapsed = 0; elapsed < wdog.pingtime; elapsed += wdog.pingdelay)
    {
      /* Sleep for the requested amount of time */

      usleep(wdog.pingdelay * 1000);

      /* Show watchdog status.  Only if debug is enabled because this
       * could interfere with the timer.
       */

#ifdef CONFIG_DEBUG_WATCHDOG
     ret = ioctl(fd, WDIOC_GETSTATUS, (unsigned long)&status);
     if (ret < 0)
       {
          message("wdog_main: ioctl(WDIOC_GETSTATUS) failed: %d\n", errno);
          goto errout_with_dev;
        }
      message("wdog_main: flags=%08x timeout=%d timeleft=%d\n",
              status.flags, status.timeout, status.timeleft);
#endif

      /* Then ping */

     ret = ioctl(fd, WDIOC_KEEPALIVE, 0);
     if (ret < 0)
       {
          message("wdog_main: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno);
          goto errout_with_dev;
        }

      message("  ping elapsed=%ld\n", elapsed);
      msgflush();
    }

  /* Then stop pinging */

  for (; ; elapsed += wdog.pingdelay)
    {
      /* Sleep for the requested amount of time */

      usleep(wdog.pingdelay * 1000);

      /* Show watchdog status.  Only if debug is enabled because this
       * could interfere with the timer.
       */

#ifdef CONFIG_DEBUG_WATCHDOG
     ret = ioctl(fd, WDIOC_GETSTATUS, (unsigned long)&status);
     if (ret < 0)
       {
          message("wdog_main: ioctl(WDIOC_GETSTATUS) failed: %d\n", errno);
          goto errout_with_dev;
        }
      message("wdog_main: flags=%08x timeout=%d timeleft=%d\n",
              status.flags, status.timeout, status.timeleft);
#endif

      message("  NO ping elapsed=%ld\n", elapsed);
      msgflush();
    }

  /* We should not get here */

  ret = ioctl(fd, WDIOC_STOP, 0);
  if (ret < 0)
    {
      message("wdog_main: ioctl(WDIOC_STOP) failed: %d\n", errno);
      goto errout_with_dev;
    }

 close(fd);
 msgflush();
 return OK;

errout_with_dev:
  close(fd);
errout:
  msgflush();
  return ERROR;
}