Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
time_units.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_TIME_UNITS_H_
8#define ZEPHYR_INCLUDE_TIME_UNITS_H_
9
10#include <zephyr/toolchain.h>
11#include <zephyr/sys/util.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
33#define SYS_FOREVER_MS (-1)
34
39#define SYS_FOREVER_US (-1)
40
43#define SYS_TIMEOUT_MS(ms) Z_TIMEOUT_TICKS((ms) == SYS_FOREVER_MS ? \
44 K_TICKS_FOREVER : Z_TIMEOUT_MS_TICKS(ms))
45
46/* Exhaustively enumerated, highly optimized time unit conversion API */
47
48#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
49__syscall int sys_clock_hw_cycles_per_sec_runtime_get(void);
50
51static inline int z_impl_sys_clock_hw_cycles_per_sec_runtime_get(void)
52{
53 extern int z_clock_hw_cycles_per_sec;
54
55 return z_clock_hw_cycles_per_sec;
56}
57#endif /* CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME */
58
59#if defined(__cplusplus) && (__cplusplus >= 201402L)
60 #if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
61 #define TIME_CONSTEXPR
62 #else
63 #define TIME_CONSTEXPR constexpr
64 #endif
65#else
66 #define TIME_CONSTEXPR
67#endif
68
73#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
74#define sys_clock_hw_cycles_per_sec() sys_clock_hw_cycles_per_sec_runtime_get()
75#else
76#define sys_clock_hw_cycles_per_sec() CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC
77#endif
78
90#define z_tmcvt_use_fast_algo(from_hz, to_hz) \
91 ((DIV_ROUND_UP(CONFIG_SYS_CLOCK_MAX_TIMEOUT_DAYS * 24ULL * 3600ULL * from_hz, \
92 UINT32_MAX) * to_hz) <= UINT32_MAX)
93
94/* Time converter generator gadget. Selects from one of three
95 * conversion algorithms: ones that take advantage when the
96 * frequencies are an integer ratio (in either direction), or a full
97 * precision conversion. Clever use of extra arguments causes all the
98 * selection logic to be optimized out, and the generated code even
99 * reduces to 32 bit only if a ratio conversion is available and the
100 * result is 32 bits.
101 *
102 * This isn't intended to be used directly, instead being wrapped
103 * appropriately in a user-facing API. The boolean arguments are:
104 *
105 * const_hz - The hz arguments are known to be compile-time
106 * constants (because otherwise the modulus test would
107 * have to be done at runtime)
108 * result32 - The result will be truncated to 32 bits on use
109 * round_up - Return the ceiling of the resulting fraction
110 * round_off - Return the nearest value to the resulting fraction
111 * (pass both round_up/off as false to get "round_down")
112 *
113 * All of this must be implemented as expressions so that, when constant,
114 * the results may be used to initialize global variables.
115 */
116
117/* true if the conversion is the identity */
118#define z_tmcvt_is_identity(__from_hz, __to_hz) \
119 ((__to_hz) == (__from_hz))
120
121/* true if the conversion requires a simple integer multiply */
122#define z_tmcvt_is_int_mul(__from_hz, __to_hz) \
123 ((__to_hz) > (__from_hz) && (__to_hz) % (__from_hz) == 0U)
124
125/* true if the conversion requires a simple integer division */
126#define z_tmcvt_is_int_div(__from_hz, __to_hz) \
127 ((__from_hz) > (__to_hz) && (__from_hz) % (__to_hz) == 0U)
128
129/*
130 * Compute the offset needed to round the result correctly when
131 * the conversion requires a simple integer division
132 */
133#define z_tmcvt_off_div(__from_hz, __to_hz, __round_up, __round_off) \
134 ((__round_off) ? ((__from_hz) / (__to_hz)) / 2 : \
135 (__round_up) ? ((__from_hz) / (__to_hz)) - 1 : \
136 0)
137
138/*
139 * All users of this macro MUST ensure its output is never used when a/b
140 * is zero because it incorrectly but by design never returns zero.
141 *
142 * Some compiler versions emit a divide-by-zero warning for this code:
143 * "false ? 42/0 : 43". Dealing with (generated) dead code is hard:
144 * https://github.com/zephyrproject-rtos/zephyr/issues/63564
145 * https://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html
146 *
147 * To silence such divide-by-zero warnings, "cheat" and never return
148 * zero. Return 1 instead. Use octal "01u" as a breadcrumb to ease a
149 * little bit the huge pain of "reverse-engineering" pre-processor
150 * output.
151 *
152 * The "Elvis" operator "a/b ?: 1" is tempting because it avoids
153 * evaluating the same expression twice. However: 1. it's a non-standard
154 * GNU extension; 2. everything in this file is designed to be computed
155 * at compile time anyway.
156 */
157#define z_tmcvt_divisor(a, b) ((a)/(b) ? (a)/(b) : 01u)
158
159/*
160 * Compute the offset needed to round the result correctly when
161 * the conversion requires a full mul/div
162 */
163#define z_tmcvt_off_gen(__from_hz, __to_hz, __round_up, __round_off) \
164 ((__round_off) ? (__from_hz) / 2 : \
165 (__round_up) ? (__from_hz) - 1 : \
166 0)
167
168/* Integer division 32-bit conversion */
169#define z_tmcvt_int_div_32(__t, __from_hz, __to_hz, __round_up, __round_off) \
170 ((uint64_t) (__t) <= 0xffffffffU - \
171 z_tmcvt_off_div(__from_hz, __to_hz, __round_up, __round_off) ? \
172 ((uint32_t)((__t) + \
173 z_tmcvt_off_div(__from_hz, __to_hz, \
174 __round_up, __round_off)) / \
175 z_tmcvt_divisor(__from_hz, __to_hz)) \
176 : \
177 (uint32_t) (((uint64_t) (__t) + \
178 z_tmcvt_off_div(__from_hz, __to_hz, \
179 __round_up, __round_off)) / \
180 z_tmcvt_divisor(__from_hz, __to_hz)) \
181 )
182
183/* Integer multiplication 32-bit conversion */
184#define z_tmcvt_int_mul_32(__t, __from_hz, __to_hz) \
185 (uint32_t) (__t)*((__to_hz) / (__from_hz))
186
187/* General 32-bit conversion */
188#define z_tmcvt_gen_32(__t, __from_hz, __to_hz, __round_up, __round_off) \
189 ((uint32_t) (((uint64_t) (__t)*(__to_hz) + \
190 z_tmcvt_off_gen(__from_hz, __to_hz, __round_up, __round_off)) / (__from_hz)))
191
192/* Integer division 64-bit conversion */
193#define z_tmcvt_int_div_64(__t, __from_hz, __to_hz, __round_up, __round_off) \
194 (((uint64_t) (__t) + z_tmcvt_off_div(__from_hz, __to_hz, \
195 __round_up, __round_off)) / \
196 z_tmcvt_divisor(__from_hz, __to_hz))
197
198/* Integer multiplcation 64-bit conversion */
199#define z_tmcvt_int_mul_64(__t, __from_hz, __to_hz) \
200 (uint64_t) (__t)*((__to_hz) / (__from_hz))
201
202/* Fast 64-bit conversion. This relies on the multiply not overflowing */
203#define z_tmcvt_gen_64_fast(__t, __from_hz, __to_hz, __round_up, __round_off) \
204 (((uint64_t) (__t)*(__to_hz) + \
205 z_tmcvt_off_gen(__from_hz, __to_hz, __round_up, __round_off)) / (__from_hz))
206
207/* Slow 64-bit conversion. This avoids overflowing the multiply */
208#define z_tmcvt_gen_64_slow(__t, __from_hz, __to_hz, __round_up, __round_off) \
209 (((uint64_t) (__t) / (__from_hz))*(__to_hz) + \
210 (((uint64_t) (__t) % (__from_hz))*(__to_hz) + \
211 z_tmcvt_off_gen(__from_hz, __to_hz, __round_up, __round_off)) / (__from_hz))
212
213/* General 64-bit conversion. Uses one of the two above macros */
214#define z_tmcvt_gen_64(__t, __from_hz, __to_hz, __round_up, __round_off) \
215 (z_tmcvt_use_fast_algo(__from_hz, __to_hz) ? \
216 z_tmcvt_gen_64_fast(__t, __from_hz, __to_hz, __round_up, __round_off) : \
217 z_tmcvt_gen_64_slow(__t, __from_hz, __to_hz, __round_up, __round_off))
218
219/* Convert, generating a 32-bit result */
220#define z_tmcvt_32(__t, __from_hz, __to_hz, __const_hz, __round_up, __round_off) \
221 ((__const_hz) ? \
222 ( \
223 z_tmcvt_is_identity(__from_hz, __to_hz) ? \
224 (uint32_t) (__t) \
225 : \
226 z_tmcvt_is_int_div(__from_hz, __to_hz) ? \
227 z_tmcvt_int_div_32(__t, __from_hz, __to_hz, __round_up, __round_off) \
228 : \
229 z_tmcvt_is_int_mul(__from_hz, __to_hz) ? \
230 z_tmcvt_int_mul_32(__t, __from_hz, __to_hz) \
231 : \
232 z_tmcvt_gen_32(__t, __from_hz, __to_hz, __round_up, __round_off) \
233 ) \
234 : \
235 z_tmcvt_gen_32(__t, __from_hz, __to_hz, __round_up, __round_off) \
236 )
237
238/* Convert, generating a 64-bit result */
239#define z_tmcvt_64(__t, __from_hz, __to_hz, __const_hz, __round_up, __round_off) \
240 ((__const_hz) ? \
241 ( \
242 z_tmcvt_is_identity(__from_hz, __to_hz) ? \
243 (uint64_t) (__t) \
244 : \
245 z_tmcvt_is_int_div(__from_hz, __to_hz) ? \
246 z_tmcvt_int_div_64(__t, __from_hz, __to_hz, __round_up, __round_off) \
247 : \
248 z_tmcvt_is_int_mul(__from_hz, __to_hz) ? \
249 z_tmcvt_int_mul_64(__t, __from_hz, __to_hz) \
250 : \
251 z_tmcvt_gen_64(__t, __from_hz, __to_hz, __round_up, __round_off) \
252 ) \
253 : \
254 z_tmcvt_gen_64_slow(__t, __from_hz, __to_hz, __round_up, __round_off) \
255 )
256
257#define z_tmcvt(__t, __from_hz, __to_hz, __const_hz, __result32, __round_up, __round_off) \
258 ((__result32) ? \
259 z_tmcvt_32(__t, __from_hz, __to_hz, __const_hz, __round_up, __round_off) : \
260 z_tmcvt_64(__t, __from_hz, __to_hz, __const_hz, __round_up, __round_off))
261
262/* The following code is programmatically generated using this perl
263 * code, which enumerates all possible combinations of units, rounding
264 * modes and precision. Do not edit directly.
265 *
266 * Note that nano/microsecond conversions are only defined with 64 bit
267 * precision. These units conversions were not available in 32 bit
268 * variants historically, and doing 32 bit math with units that small
269 * has precision traps that we probably don't want to support in an
270 * official API.
271 *
272 * #!/usr/bin/perl -w
273 * use strict;
274 *
275 * my %human = ("sec" => "seconds",
276 * "ms" => "milliseconds",
277 * "us" => "microseconds",
278 * "ns" => "nanoseconds",
279 * "cyc" => "hardware cycles",
280 * "ticks" => "ticks");
281 * my %human_round = ("ceil" => "Rounds up",
282 * "near" => "Round nearest",
283 * "floor" => "Truncates");
284 *
285 * sub big { return $_[0] eq "us" || $_[0] eq "ns"; }
286 * sub prefix { return $_[0] eq "sec" || $_[0] eq "ms" || $_[0] eq "us" || $_[0] eq "ns"; }
287 *
288 * for my $from_unit ("sec", "ms", "us", "ns", "cyc", "ticks") {
289 * for my $to_unit ("sec", "ms", "us", "ns", "cyc", "ticks") {
290 * next if $from_unit eq $to_unit;
291 * next if prefix($from_unit) && prefix($to_unit);
292 * for my $round ("floor", "near", "ceil") {
293 * for(my $big=0; $big <= 1; $big++) {
294 * my $sz = $big ? 64 : 32;
295 * my $sym = "k_${from_unit}_to_${to_unit}_$round$sz";
296 * my $type = "uint${sz}_t";
297 * my $const_hz = ($from_unit eq "cyc" || $to_unit eq "cyc")
298 * ? "Z_CCYC" : "true";
299 * my $ret32 = $big ? "64" : "32";
300 * my $rup = $round eq "ceil" ? "true" : "false";
301 * my $roff = $round eq "near" ? "true" : "false";
302 *
303 * my $hfrom = $human{$from_unit};
304 * my $hto = $human{$to_unit};
305 * my $hround = $human_round{$round};
306 * print "/", "** \@brief Convert $hfrom to $hto. $ret32 bits. $hround.\n";
307 * print " *\n";
308 * print " * Converts time values in $hfrom to $hto.\n";
309 * print " * Computes result in $sz bit precision.\n";
310 * if ($round eq "ceil") {
311 * print " * Rounds up to the next highest output unit.\n";
312 * } elsif ($round eq "near") {
313 * print " * Rounds to the nearest output unit.\n";
314 * } else {
315 * print " * Truncates to the next lowest output unit.\n";
316 * }
317 * print " *\n";
318 * print " * \@warning Generated. Do not edit. See above.\n";
319 * print " *\n";
320 * print " * \@param t Source time in $hfrom. uint64_t\n";
321 * print " *\n";
322 * print " * \@return The converted time value in $hto. $type\n";
323 * print " *", "/\n";
324 * print "#define $sym(t) \\\n";
325 * print "\tz_tmcvt_$ret32(t, Z_HZ_$from_unit, Z_HZ_$to_unit,";
326 * print " $const_hz, $rup, $roff)\n";
327 * print "\n\n";
328 * }
329 * }
330 * }
331 * }
332 */
333
334/* Some more concise declarations to simplify the generator script and
335 * save bytes below
336 */
337#define Z_HZ_sec 1
338#define Z_HZ_ms 1000
339#define Z_HZ_us 1000000
340#define Z_HZ_ns 1000000000
341#define Z_HZ_cyc sys_clock_hw_cycles_per_sec()
342#define Z_HZ_ticks CONFIG_SYS_CLOCK_TICKS_PER_SEC
343#define Z_CCYC (!IS_ENABLED(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME))
344
357#define k_sec_to_cyc_floor32(t) \
358 z_tmcvt_32(t, Z_HZ_sec, Z_HZ_cyc, Z_CCYC, false, false)
359
360
373#define k_sec_to_cyc_floor64(t) \
374 z_tmcvt_64(t, Z_HZ_sec, Z_HZ_cyc, Z_CCYC, false, false)
375
376
389#define k_sec_to_cyc_near32(t) \
390 z_tmcvt_32(t, Z_HZ_sec, Z_HZ_cyc, Z_CCYC, false, true)
391
392
405#define k_sec_to_cyc_near64(t) \
406 z_tmcvt_64(t, Z_HZ_sec, Z_HZ_cyc, Z_CCYC, false, true)
407
408
421#define k_sec_to_cyc_ceil32(t) \
422 z_tmcvt_32(t, Z_HZ_sec, Z_HZ_cyc, Z_CCYC, true, false)
423
424
437#define k_sec_to_cyc_ceil64(t) \
438 z_tmcvt_64(t, Z_HZ_sec, Z_HZ_cyc, Z_CCYC, true, false)
439
440
453#define k_sec_to_ticks_floor32(t) \
454 z_tmcvt_32(t, Z_HZ_sec, Z_HZ_ticks, true, false, false)
455
456
469#define k_sec_to_ticks_floor64(t) \
470 z_tmcvt_64(t, Z_HZ_sec, Z_HZ_ticks, true, false, false)
471
472
485#define k_sec_to_ticks_near32(t) \
486 z_tmcvt_32(t, Z_HZ_sec, Z_HZ_ticks, true, false, true)
487
488
501#define k_sec_to_ticks_near64(t) \
502 z_tmcvt_64(t, Z_HZ_sec, Z_HZ_ticks, true, false, true)
503
504
517#define k_sec_to_ticks_ceil32(t) \
518 z_tmcvt_32(t, Z_HZ_sec, Z_HZ_ticks, true, true, false)
519
520
533#define k_sec_to_ticks_ceil64(t) \
534 z_tmcvt_64(t, Z_HZ_sec, Z_HZ_ticks, true, true, false)
535
536
549#define k_ms_to_cyc_floor32(t) \
550 z_tmcvt_32(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, false, false)
551
552
565#define k_ms_to_cyc_floor64(t) \
566 z_tmcvt_64(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, false, false)
567
568
581#define k_ms_to_cyc_near32(t) \
582 z_tmcvt_32(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, false, true)
583
584
597#define k_ms_to_cyc_near64(t) \
598 z_tmcvt_64(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, false, true)
599
600
613#define k_ms_to_cyc_ceil32(t) \
614 z_tmcvt_32(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, true, false)
615
616
629#define k_ms_to_cyc_ceil64(t) \
630 z_tmcvt_64(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, true, false)
631
632
645#define k_ms_to_ticks_floor32(t) \
646 z_tmcvt_32(t, Z_HZ_ms, Z_HZ_ticks, true, false, false)
647
648
661#define k_ms_to_ticks_floor64(t) \
662 z_tmcvt_64(t, Z_HZ_ms, Z_HZ_ticks, true, false, false)
663
664
677#define k_ms_to_ticks_near32(t) \
678 z_tmcvt_32(t, Z_HZ_ms, Z_HZ_ticks, true, false, true)
679
680
693#define k_ms_to_ticks_near64(t) \
694 z_tmcvt_64(t, Z_HZ_ms, Z_HZ_ticks, true, false, true)
695
696
709#define k_ms_to_ticks_ceil32(t) \
710 z_tmcvt_32(t, Z_HZ_ms, Z_HZ_ticks, true, true, false)
711
712
725#define k_ms_to_ticks_ceil64(t) \
726 z_tmcvt_64(t, Z_HZ_ms, Z_HZ_ticks, true, true, false)
727
728
741#define k_us_to_cyc_floor32(t) \
742 z_tmcvt_32(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, false, false)
743
744
757#define k_us_to_cyc_floor64(t) \
758 z_tmcvt_64(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, false, false)
759
760
773#define k_us_to_cyc_near32(t) \
774 z_tmcvt_32(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, false, true)
775
776
789#define k_us_to_cyc_near64(t) \
790 z_tmcvt_64(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, false, true)
791
792
805#define k_us_to_cyc_ceil32(t) \
806 z_tmcvt_32(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, true, false)
807
808
821#define k_us_to_cyc_ceil64(t) \
822 z_tmcvt_64(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, true, false)
823
824
837#define k_us_to_ticks_floor32(t) \
838 z_tmcvt_32(t, Z_HZ_us, Z_HZ_ticks, true, false, false)
839
840
853#define k_us_to_ticks_floor64(t) \
854 z_tmcvt_64(t, Z_HZ_us, Z_HZ_ticks, true, false, false)
855
856
869#define k_us_to_ticks_near32(t) \
870 z_tmcvt_32(t, Z_HZ_us, Z_HZ_ticks, true, false, true)
871
872
885#define k_us_to_ticks_near64(t) \
886 z_tmcvt_64(t, Z_HZ_us, Z_HZ_ticks, true, false, true)
887
888
901#define k_us_to_ticks_ceil32(t) \
902 z_tmcvt_32(t, Z_HZ_us, Z_HZ_ticks, true, true, false)
903
904
917#define k_us_to_ticks_ceil64(t) \
918 z_tmcvt_64(t, Z_HZ_us, Z_HZ_ticks, true, true, false)
919
920
933#define k_ns_to_cyc_floor32(t) \
934 z_tmcvt_32(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, false, false)
935
936
949#define k_ns_to_cyc_floor64(t) \
950 z_tmcvt_64(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, false, false)
951
952
965#define k_ns_to_cyc_near32(t) \
966 z_tmcvt_32(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, false, true)
967
968
981#define k_ns_to_cyc_near64(t) \
982 z_tmcvt_64(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, false, true)
983
984
997#define k_ns_to_cyc_ceil32(t) \
998 z_tmcvt_32(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, true, false)
999
1000
1013#define k_ns_to_cyc_ceil64(t) \
1014 z_tmcvt_64(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, true, false)
1015
1016
1029#define k_ns_to_ticks_floor32(t) \
1030 z_tmcvt_32(t, Z_HZ_ns, Z_HZ_ticks, true, false, false)
1031
1032
1045#define k_ns_to_ticks_floor64(t) \
1046 z_tmcvt_64(t, Z_HZ_ns, Z_HZ_ticks, true, false, false)
1047
1048
1061#define k_ns_to_ticks_near32(t) \
1062 z_tmcvt_32(t, Z_HZ_ns, Z_HZ_ticks, true, false, true)
1063
1064
1077#define k_ns_to_ticks_near64(t) \
1078 z_tmcvt_64(t, Z_HZ_ns, Z_HZ_ticks, true, false, true)
1079
1080
1093#define k_ns_to_ticks_ceil32(t) \
1094 z_tmcvt_32(t, Z_HZ_ns, Z_HZ_ticks, true, true, false)
1095
1096
1109#define k_ns_to_ticks_ceil64(t) \
1110 z_tmcvt_64(t, Z_HZ_ns, Z_HZ_ticks, true, true, false)
1111
1112
1125#define k_cyc_to_sec_floor32(t) \
1126 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_sec, Z_CCYC, false, false)
1127
1128
1141#define k_cyc_to_sec_floor64(t) \
1142 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_sec, Z_CCYC, false, false)
1143
1144
1157#define k_cyc_to_sec_near32(t) \
1158 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_sec, Z_CCYC, false, true)
1159
1160
1173#define k_cyc_to_sec_near64(t) \
1174 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_sec, Z_CCYC, false, true)
1175
1176
1189#define k_cyc_to_sec_ceil32(t) \
1190 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_sec, Z_CCYC, true, false)
1191
1192
1205#define k_cyc_to_sec_ceil64(t) \
1206 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_sec, Z_CCYC, true, false)
1207
1208
1221#define k_cyc_to_ms_floor32(t) \
1222 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, false, false)
1223
1224
1237#define k_cyc_to_ms_floor64(t) \
1238 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, false, false)
1239
1240
1253#define k_cyc_to_ms_near32(t) \
1254 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, false, true)
1255
1256
1269#define k_cyc_to_ms_near64(t) \
1270 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, false, true)
1271
1272
1285#define k_cyc_to_ms_ceil32(t) \
1286 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, true, false)
1287
1288
1301#define k_cyc_to_ms_ceil64(t) \
1302 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, true, false)
1303
1304
1317#define k_cyc_to_us_floor32(t) \
1318 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, false, false)
1319
1320
1333#define k_cyc_to_us_floor64(t) \
1334 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, false, false)
1335
1336
1349#define k_cyc_to_us_near32(t) \
1350 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, false, true)
1351
1352
1365#define k_cyc_to_us_near64(t) \
1366 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, false, true)
1367
1368
1381#define k_cyc_to_us_ceil32(t) \
1382 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, true, false)
1383
1384
1397#define k_cyc_to_us_ceil64(t) \
1398 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, true, false)
1399
1400
1413#define k_cyc_to_ns_floor32(t) \
1414 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, false, false)
1415
1416
1429#define k_cyc_to_ns_floor64(t) \
1430 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, false, false)
1431
1432
1445#define k_cyc_to_ns_near32(t) \
1446 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, false, true)
1447
1448
1461#define k_cyc_to_ns_near64(t) \
1462 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, false, true)
1463
1464
1477#define k_cyc_to_ns_ceil32(t) \
1478 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, true, false)
1479
1480
1493#define k_cyc_to_ns_ceil64(t) \
1494 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, true, false)
1495
1496
1509#define k_cyc_to_ticks_floor32(t) \
1510 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, false, false)
1511
1512
1525#define k_cyc_to_ticks_floor64(t) \
1526 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, false, false)
1527
1528
1541#define k_cyc_to_ticks_near32(t) \
1542 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, false, true)
1543
1544
1557#define k_cyc_to_ticks_near64(t) \
1558 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, false, true)
1559
1560
1573#define k_cyc_to_ticks_ceil32(t) \
1574 z_tmcvt_32(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, true, false)
1575
1576
1589#define k_cyc_to_ticks_ceil64(t) \
1590 z_tmcvt_64(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, true, false)
1591
1592
1605#define k_ticks_to_sec_floor32(t) \
1606 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_sec, true, false, false)
1607
1608
1621#define k_ticks_to_sec_floor64(t) \
1622 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_sec, true, false, false)
1623
1624
1637#define k_ticks_to_sec_near32(t) \
1638 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_sec, true, false, true)
1639
1640
1653#define k_ticks_to_sec_near64(t) \
1654 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_sec, true, false, true)
1655
1656
1669#define k_ticks_to_sec_ceil32(t) \
1670 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_sec, true, true, false)
1671
1672
1685#define k_ticks_to_sec_ceil64(t) \
1686 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_sec, true, true, false)
1687
1688
1701#define k_ticks_to_ms_floor32(t) \
1702 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_ms, true, false, false)
1703
1704
1717#define k_ticks_to_ms_floor64(t) \
1718 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_ms, true, false, false)
1719
1720
1733#define k_ticks_to_ms_near32(t) \
1734 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_ms, true, false, true)
1735
1736
1749#define k_ticks_to_ms_near64(t) \
1750 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_ms, true, false, true)
1751
1752
1765#define k_ticks_to_ms_ceil32(t) \
1766 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_ms, true, true, false)
1767
1768
1781#define k_ticks_to_ms_ceil64(t) \
1782 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_ms, true, true, false)
1783
1784
1797#define k_ticks_to_us_floor32(t) \
1798 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_us, true, false, false)
1799
1800
1813#define k_ticks_to_us_floor64(t) \
1814 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_us, true, false, false)
1815
1816
1829#define k_ticks_to_us_near32(t) \
1830 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_us, true, false, true)
1831
1832
1845#define k_ticks_to_us_near64(t) \
1846 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_us, true, false, true)
1847
1848
1861#define k_ticks_to_us_ceil32(t) \
1862 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_us, true, true, false)
1863
1864
1877#define k_ticks_to_us_ceil64(t) \
1878 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_us, true, true, false)
1879
1880
1893#define k_ticks_to_ns_floor32(t) \
1894 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_ns, true, false, false)
1895
1896
1909#define k_ticks_to_ns_floor64(t) \
1910 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_ns, true, false, false)
1911
1912
1925#define k_ticks_to_ns_near32(t) \
1926 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_ns, true, false, true)
1927
1928
1941#define k_ticks_to_ns_near64(t) \
1942 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_ns, true, false, true)
1943
1944
1957#define k_ticks_to_ns_ceil32(t) \
1958 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_ns, true, true, false)
1959
1960
1973#define k_ticks_to_ns_ceil64(t) \
1974 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_ns, true, true, false)
1975
1976
1989#define k_ticks_to_cyc_floor32(t) \
1990 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, false, false)
1991
1992
2005#define k_ticks_to_cyc_floor64(t) \
2006 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, false, false)
2007
2008
2021#define k_ticks_to_cyc_near32(t) \
2022 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, false, true)
2023
2024
2037#define k_ticks_to_cyc_near64(t) \
2038 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, false, true)
2039
2040
2053#define k_ticks_to_cyc_ceil32(t) \
2054 z_tmcvt_32(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, true, false)
2055
2056
2069#define k_ticks_to_cyc_ceil64(t) \
2070 z_tmcvt_64(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, true, false)
2071
2072#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
2073#include <syscalls/time_units.h>
2074#endif
2075
2076#undef TIME_CONSTEXPR
2077
2082#ifdef __cplusplus
2083} /* extern "C" */
2084#endif
2085
2086#endif /* ZEPHYR_INCLUDE_TIME_UNITS_H_ */
Macros to abstract toolchain specific capabilities.
Misc utilities.