]>
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 | ||
3863585b WD |
7 | #include <common.h> |
8 | #include <command.h> | |
24b852a7 | 9 | #include <console.h> |
c05ed00a | 10 | #include <linux/delay.h> |
3863585b | 11 | |
09140113 SG |
12 | static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc, |
13 | char *const argv[]) | |
3863585b | 14 | { |
c4c13df2 | 15 | ulong start = get_timer(0); |
c4974632 | 16 | ulong mdelay = 0; |
3863585b | 17 | ulong delay; |
c4974632 | 18 | char *frpart; |
3863585b | 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 | |
c4974632 | 25 | frpart = strchr(argv[1], '.'); |
26 | ||
27 | if (frpart) { | |
28 | uint mult = CONFIG_SYS_HZ / 10; | |
29 | for (frpart++; *frpart != '\0' && mult > 0; frpart++) { | |
30 | if (*frpart < '0' || *frpart > '9') { | |
31 | mdelay = 0; | |
32 | break; | |
33 | } | |
34 | mdelay += (*frpart - '0') * mult; | |
35 | mult /= 10; | |
36 | } | |
37 | } | |
38 | ||
39 | delay += mdelay; | |
40 | ||
c4c13df2 | 41 | while (get_timer(start) < delay) { |
088f1b19 | 42 | if (ctrlc()) |
c4c13df2 | 43 | return (-1); |
47e26b1b | 44 | |
088f1b19 | 45 | udelay(100); |
3863585b | 46 | } |
c4c13df2 | 47 | |
3863585b WD |
48 | return 0; |
49 | } | |
c4c13df2 | 50 | |
0d498393 | 51 | U_BOOT_CMD( |
9912121f | 52 | sleep , 2, 1, do_sleep, |
2fb2604d | 53 | "delay execution for some time", |
8bde7f77 | 54 | "N\n" |
c4974632 | 55 | " - delay execution for N seconds (N is _decimal_ and can be\n" |
56 | " fractional)" | |
8bde7f77 | 57 | ); |