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

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 9c96d876d1cc42071e602259f986a5de4cd7fdca
Author: Eren Terzioglu <[email protected]>
AuthorDate: Fri Jul 24 14:07:38 2026 +0200

    arch/risc-v/espressif: Add SW LP Mailbox support
    
    Add software lp mailbox support
    
    Signed-off-by: Eren Terzioglu <[email protected]>
---
 arch/risc-v/src/common/espressif/Kconfig          |  2 +-
 arch/risc-v/src/common/espressif/esp_lp_mailbox.c | 31 ++++++++++++++++++++++-
 arch/risc-v/src/common/espressif/esp_ulp.cmake    | 21 ++++++++++++---
 arch/risc-v/src/common/espressif/esp_ulp.mk       | 11 +++++++-
 arch/risc-v/src/esp32c6/hal_esp32c6.cmake         |  4 +++
 arch/risc-v/src/esp32c6/hal_esp32c6.mk            |  4 +++
 6 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/arch/risc-v/src/common/espressif/Kconfig 
b/arch/risc-v/src/common/espressif/Kconfig
index e4df0a5c2eb..cbdbd04bd04 100644
--- a/arch/risc-v/src/common/espressif/Kconfig
+++ b/arch/risc-v/src/common/espressif/Kconfig
@@ -1732,7 +1732,7 @@ config ESPRESSIF_ANA_COMPR1
 config ESPRESSIF_LP_MAILBOX
        bool "LP Mailbox"
        default n
-       depends on ARCH_CHIP_ESP32P4 && ESPRESSIF_USE_LP_CORE
+       depends on ESPRESSIF_USE_LP_CORE
        ---help---
                Enable lp mailbox support for data passing between cores.
 
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 18a78537853..5ef4af66968 100644
--- a/arch/risc-v/src/common/espressif/esp_lp_mailbox.c
+++ b/arch/risc-v/src/common/espressif/esp_lp_mailbox.c
@@ -30,6 +30,7 @@
 #include <nuttx/debug.h>
 
 #include "lp_core_mailbox.h"
+#include "soc/soc_caps.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -52,6 +53,7 @@ struct esp_lp_mailbox_priv_s
  * Private Function Prototypes
  ****************************************************************************/
 
+static int esp_lp_mailbox_open(struct file *filep);
 static int esp_lp_mailbox_read(struct file *filep,
                                char *buffer,
                                size_t buflen);
