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
14 extern "C" {
15 #endif
16
17 /** @brief System-wide macro to denote "forever" in milliseconds
18 *
19 * Usage of this macro is limited to APIs that want to expose a timeout value
20 * that can optionally be unlimited, or "forever".
21 * This macro can not be fed into kernel functions or macros directly. Use
22 * @ref SYS_TIMEOUT_MS instead.
23 */
24 #define SYS_FOREVER_MS (-1)
25
26 /** @brief System-wide macro to denote "forever" in microseconds
27 *
28 * See @ref SYS_FOREVER_MS.
29 */
30 #define SYS_FOREVER_US (-1)
31
32 /** @brief System-wide macro to convert milliseconds to kernel timeouts
33 */
34 #define SYS_TIMEOUT_MS(ms) ((ms) == SYS_FOREVER_MS ? K_FOREVER : K_MSEC(ms))
35
36 /* Exhaustively enumerated, highly optimized time unit conversion API */
37
38 #if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
39 __syscall int sys_clock_hw_cycles_per_sec_runtime_get(void);
40
z_impl_sys_clock_hw_cycles_per_sec_runtime_get(void)41 static inline int z_impl_sys_clock_hw_cycles_per_sec_runtime_get(void)
42 {
43 extern int z_clock_hw_cycles_per_sec;
44
45 return z_clock_hw_cycles_per_sec;
46 }
47 #endif /* CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME */
48
49 #if defined(__cplusplus) && __cplusplus >= 201402L
50 #if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
51 #define TIME_CONSTEXPR
52 #else
53 #define TIME_CONSTEXPR constexpr
54 #endif
55 #else
56 #define TIME_CONSTEXPR
57 #endif
58
sys_clock_hw_cycles_per_sec(void)59 static TIME_CONSTEXPR inline int sys_clock_hw_cycles_per_sec(void)
60 {
61 #if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
62 return sys_clock_hw_cycles_per_sec_runtime_get();
63 #else
64 return CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
65 #endif
66 }
67
68 /** @internal
69 * Macro determines if fast conversion algorithm can be used. It checks if
70 * maximum timeout represented in source frequency domain and multiplied by
71 * target frequency fits in 64 bits.
72 *
73 * @param from_hz Source frequency.
74 * @param to_hz Target frequency.
75 *
76 * @retval true Use faster algorithm.
77 * @retval false Use algorithm preventing overflow of intermediate value.
78 */
79 #define Z_TMCVT_USE_FAST_ALGO(from_hz, to_hz) \
80 ((DIV_ROUND_UP(CONFIG_SYS_CLOCK_MAX_TIMEOUT_DAYS * 24ULL * 3600ULL * from_hz, \
81 UINT32_MAX) * to_hz) <= UINT32_MAX)
82
83 /* Time converter generator gadget. Selects from one of three
84 * conversion algorithms: ones that take advantage when the
85 * frequencies are an integer ratio (in either direction), or a full
86 * precision conversion. Clever use of extra arguments causes all the
87 * selection logic to be optimized out, and the generated code even
88 * reduces to 32 bit only if a ratio conversion is available and the
89 * result is 32 bits.
90 *
91 * This isn't intended to be used directly, instead being wrapped
92 * appropriately in a user-facing API. The boolean arguments are:
93 *
94 * const_hz - The hz arguments are known to be compile-time
95 * constants (because otherwise the modulus test would
96 * have to be done at runtime)
97 * result32 - The result will be truncated to 32 bits on use
98 * round_up - Return the ceiling of the resulting fraction
99 * round_off - Return the nearest value to the resulting fraction
100 * (pass both round_up/off as false to get "round_down")
101 */
z_tmcvt(uint64_t t,uint32_t from_hz,uint32_t to_hz,bool const_hz,bool result32,bool round_up,bool round_off)102 static TIME_CONSTEXPR ALWAYS_INLINE uint64_t z_tmcvt(uint64_t t, uint32_t from_hz,
103 uint32_t to_hz, bool const_hz,
104 bool result32, bool round_up,
105 bool round_off)
106 {
107 bool mul_ratio = const_hz &&
108 (to_hz > from_hz) && ((to_hz % from_hz) == 0U);
109 bool div_ratio = const_hz &&
110 (from_hz > to_hz) && ((from_hz % to_hz) == 0U);
111
112 if (from_hz == to_hz) {
113 return result32 ? ((uint32_t)t) : t;
114 }
115
116 uint64_t off = 0;
117
118 if (!mul_ratio) {
119 uint32_t rdivisor = div_ratio ? (from_hz / to_hz) : from_hz;
120
121 if (round_up) {
122 off = rdivisor - 1U;
123 }
124 if (round_off) {
125 off = rdivisor / 2U;
126 }
127 }
128
129 /* Select (at build time!) between three different expressions for
130 * the same mathematical relationship, each expressed with and
131 * without truncation to 32 bits (I couldn't find a way to make
132 * the compiler correctly guess at the 32 bit result otherwise).
133 */
134 if (div_ratio) {
135 t += off;
136 if (result32 && (t < BIT64(32))) {
137 return ((uint32_t)t) / (from_hz / to_hz);
138 } else {
139 return t / ((uint64_t)from_hz / to_hz);
140 }
141 } else if (mul_ratio) {
142 if (result32) {
143 return ((uint32_t)t) * (to_hz / from_hz);
144 } else {
145 return t * ((uint64_t)to_hz / from_hz);
146 }
147 } else {
148 if (result32) {
149 return (uint32_t)((t * to_hz + off) / from_hz);
150 } else if (const_hz && Z_TMCVT_USE_FAST_ALGO(from_hz, to_hz)) {
151 /* Faster algorithm but source is first multiplied by target frequency
152 * and it can overflow even though final result would not overflow.
153 * Kconfig option shall prevent use of this algorithm when there is a
154 * risk of overflow.
155 */
156 return ((t * to_hz + off) / from_hz);
157 } else {
158 /* Slower algorithm but input is first divided before being multiplied
159 * which prevents overflow of intermediate value.
160 */
161 return (t / from_hz) * to_hz + ((t % from_hz) * to_hz + off) / from_hz;
162 }
163 }
164 }
165
166 /* The following code is programmatically generated using this perl
167 * code, which enumerates all possible combinations of units, rounding
168 * modes and precision. Do not edit directly.
169 *
170 * Note that nano/microsecond conversions are only defined with 64 bit
171 * precision. These units conversions were not available in 32 bit
172 * variants historically, and doing 32 bit math with units that small
173 * has precision traps that we probably don't want to support in an
174 * official API.
175 *
176 * #!/usr/bin/perl -w
177 * use strict;
178 *
179 * my %human = ("ms" => "milliseconds",
180 * "us" => "microseconds",
181 * "ns" => "nanoseconds",
182 * "cyc" => "hardware cycles",
183 * "ticks" => "ticks");
184 *
185 * sub big { return $_[0] eq "us" || $_[0] eq "ns"; }
186 * sub prefix { return $_[0] eq "ms" || $_[0] eq "us" || $_[0] eq "ns"; }
187 *
188 * for my $from_unit ("ms", "us", "ns", "cyc", "ticks") {
189 * for my $to_unit ("ms", "us", "ns", "cyc", "ticks") {
190 * next if $from_unit eq $to_unit;
191 * next if prefix($from_unit) && prefix($to_unit);
192 * for my $round ("floor", "near", "ceil") {
193 * for(my $big=0; $big <= 1; $big++) {
194 * my $sz = $big ? 64 : 32;
195 * my $sym = "k_${from_unit}_to_${to_unit}_$round$sz";
196 * my $type = "u${sz}_t";
197 * my $const_hz = ($from_unit eq "cyc" || $to_unit eq "cyc")
198 * ? "Z_CCYC" : "true";
199 * my $ret32 = $big ? "false" : "true";
200 * my $rup = $round eq "ceil" ? "true" : "false";
201 * my $roff = $round eq "near" ? "true" : "false";
202 *
203 * my $hfrom = $human{$from_unit};
204 * my $hto = $human{$to_unit};
205 * print "/", "** \@brief Convert $hfrom to $hto\n";
206 * print " *\n";
207 * print " * Converts time values in $hfrom to $hto.\n";
208 * print " * Computes result in $sz bit precision.\n";
209 * if ($round eq "ceil") {
210 * print " * Rounds up to the next highest output unit.\n";
211 * } elsif ($round eq "near") {
212 * print " * Rounds to the nearest output unit.\n";
213 * } else {
214 * print " * Truncates to the next lowest output unit.\n";
215 * }
216 * print " *\n";
217 * print " * \@return The converted time value\n";
218 * print " *", "/\n";
219 *
220 * print "static TIME_CONSTEXPR inline $type $sym($type t)\n{\n\t";
221 * print "/", "* Generated. Do not edit. See above. *", "/\n\t";
222 * print "return z_tmcvt(t, Z_HZ_$from_unit, Z_HZ_$to_unit,";
223 * print " $const_hz, $ret32, $rup, $roff);\n";
224 * print "}\n\n";
225 * }
226 * }
227 * }
228 * }
229 */
230
231 /* Some more concise declarations to simplify the generator script and
232 * save bytes below
233 */
234 #define Z_HZ_ms 1000
235 #define Z_HZ_us 1000000
236 #define Z_HZ_ns 1000000000
237 #define Z_HZ_cyc sys_clock_hw_cycles_per_sec()
238 #define Z_HZ_ticks CONFIG_SYS_CLOCK_TICKS_PER_SEC
239 #define Z_CCYC (!IS_ENABLED(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME))
240
241 /** @brief Convert milliseconds to hardware cycles
242 *
243 * Converts time values in milliseconds to hardware cycles.
244 * Computes result in 32 bit precision.
245 * Truncates to the next lowest output unit.
246 *
247 * @return The converted time value
248 */
k_ms_to_cyc_floor32(uint32_t t)249 static TIME_CONSTEXPR inline uint32_t k_ms_to_cyc_floor32(uint32_t t)
250 {
251 /* Generated. Do not edit. See above. */
252 return z_tmcvt(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, true, false, false);
253 }
254
255 /** @brief Convert milliseconds to hardware cycles
256 *
257 * Converts time values in milliseconds to hardware cycles.
258 * Computes result in 64 bit precision.
259 * Truncates to the next lowest output unit.
260 *
261 * @return The converted time value
262 */
k_ms_to_cyc_floor64(uint64_t t)263 static TIME_CONSTEXPR inline uint64_t k_ms_to_cyc_floor64(uint64_t t)
264 {
265 /* Generated. Do not edit. See above. */
266 return z_tmcvt(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, false, false, false);
267 }
268
269 /** @brief Convert milliseconds to hardware cycles
270 *
271 * Converts time values in milliseconds to hardware cycles.
272 * Computes result in 32 bit precision.
273 * Rounds to the nearest output unit.
274 *
275 * @return The converted time value
276 */
k_ms_to_cyc_near32(uint32_t t)277 static TIME_CONSTEXPR inline uint32_t k_ms_to_cyc_near32(uint32_t t)
278 {
279 /* Generated. Do not edit. See above. */
280 return z_tmcvt(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, true, false, true);
281 }
282
283 /** @brief Convert milliseconds to hardware cycles
284 *
285 * Converts time values in milliseconds to hardware cycles.
286 * Computes result in 64 bit precision.
287 * Rounds to the nearest output unit.
288 *
289 * @return The converted time value
290 */
k_ms_to_cyc_near64(uint64_t t)291 static TIME_CONSTEXPR inline uint64_t k_ms_to_cyc_near64(uint64_t t)
292 {
293 /* Generated. Do not edit. See above. */
294 return z_tmcvt(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, false, false, true);
295 }
296
297 /** @brief Convert milliseconds to hardware cycles
298 *
299 * Converts time values in milliseconds to hardware cycles.
300 * Computes result in 32 bit precision.
301 * Rounds up to the next highest output unit.
302 *
303 * @return The converted time value
304 */
k_ms_to_cyc_ceil32(uint32_t t)305 static TIME_CONSTEXPR inline uint32_t k_ms_to_cyc_ceil32(uint32_t t)
306 {
307 /* Generated. Do not edit. See above. */
308 return z_tmcvt(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, true, true, false);
309 }
310
311 /** @brief Convert milliseconds to hardware cycles
312 *
313 * Converts time values in milliseconds to hardware cycles.
314 * Computes result in 64 bit precision.
315 * Rounds up to the next highest output unit.
316 *
317 * @return The converted time value
318 */
k_ms_to_cyc_ceil64(uint64_t t)319 static TIME_CONSTEXPR inline uint64_t k_ms_to_cyc_ceil64(uint64_t t)
320 {
321 /* Generated. Do not edit. See above. */
322 return z_tmcvt(t, Z_HZ_ms, Z_HZ_cyc, Z_CCYC, false, true, false);
323 }
324
325 /** @brief Convert milliseconds to ticks
326 *
327 * Converts time values in milliseconds to ticks.
328 * Computes result in 32 bit precision.
329 * Truncates to the next lowest output unit.
330 *
331 * @return The converted time value
332 */
k_ms_to_ticks_floor32(uint32_t t)333 static TIME_CONSTEXPR inline uint32_t k_ms_to_ticks_floor32(uint32_t t)
334 {
335 /* Generated. Do not edit. See above. */
336 return z_tmcvt(t, Z_HZ_ms, Z_HZ_ticks, true, true, false, false);
337 }
338
339 /** @brief Convert milliseconds to ticks
340 *
341 * Converts time values in milliseconds to ticks.
342 * Computes result in 64 bit precision.
343 * Truncates to the next lowest output unit.
344 *
345 * @return The converted time value
346 */
k_ms_to_ticks_floor64(uint64_t t)347 static TIME_CONSTEXPR inline uint64_t k_ms_to_ticks_floor64(uint64_t t)
348 {
349 /* Generated. Do not edit. See above. */
350 return z_tmcvt(t, Z_HZ_ms, Z_HZ_ticks, true, false, false, false);
351 }
352
353 /** @brief Convert milliseconds to ticks
354 *
355 * Converts time values in milliseconds to ticks.
356 * Computes result in 32 bit precision.
357 * Rounds to the nearest output unit.
358 *
359 * @return The converted time value
360 */
k_ms_to_ticks_near32(uint32_t t)361 static TIME_CONSTEXPR inline uint32_t k_ms_to_ticks_near32(uint32_t t)
362 {
363 /* Generated. Do not edit. See above. */
364 return z_tmcvt(t, Z_HZ_ms, Z_HZ_ticks, true, true, false, true);
365 }
366
367 /** @brief Convert milliseconds to ticks
368 *
369 * Converts time values in milliseconds to ticks.
370 * Computes result in 64 bit precision.
371 * Rounds to the nearest output unit.
372 *
373 * @return The converted time value
374 */
k_ms_to_ticks_near64(uint64_t t)375 static TIME_CONSTEXPR inline uint64_t k_ms_to_ticks_near64(uint64_t t)
376 {
377 /* Generated. Do not edit. See above. */
378 return z_tmcvt(t, Z_HZ_ms, Z_HZ_ticks, true, false, false, true);
379 }
380
381 /** @brief Convert milliseconds to ticks
382 *
383 * Converts time values in milliseconds to ticks.
384 * Computes result in 32 bit precision.
385 * Rounds up to the next highest output unit.
386 *
387 * @return The converted time value
388 */
k_ms_to_ticks_ceil32(uint32_t t)389 static TIME_CONSTEXPR inline uint32_t k_ms_to_ticks_ceil32(uint32_t t)
390 {
391 /* Generated. Do not edit. See above. */
392 return z_tmcvt(t, Z_HZ_ms, Z_HZ_ticks, true, true, true, false);
393 }
394
395 /** @brief Convert milliseconds to ticks
396 *
397 * Converts time values in milliseconds to ticks.
398 * Computes result in 64 bit precision.
399 * Rounds up to the next highest output unit.
400 *
401 * @return The converted time value
402 */
k_ms_to_ticks_ceil64(uint64_t t)403 static TIME_CONSTEXPR inline uint64_t k_ms_to_ticks_ceil64(uint64_t t)
404 {
405 /* Generated. Do not edit. See above. */
406 return z_tmcvt(t, Z_HZ_ms, Z_HZ_ticks, true, false, true, false);
407 }
408
409 /** @brief Convert microseconds to hardware cycles
410 *
411 * Converts time values in microseconds to hardware cycles.
412 * Computes result in 32 bit precision.
413 * Truncates to the next lowest output unit.
414 *
415 * @return The converted time value
416 */
k_us_to_cyc_floor32(uint32_t t)417 static TIME_CONSTEXPR inline uint32_t k_us_to_cyc_floor32(uint32_t t)
418 {
419 /* Generated. Do not edit. See above. */
420 return z_tmcvt(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, true, false, false);
421 }
422
423 /** @brief Convert microseconds to hardware cycles
424 *
425 * Converts time values in microseconds to hardware cycles.
426 * Computes result in 64 bit precision.
427 * Truncates to the next lowest output unit.
428 *
429 * @return The converted time value
430 */
k_us_to_cyc_floor64(uint64_t t)431 static TIME_CONSTEXPR inline uint64_t k_us_to_cyc_floor64(uint64_t t)
432 {
433 /* Generated. Do not edit. See above. */
434 return z_tmcvt(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, false, false, false);
435 }
436
437 /** @brief Convert microseconds to hardware cycles
438 *
439 * Converts time values in microseconds to hardware cycles.
440 * Computes result in 32 bit precision.
441 * Rounds to the nearest output unit.
442 *
443 * @return The converted time value
444 */
k_us_to_cyc_near32(uint32_t t)445 static TIME_CONSTEXPR inline uint32_t k_us_to_cyc_near32(uint32_t t)
446 {
447 /* Generated. Do not edit. See above. */
448 return z_tmcvt(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, true, false, true);
449 }
450
451 /** @brief Convert microseconds to hardware cycles
452 *
453 * Converts time values in microseconds to hardware cycles.
454 * Computes result in 64 bit precision.
455 * Rounds to the nearest output unit.
456 *
457 * @return The converted time value
458 */
k_us_to_cyc_near64(uint64_t t)459 static TIME_CONSTEXPR inline uint64_t k_us_to_cyc_near64(uint64_t t)
460 {
461 /* Generated. Do not edit. See above. */
462 return z_tmcvt(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, false, false, true);
463 }
464
465 /** @brief Convert microseconds to hardware cycles
466 *
467 * Converts time values in microseconds to hardware cycles.
468 * Computes result in 32 bit precision.
469 * Rounds up to the next highest output unit.
470 *
471 * @return The converted time value
472 */
k_us_to_cyc_ceil32(uint32_t t)473 static TIME_CONSTEXPR inline uint32_t k_us_to_cyc_ceil32(uint32_t t)
474 {
475 /* Generated. Do not edit. See above. */
476 return z_tmcvt(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, true, true, false);
477 }
478
479 /** @brief Convert microseconds to hardware cycles
480 *
481 * Converts time values in microseconds to hardware cycles.
482 * Computes result in 64 bit precision.
483 * Rounds up to the next highest output unit.
484 *
485 * @return The converted time value
486 */
k_us_to_cyc_ceil64(uint64_t t)487 static TIME_CONSTEXPR inline uint64_t k_us_to_cyc_ceil64(uint64_t t)
488 {
489 /* Generated. Do not edit. See above. */
490 return z_tmcvt(t, Z_HZ_us, Z_HZ_cyc, Z_CCYC, false, true, false);
491 }
492
493 /** @brief Convert microseconds to ticks
494 *
495 * Converts time values in microseconds to ticks.
496 * Computes result in 32 bit precision.
497 * Truncates to the next lowest output unit.
498 *
499 * @return The converted time value
500 */
k_us_to_ticks_floor32(uint32_t t)501 static TIME_CONSTEXPR inline uint32_t k_us_to_ticks_floor32(uint32_t t)
502 {
503 /* Generated. Do not edit. See above. */
504 return z_tmcvt(t, Z_HZ_us, Z_HZ_ticks, true, true, false, false);
505 }
506
507 /** @brief Convert microseconds to ticks
508 *
509 * Converts time values in microseconds to ticks.
510 * Computes result in 64 bit precision.
511 * Truncates to the next lowest output unit.
512 *
513 * @return The converted time value
514 */
k_us_to_ticks_floor64(uint64_t t)515 static TIME_CONSTEXPR inline uint64_t k_us_to_ticks_floor64(uint64_t t)
516 {
517 /* Generated. Do not edit. See above. */
518 return z_tmcvt(t, Z_HZ_us, Z_HZ_ticks, true, false, false, false);
519 }
520
521 /** @brief Convert microseconds to ticks
522 *
523 * Converts time values in microseconds to ticks.
524 * Computes result in 32 bit precision.
525 * Rounds to the nearest output unit.
526 *
527 * @return The converted time value
528 */
k_us_to_ticks_near32(uint32_t t)529 static TIME_CONSTEXPR inline uint32_t k_us_to_ticks_near32(uint32_t t)
530 {
531 /* Generated. Do not edit. See above. */
532 return z_tmcvt(t, Z_HZ_us, Z_HZ_ticks, true, true, false, true);
533 }
534
535 /** @brief Convert microseconds to ticks
536 *
537 * Converts time values in microseconds to ticks.
538 * Computes result in 64 bit precision.
539 * Rounds to the nearest output unit.
540 *
541 * @return The converted time value
542 */
k_us_to_ticks_near64(uint64_t t)543 static TIME_CONSTEXPR inline uint64_t k_us_to_ticks_near64(uint64_t t)
544 {
545 /* Generated. Do not edit. See above. */
546 return z_tmcvt(t, Z_HZ_us, Z_HZ_ticks, true, false, false, true);
547 }
548
549 /** @brief Convert microseconds to ticks
550 *
551 * Converts time values in microseconds to ticks.
552 * Computes result in 32 bit precision.
553 * Rounds up to the next highest output unit.
554 *
555 * @return The converted time value
556 */
k_us_to_ticks_ceil32(uint32_t t)557 static TIME_CONSTEXPR inline uint32_t k_us_to_ticks_ceil32(uint32_t t)
558 {
559 /* Generated. Do not edit. See above. */
560 return z_tmcvt(t, Z_HZ_us, Z_HZ_ticks, true, true, true, false);
561 }
562
563 /** @brief Convert microseconds to ticks
564 *
565 * Converts time values in microseconds to ticks.
566 * Computes result in 64 bit precision.
567 * Rounds up to the next highest output unit.
568 *
569 * @return The converted time value
570 */
k_us_to_ticks_ceil64(uint64_t t)571 static TIME_CONSTEXPR inline uint64_t k_us_to_ticks_ceil64(uint64_t t)
572 {
573 /* Generated. Do not edit. See above. */
574 return z_tmcvt(t, Z_HZ_us, Z_HZ_ticks, true, false, true, false);
575 }
576
577 /** @brief Convert nanoseconds to hardware cycles
578 *
579 * Converts time values in nanoseconds to hardware cycles.
580 * Computes result in 32 bit precision.
581 * Truncates to the next lowest output unit.
582 *
583 * @return The converted time value
584 */
k_ns_to_cyc_floor32(uint32_t t)585 static TIME_CONSTEXPR inline uint32_t k_ns_to_cyc_floor32(uint32_t t)
586 {
587 /* Generated. Do not edit. See above. */
588 return z_tmcvt(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, true, false, false);
589 }
590
591 /** @brief Convert nanoseconds to hardware cycles
592 *
593 * Converts time values in nanoseconds to hardware cycles.
594 * Computes result in 64 bit precision.
595 * Truncates to the next lowest output unit.
596 *
597 * @return The converted time value
598 */
k_ns_to_cyc_floor64(uint64_t t)599 static TIME_CONSTEXPR inline uint64_t k_ns_to_cyc_floor64(uint64_t t)
600 {
601 /* Generated. Do not edit. See above. */
602 return z_tmcvt(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, false, false, false);
603 }
604
605 /** @brief Convert nanoseconds to hardware cycles
606 *
607 * Converts time values in nanoseconds to hardware cycles.
608 * Computes result in 32 bit precision.
609 * Rounds to the nearest output unit.
610 *
611 * @return The converted time value
612 */
k_ns_to_cyc_near32(uint32_t t)613 static TIME_CONSTEXPR inline uint32_t k_ns_to_cyc_near32(uint32_t t)
614 {
615 /* Generated. Do not edit. See above. */
616 return z_tmcvt(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, true, false, true);
617 }
618
619 /** @brief Convert nanoseconds to hardware cycles
620 *
621 * Converts time values in nanoseconds to hardware cycles.
622 * Computes result in 64 bit precision.
623 * Rounds to the nearest output unit.
624 *
625 * @return The converted time value
626 */
k_ns_to_cyc_near64(uint64_t t)627 static TIME_CONSTEXPR inline uint64_t k_ns_to_cyc_near64(uint64_t t)
628 {
629 /* Generated. Do not edit. See above. */
630 return z_tmcvt(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, false, false, true);
631 }
632
633 /** @brief Convert nanoseconds to hardware cycles
634 *
635 * Converts time values in nanoseconds to hardware cycles.
636 * Computes result in 32 bit precision.
637 * Rounds up to the next highest output unit.
638 *
639 * @return The converted time value
640 */
k_ns_to_cyc_ceil32(uint32_t t)641 static TIME_CONSTEXPR inline uint32_t k_ns_to_cyc_ceil32(uint32_t t)
642 {
643 /* Generated. Do not edit. See above. */
644 return z_tmcvt(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, true, true, false);
645 }
646
647 /** @brief Convert nanoseconds to hardware cycles
648 *
649 * Converts time values in nanoseconds to hardware cycles.
650 * Computes result in 64 bit precision.
651 * Rounds up to the next highest output unit.
652 *
653 * @return The converted time value
654 */
k_ns_to_cyc_ceil64(uint64_t t)655 static TIME_CONSTEXPR inline uint64_t k_ns_to_cyc_ceil64(uint64_t t)
656 {
657 /* Generated. Do not edit. See above. */
658 return z_tmcvt(t, Z_HZ_ns, Z_HZ_cyc, Z_CCYC, false, true, false);
659 }
660
661 /** @brief Convert nanoseconds to ticks
662 *
663 * Converts time values in nanoseconds to ticks.
664 * Computes result in 32 bit precision.
665 * Truncates to the next lowest output unit.
666 *
667 * @return The converted time value
668 */
k_ns_to_ticks_floor32(uint32_t t)669 static TIME_CONSTEXPR inline uint32_t k_ns_to_ticks_floor32(uint32_t t)
670 {
671 /* Generated. Do not edit. See above. */
672 return z_tmcvt(t, Z_HZ_ns, Z_HZ_ticks, true, true, false, false);
673 }
674
675 /** @brief Convert nanoseconds to ticks
676 *
677 * Converts time values in nanoseconds to ticks.
678 * Computes result in 64 bit precision.
679 * Truncates to the next lowest output unit.
680 *
681 * @return The converted time value
682 */
k_ns_to_ticks_floor64(uint64_t t)683 static TIME_CONSTEXPR inline uint64_t k_ns_to_ticks_floor64(uint64_t t)
684 {
685 /* Generated. Do not edit. See above. */
686 return z_tmcvt(t, Z_HZ_ns, Z_HZ_ticks, true, false, false, false);
687 }
688
689 /** @brief Convert nanoseconds to ticks
690 *
691 * Converts time values in nanoseconds to ticks.
692 * Computes result in 32 bit precision.
693 * Rounds to the nearest output unit.
694 *
695 * @return The converted time value
696 */
k_ns_to_ticks_near32(uint32_t t)697 static TIME_CONSTEXPR inline uint32_t k_ns_to_ticks_near32(uint32_t t)
698 {
699 /* Generated. Do not edit. See above. */
700 return z_tmcvt(t, Z_HZ_ns, Z_HZ_ticks, true, true, false, true);
701 }
702
703 /** @brief Convert nanoseconds to ticks
704 *
705 * Converts time values in nanoseconds to ticks.
706 * Computes result in 64 bit precision.
707 * Rounds to the nearest output unit.
708 *
709 * @return The converted time value
710 */
k_ns_to_ticks_near64(uint64_t t)711 static TIME_CONSTEXPR inline uint64_t k_ns_to_ticks_near64(uint64_t t)
712 {
713 /* Generated. Do not edit. See above. */
714 return z_tmcvt(t, Z_HZ_ns, Z_HZ_ticks, true, false, false, true);
715 }
716
717 /** @brief Convert nanoseconds to ticks
718 *
719 * Converts time values in nanoseconds to ticks.
720 * Computes result in 32 bit precision.
721 * Rounds up to the next highest output unit.
722 *
723 * @return The converted time value
724 */
k_ns_to_ticks_ceil32(uint32_t t)725 static TIME_CONSTEXPR inline uint32_t k_ns_to_ticks_ceil32(uint32_t t)
726 {
727 /* Generated. Do not edit. See above. */
728 return z_tmcvt(t, Z_HZ_ns, Z_HZ_ticks, true, true, true, false);
729 }
730
731 /** @brief Convert nanoseconds to ticks
732 *
733 * Converts time values in nanoseconds to ticks.
734 * Computes result in 64 bit precision.
735 * Rounds up to the next highest output unit.
736 *
737 * @return The converted time value
738 */
k_ns_to_ticks_ceil64(uint64_t t)739 static TIME_CONSTEXPR inline uint64_t k_ns_to_ticks_ceil64(uint64_t t)
740 {
741 /* Generated. Do not edit. See above. */
742 return z_tmcvt(t, Z_HZ_ns, Z_HZ_ticks, true, false, true, false);
743 }
744
745 /** @brief Convert hardware cycles to milliseconds
746 *
747 * Converts time values in hardware cycles to milliseconds.
748 * Computes result in 32 bit precision.
749 * Truncates to the next lowest output unit.
750 *
751 * @return The converted time value
752 */
k_cyc_to_ms_floor32(uint32_t t)753 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ms_floor32(uint32_t t)
754 {
755 /* Generated. Do not edit. See above. */
756 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, true, false, false);
757 }
758
759 /** @brief Convert hardware cycles to milliseconds
760 *
761 * Converts time values in hardware cycles to milliseconds.
762 * Computes result in 64 bit precision.
763 * Truncates to the next lowest output unit.
764 *
765 * @return The converted time value
766 */
k_cyc_to_ms_floor64(uint64_t t)767 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ms_floor64(uint64_t t)
768 {
769 /* Generated. Do not edit. See above. */
770 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, false, false, false);
771 }
772
773 /** @brief Convert hardware cycles to milliseconds
774 *
775 * Converts time values in hardware cycles to milliseconds.
776 * Computes result in 32 bit precision.
777 * Rounds to the nearest output unit.
778 *
779 * @return The converted time value
780 */
k_cyc_to_ms_near32(uint32_t t)781 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ms_near32(uint32_t t)
782 {
783 /* Generated. Do not edit. See above. */
784 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, true, false, true);
785 }
786
787 /** @brief Convert hardware cycles to milliseconds
788 *
789 * Converts time values in hardware cycles to milliseconds.
790 * Computes result in 64 bit precision.
791 * Rounds to the nearest output unit.
792 *
793 * @return The converted time value
794 */
k_cyc_to_ms_near64(uint64_t t)795 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ms_near64(uint64_t t)
796 {
797 /* Generated. Do not edit. See above. */
798 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, false, false, true);
799 }
800
801 /** @brief Convert hardware cycles to milliseconds
802 *
803 * Converts time values in hardware cycles to milliseconds.
804 * Computes result in 32 bit precision.
805 * Rounds up to the next highest output unit.
806 *
807 * @return The converted time value
808 */
k_cyc_to_ms_ceil32(uint32_t t)809 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ms_ceil32(uint32_t t)
810 {
811 /* Generated. Do not edit. See above. */
812 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, true, true, false);
813 }
814
815 /** @brief Convert hardware cycles to milliseconds
816 *
817 * Converts time values in hardware cycles to milliseconds.
818 * Computes result in 64 bit precision.
819 * Rounds up to the next highest output unit.
820 *
821 * @return The converted time value
822 */
k_cyc_to_ms_ceil64(uint64_t t)823 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ms_ceil64(uint64_t t)
824 {
825 /* Generated. Do not edit. See above. */
826 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ms, Z_CCYC, false, true, false);
827 }
828
829 /** @brief Convert hardware cycles to microseconds
830 *
831 * Converts time values in hardware cycles to microseconds.
832 * Computes result in 32 bit precision.
833 * Truncates to the next lowest output unit.
834 *
835 * @return The converted time value
836 */
k_cyc_to_us_floor32(uint32_t t)837 static TIME_CONSTEXPR inline uint32_t k_cyc_to_us_floor32(uint32_t t)
838 {
839 /* Generated. Do not edit. See above. */
840 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, true, false, false);
841 }
842
843 /** @brief Convert hardware cycles to microseconds
844 *
845 * Converts time values in hardware cycles to microseconds.
846 * Computes result in 64 bit precision.
847 * Truncates to the next lowest output unit.
848 *
849 * @return The converted time value
850 */
k_cyc_to_us_floor64(uint64_t t)851 static TIME_CONSTEXPR inline uint64_t k_cyc_to_us_floor64(uint64_t t)
852 {
853 /* Generated. Do not edit. See above. */
854 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, false, false, false);
855 }
856
857 /** @brief Convert hardware cycles to microseconds
858 *
859 * Converts time values in hardware cycles to microseconds.
860 * Computes result in 32 bit precision.
861 * Rounds to the nearest output unit.
862 *
863 * @return The converted time value
864 */
k_cyc_to_us_near32(uint32_t t)865 static TIME_CONSTEXPR inline uint32_t k_cyc_to_us_near32(uint32_t t)
866 {
867 /* Generated. Do not edit. See above. */
868 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, true, false, true);
869 }
870
871 /** @brief Convert hardware cycles to microseconds
872 *
873 * Converts time values in hardware cycles to microseconds.
874 * Computes result in 64 bit precision.
875 * Rounds to the nearest output unit.
876 *
877 * @return The converted time value
878 */
k_cyc_to_us_near64(uint64_t t)879 static TIME_CONSTEXPR inline uint64_t k_cyc_to_us_near64(uint64_t t)
880 {
881 /* Generated. Do not edit. See above. */
882 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, false, false, true);
883 }
884
885 /** @brief Convert hardware cycles to microseconds
886 *
887 * Converts time values in hardware cycles to microseconds.
888 * Computes result in 32 bit precision.
889 * Rounds up to the next highest output unit.
890 *
891 * @return The converted time value
892 */
k_cyc_to_us_ceil32(uint32_t t)893 static TIME_CONSTEXPR inline uint32_t k_cyc_to_us_ceil32(uint32_t t)
894 {
895 /* Generated. Do not edit. See above. */
896 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, true, true, false);
897 }
898
899 /** @brief Convert hardware cycles to microseconds
900 *
901 * Converts time values in hardware cycles to microseconds.
902 * Computes result in 64 bit precision.
903 * Rounds up to the next highest output unit.
904 *
905 * @return The converted time value
906 */
k_cyc_to_us_ceil64(uint64_t t)907 static TIME_CONSTEXPR inline uint64_t k_cyc_to_us_ceil64(uint64_t t)
908 {
909 /* Generated. Do not edit. See above. */
910 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_us, Z_CCYC, false, true, false);
911 }
912
913 /** @brief Convert hardware cycles to nanoseconds
914 *
915 * Converts time values in hardware cycles to nanoseconds.
916 * Computes result in 32 bit precision.
917 * Truncates to the next lowest output unit.
918 *
919 * @return The converted time value
920 */
k_cyc_to_ns_floor32(uint32_t t)921 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ns_floor32(uint32_t t)
922 {
923 /* Generated. Do not edit. See above. */
924 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, true, false, false);
925 }
926
927 /** @brief Convert hardware cycles to nanoseconds
928 *
929 * Converts time values in hardware cycles to nanoseconds.
930 * Computes result in 64 bit precision.
931 * Truncates to the next lowest output unit.
932 *
933 * @return The converted time value
934 */
k_cyc_to_ns_floor64(uint64_t t)935 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ns_floor64(uint64_t t)
936 {
937 /* Generated. Do not edit. See above. */
938 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, false, false, false);
939 }
940
941 /** @brief Convert hardware cycles to nanoseconds
942 *
943 * Converts time values in hardware cycles to nanoseconds.
944 * Computes result in 32 bit precision.
945 * Rounds to the nearest output unit.
946 *
947 * @return The converted time value
948 */
k_cyc_to_ns_near32(uint32_t t)949 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ns_near32(uint32_t t)
950 {
951 /* Generated. Do not edit. See above. */
952 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, true, false, true);
953 }
954
955 /** @brief Convert hardware cycles to nanoseconds
956 *
957 * Converts time values in hardware cycles to nanoseconds.
958 * Computes result in 64 bit precision.
959 * Rounds to the nearest output unit.
960 *
961 * @return The converted time value
962 */
k_cyc_to_ns_near64(uint64_t t)963 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ns_near64(uint64_t t)
964 {
965 /* Generated. Do not edit. See above. */
966 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, false, false, true);
967 }
968
969 /** @brief Convert hardware cycles to nanoseconds
970 *
971 * Converts time values in hardware cycles to nanoseconds.
972 * Computes result in 32 bit precision.
973 * Rounds up to the next highest output unit.
974 *
975 * @return The converted time value
976 */
k_cyc_to_ns_ceil32(uint32_t t)977 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ns_ceil32(uint32_t t)
978 {
979 /* Generated. Do not edit. See above. */
980 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, true, true, false);
981 }
982
983 /** @brief Convert hardware cycles to nanoseconds
984 *
985 * Converts time values in hardware cycles to nanoseconds.
986 * Computes result in 64 bit precision.
987 * Rounds up to the next highest output unit.
988 *
989 * @return The converted time value
990 */
k_cyc_to_ns_ceil64(uint64_t t)991 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ns_ceil64(uint64_t t)
992 {
993 /* Generated. Do not edit. See above. */
994 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ns, Z_CCYC, false, true, false);
995 }
996
997 /** @brief Convert hardware cycles to ticks
998 *
999 * Converts time values in hardware cycles to ticks.
1000 * Computes result in 32 bit precision.
1001 * Truncates to the next lowest output unit.
1002 *
1003 * @return The converted time value
1004 */
k_cyc_to_ticks_floor32(uint32_t t)1005 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ticks_floor32(uint32_t t)
1006 {
1007 /* Generated. Do not edit. See above. */
1008 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, true, false, false);
1009 }
1010
1011 /** @brief Convert hardware cycles to ticks
1012 *
1013 * Converts time values in hardware cycles to ticks.
1014 * Computes result in 64 bit precision.
1015 * Truncates to the next lowest output unit.
1016 *
1017 * @return The converted time value
1018 */
k_cyc_to_ticks_floor64(uint64_t t)1019 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ticks_floor64(uint64_t t)
1020 {
1021 /* Generated. Do not edit. See above. */
1022 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, false, false, false);
1023 }
1024
1025 /** @brief Convert hardware cycles to ticks
1026 *
1027 * Converts time values in hardware cycles to ticks.
1028 * Computes result in 32 bit precision.
1029 * Rounds to the nearest output unit.
1030 *
1031 * @return The converted time value
1032 */
k_cyc_to_ticks_near32(uint32_t t)1033 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ticks_near32(uint32_t t)
1034 {
1035 /* Generated. Do not edit. See above. */
1036 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, true, false, true);
1037 }
1038
1039 /** @brief Convert hardware cycles to ticks
1040 *
1041 * Converts time values in hardware cycles to ticks.
1042 * Computes result in 64 bit precision.
1043 * Rounds to the nearest output unit.
1044 *
1045 * @return The converted time value
1046 */
k_cyc_to_ticks_near64(uint64_t t)1047 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ticks_near64(uint64_t t)
1048 {
1049 /* Generated. Do not edit. See above. */
1050 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, false, false, true);
1051 }
1052
1053 /** @brief Convert hardware cycles to ticks
1054 *
1055 * Converts time values in hardware cycles to ticks.
1056 * Computes result in 32 bit precision.
1057 * Rounds up to the next highest output unit.
1058 *
1059 * @return The converted time value
1060 */
k_cyc_to_ticks_ceil32(uint32_t t)1061 static TIME_CONSTEXPR inline uint32_t k_cyc_to_ticks_ceil32(uint32_t t)
1062 {
1063 /* Generated. Do not edit. See above. */
1064 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, true, true, false);
1065 }
1066
1067 /** @brief Convert hardware cycles to ticks
1068 *
1069 * Converts time values in hardware cycles to ticks.
1070 * Computes result in 64 bit precision.
1071 * Rounds up to the next highest output unit.
1072 *
1073 * @return The converted time value
1074 */
k_cyc_to_ticks_ceil64(uint64_t t)1075 static TIME_CONSTEXPR inline uint64_t k_cyc_to_ticks_ceil64(uint64_t t)
1076 {
1077 /* Generated. Do not edit. See above. */
1078 return z_tmcvt(t, Z_HZ_cyc, Z_HZ_ticks, Z_CCYC, false, true, false);
1079 }
1080
1081 /** @brief Convert ticks to milliseconds
1082 *
1083 * Converts time values in ticks to milliseconds.
1084 * Computes result in 32 bit precision.
1085 * Truncates to the next lowest output unit.
1086 *
1087 * @return The converted time value
1088 */
k_ticks_to_ms_floor32(uint32_t t)1089 static TIME_CONSTEXPR inline uint32_t k_ticks_to_ms_floor32(uint32_t t)
1090 {
1091 /* Generated. Do not edit. See above. */
1092 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ms, true, true, false, false);
1093 }
1094
1095 /** @brief Convert ticks to milliseconds
1096 *
1097 * Converts time values in ticks to milliseconds.
1098 * Computes result in 64 bit precision.
1099 * Truncates to the next lowest output unit.
1100 *
1101 * @return The converted time value
1102 */
k_ticks_to_ms_floor64(uint64_t t)1103 static TIME_CONSTEXPR inline uint64_t k_ticks_to_ms_floor64(uint64_t t)
1104 {
1105 /* Generated. Do not edit. See above. */
1106 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ms, true, false, false, false);
1107 }
1108
1109 /** @brief Convert ticks to milliseconds
1110 *
1111 * Converts time values in ticks to milliseconds.
1112 * Computes result in 32 bit precision.
1113 * Rounds to the nearest output unit.
1114 *
1115 * @return The converted time value
1116 */
k_ticks_to_ms_near32(uint32_t t)1117 static TIME_CONSTEXPR inline uint32_t k_ticks_to_ms_near32(uint32_t t)
1118 {
1119 /* Generated. Do not edit. See above. */
1120 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ms, true, true, false, true);
1121 }
1122
1123 /** @brief Convert ticks to milliseconds
1124 *
1125 * Converts time values in ticks to milliseconds.
1126 * Computes result in 64 bit precision.
1127 * Rounds to the nearest output unit.
1128 *
1129 * @return The converted time value
1130 */
k_ticks_to_ms_near64(uint64_t t)1131 static TIME_CONSTEXPR inline uint64_t k_ticks_to_ms_near64(uint64_t t)
1132 {
1133 /* Generated. Do not edit. See above. */
1134 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ms, true, false, false, true);
1135 }
1136
1137 /** @brief Convert ticks to milliseconds
1138 *
1139 * Converts time values in ticks to milliseconds.
1140 * Computes result in 32 bit precision.
1141 * Rounds up to the next highest output unit.
1142 *
1143 * @return The converted time value
1144 */
k_ticks_to_ms_ceil32(uint32_t t)1145 static TIME_CONSTEXPR inline uint32_t k_ticks_to_ms_ceil32(uint32_t t)
1146 {
1147 /* Generated. Do not edit. See above. */
1148 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ms, true, true, true, false);
1149 }
1150
1151 /** @brief Convert ticks to milliseconds
1152 *
1153 * Converts time values in ticks to milliseconds.
1154 * Computes result in 64 bit precision.
1155 * Rounds up to the next highest output unit.
1156 *
1157 * @return The converted time value
1158 */
k_ticks_to_ms_ceil64(uint64_t t)1159 static TIME_CONSTEXPR inline uint64_t k_ticks_to_ms_ceil64(uint64_t t)
1160 {
1161 /* Generated. Do not edit. See above. */
1162 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ms, true, false, true, false);
1163 }
1164
1165 /** @brief Convert ticks to microseconds
1166 *
1167 * Converts time values in ticks to microseconds.
1168 * Computes result in 32 bit precision.
1169 * Truncates to the next lowest output unit.
1170 *
1171 * @return The converted time value
1172 */
k_ticks_to_us_floor32(uint32_t t)1173 static TIME_CONSTEXPR inline uint32_t k_ticks_to_us_floor32(uint32_t t)
1174 {
1175 /* Generated. Do not edit. See above. */
1176 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_us, true, true, false, false);
1177 }
1178
1179 /** @brief Convert ticks to microseconds
1180 *
1181 * Converts time values in ticks to microseconds.
1182 * Computes result in 64 bit precision.
1183 * Truncates to the next lowest output unit.
1184 *
1185 * @return The converted time value
1186 */
k_ticks_to_us_floor64(uint64_t t)1187 static TIME_CONSTEXPR inline uint64_t k_ticks_to_us_floor64(uint64_t t)
1188 {
1189 /* Generated. Do not edit. See above. */
1190 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_us, true, false, false, false);
1191 }
1192
1193 /** @brief Convert ticks to microseconds
1194 *
1195 * Converts time values in ticks to microseconds.
1196 * Computes result in 32 bit precision.
1197 * Rounds to the nearest output unit.
1198 *
1199 * @return The converted time value
1200 */
k_ticks_to_us_near32(uint32_t t)1201 static TIME_CONSTEXPR inline uint32_t k_ticks_to_us_near32(uint32_t t)
1202 {
1203 /* Generated. Do not edit. See above. */
1204 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_us, true, true, false, true);
1205 }
1206
1207 /** @brief Convert ticks to microseconds
1208 *
1209 * Converts time values in ticks to microseconds.
1210 * Computes result in 64 bit precision.
1211 * Rounds to the nearest output unit.
1212 *
1213 * @return The converted time value
1214 */
k_ticks_to_us_near64(uint64_t t)1215 static TIME_CONSTEXPR inline uint64_t k_ticks_to_us_near64(uint64_t t)
1216 {
1217 /* Generated. Do not edit. See above. */
1218 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_us, true, false, false, true);
1219 }
1220
1221 /** @brief Convert ticks to microseconds
1222 *
1223 * Converts time values in ticks to microseconds.
1224 * Computes result in 32 bit precision.
1225 * Rounds up to the next highest output unit.
1226 *
1227 * @return The converted time value
1228 */
k_ticks_to_us_ceil32(uint32_t t)1229 static TIME_CONSTEXPR inline uint32_t k_ticks_to_us_ceil32(uint32_t t)
1230 {
1231 /* Generated. Do not edit. See above. */
1232 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_us, true, true, true, false);
1233 }
1234
1235 /** @brief Convert ticks to microseconds
1236 *
1237 * Converts time values in ticks to microseconds.
1238 * Computes result in 64 bit precision.
1239 * Rounds up to the next highest output unit.
1240 *
1241 * @return The converted time value
1242 */
k_ticks_to_us_ceil64(uint64_t t)1243 static TIME_CONSTEXPR inline uint64_t k_ticks_to_us_ceil64(uint64_t t)
1244 {
1245 /* Generated. Do not edit. See above. */
1246 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_us, true, false, true, false);
1247 }
1248
1249 /** @brief Convert ticks to nanoseconds
1250 *
1251 * Converts time values in ticks to nanoseconds.
1252 * Computes result in 32 bit precision.
1253 * Truncates to the next lowest output unit.
1254 *
1255 * @return The converted time value
1256 */
k_ticks_to_ns_floor32(uint32_t t)1257 static TIME_CONSTEXPR inline uint32_t k_ticks_to_ns_floor32(uint32_t t)
1258 {
1259 /* Generated. Do not edit. See above. */
1260 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ns, true, true, false, false);
1261 }
1262
1263 /** @brief Convert ticks to nanoseconds
1264 *
1265 * Converts time values in ticks to nanoseconds.
1266 * Computes result in 64 bit precision.
1267 * Truncates to the next lowest output unit.
1268 *
1269 * @return The converted time value
1270 */
k_ticks_to_ns_floor64(uint64_t t)1271 static TIME_CONSTEXPR inline uint64_t k_ticks_to_ns_floor64(uint64_t t)
1272 {
1273 /* Generated. Do not edit. See above. */
1274 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ns, true, false, false, false);
1275 }
1276
1277 /** @brief Convert ticks to nanoseconds
1278 *
1279 * Converts time values in ticks to nanoseconds.
1280 * Computes result in 32 bit precision.
1281 * Rounds to the nearest output unit.
1282 *
1283 * @return The converted time value
1284 */
k_ticks_to_ns_near32(uint32_t t)1285 static TIME_CONSTEXPR inline uint32_t k_ticks_to_ns_near32(uint32_t t)
1286 {
1287 /* Generated. Do not edit. See above. */
1288 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ns, true, true, false, true);
1289 }
1290
1291 /** @brief Convert ticks to nanoseconds
1292 *
1293 * Converts time values in ticks to nanoseconds.
1294 * Computes result in 64 bit precision.
1295 * Rounds to the nearest output unit.
1296 *
1297 * @return The converted time value
1298 */
k_ticks_to_ns_near64(uint64_t t)1299 static TIME_CONSTEXPR inline uint64_t k_ticks_to_ns_near64(uint64_t t)
1300 {
1301 /* Generated. Do not edit. See above. */
1302 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ns, true, false, false, true);
1303 }
1304
1305 /** @brief Convert ticks to nanoseconds
1306 *
1307 * Converts time values in ticks to nanoseconds.
1308 * Computes result in 32 bit precision.
1309 * Rounds up to the next highest output unit.
1310 *
1311 * @return The converted time value
1312 */
k_ticks_to_ns_ceil32(uint32_t t)1313 static TIME_CONSTEXPR inline uint32_t k_ticks_to_ns_ceil32(uint32_t t)
1314 {
1315 /* Generated. Do not edit. See above. */
1316 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ns, true, true, true, false);
1317 }
1318
1319 /** @brief Convert ticks to nanoseconds
1320 *
1321 * Converts time values in ticks to nanoseconds.
1322 * Computes result in 64 bit precision.
1323 * Rounds up to the next highest output unit.
1324 *
1325 * @return The converted time value
1326 */
k_ticks_to_ns_ceil64(uint64_t t)1327 static TIME_CONSTEXPR inline uint64_t k_ticks_to_ns_ceil64(uint64_t t)
1328 {
1329 /* Generated. Do not edit. See above. */
1330 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_ns, true, false, true, false);
1331 }
1332
1333 /** @brief Convert ticks to hardware cycles
1334 *
1335 * Converts time values in ticks to hardware cycles.
1336 * Computes result in 32 bit precision.
1337 * Truncates to the next lowest output unit.
1338 *
1339 * @return The converted time value
1340 */
k_ticks_to_cyc_floor32(uint32_t t)1341 static TIME_CONSTEXPR inline uint32_t k_ticks_to_cyc_floor32(uint32_t t)
1342 {
1343 /* Generated. Do not edit. See above. */
1344 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, true, false, false);
1345 }
1346
1347 /** @brief Convert ticks to hardware cycles
1348 *
1349 * Converts time values in ticks to hardware cycles.
1350 * Computes result in 64 bit precision.
1351 * Truncates to the next lowest output unit.
1352 *
1353 * @return The converted time value
1354 */
k_ticks_to_cyc_floor64(uint64_t t)1355 static TIME_CONSTEXPR inline uint64_t k_ticks_to_cyc_floor64(uint64_t t)
1356 {
1357 /* Generated. Do not edit. See above. */
1358 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, false, false, false);
1359 }
1360
1361 /** @brief Convert ticks to hardware cycles
1362 *
1363 * Converts time values in ticks to hardware cycles.
1364 * Computes result in 32 bit precision.
1365 * Rounds to the nearest output unit.
1366 *
1367 * @return The converted time value
1368 */
k_ticks_to_cyc_near32(uint32_t t)1369 static TIME_CONSTEXPR inline uint32_t k_ticks_to_cyc_near32(uint32_t t)
1370 {
1371 /* Generated. Do not edit. See above. */
1372 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, true, false, true);
1373 }
1374
1375 /** @brief Convert ticks to hardware cycles
1376 *
1377 * Converts time values in ticks to hardware cycles.
1378 * Computes result in 64 bit precision.
1379 * Rounds to the nearest output unit.
1380 *
1381 * @return The converted time value
1382 */
k_ticks_to_cyc_near64(uint64_t t)1383 static TIME_CONSTEXPR inline uint64_t k_ticks_to_cyc_near64(uint64_t t)
1384 {
1385 /* Generated. Do not edit. See above. */
1386 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, false, false, true);
1387 }
1388
1389 /** @brief Convert ticks to hardware cycles
1390 *
1391 * Converts time values in ticks to hardware cycles.
1392 * Computes result in 32 bit precision.
1393 * Rounds up to the next highest output unit.
1394 *
1395 * @return The converted time value
1396 */
k_ticks_to_cyc_ceil32(uint32_t t)1397 static TIME_CONSTEXPR inline uint32_t k_ticks_to_cyc_ceil32(uint32_t t)
1398 {
1399 /* Generated. Do not edit. See above. */
1400 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, true, true, false);
1401 }
1402
1403 /** @brief Convert ticks to hardware cycles
1404 *
1405 * Converts time values in ticks to hardware cycles.
1406 * Computes result in 64 bit precision.
1407 * Rounds up to the next highest output unit.
1408 *
1409 * @return The converted time value
1410 */
k_ticks_to_cyc_ceil64(uint64_t t)1411 static TIME_CONSTEXPR inline uint64_t k_ticks_to_cyc_ceil64(uint64_t t)
1412 {
1413 /* Generated. Do not edit. See above. */
1414 return z_tmcvt(t, Z_HZ_ticks, Z_HZ_cyc, Z_CCYC, false, true, false);
1415 }
1416
1417 #if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
1418 #include <syscalls/time_units.h>
1419 #endif
1420
1421 #undef TIME_CONSTEXPR
1422
1423 #ifdef __cplusplus
1424 } /* extern "C" */
1425 #endif
1426
1427 #endif /* ZEPHYR_INCLUDE_TIME_UNITS_H_ */
1428