diff options
Diffstat (limited to 'libmaple/delay.h')
-rw-r--r-- | libmaple/delay.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libmaple/delay.h b/libmaple/delay.h new file mode 100644 index 0000000..5372ac1 --- /dev/null +++ b/libmaple/delay.h @@ -0,0 +1,24 @@ +/** + * @brief Delay implementation + */ + +#ifndef _DELAY_H_ +#define _DELAY_H_ + +static inline void delay_us(uint32 us) { + /* TODO this makes unwarranted assumptions about the RCC + * config; add a hook so users can make their own decisions. */ + /* So (2^32)/12 micros max, or less than 6 minutes */ + us *= 12; + + /* fudge for function call overhead */ + us--; + asm volatile(" mov r0, %[us] \n\t" + "1: subs r0, #1 \n\t" + " bhi 1b \n\t" + : + : [us] "r" (us) + : "r0"); +} +#endif + |