-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelay.h
49 lines (32 loc) · 737 Bytes
/
delay.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef _UTIL_DELAY_H_
#define _UTIL_DELAY_H_
#include <limits.h>
#include "main.h"
#ifdef INTERNALTIMER
#define F_CPU 16000000
#endif
#ifdef CRYSTALTIMER
#define F_CPU 12000000
#endif
#define delay_us(us) __delay_cycles((F_CPU *(us)/10000000uL))
extern long volatile tickMs;
static inline void __delay_cycles(unsigned long us){
while(us--){};
}
static inline void delay_ms( unsigned short __ms )
{
long now = tickMs;
long ends = tickMs + __ms;
if( ends < now){
//compensate for long overflow!
while(tickMs <LONG_MAX) {
//wait while timer has not overflowed
asm("nop");
}
}
//now just wait while tick < end period
while(tickMs < ends){
asm("nop");
}
}
#endif