pic0
Posts: 34
Joined: Tue Jan 26, 2021 11:04 am

Check claim status of DMA channel

Mon Apr 19, 2021 11:29 am

Hi,

how can I check if a DMA channel (specific channel number) is currently claimed or not?

When I do a

Code: Select all

dma_channel_unclaim(channel);
it will end in a assertion if the given channel is not claimed before. So I want to call this function only in case the channel has been claimed before.

martinkooij
Posts: 53
Joined: Sun Feb 28, 2021 5:22 pm
Location: The Netherlands

Re: Check claim status of DMA channel

Tue Apr 20, 2021 3:18 pm

Hi,

Haven't found one in the SDK (you could check the SDK code how it administers claimed channels and add the function yourself ;). Or use a try/catch pair in C++ with exceptions enabled (haven't tried that one yet myself though).

I think the intended use case is my_chan = dma_claim_unused_channel(false). my_chany is negative when it fails and the channel number when you get one. At the end you can do dma_channel_unclaim(my_chan) to free for other users/libraries.

You want to unclaim a "surprise" channel that you didn't claim before?

Cheers,
Martin

pic0
Posts: 34
Joined: Tue Jan 26, 2021 11:04 am

Re: Check claim status of DMA channel

Tue Apr 20, 2021 10:11 pm

Hi,

yes, I have searched in the SDK too without success. Thats why I have asked.

The use case would be to release all active DMA channels. Yes, usually it is known which are were claimed before. But sometimes it would be easier to just do a simple loop and close just every channel.

But if there is no such function, I will go without it.

danjperron
Posts: 3765
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Check claim status of DMA channel

Wed Apr 28, 2021 8:19 pm

Why not making you own!

in pico-sdk/src/rp2_common/hardware/dma.c add this function

Code: Select all

bool dma_channel_is_claimed(uint channel) {
    check_dma_channel_param(channel);
    return hw_is_claimed(uint8_t *) &_claimed,channel);
}
and add the function declaration in the include/harwdare/dma.h

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 488
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: Check claim status of DMA channel

Thu Apr 29, 2021 1:22 am

better still, make a PR on github

danjperron
Posts: 3765
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Check claim status of DMA channel

Thu Apr 29, 2021 1:28 am

better still, make a PR on github
How long a PR will take ?

Maybe doing both is the best!

When the PR returns with something modify the code with the official code.

Return to “SDK”