This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

is this a good idea?

Hello,

I have a free running hardware timer on a LPC2478 (timers are 32 bit). no interrupts related to that timer are used.

can the following code corrupt the value latched from
the hardware timer, if the timer ticks just when the copy is done? can it cause a misbehavior of the loop? I know this is not a good programming example - I'm just curious.

unsigned long timer_value_ref = T2TC ;

do
{
}
while (T2TC - timer_value_ref < 1000) ;

Parents
  • The processor is fully 32-bit, so it can read a 32-bit variable from without the possibility of an ISR to interfere.

    But anyway - a variable handled by two threads or between the main application and an ISR should be specified as volatile, to make sure that the compiler always reloads the current value (possibly changed by the ISR or another thread) instead of loading the variable once and then just relying on the contents in a register.

Reply
  • The processor is fully 32-bit, so it can read a 32-bit variable from without the possibility of an ISR to interfere.

    But anyway - a variable handled by two threads or between the main application and an ISR should be specified as volatile, to make sure that the compiler always reloads the current value (possibly changed by the ISR or another thread) instead of loading the variable once and then just relying on the contents in a register.

Children
No data