From 4b9eb0e3fb7893f22dfc99da2cb2fa3ba566ba8b Mon Sep 17 00:00:00 2001 From: imcu Date: Mon, 2 Dec 2024 17:28:50 +0800 Subject: [PATCH] [bsp][cvitek] add icache opration --- bsp/cvitek/c906_little/Kconfig | 1 + bsp/cvitek/c906_little/board/cache.c | 23 +++++++++++++++++++++++ bsp/cvitek/c906_little/board/cache.h | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/bsp/cvitek/c906_little/Kconfig b/bsp/cvitek/c906_little/Kconfig index 6e007eb2b88d..62acab276361 100755 --- a/bsp/cvitek/c906_little/Kconfig +++ b/bsp/cvitek/c906_little/Kconfig @@ -14,6 +14,7 @@ config BSP_USING_C906_LITTLE bool select ARCH_RISCV64 select ARCH_RISCV_FPU_D + select RT_USING_CACHE select RT_USING_COMPONENTS_INIT select RT_USING_USER_MAIN default y diff --git a/bsp/cvitek/c906_little/board/cache.c b/bsp/cvitek/c906_little/board/cache.c index f35dd83fe686..e0b9bdf6122b 100644 --- a/bsp/cvitek/c906_little/board/cache.c +++ b/bsp/cvitek/c906_little/board/cache.c @@ -5,6 +5,7 @@ * * Change Logs: * Date Author Notes + * 2024/11/27 zdtyuiop4444 Add Icache operation * 2024/11/26 zdtyuiop4444 The first version */ @@ -34,3 +35,25 @@ inline void rt_hw_cpu_dcache_ops(int ops, void* addr, int size) break; } } + +inline void rt_hw_cpu_icache_enable(void) +{ + asm volatile("csrs mhcr, %0;" ::"rI"(0x1)); +} + +inline void rt_hw_cpu_icache_disable(void) +{ + asm volatile("csrc mhcr, %0;" ::"rI"(0x1)); +} + +inline void rt_hw_cpu_icache_ops(int ops, void* addr, int size) +{ + switch (ops) + { + case RT_HW_CACHE_INVALIDATE: + CACHE_OP_RANGE(ICACHE_IPA_A0, start, size); + break; + default: + break; + } +} diff --git a/bsp/cvitek/c906_little/board/cache.h b/bsp/cvitek/c906_little/board/cache.h index b8ace5eb3d69..21c752acbc7f 100644 --- a/bsp/cvitek/c906_little/board/cache.h +++ b/bsp/cvitek/c906_little/board/cache.h @@ -5,6 +5,7 @@ * * Change Logs: * Date Author Notes + * 2024/11/27 zdtyuiop4444 Add Icache operation * 2024/11/26 zdtyuiop4444 The first version */ @@ -29,6 +30,10 @@ * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | * 0000001 01011 rs1 000 00000 0001011 * + * icache.ipa rs1 (invalidate) + * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | + * 0000001 11000 rs1 000 00000 0001011 + * * sync.s * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | * 0000000 11001 00000 000 00000 0001011 @@ -36,6 +41,7 @@ #define DCACHE_IPA_A0 ".long 0x02a5000b" #define DCACHE_CPA_A0 ".long 0x0295000b" #define DCACHE_CIPA_A0 ".long 0x02b5000b" +#define ICACHE_IPA_A0 ".long 0x0385000b" #define SYNC_S ".long 0x0190000b"