Hello guys,
I have a little problem when implementing a circular Buffer.
I've defined two structs:
typedef
struct{
short value;
}ElemType;
typedef
struct{
long size;
long start;
long end;
ElemType *elems;
}Circular_Buffer;
After that in a loop in main program i read the value contained in a register, and I want to record it into the Buffer:
data->value = I2S2_RXLT1;
Write_Circular_Buffer(&Buffer,data);
I have declared the structs as follows:
ElemType *data;
Circular_Buffer Buffer;
The Write_Circular_Buffer function is the next:
void
Write_Circular_Buffer(Circular_Buffer *cb, ElemType *elem)
{
cb->elems[cb->end] = *elem;
cb->end = (cb->end + 1) % cb->size;
if (cb->end == cb->start)
{
cb->start = (cb->start + 1) % cb->size;
}
}
The problem is that after that If i look at the value in Buffer.elems[i].value, it doesn't correspond with the values of data->value.
Hope you can help me,
Best regards,
Albert Torné