You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠️ Do not use from multiple producers or multiple consumers simultaneously.
💡 Usage Examples
Basic Read / Write
uint8_tbuffer[64]; // Power of 2ring_buff_trb;
ring_buff_init(&rb, buffer, 64);
// Write a stringconstchar*msg="hello";
ring_buff_write(&rb, (uint8_t*)msg, strlen(msg));
// Read into arrayuint8_toutput[32];
size_tn=ring_buff_read(&rb, output, sizeof(output));
// n == 5, output contains "hello"
Interrupt-Driven UART (SPSC)
// ISR context — producervoiduart_rx_isr(uint8_tbyte) {
ring_buff_put(&uart_rx_buffer, byte); // Lock-free, safe in ISR
}
// Main loop — consumervoidprocess_data(void) {
uint8_tbyte;
while (ring_buff_get(&uart_rx_buffer, &byte)) {
handle_byte(byte);
}
}
Zero-Copy DMA Transfer
uint8_t*ptr;
size_tspace=ring_buff_get_write_ptr(&rb, &ptr);
// Configure DMA to write 'space' bytes to 'ptr'// ... DMA completes ...ring_buff_advance_write(&rb, dma_bytes_written);
🔧 Building & Testing
Requirements
GCC or compatible C11 compiler
GNU Make
Build
make # build tests and example
make test# run unit tests
make example # run usage example
make static # build static library (libringbuffer.a)
make debug # build with debug symbols
make clean # remove build artifacts
Running Tests
$ make test
./build/test_ring_buffer
>> RUNNING RING BUFFER DRIVER TEST
>> Lock-free SPSC version (power-of-2 sizing required)
>> TEST: basic init
PASS: init with power-of-2 should succeed
...
>> YAAY! ALL TESTS PASSED
📊 Memory Footprint
Metric
Value
Code size
~1–2 KB (depends on functions used)
RAM overhead
24 bytes per instance (32-bit) / 32 bytes (64-bit)