-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdebug.c
90 lines (82 loc) · 1.78 KB
/
debug.c
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Professional MultiSwimmers
* ECE 4440
*
* debug.c
*
* Author: Patrick Thomas
*/
#include "debug.h"
#include "msp.h"
void debug_uart_config()
{
#ifdef DEBUG
// Set UART into reset mode to edit settings.
UCA0CTLW0 = UCSWRST;
/*
Settings:
Parity disabled
Odd parity
LSB first
8-bit data
One stop bit
UART mode with automatic baud-rate detection
Async mode
Clock source: SMCLK
Erroneous characters rejected and UCRXIFG is not set
Received break characters do not set UCRXIFG
Not dormant
Next frame transmitted is data
Next frame transmitted is not a break
*/
UCA0CTLW0 |= UCMODE_3 | UCSSEL_2;
// Take UART out of reset mode.
UCA0CTLW0 &= ~UCSWRST;
#endif
}
void debug_print(char string[])
{
#ifdef DEBUG
int i;
for (i = 0; i < sizeof(string) - 1; i++)
{
// Wait for transmit buffer empty.
while (!(UCA0STATW & UCBUSY))
{
__no_operation();
}
// Send a single character.
UCA0TXBUF = string[i];
// Sleep between characters.
SLEEP(i, 1000);
}
#endif
}
void debug_println(char string[])
{
#ifdef DEBUG
int i;
for (i = 0; i < sizeof(string) - 1; i++)
{
// Wait for transmit buffer empty.
while (!(UCA0STATW & UCBUSY))
{
__no_operation();
}
// Send a single character.
UCA0TXBUF = string[i];
// Sleep between characters.
SLEEP(i, 1000);
}
// Send a newline.
// Wait for transmit buffer empty.
while (!(UCA0STATW & UCBUSY))
{
__no_operation();
}
// Send a single character.
UCA0TXBUF = '\n';
// Sleep between characters.
SLEEP(i, 1000);
#endif
}