This repository has been archived on 2026-08-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ciciec2026/sdk/software/bsp/drivers/dma.c
FallenSigh e35fa5884d Use uncached ExtRAM access (0xBC400000) to bypass CPU data cache
The open-la500 core has USE_CACHE enabled. Writes to 0x1c400000
go to the write-back data cache and never reach the SRAM model
before the testbench checks ExtRAM. Use the 0xA0000000 uncached
segment (same pattern as fft_dma/main.c).
2026-06-24 02:04:40 +08:00

37 lines
1.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "dma.h"
void dma_start_transfer(int ch_id, uint32_t src, uint32_t dst, uint32_t bytes, uint32_t tag) {
volatile dma_ch_regs_t* ch = DMA_CH(ch_id);
// 检查通道是否空闲 防止覆盖正在运行的任务
if (ch->STATUS & STATUS_BUSY_BIT) {
// printf("channel %d busy\n", ch_id);
return; // 通道正忙,处理报错或重试
}
// 写入基本地址和长度
ch->SRC_ADDR = src;
ch->DST_ADDR = dst;
ch->LENGTH = bytes;
ch->TAG = tag; // 可选,填入任务ID
// 置 Burst 属性并触发传输
// AXI SIZE: 2 (代表 2^2 = 4 Bytes,与 32-bit 数据线匹配)
// AXI LEN: 15 (代表 16 beats 突发传输,最高效)
uint32_t ctrl_val = CTRL_BURST_SIZE(2) | CTRL_BURST_LEN(15);
// 写入 CTRL 并拉高 Bit 0 (Start)
ch->CTRL = ctrl_val | CTRL_START_BIT;
}
void dma_wait_polling(int ch_id) {
volatile dma_ch_regs_t* ch = DMA_CH(ch_id);
// 死等 Done bit 置 1
while (!(ch->STATUS & STATUS_DONE_BIT)) {
}
// 清除 Done 标志位 (Write 1 to Clear Bit 1)
// 注意:写 1 清 0 的设计,所以我们对 bit 1 写入 1
ch->STATUS = STATUS_DONE_BIT;
}