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

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

commit e0819ed7d45e9bab9ffeb7b14b925a84b8d6f158
Author: Saravanan Sekar <[email protected]>
AuthorDate: Fri Nov 6 18:43:36 2026 +0530

    arch/tricore: Add the fast ASCLIN clock frequency.
    
    The baud rate depends on the fast ASCLIN clock, which the iLLD UART
    driver reads with IfxScuCcu_getAsclinFFrequency or
    IfxClock_getAsclinFFrequency.  Add tricore_clock_asclinf, which computes
    it the same way from the peripheral PLL and the ASCLINF divider.
    
    Signed-off-by: Saravanan Sekar <[email protected]>
---
 arch/tricore/src/common/tricore_internal.h    |  4 ++
 arch/tricore/src/tc3xx/hardware/tc3xx_clock.h |  1 +
 arch/tricore/src/tc3xx/tc3xx_clockconfig.c    | 50 ++++++++++++++++++++++
 arch/tricore/src/tc4xx/hardware/tc4xx_clock.h |  1 +
 arch/tricore/src/tc4xx/tc4xx_clockconfig.c    | 61 +++++++++++++++++++++++++++
 5 files changed, 117 insertions(+)

diff --git a/arch/tricore/src/common/tricore_internal.h 
b/arch/tricore/src/common/tricore_internal.h
index 352c313d739..e55451dc063 100644
--- a/arch/tricore/src/common/tricore_internal.h
+++ b/arch/tricore/src/common/tricore_internal.h
@@ -205,6 +205,10 @@ int tricore_clockconfig(void);     /* Chip: oscillator, 
PLLs and dividers */
 void tricore_start(void);          /* Start the other cores, enter NuttX */
 void tricore_main(void);           /* Per core entry into NuttX */
 
+/* Clocks *******************************************************************/
+
+uint32_t tricore_clock_asclinf(void);
+
 /* Signal handling **********************************************************/
 
 void tricore_sigdeliver(void);
diff --git a/arch/tricore/src/tc3xx/hardware/tc3xx_clock.h 
b/arch/tricore/src/tc3xx/hardware/tc3xx_clock.h
index a6ed6fed3e7..0ada5a1e704 100644
--- a/arch/tricore/src/tc3xx/hardware/tc3xx_clock.h
+++ b/arch/tricore/src/tc3xx/hardware/tc3xx_clock.h
@@ -72,6 +72,7 @@
 #define TC3XX_CCUCON0_CLKSEL_MASK  (0x3 << 28)
 #define TC3XX_CCUCON0_CLKSEL_PLL   (0x1 << 28)
 #define TC3XX_CCUCON1_CLKSEL_MASK  ((0x3 << 4) | (0x3 << 20) | (0x3 << 28))
+#define TC3XX_CCUCON2_ASCLINFDIV   (0xf << 0)
 #define TC3XX_CCUCON2_CLKSEL_MASK  (0x3 << 12)
 
 #endif /* __ARCH_TRICORE_SRC_TC3XX_HARDWARE_TC3XX_CLOCK_H */
diff --git a/arch/tricore/src/tc3xx/tc3xx_clockconfig.c 
b/arch/tricore/src/tc3xx/tc3xx_clockconfig.c
index 8ffc51b632a..3900d6c1ad6 100644
--- a/arch/tricore/src/tc3xx/tc3xx_clockconfig.c
+++ b/arch/tricore/src/tc3xx/tc3xx_clockconfig.c
@@ -402,6 +402,56 @@ static int tc3xx_pll_ramp_up(void)
  * Public Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: tricore_clock_asclinf
