]>
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); |
c4974632 | 18 | ulong mdelay = 0; |
3863585b | 19 | ulong delay; |
c4974632 | 20 | char *frpart; |
3863585b | 21 | |
47e26b1b | 22 | if (argc != 2) |
4c12eeb8 | 23 | return CMD_RET_USAGE; |
3863585b | 24 | |
6d0f6bcf | 25 | delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ; |
3863585b | 26 | |
c4974632 | 27 | frpart = strchr(argv[1], '.'); |
28 | ||
29 | if (frpart) { | |
30 | uint mult = CONFIG_SYS_HZ / 10; | |
31 | for (frpart++; *frpart != '\0' && mult > 0; frpart++) { | |
32 | if (*frpart < '0' || *frpart > '9') { | |
33 | mdelay = 0; | |
34 | break; | |
35 | } | |
36 | mdelay += (*frpart - '0') * mult; | |
37 | mult /= 10; | |
38 | } | |
39 | } | |
40 | ||
41 | delay += mdelay; | |
42 | ||
c4c13df2 | 43 | while (get_timer(start) < delay) { |
088f1b19 | 44 | if (ctrlc()) |
c4c13df2 | 45 | return (-1); |
47e26b1b | 46 | |
088f1b19 | 47 | udelay(100); |
3863585b | 48 | } |
c4c13df2 | 49 | |
3863585b WD |
50 | return 0; |
51 | } | |
c4c13df2 | 52 | |
0d498393 | 53 | U_BOOT_CMD( |
9912121f | 54 | sleep , 2, 1, do_sleep, |
2fb2604d | 55 | "delay execution for some time", |
8bde7f77 | 56 | "N\n" |
c4974632 | 57 | " - delay execution for N seconds (N is _decimal_ and can be\n" |
58 | " fractional)" | |
8bde7f77 | 59 | ); |
da83bcd7 JH |
60 | |
61 | #ifdef CONFIG_CMD_TIMER | |
62 | static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
63 | { | |
64 | static ulong start; | |
65 | ||
66 | if (argc != 2) | |
67 | return CMD_RET_USAGE; | |
68 | ||
69 | if (!strcmp(argv[1], "start")) | |
70 | start = get_timer(0); | |
71 | ||
72 | if (!strcmp(argv[1], "get")) { | |
73 | ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ; | |
74 | printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000)); | |
75 | } | |
76 | ||
77 | return 0; | |
78 | } | |
79 | ||
80 | U_BOOT_CMD( | |
81 | timer, 2, 1, do_timer, | |
82 | "access the system timer", | |
83 | "start - Reset the timer reference.\n" | |
84 | "timer get - Print the time since 'start'." | |
85 | ); | |
86 | #endif |