Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.



David M. Palmer wrote:
In article <28b79$4618394d$d8ba94f9$19383@xxxxxxxxxxx>, David Kelly
<n4hhe@xxxxxxxxx> wrote:

Don't modify the tail index in IRQ, don't modify the head index outside of IRQ. With that simple rule there is no need to protect either variable by disabling IRQs. Remember the head index can change at any time. In my example code the head should have been declared volatile.


Also, the changes to the tail pointer must be 'atomic'.

(I haven't read this whole thread, so you may have mentioned that.)

If you have an 8-bit processor modifying a 16-bit tail pointer a byte
at a time, then if an interrupt can slide in between a) incrementing
the low-byte from 0xff to 0x00, and b) incrementing the high byte with
the carry, then you will have a bug which is VERY hard to find, but
WILL bite you at the most inopportune time.

No. As stated in the original conditions the tail *index* is never modified during IRQ. In fact it is never used in IRQ. So there is no atomic question.
.