Skip to content

Commit

Permalink
apps: Convert examples to rpmsg_get_{tx,rx}_buffer_size()
Browse files Browse the repository at this point in the history
The contents of app() in these examples is given a rpmsg_device. We should
not have to know about the backing transport layer. We assume it is virtio
and call into the virtio layer to get the buffer size. This information is
now available from the rpmsg layer. Use those functions to make the app()
agnostic to the backing layer.

Signed-off-by: Andrew Davis <[email protected]>
  • Loading branch information
glneo authored and arnopo committed Apr 9, 2024
1 parent 52c27fb commit 89a8a30
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 61 deletions.
4 changes: 2 additions & 2 deletions apps/examples/echo/rpmsg-echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ int app(struct rpmsg_device *rdev, void *priv)

LPRINTF("Successfully created rpmsg endpoint.\r\n");

LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_virtio_get_tx_buffer_size(rdev));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_virtio_get_rx_buffer_size(rdev));
LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_get_tx_buffer_size(&lept));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_get_rx_buffer_size(&lept));

while(1) {
platform_poll(priv);
Expand Down
31 changes: 16 additions & 15 deletions apps/examples/echo/rpmsg-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,20 @@ int app (struct rpmsg_device *rdev, void *priv)
LPRINTF(" 1 - Send data to remote core, retrieve the echo");
LPRINTF(" and validate its integrity ..\r\n");

max_size = rpmsg_virtio_get_buffer_size(rdev);
if (max_size < 0) {
/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);

if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
return ret;
}

max_size = rpmsg_get_tx_buffer_size(&lept);
if (max_size <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);
Expand All @@ -116,22 +127,12 @@ int app (struct rpmsg_device *rdev, void *priv)

if (!i_payload) {
LPERROR("memory allocation failed.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);

if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
metal_free_memory(i_payload);
return ret;
}

LPRINTF("RPMsg driver TX buffer size: %#x\r\n", rpmsg_virtio_get_tx_buffer_size(rdev));
LPRINTF("RPMsg driver RX buffer size: %#x\r\n", rpmsg_virtio_get_rx_buffer_size(rdev));
LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_get_tx_buffer_size(&lept));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_get_rx_buffer_size(&lept));

while (!is_rpmsg_ept_ready(&lept))
platform_poll(priv);
Expand Down
19 changes: 10 additions & 9 deletions apps/examples/nocopy_echo/rpmsg-nocopy-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ static int app(struct rpmsg_device *rdev, void *priv)
LPRINTF(" 1 - Send data to remote core, retrieve the echo");
LPRINTF(" and validate its integrity ..\r\n");

max_size = rpmsg_virtio_get_buffer_size(rdev);
if ((int32_t)max_size < 0) {
LPERROR("No available buffer size.\r\n");
return -1;
}
max_size -= sizeof(struct _payload);
num_payloads = max_size - PAYLOAD_MIN_SIZE + 1;

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
Expand All @@ -142,8 +134,17 @@ static int app(struct rpmsg_device *rdev, void *priv)

while (!is_rpmsg_ept_ready(&lept))
platform_poll(priv);

LPRINTF("RPMSG endpoint is binded with remote.\r\n");

max_size = rpmsg_get_tx_buffer_size(&lept);
if ((int32_t)max_size <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);
num_payloads = max_size - PAYLOAD_MIN_SIZE + 1;

for (i = 0, size = PAYLOAD_MIN_SIZE; i < num_payloads; i++, size++) {
struct _payload *i_payload;

Expand Down
28 changes: 15 additions & 13 deletions apps/tests/msg/rpmsg-flood-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,35 @@ int app (struct rpmsg_device *rdev, void *priv)
LPRINTF(" and validate its integrity ..\r\n");

num_pkgs = NUMS_PACKAGES;
max_size = rpmsg_virtio_get_buffer_size(rdev);
if (max_size < 0) {
LPERROR("No available buffer size.\r\n");
return -1;
}
i_payload = (struct _payload *)metal_allocate_memory(max_size);

if (!i_payload) {
LPERROR("memory allocation failed.\r\n");
return -1;
}
max_size -= sizeof(struct _payload);

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME, APP_EPT_ADDR,
RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);
if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
metal_free_memory(i_payload);
return ret;
}

