You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
567 B
C++
51 lines
567 B
C++
#include "amsgenlib.hpp"
|
|
|
|
utimer::utimer()
|
|
{
|
|
t = micros();
|
|
}
|
|
|
|
utimer::~utimer()
|
|
{
|
|
t = 0;
|
|
}
|
|
|
|
void utimer::set()
|
|
{
|
|
t = micros();
|
|
}
|
|
|
|
bool utimer::isafter(unsigned long N)
|
|
{
|
|
bool ret = 0;
|
|
unsigned long t2,lmx;
|
|
if(t+N<t)
|
|
{
|
|
//wraparound
|
|
lmx = 0-1;
|
|
t2 = micros();
|
|
if(t2> ((t-lmx)+N))
|
|
{
|
|
ret = 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
t2 = micros();
|
|
if(t2>t+N)
|
|
{
|
|
ret = 1;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void utimer::delay(unsigned long N)
|
|
{
|
|
while(!this->isafter(N))
|
|
{
|
|
|
|
}
|
|
return;
|
|
}
|