forked from cinderblock/3-Phase-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerTimeout.cpp
More file actions
69 lines (56 loc) · 1.06 KB
/
TimerTimeout.cpp
File metadata and controls
69 lines (56 loc) · 1.06 KB
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
69
/*
* File: TimerTimeout.cpp
* Author: Cameron
*
* Created on April 1, 2016, 3:47 PM
*/
#include <avr/io.h>
#include <util/atomic.h>
#include "TimerTimeout.h"
void TimerTimeout::init() {
static bool initted = false;
if (initted) return;
initted = true;
TCCR0B = 0;
TIMSK0 = 0;
TIFR0 = 0xff;
// Setup TIMER0
TCCR0A = 0;
TCCR0B = timerClockSelect;
}
void TimerTimeout::startA(u1 period) {
ATOMIC_BLOCK(ATOMIC_FORCEON) {
startAISR(period);
}
}
void TimerTimeout::startB(u1 period) {
ATOMIC_BLOCK(ATOMIC_FORCEON) {
startBISR(period);
}
}
void TimerTimeout::startAISR(u1 period) {
OCR0A = TCNT0 + period;
TIFR0 = 1 << OCF0A;
TIMSK0 |= 1 << OCIE0A;
}
void TimerTimeout::startBISR(u1 period) {
OCR0B = TCNT0 + period;
TIFR0 = 1 << OCF0B;
TIMSK0 |= 1 << OCIE0B;
}
void TimerTimeout::stopA() {
ATOMIC_BLOCK(ATOMIC_FORCEON) {
stopBISR();
}
}
void TimerTimeout::stopB() {
ATOMIC_BLOCK(ATOMIC_FORCEON) {
stopBISR();
}
}
void TimerTimeout::stopAISR() {
TIMSK0 &= ~(1 << OCIE0A);
}
void TimerTimeout::stopBISR() {
TIMSK0 &= ~(1 << OCIE0A);
}