m2mb API docs  25.30.008.0
m2mb API sets documentation
m2mb_trace.h
Go to the documentation of this file.
1 /* $version: 252422_R1 */
2 /*===============================================================================================*/
3 /* >>> Copyright (C) Telit Communications S.p.A. Italy All Rights Reserved. <<< */
23 #ifndef M2M_M2MB_TRACE_H
24 #define M2M_M2MB_TRACE_H
25 
26 #include <string.h>
27 
28 /* Files to provide platform dependent optimizations for trace */
29 #include "m2mb_platform_defines.h"
30 #ifdef M2M_OPTIMIZE_TRACE
31 #include "m2mb_trace_opt.h"
32 #endif
33 
34 
35 /* GCC has only the standard predefined MACRO __FILE__ and there is no __MODULE__ like in RVCT dinoa*/
36 
37 
38 #if defined(unix) || defined(__unix__) || defined(__unix)
39 #define __FILENAMEI__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
40 #define __FILENAMER__ __FILENAMEI__
41 #else
42 #define __FILENAMEI__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
43 #define __FILENAMER__ (strrchr(__FILENAMEI__, '/') ? strrchr(__FILENAMEI__, '/') + 1 : __FILENAMEI__)
44 
45 #endif
46 
47 
48 #if !defined(__MODULE__)
49 #define __MODULE__ __FILENAMER__
50 #endif
51 
52 
53 
54 /* @FHB -------------------------------------------------------------------------------
55 
56  Info: Available ONLY for AZ user applications:
57  PROTOTIPE OF THE log_az.ini FILE, to be inserted in the filesystem of the module
58  in <mod> directory with AT#M2MWRITE="/mod/log_az.ini", or with QPST configurator
59  The log_az.ini will be read with m2mb_trace_init
60  if there is no log_az.ini, then the function m2mb_trace_init will set all the classes
61  to a value of M2MB_TL_DEBUG (5) and there will be no filter for the print
62  Here a copy of the file log_az.ini :
63 ***********************************************************************<<<start here>>>
64  ; conf file for appzone2 trace:
65 
66  [logport] ; if PORT= (empty) TRACE is the default value
67  PORT=TRACE ; TRACE, USB0, USB1, UART
68 
69  [class] ; LOG SEVERITY for each class. Setting class M2MB_TL_DEBUG (5) will show
70  ; also LOG, WARNING... Setting M2MB_TL_LOG will show WARNING, ERROR... and so on
71  ; setting to 0 will not show any trace
72  TC_GENERIC = 3
73  TC_SOCKET = 0 ; 0=OFF 1=M2MB_TL_FATAL 2=M2MB_TL_ERROR 3=M2MB_TL_WARNING 4=M2MB_TL_LOG 5=M2MB_TL_DEBUG
74  TC_CLOCK = 0
75  TC_PDP = 0
76  TC_GNSS = 0
77  TC_M2M_USER = 4
78  TC_FOTA = 0
79  TC_FS = 0
80  TC_QMI = 0
81  TC_SMS = 0
82  TC_INFO = 4
83  TC_LWM2M = 0
84  TC_NET = 0
85  TC_SIM = 0
86  TC_SPI = 0
87  TC_USB = 0
88  TC_NV = 1
89  TC_RTC = 0
90  TC_UART = 0
91  TC_POWER = 0
92 
93 *****************************************************************<<<end here>>>
94 
95  @FHE --------------------------------------------------------------------------------- */
96 
97 
98 /* Global declarations ==========================================================================*/
99 #ifndef m2mb_trace_printf
100 #define m2mb_trace_printf( _class, level, format, ... ) \
101  m2mb_trace_print_##level( _class, level, format, ##__VA_ARGS__ )
102 #endif
103 
104 #if !defined(M2MB_TRACE_LEVEL_FATAL_DISABLED)
105  #ifdef M2M_OPTIMIZE_TRACE
106  #define m2mb_trace_print_M2MB_TL_FATAL( _class, level, format, ... ) \
107  OPTIMIZED_PRINT( _class, level, format, ##__VA_ARGS__ )
108  #else
109  #define m2mb_trace_print_M2MB_TL_FATAL( _class, level, format, ... ) \
110  m2mb_trace_file_line_printf(__MODULE__, __LINE__, _class, level, format, ##__VA_ARGS__)
111  #endif
112 #else
113  #define m2mb_trace_print_M2MB_TL_FATAL( _class, level, format, ... )
114 #endif
115 
116 #if !defined(M2MB_TRACE_LEVEL_ERROR_DISABLED)
117  #ifdef M2M_OPTIMIZE_TRACE
118  #define m2mb_trace_print_M2MB_TL_ERROR( _class, level, format, ... ) \
119  OPTIMIZED_PRINT( _class, level, format, ##__VA_ARGS__ )
120  #else
121  #define m2mb_trace_print_M2MB_TL_ERROR( _class, level, format, ... ) \
122  m2mb_trace_file_line_printf(__MODULE__, __LINE__, _class, level, format, ##__VA_ARGS__)
123  #endif
124 #else
125  #define m2mb_trace_print_M2MB_TL_ERROR( _class, level, format, ... )
126 #endif
127 
128 #if !defined(M2MB_TRACE_LEVEL_WARNING_DISABLED)
129  #ifdef M2M_OPTIMIZE_TRACE
130  #define m2mb_trace_print_M2MB_TL_WARNING( _class, level, format, ... ) \
131  OPTIMIZED_PRINT( _class, level, format, ##__VA_ARGS__ )
132  #else
133  #define m2mb_trace_print_M2MB_TL_WARNING( _class, level, format, ... ) \
134  m2mb_trace_file_line_printf(__MODULE__, __LINE__, _class, level, format, ##__VA_ARGS__)
135  #endif
136 #else
137  #define m2mb_trace_print_M2MB_TL_WARNING( _class, level, format, ... )
138 #endif
139 
140 #if !defined(M2MB_TRACE_LEVEL_LOG_DISABLED)
141  #ifdef M2M_OPTIMIZE_TRACE
142  #define m2mb_trace_print_M2MB_TL_LOG( _class, level, format, ... ) \
143  OPTIMIZED_PRINT( _class, level, format, ##__VA_ARGS__ )
144  #else
145  #define m2mb_trace_print_M2MB_TL_LOG( _class, level, format, ... ) \
146  m2mb_trace_file_line_printf(__MODULE__, __LINE__, _class, level, format, ##__VA_ARGS__)
147  #endif
148 #else
149  #define m2mb_trace_print_M2MB_TL_LOG( _class, level, format, ... )
150 #endif
151 
152 #if !defined(M2MB_TRACE_LEVEL_DEBUG_DISABLED)
153  #ifdef M2M_OPTIMIZE_TRACE
154  #define m2mb_trace_print_M2MB_TL_DEBUG( _class, level, format, ... ) \
155  OPTIMIZED_PRINT( _class, level, format, ##__VA_ARGS__ )
156  #else
157  #define m2mb_trace_print_M2MB_TL_DEBUG( _class, level, format, ... ) \
158  m2mb_trace_file_line_printf(__MODULE__, __LINE__, _class, level, format, ##__VA_ARGS__)
159  #endif
160 #else
161  #define m2mb_trace_print_M2MB_TL_DEBUG( _class, level, format, ... )
162 #endif
163 
164 /* Global typedefs ==============================================================================*/
165 
166 /*
167  typedef enum
168  {
169  M2MB_TC_GENERIC = 0,
170  M2MB_TC_SOCKET = 1,
171  M2MB_TC_CLOCK = 2,
172  M2MB_TC_PDP = 3,
173  M2MB_TC_GNSS = 4,
174  M2MB_TC_M2M_USER = 5,
175  M2MB_TC_FOTA = 6,
176  M2MB_TC_FS = 7,
177  M2MB_TC_QMI = 8,
178  M2MB_TC_SMS = 9,
179  M2MB_TC_INFO = 10,
180  M2MB_TC_LWM2M = 11,
181  M2MB_TC_NET = 12,
182  M2MB_TC_SIM = 13,
183  M2MB_TC_SPI = 14,
184  M2MB_TC_USB = 15,
185  M2MB_TC_NV = 16,
186  M2MB_TC_RTC = 17,
187  M2MB_TC_UART = 18,
188  M2MB_TC_POWER = 19,
189  M2MB_TC_FTPC = 20,
190  M2MB_TC_HTTPC = 21,
191  M2MB_TC_ATI = 22,
192  M2MB_TC_BACKUP = 23,
193  M2MB_TC_NIPD = 24,
194  M2MB_TC_SYS = 25,
195  M2MB_TC_PSM = 26,
196  M2MB_TC_SSL = 27,
197  M2MB_TC_TM = 28,
198  M2MB_TC_ICO = 29,
199  M2MB_TC_CSURV = 30
200  NUM_M2MB_TC
201  } M2MB_TRACE_CLASS;
202 
203 */
204 
205 /* Parse SUBSYS_TRACE_TABLE into a struct using X-Macros
206  the result will be an enum like the commented one above
207 */
208 
209 #define SUBSYS_TRACE_TABLE \
210  SUB_TR_AZ(M2MB_TC_GENERIC, "TC_GENERIC") \
211  SUB_TR_AZ(M2MB_TC_SOCKET, "TC_SOCKET") \
212  SUB_TR_AZ(M2MB_TC_CLOCK, "TC_CLOCK") \
213  SUB_TR_AZ(M2MB_TC_PDP, "TC_PDP") \
214  SUB_TR_AZ(M2MB_TC_GNSS, "TC_GNSS") \
215  SUB_TR_AZ(M2MB_TC_M2M_USER, "TC_M2M_USER") \
216  SUB_TR_AZ(M2MB_TC_FOTA, "TC_FOTA") \
217  SUB_TR_AZ(M2MB_TC_FS, "TC_FS") \
218  SUB_TR_AZ(M2MB_TC_QMI, "TC_QMI") \
219  SUB_TR_AZ(M2MB_TC_SMS, "TC_SMS") \
220  SUB_TR_AZ(M2MB_TC_INFO, "TC_INFO") \
221  SUB_TR_AZ(M2MB_TC_LWM2M, "TC_LWM2M") \
222  SUB_TR_AZ(M2MB_TC_NET, "TC_NET") \
223  SUB_TR_AZ(M2MB_TC_SIM, "TC_SIM") \
224  SUB_TR_AZ(M2MB_TC_SPI, "TC_SPI") \
225  SUB_TR_AZ(M2MB_TC_USB, "TC_USB") \
226  SUB_TR_AZ(M2MB_TC_NV, "TC_NV") \
227  SUB_TR_AZ(M2MB_TC_RTC, "TC_RTC") \
228  SUB_TR_AZ(M2MB_TC_UART, "TC_UART") \
229  SUB_TR_AZ(M2MB_TC_POWER, "TC_POWER") \
230  SUB_TR_AZ(M2MB_TC_FTPC, "TC_FTPC") \
231  SUB_TR_AZ(M2MB_TC_HTTPC, "TC_HTTPC") \
232  SUB_TR_AZ(M2MB_TC_ATI, "TC_ATI") \
233  SUB_TR_AZ(M2MB_TC_BACKUP, "TC_BACKUP") \
234  SUB_TR_AZ(M2MB_TC_NIPD, "TC_NIPD") \
235  SUB_TR_AZ(M2MB_TC_SYS, "TC_SYS") \
236  SUB_TR_AZ(M2MB_TC_PSM, "TC_PSM") \
237  SUB_TR_AZ(M2MB_TC_SSL, "TC_SSL") \
238  SUB_TR_AZ(M2MB_TC_TM, "TC_TM") \
239  SUB_TR_AZ(M2MB_TC_ICO, "TC_ICO") \
240  SUB_TR_AZ(M2MB_TC_CSURV, "TC_CSURV")
241 
242 #define SUB_TR_AZ(a, b) a,
243 typedef enum
244 {
245  SUBSYS_TRACE_TABLE
246  NUM_M2MB_TC,
247  ENUM_TO_INT( M2MB_TRACE_CLASS )
248 } M2MB_TRACE_CLASS;
249 #undef SUB_TR_AZ
250 
251 
252 /*
253  LOG SEVERITY enum for the trace.
254  if in the ini file the log severity is set for example to M2MB_TL_LOG (4), then all
255  the log with inferior severity will be shown, but not M2MB_TL_DEBUG (5)
256 */
257 
258 typedef enum
259 {
260  M2MB_TL_FATAL = 1,
261  M2MB_TL_ERROR = 2,
262  M2MB_TL_WARNING = 3,
263  M2MB_TL_LOG = 4,
264  M2MB_TL_DEBUG = 5,
265  NUM_M2MB_TL,
266  ENUM_TO_INT( M2MB_TRACE_LEVEL )
267 } M2MB_TRACE_LEVEL;
268 
269 /*
270  Type of output for logs, to be set only in log_az.ini.
271  Without the ini file the log will always be on trace
272 */
273 typedef enum
274 {
275  LOG_TRACE, /* TRACE in the log_az.ini file */
276  LOG_USB0, /* USB0 in the log_az.ini file */
277  LOG_USB1, /* USB1 in the log_az.ini file */
278  LOG_UART, /* UART in the log_az.ini file */
279  ENUM_TO_INT( M2MB_TRACE_OUTPUT_TYPE )
280 } M2MB_TRACE_OUTPUT_TYPE;
281 
282 typedef HANDLE M2MB_TRACE_HANDLE;
283 
284 /* Global functions =============================================================================*/
285 /*-----------------------------------------------------------------------------------------------*/
306 /*-----------------------------------------------------------------------------------------------*/
307 M2MB_RESULT_E m2mb_trace_init
308 (
309  void
310 );
311 
312 /*-----------------------------------------------------------------------------------------------*/
332 /*-----------------------------------------------------------------------------------------------*/
333 M2MB_RESULT_E m2mb_trace_deinit
334 (
335  void
336 );
337 
338 
339 /*-----------------------------------------------------------------------------------------------*/
364 /*-----------------------------------------------------------------------------------------------*/
365 M2MB_RESULT_E m2mb_trace_enable
366 (
367  M2MB_TRACE_CLASS traceClass
368 );
369 
370 /*-----------------------------------------------------------------------------------------------*/
394 /*-----------------------------------------------------------------------------------------------*/
395 M2MB_RESULT_E m2mb_trace_disable
396 (
397  M2MB_TRACE_CLASS traceClass
398 );
399 
400 /*-----------------------------------------------------------------------------------------------*/
401 
402 /*-----------------------------------------------------------------------------------------------*/
439 /*-----------------------------------------------------------------------------------------------*/
440 M2MB_RESULT_E m2mb_trace_file_line_printf
441 (
442  const CHAR *file,
443  INT32 line,
444  M2MB_TRACE_CLASS traceClass,
445  M2MB_TRACE_LEVEL level,
446  CHAR *fmt,
447  ...
448 );
449 
450 /*-----------------------------------------------------------------------------------------------*/
474 /*-----------------------------------------------------------------------------------------------*/
475 M2MB_RESULT_E m2mb_trace_all( UINT8 val );
476 
477 /*-----------------------------------------------------------------------------------------------*/
500 /*-----------------------------------------------------------------------------------------------*/
502 (
503  M2MB_TRACE_CLASS traceClass
504 );
505 
506 #endif /* M2M_M2MB_TRACE_H */
507 
m2mb_platform_defines.h
Platform dependant defines.
m2mb_trace_enable
M2MB_RESULT_E m2mb_trace_enable(M2MB_TRACE_CLASS traceClass)
Base trace abilitation.
m2mb_trace_disable
M2MB_RESULT_E m2mb_trace_disable(M2MB_TRACE_CLASS traceClass)
Base trace disabilitation.
m2mb_trace_all
M2MB_RESULT_E m2mb_trace_all(UINT8 val)
m2mb_trace_all disable/enable all traces
m2mb_trace_init
M2MB_RESULT_E m2mb_trace_init(void)
Base trace system initializazion.
m2mb_is_trace_class_enabled
UINT8 m2mb_is_trace_class_enabled(M2MB_TRACE_CLASS traceClass)
Base trace abilitation check.
m2mb_trace_deinit
M2MB_RESULT_E m2mb_trace_deinit(void)
Base trace system deinitializazion.
m2mb_trace_file_line_printf
M2MB_RESULT_E m2mb_trace_file_line_printf(const CHAR *file, INT32 line, M2MB_TRACE_CLASS traceClass, M2MB_TRACE_LEVEL level, CHAR *fmt,...)
Base trace printf with file and line info.