forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
132 lines (104 loc) · 3.35 KB
/
timer.h
File metadata and controls
132 lines (104 loc) · 3.35 KB
1
2
3
4
5
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2018 Intel Corporation. All rights reserved.
*
* Author: Janusz Jankowski <janusz.jankowski@linux.intel.com>
*/
#ifndef __SOF_DRIVERS_TIMER_H__
#define __SOF_DRIVERS_TIMER_H__
#include <arch/drivers/timer.h>
#include <rtos/clk.h>
#include <sof/lib/cpu.h>
#include <rtos/sof.h>
#include <sof/platform.h>
#include <stdint.h>
struct comp_dev;
struct sof_ipc_stream_posn;
#define TIMER0 0
#define TIMER1 1
#define TIMER2 2
#define TIMER3 3
#define TIMER4 4
int timer_register(struct timer *timer, void (*handler)(void *arg), void *arg);
void timer_unregister(struct timer *timer, void *arg);
void timer_enable(struct timer *timer, void *arg, int core);
void timer_disable(struct timer *timer, void *arg, int core);
static inline struct timer *timer_get(void)
{
return sof_get()->platform_timer;
}
static inline struct timer *cpu_timer_get(void)
{
return &(sof_get()->cpu_timers[cpu_get_id()]);
}
static inline int64_t timer_set(struct timer *timer, uint64_t ticks)
{
return arch_timer_set(timer, ticks);
}
void timer_set_ms(struct timer *timer, unsigned int ms);
static inline void timer_clear(struct timer *timer)
{
arch_timer_clear(timer);
}
unsigned int timer_get_count(struct timer *timer);
unsigned int timer_get_count_delta(struct timer *timer);
static inline uint64_t timer_get_system(struct timer *timer)
{
return arch_timer_get_system(timer);
}
int64_t platform_timer_set(struct timer *timer, uint64_t ticks);
void platform_timer_clear(struct timer *timer);
uint64_t platform_timer_get(struct timer *timer);
uint64_t platform_timer_get_atomic(struct timer *timer);
static inline uint64_t platform_safe_get_time(struct timer *timer)
{
/* Default to something small but at least 1.0 microsecond so it
* does not look like an uninitialized zero; not even when the
* user does not request any microseconds decimals. See
* DEFAULT_CLOCK constant in logger.c
*/
return timer ? platform_timer_get(timer) : 50;
}
void platform_timer_start(struct timer *timer);
void platform_timer_stop(struct timer *timer);
static inline uint64_t k_ms_to_cyc_ceil64(uint64_t ms)
{
return clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, ms);
}
static inline uint64_t k_us_to_cyc_ceil64(uint64_t us)
{
return clock_us_to_ticks(PLATFORM_DEFAULT_CLOCK, us);
}
static inline uint64_t k_ns_to_cyc_near64(uint64_t ns)
{
return clock_ns_to_ticks(PLATFORM_DEFAULT_CLOCK, ns);
}
static inline uint64_t k_cyc_to_ms_near64(uint64_t ticks)
{
return ticks / clock_ms_to_ticks(PLATFORM_DEFAULT_CLOCK, 1);
}
static inline uint64_t k_cyc_to_us_near64(uint64_t ticks)
{
return ticks / clock_us_to_ticks(PLATFORM_DEFAULT_CLOCK, 1);
}
static inline uint64_t sof_cycle_get_64(void)
{
return platform_timer_get(timer_get());
}
static inline uint64_t sof_cycle_get_64_atomic(void)
{
return platform_timer_get_atomic(timer_get());
}
static inline uint64_t sof_cycle_get_64_safe(void)
{
return platform_safe_get_time(timer_get());
}
/* get timestamp for host stream DMA position */
void platform_host_timestamp(struct comp_dev *host,
struct sof_ipc_stream_posn *posn);
/* get timestamp for DAI stream DMA position */
void platform_dai_timestamp(struct comp_dev *dai,
struct sof_ipc_stream_posn *posn);
/* get current wallclock for componnent */
void platform_dai_wallclock(struct comp_dev *dai, uint64_t *wallclock);
#endif /* __SOF_DRIVERS_TIMER_H__ */