Merge tag 'tpm-master-28012025' of https://source.denx.de/u-boot/custodians/u-boot-tpm
[u-boot.git] / cmd / sleep.c
blob7616fed7556667448c532d130101483e4fea0066
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2001
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 */
7 #include <command.h>
8 #include <console.h>
9 #include <time.h>
10 #include <vsprintf.h>
11 #include <linux/delay.h>
13 static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
14 char *const argv[])
16 ulong start = get_timer(0);
17 ulong mdelay = 0;
18 ulong delay;
19 char *frpart;
21 if (argc != 2)
22 return CMD_RET_USAGE;
24 delay = dectoul(argv[1], NULL) * CONFIG_SYS_HZ;
26 frpart = strchr(argv[1], '.');
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;
35 mdelay += (*frpart - '0') * mult;
36 mult /= 10;
40 delay += mdelay;
42 while (get_timer(start) < delay) {
43 if (ctrlc())
44 return CMD_RET_FAILURE;
46 udelay(100);
49 return 0;
52 U_BOOT_CMD(
53 sleep , 2, 1, do_sleep,
54 "delay execution for some time",
55 "N\n"
56 " - delay execution for N seconds (N is _decimal_ and can be\n"
57 " fractional)"