AVRly - AVR Development Resources
log_system.h
Go to the documentation of this file.
1/******************************************************************************
2 @copyright Copyright © 2022 by Jason Duffy.
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21******************************************************************************/
22
23/**
24 * @file log_system.h
25 * @ingroup bme280
26 * @author Jason Duffy
27 * @date 1st March 2022
28 * @brief Driver file providing logging functionality over USART, to print
29 * debug messages and values to a teminal program on your PC.
30 * @bug No known bugs.
31 */
32
33#ifndef LOG_SYSTEM_DOT_H
34#define LOG_SYSTEM_DOT_H
35
36/**
37 * Enumerated constants for the type of message to be logged.
38 */
39typedef enum
40{
41 NONE,
42 ERROR,
43 WARNING,
44 INFO,
45 DEBUG,
46 VERBOSE_DEBUG
48
49
50/**
51 * Enumerated constants to specify the output format of numerical values.
52 */
53typedef enum name
54{
55 DECIMAL,
56 HEXADECIMAL,
57 BINARY
59
60
61/**
62 * Config object, to be instantiated in each file the log system is to be used,
63 * then pass it's address into the functions with names beginning with "log".
64 * p_system_tag is a string, and is used for the logsystem to report which file
65 * or subsystem the message came from, e.g. "Main".
66 * file_log_level is the maximum level you'd like logging output for a
67 * particular file.
68 */
69typedef struct
70{
71 const char *p_system_tag;
72 log_type_t file_log_level;
74
75
76/**
77 * Initialisation routine - call this function once at startup before using
78 * other functions. Log system will then be turned on by default - call
79 * log_global_off() if you do not wish it to be.
80 */
81void init_log_system(void);
82
83
84/**
85 * Sends only the system tag, log level and message string.
86 * @param p_config is a pointer to the log_system config object. Instantiate
87 * the config object at the head of each file where logging is required and
88 * pass it's address into this function.
89 * @param level is the level status of the log message - see log_type_t for
90 * available options.
91 * @param msg is the message to be logged, enclose it in "" quotation marks.
92 */
93void log_message(log_system_config_t *p_config,
94 log_type_t level,
95 const char *msg);
96
97
98/**
99 * Sends a string, followed by an 8 bit unsigned value.
100 * @param p_config is a pointer to the log_system config object. Instantiate
101 * the config object at the head of each file where logging is required and
102 * pass it's address into this function.
103 * @param level is the level status of the log message - see log_type_t for
104 * available options.
105 * @param msg is the message to be logged, enclose it in "" quotation marks.
106 * @param val is the numerical value to be logged - Acceptable values 0 to 255.
107 * @param format is the desired output format of val - see format_type_t for
108 * avilable options.
109 */
111 log_type_t level,
112 const char *msg,
113 uint8_t val,
114 format_type_t format);
115
116
117/**
118 * Sends a string, followed by an 8 bit value.
119 * @param p_config is a pointer to the log_system config object. Instantiate
120 * the config object at the head of each file where logging is required and
121 * pass it's address into this function.
122 * @param level is the level status of the log message - see log_type_t for
123 * available options.
124 * @param msg is the message to be logged, enclose it in "" quotation marks.
125 * @param val is the numerical value to be logged - Acceptable values -128 to 127.
126 * @param format is the desired output format of val - see format_type_t for
127 * avilable options.
128 */
130 log_type_t level,
131 const char *msg,
132 int8_t val,
133 format_type_t format);
134
135
136/**
137 * Sends a string, followed by a 16 bit value.
138 * @param p_config is a pointer to the log_system config object. Instantiate
139 * the config object at the head of each file where logging is required and
140 * pass it's address into this function.
141 * @param level is the level status of the log message - see log_type_t for
142 * available options.
143 * @param msg is the message to be logged, enclose it in "" quotation marks.
144 * @param val is the numerical value to be logged - Acceptable values 0 -
145 * 65,535.
146 * @param format is the desired output format of val - see format_type_t for
147 * avilable options.
148 */
150 log_type_t level,
151 const char *msg,
152 uint16_t val,
153 format_type_t format);
154
155
156/**
157 * Sends a string, followed by a 16 bit value.
158 * @param p_config is a pointer to the log_system config object. Instantiate
159 * the config object at the head of each file where logging is required and
160 * pass it's address into this function.
161 * @param level is the level status of the log message - see log_type_t for
162 * available options.
163 * @param msg is the message to be logged, enclose it in "" quotation marks.
164 * @param val is the numerical value to be logged - Acceptable values -32,768
165 * to 32,767.
166 * @param format is the desired output format of val - see format_type_t for
167 * avilable options.
168 */
170 log_type_t level,
171 const char *msg,
172 int16_t val,
173 format_type_t format);
174
175
176// Temporary ptototype to make something work in the short term.
177void log_message_with_16bit_unsigned_dec_val(log_system_config_t *p_config,
178 log_type_t level,
179 const char *msg,
180 uint16_t val);
181
182
183/**
184 * Sends a string, followed by a 32 bit value.
185 * @param p_config is a pointer to the log_system config object. Instantiate
186 * the config object at the head of each file where logging is required and
187 * pass it's address into this function.
188 * @param level is the level status of the log message - see log_type_t for
189 * available options.
190 * @param msg is the message to be logged, enclose it in "" quotation marks.
191 * @param val is the numerical value to be logged - Acceptable values 0 -
192 * 4,294,967,295.
193 * @param format is the desired output format of val - see format_type_t for
194 * avilable options.
195 */
197 log_type_t level,
198 const char *msg,
199 uint32_t val,
200 format_type_t format);
201
202
203/**
204 * Sends a string, followed by a 32 bit value.
205 * @param p_config is a pointer to the log_system config object. Instantiate
206 * the config object at the head of each file where logging is required and
207 * pass it's address into this function.
208 * @param level is the level status of the log message - see log_type_t for
209 * available options.
210 * @param msg is the message to be logged, enclose it in "" quotation marks.
211 * @param val is the numerical value to be logged - Acceptable values 0 -
212 * 4,294,967,295.
213 * @param format is the desired output format of val - see format_type_t for
214 * avilable options.
215 */
217 log_type_t level,
218 const char *msg,
219 int32_t val,
220 format_type_t format);
221
222
223/**
224 * Sends a string, followed by a 64 bit value.
225 * @param p_config is a pointer to the log_system config object. Instantiate
226 * the config object at the head of each file where logging is required and
227 * pass it's address into this function.
228 * @param level is the level status of the log message - see log_type_t for
229 * available options.
230 * @param msg is the message to be logged, enclose it in "" quotation marks.
231 * @param val is the numerical value to be logged - Acceptable values 0 -
232 * (1.8446744e+19 - 1).
233 * @param format is the desired output format of val - see format_type_t for
234 * avilable options.
235 */
237 log_type_t level,
238 const char *msg,
239 uint64_t val,
240 format_type_t format);
241
242
243/**
244 * Sends a string, followed by a 64 bit value.
245 * @param p_config is a pointer to the log_system config object. Instantiate
246 * the config object at the head of each file where logging is required and
247 * pass it's address into this function.
248 * @param level is the level status of the log message - see log_type_t for
249 * available options.
250 * @param msg is the message to be logged, enclose it in "" quotation marks.
251 * @param val is the numerical value to be logged - Acceptable values 0 -
252 * (1.8446744e+19 - 1).
253 * @param format is the desired output format of val - see format_type_t for
254 * avilable options.
255 */
257 log_type_t level,
258 const char *msg,
259 uint64_t val,
260 format_type_t format);
261
262
263
264
265/**
266 * Sets maximum output level of logging required, to be used at file scope.
267 * @param p_config is a pointer to the log_system config object. Instantiate
268 * the config object at the head of each file where logging is required and
269 * pass it's address into this function.
270 * @param level is the maximum level required - see log_type_t for available
271 * options.
272 */
274 log_type_t level);
275
276
277/**
278 * Sets maximum output level of logging required, has global effect.
279 * @param level is the maximum level required - see log_type_t for available
280 * options.
281 */
283
284
285/**
286 * Turns logging system on globally.
287 */
288void log_global_on(void);
289
290
291/**
292 * Turns logging system off globally.
293 */
294void log_global_off(void);
295
296
297#endif // LOG_SYSTEM_DOT_H
298
299
300/*** end of file ***/
void log_set_file_max_output_level(log_system_config_t *p_config, log_type_t level)
Sets maximum output level of logging required, to be used at file scope.
Definition: log_system.c:217
void log_set_global_max_output_level(log_type_t level)
Sets maximum output level of logging required, has global effect.
Definition: log_system.c:229
void log_global_on(void)
Turns logging system on globally.
Definition: log_system.c:133
void init_log_system(void)
Initialisation routine - call this function once at startup before using other functions.
Definition: log_system.c:46
void log_global_off(void)
Turns logging system off globally.
Definition: log_system.c:139
void log_message(log_system_config_t *p_config, log_type_t level, const char *msg)
Sends only the system tag, log level and message string.
Definition: log_system.c:93
log_type_t
Enumerated constants for the type of message to be logged.
Definition: log_system.h:40
void log_message_with_32bit_unsigned_val(log_system_config_t *p_config, log_type_t level, const char *msg, uint32_t val, format_type_t format)
Sends a string, followed by a 32 bit value.
void log_message_with_8bit_unsigned_val(log_system_config_t *p_config, log_type_t level, const char *msg, uint8_t val, format_type_t format)
Sends a string, followed by an 8 bit unsigned value.
void log_message_with_16bit_unsigned_val(log_system_config_t *p_config, log_type_t level, const char *msg, uint16_t val, format_type_t format)
Sends a string, followed by a 16 bit value.
name
Enumerated constants to specify the output format of numerical values.
Definition: log_system.h:54
void log_message_with_32bit_signed_val(log_system_config_t *p_config, log_type_t level, const char *msg, int32_t val, format_type_t format)
Sends a string, followed by a 32 bit value.
void log_message_with_16bit_signed_val(log_system_config_t *p_config, log_type_t level, const char *msg, int16_t val, format_type_t format)
Sends a string, followed by a 16 bit value.
enum name format_type_t
Enumerated constants to specify the output format of numerical values.
void log_message_with_8bit_signed_val(log_system_config_t *p_config, log_type_t level, const char *msg, int8_t val, format_type_t format)
Sends a string, followed by an 8 bit value.
Definition: log_system.c:118
void log_message_with_64bit_unsigned_dec_val(log_system_config_t *p_config, log_type_t level, const char *msg, uint64_t val, format_type_t format)
Sends a string, followed by a 64 bit value.
Config object, to be instantiated in each file the log system is to be used, then pass it's address i...
Definition: log_system.h:59