• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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 /**
18  * @file private_include/esp_timer_impl.h
19  *
20  * @brief Interface between common and platform-specific parts of esp_timer.
21  *
22  * The functions in this header file are implemented for each supported SoC.
23  * High level functions defined in esp_timer.c call the functions here to
24  * interact with the hardware.
25  */
26 
27 #include <stdint.h>
28 #include "esp_err.h"
29 #include "esp_intr_alloc.h"
30 
31 /**
32  * @brief Initialize platform specific layer of esp_timer
33  * @param alarm_handler function to call on timer interrupt
34  * @return ESP_OK, ESP_ERR_NO_MEM, or one of the errors from interrupt allocator
35  */
36 esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler);
37 
38 /**
39  * @brief Deinitialize platform specific layer of esp_timer
40  */
41 void esp_timer_impl_deinit(void);
42 
43 /**
44  * @brief Set up the timer interrupt to fire at a particular time
45  *
46  * If the alarm time is too close in the future, implementation should set the
47  * alarm to the earliest time possible.
48  *
49  * @param timestamp time in microseconds when interrupt should fire (relative to
50  *                  boot time, i.e. as returned by esp_timer_impl_get_time)
51  */
52 void esp_timer_impl_set_alarm(uint64_t timestamp);
53 
54 /**
55  * @brief Notify esp_timer implementation that APB frequency has changed
56  *
57  * Called by the frequency switching code.
58  *
59  * @param apb_ticks_per_us new number of APB clock ticks per microsecond
60  */
61 void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us);
62 
63 /**
64  * @brief Adjust current esp_timer time by a certain value
65  *
66  * Called from light sleep code to synchronize esp_timer time with RTC time.
67  *
68  * @param time_us  adjustment to apply to esp_timer time, in microseconds
69  */
70 void esp_timer_impl_advance(int64_t time_us);
71 
72 /**
73  * @brief Get time, in microseconds, since esp_timer_impl_init was called
74  * @return timestamp in microseconds
75  */
76 int64_t esp_timer_impl_get_time(void);
77 
78 /**
79  * @brief Get minimal timer period, in microseconds
80  * Periods shorter than the one returned may not be possible to achieve due to
81  * interrupt latency and context switch time. Short period of periodic timer may
82  * cause the system to spend all the time servicing the interrupt and timer
83  * callback, preventing other tasks from running.
84  * @return minimal period of periodic timer, in microseconds
85  */
86 uint64_t esp_timer_impl_get_min_period_us(void);
87 
88 /**
89  * @brief obtain internal critical section used esp_timer implementation
90  * This can be used when a sequence of calls to esp_timer has to be made,
91  * and it is necessary that the state of the timer is consistent between
92  * the calls. Should be treated in the same way as a spinlock.
93  * Call esp_timer_impl_unlock to release the lock
94  */
95 void esp_timer_impl_lock(void);
96 
97 
98 /**
99  * @brief counterpart of esp_timer_impl_lock
100  */
101 void esp_timer_impl_unlock(void);
102 
103 /**
104  * @brief Get counting register
105  *
106  * Bit depth dependents on implementation and can be 32-bit or 64-bit.
107  *
108  * @return the value of the counting register
109  */
110 uint64_t esp_timer_impl_get_counter_reg(void);
111 
112 /**
113  * @brief Get alarm register
114  *
115  * Bit depth dependents on implementation and can be 32-bit or 64-bit.
116  *
117  * @return the value of the alarm register
118  */
119 uint64_t esp_timer_impl_get_alarm_reg(void);
120