changeset 19:8dc98a293e43

Scrap our handle rolled loops and use AVR libc's macros instead.
author darius
date Mon, 12 Dec 2005 15:42:03 +1030
parents 108a703c39e6
children 59c7fcf10ea0
files 1wire-delay.h
diffstat 1 files changed, 12 insertions(+), 112 deletions(-) [+]
line wrap: on
line diff
--- a/1wire-delay.h	Fri Nov 25 21:49:56 2005 +1030
+++ b/1wire-delay.h	Mon Dec 12 15:42:03 2005 +1030
@@ -29,115 +29,15 @@
  * SUCH DAMAGE.
  */
 
-/*
- * Note that all these routines are clock speed sensitive!
- * (4Mhz AT908515)
- */
-
-#if (XTAL_CPU == 4000000)
-/* 6 usec */
-#define DELAY_A	asm volatile(	\
-	"ldi r21, 6\n\t"	\
-	"L_%=: nop\n\t"		\
-	"dec r21\n\t"		\
-	"brne L_%=\n\t"		\
-	::: "r21")
-
-/* 64 usec */
-#define DELAY_B asm volatile(	\
-	"ldi r21, 32\n\t"	\
-	"L_%=: nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"dec r21\n\t"		\
-	"brne L_%=\n\t"		\
-	::: "r21")
-
-/* 60 usec */
-#define DELAY_C asm volatile(	\
-	"ldi r21, 30\n\t"	\
-	"L_%=: nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"dec r21\n\t"		\
-	"brne L_%=\n\t"		\
-	::: "r21")
-
-/* 10 usec */
-#define DELAY_D asm volatile(	\
-	"ldi r21, 9\n\t"	\
-	"L_%=: nop\n\t"		\
-	"dec r21\n\t"		\
-	"brne L_%=\n\t"		\
-	::: "r21")
-
-/* 9 usec */
-#define DELAY_E asm volatile(	\
-	"ldi r21, 8\n\t"	\
-	"L_%=: nop\n\t"		\
-	"dec r21\n\t"		\
-	"brne L_%=\n\t"		\
-	::: "r21")
-
-/* 55 usec */
-#define DELAY_F asm volatile(	\
-	"ldi r21, 27\n\t"	\
-	"L_%=: nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"dec r21\n\t"		\
-	"brne L_%=\n\t"		\
-	::: "r21")
-
-/* 0 usec */    
-#define DELAY_G
-
-/* 480 usec */
-#define DELAY_H asm volatile(	\
-	"ldi r21, 120\n\t"	\
-	"L_%=: nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"dec r21\n\t"		\
-	"brne L_%=\n\t"		\
-	::: "r21")
-
-/* 70 usec */    
-#define DELAY_I asm volatile(	\
-	"ldi r21, 35\n\t"	\
-	"L_%=: nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"nop\n\t"		\
-	"dec r21\n\t"		\
-	"brne L_%=\n\t"		\
-	::: "r21")
-#else
-#error No 1 wire delay routines for selected clock speed
-#endif
-
+#define DELAY_A _delay_us(6)						/* 6 usec */
+#define DELAY_B _delay_us(30); _delay_us(30); _delay_us(4)		/* 64 usec */
+#define DELAY_C _delay_us(30); _delay_us(30)				/* 60 usec */
+#define DELAY_D _delay_us(10)						/* 10 usec */
+#define DELAY_E _delay_us(9)						/* 9 usec */
+#define DELAY_F _delay_us(25); _delay_us(30);				/* 55 usec */
+#define DELAY_G								/* 0 usec */
+#define DELAY_H _delay_us(30); _delay_us(30);  _delay_us(30);  _delay_us(30); \
+     _delay_us(30);  _delay_us(30);  _delay_us(30);  _delay_us(30); \
+     _delay_us(30);  _delay_us(30);  _delay_us(30);  _delay_us(30); \
+    _delay_us(30);  _delay_us(30);  _delay_us(30);  _delay_us(30)	/* 480 usec */
+#define DELAY_I _delay_us(30); _delay_us(30);_delay_us(10)		/* 70 usec */