blob: 7616fed7556667448c532d130101483e4fea0066 [file] [log] [blame]
Tom Rini83d290c2018-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 Glass24b852a2015-11-08 23:47:45 -07008#include <console.h>
Tom Rini03de3052024-05-20 13:35:03 -06009#include <time.h>
10#include <vsprintf.h>
Simon Glassc05ed002020-05-10 11:40:11 -060011#include <linux/delay.h>
wdenk38635852002-08-27 05:55:31 +000012
Simon Glass09140112020-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 Roesec4c13df2005-10-20 16:36:44 +020016 ulong start = get_timer(0);
mario.six@gdsys.ccc4974632016-07-19 16:20:13 +020017 ulong mdelay = 0;
wdenk38635852002-08-27 05:55:31 +000018 ulong delay;
mario.six@gdsys.ccc4974632016-07-19 16:20:13 +020019 char *frpart;
wdenk38635852002-08-27 05:55:31 +000020
Wolfgang Denk47e26b12010-07-17 01:06:04 +020021 if (argc != 2)
Simon Glass4c12eeb2011-12-10 08:44:01 +000022 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000023
Simon Glass0b1284e2021-07-24 09:03:30 -060024 delay = dectoul(argv[1], NULL) * CONFIG_SYS_HZ;
wdenk38635852002-08-27 05:55:31 +000025
mario.six@gdsys.ccc4974632016-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 Roesec4c13df2005-10-20 16:36:44 +020042 while (get_timer(start) < delay) {
Kim Phillips088f1b12012-10-29 13:34:31 +000043 if (ctrlc())
Marek Szyprowski54f884b2021-01-22 12:27:31 +010044 return CMD_RET_FAILURE;
Wolfgang Denk47e26b12010-07-17 01:06:04 +020045
Kim Phillips088f1b12012-10-29 13:34:31 +000046 udelay(100);
wdenk38635852002-08-27 05:55:31 +000047 }
Stefan Roesec4c13df2005-10-20 16:36:44 +020048
wdenk38635852002-08-27 05:55:31 +000049 return 0;
50}
Stefan Roesec4c13df2005-10-20 16:36:44 +020051
wdenk0d498392003-07-01 21:06:45 +000052U_BOOT_CMD(
Detlev Zundel99121212007-05-23 19:02:41 +020053 sleep , 2, 1, do_sleep,
Peter Tyser2fb26042009-01-27 18:03:12 -060054 "delay execution for some time",
wdenk8bde7f72003-06-27 21:31:46 +000055 "N\n"
mario.six@gdsys.ccc4974632016-07-19 16:20:13 +020056 " - delay execution for N seconds (N is _decimal_ and can be\n"
57 " fractional)"
wdenk8bde7f72003-06-27 21:31:46 +000058);