36#define _UTIL_DELAY_H_ 1
39# ifndef __HAS_DELAY_CYCLES
40# define __HAS_DELAY_CYCLES 1
43# ifndef __ATTR_ALWAYS_INLINE__
44# define __ATTR_ALWAYS_INLINE__ __inline__ __attribute__((__always_inline__))
91# warning "F_CPU not defined for <util/delay.h>"
107# define F_CPU 1000000UL
111# warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
151static __ATTR_ALWAYS_INLINE__
void _delay_ms(
double __ms);
157#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) \
158 && !defined(__DELAY_BACKWARD_COMPATIBLE__)
160 extern void __builtin_avr_delay_cycles(
uint32_t);
161 __tmp = ((
F_CPU) / 1e3) * __ms;
163 #if defined(__DELAY_ROUND_DOWN__)
164 __ticks_dc = (
uint32_t)__builtin_fabs(__tmp);
166 #elif defined(__DELAY_ROUND_CLOSEST__)
167 __ticks_dc = (
uint32_t)(__builtin_fabs(__tmp)+0.5);
171 __ticks_dc = (
uint32_t)(__builtin_ceil(__builtin_fabs(__tmp)));
174 __builtin_avr_delay_cycles(__ticks_dc);
178 __tmp = ((
F_CPU) / 4e3) * __ms;
181 else if (__tmp > 65535)
234static __ATTR_ALWAYS_INLINE__
void _delay_us(
double __us);
240#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) \
241 && !defined(__DELAY_BACKWARD_COMPATIBLE__)
243 extern void __builtin_avr_delay_cycles(
uint32_t);
244 __tmp = ((
F_CPU) / 1e6) * __us;
246 #if defined(__DELAY_ROUND_DOWN__)
247 __ticks_dc = (
uint32_t)__builtin_fabs(__tmp);
249 #elif defined(__DELAY_ROUND_CLOSEST__)
250 __ticks_dc = (
uint32_t)(__builtin_fabs(__tmp)+0.5);
254 __ticks_dc = (
uint32_t)(__builtin_ceil(__builtin_fabs(__tmp)));
257 __builtin_avr_delay_cycles(__ticks_dc);
262 __tmp = ((
F_CPU) / 3e6) * __us;
263 __tmp2 = ((
F_CPU) / 4e6) * __us;
266 else if (__tmp2 > 65535)
271 else if (__tmp > 255)
unsigned int uint16_t
Definition: stdint.h:93
unsigned long int uint32_t
Definition: stdint.h:103
unsigned char uint8_t
Definition: stdint.h:83
void _delay_loop_1(uint8_t __count)
Definition: delay_basic.h:81
void _delay_loop_2(uint16_t __count)
Definition: delay_basic.h:103
#define F_CPU
CPU frequency in Hz.
Definition: delay.h:107
static void _delay_us(double __us)
Definition: delay.h:237
static void _delay_ms(double __ms)
Definition: delay.h:154