??? 03/17/05 19:25 Read: times |
#89879 - Common Solutions Responding to: ???'s previous message |
Erik Malund said:
my rule re ISR/main sharing of variables is
if both can write to a byte or the variable is longer than a byte, it may only be accessed in main code with interrupts disabled. That is the most common and most robust rule to solve the shared data problem - it effectively makes a sequence of instructions atomic. Its only disadvantage is that it increases the worst case interrupt latency.There are other solutions including semaphors and queues but these are less reliable. The problem here is that when coding in C, the variable may be hidden if that rule is observed. qwerty &= 0xf0; may seem "atomic" but is not, in assembly mov a,qwerty, and a,#0f0h, mov qwerty,a is easy to recognize as non-atomic. Another reason why proper knowledge of assembly is essential for embedded programming. Ian |