mytime.cc
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <sys/time.h>
00003 #include <time.h>
00004 #include <unistd.h>
00005 
00006 #include "mytime.h"
00007 
00008 long double    mseconds;
00009 
00010 
00011 unsigned long GetCurrentTimeInMilliSec(void)
00012 {
00013   struct timeval tv;
00014   unsigned long milliseconds;
00015   gettimeofday(&tv, NULL);
00016   milliseconds = tv.tv_sec * 1000 + tv.tv_usec / 1000;
00017   return milliseconds;
00018 }
00019 
00020 // Zeitmessung NR_TIMER -1 special since programm start
00021 // timer 0 is for local use
00022 long double Get_mtime_diff(int timer_number)
00023 {
00024   static double   prev_clock[NR_TIMER];
00025   static int      first_time = 1;
00026   double          new_clock, clock_diff;
00027   int             i;
00028 
00029   if (first_time) {
00030     new_clock = GetCurrentTimeInMilliSec();
00031     for (i = 0; i < NR_TIMER; i++) {
00032       prev_clock[i] = new_clock;
00033     }
00034     clock_diff = new_clock;
00035     first_time = 0;
00036   }
00037   else {
00038     new_clock = GetCurrentTimeInMilliSec();
00039     clock_diff = new_clock - prev_clock[timer_number];
00040     if (timer_number != (NR_TIMER - 1)) prev_clock[timer_number] = new_clock;
00041   }
00042 
00043   return(clock_diff);
00044 }
00045 
00046 /*-------------------------------------------------------------------------*
00047  * NAME        : mydelay
00048  * DESCRIPTION
00049  *  warten und nichts tun
00050  *  achtung blockiert also nur waehrend der initialisierung verwenden
00051  *
00052  * PARAMETERS
00053  * RESULT
00054  *    --
00055  *-------------------------------------------------------------------------*/
00056 void mydelay (unsigned long msec)
00057 {
00058   unsigned long start_clock, cur_clock;
00059 
00060   start_clock = GetCurrentTimeInMilliSec();
00061 
00062   do  {
00063     cur_clock  = GetCurrentTimeInMilliSec();
00064   } while ((cur_clock - start_clock) < msec);
00065 
00066 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


kurt_base
Author(s): Jochen Sprickerhof
autogenerated on Tue May 28 2013 14:54:59