I’m working on firmware level code that is constantly checking for user input:
while (1) {
if (user_input()) {
Handle_user_input()
}
}
Currently this loop causes CPU usage to be 100%. What I am hoping for is a way to implement a sleep() function that will cause the CPU to sleep or go into some lower power mode for a specified amount of time to reduce CPU usage to something more pleasant (close to 0%).
while (1) {
if (user_input()) {
Handle_user_input()
}
sleep(ONE_MILLISECOND);
}
Please send me your implementation of the sleep() function that you think would work.
Thank you.
P.S. If you wish to use PowerPC assembly language, please use 'asm volatile("your code");'.