1
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* ... */
#include <stdlib.h>
#include "hal/timer_hal.h"
#include "hal/timer_ll.h"
#include "soc/soc_caps.h"
void timer_hal_init(timer_hal_context_t *hal, uint32_t group_num, uint32_t timer_num)
{
hal->dev = TIMER_LL_GET_HW(group_num);
hal->timer_id = timer_num;
timer_ll_enable_counter(hal->dev, timer_num, false);
timer_ll_enable_auto_reload(hal->dev, timer_num, false);
timer_ll_enable_alarm(hal->dev, timer_num, false);
#if SOC_TIMER_SUPPORT_ETM
timer_ll_enable_etm(hal->dev, true);
#endif
}{ ... }
void timer_hal_deinit(timer_hal_context_t *hal)
{
timer_ll_enable_counter(hal->dev, hal->timer_id, false);
timer_ll_enable_auto_reload(hal->dev, hal->timer_id, false);
timer_ll_enable_alarm(hal->dev, hal->timer_id, false);
#if SOC_TIMER_SUPPORT_ETM
timer_ll_enable_etm(hal->dev, false);
#endif
hal->dev = NULL;
}{ ... }
void timer_hal_set_counter_value(timer_hal_context_t *hal, uint64_t load_val)
{
uint64_t old_reload = timer_ll_get_reload_value(hal->dev, hal->timer_id);
timer_ll_set_reload_value(hal->dev, hal->timer_id, load_val);
timer_ll_trigger_soft_reload(hal->dev, hal->timer_id);
timer_ll_set_reload_value(hal->dev, hal->timer_id, old_reload);
}{ ... }
uint64_t timer_hal_capture_and_get_counter_value(timer_hal_context_t *hal)
{
timer_ll_trigger_soft_capture(hal->dev, hal->timer_id);
return timer_ll_get_counter_value(hal->dev, hal->timer_id);
}{ ... }