Wait function
Posted: Sat Apr 27, 2019 8:14 am
Hi, I would like to write a wait function for my OS.
Just a simple one that adds a delay with a loop. I tried like this :
but it does not work, it does not even enter the while loop (I tested with a printf). I think this might be related to GCC optimization (correct me if I am wrong).
How can I change to make this function work?
Regards
Just a simple one that adds a delay with a loop. I tried like this :
Code: Select all
// library.c
extern void wait_ms(uint32_t ms)
{
const uint32_t BEG = ms + timer_get_tick();
while (BEG < timer_get_tick());
}
// timer.c
static volatile uint32_t tick = 0;
extern volatile uint32_t timer_get_tick(void)
{
return tick;
}
How can I change to make this function work?
Regards