How to implement sleep?

What is the best way to implement sleep in hifive1-rev B board?

While waiting for data to arrive at UART rx, how to put the processor to sleep and to be woken by UART1 rx interrupt only. Any help in this regard is appreciated.

1 Like

WFI (Wait For Interrupt) instruction maybe?
But it really depends on how a particular RISC-V implementation implements it.
And what the context is - e.g. bare metal, lightweight [RT]OS, more fully featured OS such as GNU/Linux etc.

@tgm Thanks, its ON bare metal.

When I read the manual I came across “Wfi” but don’t know how to use it. Is it an assembly instruction. Can you expand on how to use it?

I also read writing into pmusleep would initiate a sleep sequence from sleep program memory. I am not sure how can I program the sleep program memory.

When I

If you’re using GCC you can use inline assembly.
There’s an example of invoking WFI using it on this page:

Most or all other compiler toolchains will have a similar mechanism.

1 Like

Thanks