-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebugPrint.c
60 lines (49 loc) · 1.51 KB
/
DebugPrint.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
#include "DebugPrint.h"
#include <stdio.h>
#include <stdbool.h>
unsigned int last_output = 0;
bool tx_overflowed = false;
void _debug_print_str(char* str) {
size_t len = strlen(str);
last_output = UART2_WriteBuffer((uint8_t*)str, len);
if (UART2_StatusGet() & UART2_TX_FULL) {
tx_overflowed = true;
}
// Might as well wait for write to complete
// UART2_Flush();
}
void _debug_println_str(char* str) {
_debug_print_str(str);
//UART2_Write('\r');
UART2_Write('\n');
// UART2_Flush();
}
// hex mode: one byte becomes 'xFF '
char formatted_str[DEBUG_PRINTHEX_MAX * 4];
void _debug_print_hex(byte* buf, size_t len) {
size_t i, real_len;
// Maximum length acceptable is DEBUG_PRINTHEX_MAX
real_len = (len > DEBUG_PRINTHEX_MAX) ? DEBUG_PRINTHEX_MAX : len;
// hex it
for (i=0; i<real_len; i++) {
sprintf(formatted_str + i*4, "x%02X ", buf[i]);
}
// only write as many bytes as we actually wrote
UART2_WriteBuffer((uint8_t*)formatted_str, (size_t)real_len*4);
// UART2_Flush();
}
void _debug_println_hex(byte* buf, size_t len) {
_debug_print_hex(buf, len);
UART2_Write('\n');
// UART2_Flush();
}
void _debug_print_int(int x) {
int str_len = sprintf(formatted_str, "%d", x);
UART2_WriteBuffer((uint8_t*)formatted_str, str_len);
// UART2_Flush();
}
void _debug_print_uint(unsigned int x) {
int str_len = sprintf(formatted_str, "%u", x);
UART2_WriteBuffer((uint8_t*)formatted_str, str_len);
// UART2_Flush();
}