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



David M. Palmer wrote:
In article <131km4g7782c44@xxxxxxxxxxxxxxxxxx>, David Kelly
<n4hhe@xxxxxxxxx> wrote:

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.

For the receiving IRQ, the head index (where the incoming data is being
stored) is compared to the tail index (where the unprocessed data is
stored) to prevent the new data from overwriting unprocessed old data,
or at least to notice when it happens. The tail index is modified by
the non-interrupt thread as it processes the data.

If the write to the tail pointer is in the middle of changing when the
interrupt occurs, the data can be silently corrupted.

Back to my original statement, that tail is never used in IRQ.

Wrote earlier in this thread that it is interesting to know when one has overflowed a buffer but that there isn't much one can do to recover in the field. Being a circular buffer an entire buffer full of data is lost but its not the same sort of thing as a buffer overflow security violation.

If one does not notice the data loss from an overflowed buffer then one might claim their application is robust and error tolerant. If the overflow causes your device to barf then one doesn't need debugging flags to indicate something isn't working. Flags might help find it.

Have seen others to go much effort to calculate the length of data in the buffer. Beyond debugging I have seen little need. If there is data waiting it needs to be processed no matter how much is waiting.
.