c3dhall3  2.0.0.0
log.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
27 #ifndef _LOG_H_
28 #define _LOG_H_
29 #ifdef __cplusplus
30 extern "C"{
31 #endif
32 // #include "../../../generic.h"
33 #include "drv_uart.h"
34 #include <stdarg.h>
44 typedef enum
45 {
51 } log_level_t;
55 typedef struct
56 {
57  uart_t uart;
59 } log_t;
63 typedef struct
64 {
65  hal_pin_name_t rx_pin;
66  hal_pin_name_t tx_pin;
67  uint32_t baud;
69 
70 } log_cfg_t;
74 #define LOG_MAP_USB_UART(cfg) \
75  cfg.rx_pin = USB_UART_RX; \
76  cfg.tx_pin = USB_UART_TX; \
77  cfg.baud = 9600; \
78  cfg.level = LOG_LEVEL_DEBUG;
79 
82 #define LOG_MAP_MIKROBUS(cfg, mikrobus) \
83  cfg.rx_pin = MIKROBUS(mikrobus, MIKROBUS_RX); \
84  cfg.tx_pin = MIKROBUS(mikrobus, MIKROBUS_TX); \
85  cfg.baud = 9600; \
86  cfg.level = LOG_LEVEL_DEBUG;
87 
96 void log_init ( log_t *log, log_cfg_t *cfg );
106 void log_printf ( log_t *log, const code char * /*__generic*/ f,... );
112 void log_clear ( log_t *log );
123 int8_t log_read ( log_t *log, uint8_t *rx_data_buf, uint8_t max_len );
134 void log_info ( log_t *log, const code char * /*__generic*/ f,... );
145 void log_error ( log_t *log, const code char * /*__generic*/ f,... );
156 void log_fatal ( log_t *log, const code char * /*__generic*/ f,... );
167 void log_debug ( log_t *log, const code char * /*__generic*/ f,... );
178 void log_warning ( log_t *log, const code char * /*__generic*/ f,... );
190 void log_log ( log_t *log, char * prefix, const code char * /*__generic*/ f, ... ); // loggroup // apigroup
193 #ifdef __cplusplus
194 }
195 #endif
196 #endif // _LOG_H_
197 // ------------------------------------------------------------------------- END
log_t::uart
uart_t uart
Definition: log.h:57
log_init
void log_init(log_t *log, log_cfg_t *cfg)
Initializes LOG module.
log_info
void log_info(log_t *log, const code char *f,...)
INFO printf function.
log_cfg_t::rx_pin
hal_pin_name_t rx_pin
Definition: log.h:65
log_t::log_level
log_level_t log_level
Definition: log.h:58
log_warning
void log_warning(log_t *log, const code char *f,...)
WARNING printf function.
log_log
void log_log(log_t *log, char *prefix, const code char *f,...)
Printf function with a variable prefix.
LOG_LEVEL_DEBUG
Definition: log.h:46
LOG_LEVEL_WARNING
Definition: log.h:48
log_clear
void log_clear(log_t *log)
Discards all characters from the output and input buffer.
log_t
LOG context structure.
Definition: log.h:55
LOG_LEVEL_FATAL
Definition: log.h:50
log_printf
void log_printf(log_t *log, const code char *f,...)
Printf function.
log_read
int8_t log_read(log_t *log, uint8_t *rx_data_buf, uint8_t max_len)
Reads at most size bytes of data from the device into buffer.
log_cfg_t
LOG init configuration structure.
Definition: log.h:63
log_error
void log_error(log_t *log, const code char *f,...)
ERROR printf function.
log_cfg_t::level
log_level_t level
Definition: log.h:68
log_level_t
log_level_t
Log level values.
Definition: log.h:44
log_cfg_t::tx_pin
hal_pin_name_t tx_pin
Definition: log.h:66
LOG_LEVEL_INFO
Definition: log.h:47
log_debug
void log_debug(log_t *log, const code char *f,...)
DEBUG printf function.
log_fatal
void log_fatal(log_t *log, const code char *f,...)
FATAL printf function.
LOG_LEVEL_ERROR
Definition: log.h:49
log_cfg_t::baud
uint32_t baud
Definition: log.h:67