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