+ *
+ * Description:
+ *   Return the fast ASCLIN clock (fASCLINF) in Hz, from the peripheral PLL
+ *   output 2 and the ASCLINF divider, computed as the iLLD IfxScuCcu does.
+ *
+ ****************************************************************************/
+
+uint32_t tricore_clock_asclinf(void)
+{
+  static const uint8_t divs[16] =
+  {
+    1, 1, 2, 3, 4, 5, 6, 6, 8, 8, 10, 10, 12, 12, 12, 15
+  };
+
+  uint32_t div = getreg32(TC3XX_SCU_CCUCON2) & TC3XX_CCUCON2_ASCLINFDIV;
+  uint32_t con0 = getreg32(TC3XX_SCU_PERPLLCON0);
+  uint32_t con1 = getreg32(TC3XX_SCU_PERPLLCON1);
+  uint64_t pll2;
+
+  if (div == 0)
+    {
+      return 0;
+    }
+
+  /* Backup clock, 100 MHz */
+
+  if ((getreg32(TC3XX_SCU_CCUCON0) & TC3XX_CCUCON0_CLKSEL_MASK) !=
+      TC3XX_CCUCON0_CLKSEL_PLL)
+    {
+      return 100000000 / divs[div];
+    }
+
+  /* The PLL output 2 divider is K3DIV + 1 times 2, or times 1.6 without
+   * DIVBY, counted here in tenths
+   */
+
+  pll2 = ((uint64_t)TC3XX_XTAL_MHZ * 1000000 *
+          (((con0 & TC3XX_PLLCON0_NDIV_MASK) >> TC3XX_PLLCON0_NDIV_SHIFT) +
+           1) * 10) /
+         ((((con0 & TC3XX_PLLCON0_PDIV_MASK) >> TC3XX_PLLCON0_PDIV_SHIFT) +
+           1) *
+          (((con1 & TC3XX_PLLCON1_K3DIV_MASK) >> TC3XX_PLLCON1_K3DIV_SHIFT) +
+           1) *
+          ((con0 & TC3XX_PLLCON0_DIVBY) != 0 ? 20 : 16));
+
+  return pll2 / divs[div];
+}
+
 /****************************************************************************
  * Name: tricore_clockconfig
  *
diff --git a/arch/tricore/src/tc4xx/hardware/tc4xx_clock.h 
b/arch/tricore/src/tc4xx/hardware/tc4xx_clock.h
index ae75ed52aea..37aa47cb13a 100644
--- a/arch/tricore/src/tc4xx/hardware/tc4xx_clock.h
+++ b/arch/tricore/src/tc4xx/hardware/tc4xx_clock.h
@@ -95,5 +95,6 @@
 #define TC4XX_CCU_CLKSELS_RAMP     2
 #define TC4XX_CCU_CLKSELP          (1 << 16)   /* Set: backup clock */
 #define TC4XX_CCUCON_UP            (1 << 30)   /* SYSCCUCON0 and 1 */
+#define TC4XX_PERCCUCON1_ASCLINFDIV (0xf << 0)
 
 #endif /* __ARCH_TRICORE_SRC_TC4XX_HARDWARE_TC4XX_CLOCK_H */
diff --git a/arch/tricore/src/tc4xx/tc4xx_clockconfig.c 
b/arch/tricore/src/tc4xx/tc4xx_clockconfig.c
index 4f2726c7128..cc6d9bd04e4 100644
--- a/arch/tricore/src/tc4xx/tc4xx_clockconfig.c
+++ b/arch/tricore/src/tc4xx/tc4xx_clockconfig.c
@@ -457,6 +457,67 @@ static void tc4xx_osc_power_on(void)
  * Public Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: tricore_clock_asclinf
+ *
+ * Description:
+ *   Return the fast ASCLIN clock (fASCLINF) in Hz, from the peripheral PLL
+ *   output 2 and the ASCLINF divider, computed as the iLLD IfxClock does.
+ *
+ ****************************************************************************/
+
+uint32_t tricore_clock_asclinf(void)
+{
+  static const uint8_t divs[16] =
+  {
+    1, 1, 2, 3, 4, 5, 6, 6, 8, 8, 10, 10, 12, 12, 12, 15
+  };
+
+  /* K3 predivider in tenths */
+
+  static const uint8_t prediv[16] =
+  {
+    10, 11, 12, 10, 14, 10, 16, 17, 10, 10, 20, 10, 10, 10, 10, 10
+  };
+
+  uint32_t div = getreg32(TC4XX_CLOCK_PERCCUCON1) &
+                 TC4XX_PERCCUCON1_ASCLINFDIV;
+  uint32_t con0 = getreg32(TC4XX_CLOCK_PERPLLCON0);
+  uint32_t con1 = getreg32(TC4XX_CLOCK_PERPLLCON1);
+  uint32_t stat = getreg32(TC4XX_CLOCK_PERPLLSTAT);
+  uint64_t pll2;
+
+  if (div == 0)
+    {
+      return 0;
+    }
+
+  /* Backup clock, 100 MHz */
+
+  if ((getreg32(TC4XX_CLOCK_CCUSTAT) & TC4XX_CCU_CLKSELP) != 0)
+    {
+      return 100000000 / divs[div];
+    }
+
+  if ((stat & (TC4XX_PLLSTAT_PLLLOCK | TC4XX_PLLSTAT_PWRSTAT)) !=
+      (TC4XX_PLLSTAT_PLLLOCK | TC4XX_PLLSTAT_PWRSTAT))
+    {
+      return 0;
+    }
+
+  pll2 = ((uint64_t)TC4XX_XTAL_MHZ * 1000000 *
+          (((con0 & TC4XX_PLLCON0_NDIV_MASK) >> TC4XX_PLLCON0_NDIV_SHIFT) +
+           1) * 10) /
+         ((((con0 & TC4XX_PLLCON0_PDIV_MASK) >> TC4XX_PLLCON0_PDIV_SHIFT) +
+           1) *
+          (((con1 & TC4XX_PLLCON1_K3DIV_MASK) >> TC4XX_PLLCON1_K3DIV_SHIFT) +
+           1) *
+          prediv[(con1 & TC4XX_PLLCON1_K3PRE_MASK) >>
+                 TC4XX_PLLCON1_K3PRE_SHIFT]);
+
+  return pll2 / divs[div];
+}
+
 /****************************************************************************
  * Name: tricore_clockconfig
  *

Reply via email to