Private
Public Access
2
0

UART: Fixing UART issues on UP2

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik
2018-03-14 12:27:46 -07:00
parent acff725d93
commit cfda9c99d7
3 changed files with 48 additions and 5 deletions

View File

@@ -168,6 +168,16 @@ mraa_result_t mraa_atoi(char* intStr, int* value);
*/
int mraa_find_i2c_bus_pci(const char* pci_device, const char *pci_id, const char* adapter_name);
/**
* helper function to find the uart device based on pci data
*
* @param pci_dev_path points to the location of tty device which corresponds
* to the uart device available on the platform
* @param dev_name as retrieved from pci_dev_path
* @return Result of the operation
*/
mraa_result_t mraa_find_uart_bus_pci(const char* pci_dev_path, char** dev_name);
#if defined(IMRAA)
/**
* read Imraa subplatform lock file, caller is responsible to free return

View File

@@ -282,21 +282,22 @@ mraa_deinit()
}
free(sub_plat);
}
#if defined(JSONPLAT)
if (plat->platform_type == MRAA_JSON_PLATFORM) {
// Free the platform name
free(plat->platform_name);
plat->platform_name = NULL;
}
int i = 0;
// Free the UART device path
if ((plat->platform_type == MRAA_JSON_PLATFORM) || (plat->platform_type == MRAA_UP2)) {
for (i = 0; i < plat->uart_dev_count; i++) {
if (plat->uart_dev[i].device_path != NULL) {
free(plat->uart_dev[i].device_path);
}
}
}
#endif
free(plat);
plat = NULL;
@@ -1135,6 +1136,34 @@ mraa_link_targets(const char* filename, const char* targetname)
}
}
mraa_result_t
mraa_find_uart_bus_pci(const char* pci_dev_path, char** dev_name)
{
char path[PATH_MAX];
const int max_allowable_len = 16;
snprintf(path, PATH_MAX - 1, "%s", pci_dev_path);
if (!mraa_file_exist(path)) {
return MRAA_ERROR_INVALID_PARAMETER;
}
struct dirent** namelist;
int n = scandir(path, &namelist, NULL, alphasort);
if (n <= 0) {
syslog(LOG_ERR, "Failed to find expected UART bus: %s", strerror(errno));
return MRAA_ERROR_INVALID_RESOURCE;
}
*dev_name = (char*) malloc(sizeof(char) * max_allowable_len);
snprintf(*dev_name, max_allowable_len, "/dev/%s", namelist[n - 1]->d_name);
while (n--) {
free(namelist[n]);
}
free(namelist);
syslog(LOG_INFO, "UART device: %s selected for initialization", *dev_name);
return MRAA_SUCCESS;
}
static int
mraa_count_i2c_files(const char* path, const struct stat* sb, int flag, struct FTW* ftwb)
{

View File

@@ -242,7 +242,11 @@ mraa_up2_board()
// Configure UART
b->uart_dev_count = 0;
b->def_uart_dev = 0;
b->uart_dev[0].device_path = "/dev/ttyS1";
// setting up a default path
if (mraa_find_uart_bus_pci("/sys/bus/pci/devices/0000:00:18.1/dw-apb-uart.9/tty/",
&(b->uart_dev[0].device_path)) != MRAA_SUCCESS) {
goto error;
}
// Configure UART #1 (default)
mraa_up2_get_pin_index(b, "UART_RX", &(b->uart_dev[0].rx));