1 #ifndef __BESBLE_DEBUG_H 2 #define __BESBLE_DEBUG_H 3 4 #include "hal_uart.h" 5 6 const char *DebugMask2Prefix(uint8_t mask); 7 8 #define DEBUG_PREFIX_FORMAT "%s<%s> " 9 #define DEBUG_SUFFIX_FORMAT "\n" 10 11 #define LOG_HCI_TAG "[BLE HCI]: " 12 #define LOG_L2C_TAG "[BLE L2C]: " 13 #define LOG_ATT_TAG "[BLE ATT]: " 14 #define LOG_GATT_TAG "[BLE GATT]: " 15 #define LOG_SMP_TAG "[BLE SMP]: " 16 17 #define LOG_GAP_TAG "[BLE GAP]: " 18 #define LOG_APP_TAG "[BLE APP]: " 19 #define LOG_BLE_TAG "[BLE]: " 20 #define LOG_HTP_TAG "[BLE HTP]: " 21 22 #define GAP_ERROR 1 23 #define GAP_OUT 2 24 #define GATT_ERROR 3 25 #define GATT_OUT 4 26 #define ATT_ERROR 5 27 #define ATT_OUT 6 28 #define L2C_ERROR 7 29 #define L2C_OUT 8 30 #define HCI_ERROR 9 31 #define HCI_OUT 10 32 #define SMP_ERROR 11 33 #define SMP_OUT 12 34 #define APP_ERROR 13 35 #define APP_OUT 14 36 /* Profile macro start */ 37 #define PRF_HT_ERROR 15 38 #define PRF_HT_OUT 16 39 /* Profile macro end */ 40 #define BLE_ERROR 30 41 #define BLE_OUT 31 42 43 44 #define DebugOut(mask, str,...) do \ 45 { \ 46 const char *prefix = NULL; \ 47 prefix = DebugMask2Prefix(mask); \ 48 TRACE(DEBUG_PREFIX_FORMAT, prefix, __FUNCTION__); \ 49 TRACE (str, ##__VA_ARGS__); \ 50 } \ 51 while (0) 52 53 #if 0 54 #define DEBUG_HCI_DBG 1 55 #define DEBUG_GAP_DBG 0 56 #define DEBUG_GATT_DBG 0 57 #define DEBUG_ATT_DBG 0 58 #define DEBUG_L2C_DBG 0 59 #define DEBUG_SMP_DBG 0 60 #define DEBUG_APP_DBG 0 61 #define DEBUG_PRF_DBG 0 62 #define DEBUG_BLE_DBG 0 63 64 #else 65 /* ble debug macro switch */ 66 #define DEBUG_HCI_DBG 0 67 #define DEBUG_GAP_DBG 0 68 #define DEBUG_GATT_DBG 0 69 #define DEBUG_ATT_DBG 0 70 #define DEBUG_L2C_DBG 0 71 #define DEBUG_SMP_DBG 0 72 #define DEBUG_APP_DBG 0 73 #define DEBUG_PRF_DBG 0 74 #define DEBUG_BLE_DBG 0 75 #endif 76 77 #if DEBUG_HCI_DBG 78 #define BLE_HCI_DBG(str,...) DebugOut(HCI_OUT, str, ##__VA_ARGS__) 79 #define BLE_HCI_ERR(str,...) DebugOut(HCI_ERROR, str, ##__VA_ARGS__) 80 #define BLE_HCI_FUNC_ENTER() TRACE(LOG_BLE_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 81 #define BLE_HCI_FUNC_LEAVE() TRACE(LOG_BLE_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 82 #else 83 #define BLE_HCI_DBG(str,...) 84 #define BLE_HCI_ERR(str,...) DebugOut(HCI_ERROR, str, ##__VA_ARGS__) 85 #define BLE_HCI_FUNC_ENTER() 86 #define BLE_HCI_FUNC_LEAVE() 87 #endif 88 89 #if DEBUG_GAP_DBG 90 #define BLE_GAP_DBG(str,...) DebugOut(GAP_OUT, str, ##__VA_ARGS__) 91 #define BLE_GAP_ERR(str,...) DebugOut(GAP_ERROR, str, ##__VA_ARGS__) 92 #define BLE_GAP_FUNC_ENTER() TRACE(LOG_GAP_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 93 #define BLE_GAP_FUNC_LEAVE() TRACE(LOG_GAP_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 94 #else 95 #define BLE_GAP_DBG(str,...) 96 #define BLE_GAP_ERR(str,...) DebugOut(GAP_ERROR, str, ##__VA_ARGS__) 97 #define BLE_GAP_FUNC_ENTER() 98 #define BLE_GAP_FUNC_LEAVE() 99 #endif 100 101 #if DEBUG_GATT_DBG 102 #define BLE_GATT_DBG(str,...) DebugOut(GATT_OUT, str, ##__VA_ARGS__) 103 #define BLE_GATT_ERR(str,...) DebugOut(GATT_ERROR, str, ##__VA_ARGS__) 104 #define BLE_GATT_FUNC_ENTER() TRACE(LOG_GATT_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 105 #define BLE_GATT_FUNC_LEAVE() TRACE(LOG_GATT_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 106 #else 107 #define BLE_GATT_DBG(str,...) 108 #define BLE_GATT_ERR(str,...) DebugOut(GATT_ERROR, str, ##__VA_ARGS__) 109 #define BLE_GATT_FUNC_ENTER() 110 #define BLE_GATT_FUNC_LEAVE() 111 #endif 112 113 #if DEBUG_ATT_DBG 114 #define BLE_ATT_DBG(str,...) DebugOut(ATT_OUT, str, ##__VA_ARGS__) 115 #define BLE_ATT_ERR(str,...) DebugOut(ATT_ERROR, str, ##__VA_ARGS__) 116 #define BLE_ATT_FUNC_ENTER() TRACE(LOG_ATT_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 117 #define BLE_ATT_FUNC_LEAVE() TRACE(LOG_ATT_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 118 #else 119 #define BLE_ATT_DBG(str,...) 120 #define BLE_ATT_ERR(str,...) DebugOut(ATT_ERROR, str, ##__VA_ARGS__) 121 #define BLE_ATT_FUNC_ENTER() 122 #define BLE_ATT_FUNC_LEAVE() 123 #endif 124 125 #if DEBUG_L2C_DBG 126 #define BLE_L2C_DBG(str,...) DebugOut(L2C_OUT, str, ##__VA_ARGS__) 127 #define BLE_L2C_ERR(str,...) DebugOut(L2C_ERROR, str, ##__VA_ARGS__) 128 #define BLE_L2C_FUNC_ENTER() TRACE(LOG_L2C_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 129 #define BLE_L2C_FUNC_LEAVE() TRACE(LOG_L2C_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 130 #else 131 #define BLE_L2C_DBG(str,...) 132 #define BLE_L2C_ERR(str,...) DebugOut(L2C_ERROR, str, ##__VA_ARGS__) 133 #define BLE_L2C_FUNC_ENTER() 134 #define BLE_L2C_FUNC_LEAVE() 135 #endif 136 137 #if DEBUG_L2C_DBG 138 #define BLE_SMP_DBG(str,...) DebugOut(SMP_OUT, str, ##__VA_ARGS__) 139 #define BLE_SMP_ERR(str,...) DebugOut(SMP_ERROR, str, ##__VA_ARGS__) 140 #define BLE_SMP_FUNC_ENTER() TRACE(LOG_SMP_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 141 #define BLE_SMP_FUNC_LEAVE() TRACE(LOG_SMP_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 142 #else 143 #define BLE_SMP_DBG(str,...) 144 #define BLE_SMP_ERR(str,...) DebugOut(SMP_ERROR, str, ##__VA_ARGS__) 145 #define BLE_SMP_FUNC_ENTER() 146 #define BLE_SMP_FUNC_LEAVE() 147 #endif 148 149 #if DEBUG_APP_DBG 150 #define BLE_APP_DBG(str,...) DebugOut(APP_OUT, str, ##__VA_ARGS__) 151 #define BLE_APP_ERR(str,...) DebugOut(APP_ERROR, str, ##__VA_ARGS__) 152 #define BLE_APP_FUNC_ENTER() TRACE(LOG_APP_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 153 #define BLE_APP_FUNC_LEAVE() TRACE(LOG_APP_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 154 #else 155 #define BLE_APP_DBG(str,...) 156 #define BLE_APP_ERR(str,...) DebugOut(APP_ERROR, str, ##__VA_ARGS__) 157 #define BLE_APP_FUNC_ENTER() 158 #define BLE_APP_FUNC_LEAVE() 159 #endif 160 161 #if DEBUG_PRF_DBG 162 #define BLE_PRF_HP_DBG(str,...) DebugOut(PRF_HT_OUT, str, ##__VA_ARGS__) 163 #define BLE_PRF_HP_ERR(str,...) DebugOut(PRF_HT_ERROR, str, ##__VA_ARGS__) 164 #define BLE_PRF_HP_FUNC_ENTER() TRACE(LOG_HTP_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 165 #define BLE_PRF_HP_FUNC_LEAVE() TRACE(LOG_HTP_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 166 #else 167 #define BLE_PRF_HP_DBG(str,...) 168 #define BLE_PRF_HP_ERR(str,...) DebugOut(PRF_HT_ERROR, str, ##__VA_ARGS__) 169 #define BLE_PRF_HP_FUNC_ENTER() 170 #define BLE_PRF_HP_FUNC_LEAVE() 171 #endif 172 173 #if DEBUG_BLE_DBG 174 #define BLE_DBG(str,...) DebugOut(BLE_OUT, str, ##__VA_ARGS__) 175 #define BLE_ERR(str,...) DebugOut(BLE_ERROR, str, ##__VA_ARGS__) 176 #define BLE_FUNC_ENTER() TRACE(LOG_BLE_TAG"%s line: %d +++\n", __FUNCTION__, __LINE__) 177 #define BLE_FUNC_LEAVE() TRACE(LOG_BLE_TAG"%s line: %d ---\n", __FUNCTION__, __LINE__) 178 #define BLE_DUMP8(x,y,z) DUMP8(x,y,z) 179 180 #else 181 #define BLE_DBG(str,...) 182 #define BLE_ERR(str,...) DebugOut(BLE_ERROR, str, ##__VA_ARGS__) 183 #define BLE_FUNC_ENTER() 184 #define BLE_FUNC_LEAVE() 185 #define BLE_DUMP8(x,y,z) 186 187 #endif 188 189 190 191 #endif 192