forked from cinderblock/3-Phase-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebug.cpp
More file actions
71 lines (55 loc) · 965 Bytes
/
Debug.cpp
File metadata and controls
71 lines (55 loc) · 965 Bytes
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
70
71
/*
* File: Debug.cpp
* Author: Cameron
*
* Created on January 9, 2015, 4:09 PM
*/
#include "Debug.h"
#include "Clock.h"
#include <avr/io.h>
#include "CRC8.h"
IOpin& Debug::LED = Board::LED;
Debug::Printer Debug::SOUT;
static CRC8 CRC;
void Debug::init() {
UBRR1 = 0;
// Set default
UCSR1D = 0b00;
// Set default
UCSR1C = 0b00000110;
// Set default
UCSR1A = 0b00000000;
// Enable transmitter
UCSR1B = 0b00001000;
}
void Debug::sendByte(const u1 c) {
while (!(UCSR1A & (1 << UDRE1)));
UDR1 = c;
}
u1 nibToHex(u1 const nib) {
if (nib < 10)
return '0' + nib;
if (nib < 16)
return 'A' - 10 + nib;
return '*';
}
void Debug::reportU1(const u1 b) {
CRC << b;
sendByte(b);
}
void Debug::reportClock() {
u4 t;
Clock::readTime(t);
reportU2(t);
}
void Debug::sendHeader() {
sendByte(0xff);
sendByte(0xff);
sendByte(0xff);
sendByte(0xee);
sendByte(0xff);
CRC.reset();
}
void Debug::sendEnd() {
sendByte(CRC.getCRC());
}