ql_log.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /** @file
  2. ql_log.h
  3. @brief
  4. This file is used to define log interface for different Quectel Project.
  5. */
  6. /*================================================================
  7. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  8. Quectel Wireless Solution Proprietary and Confidential.
  9. =================================================================*/
  10. /*=================================================================
  11. EDIT HISTORY FOR MODULE
  12. This section contains comments describing changes made to the module.
  13. Notice that changes are listed in reverse chronological order.
  14. WHEN WHO WHAT, WHERE, WHY
  15. ------------ ------- -------------------------------------------------------------------------------
  16. =================================================================*/
  17. #ifndef QL_LOG_H
  18. #define QL_LOG_H
  19. #include "osi_log.h"
  20. #include "ql_api_common.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*========================================================================
  25. * Macro Definition
  26. *========================================================================*/
  27. #define QL_LOG_ERRCODE_BASE (QL_COMPONENT_LOG<<16)
  28. #define QL_LOG_LEVEL_NEVER OSI_LOG_LEVEL_NEVER
  29. #define QL_LOG_LEVEL_ERROR OSI_LOG_LEVEL_ERROR
  30. #define QL_LOG_LEVEL_WARN OSI_LOG_LEVEL_WARN
  31. #define QL_LOG_LEVEL_INFO OSI_LOG_LEVEL_INFO
  32. #define QL_LOG_LEVEL_DEBUG OSI_LOG_LEVEL_DEBUG
  33. #define QL_LOG_LEVEL_VERBOSE OSI_LOG_LEVEL_VERBOSE
  34. #define QL_LOG_OUTPUT_LEVEL QL_LOG_LEVEL_INFO
  35. #define QL_LOG_TAG_OPEN OSI_MAKE_LOG_TAG('Q', 'O', 'P', 'N')
  36. #define QL_LOG_TAG_QDEV OSI_MAKE_LOG_TAG('Q', 'D', 'E', 'V')
  37. #define QL_LOG_TAG_SMS OSI_MAKE_LOG_TAG('Q', 'S', 'M', 'S')
  38. #define QL_LOG_TAG_QVOLTE OSI_MAKE_LOG_TAG('Q', 'V', 'L', 'T')
  39. #define QL_LOG_TAG_DATACALL OSI_MAKE_LOG_TAG('Q', 'D', 'C', 'A')
  40. #define QL_LOG_TAG_NW OSI_MAKE_LOG_TAG('Q', 'L', 'N', 'W')
  41. #define QL_LOG_TAG_QPBK OSI_MAKE_LOG_TAG('Q', 'P', 'B', 'K')
  42. #define QL_LOG_TAG_QSIM OSI_MAKE_LOG_TAG('Q', 'S', 'I', 'M')
  43. #define QL_LOG_TAG_QVIMADAPT OSI_MAKE_LOG_TAG('Q', 'V', 'S', 'A')
  44. #define QL_LOG_TAG_QUSBNET OSI_MAKE_LOG_TAG('Q', 'U', 'N', 'T')
  45. #define QL_LOG_TAG_QSPI OSI_MAKE_LOG_TAG('Q', 'S', 'P', 'I')
  46. #define QL_LOG_TAG_SPI_NOR_FLASH OSI_MAKE_LOG_TAG('Q', 'S', 'N', 'O')
  47. #define QL_LOG_TAG_SPI_NAND_FLASH OSI_MAKE_LOG_TAG('Q', 'S', 'N', 'A')
  48. #define QL_LOG_TAG_SPI4_EXTNSFFS OSI_MAKE_LOG_TAG('Q', 'E', '4', 'T')
  49. #define QL_LOG_TAG_SPI6_EXTNSFFS OSI_MAKE_LOG_TAG('Q', 'E', '6', 'T')
  50. #define QL_LOG_TAG_TP OSI_MAKE_LOG_TAG('Q', 'T', 'P', '0')
  51. #define QL_LOG_TAG_NTRIP_RTK OSI_MAKE_LOG_TAG('Q', 'N', 'R', 'K')
  52. #define QL_LOG_TAG_VIRT_AT OSI_MAKE_LOG_TAG('Q', 'V', 'A', 'T')
  53. #define QL_LOG_TAG_SDMMC OSI_MAKE_LOG_TAG('Q', 'S', 'D', 'M')
  54. #define QL_LOG_TAG_AUDIO OSI_MAKE_LOG_TAG('Q', 'A', 'D', 'O')
  55. #ifdef CONFIG_QUEC_PROJECT_FEATURE
  56. #define QL_LOG_TAG_MTP OSI_MAKE_LOG_TAG('Q', 'M', 'T', 'P')
  57. #endif
  58. #define QL_LOG_TAG_CODEC OSI_MAKE_LOG_TAG('Q', 'C', 'O', 'D')
  59. #define QL_LOG_TAG_DECODER OSI_MAKE_LOG_TAG('Q', 'D', 'C', 'D')
  60. #define QL_LOG_TAG_FOTA OSI_MAKE_LOG_TAG('Q', 'F', 'T', 'A')
  61. #define QL_LOG_TAG_GNSS OSI_MAKE_LOG_TAG('Q', 'G', 'N', 'S')
  62. #define QL_LOG_TAG_NMEA OSI_MAKE_LOG_TAG('Q', 'N', 'M', 'E')
  63. #define QL_LOG_TAG_HTTP OSI_MAKE_LOG_TAG('Q', 'H', 'T', 'T')
  64. #define QL_LOG_TAG_LCD OSI_MAKE_LOG_TAG('Q', 'L', 'C', 'D')
  65. #define QL_LOG_TAG_IIC OSI_MAKE_LOG_TAG('Q', 'I', 'I', 'C')
  66. #define QL_LOG_TAG_OSI OSI_MAKE_LOG_TAG('Q', 'O', 'S', 'I')
  67. #define QL_LOG_TAG_POWER OSI_MAKE_LOG_TAG('Q', 'P', 'W', 'R')
  68. #define QL_LOG_TAG_USB OSI_MAKE_LOG_TAG('Q', 'U', 'S', 'B')
  69. #define QL_LOG_TAG_USB_AUDIO OSI_MAKE_LOG_TAG('Q', 'U', 'A', 'C')
  70. #define QL_LOG_TAG_WIFISCAN OSI_MAKE_LOG_TAG('Q', 'W', 'I', 'F')
  71. #define QL_LOG_TAG_CAMERA OSI_MAKE_LOG_TAG('Q', 'C', 'A', 'M')
  72. #define QL_LOG_TAG_ADC OSI_MAKE_LOG_TAG('Q', 'A', 'D', 'C')
  73. #define QL_LOG_TAG_GPIO OSI_MAKE_LOG_TAG('Q', 'G', 'I', 'O')
  74. #define QL_LOG_TAG_KEYPAD OSI_MAKE_LOG_TAG('Q', 'K', 'Y', 'D')
  75. #define QL_LOG_TAG_PWM OSI_MAKE_LOG_TAG('Q', 'P', 'W', 'M')
  76. #define QL_LOG_TAG_RTC OSI_MAKE_LOG_TAG('Q', 'R', 'T', 'C')
  77. #define QL_LOG_TAG_UART OSI_MAKE_LOG_TAG('Q', 'U', 'A', 'T')
  78. #define QL_LOG_TAG_FATFS OSI_MAKE_LOG_TAG('Q', 'F', 'T', 'S')
  79. #define QL_LOG_TAG_NOR_FLASH OSI_MAKE_LOG_TAG('Q', 'N', 'O', 'F')
  80. #define QL_LOG_TAG_TTS OSI_MAKE_LOG_TAG('Q', 'T', 'T', 'S')
  81. #define QL_LOG_TAG_ALIYUN_IOT_SMARTCARD OSI_MAKE_LOG_TAG('Q', 'A', 'L', 'S')
  82. #define QL_LOG_TAG_ALIPAY_IOT OSI_MAKE_LOG_TAG('Q', 'A', 'L', 'P')
  83. #define QL_LOG_TAG_FIREWALL OSI_MAKE_LOG_TAG('Q', 'F', 'I', 'W')
  84. #define QL_LOG_TAG_HW_IOT_DEVICE OSI_MAKE_LOG_TAG('Q', 'H', 'W', 'D')
  85. #define QL_LOG_TAG_CTSREG OSI_MAKE_LOG_TAG('Q', 'C', 'T', 'R')
  86. #define QL_LOG_TAG_CERT OSI_MAKE_LOG_TAG('Q', 'C', 'R', 'T')
  87. #define QL_LOG_TAG_ZIP OSI_MAKE_LOG_TAG('Q', 'Z', 'I', 'P')
  88. #define QL_LOG_TAG_FILE OSI_MAKE_LOG_TAG('Q', 'F', 'I', 'L')
  89. #define QL_LOG_TAG_BT_BLE OSI_MAKE_LOG_TAG('Q', 'B', 'T', 'E')
  90. #define QL_LOG_TAG_BLE_GATT OSI_MAKE_LOG_TAG('Q', 'A', 'T', 'T')
  91. #define QL_LOG_TAG_WEBSOCKET OSI_MAKE_LOG_TAG('Q', 'W', 'W', 'S')
  92. #define QL_LOG_TAG_ETHERNET OSI_MAKE_LOG_TAG('Q', 'E', 'T', 'H')
  93. #define QL_LOG_TAG_WIFI OSI_MAKE_LOG_TAG('Q', 'W', 'F', 'I')
  94. #define QL_LOG_PRINTF_TAG(level, tag, fmt, ...) \
  95. do \
  96. { \
  97. if (QL_LOG_OUTPUT_LEVEL >= level) \
  98. osiTracePrintf((level << 28) | (tag), fmt, ##__VA_ARGS__); \
  99. } while (0)
  100. #define QL_LOG_PRINTF(level, fmt, ...) QL_LOG_PRINTF_TAG(level, QL_LOG_TAG_OPEN, fmt, ##__VA_ARGS__)
  101. //CSDK compilation will generate CONFIG_QL_CCSDK_BUILD_ON,otherwise only CONFIG_QL_CCSDK_BUILD_ will be generated
  102. #ifdef CONFIG_QL_CCSDK_BUILD_ON
  103. //csdk app build use this
  104. #define QL_LOG_PUSH(module_str, msg, ...) QL_LOG_PRINTF_TAG(QL_LOG_OUTPUT_LEVEL, QL_LOG_TAG_OPEN, module_str":%s %d "msg"", __FUNCTION__, __LINE__, ##__VA_ARGS__)
  105. #define QL_LOG(level, module_str, msg, ...) QL_LOG_PRINTF_TAG(level, QL_LOG_TAG_OPEN, module_str":%s %d "msg"", __FUNCTION__, __LINE__, ##__VA_ARGS__)
  106. #define QL_LOG_PUSH_TAG(module_str, tag, msg, ...) QL_LOG_PRINTF_TAG(QL_LOG_OUTPUT_LEVEL, tag, module_str":%s %d "msg"", __FUNCTION__, __LINE__, ##__VA_ARGS__)
  107. #define QL_LOG_TAG(level, tag, module_str, msg, ...) QL_LOG_PRINTF_TAG(level, tag, module_str":%s %d "msg"", __FUNCTION__, __LINE__, ##__VA_ARGS__)
  108. #else
  109. //local or kernel build use this
  110. #ifndef _THIS_IP_
  111. //get the function address
  112. #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
  113. #endif
  114. #define QL_LOG_PUSH(module_str, msg, ...) QL_LOG_PRINTF_TAG(QL_LOG_OUTPUT_LEVEL, QL_LOG_TAG_OPEN, "%p %d "msg"", _THIS_IP_, __LINE__, ##__VA_ARGS__)
  115. #define QL_LOG(level, user_str, msg, ...) QL_LOG_PRINTF_TAG(level, QL_LOG_TAG_OPEN, "%p %d "msg"", _THIS_IP_,__LINE__, ##__VA_ARGS__)
  116. #define QL_LOG_PUSH_TAG(module_str, tag, msg, ...) QL_LOG_PRINTF_TAG(QL_LOG_OUTPUT_LEVEL, tag, "%p %d "msg"", _THIS_IP_, __LINE__, ##__VA_ARGS__)
  117. #define QL_LOG_TAG(level, tag, module_str, msg, ...) QL_LOG_PRINTF_TAG(level, tag, "%p %d "msg"", _THIS_IP_, __LINE__, ##__VA_ARGS__)
  118. #endif
  119. #undef printf
  120. #define printf(fmt, args...) QL_LOG_PRINTF_TAG(QL_LOG_OUTPUT_LEVEL, QL_LOG_TAG_OPEN, fmt, ##args)
  121. #define QUEC_FSTRACE_SUPPORT_NOR_FLASH 0 //Saving logs to Norflash is not supported by default, because the capacity is too small
  122. //This configuration does not take effect in the SDK. You need to generate a new SDK
  123. //[0]: aplog, [1] profile, [2] bsdump, [3] cplog, [4] zsplog, [5] moslog, [11] debug/usb [12] sdcard, [13]nandflash, [14]spi4nor, [15]spi6nor
  124. #define QUEC_FS_TRACE_PORT_BEFORE (1<<11)
  125. #define QUEC_FS_TRACE_PORT_SD (1<<12)
  126. #define QUEC_FS_TRACE_PORT_NAND (1<<13)
  127. #define QUEC_FS_TRACE_PORT_EXTNOR (1<<14)
  128. #define QUEC_FS_TRACE_PORT_EXT (1<<15)
  129. #define FSTRACE_FNAME_MAX (64)
  130. #define FS_MOUNT_POINT_MAX (16) //Maximum length of mount path
  131. /*========================================================================
  132. * Enumeration Definition
  133. *========================================================================*/
  134. //log component detail errcode, 4 bytes
  135. typedef enum
  136. {
  137. QL_LOG_SUCCESS = QL_SUCCESS,
  138. QL_LOG_EXECUTE_ERR = 1|QL_LOG_ERRCODE_BASE,
  139. QL_LOG_MEM_ADDR_NULL_ERR,
  140. QL_LOG_INVALID_PARAM_ERR,
  141. QL_LOG_BUSY_ERR,
  142. QL_LOG_SEMAPHORE_CREATE_ERR,
  143. QL_LOG_SEMAPHORE_TIMEOUT_ERR,
  144. QL_LOG_PORT_SET_ERR = 15|QL_LOG_ERRCODE_BASE,
  145. } ql_errcode_log_e;
  146. typedef enum
  147. {
  148. QL_LOG_PORT_NONE = 0x0,
  149. QL_LOG_PORT_UART = 0x1,
  150. QL_LOG_PORT_USB = 0x2,
  151. QL_LOG_PORT_SDCARD = 0x4, //SDCARD
  152. QL_LOG_PORT_EXNAND = 0x5, //NAND FLASH
  153. #if QUEC_FSTRACE_SUPPORT_NOR_FLASH
  154. QL_LOG_PORT_EXNOR = 0x6, //SPI4 NOR FLASH
  155. QL_LOG_PORT_EXT = 0x7, //SPI6 NOR FLASH
  156. #endif
  157. }ql_log_port_e;
  158. typedef struct
  159. {
  160. int64 total_size_max;
  161. int aplog_fsize_max; // aplog each file size
  162. int cplog_fsize_max; // cplog each file size
  163. int moslog_fsize_max; // moslog each file size
  164. int prolog_fsize_max; // profile each file size
  165. char fs_trace_mount_point_len;
  166. char fs_trace_mount_point[FS_MOUNT_POINT_MAX]; //"/sdcard0" "/exnand" "/exnor" "/ext"
  167. char fstrace_fname[FSTRACE_FNAME_MAX];
  168. }quec_fs_trace_path_t;
  169. typedef enum
  170. {
  171. QL_LOG_PCAP_NONE = 0,
  172. QL_LOG_PCAP_PPP = (1 << 0),
  173. QL_LOG_PCAP_ECM_RNDIS = (1 << 1),
  174. }ql_log_pcap_e;
  175. /*========================================================================
  176. * function Definition
  177. *========================================================================*/
  178. /*
  179. * to config the log port for AP, it will take effect after reboot.
  180. */
  181. ql_errcode_log_e ql_log_set_port(ql_log_port_e dst_port);
  182. /*
  183. * to enable or disable quectel log
  184. */
  185. void ql_quec_trace_enable(bool allow_Put);
  186. /*
  187. * Initialization Saves logs in the file system.
  188. * Logs before fstrace init can be output via USB or debug port, which can be configured in prvTraceInit of app_start.
  189. * Debug port is used by default.
  190. */
  191. //void ql_fs_trace_init(void);
  192. ql_errcode_log_e ql_log_pcap_get_from_nv();
  193. ql_errcode_log_e ql_log_pcap_get(ql_log_pcap_e* flag);
  194. ql_errcode_log_e ql_log_pcap_set(ql_log_pcap_e flag);
  195. #ifdef __cplusplus
  196. } /*"C" */
  197. #endif
  198. #endif /* QL_LOG_H */