mikroSDK Reference Manual
log.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 MikroElektronika d.o.o.
4 ** Contact: https://www.mikroe.com/contact
5 **
6 ** This file is part of the mikroSDK package
7 **
8 ** Commercial License Usage
9 **
10 ** Licensees holding valid commercial NECTO compilers AI licenses may use this
11 ** file in accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The mikroElektronika Company.
14 ** For licensing terms and conditions see
15 ** https://www.mikroe.com/legal/software-license-agreement.
16 ** For further information use the contact form at
17 ** https://www.mikroe.com/contact.
18 **
19 **
20 ** GNU Lesser General Public License Usage
21 **
22 ** Alternatively, this file may be used for
23 ** non-commercial projects under the terms of the GNU Lesser
24 ** General Public License version 3 as published by the Free Software
25 ** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26 **
27 ** The above copyright notice and this permission notice shall be
28 ** included in all copies or substantial portions of the Software.
29 **
30 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 ** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32 ** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 **
38 ****************************************************************************/
39 
43 #ifndef _LOG_H_
44 #define _LOG_H_
45 
46 #ifdef __cplusplus
47 extern "C"{
48 #endif
49 
50 #include "../../../generic.h"
51 #include "drv_uart.h"
52 #include <stdarg.h>
53 
57 typedef enum
58 {
59  LOG_LEVEL_DEBUG = 0x00,
60  LOG_LEVEL_INFO = 0x01,
62  LOG_LEVEL_ERROR = 0x03,
63  LOG_LEVEL_FATAL = 0x04,
64 } log_level_t;
65 
69 typedef struct
70 {
71  uart_t uart;
72  log_level_t log_level;
73 } log_t;
74 
78 typedef struct
79 {
80  hal_pin_name_t rx_pin;
81  hal_pin_name_t tx_pin;
82  uint32_t baud;
83  log_level_t level;
85 } log_cfg_t;
86 
102 #define ABS(x) (((x)>0)?(x):-(x))
103 
112 #define LOG_MAP_USB_UART(cfg) \
113  cfg.rx_pin = USB_UART_RX; \
114  cfg.tx_pin = USB_UART_TX; \
115  cfg.baud = 9600; \
116  cfg.level = LOG_LEVEL_DEBUG;
117 
121 #define LOG_MAP_MIKROBUS(cfg, mikrobus) \
122  cfg.rx_pin = MIKROBUS(mikrobus, MIKROBUS_RX); \
123  cfg.tx_pin = MIKROBUS(mikrobus, MIKROBUS_TX); \
124  cfg.baud = 9600; \
125  cfg.level = LOG_LEVEL_DEBUG;
126 
134 void log_init ( log_t *log, log_cfg_t *cfg );
135 
144 void log_printf ( log_t *log, const code char * __generic f,... );
145 
152 void log_clear ( log_t *log );
153 
163 int8_t log_read ( log_t *log, uint8_t *rx_data_buf, uint8_t max_len );
164 
173 void log_info ( log_t *log, const code char * __generic f,... );
174 
183 void log_error ( log_t *log, const code char * __generic f,... );
184 
194 void log_fatal ( log_t *log, const code char * __generic f,... );
195 
204 void log_debug ( log_t *log, const code char * __generic f,... );
205 
214 void log_warning ( log_t *log, const code char * __generic f,... );
215 
225 void log_log ( log_t *log, char * prefix, const code char * __generic f, ... );
226  // loggroup // apigroup
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 #endif // _LOG_H_
234 // ------------------------------------------------------------------------- END
drv_uart.h
API for UART driver.
LOG_LEVEL_DEBUG
Definition: log.h:58
LOG_LEVEL_ERROR
Definition: log.h:61
log_init
void log_init(log_t *log, log_cfg_t *cfg)
Initializes LOG module.
log_fatal
void log_fatal(log_t *log, const code char *__generic f,...)
FATAL printf function.
log_debug
void log_debug(log_t *log, const code char *__generic f,...)
DEBUG printf function.
log_log
void log_log(log_t *log, char *prefix, const code char *__generic f,...)
Printf function with a variable prefix.
hal_pin_name_t
hal_ll_pin_name_t hal_pin_name_t
Definition: hal_target.h:59
log_clear
void log_clear(log_t *log)
Discards all characters from the output and input buffer.
log_error
void log_error(log_t *log, const code char *__generic f,...)
ERROR printf function.
log_warning
void log_warning(log_t *log, const code char *__generic f,...)
WARNING printf function.
log_t
LOG context structure.
Definition: log.h:68
uart_t
UART driver context structure, consisted of the following fields :
Definition: drv_uart.h:163
log
double log(double num)
Calculates the natural logarithm - ln( num ).
LOG_LEVEL_FATAL
Definition: log.h:62
log_level_t
log_level_t
Log level values.
Definition: log.h:56
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:77
LOG_LEVEL_INFO
Definition: log.h:59
log_printf
void log_printf(log_t *log, const code char *__generic f,...)
Printf function.
log_info
void log_info(log_t *log, const code char *__generic f,...)
INFO printf function.
LOG_LEVEL_WARNING
Definition: log.h:60