From fe895726320cb56431297cf6619690729c78bc55 Mon Sep 17 00:00:00 2001 From: Eren Terzioglu Date: Tue, 25 Aug 2026 15:08:29 +0200 Subject: [PATCH] arch/risc-v: Add nonblock timeout support for LP-Mailbox Add nonblock timeout support for LP-Mailbox for esp32[-c6|-p4] Signed-off-by: Eren Terzioglu --- .../src/common/espressif/esp_lp_mailbox.c | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/arch/risc-v/src/common/espressif/esp_lp_mailbox.c b/arch/risc-v/src/common/espressif/esp_lp_mailbox.c index 5ef4af66968..e2deff1b78b 100644 --- a/arch/risc-v/src/common/espressif/esp_lp_mailbox.c +++ b/arch/risc-v/src/common/espressif/esp_lp_mailbox.c @@ -24,6 +24,9 @@ #include +#include +#include + #include #include @@ -162,7 +165,7 @@ static int esp_lp_mailbox_read(struct file *filep, { struct inode *inode = filep->f_inode; struct esp_lp_mailbox_priv_s *priv = inode->i_private; - lp_message_t msg; + uint32_t timeout = (filep->f_oflags & O_NONBLOCK) ? 0 : UINT32_MAX; int i = 0; int ret = OK; lp_message_t recv; @@ -171,10 +174,19 @@ static int esp_lp_mailbox_read(struct file *filep, while (i < buflen) { - ret = lp_core_mailbox_receive(priv->mailbox, &recv, UINT32_MAX); + ret = lp_core_mailbox_receive(priv->mailbox, &recv, timeout); if (ret != OK) { - ferr("Failed to receive %dth byte\n", i + 1); + if (i == 0 && (filep->f_oflags & O_NONBLOCK) != 0) + { + return -EAGAIN; + } + + if ((filep->f_oflags & O_NONBLOCK) == 0) + { + ferr("Failed to receive %dth byte\n", i + 1); + } + return i; } @@ -296,15 +308,15 @@ static int esp_lp_mailbox_ioctl(struct file *filep, priv->async_op = true; } - if (ret != OK) - { - priv->async_op = false; - ferr("Could not register callback-%lx to lp-mailbox!\n", - (uint32_t)handler); - return ERROR; - } + if (ret != OK) + { + priv->async_op = false; + ferr("Could not register callback-%lx to lp-mailbox!\n", + (uint32_t)handler); + return ERROR; + } - priv->handler = handler; + priv->handler = handler; break; }