Hi, I am writing a circular buffer where originally its structure was the classic one (I guess), in the rbuffer.c lib:
struct ring_buff { uint8_t buff[RB_SIZE]; rb_sz_t head; rb_sz_t tail; rb_sz_t count; };
The problem is that in the serial.c I instantiate 2 buffers, for TX and RX. But one of them may need a rather smaller size. And I might want to use the ring buffer for other communication code, which could include very long buffers or jsut few chars.
So I thought:
struct ring_buff { uint8_t** buff; rb_sz_t head; rb_sz_t tail; rb_sz_t count; };
Because when I dereference buff I need to get back a pointer of where my (serial, for example) buffer is located.
So I declare:
uint8_t tx_buff[SER_RB_SIZE]; uint8_t rx_buff[SER_RB_SIZE]; struct ring_buff* serial_tx_buff; struct ring_buff* serial_rx_buff;
and I initialize pointers in this way:
(*(uint8_t**)serial_tx_buff->buff) = tx_buff; (*(uint8_t**)serial_rx_buff->buff) = rx_buff;
The test echo code, if with the original code was working, now does gobbledygook. So, to cut down the problem, here the first issue.
Here you see the initial statues of the array and their pointers:
When initializing, the poiner of tx get correcty stored in the tx struct. But also on the rx one (???).
Then, when the RX buff gets assigned, for some reason its value is stored in the location (of data!) of the tx buff.
If I solve this, I may think where I am wrong with the read and write. But I believe there is something very wrong with what I am doing.
Is it even possible at all? Any alternative?