esp_ieee802154_debug.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdio.h>
  7. #include "hal/ieee802154_ll.h"
  8. #include "esp_ieee802154_util.h"
  9. #include "esp_log.h"
  10. #if CONFIG_IEEE802154_DEBUG
  11. ieee802154_probe_info_t g_ieee802154_probe;
  12. #define TAG "ieee802154_debug"
  13. #if CONFIG_IEEE802154_RECORD_EVENT
  14. static char *ieee802154_get_event_string(ieee802154_ll_event_t events)
  15. {
  16. char *event_string = "";
  17. switch (events) {
  18. case IEEE802154_EVENT_TX_DONE:
  19. event_string = "TX_DONE";
  20. break;
  21. case IEEE802154_EVENT_RX_DONE:
  22. event_string = "RX_DONE";
  23. break;
  24. case IEEE802154_EVENT_ACK_TX_DONE:
  25. event_string = "ACK_TX_DONE";
  26. break;
  27. case IEEE802154_EVENT_ACK_RX_DONE:
  28. event_string = "ACK_RX_DONE";
  29. break;
  30. case IEEE802154_EVENT_RX_ABORT:
  31. event_string = "RX_ABORT";
  32. break;
  33. case IEEE802154_EVENT_TX_ABORT:
  34. event_string = "TX_ABORT";
  35. break;
  36. case IEEE802154_EVENT_ED_DONE:
  37. event_string = "ED_DONE";
  38. break;
  39. case IEEE802154_EVENT_TIMER0_OVERFLOW:
  40. event_string = "TIMER0_OVERFLOW";
  41. break;
  42. case IEEE802154_EVENT_TIMER1_OVERFLOW:
  43. event_string = "TIMER1_OVERFLOW";
  44. break;
  45. case IEEE802154_EVENT_CLOCK_COUNT_MATCH:
  46. event_string = "CLOCK_COUNT_MATCH";
  47. break;
  48. case IEEE802154_EVENT_TX_SFD_DONE:
  49. event_string = "TX_SFD_DONE";
  50. break;
  51. case IEEE802154_EVENT_RX_SFD_DONE:
  52. event_string = "RX_SFD_DONE";
  53. break;
  54. default:
  55. event_string = "Multi events";
  56. break;
  57. }
  58. return event_string;
  59. }
  60. #endif // CONFIG_IEEE802154_RECORD_EVENT
  61. #if CONFIG_IEEE802154_RECORD_STATE || CONFIG_IEEE802154_RECORD_EVENT
  62. static char *ieee802154_state_string[] = {
  63. "DISABLE",
  64. "IDLE",
  65. "SLEEP",
  66. "RX",
  67. "TX_ACK",
  68. "TX_ENH_ACK",
  69. "TX_CCA",
  70. "TX",
  71. "DTM_TX",
  72. "RX_ACK",
  73. "ED",
  74. "CCA",
  75. };
  76. #endif // CONFIG_IEEE802154_RECORD_STATE
  77. #if CONFIG_IEEE802154_RECORD_CMD
  78. static char *ieee802154_get_cmd_string(ieee802154_ll_cmd_t cmd)
  79. {
  80. char *cmd_string = "";
  81. switch (cmd) {
  82. case IEEE802154_CMD_TX_START:
  83. cmd_string = "tx";
  84. break;
  85. case IEEE802154_CMD_RX_START:
  86. cmd_string = "rx";
  87. break;
  88. case IEEE802154_CMD_CCA_TX_START:
  89. cmd_string = "tx cca";
  90. break;
  91. case IEEE802154_CMD_ED_START:
  92. cmd_string = "ed";
  93. break;
  94. case IEEE802154_CMD_STOP:
  95. cmd_string = "stop";
  96. break;
  97. case IEEE802154_CMD_TEST_TX_START:
  98. cmd_string = "test tx";
  99. break;
  100. case IEEE802154_CMD_TEST_RX_START:
  101. cmd_string = "test rx";
  102. break;
  103. case IEEE802154_CMD_TEST_STOP:
  104. cmd_string = "test stop";
  105. break;
  106. case IEEE802154_CMD_TIMER0_START:
  107. cmd_string = "timer0 start";
  108. break;
  109. case IEEE802154_CMD_TIMER0_STOP:
  110. cmd_string = "timer0 stop";
  111. break;
  112. case IEEE802154_CMD_TIMER1_START:
  113. cmd_string = "timer1 start";
  114. break;
  115. case IEEE802154_CMD_TIMER1_STOP:
  116. cmd_string = "timer1 stop";
  117. break;
  118. }
  119. return cmd_string;
  120. }
  121. #endif // CONFIG_IEEE802154_RECORD_CMD
  122. #if CONFIG_IEEE802154_RECORD_EVENT || CONFIG_IEEE802154_RECORD_ABORT
  123. static char *ieee80154_rx_abort_reason_string[] = {
  124. "RSVD", // = 0,
  125. "RX_STOP", // = 1,
  126. "SFD_TIMEOUT", // = 2,
  127. "CRC_ERROR ", // = 3,
  128. "INVALID_LEN", // = 4,
  129. "FILTER_FAIL", // = 5,
  130. "NO_RSS ", // = 6,
  131. "COEX_BREAK ", // = 7,
  132. "UNEXPECTED_ACK", // = 8,
  133. "RX_RESTART", // = 9,
  134. "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", // = 10~15,
  135. "TX_ACK_TIMEOUT", // = 16,
  136. "TX_ACK_STOP", // = 17,
  137. "TX_ACK_COEX_BREAK", // = 18,
  138. "ENHACK_SECURITY_ERROR", // = 19,
  139. "RSVD", "RSVD", "RSVD", "RSVD", // = 20~23
  140. "ED_ABORT", // = 24,
  141. "ED_STOP", // = 25,
  142. "ED_COEX_REJECT", // = 26,
  143. };
  144. static char *ieee80154_tx_abort_reason_string[] = {
  145. "RSVD", // = 0,
  146. "RX_ACK_STOP", // = 1,
  147. "RX_ACK_SFD_TIMEOUT", // = 2,
  148. "RX_ACK_CRC_ERROR", // = 3,
  149. "RX_ACK_INVALID_LEN", // = 4,
  150. "RX_ACK_FILTER_FAIL", // = 5,
  151. "RX_ACK_NO_RSS", // = 6,
  152. "RX_ACK_COEX_BREAK", // = 7,
  153. "RX_ACK_TYPE_NOT_ACK", // = 8,
  154. "RX_ACK_RESTART", // = 9,
  155. "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", // = 10~15,
  156. "RX_ACK_TIMEOUT", // = 16,
  157. "TX_STOP", // = 17,
  158. "TX_COEX_BREAK", // = 18,
  159. "TX_SECURITY_ERROR", // = 19,
  160. "RSVD", "RSVD", "RSVD", "RSVD", // = 20~23
  161. "CCA_FAILED", // = 24,
  162. "CCA_BUSY", // = 25,
  163. };
  164. #endif // CONFIG_IEEE802154_RECORD_EVENT
  165. #if CONFIG_IEEE802154_ASSERT
  166. void ieee802154_assert_print(void)
  167. {
  168. #if CONFIG_IEEE802154_RECORD_EVENT
  169. ESP_EARLY_LOGW(TAG, "Print the record event, current event index: %d", g_ieee802154_probe.event_index);
  170. for (uint8_t i = 0; i < IEEE802154_ASSERT_RECORD_EVENT_SIZE; i++) {
  171. char event_log[200] = { 0 };
  172. char abort_log[100] = { 0 };
  173. snprintf(event_log, 200,"index %2d: event: 0x%4x, %15s, state:%10s, timestamp: %lld", i, g_ieee802154_probe.event[i].event,
  174. ieee802154_get_event_string(g_ieee802154_probe.event[i].event),
  175. ieee802154_state_string[g_ieee802154_probe.event[i].state],
  176. g_ieee802154_probe.event[i].timestamp);
  177. if (g_ieee802154_probe.event[i].event == IEEE802154_EVENT_RX_ABORT) {
  178. snprintf(abort_log, 100, "rx abort reason: %4x, %20s", g_ieee802154_probe.event[i].abort_reason.rx,
  179. ieee80154_rx_abort_reason_string[g_ieee802154_probe.event[i].abort_reason.rx]);
  180. } else if (g_ieee802154_probe.event[i].event == IEEE802154_EVENT_TX_ABORT) {
  181. snprintf(abort_log, 100, "tx abort reason: %4x, %20s", g_ieee802154_probe.event[i].abort_reason.tx,
  182. ieee80154_tx_abort_reason_string[g_ieee802154_probe.event[i].abort_reason.tx]);
  183. }
  184. ESP_EARLY_LOGW(TAG, "%s %s", event_log, abort_log);
  185. }
  186. ESP_EARLY_LOGW(TAG,"Print the record event done.\n");
  187. #endif // CONFIG_IEEE802154_RECORD_EVENT
  188. #if CONFIG_IEEE802154_RECORD_STATE
  189. ESP_EARLY_LOGW(TAG, "Print the record state, current state index: %d", g_ieee802154_probe.state_index);
  190. for (uint8_t i = 0; i < IEEE802154_ASSERT_RECORD_STATE_SIZE; i++) {
  191. ESP_EARLY_LOGW(TAG, "index %2d: line:%5s, state:%10s, timestamp: %lld",
  192. i, g_ieee802154_probe.state[i].line_str,
  193. ieee802154_state_string[g_ieee802154_probe.state[i].state],
  194. g_ieee802154_probe.state[i].timestamp);
  195. }
  196. ESP_EARLY_LOGW(TAG,"Print the record state done.\n");
  197. #endif // CONFIG_IEEE802154_RECORD_STATE
  198. #if CONFIG_IEEE802154_RECORD_CMD
  199. ESP_EARLY_LOGW(TAG, "Print the record cmd, current cmd index: %d", g_ieee802154_probe.cmd_index);
  200. for (uint8_t i = 0; i < IEEE802154_ASSERT_RECORD_CMD_SIZE; i++) {
  201. ESP_EARLY_LOGW(TAG, "index %2d: line:%5s, cmd:%10s, timestamp: %lld",
  202. i, g_ieee802154_probe.cmd[i].line_str,
  203. ieee802154_get_cmd_string(g_ieee802154_probe.cmd[i].cmd),
  204. g_ieee802154_probe.cmd[i].timestamp);
  205. }
  206. ESP_EARLY_LOGW(TAG,"Print the record cmd done.\n");
  207. #endif // CONFIG_IEEE802154_RECORD_CMD
  208. #if CONFIG_IEEE802154_RECORD_ABORT
  209. ESP_EARLY_LOGW(TAG, "Print the record abort, current abort index: %d", g_ieee802154_probe.abort_index);
  210. for (uint8_t i = 0; i < IEEE802154_ASSERT_RECORD_ABORT_SIZE; i++) {
  211. if (g_ieee802154_probe.abort[i].is_tx_abort) {
  212. ESP_EARLY_LOGW(TAG, "index %2d: tx abort: %4x, %15s, timestamp: %lld",
  213. i, g_ieee802154_probe.abort[i].abort_reason.tx,
  214. ieee80154_tx_abort_reason_string[g_ieee802154_probe.abort[i].abort_reason.tx],
  215. g_ieee802154_probe.abort[i].timestamp);
  216. } else {
  217. ESP_EARLY_LOGW(TAG, "index %2d: rx abort: %4x, %15s, timestamp: %lld",
  218. i, g_ieee802154_probe.abort[i].abort_reason.rx,
  219. ieee80154_rx_abort_reason_string[g_ieee802154_probe.abort[i].abort_reason.rx],
  220. g_ieee802154_probe.abort[i].timestamp);
  221. }
  222. }
  223. ESP_EARLY_LOGW(TAG,"Print the record abort done.\n");
  224. #endif // CONFIG_IEEE802154_RECORD_ABORT
  225. }
  226. #endif // CONFIG_IEEE802154_ASSERT
  227. #endif // CONFIG_IEEE802154_DEBUG