Fixed critical ring buffer underflow bug
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <assert.h>
|
||||
#include <ring_buffer.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void ringBufferPush(volatile ring_buffer_t *rb, uint32_t value) {
|
||||
rb->buffer[rb->w_head] = value;
|
||||
@@ -13,7 +14,8 @@ void ringBufferPush(volatile ring_buffer_t *rb, uint32_t value) {
|
||||
}
|
||||
|
||||
uint32_t ringBufferRead(volatile ring_buffer_t *rb, uint8_t neg_idx) {
|
||||
return rb->buffer[rb->w_head - 1 - neg_idx];
|
||||
uint8_t idx = (uint8_t)(rb->w_head - 1u - neg_idx);
|
||||
return rb->buffer[idx];
|
||||
}
|
||||
|
||||
void ringBufferRevert(volatile ring_buffer_t *rb, uint8_t val) {
|
||||
|
||||
Reference in New Issue
Block a user