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