@@ -68,7 +70,7 @@ static int esp_lp_mailbox_ioctl(struct file *filep,
 
 static const struct file_operations g_esp_lp_mailbox_fops =
 {
-  .open = NULL,                       /* open */
+  .open = esp_lp_mailbox_open,        /* open */
   .close = NULL,                      /* close */
   .read = esp_lp_mailbox_read,        /* read */
   .write = esp_lp_mailbox_write,      /* write */
@@ -91,6 +93,31 @@ struct esp_lp_mailbox_priv_s esp_lp_mailbox_priv =
  * Private Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: esp_lp_mailbox_open
+ *
+ * Description:
+ *   Handler for the LP Mailbox initializer.
+ *
+ * Input Parameters:
+ *   filep - Pointer to the file structure.
+ *
+ * Returned Value:
+ *   None.
+ *
+ ****************************************************************************/
+
+static int esp_lp_mailbox_open(struct file *filep)
+{
+  int ret = OK;
+#ifndef SOC_LP_MAILBOX_SUPPORTED
+  ret = lp_core_mailbox_init(&esp_lp_mailbox_priv.mailbox,
+                             &esp_lp_mailbox_priv.config);
+#endif
+
+  return ret;
+}
+
 /****************************************************************************
  * Name: esp_lp_mailbox_rcv_callback
  *
@@ -312,6 +339,7 @@ static int esp_lp_mailbox_ioctl(struct file *filep,
 
 int esp_lp_mailbox_init(void)
 {
+#ifdef SOC_LP_MAILBOX_SUPPORTED
   int ret = lp_core_mailbox_init(&esp_lp_mailbox_priv.mailbox,
                                  &esp_lp_mailbox_priv.config);
 
@@ -320,6 +348,7 @@ int esp_lp_mailbox_init(void)
       ferr("Failed to initialize LP Mailbox driver: %d\n", ret);
       return ret;
     }
+#endif
 
   register_driver("/dev/lp_mailbox", esp_lp_mailbox_priv.ops,
                   0600, (void *)&esp_lp_mailbox_priv);
diff --git a/arch/risc-v/src/common/espressif/esp_ulp.cmake 
b/arch/risc-v/src/common/espressif/esp_ulp.cmake
index cc9961b8acc..9fbef1708e2 100644
--- a/arch/risc-v/src/common/espressif/esp_ulp.cmake
+++ b/arch/risc-v/src/common/espressif/esp_ulp.cmake
@@ -206,6 +206,7 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE)
       ${HAL}/components/ulp/lp_core/lp_core/lp_core_startup.c
       ${HAL}/components/ulp/lp_core/lp_core/lp_core_utils.c
       ${HAL}/components/ulp/lp_core/lp_core/lp_core_uart.c
+      ${HAL}/components/ulp/lp_core/lp_core/lp_core_mailbox.c
       ${HAL}/components/ulp/lp_core/lp_core/lp_core_print.c
       ${HAL}/components/ulp/lp_core/lp_core/lp_core_panic.c
       ${HAL}/components/ulp/lp_core/lp_core/lp_core_interrupt.c
@@ -216,10 +217,14 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE)
   )
 
   if(CONFIG_ARCH_CHIP_ESP32P4)
-    list(
-      APPEND ULP_CSOURCES ${HAL}/components/ulp/lp_core/lp_core/lp_core_touch.c
-      ${HAL}/components/ulp/lp_core/lp_core/port/lp_core_mailbox_impl_hw.c
-      ${HAL}/components/ulp/lp_core/lp_core/lp_core_mailbox.c)
+    list(APPEND ULP_CSOURCES
+         ${HAL}/components/ulp/lp_core/lp_core/lp_core_touch.c
+         ${HAL}/components/ulp/lp_core/lp_core/port/lp_core_mailbox_impl_hw.c)
+  endif()
+
+  if(CONFIG_ARCH_CHIP_ESP32C6)
+    list(APPEND ULP_CSOURCES
+         ${HAL}/components/ulp/lp_core/lp_core/port/lp_core_mailbox_impl_sw.c)
   endif()
 
   # 
############################################################################
@@ -420,6 +425,13 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE)
       COMMENT "Linking ULP firmware"
       VERBATIM)
 
+    set(_ulp_postprocess_sw_mailbox_alias
+        [=[if grep -q 'g_lp_core_mailbox_impl_sw_ctx' "@ULP_MAIN_LD@"; then 
addr=$(grep 'g_lp_core_mailbox_impl_sw_ctx' "@ULP_MAIN_LD@" | head -1 | sed -E 
's/.*=[[:space:]]*([0x0-9a-fA-F]+);.*/\1/'); if ! grep -qE 
'^[[:space:]]*ulp_g_lp_core_mailbox_impl_sw_ctx[[:space:]]*=' "@ULP_MAIN_LD@"; 
then echo "ulp_g_lp_core_mailbox_impl_sw_ctx = ${addr};" >> "@ULP_MAIN_LD@"; 
fi; fi]=]
+    )
+    string(REPLACE "@ULP_MAIN_LD@" "${ULP_MAIN_LD}"
+                   _ulp_postprocess_sw_mailbox_alias
+                   "${_ulp_postprocess_sw_mailbox_alias}")
+
     set(_ulp_postprocess_aliases
         [=[grep -E 
'^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*=[[:space:]]*[0x]*[0-9a-fA-F]+;'
 "@ULP_MAIN_LD@" | while IFS= read -r line; do var_name=$(echo "$line" | sed -E 
's/^[[:space:]]*([a-zA-Z_][a-zA-Z0-9_]*).*/\1/'); existing_line=$(grep -E 
"^[[:space:]]*${var_name}[[:space:]]*=" "@ULP_ALIASES_LD@" 2>/dev/null || 
true); if [ -n "$existing_line" ]; then if [ "$existing_line" != "$line" ]; 
then sed -i "/${existing_line}/c\\${line}" "@ULP_ALIASES_LD@"; fi; else echo 
"$line" >> " [...]
     )
@@ -448,6 +460,7 @@ if(CONFIG_ESPRESSIF_USE_LP_CORE)
       COMMAND ${ULP_READELF} -sW ${ULP_ELF_FILE} > ${ULP_SYM_FILE}
       COMMAND ${Python3_EXECUTABLE} ${ULP_MAPGEN_TOOL} -s ${ULP_SYM_FILE} -o
               ${ULP_FOLDER}/ulp_main --base ${ULP_BASE} --prefix ${ULP_PREFIX}
+      COMMAND bash -c "${_ulp_postprocess_sw_mailbox_alias}"
       COMMAND bash -c "${_ulp_postprocess_aliases}"
       COMMAND sed -i "/${ULP_PREFIX}/d" ${ULP_VARS_HEADER}
       COMMAND
diff --git a/arch/risc-v/src/common/espressif/esp_ulp.mk 
b/arch/risc-v/src/common/espressif/esp_ulp.mk
index 4095b0c13fa..4f1a5d64840 100644
--- a/arch/risc-v/src/common/espressif/esp_ulp.mk
+++ b/arch/risc-v/src/common/espressif/esp_ulp.mk
@@ -143,10 +143,12 @@ ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM
 ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_lp_adc_shared.c
 ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_lp_vad_shared.c
 ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_critical_section_shared.c
+ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_mailbox.c
 ifeq ($(CONFIG_ARCH_CHIP_ESP32P4),y)
        ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_touch.c
        ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)port$(DELIM)lp_core_mailbox_impl_hw.c
-       ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)lp_core_mailbox.c
+else
+       ULP_CSOURCES += 
$(CHIP)$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core$(DELIM)port$(DELIM)lp_core_mailbox_impl_sw.c
 endif
 
 # Add ULP app source files and directories
@@ -305,6 +307,13 @@ ifneq ($(suffix $(ULP_APP_BIN)),.bin)
        $(Q) $(OBJCOPY) -O binary $(ULP_ELF_FILE) $(ULP_BIN_FILE)
        $(Q) $(ULP_READELF) -sW $(ULP_ELF_FILE) > $(ULP_SYM_FILE)
        $(Q) python3 $(ULP_MAPGEN_TOOL_PATH) -s $(ULP_SYM_FILE) -o 
$(ULP_FOLDER)$(DELIM)ulp_main --base $(ULP_BASE) --prefix $(ULP_PREFIX)
+       $(Q) if grep -q 'g_lp_core_mailbox_impl_sw_ctx' 
$(ULP_FOLDER)$(DELIM)ulp_main.ld; then \
+               addr=$$(grep 'g_lp_core_mailbox_impl_sw_ctx' 
$(ULP_FOLDER)$(DELIM)ulp_main.ld | head -1 | \
+                       sed -E 's/.*=[[:space:]]*([0x0-9a-fA-F]+);.*/\1/'); \
+               if ! grep -qE 
'^[[:space:]]*ulp_g_lp_core_mailbox_impl_sw_ctx[[:space:]]*=' 
$(ULP_FOLDER)$(DELIM)ulp_main.ld; then \
+                       echo "ulp_g_lp_core_mailbox_impl_sw_ctx = $$addr;" >> 
$(ULP_FOLDER)$(DELIM)ulp_main.ld; \
+               fi; \
+       fi
 # Checking ULP linker script output and adding/changing related lines on 
common linker for HP core to access ULP core variables on HP core.
        $(Q) grep -E 
'^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*=[[:space:]]*[0x]*[0-9a-fA-F]+;'
 $(ULP_FOLDER)$(DELIM)ulp_main.ld | while IFS= read -r line; do \
                out_file=$(BOARD)$(DELIM)scripts$(DELIM)ulp_aliases.ld; \
diff --git a/arch/risc-v/src/esp32c6/hal_esp32c6.cmake 
b/arch/risc-v/src/esp32c6/hal_esp32c6.cmake
index 897a290a7e5..994bc313e2d 100644
--- a/arch/risc-v/src/esp32c6/hal_esp32c6.cmake
+++ b/arch/risc-v/src/esp32c6/hal_esp32c6.cmake
@@ -270,6 +270,7 @@ list(
   ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/mac_addr.c
   ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/modem_clock.c
   ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/periph_ctrl.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/pmu_share_hw.c
   ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/regi2c_ctrl.c
   ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/rtc_module.c
   ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/sleep_console.c
@@ -504,6 +505,9 @@ list(
   HAL_SRCS
   ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/lp_core_i2c.c
   ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/lp_core.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/lp_core_mailbox.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/lp_core_mailbox_impl_sw.c
+  
${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/shared/ulp_lp_core_critical_section_shared.c
   
${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/shared/ulp_lp_core_memory_shared.c
   
${ESP_HAL_3RDPARTY_REPO}/components/ulp/lp_core/shared/ulp_lp_core_lp_timer_shared.c
 )
diff --git a/arch/risc-v/src/esp32c6/hal_esp32c6.mk 
b/arch/risc-v/src/esp32c6/hal_esp32c6.mk
index 6da49a12d2a..c3dbd8d66d0 100644
--- a/arch/risc-v/src/esp32c6/hal_esp32c6.mk
+++ b/arch/risc-v/src/esp32c6/hal_esp32c6.mk
@@ -213,6 +213,7 @@ CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)mac_addr.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)modem_clock.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)periph_ctrl.c
+CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)pmu_share_hw.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)regi2c_ctrl.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)rtc_module.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)esp_hw_support$(DELIM)sleep_console.c
@@ -364,6 +365,9 @@ CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)spi_
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)spi_flash$(DELIM)cache_utils.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core_i2c.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core.c
+CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core_mailbox.c
+CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)lp_core_mailbox_impl_sw.c
+CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_critical_section_shared.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_memory_shared.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)ulp$(DELIM)lp_core$(DELIM)shared$(DELIM)ulp_lp_core_lp_timer_shared.c
 CHIP_CSRCS += 
chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)upper_hal_rmt$(DELIM)src$(DELIM)rmt_common.c

Reply via email to