Chinaunix首页 | 论坛 | 博客
  • 博客访问: 477534
  • 博文数量: 223
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2145
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-01 10:23
个人简介

该坚持的时候坚持,该妥协的时候妥协,该放弃的时候放弃

文章分类

全部博文(223)

文章存档

2017年(56)

2016年(118)

2015年(3)

2014年(46)

我的朋友

分类: 嵌入式

2016-11-20 21:35:07

samsung.c:

点击(此处)折叠或打开

  1. /* linux/drivers/serial/samsuing.c


  2. /* ? - where has parity gone?? */
  3. #define S3C2410_UERSTAT_PARITY (0x1000)

  4. static irqreturn_t
  5. s3c24xx_serial_rx_chars(int irq, void *dev_id)
  6. {
  7.     struct s3c24xx_uart_port *ourport = dev_id;
  8.     struct uart_port *port = &ourport->port;
  9.     struct tty_struct *tty = port->info->port.tty;
  10.     unsigned int ufcon, ch, flag, ufstat, uerstat;
  11.     int max_count = 64;
  12.     
  13.     while(max_count-- > 0)
  14.     {
  15.      //1.如果接收FIFO为空
  16.      ufstat = rd_regl(port, S3C2410_UFSTAT);
  17.      if((ufstat & 0x3f) == 0)
  18.      break;
  19.      //2.
  20.      uerstat = rd_regl(port, S3C2410_UERSTAT);
  21.      //3.从URXH寄存器中获取接收到的字符
  22.      ch = rd_regb(port, S3C2410_URXH);
  23.      //6.
  24.      if(uart_handle_sysrq_char(port, ch))
  25.      break;
  26.      flag = TTY_NORMAL;
  27.      //7.
  28.      uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN, ch, flag);
  29.     }
  30.     //8.
  31.     tty_flip_buffer_push(tty);

  32.     return IRQ_HANDLED;
  33. }

  34. static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id)
  35. {
  36.     struct s3c24xx_uart_port *ourport = id;
  37.     struct uart_port *port = &ourport->port;
  38.     struct circ_buf *xmit = &port->info->xmit;
  39.     int count = 256;

  40.     //1.判断x_char是否为0
  41.     if(port->x_char)
  42.     {
  43.      wr_regb(port, S3C2410_UTXH, port->x_char);
  44.      goto out;
  45.     }

  46.     //2.如果发送缓冲空,或者驱动为停止发送状态,则取消发送
  47.     if(uart_circ_empty(xmit) || uart_tx_stopped(port))
  48.     {
  49.      s3c24xx_serial_stop_tx(port);
  50.      goto out;
  51.     }

  52.     //3.循环发送,循环条件:发送缓冲不为空
  53.     while(!uart_circ_empty(xmit) && ((count--)>0))
  54.     {
  55.      //3.1 判断FIFO是否满了
  56.      if(rd_regl(port, S3C2410_UFSTAT) & (1<<14))
  57.      break;
  58.      //3.2 将要发送的字符写入发送寄存器
  59.      wr_regl(port, S3C2410_UTXH, xmit->buf[xmit->tail]);
  60.      //3.3 修改循环缓冲的尾部位置
  61.      xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE -1);
  62.      port->icount.tx++;
  63.     }
  64.     //4.如果发送余量数据<256,唤醒之前阻塞的发送进程
  65.     if(uart_circ_chars_pending(xmit) < 256)
  66.     {
  67.      uart_write_wakeup(port);
  68.     }
  69.     //5.如果发送缓冲空,关闭发送功能
  70.     if(uart_circ_empty(xmit))
  71.      s3c24xx_serial_stop_tx(port);
  72. out:
  73.     return IRQ_HANDLED;
  74. }
阅读(934) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~