2 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
4 * This software may be freely used, copied, modified, and distributed
5 * provided that the above copyright notice is preserved in all copies of the
17 # define _POSIX_SOURCE 1
25 # define _TERMIOS_INCLUDED
26 # include <sys/termio.h>
27 # undef _TERMIOS_INCLUDED
36 #include <sys/types.h>
40 # include <sys/ioccom.h>
42 # include <sys/bpp_io.h>
44 # include <sbusdev/bpp_io.h>
50 # include <sys/ttydev.h>
53 # include <sys/ioctl.h>
55 # include <sys/filio.h>
60 # define _INCLUDE_HPUX_SOURCE
61 # include <sys/ioctl.h>
62 # undef _INCLUDE_HPUX_SOURCE
68 #define PP_TIMEOUT 1 /* seconds */
71 #define SERIAL_PREFIX "/dev/tty"
72 #define SERPORT1 "/dev/ttya"
73 #define SERPORT2 "/dev/ttyb"
74 #define PARPORT1 "/dev/bpp0"
75 #define PARPORT2 "/dev/bpp1"
79 #define SERIAL_PREFIX "/dev/tty"
80 #define SERPORT1 "/dev/tty00"
81 #define SERPORT2 "/dev/tty01"
82 #define PARPORT1 "/dev/ptr_parallel"
83 #define PARPORT2 "/dev/ptr_parallel"
87 #define SERIAL_PREFIX "/dev/ttyS"
88 #define SERPORT1 "/dev/ttyS0"
89 #define SERPORT2 "/dev/ttyS1"
90 #define PARPORT1 "/dev/par0"
91 #define PARPORT2 "/dev/par1"
94 #if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (bsdi)
95 #define SERIAL_PREFIX "/dev/cuaa"
96 #define SERPORT1 "/dev/cuaa0"
97 #define SERPORT2 "/dev/cuaa1"
98 #define PARPORT1 "/dev/lpt0"
99 #define PARPORT2 "/dev/lpt1"
103 #if defined(_WIN32) || defined (__CYGWIN32__)
104 #define SERIAL_PREFIX "com"
105 #define SERPORT1 "com1"
106 #define SERPORT2 "com2"
107 #define PARPORT1 "lpt1"
108 #define PARPORT2 "lpt2"
114 * Parallel port output pins, used for signalling to target
121 static int serpfd
= -1;
122 static int parpfd
= -1;
124 extern const char *Unix_MatchValidSerialDevice(const char *name
)
129 /* Accept no name as the default serial port */
134 /* Look for the simple cases - 1,2,s,S,/dev/... first, and
135 * afterwards look for S=... clauses, which need parsing properly.
138 /* Accept /dev/tty* where * is limited */
139 if (strlen(name
) == strlen(SERPORT1
)
140 && strncmp(name
, SERIAL_PREFIX
, strlen (SERIAL_PREFIX
)) == 0)
145 /* Accept "1" or "2" or "S" - S is equivalent to "1" */
146 if (strcmp(name
, "1") == 0 ||
147 strcmp(name
, "S") == 0 || strcmp(name
, "s") == 0) {
150 if (strcmp(name
, "2") == 0) return SERPORT2
;
152 /* It wasn't one of the simple cases, so now we have to parse it
159 /* Skip over commas */
165 /* Unexpected character => error - not matched */
168 /* End of string means return whatever we have matched */
175 char ch
= tolower(name
[i
]);
176 int j
, continue_from
, len
;
178 /* If the next character is a comma or a NULL then this is
179 * a request for the default Serial port
181 if (name
[++i
] == 0 || name
[i
] == ',') {
187 /* Next character must be an = */
188 if (name
[i
] != '=') return 0;
189 /* Search for the end of the port spec. (ends in NULL or ,) */
190 for (j
= ++i
; name
[j
] != 0 && name
[j
] != ','; j
++)
192 /* Notice whether this is the last thing to parse or not
193 * and also calaculate the length of the string
195 if (name
[j
] == '0') continue_from
= -1;
196 else continue_from
= j
;
199 /* And now try to match the serial / parallel port */
202 /* Match serial port */
206 else if (name
[i
]=='2')
208 } else if (len
==strlen(SERPORT1
)) {
209 if (strncmp(name
+i
,SERPORT1
,strlen(SERPORT1
)) == 0)
211 else if (strncmp(name
+i
,SERPORT2
,strlen(SERPORT2
)) == 0)
219 /* We don't actually deal with the H case here, we just
220 * match it and allow it through.
225 if (continue_from
== -1) return sername
;
236 extern int Unix_IsSerialInUse(void)
244 extern int Unix_OpenSerial(const char *name
)
246 #if defined(BSD) || defined(__CYGWIN32__)
247 serpfd
= open(name
, O_RDWR
);
249 serpfd
= open(name
, O_RDWR
| O_NONBLOCK
);
260 extern void Unix_CloseSerial(void)
269 extern int Unix_ReadSerial(unsigned char *buf
, int n
, bool block
)
276 FD_SET(serpfd
, &fdset
);
279 tv
.tv_usec
= (block
? 10000 : 0);
281 err
= select(serpfd
+ 1, &fdset
, NULL
, NULL
, &tv
);
283 if (err
< 0 && errno
!= EINTR
)
288 panic("select failure");
291 else if (err
> 0 && FD_ISSET(serpfd
, &fdset
))
295 s
= read(serpfd
, buf
, n
);
300 else /* err == 0 || FD_CLR(serpfd, &fdset) */
302 errno
= ERRNO_FOR_BLOCKED_IO
;
307 extern int Unix_WriteSerial(unsigned char *buf
, int n
)
309 return write(serpfd
, buf
, n
);
312 extern void Unix_ResetSerial(void)
314 struct termios terminfo
;
316 tcgetattr(serpfd
, &terminfo
);
317 terminfo
.c_lflag
&= ~(ICANON
| ISIG
| ECHO
| IEXTEN
);
318 terminfo
.c_iflag
&= ~(IGNCR
| INPCK
| ISTRIP
| ICRNL
| BRKINT
);
319 terminfo
.c_iflag
|= (IXON
| IXOFF
| IGNBRK
);
320 terminfo
.c_cflag
= (terminfo
.c_cflag
& ~CSIZE
) | CS8
| CREAD
;
321 terminfo
.c_cflag
&= ~PARENB
;
322 terminfo
.c_cc
[VMIN
] = 1;
323 terminfo
.c_cc
[VTIME
] = 0;
324 terminfo
.c_oflag
&= ~OPOST
;
325 tcsetattr(serpfd
, TCSAFLUSH
, &terminfo
);
328 extern void Unix_SetSerialBaudRate(int baudrate
)
330 struct termios terminfo
;
332 tcgetattr(serpfd
, &terminfo
);
333 cfsetospeed(&terminfo
, baudrate
);
334 cfsetispeed(&terminfo
, baudrate
);
335 tcsetattr(serpfd
, TCSAFLUSH
, &terminfo
);
338 extern void Unix_ioctlNonBlocking(void)
341 int nonblockingIO
= 1;
342 (void)ioctl(serpfd
, FIONBIO
, &nonblockingIO
);
345 (void)ioctl(parpfd
, FIONBIO
, &nonblockingIO
);
349 extern void Unix_IsValidParallelDevice(
350 const char *portstring
, char **sername
, char **parname
)
356 /* Do not recognise a NULL portstring */
357 if (portstring
==NULL
) return;
360 switch (portstring
[i
]) {
362 /* Skip over commas */
368 /* End of string or bad characcter means we have finished */
377 char ch
= tolower(portstring
[i
]);
378 int j
, continue_from
, len
;
380 /* If the next character is a comma or a NULL then this is
381 * a request for the default Serial or Parallel port
383 if (portstring
[++i
] == 0 || portstring
[i
] == ',') {
384 if (ch
=='s') *sername
=SERPORT1
;
385 else if (ch
=='p') *parname
=PARPORT1
;
389 /* Next character must be an = */
390 if (portstring
[i
] != '=') return;
391 /* Search for the end of the port spec. (ends in NULL or ,) */
392 for (j
= ++i
; portstring
[j
] != 0 && portstring
[j
] != ','; j
++)
394 /* Notice whether this is the last thing to parse or not
395 * and also calaculate the length of the string
397 if (portstring
[j
] == '0') continue_from
= -1;
398 else continue_from
= j
;
401 /* And now try to match the serial / parallel port */
404 /* Match serial port */
406 if (portstring
[i
]=='1') *sername
=SERPORT1
;
407 else if (portstring
[i
]=='2') *sername
=SERPORT2
;
408 } else if (len
==strlen(SERPORT1
)) {
409 if (strncmp(portstring
+i
,SERPORT1
,strlen(SERPORT1
)) == 0)
411 else if (strncmp(portstring
+i
,SERPORT2
,strlen(SERPORT2
)) == 0)
418 /* Match parallel port */
420 if (portstring
[i
]=='1') *parname
=PARPORT1
;
421 else if (portstring
[i
]=='2') *parname
=PARPORT2
;
422 } else if (len
==strlen(PARPORT1
)) {
423 if (strncmp(portstring
+i
,PARPORT1
,strlen(PARPORT1
)) == 0)
425 else if (strncmp(portstring
+i
,PARPORT2
,strlen(PARPORT2
)) == 0)
432 /* We don't actually deal with the H case here, we just
433 * match it and allow it through.
438 if (continue_from
== -1) return;
444 return; /* Will never get here */
447 extern int Unix_IsParallelInUse(void)
455 extern int Unix_OpenParallel(const char *name
)
458 parpfd
= open(name
, O_RDWR
);
460 parpfd
= open(name
, O_RDWR
| O_NONBLOCK
);
467 sprintf(errbuf
, "open %s", name
);
476 extern void Unix_CloseParallel(void)
486 extern unsigned int Unix_WriteParallel(unsigned char *buf
, int n
)
490 if ((ngone
= write(parpfd
, buf
, n
)) < 0)
493 * we ignore errors (except for debug purposes)
498 sprintf(errbuf
, "send_packet: write");
505 return (unsigned int)ngone
;
510 extern void Unix_ResetParallel(void)
512 struct bpp_transfer_parms tp
;
515 printf("serpar_reset\n");
519 * we need to set the parallel port up for BUSY handshaking,
520 * and select the timeout
522 if (ioctl(parpfd
, BPPIOC_GETPARMS
, &tp
) < 0)
525 perror("ioctl(BPPIOCGETPARMS)");
527 panic("serpar_reset: cannot get BPP parameters");
530 tp
.write_handshake
= BPP_BUSY_HS
;
531 tp
.write_timeout
= PP_TIMEOUT
;
533 if (ioctl(parpfd
, BPPIOC_SETPARMS
, &tp
) < 0)
536 perror("ioctl(BPPIOC_SETPARMS)");
538 panic("serpar_reset: cannot set BPP parameters");
544 /* Parallel not supported on HP */
546 extern void Unix_ResetParallel(void)
This page took 0.040754 seconds and 4 git commands to generate.