How can my program tell if code is in a interrupt handler?(riscv32)

Is there an exact way to tell if code is running in a interrupt handler? Since I need to distinguish between interrupt context and thread context to use correct FreeRTOS API(eg:xSemaphoreGive/xSemaphoreGiveFromISR)

Referring to the arm platform, whether in interrupt handler can be obtained through IPSR or SCB->ICSR.Similarly, on riscv, I wonder if there is similar way to tell if code is in interrupt handler.

thanks~

If your core implements CLIC extension, you can probably use mintstatus CSR.

Can you not call the FromISR APIs from your ISR? Why do you need to determine the context?

If your core implements [CLIC extension ], you can probably use mintstatus CSR.

I have learned about this CSR, and feel it can satisfy my need. By the way, I wonder how or where you found this CSR can determine code is in isr.

Can you not call the FromISR APIs from your ISR? Why do you need to determine the context?

because we write an abstraction layer for wrapping freertos api. Take api OS_SemaphoreRelease for example, we determine which context to call xSemaphoreGive or xSemaphoreGiveFromISR.

Which means you are adding overhead to all your API calls. That is one problem with abstraction layers, they add overhead, and that can add up.

It also says that your abstraction layer may not be able to handle forcing a task switch when needed.

Some processor require that the yield from the ISR be at the VERY END of the ISR.

I googled and came across the doc I linked.

@richard-damon has already explained why you should re-think about having the overhead of abstraction layer.