File syn_pingpong.h¶
FileList > src > syntropic > util > syn_pingpong.h
Go to the source code of this file
Ping-pong (double) buffer — header-only, zero-copy DMA pattern. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_PingPong Ping-pong (double) buffer — zero-copy DMA pattern. |
Public Static Functions¶
| Type | Name |
|---|---|
| uint8_t * | syn_pingpong_active (const SYN_PingPong * pp) Get pointer to the active (being-filled) buffer. |
| void | syn_pingpong_consume (SYN_PingPong * pp) Mark the ready buffer as consumed. Call after processing. |
| void | syn_pingpong_init (SYN_PingPong * pp, uint8_t * buf_a, uint8_t * buf_b, size_t size) Initialize with two user-provided buffers of equal size. |
| bool | syn_pingpong_ready (const SYN_PingPong * pp) Check if the ready buffer has unprocessed data. |
| uint8_t * | syn_pingpong_ready_buf (const SYN_PingPong * pp) Get pointer to the ready (available-for-reading) buffer. |
| size_t | syn_pingpong_size (const SYN_PingPong * pp) Get the buffer size. |
| void | syn_pingpong_swap (SYN_PingPong * pp) Swap buffers. Call from ISR/DMA complete. |
Detailed Description¶
One buffer is "active" (being filled by DMA/ISR), the other is "ready" (available for processing). Call swap() when the active buffer is full to exchange them atomically.
** **
uint8_t pool_a[256], pool_b[256];
SYN_PingPong pp;
syn_pingpong_init(&pp, pool_a, pool_b, 256);
// DMA writes into active buffer:
uint8_t *dma_buf = syn_pingpong_active(&pp);
start_dma(dma_buf, 256);
// DMA complete ISR:
syn_pingpong_swap(&pp);
// Main loop processes the ready buffer:
if (syn_pingpong_ready(&pp)) {
uint8_t *data = syn_pingpong_ready_buf(&pp);
process(data, 256);
syn_pingpong_consume(&pp);
}
Public Static Functions Documentation¶
function syn_pingpong_active¶
Get pointer to the active (being-filled) buffer.
Parameters:
ppPing-pong instance.
Returns:
Active buffer pointer.
function syn_pingpong_consume¶
Mark the ready buffer as consumed. Call after processing.
Parameters:
ppPing-pong instance.
function syn_pingpong_init¶
Initialize with two user-provided buffers of equal size.
static inline void syn_pingpong_init (
SYN_PingPong * pp,
uint8_t * buf_a,
uint8_t * buf_b,
size_t size
)
Parameters:
ppPing-pong instance.buf_aFirst buffer.buf_bSecond buffer.sizeSize of each buffer in bytes.
function syn_pingpong_ready¶
Check if the ready buffer has unprocessed data.
Parameters:
ppPing-pong instance.
Returns:
true if data is ready.
function syn_pingpong_ready_buf¶
Get pointer to the ready (available-for-reading) buffer.
Parameters:
ppPing-pong instance.
Returns:
Ready buffer pointer.
function syn_pingpong_size¶
Get the buffer size.
Parameters:
ppPing-pong instance.
Returns:
Buffer size in bytes.
function syn_pingpong_swap¶
Swap buffers. Call from ISR/DMA complete.
The previously-active buffer becomes ready for processing. The previously-ready buffer becomes the new active buffer.
Parameters:
ppPing-pong instance.
The documentation for this class was generated from the following file src/syntropic/util/syn_pingpong.h