osdep_posix.c
Go to the documentation of this file.
00001 
00009 /*
00010  * Copyright (c) 2010 ThingMagic, Inc.
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a copy
00013  * of this software and associated documentation files (the "Software"), to deal
00014  * in the Software without restriction, including without limitation the rights
00015  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00016  * copies of the Software, and to permit persons to whom the Software is
00017  * furnished to do so, subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be included in
00020  * all copies or substantial portions of the Software.
00021  * 
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00023  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00025  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00027  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00028  * THE SOFTWARE.
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   /* Sleep until the proper time has elapsed, and re-sleep if interrupted. */
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 }


thingmagic_rfid
Author(s): Brian Bingham
autogenerated on Thu May 16 2019 03:01:23