[En-Nut-Discussion] AVR ADC sample fails

Harald Kipp harald.kipp at egnite.de
Wed Jul 8 20:12:04 CEST 2009


Ole Reinhardt wrote:
>>> But I'd still vote for 
>>>
>>> #define ADC_BUF_TAIL (ADC_BUF_SIZE+1)
>>> [...]
>>> buf[ADC_BUF_TAIL] = 0;
>>>
>>> instead of using 
>>>
>>> buf[ADC_BUF_SIZE+1] = 0;
>> The disadvantage is, that something is hidden. What's the advantage then?
> 
> The advantage is that you know what this array index is used for. On the
> other hand it's no good idea to save the head and tail pointer in the
> buffer at all. It better should be solved as seperate variables. But
> this design allows you to just pass the buffer array to a function
> instead of several variables. Yes, we should better put all this stuff
> in a struct.

I didn't understand really what's going on in this code, but now it
makes sense. I agree with both, that the special use of the 2 upper
elements requires the defines and that a structure would be easier to
understand.

Indeed, parameter passing consumes a lot of code space on the AVR.

Harald





More information about the En-Nut-Discussion mailing list