1 /*
2  * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <assert.h>
8 #include "esp_log_private.h"
9 #include "esp_rom_sys.h"
10 #include "esp_cpu.h"
11 
12 static int s_lock = 0;
13 
esp_log_impl_lock(void)14 void esp_log_impl_lock(void)
15 {
16     assert(s_lock == 0);
17     s_lock = 1;
18 }
19 
esp_log_impl_lock_timeout(void)20 bool esp_log_impl_lock_timeout(void)
21 {
22     esp_log_impl_lock();
23     return true;
24 }
25 
esp_log_impl_unlock(void)26 void esp_log_impl_unlock(void)
27 {
28     assert(s_lock == 1);
29     s_lock = 0;
30 }
31 
32 /* FIXME: define an API for getting the timestamp in soc/hal IDF-2351 */
esp_log_early_timestamp(void)33 uint32_t esp_log_early_timestamp(void)
34 {
35     return esp_cpu_get_cycle_count() / (esp_rom_get_cpu_ticks_per_us() * 1000);
36 }
37 
38 uint32_t esp_log_timestamp(void) __attribute__((alias("esp_log_early_timestamp")));
39