1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2001
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 */
6
7 #include <common.h>
8 #include <command.h>
9 #include <console.h>
10 #include <linux/delay.h>
11
do_sleep(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])12 static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
13 char *const argv[])
14 {
15 ulong start = get_timer(0);
16 ulong mdelay = 0;
17 ulong delay;
18 char *frpart;
19
20 if (argc != 2)
21 return CMD_RET_USAGE;
22
23 delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ;
24
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
41 while (get_timer(start) < delay) {
42 if (ctrlc())
43 return CMD_RET_FAILURE;
44
45 udelay(100);
46 }
47
48 return 0;
49 }
50
51 U_BOOT_CMD(
52 sleep , 2, 1, do_sleep,
53 "delay execution for some time",
54 "N\n"
55 " - delay execution for N seconds (N is _decimal_ and can be\n"
56 " fractional)"
57 );
58