Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
facchinm merged 1 commit intoarduino:masterfromiabdalkader:dma_pool
May 6, 2024
Merged

api: Add DMAPool.#231

facchinm merged 1 commit intoarduino:masterfromiabdalkader:dma_pool
May 6, 2024

Conversation

@iabdalkader
Copy link
Contributor

@iabdalkaderiabdalkader commentedMay 2, 2024
edited
Loading

TheDMAPool 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).
TheDMAPool 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 ofDMAPool 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:

// 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 theDMAPool 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 theDMAPool to be used from an ISR producer/consumer, with only the main thread, and without disabling IRQs.

The DMAPool class allocates and manages a pool of buffers that are DMA and cachefriendly, designed for applications that require frequent buffer exchanges betweenthe CPU and DMA (such as audio applications).The DMAPool maintains a read and write queues of DMA buffers. DMA buffers' sizesare rounded up to a multiple of the pool's alignment (which defaults to cache linesize on platforms with caches), and their memory is initialized from one contiguousmemory block.A typical usage of DMAPool involves allocating a DMA buffer from the write queuefor 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 queuefor 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 storebuffers, 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>
@facchinmfacchinm merged commit6ebbb86 intoarduino:masterMay 6, 2024
@iabdalkaderiabdalkader deleted the dma_pool branchMay 6, 2024 10:39
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@facchinmfacchinmfacchinm approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@iabdalkader@facchinm@per1234

[8]ページ先頭

©2009-2025 Movatter.jp