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