mibuild/sim: get serial dev from /tmp/simserial
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 9 Mar 2015 23:42:54 +0000 (00:42 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 9 Mar 2015 23:42:54 +0000 (00:42 +0100)
mibuild/sim/dut_tb.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 4cce650..794e64f
@@ -52,7 +52,7 @@ struct sim {
        char rx_serial_data;
        char rx_serial_presented;
 #else
-       const char *serial_dev;
+       char serial_dev[64];
        int serial_fd;
        unsigned char serial_rx_data;
        unsigned char serial_tx_data;
@@ -216,11 +216,20 @@ int console_service(struct sim *s)
        return 0;
 }
 #else
-void console_open(struct sim *s, const char *dev)
+void console_init(struct sim *s)
 {
-       s->serial_fd = open(dev, O_RDWR);
+       FILE *f;
+       f = fopen("/tmp/simserial","r");
+       fscanf(f, "%[^\n]", s->serial_dev);
+       fclose(f);
+       return;
+}
+
+void console_open(struct sim *s)
+{
+       s->serial_fd = open(s->serial_dev, O_RDWR);
        if(s->serial_fd < 0) {
-               fprintf (stderr, " Could not open dev %s\n", s->serial_dev);
+               fprintf(stderr, " Could not open dev %s\n", s->serial_dev);
                return;
        }
        return;
@@ -352,7 +361,8 @@ int main(int argc, char **argv, char **env)
        sim_init(&s);
 
 #ifdef WITH_SERIAL_PTY
-       console_open(&s, "/dev/pts/3"); // XXX get this from /tmp/simserial
+       console_init(&s);
+       console_open(&s);
 #endif
 
 #ifdef WITH_ETH