[OpenWrt-Devel] [PATCH v5 1/2] serial: ar933x_uart: add rs485 support

Daniel Golle daniel at makrotopia.org
Wed Feb 12 11:51:13 EST 2020


Hi Petr,


On Wed, Feb 12, 2020 at 05:33:59PM +0100, Petr Štetiar wrote:
> Daniel Golle <daniel at makrotopia.org> [2020-02-12 16:37:36]:
> 
> ...
> 
> > ++static inline int ar933x_uart_is_half_duplex(struct ar933x_uart_port *up)
> > ++{
> 
> That function name is quite confusing as it's checking for 485/HD.

If someone wants to implement other half-duplex uses, one could add
more detection flags here (see atmel_serial.c where SER_ISO7816_ENABLED
has been added recently).

> 
> > ++	return (up->port.rs485.flags & SER_RS485_ENABLED) &&
> > ++		  !(up->port.rs485.flags & SER_RS485_RX_DURING_TX);
> > ++}
> 
> ...

Comes from atmel_serial.c and looks sane to me:
static inline int atmel_uart_is_half_duplex(struct uart_port *port)
{
	return (port->rs485.flags & SER_RS485_ENABLED) &&
		!(port->rs485.flags & SER_RS485_RX_DURING_TX);
}

How else would you solve that?

> 
> > +-	if (!uart_circ_empty(xmit))
> > ++	if (!uart_circ_empty(xmit)) {
> > + 		ar933x_uart_start_tx_interrupt(up);
> > ++	} else if (ar933x_uart_is_half_duplex(up)) {
> > ++		ar933x_uart_wait_tx_complete(up);
> > ++		ar933x_uart_rx_flush(up);
> > ++		ar933x_uart_start_rx_interrupt(up);
> > ++	}
> 
> This change looks strange, how are these two related? Where do you re-enable
> the TX interrupts in that 485/HD case?

So let's first look at it how it was before my change:
If the circular buffer is non-empty, enable the TX interrupt which
will soon call ar933x_uart_tx_chars() again to send more characters.
If the circular buffer is empty, do nothing and return.

So now I change the behaviour only in case there are no more characters
left to send (ie. uart_circ_empty(xmit)) and handle the half-duplex
emulation by waiting for transmission to complete, flushing everything
received in the meantime and re-enabling the RX interrupt which was
disabled before starting to transmit in the half-duplex case a few
lines above.



Cheers


Daniel

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list