Heinrich Schuchardt | 13ea685 | 2018-09-07 19:43:11 +0200 | [diff] [blame] | 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 | */ |
Heinrich Schuchardt | 13ea685 | 2018-09-07 19:43:11 +0200 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 9 | #include <linux/delay.h> |
Heinrich Schuchardt | 13ea685 | 2018-09-07 19:43:11 +0200 | [diff] [blame] | 10 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 11 | static int do_conitrace(struct cmd_tbl *cmdtp, int flag, int argc, |
| 12 | char *const argv[]) |
Heinrich Schuchardt | 13ea685 | 2018-09-07 19:43:11 +0200 | [diff] [blame] | 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()) |
Heinrich Schuchardt | 30ca181 | 2020-10-23 12:46:04 +0200 | [diff] [blame] | 21 | getchar(); |
Heinrich Schuchardt | 13ea685 | 2018-09-07 19:43:11 +0200 | [diff] [blame] | 22 | |
| 23 | for (;;) { |
Heinrich Schuchardt | 30ca181 | 2020-10-23 12:46:04 +0200 | [diff] [blame] | 24 | int c = getchar(); |
Heinrich Schuchardt | 13ea685 | 2018-09-07 19:43:11 +0200 | [diff] [blame] | 25 | |
| 26 | if (first && (c == 'x' || c == 'X')) |
| 27 | break; |
| 28 | |
| 29 | printf("%02x ", c); |
| 30 | first = false; |
| 31 | |
Heinrich Schuchardt | 11a3fe0 | 2020-12-27 00:12:28 +0100 | [diff] [blame] | 32 | /* 10 ms delay - serves to detect separate keystrokes */ |
| 33 | udelay(10000); |
Heinrich Schuchardt | 13ea685 | 2018-09-07 19:43:11 +0200 | [diff] [blame] | 34 | if (!tstc()) { |
| 35 | printf("\n"); |
| 36 | first = true; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return CMD_RET_SUCCESS; |
| 41 | } |
| 42 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 43 | U_BOOT_LONGHELP(conitrace, ""); |
Heinrich Schuchardt | 13ea685 | 2018-09-07 19:43:11 +0200 | [diff] [blame] | 44 | |
| 45 | U_BOOT_CMD_COMPLETE( |
| 46 | conitrace, 2, 0, do_conitrace, |
| 47 | "trace console input", |
| 48 | conitrace_help_text, NULL |
| 49 | ); |