1 /******************************************************************************* 2 Copyright � 2015, STMicroelectronics International N.V. 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above copyright 10 notice, this list of conditions and the following disclaimer in the 11 documentation and/or other materials provided with the distribution. 12 * Neither the name of STMicroelectronics nor the 13 names of its contributors may be used to endorse or promote products 14 derived from this software without specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND 19 NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED. 20 IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 ********************************************************************************/ 28 29 30 #ifndef _VL53L0X_PLATFORM_LOG_H_ 31 #define _VL53L0X_PLATFORM_LOG_H_ 32 33 #include <stdio.h> 34 #include <string.h> 35 /* LOG Functions */ 36 37 #ifdef __cplusplus 38 extern "C" 39 { 40 #endif 41 42 43 /** 44 * @file vl53l0x_platform_log.h 45 * 46 * @brief platform log function definition 47 */ 48 49 //#define VL53L0X_LOG_ENABLE 0 50 51 enum 52 { 53 TRACE_LEVEL_NONE, 54 TRACE_LEVEL_ERRORS, 55 TRACE_LEVEL_WARNING, 56 TRACE_LEVEL_INFO, 57 TRACE_LEVEL_DEBUG, 58 TRACE_LEVEL_ALL, 59 TRACE_LEVEL_IGNORE 60 }; 61 62 enum 63 { 64 TRACE_FUNCTION_NONE = 0, 65 TRACE_FUNCTION_I2C = 1, 66 TRACE_FUNCTION_ALL = 0x7fffffff // all bits except sign 67 }; 68 69 enum 70 { 71 TRACE_MODULE_NONE = 0x0, 72 TRACE_MODULE_API = 0x1, 73 TRACE_MODULE_PLATFORM = 0x2, 74 TRACE_MODULE_ALL = 0x7fffffff // all bits except sign 75 }; 76 77 78 #if defined(VL53L0X_LOG_ENABLE) && (TRACE_UART == 1) 79 80 #include <stdarg.h> 81 extern int uart_printf(const char *msg, ...); 82 extern int uart_vprintf(const char *msg, va_list ap); 83 84 #define trace_printf uart_printf 85 #define trace_vprintf uart_vprintf 86 87 88 extern uint32_t _trace_level; 89 90 91 int32_t VL53L0X_trace_config(char *filename, uint32_t modules, 92 uint32_t level, uint32_t functions); 93 void trace_print_module_function(uint32_t module, uint32_t level, 94 uint32_t function, const char *format, 95 ...); 96 97 98 // extern FILE * log_file; 99 100 #define LOG_GET_TIME() (int)HAL_GetTick() 101 102 #define _LOG_FUNCTION_START(module, fmt, ...) \ 103 trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, \ 104 "%ld <START> %s " fmt "\n", LOG_GET_TIME(), \ 105 __FUNCTION__, ##__VA_ARGS__); 106 107 #define _LOG_FUNCTION_END(module, status, ...) \ 108 trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, \ 109 "%d <END> %s %d\n", LOG_GET_TIME(), \ 110 __FUNCTION__, (int)status, ##__VA_ARGS__) 111 112 #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...) \ 113 trace_print_module_function(module, _trace_level, TRACE_FUNCTION_ALL, \ 114 "%d <END> %s %d " fmt "\n", LOG_GET_TIME(), \ 115 __FUNCTION__, (int)status, ##__VA_ARGS__) 116 117 118 #else /* VL53L0X_LOG_ENABLE no logging or no TRACE_UART */ 119 #define VL53L0X_ErrLog(...) (void)0 120 #define _LOG_FUNCTION_START(module, fmt, ...) (void)0 121 #define _LOG_FUNCTION_END(module, status, ...) (void)0 122 #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...) (void)0 123 #define trace_vprintf(...) (void)0 124 #define VL53L0X_trace_config(...) (void)0 125 126 #endif /* else */ 127 128 #define VL53L0_COPYSTRING(str, ...) strcpy(str, ##__VA_ARGS__) 129 #ifdef __cplusplus 130 } 131 #endif 132 #endif /* _VL53L0X_PLATFORM_LOG_H_ */ 133