1 /* vl53l1x_platform_log.h - Zephyr customization of ST vl53l1x library. */ 2 3 /* 4 * Copyright (c) 2017 STMicroelectronics 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 10 #ifndef _VL53L1_PLATFORM_LOG_H_ 11 #define _VL53L1_PLATFORM_LOG_H_ 12 13 14 #ifdef VL53L1_LOG_ENABLE 15 #include "vl53l1_platform_user_config.h" 16 17 #ifdef _MSC_VER 18 # define EWOKPLUS_EXPORTS __declspec(dllexport) 19 #else 20 # define EWOKPLUS_EXPORTS 21 #endif 22 23 #include "vl53l1_types.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #include <time.h> 30 31 /** 32 * @brief Set the level, output and specific functions for module logging. 33 * 34 * 35 * @param filename - full path of output log file, NULL for print to stdout 36 * 37 * @param modules - Module or None or All to trace 38 * VL53L1_TRACE_MODULE_NONE 39 * VL53L1_TRACE_MODULE_API 40 * VL53L1_TRACE_MODULE_CORE 41 * VL53L1_TRACE_MODULE_TUNING 42 * VL53L1_TRACE_MODULE_CHARACTERISATION 43 * VL53L1_TRACE_MODULE_PLATFORM 44 * VL53L1_TRACE_MODULE_ALL 45 * 46 * @param level - trace level 47 * VL53L1_TRACE_LEVEL_NONE 48 * VL53L1_TRACE_LEVEL_ERRORS 49 * VL53L1_TRACE_LEVEL_WARNING 50 * VL53L1_TRACE_LEVEL_INFO 51 * VL53L1_TRACE_LEVEL_DEBUG 52 * VL53L1_TRACE_LEVEL_ALL 53 * VL53L1_TRACE_LEVEL_IGNORE 54 * 55 * @param functions - function level to trace; 56 * VL53L1_TRACE_FUNCTION_NONE 57 * VL53L1_TRACE_FUNCTION_I2C 58 * VL53L1_TRACE_FUNCTION_ALL 59 * 60 * @return status - always VL53L1_ERROR_NONE 61 * 62 */ 63 64 #define VL53L1_TRACE_LEVEL_NONE 0x00000000 65 #define VL53L1_TRACE_LEVEL_ERRORS 0x00000001 66 #define VL53L1_TRACE_LEVEL_WARNING 0x00000002 67 #define VL53L1_TRACE_LEVEL_INFO 0x00000004 68 #define VL53L1_TRACE_LEVEL_DEBUG 0x00000008 69 #define VL53L1_TRACE_LEVEL_ALL 0x00000010 70 #define VL53L1_TRACE_LEVEL_IGNORE 0x00000020 71 72 #define VL53L1_TRACE_FUNCTION_NONE 0x00000000 73 #define VL53L1_TRACE_FUNCTION_I2C 0x00000001 74 #define VL53L1_TRACE_FUNCTION_ALL 0x7fffffff 75 76 #define VL53L1_TRACE_MODULE_NONE 0x00000000 77 #define VL53L1_TRACE_MODULE_API 0x00000001 78 #define VL53L1_TRACE_MODULE_CORE 0x00000002 79 #define VL53L1_TRACE_MODULE_PROTECTED 0x00000004 80 #define VL53L1_TRACE_MODULE_HISTOGRAM 0x00000008 81 #define VL53L1_TRACE_MODULE_REGISTERS 0x00000010 82 #define VL53L1_TRACE_MODULE_PLATFORM 0x00000020 83 #define VL53L1_TRACE_MODULE_NVM 0x00000040 84 #define VL53L1_TRACE_MODULE_CALIBRATION_DATA 0x00000080 85 #define VL53L1_TRACE_MODULE_NVM_DATA 0x00000100 86 #define VL53L1_TRACE_MODULE_HISTOGRAM_DATA 0x00000200 87 #define VL53L1_TRACE_MODULE_RANGE_RESULTS_DATA 0x00000400 88 #define VL53L1_TRACE_MODULE_XTALK_DATA 0x00000800 89 #define VL53L1_TRACE_MODULE_OFFSET_DATA 0x00001000 90 #define VL53L1_TRACE_MODULE_DATA_INIT 0x00002000 91 #define VL53L1_TRACE_MODULE_REF_SPAD_CHAR 0x00004000 92 #define VL53L1_TRACE_MODULE_SPAD_RATE_MAP 0x00008000 93 #ifdef PAL_EXTENDED 94 #define VL53L1_TRACE_MODULE_SPAD 0x01000000 95 #define VL53L1_TRACE_MODULE_FMT 0x02000000 96 #define VL53L1_TRACE_MODULE_UTILS 0x04000000 97 #define VL53L1_TRACE_MODULE_BENCH_FUNCS 0x08000000 98 #endif 99 #define VL53L1_TRACE_MODULE_CUSTOMER_API 0x40000000 100 #define VL53L1_TRACE_MODULE_ALL 0x7fffffff 101 102 103 extern uint32_t _trace_level; 104 105 /* 106 * NOTE: dynamically exported if we enable logging. 107 * this way, Python interfaces can access this function, but we don't 108 * need to include it in the .def files. 109 */ 110 EWOKPLUS_EXPORTS int8_t VL53L1_trace_config( 111 char *filename, 112 uint32_t modules, 113 uint32_t level, 114 uint32_t functions); 115 116 /** 117 * @brief Print trace module function. 118 * 119 * @param module - ?? 120 * @param level - ?? 121 * @param function - ?? 122 * @param format - ?? 123 * 124 */ 125 126 EWOKPLUS_EXPORTS void VL53L1_trace_print_module_function( 127 uint32_t module, 128 uint32_t level, 129 uint32_t function, 130 const char *format, ...); 131 132 /** 133 * @brief Get global _trace_functions parameter 134 * 135 * @return _trace_functions 136 */ 137 138 uint32_t VL53L1_get_trace_functions(void); 139 140 /** 141 * @brief Set global _trace_functions parameter 142 * 143 * @param[in] function : new function code 144 */ 145 146 void VL53L1_set_trace_functions(uint32_t function); 147 148 149 /* 150 * @brief Returns the current system tick count in [ms] 151 * 152 * @return time_ms : current time in [ms] 153 * 154 */ 155 156 uint32_t VL53L1_clock(void); 157 158 #define LOG_GET_TIME() \ 159 ((int)VL53L1_clock()) 160 161 #define _LOG_TRACE_PRINT(module, level, function, ...) \ 162 VL53L1_trace_print_module_function(module, level, function, ##__VA_ARGS__); 163 164 #define _LOG_FUNCTION_START(module, fmt, ...) \ 165 VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL,\ 166 "%6ld <S> %s "fmt"\n", LOG_GET_TIME(), __func__, ##__VA_ARGS__); 167 168 #define _LOG_FUNCTION_END(module, status, ...)\ 169 VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL,\ 170 "%6ld <E> %s %d\n", LOG_GET_TIME(), __func__, (int)status, ##__VA_ARGS__) 171 172 #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...)\ 173 VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL,\ 174 "%6ld <E> %s %d "fmt"\n", LOG_GET_TIME(), __func__, (int)status, ##__VA_ARGS__) 175 176 #define _LOG_GET_TRACE_FUNCTIONS()\ 177 VL53L1_get_trace_functions() 178 179 #define _LOG_SET_TRACE_FUNCTIONS(functions)\ 180 VL53L1_set_trace_functions(functions) 181 182 #define _LOG_STRING_BUFFER(x) char x[VL53L1_MAX_STRING_LENGTH] 183 184 #ifdef __cplusplus 185 } 186 #endif 187 188 #else /* VL53L1_LOG_ENABLE - no logging */ 189 190 #define _LOG_TRACE_PRINT(module, level, function, ...) 191 #define _LOG_FUNCTION_START(module, fmt, ...) 192 #define _LOG_FUNCTION_END(module, status, ...) 193 #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...) 194 #define _LOG_GET_TRACE_FUNCTIONS() 0 195 #define _LOG_SET_TRACE_FUNCTIONS(functions) 196 #define _LOG_STRING_BUFFER(x) 197 198 #endif /* VL53L1_LOG_ENABLE */ 199 200 #endif /* _VL53L1_PLATFORM_LOG_H_ */ 201