• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015-2018 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 
17 #include <stdint.h>
18 #include <stdbool.h>
19 
20 #define MHZ (1000000)
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 void rtc_clk_cpu_freq_to_xtal(int freq, int div);
27 
28 /* Values of RTC_XTAL_FREQ_REG and RTC_APB_FREQ_REG are stored as two copies in
29  * lower and upper 16-bit halves. These are the routines to work with such a
30  * representation.
31  */
clk_val_is_valid(uint32_t val)32 static inline bool clk_val_is_valid(uint32_t val) {
33     return (val & 0xffff) == ((val >> 16) & 0xffff) &&
34             val != 0 &&
35             val != UINT32_MAX;
36 }
37 
reg_val_to_clk_val(uint32_t val)38 static inline uint32_t reg_val_to_clk_val(uint32_t val) {
39     return val & UINT16_MAX;
40 }
41 
clk_val_to_reg_val(uint32_t val)42 static inline uint32_t clk_val_to_reg_val(uint32_t val) {
43     return (val & UINT16_MAX) | ((val & UINT16_MAX) << 16);
44 }
45 
46 #ifdef __cplusplus
47 }
48 #endif
49