/***********************************************
*
*	avr/delay.h - loops for small accurate delays
*
************************************************/

#ifndef _AVR_DELAY_H_
#define _AVR_DELAY_H_ 1

#include <inttypes.h>

/* 8-bit count, 3 cycles/loop */
static inline void
_delay_loop_1(uint8_t __count)
{
	asm volatile (
		"1: dec %0" "\n\t"
		"brne 1b"
		: "=r" (__count)
		: "0" (__count)
	);
}

/* 16-bit count, 4 cycles/loop */
static inline void
_delay_loop_2(uint16_t __count)
{
	asm volatile (
		"1: sbiw %0,1" "\n\t"
		"brne 1b"
		: "=w" (__count)
		: "0" (__count)
	);
}

/* TODO: macros to allow specifying delays directly in microseconds
   (with MCU clock frequency defined by the user).  With constant
   delays, all floating point math would be done at compile time.  */

#endif /* _AVR_DELAY_H_ */

