From 1106dea40d3b18fbab2f42a2510d0a7899650db9 Mon Sep 17 00:00:00 2001 From: Nick Sanders Date: Tue, 11 Jul 2017 15:14:37 -0700 Subject: servo_micro: add parity setting Add a control interface to set parity for USB-UART bridge. BRANCH=None BUG=b:37513705 TEST=parity settable on command line or by servod Signed-off-by: Nick Sanders Change-Id: Ib859a70981162be58edfa79c7cb267e0084e05e6 Reviewed-on: https://chromium-review.googlesource.com/564150 Reviewed-by: Nicolas Boichat --- board/servo_micro/board.c | 56 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'board/servo_micro/board.c') diff --git a/board/servo_micro/board.c b/board/servo_micro/board.c index dedfcfdd7a..505a6d628a 100644 --- a/board/servo_micro/board.c +++ b/board/servo_micro/board.c @@ -5,6 +5,7 @@ /* Servo micro board configuration */ #include "common.h" +#include "console.h" #include "ec_version.h" #include "gpio.h" #include "hooks.h" @@ -52,14 +53,15 @@ static struct usart_config const usart2 = usart2_to_usb, usb_to_usart2); -USB_STREAM_CONFIG(usart2_usb, +USB_STREAM_CONFIG_USART_IFACE(usart2_usb, USB_IFACE_USART2_STREAM, USB_STR_USART2_STREAM_NAME, USB_EP_USART2_STREAM, USB_STREAM_RX_SIZE, USB_STREAM_TX_SIZE, usb_to_usart2, - usart2_to_usb) + usart2_to_usb, + usart2) /****************************************************************************** @@ -82,14 +84,15 @@ static struct usart_config const usart3 = usart3_to_usb, usb_to_usart3); -USB_STREAM_CONFIG(usart3_usb, +USB_STREAM_CONFIG_USART_IFACE(usart3_usb, USB_IFACE_USART3_STREAM, USB_STR_USART3_STREAM_NAME, USB_EP_USART3_STREAM, USB_STREAM_RX_SIZE, USB_STREAM_TX_SIZE, usb_to_usart3, - usart3_to_usb) + usart3_to_usb, + usart3) /****************************************************************************** @@ -112,15 +115,56 @@ static struct usart_config const usart4 = usart4_to_usb, usb_to_usart4); -USB_STREAM_CONFIG(usart4_usb, +USB_STREAM_CONFIG_USART_IFACE(usart4_usb, USB_IFACE_USART4_STREAM, USB_STR_USART4_STREAM_NAME, USB_EP_USART4_STREAM, USB_STREAM_RX_SIZE, USB_STREAM_TX_SIZE, usb_to_usart4, - usart4_to_usb) + usart4_to_usb, + usart4) +/****************************************************************************** + * Check parity setting on usarts. + */ +static int command_uart_parity(int argc, char **argv) +{ + int parity, newparity; + struct usart_config const *usart; + char *e; + + if ((argc < 2) || (argc > 3)) + return EC_ERROR_PARAM_COUNT; + + if (!strcasecmp(argv[1], "usart2")) + usart = &usart2; + else if (!strcasecmp(argv[1], "usart3")) + usart = &usart3; + else if (!strcasecmp(argv[1], "usart4")) + usart = &usart4; + else + return EC_ERROR_PARAM1; + + if (argc == 3) { + parity = strtoi(argv[2], &e, 0); + if (*e || (parity < 0) || (parity > 2)) + return EC_ERROR_PARAM2; + + usart_set_parity(usart, parity); + } + + newparity = usart_get_parity(usart); + ccprintf("Parity on %s is %d.\n", argv[1], newparity); + + if ((argc == 3) && (newparity != parity)) + return EC_ERROR_UNKNOWN; + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(parity, command_uart_parity, + "usart[2|3|4] [0|1|2]", + "Set parity on uart"); /****************************************************************************** * Define the strings used in our USB descriptors. -- cgit v1.2.1