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

📄 serial.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
	CONTROL_PINS_PORT_NOT_USED(3)#endif			}};#else  /* CONFIG_ETRAX_SERX_DTR_RI_DSR_CD_MIXED *//* All pins are on either PA or PB for each serial port */#define CONTROL_PINS_PORT_NOT_USED(line) \  &dummy_ser[line], &dummy_ser[line], \  DUMMY_DTR_MASK, DUMMY_RI_MASK, DUMMY_DSR_MASK, DUMMY_CD_MASK    struct control_pins{	volatile unsigned char *port;	unsigned char          *shadow;	unsigned char dtr_mask;	unsigned char ri_mask;	unsigned char dsr_mask;	unsigned char cd_mask;};#define dtr_port port#define dtr_shadow shadow#define ri_port port#define ri_shadow shadow#define dsr_port port#define dsr_shadow shadow#define cd_port port#define cd_shadow shadowstatic const struct control_pins e100_modem_pins[NR_PORTS] = {	/* Ser 0 */	{#ifdef CONFIG_ETRAX_SERIAL_PORT0	E100_STRUCT_PORT(0,DTR), E100_STRUCT_SHADOW(0,DTR),	E100_STRUCT_MASK(0,DTR),	E100_STRUCT_MASK(0,RI),	E100_STRUCT_MASK(0,DSR),	E100_STRUCT_MASK(0,CD)#else	CONTROL_PINS_PORT_NOT_USED(0)#endif		},	/* Ser 1 */	{#ifdef CONFIG_ETRAX_SERIAL_PORT1	  	E100_STRUCT_PORT(1,DTR), E100_STRUCT_SHADOW(1,DTR),	E100_STRUCT_MASK(1,DTR),	E100_STRUCT_MASK(1,RI),	E100_STRUCT_MASK(1,DSR),	E100_STRUCT_MASK(1,CD)#else	CONTROL_PINS_PORT_NOT_USED(1)#endif			},	/* Ser 2 */	{#ifdef CONFIG_ETRAX_SERIAL_PORT2	  	E100_STRUCT_PORT(2,DTR), E100_STRUCT_SHADOW(2,DTR),	E100_STRUCT_MASK(2,DTR),	E100_STRUCT_MASK(2,RI),	E100_STRUCT_MASK(2,DSR),	E100_STRUCT_MASK(2,CD)#else	CONTROL_PINS_PORT_NOT_USED(2)#endif			},	/* Ser 3 */	{#ifdef CONFIG_ETRAX_SERIAL_PORT3	  	E100_STRUCT_PORT(3,DTR), E100_STRUCT_SHADOW(3,DTR),	E100_STRUCT_MASK(3,DTR),	E100_STRUCT_MASK(3,RI),	E100_STRUCT_MASK(3,DSR),	E100_STRUCT_MASK(3,CD)#else	CONTROL_PINS_PORT_NOT_USED(3)#endif			}};#endif /* !CONFIG_ETRAX_SERX_DTR_RI_DSR_CD_MIXED */#if defined(CONFIG_ETRAX_RS485) && defined(CONFIG_ETRAX_RS485_ON_PA)unsigned char rs485_pa_port = CONFIG_ETRAX_RS485_ON_PA_BIT;#endif#define E100_RTS_MASK 0x20#define E100_CTS_MASK 0x40/* All serial port signals are active low: * active   = 0 -> 3.3V to RS-232 driver -> -12V on RS-232 level * inactive = 1 -> 0V   to RS-232 driver -> +12V on RS-232 level * * These macros returns the pin value: 0=0V, >=1 = 3.3V on ETRAX chip *//* Output */#define E100_RTS_GET(info) ((info)->rx_ctrl & E100_RTS_MASK)/* Input */#define E100_CTS_GET(info) ((info)->port[REG_STATUS] & E100_CTS_MASK)/* These are typically PA or PB and 0 means 0V, 1 means 3.3V *//* Is an output */#define E100_DTR_GET(info) ((*e100_modem_pins[(info)->line].dtr_shadow) & e100_modem_pins[(info)->line].dtr_mask)/* Normally inputs */#define E100_RI_GET(info) ((*e100_modem_pins[(info)->line].ri_port) & e100_modem_pins[(info)->line].ri_mask)#define E100_CD_GET(info) ((*e100_modem_pins[(info)->line].cd_port) & e100_modem_pins[(info)->line].cd_mask)/* Input */#define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask)/* * tmp_buf is used as a temporary buffer by serial_write.  We need to * lock it in case the memcpy_fromfs blocks while swapping in a page, * and some other program tries to do a serial write at the same time. * Since the lock will only come under contention when the system is * swapping and available memory is low, it makes sense to share one * buffer across all the serial ports, since it significantly saves * memory if large numbers of serial ports are open. */static unsigned char *tmp_buf;#ifdef DECLARE_MUTEXstatic DECLARE_MUTEX(tmp_buf_sem);#elsestatic struct semaphore tmp_buf_sem = MUTEX;#endif#ifdef CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST/* clock select 10 for timer 1 gives 230400 Hz */#define FASTTIMER_SELECT (10)/* we use a source of 230400 Hz and a divider of 15 => 15360 Hz */#define FASTTIMER_DIV (15)/* fast flush timer stuff */static int fast_timer_started = 0;static unsigned long int fast_timer_ints = 0;static void _INLINE_ start_flush_timer(void){	if (fast_timer_started)		return;	*R_TIMER_CTRL = r_timer_ctrl_shadow = 		(r_timer_ctrl_shadow &		 ~IO_MASK(R_TIMER_CTRL, timerdiv1) &		 ~IO_MASK(R_TIMER_CTRL, tm1) &		 ~IO_MASK(R_TIMER_CTRL, clksel1)) | 		IO_FIELD(R_TIMER_CTRL, timerdiv1, FASTTIMER_DIV) |		IO_STATE(R_TIMER_CTRL, tm1, stop_ld) | 		IO_FIELD(R_TIMER_CTRL, clksel1, FASTTIMER_SELECT);	*R_TIMER_CTRL = r_timer_ctrl_shadow = 		(r_timer_ctrl_shadow & ~IO_MASK(R_TIMER_CTRL, tm1)) |		IO_STATE(R_TIMER_CTRL, tm1, run);	/* enable timer1 irq */	*R_IRQ_MASK0_SET = IO_STATE(R_IRQ_MASK0_SET, timer1, set);	fast_timer_started = 1;}#endif /* CONFIG_ETRAX_SERIAL_FLUSH_DMA_FAST *//* Calculate the chartime depending on baudrate, numbor of bits etc. */static void update_char_time(struct e100_serial * info){	tcflag_t cflags = info->tty->termios->c_cflag;	int bits;	/* calc. number of bits / data byte */	/* databits + startbit and 1 stopbit */	if ((cflags & CSIZE) == CS7)		bits = 9;	else		bits = 10;  	if (cflags & CSTOPB)     /* 2 stopbits ? */		bits++;	if (cflags & PARENB)     /* parity bit ? */		bits++;	/* calc timeout */	info->char_time_usec = ((bits * 1000000) / info->baud) + 1;	info->flush_time_usec = 4*info->char_time_usec;	if (info->flush_time_usec < MIN_FLUSH_TIME_USEC)		info->flush_time_usec = MIN_FLUSH_TIME_USEC;}/* * This function maps from the Bxxxx defines in asm/termbits.h into real * baud rates. */static int cflag_to_baud(unsigned int cflag){	static int baud_table[] = {		0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,		4800, 9600, 19200, 38400 };	static int ext_baud_table[] = {		0, 57600, 115200, 230400, 460800, 921600, 1843200, 6250000,                0, 0, 0, 0, 0, 0, 0, 0 };	if (cflag & CBAUDEX)		return ext_baud_table[(cflag & CBAUD) & ~CBAUDEX];	else 		return baud_table[cflag & CBAUD];}/* and this maps to an etrax100 hardware baud constant */static unsigned char cflag_to_etrax_baud(unsigned int cflag){	char retval;	static char baud_table[] = {		-1, -1, -1, -1, -1, -1, -1, 0, 1, 2, -1, 3, 4, 5, 6, 7 };	static char ext_baud_table[] = {		-1, 8, 9, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1, -1, -1 };	if (cflag & CBAUDEX)		retval = ext_baud_table[(cflag & CBAUD) & ~CBAUDEX];	else 		retval = baud_table[cflag & CBAUD];	if (retval < 0) {		printk(KERN_WARNING "serdriver tried setting invalid baud rate, flags %x.\n", cflag);		retval = 5; /* choose default 9600 instead */	}	return retval | (retval << 4); /* choose same for both TX and RX */}/* Various static support functions *//* Functions to set or clear DTR/RTS on the requested line *//* It is complicated by the fact that RTS is a serial port register, while * DTR might not be implemented in the HW at all, and if it is, it can be on * any general port. */static inline void e100_dtr(struct e100_serial *info, int set){#ifndef CONFIG_SVINTO_SIM	unsigned char mask = e100_modem_pins[info->line].dtr_mask;#ifdef SERIAL_DEBUG_IO  	printk("ser%i dtr %i mask: 0x%02X\n", info->line, set, mask);	printk("ser%i shadow before 0x%02X get: %i\n", 	       info->line, *e100_modem_pins[info->line].dtr_shadow,	       E100_DTR_GET(info));#endif	/* DTR is active low */	{		unsigned long flags;		save_flags(flags);		cli();		*e100_modem_pins[info->line].dtr_shadow &= ~mask;		*e100_modem_pins[info->line].dtr_shadow |= (set ? 0 : mask); 		*e100_modem_pins[info->line].dtr_port = *e100_modem_pins[info->line].dtr_shadow;		restore_flags(flags);	}	#ifdef SERIAL_DEBUG_IO	printk("ser%i shadow after 0x%02X get: %i\n", 	       info->line, *e100_modem_pins[info->line].dtr_shadow, 	       E100_DTR_GET(info));#endif#endif}/* set = 0 means 3.3V on the pin, bitvalue: 0=active, 1=inactive   *                                          0=0V    , 1=3.3V */static inline void e100_rts(struct e100_serial *info, int set){#ifndef CONFIG_SVINTO_SIM	unsigned long flags;	save_flags(flags);	cli();	info->rx_ctrl &= ~E100_RTS_MASK;	info->rx_ctrl |= (set ? 0 : E100_RTS_MASK);  /* RTS is active low */	info->port[REG_REC_CTRL] = info->rx_ctrl;	restore_flags(flags);#ifdef SERIAL_DEBUG_IO  	printk("ser%i rts %i\n", info->line, set);#endif#endif}/* If this behaves as a modem, RI and CD is an output */static inline void e100_ri_out(struct e100_serial *info, int set){#ifndef CONFIG_SVINTO_SIM	/* RI is active low */	{		unsigned char mask = e100_modem_pins[info->line].ri_mask;		unsigned long flags;		save_flags(flags);		cli();		*e100_modem_pins[info->line].ri_shadow &= ~mask;		*e100_modem_pins[info->line].ri_shadow |= (set ? 0 : mask); 		*e100_modem_pins[info->line].ri_port = *e100_modem_pins[info->line].ri_shadow;		restore_flags(flags);	}#endif}static inline void e100_cd_out(struct e100_serial *info, int set){#ifndef CONFIG_SVINTO_SIM	/* CD is active low */	{		unsigned char mask = e100_modem_pins[info->line].cd_mask;		unsigned long flags;		save_flags(flags);		cli();		*e100_modem_pins[info->line].cd_shadow &= ~mask;		*e100_modem_pins[info->line].cd_shadow |= (set ? 0 : mask); 		*e100_modem_pins[info->line].cd_port = *e100_modem_pins[info->line].cd_shadow;		restore_flags(flags);	}#endif}static inline voide100_disable_rx(struct e100_serial *info){#ifndef CONFIG_SVINTO_SIM	/* disable the receiver */	info->port[REG_REC_CTRL] =		(info->rx_ctrl &= ~IO_MASK(R_SERIAL0_REC_CTRL, rec_enable));#endif}static inline void e100_enable_rx(struct e100_serial *info){#ifndef CONFIG_SVINTO_SIM	/* enable the receiver */	info->port[REG_REC_CTRL] =		(info->rx_ctrl |= IO_MASK(R_SERIAL0_REC_CTRL, rec_enable));#endif}/* the rx DMA uses both the dma_descr and the dma_eop interrupts */static inline voide100_disable_rxdma_irq(struct e100_serial *info) {#ifdef SERIAL_DEBUG_INTR	printk("rxdma_irq(%d): 0\n",info->line);#endif	DINTR1(DEBUG_LOG(info->line,"IRQ disable_rxdma_irq %i\n", info->line));	*R_IRQ_MASK2_CLR = (info->irq << 2) | (info->irq << 3);}static inline voide100_enable_rxdma_irq(struct e100_serial *info) {#ifdef SERIAL_DEBUG_INTR	printk("rxdma_irq(%d): 1\n",info->line);#endif	DINTR1(DEBUG_LOG(info->line,"IRQ enable_rxdma_irq %i\n", info->line));	*R_IRQ_MASK2_SET = (info->irq << 2) | (info->irq << 3);}/* the tx DMA uses only dma_descr interrupt */static inline voide100_disable_txdma_irq(struct e100_serial *info) {#ifdef SERIAL_DEBUG_INTR	printk("txdma_irq(%d): 0\n",info->line);#endif	DINTR1(DEBUG_LOG(info->line,"IRQ disable_txdma_irq %i\n", info->line));	*R_IRQ_MASK2_CLR = info->irq;}static inline voide100_enable_txdma_irq(struct e100_serial *info) {#ifdef SERIAL_DEBUG_INTR	printk("txdma_irq(%d): 1\n",info->line);#endif	DINTR1(DEBUG_LOG(info->line,"IRQ enable_txdma_irq %i\n", info->line));	*R_IRQ_MASK2_SET = info->irq;}static _INLINE_ void

⌨️ 快捷键说明

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