mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
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:
@@ -722,6 +722,31 @@ void rpmsg_port_queue_add_buffer(FAR struct rpmsg_port_queue_s *queue,
|
|||||||
rpmsg_port_post(&queue->ready.sem);
|
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
|
* Name: rpmsg_port_register
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|||||||
@@ -37,6 +37,14 @@
|
|||||||
#include <nuttx/rpmsg/rpmsg.h>
|
#include <nuttx/rpmsg/rpmsg.h>
|
||||||
#include <nuttx/rpmsg/rpmsg_port.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
|
* 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);
|
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
|
* Name: rpmsg_port_initialize
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -49,10 +49,6 @@
|
|||||||
# define rpmsg_port_spi_crc16(hdr) 0
|
# define rpmsg_port_spi_crc16(hdr) 0
|
||||||
#endif
|
#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))
|
#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
|
* 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
|
* 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.
|
* 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.
|
* 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)
|
else if (rpspi->rxhdr->cmd == RPMSG_PORT_SPI_CMD_CONNECT)
|
||||||
|
|||||||
@@ -49,10 +49,6 @@
|
|||||||
# define rpmsg_port_spi_crc16(hdr) 0
|
# define rpmsg_port_spi_crc16(hdr) 0
|
||||||
#endif
|
#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))
|
#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
|
* 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
|
* 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.
|
* 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.
|
* 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)
|
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)
|
if (rpspi->rxhdr->cmd == RPMSG_PORT_SPI_CMD_SHUTDOWN)
|
||||||
{
|
{
|
||||||
rpspi->state = RPMSG_PORT_SPI_STATE_DISCONNECTING;
|
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);
|
rpmsg_port_queue_add_buffer(&rpspi->port.rxq, rpspi->rxhdr);
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ static void rpmsg_port_uart_send_packet(FAR struct rpmsg_port_uart_s *rpuart,
|
|||||||
rpmsg_port_uart_wakeup(rpuart);
|
rpmsg_port_uart_wakeup(rpuart);
|
||||||
|
|
||||||
rpmsgdump("TX Packed Data", data, datalen);
|
rpmsgdump("TX Packed Data", data, datalen);
|
||||||
|
rpmsgdbg("Sent %zu Data\n", datalen);
|
||||||
|
|
||||||
while (datalen > 0)
|
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);
|
rpmsgdbg("Connect Request Command %d\n", rpuart->connected);
|
||||||
if (rpuart->connected)
|
if (rpuart->connected)
|
||||||
{
|
{
|
||||||
|
rpmsg_port_drop_packets(&rpuart->port, RPMSG_PORT_DROP_TXQ);
|
||||||
rpmsg_port_unregister(&rpuart->port);
|
rpmsg_port_unregister(&rpuart->port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -315,6 +317,7 @@ rpmsg_port_uart_process_rx_conn(FAR struct rpmsg_port_uart_s *rpuart,
|
|||||||
rpuart->connected = true;
|
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_uart_send_command(rpuart, RPMSG_PORT_UART_CONNACK);
|
||||||
rpmsg_port_register(&rpuart->port, rpuart->localcpu);
|
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)
|
if (!rpuart->connected)
|
||||||
{
|
{
|
||||||
rpuart->connected = true;
|
rpuart->connected = true;
|
||||||
|
rpmsg_port_drop_packets(&rpuart->port, RPMSG_PORT_DROP_ALL);
|
||||||
rpmsg_port_register(&rpuart->port, rpuart->localcpu);
|
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)
|
else if (buf[i] == RPMSG_PORT_UART_POWEROFF)
|
||||||
{
|
{
|
||||||
rpmsgdbg("Received poweroff command\n");
|
rpmsgdbg("Received poweroff command\n");
|
||||||
|
rpmsg_port_drop_packets(&rpuart->port, RPMSG_PORT_DROP_TXQ);
|
||||||
rpmsg_port_unregister(&rpuart->port);
|
rpmsg_port_unregister(&rpuart->port);
|
||||||
rpuart->connected = false;
|
rpuart->connected = false;
|
||||||
continue;
|
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)
|
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);
|
rpmsg_port_queue_return_buffer(txq, hdr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user