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