Skip to content

Commit 219ff88

Browse files
vigneshraja123717root
authored andcommitted
uart stop bits configurable
1 parent 707217f commit 219ff88

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/platform/linux-uart.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ struct switchtec_uart{
119119
#define UART_MAX_READ_BYTES 1024
120120
#define RETRY_NUM 3
121121
#define SWITCHTEC_UART_BAUDRATE (B230400)
122+
#define SWITCHTEC_UART_STOP_BITS (2)
122123

123124
static int send_cmd(int fd, const char *fmt, int write_bytes, ...)
124125
{
@@ -461,7 +462,7 @@ static const struct switchtec_ops uart_ops = {
461462
.write_from_gas = uart_write_from_gas,
462463
};
463464

464-
static int set_uart_attribs(int fd, int speed, int parity)
465+
static int set_uart_attribs(int fd, int speed, int parity, int stop_bits)
465466
{
466467
int ret;
467468
struct termios uart_attribs;
@@ -482,7 +483,10 @@ static int set_uart_attribs(int fd, int speed, int parity)
482483
uart_attribs.c_cflag |= (CLOCAL | CREAD);
483484
uart_attribs.c_cflag &= ~(PARENB | PARODD);
484485
uart_attribs.c_cflag |= parity;
485-
uart_attribs.c_cflag |= CSTOPB;
486+
if(stop_bits == 1)
487+
uart_attribs.c_cflag &= ~CSTOPB;
488+
else if (stop_bits == 2)
489+
uart_attribs.c_cflag |= CSTOPB;
486490
uart_attribs.c_cflag &= ~CRTSCTS;
487491
uart_attribs.c_cc[VMIN] = 0;
488492
uart_attribs.c_cc[VTIME] = 50;
@@ -511,7 +515,7 @@ struct switchtec_dev *switchtec_open_uart(int fd)
511515
if (ret)
512516
goto err_close_free;
513517

514-
ret = set_uart_attribs(udev->fd, SWITCHTEC_UART_BAUDRATE, 0);
518+
ret = set_uart_attribs(udev->fd, SWITCHTEC_UART_BAUDRATE, 0, SWITCHTEC_UART_STOP_BITS);
515519
if (ret)
516520
goto err_close_free;
517521

0 commit comments

Comments
 (0)