我正试图在我的程序中建立半双工通信。我让我的RS485收发器使用RTS标志(TIOCM_RTS)在发送和接收之间来回切换。要发送/接收数据,我需要手动更改RTS标志:
我的问题是: linux内核不应该自动切换RTS吗?如何确保在调用setRTS(0)之前发送数据?
发布于 2014-08-11 21:50:38
linux内核不应该自动切换RTS吗?
是的,从Linux3.0开始就有这样的内核框架。
在include/uapi/asm-generic/ioctls.h中有两个ioctls
#define TIOCGRS485 0x542E
#define TIOCSRS485 0x542F
以RS-485模式检索和配置tty串口驱动程序.
这些ioctls使用struct serial_rs485
/*
* Serial interface for controlling RS485 settings on chips with suitable
* support. Set with TIOCSRS485 and get with TIOCGRS485 if supported by your
* platform. The set function returns the new state, with any unsupported bits
* reverted appropriately.
*/
struct serial_rs485 {
__u32 flags; /* RS485 feature flags */
#define SER_RS485_ENABLED (1 << 0) /* If enabled */
#define SER_RS485_RTS_ON_SEND (1 << 1) /* Logical level for
RTS pin when
sending */
#define SER_RS485_RTS_AFTER_SEND (1 << 2) /* Logical level for
RTS pin after sent*/
#define SER_RS485_RX_DURING_TX (1 << 4)
__u32 delay_rts_before_send; /* Delay before send (milliseconds) */
__u32 delay_rts_after_send; /* Delay after send (milliseconds) */
__u32 padding[5]; /* Memory is cheap, new structs
are a royal PITA .. */
};
我已经在Atmel和Etrax上使用了这个RS-485功能,但是在Linux /USART驱动程序中实现这些ioctls是非常稀疏的。
如果您的驱动程序没有它,那么考虑自己实现它。您可以使用drivers/tty/serial/atmel_serial.c中的实现作为指导。还可以阅读用于RS485的Linux内核文档。
发布于 2014-08-11 19:33:23
这确实是很棘手的--要主动地这样做--您需要知道最后一个字节何时清除了UART引擎,或者至少当它进入时(缓冲区为空)并添加一个根据波特率和字长计算的延迟。这确实是值得在串行驱动程序本身中实现的东西,在这里所有这些都是可见的。
但是,这个问题在共享总线上最常见,在共享总线中,您也接收到您发送的所有内容。如果是这样的话,您可以使用接收您自己的传输结束(假设您及时发现)作为触发器,以禁用驱动程序。
https://stackoverflow.com/questions/25250731
复制相似问题