| ??? 02/08/04 12:12 Read: times |
#64225 - RE: Circular buffers Responding to: ???'s previous message |
Circular buffers - such a simple concept but loaded with traps for the unwary.
I think the Keil site has demo code for circ buffers in 'c' - I modified this to work with an AVR cpu recently. Debug the tx and rx buffer separately. Test the tx one first as it's the easiest. Be sure to pay attention to variables that are shared between the interrupt code and the main line code (like the pointers). The interrupt code can jump in at any time on you main line code so whenever your mail line code has to read the pointers or modify the pointers that you lock out the interrupts whilst you do this. This the tx circ buffer by having your main line code sent 1 char, then 2 chars, 10 chars then more than the buffer size (>100 chars). If it survives these tests then there is a fair chance that it works. Then onto the rx buffer. Same warnings apply. I went through all this recently whilst tutoring a younger employee. We hit all the possible problems!! At the end we had some nice, robust and tested code. |



