112 lines
4.4 KiB
C
112 lines
4.4 KiB
C
/**
|
|
* user-sample - CIC-IEC 2026 Stage 3 Evaluation Program
|
|
*
|
|
* Matmul AXI-master path.
|
|
*/
|
|
|
|
#include <dma.h>
|
|
|
|
/* ─── UART 16550 direct access (bypasses slow printf/picolibc) ──────── */
|
|
#define UART_THR (*(volatile unsigned char *)0xbf000000)
|
|
#define UART_LSR (*(volatile unsigned char *)0xbf000005)
|
|
#define LSR_THRE 0x20
|
|
|
|
static inline void uart_tx(unsigned char c) {
|
|
while (!(UART_LSR & LSR_THRE)) {}
|
|
UART_THR = c;
|
|
}
|
|
|
|
static void uart_puts(const char *s) {
|
|
while (*s) uart_tx(*s++);
|
|
}
|
|
|
|
static void uart_puthex(unsigned int val) {
|
|
int i;
|
|
for (i = 28; i >= 0; i -= 4) {
|
|
unsigned char nibble = (val >> i) & 0xF;
|
|
uart_tx(nibble < 10 ? '0' + nibble : 'a' + nibble - 10);
|
|
}
|
|
}
|
|
|
|
/* ─── Configurable group count (default 5000) ──────────────────────── */
|
|
#ifndef MATMUL_GROUP_NUM
|
|
#define MATMUL_GROUP_NUM 5000
|
|
#endif
|
|
|
|
/* ─── BSP globals ─────────────────────────────────────────────────── */
|
|
unsigned long UART_BASE = 0xbf000000;
|
|
|
|
/* ─── Memory layout ────────────────────────────────────────────────── */
|
|
#define EXTRAM_BASE_PHYS 0x1c400000
|
|
#define EXTRAM_BASE_UNCACHED (0xA0000000 | (EXTRAM_BASE_PHYS & 0x1FFFFFFF))
|
|
|
|
#define SRC_BASE_WORDS 0
|
|
#define DST_BASE_WORDS (SRC_BASE_WORDS + MATMUL_GROUP_NUM * 32)
|
|
#define RESULT_WORDS (MATMUL_GROUP_NUM * 48)
|
|
|
|
/* ExtRAM Physical Addresses for DMA */
|
|
#define EXTRAM_PHYS_AB(g) (EXTRAM_BASE_PHYS + (SRC_BASE_WORDS * 4) + (g) * 128)
|
|
#define EXTRAM_PHYS_C(g) (EXTRAM_BASE_PHYS + (DST_BASE_WORDS * 4) + (g) * 192)
|
|
|
|
/* ─── MATMUL IP registers (Ping-Pong Memory Map) ──────────────────── */
|
|
#define MATMUL_BASE_PHYS 0x1f500000
|
|
#define MATMUL_BASE_UNCACHED 0xbf500000
|
|
|
|
#define MATMUL_CTRL (MATMUL_BASE_UNCACHED + 0x000)
|
|
#define MATMUL_STATUS (MATMUL_BASE_UNCACHED + 0x004)
|
|
#define MATMUL_DMA_SRC_BASE (MATMUL_BASE_UNCACHED + 0x020)
|
|
#define MATMUL_DMA_DST_BASE (MATMUL_BASE_UNCACHED + 0x024)
|
|
#define MATMUL_DMA_GROUPS (MATMUL_BASE_UNCACHED + 0x028)
|
|
#define MATMUL_DMA_SRC_STRIDE (MATMUL_BASE_UNCACHED + 0x02C)
|
|
#define MATMUL_DMA_DST_STRIDE (MATMUL_BASE_UNCACHED + 0x030)
|
|
|
|
#define CTRL_START_B0 0x1
|
|
#define CTRL_START_B1 0x2
|
|
#define CTRL_DMA_START (1 << 8)
|
|
#define STATUS_DONE 0x2
|
|
#define STATUS_ERROR 0x4
|
|
#define STATUS_DMA_BUSY (1 << 3)
|
|
#define STATUS_DMA_DONE (1 << 4)
|
|
|
|
#define MATMUL_CRC (MATMUL_BASE_UNCACHED + 0x010)
|
|
|
|
/* ─── Pre-computed DMA burst control word ──────────────────────────── */
|
|
#define DMA_CTRL_VAL (CTRL_BURST_SIZE(2) | CTRL_BURST_LEN(63) | CTRL_START_BIT)
|
|
#define MATMUL_EP_ID 0
|
|
|
|
/* ═══════════════════════════════════════════════════════════════════ */
|
|
int main(void)
|
|
{
|
|
if (MATMUL_GROUP_NUM <= 0) return 0;
|
|
|
|
/* ── Hot-path local volatile pointers (one-time addr calc) ──────── */
|
|
volatile unsigned int *mat_ctrl = (volatile unsigned int *)MATMUL_CTRL;
|
|
volatile unsigned int *mat_status = (volatile unsigned int *)MATMUL_STATUS;
|
|
volatile unsigned int *mat_crc = (volatile unsigned int *)MATMUL_CRC;
|
|
|
|
unsigned int crc;
|
|
|
|
/* ── Start marker (must be first output) ──────────────────── */
|
|
uart_puts("MATMUL_START\n");
|
|
|
|
*(volatile unsigned int *)MATMUL_CRC = 0;
|
|
*mat_status = STATUS_DMA_DONE | STATUS_DONE | STATUS_ERROR;
|
|
*(volatile unsigned int *)MATMUL_DMA_SRC_BASE = EXTRAM_PHYS_AB(0);
|
|
*(volatile unsigned int *)MATMUL_DMA_DST_BASE = EXTRAM_PHYS_C(0);
|
|
*(volatile unsigned int *)MATMUL_DMA_GROUPS = MATMUL_GROUP_NUM;
|
|
*(volatile unsigned int *)MATMUL_DMA_SRC_STRIDE = 128;
|
|
*(volatile unsigned int *)MATMUL_DMA_DST_STRIDE = 192;
|
|
*mat_ctrl = CTRL_DMA_START;
|
|
while (!(*mat_status & STATUS_DMA_DONE)) {}
|
|
*mat_status = STATUS_DMA_DONE;
|
|
|
|
/* ── Read hardware CRC32 ──────────────────────────────────── */
|
|
crc = *mat_crc;
|
|
|
|
uart_puts("MATMUL_CRC32=");
|
|
uart_puthex(crc);
|
|
uart_puts("\nMATMUL_DONE\n");
|
|
|
|
return 0;
|
|
}
|