rpmsg/rpmsg_port_uart: drop all the packets when reconnect to peer

1. move drop packets function from port spi to port;
2. add drop packets logic when reconnect to peer;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: liaoao <liaoao@xiaomi.com>
This commit is contained in:
Bowen Wang
2024-12-31 14:57:12 +08:00
committed by Xiang Xiao
parent 3d764939c8
commit 2a8acac159
5 changed files with 54 additions and 66 deletions
+25
View File
@@ -722,6 +722,31 @@ void rpmsg_port_queue_add_buffer(FAR struct rpmsg_port_queue_s *queue,
rpmsg_port_post(&queue->ready.sem);
}
/****************************************************************************
* Name: rpmsg_port_drop_packets
****************************************************************************/
void rpmsg_port_drop_packets(FAR struct rpmsg_port_s *rport, uint8_t type)
{
FAR struct rpmsg_port_header_s *hdr;
if (type & RPMSG_PORT_DROP_TXQ)
{
while (!!(hdr = rpmsg_port_queue_get_buffer(&rport->txq, false)))
{
rpmsg_port_queue_return_buffer(&rport->txq, hdr);
}
}
if (type & RPMSG_PORT_DROP_RXQ)
{
while (!!(hdr = rpmsg_port_queue_get_buffer(&rport->rxq, false)))
{
rpmsg_port_queue_return_buffer(&rport->rxq, hdr);
}
}
}
/****************************************************************************
* Name: rpmsg_port_register
****************************************************************************/
+14
View File
@@ -37,6 +37,14 @@
#include <nuttx/rpmsg/rpmsg.h>
#include <nuttx/rpmsg/rpmsg_port.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define RPMSG_PORT_DROP_TXQ 0x01
#define RPMSG_PORT_DROP_RXQ 0x02
#define RPMSG_PORT_DROP_ALL 0x03
/****************************************************************************
* Public Types
****************************************************************************/
@@ -264,6 +272,12 @@ uint16_t rpmsg_port_queue_nused(FAR struct rpmsg_port_queue_s *queue)
return atomic_read(&queue->ready.num);
}
/****************************************************************************
* Name: rpmsg_port_drop_packets
****************************************************************************/
void rpmsg_port_drop_packets(FAR struct rpmsg_port_s *rport, uint8_t type);
/****************************************************************************
* Name: rpmsg_port_initialize
*
+2 -32
View File
@@ -49,10 +49,6 @@
# define rpmsg_port_spi_crc16(hdr) 0
#endif
#define RPMSG_PORT_SPI_DROP_TXQ 0x01
#define RPMSG_PORT_SPI_DROP_RXQ 0x02
#define RPMSG_PORT_SPI_DROP_ALL 0x03
#define BYTES2WORDS(s,b) ((b) / ((s)->nbits >> 3))
/****************************************************************************
@@ -141,32 +137,6 @@ static const struct rpmsg_port_ops_s g_rpmsg_port_spi_ops =
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: rpmsg_port_spi_drop_packets
****************************************************************************/
static void
rpmsg_port_spi_drop_packets(FAR struct rpmsg_port_spi_s *rpspi, uint8_t type)
{
FAR struct rpmsg_port_header_s *hdr;
if (type & RPMSG_PORT_SPI_DROP_TXQ)
{
while (!!(hdr = rpmsg_port_queue_get_buffer(&rpspi->port.txq, false)))
{
rpmsg_port_queue_return_buffer(&rpspi->port.txq, hdr);
}
}
if (type & RPMSG_PORT_SPI_DROP_RXQ)
{
while (!!(hdr = rpmsg_port_queue_get_buffer(&rpspi->port.rxq, false)))
{
rpmsg_port_queue_return_buffer(&rpspi->port.rxq, hdr);
}
}
}
/****************************************************************************
* Name: rpmsg_port_spi_notify_tx_ready
****************************************************************************/
@@ -186,7 +156,7 @@ static void rpmsg_port_spi_notify_tx_ready(FAR struct rpmsg_port_s *port)
* status false.
*/
rpmsg_port_spi_drop_packets(rpspi, RPMSG_PORT_SPI_DROP_TXQ);
rpmsg_port_drop_packets(&rpspi->port, RPMSG_PORT_DROP_TXQ);
}
}
@@ -331,7 +301,7 @@ static void rpmsg_port_spi_complete_handler(FAR void *arg)
* when a reconnect request to be received.
*/
rpmsg_port_spi_drop_packets(rpspi, RPMSG_PORT_SPI_DROP_ALL);
rpmsg_port_drop_packets(&rpspi->port, RPMSG_PORT_DROP_ALL);
}
}
else if (rpspi->rxhdr->cmd == RPMSG_PORT_SPI_CMD_CONNECT)
+3 -33
View File
@@ -49,10 +49,6 @@
# define rpmsg_port_spi_crc16(hdr) 0
#endif
#define RPMSG_PORT_SPI_DROP_TXQ 0x01
#define RPMSG_PORT_SPI_DROP_RXQ 0x02
#define RPMSG_PORT_SPI_DROP_ALL 0x03
#define BYTES2WORDS(s,b) ((b) / ((s)->nbits >> 3))
/****************************************************************************
@@ -162,32 +158,6 @@ static const struct spi_slave_devops_s g_rpmsg_port_spi_slave_ops =
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: rpmsg_port_spi_drop_packets
****************************************************************************/
static void
rpmsg_port_spi_drop_packets(FAR struct rpmsg_port_spi_s *rpspi, int type)
{
FAR struct rpmsg_port_header_s *hdr;
if (type & RPMSG_PORT_SPI_DROP_TXQ)
{
while (!!(hdr = rpmsg_port_queue_get_buffer(&rpspi->port.txq, false)))
{
rpmsg_port_queue_return_buffer(&rpspi->port.txq, hdr);
}
}
if (type & RPMSG_PORT_SPI_DROP_RXQ)
{
while (!!(hdr = rpmsg_port_queue_get_buffer(&rpspi->port.rxq, false)))
{
rpmsg_port_queue_return_buffer(&rpspi->port.rxq, hdr);
}
}
}
/****************************************************************************
* Name: rpmsg_port_spi_exchange
****************************************************************************/
@@ -254,7 +224,7 @@ static void rpmsg_port_spi_notify_tx_ready(FAR struct rpmsg_port_s *port)
* status false.
*/
rpmsg_port_spi_drop_packets(rpspi, RPMSG_PORT_SPI_DROP_TXQ);
rpmsg_port_drop_packets(&rpspi->port, RPMSG_PORT_DROP_TXQ);
}
}
@@ -392,7 +362,7 @@ static void rpmsg_port_spi_slave_notify(FAR struct spi_slave_dev_s *dev,
* when a reconnect request to be received.
*/
rpmsg_port_spi_drop_packets(rpspi, RPMSG_PORT_SPI_DROP_ALL);
rpmsg_port_drop_packets(&rpspi->port, RPMSG_PORT_DROP_ALL);
}
}
else if (rpspi->rxhdr->cmd == RPMSG_PORT_SPI_CMD_CONNECT)
@@ -423,7 +393,7 @@ static void rpmsg_port_spi_slave_notify(FAR struct spi_slave_dev_s *dev,
if (rpspi->rxhdr->cmd == RPMSG_PORT_SPI_CMD_SHUTDOWN)
{
rpspi->state = RPMSG_PORT_SPI_STATE_DISCONNECTING;
rpmsg_port_spi_drop_packets(rpspi, RPMSG_PORT_SPI_DROP_ALL);
rpmsg_port_drop_packets(&rpspi->port, RPMSG_PORT_DROP_ALL);
}
rpmsg_port_queue_add_buffer(&rpspi->port.rxq, rpspi->rxhdr);
+10 -1
View File
@@ -199,6 +199,7 @@ static void rpmsg_port_uart_send_packet(FAR struct rpmsg_port_uart_s *rpuart,
rpmsg_port_uart_wakeup(rpuart);
rpmsgdump("TX Packed Data", data, datalen);
rpmsgdbg("Sent %zu Data\n", datalen);
while (datalen > 0)
{
@@ -308,6 +309,7 @@ rpmsg_port_uart_process_rx_conn(FAR struct rpmsg_port_uart_s *rpuart,
rpmsgdbg("Connect Request Command %d\n", rpuart->connected);
if (rpuart->connected)
{
rpmsg_port_drop_packets(&rpuart->port, RPMSG_PORT_DROP_TXQ);
rpmsg_port_unregister(&rpuart->port);
}
else
@@ -315,6 +317,7 @@ rpmsg_port_uart_process_rx_conn(FAR struct rpmsg_port_uart_s *rpuart,
rpuart->connected = true;
}
rpmsg_port_drop_packets(&rpuart->port, RPMSG_PORT_DROP_ALL);
rpmsg_port_uart_send_command(rpuart, RPMSG_PORT_UART_CONNACK);
rpmsg_port_register(&rpuart->port, rpuart->localcpu);
}
@@ -324,6 +327,7 @@ rpmsg_port_uart_process_rx_conn(FAR struct rpmsg_port_uart_s *rpuart,
if (!rpuart->connected)
{
rpuart->connected = true;
rpmsg_port_drop_packets(&rpuart->port, RPMSG_PORT_DROP_ALL);
rpmsg_port_register(&rpuart->port, rpuart->localcpu);
}
}
@@ -389,6 +393,7 @@ static int rpmsg_port_uart_rx_thread(int argc, FAR char *argv[])
else if (buf[i] == RPMSG_PORT_UART_POWEROFF)
{
rpmsgdbg("Received poweroff command\n");
rpmsg_port_drop_packets(&rpuart->port, RPMSG_PORT_DROP_TXQ);
rpmsg_port_unregister(&rpuart->port);
rpuart->connected = false;
continue;
@@ -482,7 +487,11 @@ static int rpmsg_port_uart_tx_thread(int argc, FAR char *argv[])
while ((hdr = rpmsg_port_queue_get_buffer(txq, true)) != NULL)
{
rpmsg_port_uart_send_data(rpuart, hdr);
if (rpuart->connected)
{
rpmsg_port_uart_send_data(rpuart, hdr);
}
rpmsg_port_queue_return_buffer(txq, hdr);
}
}