1 /* Remote serial interface for local (hardwired) serial ports for Macintosh.
2 Copyright 1994, 2000 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Stan Shebs.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
27 /* This is the regular Mac Serial.h, but copied to a different name
28 so as not to get confused with the GDB serial.h above. */
29 #include "MacSerial.h"
31 /* This is unused for now. We just return a placeholder. */
38 static int mac_open PARAMS ((serial_t scb, const char *name));
39 static void mac_raw PARAMS ((serial_t scb));
40 static int mac_readchar PARAMS ((serial_t scb, int timeout));
41 static int mac_setbaudrate PARAMS ((serial_t scb, int rate));
42 static int mac_write PARAMS ((serial_t scb, const char *str, int len));
43 static void mac_close PARAMS ((serial_t scb));
44 static serial_ttystate mac_get_tty_state PARAMS ((serial_t scb));
45 static int mac_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
46 static char *aptr PARAMS ((short p));
51 char *mac_input_buffer;
52 char *mac_output_buffer;
61 /* Alloc buffer space first - that way any allocation failures are
62 intercepted before the serial driver gets involved. */
63 if (mac_input_buffer == NULL)
64 mac_input_buffer = (char *) xmalloc (4096);
65 /* Match on a name and open a port. */
66 if (strcmp (name, "modem") == 0)
68 err = OpenDriver ("\p.AIn", &input_refnum);
73 err = OpenDriver ("\p.AOut", &output_refnum);
76 CloseDriver (input_refnum);
80 else if (strcmp (name, "printer") == 0)
82 err = OpenDriver ("\p.BIn", &input_refnum);
87 err = OpenDriver ("\p.BOut", &output_refnum);
90 CloseDriver (input_refnum);
99 error ("You must specify a valid serial port name; your choices are `modem' or `printer'.");
103 /* We got something open. */
104 if (1 /* using custom buffer */ )
105 SerSetBuf (input_refnum, mac_input_buffer, 4096);
106 /* Set to a GDB-preferred state. */
107 SerReset (input_refnum, stop10 | noParity | data8 | baud9600);
108 SerReset (output_refnum, stop10 | noParity | data8 | baud9600);
111 struct SerShk *handshake;
113 cb.ioCRefNum = output_refnum;
115 handshake = (struct SerShk *) &cb.csParam[0];
124 err = PBControl ((ParmBlkPtr) & cb, 0);
144 /* Always effectively in raw mode. */
147 /* Read a character with user-specified timeout. TIMEOUT is number of seconds
148 to wait, or -1 to wait forever. Use timeout of 0 to effect a poll. Returns
149 char if successful. Returns -2 if timeout expired, EOF if line dropped
150 dead, or -3 for any other error (see errno in that case). */
153 mac_readchar (scb, timeout)
158 /* time_t */ unsigned long start_time, now;
163 if (scb->bufcnt-- > 0)
170 cb.ioCRefNum = input_refnum;
172 err = PBStatus ((ParmBlkPtr) & cb, 0);
175 n = *((long *) &cb.csParam[0]);
178 pb.ioRefNum = input_refnum;
179 pb.ioBuffer = (Ptr) (scb->buf);
180 pb.ioReqCount = (n > 64 ? 64 : n);
181 err = PBRead ((ParmBlkPtr) & pb, 0);
184 scb->bufcnt = pb.ioReqCount;
186 scb->bufp = scb->buf;
189 else if (timeout == 0)
190 return SERIAL_TIMEOUT;
191 else if (timeout == -1)
196 if (now > start_time + timeout)
197 return SERIAL_TIMEOUT;
203 /* mac_{get set}_tty_state() are both dummys to fill out the function
204 vector. Someday, they may do something real... */
206 static serial_ttystate
207 mac_get_tty_state (scb)
210 struct mac_ttystate *state;
212 state = (struct mac_ttystate *) xmalloc (sizeof *state);
214 return (serial_ttystate) state;
218 mac_set_tty_state (scb, ttystate)
220 serial_ttystate ttystate;
226 mac_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
228 serial_ttystate new_ttystate;
229 serial_ttystate old_ttystate;
235 mac_print_tty_state (serial_t scb,
236 serial_ttystate ttystate,
237 struct ui_file *stream)
239 /* Nothing to print. */
243 /* If there is a tricky formula to relate real baud rates
244 to what the serial driver wants, we should use it. Until
245 we get one, this table will have to do. */
252 mac_baud_rate_table[] =
308 mac_set_baud_rate (scb, rate)
314 for (i = 0; mac_baud_rate_table[i].real_rate != 0; ++i)
316 if (mac_baud_rate_table[i].real_rate == rate)
318 bits = mac_baud_rate_table[i].bits;
322 SerReset (input_refnum, stop10 | noParity | data8 | bits);
323 SerReset (output_refnum, stop10 | noParity | data8 | bits);
327 mac_set_stop_bits (scb, num)
334 int first_mac_write = 0;
337 mac_write (scb, str, len)
345 if (first_mac_write++ < 4)
349 pb.ioRefNum = output_refnum;
350 pb.ioBuffer = (Ptr) str;
352 err = PBWrite ((ParmBlkPtr) & pb, 0);
361 mac_close (serial_t scb)
365 if (1 /* custom buffer */ )
366 SerSetBuf (input_refnum, mac_input_buffer, 0);
367 CloseDriver (input_refnum);
372 if (0 /* custom buffer */ )
373 SerSetBuf (input_refnum, mac_output_buffer, 0);
374 CloseDriver (output_refnum);
379 static struct serial_ops mac_ops =
387 mac_noop, /* flush output */
388 mac_noop, /* flush input */
389 mac_noop, /* send break -- currently only for nindy */
394 mac_noflush_set_tty_state,
397 mac_noop, /* wait for output to drain */
401 _initialize_ser_mac ()
403 serial_add_interface (&mac_ops);