5 COMEDILIB - Linux Control and Measurement Device Interface Library
6 Copyright (C) 1997-2001 David A. Schleef <ds@schleef.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation, version 2.1
13 This library 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 GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <sys/types.h>
31 #include <sys/ioctl.h>
35 #include "libinternal.h"
41 static int dt282x_timer(double freq,unsigned int *trigvar,double *actual_freq)
43 int divider,prescaler;
46 divider=floor(4e6/(freq));
58 if(prescaler>=16)return -1;
59 *trigvar=(prescaler<<8)|(255-divider);
60 *actual_freq=basefreq/divider;
67 static int dt2814_timer(double freq,unsigned int *trigvar,double *actual_freq)
87 /* atmio/pcimio timer */
88 static int atmio_timer(double freq,unsigned int *trigvar,double *actual_freq)
92 divider=floor(20e6/(freq));
93 *actual_freq=20e6/divider;
100 static int acl8112_timer(double freq,unsigned int *trigvar,double *actual_freq)
102 int divider,prescaler;
105 /* XXX my notes say that the prescaler and divider cannot
106 be 1. This needs to be checked. --ds */
108 /* Force at least one division to get something in CTR2. */
110 divider = basefreq/(freq);
112 while(divider>32767){
117 *trigvar = (prescaler<<16) | divider;
118 *actual_freq=basefreq/(divider*prescaler);
124 static int nanosec_timer(double freq,unsigned int *trigvar,double *actual_freq)
127 *actual_freq=1e9/(*trigvar);
132 typedef int (*timerfunc)(double freq,unsigned int *trigvar,double *actual_freq);
134 static timerfunc timer_functions[]={
142 #define N_TIMERTYPES 6
144 EXPORT_ALIAS_DEFAULT(_comedi_get_timer,comedi_get_timer,0.7.18);
145 int _comedi_get_timer(comedi_t *it,unsigned int subdev,double freq,
146 unsigned int *trigvar,double *actual_freq)
150 if(!valid_subd(it,subdev) || !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);