You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/08/20 14:36:39 UTC

[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #1613: xtensa/esp32: Add functions to switch CPU frequency from 80MHz to 240Mhz

Ouss4 commented on a change in pull request #1613:
URL: https://github.com/apache/incubator-nuttx/pull/1613#discussion_r474031523



##########
File path: arch/xtensa/src/esp32/esp32_clockconfig.c
##########
@@ -31,34 +31,291 @@
 #include <stdint.h>
 #include "xtensa.h"
 
-#ifndef CONFIG_SUPPRESS_CLOCK_CONFIG
-#warning REVISIT ... function prototypes
-
-void phy_get_romfunc_addr(void);
-void rtc_init_lite(void);
-void rtc_set_cpu_freq(xtal_freq_t xtal_freq, enum xtal_freq_e cpu_freq);
-#endif
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_soc.h"
 
 /****************************************************************************
  * Private Types
  ****************************************************************************/
 
-#ifndef CONFIG_SUPPRESS_CLOCK_CONFIG
-enum xtal_freq_e
+enum xtal_freq_t

Review comment:
       ```suggestion
   enum xtal_freq_e
   ```

##########
File path: arch/xtensa/src/esp32/esp32_clockconfig.c
##########
@@ -31,34 +31,291 @@
 #include <stdint.h>
 #include "xtensa.h"
 
-#ifndef CONFIG_SUPPRESS_CLOCK_CONFIG
-#warning REVISIT ... function prototypes
-
-void phy_get_romfunc_addr(void);
-void rtc_init_lite(void);
-void rtc_set_cpu_freq(xtal_freq_t xtal_freq, enum xtal_freq_e cpu_freq);
-#endif
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_soc.h"
 
 /****************************************************************************
  * Private Types
  ****************************************************************************/
 
-#ifndef CONFIG_SUPPRESS_CLOCK_CONFIG
-enum xtal_freq_e
+enum xtal_freq_t
 {
   XTAL_40M = 40,
   XTAL_26M = 26,
   XTAL_24M = 24,
   XTAL_AUTO = 0
 };
 
-enum xtal_freq_e
+enum cpu_freq_t
 {
-  CPU_80M = 1,
-  CPU_160M = 2,
-  CPU_240M = 3,
+  CPU_80M = 0,
+  CPU_160M = 1,
+  CPU_240M = 2,
 };
-#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_set_cpu_freq
+ *
+ * Description:
+ *   Switch to one of PLL-based frequencies.
+ *   Current frequency can be XTAL or PLL.
+ *
+ * Input Parameters:
+ *   cpu_freq_mhz      - new CPU frequency
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static void esp32_set_cpu_freq(int cpu_freq_mhz)
+{
+  int dbias = DIG_DBIAS_80M_160M;
+  int per_conf;
+  uint32_t  value;
+
+  switch (cpu_freq_mhz)
+    {
+      case 160:
+        per_conf = CPU_160M;
+        break;
+      case 240:
+        dbias = DIG_DBIAS_240M;
+        per_conf = CPU_240M;
+        break;
+      case 80:
+        per_conf = CPU_80M;
+      default:
+        break;
+    }
+
+  value = (((80 * MHZ) >> 12) & UINT16_MAX)
+          | ((((80 * MHZ) >> 12) & UINT16_MAX) << 16);
+  putreg32(value, RTC_APB_FREQ_REG);
+  putreg32(per_conf, DPORT_CPU_PER_CONF_REG);
+  REG_SET_FIELD(RTC_CNTL_REG, RTC_CNTL_DIG_DBIAS_WAK, dbias);
+  REG_SET_FIELD(RTC_CNTL_CLK_CONF_REG, RTC_CNTL_SOC_CLK_SEL,
+                RTC_CNTL_SOC_CLK_SEL_PLL);
+}
+
+/****************************************************************************
+ * Name: esp32_bbpll_configure
+ *
+ * Description:
+ *   Configure main XTAL frequency values according to pll_freq.
+ *
+ * Input Parameters:
+ *   xtal_freq -    XTAL frequency values
+ *   pll_freq  -    PLL frequency values
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static void esp32_bbpll_configure(enum xtal_freq_t xtal_freq, int pll_freq)

Review comment:
       ```suggestion
   static void esp32_bbpll_configure(enum xtal_freq_e xtal_freq, int pll_freq)
   ```

##########
File path: arch/xtensa/src/esp32/esp32_clockconfig.c
##########
@@ -31,34 +31,291 @@
 #include <stdint.h>
 #include "xtensa.h"
 
-#ifndef CONFIG_SUPPRESS_CLOCK_CONFIG
-#warning REVISIT ... function prototypes
-
-void phy_get_romfunc_addr(void);
-void rtc_init_lite(void);
-void rtc_set_cpu_freq(xtal_freq_t xtal_freq, enum xtal_freq_e cpu_freq);
-#endif
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_soc.h"
 
 /****************************************************************************
  * Private Types
  ****************************************************************************/
 
-#ifndef CONFIG_SUPPRESS_CLOCK_CONFIG
-enum xtal_freq_e
+enum xtal_freq_t
 {
   XTAL_40M = 40,
   XTAL_26M = 26,
   XTAL_24M = 24,
   XTAL_AUTO = 0
 };
 
-enum xtal_freq_e
+enum cpu_freq_t

Review comment:
       ```suggestion
   enum cpu_freq_e
   ```

##########
File path: arch/xtensa/src/esp32/esp32_clockconfig.c
##########
@@ -76,40 +333,29 @@ enum xtal_freq_e
 
 void esp32_clockconfig(void)
 {
-#ifdef CONFIG_SUPPRESS_CLOCK_CONFIG
-#  warning WARNING: Clock configuration disabled
-#else
   uint32_t freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ;
-  enum xtal_freq_e freq;
-
-  phy_get_romfunc_addr();
-
-  /* Frequency will be changed to 40MHz in rtc_init_lite */
-
-  rtc_init_lite();
+  uint32_t source_freq_mhz;
+  enum xtal_freq_t xtal_freq = XTAL_40M;
+  enum cpu_freq_t freq;

Review comment:
       ```suggestion
     enum cpu_freq_e freq;
   ```

##########
File path: arch/xtensa/src/esp32/esp32_clockconfig.c
##########
@@ -76,40 +333,29 @@ enum xtal_freq_e
 
 void esp32_clockconfig(void)
 {
-#ifdef CONFIG_SUPPRESS_CLOCK_CONFIG
-#  warning WARNING: Clock configuration disabled
-#else
   uint32_t freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ;
-  enum xtal_freq_e freq;
-
-  phy_get_romfunc_addr();
-
-  /* Frequency will be changed to 40MHz in rtc_init_lite */
-
-  rtc_init_lite();
+  uint32_t source_freq_mhz;
+  enum xtal_freq_t xtal_freq = XTAL_40M;

Review comment:
       ```suggestion
     enum xtal_freq_e xtal_freq = XTAL_40M;
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org