??? 03/17/05 12:23 Read: times |
#89860 - Atomic Operations Responding to: ???'s previous message |
Craig Steiner said:
If the variables are single-byte then it's possible that there won't be a problem, but it ultimately depends on whether you read/write the variable in the interrupt, read/write it in the other function, and exactly what you're doing with it in both locations. And, of course, it ultimately depends on the code that the compiler generates in both places. What we are talking about here are atomic operations i.e. an instruction that cannot be interrupted. This is not usually a problem for the ISR as it is doing the interrupting, but the main code may be interrupted halfway thru using the data e.g. mov a, mydatabyte sub a, #OFFSET mov mydatabyte,a This just subtracts an offset from the value. If the interrupt happens to occur during the mov a,mydatabyte instruction then it may put a new value in mydata byte. When the ISR returns this gets overwritten. This is not an atomic operation because several instructions are involved in the operation on the variable. The only operations that are save in this situatiion are atomic ones i.e single instructions of which there are only a few that can do useful operations in this context. Ian |