Merge branch 'master' of git://git.denx.de/u-boot-spi
[platform/kernel/u-boot.git] / cmd / conitrace.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * The 'conitrace' command prints the codes received from the console input as
4  * hexadecimal numbers.
5  *
6  * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de>
7  */
8 #include <common.h>
9 #include <command.h>
10
11 static int do_conitrace(cmd_tbl_t *cmdtp, int flag, int argc,
12                         char * const argv[])
13 {
14         bool first = true;
15
16         printf("Waiting for your input\n");
17         printf("To terminate type 'x'\n");
18
19         /* Empty input buffer */
20         while (tstc())
21                 getc();
22
23         for (;;) {
24                 int c = getc();
25
26                 if (first && (c == 'x' || c == 'X'))
27                         break;
28
29                 printf("%02x ", c);
30                 first = false;
31
32                 /* 1 ms delay - serves to detect separate keystrokes */
33                 udelay(1000);
34                 if (!tstc()) {
35                         printf("\n");
36                         first = true;
37                 }
38         }
39
40         return CMD_RET_SUCCESS;
41 }
42
43 #ifdef CONFIG_SYS_LONGHELP
44 static char conitrace_help_text[] = "";
45 #endif
46
47 U_BOOT_CMD_COMPLETE(
48         conitrace, 2, 0, do_conitrace,
49         "trace console input",
50         conitrace_help_text, NULL
51 );