termios-serial develop

讨论

需要真实物理连接
  1. 同一台电脑,两个串口相连,测试通信,使用何种物理通信线来相连?链接链接链接
    1. 设想是,利用同一个电脑上两个串口,一个vm-host,一个host,两者通信,vm启动程序,host启动串口助手,这种情况,需要真实的物理接线。
  2. 一个linux串口(不是vm,而是真实host),一块单片机,连接(跟实际开一样,但跟测试不一样)

不需要真实物理连接
一个串口
  1. http://blog.csdn.net/wdq347/article/details/39498037vbox一个串口,主机管道。(vbox测试,win-host,vbox不可使用功管道)
两个串口
  1. http://www.51testing.com/html/79/n-861579.htmlvm下创建两个串口,通过相同的命名管道实现通信。(vm已测试,挺方便的)
  2. http://blog.csdn.net/kimherojae/article/details/44653183在win下使用软件,虚拟出两个端口并”桥接“,然后启动监控软件,vm同样创建两个串口,然后使用“主机设备”连接win下虚拟端口,实现通信。(测试,也是最终采用的方案,实际撒开发也是这个场景)
    1. 推荐了这两个软件http://blog.qdac.cc/?p=3373

综上:有两个方案是比较好的
  1. 虚拟+监控(实际需要,按应用程序功能编写测试即可),两个串口,收发都行
  2. 实物链接,单片机+vm-host,一个串口,收发都行

基本操作

适用工具
  1. [工具]minicom

串口信息查询
  1. 查看串口是否可用,可以对串口发送数据比如对com1口,echo lyjie126 > /dev/ttyS0
  2. 查看串口名称使用 ls -l /dev/ttyS* 一般情况下串口的名称全部在dev下面,如果你没有外插串口卡的话默认是dev下的ttyS* ,一般ttyS0对应com1,ttyS1对应com2,当然也不一定是必然的;
  3. 查看串口驱动:cat /proc/tty/drivers/serial
  4. 查看串口设备:dmesg | grep ttyS*
  5. 列出usb设备:lsusb

调试

思考过程
  1. VM-host的“连接”,最终为了建立“串口连接“
    1. VM中linux和windows主机进行串口通信 ,链接,带测试流程
    2. 如何配置VirtualBox中的虚拟机的串口 ,链接,四种配置方式
    3. 使用虚拟串口来仿真测试串口通讯 ,链接,双虚拟串口的实现方式
  2. Linux串口调试终端minicom, [工具]minicom
  3. 查看串口设备或usb转串口设备(dmesg|grep tty)
  4. 检测串口是否可用(echo/cat配合)

结果
  1. 因为采用了虚拟串口,所以,关闭vbox-linux后出错,只能每次调试serial时才重新将所需serial添加进去。最终直接编写一个reboot脚本,很可惜,vbox现在重启非常慢。
static void pl011_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) { struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port); unsigned int lcr_h, old_cr; unsigned long flags; unsigned int baud, quot, clkdiv; if (uap->vendor->oversampling) clkdiv = 8; else clkdiv = 16; baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / clkdiv); if (baud > port->uartclk/16) quot = DIV_ROUND_CLOSEST(port->uartclk * 8, baud); else quot = DIV_ROUND_CLOSEST(port->uartclk * 4, baud); switch (termios->c_cflag & CSIZE) { case CS5: lcr_h = UART01x_LCRH_WLEN_5; break; case CS6: lcr_h = UART01x_LCRH_WLEN_6; break; case CS7: lcr_h = UART01x_LCRH_WLEN_7; break; default: // CS8 lcr_h = UART01x_LCRH_WLEN_8; break; } if (termios->c_cflag & CSTOPB) lcr_h |= UART01x_LCRH_STP2; if (termios->c_cflag & PARENB) { lcr_h |= UART01x_LCRH_PEN; if (!(termios->c_cflag & PARODD)) lcr_h |= UART01x_LCRH_EPS; if (termios->c_cflag & CMSPAR) lcr_h |= UART011_LCRH_SPS; } if (uap->fifosize > 1) lcr_h |= UART01x_LCRH_FEN; spin_lock_irqsave(&port->lock, flags); uart_update_timeout(port, termios->c_cflag, baud); pl011_setup_status_masks(port, termios); if (UART_ENABLE_MS(port, termios->c_cflag)) pl011_enable_ms(port); old_cr = pl011_read(uap, REG_CR); pl011_write(0, uap, REG_CR); if (termios->c_cflag & CRTSCTS) { if (old_cr & UART011_CR_RTS) old_cr |= UART011_CR_RTSEN; old_cr |= UART011_CR_CTSEN; port->status |= UPSTAT_AUTOCTS | UPSTAT_AUTORTS; } else { old_cr &= ~(UART011_CR_CTSEN | UART011_CR_RTSEN); port->status &= ~(UPSTAT_AUTOCTS | UPSTAT_AUTORTS); } if (uap->vendor->oversampling) { if (baud > port->uartclk / 16) old_cr |= ST_UART011_CR_OVSFACT; else old_cr &= ~ST_UART011_CR_OVSFACT; } if (uap->vendor->oversampling) { if ((baud >= 3000000) && (baud < 3250000) && (quot > 1)) quot -= 1; else if ((baud > 3250000) && (quot > 2)) quot -= 2; } pl011_write(quot & 0x3f, uap, REG_FBRD); pl011_write(quot >> 6, uap, REG_IBRD); pl011_write_lcr_h(uap, lcr_h); pl011_write(old_cr, uap, REG_CR); spin_unlock_irqrestore(&port->lock, flags); 详细分析这段代码中哪些部分是设置波特率,哪些是设置校验位,哪些是设置停止位,拆分出来
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值