fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a termios character driver

Hampa Hug 6d3db0fa ba62314e

+526 -7
+6
config.inc.in
··· 102 102 103 103 PCE_ENABLE_TUN := @PCE_ENABLE_TUN@ 104 104 105 + PCE_ENABLE_CHAR_TIOS := @PCE_ENABLE_CHAR_TIOS@ 106 + 105 107 106 108 # end of user editable section 107 109 #-------------------------------------------------------------------------- ··· 167 169 PCE_CHAR_OBJ += $(pcedst)/drivers/char/char-stdio.o 168 170 PCE_CHAR_HDR := drivers/char/char.h 169 171 PCE_CHAR_LIB := 172 + 173 + ifeq "$(PCE_ENABLE_CHAR_TIOS)" "1" 174 + PCE_CHAR_OBJ += $(pcedst)/drivers/char/char-tios.o 175 + endif
+47 -3
configure.in
··· 192 192 193 193 AC_HEADER_STDC 194 194 AC_CHECK_HEADERS( \ 195 - fcntl.h limits.h termios.h unistd.h \ 196 - sys/ioctl.h sys/poll.h sys/socket.h sys/time.h \ 197 - linux/if_tun.h 195 + fcntl.h \ 196 + linux/if_tun.h \ 197 + limits.h \ 198 + sys/ioctl.h \ 199 + sys/poll.h \ 200 + sys/socket.h \ 201 + sys/stat.h \ 202 + sys/time.h \ 203 + sys/types.h \ 204 + termios.h \ 205 + unistd.h 198 206 ) 199 207 200 208 AC_CHECK_HEADER(stdint.h, ··· 676 684 fi 677 685 678 686 687 + AC_MSG_CHECKING([whether to enable the termios character driver]) 688 + AC_ARG_ENABLE(char-termios, 689 + AC_HELP_STRING([--enable-char-termios], [Enable the termios character driver]), 690 + [ 691 + if test "x$enableval" = "xyes" ; then 692 + PCE_ENABLE_CHAR_TIOS=1 693 + AC_MSG_RESULT([yes]) 694 + else 695 + PCE_ENABLE_CHAR_TIOS=0 696 + AC_MSG_RESULT([no]) 697 + fi 698 + ],[ 699 + PCE_ENABLE_CHAR_TIOS=1 700 + test "x$ac_cv_header_fcntl_h" = "xyes" || PCE_ENABLE_CHAR_TIOS=0 701 + test "x$ac_cv_header_sys_ioctl_h" = "xyes" || PCE_ENABLE_CHAR_TIOS=0 702 + test "x$ac_cv_header_sys_poll_h" = "xyes" || PCE_ENABLE_CHAR_TIOS=0 703 + test "x$ac_cv_header_termios_h" = "xyes" || PCE_ENABLE_CHAR_TIOS=0 704 + test "x$ac_cv_header_unistd_h" = "xyes" || PCE_ENABLE_CHAR_TIOS=0 705 + if test "x$PCE_ENABLE_CHAR_TIOS" = "x1" ; then 706 + AC_MSG_RESULT([yes (guess)]) 707 + else 708 + AC_MSG_RESULT([no (guess)]) 709 + fi 710 + ] 711 + ) 712 + AC_SUBST(PCE_ENABLE_CHAR_TIOS) 713 + if test "x$PCE_ENABLE_CHAR_TIOS" = "x1" ; then 714 + AC_DEFINE(PCE_ENABLE_CHAR_TIOS) 715 + fi 716 + 717 + 679 718 # Don't know how to autodetect this properly. 680 719 AC_MSG_CHECKING([whether to enable tun]) 681 720 AC_ARG_ENABLE(tun, ··· 871 910 char1=" null stdio" 872 911 char2="" 873 912 913 + if test "x$PCE_ENABLE_CHAR_TIOS" = "x1" ; then 914 + char1="$char1 termios" 915 + else 916 + char2="$char2 termios" 917 + fi 874 918 875 919 option1="" 876 920 option2=""
+7 -3
src/config.h.in
··· 45 45 46 46 #undef HAVE_FCNTL_H 47 47 #undef HAVE_INTTYPES_H 48 + #undef HAVE_LINUX_IF_TUN_H 48 49 #undef HAVE_LIMITS_H 49 50 #undef HAVE_STDINT_H 50 - #undef HAVE_TERMIOS_H 51 - #undef HAVE_UNISTD_H 52 - #undef HAVE_LINUX_IF_TUN_H 53 51 #undef HAVE_SYS_IOCTL_H 54 52 #undef HAVE_SYS_POLL_H 55 53 #undef HAVE_SYS_SOCKET_H 54 + #undef HAVE_SYS_STAT_H 56 55 #undef HAVE_SYS_TIME_H 56 + #undef HAVE_SYS_TYPES_H 57 + #undef HAVE_TERMIOS_H 58 + #undef HAVE_UNISTD_H 57 59 58 60 #undef HAVE_FSEEKO 59 61 #undef HAVE_USLEEP ··· 84 86 85 87 #undef PCE_ENABLE_TUN 86 88 #undef PCE_ENABLE_SERPORT 89 + 90 + #undef PCE_ENABLE_CHAR_TIOS 87 91 88 92 /* directory separator */ 89 93 #define PCE_DIR_SEP '/'
+6 -1
src/drivers/char/Makefile.in
··· 9 9 include $(reldir)/config.inc 10 10 11 11 12 - ALLFILES := char char-null char-stdio 12 + ALLFILES := char char-null char-stdio char-tios 13 13 14 14 FILES := char char-null char-stdio 15 + 16 + ifeq "$(PCE_ENABLE_CHAR_TIOS)" "1" 17 + FILES += char-tios 18 + endif 15 19 16 20 ALLSRC := $(foreach f,$(ALLFILES),$(f).c) 17 21 ALLOBJ := $(foreach f,$(ALLFILES),$(f).o) ··· 37 41 char.o: char.c char.h $(SDP) 38 42 char-null.o: char-null.c char-null.h char.h $(SDP) 39 43 char-stdio.o: char-stdio.c char-stdio.h char.h $(SDP) 44 + char-tios.o: char-tios.c char-tios.h char.h $(SDP)
+415
src/drivers/char/char-tios.c
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: src/drivers/char/char-tios.c * 7 + * Created: 2009-03-06 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2009 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #include <stdlib.h> 24 + #include <limits.h> 25 + 26 + #include <fcntl.h> 27 + #include <sys/ioctl.h> 28 + #include <sys/poll.h> 29 + #include <sys/stat.h> 30 + #include <sys/types.h> 31 + #include <termios.h> 32 + #include <unistd.h> 33 + 34 + #include <drivers/char/char.h> 35 + #include <drivers/char/char-tios.h> 36 + 37 + 38 + /* 39 + * Check if file descriptor fd is readable and/or writeable 40 + */ 41 + static 42 + int chr_tios_check_fd (int fd, int rd, int wr) 43 + { 44 + int r; 45 + struct pollfd pfd[1]; 46 + 47 + if (fd < 0) { 48 + return (0); 49 + } 50 + 51 + pfd[0].fd = fd; 52 + pfd[0].events = (rd ? POLLIN : 0) | (wr ? POLLOUT : 0); 53 + 54 + r = poll (pfd, 1, 0); 55 + 56 + if (r < 0) { 57 + return (0); 58 + } 59 + 60 + if ((pfd[0].revents & (POLLIN | POLLOUT)) == 0) { 61 + return (0); 62 + } 63 + 64 + return (1); 65 + } 66 + 67 + static 68 + void chr_tios_close (char_drv_t *cdrv) 69 + { 70 + char_tios_t *drv; 71 + 72 + drv = cdrv->ext; 73 + 74 + if (drv->fname != NULL) { 75 + free (drv->fname); 76 + } 77 + 78 + if (drv->fd >= 0) { 79 + close (drv->fd); 80 + } 81 + 82 + free (drv); 83 + } 84 + 85 + static 86 + unsigned chr_tios_read (char_drv_t *cdrv, void *buf, unsigned cnt) 87 + { 88 + char_tios_t *drv; 89 + ssize_t r; 90 + 91 + drv = cdrv->ext; 92 + 93 + if (chr_tios_check_fd (drv->fd, 1, 0) == 0) { 94 + return (0); 95 + } 96 + 97 + if (cnt > SSIZE_MAX) { 98 + cnt = SSIZE_MAX; 99 + } 100 + 101 + r = read (drv->fd, buf, cnt); 102 + 103 + if (r <= 0) { 104 + return (0); 105 + } 106 + 107 + return (r); 108 + } 109 + 110 + static 111 + unsigned chr_tios_write (char_drv_t *cdrv, const void *buf, unsigned cnt) 112 + { 113 + char_tios_t *drv; 114 + ssize_t r; 115 + 116 + drv = cdrv->ext; 117 + 118 + if (drv->fd < 0) { 119 + return (cnt); 120 + } 121 + 122 + if (chr_tios_check_fd (drv->fd, 0, 1) == 0) { 123 + return (0); 124 + } 125 + 126 + if (cnt > SSIZE_MAX) { 127 + cnt = SSIZE_MAX; 128 + } 129 + 130 + r = write (drv->fd, buf, cnt); 131 + 132 + if (r <= 0) { 133 + return (0); 134 + } 135 + 136 + return (r); 137 + } 138 + 139 + static 140 + int chr_tios_get_ctl (char_drv_t *cdrv, unsigned *ctl) 141 + { 142 + char_tios_t *drv; 143 + int val; 144 + 145 + drv = cdrv->ext; 146 + 147 + *ctl = 0; 148 + 149 + if (drv->fd >= 0) { 150 + ioctl (drv->fd, TIOCMGET, &val); 151 + } 152 + else { 153 + val = TIOCM_DSR | TIOCM_CTS | TIOCM_CD; 154 + } 155 + 156 + *ctl |= (val & TIOCM_DSR) ? PCE_CHAR_DSR : 0; 157 + *ctl |= (val & TIOCM_CTS) ? PCE_CHAR_CTS : 0; 158 + *ctl |= (val & TIOCM_CD) ? PCE_CHAR_CD : 0; 159 + *ctl |= (val & TIOCM_RI) ? PCE_CHAR_RI : 0; 160 + 161 + *ctl |= PCE_CHAR_DSR; 162 + *ctl |= PCE_CHAR_CTS; 163 + 164 + return (0); 165 + } 166 + 167 + static 168 + int chr_tios_set_ctl (char_drv_t *cdrv, unsigned ctl) 169 + { 170 + char_tios_t *drv; 171 + int val; 172 + 173 + drv = cdrv->ext; 174 + 175 + if (drv->fd < 0) { 176 + return (0); 177 + } 178 + 179 + ioctl (drv->fd, TIOCMGET, &val); 180 + val &= ~(TIOCM_DTR | TIOCM_RTS); 181 + val |= (ctl & PCE_CHAR_DTR) ? TIOCM_DTR : 0; 182 + val |= (ctl & PCE_CHAR_RTS) ? TIOCM_RTS : 0; 183 + ioctl (drv->fd, TIOCMSET, &val); 184 + 185 + return (0); 186 + } 187 + 188 + static 189 + int chr_tios_set_params (char_drv_t *cdrv, unsigned long bps, unsigned bpc, unsigned parity, unsigned stop) 190 + { 191 + char_tios_t *drv; 192 + struct termios tio; 193 + speed_t spd; 194 + 195 + drv = cdrv->ext; 196 + 197 + if (drv->fd < 0) { 198 + return (0); 199 + } 200 + 201 + if (tcgetattr (drv->fd, &tio)) { 202 + return (1); 203 + } 204 + 205 + tio.c_iflag &= ~INPCK; /* Input parity check */ 206 + tio.c_iflag &= ~ISTRIP; /* Strip to 7 bits */ 207 + tio.c_iflag &= ~IGNBRK; /* Ignore break conditions */ 208 + tio.c_iflag &= ~BRKINT; /* SIGINT on break condition */ 209 + tio.c_iflag &= ~IGNCR; /* Discard CR on intput */ 210 + tio.c_iflag &= ~ICRNL; /* Convert CR to LF on input */ 211 + tio.c_iflag &= ~INLCR; /* Convert LF to CR on input */ 212 + tio.c_iflag &= ~IXOFF; /* Enable input flow control */ 213 + tio.c_iflag &= ~IXON; /* Enable output flow control */ 214 + tio.c_iflag &= ~IXANY; /* Any character as START */ 215 + tio.c_iflag &= ~IMAXBEL; /* Send BEL on buffer overflow */ 216 + 217 + tio.c_oflag &= ~OPOST; /* Enable output post processing */ 218 + 219 + tio.c_cflag |= CLOCAL; /* Don't use modem control lines */ 220 + tio.c_cflag &= ~HUPCL; /* Hang up modem on device close */ 221 + tio.c_cflag |= CREAD; /* Input can be read */ 222 + tio.c_cflag &= ~CRTSCTS; 223 + 224 + tio.c_lflag &= ~ICANON; /* Canonical mode */ 225 + tio.c_lflag &= ~ECHO; /* Enable echo */ 226 + tio.c_lflag &= ~ECHOE; /* Enable echo */ 227 + #ifdef ECHOPRT 228 + tio.c_lflag &= ~ECHOPRT; /* Enable echo */ 229 + #endif 230 + tio.c_lflag &= ~ECHOK; /* Enable echo */ 231 + tio.c_lflag &= ~ECHONL; /* Enable echo */ 232 + #ifdef ECHOCTL 233 + tio.c_lflag &= ~ECHOCTL; /* Enable echo */ 234 + #endif 235 + tio.c_lflag &= ~ISIG; /* Enable signals on special characters */ 236 + tio.c_lflag |= NOFLSH; /* Don't flush queues on special characters */ 237 + 238 + tio.c_cflag &= ~CSIZE; 239 + 240 + switch (bpc) { 241 + case 8: 242 + tio.c_cflag |= CS8; 243 + break; 244 + 245 + case 7: 246 + tio.c_cflag |= CS7; 247 + break; 248 + 249 + case 6: 250 + tio.c_cflag |= CS6; 251 + break; 252 + 253 + case 5: 254 + tio.c_cflag |= CS5; 255 + break; 256 + 257 + default: 258 + tio.c_cflag |= CS8; 259 + break; 260 + } 261 + 262 + if (stop == 1) { 263 + tio.c_cflag &= ~CSTOPB; 264 + } 265 + else { 266 + tio.c_cflag |= CSTOPB; 267 + } 268 + 269 + switch (parity) { 270 + case 0: 271 + tio.c_cflag &= ~PARENB; 272 + break; 273 + 274 + case 1: /* odd */ 275 + tio.c_cflag |= PARENB; 276 + tio.c_cflag |= PARODD; 277 + break; 278 + 279 + case 2: /* even */ 280 + tio.c_cflag |= PARENB; 281 + tio.c_cflag &= ~PARODD; 282 + break; 283 + 284 + case 3: /* mark */ 285 + case 4: /* space */ 286 + /* termios does not support these */ 287 + tio.c_cflag |= PARENB; 288 + tio.c_cflag &= ~PARODD; 289 + break; 290 + 291 + default: 292 + tio.c_cflag &= !PARENB; 293 + break; 294 + } 295 + 296 + if (bps < ((50 + 75) / 2)) { 297 + spd = B50; 298 + } 299 + else if (bps < ((75 + 110) / 2)) { 300 + spd = B75; 301 + } 302 + else if (bps < ((110 + 134) / 2)) { 303 + spd = B110; 304 + } 305 + else if (bps < ((134 + 150) / 2)) { 306 + spd = B134; 307 + } 308 + else if (bps < ((150 + 200) / 2)) { 309 + spd = B150; 310 + } 311 + else if (bps < ((200 + 300) / 2)) { 312 + spd = B200; 313 + } 314 + else if (bps < ((300 + 600) / 2)) { 315 + spd = B300; 316 + } 317 + else if (bps < ((600 + 1200) / 2)) { 318 + spd = B600; 319 + } 320 + else if (bps < ((1200 + 2400) / 2)) { 321 + spd = B1200; 322 + } 323 + else if (bps < ((2400 + 4800) / 2)) { 324 + spd = B2400; 325 + } 326 + else if (bps < ((4800 + 9600) / 2)) { 327 + spd = B4800; 328 + } 329 + else if (bps < ((9600 + 19200) / 2)) { 330 + spd = B9600; 331 + } 332 + else if (bps < ((19200 + 38400) / 2)) { 333 + spd = B19200; 334 + } 335 + #ifdef B38400 336 + else if (bps < ((38400 + 57600) / 2)) { 337 + spd = B38400; 338 + } 339 + #endif 340 + #ifdef B57600 341 + else if (bps < ((57600 + 115200) / 2)) { 342 + spd = B57600; 343 + } 344 + #endif 345 + #ifdef B115200 346 + else if (bps < ((115200 + 230400) / 2)) { 347 + spd = B115200; 348 + } 349 + #endif 350 + else { 351 + spd = B9600; 352 + } 353 + 354 + cfsetispeed (&tio, spd); 355 + cfsetospeed (&tio, spd); 356 + 357 + tio.c_cc[VMIN] = 1; 358 + tio.c_cc[VTIME] = 0; 359 + 360 + if (tcsetattr (drv->fd, TCSANOW, &tio)) { 361 + return (1); 362 + } 363 + 364 + tcflush (drv->fd, TCIOFLUSH); 365 + 366 + return (0); 367 + } 368 + 369 + static 370 + int chr_tios_init (char_tios_t *drv, const char *name) 371 + { 372 + chr_init (&drv->cdrv, drv); 373 + 374 + drv->cdrv.close = chr_tios_close; 375 + drv->cdrv.read = chr_tios_read; 376 + drv->cdrv.write = chr_tios_write; 377 + drv->cdrv.get_ctl = chr_tios_get_ctl; 378 + drv->cdrv.set_ctl = chr_tios_set_ctl; 379 + drv->cdrv.set_params = chr_tios_set_params; 380 + 381 + drv->fd = -1; 382 + 383 + drv->fname = chr_get_option (name, "file", 1); 384 + 385 + if (drv->fname != NULL) { 386 + drv->fd = open (drv->fname, O_RDWR | O_NOCTTY); 387 + 388 + if (drv->fd < 0) { 389 + return (1); 390 + } 391 + 392 + chr_tios_set_params (&drv->cdrv, 9600, 8, 0, 1); 393 + } 394 + 395 + return (0); 396 + } 397 + 398 + char_drv_t *chr_tios_open (const char *name) 399 + { 400 + char_tios_t *drv; 401 + 402 + drv = malloc (sizeof (char_tios_t)); 403 + 404 + if (drv == NULL) { 405 + return (NULL); 406 + } 407 + 408 + if (chr_tios_init (drv, name)) { 409 + chr_tios_close (&drv->cdrv); 410 + 411 + return (NULL); 412 + } 413 + 414 + return (&drv->cdrv); 415 + }
+41
src/drivers/char/char-tios.h
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: src/drivers/char/char-tios.h * 7 + * Created: 2009-03-06 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2009 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #ifndef PCE_DRIVERS_CHAR_TIOS_H 24 + #define PCE_DRIVERS_CHAR_TIOS_H 1 25 + 26 + 27 + #include <stdio.h> 28 + 29 + #include <drivers/char/char.h> 30 + 31 + 32 + typedef struct char_tios_t { 33 + char_drv_t cdrv; 34 + 35 + char *fname; 36 + 37 + int fd; 38 + } char_tios_t; 39 + 40 + 41 + #endif
+3
src/drivers/char/char.c
··· 36 36 struct chr_drv_list drvtab[] = { 37 37 { "null", chr_null_open }, 38 38 { "stdio", chr_stdio_open }, 39 + #ifdef PCE_ENABLE_CHAR_TIOS 40 + { "tios", chr_tios_open }, 41 + #endif 39 42 { NULL, NULL } 40 43 }; 41 44
+1
src/drivers/char/char.h
··· 90 90 char_drv_t *chr_open (const char *name); 91 91 char_drv_t *chr_null_open (const char *name); 92 92 char_drv_t *chr_stdio_open (const char *name); 93 + char_drv_t *chr_tios_open (const char *name); 93 94 94 95 95 96 #endif