3 comedi library routines
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-8 David A. Schleef <ds@stm.lbl.gov>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <sys/types.h>
31 #include <sys/ioctl.h>
36 #include <libinternal.h>
42 static int dt282x_timer(double freq,unsigned int *trigvar,double *actual_freq)
44 int divider,prescaler;
47 divider=floor(4e6/(freq));
59 if(prescaler>=16)return -1;
60 *trigvar=(prescaler<<8)|(255-divider);
61 *actual_freq=basefreq/divider;
68 static int dt2814_timer(double freq,unsigned int *trigvar,double *actual_freq)
88 /* atmio/pcimio timer */
89 static int atmio_timer(double freq,unsigned int *trigvar,double *actual_freq)
93 divider=floor(20e6/(freq));
94 *actual_freq=20e6/divider;
101 static int acl8112_timer(double freq,unsigned int *trigvar,double *actual_freq)
103 int divider,prescaler;
106 /* XXX my notes say that the prescaler and divider cannot
107 be 1. This needs to be checked. --ds */
109 /* Force at least one division to get something in CTR2. */
111 divider = basefreq/(freq);
113 while(divider>32767){
118 *trigvar = (prescaler<<16) | divider;
119 *actual_freq=basefreq/(divider*prescaler);
125 static int nanosec_timer(double freq,unsigned int *trigvar,double *actual_freq)
128 *actual_freq=1e9/(*trigvar);
133 typedef int (*timerfunc)(double freq,unsigned int *trigvar,double *actual_freq);
135 static timerfunc timer_functions[]={
143 #define N_TIMERTYPES 6
145 int comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,
146 unsigned int *trigvar,double *actual_freq)
150 if(!it || !trigvar || !actual_freq)
153 timer_type=it->subdevices[subdev].timer_type;
155 if(timer_type==0 || timer_type>=N_TIMERTYPES)
158 return (timer_functions[timer_type])(freq,trigvar,actual_freq);