Blame view
cmd/misc.c
1.57 KB
3863585bb Initial revision |
1 2 3 4 |
/* * (C) Copyright 2001 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
3863585bb Initial revision |
6 7 8 9 10 11 12 |
*/ /* * Misc functions */ #include <common.h> #include <command.h> |
24b852a7a Move console defi... |
13 |
#include <console.h> |
3863585bb Initial revision |
14 |
|
088f1b199 common/cmd_*.c: s... |
15 |
static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
3863585bb Initial revision |
16 |
{ |
c4c13df28 Fix problem with ... |
17 |
ulong start = get_timer(0); |
c4974632e cmd: misc: Add su... |
18 |
ulong mdelay = 0; |
3863585bb Initial revision |
19 |
ulong delay; |
c4974632e cmd: misc: Add su... |
20 |
char *frpart; |
3863585bb Initial revision |
21 |
|
47e26b1bf cmd_usage(): simp... |
22 |
if (argc != 2) |
4c12eeb8b Convert cmd_usage... |
23 |
return CMD_RET_USAGE; |
3863585bb Initial revision |
24 |
|
6d0f6bcf3 rename CFG_ macro... |
25 |
delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ; |
3863585bb Initial revision |
26 |
|
c4974632e cmd: misc: Add su... |
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
frpart = strchr(argv[1], '.'); if (frpart) { uint mult = CONFIG_SYS_HZ / 10; for (frpart++; *frpart != '\0' && mult > 0; frpart++) { if (*frpart < '0' || *frpart > '9') { mdelay = 0; break; } mdelay += (*frpart - '0') * mult; mult /= 10; } } delay += mdelay; |
c4c13df28 Fix problem with ... |
42 |
while (get_timer(start) < delay) { |
088f1b199 common/cmd_*.c: s... |
43 |
if (ctrlc()) |
c4c13df28 Fix problem with ... |
44 |
return (-1); |
47e26b1bf cmd_usage(): simp... |
45 |
|
088f1b199 common/cmd_*.c: s... |
46 |
udelay(100); |
3863585bb Initial revision |
47 |
} |
c4c13df28 Fix problem with ... |
48 |
|
3863585bb Initial revision |
49 50 |
return 0; } |
c4c13df28 Fix problem with ... |
51 |
|
0d4983930 Patch by Kenneth ... |
52 |
U_BOOT_CMD( |
9912121f7 Change 'repeatabl... |
53 |
sleep , 2, 1, do_sleep, |
2fb2604d5 Command usage cle... |
54 |
"delay execution for some time", |
8bde7f776 * Code cleanup: |
55 56 |
"N " |
c4974632e cmd: misc: Add su... |
57 58 59 |
" - delay execution for N seconds (N is _decimal_ and can be " " fractional)" |
8bde7f776 * Code cleanup: |
60 |
); |
da83bcd7b Add a command to ... |
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
#ifdef CONFIG_CMD_TIMER static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { static ulong start; if (argc != 2) return CMD_RET_USAGE; if (!strcmp(argv[1], "start")) start = get_timer(0); if (!strcmp(argv[1], "get")) { ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ; printf("%ld.%03d ", msecs / 1000, (int)(msecs % 1000)); } return 0; } U_BOOT_CMD( timer, 2, 1, do_timer, "access the system timer", "start - Reset the timer reference. " "timer get - Print the time since 'start'." ); #endif |