/** * matmul_test - CIC-IEC 2026 Stage 3 Evaluation Program * * Uses the CDMA-to-matmul direct endpoint sequencer. The CDMA still owns the * external-memory traffic, while matmul A/B/C transfers use local wires instead * of the AXI crossbar. */ #include #include /* UART 16550 direct access avoids the printf/newlib overhead on the hot path. */ #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((unsigned char)*s++); } } static void uart_puthex(uint32_t val) { int i; for (i = 28; i >= 0; i -= 4) { unsigned char nibble = (unsigned char)((val >> i) & 0xF); uart_tx((unsigned char)(nibble < 10 ? ('0' + nibble) : ('a' + nibble - 10))); } } #ifndef MATMUL_GROUP_NUM #define MATMUL_GROUP_NUM 5000 #endif unsigned long UART_BASE = 0xbf000000; #define EXTRAM_BASE_PHYS 0x1c400000u #define SRC_BASE_WORDS 0u #define DST_BASE_WORDS (SRC_BASE_WORDS + MATMUL_GROUP_NUM * 32u) #define EXTRAM_PHYS_AB(g) (EXTRAM_BASE_PHYS + (SRC_BASE_WORDS * 4u) + (uint32_t)(g) * 128u) #define EXTRAM_PHYS_C(g) (EXTRAM_BASE_PHYS + (DST_BASE_WORDS * 4u) + (uint32_t)(g) * 192u) #define MATMUL_BASE_UNCACHED 0xbf500000u #define MATMUL_CRC (*(volatile uint32_t *)(MATMUL_BASE_UNCACHED + 0x010u)) int main(void) { uint32_t crc; if (MATMUL_GROUP_NUM <= 0) { return 0; } uart_puts("MATMUL_START\n"); DMA_SEQ->STATUS = SEQ_DONE_BIT; DMA_SEQ->SRC_BASE = EXTRAM_PHYS_AB(0); DMA_SEQ->DST_BASE = EXTRAM_PHYS_C(0); DMA_SEQ->GROUPS = MATMUL_GROUP_NUM; DMA_SEQ->MAT_BASE = 0x1f500000u; DMA_SEQ->SRC_STRIDE = 128u; DMA_SEQ->DST_STRIDE = 192u; DMA_SEQ->CTRL = SEQ_START_BIT; while ((DMA_SEQ->STATUS & SEQ_DONE_BIT) == 0u) { } DMA_SEQ->STATUS = SEQ_DONE_BIT; crc = MATMUL_CRC; uart_puts("MATMUL_CRC32="); uart_puthex(crc); uart_puts("\nMATMUL_DONE\n"); return 0; }