mirror of
https://github.com/DanielBroad/AVCSniffer
synced 2025-06-07 07:56:29 +00:00
61 lines
1.8 KiB
C
Executable File
61 lines
1.8 KiB
C
Executable File
/*
|
|
Precise Delay Functions
|
|
V 0.5, Martin Thomas, 9/2004
|
|
|
|
In the original Code from Peter Dannegger a timer-interrupt
|
|
driven "timebase" has been used for precise One-Wire-Delays.
|
|
My loop-approach is less elegant but may be more usable
|
|
as library-function. Since it's not "timer-dependent"
|
|
See also delay.h.
|
|
|
|
Inspired by the avr-libc's loop-code
|
|
*/
|
|
|
|
#include <avr/io.h>
|
|
#include <avr/io.h>
|
|
//#include <avr/timer.h>
|
|
#include <inttypes.h>
|
|
|
|
#include "delay.h"
|
|
|
|
void delayloop32(uint32_t loops)
|
|
{
|
|
__asm__ volatile ( "cp %A0,__zero_reg__ \n\t" \
|
|
"cpc %B0,__zero_reg__ \n\t" \
|
|
"cpc %C0,__zero_reg__ \n\t" \
|
|
"cpc %D0,__zero_reg__ \n\t" \
|
|
"breq L_Exit_%= \n\t" \
|
|
"L_LOOP_%=: \n\t" \
|
|
"subi %A0,1 \n\t" \
|
|
"sbci %B0,0 \n\t" \
|
|
"sbci %C0,0 \n\t" \
|
|
"sbci %D0,0 \n\t" \
|
|
"brne L_LOOP_%= \n\t" \
|
|
"L_Exit_%=: \n\t" \
|
|
: "=w" (loops) \
|
|
: "0" (loops) \
|
|
); \
|
|
|
|
return;
|
|
}
|
|
//------------------------------------------------------------------------------
|
|
#define COUNT_FOR_1US 2
|
|
|
|
void delay1(u16 count)
|
|
{
|
|
count *= (COUNT_FOR_1US);
|
|
while (count-- != 0);
|
|
}
|
|
//------------------------------------------------------------------------------
|
|
//void delay1us(volatile u08 delay, u08 count)
|
|
//{
|
|
// timer0_source(CK);
|
|
//while (count-- !=0)
|
|
//{
|
|
//timer0_start();
|
|
//while (inb(TCNT0) < delay);
|
|
//
|
|
//}
|
|
//}
|
|
//------------------------------------------------------------------------------
|