Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- From: David Kelly <n4hhe@xxxxxxxxx>
- Date: Mon, 09 Apr 2007 10:15:27 -0500
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.
.
- Follow-Ups:
- Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- From: David M. Palmer
- Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- References:
- C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- From: Roger Walker
- Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- From: Paul Burke
- Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- From: Roger Walker
- Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- From: David Kelly
- Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- From: David M. Palmer
- C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- Prev by Date: Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- Next by Date: Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- Previous by thread: Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- Next by thread: Re: C 'desktop' programmer needs advice on how to code embedded C on a micro controller.
- Index(es):