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

📄 uart.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
{	struct serial_state *sstate;	sstate = rs_table + line;	if (sstate->info) {		sstate->count++;		*ret_info = (ser_info_t *)sstate->info;		return 0;	}	else {		return -ENOMEM;	}}/* * 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 rs_8xx_open(struct tty_struct *tty, struct file * filp){	ser_info_t	*info;	int 		retval, line;	line = MINOR(tty->device) - tty->driver.minor_start;	if ((line < 0) || (line >= NR_PORTS))		return -ENODEV;	retval = get_async_struct(line, &info);	if (retval)		return retval;	if (serial_paranoia_check(info, tty->device, "rs_open"))		return -ENODEV;#ifdef SERIAL_DEBUG_OPEN	printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,	       info->state->count);#endif	tty->driver_data = info;	info->tty = tty;	/*	 * Start up serial port	 */	retval = startup(info);	if (retval)		return retval;	MOD_INC_USE_COUNT;	retval = block_til_ready(tty, filp, info);	if (retval) {#ifdef SERIAL_DEBUG_OPEN		printk("rs_open returning after block_til_ready with %d\n",		       retval);#endif		MOD_DEC_USE_COUNT;		return retval;	}	if ((info->state->count == 1) &&	    (info->flags & ASYNC_SPLIT_TERMIOS)) {		if (tty->driver.subtype == SERIAL_TYPE_NORMAL)			*tty->termios = info->state->normal_termios;		else			*tty->termios = info->state->callout_termios;		change_speed(info);	}	info->session = current->session;	info->pgrp = current->pgrp;#ifdef SERIAL_DEBUG_OPEN	printk("rs_open ttys%d successful...", info->line);#endif	return 0;}/* * /proc fs routines.... */static int inline line_info(char *buf, struct serial_state *state){#ifdef notdef	struct async_struct *info = state->info, scr_info;	char	stat_buf[30], control, status;#endif	int	ret;	ret = sprintf(buf, "%d: uart:%s port:%X irq:%d",		      state->line,		      (PORT_IS_SCC(state->smc_scc_num)) ? "SCC" : "SMC",		      (unsigned int)(state->port), state->irq);	if (!state->port || (state->type == PORT_UNKNOWN)) {		ret += sprintf(buf+ret, "\n");		return ret;	}#ifdef notdef	/*	 * Figure out the current RS-232 lines	 */	if (!info) {		info = &scr_info;	/* This is just for serial_{in,out} */		info->magic = SERIAL_MAGIC;		info->port = state->port;		info->flags = state->flags;		info->quot = 0;		info->tty = 0;	}	cli();	status = serial_in(info, UART_MSR);	control = info ? info->MCR : serial_in(info, UART_MCR);	sti();	stat_buf[0] = 0;	stat_buf[1] = 0;	if (control & UART_MCR_RTS)		strcat(stat_buf, "|RTS");	if (status & UART_MSR_CTS)		strcat(stat_buf, "|CTS");	if (control & UART_MCR_DTR)		strcat(stat_buf, "|DTR");	if (status & UART_MSR_DSR)		strcat(stat_buf, "|DSR");	if (status & UART_MSR_DCD)		strcat(stat_buf, "|CD");	if (status & UART_MSR_RI)		strcat(stat_buf, "|RI");	if (info->quot) {		ret += sprintf(buf+ret, " baud:%d",			       state->baud_base / info->quot);	}	ret += sprintf(buf+ret, " tx:%d rx:%d",		      state->icount.tx, state->icount.rx);	if (state->icount.frame)		ret += sprintf(buf+ret, " fe:%d", state->icount.frame);	if (state->icount.parity)		ret += sprintf(buf+ret, " pe:%d", state->icount.parity);	if (state->icount.brk)		ret += sprintf(buf+ret, " brk:%d", state->icount.brk);	if (state->icount.overrun)		ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);	/*	 * Last thing is the RS-232 status lines	 */	ret += sprintf(buf+ret, " %s\n", stat_buf+1);#endif	return ret;}int rs_8xx_read_proc(char *page, char **start, off_t off, int count,		 int *eof, void *data){	int i, len = 0;	off_t	begin = 0;	len += sprintf(page, "serinfo:1.0 driver:%s\n", serial_version);	for (i = 0; i < NR_PORTS && len < 4000; i++) {		len += line_info(page + len, &rs_table[i]);		if (len+begin > off+count)			goto done;		if (len+begin < off) {			begin += len;			len = 0;		}	}	*eof = 1;done:	if (off >= len+begin)		return 0;	*start = page + (begin-off);	return ((count < begin+len-off) ? count : begin+len-off);}/* * --------------------------------------------------------------------- * rs_init() and friends * * rs_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\n", serial_name, serial_version);}/* * The serial console driver used during boot.  Note that these names * clash with those found in "serial.c", so we currently can't support * the 16xxx uarts and these at the same time.  I will fix this to become * an indirect function call from tty_io.c (or something). */#ifdef CONFIG_SERIAL_CONSOLE/* I need this just so I can store the virtual addresses and have * common functions for the early console printing. */static ser_info_t consinfo;/* * Print a string to the serial port trying not to disturb any possible * real use of the port... */static void my_console_write(int idx, const char *s,				unsigned count){	struct		serial_state	*ser;	ser_info_t			*info;	unsigned			i, c, cr_missing, max_tx_size;	volatile	cbd_t		*bdp, *bdbase;	volatile	smc_uart_t	*up;	volatile	u_char		*cp;	unsigned long                   flags;	ser = rs_table + idx;	/* If the port has been initialized for general use, we have	 * to use the buffer descriptors allocated there.  Otherwise,	 * we simply use the single buffer allocated.	 */	if ((info = (ser_info_t *)ser->info) != NULL) {		bdbase = info->tx_bd_base;	} else {		/* Pointer to UART in parameter ram. */		up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];		/* Get the address of the host memory buffer.*/		info = &consinfo;		info->tx_bd_base = (cbd_t *)bdbase = (cbd_t *)&cpmp->cp_dpmem[up->smc_tbase];		info->tx_cur = (cbd_t *)bdbase;	}	max_tx_size = console_tx_buf_len;	cr_missing = 0;	while (1){		c = MIN(max_tx_size, count);		if (c <= 0)			break;		local_irq_save(flags);		bdp = info->tx_cur;		bdbase = info->tx_bd_base;		if (bdp->cbd_sc & BD_SC_WRAP)			info->tx_cur = (cbd_t *)bdbase;		else			info->tx_cur = (cbd_t *)(bdp+1);		local_irq_restore(flags);		/* Wait for transmitter fifo to empty.		 * Ready indicates output is ready, and xmt is doing		 * that, not that it is ready for us to send.		 */		while (bdp->cbd_sc & BD_SC_READY);		/* Send the characters out.		 * If the buffer address is in the CPM DPRAM, don't		 * convert it.		 */		if ((uint)(bdp->cbd_bufaddr) > (uint)IMAP_ADDR)			cp = (u_char *)(bdp->cbd_bufaddr);		else			cp = info->tx_va_base + ((bdp - info->tx_bd_base) * TX_BUF_SIZE);		i=1; /* Keeps track of consumed TX buffer space */		if (cr_missing) {			/* Previus loop didn't have room for the CR, insert it first in this */			*cp++ = '\r';			i++;		}		cr_missing = 0;		for (; i <= c; i++) {			if ((*cp++ = *s++) != '\n')				continue; /* Copy bytes until a NewLine is found */			/* NewLine found, see if there is space in the TX buffer to add a CR */			if (i < max_tx_size) {				*cp++ = '\r'; /* yes, there is space to add a CR */				i++;			} else				cr_missing = 1; /* No space in the TX buffer,						   rember it so it can be inserted in the next loop */		}		count -= (c-cr_missing);		bdp->cbd_datlen = i-1;		bdp->cbd_sc |= BD_SC_READY;	}	/* while (bdp->cbd_sc & BD_SC_READY); is this really needed? */}static void serial_console_write(struct console *c, const char *s,				unsigned count){#ifdef CONFIG_KGDB_CONSOLE	/* Try to let stub handle output. Returns true if it did. */	if (kgdb_output_string(s, count))		return;#endif	my_console_write(c->index, s, count);}#ifdef CONFIG_XMONintxmon_8xx_write(const char *s, unsigned count){	my_console_write(0, s, count);	return(count);}#endif#if defined(CONFIG_KGDB) || defined(CONFIG_XMON)/* * Receive character from the serial port.  This only works well * before the port is initialized for real use. */static int my_console_wait_key(int idx, int xmon, char *obuf){	struct serial_state		*ser;	u_char				c, *cp;	ser_info_t			*info;	volatile	cbd_t		*bdp;	volatile	smc_uart_t	*up;	int				i;	ser = rs_table + idx;	/* Pointer to UART in parameter ram.	*/	up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];	/* Get the address of the host memory buffer.	 * If the port has been initialized for general use, we must	 * use information from the port structure.	 */	if ((info = (ser_info_t *)ser->info)) {		bdp = info->rx_cur;	}	else {		bdp = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];		info = &consinfo;	}	/*	 * We need to gracefully shut down the receiver, disable	 * interrupts, then read the input.	 * XMON just wants a poll.  If no character, return -1, else	 * return the character.	 */	if (!xmon) {		while (bdp->cbd_sc & BD_SC_EMPTY);	}	else {		if (bdp->cbd_sc & BD_SC_EMPTY)			return -1;	}	/* If the buffer address is in the CPM DPRAM, don't	 * convert it.	 */	if ((uint)(bdp->cbd_bufaddr) > (uint)IMAP_ADDR)		cp = (u_char *)(bdp->cbd_bufaddr);	else		cp = info->rx_va_base + ((bdp - info->rx_bd_base) * RX_BUF_SIZE);	if (obuf) {		i = c = bdp->cbd_datlen;		while (i-- > 0)			*obuf++ = *cp++;	}	else {		c = *cp;	}	bdp->cbd_sc |= BD_SC_EMPTY;	if (info) {		if (bdp->cbd_sc & BD_SC_WRAP) {			bdp = info->rx_bd_base;		}		else {			bdp++;		}		info->rx_cur = (cbd_t *)bdp;	}	return((int)c);}#endif /* CONFIG_KGDB || CONFIG_XMON */#ifdef CONFIG_XMONintxmon_8xx_read_poll(void){	return(my_console_wait_key(0, 1, NULL));}intxmon_8xx_read_char(void){	return(my_console_wait_key(0, 0, NULL));}#endif#ifdef CONFIG_KGDBstatic char kgdb_buf[RX_BUF_SIZE], *kgdp;static int kgdb_chars;voidputDebugChar(char ch){	my_console_write(0, &ch, 1);}chargetDebugChar(void){	if (kgdb_chars <= 0) {		kgdb_chars = my_console_wait_key(0, 0, kgdb_buf);		kgdp = kgdb_buf;	}	kgdb_chars--;	return(*kgdp++);}void kgdb_interruptible(int yes){	volatile smc_t	*smcp;	smcp = &cpmp->cp_smc[KGDB_SER_IDX];	if (yes == 1)		smcp->smc_smcm |= SMCM_RX;	else		smcp->smc_smcm &= ~SMCM_RX;}void kgdb_map_scc(void){	struct		serial_state *ser;	uint		mem_addr;	volatile	cbd_t		*bdp;	volatile	smc_uart_t	*up;	cpmp = (cpm8xx_t *)&(((immap_t *)IMAP_ADDR)->im_cpm);	/* To avoid data cache CPM DMA coherency problems, allocate a	 * buffer in the CPM DPRAM.  This will work until the CPM and	 * serial ports are initialized.  At that time a memory buffer	 * will be allocated.	 * The port is already initialized from the boot procedure, all	 * we do here is give it a different buffer and make it a FIFO.	 */	ser = rs_table;	/* Right now, assume we are using SMCs.	*/	up = (smc_uart_t *)&cpmp->cp_dparam[ser->port];	/* Allocate space for an input FIFO, plus a few bytes for output.	 * Allocate bytes to maintain word alignment.	 */	mem_addr = (uint)(&cpmp->cp_dpmem[0xa00]);	/* Set the physical address of the host memory buffers in	 * the buffer descriptors.	 */	bdp = (cbd_t *)&cpmp->cp_dpmem[up->smc_rbase];	bdp->cbd_bufaddr = mem_addr;	bdp = (cbd_t *)&cpmp->cp_dpmem[up->smc_tbase];	bdp->cbd_bufaddr = mem_addr+RX_BUF_SIZE;	up->smc_mrblr = RX_BUF_SIZE;		/* receive buffer length */	up->smc_maxidl = RX_BUF_SIZE;}#endifstatic kdev_t serial_console_device(struct console *c){	return MKDEV(TTY_MAJOR, 64 + c->index);}/* *	Register console. */long __init console_8xx_init(long kmem_start, long kmem_end){	register_console(&sercons);	return kmem_start;}#endif /* CONFIG_SERIAL_CONSOLE *//* Index in baud rate table of the default console baud rate.*/static	

⌨️ 快捷键说明

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