Chinaunix首页 | 论坛 | 博客
  • 博客访问: 476271
  • 博文数量: 55
  • 博客积分: 1867
  • 博客等级: 上尉
  • 技术积分: 587
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-29 01:33
文章分类

全部博文(55)

文章存档

2013年(1)

2012年(2)

2011年(16)

2010年(11)

2009年(5)

2008年(10)

2007年(8)

2006年(2)

分类: C/C++

2007-07-01 17:38:58

/**
 * Rx complete interrupt handler
 */
void NAKED SIG_UART_RECV(void);
void SIG_UART_RECV(void){
  into_critical();

  prologue();
 
  if (!(uart.status & UART_RECVDATA)){
    uart.status |= UART_RECVDATA;
    if (uart.hook != NULL) uart.hook(uart.status);
  }

  if (!(UCSRA & (_BV(FE) | _BV(DOR)))){
    unsigned char b = UDR;
    int err = fifo_putbyte(uart.rxbuf, b);
    if (err == -1){
      uart.status |= UART_RX_FULLY;
      if (uart.hook != NULL) uart.hook(uart.status);
    }
  }
 
  epilogue();
}

应改为:

/**
 * Rx complete interrupt handler
 */
void NAKED SIG_UART_RECV(void);
void SIG_UART_RECV(void){
  into_critical();

  prologue();
 
  if (!(uart.status & UART_RECVDATA)){
    uart.status |= UART_RECVDATA;
    if (uart.hook != NULL) uart.hook(uart.status);
  }
 
  unsigned char tmp = UCSRA;
  unsigned char b = UDR;
  if (!(tmp & (_BV(FE) | _BV(DOR)))){
    unsigned char b = UDR;
    int err = fifo_putbyte(uart.rxbuf, b);
    if (err == -1){
      uart.status |= UART_RX_FULLY;
      if (uart.hook != NULL) uart.hook(uart.status);
    }
  }
 
  epilogue();
}

原来的代码在出现祯错误或奇偶错后,没有读UDR来消除错误,这样通常会在通信电缆插拔时带来意想不到的问题。
阅读(1489) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~