Go to the documentation of this file.00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <time.h>
00032 #include <sys/time.h>
00033
00034 #include "osdep.h"
00035
00036 uint64_t
00037 tmr_gettime()
00038 {
00039 struct timeval tv;
00040 uint64_t totalms;
00041
00042 gettimeofday(&tv, NULL);
00043 totalms = (((uint64_t)tv.tv_sec) * 1000) + ((uint64_t) tv.tv_usec) / 1000;
00044
00045 return totalms;
00046 }
00047
00048 uint32_t
00049 tmr_gettime_low()
00050 {
00051
00052 return (tmr_gettime() >> 0) & 0xffffffff;
00053 }
00054
00055 uint32_t
00056 tmr_gettime_high()
00057 {
00058
00059 return (tmr_gettime() >> 32) & 0xffffffff;
00060 }
00061
00062
00063 void
00064 tmr_sleep(uint32_t sleepms)
00065 {
00066 struct timespec sleep, rem;
00067
00068 sleep.tv_sec = sleepms / 1000;
00069 sleep.tv_nsec = (sleepms % 1000) * 1000000L;
00070
00071
00072 while (-1 == nanosleep(&sleep, &rem))
00073 {
00074 sleep = rem;
00075 }
00076 }
00077
00078 TMR_TimeStructure
00079 tmr_gettimestructure()
00080 {
00081 time_t now;
00082 uint64_t temp;
00083 struct tm *timestamp;
00084 TMR_TimeStructure timestructure;
00085
00086 temp = tmr_gettime();
00087 now = (time_t)(temp/1000);
00088 timestamp = localtime(&now);
00089
00090 timestructure.tm_year = (uint32_t)(1900 + timestamp->tm_year);
00091 timestructure.tm_mon = (uint32_t)(1 + timestamp->tm_mon);
00092 timestructure.tm_mday = (uint32_t)timestamp->tm_mday;
00093 timestructure.tm_hour = (uint32_t)timestamp->tm_hour;
00094 timestructure.tm_min = (uint32_t)timestamp->tm_min;
00095 timestructure.tm_sec = (uint32_t)timestamp->tm_sec;
00096 return timestructure;
00097 }