Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions drivers/dma/dma_si32.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ static int dma_si32_config(const struct device *dev, uint32_t channel, struct dm
return -EINVAL;
}

/* Prevent messing up (potentially) ongoing DMA operations and their settings. This behavior
* is required by the Zephyr DMA API.
*/
if (SI32_DMACTRL_A_is_channel_enabled(SI32_DMACTRL_0, channel)) {
LOG_ERR("DMA channel is currently in use");
return -EBUSY;
}

channel_descriptor = &channel_descriptors[channel];

if (cfg == NULL) {
Expand Down Expand Up @@ -333,8 +341,6 @@ static int dma_si32_config(const struct device *dev, uint32_t channel, struct dm
return -EINVAL;
}

SI32_DMACTRL_A_enable_channel(SI32_DMACTRL_0, channel);

return 0;
}

Expand Down Expand Up @@ -365,7 +371,6 @@ static int dma_si32_start(const struct device *dev, const uint32_t channel)
__ASSERT(SI32_DMACTRL_A_is_primary_selected(SI32_DMACTRL_0, channel),
"Primary descriptors must be used for basic and auto-request operations.");
__ASSERT(SI32_SCONFIG_0->CONFIG.FDMAEN, "Fast mode is recommened to be enabled.");
__ASSERT(SI32_DMACTRL_0->CHENSET.U32 & BIT(channel), "Channel must be enabled.");
__ASSERT(SI32_DMACTRL_0->CHSTATUS.U32 & BIT(channel),
"Channel must be waiting for request");

Expand All @@ -377,6 +382,8 @@ static int dma_si32_start(const struct device *dev, const uint32_t channel)
/* Enable interrupt for this DMA channels. */
irq_enable(DMACH0_IRQn + channel);

SI32_DMACTRL_A_enable_channel(SI32_DMACTRL_0, channel);

/* memory-to-memory transfers have to be started by this driver. When peripherals are
* involved, the caller has to enable the peripheral to start the transfer.
*/
Expand Down Expand Up @@ -405,6 +412,8 @@ static int dma_si32_stop(const struct device *dev, const uint32_t channel)

channel_descriptors[channel].CONFIG.TMD = 0; /* Stop the DMA channel. */

SI32_DMACTRL_A_disable_channel(SI32_DMACTRL_0, channel);

return 0;
}

Expand Down
Loading