MCPcopy Create free account
hub / github.com/apache/nuttx / rpmsgmtd_write

Function rpmsgmtd_write

drivers/mtd/rpmsgmtd.c:492–568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490
491#ifdef CONFIG_MTD_BYTE_WRITE
492static ssize_t rpmsgmtd_write(FAR struct mtd_dev_s *dev, off_t offset,
493 size_t nbytes, FAR const uint8_t *buffer)
494{
495 FAR struct rpmsgmtd_s *priv = (FAR struct rpmsgmtd_s *)dev;
496 FAR struct rpmsgmtd_write_s *msg;
497 struct rpmsgmtd_cookie_s cookie;
498 uint32_t space;
499 size_t written = 0;
500 int ret;
501
502 if (buffer == NULL)
503 {
504 return -EINVAL;
505 }
506
507 /* Sanity checks */
508
509 DEBUGASSERT(priv != NULL);
510
511 /* Perform the rpmsg write */
512
513 memset(&cookie, 0, sizeof(cookie));
514 nxsem_init(&cookie.sem, 0, 0);
515
516 while (written < nbytes)
517 {
518 msg = rpmsgmtd_get_tx_payload_buffer(priv, &space);
519 if (msg == NULL)
520 {
521 ret = -ENOMEM;
522 goto out;
523 }
524
525 space -= sizeof(*msg) - 1;
526 if (space >= nbytes - written)
527 {
528 /* Send complete, set cookie is valid, need ack */
529
530 space = nbytes - written;
531 msg->header.cookie = (uintptr_t)&cookie;
532 }
533 else
534 {
535 /* Not send complete, set cookie invalid, do not need ack */
536
537 msg->header.cookie = 0;
538 }
539
540 msg->header.command = RPMSGMTD_WRITE;
541 msg->header.result = -ENXIO;
542 msg->offset = offset;
543 msg->nbytes = space;
544 memcpy(msg->buf, buffer, space);
545
546 ret = rpmsg_send_nocopy(&priv->ept, msg, sizeof(*msg) - 1 + space);
547 if (ret < 0)
548 {
549 goto out;

Callers

nothing calls this directly

Calls 6

nxsem_initFunction · 0.85
rpmsg_waitFunction · 0.85
nxsem_destroyFunction · 0.85
memsetFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected