summaryrefslogtreecommitdiff
path: root/common/console_output.c
blob: e3334ee20d5541216b9ccf08fc3df91c89c0ebc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* 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.
 */

/* Console output module for Chrome EC */

#include "console.h"
#include "uart.h"
#include "util.h"

/* Default to all channels active */
#ifndef CC_DEFAULT
#define CC_DEFAULT	CC_ALL
#endif
static uint32_t channel_mask = CC_DEFAULT;

/* List of channel names; must match enum console_channel. */
/* TODO: move this to board.c */
static const char *channel_names[CC_CHANNEL_COUNT] = {
	"command",
	"charger",
	"chipset",
	"dma",
	"events",
	"gpio",
	"hostcmd",
	"i2c",
	"i8042",
	"keyboard",
	"keyscan",
	"lightbar",
	"lpc",
	"port80",
	"powerbtn",
	"pwm",
	"spi",
	"system",
	"task",
	"usbcharge",
	"vboot",
};

/*****************************************************************************/
/* Channel-based console output */

int cputs(enum console_channel channel, const char *outstr)
{
	/* Filter out inactive channels */
	if (!(CC_MASK(channel) & channel_mask))
		return EC_SUCCESS;

	return uart_puts(outstr);
}


int cprintf(enum console_channel channel, const char *format, ...)
{
	int rv;
	va_list args;

	/* Filter out inactive channels */
	if (!(CC_MASK(channel) & channel_mask))
		return EC_SUCCESS;

	va_start(args, format);
	rv = uart_vprintf(format, args);
	va_end(args);
	return rv;
}


void cflush(void)
{
	uart_flush_output();
}

/*****************************************************************************/
/* Console commands */

/* Set active channels */
static int command_ch(int argc, char **argv)
{
	int i;
	char *e;

	/* If one arg, set the mask */
	if (argc == 2) {
		int m = strtoi(argv[1], &e, 0);
		if (*e)
			return EC_ERROR_PARAM1;

		/* No disabling the command output channel */
		channel_mask = m | CC_MASK(CC_COMMAND);

		/* TODO: save channel list to EEPROM */

		return EC_SUCCESS;
	}

	/* Print the list of channels */
	ccputs(" # Mask     E Channel\n");
	for (i = 0; i < CC_CHANNEL_COUNT; i++) {
		ccprintf("%2d %08x %c %s\n",
			 i, CC_MASK(i),
			 (channel_mask & CC_MASK(i)) ? '*' : ' ',
			 channel_names[i]);
		cflush();
	}
	return EC_SUCCESS;
};
DECLARE_CONSOLE_COMMAND(chan, command_ch,
			"[mask]",
			"Get or set console channel mask",
			NULL);