while (!is_rpmsg_ept_ready(&lept))
platform_poll(priv);
LPRINTF("RPMSG endpoint is binded with remote.\r\n");

max_size = rpmsg_get_tx_buffer_size(&lept);
if (max_size <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
i_payload = (struct _payload *)metal_allocate_memory(max_size);

if (!i_payload) {
LPERROR("memory allocation failed.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);

memset(&(i_payload->data[0]), 0xA5, max_size);
for (s = PAYLOAD_MIN_SIZE; s <= max_size; s++) {
int size;
Expand Down
17 changes: 9 additions & 8 deletions apps/tests/msg/rpmsg-nocopy-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ int app(struct rpmsg_device *rdev, void *priv)
int expect_rnum = 0;
void *buff_list[MAX_NB_TX_BUFF];

max_size = rpmsg_virtio_get_buffer_size(rdev);
if (((int)max_size) < 0) {
LPERROR("No available buffer size.\r\n");
return -1;
}
max_size -= sizeof(struct _payload);
num_payloads = max_size - PAYLOAD_MIN_SIZE + 1;

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
Expand All @@ -155,6 +147,15 @@ int app(struct rpmsg_device *rdev, void *priv)

LPRINTF("RPMSG endpoint is binded with remote.\r\n");

max_size = rpmsg_get_tx_buffer_size(&lept);
if (((int)max_size) <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);
num_payloads = max_size - PAYLOAD_MIN_SIZE + 1;

LPRINTF(" 1 - Get some TX buffers\r\n");
for (i = 0; i < MAX_NB_TX_BUFF; i++)
buff_list[i] = rpmsg_get_tx_payload_buffer(&lept, &max_size, 1);
Expand Down
29 changes: 15 additions & 14 deletions apps/tests/msg/rpmsg-ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@ int app (struct rpmsg_device *rdev, void *priv)
LPRINTF(" 1 - Send data to remote core, retrieve the echo");
LPRINTF(" and validate its integrity ..\r\n");

max_size = rpmsg_virtio_get_buffer_size(rdev);
if (max_size < 0) {
/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);
if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
return ret;
}

max_size = rpmsg_get_tx_buffer_size(&lept);
if (max_size <= 0) {
LPERROR("No available buffer size.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}
max_size -= sizeof(struct _payload);
Expand All @@ -121,21 +131,12 @@ int app (struct rpmsg_device *rdev, void *priv)

if (!i_payload) {
LPERROR("memory allocation failed.\r\n");
rpmsg_destroy_ept(&lept);
return -1;
}

/* Create RPMsg endpoint */
ret = rpmsg_create_ept(&lept, rdev, RPMSG_SERVICE_NAME,
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
rpmsg_endpoint_cb, rpmsg_service_unbind);
if (ret) {
LPERROR("Failed to create RPMsg endpoint.\r\n");
metal_free_memory(i_payload);
return ret;
}

LPRINTF("RPMsg driver TX buffer size: %#x\r\n", rpmsg_virtio_get_tx_buffer_size(rdev));
LPRINTF("RPMsg driver RX buffer size: %#x\r\n", rpmsg_virtio_get_rx_buffer_size(rdev));
LPRINTF("RPMsg device TX buffer size: %#x\r\n", rpmsg_get_tx_buffer_size(&lept));
LPRINTF("RPMsg device RX buffer size: %#x\r\n", rpmsg_get_rx_buffer_size(&lept));

while (!is_rpmsg_ept_ready(&lept))
platform_poll(priv);
Expand Down

0 comments on commit 89a8a30

Please sign in to comment.