blob: 7616fed7556667448c532d130101483e4fea0066 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk38635852002-08-27 05:55:31 +00002/*
3 * (C) Copyright 2001
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk38635852002-08-27 05:55:31 +00005 */
6
wdenk38635852002-08-27 05:55:31 +00007#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -07008#include <console.h>
Tom Rini5c1444f2024-04-27 08:10:59 -06009#include <time.h>
10#include <vsprintf.h>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
wdenk38635852002-08-27 05:55:31 +000012
Simon Glassed38aef2020-05-10 11:40:03 -060013static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
14 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000015{
Stefan Roesef1d66992005-10-20 16:36:44 +020016 ulong start = get_timer(0);
mario.six@gdsys.ccae2eba62016-07-19 16:20:13 +020017 ulong mdelay = 0;
wdenk38635852002-08-27 05:55:31 +000018 ulong delay;
mario.six@gdsys.ccae2eba62016-07-19 16:20:13 +020019 char *frpart;
wdenk38635852002-08-27 05:55:31 +000020
Wolfgang Denk3b683112010-07-17 01:06:04 +020021 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000022 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000023
Simon Glassff9b9032021-07-24 09:03:30 -060024 delay = dectoul(argv[1], NULL) * CONFIG_SYS_HZ;
wdenk38635852002-08-27 05:55:31 +000025
mario.six@gdsys.ccae2eba62016-07-19 16:20:13 +020026 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
Stefan Roesef1d66992005-10-20 16:36:44 +020042 while (get_timer(start) < delay) {
Kim Phillipsdc00a682012-10-29 13:34:31 +000043 if (ctrlc())
Marek Szyprowski196e0dc2021-01-22 12:27:31 +010044 return CMD_RET_FAILURE;
Wolfgang Denk3b683112010-07-17 01:06:04 +020045
Kim Phillipsdc00a682012-10-29 13:34:31 +000046 udelay(100);
wdenk38635852002-08-27 05:55:31 +000047 }
Stefan Roesef1d66992005-10-20 16:36:44 +020048
wdenk38635852002-08-27 05:55:31 +000049 return 0;
50}
Stefan Roesef1d66992005-10-20 16:36:44 +020051
wdenkf287a242003-07-01 21:06:45 +000052U_BOOT_CMD(
Detlev Zundel409a2852007-05-23 19:02:41 +020053 sleep , 2, 1, do_sleep,
Peter Tyserdfb72b82009-01-27 18:03:12 -060054 "delay execution for some time",
wdenk57b2d802003-06-27 21:31:46 +000055 "N\n"
mario.six@gdsys.ccae2eba62016-07-19 16:20:13 +020056 " - delay execution for N seconds (N is _decimal_ and can be\n"
57 " fractional)"
wdenk57b2d802003-06-27 21:31:46 +000058);