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