Page 1 of 1

Help converting code

Posted: Mon Dec 11, 2006 9:45 am
by Seb McClouth
Hey

I've tried to convert this Code:

Code: Select all

unsigned long loops_per_sec = 1; 
228 
229 static void calibrate_delay(void) 
230 { 
231         int ticks; 
232 
233         printk("Calibrating delay loop.. "); 
234         while (loops_per_sec <<= 1) { 
235                 ticks = jiffies; 
236                 __delay(loops_per_sec); 
237                 ticks = jiffies - ticks; 
238                 if (ticks >= HZ) { 
239                         __asm__("mull %1 ; divl %2" 
240                                 :"=a" (loops_per_sec) 
241                                 :"d" (HZ), 
242                                  "r" (ticks), 
243                                  "" (loops_per_sec) 
244                                 :"dx"); 
245                         printk("ok - %lu.%02lu BogoMips\n", 
246                                 loops_per_sec/500000, 
247                                 (loops_per_sec/5000) % 100); 
248                         return; 
249                 } 
250         } 
251         printk("failed\n"); 
252 } 
For as far possible ofcourse since I don't have the ___asm___ thingy. I wrote the following:

Code:

Code: Select all

SUB CalibrateDelay 
Do While LoopsPerSec! <> 0 'needs to be! for use with Delay 
 LoopsPerSec! = LoopsPerSec! * 2 
 ticks = jiffies 
 Delay LoopsPerSec! 
 ticks = jiffies - ticks 
 If LoopsPerSec! >= HZ THEN 'HZ = 100 
  Print "Passed." 
  EXIT LOOP 
 ELSE 
  Print "Failed." 
  EXIT LOOP 
 END IF 
LOOP 
END SUB 

'The Delay Sub I'm using: 
SUB Delay (loops!) 
 T! = Timer + loops! 
 PT! = Timer 
 Do: Loop Until Timer >= T! Or Timer < PT! 
END SUB 

Fairly easy said... it does nothing. Can someone enlight me/help me out?