Home | History | Annotate | Line # | Download | only in raidframe
rf_etimer.h revision 1.3
      1  1.3  oster /*	$NetBSD: rf_etimer.h,v 1.3 1999/02/05 00:06:11 oster Exp $	*/
      2  1.1  oster /*
      3  1.1  oster  * Copyright (c) 1995 Carnegie-Mellon University.
      4  1.1  oster  * All rights reserved.
      5  1.1  oster  *
      6  1.1  oster  * Author: Mark Holland
      7  1.1  oster  *
      8  1.1  oster  * Permission to use, copy, modify and distribute this software and
      9  1.1  oster  * its documentation is hereby granted, provided that both the copyright
     10  1.1  oster  * notice and this permission notice appear in all copies of the
     11  1.1  oster  * software, derivative works or modified versions, and any portions
     12  1.1  oster  * thereof, and that both notices appear in supporting documentation.
     13  1.1  oster  *
     14  1.1  oster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  1.1  oster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16  1.1  oster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  1.1  oster  *
     18  1.1  oster  * Carnegie Mellon requests users of this software to return to
     19  1.1  oster  *
     20  1.1  oster  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  1.1  oster  *  School of Computer Science
     22  1.1  oster  *  Carnegie Mellon University
     23  1.1  oster  *  Pittsburgh PA 15213-3890
     24  1.1  oster  *
     25  1.1  oster  * any improvements or extensions that they make and grant Carnegie the
     26  1.1  oster  * rights to redistribute these changes.
     27  1.1  oster  */
     28  1.1  oster 
     29  1.1  oster /* rf_etimer.h -- header file for code related to accurate timing
     30  1.1  oster  * This code currently assumes that the elapsed time between START_TIMER
     31  1.1  oster  * and START_TIMER is less than the period of the cycle counter.  This
     32  1.1  oster  * means the events you want to time must be less than:
     33  1.1  oster  *        clock speed               max time
     34  1.1  oster  *        ----------                --------
     35  1.1  oster  *           175 MHz                 24 sec
     36  1.1  oster  *           150 MHz                 28 sec
     37  1.1  oster  *           125 MHz                 34 sec
     38  1.1  oster  *
     39  1.1  oster  *
     40  1.1  oster  */
     41  1.1  oster 
     42  1.1  oster 
     43  1.1  oster #ifndef _RF__RF_TIMER_H_
     44  1.1  oster #define _RF__RF_TIMER_H_
     45  1.1  oster 
     46  1.1  oster #include "rf_options.h"
     47  1.1  oster 
     48  1.1  oster extern unsigned int rpcc(void);
     49  1.1  oster #define rf_read_cycle_counter rpcc
     50  1.1  oster 
     51  1.1  oster #define RF_DEF_TIMER_MAX_VAL            0xFFFFFFFF
     52  1.1  oster 
     53  1.1  oster typedef struct RF_EtimerVal_s {
     54  1.3  oster 	unsigned ccnt;		/* cycle count */
     55  1.3  oster }       RF_EtimerVal_t;
     56  1.1  oster 
     57  1.1  oster struct RF_Etimer_s {
     58  1.3  oster 	RF_EtimerVal_t st;
     59  1.3  oster 	RF_EtimerVal_t et;
     60  1.3  oster 	unsigned long ticks;	/* elapsed time in ticks */
     61  1.1  oster };
     62  1.1  oster 
     63  1.1  oster extern long rf_timer_max_val;
     64  1.1  oster extern long rf_timer_ticks_per_second;
     65  1.1  oster extern unsigned long rf_timer_ticks_per_usec;
     66  1.1  oster 
     67  1.1  oster #define RF_ETIMER_TICKS2US(_tcks_)  ( (_tcks_) / rf_timer_ticks_per_usec )
     68  1.1  oster #define RF_ETIMER_START(_t_)  { (_t_).st.ccnt = rf_read_cycle_counter(); }
     69  1.1  oster #define RF_ETIMER_STOP(_t_)   { (_t_).et.ccnt = rf_read_cycle_counter(); }
     70  1.1  oster #define RF_ETIMER_EVAL(_t_) { \
     71  1.1  oster 	if ((_t_).st.ccnt < (_t_).et.ccnt) \
     72  1.1  oster 		(_t_).ticks = (_t_).et.ccnt - (_t_).st.ccnt; \
     73  1.1  oster 	else \
     74  1.1  oster 		(_t_).ticks = rf_timer_max_val - ((_t_).st.ccnt - (_t_).et.ccnt); \
     75  1.1  oster }
     76  1.1  oster 
     77  1.1  oster #define RF_ETIMER_VAL_TICKS(_t_)  ((_t_).ticks)
     78  1.1  oster #define RF_ETIMER_VAL_US(_t_)      (RF_ETIMER_TICKS2US((_t_).ticks))
     79  1.1  oster #define RF_ETIMER_VAL_MS(_t_)      (RF_ETIMER_TICKS2US((_t_).ticks)/1000)
     80  1.1  oster 
     81  1.1  oster 
     82  1.3  oster #endif				/* !_RF__RF_TIMER_H_ */
     83