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 #pragma once 16 #include <stdint.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 /** 23 * @file esp_clk.h 24 * 25 * This file contains declarations of clock related functions. 26 */ 27 28 /** 29 * @brief Get the calibration value of RTC slow clock 30 * 31 * The value is in the same format as returned by rtc_clk_cal (microseconds, 32 * in Q13.19 fixed-point format). 33 * 34 * @return the calibration value obtained using rtc_clk_cal, at startup time 35 */ 36 uint32_t esp_clk_slowclk_cal_get(void); 37 38 /** 39 * @brief Update the calibration value of RTC slow clock 40 * 41 * The value has to be in the same format as returned by rtc_clk_cal (microseconds, 42 * in Q13.19 fixed-point format). 43 * This value is used by timekeeping functions (such as gettimeofday) to 44 * calculate current time based on RTC counter value. 45 * @param value calibration value obtained using rtc_clk_cal 46 */ 47 void esp_clk_slowclk_cal_set(uint32_t value); 48 49 /** 50 * @brief Return current CPU clock frequency 51 * When frequency switching is performed, this frequency may change. 52 * However it is guaranteed that the frequency never changes with a critical 53 * section. 54 * 55 * @return CPU clock frequency, in Hz 56 */ 57 int esp_clk_cpu_freq(void); 58 59 /** 60 * @brief Return current APB clock frequency 61 * 62 * When frequency switching is performed, this frequency may change. 63 * However it is guaranteed that the frequency never changes with a critical 64 * section. 65 * 66 * @return APB clock frequency, in Hz 67 */ 68 int esp_clk_apb_freq(void); 69 70 71 /** 72 * @brief Read value of RTC counter, converting it to microseconds 73 * @attention The value returned by this function may change abruptly when 74 * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set 75 * function. This should not happen unless application calls esp_clk_slowclk_cal_set. 76 * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code. 77 * 78 * @return Value or RTC counter, expressed in microseconds 79 */ 80 uint64_t esp_clk_rtc_time(void); 81 82 #ifdef __cplusplus 83 } 84 #endif 85