39 #include <px4_platform_common/px4_config.h> 40 #include <px4_platform_common/defines.h> 41 #include <px4_platform_common/posix.h> 42 #include <sys/types.h> 50 #include <arch/board/board.h> 63 static uint64_t basetime;
64 static uint32_t lasttime;
67 cycles = *(
unsigned long *)0xe0001004;
69 if (cycles < lasttime) {
70 basetime += 0x100000000ULL;
75 return (basetime + cycles) / 168;
81 int64_t lowdelta, maxdelta = 0;
82 int64_t delta, deltadelta;
85 (*(
unsigned long *)0xe000edfc) |= (1 << 24);
86 (*(
unsigned long *)0xe0001000) |= 1;
91 for (
unsigned i = 0; i < 100; i++) {
92 uint32_t flags = px4_enter_critical_section();
97 px4_leave_critical_section(flags);
102 lowdelta =
abs(delta / 100);
105 for (
unsigned i = 0; i < 100; i++) {
107 usleep(rand() % SHRT_MAX);
109 uint32_t flags = px4_enter_critical_section();
114 px4_leave_critical_section(flags);
117 deltadelta =
abs(delta - lowdelta);
119 if (deltadelta > maxdelta) {
120 maxdelta = deltadelta;
123 if (deltadelta > 1000) {
124 fprintf(stderr,
"h %" PRIu64
" c %" PRIu64
" d %" PRId64
"\n", h, c, delta - lowdelta);
128 printf(
"Maximum jitter %" PRId64
"us\n", maxdelta);
int test_time(int argc, char *argv[])
static hrt_abstime cycletime(void)
High-resolution timer with callouts and timekeeping.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Dual< Scalar, N > abs(const Dual< Scalar, N > &a)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).