简体   繁体   English

如何在两个半双工串行端口之间创建隧道?

[英]How to create a tunnel between two half-duplex serial ports?

I am working on an embedded project which includes two half duplex UARTS, and one full duplex UART. 我正在从事一个嵌入式项目,该项目包括两个半双工UART和一个全双工UART。

UART1 is connected to Device A. UART2 is connected to Device B, and UART3 is connected to the PC. UART1连接到设备A。UART2连接到设备B,而UART3连接到PC。 UART1 and UART2 are half-duplex, thus RX/TX modes have to be configured properly. UART1和UART2是半双工的,因此必须正确配置RX / TX模式。

When a signal on UART1 is triggered, UART2 fetches some data from Device B. That data is put into a buffer, and then transmitted back to UART1, AND UART3. 触发UART1上的信号时,UART2从设备B中获取一些数据。该数据放入缓冲区中,然后传输回UART1和UART3。 Device A consumes the data, and sends more items on UART1, which then has to be passed to UART2 for Device B to respond. 器件A消耗数据,并在UART1上发送更多项目,然后必须将其传递到UART2,以使器件B响应。

I was thinking about an efficient state machine that can handle the switching modes between TX/RX mode, and so far my UART code is interrupt driven. 我在考虑一种可以处理TX / RX模式之间切换模式的高效状态机,到目前为止,我的UART代码是中断驱动的。 What would be some ways to tackle the flow of this program? 有什么方法可以解决该计划的流程?

I don't think you will need a state machine for this case. 在这种情况下,我认为您不需要状态机。 Why not just hook up all interrupts accordingly and just forward anything received from one devivce to the other(s)? 为什么不仅仅相应地挂接所有中断,然后将从一个设备收到的任何内容转发给另一个设备呢?

You may want to include a TX (ring-)buffer to accomodate for different speeds of each UART and then just have a RX-ISR write the data received to the appropriate TX buffer(s), from where it will then be consumed by the other UARTs' UDRE-ISRs. 您可能需要包括一个TX(环形)缓冲区,以适应每个UART的不同速度,然后让RX-ISR将接收到的数据写入适当的TX缓冲区,然后从那里将它们消耗掉。其他UART的UDRE-ISR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM