Lines Matching defs:scb

68 static int hardwire_open (struct serial *scb, const char *name);
69 static void hardwire_raw (struct serial *scb);
70 static int wait_for (struct serial *scb, int timeout);
71 static int hardwire_readchar (struct serial *scb, int timeout);
72 static int do_hardwire_readchar (struct serial *scb, int timeout);
73 static int generic_readchar (struct serial *scb, int timeout,
74 int (*do_readchar) (struct serial *scb,
77 static int hardwire_setbaudrate (struct serial *scb, int rate);
78 static void hardwire_close (struct serial *scb);
79 static int get_tty_state (struct serial *scb,
81 static int set_tty_state (struct serial *scb,
83 static serial_ttystate hardwire_get_tty_state (struct serial *scb);
84 static int hardwire_set_tty_state (struct serial *scb, serial_ttystate state);
95 static int do_unix_readchar (struct serial *scb, int timeout);
98 static void reschedule (struct serial *scb);
107 hardwire_open (struct serial *scb, const char *name)
109 scb->fd = open (name, O_RDWR);
110 if (scb->fd < 0)
117 get_tty_state (struct serial *scb, struct hardwire_ttystate *state)
120 if (tcgetattr (scb->fd, &state->termios) < 0)
127 if (ioctl (scb->fd, TCGETA, &state->termio) < 0)
133 if (ioctl (scb->fd, TIOCGETP, &state->sgttyb) < 0)
135 if (ioctl (scb->fd, TIOCGETC, &state->tc) < 0)
137 if (ioctl (scb->fd, TIOCGLTC, &state->ltc) < 0)
139 if (ioctl (scb->fd, TIOCLGET, &state->lmode) < 0)
147 set_tty_state (struct serial *scb, struct hardwire_ttystate *state)
150 if (tcsetattr (scb->fd, TCSANOW, &state->termios) < 0)
157 if (ioctl (scb->fd, TCSETA, &state->termio) < 0)
163 if (ioctl (scb->fd, TIOCSETN, &state->sgttyb) < 0)
165 if (ioctl (scb->fd, TIOCSETC, &state->tc) < 0)
167 if (ioctl (scb->fd, TIOCSLTC, &state->ltc) < 0)
169 if (ioctl (scb->fd, TIOCLSET, &state->lmode) < 0)
177 hardwire_get_tty_state (struct serial *scb)
183 if (get_tty_state (scb, state))
190 hardwire_set_tty_state (struct serial *scb, serial_ttystate ttystate)
196 return set_tty_state (scb, state);
200 hardwire_noflush_set_tty_state (struct serial *scb,
229 return set_tty_state (scb, &new_state);
233 hardwire_print_tty_state (struct serial *scb,
291 hardwire_drain_output (struct serial *scb)
294 return tcdrain (scb->fd);
298 return ioctl (scb->fd, TCSBRK, 1);
307 if (get_tty_state (scb, &state))
313 return (ioctl (scb->fd, TIOCSETP, &state.sgttyb));
320 hardwire_flush_output (struct serial *scb)
323 return tcflush (scb->fd, TCOFLUSH);
327 return ioctl (scb->fd, TCFLSH, 1);
332 return ioctl (scb->fd, TIOCFLUSH, 0);
337 hardwire_flush_input (struct serial *scb)
339 ser_unix_flush_input (scb);
342 return tcflush (scb->fd, TCIFLUSH);
346 return ioctl (scb->fd, TCFLSH, 0);
351 return ioctl (scb->fd, TIOCFLUSH, 0);
356 hardwire_send_break (struct serial *scb)
359 return tcsendbreak (scb->fd, 0);
363 return ioctl (scb->fd, TCSBRK, 0);
371 status = ioctl (scb->fd, TIOCSBRK, 0);
379 status = ioctl (scb->fd, TIOCCBRK, 0);
386 hardwire_raw (struct serial *scb)
390 if (get_tty_state (scb, &state))
418 scb->current_timeout = 0;
420 if (set_tty_state (scb, &state))
424 /* Wait for input on scb, with timeout seconds. Returns 0 on success,
441 wait_for (struct serial *scb, int timeout)
458 FD_SET (scb->fd, &readfds);
461 numfds = select (scb->fd + 1, &readfds, 0, 0, &tv);
463 numfds = select (scb->fd + 1, &readfds, 0, 0, 0);
478 if (timeout == scb->current_timeout)
481 scb->current_timeout = timeout;
486 if (get_tty_state (scb, &state))
507 scb->current_timeout = 12;
508 state.termios.c_cc[VTIME] = scb->current_timeout * 10;
509 scb->timeout_remaining = timeout - scb->current_timeout;
531 scb->current_timeout = 12;
532 state.termio.c_cc[VTIME] = scb->current_timeout * 10;
533 scb->timeout_remaining = timeout - scb->current_timeout;
538 if (set_tty_state (scb, &state))
562 do_hardwire_readchar (struct serial *scb, int timeout)
582 quickly as possible. It is not safe to touch scb, since
592 scb->timeout_remaining = (timeout < 0 ? timeout : timeout - delta);
593 status = wait_for (scb, delta);
598 status = read (scb->fd, scb->buf, BUFSIZ);
606 if (scb->timeout_remaining > 0)
608 timeout = scb->timeout_remaining;
611 else if (scb->timeout_remaining < 0)
622 scb->bufcnt = status;
623 scb->bufcnt--;
624 scb->bufp = scb->buf;
625 return *scb->bufp++;
630 hardwire_readchar (struct serial *scb, int timeout)
632 return generic_readchar (scb, timeout, do_hardwire_readchar);
781 hardwire_setbaudrate (struct serial *scb, int rate)
794 if (get_tty_state (scb, &state))
816 return set_tty_state (scb, &state);
820 hardwire_setstopbits (struct serial *scb, int num)
825 if (get_tty_state (scb, &state))
859 return set_tty_state (scb, &state);
863 hardwire_close (struct serial *scb)
865 if (scb->fd < 0)
868 close (scb->fd);
869 scb->fd = -1;
877 ser_unix_nop_get_tty_state (struct serial *scb)
884 ser_unix_nop_set_tty_state (struct serial *scb, serial_ttystate ttystate)
890 ser_unix_nop_raw (struct serial *scb)
895 /* Wait for input on scb, with timeout seconds. Returns 0 on success,
899 ser_unix_wait_for (struct serial *scb, int timeout)
916 FD_SET (scb->fd, &readfds);
917 FD_SET (scb->fd, &exceptfds);
920 numfds = select (scb->fd + 1, &readfds, 0, &exceptfds, &tv);
922 numfds = select (scb->fd + 1, &readfds, 0, &exceptfds, 0);
944 do_unix_readchar (struct serial *scb, int timeout)
962 quickly as possible. It is not safe to touch scb, since
972 status = ser_unix_wait_for (scb, delta);
999 status = read (scb->fd, scb->buf, BUFSIZ);
1014 scb->bufcnt = status;
1015 scb->bufcnt--;
1016 scb->bufp = scb->buf;
1017 return *scb->bufp++;
1035 generic_readchar (struct serial *scb, int timeout,
1036 int (do_readchar) (struct serial *scb, int timeout))
1039 if (scb->bufcnt > 0)
1041 ch = *scb->bufp;
1042 scb->bufcnt--;
1043 scb->bufp++;
1045 else if (scb->bufcnt < 0)
1048 ch = scb->bufcnt;
1052 ch = do_readchar (scb, timeout);
1060 scb->bufcnt = ch;
1063 scb->bufcnt = 0;
1068 reschedule (scb);
1073 ser_unix_readchar (struct serial *scb, int timeout)
1075 return generic_readchar (scb, timeout, do_unix_readchar);
1079 ser_unix_nop_noflush_set_tty_state (struct serial *scb,
1087 ser_unix_nop_print_tty_state (struct serial *scb,
1096 ser_unix_nop_setbaudrate (struct serial *scb, int rate)
1102 ser_unix_nop_setstopbits (struct serial *scb, int num)
1108 ser_unix_write (struct serial *scb, const char *str, int len)
1114 cc = write (scb->fd, str, len);
1125 ser_unix_nop_flush_output (struct serial *scb)
1131 ser_unix_flush_input (struct serial *scb)
1133 if (scb->bufcnt >= 0)
1135 scb->bufcnt = 0;
1136 scb->bufp = scb->buf;
1144 ser_unix_nop_send_break (struct serial *scb)
1150 ser_unix_nop_drain_output (struct serial *scb)
1167 /* Value of scb->async_state: */
1182 /* Identify and schedule the next ASYNC task based on scb->async_state
1183 and scb->buf* (the input FIFO). A state machine is used to avoid
1188 reschedule (struct serial *scb)
1190 if (serial_is_async_p (scb))
1193 switch (scb->async_state)
1196 if (scb->bufcnt == 0)
1200 delete_file_handler (scb->fd);
1201 next_state = create_timer (0, push_event, scb);
1205 if (scb->bufcnt == 0)
1207 add_file_handler (scb->fd, fd_event, scb);
1212 next_state = create_timer (0, push_event, scb);
1216 if (scb->bufcnt == 0)
1218 delete_timer (scb->async_state);
1219 add_file_handler (scb->fd, fd_event, scb);
1223 next_state = scb->async_state;
1226 if (serial_debug_p (scb))
1231 if (scb->async_state != FD_SCHEDULED)
1233 scb->fd);
1236 if (scb->async_state == FD_SCHEDULED)
1238 scb->fd);
1242 scb->async_state = next_state;
1255 struct serial *scb = context;
1258 scb->bufcnt = SERIAL_ERROR;
1260 else if (scb->bufcnt == 0)
1268 nr = read (scb->fd, scb->buf, BUFSIZ);
1273 scb->bufcnt = SERIAL_EOF;
1277 scb->bufcnt = nr;
1278 scb->bufp = scb->buf;
1282 scb->bufcnt = SERIAL_ERROR;
1285 scb->async_handler (scb, scb->async_context);
1286 reschedule (scb);
1297 struct serial *scb = context;
1298 scb->async_state = NOTHING_SCHEDULED; /* Timers are one-off */
1299 scb->async_handler (scb, scb->async_context);
1301 reschedule (scb);
1307 ser_unix_async (struct serial *scb,
1313 scb->async_state = NOTHING_SCHEDULED;
1314 if (serial_debug_p (scb))
1316 scb->fd);
1317 reschedule (scb);
1321 if (serial_debug_p (scb))
1323 scb->fd);
1325 switch (scb->async_state)
1328 delete_file_handler (scb->fd);
1333 delete_timer (scb->async_state);