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

📄 esp.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 5 页
字号:
	case TIOCSHAYESESP:		return (set_esp_config(info, (struct hayes_esp_config *)arg));		default:			return -ENOIOCTLCMD;		}	return 0;}static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios){	struct esp_struct *info = (struct esp_struct *)tty->driver_data;	if (   (tty->termios->c_cflag == old_termios->c_cflag)	    && (   RELEVANT_IFLAG(tty->termios->c_iflag) 		== RELEVANT_IFLAG(old_termios->c_iflag)))	  return;	change_speed(info);	/* Handle transition to B0 status */	if ((old_termios->c_cflag & CBAUD) &&		!(tty->termios->c_cflag & CBAUD)) {		info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);		cli();		serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);		serial_out(info, UART_ESI_CMD2, UART_MCR);		serial_out(info, UART_ESI_CMD2, info->MCR);		sti();	}	/* Handle transition away from B0 status */	if (!(old_termios->c_cflag & CBAUD) &&		(tty->termios->c_cflag & CBAUD)) {		info->MCR |= (UART_MCR_DTR | UART_MCR_RTS);		cli();		serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);		serial_out(info, UART_ESI_CMD2, UART_MCR);		serial_out(info, UART_ESI_CMD2, info->MCR);		sti();	}	/* Handle turning of CRTSCTS */	if ((old_termios->c_cflag & CRTSCTS) &&	    !(tty->termios->c_cflag & CRTSCTS)) {		rs_start(tty);	}#if 0	/*	 * No need to wake up processes in open wait, since they	 * sample the CLOCAL flag once, and don't recheck it.	 * XXX  It's not clear whether the current behavior is correct	 * or not.  Hence, this may change.....	 */	if (!(old_termios->c_cflag & CLOCAL) &&	    (tty->termios->c_cflag & CLOCAL))		wake_up_interruptible(&info->open_wait);#endif}/* * ------------------------------------------------------------ * rs_close() *  * This routine is called when the serial port gets closed.  First, we * wait for the last remaining data to be sent.  Then, we unlink its * async structure from the interrupt chain if necessary, and we free * that IRQ if nothing is left in the chain. * ------------------------------------------------------------ */static void rs_close(struct tty_struct *tty, struct file * filp){	struct esp_struct * info = (struct esp_struct *)tty->driver_data;	unsigned long flags;	if (!info || serial_paranoia_check(info, tty->device, "rs_close"))		return;		save_flags(flags); cli();		if (tty_hung_up_p(filp)) {		DBG_CNT("before DEC-hung");		goto out;	}	#ifdef SERIAL_DEBUG_OPEN	printk("rs_close ttys%d, count = %d\n", info->line, info->count);#endif	if ((tty->count == 1) && (info->count != 1)) {		/*		 * Uh, oh.  tty->count is 1, which means that the tty		 * structure will be freed.  Info->count should always		 * be one in these conditions.  If it's greater than		 * one, we've got real problems, since it means the		 * serial port won't be shutdown.		 */		printk("rs_close: bad serial port count; tty->count is 1, "		       "info->count is %d\n", info->count);		info->count = 1;	}	if (--info->count < 0) {		printk("rs_close: bad serial port count for ttys%d: %d\n",		       info->line, info->count);		info->count = 0;	}	if (info->count) {		DBG_CNT("before DEC-2");		goto out;	}	info->flags |= ASYNC_CLOSING;	/*	 * Save the termios structure, since this port may have	 * separate termios for callout and dialin.	 */	if (info->flags & ASYNC_NORMAL_ACTIVE)		info->normal_termios = *tty->termios;	if (info->flags & ASYNC_CALLOUT_ACTIVE)		info->callout_termios = *tty->termios;	/*	 * Now we wait for the transmit buffer to clear; and we notify 	 * the line discipline to only process XON/XOFF characters.	 */	tty->closing = 1;	if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)		tty_wait_until_sent(tty, info->closing_wait);	/*	 * At this point we stop accepting input.  To do this, we	 * disable the receive line status interrupts, and tell the	 * interrupt driver to stop checking the data ready bit in the	 * line status register.	 */	/* info->IER &= ~UART_IER_RLSI; */	info->IER &= ~UART_IER_RDI;	info->read_status_mask &= ~UART_LSR_DR;	if (info->flags & ASYNC_INITIALIZED) {		serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);		serial_out(info, UART_ESI_CMD2, info->IER);		/* disable receive timeout */		serial_out(info, UART_ESI_CMD1, ESI_SET_RX_TIMEOUT);		serial_out(info, UART_ESI_CMD2, 0x00);		/*		 * Before we drop DTR, make sure the UART transmitter		 * has completely drained; this is especially		 * important if there is a transmit FIFO!		 */		rs_wait_until_sent(tty, info->timeout);	}	shutdown(info);	if (tty->driver.flush_buffer)		tty->driver.flush_buffer(tty);	if (tty->ldisc.flush_buffer)		tty->ldisc.flush_buffer(tty);	tty->closing = 0;	info->event = 0;	info->tty = 0;	if (info->blocked_open) {		if (info->close_delay) {			set_current_state(TASK_INTERRUPTIBLE);			schedule_timeout(info->close_delay);		}		wake_up_interruptible(&info->open_wait);	}	info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|			 ASYNC_CLOSING);	wake_up_interruptible(&info->close_wait);out:	MOD_DEC_USE_COUNT;	restore_flags(flags);}static void rs_wait_until_sent(struct tty_struct *tty, int timeout){	struct esp_struct *info = (struct esp_struct *)tty->driver_data;	unsigned long orig_jiffies, char_time;	unsigned long flags;	if (serial_paranoia_check(info, tty->device, "rs_wait_until_sent"))		return;	orig_jiffies = jiffies;	char_time = ((info->timeout - HZ / 50) / 1024) / 5;	if (!char_time)		char_time = 1;	save_flags(flags); cli();	serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);	serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);	while ((serial_in(info, UART_ESI_STAT1) != 0x03) ||		(serial_in(info, UART_ESI_STAT2) != 0xff)) {		set_current_state(TASK_INTERRUPTIBLE);		schedule_timeout(char_time);		if (signal_pending(current))			break;		if (timeout && ((orig_jiffies + timeout) < jiffies))			break;		serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);		serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);	}		restore_flags(flags);	set_current_state(TASK_RUNNING);}/* * esp_hangup() --- called by tty_hangup() when a hangup is signaled. */static void esp_hangup(struct tty_struct *tty){	struct esp_struct * info = (struct esp_struct *)tty->driver_data;		if (serial_paranoia_check(info, tty->device, "esp_hangup"))		return;		rs_flush_buffer(tty);	shutdown(info);	info->event = 0;	info->count = 0;	info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);	info->tty = 0;	wake_up_interruptible(&info->open_wait);}/* * ------------------------------------------------------------ * esp_open() and friends * ------------------------------------------------------------ */static int block_til_ready(struct tty_struct *tty, struct file * filp,			   struct esp_struct *info){	DECLARE_WAITQUEUE(wait, current);	int		retval;	int		do_clocal = 0;	unsigned long	flags;	/*	 * If the device is in the middle of being closed, then block	 * until it's done, and then try again.	 */	if (tty_hung_up_p(filp) ||	    (info->flags & ASYNC_CLOSING)) {		if (info->flags & ASYNC_CLOSING)			interruptible_sleep_on(&info->close_wait);#ifdef SERIAL_DO_RESTART		if (info->flags & ASYNC_HUP_NOTIFY)			return -EAGAIN;		else			return -ERESTARTSYS;#else		return -EAGAIN;#endif	}	/*	 * If this is a callout device, then just make sure the normal	 * device isn't being used.	 */	if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {		if (info->flags & ASYNC_NORMAL_ACTIVE)			return -EBUSY;		if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&		    (info->flags & ASYNC_SESSION_LOCKOUT) &&		    (info->session != current->session))		    return -EBUSY;		if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&		    (info->flags & ASYNC_PGRP_LOCKOUT) &&		    (info->pgrp != current->pgrp))		    return -EBUSY;		info->flags |= ASYNC_CALLOUT_ACTIVE;		return 0;	}		/*	 * If non-blocking mode is set, or the port is not enabled,	 * then make the check up front and then exit.	 */	if ((filp->f_flags & O_NONBLOCK) ||	    (tty->flags & (1 << TTY_IO_ERROR))) {		if (info->flags & ASYNC_CALLOUT_ACTIVE)			return -EBUSY;		info->flags |= ASYNC_NORMAL_ACTIVE;		return 0;	}	if (info->flags & ASYNC_CALLOUT_ACTIVE) {		if (info->normal_termios.c_cflag & CLOCAL)			do_clocal = 1;	} else {		if (tty->termios->c_cflag & CLOCAL)			do_clocal = 1;	}		/*	 * Block waiting for the carrier detect and the line to become	 * free (i.e., not in use by the callout).  While we are in	 * this loop, info->count is dropped by one, so that	 * rs_close() knows when to free things.  We restore it upon	 * exit, either normal or abnormal.	 */	retval = 0;	add_wait_queue(&info->open_wait, &wait);#ifdef SERIAL_DEBUG_OPEN	printk("block_til_ready before block: ttys%d, count = %d\n",	       info->line, info->count);#endif	save_flags(flags);	cli();	if (!tty_hung_up_p(filp)) 		info->count--;	restore_flags(flags);	info->blocked_open++;	while (1) {		save_flags(flags);		cli();		if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&			(tty->termios->c_cflag & CBAUD)) {			unsigned int scratch;			serial_out(info, UART_ESI_CMD1, ESI_READ_UART);			serial_out(info, UART_ESI_CMD2, UART_MCR);			scratch = serial_in(info, UART_ESI_STAT1);			serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);			serial_out(info, UART_ESI_CMD2, UART_MCR);			serial_out(info, UART_ESI_CMD2,				scratch | UART_MCR_DTR | UART_MCR_RTS);		}		restore_flags(flags);		set_current_state(TASK_INTERRUPTIBLE);		if (tty_hung_up_p(filp) ||		    !(info->flags & ASYNC_INITIALIZED)) {#ifdef SERIAL_DO_RESTART			if (info->flags & ASYNC_HUP_NOTIFY)				retval = -EAGAIN;			else				retval = -ERESTARTSYS;	#else			retval = -EAGAIN;#endif			break;		}		serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);		if (serial_in(info, UART_ESI_STAT2) & UART_MSR_DCD)			do_clocal = 1;		if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&		    !(info->flags & ASYNC_CLOSING) &&		    (do_clocal))			break;		if (signal_pending(current)) {			retval = -ERESTARTSYS;			break;		}#ifdef SERIAL_DEBUG_OPEN		printk("block_til_ready blocking: ttys%d, count = %d\n",		       info->line, info->count);#endif		schedule();	}	set_current_state(TASK_RUNNING);	remove_wait_queue(&info->open_wait, &wait);	if (!tty_hung_up_p(filp))		info->count++;	info->blocked_open--;#ifdef SERIAL_DEBUG_OPEN	printk("block_til_ready after blocking: ttys%d, count = %d\n",	       info->line, info->count);#endif	if (retval)		return retval;	info->flags |= ASYNC_NORMAL_ACTIVE;	return 0;}	/* * This routine is called whenever a serial port is opened.  It * enables interrupts for a serial port, linking in its async structure into * the IRQ chain.   It also performs the serial-specific * initialization for the tty structure. */static int esp_open(struct tty_struct *tty, struct file * filp){	struct esp_struct	*info;	int 			retval, line;	line = MINOR(tty->device) - tty->driver.minor_start;	if ((line < 0) || (line >= NR_PORTS))		return -ENODEV;	/* find the port in the chain */	info = ports;	while (info && (info->line != line))		info = info->next_port;	if (!info) {		serial_paranoia_check(info, tty->device, "esp_open");		return -ENODEV;	}#ifdef SERIAL_DEBUG_OPEN	printk("esp_open %s%d, count = %d\n", tty->driver.name, info->line,	       info->count);#endif	MOD_INC_USE_COUNT;	info->count++;	tty->driver_data = info;	info->tty = tty;	if (!tmp_buf) {		tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);		if (!tmp_buf)			return -ENOMEM;	}		/*	 * Start up serial port	 */	retval = startup(info);	if (retval)		return retval;	retval = block_til_ready(tty, filp, info);	if (retval) {#ifdef SERIAL_DEBUG_OPEN		printk("esp_open returning after block_til_ready with %d\n",		       retval);#endif		return retval;	}	if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {		if (tty->driver.subtype == SERIAL_TYPE_NORMAL)			*tty->termios = info->normal_termios;		else 			*tty->termios = info->callout_termios;		change_speed(info);	}	info->session = current->session;	info->pgrp = current->pgrp;#ifdef SERIAL_DEBUG_OPEN	printk("esp_open ttys%d successful...", info->line);#endif	return 0;}/* * --------------------------------------------------------------------- * espserial_init() and friends * * espserial_init() is called at boot-time to initialize the serial driver. * --------------------------------------------------------------------- *//* * This routine prints out the appropriate serial driver version * number, and identifies which options were configured into this * driver. */ static _INLINE_ void show_serial_version(void){ 	printk(KERN_INFO "%s version %s (DMA %u)\n",		serial_name, serial_version, dma);}/* * This routine is called by espserial_init() to initialize a specific serial * port. */static _INLINE_ int autoconfig(struct esp_struct * info, int *region_start){	int port_detected = 0;	unsigned long flags;	save_flags(flags); cli();		/*	 * Check for ES

⌨️ 快捷键说明

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