Port FreeRTOS on RISCV-CPU without mtime and mtime_cmp registers

My target CPU does not implement the CLINT (mtime & mtime_cmp) registers. As a result, vTaskStartScheduler() does not work as expected. Because the timer interrupt is not functioning as intended.
Is there any method to implement vPortSetupTimerInterrupt() without relying on the mtime and mtime_cmp registers?

Yes there is. You can provide your own implementation of vPortSetupTimerInterrupt() using any timer that can generate the tick interrupt on your target CPU. At build time, the linker will use your implementation of vPortSetupTimerInterrupt() and not the one in port.c, which is marked as “weak”. FreeRTOS-Kernel/portable/GCC/RISC-V/port.c at 1947dd2f94419d368316052e92f4bd396bce5f55 · FreeRTOS/FreeRTOS-Kernel · GitHub

Then you’ll also need to provide an interrupt handler for the timer you selected that calls xTaskIncrementTick() and calls portYIELD_FROM_ISR() with the return value from xTaskIncrementTick().

Can I implement vPortSetupTimerInterrupt() using a software method without interacting with hardware? By the way, is there an example code for the implementation of vPortSetupTimerInterrupt()? Thanks.

I do not think so, you need a hardware timer for driving the FreeRTOS tick.

The weak implementation shared above is an example, right?

Thanks for the reply. At this point, I believe I should proceed with implementing mtime and mtime_cmp on my target CPU to facilitate the porting of FreeRTOS onto it.

1 Like

Ok. Adopting the CPU this way is a pretty cool approach :+1: