mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-12 19:10:32 +03:00
PICO: Correct DMA index usage
//TODO: index / channel / identifier can be one and the same - need support for zero based
This commit is contained in:
parent
6a95d4e13f
commit
62ad213878
2 changed files with 25 additions and 5 deletions
|
@ -58,13 +58,12 @@ dmaChannelDescriptor_t dmaDescriptors[DMA_LAST_HANDLER] = {
|
|||
#endif
|
||||
};
|
||||
|
||||
#define DMA_CHANNEL_TO_INDEX(channel) ((channel) + 1)
|
||||
|
||||
void dma_irq_handler(bool isIrq1)
|
||||
{
|
||||
uint32_t status = isIrq1 ? dma_hw->ints1 : dma_hw->ints0; // Read the status register once
|
||||
|
||||
// Iterate through all possible DMA channels that have triggered an interrupt
|
||||
// channel equates to index in the dmaDescriptors array
|
||||
for (uint8_t channel = 0; channel < DMA_LAST_HANDLER; channel++) {
|
||||
if (status & (1u << channel)) {
|
||||
uint8_t index = DMA_CHANNEL_TO_INDEX(channel);
|
||||
|
@ -92,8 +91,21 @@ void dma_irq1_handler(void)
|
|||
dma_irq_handler(true);
|
||||
}
|
||||
|
||||
dmaIdentifier_e dmaGetFreeIdentifier(void)
|
||||
{
|
||||
const int channel = dma_claim_unused_channel(true);
|
||||
if (channel == DMA_INVALID) {
|
||||
return DMA_INVALID; // No free channel available
|
||||
}
|
||||
return DMA_CHANNEL_TO_IDENTIFIER(channel);
|
||||
}
|
||||
|
||||
void dmaSetHandler(dmaIdentifier_e identifier, dmaCallbackHandlerFuncPtr callback, uint32_t priority, uint32_t userParam)
|
||||
{
|
||||
if (identifier < DMA_CH0_HANDLER || identifier > DMA_LAST_HANDLER) {
|
||||
return; // Invalid identifier
|
||||
}
|
||||
|
||||
UNUSED(priority);
|
||||
/*
|
||||
Assign the interrupt handler for the DMA channel based on the core
|
||||
|
@ -114,7 +126,8 @@ void dmaSetHandler(dmaIdentifier_e identifier, dmaCallbackHandlerFuncPtr callbac
|
|||
const uint8_t core = 0;
|
||||
#endif
|
||||
|
||||
const uint32_t channel = dmaDescriptors[identifier].channel;
|
||||
const int index = DMA_IDENTIFIER_TO_INDEX(identifier);
|
||||
const uint32_t channel = dmaDescriptors[index].channel;
|
||||
if (core) {
|
||||
// Core 1 uses DMA IRQ1
|
||||
if (!dma_irq1_handler_registered) {
|
||||
|
@ -133,8 +146,8 @@ void dmaSetHandler(dmaIdentifier_e identifier, dmaCallbackHandlerFuncPtr callbac
|
|||
}
|
||||
}
|
||||
|
||||
dmaDescriptors[identifier].irqHandlerCallback = callback;
|
||||
dmaDescriptors[identifier].userParam = userParam;
|
||||
dmaDescriptors[index].irqHandlerCallback = callback;
|
||||
dmaDescriptors[index].userParam = userParam;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "platform.h"
|
||||
|
||||
typedef enum {
|
||||
DMA_INVALID = -1,
|
||||
DMA_NONE = 0,
|
||||
DMA_CH0_HANDLER = 1,
|
||||
DMA_CH1_HANDLER,
|
||||
|
@ -65,3 +66,9 @@ typedef enum {
|
|||
.owner.owner = 0, \
|
||||
.owner.resourceIndex = 0 \
|
||||
}
|
||||
|
||||
#define DMA_IDENTIFIER_TO_CHANNEL(identifier) ((identifier) - 1)
|
||||
#define DMA_CHANNEL_TO_IDENTIFIER(channel) ((dmaIdentifier_e)((channel) + 1))
|
||||
#define DMA_CHANNEL_TO_INDEX(channel) (channel)
|
||||
|
||||
dmaIdentifier_e dmaGetFreeIdentifier(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue