28 #undef __STRICT_ANSI__ 30 #include <rtems/test.h> 33 #include <stdatomic.h> 44 round_sbt(T_time time)
56 T_time_to_string_ns(T_time time, T_time_string
string)
62 time = round_sbt(time);
63 s = (uint32_t)(time >> 32);
64 f = (uint32_t)(((uint64_t)1000000000 * (uint32_t)time) >> 32);
66 s = (uint32_t)(time / 1000000000);
67 f = (uint32_t)(time % 1000000000);
70 (void)T_snprintf(
string,
sizeof(T_time_string),
71 "%" PRIu32
".%09" PRIu32, s, f);
76 T_time_to_string_us(T_time time, T_time_string
string)
82 time = round_sbt(time);
83 s = (uint32_t)(time >> 32);
84 f = (uint32_t)(((uint64_t)1000000 * (uint32_t)time) >> 32);
87 s = (uint32_t)(time / 1000000);
88 f = (uint32_t)(time % 1000000);
91 (void)T_snprintf(
string,
sizeof(T_time_string),
92 "%" PRIu32
".%06" PRIu32, s, f);
97 T_time_to_string_ms(T_time time, T_time_string
string)
103 time = round_sbt(time);
104 s = (uint32_t)(time >> 32);
105 f = (uint32_t)(((uint64_t)1000 * (uint32_t)time) >> 32);
108 s = (uint32_t)(time / 1000);
109 f = (uint32_t)(time % 1000);
112 (void)T_snprintf(
string,
sizeof(T_time_string),
113 "%" PRIu32
".%03" PRIu32, s, f);
118 T_time_to_string_s(T_time time, T_time_string
string)
123 time = round_sbt(time);
124 s = (uint32_t)(time >> 32);
126 s = (uint32_t)(time / 1000000000);
129 (void)T_snprintf(
string,
sizeof(T_time_string),
"%" PRIu32, s);
134 T_ticks_to_string_ns(T_ticks ticks, T_time_string
string)
136 return T_time_to_string_ns(T_ticks_to_time(ticks),
string);
140 T_ticks_to_string_us(T_ticks ticks, T_time_string
string)
142 return T_time_to_string_us(T_ticks_to_time(ticks),
string);
146 T_ticks_to_string_ms(T_ticks ticks, T_time_string
string)
148 return T_time_to_string_ms(T_ticks_to_time(ticks),
string);
152 T_ticks_to_string_s(T_ticks ticks, T_time_string
string)
154 return T_time_to_string_s(T_ticks_to_time(ticks),
string);
158 T_ticks_to_time(T_ticks ticks)
168 T_time_to_ticks(T_time time)
178 T_seconds_and_nanoseconds_to_time(uint32_t s, uint32_t ns)
184 ts.tv_nsec = (long)ns;
185 return (T_time)tstosbt(ts);
187 return (T_time)s * (T_time)1000000000 + (T_time)ns;
192 T_time_to_seconds_and_nanoseconds(T_time time, uint32_t *s, uint32_t *ns)
195 time = round_sbt(time);
196 *s = (uint32_t)(time >> 32);
197 *ns = (uint32_t)(((uint64_t)1000000000 * (uint32_t)time) >> 32);
199 *s = (uint32_t)(time / 1000000000);
200 *ns = (uint32_t)(time % 1000000000);
210 (void)clock_gettime(CLOCK_MONOTONIC, &tp);
211 return (T_time)tp.tv_sec * (T_time)1000000000 + (T_time)tp.tv_nsec;
225 static atomic_uint T_dummy_time;
230 return atomic_fetch_add_explicit(&T_dummy_time, 1,
231 memory_order_relaxed);
237 return T_ticks_to_time(T_tick());
Free-Running Counter and Busy Wait Delay API.
int64_t rtems_counter_ticks_to_sbintime(rtems_counter_ticks ticks)
Converts counter ticks into signed binary time (sbintime_t).
int64_t _Timecounter_Sbinuptime(void)
Returns the uptime in the sbintime_t format.
rtems_counter_ticks rtems_counter_sbintime_to_ticks(int64_t sbt)
Converts signed binary time (sbintime_t) into counter ticks.