Quote:
Originally Posted by vamfun
This is along the lines I was thinking. But it seems that we have to capture the complete register array before we start using the results or at least temporarily halt the interrupts while we do multiple register reads.
I.E Wouldn't this be a possible problem?
Code:
*/
INT32 Counter::Chris_Get()
{
INT32 cnt = m_counter->readOutput_Value(&status);
bool dir = m_counter->readOutput_Direction(&status);
//Couldn't the registers be different when we read dir vs the cnt read ??
if(dir ) // Assume dir = 0 decrements count
{ return value ; } // if we haven't reversed then update count
else
{ return value +1; } // else keep the count at last value
}
|
Yes... if you did it that way, you would have a small window for the register to change. However, that is why I put both in the same register. Same thing goes for the period, the count, and the stall information. All related; all in the same register.
If instead you did:
Code:
INT32 Counter::Chris_Get()
{
//Now all the information is read in one register access!
tCounter::tOutput output = m_counter->readOutput(&status);
// dir = 0 decrements count
if (output.Direction)
{
// if we haven't reversed then update count
return output.Value;
}
else
{
// else keep the count at last value
return output.Value + 1;
}
}
Cheers!
-Joe