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 a141a03dfd9c427112a1c5d3808c79b0512bc8b5
Author: Saravanan Sekar <[email protected]>
AuthorDate: Fri Nov 6 16:29:35 2026 +0530

    arch/tricore: Disable the watchdogs without the iLLD.
    
    core0_main disables the CPU and the safety (TC3xx) or system (TC4xx)
    watchdog through IfxScuWdt or IfxWtu.  Add tricore_wdt_disable for each
    chip family, which does the same with the SCU WDT or WTU registers: read
    the password, clear ENDINIT (TC3xx) or unlock CTRLA (TC4xx), request the
    disable and lock again.
    
    Signed-off-by: Saravanan Sekar <[email protected]>
---
 arch/tricore/src/common/tricore_internal.h  |   4 ++
 arch/tricore/src/common/tricore_main.c      |  14 +---
 arch/tricore/src/tc3xx/CMakeLists.txt       |   2 +-
 arch/tricore/src/tc3xx/Make.defs            |   1 +
 arch/tricore/src/tc3xx/hardware/tc3xx_wdt.h |  48 +++++++++++++
 arch/tricore/src/tc3xx/tc3xx_wdt.c          | 105 ++++++++++++++++++++++++++++
 arch/tricore/src/tc4xx/CMakeLists.txt       |   2 +-
 arch/tricore/src/tc4xx/Make.defs            |   1 +
 arch/tricore/src/tc4xx/hardware/tc4xx_wdt.h |  50 +++++++++++++
 arch/tricore/src/tc4xx/tc4xx_wdt.c          |  94 +++++++++++++++++++++++++
 10 files changed, 306 insertions(+), 15 deletions(-)

diff --git a/arch/tricore/src/common/tricore_internal.h 
b/arch/tricore/src/common/tricore_internal.h
index 11149bfdc5f..957c2654a48 100644
--- a/arch/tricore/src/common/tricore_internal.h
+++ b/arch/tricore/src/common/tricore_internal.h
@@ -192,6 +192,10 @@ extern uintptr_t        _eheap[]; /* End+1 of .heap */
 void tricore_ack_irq(int irq);
 void tricore_doirq(void);
 
+/* Watchdog *****************************************************************/
+
+void tricore_wdt_disable(void);
+
 /* Signal handling **********************************************************/
 
 void tricore_sigdeliver(void);
diff --git a/arch/tricore/src/common/tricore_main.c 
b/arch/tricore/src/common/tricore_main.c
index a297fd84383..151f91f28c9 100644
--- a/arch/tricore/src/common/tricore_main.c
+++ b/arch/tricore/src/common/tricore_main.c
@@ -30,12 +30,6 @@
 #include "Ifx_Types.h"
 #include "IfxCpu.h"
 
-#ifdef CONFIG_ARCH_CHIP_TC4XX
-#  include "IfxWtu.h"
-#else
-#  include "IfxScuWdt.h"
-#endif
-
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -82,13 +76,7 @@ void core0_main(void)
    * to ensure the normal startup of the system.
    */
 
-#if defined(CONFIG_ARCH_CHIP_TC3XX)
-  IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
-  IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
-#elif defined(CONFIG_ARCH_CHIP_TC4XX)
-  IfxWtu_disableCpuWatchdog(IfxWtu_getCpuWatchdogPassword());
-  IfxWtu_disableSystemWatchdog(IfxWtu_getSystemWatchdogPassword());
-#endif
+  tricore_wdt_disable();
 
   core_main();
 }
diff --git a/arch/tricore/src/tc3xx/CMakeLists.txt 
b/arch/tricore/src/tc3xx/CMakeLists.txt
index de36cca455e..110678a96e7 100644
--- a/arch/tricore/src/tc3xx/CMakeLists.txt
+++ b/arch/tricore/src/tc3xx/CMakeLists.txt
@@ -20,7 +20,7 @@
 #
 # 
##############################################################################
 
