• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  ****************************************************************************************
3  *
4  * @file app_log.h
5  *
6  * @brief App Log API
7  *
8  ****************************************************************************************
9  * @attention
10   #####Copyright (c) 2019 GOODIX
11   All rights reserved.
12 
13     Redistribution and use in source and binary forms, with or without
14     modification, are permitted provided that the following conditions are met:
15   * Redistributions of source code must retain the above copyright
16     notice, this list of conditions and the following disclaimer.
17   * Redistributions in binary form must reproduce the above copyright
18     notice, this list of conditions and the following disclaimer in the
19     documentation and/or other materials provided with the distribution.
20   * Neither the name of GOODIX nor the names of its contributors may be used
21     to endorse or promote products derived from this software without
22     specific prior written permission.
23 
24   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27   ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34   POSSIBILITY OF SUCH DAMAGE.
35  *****************************************************************************************
36  */
37 
38 #ifndef __APP_LOG_H__
39 #define __APP_LOG_H__
40 
41 #include "custom_config.h"
42 #include "gr55xx_sys.h"
43 #include "gr55xx_hal.h"
44 #if APP_LOG_STORE_ENABLE
45 #include "app_log_store.h"
46 #endif
47 #include <stdint.h>
48 #include <stdbool.h>
49 
50 /**
51  * @defgroup APP_LOG_MAROC Defines
52  * @{
53  */
54 /**
55  * @defgroup APP_LOG_CFG_MAROC Defines
56  * @{
57  */
58 #ifndef APP_LOG_PRINTF_ENABLE
59 #define APP_LOG_PRINTF_ENABLE           APP_LOG_ENABLE             /**< Enable app log module.*/
60 #endif
61 
62 #ifndef APP_LOG_COLOR_ENABLE
63 #define APP_LOG_COLOR_ENABLE            0                          /**< Enable text color format. */
64 #endif
65 
66 #ifndef APP_LOG_TAG_ENABLE
67 #define APP_LOG_TAG_ENABLE              0                          /**< Enable app log tag. */
68 #endif
69 
70 #define APP_LOG_LOCK()                  LOCAL_INT_DISABLE(BLE_IRQn) /**< App log lock. */
71 #define APP_LOG_UNLOCK()                LOCAL_INT_RESTORE()         /**< APP log unlock. */
72 
73 #ifndef APP_LOG_TAG
74 #define APP_LOG_TAG                 "NO_TAG"                   /**< Default app log tag. */
75 #endif
76 
77 #define APP_LOG_LINE_BUF_SIZE           256                        /**< Buffer size for every line's log. */
78 #define APP_LOG_SEVERITY_LEVEL          APP_LOG_LVL_DEBUG           /**< Default log severity level. */
79 #define APP_LOG_TAG_LEN_MAX             20                         /**< Maximum length of output filter's tag. */
80 #define APP_LOG_LINE_NB_LEN_MAX         5                          /**< Maximum length of output line number. */
81 #define APP_LOG_NEWLINE_SIGN            "\r\n"                     /**< Newline sign output. */
82 /** @} */
83 
84 /**
85  * @defgroup APP_LOG_FMT APP Log Formats
86  * @{
87  */
88 #define APP_LOG_FMT_NULL        (0x00)          /**< No add any app log format. */
89 #define APP_LOG_FMT_LVL         (1 << 0)        /**< Add app log level format. */
90 #define APP_LOG_FMT_TAG         (1 << 1)        /**< Add app log tag format. */
91 #define APP_LOG_FMT_DIR         (1 << 2)        /**< Add app log file directory and name format. */
92 #define APP_LOG_FMT_FUNC        (1 << 3)        /**< Add app log function name format. */
93 #define APP_LOG_FMT_LINE        (1 << 4)        /**< Add app log number format. */
94 #define APP_LOG_FMT_ALL         (0x1f)          /**< Add all app log formats. */
95 /** @} */
96 
97 /**
98  * @defgroup APP_LOG_SVT_LVL APP Log Severity Levels
99  * @{
100  */
101 #define APP_LOG_LVL_ERROR       (0)             /**< Error severity level. */
102 #define APP_LOG_LVL_WARNING     (1)             /**< Warning severity level. */
103 #define APP_LOG_LVL_INFO        (2)             /**< Info severity level. */
104 #define APP_LOG_LVL_DEBUG       (3)             /**< Debug severity level. */
105 #define APP_LOG_LVL_NB          (4)             /**< Number of all severity level.  */
106 /** @} */
107 
108 #if APP_LOG_PRINTF_ENABLE
109 #if APP_LOG_SEVERITY_LEVEL >= APP_LOG_LVL_ERROR
110 #define APP_LOG_ERROR(...) app_log_output(APP_LOG_LVL_ERROR, APP_LOG_TAG, \
111                                           __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
112 #else
113 #define APP_LOG_ERROR(...)
114 #endif
115 
116 #if APP_LOG_SEVERITY_LEVEL >= APP_LOG_LVL_WARNING
117 #define APP_LOG_WARNING(...) app_log_output(APP_LOG_LVL_WARNING, APP_LOG_TAG, __FILE__, \
118                                             __FUNCTION__, __LINE__, __VA_ARGS__)
119 #else
120 #define APP_LOG_WARNING(...)
121 #endif
122 
123 #if APP_LOG_SEVERITY_LEVEL >= APP_LOG_LVL_INFO
124 #define APP_LOG_INFO(...) app_log_output(APP_LOG_LVL_INFO, APP_LOG_TAG, __FILE__, \
125                                          __FUNCTION__, __LINE__, __VA_ARGS__)
126 #else
127 #define APP_LOG_INFO(...)
128 #endif
129 
130 #if APP_LOG_SEVERITY_LEVEL >= APP_LOG_LVL_DEBUG
131 #define APP_LOG_DEBUG(...) app_log_output(APP_LOG_LVL_DEBUG, APP_LOG_TAG, __FILE__, \
132                                           __FUNCTION__, __LINE__, __VA_ARGS__)
133 #else
134 #define APP_LOG_DEBUG(...)
135 #endif
136 
137 #define APP_LOG_RAW_INFO(...)             app_log_raw_info(__VA_ARGS__)
138 #define APP_LOG_HEX_DUMP(p_data, length)  app_log_hex_dump(p_data, length)
139 #else
140 #define APP_LOG_ERROR(...)
141 #define APP_LOG_WARNING(...)
142 #define APP_LOG_INFO(...)
143 #define APP_LOG_DEBUG(...)
144 #define APP_LOG_RAW_INFO(...)
145 #define APP_LOG_HEX_DUMP(p_data, length)
146 #endif
147 /** @} */
148 
149 /**
150  * @defgroup APP_LOG_TYPEDEF Typedefs
151  * @{
152  */
153 /**@brief  APP LOG transmit function type. */
154 typedef void (*app_log_trans_func_t)(uint8_t *p_data, uint16_t length);
155 
156 /**@brief  APP LOG flush function type. */
157 typedef void (*app_log_flush_func_t)(void);
158 /** @} */
159 
160 /**
161  * @defgroup APP_LOG_STRUCT Structures
162  * @{
163  */
164 /**@brief App log filter. */
165 typedef struct {
166     uint8_t     level;                          /**< App log filter level. */
167     char        tag[APP_LOG_TAG_LEN_MAX + 1];   /**< App log filter tag. */
168 } app_log_filter_t;
169 
170 /**@brief App log init stucture. */
171 typedef struct {
172     app_log_filter_t      filter;                     /**< App log filter. */
173     uint8_t               fmt_set[APP_LOG_LVL_NB];    /**< Format of app log. See @ref APP_LOG_FMT.*/
174 } app_log_init_t;
175 /** @} */
176 
177 /**
178  * @defgroup APP_LOG_FUNCTION Functions
179  * @{
180  */
181 /**
182  *****************************************************************************************
183  * @brief Initialize app log module.
184  *
185  * @param[in] p_log_feat: Pointer to app log feature set.
186  * @param[in] trans_func: App log transmit function.
187  * @param[in] flush_func: App log flush function.
188 
189  *
190  * @return Result of initialization.
191  *****************************************************************************************
192  */
193 sdk_err_t app_log_init(app_log_init_t *p_log_init, app_log_trans_func_t trans_func, app_log_flush_func_t flush_func);
194 
195 /**
196  *****************************************************************************************
197  * @brief Output app log.
198  *
199  * @param[in] level: App log severity level.
200  * @param[in] tag:   App log tag.
201  * @param[in] file:  File name.
202  * @param[in] func:  Funciton name.
203  * @param[in] line: Line number.
204  * @param[in] fomat: Output format.
205  * @param[in] ...:   Arguments.
206  *****************************************************************************************
207  */
208 void app_log_output(uint8_t level, const char *tag, const char *file, const char *func, const long line,
209                     const char *format, ...);
210 
211 /**
212  *****************************************************************************************
213  * @brief Output RAW format log
214  *
215  * @param[in] fomat: Output format.
216  * @param[in] ...:   Arguments.
217  *****************************************************************************************
218  */
219 void app_log_raw_info(const char *format, ...);
220 
221 /**
222  *****************************************************************************************
223  * @brief Dump the hex format data to log.
224  *
225  * @param[in] p_data: Pointer to data.
226  * @param[in] length  Length of data.
227  *****************************************************************************************
228  */
229 void app_log_hex_dump(uint8_t *p_data, uint16_t length);
230 
231 /**
232  *****************************************************************************************
233  * @brief Flush app log.
234  *****************************************************************************************
235  */
236 void app_log_flush(void);
237 /** @} */
238 
239 #endif
240