Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
74 arune 1
/*
2
   Precise Delay Functions
3
   V 0.5, Martin Thomas, 9/2004
4
 
5
   In the original Code from Peter Dannegger a timer-interrupt
6
   driven "timebase" has been used for precise One-Wire-Delays.
7
   My loop-approach is less elegant but may be more usable
8
   as library-function. Since it's not "timer-dependent"
9
   See also delay.h.
10
 
11
   Inspired by the avr-libc's loop-code
12
*/
13
 
14
#include <avr/io.h>
15
#include <avr/io.h>
16
#include <inttypes.h>
17
 
18
#include "delay.h"
19
 
20
void delayloop32(uint32_t loops)
21
{
22
  __asm__ volatile ( "cp  %A0,__zero_reg__ \n\t"  \
23
                     "cpc %B0,__zero_reg__ \n\t"  \
24
                     "cpc %C0,__zero_reg__ \n\t"  \
25
                     "cpc %D0,__zero_reg__ \n\t"  \
26
                     "breq L_Exit_%=       \n\t"  \
27
                     "L_LOOP_%=:           \n\t"  \
28
                     "subi %A0,1           \n\t"  \
29
                     "sbci %B0,0           \n\t"  \
30
                     "sbci %C0,0           \n\t"  \
31
                     "sbci %D0,0           \n\t"  \
32
                     "brne L_LOOP_%=            \n\t"  \
33
                     "L_Exit_%=:           \n\t"  \
34
                     : "=w" (loops)              \
35
                     : "0"  (loops)              \
36
                   );                             \
37
 
38
    return;
39
}