Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipc: icmsg & icbmsg: Add support for the nrf5340bsim #78390

Merged
merged 8 commits into from
Sep 26, 2024
22 changes: 19 additions & 3 deletions include/zephyr/ipc/pbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ struct pbuf {
}

/**
* @brief Initialize the packet buffer.
* @brief Initialize the Tx packet buffer.
*
* This function initializes the packet buffer based on provided configuration.
* This function initializes the Tx packet buffer based on provided configuration.
* If the configuration is incorrect, the function will return error.
*
* It is recommended to use PBUF_DEFINE macro for build time initialization.
Expand All @@ -165,7 +165,23 @@ struct pbuf {
* @retval 0 on success.
* @retval -EINVAL when the input parameter is incorrect.
*/
int pbuf_init(struct pbuf *pb);
int pbuf_tx_init(struct pbuf *pb);

/**
* @brief Initialize the Rx packet buffer.
*
* This function initializes the Rx packet buffer.
* If the configuration is incorrect, the function will return error.
*
* It is recommended to use PBUF_DEFINE macro for build time initialization.
*
* @param pb Pointer to the packed buffer containing
* configuration and data. Configuration has to be
* fixed before the initialization.
* @retval 0 on success.
* @retval -EINVAL when the input parameter is incorrect.
*/
int pbuf_rx_init(struct pbuf *pb);

/**
* @brief Write specified amount of data to the packet buffer.
Expand Down
6 changes: 2 additions & 4 deletions subsys/ipc/ipc_service/lib/icmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,14 @@ int icmsg_open(const struct icmsg_config_t *conf,
k_mutex_init(&dev_data->tx_lock);
#endif

int ret = pbuf_init(dev_data->tx_pb);
int ret = pbuf_tx_init(dev_data->tx_pb);

if (ret < 0) {
__ASSERT(false, "Incorrect configuration");
return ret;
}

/* Initialize local copies of rx_pb. */
dev_data->rx_pb->data.wr_idx = 0;
dev_data->rx_pb->data.rd_idx = 0;
(void)pbuf_rx_init(dev_data->rx_pb);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't treat the error returned would be nice to have a comment explaining why


ret = pbuf_write(dev_data->tx_pb, magic, sizeof(magic));

Expand Down
14 changes: 13 additions & 1 deletion subsys/ipc/ipc_service/lib/pbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static int validate_cfg(const struct pbuf_cfg *cfg)
return 0;
}

int pbuf_init(struct pbuf *pb)
int pbuf_tx_init(struct pbuf *pb)
{
if (validate_cfg(pb->cfg) != 0) {
return -EINVAL;
Expand All @@ -77,6 +77,18 @@ int pbuf_init(struct pbuf *pb)
return 0;
}

int pbuf_rx_init(struct pbuf *pb)
{
if (validate_cfg(pb->cfg) != 0) {
return -EINVAL;
}
/* Initialize local copy of indexes. */
pb->data.wr_idx = 0;
pb->data.rd_idx = 0;

return 0;
}

int pbuf_write(struct pbuf *pb, const char *data, uint16_t len)
{
if (pb == NULL || len == 0 || data == NULL) {
Expand Down
10 changes: 5 additions & 5 deletions tests/subsys/ipc/pbuf/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ZTEST(test_pbuf, test_rw)
write_buf[i] = i+1;
}

zassert_equal(pbuf_init(&pb), 0);
zassert_equal(pbuf_tx_init(&pb), 0);

/* Write MSGA_SZ bytes packet. */
ret = pbuf_write(&pb, write_buf, MSGA_SZ);
Expand Down Expand Up @@ -132,9 +132,9 @@ ZTEST(test_pbuf, test_retcodes)
};

/* Initialize buffers. */
zassert_equal(pbuf_init(&pb0), 0);
zassert_equal(pbuf_init(&pb1), 0);
zassert_equal(pbuf_init(&pb2), 0);
zassert_equal(pbuf_tx_init(&pb0), 0);
zassert_equal(pbuf_tx_init(&pb1), 0);
zassert_equal(pbuf_tx_init(&pb2), 0);

print_pbuf_info(&pb0);
print_pbuf_info(&pb1);
Expand Down Expand Up @@ -274,7 +274,7 @@ ZTEST(test_pbuf, test_stress)
.cfg = &cfg,
};

zassert_equal(pbuf_init(&pb), 0);
zassert_equal(pbuf_tx_init(&pb), 0);
ctx.pbuf = &pb;
ctx.wr_cnt = 0;
ctx.rd_cnt = 0;
Expand Down