-set(SRCS tc3xx_timerisr.c tc3xx_serial.c)
+set(SRCS tc3xx_timerisr.c tc3xx_serial.c tc3xx_wdt.c)
 
 target_sources(arch PRIVATE ${SRCS})
 
diff --git a/arch/tricore/src/tc3xx/Make.defs b/arch/tricore/src/tc3xx/Make.defs
index 6f6dc842dff..f72a7759f76 100644
--- a/arch/tricore/src/tc3xx/Make.defs
+++ b/arch/tricore/src/tc3xx/Make.defs
@@ -22,6 +22,7 @@
 
 CHIP_CSRCS += tc3xx_timerisr.c
 CHIP_CSRCS += tc3xx_serial.c
+CHIP_CSRCS += tc3xx_wdt.c
 
 VPATH += tc3xx
 
diff --git a/arch/tricore/src/tc3xx/hardware/tc3xx_wdt.h 
b/arch/tricore/src/tc3xx/hardware/tc3xx_wdt.h
new file mode 100644
index 00000000000..6d3764a1063
--- /dev/null
+++ b/arch/tricore/src/tc3xx/hardware/tc3xx_wdt.h
@@ -0,0 +1,48 @@
+/****************************************************************************
+ * arch/tricore/src/tc3xx/hardware/tc3xx_wdt.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_TRICORE_SRC_TC3XX_HARDWARE_TC3XX_WDT_H
+#define __ARCH_TRICORE_SRC_TC3XX_HARDWARE_TC3XX_WDT_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* SCU watchdog timers: one per CPU and the safety watchdog */
+
+#define TC3XX_SCU_WDTCPU_CON0(n)   (0xf003624c + (n) * 0xc)
+#define TC3XX_SCU_WDTCPU_CON1(n)   (0xf0036250 + (n) * 0xc)
+#define TC3XX_SCU_WDTS_CON0        0xf00362a8
+#define TC3XX_SCU_WDTS_CON1        0xf00362ac
+
+#define TC3XX_WDT_CON0_ENDINIT     (1 << 0)          /* End of init */
+#define TC3XX_WDT_CON0_LCK         (1 << 1)          /* Lock */
+#define TC3XX_WDT_CON0_PW_SHIFT    2                 /* Password */
+#define TC3XX_WDT_CON0_PW_MASK     (0x3fff << TC3XX_WDT_CON0_PW_SHIFT)
+#define TC3XX_WDT_CON0_REL_MASK    (0xffff << 16)    /* Reload value */
+#define TC3XX_WDT_CON1_DR          (1 << 3)          /* Disable request */
+
+/* The low six password bits read inverted */
+
+#define TC3XX_WDT_PW_INVERTED      0x3f
+
+#endif /* __ARCH_TRICORE_SRC_TC3XX_HARDWARE_TC3XX_WDT_H */
diff --git a/arch/tricore/src/tc3xx/tc3xx_wdt.c 
b/arch/tricore/src/tc3xx/tc3xx_wdt.c
new file mode 100644
index 00000000000..d5538028b23
--- /dev/null
+++ b/arch/tricore/src/tc3xx/tc3xx_wdt.c
@@ -0,0 +1,105 @@
+/****************************************************************************
+ * arch/tricore/src/tc3xx/tc3xx_wdt.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/config.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <arch/arch.h>
+
+#include "tricore_internal.h"
+#include "hardware/tc3xx_wdt.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: tc3xx_wdt_endinit
+ *
+ * Description:
+ *   Set or clear ENDINIT of a watchdog with its password, unlocking CON0
+ *   first if it is locked, and wait until ENDINIT has changed.
+ *
+ ****************************************************************************/
+
+static void tc3xx_wdt_endinit(uintptr_t con0, uint32_t pw, bool set)
+{
+  uint32_t regval = getreg32(con0);
+  uint32_t rel = regval & TC3XX_WDT_CON0_REL_MASK;
+
+  pw <<= TC3XX_WDT_CON0_PW_SHIFT;
+  if ((regval & TC3XX_WDT_CON0_LCK) != 0)
+    {
+      putreg32(rel | pw | TC3XX_WDT_CON0_ENDINIT, con0);
+    }
+
+  putreg32(rel | pw | TC3XX_WDT_CON0_LCK |
+           (set ? TC3XX_WDT_CON0_ENDINIT : 0), con0);
+
+  while (((getreg32(con0) & TC3XX_WDT_CON0_ENDINIT) != 0) != set);
+}
+
+/****************************************************************************
+ * Name: tc3xx_wdt_disable
+ *
+ * Description:
+ *   Request a watchdog to be disabled.
+ *
+ ****************************************************************************/
+
+static void tc3xx_wdt_disable(uintptr_t con0, uintptr_t con1)
+{
+  uint32_t pw = ((getreg32(con0) & TC3XX_WDT_CON0_PW_MASK) >>
+                 TC3XX_WDT_CON0_PW_SHIFT) ^ TC3XX_WDT_PW_INVERTED;
+
+  tc3xx_wdt_endinit(con0, pw, false);
+  putreg32(getreg32(con1) | TC3XX_WDT_CON1_DR, con1);
+  tc3xx_wdt_endinit(con0, pw, true);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: tricore_wdt_disable
+ *
+ * Description:
+ *   Disable the watchdog of the calling CPU and the safety watchdog.  CPU5
+ *   has the core ID 6 on TC39x, hence the limit to 5.
+ *
+ ****************************************************************************/
+
+void tricore_wdt_disable(void)
+{
+  uint32_t cpu = tricore_mfcr(TRICORE_CPU_CORE_ID);
+
+  cpu = cpu > 5 ? 5 : cpu;
+  tc3xx_wdt_disable(TC3XX_SCU_WDTCPU_CON0(cpu), TC3XX_SCU_WDTCPU_CON1(cpu));
+  tc3xx_wdt_disable(TC3XX_SCU_WDTS_CON0, TC3XX_SCU_WDTS_CON1);
+}
diff --git a/arch/tricore/src/tc4xx/CMakeLists.txt 
b/arch/tricore/src/tc4xx/CMakeLists.txt
index 2f0db1ce11d..3ea36ddea2c 100644
--- a/arch/tricore/src/tc4xx/CMakeLists.txt
+++ b/arch/tricore/src/tc4xx/CMakeLists.txt
@@ -20,7 +20,7 @@
 #
 # 
##############################################################################
 
-set(SRCS tc4xx_timerisr.c tc4xx_serial.c)
+set(SRCS tc4xx_timerisr.c tc4xx_serial.c tc4xx_wdt.c)
 
 target_sources(arch PRIVATE ${SRCS})
 
diff --git a/arch/tricore/src/tc4xx/Make.defs b/arch/tricore/src/tc4xx/Make.defs
index b278fa3fa82..7ca2ce0a8ac 100644
--- a/arch/tricore/src/tc4xx/Make.defs
+++ b/arch/tricore/src/tc4xx/Make.defs
@@ -22,6 +22,7 @@
 
 CHIP_CSRCS += tc4xx_timerisr.c
 CHIP_CSRCS += tc4xx_serial.c
+CHIP_CSRCS += tc4xx_wdt.c
 
 VPATH += tc4xx
 
diff --git a/arch/tricore/src/tc4xx/hardware/tc4xx_wdt.h 
b/arch/tricore/src/tc4xx/hardware/tc4xx_wdt.h
new file mode 100644
index 00000000000..db0b94c16ff
--- /dev/null
+++ b/arch/tricore/src/tc4xx/hardware/tc4xx_wdt.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+ * arch/tricore/src/tc4xx/hardware/tc4xx_wdt.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_TRICORE_SRC_TC4XX_HARDWARE_TC4XX_WDT_H
+#define __ARCH_TRICORE_SRC_TC4XX_HARDWARE_TC4XX_WDT_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* WTU watchdog timers: one per CPU and the system watchdog */
+
+#define TC4XX_WTU_WDTCPU_CTRLA(n)  (0xf000003c + (n) * 0x30)
+#define TC4XX_WTU_WDTCPU_CTRLB(n)  (0xf0000040 + (n) * 0x30)
+#define TC4XX_WTU_WDTSYS_CTRLA     0xf00001a8
+#define TC4XX_WTU_WDTSYS_CTRLB     0xf00001ac
+#define TC4XX_WTU_STAT_OFFSET      8                 /* From CTRLA */
+
+#define TC4XX_WTU_CTRLA_LCK        (1 << 0)          /* Lock */
+#define TC4XX_WTU_CTRLA_PW_SHIFT   1                 /* Password */
+#define TC4XX_WTU_CTRLA_PW_MASK    (0x7fff << TC4XX_WTU_CTRLA_PW_SHIFT)
+#define TC4XX_WTU_CTRLA_TCVI_SHIFT 16                /* Timer check value */
+#define TC4XX_WTU_CTRLB_DR         (1 << 0)          /* Disable request */
+#define TC4XX_WTU_STAT_TC          (1 << 8)          /* Timer check */
+#define TC4XX_WTU_STAT_TIM_SHIFT   16                /* Timer value */
+
+/* The low seven password bits read inverted */
+
+#define TC4XX_WTU_PW_INVERTED      0x7f
+
+#endif /* __ARCH_TRICORE_SRC_TC4XX_HARDWARE_TC4XX_WDT_H */
diff --git a/arch/tricore/src/tc4xx/tc4xx_wdt.c 
b/arch/tricore/src/tc4xx/tc4xx_wdt.c
new file mode 100644
index 00000000000..87e1cefa534
--- /dev/null
+++ b/arch/tricore/src/tc4xx/tc4xx_wdt.c
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * arch/tricore/src/tc4xx/tc4xx_wdt.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/config.h>
+
+#include <stdint.h>
+
+#include <arch/arch.h>
+
+#include "tricore_internal.h"
+#include "hardware/tc4xx_wdt.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Core index in CORE_ID */
+
+#define TC4XX_CORE_ID_MASK         0x7
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: tc4xx_wdt_disable
+ *
+ * Description:
+ *   Request a watchdog to be disabled: unlock CTRLA with the password if it
+ *   is locked, set the disable request in CTRLB and lock CTRLA again.
+ *
+ ****************************************************************************/
+
+static void tc4xx_wdt_disable(uintptr_t ctrla, uintptr_t ctrlb)
+{
+  uint32_t a = getreg32(ctrla);
+  uint32_t b = getreg32(ctrlb);
+  uint32_t pw = ((a & TC4XX_WTU_CTRLA_PW_MASK) >> TC4XX_WTU_CTRLA_PW_SHIFT) ^
+                TC4XX_WTU_PW_INVERTED;
+
+  if ((a & TC4XX_WTU_CTRLA_LCK) != 0)
+    {
+      a &= ~(TC4XX_WTU_CTRLA_LCK | TC4XX_WTU_CTRLA_PW_MASK);
+      a |= pw << TC4XX_WTU_CTRLA_PW_SHIFT;
+    }
+
+  putreg32(a, ctrla);
+  putreg32(b | TC4XX_WTU_CTRLB_DR, ctrlb);
+  putreg32(a | TC4XX_WTU_CTRLA_LCK, ctrla);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: tricore_wdt_disable
+ *
+ * Description:
+ *   Disable the watchdog of the calling CPU and the system watchdog.
+ *
+ ****************************************************************************/
+
+void tricore_wdt_disable(void)
+{
+  uint32_t cpu = tricore_mfcr(TRICORE_CPU_CORE_ID) & TC4XX_CORE_ID_MASK;
+
+  tc4xx_wdt_disable(TC4XX_WTU_WDTCPU_CTRLA(cpu),
+                    TC4XX_WTU_WDTCPU_CTRLB(cpu));
+  tc4xx_wdt_disable(TC4XX_WTU_WDTSYS_CTRLA, TC4XX_WTU_WDTSYS_CTRLB);
+}

Reply via email to