#define DEV_PATH_FMT_MAX_SIZE sizeof("/dev/ttyXXX" MAX_d_FMT)
#define DEV_PATH_FMT "%s%d"
+#define UART_INI_PATH "/hal/etc/peripheral-io/uart.ini"
+
/**
* @brief Internal struct for uart context
*/
}
}
+static int peripheral_uart_find_devpath(int port, char *buffer, int len)
+{
+ FILE *fp;
+ char line[128];
+ int key;
+ char value[22];
+
+ fp = fopen(UART_INI_PATH, "r");
+ if (!fp)
+ return -1;
+
+ while (fgets(line, sizeof(line), fp)) {
+ if (sscanf(line, "%d=%21s", &key, value) != 2)
+ continue;
+
+ if (key != port)
+ continue;
+
+ strncpy(buffer, value, len);
+ fclose(fp);
+
+ return 0;
+ }
+
+ fclose(fp);
+
+ return -1;
+}
+
/**
* @brief Initializes uart communication and creates uart handle.
*/
"/dev/ttySAC",
};
- size_t index;
+ size_t index = 0;
+ int retval;
char path[DEV_PATH_FMT_MAX_SIZE] = {0, }; /* space for /dev/ttyXXX%d */
- for (index = 0; index < ARRAY_SIZE(sysfs_uart_path); index++) {
- snprintf(path, sizeof path, DEV_PATH_FMT, sysfs_uart_path[index], port);
- if (access(path, F_OK) == 0)
- break;
+ retval = peripheral_uart_find_devpath(port, path, DEV_PATH_FMT_MAX_SIZE);
+ if (retval < 0 || access(path, F_OK) != 0) {
+ for (index = 0; index < ARRAY_SIZE(sysfs_uart_path); index++) {
+ snprintf(path, sizeof path, DEV_PATH_FMT, sysfs_uart_path[index], port);
+ if (access(path, F_OK) == 0)
+ break;
+ }
}
if (index == ARRAY_SIZE(sysfs_uart_path))