• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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 #include <assert.h>
16 #include "esp_log_private.h"
17 #include "hal/cpu_hal.h"  // for cpu_hal_get_cycle_count()
18 
19 static int s_lock = 0;
20 
esp_log_impl_lock(void)21 void esp_log_impl_lock(void)
22 {
23     assert(s_lock == 0);
24     s_lock = 1;
25 }
26 
esp_log_lock_impl_timeout(void)27 bool esp_log_lock_impl_timeout(void)
28 {
29     esp_log_impl_lock();
30     return true;
31 }
32 
esp_log_impl_unlock(void)33 void esp_log_impl_unlock(void)
34 {
35     assert(s_lock == 1);
36     s_lock = 0;
37 }
38 
39 /* FIXME: define an API for getting the timestamp in soc/hal IDF-2351 */
esp_log_early_timestamp(void)40 uint32_t esp_log_early_timestamp(void)
41 {
42     extern uint32_t ets_get_cpu_frequency(void);
43     return cpu_hal_get_cycle_count() / (ets_get_cpu_frequency() * 1000);
44 }
45 
46 uint32_t esp_log_timestamp(void) __attribute__((alias("esp_log_early_timestamp")));
47