]>
Commit | Line | Data |
---|---|---|
3863585b WD |
1 | /* |
2 | * (C) Copyright 2001 | |
3 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
3863585b WD |
6 | */ |
7 | ||
8 | /* | |
9 | * Misc functions | |
10 | */ | |
11 | #include <common.h> | |
12 | #include <command.h> | |
13 | ||
088f1b19 | 14 | static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585b | 15 | { |
c4c13df2 | 16 | ulong start = get_timer(0); |
3863585b WD |
17 | ulong delay; |
18 | ||
47e26b1b | 19 | if (argc != 2) |
4c12eeb8 | 20 | return CMD_RET_USAGE; |
3863585b | 21 | |
6d0f6bcf | 22 | delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ; |
3863585b | 23 | |
c4c13df2 | 24 | while (get_timer(start) < delay) { |
088f1b19 | 25 | if (ctrlc()) |
c4c13df2 | 26 | return (-1); |
47e26b1b | 27 | |
088f1b19 | 28 | udelay(100); |
3863585b | 29 | } |
c4c13df2 | 30 | |
3863585b WD |
31 | return 0; |
32 | } | |
c4c13df2 | 33 | |
0d498393 | 34 | U_BOOT_CMD( |
9912121f | 35 | sleep , 2, 1, do_sleep, |
2fb2604d | 36 | "delay execution for some time", |
8bde7f77 | 37 | "N\n" |
a89c33db | 38 | " - delay execution for N seconds (N is _decimal_ !!!)" |
8bde7f77 | 39 | ); |
da83bcd7 JH |
40 | |
41 | #ifdef CONFIG_CMD_TIMER | |
42 | static 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 | ||
60 | U_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 |