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