Files
OpenCellular/include/console.h
Vadim Bendebury 6a324c1de5 Allow console commands abbreviation
The EC console input handling code is being enhanced to accept
abbreviated command names.

If the abbreviation is unique, the appropriate command is used, if the
abbreviation is ambiguous, the command is handled as nonexistent. The
error message is being modified to mention that the command either
does not exist or is ambiguous.

This change also makes it impossible to have command names matching
the beginning of other command names. Two such cases are being fixed
(`ch' renamed to `chan' and `thermal' renamed to 'thermalconf').

BUG=none
TEST=manual
 . program the new EC image. Try entering at the console:
  > h
  Command 'h' either not found or ambiguous.
  Command returned error 1
  > he
  Known commands:
    adc            autofan        battery        ch             charger
  ...
  > help
  Known commands:
    adc            autofan        battery        ch             charger
  ...

Change-Id: Iaa3e91e1504e42daefb02d561e00c39003548197
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
2012-05-14 13:35:03 -07:00

90 lines
2.4 KiB
C

/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Debug console for Chrome EC */
#ifndef __CROS_EC_CONSOLE_H
#define __CROS_EC_CONSOLE_H
#include "common.h"
/* Console command; used by DECLARE_CONSOLE_COMMAND macro. */
struct console_command {
/* Command name. Case-insensitive. */
const char *name;
/* Handler for the command. argv[0] will be the command name. */
int (*handler)(int argc, char **argv);
};
/* Console channels */
enum console_channel {
CC_COMMAND = 0, /* Console command (interactive I/O). Use this only
* inside a console command routine. */
CC_CHARGER,
CC_CHIPSET,
CC_DMA,
CC_GPIO,
CC_HOSTCMD,
CC_I2C,
CC_I8042,
CC_KEYBOARD,
CC_KEYSCAN,
CC_LIGHTBAR,
CC_LPC,
CC_PORT80,
CC_POWERBTN,
CC_PWM,
CC_SYSTEM,
CC_TASK,
CC_USBCHARGE,
CC_VBOOT,
/* Channel count; not itself a channel */
CC_CHANNEL_COUNT
};
/* Mask in channel_mask for a particular channel */
#define CC_MASK(channel) (1UL << (channel))
/* Mask to use to enable all channels */
#define CC_ALL 0xffffffffUL
/* Put a string to the console channel. */
int cputs(enum console_channel channel, const char *outstr);
/* Print formatted output to the console channel. See uart_vprintf() for
* valid format codes. */
int cprintf(enum console_channel channel, const char *format, ...);
/* Flush the console output for all channels. */
void cflush(void);
/* Convenience macros for printing to the command channel.
*
* Modules may define similar macros in their .c files for their own use; it is
* recommended those module-specific macros be named CPUTS and CPRINTF. */
#define ccputs(outstr) cputs(CC_COMMAND, outstr)
/* gcc allows variable arg lists in macros; see
* http://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html */
#define ccprintf(format, args...) cprintf(CC_COMMAND, format, ## args)
/* Called by UART when a line of input is pending. */
void console_has_input(void);
/*
* Register a console command handler. Note that `name' must never be a
* beginning of another existing command name.
*/
#define DECLARE_CONSOLE_COMMAND(name, routine) \
static const char __con_cmd_label_##name[] = #name; \
const struct console_command __con_cmd_##name \
__attribute__((section(".rodata.cmds"))) \
= {__con_cmd_label_##name, routine}
#endif /* __CROS_EC_CONSOLE_H */