Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/fix uart flow control #685

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/mraa_internal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 24 additions & 2 deletions src/uart/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
* Contributions: Jon Trulson <jtrulson@ics.com>
* Brendan le Foll <brendan.le.foll@intel.com>
* Nicola Lunghi <nicola.lunghi@emutex.com>
* Copyright (c) 2014 - 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -799,5 +823,3 @@ mraa_uart_data_available(mraa_uart_context dev, unsigned int millis)
return 0;
}
}