From 1d08be3d818861df476b2b15dfb860dc31ba3e28 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Fri, 3 Mar 2000 23:10:09 +0000 Subject: [PATCH] added timer function --- comedi/drivers/pcl812.c | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/comedi/drivers/pcl812.c b/comedi/drivers/pcl812.c index b7975041..2c674102 100644 --- a/comedi/drivers/pcl812.c +++ b/comedi/drivers/pcl812.c @@ -783,3 +783,55 @@ void cleanup_module(void) comedi_driver_unregister(&driver_pcl812); } #endif + + +/* pcl812 timer */ +void Zisti_Div8254(long celk, long *d1, long *d2) { + + long minch,chyba,mini,i; + + minch=32000; mini=1; + if (celk<=(65536*2)) { i=2; + } + else { i=celk / 65536; } + do + { + *d1=i; + *d2=celk / *d1; + if (*d2<65536) { + chyba=celk- *d1* *d2; + if (chyba<0) { chyba=-chyba; } + if (chyba2)&&(*d2> *d1)); + i=mini; + *d1 =i; + *d2=celk/ *d1; +} + +#include + +static int pcl812_timer(double freq,unsigned int *trigvar,double *actual_freq) { + + long divisor1,divisor2,divid; + double Oscilator=2e6; + + if (freq<0.0004) { freq=0.0004; } + if (freq>30000) { freq=30000; } + divid=rint(Oscilator/freq); + Zisti_Div8254(divid,&divisor1,&divisor2); + // @@Kluvi: magic crystaline sphere error correction, I hope that work identicaly under C and TP :-) } + divid=rint(Oscilator/freq+0.5* +(divid-divisor1*divisor2)); + Zisti_Div8254(divid,&divisor1,&divisor2); + *actual_freq=Oscilator/(divisor1*divisor2); + + *trigvar = (divisor1<<16) | divisor2; + return 0; +} + -- 2.26.2