home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / nindy-share / ttybreak.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  2.5 KB  |  81 lines

  1. /*****************************************************************************
  2.  * Copyright 1990, 1992 Free Software Foundation, Inc.
  3.  *
  4.  * This code was donated by Intel Corp.
  5.  *
  6.  * Intel hereby grants you permission to copy, modify, and 
  7.  * distribute this software and its documentation.  Intel grants
  8.  * this permission provided that the above copyright notice 
  9.  * appears in all copies and that both the copyright notice and
  10.  * this permission notice appear in supporting documentation.  In
  11.  * addition, Intel grants this permission provided that you
  12.  * prominently mark as not part of the original any modifications
  13.  * made to this software or documentation, and that the name of 
  14.  * Intel Corporation not be used in advertising or publicity 
  15.  * pertaining to distribution of the software or the documentation 
  16.  * without specific, written prior permission.  
  17.  *
  18.  * Intel Corporation does not warrant, guarantee or make any 
  19.  * representations regarding the use of, or the results of the use
  20.  * of, the software and documentation in terms of correctness, 
  21.  * accuracy, reliability, currentness, or otherwise; and you rely
  22.  * on the software, documentation and results solely at your own risk.
  23.  *****************************************************************************/
  24.  
  25. static char rcsid[] =
  26.     "$Id";
  27.  
  28.  
  29. /******************************************************************************
  30.  * send_break:
  31.  *
  32.  *    This function sends a a "break" to the specified tty.  This is useful
  33.  *    if the tty is attached to an i960 board equipped with a break-detector
  34.  *    circuit that causes a hard reset of the board.
  35.  ******************************************************************************/
  36.  
  37. #include <stdio.h>
  38. #include "ttycntl.h"
  39.  
  40. #ifdef USG
  41.     send_break( fd )
  42.         int fd;    /* File descriptor of i960 tty */
  43.     {
  44.         TTY_FLUSH(fd);
  45.         ioctl( fd, TCSBRK, 0 );
  46.     }
  47.  
  48. #else    /* BSD Unix */
  49.  
  50. #    include <signal.h>
  51. #    include <sys/time.h>
  52.  
  53.     static void
  54.     alarm_handler()
  55.     {
  56.         return;
  57.     }
  58.  
  59.     send_break( fd )
  60.         int fd;    /* File descriptor of i960 tty */
  61.     {
  62.         struct itimerval t;
  63.         void (*old_alarm)();    /* Alarm signal handler on entry */
  64.  
  65.         old_alarm = signal( SIGALRM, alarm_handler );
  66.  
  67.         /* Set timer for 1/4 second break */
  68.         t.it_value.tv_sec = 0;
  69.         t.it_value.tv_usec = 250000;
  70.         t.it_interval.tv_sec = t.it_interval.tv_usec = 0;
  71.  
  72.         /* Assert break for the duration of the timer */
  73.         ioctl( fd, TIOCSBRK, 0 );
  74.         setitimer( ITIMER_REAL, &t, 0 );
  75.         sigpause(0);
  76.         ioctl( fd, TIOCCBRK, 0 );
  77.  
  78.         signal( SIGALRM, old_alarm );
  79.     }
  80. #endif
  81.