]>
Commit | Line | Data |
---|---|---|
d684c216 | 1 | /* |
35edb766 L |
2 | * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> |
3 | * | |
d684c216 L |
4 | * Copyright 2000-2009 |
5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
6 | * | |
7 | * SPDX-License-Identifier: GPL-2.0+ | |
8 | */ | |
9 | ||
10 | #include "common.h" | |
8a7decea | 11 | #include <stdlib.h> |
bbd45c46 | 12 | #include <stdbool.h> |
8a7decea | 13 | |
d684c216 | 14 | #include "command.h" |
8a7decea L |
15 | #include "timer.h" |
16 | #include "con-utils.h" | |
bbd45c46 | 17 | #include "getopt-min.h" |
d684c216 L |
18 | |
19 | ||
d0581f88 | 20 | command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
d684c216 | 21 | { |
bbd45c46 | 22 | bool put_newline = true; |
8a7decea | 23 | |
d684c216 L |
24 | (void) cmdtp; (void) flag; |
25 | ||
bbd45c46 | 26 | /* reset getopt() */ |
beafa6d6 | 27 | optind = 0; |
bbd45c46 L |
28 | |
29 | int opt; | |
30 | while ((opt = getopt(argc, argv, PSTR("n"))) != -1) { | |
31 | switch (opt) { | |
32 | case 'n': | |
33 | put_newline = false; | |
34 | break; | |
35 | default: /* '?' */ | |
36 | return CMD_RET_USAGE; | |
37 | } | |
38 | } | |
d684c216 | 39 | |
bbd45c46 | 40 | for (uint_fast8_t i = optind; i < argc; i++) { |
8a7decea | 41 | |
bbd45c46 | 42 | if (i != optind) |
d684c216 | 43 | putchar(' '); |
bbd45c46 L |
44 | |
45 | my_puts(argv[i]); | |
8a7decea L |
46 | } |
47 | ||
bbd45c46 | 48 | if (put_newline) |
d684c216 L |
49 | putchar('\n'); |
50 | ||
d0581f88 | 51 | return CMD_RET_SUCCESS; |
d684c216 L |
52 | } |
53 | ||
8a7decea L |
54 | |
55 | command_ret_t do_sleep(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | |
56 | { | |
57 | unsigned long start = get_timer(0); | |
58 | unsigned long delay; | |
59 | char *sp; | |
60 | uint_fast8_t millisec = 0; | |
61 | ||
62 | (void) cmdtp; (void) flag; | |
63 | ||
64 | if (argc != 2) | |
65 | return CMD_RET_USAGE; | |
66 | ||
67 | delay = strtoul(argv[1], &sp, 10); | |
68 | ||
69 | if (*sp == 'm') { | |
70 | millisec = 1; | |
71 | sp++; | |
72 | } | |
73 | if (*sp == 's') | |
74 | sp++; | |
75 | if (*sp != '\0') | |
76 | return CMD_RET_USAGE; | |
77 | ||
78 | if (!millisec) | |
79 | delay *= 1000; | |
80 | ||
81 | while (get_timer(start) < delay) { | |
82 | if (ctrlc()) | |
83 | return CMD_RET_FAILURE; | |
84 | ||
85 | udelay(100); | |
86 | } | |
87 | ||
88 | return CMD_RET_SUCCESS; | |
89 | } |