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 SERPORT1 "/dev/ttya"
72 #define SERPORT2 "/dev/ttyb"
73 #define PARPORT1 "/dev/bpp0"
74 #define PARPORT2 "/dev/bpp1"
78 #define SERPORT1 "/dev/tty00"
79 #define SERPORT2 "/dev/tty01"
80 #define PARPORT1 "/dev/ptr_parallel"
81 #define PARPORT2 "/dev/ptr_parallel"
85 #define SERPORT1 "/dev/cua0"
86 #define SERPORT2 "/dev/cua1"
87 #define PARPORT1 "/dev/par0"
88 #define PARPORT2 "/dev/par1"
92 #define SERPORT1 "com1"
93 #define SERPORT2 "com2"
94 #define PARPORT1 "lpt1"
95 #define PARPORT2 "lpt2"
99 * Parallel port output pins, used for signalling to target
106 static int serpfd
= -1;
107 static int parpfd
= -1;
109 extern const char *Unix_MatchValidSerialDevice(const char *name
)
114 /* Accept no name as the default serial port */
119 /* Look for the simple cases - 1,2,s,S,/dev/... first, and
120 * afterwards look for S=... clauses, which need parsing properly.
123 /* Accept /dev/tty* where * is limited */
124 if (strlen(name
) == strlen(SERPORT1
) && strncmp(name
, "/dev/tty", 8) == 0) return name
;
126 /* Accept "1" or "2" or "S" - S is equivalent to "1" */
127 if (strcmp(name
, "1") == 0 ||
128 strcmp(name
, "S") == 0 || strcmp(name
, "s") == 0) {
131 if (strcmp(name
, "2") == 0) return SERPORT2
;
133 /* It wasn't one of the simple cases, so now we have to parse it
140 /* Skip over commas */
146 /* Unexpected character => error - not matched */
149 /* End of string means return whatever we have matched */
156 char ch
= tolower(name
[i
]);
157 int j
, continue_from
, len
;
159 /* If the next character is a comma or a NULL then this is
160 * a request for the default Serial port
162 if (name
[++i
] == 0 || name
[i
] == ',') {
168 /* Next character must be an = */
169 if (name
[i
] != '=') return 0;
170 /* Search for the end of the port spec. (ends in NULL or ,) */
171 for (j
= ++i
; name
[j
] != 0 && name
[j
] != ','; j
++)
173 /* Notice whether this is the last thing to parse or not
174 * and also calaculate the length of the string
176 if (name
[j
] == '0') continue_from
= -1;
177 else continue_from
= j
;
180 /* And now try to match the serial / parallel port */
183 /* Match serial port */
187 else if (name
[i
]=='2')
189 } else if (len
==strlen(SERPORT1
)) {
190 if (strncmp(name
+i
,SERPORT1
,strlen(SERPORT1
)) == 0)
192 else if (strncmp(name
+i
,SERPORT2
,strlen(SERPORT2
)) == 0)
200 /* We don't actually deal with the H case here, we just
201 * match it and allow it through.
206 if (continue_from
== -1) return sername
;
217 extern int Unix_IsSerialInUse(void)
225 extern int Unix_OpenSerial(const char *name
)
228 serpfd
= open(name
, O_RDWR
);
230 serpfd
= open(name
, O_RDWR
| O_NONBLOCK
);
241 extern void Unix_CloseSerial(void)
250 extern int Unix_ReadSerial(unsigned char *buf
, int n
, bool block
)
257 FD_SET(serpfd
, &fdset
);
260 tv
.tv_usec
= (block
? 10000 : 0);
262 err
= select(serpfd
+ 1, &fdset
, NULL
, NULL
, &tv
);
264 if (err
< 0 && errno
!= EINTR
)
269 panic("select failure");
272 else if (err
> 0 && FD_ISSET(serpfd
, &fdset
))
273 return read(serpfd
, buf
, n
);
274 else /* err == 0 || FD_CLR(serpfd, &fdset) */
276 errno
= ERRNO_FOR_BLOCKED_IO
;
281 extern int Unix_WriteSerial(unsigned char *buf
, int n
)
283 return write(serpfd
, buf
, n
);
286 extern void Unix_ResetSerial(void)
288 struct termios terminfo
;
290 tcgetattr(serpfd
, &terminfo
);
292 /* Expedient, but it works. */
293 terminfo
.c_iflag
= 0;
294 terminfo
.c_oflag
= 0;
295 terminfo
.c_cflag
= 48;
296 terminfo
.c_lflag
= 0;
297 terminfo
.c_cc
[VMIN
] = 0;
298 terminfo
.c_cc
[VTIME
] = 1;
300 terminfo
.c_lflag
&= ~(ICANON
| ISIG
| ECHO
| IEXTEN
);
301 terminfo
.c_iflag
&= ~(IGNCR
| INPCK
| ISTRIP
| ICRNL
| BRKINT
);
302 terminfo
.c_iflag
|= (IXON
| IXOFF
| IGNBRK
);
303 terminfo
.c_cflag
= (terminfo
.c_cflag
& ~CSIZE
) | CS8
| CREAD
;
304 terminfo
.c_cflag
&= ~PARENB
;
305 terminfo
.c_cc
[VMIN
] = 1;
306 terminfo
.c_cc
[VTIME
] = 0;
307 terminfo
.c_oflag
&= ~OPOST
;
309 tcsetattr(serpfd
, TCSAFLUSH
, &terminfo
);
312 extern void Unix_SetSerialBaudRate(int baudrate
)
314 struct termios terminfo
;
316 tcgetattr(serpfd
, &terminfo
);
317 cfsetospeed(&terminfo
, baudrate
);
318 cfsetispeed(&terminfo
, baudrate
);
319 tcsetattr(serpfd
, TCSAFLUSH
, &terminfo
);
322 extern void Unix_ioctlNonBlocking(void)
325 int nonblockingIO
= 1;
326 (void)ioctl(serpfd
, FIONBIO
, &nonblockingIO
);
329 (void)ioctl(parpfd
, FIONBIO
, &nonblockingIO
);
333 extern void Unix_IsValidParallelDevice(
334 const char *portstring
, char **sername
, char **parname
)
340 /* Do not recognise a NULL portstring */
341 if (portstring
==NULL
) return;
344 switch (portstring
[i
]) {
346 /* Skip over commas */
352 /* End of string or bad characcter means we have finished */
361 char ch
= tolower(portstring
[i
]);
362 int j
, continue_from
, len
;
364 /* If the next character is a comma or a NULL then this is
365 * a request for the default Serial or Parallel port
367 if (portstring
[++i
] == 0 || portstring
[i
] == ',') {
368 if (ch
=='s') *sername
=SERPORT1
;
369 else if (ch
=='p') *parname
=PARPORT1
;
373 /* Next character must be an = */
374 if (portstring
[i
] != '=') return;
375 /* Search for the end of the port spec. (ends in NULL or ,) */
376 for (j
= ++i
; portstring
[j
] != 0 && portstring
[j
] != ','; j
++)
378 /* Notice whether this is the last thing to parse or not
379 * and also calaculate the length of the string
381 if (portstring
[j
] == '0') continue_from
= -1;
382 else continue_from
= j
;
385 /* And now try to match the serial / parallel port */
388 /* Match serial port */
390 if (portstring
[i
]=='1') *sername
=SERPORT1
;
391 else if (portstring
[i
]=='2') *sername
=SERPORT2
;
392 } else if (len
==strlen(SERPORT1
)) {
393 if (strncmp(portstring
+i
,SERPORT1
,strlen(SERPORT1
)) == 0)
395 else if (strncmp(portstring
+i
,SERPORT2
,strlen(SERPORT2
)) == 0)
402 /* Match parallel port */
404 if (portstring
[i
]=='1') *parname
=PARPORT1
;
405 else if (portstring
[i
]=='2') *parname
=PARPORT2
;
406 } else if (len
==strlen(PARPORT1
)) {
407 if (strncmp(portstring
+i
,PARPORT1
,strlen(PARPORT1
)) == 0)
409 else if (strncmp(portstring
+i
,PARPORT2
,strlen(PARPORT2
)) == 0)
416 /* We don't actually deal with the H case here, we just
417 * match it and allow it through.
422 if (continue_from
== -1) return;
428 return; /* Will never get here */
431 extern int Unix_IsParallelInUse(void)
439 extern int Unix_OpenParallel(const char *name
)
442 parpfd
= open(name
, O_RDWR
);
444 parpfd
= open(name
, O_RDWR
| O_NONBLOCK
);
451 sprintf(errbuf
, "open %s", name
);
460 extern void Unix_CloseParallel(void)
470 extern unsigned int Unix_WriteParallel(unsigned char *buf
, int n
)
474 if ((ngone
= write(parpfd
, buf
, n
)) < 0)
477 * we ignore errors (except for debug purposes)
482 sprintf(errbuf
, "send_packet: write");
489 return (unsigned int)ngone
;
494 extern void Unix_ResetParallel(void)
496 struct bpp_transfer_parms tp
;
499 printf("serpar_reset\n");
503 * we need to set the parallel port up for BUSY handshaking,
504 * and select the timeout
506 if (ioctl(parpfd
, BPPIOC_GETPARMS
, &tp
) < 0)
509 perror("ioctl(BPPIOCGETPARMS)");
511 panic("serpar_reset: cannot get BPP parameters");
514 tp
.write_handshake
= BPP_BUSY_HS
;
515 tp
.write_timeout
= PP_TIMEOUT
;
517 if (ioctl(parpfd
, BPPIOC_SETPARMS
, &tp
) < 0)
520 perror("ioctl(BPPIOC_SETPARMS)");
522 panic("serpar_reset: cannot set BPP parameters");
528 /* Parallel not supported on HP */
530 extern void Unix_ResetParallel(void)
This page took 0.040833 seconds and 5 git commands to generate.