realtime.c File Reference

#include <stdio.h>
#include "machine.h"
#include "realtime.h"
#include <sys/time.h>
#include <unistd.h>

Include dependency graph for realtime.c:

Go to the source code of this file.

Defines

#define inline

Functions

static unsigned long long TIME2ULL (struct timeval t)
static struct timeval ULL2TIME (unsigned long long t)
int C2F() realtimeinit (double *t, double *scale)
int C2F() realtime (double *t)

Variables

static double simulation_start = 0
static double simulation_scale = 0
static unsigned long long realtime_start = 0
static int simulation_doinit = 1


Define Documentation

#define inline

Definition at line 14 of file realtime.c.


Function Documentation

int C2F() realtime ( double *  t  ) 

Definition at line 69 of file realtime.c.

References long, realtime_start, simulation_doinit, simulation_scale, simulation_start, t, TIME2ULL(), and ULL2TIME().

00070 {
00071   struct timeval now;
00072   unsigned long long realtime_diff;
00073   double simulation_diff;
00074   long long delay;
00075 
00076   if (simulation_doinit) {
00077     simulation_doinit = 0;
00078     simulation_start = *t;
00079   }
00080   gettimeofday(&now, 0); 
00081   realtime_diff = TIME2ULL(now) - realtime_start;
00082   simulation_diff = (*t - simulation_start) * simulation_scale;
00083   delay = (long long)(simulation_diff * 1000000) - realtime_diff;
00084 
00085   if (delay > 0) 
00086         {
00087     struct timeval d ;
00088     d = ULL2TIME(delay);
00089     select(0, 0, 0, 0, &d);
00090   }
00091   return 0;
00092 }

Here is the call graph for this function:

int C2F() realtimeinit ( double *  t,
double *  scale 
)

Definition at line 56 of file realtime.c.

References realtime_start, scale, simulation_doinit, simulation_scale, and TIME2ULL().

00057 {
00058   struct timeval now;
00059   
00060   gettimeofday(&now, 0); 
00061   realtime_start = TIME2ULL(now);
00062   simulation_doinit = 1;
00063   simulation_scale = *scale;
00064   return 0;
00065 }

Here is the call graph for this function:

static unsigned long long TIME2ULL ( struct timeval  t  )  [inline, static]

Definition at line 37 of file realtime.c.

References long, and result.

Referenced by realtime(), and realtimeinit().

00038 {
00039   unsigned long long result;
00040   result = (unsigned long long)t.tv_sec * 1000000 + t.tv_usec;
00041   return result;
00042 }

Here is the caller graph for this function:

static struct timeval ULL2TIME ( unsigned long long  t  )  [inline, static]

Definition at line 46 of file realtime.c.

References result, and t.

Referenced by realtime().

00047 {
00048   struct timeval result;
00049   result.tv_sec = t / 1000000;
00050   result.tv_usec = t % 1000000;
00051   return result;
00052 }

Here is the caller graph for this function:


Variable Documentation

unsigned long long realtime_start = 0 [static]

Definition at line 31 of file realtime.c.

Referenced by realtime(), and realtimeinit().

int simulation_doinit = 1 [static]

Definition at line 32 of file realtime.c.

Referenced by realtime(), and realtimeinit().

double simulation_scale = 0 [static]

Definition at line 30 of file realtime.c.

Referenced by realtime(), and realtimeinit().

double simulation_start = 0 [static]

Definition at line 29 of file realtime.c.

Referenced by realtime().


Generated on Sun Mar 4 16:13:59 2007 for Scilab [trunk] by  doxygen 1.5.1