delay calculation for LSB in timer
On the following link
Following code is given Code:
loopbit = loops_per_jiffy; Code:
loops_per_jiffy |= loopbit; Code:
loops_per_jiffy &= ~loopbit; |
The first one sets the bits in loopbit, the second operation clears them. The whole operation tries to set the delay, if the current configuration doesn't work, it doesn't use it anymore. Try to work it out using some example numbers.
|
Yea I was able to do it with example.I will mention my observation if some once come here by chance should help them.
lets assume Code:
loops_per_jiffy = 1011 0010 Code:
loopbit = loops_per_jiffy; Code:
/* Gradually work on the lower-order bits */ loopbit = loopbit/2 by above operation so new value of loopbit is Code:
loopbit = 0101 1001 Code:
loops_per_jiffy |= loopbit; Quote:
Quote:
Code:
ticks = jiffies; Code:
while (ticks == jiffies); /* Wait until the start it will make sure that as Code:
tick==jiffies at the start of jiffy Code:
of the next jiffy */ Code:
/* Delay */ Code:
if (jiffies != ticks) will go back divide the loopbits by 2 as a result of >> (right shift) and the OR operation will make sure that the value which is divided by 2 of loopbits gets added to loops_per_jiffy will enter the delay loop and in this case if this time the "if" condition is true then the result of Quote:
Quote:
sure on this part) and the result is the value is subtracted (as it was more than required value) and then loopbit is again divided so added and this cycle will continue until exact value of loops_per_jiffy is calculated. Code:
} I just came across this one. |
All times are GMT -5. The time now is 07:24 AM. |