From: David Schleef Date: Fri, 3 Mar 2000 23:10:09 +0000 (+0000) Subject: added timer function X-Git-Tag: r0_7_40~16 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1d08be3d818861df476b2b15dfb860dc31ba3e28;p=comedi.git added timer function --- 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; +} +