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