Updated ring buffer
Updated ring buffer to match use case, one write head with negative read index
This commit is contained in:
@@ -9,20 +9,9 @@
|
||||
inline void ringBufferPush(ring_buffer_t *rb, uint32_t value) {
|
||||
rb->buffer[rb->w_head] = value;
|
||||
rb->w_head++;
|
||||
if (rb->w_head == rb->r_head) {
|
||||
// if write head catches up to read head, crash program as consumer task
|
||||
// should keep up with write head
|
||||
assert(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
inline int ringBufferPop(ring_buffer_t *rb, uint32_t *output) {
|
||||
if (rb->w_head == rb->r_head) {
|
||||
// if read head is at write head, buffer is empty so nothing to pop
|
||||
return 1;
|
||||
}
|
||||
*output = rb->buffer[rb->r_head];
|
||||
rb->r_head++;
|
||||
return 0;
|
||||
inline uint32_t ringBufferRead(ring_buffer_t *rb, uint8_t idx) {
|
||||
return rb->buffer[rb->w_head - 1 - idx];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user