home *** CD-ROM | disk | FTP | other *** search
- /******************************************
- * TIMERS.C *
- * Copyright TimeSlice, Inc. 1985, 86, 87. *
- ******************************************/
-
- #include <ts.h>
-
- extern TIMER *_tpfrnt; /*head of TIMER structs list*/
-
- void time_isr();
-
- /***
- * PTIMER( TUNITS, PROC )
- * This function attaches an isr to interrupt # 8. Evry Tunits, the process
- * proc is awakened. A pointer to that allocated TIMER is returned.
- ***/
- TIMER *ptimer( tunits, proc )
- unsigned long tunits;
- PROCESS *proc;
- {
- return ftimer( tunits, wakeproc, (char *)proc );
- }
-
- /***
- * FTIMER( TUNITS, FUNC, ARG )
- * This function attaches an isr to interrupt # 8. Evry Tunits, the function
- * func is called. A pointer to that allocated TIMER is returned.
- ***/
- TIMER *ftimer( tunits, func, arg )
- unsigned long tunits;
- void (*func)();
- char *arg;
- {
- TIMER *tp;
- char *malloc();
- int cpuflags;
- static installed;
-
- critstart( DOS_CRCLASS );
-
- /*if called for the first time, install time_isr*/
- if( !installed ) {
- intatt( 0x08, 0x300, time_isr, BEFORE ) ;
- installed = 1;
- }
-
- /*allocate a new TIMER and put it in front of _tpfrnt list*/
- tp = (TIMER *)malloc( sizeof( TIMER ) );
- cpuflags = cli();
- tp->nxt = _tpfrnt;
- _tpfrnt = tp;
- putf( cpuflags );
- tp->cntr = tp->reset = tunits;
- tp->func = func;
- tp->arg = arg;
- critend( DOS_CRCLASS );
-
- return tp;
- }
-
- /*****
- * TIME_ISR()
- * This isr is attached to the primary hardware timer interrupt.
- * It then processes each WPROC in the list and calls each function as needed.
- *****/
- void time_isr() {
- TIMER *tp; /* Pointer to TIMER structure */
-
- /*process all wprocs*/
- for( tp = _tpfrnt ; tp ; tp = tp->nxt )
- if( !--tp->cntr ) { /* if counter reaches 0, call func*/
- tp->cntr = tp->reset;
- (*tp->func)( tp->arg );
- }
- }
-
- /***
- * RMVTIMER( TP )
- * Remove TIMER structure *TP from TIMER list.
- ***/
- void rmvtimer( tp )
- TIMER *tp;
- {
- TIMER *tp2;
- int cpuflags;
-
- cpuflags = cli();
- for( tp2 = (TIMER *)&_tpfrnt ; tp2->nxt ; tp2 = tp2->nxt )
- if( tp2->nxt == tp ) {
- tp2->nxt = tp->nxt;
- critstart( DOS_CRCLASS );
- free( tp );
- critend( DOS_CRCLASS );
- break;
- }
- putf( cpuflags );
- }
-
-
- /***
- * RESET_TIMER( TIMER, TUNITS )
- * This function resets the timer to a new value.
- ***/
-
- void reset_timer(TIMER *tp, unsigned long tunits)
- {
- if (tunits == 0xffffffffL) tp->cntr = tp->reset;
- else tp->cntr = tp->reset = tunits;
- }
-