Advertisement
Guest User

loop based udelay without multiplication

a guest
Jun 18th, 2010
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. static inline void udelay(unsigned usecs)
  2. {
  3.     unsigned cycles_per_usec;
  4.     unsigned loops_per_usec;
  5.  
  6.     if (cpu_frequency == CPUFREQ_MAX) {
  7.         cycles_per_usec = (CPUFREQ_MAX + 999999) / 1000000;
  8.     } else {
  9.         cycles_per_usec = (CPUFREQ_NORMAL + 999999) / 1000000;
  10.     }
  11.  
  12.     /*
  13.      * One iteration of the inner loop takes 4 cycles,
  14.      * sustract 1 to account for the outer loop.
  15.      */
  16.     loops_per_usec = (cycles_per_usec+3)/4 - 1;
  17.  
  18.     asm volatile(
  19.         "2: mov  r0, %1      \n"
  20.         "1: subs r0, r0, #1  \n"
  21.         "   bne  1b          \n"
  22.         "   subs %0, %0, #1  \n"
  23.         "   bne  2b          \n"
  24.         : : "r"(usecs), "r"(loops_per_usec) : "r0"
  25.     );
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement