I've searched for over an hour to try to introduce a delay of a few microseconds into my program flow.
There are of course other ways to achieve this. But starting timers, and things like that make my program more complex than it needs to be.
Now with a bit of luck your programming environment will provide you with a function that does this. For example, the avr-gcc compiler comes with a header "delay.h" that will define a _delay_us function that allows a constant argument and inlines into the proper delay with quite some accuracy.
With Chibios we however are not so lucky. Until today. I've written a first implementation for a delay_us function that "works for me".
(The "polled delay" function is not available on my STM32F0xx. It took me a while to figure out the new name of the function, all forum posts referred to the old name of that polledDelay function. Then it took me a while to figure out why it could not be found. I really didn't expect that one of the primary platforms (STM32Fxxx) would be "not RT capable".).
Code: Select all
void delay_us (int us)
{
#if 0
// it would be nice if chibios supported (busywaiting) delays
// with microsecond resolution.
//
osalSysPolledDelayX (US2RTT(us));
#else
for ( us *= 48/6;us>0;us--)
__asm__(" nop;");
#endif
}