watchdog.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * (C) Copyright 2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Author: Igor Lisitsin <igor@emcraft.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. /*
  11. * Watchdog test
  12. *
  13. * The test verifies the watchdog timer operation.
  14. * On the first iteration, the test routine disables interrupts and
  15. * makes a 10-second delay. If the system does not reboot during this delay,
  16. * the watchdog timer is not operational and the test fails. If the system
  17. * reboots, on the second iteration the test routine reports a success.
  18. */
  19. #include <post.h>
  20. #if CONFIG_POST & CONFIG_SYS_POST_WATCHDOG
  21. #include <watchdog.h>
  22. int watchdog_post_test (int flags)
  23. {
  24. if (flags & POST_REBOOT) {
  25. /* Test passed */
  26. return 0;
  27. }
  28. else {
  29. /* 10-second delay */
  30. int ints = disable_interrupts ();
  31. ulong base = post_time_ms (0);
  32. while (post_time_ms (base) < 10000)
  33. ;
  34. if (ints)
  35. enable_interrupts ();
  36. /*
  37. * If we have reached this point, the watchdog timer
  38. * does not work
  39. */
  40. return -1;
  41. }
  42. }
  43. #endif /* CONFIG_POST & CONFIG_SYS_POST_WATCHDOG */