Basic debug library
Dependents: modem_ref_helper_for_v5_3_217 modem_ref_helper
WizziDebug.h
00001 #ifndef DBG_H 00002 #define DBG_H 00003 00004 #include "mbed.h" 00005 #include "WizziCom.h" 00006 00007 // Enable the debug prints. 00008 #define __PRINT_ENABLED__ 00009 00010 // Reboot the device on fatal error, else trap the processor. 00011 #define __REBOOT_ON_ASSERT__ 00012 00013 // Flush the debug queue if full to avoid losing traces (can impact performances) 00014 //#define __FLUSH_IF_FULL__ 00015 00016 // Force flush until an EOL character ('\n') 00017 //#define __FORCE_LINE_INTEGRITY__ 00018 00019 // Force flush, do not bufferise trace 00020 //#define __FORCE_FLUSH__ 00021 00022 #ifdef __PRINT_ENABLED__ 00023 #define DBG_OPEN(...) dbg_open(__VA_ARGS__) 00024 #define FLUSH() dbg_flush() 00025 00026 // Enable or disable trace levels 00027 #define _USER_PRINTS_ 00028 #define _PRINT_ERRORS_ 00029 #define _PRINT_WARNINGS_ 00030 #define _PRINT_INFOS_ 00031 //#define _PRINT_DEBUG_ 00032 //#define _PRINT_FUNCTIONS_ // Print the function name where FPRINT is called 00033 //#define _TRACE_MALLOC_ 00034 00035 #else 00036 #define DBG_OPEN(led) dbg_set_led(led) 00037 #define FLUSH(); 00038 #endif 00039 00040 00041 #define RAM_START_ADDRESS (0x20000000) 00042 #define RAM_END_ADDRESS (0x40000000) 00043 00044 #define ASSERT(...) dbg_assert(__VA_ARGS__) 00045 00046 00047 #ifdef _USER_PRINTS_ 00048 #define PRINT(...) dbg_print(__VA_ARGS__) 00049 #define PRINT_DATA(...) dbg_print_data(__VA_ARGS__) 00050 #else 00051 #define PRINT(...); 00052 #define PRINT_DATA(...); 00053 #endif 00054 00055 00056 #ifdef _PRINT_ERRORS_ 00057 #define EPRINT(format,...) dbg_print("ERROR: "format, __VA_ARGS__) 00058 #else 00059 #define EPRINT(...); 00060 #endif 00061 00062 00063 #ifdef _PRINT_WARNINGS_ 00064 #define WARNING(w,format,...) do { if(!(w)) { dbg_print("WARNING: "format, __VA_ARGS__); } } while(0) 00065 #else 00066 #define WARNING(...); 00067 #endif 00068 00069 00070 #ifdef _PRINT_FUNCTIONS_ 00071 #define FPRINT(format,...) dbg_print("%s"format,__FUNCTION__,##__VA_ARGS__) 00072 #else 00073 #define FPRINT(...); 00074 #endif 00075 00076 00077 #ifdef _PRINT_INFOS_ 00078 #define IPRINT(...) dbg_print("INFO: "__VA_ARGS__) 00079 #else 00080 #define IPRINT(...); 00081 #endif 00082 00083 00084 #ifdef _PRINT_DEBUG_ 00085 #define DPRINT(...) dbg_print(__VA_ARGS__) 00086 #define DPRINT_DATA(...) dbg_print_data(__VA_ARGS__) 00087 #else 00088 #define DPRINT(...); 00089 #define DPRINT_DATA(...); 00090 #endif 00091 00092 00093 #ifdef _TRACE_MALLOC_ 00094 #define MALLOC(s) dbg_malloc((s),__FUNCTION__,__LINE__);FLUSH(); 00095 #define REALLOC(p,s) dbg_realloc((p),(s),__FUNCTION__,__LINE__);FLUSH(); 00096 #define FREE(p) dbg_free((p),__FUNCTION__,__LINE__);FLUSH(); 00097 #else 00098 #define MALLOC(s) malloc(s) 00099 #define REALLOC(p,s) realloc(p,s) 00100 #define FREE(p) free(p) 00101 #endif 00102 00103 void dbg_open(PinName led = NC, PinName tx = USBTX, PinName rx = USBRX); 00104 void dbg_close( void ); 00105 00106 void dbg_set_led(PinName led = NC, PinName dummy1 = NC, PinName dummy2 = NC); 00107 00108 /** 00109 Asserts and trap processor. 00110 00111 @param bool Assert condition 00112 @param const char* Assert message format 00113 @param ... Assert message parameters 00114 @return void 00115 */ 00116 void dbg_assert(bool test, const char* format, ...); 00117 00118 /** 00119 Prints a message to the debug port. 00120 00121 @param const char* Message format 00122 @param ... Message parameters 00123 @return void 00124 */ 00125 void dbg_print(const char* format, ...); 00126 00127 /** 00128 Flushes the pending debug messages. 00129 00130 @param void 00131 @return void 00132 */ 00133 void dbg_flush( void ); 00134 00135 /** 00136 Prints malloc parameters. 00137 00138 @param size_t Size to allocate 00139 @param const char* Current function name 00140 @param uint32_t Current file line 00141 @return void* Pointer to allocated memory 00142 */ 00143 void* dbg_malloc(size_t size, const char* f, uint32_t l); 00144 00145 /** 00146 Prints realloc parameters. 00147 00148 @param void* Pointer to reallocate 00149 @param size_t New size to allocate 00150 @param const char* Current function name 00151 @param uint32_t Current file line 00152 @return void* Pointer to allocated memory 00153 */ 00154 void* dbg_realloc(void* p, size_t size, const char* f, uint32_t l); 00155 00156 /** 00157 Prints free parameters. 00158 00159 @param void* Pointer to memory to free 00160 @param const char* Current function name 00161 @param uint32_t Current file line 00162 @return void 00163 */ 00164 void dbg_free(void* p, const char* f, uint32_t l); 00165 00166 void dbg_print_data(const char* before, const char* format, uint8_t* data, uint8_t length, const char* after); 00167 00168 void dbg_set_rx_callback(void (*rx_isr)(char c)); 00169 00170 #endif // DBG_H
Generated on Sat Jul 16 2022 17:03:31 by 1.7.2