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

Function rpmsgmtd_bwrite

drivers/mtd/rpmsgmtd.c:330–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328 ****************************************************************************/
329
330static ssize_t rpmsgmtd_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
331 size_t nblocks, FAR const uint8_t *buffer)
332{
333 FAR struct rpmsgmtd_s *priv = (FAR struct rpmsgmtd_s *)dev;
334 FAR struct rpmsgmtd_bwrite_s *msg;
335 struct rpmsgmtd_cookie_s cookie;
336 uint32_t blocksize;
337 uint32_t space;
338 size_t written = 0;
339 int ret;
340
341 if (buffer == NULL)
342 {
343 return -EINVAL;
344 }
345
346 /* Sanity checks */
347
348 DEBUGASSERT(priv != NULL);
349
350 /* Get the server mtd geometry */
351
352 ret = rpmsgmtd_get_geometry(priv, NULL);
353 if (ret < 0)
354 {
355 ferr("Get geometry failed, ret=%d\n", ret);
356 return ret;
357 }
358
359 /* Perform the rpmsg write */
360
361 memset(&cookie, 0, sizeof(cookie));
362 nxsem_init(&cookie.sem, 0, 0);
363
364 blocksize = priv->geo.blocksize;
365 while (written < nblocks)
366 {
367 msg = rpmsgmtd_get_tx_payload_buffer(priv, &space);
368 if (msg == NULL)
369 {
370 ret = -ENOMEM;
371 goto out;
372 }
373
374 DEBUGASSERT(sizeof(*msg) - 1 + blocksize <= space);
375
376 msg->nblocks = (space - sizeof(*msg) + 1) / blocksize;
377 if (msg->nblocks >= nblocks - written)
378 {
379 /* Send complete, set cookie is valid, need ack */
380
381 msg->nblocks = nblocks - written;
382 msg->header.cookie = (uintptr_t)&cookie;
383 }
384 else
385 {
386 /* Not send complete, set cookie invalid, do not need ack */
387

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected