Zephyr Project API  3.3.0
A Scalable Open Source RTOS
time_units.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_TIME_UNITS_H_
8#define ZEPHYR_INCLUDE_TIME_UNITS_H_
9
10#include <zephyr/toolchain.h>
11#include <zephyr/sys/util.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
24#define SYS_FOREVER_MS (-1)
25
30#define SYS_FOREVER_US (-1)
31
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
41static 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
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
79#define Z_TMCVT_USE_FAST_ALGO(from_hz, to_hz) \
80 ((ceiling_fraction(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 */
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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_ */
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa off
Definition: asm-macro-32-bit-gnu.h:17
#define ALWAYS_INLINE
Definition: common.h:124
#define BIT64(_n)
64-bit unsigned integer with bit position _n set.
Definition: util_macro.h:49
struct k_thread t
Definition: kobject.c:1327
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT64_TYPE__ uint64_t
Definition: stdint.h:91
static uint32_t k_ms_to_cyc_floor32(uint32_t t)
Convert milliseconds to hardware cycles.
Definition: time_units.h:249
static uint64_t k_cyc_to_ns_near64(uint64_t t)
Convert hardware cycles to nanoseconds.
Definition: time_units.h:963
static uint64_t k_ticks_to_ns_floor64(uint64_t t)
Convert ticks to nanoseconds.
Definition: time_units.h:1271
static uint64_t k_ms_to_cyc_near64(uint64_t t)
Convert milliseconds to hardware cycles.
Definition: time_units.h:291
static uint64_t k_ms_to_cyc_ceil64(uint64_t t)
Convert milliseconds to hardware cycles.
Definition: time_units.h:319
static uint32_t k_ticks_to_ms_near32(uint32_t t)
Convert ticks to milliseconds.
Definition: time_units.h:1117
static uint32_t k_ns_to_cyc_floor32(uint32_t t)
Convert nanoseconds to hardware cycles.
Definition: time_units.h:585
static uint32_t k_ticks_to_ns_near32(uint32_t t)
Convert ticks to nanoseconds.
Definition: time_units.h:1285
static uint32_t k_us_to_ticks_near32(uint32_t t)
Convert microseconds to ticks.
Definition: time_units.h:529
static uint32_t k_ns_to_ticks_floor32(uint32_t t)
Convert nanoseconds to ticks.
Definition: time_units.h:669
static uint64_t k_ns_to_ticks_ceil64(uint64_t t)
Convert nanoseconds to ticks.
Definition: time_units.h:739
static uint64_t k_cyc_to_ticks_floor64(uint64_t t)
Convert hardware cycles to ticks.
Definition: time_units.h:1019
static int sys_clock_hw_cycles_per_sec(void)
Definition: time_units.h:59
static uint64_t k_ticks_to_ns_near64(uint64_t t)
Convert ticks to nanoseconds.
Definition: time_units.h:1299
static uint64_t k_cyc_to_ms_floor64(uint64_t t)
Convert hardware cycles to milliseconds.
Definition: time_units.h:767
static uint64_t k_us_to_cyc_ceil64(uint64_t t)
Convert microseconds to hardware cycles.
Definition: time_units.h:487
static uint64_t k_ns_to_cyc_floor64(uint64_t t)
Convert nanoseconds to hardware cycles.
Definition: time_units.h:599
static uint64_t k_us_to_ticks_floor64(uint64_t t)
Convert microseconds to ticks.
Definition: time_units.h:515
static uint32_t k_cyc_to_us_ceil32(uint32_t t)
Convert hardware cycles to microseconds.
Definition: time_units.h:893
static uint32_t k_cyc_to_ns_floor32(uint32_t t)
Convert hardware cycles to nanoseconds.
Definition: time_units.h:921
static uint64_t k_ms_to_ticks_floor64(uint64_t t)
Convert milliseconds to ticks.
Definition: time_units.h:347
static uint64_t k_cyc_to_ms_ceil64(uint64_t t)
Convert hardware cycles to milliseconds.
Definition: time_units.h:823
static uint32_t k_us_to_cyc_ceil32(uint32_t t)
Convert microseconds to hardware cycles.
Definition: time_units.h:473
#define TIME_CONSTEXPR
Definition: time_units.h:56
static uint32_t k_ticks_to_ms_ceil32(uint32_t t)
Convert ticks to milliseconds.
Definition: time_units.h:1145
static uint32_t k_ticks_to_cyc_floor32(uint32_t t)
Convert ticks to hardware cycles.
Definition: time_units.h:1341
static uint64_t k_ticks_to_cyc_ceil64(uint64_t t)
Convert ticks to hardware cycles.
Definition: time_units.h:1411
static uint32_t k_us_to_ticks_floor32(uint32_t t)
Convert microseconds to ticks.
Definition: time_units.h:501
static uint32_t k_ns_to_ticks_near32(uint32_t t)
Convert nanoseconds to ticks.
Definition: time_units.h:697
static uint64_t k_ns_to_ticks_floor64(uint64_t t)
Convert nanoseconds to ticks.
Definition: time_units.h:683
static uint64_t k_ms_to_ticks_near64(uint64_t t)
Convert milliseconds to ticks.
Definition: time_units.h:375
static uint32_t k_ticks_to_ns_ceil32(uint32_t t)
Convert ticks to nanoseconds.
Definition: time_units.h:1313
static uint64_t k_us_to_cyc_near64(uint64_t t)
Convert microseconds to hardware cycles.
Definition: time_units.h:459
static uint32_t k_ns_to_cyc_near32(uint32_t t)
Convert nanoseconds to hardware cycles.
Definition: time_units.h:613
static uint64_t k_us_to_cyc_floor64(uint64_t t)
Convert microseconds to hardware cycles.
Definition: time_units.h:431
static uint32_t k_ticks_to_ns_floor32(uint32_t t)
Convert ticks to nanoseconds.
Definition: time_units.h:1257
static uint64_t k_cyc_to_ms_near64(uint64_t t)
Convert hardware cycles to milliseconds.
Definition: time_units.h:795
static uint32_t k_us_to_cyc_near32(uint32_t t)
Convert microseconds to hardware cycles.
Definition: time_units.h:445
static uint64_t k_ticks_to_ms_floor64(uint64_t t)
Convert ticks to milliseconds.
Definition: time_units.h:1103
static uint32_t k_ns_to_ticks_ceil32(uint32_t t)
Convert nanoseconds to ticks.
Definition: time_units.h:725
static uint32_t k_cyc_to_ms_near32(uint32_t t)
Convert hardware cycles to milliseconds.
Definition: time_units.h:781
static uint32_t k_cyc_to_ms_ceil32(uint32_t t)
Convert hardware cycles to milliseconds.
Definition: time_units.h:809
static uint64_t k_ns_to_ticks_near64(uint64_t t)
Convert nanoseconds to ticks.
Definition: time_units.h:711
static uint64_t k_ticks_to_us_near64(uint64_t t)
Convert ticks to microseconds.
Definition: time_units.h:1215
static uint32_t k_cyc_to_ticks_ceil32(uint32_t t)
Convert hardware cycles to ticks.
Definition: time_units.h:1061
static uint64_t k_ns_to_cyc_ceil64(uint64_t t)
Convert nanoseconds to hardware cycles.
Definition: time_units.h:655
static uint32_t k_ms_to_cyc_ceil32(uint32_t t)
Convert milliseconds to hardware cycles.
Definition: time_units.h:305
static uint32_t k_ticks_to_ms_floor32(uint32_t t)
Convert ticks to milliseconds.
Definition: time_units.h:1089
static uint32_t k_ms_to_ticks_floor32(uint32_t t)
Convert milliseconds to ticks.
Definition: time_units.h:333
static uint64_t k_cyc_to_ticks_near64(uint64_t t)
Convert hardware cycles to ticks.
Definition: time_units.h:1047
static uint64_t k_ticks_to_us_floor64(uint64_t t)
Convert ticks to microseconds.
Definition: time_units.h:1187
static uint64_t k_cyc_to_ns_floor64(uint64_t t)
Convert hardware cycles to nanoseconds.
Definition: time_units.h:935
static uint32_t k_cyc_to_ns_ceil32(uint32_t t)
Convert hardware cycles to nanoseconds.
Definition: time_units.h:977
static uint32_t k_cyc_to_us_floor32(uint32_t t)
Convert hardware cycles to microseconds.
Definition: time_units.h:837
static uint64_t k_cyc_to_us_floor64(uint64_t t)
Convert hardware cycles to microseconds.
Definition: time_units.h:851
static uint32_t k_us_to_cyc_floor32(uint32_t t)
Convert microseconds to hardware cycles.
Definition: time_units.h:417
static uint64_t k_ms_to_ticks_ceil64(uint64_t t)
Convert milliseconds to ticks.
Definition: time_units.h:403
static uint32_t k_us_to_ticks_ceil32(uint32_t t)
Convert microseconds to ticks.
Definition: time_units.h:557
static uint32_t k_ticks_to_us_near32(uint32_t t)
Convert ticks to microseconds.
Definition: time_units.h:1201
static uint32_t k_cyc_to_ticks_floor32(uint32_t t)
Convert hardware cycles to ticks.
Definition: time_units.h:1005
static uint32_t k_ticks_to_us_ceil32(uint32_t t)
Convert ticks to microseconds.
Definition: time_units.h:1229
static uint32_t k_ms_to_ticks_near32(uint32_t t)
Convert milliseconds to ticks.
Definition: time_units.h:361
static uint64_t k_cyc_to_ns_ceil64(uint64_t t)
Convert hardware cycles to nanoseconds.
Definition: time_units.h:991
static uint32_t k_ns_to_cyc_ceil32(uint32_t t)
Convert nanoseconds to hardware cycles.
Definition: time_units.h:641
static uint32_t k_ticks_to_cyc_ceil32(uint32_t t)
Convert ticks to hardware cycles.
Definition: time_units.h:1397
static uint64_t k_cyc_to_us_ceil64(uint64_t t)
Convert hardware cycles to microseconds.
Definition: time_units.h:907
static uint32_t k_ms_to_cyc_near32(uint32_t t)
Convert milliseconds to hardware cycles.
Definition: time_units.h:277
static uint32_t k_ticks_to_us_floor32(uint32_t t)
Convert ticks to microseconds.
Definition: time_units.h:1173
static uint32_t k_cyc_to_ms_floor32(uint32_t t)
Convert hardware cycles to milliseconds.
Definition: time_units.h:753
static uint64_t k_ticks_to_ms_near64(uint64_t t)
Convert ticks to milliseconds.
Definition: time_units.h:1131
static uint64_t k_ticks_to_us_ceil64(uint64_t t)
Convert ticks to microseconds.
Definition: time_units.h:1243
static uint64_t k_us_to_ticks_near64(uint64_t t)
Convert microseconds to ticks.
Definition: time_units.h:543
static uint32_t k_cyc_to_ns_near32(uint32_t t)
Convert hardware cycles to nanoseconds.
Definition: time_units.h:949
static uint32_t k_ticks_to_cyc_near32(uint32_t t)
Convert ticks to hardware cycles.
Definition: time_units.h:1369
static uint64_t k_cyc_to_ticks_ceil64(uint64_t t)
Convert hardware cycles to ticks.
Definition: time_units.h:1075
static uint32_t k_ms_to_ticks_ceil32(uint32_t t)
Convert milliseconds to ticks.
Definition: time_units.h:389
static uint64_t k_ticks_to_ms_ceil64(uint64_t t)
Convert ticks to milliseconds.
Definition: time_units.h:1159
static uint64_t k_ticks_to_cyc_floor64(uint64_t t)
Convert ticks to hardware cycles.
Definition: time_units.h:1355
static uint64_t k_cyc_to_us_near64(uint64_t t)
Convert hardware cycles to microseconds.
Definition: time_units.h:879
static uint64_t k_ticks_to_cyc_near64(uint64_t t)
Convert ticks to hardware cycles.
Definition: time_units.h:1383
static uint64_t k_ms_to_cyc_floor64(uint64_t t)
Convert milliseconds to hardware cycles.
Definition: time_units.h:263
static uint64_t k_ticks_to_ns_ceil64(uint64_t t)
Convert ticks to nanoseconds.
Definition: time_units.h:1327
static uint32_t k_cyc_to_ticks_near32(uint32_t t)
Convert hardware cycles to ticks.
Definition: time_units.h:1033
static uint64_t k_ns_to_cyc_near64(uint64_t t)
Convert nanoseconds to hardware cycles.
Definition: time_units.h:627
static uint64_t k_us_to_ticks_ceil64(uint64_t t)
Convert microseconds to ticks.
Definition: time_units.h:571
static uint32_t k_cyc_to_us_near32(uint32_t t)
Convert hardware cycles to microseconds.
Definition: time_units.h:865
Macros to abstract toolchain specific capabilities.
Misc utilities.