summaryrefslogtreecommitdiff
path: root/chip/stm32/usart_info_command.c
blob: 2649a97351332c69167d5e51063e2f6138d37640 (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
/* Copyright 2015 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 command to query USART state
 */
#include "atomic.h"
#include "common.h"
#include "console.h"
#include "usart.h"

static int command_usart_info(int argc, char **argv)
{
	struct usart_configs configs = usart_get_configs();
	size_t i;

	for (i = 0; i < configs.count; i++) {
		struct usart_config const *config = configs.configs[i];

		if (config == NULL)
			continue;

		ccprintf(
			"USART%d\n"
			"    dropped %d bytes\n"
			"    overran %d times\n",
			config->hw->index + 1,
			atomic_clear((uint32_t *)&(config->state->rx_dropped)),
			atomic_clear((uint32_t *)&(config->state->rx_overrun)));

		if (config->rx->info)
			config->rx->info(config);

		if (config->tx->info)
			config->tx->info(config);
	}

	return EC_SUCCESS;
}

DECLARE_CONSOLE_COMMAND(usart_info,
			command_usart_info,
			NULL,
			"Display USART info");