USART: Add usart_info command

This optional console command is enabled with CONFIG_USART_INFO_COMMAND.
It will display and clear dropped character and overrun counts for all
configured USARTs.

Signed-off-by: Anton Staaf <robotboy@chromium.org>

BRANCH=None
BUG=None
TEST=make buildall -j

Change-Id: Icf6061aaab2cda71e9d317455c897828b9daf844
Reviewed-on: https://chromium-review.googlesource.com/292770
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
Trybot-Ready: Anton Staaf <robotboy@chromium.org>
This commit is contained in:
Anton Staaf
2015-07-28 15:11:28 -07:00
committed by ChromeOS Commit Bot
parent f7fa6248bf
commit 16f63703c9
12 changed files with 90 additions and 6 deletions

View File

@@ -16,6 +16,7 @@
#define CONFIG_STREAM_USART1
#define CONFIG_STREAM_USART4
#define CONFIG_STREAM_USB
#define CONFIG_CMD_USART_INFO
/* the UART console is on USART2 (PA14/PA15) */
#undef CONFIG_UART_CONSOLE

View File

@@ -15,6 +15,7 @@
/* Enable USART2 */
#define CONFIG_STREAM_USART
#define CONFIG_STREAM_USART2
#define CONFIG_CMD_USART_INFO
/*
* Allow dangerous commands all the time, since we don't have a write protect

View File

@@ -38,6 +38,7 @@ chip-$(CONFIG_STREAM_USART)+=usart.o usart-$(CHIP_FAMILY).o
chip-$(CONFIG_STREAM_USART)+=usart_rx_interrupt-$(CHIP_FAMILY).o
chip-$(CONFIG_STREAM_USART)+=usart_tx_interrupt.o
chip-$(CONFIG_STREAM_USART)+=usart_tx_dma.o
chip-$(CONFIG_CMD_USART_INFO)+=usart_info_command.o
chip-$(CONFIG_STREAM_USB)+=usb-stream.o
chip-$(CONFIG_WATCHDOG)+=watchdog.o
chip-$(HAS_TASK_CONSOLE)+=uart.o

View File

@@ -6,6 +6,7 @@
#include "clock.h"
#include "common.h"
#include "compile_time_macros.h"
#include "hooks.h"
#include "registers.h"
#include "task.h"
@@ -16,8 +17,15 @@
* each USART, an entry will be NULL if no USART driver is initialized for the
* corresponding hardware instance.
*/
#define STM32_USARTS_MAX 4
static struct usart_config const *configs[STM32_USARTS_MAX];
struct usart_configs usart_get_configs(void)
{
return (struct usart_configs) {configs, ARRAY_SIZE(configs)};
}
static void usart_variant_enable(struct usart_config const *config)
{
/*

View File

@@ -7,8 +7,6 @@
#include "usart.h"
#define STM32_USARTS_MAX 4
/*
* The STM32F0 series can have as many as four UARTS. These are the HW configs
* for those UARTS. They can be used to initialize STM32 generic UART configs.

View File

@@ -5,6 +5,7 @@
#include "usart-stm32f3.h"
#include "common.h"
#include "compile_time_macros.h"
#include "hooks.h"
#include "registers.h"
#include "task.h"
@@ -15,8 +16,15 @@
* each USART, an entry will be NULL if no USART driver is initialized for the
* corresponding hardware instance.
*/
#define STM32_USARTS_MAX 3
static struct usart_config const *configs[STM32_USARTS_MAX];
struct usart_configs usart_get_configs(void)
{
return (struct usart_configs) {configs, ARRAY_SIZE(configs)};
}
static void usart_variant_enable(struct usart_config const *config)
{
configs[config->hw->index] = config;

View File

@@ -7,8 +7,6 @@
#include "usart.h"
#define STM32_USARTS_MAX 3
/*
* The STM32F3 series can have as many as three UARTS. These are the HW configs
* for those UARTS. They can be used to initialize STM32 generic UART configs.

View File

@@ -6,6 +6,7 @@
#include "clock.h"
#include "common.h"
#include "compile_time_macros.h"
#include "hooks.h"
#include "registers.h"
#include "task.h"
@@ -16,8 +17,15 @@
* each USART, an entry will be NULL if no USART driver is initialized for the
* corresponding hardware instance.
*/
#define STM32_USARTS_MAX 3
static struct usart_config const *configs[STM32_USARTS_MAX];
struct usart_configs usart_get_configs(void)
{
return (struct usart_configs) {configs, ARRAY_SIZE(configs)};
}
static void usart_variant_enable(struct usart_config const *config)
{
/* Use single-bit sampling */

View File

@@ -7,8 +7,6 @@
#include "usart.h"
#define STM32_USARTS_MAX 3
/*
* The STM32L series can have as many as three UARTS. These are the HW configs
* for those UARTS. They can be used to initialize STM32 generic UART configs.

View File

@@ -183,4 +183,28 @@ void usart_set_baud_f(struct usart_config const *config, int frequency_hz);
*/
void usart_clear_tc(struct usart_config const *config);
/*
* Each family implementation provides the usart_get_configs function to access
* a read only list of the configs that are currently enabled.
*/
struct usart_configs {
/*
* The family's usart_config array, entries in the array for disabled
* configs will be NULL, enabled configs will point to the usart_config
* that was enabled. And the following will be true:
*
* configs[i]->hw->index == i;
*/
struct usart_config const * const *configs;
/*
* The total possible number of configs that this family supports.
* This will be the same as the number of usart_hw structs that the
* family provides in its family specific usart header.
*/
size_t count;
};
struct usart_configs usart_get_configs(void);
#endif /* __CROS_EC_USART_H */

View File

@@ -0,0 +1,38 @@
/* 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_read_clear(&(config->state->rx_dropped)),
atomic_read_clear(&(config->state->rx_overrun)));
}
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(usart_info,
command_usart_info,
NULL,
"Display USART info",
NULL);

View File

@@ -478,6 +478,7 @@
#define CONFIG_CMD_TEMP_SENSOR
#define CONFIG_CMD_TIMERINFO
#define CONFIG_CMD_TYPEC
#undef CONFIG_CMD_USART_INFO
#undef CONFIG_CMD_USB_PD_PE
#define CONFIG_CMD_USBMUX