-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.c
50 lines (39 loc) · 1.23 KB
/
error.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
#include "error.h"
#include "timer.h"
#include "uart.h"
#include <string.h>
const char *pmcu_errors_str[] = { PMCU_ALL_ERRORS(GENERATE_STRING) };
inline const char *PMCU_error_str(PMCU_Error error) {
return pmcu_errors_str[error];
}
void PMCU_log(const char *message) {
char tmp[8];
ltoa(timer_timestamp(), tmp);
uart_write_string(UART_A1, "[");
uart_write_string(UART_A1, tmp);
uart_write_string(UART_A1, "] ");
uart_write_string(UART_A1, message);
uart_write_string(UART_A1, "\r\n");
}
void PMCU_error_print(const char *source, PMCU_Error error, const char *message) {
timer_Task task;
do {
repeat:
uart_write_string(UART_A1, "\r\n");
uart_write_string(UART_A1, source);
uart_write_string(UART_A1, ": ");
uart_write_string(UART_A1, PMCU_error_str(error));
if (message) {
uart_write_string(UART_A1, " > ");
uart_write_string(UART_A1, message);
}
uart_write_string(UART_A1, "\r\n");
uart_write_string(UART_A1, "\r\n");
timer_task_start(&task, 3);
while (1) {
if (task.satisfied) {
goto repeat; // sorry mom
}
}
} while (1); // runs forever
}