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 51efd9c1351039172fd39a20712a56b4e56ed080
Author: Saravanan Sekar <[email protected]>
AuthorDate: Fri Nov 6 19:37:18 2026 +0530

    arch/tricore: Synchronize the cores at startup without the iLLD.
    
    core_main uses IfxCpu_emitEvent, IfxCpu_waitEvent and
    IfxCpu_getCoreIndex to wait for the other cores before NuttX starts.
    Do the same natively: set the bit of the core with imask and ldmst, and
    wait for the cores and with the timeout that IfxCpu used, all cores with
    1 ms on TC3xx and only CPU0 on TC4xx, as given in the chip.h of each family.
    
    Signed-off-by: Saravanan Sekar <[email protected]>
---
 arch/tricore/src/common/tricore_main.c | 63 +++++++++++++++++++++++++++-------
 arch/tricore/src/tc3xx/chip.h          | 17 +++++++++
 arch/tricore/src/tc4xx/chip.h          | 16 +++++++++
 3 files changed, 84 insertions(+), 12 deletions(-)

diff --git a/arch/tricore/src/common/tricore_main.c 
b/arch/tricore/src/common/tricore_main.c
index f604026c42b..c38d07c02f5 100644
--- a/arch/tricore/src/common/tricore_main.c
+++ b/arch/tricore/src/common/tricore_main.c
@@ -24,19 +24,64 @@
  * Included Files
  ****************************************************************************/
 
-#include <tricore_internal.h>
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
 #include <nuttx/init.h>
 
-#include "Ifx_Types.h"
-#include "IfxCpu.h"
+#include <arch/arch.h>
+
+#include "tricore_internal.h"
+#include "tricore_stm.h"
+#include "chip.h"
 
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: tricore_core_sync
+ *
+ * Description:
+ *   Set the bit of this core in the sync word, atomically for the other
+ *   cores, and wait until the bits of TRICORE_CORE_SYNC_MASK are set or the
+ *   timeout on the STM of CPU0 has passed.
+ *
+ ****************************************************************************/
+
+static void tricore_core_sync(volatile uint32_t *sync)
+{
+  uint32_t core = tricore_core_id();
+#if TRICORE_CORE_SYNC_TIMEOUT > 0
+  uint32_t start = getreg32(TRICORE_STM0_BASE + TRICORE_STM_TIM0_OFFSET);
+#endif
+
+#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING
+  __imaskldmst((unsigned int *)sync, 1, core, 1);
+#else
+  long long tmp;
+
+  __asm__ __volatile__ ("imask %A0, %1, %2, 1\n\t"
+                    "ldmst [%3]0, %A0"
+                    : "=&d"(tmp) : "d"(1), "d"(core), "a"(sync) : "memory");
+#endif
+
+  while ((*sync & TRICORE_CORE_SYNC_MASK) != TRICORE_CORE_SYNC_MASK)
+    {
+#if TRICORE_CORE_SYNC_TIMEOUT > 0
+      if (getreg32(TRICORE_STM0_BASE + TRICORE_STM_TIM0_OFFSET) - start >=
+          TRICORE_CORE_SYNC_TIMEOUT)
+        {
+          break;
+        }
+#endif
+    }
+}
+
 static void core_main(void)
 {
-  static IfxCpu_syncEvent g_sync_event = 0;
+  static volatile uint32_t g_sync_event;
 
 #ifdef CONFIG_ARCH_HAVE_FPU
   tricore_fpuinit();
@@ -52,15 +97,9 @@ static void core_main(void)
 
   /* Wait for CPU sync event */
 
-  IfxCpu_emitEvent(&g_sync_event);
-
-#if defined(CONFIG_ARCH_CHIP_TC3XX)
-  IfxCpu_waitEvent(&g_sync_event, 1);
-#else
-  IfxCpu_waitEvent(&g_sync_event, UINT32_MAX, 1);
-#endif
+  tricore_core_sync(&g_sync_event);
 
-  if (IfxCpu_getCoreIndex() == 0)
+  if (tricore_core_index() == 0)
     {
       tricore_earlyserialinit();
 #ifdef CONFIG_BUILD_PROTECTED
diff --git a/arch/tricore/src/tc3xx/chip.h b/arch/tricore/src/tc3xx/chip.h
index 5ffe3875d6a..7bbbe95cf1d 100644
--- a/arch/tricore/src/tc3xx/chip.h
+++ b/arch/tricore/src/tc3xx/chip.h
@@ -30,4 +30,21 @@
 #define UART_PIN_RX IfxAsclin0_RXA_P14_1_IN     /* UART receive port pin  */
 #define UART_PIN_TX IfxAsclin0_TX_P14_0_OUT     /* UART transmit port pin */
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Startup core synchronization: core ID bits to wait for and the timeout
+ * in STM ticks (0: no timeout)
+ */
+
+#define TRICORE_CORE_SYNC_MASK     0x5f
+#define TRICORE_CORE_SYNC_TIMEOUT  100000
+
+/* Core index from CORE_ID; CPU5 has the core ID 6 on TC39x */
+
+#define tricore_core_id()          tricore_mfcr(TRICORE_CPU_CORE_ID)
+#define tricore_core_index()       (tricore_core_id() > 5 ? 5 : \
+                                    tricore_core_id())
+
 #endif /* __ARCH_TRICORE_SRC_TC3XX_CHIP_H */
diff --git a/arch/tricore/src/tc4xx/chip.h b/arch/tricore/src/tc4xx/chip.h
index 7d3d255ad69..b0fa63f02a2 100644
--- a/arch/tricore/src/tc4xx/chip.h
+++ b/arch/tricore/src/tc4xx/chip.h
@@ -30,4 +30,20 @@
 #define UART_PIN_RX IfxAsclin0_RXA_F_P14_1_IN     /* UART receive port pin  */
 #define UART_PIN_TX IfxAsclin0_TX_F_P14_0_OUT     /* UART transmit port pin */
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Startup core synchronization: core ID bits to wait for and the timeout
+ * in STM ticks (0: no timeout)
+ */
+
+#define TRICORE_CORE_SYNC_MASK     0x01
+#define TRICORE_CORE_SYNC_TIMEOUT  0
+
+/* Core index from CORE_ID */
+
+#define tricore_core_id()          (tricore_mfcr(TRICORE_CPU_CORE_ID) & 0x7)
+#define tricore_core_index()       tricore_core_id()
+
 #endif /* __ARCH_TRICORE_SRC_TC4XX_CHIP_H */

Reply via email to