linux内核不应该能够自动切换RTS吗?
是的,从 Linux 3.0 开始就有这个内核框架。include/uapi/asm-generic/ioctls.h
中有两个 ioctl :
#define TIOCGRS485 0x542E
#define TIOCSRS485 0x542F
在 RS-485 模式下检索和配置 tty 串行端口驱动程序。
这些 ioctl 使用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 SoC 上使用了这个 RS-485 功能,但是在 Linux UART/USART 驱动程序中这些 ioctl 的实现非常稀疏。
如果您的驱动程序没有它,那么请考虑自己实现它。您可以使用drivers/tty/serial/atmel_serial.c中的实现作为指导。另请阅读RS485 的 Linux 内核文档。