aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/delay.h
blob: dd68ec648e023c6a1e69bc560d9a614aa14d6d6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
 * @file delay.h
 * @brief Delay implementation
 */

#include "libmaple_types.h"
#include "stm32.h"

#ifndef _DELAY_H_
#define _DELAY_H_

/**
 * @brief Delay the given number of microseconds.
 *
 * @param us Number of microseconds to delay.
 */
static inline void delay_us(uint32 us) {
    us *= DELAY_US_MULT;

    /* 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