From 030715f7d9f8bd5528aca2921bc2be5d33b07ead Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Mon, 27 Jan 2025 10:43:59 +0800 Subject: [PATCH 1/3] bsp: cvitek: c906_littel: fixed build warnings for board.c When building bsp/cvitek/c906_little, compiler warns: ``` board/board.c: In function 'rt_hw_board_init': board/board.c:26:5: warning: implicit declaration of function 'rt_hw_tick_init'; did you mean 'rt_hw_stack_init'? [-Wimplicit-function-declaration] 26 | rt_hw_tick_init(); | ^~~~~~~~~~~~~~~ | rt_hw_stack_init board/board.c:29:5: warning: implicit declaration of function 'rt_hw_uart_init'; did you mean 'rt_hw_board_init'? [-Wimplicit-function-declaration] 29 | rt_hw_uart_init(); | ^~~~~~~~~~~~~~~ | rt_hw_board_init ``` To remove these build warnings, include header files which declare these functions. Plus, remove the decalartion of `tick_isr()`, this function does not exist. Signed-off-by: Chen Wang --- bsp/cvitek/c906_little/board/board.c | 2 ++ bsp/cvitek/c906_little/board/tick.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/cvitek/c906_little/board/board.c b/bsp/cvitek/c906_little/board/board.c index 8bcc0418022..414d2663ff4 100755 --- a/bsp/cvitek/c906_little/board/board.c +++ b/bsp/cvitek/c906_little/board/board.c @@ -11,6 +11,8 @@ #include #include "board.h" +#include "tick.h" +#include "drv_uart.h" void rt_hw_board_init(void) { diff --git a/bsp/cvitek/c906_little/board/tick.h b/bsp/cvitek/c906_little/board/tick.h index 7e0d0add4cb..7c5ca9dd1fb 100755 --- a/bsp/cvitek/c906_little/board/tick.h +++ b/bsp/cvitek/c906_little/board/tick.h @@ -11,8 +11,6 @@ #ifndef __TICK_H__ #define __TICK_H__ - -int tick_isr(void); int rt_hw_tick_init(void); #endif /* __TICK_H__ */ From 9899b0c0dbed7f09fb6fc9e4cff220474d40b23a Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Mon, 27 Jan 2025 10:58:05 +0800 Subject: [PATCH 2/3] libcpu: riscv: common: fixed build warnings When building bsp/cvitek/c906_little, compiler warns: ``` .../rt-thread/libcpu/risc-v/common/trap_common.c: In function 'rt_hw_interrupt_install': .../rt-thread/libcpu/risc-v/common/trap_common.c:50:11: warning: unused variable 'user_param' [-Wunused-variable] 50 | void *user_param = param; | ^~~~~~~~~~ .../rt-thread/libcpu/risc-v/common/trap_common.c: In function 'rt_rv32_system_irq_handler': .../rt-thread/libcpu/risc-v/common/trap_common.c:77:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 77 | s_stack_frame = (rt_hw_stack_frame_t *)mscratch; | ^ ``` Fixed these warnings as per indication from gcc. Signed-off-by: Chen Wang --- libcpu/risc-v/common/trap_common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libcpu/risc-v/common/trap_common.c b/libcpu/risc-v/common/trap_common.c index 6f7352cd569..0dbd7f2c75c 100644 --- a/libcpu/risc-v/common/trap_common.c +++ b/libcpu/risc-v/common/trap_common.c @@ -47,7 +47,6 @@ rt_weak rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t ha void *param, const char *name) { rt_isr_handler_t old_handler = RT_NULL; - void *user_param = param; if(vector < ISR_NUMBER) { @@ -74,7 +73,7 @@ rt_weak void rt_rv32_system_irq_handler(rt_uint32_t mcause) rt_uint32_t exception = !(mcause & 0x80000000); if(exception) { - s_stack_frame = (rt_hw_stack_frame_t *)mscratch; + s_stack_frame = (volatile rt_hw_stack_frame_t *)(uintptr_t)mscratch; rt_show_stack_frame(); } else From 326507d882df1ba3e80f31fc85778e1fb0cfb487 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Mon, 27 Jan 2025 14:18:08 +0800 Subject: [PATCH 3/3] libcpu: riscv: rv64: fixed warnings When building bsp/cvitek/c906_little, compiler reports: ``` .../rt-thread/libcpu/risc-v/rv64/trap.c: In function 'handle_trap': .../rt-thread/libcpu/risc-v/rv64/trap.c:106:13: warning: implicit declaration of function 'rt_hw_tick_isr'; did you mean 'rt_hw_stack_init'? [-Wimplicit-function-declaration] 106 | rt_hw_tick_isr(); | ^~~~~~~~~~~~~~ | rt_hw_stack_init .../rt-thread/libcpu/risc-v/rv64/trap.c:110:13: warning: implicit declaration of function 'rt_hw_irq_isr'; did you mean 'rt_hw_soft_irq_isr'? [-Wimplicit-function-declaration] 110 | rt_hw_irq_isr(); | ^~~~~~~~~~~~~ | rt_hw_soft_irq_isr ``` rt_hw_tick_isr()/rt_hw_irq_isr() are implemented by bsp, but libcpu/risc-v/rv64 doesn't declare them, so compiler warns. There are three BSPs using 'rv64' (libcpu/risc-v/rv64): - `bsp/cvitek/c906_little/rtconfig.py` - `bsp/juicevm/rtconfig.py` - `bsp/k210/rtconfig.py` `handle_trap` in `libcpu/risc-v/rv64` is defined as weak. BSP can use this function directly or define and overload it by itself. If bsp use this function directly, bsp need to pay attention to the fact that three functions will be called in this function: - `rt_hw_soft_irq_isr` - `rt_hw_tick_isr` - `rt_hw_irq_isr` In `libcpu/risc-v/rv64`, `rt_hw_soft_irq_isr` has a weak definition, while the other two do not. This means that if the bsp does not overload `handle_trap`, bsp must define `rt_hw_tick_isr` and `rt_hw_irq_isr` itself. This is also the practice of `bsp/cvitek/c906_little`. There is also a similar bsp `bsp/k210`, and the form of `bsp/juicevm` implements `handle_trap` by itself. It seems that `rt_hw_tick_isr` and `rt_hw_irq_isr` are not required to be implemented by all BSPs using `libcpu/risc-v/rv64`. The premise for BSP to implement them is that it does not overload `handle_trap`. So declaring `rt_hw_tick_isr` and `rt_hw_irq_isr` with extern in `libcpu/risc-v/rv64` is not proper. In addition, the `rt_hw_tick_isr/rt_hw_irq_isr` are only used by `libcpu/risc-v/rv64`, so it is not worth putting the declaration in `./include/rthw.h`. Sum up, the best solution is to add weak definition to `rt_hw_tick_isr/rt_hw_irq_isr` as existing `rt_hw_soft_irq_isr`. Signed-off-by: Chen Wang --- libcpu/risc-v/rv64/trap.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libcpu/risc-v/rv64/trap.c b/libcpu/risc-v/rv64/trap.c index 781fbed72aa..f0144157db3 100755 --- a/libcpu/risc-v/rv64/trap.c +++ b/libcpu/risc-v/rv64/trap.c @@ -92,6 +92,15 @@ rt_weak void rt_hw_soft_irq_isr(void) } +rt_weak int rt_hw_tick_isr(void) +{ + return 0; +} + +rt_weak void rt_hw_irq_isr(void) +{ + +} rt_weak rt_size_t handle_trap(rt_size_t cause, rt_size_t epc, rt_size_t *sp) {