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
commit fa3cd4ee33fff312f80fee2eda27736f34542202 Author: Andrzej Kaczmarek <andrzej.kaczma...@codecoup.pl> AuthorDate: Tue Oct 11 22:07:01 2022 +0200 hw/ipc_nrf5340: Add APIs to get used/free space in IPC channel --- .../ipc_nrf5340/include/ipc_nrf5340/ipc_nrf5340.h | 26 ++++++++++++++++++++++ hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c | 15 +++++++++++++ 2 files changed, 41 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 d0398d518..b20ecc5a6 100644 --- a/hw/drivers/ipc_nrf5340/include/ipc_nrf5340/ipc_nrf5340.h +++ b/hw/drivers/ipc_nrf5340/include/ipc_nrf5340/ipc_nrf5340.h @@ -131,6 +131,32 @@ uint16_t ipc_nrf5340_available(int channel); */ uint16_t ipc_nrf5340_available_buf(int channel, void **dptr); +/** + * Returns number of data bytes available in IPC ring buffer for reading. + * + * Note: this function does not use any kind of locking so it's up to caller + * to make sure it's not used during write from other context as it may + * yield incorrect results. + * + * @param channel IPC channel number + * + * @return Number of bytes available in IPC ring buffer + */ +uint16_t ipc_nrf5340_data_available_get(int channel); + +/** + * Returns number of free data bytes available in IPC ring buffer for writing. + * + * Note: this function does not use any kind of locking so it's up to caller + * to make sure it's not used during write from other context as it may + * yield incorrect results. + * + * @param channel IPC channel number + * + * @return Number of bytes available in IPC ring buffer + */ +uint16_t ipc_nrf5340_data_free_get(int channel); + /** * 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 45a5b6d51..53c1d8a26 100644 --- a/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c +++ b/hw/drivers/ipc_nrf5340/src/ipc_nrf5340.c @@ -470,6 +470,21 @@ ipc_nrf5340_available_buf(int channel, void **dptr) return 0; } +uint16_t +ipc_nrf5340_data_available_get(int channel) +{ + assert(channel < IPC_MAX_CHANS); + + return ipc_nrf5340_shm_get_data_length(shms[channel].head, + shms[channel].tail); +} + +uint16_t +ipc_nrf5340_data_free_get(int channel) +{ + return IPC_BUF_SIZE - ipc_nrf5340_data_available_get(channel) - 1; +} + uint16_t ipc_nrf5340_consume(int channel, uint16_t len) {