forked from Traumflug/Teacup_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delay.h
51 lines (42 loc) · 1.19 KB
/
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
50
51
#ifndef _DELAY_H
#define _DELAY_H
#include <stdint.h>
#include <util/delay_basic.h>
#include "watchdog.h"
#define WAITING_DELAY 100
#if F_CPU < 4000000UL
#error Delay functions only work with F_CPU >= 4000000UL
#endif
// microsecond delay, does NOT reset WDT if feature enabled
void delay_us(uint16_t delay);
// microsecond delay, does reset WDT if feature enabled
void _delay(uint32_t delay);
// millisecond delay, does reset WDT if feature enabled
void _delay_ms(uint32_t delay);
// microsecond timer, does reset WDT if feature enabled
// 0 results in no real delay, but the watchdog
// reset is called if the feature is enabled
static void delay(uint32_t) __attribute__ ((always_inline));
inline void delay(uint32_t d) {
if (d > (65536L / (F_CPU / 4000000L))) {
_delay(d);
}
else {
wd_reset();
if( d ) {
_delay_loop_2(d * (F_CPU / 4000000L));
wd_reset();
}
}
}
// millisecond timer, does reset WDT if feature enabled
// 0 results in no real delay, but the watchdog
// reset is called if the feature is enabled
static void delay_ms(uint32_t) __attribute__ ((always_inline));
inline void delay_ms(uint32_t d) {
if (d > 65)
_delay_ms(d);
else
delay(d * 1000);
}
#endif /* _DELAY_H */