TTK4155 Lab Node 1
Term project in the NTNU course TTK4155 Embedded and Industrial Computer Systems Design
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
8
9#ifndef INCLUDE_INCLUDE_LOG_H_
10#define INCLUDE_INCLUDE_LOG_H_
11
12#include "uart.h"
13#include "utils.h"
14
15#define LOG_LEVEL_NONE 0
16#define LOG_LEVEL_CRITICAL 1
17#define LOG_LEVEL_ERROR 2
18#define LOG_LEVEL_INFO 3
19
20#ifndef LOG_LEVEL
21#define LOG_LEVEL LOG_LEVEL_INFO
22#endif
23
24static const char log_prefix_critical[] PROGMEM = "CRITICAL: ";
25static const char log_prefix_info[] PROGMEM = "INF: ";
26static const char log_prefix_error[] PROGMEM = "ERR: ";
27static const char log_colon_space[] PROGMEM = ": ";
28static const char log_newline[] PROGMEM = "\r\n";
29
30// UART transmit from progmem
31static inline void _log_print_P(PGM_P p) {
32 char c;
33 while ((c = pgm_read_byte(p++)) != 0) {
35 }
36}
37
38#if LOG_LEVEL > LOG_LEVEL_NONE
39#define LOG_MODULE_DEFINE(name) \
40 static const char _log_module_name[] PROGMEM = name
41#else
42#define LOG_MODULE_DEFINE(name)
43#endif
44
45#if LOG_LEVEL >= LOG_LEVEL_CRITICAL
46#define LOG_CRITICAL(msg) \
47 do { \
48 _log_print_P(log_prefix_critical); \
49 _log_print_P(_log_module_name); \
50 _log_print_P(log_colon_space); \
51 USART_SendString(msg); \
52 _log_print_P(log_newline); \
53 } while (0)
54#else
55#define LOG_CRITICAL(msg) ((void)0)
56#endif
57
58#if LOG_LEVEL >= LOG_LEVEL_INFO
59#define LOG_INF(msg) \
60 do { \
61 _log_print_P(log_prefix_info); \
62 _log_print_P(_log_module_name); \
63 _log_print_P(log_colon_space); \
64 USART_SendString(msg); \
65 _log_print_P(log_newline); \
66 } while (0)
67#else
68#define LOG_INF(msg) ((void)0)
69#endif
70
71#if LOG_LEVEL >= LOG_LEVEL_ERROR
72#define LOG_ERR(msg, status) \
73 do { \
74 _log_print_P(log_prefix_error); \
75 _log_print_P(_log_module_name); \
76 _log_print_P(log_colon_space); \
77 USART_SendString(msg); \
78 _log_print_P(log_newline); \
79 STATUS_ASSERT(status); \
80 } while (0)
81#else
82#define LOG_ERR(msg, status) ((void)0)
83#endif
84
85#endif // INCLUDE_LOG_H_
86
static const char log_prefix_critical[] PROGMEM
Definition log.h:24
static void _log_print_P(PGM_P p)
Definition log.h:31
int USART_Transmit(unsigned char data)
Transmit a single byte via USART0.
Definition uart.c:39
UART communication driver.
Utility and helper functions for joystick, LED debugging, and mapping.