vl53l1_platform_log.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
  3. *
  4. * This file is part of VL53L1 Core and is dual licensed,
  5. * either 'STMicroelectronics
  6. * Proprietary license'
  7. * or 'BSD 3-clause "New" or "Revised" License' , at your option.
  8. *
  9. ********************************************************************************
  10. *
  11. * 'STMicroelectronics Proprietary license'
  12. *
  13. ********************************************************************************
  14. *
  15. * License terms: STMicroelectronics Proprietary in accordance with licensing
  16. * terms at www.st.com/sla0081
  17. *
  18. * STMicroelectronics confidential
  19. * Reproduction and Communication of this document is strictly prohibited unless
  20. * specifically authorized in writing by STMicroelectronics.
  21. *
  22. *
  23. ********************************************************************************
  24. *
  25. * Alternatively, VL53L1 Core may be distributed under the terms of
  26. * 'BSD 3-clause "New" or "Revised" License', in which case the following
  27. * provisions apply instead of the ones mentioned above :
  28. *
  29. ********************************************************************************
  30. *
  31. * License terms: BSD 3-clause "New" or "Revised" License.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted provided that the following conditions are met:
  35. *
  36. * 1. Redistributions of source code must retain the above copyright notice, this
  37. * list of conditions and the following disclaimer.
  38. *
  39. * 2. Redistributions in binary form must reproduce the above copyright notice,
  40. * this list of conditions and the following disclaimer in the documentation
  41. * and/or other materials provided with the distribution.
  42. *
  43. * 3. Neither the name of the copyright holder nor the names of its contributors
  44. * may be used to endorse or promote products derived from this software
  45. * without specific prior written permission.
  46. *
  47. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  48. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  50. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  51. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  52. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  55. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  56. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  57. *
  58. *
  59. ********************************************************************************
  60. *
  61. */
  62. /**
  63. * @file vl53l1_platform_log.h
  64. *
  65. * @brief EwokPlus25 platform logging function definition
  66. */
  67. #ifndef _VL53L1_PLATFORM_LOG_H_
  68. #define _VL53L1_PLATFORM_LOG_H_
  69. #ifdef VL53L1_LOG_ENABLE
  70. #include "vl53l1_platform_user_config.h"
  71. #ifdef _MSC_VER
  72. # define EWOKPLUS_EXPORTS __declspec(dllexport)
  73. #else
  74. # define EWOKPLUS_EXPORTS
  75. #endif
  76. #include "vl53l1_types.h"
  77. #ifdef __cplusplus
  78. extern "C" {
  79. #endif
  80. #include <time.h>
  81. /**
  82. * @brief Set the level, output and specific functions for module logging.
  83. *
  84. *
  85. * @param filename - full path of output log file, NULL for print to stdout
  86. *
  87. * @param modules - Module or None or All to trace
  88. * VL53L1_TRACE_MODULE_NONE
  89. * VL53L1_TRACE_MODULE_API
  90. * VL53L1_TRACE_MODULE_CORE
  91. * VL53L1_TRACE_MODULE_TUNING
  92. * VL53L1_TRACE_MODULE_CHARACTERISATION
  93. * VL53L1_TRACE_MODULE_PLATFORM
  94. * VL53L1_TRACE_MODULE_ALL
  95. *
  96. * @param level - trace level
  97. * VL53L1_TRACE_LEVEL_NONE
  98. * VL53L1_TRACE_LEVEL_ERRORS
  99. * VL53L1_TRACE_LEVEL_WARNING
  100. * VL53L1_TRACE_LEVEL_INFO
  101. * VL53L1_TRACE_LEVEL_DEBUG
  102. * VL53L1_TRACE_LEVEL_ALL
  103. * VL53L1_TRACE_LEVEL_IGNORE
  104. *
  105. * @param functions - function level to trace;
  106. * VL53L1_TRACE_FUNCTION_NONE
  107. * VL53L1_TRACE_FUNCTION_I2C
  108. * VL53L1_TRACE_FUNCTION_ALL
  109. *
  110. * @return status - always VL53L1_ERROR_NONE
  111. *
  112. */
  113. #define VL53L1_TRACE_LEVEL_NONE 0x00000000
  114. #define VL53L1_TRACE_LEVEL_ERRORS 0x00000001
  115. #define VL53L1_TRACE_LEVEL_WARNING 0x00000002
  116. #define VL53L1_TRACE_LEVEL_INFO 0x00000004
  117. #define VL53L1_TRACE_LEVEL_DEBUG 0x00000008
  118. #define VL53L1_TRACE_LEVEL_ALL 0x00000010
  119. #define VL53L1_TRACE_LEVEL_IGNORE 0x00000020
  120. #define VL53L1_TRACE_FUNCTION_NONE 0x00000000
  121. #define VL53L1_TRACE_FUNCTION_I2C 0x00000001
  122. #define VL53L1_TRACE_FUNCTION_ALL 0x7fffffff
  123. #define VL53L1_TRACE_MODULE_NONE 0x00000000
  124. #define VL53L1_TRACE_MODULE_API 0x00000001
  125. #define VL53L1_TRACE_MODULE_CORE 0x00000002
  126. #define VL53L1_TRACE_MODULE_PROTECTED 0x00000004
  127. #define VL53L1_TRACE_MODULE_HISTOGRAM 0x00000008
  128. #define VL53L1_TRACE_MODULE_REGISTERS 0x00000010
  129. #define VL53L1_TRACE_MODULE_PLATFORM 0x00000020
  130. #define VL53L1_TRACE_MODULE_NVM 0x00000040
  131. #define VL53L1_TRACE_MODULE_CALIBRATION_DATA 0x00000080
  132. #define VL53L1_TRACE_MODULE_NVM_DATA 0x00000100
  133. #define VL53L1_TRACE_MODULE_HISTOGRAM_DATA 0x00000200
  134. #define VL53L1_TRACE_MODULE_RANGE_RESULTS_DATA 0x00000400
  135. #define VL53L1_TRACE_MODULE_XTALK_DATA 0x00000800
  136. #define VL53L1_TRACE_MODULE_OFFSET_DATA 0x00001000
  137. #define VL53L1_TRACE_MODULE_DATA_INIT 0x00002000
  138. #define VL53L1_TRACE_MODULE_REF_SPAD_CHAR 0x00004000
  139. #define VL53L1_TRACE_MODULE_SPAD_RATE_MAP 0x00008000
  140. #ifdef PAL_EXTENDED
  141. #define VL53L1_TRACE_MODULE_SPAD 0x01000000
  142. #define VL53L1_TRACE_MODULE_FMT 0x02000000
  143. #define VL53L1_TRACE_MODULE_UTILS 0x04000000
  144. #define VL53L1_TRACE_MODULE_BENCH_FUNCS 0x08000000
  145. #endif
  146. #define VL53L1_TRACE_MODULE_CUSTOMER_API 0x40000000
  147. #define VL53L1_TRACE_MODULE_ALL 0x7fffffff
  148. extern uint32_t _trace_level;
  149. /*
  150. * NOTE: dynamically exported if we enable logging.
  151. * this way, Python interfaces can access this function, but we don't
  152. * need to include it in the .def files.
  153. */
  154. EWOKPLUS_EXPORTS int8_t VL53L1_trace_config(
  155. char *filename,
  156. uint32_t modules,
  157. uint32_t level,
  158. uint32_t functions);
  159. /**
  160. * @brief Print trace module function.
  161. *
  162. * @param module - ??
  163. * @param level - ??
  164. * @param function - ??
  165. * @param format - ??
  166. *
  167. */
  168. EWOKPLUS_EXPORTS void VL53L1_trace_print_module_function(
  169. uint32_t module,
  170. uint32_t level,
  171. uint32_t function,
  172. const char *format, ...);
  173. /**
  174. * @brief Get global _trace_functions parameter
  175. *
  176. * @return _trace_functions
  177. */
  178. uint32_t VL53L1_get_trace_functions(void);
  179. /**
  180. * @brief Set global _trace_functions parameter
  181. *
  182. * @param[in] function : new function code
  183. */
  184. void VL53L1_set_trace_functions(uint32_t function);
  185. /*
  186. * @brief Returns the current system tick count in [ms]
  187. *
  188. * @return time_ms : current time in [ms]
  189. *
  190. */
  191. uint32_t VL53L1_clock(void);
  192. #define LOG_GET_TIME() \
  193. ((int)VL53L1_clock())
  194. #define _LOG_TRACE_PRINT(module, level, function, ...) \
  195. VL53L1_trace_print_module_function(module, level, function, ##__VA_ARGS__);
  196. #define _LOG_FUNCTION_START(module, fmt, ...) \
  197. VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld <START> %s "fmt"\n", LOG_GET_TIME(), __FUNCTION__, ##__VA_ARGS__);
  198. #define _LOG_FUNCTION_END(module, status, ...)\
  199. VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld <END> %s %d\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__)
  200. #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...)\
  201. VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld <END> %s %d "fmt"\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__)
  202. #define _LOG_GET_TRACE_FUNCTIONS()\
  203. VL53L1_get_trace_functions()
  204. #define _LOG_SET_TRACE_FUNCTIONS(functions)\
  205. VL53L1_set_trace_functions(functions)
  206. #define _LOG_STRING_BUFFER(x) char x[VL53L1_MAX_STRING_LENGTH]
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210. #else /* VL53L1_LOG_ENABLE - no logging */
  211. #define _LOG_TRACE_PRINT(module, level, function, ...)
  212. #define _LOG_FUNCTION_START(module, fmt, ...)
  213. #define _LOG_FUNCTION_END(module, status, ...)
  214. #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...)
  215. #define _LOG_GET_TRACE_FUNCTIONS() 0
  216. #define _LOG_SET_TRACE_FUNCTIONS(functions)
  217. #define _LOG_STRING_BUFFER(x)
  218. #endif /* VL53L1_LOG_ENABLE */
  219. #endif /* _VL53L1_PLATFORM_LOG_H_ */