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