123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include <sys/time.h>
- #include <unistd.h>
- #include <errno.h>
- #include <string.h>
- #include <assert.h>
- #include "core_time.h"
- /*
- * time in miliseconds
- * args:
- * none
- *
- * asserts:
- * none
- *
- * returns: time of day in miliseconds
- */
- //uint32_t ms_time ()
- //{
- // struct timeval now;
- //
- // if(gettimeofday(&now, NULL) != 0)
- // {
- // fprintf(stderr, "V4L2_CORE: ms_time (gettimeofday) error: %s\n", strerror(errno));
- // return 0;
- // }
- //
- // uint32_t mst = (uint32_t) now.tv_sec * 1000 + (uint32_t) now.tv_usec / 1000;
- //
- // return (mst);
- //}
- /*
- * time in microseconds
- * args:
- * none
- *
- * asserts:
- * none
- *
- * returns: time of day in microseconds
- */
- //uint64_t us_time(void)
- //{
- // struct timeval now;
- //
- // if(gettimeofday(&now, NULL) != 0)
- // {
- // fprintf(stderr, "V4L2_CORE: us_time (gettimeofday) error: %s\n", strerror(errno));
- // return 0;
- // }
- //
- // uint64_t ust = (uint64_t) now.tv_sec * USEC_PER_SEC + (uint64_t) now.tv_usec;
- //
- // return (ust);
- //}
- /*
- * time in nanoseconds
- * args:
- * none
- *
- * asserts:
- * none
- *
- * returns: time in nanoseconds
- */
- //uint64_t ns_time (void)
- //{
- // struct timespec now;
- //
- // if(clock_gettime(CLOCK_REALTIME, &now) != 0)
- // {
- // fprintf(stderr, "V4L2_CORE: ns_time (clock_gettime) error: %s\n", strerror(errno));
- // return 0;
- // }
- //
- // return ((uint64_t) now.tv_sec * NSEC_PER_SEC + (uint64_t) now.tv_nsec);
- //}
- /*
- * monotonic time in nanoseconds
- * args:
- * none
- *
- * asserts:
- * none
- *
- * returns: monotonic time in nanoseconds
- */
- uint64_t ns_time_monotonic()
- {
- struct timespec now;
- if(clock_gettime(CLOCK_MONOTONIC, &now) != 0)
- {
- printf("V4L2_CORE: ns_time_monotonic (clock_gettime) error: %s\n", strerror(errno));
- return 0;
- }
- return ((uint64_t)now.tv_sec * NSEC_PER_SEC + (uint64_t) now.tv_nsec);
- }
|