1
2
3
4
5
6
7
8
9
10
11#include <common.h>
12#include <command.h>
13
14static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
15{
16 ulong start = get_timer(0);
17 ulong delay;
18
19 if (argc != 2)
20 return CMD_RET_USAGE;
21
22 delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
23
24 while (get_timer(start) < delay) {
25 if (ctrlc())
26 return (-1);
27
28 udelay(100);
29 }
30
31 return 0;
32}
33
34U_BOOT_CMD(
35 sleep , 2, 1, do_sleep,
36 "delay execution for some time",
37 "N\n"
38 " - delay execution for N seconds (N is _decimal_ !!!)"
39);
40
41#ifdef CONFIG_CMD_TIMER
42static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
43{
44 static ulong start;
45
46 if (argc != 2)
47 return CMD_RET_USAGE;
48
49 if (!strcmp(argv[1], "start"))
50 start = get_timer(0);
51
52 if (!strcmp(argv[1], "get")) {
53 ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ;
54 printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000));
55 }
56
57 return 0;
58}
59
60U_BOOT_CMD(
61 timer, 2, 1, do_timer,
62 "access the system timer",
63 "start - Reset the timer reference.\n"
64 "timer get - Print the time since 'start'."
65);
66#endif
67