changeset 348:37b5f94de802

fluid-mnf: sensible target tty specification
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Mar 2020 06:41:44 +0000
parents 21d38dce4d15
children f2eaa4238bef
files fluid-mnf/fluid.c fluid-mnf/fluid.h fluid-mnf/machine.c fluid-mnf/serial.c fluid-mnf/serial.h fluid-mnf/target.c fluid-mnf/target.h
diffstat 7 files changed, 20 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/fluid-mnf/fluid.c	Fri Mar 13 06:27:15 2020 +0000
+++ b/fluid-mnf/fluid.c	Fri Mar 13 06:41:44 2020 +0000
@@ -68,7 +68,7 @@
 int  arg_device_id0 = -1;
 int  arg_device_id1 = -1;
 
-int  arg_uart_port = 1;
+char *arg_uart_ttyport = (char *) 0;
 int  arg_uart_baudrate = 115200;
 char arg_uart_flowcontrol[] = "pn";
 char arg_uart_level_convert = 0;
@@ -523,9 +523,7 @@
             arg_file_list[arg_file_list_size] = NULL;
             break;
         case 'p':
-            arg_uart_port = arg_long_get();
-            if (arg_uart_port < 1 || 24 < arg_uart_port)
-                main_error(E_BADARG);
+            arg_uart_ttyport = optarg;
             break;
         case 'b':
             arg_uart_baudrate = arg_long_get();
@@ -748,7 +746,8 @@
         printf("Command line option values:\n");
         printf("argv[0] = '%s'\n", argv[0]);
         printf("\n");
-        printf("port = %d\n", arg_uart_port);
+        printf("port = %s\n",
+               arg_uart_ttyport ? arg_uart_ttyport : "FLUID_PORT");
         printf("baudrate = %d\n", arg_uart_baudrate);
 
         printf("target_trace_enable = %d\n", arg_target_trace_enable);
--- a/fluid-mnf/fluid.h	Fri Mar 13 06:27:15 2020 +0000
+++ b/fluid-mnf/fluid.h	Fri Mar 13 06:41:44 2020 +0000
@@ -139,7 +139,7 @@
 extern int  arg_device_id0;
 extern int  arg_device_id1;
 
-extern int  arg_uart_port;
+extern char *arg_uart_ttyport;
 extern int  arg_uart_baudrate;
 extern char arg_uart_flowcontrol[2];
 extern char arg_uart_level_convert;
--- a/fluid-mnf/machine.c	Fri Mar 13 06:27:15 2020 +0000
+++ b/fluid-mnf/machine.c	Fri Mar 13 06:41:44 2020 +0000
@@ -204,8 +204,7 @@
             image_map_show();
     }
 
-    if ((error = target_driver_init(arg_uart_port, 115200,
-                                    arg_uart_flowcontrol)) < 0)
+    if ((error = target_driver_init(arg_uart_ttyport, 115200)) < 0)
         main_fatal(error);
 
     if (target_type_set(arg_target_type) != 0)
--- a/fluid-mnf/serial.c	Fri Mar 13 06:27:15 2020 +0000
+++ b/fluid-mnf/serial.c	Fri Mar 13 06:41:44 2020 +0000
@@ -45,8 +45,6 @@
 static int target_fd;
 static struct termios2 target_termios;
 
-static const char port_name_prefix[] = "/dev/ttyUSB";
-
 static void fill_termios(int bps)
 {
 	int termios_baud_code;
@@ -89,12 +87,19 @@
 	target_termios.c_ospeed = bps;
 }
 
-int serial_init(int uart, int bps, char *flowcontrol)
+int serial_init(char *ttyport, int bps)
 {
-	char ttyport[32];
 	static int zero = 0;
 
-	sprintf(ttyport, "%s%d", port_name_prefix, uart);
+	if (!ttyport) {
+		ttyport = getenv("FLUID_PORT");
+		if (!ttyport) {
+			fprintf(stderr,
+"fluid-mnf error: target tty port must be specified with -p or FLUID_PORT=\n");
+			exit(-E_BADARG);
+		}
+	}
+
 	target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
 	if (target_fd < 0)
 		return E_OS + E_UART_INIT;
--- a/fluid-mnf/serial.h	Fri Mar 13 06:27:15 2020 +0000
+++ b/fluid-mnf/serial.h	Fri Mar 13 06:41:44 2020 +0000
@@ -13,7 +13,7 @@
  *
  ******************************************************************************/
 
-int serial_init(int uart, int baudrate, char *flowcontrol);
+int serial_init(char *ttyport, int baudrate);
 int serial_is_baudrate(int bps);
 int serial_baudrate_set(int baudrate);
 int serial_baudrate_get(void);
--- a/fluid-mnf/target.c	Fri Mar 13 06:27:15 2020 +0000
+++ b/fluid-mnf/target.c	Fri Mar 13 06:41:44 2020 +0000
@@ -90,11 +90,11 @@
     serial_recv_reset();
 }
 
-int target_driver_init(int uart, int baudrate, char *flowcontrol)
+int target_driver_init(char *ttyport, int baudrate)
 {
     int rc;
 
-    rc = serial_init(uart, baudrate, flowcontrol);
+    rc = serial_init(ttyport, baudrate);
     if (rc < 0)
         return rc;
 
--- a/fluid-mnf/target.h	Fri Mar 13 06:27:15 2020 +0000
+++ b/fluid-mnf/target.h	Fri Mar 13 06:41:44 2020 +0000
@@ -13,7 +13,7 @@
 
 int target_uart_baudrate_divider_get(int clk, int bps);
 
-int target_driver_init(int uart, int baudrate, char *flowcontrol);
+int target_driver_init(char *ttyport, int baudrate);
 int target_driver_baudrate(int baudrate);
 
 int target_send(char *buf, int size);