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
  • can it cause a misbehavior of the loop?

    To judge that, you'll have to describe the desired behavior of the loop first.

    can the following code corrupt the value latched from the hardware timer, if the timer ticks just when the copy is done?

    On an ARM, the read should be atomic (unless the compiler messes things up), so there shouldn't be any atomicitiy issues.

    However, in the unlikely case that the loop takes longer than it takes the timer to overflow, you might get a longer delay than you expected.

Reply
  • can it cause a misbehavior of the loop?

    To judge that, you'll have to describe the desired behavior of the loop first.

    can the following code corrupt the value latched from the hardware timer, if the timer ticks just when the copy is done?

    On an ARM, the read should be atomic (unless the compiler messes things up), so there shouldn't be any atomicitiy issues.

    However, in the unlikely case that the loop takes longer than it takes the timer to overflow, you might get a longer delay than you expected.

Children