Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 7 | #include <common.h> |
| 8 | #include <command.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 9 | #include <console.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 10 | #include <linux/delay.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 11 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 12 | static int do_sleep(struct cmd_tbl *cmdtp, int flag, int argc, |
| 13 | char *const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 14 | { |
Stefan Roese | c4c13df | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 15 | ulong start = get_timer(0); |
mario.six@gdsys.cc | c497463 | 2016-07-19 16:20:13 +0200 | [diff] [blame] | 16 | ulong mdelay = 0; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 17 | ulong delay; |
mario.six@gdsys.cc | c497463 | 2016-07-19 16:20:13 +0200 | [diff] [blame] | 18 | char *frpart; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 19 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 20 | if (argc != 2) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 21 | return CMD_RET_USAGE; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 22 | |
Simon Glass | 0b1284e | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 23 | delay = dectoul(argv[1], NULL) * CONFIG_SYS_HZ; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 24 | |
mario.six@gdsys.cc | c497463 | 2016-07-19 16:20:13 +0200 | [diff] [blame] | 25 | 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 Roese | c4c13df | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 41 | while (get_timer(start) < delay) { |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 42 | if (ctrlc()) |
Marek Szyprowski | 54f884b | 2021-01-22 12:27:31 +0100 | [diff] [blame] | 43 | return CMD_RET_FAILURE; |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 44 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 45 | udelay(100); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 46 | } |
Stefan Roese | c4c13df | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 47 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 48 | return 0; |
| 49 | } |
Stefan Roese | c4c13df | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 50 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 51 | U_BOOT_CMD( |
Detlev Zundel | 9912121 | 2007-05-23 19:02:41 +0200 | [diff] [blame] | 52 | sleep , 2, 1, do_sleep, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 53 | "delay execution for some time", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | "N\n" |
mario.six@gdsys.cc | c497463 | 2016-07-19 16:20:13 +0200 | [diff] [blame] | 55 | " - delay execution for N seconds (N is _decimal_ and can be\n" |
| 56 | " fractional)" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 57 | ); |