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

📄 io_edgeport.c

📁 h内核
💻 C
📖 第 1 页 / 共 5 页
字号:
		return;	}	tty = port->tty;	if (!tty) {		dbg ("%s - no tty available", __FUNCTION__);		return;	}	/* if we are implementing XON/XOFF, send the stop character */	if (I_IXOFF(tty)) {		unsigned char stop_char = STOP_CHAR(tty);		status = edge_write (port, &stop_char, 1);		if (status <= 0) {			return;		}	}	/* if we are implementing RTS/CTS, toggle that line */	if (tty->termios->c_cflag & CRTSCTS) {		edge_port->shadowMCR &= ~MCR_RTS;		status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR);		if (status != 0) {			return;		}	}	return;}/***************************************************************************** * edge_unthrottle *	this function is called by the tty driver when it wants to resume the data *	being read from the port (called after SerialThrottle is called) *****************************************************************************/static void edge_unthrottle (struct usb_serial_port *port){	struct edgeport_port *edge_port = usb_get_serial_port_data(port);	struct tty_struct *tty;	int status;	dbg("%s - port %d", __FUNCTION__, port->number);	if (edge_port == NULL)		return;	if (!edge_port->open) {		dbg("%s - port not opened", __FUNCTION__);		return;	}	tty = port->tty;	if (!tty) {		dbg ("%s - no tty available", __FUNCTION__);		return;	}	/* if we are implementing XON/XOFF, send the start character */	if (I_IXOFF(tty)) {		unsigned char start_char = START_CHAR(tty);		status = edge_write (port, &start_char, 1);		if (status <= 0) {			return;		}	}	/* if we are implementing RTS/CTS, toggle that line */	if (tty->termios->c_cflag & CRTSCTS) {		edge_port->shadowMCR |= MCR_RTS;		status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR);		if (status != 0) {			return;		}	}	return;}/***************************************************************************** * SerialSetTermios *	this function is called by the tty driver when it wants to change the termios structure *****************************************************************************/static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios){	struct edgeport_port *edge_port = usb_get_serial_port_data(port);	struct tty_struct *tty = port->tty;	unsigned int cflag;	if (!port->tty || !port->tty->termios) {		dbg ("%s - no tty or termios", __FUNCTION__);		return;	}	cflag = tty->termios->c_cflag;	/* check that they really want us to change something */	if (old_termios) {		if (cflag == old_termios->c_cflag &&		    tty->termios->c_iflag == old_termios->c_iflag) {			dbg("%s - nothing to change", __FUNCTION__);			return;		}	}	dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 	    tty->termios->c_cflag, tty->termios->c_iflag);	if (old_termios) {		dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,		    old_termios->c_cflag, old_termios->c_iflag);	}	dbg("%s - port %d", __FUNCTION__, port->number);	if (edge_port == NULL)		return;	if (!edge_port->open) {		dbg("%s - port not opened", __FUNCTION__);		return;	}	/* change the port settings to the new ones specified */	change_port_settings (edge_port, old_termios);	return;}/***************************************************************************** * get_lsr_info - get line status register info * * Purpose: Let user call ioctl() to get info when the UART physically * 	    is emptied.  On bus types like RS485, the transmitter must * 	    release the bus after transmitting. This must be done when * 	    the transmit shift register is empty, not be done when the * 	    transmit holding register is empty.  This functionality * 	    allows an RS485 driver to be written in user space.  *****************************************************************************/static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *value){	unsigned int result = 0;	unsigned long flags;	spin_lock_irqsave(&edge_port->ep_lock, flags);	if (edge_port->maxTxCredits == edge_port->txCredits &&	    edge_port->txfifo.count == 0) {		dbg("%s -- Empty", __FUNCTION__);		result = TIOCSER_TEMT;	}	spin_unlock_irqrestore(&edge_port->ep_lock, flags);	if (copy_to_user(value, &result, sizeof(int)))		return -EFAULT;	return 0;}static int get_number_bytes_avail(struct edgeport_port *edge_port, unsigned int __user *value){	unsigned int result = 0;	struct tty_struct *tty = edge_port->port->tty;	if (!tty)		return -ENOIOCTLCMD;	result = tty->read_cnt;	dbg("%s(%d) = %d", __FUNCTION__,  edge_port->port->number, result);	if (copy_to_user(value, &result, sizeof(int)))		return -EFAULT;	//return 0;	return -ENOIOCTLCMD;}static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear){	struct edgeport_port *edge_port = usb_get_serial_port_data(port);	unsigned int mcr;	dbg("%s - port %d", __FUNCTION__, port->number);	mcr = edge_port->shadowMCR;	if (set & TIOCM_RTS)		mcr |= MCR_RTS;	if (set & TIOCM_DTR)		mcr |= MCR_DTR;	if (set & TIOCM_LOOP)		mcr |= MCR_LOOPBACK;	if (clear & TIOCM_RTS)		mcr &= ~MCR_RTS;	if (clear & TIOCM_DTR)		mcr &= ~MCR_DTR;	if (clear & TIOCM_LOOP)		mcr &= ~MCR_LOOPBACK;	edge_port->shadowMCR = mcr;	send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR);	return 0;}static int edge_tiocmget(struct usb_serial_port *port, struct file *file){	struct edgeport_port *edge_port = usb_get_serial_port_data(port);	unsigned int result = 0;	unsigned int msr;	unsigned int mcr;	dbg("%s - port %d", __FUNCTION__, port->number);	msr = edge_port->shadowMSR;	mcr = edge_port->shadowMCR;	result = ((mcr & MCR_DTR)	? TIOCM_DTR: 0)	  /* 0x002 */		  | ((mcr & MCR_RTS)	? TIOCM_RTS: 0)   /* 0x004 */		  | ((msr & EDGEPORT_MSR_CTS)	? TIOCM_CTS: 0)   /* 0x020 */		  | ((msr & EDGEPORT_MSR_CD)	? TIOCM_CAR: 0)   /* 0x040 */		  | ((msr & EDGEPORT_MSR_RI)	? TIOCM_RI:  0)   /* 0x080 */		  | ((msr & EDGEPORT_MSR_DSR)	? TIOCM_DSR: 0);  /* 0x100 */	dbg("%s -- %x", __FUNCTION__, result);	return result;}static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct __user *retinfo){	struct serial_struct tmp;	if (!retinfo)		return -EFAULT;	memset(&tmp, 0, sizeof(tmp));	tmp.type		= PORT_16550A;	tmp.line		= edge_port->port->serial->minor;	tmp.port		= edge_port->port->number;	tmp.irq			= 0;	tmp.flags		= ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;	tmp.xmit_fifo_size	= edge_port->maxTxCredits;	tmp.baud_base		= 9600;	tmp.close_delay		= 5*HZ;	tmp.closing_wait	= 30*HZ;//	tmp.custom_divisor	= state->custom_divisor;//	tmp.hub6		= state->hub6;//	tmp.io_type		= state->io_type;	if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))		return -EFAULT;	return 0;}/***************************************************************************** * SerialIoctl *	this function handles any ioctl calls to the driver *****************************************************************************/static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg){	struct edgeport_port *edge_port = usb_get_serial_port_data(port);	struct async_icount cnow;	struct async_icount cprev;	struct serial_icounter_struct icount;	dbg("%s - port %d, cmd = 0x%x", __FUNCTION__, port->number, cmd);	switch (cmd) {		// return number of bytes available		case TIOCINQ:			dbg("%s (%d) TIOCINQ", __FUNCTION__,  port->number);			return get_number_bytes_avail(edge_port, (unsigned int __user *) arg);			break;		case TIOCSERGETLSR:			dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__,  port->number);			return get_lsr_info(edge_port, (unsigned int __user *) arg);			return 0;		case TIOCGSERIAL:			dbg("%s (%d) TIOCGSERIAL", __FUNCTION__,  port->number);			return get_serial_info(edge_port, (struct serial_struct __user *) arg);		case TIOCSSERIAL:			dbg("%s (%d) TIOCSSERIAL", __FUNCTION__,  port->number);			break;		case TIOCMIWAIT:			dbg("%s (%d) TIOCMIWAIT", __FUNCTION__,  port->number);			cprev = edge_port->icount;			while (1) {				interruptible_sleep_on(&edge_port->delta_msr_wait);				/* see if a signal did it */				if (signal_pending(current))					return -ERESTARTSYS;				cnow = edge_port->icount;				if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&				    cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)					return -EIO; /* no change => error */				if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||				    ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||				    ((arg & TIOCM_CD)  && (cnow.dcd != cprev.dcd)) ||				    ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {					return 0;				}				cprev = cnow;			}			/* NOTREACHED */			break;		case TIOCGICOUNT:			cnow = edge_port->icount;			memset(&icount, 0, sizeof(icount));			icount.cts = cnow.cts;			icount.dsr = cnow.dsr;			icount.rng = cnow.rng;			icount.dcd = cnow.dcd;			icount.rx = cnow.rx;			icount.tx = cnow.tx;			icount.frame = cnow.frame;			icount.overrun = cnow.overrun;			icount.parity = cnow.parity;			icount.brk = cnow.brk;			icount.buf_overrun = cnow.buf_overrun;			dbg("%s (%d) TIOCGICOUNT RX=%d, TX=%d", __FUNCTION__,  port->number, icount.rx, icount.tx );			if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))				return -EFAULT;			return 0;	}	return -ENOIOCTLCMD;}/***************************************************************************** * SerialBreak *	this function sends a break to the port *****************************************************************************/static void edge_break (struct usb_serial_port *port, int break_state){	struct edgeport_port *edge_port = usb_get_serial_port_data(port);	int status;	/* flush and chase */	edge_port->chaseResponsePending = TRUE;	dbg("%s - Sending IOSP_CMD_CHASE_PORT", __FUNCTION__);	status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0);	if (status == 0) {		// block until chase finished		block_until_chase_response(edge_port);	} else {		edge_port->chaseResponsePending = FALSE;	}	if (break_state == -1) {		dbg("%s - Sending IOSP_CMD_SET_BREAK", __FUNCTION__);		status = send_iosp_ext_cmd (edge_port, IOSP_CMD_SET_BREAK, 0);	} else {		dbg("%s - Sending IOSP_CMD_CLEAR_BREAK", __FUNCTION__);		status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CLEAR_BREAK, 0);	}	if (status) {		dbg("%s - error sending break set/clear command.", __FUNCTION__);	}	return;}/***************************************************************************** * process_rcvd_data *	this function handles the data received on the bulk in pipe. *****************************************************************************/static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char * buffer, __u16 bufferLength){	struct usb_serial_port *port;	struct edgeport_port *edge_port;	struct tty_struct *tty;	__u16 lastBufferLength;	__u16 rxLen;	dbg("%s", __FUNCTION__);	lastBufferLength = bufferLength + 1;	while (bufferLength > 0) {		/* failsafe incase we get a message that we don't understand */		if (lastBufferLength == bu

⌨️ 快捷键说明

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