--- multiplexer/global.c 2001/03/19 20:52:34 1.1 +++ multiplexer/global.c 2001/03/29 13:27:43 1.2 @@ -22,24 +22,6 @@ long logtpc; timepoll *ltp; #endif -/* -int secusec2msec (struct timeval *s) -{ -} - -void secusec2clockref (struct timeval *s, clockref *d) -{ -} - -void msec2clockref (int s, clockref *d) -{ -} - -int clockref2msec (clockref *s) -{ -} -*/ - int msec_now (void) { static long last; @@ -64,6 +46,50 @@ int msec_now (void) return (now + global_delta); } +void cref2msec (conversion_base *b, + clockref c, + int *m) +{ +#define CREF2MSEC_LIMIT (90 * 1024 * 16) /* 16 sec */ + unsigned long d; + d = c.base - b->base; + if (d >= (2 * CREF2MSEC_LIMIT)) { + if (d >= (3 * CREF2MSEC_LIMIT)) { + b->base = c.base - CREF2MSEC_LIMIT; + b->msec = b->base / 90; + } else { + b->base += CREF2MSEC_LIMIT; + b->msec += CREF2MSEC_LIMIT / 90; + } + d = c.base - b->base; + } + *m = (d / 90) + b->msec; +} + +void msec2cref (conversion_base *b, + int m, + clockref *c) +{ +#define MSEC2CREF_LIMIT (1024 * 10) /* 10 sec */ + unsigned int d; + d = m - b->msec; + if (d >= (2 * MSEC2CREF_LIMIT)) { + if (d >= (3 * MSEC2CREF_LIMIT)) { + b->msec = m - MSEC2CREF_LIMIT; + b->base = b->msec * 45; + } else { + b->msec += MSEC2CREF_LIMIT; + b->base += MSEC2CREF_LIMIT * 45; + } + d = m - b->msec; + } + d = (d * 45) + b->base; + c->base = d * 2; + c->ba33 = (d >> 31) & 0x01; + c->ext = 0; + c->valid = TRUE; +} + void global_init (void) { #ifdef DEBUG_TIMEPOLL