Allocate DMA channels dynamically
Instead of relying on arbitrary selected DMA channels for various uses, which requires us to maintain a list of these channels, we could allocate channels dynamically. There exist a function in Zephyr to do so, dma_request_channel
, but it fails when called because of DMA_MAGIC not being set.
Information about DMA_MAGIC is:
/* magic code to identify context content */
#define DMA_MAGIC 0x47494749
This is the kind of stuff we can test again when we move to Zephyr 3.
Code used for the test:
// Obtain DMA channel for the ADC
enum dma_channel_filter filter = DMA_CHANNEL_NORMAL;
int channel = dma_request_channel(dma1, (void*)&filter);
printk("%d\n", channel);
__ASSERT(channel > 0, "Error! No DMA channel available.");