Circular Buffer
Posted: Fri Apr 17, 2020 7:02 pm
Mentioned this briefly in passing in the forum.
Circular buffer GetNumberOfBytes - doesn't return correct value.
Demonstrates (in simulation or on hardware) - the circular buffer size (in my demo) is 128 bytes - but the maximum size returned by GetNumberOfBytes is 127.
I think the error is in GetNumberofBytes:
Following PutByte - DATAEND has a maximum value (the index into the buffer) or 127 - and if DATASTART = 0 (buffer full for the first time) - then the maximum value returned will be 127. This, however, is the index of the final byte rather than the number of bytes. I didn't attempt the math for other possibilities but the value should be +1 here.
PutBytes - looks correct (FCL_TEMP >=128) so reading data from the buffer will possibly lose a byte????
Martin
Circular buffer GetNumberOfBytes - doesn't return correct value.
Demonstrates (in simulation or on hardware) - the circular buffer size (in my demo) is 128 bytes - but the maximum size returned by GetNumberOfBytes is 127.
I think the error is in GetNumberofBytes:
Code: Select all
if (FCV_01211_CircularBuffer1__DATAEND > FCV_01211_CircularBuffer1__DATASTART)
{
// .Return = DataEnd - DataStart
FCR_RETVAL = FCV_01211_CircularBuffer1__DATAEND - FCV_01211_CircularBuffer1__DATASTART;
PutBytes - looks correct (FCL_TEMP >=128) so reading data from the buffer will possibly lose a byte????
Martin