RS-485.zip
(12.84 KB)
1、在DTS文件中增加rts-gpio及其管脚配置
&uart12 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart12>;
rts-gpio = <&gpioi 1 0>;
};
&uart14 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart14>;
rts-gpio = <&gpioi 5 0>;
};
2、在驱动文件ma35d1_serial.c中结构体uart_ma35d1_port增加变量int rts_gpio;
3、在probe函数里面增加获取rts_gpio的代码:
up->rts_gpio = of_get_named_gpio(pdev->dev.of_node, "rts-gpio", 0);
if (gpio_is_valid(up->rts_gpio)) {
pr_err("test will request gpio\n");
ret = devm_gpio_request(up->port.dev,
up->rts_gpio, "RTS");
if (ret) {
dev_err(&pdev->dev,
"error requesting RTS GPIO\n");
}
ret = gpio_direction_output(up->rts_gpio,0);
if (ret) {
dev_err(&pdev->dev, "error setting RTS GPIO\n");
}
}else{
pr_err("test port do not have rts_port\n");
up->rts_gpio=-EINVAL;
}
4、增加修改极性的函数
static void set_rs485_rst(struct uart_ma35d1_port *p,int value)
{
int i=0;
i= value;
if(p->rts_gpio != -EINVAL){
gpio_direction_output(p->rts_gpio,i);
}
}
5、在合适的地方调用步骤4增加的函数
static inline void __stop_tx(struct uart_ma35d1_port *p)
{
unsigned int ier;
ier = serial_in(p, UART_REG_IER);
if (ier & THRE_IEN){
if(p->rts_gpio!=-EINVAL){
if(serial_in(p,UART_REG_FSR)&TE_FLAG){
set_rs485_rst(p,0);
serial_out(p, UART_REG_IER, ier & ~THRE_IEN);
}
}else{
serial_out(p, UART_REG_IER, ier & ~THRE_IEN);
}
}
if (p->rs485.flags & SER_RS485_ENABLED)
rs485_start_rx(p);
}
static void ma35d1serial_start_tx(struct uart_port *port)
{
struct uart_ma35d1_port *up = (struct uart_ma35d1_port *)port;
unsigned int ier;
struct circ_buf *xmit = &up->port.state->xmit;
set_rs485_rst(up,1);
if (up->rs485.flags & SER_RS485_ENABLED)
rs485_stop_rx(up);
...... |