blob: c741b4aa029bdbf38da667467213c41c0bc87a72 [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
Tom Riniabb9a042024-05-18 20:20:43 -06007#include <common.h>
wdenk38635852002-08-27 05:55:31 +00008#include <command.h>
Simon Glassa73bda42015-11-08 23:47:45 -07009#include <console.h>
Simon Glassdbd79542020-05-10 11:40:11 -060010#include <linux/delay.h>
wdenk38635852002-08-27 05:55:31 +000011
Simon Glassed38aef2020-05-10 11:40:03 -060012static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
13 char *const argv[])
wdenk38635852002-08-27 05:55:31 +000014{
Stefan Roesef1d66992005-10-20 16:36:44 +020015 ulong start = get_timer(0);
mario.six@gdsys.ccae2eba62016-07-19 16:20:13 +020016 ulong mdelay = 0;
wdenk38635852002-08-27 05:55:31 +000017 ulong delay;
mario.six@gdsys.ccae2eba62016-07-19 16:20:13 +020018 char *frpart;
wdenk38635852002-08-27 05:55:31 +000019
Wolfgang Denk3b683112010-07-17 01:06:04 +020020 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000021 return CMD_RET_USAGE;
wdenk38635852002-08-27 05:55:31 +000022
Simon Glassff9b9032021-07-24 09:03:30 -060023 delay = dectoul(argv[1], NULL) * CONFIG_SYS_HZ;
wdenk38635852002-08-27 05:55:31 +000024
mario.six@gdsys.ccae2eba62016-07-19 16:20:13 +020025 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
Stefan Roesef1d66992005-10-20 16:36:44 +020041 while (get_timer(start) < delay) {
Kim Phillipsdc00a682012-10-29 13:34:31 +000042 if (ctrlc())
Marek Szyprowski196e0dc2021-01-22 12:27:31 +010043 return CMD_RET_FAILURE;
Wolfgang Denk3b683112010-07-17 01:06:04 +020044
Kim Phillipsdc00a682012-10-29 13:34:31 +000045 udelay(100);
wdenk38635852002-08-27 05:55:31 +000046 }
Stefan Roesef1d66992005-10-20 16:36:44 +020047
wdenk38635852002-08-27 05:55:31 +000048 return 0;
49}
Stefan Roesef1d66992005-10-20 16:36:44 +020050
wdenkf287a242003-07-01 21:06:45 +000051U_BOOT_CMD(
Detlev Zundel409a2852007-05-23 19:02:41 +020052 sleep , 2, 1, do_sleep,
Peter Tyserdfb72b82009-01-27 18:03:12 -060053 "delay execution for some time",
wdenk57b2d802003-06-27 21:31:46 +000054 "N\n"
mario.six@gdsys.ccae2eba62016-07-19 16:20:13 +020055 " - delay execution for N seconds (N is _decimal_ and can be\n"
56 " fractional)"
wdenk57b2d802003-06-27 21:31:46 +000057);