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