From 6f906b2b5a7d411c680e4d54e798dcdb3771d69e Mon Sep 17 00:00:00 2001 From: Nicola Lunghi Date: Wed, 3 May 2017 13:33:42 +0100 Subject: [PATCH] Add support for uart flow control Signed-off-by: Nicola Lunghi --- include/mraa_internal_types.h | 2 ++ src/uart/uart.c | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/mraa_internal_types.h b/include/mraa_internal_types.h index 69e73039d..d65ae606c 100644 --- a/include/mraa_internal_types.h +++ b/include/mraa_internal_types.h @@ -372,6 +372,8 @@ typedef struct { unsigned int index; /**< ID as exposed in the system */ int rx; /**< uart rx */ int tx; /**< uart tx */ + int cts; /**< uart cts */ + int rts; /**< uart rts */ char* device_path; /**< To store "/dev/ttyS1" for example */ /*@}*/ } mraa_uart_dev_t; diff --git a/src/uart/uart.c b/src/uart/uart.c index b9c7e1b94..bd90a54be 100644 --- a/src/uart/uart.c +++ b/src/uart/uart.c @@ -2,6 +2,7 @@ * Author: Thomas Ingleby * Contributions: Jon Trulson * Brendan le Foll + * Nicola Lunghi * Copyright (c) 2014 - 2015 Intel Corporation. * * Permission is hereby granted, free of charge, to any person obtaining @@ -609,6 +610,29 @@ mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xonxoff, mraa_bo return dev->advance_func->uart_set_flowcontrol_replace(dev, xonxoff, rtscts); } + if (rtscts) { + // assign the CTS and RTS pin to the uart interface when enabling flow control + if (!plat->no_bus_mux) { + int pos_cts = plat->uart_dev[dev->index].cts; + int pos_rts = plat->uart_dev[dev->index].rts; + + if ((pos_cts >= 0) && (pos_rts >= 0)) { + if (plat->pins[pos_cts].uart.mux_total > 0) { + if (mraa_setup_mux_mapped(plat->pins[pos_cts].uart) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart%i: init: failed to setup muxes for CTS pin", dev->index); + return MRAA_ERROR_FEATURE_NOT_SUPPORTED; + } + } + if (plat->pins[pos_rts].uart.mux_total > 0) { + if (mraa_setup_mux_mapped(plat->pins[pos_rts].uart) != MRAA_SUCCESS) { + syslog(LOG_ERR, "uart%i: init: failed to setup muxes for RTS pin", dev->index); + return MRAA_ERROR_FEATURE_NOT_SUPPORTED; + } + } + } + } + } + // hardware flow control int action = TCIOFF; if (xonxoff) { @@ -799,5 +823,3 @@ mraa_uart_data_available(mraa_uart_context dev, unsigned int millis) return 0; } } - -