Skip to content

Commit

Permalink
libcpu: riscv: rv64: fixed warnings
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
unicornx committed Jan 27, 2025
1 parent 9899b0c commit 326507d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libcpu/risc-v/rv64/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 326507d

Please sign in to comment.