Implemented ring buffer with inline push and pop functions Updated copyrights on main.c and ring_buffer files
29 lines
798 B
C
29 lines
798 B
C
// Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
|
// Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include <assert.h>
|
|
#include <ring_buffer.h>
|
|
#include <stdbool.h>
|
|
|
|
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;
|
|
}
|