由于某些设计需求,我需要在运行时更改DMA描述符。为实现这一目标,我将采取以下步骤:
这是我正在使用的代码片段:
//Select DMA channel
DMAC->CHID.reg = DMAC_CHID_ID(cSPIDMAResource0.channel_id);
//Abort Selected DMA channel
DMAC->CHCTRLA.reg &= ~DMA_CHANNEL_ENABLE_BIT_POS;
//Wait until Abort completed
while((DMAC->CHCTRLA.reg & DMA_CHANNEL_ENABLE_BIT_POS) == DMA_CHANNEL_ENABLE_BIT_POS);
/*
Modify Descriptor here
*/
//Enable DMA channel
DMAC->CHCTRLA.reg |= DMA_CHANNEL_ENABLE_BIT_POS;上面提到的步骤运行良好,没有任何问题,但从长远来看,我面临描述符损坏问题。
在执行DMA中止时,DMA硬件正在将当前执行描述符存储在另一个DMA信道的write_back RAM位置(而不是自己的write_back RAM位置)。
如果有人知道出了什么问题,或者知道如何才能完全避免描述符腐败问题,我想尝试一下。
发布于 2015-11-24 15:59:46
为什么不使用atmel软件框架的dma驱动程序呢?这是他们做流产的方法。
void dma_abort_job(struct dma_resource *resource)
{
uint32_t write_size;
uint32_t total_size;
Assert(resource);
Assert(resource->channel_id != DMA_INVALID_CHANNEL);
system_interrupt_enter_critical_section();
DMAC->CHID.reg = DMAC_CHID_ID(resource->channel_id);
DMAC->CHCTRLA.reg = 0;
system_interrupt_leave_critical_section();
/* Get transferred size */
total_size = descriptor_section[resource->channel_id].BTCNT.reg;
write_size = _write_back_section[resource->channel_id].BTCNT.reg;
resource->transfered_size = total_size - write_size;
resource->job_status = STATUS_ABORTED;
}可以解释这一问题的一个不同之处是,在寄存器写入终止dma通道时,通过system_interrupt_leave_critical_section()禁用中断。
https://stackoverflow.com/questions/33750367
复制相似问题