Main Page | Data Structures | File List | Data Fields | Globals

timer.c File Reference

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <strings.h>
#include <string.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include "timer.h"

Include dependency graph for timer.c:

Include dependency graph

Go to the source code of this file.

Defines

#define JITTER_MAX   1000

Functions

long jitter (long period)
int delay_uS (int uS)
void * periodic_thread (void *arg)


Define Documentation

#define JITTER_MAX   1000
 

Definition at line 61 of file timer.c.


Function Documentation

int delay_uS int  uS  ) 
 

Definition at line 65 of file timer.c.

References jitter().

Referenced by main(), and periodic_thread().

00065                      {
00066   struct timeval to;
00067   long time_error;
00068   to.tv_sec = 0;
00069   to.tv_usec = uS;    
00070   select(0,NULL,NULL,NULL,&to);
00071   time_error=jitter((long)uS);
00072   if ((time_error>JITTER_MAX)||(time_error<-JITTER_MAX)) {
00073     printf("%ld\n",time_error);
00074   }
00075   return (0);
00076 }

Here is the call graph for this function:

long jitter long  period  ) 
 

Definition at line 90 of file timer.c.

References error().

Referenced by delay_uS().

00090                          {
00091   static struct timeval tv_last;
00092   static int init=1;
00093   struct timeval tv;
00094   long delta;
00095   long error;
00096   gettimeofday(&tv,NULL);
00097   if (!init) {
00098     if (tv.tv_usec<tv_last.tv_usec) {
00099       delta=(1000000-tv_last.tv_usec)+tv.tv_usec;
00100     }
00101     else {
00102       delta=tv.tv_usec-tv_last.tv_usec;
00103     }
00104     tv_last.tv_usec=tv.tv_usec;
00105     error=delta-period;
00106   }
00107   else {
00108     tv_last.tv_usec=tv.tv_usec;
00109     error=0;
00110     init=0;
00111   }
00112   return(error);
00113 }

Here is the call graph for this function:

void* periodic_thread void *  arg  ) 
 

Definition at line 78 of file timer.c.

References delay_uS(), timer_struct::timeout, timer_struct::timer_period, and timer_struct_t.

Referenced by scheduler().

00078                                  {
00079   int status;
00080   timer_struct_t *tp = (timer_struct_t *) arg;
00081 
00082   while (1) {
00083     delay_uS(tp->timer_period);
00084     tp->timeout=1;
00085   }
00086   status = pthread_detach(pthread_self());
00087   return NULL;
00088 }

Here is the call graph for this function:


Generated on Fri Nov 3 15:24:58 2006 for ERT1 Communication Server by  doxygen 1.3.9.1