- 论坛徽章:
- 0
|
本帖最后由 klanet 于 2010-08-31 10:56 编辑
回复 2# dreamice
版主要的是那部分的代码?
驱动的还是协议层的?
协议层的- // 找头字符:
- int i=0;
- sRecStr[0] = 0;
- do
- {
- ReadFile( hComm, (char*)sRecStr, 1, &lRead, NULL );
- i++;
- }while( lRead==1 && sRecStr[0]!=bySOI && i<nMaxDllBufNum-1 );
- // 读后续数据串
- if( lRead && sRecStr[0]==bySOI )
- {
- // 读取到数据段长度字符,以便决定本包总数据量.
- ReadFile( hComm, (char*)sRecStr+1, 12, &lRead, NULL );
- if( lRead==12 )
- {
- int nLen=0;
- sscanf( (char *)sRecStr+9,"%04x", &nLen );
- nLen = nLen & 0x0FFF; // 去掉校验位
- if( nLen+18 < nMaxDllBufNum-1 ) // 缓冲区溢出判断
- {
- ReadFile( hComm, (char*)sRecStr+13, nLen+5, &lRead, NULL );
- }
- lRead += 12;
- }
- lRead++;
- }
- sRecStr[lRead] = 0;
- // 跟踪调试的接收信息处理:回应信息记录。
复制代码 上面的是buffer读取,改为一个一个字节读取就不贴出来了,都差不多。
驱动代码在 drivers/serial/atmel_serial.c
下面是中断发的代码- static void atmel_tx_chars(struct uart_port *port)
- {
- struct circ_buf *xmit = &port->info->xmit;
- if (port->x_char) {
- UART_PUT_CHAR(port, port->x_char);
- port->icount.tx++;
- port->x_char = 0;
- return;
- }
- if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
- atmel_stop_tx(port);
- return;
- }
- while (UART_GET_CSR(port) & ATMEL_US_TXRDY) {
- UART_PUT_CHAR(port, xmit->buf[xmit->tail]);
- xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
- port->icount.tx++;
- if (uart_circ_empty(xmit))
- break;
- }
- if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
- uart_write_wakeup(port);
- if (uart_circ_empty(xmit))
- atmel_stop_tx(port);
- }
复制代码 下面是中断收- static void atmel_rx_chars(struct uart_port *port)
- {
- struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
- struct tty_struct *tty = port->info->tty;
- unsigned int status, ch, flg;
- status = UART_GET_CSR(port);
- while (status & ATMEL_US_RXRDY) {
- ch = UART_GET_CHAR(port);
- port->icount.rx++;
- flg = TTY_NORMAL;
- /*
- * note that the error handling code is
- * out of the main execution path
- */
- if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME
- | ATMEL_US_OVRE | ATMEL_US_RXBRK)
- || atmel_port->break_active)) {
- UART_PUT_CR(port, ATMEL_US_RSTSTA); /* clear error */
- if (status & ATMEL_US_RXBRK
- && !atmel_port->break_active) {
- status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME); /* ignore side-effect */
- port->icount.brk++;
- atmel_port->break_active = 1;
- UART_PUT_IER(port, ATMEL_US_RXBRK);
- if (uart_handle_break(port))
- goto ignore_char;
- } else {
- /*
- * This is either the end-of-break
- * condition or we've received at
- * least one character without RXBRK
- * being set. In both cases, the next
- * RXBRK will indicate start-of-break.
- */
- UART_PUT_IDR(port, ATMEL_US_RXBRK);
- status &= ~ATMEL_US_RXBRK;
- atmel_port->break_active = 0;
- }
- if (status & ATMEL_US_PARE)
- port->icount.parity++;
- if (status & ATMEL_US_FRAME)
- port->icount.frame++;
- if (status & ATMEL_US_OVRE)
- port->icount.overrun++;
- status &= port->read_status_mask;
- if (status & ATMEL_US_RXBRK)
- flg = TTY_BREAK;
- else if (status & ATMEL_US_PARE)
- flg = TTY_PARITY;
- else if (status & ATMEL_US_FRAME)
- flg = TTY_FRAME;
- }
- if (uart_handle_sysrq_char(port, ch))
- goto ignore_char;
- uart_insert_char(port, status, ATMEL_US_OVRE, ch, flg);
- ignore_char:
- status = UART_GET_CSR(port);
- }
- tty_flip_buffer_push(tty);
- }
复制代码 |
|