]> granicus.if.org Git - esp-idf/commitdiff
freertos: deprecate XT_CLOCK_FREQ
authorIvan Grokhotkov <ivan@espressif.com>
Fri, 22 Sep 2017 15:09:16 +0000 (23:09 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Wed, 18 Oct 2017 06:19:19 +0000 (14:19 +0800)
- freertos: add deprecated definition for XT_CLOCK_FREQ
- flash_ops: don't use XT_CLOCK_FREQ
- unity: don't use XT_CLOCK_FREQ
- hw_random: don't use XT_CLOCK_FREQ
- core_dump: don't use XT_CLOCK_FREQ
- app_trace: don't use XT_CLOCK_FREQ
- xtensa_init: init xt_tick_divisor

components/app_trace/app_trace.c
components/app_trace/app_trace_util.c
components/app_trace/test/test_trace.c
components/esp32/core_dump.c
components/esp32/hw_random.c
components/freertos/include/freertos/FreeRTOSConfig.h
components/freertos/xtensa_init.c
components/spi_flash/flash_ops.c
tools/unit-test-app/components/unity/unity_platform.c

index c46f71b5afe9c655f22023f31d5661d1442d39e7..1e792dd862681ff8250ab04ce7f5e5685596c84d 100644 (file)
@@ -203,8 +203,6 @@ const static char *TAG = "esp_apptrace";
 #define ESP_APPTRACE_LOGV( format, ... )  ESP_APPTRACE_LOG_LEV(V, ESP_LOG_VERBOSE, format, ##__VA_ARGS__)
 #define ESP_APPTRACE_LOGO( format, ... )  ESP_APPTRACE_LOG_LEV(E, ESP_LOG_NONE, format, ##__VA_ARGS__)
 
-#define ESP_APPTRACE_CPUTICKS2US(_t_)       ((_t_)/(XT_CLOCK_FREQ/1000000))
-
 // TODO: move these (and same definitions in trax.c to dport_reg.h)
 #define TRACEMEM_MUX_PROBLK0_APPBLK1            0
 #define TRACEMEM_MUX_BLK0_ONLY                  1
index 2af3cd4d9e8cd09d2d13db09efe2a130ab74644b..da0a8d58a448697e4d325eae2fa158ced5c34362 100644 (file)
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "esp_app_trace_util.h"
+#include "esp_clk.h"
 
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////// TIMEOUT /////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 
-// TODO: get actual clock from PLL config
-#define ESP_APPTRACE_CPUTICKS2US(_t_)       ((_t_)/(XT_CLOCK_FREQ/1000000))
-#define ESP_APPTRACE_US2CPUTICKS(_t_)       ((_t_)*(XT_CLOCK_FREQ/1000000))
+#define ESP_APPTRACE_CPUTICKS2US(_t_, _cpu_freq_)       ((_t_)/(_cpu_freq_/1000000))
+#define ESP_APPTRACE_US2CPUTICKS(_t_, _cpu_freq_)       ((_t_)*(_cpu_freq_/1000000))
 
 esp_err_t esp_apptrace_tmo_check(esp_apptrace_tmo_t *tmo)
 {
+    int cpu_freq = esp_clk_cpu_freq();
     if (tmo->tmo != ESP_APPTRACE_TMO_INFINITE) {
         unsigned cur = portGET_RUN_TIME_COUNTER_VALUE();
         if (tmo->start <= cur) {
-            tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(cur - tmo->start);
+            tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(cur - tmo->start, cpu_freq);
         } else {
-            tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(0xFFFFFFFF - tmo->start + cur);
+            tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(0xFFFFFFFF - tmo->start + cur, cpu_freq);
         }
         if (tmo->elapsed >= tmo->tmo) {
             return ESP_ERR_TIMEOUT;
index e92b6ffc6a330cea90491a9c6cb8d0557693356c..6846ea50a26ea0e9b23023f3c82cc1e9690bbe25 100644 (file)
@@ -87,8 +87,6 @@ static void esp_apptrace_test_timer_init(int timer_group, int timer_idx, uint32_
 #define ESP_APPTRACE_TEST_WRITE_FROM_ISR(_b_, _s_)   esp_apptrace_write(ESP_APPTRACE_DEST_TRAX, _b_, _s_, 0UL)
 #define ESP_APPTRACE_TEST_WRITE_NOWAIT(_b_, _s_)     esp_apptrace_write(ESP_APPTRACE_DEST_TRAX, _b_, _s_, 0)
 
-#define ESP_APPTRACE_TEST_CPUTICKS2US(_t_)       ((_t_)/(XT_CLOCK_FREQ/1000000))
-
 typedef struct {
     uint8_t *buf;
     uint32_t buf_sz;
index 12f63a4420bf093f8966214b6a37c00b7c2fc82f..56ce08b64a744d3927ef9aaa1ce7e47ef9044f1f 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "esp_panic.h"
 #include "esp_partition.h"
+#include "esp_clk.h"
 
 #if CONFIG_ESP32_ENABLE_COREDUMP
 #define LOG_LOCAL_LEVEL CONFIG_ESP32_CORE_DUMP_LOG_LEVEL
@@ -522,10 +523,11 @@ void esp_core_dump_to_uart(XtExcFrame *frame)
     PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_U0TXD);
 
     ESP_COREDUMP_LOGI("Press Enter to print core dump to UART...");
-    tm_end = xthal_get_ccount() / (XT_CLOCK_FREQ / 1000) + CONFIG_ESP32_CORE_DUMP_UART_DELAY;
+    const int cpu_ticks_per_ms = esp_clk_cpu_freq() / 1000;
+    tm_end = xthal_get_ccount() / cpu_ticks_per_ms + CONFIG_ESP32_CORE_DUMP_UART_DELAY;
     ch = esp_core_dump_uart_get_char();
     while (!(ch == '\n' || ch == '\r')) {
-        tm_cur = xthal_get_ccount() / (XT_CLOCK_FREQ / 1000);
+        tm_cur = xthal_get_ccount() / cpu_ticks_per_ms;
         if (tm_cur >= tm_end)
             break;
         ch = esp_core_dump_uart_get_char();
index 4f63ecd989921f3fe7153a6daa72644ad0081d2d..78ad542fc2637d385c8e3b51586669a172273667 100644 (file)
@@ -17,6 +17,7 @@
 #include <stddef.h>
 #include <string.h>
 #include "esp_attr.h"
+#include "esp_clk.h"
 #include "soc/wdev_reg.h"
 #include "freertos/FreeRTOSConfig.h"
 #include "xtensa/core-macros.h"
@@ -35,13 +36,21 @@ uint32_t IRAM_ATTR esp_random(void)
      * WDEV_RND_REG reads while waiting.
      */
 
+    /* This code does not run in a critical section, so CPU frequency switch may
+     * happens while this code runs (this will not happen in the current
+     * implementation, but possible in the future). However if that happens,
+     * the number of cycles spent on frequency switching will certainly be more
+     * than the number of cycles we need to wait here.
+     */
+    uint32_t cpu_to_apb_freq_ratio = esp_clk_cpu_freq() / esp_clk_apb_freq();
+
     static uint32_t last_ccount = 0;
     uint32_t ccount;
     uint32_t result = 0;
     do {
         ccount = XTHAL_GET_CCOUNT();
         result ^= REG_READ(WDEV_RND_REG);
-    } while (ccount - last_ccount < XT_CLOCK_FREQ / APB_CLK_FREQ * 16);
+    } while (ccount - last_ccount < cpu_to_apb_freq_ratio * 16);
     last_ccount = ccount;
     return result ^ REG_READ(WDEV_RND_REG);
 }
index 3ccd3fda695f3032a24f44185caad6ae005545f4..f830a452099d1a07ebd04e465e95bf3b9986fc06 100644 (file)
 #define configNUM_THREAD_LOCAL_STORAGE_POINTERS CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS
 #define configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS 1
 
-/* TODO: config freq by menuconfig */
-#define XT_CLOCK_FREQ (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000)
+#ifndef __ASSEMBLER__
+
+/**
+ * This function is defined to provide a deprecation warning whenever
+ * XT_CLOCK_FREQ macro is used.
+ * Update the code to use esp_clk_cpu_freq function instead.
+ * @return current CPU clock frequency, in Hz
+ */
+int xt_clock_freq(void) __attribute__((deprecated));
+
+#define XT_CLOCK_FREQ   (xt_clock_freq())
+
+#endif // __ASSEMBLER__
+
 
 /* Required for configuration-dependent settings */
 #include "xtensa_config.h"
index ded8df109835a8d1914de375e5f7f1134e80fe2e..624f242b1e6357812eda7375b33b970802b25749 100644 (file)
@@ -34,31 +34,21 @@ that are implemented in C.
 #endif
 
 #include    "xtensa_rtos.h"
+#include    "esp_clk.h"
 
 #ifdef XT_RTOS_TIMER_INT
 
 unsigned _xt_tick_divisor = 0;  /* cached number of cycles per tick */
 
-/*
-Compute and initialize at run-time the tick divisor (the number of 
-processor clock cycles in an RTOS tick, used to set the tick timer).
-Called when the processor clock frequency is not known at compile-time.
-*/
 void _xt_tick_divisor_init(void)
 {
-#ifdef XT_CLOCK_FREQ
-
-    _xt_tick_divisor = (XT_CLOCK_FREQ / XT_TICK_PER_SEC);
-
-#else
-
-    #ifdef XT_BOARD
-    _xt_tick_divisor = xtbsp_clock_freq_hz() / XT_TICK_PER_SEC;
-    #else
-    #error "No way to obtain processor clock frequency"
-    #endif  /* XT_BOARD */
+    _xt_tick_divisor = esp_clk_cpu_freq() / XT_TICK_PER_SEC;
+}
 
-#endif /* XT_CLOCK_FREQ */
+/* Deprecated, to be removed */
+int xt_clock_freq(void)
+{
+    return esp_clk_cpu_freq();
 }
 
 #endif /* XT_RTOS_TIMER_INT */
index afb8f407be40e760ba6f68e8e5882b2834200296..2302bf1d40607d237d263f026383e43fca4f1318 100644 (file)
@@ -49,7 +49,7 @@ static spi_flash_counters_t s_flash_stats;
 #define COUNTER_STOP(counter)  \
     do{ \
         s_flash_stats.counter.count++; \
-        s_flash_stats.counter.time += (xthal_get_ccount() - ts_begin) / (XT_CLOCK_FREQ / 1000000); \
+        s_flash_stats.counter.time += (xthal_get_ccount() - ts_begin) / (esp_clk_cpu_freq() / 1000000); \
     } while(0)
 
 #define COUNTER_ADD_BYTES(counter, size) \
index 8e73fd525738b8e32d7b43025131231e8c1c2934..2eeb66048bb5b81c890aa82b16d387d158edcf57 100644 (file)
@@ -8,6 +8,7 @@
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "esp_log.h"
+#include "esp_clk.h"
 #include "soc/cpu.h"
 #include "esp_heap_caps.h"
 #include "test_utils.h"
@@ -150,7 +151,7 @@ static void unity_run_single_test_by_index_parse(const char* filter, int index_m
         unity_run_single_test_by_index(test_index - 1);
         uint32_t end;
         RSR(CCOUNT, end);
-        uint32_t ms = (end - start) / (XT_CLOCK_FREQ / 1000);
+        uint32_t ms = (end - start) / (esp_clk_cpu_freq() / 1000);
         printf("Test ran in %dms\n", ms);
     }
 }