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 port. 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
;
201 /* mac_{get set}_tty_state() are both dummys to fill out the function
202 vector. Someday, they may do something real... */
204 static serial_ttystate
205 mac_get_tty_state (scb
)
208 struct mac_ttystate
*state
;
210 state
= (struct mac_ttystate
*) xmalloc (sizeof *state
);
212 return (serial_ttystate
) state
;
216 mac_set_tty_state (scb
, ttystate
)
218 serial_ttystate ttystate
;
224 mac_noflush_set_tty_state (scb
, new_ttystate
, old_ttystate
)
226 serial_ttystate new_ttystate
;
227 serial_ttystate old_ttystate
;
233 mac_print_tty_state (scb
, ttystate
)
235 serial_ttystate ttystate
;
237 /* Nothing to print. */
242 mac_set_baud_rate (scb
, rate
)
249 int first_mac_write
= 0;
252 mac_write (scb
, str
, len
)
260 if (first_mac_write
++ < 4)
264 pb
.ioRefNum
= output_refnum
;
265 pb
.ioBuffer
= (Ptr
) str
;
267 err
= PBWrite ((ParmBlkPtr
) &pb
, 0);
275 sec_sleep (int timeout
)
277 unsigned long start_time
, now
;
284 if (now
> start_time
+ timeout
)
290 mac_close (serial_t scb
)
294 if (1 /* custom buffer */)
295 SerSetBuf (input_refnum
, mac_input_buffer
, 0);
296 CloseDriver (input_refnum
);
301 if (0 /* custom buffer */)
302 SetSetBuf (input_refnum
, mac_output_buffer
, 0);
303 CloseDriver (output_refnum
);
308 static struct serial_ops mac_ops
=
316 mac_noop
, /* flush output */
317 mac_noop
, /* flush input */
318 mac_noop
, /* send break -- currently only for nindy */
323 mac_noflush_set_tty_state
,
328 _initialize_ser_mac ()
330 serial_add_interface (&mac_ops
);