论坛元老
- 积分
- 4133
- 金钱
- 4133
- 注册时间
- 2018-5-14
- 在线时间
- 902 小时
|
发表于 2022-2-23 12:05:04
|
显示全部楼层
&uart4 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_uart4>; fsl,rs485-gpio-txen = <&gpio1 18 GPIO_ACTIVE_LOW>; linux,rs485-enabled-at-boot-time; status = "okay";};
#include <asm-generic/ioctls.h>
int rs485_enable(const int fd, const RS485_ENABLE_t enable)
{
struct serial_rs485 rs485conf;
int res;
//read config
res = ioctl(fd, TIOCGRS485, &rs485conf);
if (res < 0) {
perror("Ioctl error on getting 485 configure:");
close(fd);
return res;
}
if (enable) { // Enable rs485 mode
rs485conf.flags |= SER_RS485_ENABLED;
} else { // Disable rs485 mode
rs485conf.flags &= ~(SER_RS485_ENABLED);
}
rs485conf.delay_rts_before_send = 0x00000004;
//write config
res = ioctl(fd, TIOCSRS485, &rs485conf);
if (res < 0) {
perror("Ioctl error on setting 485 configure:");
close(fd);
}
return res;
}
|
|