feat: optimize startup and linking

This commit is contained in:
2026-07-05 17:27:26 +08:00
parent 423ff32b49
commit 7281df356f
11 changed files with 292 additions and 97 deletions

View File

@@ -19,27 +19,34 @@ CFLAGS += -nostartfiles -nostdlib -nostdinc -static -fno-builtin
CFLAGS += -DCLOCKS_PER_SEC=CORE_CLOCKS_PER_SEC -D_CLOCKS_PER_SEC_=CORE_CLOCKS_PER_SEC
CFLAGS += -DUSE_CPU_CLOCK_COUNT
LINKER_SCRIPT ?= $(COMMON_DIR)/env/script.lds
BSP_STARTUP ?= $(COMMON_DIR)/env/start.S
BSP_USE_TRAP ?= 1
BSP_USE_DRIVERS ?= 1
#若使用 newlib , 将下面的 -lsemihost 替换为 -lgloss
LDFLAGS += -T $(LINKER_SCRIPT) \
-Wl,--gc-sections -Wl,--check-sections \
-lc -lm -lg -lsemihost -lgcc -L$(PICOLIBC_DIR)/lib
LINKER_SCRIPT := $(COMMON_DIR)/env/script.lds
ASM_SRCS += $(COMMON_DIR)/env/start.S
ASM_SRCS += $(BSP_STARTUP)
ifeq ($(BSP_USE_TRAP),1)
ifeq ($(TARGET), RTThread_Nano)
else
ASM_SRCS += $(COMMON_DIR)/env/trap_handler.S
endif
endif
ifeq ($(BSP_USE_DRIVERS),1)
C_SRCS += $(COMMON_DIR)/drivers/confreg_time.c
C_SRCS += $(COMMON_DIR)/drivers/core_time.c
C_SRCS += $(COMMON_DIR)/drivers/common_func.c
C_SRCS += $(COMMON_DIR)/drivers/dvi.c \
$(COMMON_DIR)/drivers/led.c \
$(COMMON_DIR)/drivers/seg7.c
endif
INCLUDES += -I./ \
-I$(COMMON_DIR)/include \

View File

@@ -1,37 +0,0 @@
#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;
}

View File

@@ -1,14 +0,0 @@
#include "fft.h"
#include "common_func.h"
void fft_start() {
RegWrite(FFT_CSR_REG, FFT_CTRL_START);
}
void fft_wait() {
while ((RegRead(FFT_CSR_REG) & FFT_STAT_DONE) == 0) {}
}
unsigned int fft_get_csr() {
return RegRead(FFT_CSR_REG);
}

View File

@@ -1,56 +0,0 @@
#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);

View File

@@ -1,16 +0,0 @@
#pragma once
#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
void fft_start();
void fft_wait();
unsigned int fft_get_csr();