test(dma,fft): rewrite test programs for dma, fft and fft_dma

This commit is contained in:
2026-04-13 17:26:12 +08:00
parent 63fb8f6cc1
commit 84155db987
3 changed files with 28 additions and 109 deletions

View File

@@ -1,8 +1,10 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <common_func.h>
#include <confreg_time.h>
#include <fft.h>
// BSP板级支持包所需全局变量
unsigned long UART_BASE = 0xbf000000;
@@ -10,24 +12,6 @@ unsigned long CONFREG_TIMER_BASE = 0xbf20f100;
unsigned long CONFREG_CLOCKS_PER_SEC = 50000000L;
unsigned long CORE_CLOCKS_PER_SEC = 33000000L;
#define FFT_BASE 0xbf400000
#define FFT_IN_RE_BASE (FFT_BASE + 0x1000)
#define FFT_IN_IM_BASE (FFT_BASE + 0x2000)
#define FFT_OUT_RE_BASE (FFT_BASE + 0x3000)
#define FFT_OUT_IM_BASE (FFT_BASE + 0x4000)
#define FFT_CSR_REG (FFT_BASE + 0xF000)
#define FFT_CTRL_START (1 << 4)
#define FFT_STAT_DONE (1 << 1)
#define FFT_STAT_BUSY (1 << 0)
#define FFT_POINT_NUM 1024
#define DMA_BASE 0xbf300000
#define DMA_CTRL (DMA_BASE + 0x0000)
#define DMA_LEN (DMA_BASE + 0x0004)
#define DMA_SRC_ADDR (DMA_BASE + 0x0008)
#define DMA_DST_ADDR (DMA_BASE + 0x000c)
#define DMA_STATUS (DMA_BASE + 0x0010)
const float PI = 3.14159265358979323846;
// 读取定时器的当前Tick
@@ -35,14 +19,12 @@ unsigned int get_timer_ticks() {
return RegRead(CONFREG_TIMER_BASE);
}
// ---------------------------------------------------------
// 软件FFT实现 (基2 DIT-FFT 算法)
// ---------------------------------------------------------
void sw_fft(float re[], float im[], int n) {
int i, j, k, l;
float tr, ti, ur, ui, wr, wi;
// 1. 比特翻转 (Bit Reversal)
// 比特翻转 (Bit Reversal)
j = 0;
for (i = 0; i < n - 1; i++) {
if (i < j) {
@@ -58,7 +40,7 @@ void sw_fft(float re[], float im[], int n) {
j += k;
}
// 2. 蝶形运算 (Butterfly Computation)
// 蝶形运算 (Butterfly Computation)
for (l = 1; l < n; l *= 2) {
ur = 1.0;
ui = 0.0;
@@ -110,9 +92,7 @@ int main(int argc, char** argv)
unsigned int tick_start, tick_end;
unsigned int hw_time, sw_time;
// ==========================================
// 1. 硬件加速 FFT 测试
// ==========================================
// 硬件加速 FFT 测试
printf("\n--- Starting Hardware FFT ---\n");
tick_start = get_ns();
@@ -122,10 +102,8 @@ int main(int argc, char** argv)
}
RegWrite(FFT_CSR_REG, FFT_CTRL_START);
while ((RegRead(FFT_CSR_REG) & FFT_STAT_DONE) == 0) {
// 等待硬件计算完成
}
fft_start();
fft_wait();
tick_end = get_ns();