summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2015-07-28 15:11:28 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-08-24 19:08:30 +0000
commit16f63703c9ccc46ec48abcc586a595456e99fc9a (patch)
tree17dc3fa9b72217675e64507facddb7395e91390c
parentf7fa6248bf170d2fffbf3fb067b6ed40f0a4d55f (diff)
downloadchrome-ec-16f63703c9ccc46ec48abcc586a595456e99fc9a.tar.gz
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>
-rw-r--r--board/discovery-stm32f072/board.h1
-rw-r--r--board/discovery/board.h1
-rw-r--r--chip/stm32/build.mk1
-rw-r--r--chip/stm32/usart-stm32f0.c8
-rw-r--r--chip/stm32/usart-stm32f0.h2
-rw-r--r--chip/stm32/usart-stm32f3.c8
-rw-r--r--chip/stm32/usart-stm32f3.h2
-rw-r--r--chip/stm32/usart-stm32l.c8
-rw-r--r--chip/stm32/usart-stm32l.h2
-rw-r--r--chip/stm32/usart.h24
-rw-r--r--chip/stm32/usart_info_command.c38
-rw-r--r--include/config.h1
12 files changed, 90 insertions, 6 deletions
diff --git a/board/discovery-stm32f072/board.h b/board/discovery-stm32f072/board.h
index 2e57167604..9a6fd7905d 100644
--- a/board/discovery-stm32f072/board.h
+++ b/board/discovery-stm32f072/board.h
@@ -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
diff --git a/board/discovery/board.h b/board/discovery/board.h
index c66a21eac9..f66f7231fb 100644
--- a/board/discovery/board.h
+++ b/board/discovery/board.h
@@ -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
diff --git a/chip/stm32/build.mk b/chip/stm32/build.mk
index 0cfd72b93f..0af797f0e0 100644
--- a/chip/stm32/build.mk
+++ b/chip/stm32/build.mk
@@ -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
diff --git a/chip/stm32/usart-stm32f0.c b/chip/stm32/usart-stm32f0.c
index f5f6c910e6..4b24e49642 100644
--- a/chip/stm32/usart-stm32f0.c
+++ b/chip/stm32/usart-stm32f0.c
@@ -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)
{
/*
diff --git a/chip/stm32/usart-stm32f0.h b/chip/stm32/usart-stm32f0.h
index 4c4e9ad93e..74ae71622c 100644
--- a/chip/stm32/usart-stm32f0.h
+++ b/chip/stm32/usart-stm32f0.h
@@ -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.
diff --git a/chip/stm32/usart-stm32f3.c b/chip/stm32/usart-stm32f3.c
index 9484fcdbd7..a6c7fc8991 100644
--- a/chip/stm32/usart-stm32f3.c
+++ b/chip/stm32/usart-stm32f3.c
@@ -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;
diff --git a/chip/stm32/usart-stm32f3.h b/chip/stm32/usart-stm32f3.h
index 9399b339a2..2e26a6bb33 100644
--- a/chip/stm32/usart-stm32f3.h
+++ b/chip/stm32/usart-stm32f3.h
@@ -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.
diff --git a/chip/stm32/usart-stm32l.c b/chip/stm32/usart-stm32l.c
index 0ac9d092b2..a42eab41ff 100644
--- a/chip/stm32/usart-stm32l.c
+++ b/chip/stm32/usart-stm32l.c
@@ -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 */
diff --git a/chip/stm32/usart-stm32l.h b/chip/stm32/usart-stm32l.h
index ca97bb0912..f0ffdf4c48 100644
--- a/chip/stm32/usart-stm32l.h
+++ b/chip/stm32/usart-stm32l.h
@@ -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.
diff --git a/chip/stm32/usart.h b/chip/stm32/usart.h
index a274aa8dce..8db3558b50 100644
--- a/chip/stm32/usart.h
+++ b/chip/stm32/usart.h
@@ -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 */
diff --git a/chip/stm32/usart_info_command.c b/chip/stm32/usart_info_command.c
new file mode 100644
index 0000000000..7b949b10c6
--- /dev/null
+++ b/chip/stm32/usart_info_command.c
@@ -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);
diff --git a/include/config.h b/include/config.h
index 86494f1900..2aa79945ec 100644
--- a/include/config.h
+++ b/include/config.h
@@ -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