-
Notifications
You must be signed in to change notification settings - Fork 1
/
Delay.cpp
68 lines (60 loc) · 1.86 KB
/
Delay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "Delay.hpp"
#include "Cp0.hpp"
#include "Osc.hpp"
//Delay functions
// set us
//=============================================================================
Delay::
Delay (uint32_t us)
{
set(us);
}
//=============================================================================
auto Delay::
expired () -> bool
{
if( m_expired ) return true; //do not calc, already know
if((Cp0::count() - m_start) >= m_countn) expire();
return m_expired;
}
//force time expired
//=============================================================================
auto Delay::
expire () -> void
{
m_expired = true;
}
//=============================================================================
auto Delay::
restart () -> void
{
m_start = Cp0::count();
m_expired = false;
}
// in micrososends
//=============================================================================
auto Delay::
set (uint32_t n) -> void
{
if(n > m_max_us) n = m_max_us;
set_count(n);
}
// private
//=============================================================================
auto Delay::
set_count (uint32_t n) -> void
{
restart();
m_countn = Osc::sysclk() / 2000000UL * n;
}
// static
// in micrososends
//=============================================================================
auto Delay::
wait (uint32_t n) -> void
{
if(n > m_max_us) n = m_max_us;
n = Osc::sysclk() / 2000000UL * n;
uint32_t start = Cp0::count();
while((Cp0::count() - start) < n);
}