2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-08-27 13:55:31 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2015-11-09 14:47:45 +08:00
|
|
|
#include <console.h>
|
2020-05-11 01:40:11 +08:00
|
|
|
#include <linux/delay.h>
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2020-05-11 01:40:03 +08:00
|
|
|
static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2002-08-27 13:55:31 +08:00
|
|
|
{
|
2005-10-20 22:36:44 +08:00
|
|
|
ulong start = get_timer(0);
|
2016-07-19 22:20:13 +08:00
|
|
|
ulong mdelay = 0;
|
2002-08-27 13:55:31 +08:00
|
|
|
ulong delay;
|
2016-07-19 22:20:13 +08:00
|
|
|
char *frpart;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2010-07-17 07:06:04 +08:00
|
|
|
if (argc != 2)
|
2011-12-10 16:44:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2021-07-24 23:03:30 +08:00
|
|
|
delay = dectoul(argv[1], NULL) * CONFIG_SYS_HZ;
|
2002-08-27 13:55:31 +08:00
|
|
|
|
2016-07-19 22:20:13 +08:00
|
|
|
frpart = strchr(argv[1], '.');
|
|
|
|
|
|
|
|
if (frpart) {
|
|
|
|
uint mult = CONFIG_SYS_HZ / 10;
|
|
|
|
for (frpart++; *frpart != '\0' && mult > 0; frpart++) {
|
|
|
|
if (*frpart < '0' || *frpart > '9') {
|
|
|
|
mdelay = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mdelay += (*frpart - '0') * mult;
|
|
|
|
mult /= 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delay += mdelay;
|
|
|
|
|
2005-10-20 22:36:44 +08:00
|
|
|
while (get_timer(start) < delay) {
|
2012-10-29 21:34:31 +08:00
|
|
|
if (ctrlc())
|
2021-01-22 19:27:31 +08:00
|
|
|
return CMD_RET_FAILURE;
|
2010-07-17 07:06:04 +08:00
|
|
|
|
2012-10-29 21:34:31 +08:00
|
|
|
udelay(100);
|
2002-08-27 13:55:31 +08:00
|
|
|
}
|
2005-10-20 22:36:44 +08:00
|
|
|
|
2002-08-27 13:55:31 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-10-20 22:36:44 +08:00
|
|
|
|
2003-07-02 05:06:45 +08:00
|
|
|
U_BOOT_CMD(
|
2007-05-24 01:02:41 +08:00
|
|
|
sleep , 2, 1, do_sleep,
|
2009-01-28 08:03:12 +08:00
|
|
|
"delay execution for some time",
|
2003-06-28 05:31:46 +08:00
|
|
|
"N\n"
|
2016-07-19 22:20:13 +08:00
|
|
|
" - delay execution for N seconds (N is _decimal_ and can be\n"
|
|
|
|
" fractional)"
|
2003-06-28 05:31:46 +08:00
|
|
|
);
|