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