jamesmunns / bbqueue

A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers
Apache License 2.0
431 stars 51 forks source link

Mark BBBuffer as #[repr(C)] to support alignment #93

Open mciantyre opened 2 years ago

mciantyre commented 2 years ago

Some DMA engines and peripherals require that buffers are precisely aligned. This commit marks BBBuffer as #[repr(C)] so that the buffer is the first member of the struct. With this guarantee, we can align the BBBuffer for our hardware-assisted transfers. Updated documentation shows one way to align the buffer.

Tested on an i.MX RT processor, where the DMA engine requires circular buffers that are power-of-two sized and aligned. If I can't align my BBBuffer, I'll treat the BBBuffer as linear memory and schedule multiple transfers to handle split_read wraparound. I'm happy to go this route if this commit isn't appropriate for bbqueue.