wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Misc functions |
| 10 | */ |
| 11 | #include <common.h> |
| 12 | #include <command.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 13 | #include <console.h> |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 14 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 15 | static int do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 16 | { |
Stefan Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 17 | ulong start = get_timer(0); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 18 | ulong delay; |
| 19 | |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 20 | if (argc != 2) |
Simon Glass | a06dfc7 | 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 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | delay = simple_strtoul(argv[1], NULL, 10) * CONFIG_SYS_HZ; |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 24 | |
Stefan Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 25 | while (get_timer(start) < delay) { |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 26 | if (ctrlc()) |
Stefan Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 27 | return (-1); |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 28 | |
Kim Phillips | dc00a68 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 29 | udelay(100); |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 30 | } |
Stefan Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 31 | |
wdenk | 3863585 | 2002-08-27 05:55:31 +0000 | [diff] [blame] | 32 | return 0; |
| 33 | } |
Stefan Roese | f1d6699 | 2005-10-20 16:36:44 +0200 | [diff] [blame] | 34 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 35 | U_BOOT_CMD( |
Detlev Zundel | 409a285 | 2007-05-23 19:02:41 +0200 | [diff] [blame] | 36 | sleep , 2, 1, do_sleep, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 37 | "delay execution for some time", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 38 | "N\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 39 | " - delay execution for N seconds (N is _decimal_ !!!)" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 40 | ); |
Joe Hershberger | 59f3f52 | 2012-10-03 12:14:57 +0000 | [diff] [blame] | 41 | |
| 42 | #ifdef CONFIG_CMD_TIMER |
| 43 | static int do_timer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 44 | { |
| 45 | static ulong start; |
| 46 | |
| 47 | if (argc != 2) |
| 48 | return CMD_RET_USAGE; |
| 49 | |
| 50 | if (!strcmp(argv[1], "start")) |
| 51 | start = get_timer(0); |
| 52 | |
| 53 | if (!strcmp(argv[1], "get")) { |
| 54 | ulong msecs = get_timer(start) * 1000 / CONFIG_SYS_HZ; |
| 55 | printf("%ld.%03d\n", msecs / 1000, (int)(msecs % 1000)); |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | U_BOOT_CMD( |
| 62 | timer, 2, 1, do_timer, |
| 63 | "access the system timer", |
| 64 | "start - Reset the timer reference.\n" |
| 65 | "timer get - Print the time since 'start'." |
| 66 | ); |
| 67 | #endif |