57 lines
2.2 KiB
C
57 lines
2.2 KiB
C
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
typedef struct {
|
|
volatile uint32_t SRC_ADDR; // 0x00: 源地址
|
|
volatile uint32_t DST_ADDR; // 0x04: 目的地址
|
|
volatile uint32_t LENGTH; // 0x08: 传输总字节数
|
|
volatile uint32_t TAG; // 0x0C: 软件 Tag (硬件不处理,留给软件标记任务用)
|
|
volatile uint32_t CTRL; // 0x10: 控制寄存器 (配置 Burst 属性 + 启动)
|
|
volatile uint32_t STATUS; // 0x14: 状态寄存器 (Busy, Done)
|
|
volatile uint32_t MODE; // 0x18: 0=mem2mem, 1=mem2ep, 2=ep2mem
|
|
volatile uint32_t EP_CFG; // 0x1C: [3:0]=bank, [15:8]=word offset, [19:16]=endpoint id
|
|
volatile uint32_t RESV[8]; // 0x20 ~ 0x3C: 保留空间,凑齐 0x40 字节
|
|
} dma_ch_regs_t;
|
|
|
|
// DMA 控制器基地址
|
|
#define CDMA_MUX_BASE 0xbf300000
|
|
#define DMA_CH(i) ((volatile dma_ch_regs_t*)(CDMA_MUX_BASE + (i) * 0x40))
|
|
|
|
typedef struct {
|
|
volatile uint32_t CTRL; // 0x200: bit0 start
|
|
volatile uint32_t STATUS; // 0x204: bit0 busy, bit1 done (W1C)
|
|
volatile uint32_t SRC_BASE; // 0x208
|
|
volatile uint32_t DST_BASE; // 0x20C
|
|
volatile uint32_t GROUPS; // 0x210
|
|
volatile uint32_t MAT_BASE; // 0x214: 保留,兼容旧软件
|
|
volatile uint32_t SRC_STRIDE; // 0x218
|
|
volatile uint32_t DST_STRIDE; // 0x21C
|
|
} dma_seq_regs_t;
|
|
|
|
#define DMA_SEQ ((volatile dma_seq_regs_t*)(CDMA_MUX_BASE + 0x200))
|
|
|
|
// CTRL 寄存器位定义
|
|
#define CTRL_START_BIT (1 << 0)
|
|
#define CTRL_BURST_SIZE(x) (((x) & 0x7) << 3) // Bits [5:3]: AXI AxSIZE (0=1B, 1=2B, 2=4B, 3=8B)
|
|
#define CTRL_BURST_LEN(x) (((x) & 0xFF) << 6) // Bits [13:6]: AXI AxLEN (0=1 beat, 15=16 beats)
|
|
|
|
#define DMA_MODE_MEM2MEM 0
|
|
#define DMA_MODE_MEM2EP 1
|
|
#define DMA_MODE_EP2MEM 2
|
|
#define DMA_EP_CFG(id, bank, word_off) \
|
|
((((id) & 0xF) << 16) | (((word_off) & 0xFF) << 8) | ((bank) & 0xF))
|
|
|
|
// STATUS 寄存器位定义
|
|
#define STATUS_BUSY_BIT (1 << 0)
|
|
#define STATUS_DONE_BIT (1 << 1)
|
|
|
|
#define SEQ_START_BIT (1 << 0)
|
|
#define SEQ_SKIP_STORE_BIT (1 << 1)
|
|
#define SEQ_BUSY_BIT (1 << 0)
|
|
#define SEQ_DONE_BIT (1 << 1)
|
|
|
|
void dma_start_transfer(int ch_id, uint32_t src, uint32_t dst, uint32_t bytes, uint32_t tag);
|
|
void dma_wait_polling(int ch_id);
|