1 /*
2  * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*******************************************************************************
8  * NOTICE
9  * The hal is not public api, don't use in application code.
10  * See readme.md in hal/include/hal/readme.md
11  ******************************************************************************/
12 
13 #pragma once
14 
15 #include <stdint.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 typedef struct timg_dev_t *gptimer_soc_handle_t; // GPTimer SOC layer handle
22 
23 /**
24  * Context that should be maintained by both the driver and the HAL
25  */
26 typedef struct {
27     gptimer_soc_handle_t dev; // Timer SOC layer handle (i.e. register base address)
28     uint32_t timer_id;        // Timer ID (i.e. index of the timer in the group)
29 } timer_hal_context_t;
30 
31 /**
32  * @brief Init the timer hal. This function should be called first before other hal layer function is called
33  *
34  * @param hal Context of the HAL layer
35  * @param group_num The timer group number
36  * @param timer_num The timer number
37  */
38 void timer_hal_init(timer_hal_context_t *hal, uint32_t group_num, uint32_t timer_num);
39 
40 /**
41  * @brief Deinit timer hal context.
42  *
43  * @param hal Context of HAL layer
44  */
45 void timer_hal_deinit(timer_hal_context_t *hal);
46 
47 /**
48  * @brief Load counter value into time-base counter
49  *
50  * @param hal Context of the HAL layer
51  * @param load_val Counter value
52  */
53 void timer_hal_set_counter_value(timer_hal_context_t *hal, uint64_t load_val);
54 
55 /**
56  * @brief Trigger a software capture event and then return the captured count value
57  *
58  * @param hal Context of the HAL layer
59  * @return Counter value
60  */
61 uint64_t timer_hal_capture_and_get_counter_value(timer_hal_context_t *hal);
62 
63 #ifdef __cplusplus
64 }
65 #endif
66