]> cloudbase.mooo.com Git - z180-stamp.git/blob - avr/cmd_misc.c
Merge branch 'chan-fatfs' into fatfs-integration
[z180-stamp.git] / avr / cmd_misc.c
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 "common.h"
11 #include "eval_arg.h"
12 #include <stdbool.h>
13
14 #include "command.h"
15 #include "timer.h"
16 #include "con-utils.h"
17 #include "getopt-min.h"
18
19
20 command_ret_t do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
21 {
22 bool put_newline = true;
23
24 (void) cmdtp; (void) flag;
25
26 /* reset getopt() */
27 optind = 0;
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 }
39
40 for (uint_fast8_t i = optind; i < argc; i++) {
41
42 if (i != optind)
43 putchar(' ');
44
45 my_puts(argv[i]);
46 }
47
48 if (put_newline)
49 putchar('\n');
50
51 return CMD_RET_SUCCESS;
52 }
53
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 = eval_arg(argv[1], &sp);
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 }