drivers/rpmsg: Use optimal rx size and tx size

Use the minimal tx and rx size form two edge cpu to maintain
the transmit buffer size not exceed the edge cpus' buffer size.

[edg0] tx <---> rx0 [hub] rx1 <---> tx [edge1]
       rx <---> tx0       tx1 <---> rx

edge0_tx = min(rx0, tx1);
edge0_rx = min(tx0, rx1);

edge1_tx = min(rx1, tx0);
edge1_rx = min(tx1, rx0);

Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
yintao 2024-06-21 20:50:42 +08:00 committed by Xiang Xiao
parent ab47465dd5
commit 3fb39c6fc9

View file

@ -311,6 +311,7 @@ static void rpmsg_router_bound(FAR struct rpmsg_endpoint *ept)
FAR struct rpmsg_router_hub_s *hub = ept->priv;
struct rpmsg_router_s msg;
int ret;
int i;
if (!is_rpmsg_ept_ready(&hub->ept[0]) ||
!is_rpmsg_ept_ready(&hub->ept[1]))
@ -318,15 +319,15 @@ static void rpmsg_router_bound(FAR struct rpmsg_endpoint *ept)
return;
}
msg.tx_len = MIN(rpmsg_get_tx_buffer_size(hub->ept[0].rdev),
rpmsg_get_tx_buffer_size(hub->ept[1].rdev));
msg.rx_len = MIN(rpmsg_get_rx_buffer_size(hub->ept[0].rdev),
rpmsg_get_rx_buffer_size(hub->ept[1].rdev));
ret = rpmsg_send(&hub->ept[0], &msg, sizeof(msg));
DEBUGASSERT(ret >= 0);
ret = rpmsg_send(&hub->ept[1], &msg, sizeof(msg));
DEBUGASSERT(ret >= 0);
for (i = 0; i < 2; i++)
{
msg.tx_len = MIN(rpmsg_get_rx_buffer_size(hub->ept[i].rdev),
rpmsg_get_tx_buffer_size(hub->ept[1 - i].rdev));
msg.rx_len = MIN(rpmsg_get_tx_buffer_size(hub->ept[i].rdev),
rpmsg_get_rx_buffer_size(hub->ept[1 - i].rdev));
ret = rpmsg_send(&hub->ept[i], &msg, sizeof(msg));
DEBUGASSERT(ret >= 0);
}
}
/****************************************************************************