-
-
Notifications
You must be signed in to change notification settings - Fork 140
api: Add DMAPool. #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
api: Add DMAPool. #231
+315
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@iabdalkader
iabdalkader
force-pushed
the
dma_pool
branch
from
May 2, 2024 09:10
5d42631 to
e409b25
Compare
The DMAPool class allocates and manages a pool of buffers that are DMA and cache
friendly, designed for applications that require frequent buffer exchanges between
the CPU and DMA (such as audio applications).
The DMAPool maintains a read and write queues of DMA buffers. DMA buffers' sizes
are rounded up to a multiple of the pool's alignment (which defaults to cache line
size on platforms with caches), and their memory is initialized from one contiguous
memory block.
A typical usage of DMAPool involves allocating a DMA buffer from the write queue
for writing by a producer, updating its contents, and then releasing it. When released,
the DMA buffer returns to the pool, which in turn places it back into the read queue
for later consumption by the consumer. For example:
```C++
// Writer/Producer side (For example, an IRQ handler).
DMABuffer<uint16_t> *buf = pool->alloc(DMA_BUFFER_WRITE);
for (size_t i=0; i<buf.size(); i++) {
buf[i] = 0xFFFF;
}
buf->release();
// Reader/Consumer side (User/library).
DMABuffer<uint16_t> *buf = pool->alloc(DMA_BUFFER_READ);
for (size_t i=0; i<buf.size(); i++) {
print(buf[i]);
}
buf->release();
```
Note that the DMAPool uses single-writer, single-reader lock-free queues to store
buffers, and as such, it can only be used by a single reader and a single writer.
Locks are avoided to allow the DMAPool to be used from an ISR producer/consumer,
with only the main thread, and without disabling IRQs.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
@iabdalkader
iabdalkader
force-pushed
the
dma_pool
branch
from
May 2, 2024 09:18
e409b25 to
4c7bc29
Compare
2 tasks
facchinm
facchinm
approved these changes
May 6, 2024
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.
Uh oh!
There was an error while loading. Please reload this page.
The
DMAPoolclass allocates and manages a pool of buffers that are DMA and cache-friendly, designed for applications that require frequent buffer exchanges between the CPU and DMA (such as audio applications).The
DMAPoolmaintains a read and write queues of DMA buffers. DMA buffers' sizes are rounded up to a multiple of the pool's alignment (which defaults to cache line size on platforms with caches), and their memory is initialized from one contiguous memory block.A typical usage of
DMAPoolinvolves allocating a DMA buffer from the write queue for writing by a producer, updating its contents, and then releasing it. When released, the DMA buffer returns to the pool, which in turn places it back into the read queue for later consumption by the consumer. For example:Note that the
DMAPooluses single-writer, single-reader lock-free queues to store buffers, and as such, it can only be used by a single reader and a single writer. Locks are avoided to allow theDMAPoolto be used from an ISR producer/consumer, with only the main thread, and without disabling IRQs.