nb85e_uart.c

来自「这是一个SIGMA方案的PMP播放器的UCLINUX程序,可播放DVD,VCD,」· C语言 代码 · 共 599 行 · 第 1/2 页

C
599 行
字号
		if (port->gs.xmit_cnt <= port->gs.wakeup_chars) {			port->gs.event |= 1 << RS_EVENT_WRITE_WAKEUP;			queue_task (&port->tqueue, &tq_immediate);			mark_bh (IMMEDIATE_BH);		}	}	save_flags_cli (flags);	if (port->gs.xmit_cnt == 0)		port->gs.flags &= ~GS_TX_INTEN;	restore_flags (flags);}static void nb85e_uart_tty_disable_tx_interrupts (void *driver_data){	struct nb85e_uart_tty_port *port = driver_data;	nb85e_intc_disable_irq (IRQ_INTST (port->chan));}static void nb85e_uart_tty_enable_tx_interrupts (void *driver_data){	struct nb85e_uart_tty_port *port = driver_data;	nb85e_intc_disable_irq (IRQ_INTST (port->chan));	nb85e_uart_tty_tx (port);	nb85e_intc_enable_irq (IRQ_INTST (port->chan));}static void nb85e_uart_tty_disable_rx_interrupts (void *driver_data){	struct nb85e_uart_tty_port *port = driver_data;	nb85e_intc_disable_irq (IRQ_INTSR (port->chan));}static void nb85e_uart_tty_enable_rx_interrupts (void *driver_data){	struct nb85e_uart_tty_port *port = driver_data;	nb85e_intc_enable_irq (IRQ_INTSR (port->chan));}static int nb85e_uart_tty_get_CD (void *driver_data){	return 1;		/* Can't really detect it, sorry... */}static void nb85e_uart_tty_shutdown_port (void *driver_data){	struct nb85e_uart_tty_port *port = driver_data;	port->gs.flags &= ~ GS_ACTIVE;	/* Disable port interrupts.  */	free_irq (IRQ_INTST (port->chan), port);	free_irq (IRQ_INTSR (port->chan), port);	/* Turn off xmit/recv enable bits.  */	NB85E_UART_ASIM (port->chan) &= ~(NB85E_UART_ASIM_TXE | NB85E_UART_ASIM_RXE);	/* Then reset the channel.  */	NB85E_UART_ASIM (port->chan) = 0;}static int nb85e_uart_tty_set_real_termios (void *driver_data){	struct nb85e_uart_tty_port *port = driver_data;	unsigned cflag = port->gs.tty->termios->c_cflag;	nb85e_uart_configure (port->chan, cflag, port->gs.baud);}static int nb85e_uart_tty_chars_in_buffer (void *driver_data){	/* There's only a one-character `buffer', and the only time we	   actually know there's a character in it is when we receive a	   character-received interrupt -- in which case we immediately	   remove it anyway.  */	return 0;}static void nb85e_uart_tty_close (void *driver_data){	MOD_DEC_USE_COUNT;}static void nb85e_uart_tty_hungup (void *driver_data){	MOD_DEC_USE_COUNT;}static void nb85e_uart_tty_getserial (void *driver_data, struct serial_struct *s){	struct nb85e_uart_tty_port *port = driver_data;	s->line = port->chan;	s->xmit_fifo_size = 1;	s->irq = IRQ_INTSR (port->chan); /* actually have TX irq too, but... */}static struct real_driver nb85e_uart_tty_gs_driver = {	disable_tx_interrupts: 	nb85e_uart_tty_disable_tx_interrupts,	enable_tx_interrupts:	nb85e_uart_tty_enable_tx_interrupts,	disable_rx_interrupts:	nb85e_uart_tty_disable_rx_interrupts,	enable_rx_interrupts:	nb85e_uart_tty_enable_rx_interrupts,	get_CD:			nb85e_uart_tty_get_CD,	shutdown_port:		nb85e_uart_tty_shutdown_port,	set_real_termios:	nb85e_uart_tty_set_real_termios,	chars_in_buffer:	nb85e_uart_tty_chars_in_buffer,	close:			nb85e_uart_tty_close,	hungup:			nb85e_uart_tty_hungup,	getserial:		nb85e_uart_tty_getserial,};static struct nb85e_uart_tty_port nb85e_uart_tty_ports[NB85E_UART_NUM_CHANNELS];static void init_nb85e_uart_tty_ports (void){	int chan;	for (chan = 0; chan < NB85E_UART_NUM_CHANNELS; chan++) {		struct nb85e_uart_tty_port *port = &nb85e_uart_tty_ports[chan];		port->chan = chan;		port->gs.magic = NB85E_UART_MAGIC;		port->gs.rd = &nb85e_uart_tty_gs_driver;		init_waitqueue_head (&port->gs.open_wait);		init_waitqueue_head (&port->gs.close_wait);		port->gs.normal_termios	= tty_std_termios;		port->gs.normal_termios.c_cflag = NB85E_UART_INIT_CFLAGS;		port->gs.close_delay = HZ / 2;   /* .5s */		port->gs.closing_wait = 30 * HZ; /* 30s */	}}/* TTY interrupt handlers.  */void nb85e_uart_tty_tx_irq (int irq, void *data, struct pt_regs *regs){	struct nb85e_uart_tty_port *port = data;	if (port->gs.flags & GS_ACTIVE)		nb85e_uart_tty_tx (port);	else		nb85e_uart_tty_disable_tx_interrupts (data);}void nb85e_uart_tty_rx_irq (int irq, void *data, struct pt_regs *regs){	struct nb85e_uart_tty_port *port = data;	if (port->gs.flags & GS_ACTIVE) {		unsigned ch_stat;		unsigned err = NB85E_UART_ASIS (port->chan);		unsigned ch = NB85E_UART_RXB (port->chan);		if (err & NB85E_UART_ASIS_OVE)			ch_stat = TTY_OVERRUN;		else if (err & NB85E_UART_ASIS_FE)			ch_stat = TTY_FRAME;		else if (err & NB85E_UART_ASIS_PE)			ch_stat = TTY_PARITY;		else			ch_stat = TTY_NORMAL;		tty_insert_flip_char (port->gs.tty, ch, ch_stat);		tty_schedule_flip (port->gs.tty);	} else		nb85e_uart_tty_disable_rx_interrupts (port);}/* Higher level TTY interface.  */static struct tty_struct *nb85e_uart_ttys[NB85E_UART_NUM_CHANNELS] = { 0 };static struct termios *nb85e_uart_tty_termios[NB85E_UART_NUM_CHANNELS] = { 0 };static struct termios *nb85e_uart_tty_termios_locked[NB85E_UART_NUM_CHANNELS] = { 0 };static struct tty_driver nb85e_uart_tty_driver = { 0 };static int nb85e_uart_tty_refcount = 0;int nb85e_uart_tty_open (struct tty_struct *tty, struct file *filp){	int err;	struct nb85e_uart_tty_port *port;	unsigned chan = MINOR (tty->device) - NB85E_UART_MINOR_BASE;	if (chan >= NB85E_UART_NUM_CHANNELS)		return -ENODEV;	port = &nb85e_uart_tty_ports[chan];	tty->driver_data = port;	port->gs.tty = tty;	port->gs.count++;	port->tqueue.routine = gs_do_softint;	port->tqueue.data = &port->gs;	/*	 * Start up serial port	 */	err = gs_init_port (&port->gs);	if (err)		goto failed_1;	port->gs.flags |= GS_ACTIVE;	if (port->gs.count == 1) {		MOD_INC_USE_COUNT;		/* Alloc RX irq.  */		err = request_irq (IRQ_INTSR (chan), nb85e_uart_tty_rx_irq,				   SA_INTERRUPT, "nb85e_uart", port);		if (err)			goto failed_2;		/* Alloc TX irq.  */		err = request_irq (IRQ_INTST (chan), nb85e_uart_tty_tx_irq,				   SA_INTERRUPT, "nb85e_uart", port);		if (err) {			free_irq (IRQ_INTSR (chan), port);			goto failed_2;		}	}	err = gs_block_til_ready (port, filp);	if (err)		goto failed_3;	*tty->termios = port->gs.normal_termios;	nb85e_uart_tty_enable_rx_interrupts (port);	port->gs.session = current->session;	port->gs.pgrp = current->pgrp;	return 0;failed_3:	free_irq (IRQ_INTST (chan), port);	free_irq (IRQ_INTSR (chan), port);failed_2:	MOD_DEC_USE_COUNT;failed_1:	port->gs.count--;	return err;}int __init nb85e_uart_tty_init (void){	struct tty_driver *d = &nb85e_uart_tty_driver;	d->driver_name = "nb85e_uart";#ifdef CONFIG_DEVFS_FS	d->name = "tts/%d";#else	d->name = "ttyS";#endif	d->major = TTY_MAJOR;	d->minor_start = NB85E_UART_MINOR_BASE;	d->num = 1;	d->type = TTY_DRIVER_TYPE_SERIAL;	d->subtype = SERIAL_TYPE_NORMAL;	d->refcount = &nb85e_uart_tty_refcount;	d->table = nb85e_uart_ttys;	d->termios = nb85e_uart_tty_termios;	d->termios_locked = nb85e_uart_tty_termios_locked;	d->init_termios = tty_std_termios;	d->init_termios.c_cflag = NB85E_UART_INIT_CFLAGS;	d->open = nb85e_uart_tty_open;	d->put_char = gs_put_char;	d->write = gs_write;	d->write_room = gs_write_room;	d->start = gs_start;	d->stop = gs_stop;	d->close = gs_close;	d->write = gs_write;	d->put_char = gs_put_char;	d->flush_chars = gs_flush_chars;	d->write_room = gs_write_room;	d->chars_in_buffer = gs_chars_in_buffer;	d->set_termios = gs_set_termios;	d->throttle = 0;  /* NB85E_UART uarts have no hardware flow control */	d->unthrottle = 0; /* " */	d->stop = gs_stop;	d->start = gs_start;	d->hangup = gs_hangup;	d->flush_buffer = gs_flush_buffer;	init_nb85e_uart_tty_ports ();	tty_register_driver (&nb85e_uart_tty_driver);}__initcall (nb85e_uart_tty_init);

⌨️ 快捷键说明

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