You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/03/22 14:47:20 UTC

[mynewt-core] branch master updated: hw/drivers/nrf53_ipc: Add API to retrieve pointer to data buffer

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 394ea8d  hw/drivers/nrf53_ipc: Add API to retrieve pointer to data buffer
394ea8d is described below

commit 394ea8dcee0a5c68ecd97c27a5c559fd4e73b794
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Mar 21 18:18:44 2022 +0100

    hw/drivers/nrf53_ipc: Add API to retrieve pointer to data buffer
    
    This allows to read directly from an IPC flat buffer instead of reading
    to a buffer.
---
 .../ipc_nrf5340/include/ipc_nrf5340/ipc_nrf5340.h      | 11 +++++++++++
 hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c               | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/hw/drivers/ipc_nrf5340/include/ipc_nrf5340/ipc_nrf5340.h b/hw/drivers/ipc_nrf5340/include/ipc_nrf5340/ipc_nrf5340.h
index 439915f..a912deb 100644
--- a/hw/drivers/ipc_nrf5340/include/ipc_nrf5340/ipc_nrf5340.h
+++ b/hw/drivers/ipc_nrf5340/include/ipc_nrf5340/ipc_nrf5340.h
@@ -105,6 +105,17 @@ uint16_t ipc_nrf5340_read_om(int channel, struct os_mbuf *om, uint16_t len);
 uint16_t ipc_nrf5340_available(int channel);
 
 /**
+ * Returns number of continuous data bytes available in IPC ring buffer with
+ * pointer to that data. Should be used only from ipc_nrf5340_recv_cb context.
+ *
+ * @param channel     IPC channel number
+ * @param dptr        Pointer to data buffer
+ *
+ * @return            Number of bytes available in IPC ring buffer
+ */
+uint16_t ipc_nrf5340_available_buf(int channel, void **dptr);
+
+/**
  * Consumes data from IPC ring buffer without copying. Should be used only
  * from ipc_nrf5340_recv_cb context.
  *
diff --git a/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c b/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c
index 9168dd4..96cf23d 100644
--- a/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c
+++ b/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c
@@ -453,6 +453,24 @@ ipc_nrf5340_available(int channel)
 }
 
 uint16_t
+ipc_nrf5340_available_buf(int channel, void **dptr)
+{
+    struct ipc_shm *shm = &shms[channel];
+    uint16_t head = shm->head;
+    uint16_t tail = shm->tail;
+
+    *dptr = &shm->buf[tail];
+
+    if (head > tail) {
+        return head - tail;
+    } else if (head < tail) {
+        return IPC_BUF_SIZE - tail;
+    }
+
+    return 0;
+}
+
+uint16_t
 ipc_nrf5340_consume(int channel, uint16_t len)
 {
     assert(channel < IPC_MAX_CHANS);