FreeCalypso > hg > freecalypso-reveng
comparison fluid-mnf/serial.c @ 348:37b5f94de802
fluid-mnf: sensible target tty specification
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 13 Mar 2020 06:41:44 +0000 |
parents | 2bd27d940023 |
children | 49fe64a5e207 |
comparison
equal
deleted
inserted
replaced
347:21d38dce4d15 | 348:37b5f94de802 |
---|---|
43 ******************************************************************************/ | 43 ******************************************************************************/ |
44 | 44 |
45 static int target_fd; | 45 static int target_fd; |
46 static struct termios2 target_termios; | 46 static struct termios2 target_termios; |
47 | 47 |
48 static const char port_name_prefix[] = "/dev/ttyUSB"; | |
49 | |
50 static void fill_termios(int bps) | 48 static void fill_termios(int bps) |
51 { | 49 { |
52 int termios_baud_code; | 50 int termios_baud_code; |
53 | 51 |
54 switch (bps) { | 52 switch (bps) { |
87 target_termios.c_cc[VTIME] = 0; | 85 target_termios.c_cc[VTIME] = 0; |
88 target_termios.c_ispeed = bps; | 86 target_termios.c_ispeed = bps; |
89 target_termios.c_ospeed = bps; | 87 target_termios.c_ospeed = bps; |
90 } | 88 } |
91 | 89 |
92 int serial_init(int uart, int bps, char *flowcontrol) | 90 int serial_init(char *ttyport, int bps) |
93 { | 91 { |
94 char ttyport[32]; | |
95 static int zero = 0; | 92 static int zero = 0; |
96 | 93 |
97 sprintf(ttyport, "%s%d", port_name_prefix, uart); | 94 if (!ttyport) { |
95 ttyport = getenv("FLUID_PORT"); | |
96 if (!ttyport) { | |
97 fprintf(stderr, | |
98 "fluid-mnf error: target tty port must be specified with -p or FLUID_PORT=\n"); | |
99 exit(-E_BADARG); | |
100 } | |
101 } | |
102 | |
98 target_fd = open(ttyport, O_RDWR|O_NONBLOCK); | 103 target_fd = open(ttyport, O_RDWR|O_NONBLOCK); |
99 if (target_fd < 0) | 104 if (target_fd < 0) |
100 return E_OS + E_UART_INIT; | 105 return E_OS + E_UART_INIT; |
101 ioctl(target_fd, TIOCEXCL); | 106 ioctl(target_fd, TIOCEXCL); |
102 fill_termios(bps); | 107 fill_termios(bps); |