diff --git a/api/mraa/common.h b/api/mraa/common.h index ff4ee14..8456b8d 100644 --- a/api/mraa/common.h +++ b/api/mraa/common.h @@ -149,6 +149,7 @@ typedef struct { unsigned int index; /**< ID as exposed in the system */ int rx; /**< uart rx */ int tx; /**< uart tx */ + char* device_path; /**< To store "/dev/ttyS1" for example */ /*@}*/ } mraa_uart_dev_t; diff --git a/api/mraa/uart.h b/api/mraa/uart.h index efb5e04..351a30b 100644 --- a/api/mraa/uart.h +++ b/api/mraa/uart.h @@ -54,6 +54,15 @@ typedef struct _uart* mraa_uart_context; */ mraa_uart_context mraa_uart_init(int uart); +/** + * Get Char pointer with tty device path within Linux + * For example. Could point to "/dev/ttyS0" + * + * @param dev uart context + * @return char pointer of device path + */ +char* mraa_uart_get_dev_path(mraa_uart_context dev); + #ifdef __cplusplus } #endif diff --git a/api/mraa/uart.hpp b/api/mraa/uart.hpp index 7bf807a..b86643d 100644 --- a/api/mraa/uart.hpp +++ b/api/mraa/uart.hpp @@ -55,6 +55,17 @@ class Uart { ~Uart() { return; } + + /** + * Get string with tty device path within Linux + * For example. Could point to "/dev/ttyS0" + * + * @return char pointer of device path + */ + std::string getDevicePath() { + std::string ret_val(mraa_uart_get_dev_path(m_uart)); + return ret_val; + } private: mraa_uart_context m_uart; }; diff --git a/include/mraa_internal_types.h b/include/mraa_internal_types.h index 34b7607..977bc36 100644 --- a/include/mraa_internal_types.h +++ b/include/mraa_internal_types.h @@ -91,5 +91,6 @@ struct _aio { struct _uart { /*@{*/ int index; /**< the uart index, as known to the os. */ + char* path; /**< the uart device path. */ /*@}*/ }; diff --git a/src/arm/raspberry_pi_b.c b/src/arm/raspberry_pi_b.c index afff2cb..2bf2c7c 100644 --- a/src/arm/raspberry_pi_b.c +++ b/src/arm/raspberry_pi_b.c @@ -28,6 +28,8 @@ #include "common.h" #include "arm/raspberry_pi_b.h" +#define UART_DEV_PATH "/dev/ttyAMA0" + mraa_board_t* mraa_raspberry_pi_b() { @@ -178,6 +180,17 @@ mraa_raspberry_pi_b() b->def_uart_dev = 0; b->uart_dev[0].rx = 10; b->uart_dev[0].tx = 8; + int uart_path_length = strlen(UART_DEV_PATH) + 1; + b->uart_dev[0].device_path = (char*) malloc(sizeof(char) * uart_path_length); + if (b->uart_dev[0].device_path == NULL) { + goto error; + } + strncpy(b->uart_dev[0].device_path, UART_DEV_PATH, uart_path_length); return b; + +error: + syslog(LOG_CRIT, "raspberry pi: board failed to initialise"); + free(b); + return NULL; } diff --git a/src/uart/uart.c b/src/uart/uart.c index 2828986..d1b811e 100644 --- a/src/uart/uart.c +++ b/src/uart/uart.c @@ -83,6 +83,7 @@ mraa_uart_init(int index) memset(dev, 0, sizeof(struct _uart)); dev->index = index; + dev->path = plat->uart_dev[index].device_path; if (advance_func->uart_init_post != NULL) { mraa_result_t ret = advance_func->uart_init_post(dev); if (ret != MRAA_SUCCESS) { @@ -93,3 +94,17 @@ mraa_uart_init(int index) return dev; } + +char* +mraa_uart_get_dev_path(mraa_uart_context dev) +{ + if (dev == NULL) { + syslog(LOG_ERR, "uart: get_device_path failed, context is NULL"); + return "ERROR:CONTEXT_IS_NULL"; + } + if (dev->path == NULL) { + syslog(LOG_ERR, "uart: device path undefined"); + return "ERROR:PATH_NOT_SET"; + } + return dev->path; +} diff --git a/src/x86/intel_de3815.c b/src/x86/intel_de3815.c index 6b3071d..970bf6a 100644 --- a/src/x86/intel_de3815.c +++ b/src/x86/intel_de3815.c @@ -140,6 +140,8 @@ mraa_intel_de3815() b->spi_bus[0].miso = 12; b->spi_bus[0].sclk = 13; + b->uart_dev_count = 0; + return b; error: syslog(LOG_CRIT, "de3815: Platform failed to initialise"); diff --git a/src/x86/intel_edison_fab_c.c b/src/x86/intel_edison_fab_c.c index e65e7a4..d2c4cd4 100644 --- a/src/x86/intel_edison_fab_c.c +++ b/src/x86/intel_edison_fab_c.c @@ -40,6 +40,7 @@ // Might not always be correct. First thing to check if mmap stops // working. Check the device for 0x1199 and Intel Vendor (0x8086) #define MMAP_PATH "/sys/devices/pci0000:00/0000:00:0c.0/resource0" +#define UART_DEV_PATH "/dev/ttyMFD1" typedef struct { int sysfs; @@ -1365,6 +1366,13 @@ mraa_intel_edison_fab_c() b->uart_dev[0].rx = 0; b->uart_dev[0].tx = 1; + int uart_path_length = strlen(UART_DEV_PATH) + 1; + b->uart_dev[0].device_path = (char*) malloc(sizeof(char) * uart_path_length); + if (b->uart_dev[0].device_path == NULL) { + goto error; + } + strncpy(b->uart_dev[0].device_path, UART_DEV_PATH, uart_path_length); + int il; for (il =0; il < MRAA_INTEL_EDISON_PINCOUNT; il++) { pinmodes[il].gpio.sysfs = -1; diff --git a/src/x86/intel_galileo_rev_d.c b/src/x86/intel_galileo_rev_d.c index 2f4fb55..dbfb461 100644 --- a/src/x86/intel_galileo_rev_d.c +++ b/src/x86/intel_galileo_rev_d.c @@ -405,11 +405,25 @@ mraa_intel_galileo_rev_d() b->spi_bus[0].miso = 12; b->spi_bus[0].sclk = 13; + int uart_path_length = strlen("/dev/ttyS0") + 1; + + b->uart_dev_count = 2; b->def_uart_dev = 0; b->uart_dev[0].rx = 0; b->uart_dev[0].tx = 1; + b->uart_dev[0].device_path = (char*) malloc(sizeof(char) * uart_path_length); + if (b->uart_dev[0].device_path == NULL) { + goto error; + } + strncpy(b->uart_dev[0].device_path, "/dev/ttyS0", uart_path_length); + b->uart_dev[1].rx = -1; b->uart_dev[1].tx = -1; + b->uart_dev[1].device_path = (char*) malloc(sizeof(char) * uart_path_length); + if (b->uart_dev[1].device_path == NULL) { + goto error; + } + strncpy(b->uart_dev[1].device_path, "/dev/ttyS1", uart_path_length); return b; error: diff --git a/src/x86/intel_galileo_rev_g.c b/src/x86/intel_galileo_rev_g.c index d0eceec..cd83041 100644 --- a/src/x86/intel_galileo_rev_g.c +++ b/src/x86/intel_galileo_rev_g.c @@ -746,10 +746,17 @@ mraa_intel_galileo_gen2() b->spi_bus[0].miso = 12; b->spi_bus[0].sclk = 13; + int uart_path_length = strlen("/dev/ttyS0") + 1; + b->uart_dev_count = 1; b->def_uart_dev = 0; b->uart_dev[0].rx = 0; b->uart_dev[0].tx = 1; + b->uart_dev[0].device_path = (char*) malloc(sizeof(char) * uart_path_length); + if (b->uart_dev[0].device_path == NULL) { + goto error; + } + strncpy(b->uart_dev[0].device_path, "/dev/ttyS0", uart_path_length); return b; error: diff --git a/src/x86/intel_minnow_max.c b/src/x86/intel_minnow_max.c index e1a1320..dab8312 100644 --- a/src/x86/intel_minnow_max.c +++ b/src/x86/intel_minnow_max.c @@ -181,6 +181,8 @@ mraa_intel_minnow_max() b->spi_bus[0].miso = 7; b->spi_bus[0].sclk = 11; + b->uart_dev_count = 0; + return b; error: syslog(LOG_CRIT, "minnowmax: Platform failed to initialise");