1 /* Remote serial interface for local (hardwired) serial ports for Macintosh.
2 Copyright 1994 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 /* This is the regular Mac Serial.h, but copied to a different name
27 so as not to get confused with the GDB serial.h above. */
28 #include "MacSerial.h"
30 /* This is unused for now. We just return a placeholder. */
37 static int mac_open
PARAMS ((serial_t scb
, const char *name
));
38 static void mac_raw
PARAMS ((serial_t scb
));
39 static int mac_readchar
PARAMS ((serial_t scb
, int timeout
));
40 static int mac_setbaudrate
PARAMS ((serial_t scb
, int rate
));
41 static int mac_write
PARAMS ((serial_t scb
, const char *str
, int len
));
42 static void mac_close
PARAMS ((serial_t scb
));
43 static serial_ttystate mac_get_tty_state
PARAMS ((serial_t scb
));
44 static int mac_set_tty_state
PARAMS ((serial_t scb
, serial_ttystate state
));
45 static char *aptr
PARAMS ((short p
));
50 char *mac_input_buffer
;
51 char *mac_output_buffer
;
60 /* Alloc buffer space first - that way any allocation failures are
61 intercepted before the serial driver gets involved. */
62 if (mac_input_buffer
== NULL
)
63 mac_input_buffer
= (char *) xmalloc (256);
64 /* Match on a name and open a port. */
65 if (strcmp (name
, "modem") == 0)
67 err
= OpenDriver ("\p.AIn", &input_refnum
);
72 err
= OpenDriver ("\p.AOut", &output_refnum
);
75 CloseDriver (input_refnum
);
79 else if (strcmp (name
, "printer") == 0)
81 err
= OpenDriver ("\p.BIn", &input_refnum
);
86 err
= OpenDriver ("\p.BOut", &output_refnum
);
89 CloseDriver (input_refnum
);
98 error ("You must specify a valid serial port name; your choices are `modem' or `printer'.");
102 /* We got something open. */
103 if (1 /* using custom buffer */)
104 SerSetBuf (input_refnum
, mac_input_buffer
, 256);
105 /* Set to a GDB-preferred state. */
106 SerReset (input_refnum
, stop10
|noParity
|data8
|baud9600
);
107 SerReset (output_refnum
, stop10
|noParity
|data8
|baud9600
);
110 struct SerShk
*handshake
;
112 cb
.ioCRefNum
= output_refnum
;
114 handshake
= (struct SerShk
*) &cb
.csParam
[0];
123 err
= PBControl ((ParmBlkPtr
) &cb
, 0);
143 /* Always effectively in raw mode. */
146 /* Read a character with user-specified timeout. TIMEOUT is number of seconds
147 to wait, or -1 to wait forever. Use timeout of 0 to effect a poll. Returns
148 char if successful. Returns -2 if timeout expired, EOF if line dropped
149 dead, or -3 for any other error (see errno in that case). */
152 mac_readchar (scb
, timeout
)
157 /* time_t */ unsigned long start_time
, now
;
162 if (scb
->bufcnt
-- > 0)
169 cb
.ioCRefNum
= input_refnum
;
171 err
= PBStatus ((ParmBlkPtr
) &cb
, 0);
174 n
= *((long *) &cb
.csParam
[0]);
177 pb
.ioRefNum
= input_refnum
;
178 pb
.ioBuffer
= (Ptr
) (scb
->buf
);
179 pb
.ioReqCount
= (n
> 64 ? 64 : n
);
180 err
= PBRead ((ParmBlkPtr
) &pb
, 0);
183 scb
->bufcnt
= pb
.ioReqCount
;
185 scb
->bufp
= scb
->buf
;
188 else if (timeout
== 0)
189 return SERIAL_TIMEOUT
;
190 else if (timeout
== -1)
195 if (now
> start_time
+ timeout
)
196 return SERIAL_TIMEOUT
;
202 /* mac_{get set}_tty_state() are both dummys to fill out the function
203 vector. Someday, they may do something real... */
205 static serial_ttystate
206 mac_get_tty_state (scb
)
209 struct mac_ttystate
*state
;
211 state
= (struct mac_ttystate
*) xmalloc (sizeof *state
);
213 return (serial_ttystate
) state
;
217 mac_set_tty_state (scb
, ttystate
)
219 serial_ttystate ttystate
;
225 mac_noflush_set_tty_state (scb
, new_ttystate
, old_ttystate
)
227 serial_ttystate new_ttystate
;
228 serial_ttystate old_ttystate
;
234 mac_print_tty_state (scb
, ttystate
)
236 serial_ttystate ttystate
;
238 /* Nothing to print. */
242 /* If there is a tricky formula to relate real baud rates
243 to what the serial driver wants, we should use it. Until
244 we get one, this table will have to do. */
249 } mac_baud_rate_table
[] = {
250 { 57600, baud57600
},
252 { 19200, baud19200
},
266 mac_set_baud_rate (scb
, rate
)
272 for (i
= 0; mac_baud_rate_table
[i
].real_rate
!= 0; ++i
)
274 if (mac_baud_rate_table
[i
].real_rate
== rate
)
276 bits
= mac_baud_rate_table
[i
].bits
;
280 SerReset (input_refnum
, stop10
|noParity
|data8
|bits
);
281 SerReset (output_refnum
, stop10
|noParity
|data8
|bits
);
285 mac_set_stop_bits (scb
, num
)
292 int first_mac_write
= 0;
295 mac_write (scb
, str
, len
)
303 if (first_mac_write
++ < 4)
307 pb
.ioRefNum
= output_refnum
;
308 pb
.ioBuffer
= (Ptr
) str
;
310 err
= PBWrite ((ParmBlkPtr
) &pb
, 0);
319 mac_close (serial_t scb
)
323 if (1 /* custom buffer */)
324 SerSetBuf (input_refnum
, mac_input_buffer
, 0);
325 CloseDriver (input_refnum
);
330 if (0 /* custom buffer */)
331 SetSetBuf (input_refnum
, mac_output_buffer
, 0);
332 CloseDriver (output_refnum
);
337 static struct serial_ops mac_ops
=
345 mac_noop
, /* flush output */
346 mac_noop
, /* flush input */
347 mac_noop
, /* send break -- currently only for nindy */
352 mac_noflush_set_tty_state
,
358 _initialize_ser_mac ()
360 serial_add_interface (&mac_ops
);