1 static char _[] = "@(#)tdfunc.c 5.25 93/10/28 08:44:32, Srini, AMD.";
2 /******************************************************************************
3 * Copyright 1991 Advanced Micro Devices, Inc.
5 * This software is the property of Advanced Micro Devices, Inc (AMD) which
6 * specifically grants the user the right to modify, use and distribute this
7 * software provided this notice is not removed or altered. All other rights
10 * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
11 * SOFTWARE. IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
12 * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
13 * USE OF THIS SOFTWARE.
15 * So that all may benefit from your experience, please report any problems
16 * or suggestions about this software to the 29K Technical Support Center at
17 * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131 in the UK, or
18 * 0031-11-1129 in Japan, toll free. The direct dial number is 512-462-4118.
20 * Advanced Micro Devices, Inc.
21 * 29K Support Products
23 * 5900 E. Ben White Blvd.
26 *****************************************************************************
27 * Engineer: Srini Subramanian.
28 *****************************************************************************
29 * This module contains the functions to initialize, read, and write to the
30 * serial port on an Unix-based machine.
31 *****************************************************************************
34 /* This file contains the Target Dependent Functions used by Minimon's
44 #include <sys/modem.h>
52 /* Serial connection */
54 ** Serial port routines
58 #define BAUD_RATE B9600
61 #define PARITY_ENABLE 0
64 #define CH0_BUFFER_SIZE 1024
69 /* Global for serial */
72 static INT32 in_byte_count=0;
74 extern int BlockCount;
77 ** This function is used to initialize the communication
78 ** channel. This consists of basically opening the com
79 ** port for reading and writing.
81 ** With Sun UNIX, each time the port is opened, the communication
82 ** parameters are reset to default values. These default values for
83 ** the serial port are currently 9600 baud, 7 bits, even parity.
87 init_comm_serial(ignore1, ignore2)
99 int cd; /* carrier detect */
101 /* Open serial port */
102 if ((msg_port = open(tip_config.comm_port, O_NDELAY|O_RDWR)) == -1) {
107 if (strcmp(tip_config.baud_rate, "300") == 0)
110 if (strcmp(tip_config.baud_rate, "600") == 0)
113 if (strcmp(tip_config.baud_rate, "1200") == 0)
116 if (strcmp(tip_config.baud_rate, "2400") == 0)
119 if (strcmp(tip_config.baud_rate, "4800") == 0)
122 if (strcmp(tip_config.baud_rate, "9600") == 0)
125 if (strcmp(tip_config.baud_rate, "19200") == 0)
128 if (strcmp(tip_config.baud_rate, "38400") == 0)
134 /* Set up new parameters */
135 /* Get termio (for modification) */
136 result = ioctl(msg_port, TCGETA, &tbuf);
141 ** Note: On a Sun III, the port comes up at 9600 baud,
142 ** 7 bits, even parity, with read enabled. We will change
143 ** this to 8 bits, no parity (with RTS/CTS handshaking).
144 ** We will also set I/O to "raw" mode.
147 /* Set up new parameters */
150 tbuf.c_cflag = (baud | CHAR_SIZE | STOP_BITS | CREAD |
151 PARITY_ENABLE | PARITY );
153 tbuf.c_cc[VMIN] = 0; /* Number of characters to satisfy read */
155 tbuf.c_cc[VTIME] = 100; /* intercharacter timer interval in seconds */
157 tbuf.c_cc[VTIME] = 1; /* intercharacter timer interval in seconds */
160 /* Set termio to new mode */
161 result = ioctl(msg_port, TCSETA, &tbuf);
167 (void) ioctl (msg_port, MCGETA, &mbits);
168 mbits = (MDSR|MDTR|MRTS);
169 (void) ioctl (msg_port, MCSETA, &mbits);
172 (void) ioctl (msg_port, TIOCMGET, &mbits);
173 mbits = (TIOCM_DTR|TIOCM_RTS);
174 (void) ioctl (msg_port, TIOCMSET, &mbits);
178 if (ioctl(msg_port, TCFLSH, 2) == -1)
182 } /* end init_comm_serial() */
186 ** This function is used to send a message over the
189 ** If the message is successfully sent, a zero is
190 ** returned. If the message was not sendable, a -1
191 ** is returned. This function blocks. That is, it
192 ** does not return until the message is completely
193 ** sent, or until an error is encountered.
198 send_bfr_serial(bfr_ptr, length, port_base, comm_err)
207 result = write(msg_port, (char *)bfr_ptr, length);
208 if (result != length)
213 } /* end msg_send_serial() */
217 ** This function is used to receive a message over a
220 ** If the message is waiting in the buffer, a zero is
221 ** returned and the buffer pointed to by msg_ptr is filled
222 ** in. If no message was available, a -1 is returned.
226 /* Read as many characters as are coming and return the number of character
227 * read into the buffer.
228 * Buffer : pointer to the receiving buffer.
229 * nbytes : number of bytes requested.
230 * Mode : Blocking/Non-blocking mode. In blocking mode, this will not
231 * return until atleast a character is received. It is used when
232 * the TIP is to wait for a response from the target, and there is
233 * no need to poll the keyboard.
234 * PortBase : not used.
235 * CommError : Error during communication.
238 recv_bfr_serial(Buffer, nbytes, Mode, PortBase, CommError)
249 struct termio OrigTBuf, NewTBuf;
255 while (bcount++ < BlockCount) {
256 if ((result = read(msg_port, (char *)&ch, 1)) == 1) { /* success */
257 *Buffer++ = (BYTE) ch;
265 } else { /* non-block */
266 if ((result = read(msg_port, (char *)&ch, 1)) == 1) { /* success */
267 *Buffer++ = (BYTE) ch;
269 } else { /* Timed out */
273 } while (count < nbytes);
277 if (Mode) { /* BLOCK while reading */
279 * Set blocking mode by set MIN=0 and TIME > 0
280 * Here we set TIME to block for 60 seconds.
282 (void) ioctl (msg_port, TCGETA, &OrigTBuf);
283 (void) ioctl (msg_port, TCGETA, &NewTBuf);
284 NewTBuf.c_cc[4] = 0; /* set MIN to 0 */
285 NewTBuf.c_cc[5] = 1; /* 600 * 0.1 seconds */
286 (void) ioctl (msg_port, TCSETA, &NewTBuf);
289 if (read(msg_port, (char *)&ch, 1) == 1) { /* success */
290 *Buffer++ = (BYTE) ch;
292 } else { /* Timed out */
293 (void) ioctl (msg_port, TCSETA, &OrigTBuf); /* restore termio */
296 } while (count < nbytes);
297 (void) ioctl (msg_port, TCSETA, &OrigTBuf); /* restore termio */
299 } else { /* Non blocking */
302 while ((count < nbytes) && (read(msg_port, (char *)&ch, 1) == 1)) {
303 *Buffer++ = (BYTE) ch;
307 if (count == nbytes) /* read enough */
309 else /* not enough chars read */
314 result = read(msg_port, (char *) Buffer, nbytes); /* read as many */
315 if (result == nbytes) {
321 in_byte_count = in_byte_count + result;
323 if (in_byte_count >= length) {
324 /* Message received */
330 /* return if no char & not blocking */
331 if (block == NOBLOCK) return (-1);
333 /* return if no char, blocking, and past block count */
334 if ((block == BLOCK) && (block_count++ > BlockCount))
339 } /* end msg_recv_serial() */
344 ** This function is used to close the communication
345 ** channel. This is used when resyncing the host and
346 ** target and when exiting the monitor.
350 reset_comm_pcserver(ignore1, ignore2)
362 /* Reset message buffer counters */
366 mbits = (MDSR|MDTR|MRTS);
367 (void) ioctl (msg_port, MCSETA, &mbits);
369 mbits = (TIOCM_DTR|TIOCM_RTS);
370 (void) ioctl (msg_port, TIOCMGET, &mbits);
373 /* Clear data from buffer */
374 if (ioctl(msg_port, TCFLSH, 2) == -1) {
379 } /* end reset_comm_serial() */
383 ** This function is used to close the communication
384 ** channel. This is used when resyncing the host and
385 ** target and when exiting the monitor.
389 reset_comm_serial(ignore1, ignore2)
399 /* Reset message buffer counters */
403 (void) ioctl (msg_port, MCGETA, &mbits);
404 mbits = (MDSR|MDTR|MRTS);
405 (void) ioctl (msg_port, MCSETA, &mbits);
407 (void) ioctl (msg_port, TIOCMGET, &mbits);
408 mbits = (TIOCM_DTR|TIOCM_RTS);
409 (void) ioctl (msg_port, TIOCMSET, &mbits);
412 /* Clear data from buffer */
413 if (ioctl(msg_port, TCFLSH, 2) == -1) {
418 } /* end reset_comm_serial() */
422 exit_comm_serial(ignore1, ignore2)
426 /* Reset message buffer counters */
429 (void) close(msg_port);
432 } /* end reset_comm_serial() */
434 ** This function is usually used to "kick-start" the target.
435 ** This is nesessary when targets are shared memory boards.
436 ** With serial communications, this function does nothing.
440 go_serial(port_base, msg_seg)
447 write_memory_serial (ignore1, ignore2, ignore3, ignore4, ignore5, ignore6)
458 read_memory_serial (ignore1, ignore2, ignore3, ignore4, ignore5, ignore6)
472 ** Stubs for PC plug-in board routines
477 INT32 init_comm_eb29k() {return (FAILURE);}
478 INT32 msg_send_eb29k() {return (-1);}
479 INT32 msg_recv_eb29k() {return (-1);}
480 INT32 reset_comm_eb29k() {return (-1);}
481 INT32 exit_comm_eb29k() {return (-1);}
483 INT32 read_memory_eb29k() {return (-1);}
484 INT32 write_memory_eb29k() {return (-1);}
485 INT32 fill_memory_eb29k() {return (-1);}
489 INT32 init_comm_lcb29k() {return (FAILURE);}
490 INT32 msg_send_lcb29k() {return (-1);}
491 INT32 msg_recv_lcb29k() {return (-1);}
492 INT32 reset_comm_lcb29k() {return (-1);}
493 INT32 exit_comm_lcb29k() {return (-1);}
495 INT32 read_memory_lcb29k() {return (-1);}
496 INT32 write_memory_lcb29k(){return (-1);}
497 INT32 fill_memory_lcb29k() {return (-1);}
501 INT32 init_comm_pceb() {return (FAILURE);}
502 INT32 msg_send_pceb() {return (-1);}
503 INT32 msg_recv_pceb() {return (-1);}
504 INT32 reset_comm_pceb() {return (-1);}
505 INT32 exit_comm_pceb() {return (-1);}
507 INT32 read_memory_pceb() {return (-1);}
508 INT32 write_memory_pceb() {return (-1);}
509 INT32 fill_memory_pceb() {return (-1);}
513 INT32 init_comm_eb030() {return (FAILURE);}
514 INT32 msg_send_eb030() {return (-1);}
515 INT32 msg_recv_eb030() {return (-1);}
516 INT32 reset_comm_eb030() {return (-1);}
517 INT32 exit_comm_eb030() {return (-1);}
519 INT32 read_memory_eb030() {return (-1);}
520 INT32 write_memory_eb030() {return (-1);}
521 INT32 fill_memory_eb030() {return (-1);}