⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sh.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
#ifndef lintstatic char *sccsid = "@(#)sh.c	4.1	(ULTRIX)	7/2/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1985-88 by			* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any	other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived	from  software	received  from	the	* *   University    of	California,   Berkeley,   and	from   Bell	* *   Laboratories.  Use, duplication, or disclosure is	subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or	reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//* * sh.c * * MicroVAX 2000 serial line expander (8 line SLU) driver * * Modification history *  * 31-Oct-89 - Randall Brown * *	Added the support to allow the device to determine if baudrate is  *	supported before it is set in the tty data structures. * * 15-Aug-89 - Randall Brown * *	Changed all references of TCSADFLUSH to TCSAFLUSH  * * 21-Jul-89 - Randall Brown * *	Moved default open and default close code to tty.c and call it *	using tty_def_open() and tty_def_close().  In the close routine, *	don't clear the baudrate so that subsequent opens will keep the *	present attributes.  This only applies to a Berkeley environment. * * 12-Jun-89 - dws *	Added trusted path support. * * 30-May-89 - Darrell Dunnuck *	Changed check of system type to check for system type VAXSTAR. * * 25-Jan-89 - Randall Brown * *	Changed cd_drop to look at LNOHANG.  Changed close routine to look *	at HUPCL. * * 02-Sep-88 - Tim Burke * *	Return EINVAL instead of ENOTTY for POSIX programs on invalid ioctls. * * 18-Aug-88 - Tim Burke * *	If PARMRK is set and a BREAK occurs, return '\0377','\0','\0'. * * 5-Aug-88 - Tim Burke * *	Return the 2 character sequence 0377, 0377 upon receipt of a valid *	0377 character only when PARMRK is set under the termio line disc. * *  16-May-88 - Tim Burke * * 	Call param routine for setting of local mode word because it can  * 	affect bit size and parity. * * 15-Feb-88 - Fred Canter *	Changes for VAX420 (CVAXstar/PVAX) support. * * 29-Jan-88 - Tim Burke *	Changed most softCAR[unit&LINEMASK] references to use the CLOCAL *	bit of the control flags to determine if the line is set to be a *	modem line or a direct connect.  The setting of softCAR[] remains *	to allow one to set default settings for device open. * *  1-Dec-87 - Tim Burke * *	Added support for both System V termio(7) and POSIX termios(7).  These *	changes also include support for 8-bit canonical processing.  Changes *	involve: * *	- Default settings on first open depend on mode of open.  For termio *	  opens the defaults are "RAW" style, while non-termio opens default *	  to the traditional "cooked" style. *	- The driver now represents its terminal attributes and special  *	  characters in the POSIX termios data structure.  This contrasts the *	  original approach of storing attributes and special chars in the *	  t_flags, ltchars and tchars. *	- New termio ioctls: TCSANOW, TCSADRAIN, TCSADFLUSH, TCSETA, TESETAW, *	  TCSETAF.	 *	- Addition of LPASS8 to local mode word for 8-bit canonical support. * *  8-Sep-87 - Ricky Palmer (rsp) * *      Fixed DEVIOCGET to use LINEMASK where appropriate to correctly *      select line number off of unit. * *  7-Sep-87 - rsp * *      Added code in DEVIOCGET to "&" in LINEMASK with unit to *      correctly determine line number. * *  2-Sept-87 - Tim Burke * *	Added support for hardware auto flow control on the outgoing side.  This *	will provide quick response to start/stop characters which will reduce *	buffer overflow on the receiving device. * * 24-Mar-87 - Tim Burke * *	Added full TERMIO functionality to terminal subsystem. * *  6-Feb-87 - Tim Burke * *	Removed printf of master reset failure in probe routine, as it may be *	incorrectly appearing. (Particularly in the DMF & DMZ drivers) *	This catches sh.c up to all changes in dhu.c thru delta 1.31. * * 28-Jan-87 - Tim Burke * *	Added the capability to ignore the "DSR" modem signal.  This is being *	done to allow modems that do not follow DEC Standard 52 to still  *	function as they would have prior to the addition of DECSTD52 code *	into the drivers.  If the driver is setup to ignore "DSR" then it will *	not be following DECSTD52.  To follow DECSTD52 set shdsr to "1", to *	ignore "DSR" set shdsr to be "0"; *	This catches sh.c up to all changes in dhu.c thru delta 1.30. * *  23-Jan-87 -- tim  (Tim Burke) *	Bug fix in shclose to prevent lines from hanging after another line has *	closed.  The problem is a result of not setting the correct line number *	in the csr and masking interrupts. *	This catches sh.c up to all changes in dhu.c thru delta 1.29. * *  18-Jan-87 -- fred (Fred Canter) *	Added Tim Burke's latest modem control change: *	"Bug fix to TIOCMODEM to clear modem flags if signals are not up". *	This catches sh.c up to all changes in dhu.c thru delta 1.28. *	Removed unused variable and one line of code from shxint(). *	Replaced referrences to dhu with sh in comments. * *  15-Jan-87 -- fred (Fred Canter) *	Fixed a bug in the two character line parameter change *	delay added in the last modification. * *   7-Jan-87 -- fred (Fred Canter) *	Added a two character delay before changing line parameters, *	to get rid of extra characters printed after the login prompt. *	Cleaned out all my debug code. *	The sh driver is now up to date with shu.c delta 1.27. * *  16-Dec-86 -- fred (Fred Canter) *	Changes for removal of DEV_MODEM_OFF devioctl flag. *	Improved driver (fixed flow control). * *   4-Dec-86 -- fred (Fred Canter) *	Converted first pass driver into a real driver. *	Cought up to data with all changes in dhu.c (delta 1.26). * *   3-Sep-86 -- fred (Fred Canter) *	Cleaned up some comments. *	Only configure the sh device on a MicroVAX 2000. *	Select sh as interrupt source instead of video board. * *  26-Aug-86 -- rsp (Ricky Palmer) *	Cleaned up devioctl code to (1) zero out devget structure *	upon entry, (2) use strlen instead of fixed storage *	for bcopy's, and (3) updated DEVIOCGET request code. * *   2-Jul-86 -- fred (Fred Canter) *	Created this first pass driver for MicroVAX 2000 *	serial line expander (8 line SLU). *	Derived from dhu.c (delta 1.17). * *//* * Implementation notes: * *	Multiunit support maintained (except for unit CSR address) *	for possible future expansion. * *	Decstandard 52 modem control support remains in tact, *	in case modem control is ever added to this device. *	The modem control code is disabled if bit 2 (SH_MSTAT) in *	the line status register is set, which it is for the *	current implementation of the serial line expander hardware. * *	Complete deactivation of the latent modem control code depends *	on the flags in the config file being set to 0x0ff (all lines *	local mode). Turning off any of the flag bit would probably *	cause the line to hang waiting for carrier. * *	This driver was derived from the DHU11 driver. The DHU11 *	register names and bit names were used for consistency and *	to allow easy porting of dhu.c changes to sh.c. * *	WARNING: *		The sh device (really a dhu11 chip) requires a delay of *		two character times after a transmitter action interrupt *		before the modem signals or line parameters can be *		changed. This driver handles this restriction for line *		parameter changes, but not for modem control changes. *		If modem control is ever added to the hardware, this *		restriction must be taken in to account. * */#include "sh.h"#if NSH > 0  || defined(BINARY)#include "../data/sh_data.c"int shdebug = 0;int shcdtime = 2;char sh_speeds[] = {	0, 0, 01, 02, 03, 04, 0, 05,	06, 07, 010, 012, 013, 015, 016, 0	};short	sh_valid_speeds = 0xffbf; /* 1,1,1,1, 1,1,1,1, 1,0,1,1, 1,1,1,1 *//* * Number of microseconds per character for each bit * rate in the sh_speeds[] tables. Used in shparam() * to ensure a delay of two character times between * a transmitter interrupt and the driver changing the * line parameters. The hardware tells us it is done * transmitting two characters before it really is done. */#define	SHDTSIZE	16	/* size of delay table */int sh_delays[] = {	0,		/* 0 */	500000,		/* 50 */	133333,		/* 75 */	100000,		/* 110 */	67159,		/* 134.5 */	66667,		/* 150 */	50000,		/* 200 - not supported by the hardware */	33333,		/* 300 */	16667,		/* 600 */	8333,		/* 1200 */	5556,		/* 1800 */			/* 2000 - NOT in bit rate table! */	4167,		/* 2400 */	2083,		/* 4800 */			/* 7200 - not in bit rate table! */	1042,		/* 9600 */	521,		/* 19200 */	260,		/* 38400 - not allowed by software */};/* * This array holds the new value to be loaded into * the line parameter register after the two character * timeout (see above) has expired. */int	sh_lpr_load();unsigned short sh_newlpr[8];/* * Soft copy of CSR low byte. We need this * because any read of the CSR can cause a loss * of a transmitter action interrupt. */char	sh_softcsr;/* * Definition of the driver for the auto-configuration program. */int	shprobe(), shattach(), shrint(), shxint(), shbaudrate();int	sh_cd_drop(), sh_dsr_check(), sh_cd_down(), sh_tty_drop();struct	timeval shzerotime = {0,0};u_short shstd[] = { 0 };struct	uba_driver shdriver =	{ shprobe, 0, shattach, 0, shstd, "sh", shinfo };int	shstart(), ttrstrt();#ifndef MODEM_CD#define MODEM_CD   0x01#define MODEM_DSR  0x02#define MODEM_CTS  0x04#define MODEM_DSR_START  0x08#endif#define LINEMASK 0x07	/* mask of higher bits of csr to get a line # */extern	struct	nexus	nexus[];/* * Routine for configuration to force a sh to interrupt. * Set to transmit at 9600 baud, and cause a transmitter interrupt. *//*ARGSUSED*/shprobe(reg)	caddr_t reg;		/* NOT USED */{	register struct nb_regs *shiaddr = (struct nb_regs *)nexus;	register struct shdevice *shaddr = (struct shdevice *)shmem;	int totaldelay; 		/* Self-test timeout counter */#ifdef lint	if (sh_cnt == 0) sh_cnt = 1;	shrint(0); shxint(0);#endif	if(shdebug)		printf("shprobe\n");	/*	 * Only on a MicroVAX 2000 and	 * only if serial line expander installed.	 * Also on CVAXstar (assume there will be a CTEAMMATE).	 * CAUTION: watchout for MULTU bit meaning change on CVAXstar!	 */	if (((cpu != VAXSTAR) && (cpu != C_VAXSTAR)) ||	    ((vs_cfgtst&VS_MULTU) == 0) || ((vs_cfgtst&VS_VIDOPT) == 0))		return(0);	shiaddr->nb_vdc_sel = 1;	/* select serial option interrupts */	/*	 * If a self test is not being done, start one up.  Wait for the	 * self-test (to a max of 3.5 sec.) to complete before interrupting.	 * SLU spec. says max of 2 seconds for self test to complete.	 */	if ((shaddr->csr.low & SH_MRESET) == 0)	    shaddr->csr.low = SH_MRESET;	totaldelay = 0;	while ( (shaddr->csr.low & SH_MRESET) && ( totaldelay <= 70) ){	    totaldelay++;	    DELAY(50000);	}	if (shaddr->csr.low & SH_MRESET)	    printf("sh0: hardware failed to exit self-test\n");	else if (shaddr->csr.high & SH_DIAGFAIL)	    printf("se0: hardware failed self-test\n");	/*	 * Clear intr cntlr req bits and set enable bits	 */	shiaddr->nb_int_reqclr = (SINT_VF|SINT_VS);	shiaddr->nb_int_msk |= (SINT_VF|SINT_VS);	shaddr->csr.low = 0;  /* transmit on channel 0 */	sh_softcsr = 0;	shaddr->csr.high = SH_XIE; /* enable transmit interrupts */	shaddr->lpr = sh_speeds[B9600] << 12 | SH_BITS7 | SH_PENABLE;	shaddr->tbuffad2.high = SH_XEN;	shaddr->fun.fs.fifosize = (char) 0;	DELAY(100000);		/* wait 1/10'th of a sec for interrupt */	{ char temp = shaddr->csr.high; /* clear transmit action */ }	shaddr->csr.high = 0;	 /* disable transmit interrupts */	shiaddr->nb_int_reqclr = (SINT_VF|SINT_VS);	if (cvec && cvec != 0x200) /* check to see if interrupt occurred */		cvec -= 4;	   /* point to first interrupt vector (recv)*/	return (1);	/* not sizeof anything, just says probe succeeded */}/* * Routine called to attach a sh. */shattach(ui)	struct uba_device *ui;{#ifdef SHDEBUG	if(shdebug)		printf("shattach %x, %d\n", ui->ui_flags, ui->ui_unit);#endif SHDEBUG	shsoftCAR[ui->ui_unit] = ui->ui_flags;	shdefaultCAR[ui->ui_unit] = ui->ui_flags;}/* * Open an SH line. * Turn on this sh if this is the first use of it. *//*ARGSUSED*/shopen(dev, flag)	dev_t dev;{	register struct tty *tp;	register int unit, sh;	register struct shdevice *addr;	register struct uba_device *ui;	int s;	int inuse;  /*hold state of inuse bit while blocked waiting for carr*/	unit = minor(dev);	sh = unit >> 3;	if (unit >= nNSH*8 || (ui = shinfo[sh])== 0 || ui->ui_alive == 0)		return (ENXIO);	tp = &sh_tty[unit];	if (tp->t_state&TS_XCLUDE && u.u_uid!=0)		return (EBUSY);#ifdef SHDEBUG	if (shdebug)		mprintf("shopen:  line=%d, state=%x, pid=%d\n", unit,			tp->t_state, u.u_procp->p_pid);#endif	while (tp->t_state&TS_CLOSING) /* let DTR stay down for awhile */		sleep((caddr_t)&tp->t_rawq, TTIPRI);	addr = (struct shdevice *)shmem;	tp->t_addr = (caddr_t)addr;	tp->t_oproc = shstart;	tp->t_baudrate = shbaudrate;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -