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

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

commit 850805d70c88b0d63d4364d7110ce5363d2448ee
Author: zhangyu117 <[email protected]>
AuthorDate: Fri Aug 14 14:58:38 2026 +0800

    arch/arm/src: realize atomic for cxd56, rp2040 and lc823450
    
    Add per-chip atomic hwspinlock device definitions for cxd56, rp2040,
    and lc823450. Replace CXD56_TESTSET with CXD56_ATOMIC_WITH_HWSEM
    which selects LIBC_ATOMIC_HWSPINLOCK.
    
    RP2040: Cortex-M0+ no atomic, IRQ for non-SMP, hwspinlock for SMP.
    CXD56XX: CXD56_USE_SYSBUS controls hwsem usage in SMP.
    LC823450: toolchain supports atomic, hwspinlock optional for SMP.
    
    Signed-off-by: zhangyu117 <[email protected]>
---
 arch/arm/Kconfig                        |  2 ++
 arch/arm/src/cxd56xx/CMakeLists.txt     |  3 +-
 arch/arm/src/cxd56xx/Kconfig            |  6 ++++
 arch/arm/src/cxd56xx/Make.defs          |  1 +
 arch/arm/src/cxd56xx/cxd56_atomic.c     | 50 +++++++++++++++++++++++++++++++++
 arch/arm/src/cxd56xx/cxd56_sph.c        |  6 ++--
 arch/arm/src/lc823450/Make.defs         |  1 +
 arch/arm/src/lc823450/lc823450_atomic.c | 50 +++++++++++++++++++++++++++++++++
 arch/arm/src/rp2040/Make.defs           |  1 +
 arch/arm/src/rp2040/rp2040_atomic.c     | 50 +++++++++++++++++++++++++++++++++
 10 files changed, 167 insertions(+), 3 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index c105efb1204..5721c73b3c7 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -382,6 +382,8 @@ config ARCH_CHIP_RP2040
        select ARCH_BOARD_COMMON
        select ARCH_HAVE_CUSTOM_TESTSET
        select ARCH_USBDEV_STALLQUEUE if USBDEV
+       select LIBC_ATOMIC_IRQ if !SMP
+       select LIBC_ATOMIC_HWSPINLOCK if SMP
        ---help---
                Raspberry Pi RP2040 architectures (ARM dual Cortex-M0+).
 
diff --git a/arch/arm/src/cxd56xx/CMakeLists.txt 
b/arch/arm/src/cxd56xx/CMakeLists.txt
index f6745758f22..f7bdb5aa9b7 100644
--- a/arch/arm/src/cxd56xx/CMakeLists.txt
+++ b/arch/arm/src/cxd56xx/CMakeLists.txt
@@ -40,7 +40,8 @@ set(SRCS
     cxd56_powermgr.c
     cxd56_farapi.c
     cxd56_sysctl.c
-    cxd56_hwspinlock.c)
+    cxd56_hwspinlock.c
+    cxd56_atomic.c)
 
 if(CONFIG_SMP)
   list(APPEND SRCS cxd56_cpuidlestack.c)
diff --git a/arch/arm/src/cxd56xx/Kconfig b/arch/arm/src/cxd56xx/Kconfig
index 5b2f5af3de3..f1cc8634117 100644
--- a/arch/arm/src/cxd56xx/Kconfig
+++ b/arch/arm/src/cxd56xx/Kconfig
@@ -1429,6 +1429,12 @@ config CXD56_TESTSET_WITH_HWSEM
 
 endif # CXD56_TESTSET
 
+config CXD56_ATOMIC_WITH_HWSEM
+       bool "Use atomic based on hardware semaphore"
+       default !CXD56_USE_SYSBUS
+       depends on SMP
+       select LIBC_ATOMIC_HWSPINLOCK
+
 config CXD56_USE_SYSBUS
        bool "Use the system bus for the data section"
        default y
diff --git a/arch/arm/src/cxd56xx/Make.defs b/arch/arm/src/cxd56xx/Make.defs
index 0c14887131e..04e9ee59d01 100644
--- a/arch/arm/src/cxd56xx/Make.defs
+++ b/arch/arm/src/cxd56xx/Make.defs
@@ -39,6 +39,7 @@ CHIP_CSRCS += cxd56_icc.c
 CHIP_CSRCS += cxd56_powermgr.c
 CHIP_CSRCS += cxd56_farapi.c
 CHIP_CSRCS += cxd56_sysctl.c
+CHIP_CSRCS += cxd56_atomic.c
 CHIP_CSRCS += cxd56_hwspinlock.c
 
 ifeq ($(CONFIG_SMP),y)
diff --git a/arch/arm/src/cxd56xx/cxd56_atomic.c 
b/arch/arm/src/cxd56xx/cxd56_atomic.c
new file mode 100644
index 00000000000..2736b3fd9de
--- /dev/null
+++ b/arch/arm/src/cxd56xx/cxd56_atomic.c
@@ -0,0 +1,50 @@
+/****************************************************************************
+ * arch/arm/src/cxd56xx/cxd56_atomic.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/hwspinlock/hwspinlock.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define SPH_SMP  13
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+extern const struct hwspinlock_ops_s g_cxd56_hwspinlock_ops;
+
+struct hwspinlock_dev_s g_atomic_hwspinlock =
+{
+  .id       = SPH_SMP,
+  .priority = 0,
+  .ops      = &g_cxd56_hwspinlock_ops
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
diff --git a/arch/arm/src/cxd56xx/cxd56_sph.c b/arch/arm/src/cxd56xx/cxd56_sph.c
index 5f9d68e33cb..3b3f9bb0acf 100644
--- a/arch/arm/src/cxd56xx/cxd56_sph.c
+++ b/arch/arm/src/cxd56xx/cxd56_sph.c
@@ -270,9 +270,11 @@ int cxd56_sphinitialize(const char *devname)
   int ret;
   int i;
 
-  /* No. 0-2 and (14)-15 semaphores are reserved by other system. */
+  /* No. 0-2 and (13)-15 semaphores are reserved by other system. */
 
-#ifdef CONFIG_CXD56_TESTSET
+#if defined(CONFIG_CXD56_ATOMIC_WITH_HWSEM)
+  for (i = 3; i < 13; i++)
+#elif defined(CONFIG_CXD56_TESTSET_WITH_HWSEM)
   for (i = 3; i < 14; i++)
 #else
   for (i = 3; i < 15; i++)
diff --git a/arch/arm/src/lc823450/Make.defs b/arch/arm/src/lc823450/Make.defs
index d6a60696eef..acff774bee0 100644
--- a/arch/arm/src/lc823450/Make.defs
+++ b/arch/arm/src/lc823450/Make.defs
@@ -124,3 +124,4 @@ endif
 ifeq ($(CONFIG_ARM_MPU),y)
 CHIP_CSRCS += lc823450_mpuinit2.c
 endif
+CHIP_CSRCS += lc823450_atomic.c
diff --git a/arch/arm/src/lc823450/lc823450_atomic.c 
b/arch/arm/src/lc823450/lc823450_atomic.c
new file mode 100644
index 00000000000..14428595272
--- /dev/null
+++ b/arch/arm/src/lc823450/lc823450_atomic.c
@@ -0,0 +1,50 @@
+/****************************************************************************
+ * arch/arm/src/lc823450/lc823450_atomic.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/hwspinlock/hwspinlock.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define LC823450_MUTEX_REG  0
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+extern const struct hwspinlock_ops_s g_lc823450_hwspinlock_ops;
+
+struct hwspinlock_dev_s g_atomic_hwspinlock =
+{
+  .id       = LC823450_MUTEX_REG,
+  .priority = 0,
+  .ops      = &g_lc823450_hwspinlock_ops
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
diff --git a/arch/arm/src/rp2040/Make.defs b/arch/arm/src/rp2040/Make.defs
index 43685810274..f617f2d6d0d 100644
--- a/arch/arm/src/rp2040/Make.defs
+++ b/arch/arm/src/rp2040/Make.defs
@@ -104,3 +104,4 @@ ifneq ($(PICO_SDK_PATH),)
 include chip/boot2/Make.defs
 endif
 endif
+CHIP_CSRCS += rp2040_atomic.c
diff --git a/arch/arm/src/rp2040/rp2040_atomic.c 
b/arch/arm/src/rp2040/rp2040_atomic.c
new file mode 100644
index 00000000000..b1c3f9bf0ff
--- /dev/null
+++ b/arch/arm/src/rp2040/rp2040_atomic.c
@@ -0,0 +1,50 @@
+/****************************************************************************
+ * arch/arm/src/rp2040/rp2040_atomic.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/hwspinlock/hwspinlock.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define RP2040_HWSPINLOCK  0
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+extern const struct hwspinlock_ops_s g_rp2040_hwspinlock_ops;
+
+struct hwspinlock_dev_s g_atomic_hwspinlock =
+{
+  .id       = RP2040_HWSPINLOCK,
+  .priority = 0,
+  .ops      = &g_rp2040_hwspinlock_ops
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/

Reply via email to