]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/time.h
common: Drop init.h from common header
[thirdparty/u-boot.git] / include / time.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
a7b81769
MY
2
3#ifndef _TIME_H
4#define _TIME_H
5
21cdd133 6#include <linux/typecheck.h>
6a853dbc 7#include <linux/types.h>
21cdd133 8
049f8d6f
SG
9ulong get_tbclk(void);
10
a7b81769
MY
11unsigned long get_timer(unsigned long base);
12
13/*
14 * Return the current value of a monotonically increasing microsecond timer.
15 * Granularity may be larger than 1us if hardware does not support this.
16 */
17unsigned long timer_get_us(void);
80e7e7c2 18uint64_t get_timer_us(uint64_t base);
a7b81769 19
d0a9b82b
NA
20/*
21 * timer_test_add_offset()
22 *
23 * Allow tests to add to the time reported through lib/time.c functions
24 * offset: number of milliseconds to advance the system time
25 */
26void timer_test_add_offset(unsigned long offset);
27
6a853dbc
HS
28/**
29 * usec_to_tick() - convert microseconds to clock ticks
30 *
31 * @usec: duration in microseconds
32 * Return: duration in clock ticks
33 */
34uint64_t usec_to_tick(unsigned long usec);
35
21cdd133
MY
36/*
37 * These inlines deal with timer wrapping correctly. You are
38 * strongly encouraged to use them
39 * 1. Because people otherwise forget
40 * 2. Because if the timer wrap changes in future you won't have to
41 * alter your driver code.
42 *
43 * time_after(a,b) returns true if the time a is after time b.
44 *
45 * Do this with "<0" and ">=0" to only test the sign of the result. A
46 * good compiler would generate better code (and a really good compiler
47 * wouldn't care). Gcc is currently neither.
48 */
49#define time_after(a,b) \
50 (typecheck(unsigned long, a) && \
51 typecheck(unsigned long, b) && \
52 ((long)((b) - (a)) < 0))
53#define time_before(a,b) time_after(b,a)
54
55#define time_after_eq(a,b) \
56 (typecheck(unsigned long, a) && \
57 typecheck(unsigned long, b) && \
58 ((long)((a) - (b)) >= 0))
59#define time_before_eq(a,b) time_after_eq(b,a)
60
61/*
62 * Calculate whether a is in the range of [b, c].
63 */
64#define time_in_range(a,b,c) \
65 (time_after_eq(a,b) && \
66 time_before_eq(a,c))
67
68/*
69 * Calculate whether a is in the range of [b, c).
70 */
71#define time_in_range_open(a,b,c) \
72 (time_after_eq(a,b) && \
73 time_before(a,c))
74
6887c5be
SG
75/**
76 * usec2ticks() - Convert microseconds to internal ticks
77 *
78 * @usec: Value of microseconds to convert
79 * @return Corresponding internal ticks value, calculated using get_tbclk()
80 */
81ulong usec2ticks(unsigned long usec);
82
83/**
84 * ticks2usec() - Convert internal ticks to microseconds
85 *
86 * @ticks: Value of ticks to convert
87 * @return Corresponding microseconds value, calculated using get_tbclk()
88 */
89ulong ticks2usec(unsigned long ticks);
90
036a017f
SG
91/**
92 * wait_ticks() - waits a given number of ticks
93 *
94 * This is an internal function typically used to implement udelay() and
95 * similar. Normally you should use udelay() or mdelay() instead.
96 *
97 * @ticks: Number of ticks to wait
98 */
99void wait_ticks(unsigned long ticks);
100
f0143a86
SG
101/**
102 * timer_get_us() - Get monotonic microsecond timer
103 *
104 * @return value of monotonic microsecond timer
105 */
106unsigned long timer_get_us(void);
107
1045315d
SG
108/**
109 * get_ticks() - Get the current tick value
110 *
111 * This is an internal value used by the timer on the system. Ticks increase
112 * monotonically at the rate given by get_tbclk().
113 *
114 * @return current tick value
115 */
116uint64_t get_ticks(void);
117
a7b81769 118#endif /* _TIME_H */