1 // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <stdint.h> 16 #include <sys/param.h> 17 18 #include "esp_attr.h" 19 #include "soc/rtc.h" 20 #include "esp32/clk.h" 21 22 #define MHZ (1000000) 23 24 // g_ticks_us defined in ROMs for PRO and APP CPU 25 extern uint32_t g_ticks_per_us_pro; 26 #ifndef CONFIG_FREERTOS_UNICORE 27 extern uint32_t g_ticks_per_us_app; 28 #endif 29 esp_clk_cpu_freq(void)30int IRAM_ATTR esp_clk_cpu_freq(void) 31 { 32 return g_ticks_per_us_pro * MHZ; 33 } 34 esp_clk_apb_freq(void)35int IRAM_ATTR esp_clk_apb_freq(void) 36 { 37 return MIN(g_ticks_per_us_pro, 80) * MHZ; 38 } 39 esp_clk_xtal_freq(void)40int IRAM_ATTR esp_clk_xtal_freq(void) 41 { 42 return rtc_clk_xtal_freq_get() * MHZ; 43 } 44 ets_update_cpu_frequency(uint32_t ticks_per_us)45void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us) 46 { 47 /* Update scale factors used by esp_rom_delay_us */ 48 g_ticks_per_us_pro = ticks_per_us; 49 #ifndef CONFIG_FREERTOS_UNICORE 50 g_ticks_per_us_app = ticks_per_us; 51 #endif 52 } 53