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 
10 #ifdef __ZEPHYR__
11 #include <zephyr/kernel.h>
12 #endif
13 #include "hal/cpu_hal.h"
14 
15 static int s_lock = 0;
16 
esp_log_impl_lock(void)17 void esp_log_impl_lock(void)
18 {
19     assert(s_lock == 0);
20     s_lock = 1;
21 }
22 
esp_log_impl_lock_timeout(void)23 bool esp_log_impl_lock_timeout(void)
24 {
25     esp_log_impl_lock();
26     return true;
27 }
28 
esp_log_impl_unlock(void)29 void esp_log_impl_unlock(void)
30 {
31     assert(s_lock == 1);
32     s_lock = 0;
33 }
34 
35 /* FIXME: define an API for getting the timestamp in soc/hal IDF-2351 */
esp_log_early_timestamp(void)36 uint32_t esp_log_early_timestamp(void)
37 {
38     extern uint32_t ets_get_cpu_frequency(void);
39     return cpu_hal_get_cycle_count() / (ets_get_cpu_frequency() * 1000);
40 }
41 
42 uint32_t esp_log_timestamp(void) __attribute__((alias("esp_log_early_timestamp")));
43