| 
									
										
										
										
											2017-04-24 18:36:47 +08:00
										 |  |  | // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  | // you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  | // You may obtain a copy of the License at
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Unless required by applicable law or agreed to in writing, software
 | 
					
						
							|  |  |  | // distributed under the License is distributed on an "AS IS" BASIS,
 | 
					
						
							|  |  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					
						
							|  |  |  | // See the License for the specific language governing permissions and
 | 
					
						
							|  |  |  | // limitations under the License.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdint.h>
 | 
					
						
							| 
									
										
										
										
											2017-09-22 23:04:16 +08:00
										 |  |  | #include <sys/param.h>
 | 
					
						
							| 
									
										
										
										
											2020-01-31 18:21:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-24 18:36:47 +08:00
										 |  |  | #include "esp_attr.h"
 | 
					
						
							|  |  |  | #include "soc/rtc.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-31 18:21:18 +08:00
										 |  |  | #include "esp32/clk.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-10 19:23:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-13 17:34:43 +08:00
										 |  |  | #define MHZ (1000000)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-22 23:04:16 +08:00
										 |  |  | // g_ticks_us defined in ROMs for PRO and APP CPU
 | 
					
						
							|  |  |  | extern uint32_t g_ticks_per_us_pro; | 
					
						
							| 
									
										
										
										
											2018-09-19 13:46:59 +08:00
										 |  |  | #ifndef CONFIG_FREERTOS_UNICORE
 | 
					
						
							| 
									
										
										
										
											2017-09-22 23:04:16 +08:00
										 |  |  | extern uint32_t g_ticks_per_us_app; | 
					
						
							| 
									
										
										
										
											2018-09-19 13:46:59 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-09-22 23:04:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | int IRAM_ATTR esp_clk_cpu_freq(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-29 09:34:49 +03:00
										 |  |  |     return g_ticks_per_us_pro * MHZ; | 
					
						
							| 
									
										
										
										
											2017-09-22 23:04:16 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int IRAM_ATTR esp_clk_apb_freq(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-29 09:34:49 +03:00
										 |  |  |     return MIN(g_ticks_per_us_pro, 80) * MHZ; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int IRAM_ATTR esp_clk_xtal_freq(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return rtc_clk_xtal_freq_get() * MHZ; | 
					
						
							| 
									
										
										
										
											2017-09-22 23:04:16 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-24 18:36:47 +08:00
										 |  |  | void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-21 13:07:34 +08:00
										 |  |  |     /* Update scale factors used by esp_rom_delay_us */ | 
					
						
							| 
									
										
										
										
											2017-04-24 18:36:47 +08:00
										 |  |  |     g_ticks_per_us_pro = ticks_per_us; | 
					
						
							| 
									
										
										
										
											2018-09-19 13:46:59 +08:00
										 |  |  | #ifndef CONFIG_FREERTOS_UNICORE
 | 
					
						
							| 
									
										
										
										
											2017-04-24 18:36:47 +08:00
										 |  |  |     g_ticks_per_us_app = ticks_per_us; | 
					
						
							| 
									
										
										
										
											2018-09-19 13:46:59 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-04-24 18:36:47 +08:00
										 |  |  | } |