Watt-32 tcp/ip  2.2 dev-rel.10
Functions | Variables
timer.c File Reference

Go to the source code of this file.

Functions

void init_timers (void)
 Setup timer stuff and measure CPU speed. More...
 
void W32_CALL init_userSuppliedTimerTick (void)
 init_userSuppliedTimerTick() - setup timer handling for programs that are already running a periodic interrupt or whatever (i.e. More...
 
void W32_CALL userTimerTick (DWORD elapsed_time_msec)
 Provide timer-ticks from an application. More...
 
static void new_int_8 (void)
 User defined 10 (or 55) milli-sec counter ISR.
 
void exit_timer_isr (void)
 
void init_timer_isr (void)
 
int W32_CALL cmp_timers (DWORD t1, DWORD t2)
 Compare two timers with expirary at 't1' and 't2'. More...
 
int hires_timer (int on)
 Control use of high-resolution timer. More...
 
DWORD clockbits (void)
 
DWORD millisec_clock (void)
 
DWORD W32_CALL set_timeout (DWORD msec)
 Return time for when given timeout (msec) expires. More...
 
BOOL W32_CALL chk_timeout (DWORD value)
 Check if milli-sec value has expired: More...
 
int W32_CALL set_timediff (long msec)
 Must be called by user right before or after a time change occurs. More...
 
long W32_CALL get_timediff (DWORD now, DWORD tim)
 Return time difference between timers 'now' and 'tim'. More...
 
double W32_CALL timeval_diff (const struct timeval *newer, const struct timeval *older)
 
struct timeval W32_CALL timeval_diff2 (struct timeval *ta, struct timeval *tb)
 
const char * time_str (DWORD val)
 
const char * hms_str (DWORD sec)
 
const char * elapsed_str (DWORD val)
 
DWORD ms_clock (void)
 
void delay (unsigned int msec)
 
static void Wait_N_ticks (int num)
 
uint64 get_cpu_speed (void)
 Return estimated CPU speed in Hz.
 
uint64 win_get_perf_count (void)
 
uint64 win_get_rdtsc (void)
 

Variables

DWORD start_time = 0
 Start-time of watt_sock_init() (in msec)
 
DWORD start_day = 0
 Start-day of watt_sock_init()
 
static int num_cpus = 1
 
BOOL has_rdtsc = TRUE
 Never set in Watt-32. More...
 
BOOL use_rdtsc = TRUE
 Ditto. More...
 
BOOL has_8254 = FALSE
 Do we have a working 8254 timer chip?
 
BOOL using_int8 = FALSE
 init_timer_isr() called
 
DWORD clocks_per_usec = 0L
 Measured CPU speed (MHz)
 
time_t user_tick_base = 0UL
 
DWORD user_tick_msec = 0UL
 
BOOL user_tick_active = FALSE
 
static DWORD date = 0
 
static DWORD date_ms = 0
 
static W32_IntrHandler old_int_8 = NULL
 
static REALPTR int8_cback
 
static RMC_BLK rmBlock_int8
 
static DWORD itimer_resolution = 0UL
 
static void(* old_sigalrm )(int)
 
static struct itimerval old_itimer
 
static DWORD tick_timer_8254 = 0UL
 

Detailed Description

Module for handling timers.

Modifications by GvB 2002-09

Todo:
To get rid of the timer problem once and for all we need a timer ISR that increments a 32-bit value no regard to day roll-over etc. Maybe hook up IRQ 8 to call a real-mode stub that we opy to DOS-memory (similar to the pkt_receiver stub code. Then far-peek at that timer variable.

09-Jan-2003: Bernd Omenitch Omeni.nosp@m.tsch.nosp@m.@cash.nosp@m.poin.nosp@m.t.at contributed the Timer ISR code (init_timer_isr() etc). I rewrote it and added support for Borland/PowerPak/Pharlap).

Definition in file timer.c.

Function Documentation

BOOL W32_CALL chk_timeout ( DWORD  value)

Check if milli-sec value has expired:

Return values
\liTRUE timer expired
  • FALSE not expired (or value not set)

Definition at line 547 of file timer.c.

References has_8254, and set_timeout().

int W32_CALL cmp_timers ( DWORD  t1,
DWORD  t2 
)

Compare two timers with expirary at 't1' and 't2'.

Return values
\li-1 if t1 expires before t2
  • 0 if t1 == t2
  • +1 if t1 expires after t2
Note
This logic fails when timers approaches ULONG_MAX after approx. 50 days.

Definition at line 359 of file timer.c.

long W32_CALL get_timediff ( DWORD  now,
DWORD  tim 
)

Return time difference between timers 'now' and 'tim'.

Check for day rollover. Max timer distance is 24 hours. This function should be called immediately after chk_timeout() is called.

Definition at line 621 of file timer.c.

References has_8254.

int hires_timer ( int  on)

Control use of high-resolution timer.

When using Watt-32 together with programs that reprogram the PIT (8254 timer chip), the millisec_clock() function may return wrong values. In such cases it's best to use old-style 55ms timers. Using Watt-32 with Allegro graphics library is one such case where application program should call `hires_timer(0)' after `sock_init()' has been called.

Definition at line 377 of file timer.c.

References chk_timeout(), and has_8254.

void init_timers ( void  )

Setup timer stuff and measure CPU speed.

Called from init_misc().

<

Todo:
check if 8254 PIT is really working

Definition at line 111 of file timer.c.

References chk_timeout(), clocks_per_usec, get_cpu_speed(), get_day_num(), has_rdtsc, hires_timer(), set_timeout(), set_utc_offset(), start_day, start_time, and use_rdtsc.

void W32_CALL init_userSuppliedTimerTick ( void  )

init_userSuppliedTimerTick() - setup timer handling for programs that are already running a periodic interrupt or whatever (i.e.

ALLEGRO & more). This is called to signify that the 'user task' will periodically call userTimerTick() to supply the elapsed time since the last call. Best called once before sock_init(). There is no way to revert to original timer handling once this is called. By GvB 2002-09

Definition at line 156 of file timer.c.

References has_8254.

int W32_CALL set_timediff ( long  msec)

Must be called by user right before or after a time change occurs.

Not used in Watt-32.

Definition at line 608 of file timer.c.

DWORD W32_CALL set_timeout ( DWORD  msec)

Return time for when given timeout (msec) expires.

Make sure it never returns 0 (it will confuse chk_timeout).

Definition at line 503 of file timer.c.

References has_8254.

void W32_CALL userTimerTick ( DWORD  elapsed_time_msec)

Provide timer-ticks from an application.

This should be periodically called from user code to increment the timer count once activated via init_userSuppliedTimerTick(). Best called from a periodic interrupt handler (int 8/1Ch/70h) which is the case now with init_timer_isr().

by GvB 2002-09

Definition at line 186 of file timer.c.

Variable Documentation

BOOL has_rdtsc = TRUE

Never set in Watt-32.

Do we have a CPU with RDTSC instruction?

Some users may need it.

Definition at line 52 of file timer.c.

BOOL use_rdtsc = TRUE

Ditto.

Do not use RDTSC by default.

Definition at line 53 of file timer.c.