From 9039ffeb622876790cfa3cdf5da2f62d50ce5a2d Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Thu, 14 Nov 2024 10:35:29 +0800 Subject: [PATCH 1/4] feat(802.15.4): IEEE802.15.4 add rx buffer statistic --- components/ieee802154/Kconfig | 30 ++- .../ieee802154/driver/esp_ieee802154_debug.c | 49 ++++- .../ieee802154/driver/esp_ieee802154_dev.c | 7 +- components/ieee802154/esp_ieee802154.c | 21 ++- .../ieee802154/include/esp_ieee802154.h | 23 +++ .../private_include/esp_ieee802154_util.h | 41 ++++- .../cmd_ieee802154/ieee802154_cmd.c | 2 +- .../cmd_ieee802154_stats/CMakeLists.txt | 3 + .../cmd_ieee802154_stats/ieee802154_stats.c | 174 ++++++++++++++++++ .../cmd_ieee802154_stats/ieee802154_stats.h | 11 ++ .../ieee802154_cli/main/CMakeLists.txt | 3 +- .../ieee802154_cli/main/esp_ieee802154_cli.c | 4 + 12 files changed, 350 insertions(+), 18 deletions(-) create mode 100644 examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/CMakeLists.txt create mode 100644 examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c create mode 100644 examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.h diff --git a/components/ieee802154/Kconfig b/components/ieee802154/Kconfig index 9c5d18e237..9fb39d37dd 100644 --- a/components/ieee802154/Kconfig +++ b/components/ieee802154/Kconfig @@ -97,17 +97,31 @@ menu "IEEE 802.15.4" Enabling this option allows different kinds of IEEE802154 debug output. All IEEE802154 debug features increase the size of the final binary. - config IEEE802154_ASSERT - bool "Enrich the assert information with IEEE802154 state and event" + config IEEE802154_RX_BUFFER_STATISTIC + bool "Rx buffer statistic" depends on IEEE802154_DEBUG default n help - Enabling this option to add some probe codes in the driver, and these informations - will be printed when assert. + Enabling this option to count IEEE802154 rx buffer when allocating or freeing. + + config IEEE802154_ASSERT + bool "Enrich the assert information" + depends on IEEE802154_DEBUG + select IEEE802154_RECORD + default n + help + Enabling this option to print more information when assert. + + config IEEE802154_RECORD + bool "Record the information with IEEE802154 state and event" + depends on IEEE802154_DEBUG + default n + help + Enabling this option to add some probe codes in the driver, and record these information. config IEEE802154_RECORD_EVENT bool "Enable record event information for debugging" - depends on IEEE802154_DEBUG + depends on IEEE802154_RECORD default n help Enabling this option to record event, when assert, the recorded event will be printed. @@ -122,7 +136,7 @@ menu "IEEE 802.15.4" config IEEE802154_RECORD_STATE bool "Enable record state information for debugging" - depends on IEEE802154_DEBUG + depends on IEEE802154_RECORD default n help Enabling this option to record state, when assert, the recorded state will be printed. @@ -137,7 +151,7 @@ menu "IEEE 802.15.4" config IEEE802154_RECORD_CMD bool "Enable record command information for debugging" - depends on IEEE802154_DEBUG + depends on IEEE802154_RECORD default n help Enabling this option to record the command, when assert, the recorded @@ -153,7 +167,7 @@ menu "IEEE 802.15.4" config IEEE802154_RECORD_ABORT bool "Enable record abort information for debugging" - depends on IEEE802154_DEBUG + depends on IEEE802154_RECORD default n help Enabling this option to record the abort, when assert, the recorded diff --git a/components/ieee802154/driver/esp_ieee802154_debug.c b/components/ieee802154/driver/esp_ieee802154_debug.c index 0dbfd4bc59..7dec983213 100644 --- a/components/ieee802154/driver/esp_ieee802154_debug.c +++ b/components/ieee802154/driver/esp_ieee802154_debug.c @@ -171,8 +171,8 @@ static char *ieee80154_tx_abort_reason_string[] = { #endif // CONFIG_IEEE802154_RECORD_EVENT -#if CONFIG_IEEE802154_ASSERT -void ieee802154_assert_print(void) +#if CONFIG_IEEE802154_RECORD +void ieee802154_record_print(void) { #if CONFIG_IEEE802154_RECORD_EVENT ESP_EARLY_LOGW(IEEE802154_TAG, "Print the record event, current event index: %d", g_ieee802154_probe.event_index); @@ -235,7 +235,7 @@ void ieee802154_assert_print(void) ESP_EARLY_LOGW(IEEE802154_TAG,"Print the record abort done."); #endif // CONFIG_IEEE802154_RECORD_ABORT } -#endif // CONFIG_IEEE802154_ASSERT +#endif // CONFIG_IEEE802154_RECORD #if CONFIG_IEEE802154_TXRX_STATISTIC static ieee802154_txrx_statistic_t s_ieee802154_txrx_statistic; @@ -370,4 +370,47 @@ void ieee802154_txrx_statistic_print(void) #endif // CONFIG_IEEE802154_TXRX_STATISTIC +#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC +#define IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL 10 +#define IEEE802154_RX_BUFFER_GET_USED_LEVEL(a) (((a) * IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL) / (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1)) +static uint16_t s_rx_buffer_used_nums = 0; +static uint64_t s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1]; +void ieee802154_rx_buffer_statistic_is_free(bool is_free) +{ + if (is_free) { + s_rx_buffer_used_nums--; + } else { + s_rx_buffer_used_nums++; + // (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1) means buffer full. + if (s_rx_buffer_used_nums > (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1)) { + s_rx_buffer_used_nums = CONFIG_IEEE802154_RX_BUFFER_SIZE + 1; + } + s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_GET_USED_LEVEL(s_rx_buffer_used_nums)]++; + } +} + +void ieee802154_rx_buffer_statistic_clear(void) +{ + memset((void*)s_rx_buffer_used_water_level, 0, sizeof(uint64_t)*(IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1)); +} + +void ieee802154_rx_buffer_statistic_printf(void) +{ + uint64_t total_times = 0; + for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1); i++) { + total_times += s_rx_buffer_used_water_level[i]; + } + ESP_LOGW(IEEE802154_TAG, "+--------------------+-------------------------+-------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-25s|%-25u|", "rx buff total size:", "", CONFIG_IEEE802154_RX_BUFFER_SIZE); + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-25s|%-25llu|", "buffer alloc times:", "", total_times); + ESP_LOGW(IEEE802154_TAG, "+--------------------+-------------------------+-------------------------+"); + for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL); i++) { + ESP_LOGW(IEEE802154_TAG, "|%-20s|%4d%%%5s%4d%%%-10s|%-15llu%9.2f%%|", "", ((i) * 100 / IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL), "~", ((i + 1) * 100 / IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL), " used:", s_rx_buffer_used_water_level[i], ((float)s_rx_buffer_used_water_level[i] / (float)total_times)*100); + } + ESP_LOGW(IEEE802154_TAG, "|%-20s|%-25s|%-15llu%9.2f%%|", "", "full used:", s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL], ((float)s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL] / (float)total_times)*100); + ESP_LOGW(IEEE802154_TAG, "+--------------------+-------------------------+-------------------------+"); +} + +#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC + #endif // CONFIG_IEEE802154_DEBUG diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index 6ce02905bc..9df0a3a95c 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -87,7 +87,10 @@ static pending_tx_t s_pending_tx = { 0 }; static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *frame_info) { // If the RX done packet is written in the stub buffer, drop it silently. - if (s_rx_index != CONFIG_IEEE802154_RX_BUFFER_SIZE) { + IEEE802154_RX_BUFFER_STAT_IS_FREE(false); + if (s_rx_index == CONFIG_IEEE802154_RX_BUFFER_SIZE) { + esp_rom_printf("receive buffer full, drop the current frame.\n"); + } else { // Otherwise, post it to the upper layer. // Ignore bit8 for the frame length, due to the max frame length is 127 based 802.15.4 spec. data[0] = data[0] & 0x7f; @@ -99,6 +102,7 @@ static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t * static void ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info) { if (ack && ack_frame_info) { + IEEE802154_RX_BUFFER_STAT_IS_FREE(false); if (s_rx_index == CONFIG_IEEE802154_RX_BUFFER_SIZE) { esp_ieee802154_transmit_failed(frame, ESP_IEEE802154_TX_ERR_NO_ACK); } else { @@ -118,6 +122,7 @@ esp_err_t ieee802154_receive_handle_done(const uint8_t *data) return ESP_FAIL; } s_rx_frame_info[size / IEEE802154_RX_FRAME_SIZE].process = false; + IEEE802154_RX_BUFFER_STAT_IS_FREE(true); return ESP_OK; } diff --git a/components/ieee802154/esp_ieee802154.c b/components/ieee802154/esp_ieee802154.c index 796b161a7b..2d021891a1 100644 --- a/components/ieee802154/esp_ieee802154.c +++ b/components/ieee802154/esp_ieee802154.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -414,3 +414,22 @@ void esp_ieee802154_txrx_statistic_print(void) ieee802154_txrx_statistic_print(); } #endif // CONFIG_IEEE802154_TXRX_STATISTIC + +#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC +void esp_ieee802154_rx_buffer_statistic_clear(void) +{ + ieee802154_rx_buffer_statistic_clear(); +} + +void esp_ieee802154_rx_buffer_statistic_printf(void) +{ + ieee802154_rx_buffer_statistic_printf(); +} +#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC + +#if CONFIG_IEEE802154_RECORD +void esp_ieee802154_record_print(void) +{ + ieee802154_record_print(); +} +#endif // CONFIG_IEEE802154_RECORD diff --git a/components/ieee802154/include/esp_ieee802154.h b/components/ieee802154/include/esp_ieee802154.h index 51adf6ce00..90ffb2b41a 100644 --- a/components/ieee802154/include/esp_ieee802154.h +++ b/components/ieee802154/include/esp_ieee802154.h @@ -623,6 +623,29 @@ void esp_ieee802154_txrx_statistic_clear(void); void esp_ieee802154_txrx_statistic_print(void); #endif // CONFIG_IEEE802154_TXRX_STATISTIC +#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC + +/** + * @brief Print the current IEEE802.15.4 rx buffer statistic. + * + */ +void esp_ieee802154_rx_buffer_statistic_clear(void); + +/** + * @brief Clear the current IEEE802.15.4 rx buffer statistic. + * + */ +void esp_ieee802154_rx_buffer_statistic_printf(void); +#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC + +#if CONFIG_IEEE802154_RECORD + +/** + * @brief Print the current IEEE802.15.4 event/command/state record. + * + */ +void esp_ieee802154_record_print(void); +#endif // CONFIG_IEEE802154_RECORD #ifdef __cplusplus } #endif diff --git a/components/ieee802154/private_include/esp_ieee802154_util.h b/components/ieee802154/private_include/esp_ieee802154_util.h index c1e843055a..843e34117c 100644 --- a/components/ieee802154/private_include/esp_ieee802154_util.h +++ b/components/ieee802154/private_include/esp_ieee802154_util.h @@ -168,19 +168,27 @@ typedef struct { extern ieee802154_probe_info_t g_ieee802154_probe; -#if CONFIG_IEEE802154_ASSERT +#if CONFIG_IEEE802154_RECORD /** * @brief This function print rich information, which is useful for debug. * Only can be used when `IEEE802154_ASSERT` is enabled. * */ -void ieee802154_assert_print(void); +void ieee802154_record_print(void); +#endif + +#if CONFIG_IEEE802154_ASSERT + +#if CONFIG_IEEE802154_RECORD #define IEEE802154_ASSERT(a) do { \ if(unlikely(!(a))) { \ - ieee802154_assert_print(); \ + ieee802154_record_print(); \ assert(a); \ } \ } while (0) +#else +#error "CONFIG_IEEE802154_RECORD must be enabled when CONFIG_IEEE802154_ASSERT enabled" +#endif #else // CONFIG_IEEE802154_ASSERT #define IEEE802154_ASSERT(a) assert(a) #endif // CONFIG_IEEE802154_ASSERT @@ -249,6 +257,33 @@ void ieee802154_tx_break_coex_nums_update(void); #define IEEE802154_TX_BREAK_COEX_NUMS_UPDATE() #endif // CONFIG_IEEE802154_TXRX_STATISTIC +#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC + +/** + * @brief Count the rx buffer used. + * + * @param[in] is_free True for rx buffer frees and false for rx buffer allocates. + * + */ +void ieee802154_rx_buffer_statistic_is_free(bool is_free); + +/** + * @brief Clear the current IEEE802.15.4 rx buffer statistic. + * + */ +void ieee802154_rx_buffer_statistic_clear(void); + +/** + * @brief Print the current IEEE802.15.4 rx buffer statistic. + * + */ +void ieee802154_rx_buffer_statistic_printf(void); + +#define IEEE802154_RX_BUFFER_STAT_IS_FREE(a) ieee802154_rx_buffer_statistic_is_free(a) +#else +#define IEEE802154_RX_BUFFER_STAT_IS_FREE(a) +#endif + // TODO: replace etm code using common interface #define IEEE802154_ETM_CHANNEL0 0 diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c index 00d62cf73c..bef801beb4 100644 --- a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c +++ b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/CMakeLists.txt b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/CMakeLists.txt new file mode 100644 index 0000000000..c59fc3d2d7 --- /dev/null +++ b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "ieee802154_stats.c" + INCLUDE_DIRS "." + REQUIRES ieee802154 console esp_phy) diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c new file mode 100644 index 0000000000..dbda393bdc --- /dev/null +++ b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c @@ -0,0 +1,174 @@ +/* + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#include +#include +#include "esp_log.h" +#include "esp_ieee802154.h" +#include "esp_console.h" +#include "argtable3/argtable3.h" +#include "ieee802154_stats.h" + +#if CONFIG_IEEE802154_DEBUG +static const char* TAG = "i154cmd"; +#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC +static void register_rx_buffer_statistic(void); +#endif + +#if CONFIG_IEEE802154_TXRX_STATISTIC +static void register_txrx_statistic(void); +#endif + +#if CONFIG_IEEE802154_RECORD +static void register_record(void); +#endif + +void register_ieee802154_debug_cmd(void) +{ +#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC + register_rx_buffer_statistic(); +#endif +#if CONFIG_IEEE802154_TXRX_STATISTIC + register_txrx_statistic(); +#endif +#if CONFIG_IEEE802154_RECORD + register_record(); +#endif +} +#endif + +#if CONFIG_IEEE802154_DEBUG +#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC +static struct { + struct arg_lit *clear; + struct arg_lit *print; + struct arg_end *end; +} rx_buff_stat_args; + +static int process_rx_buffer_statistic(int argc, char **argv) +{ + int nerrors = arg_parse(argc, argv, (void **) &rx_buff_stat_args); + if (nerrors != 0) { + arg_print_errors(stderr, rx_buff_stat_args.end, argv[0]); + return 1; + } + if (rx_buff_stat_args.print->count) { + esp_ieee802154_rx_buffer_statistic_printf(); + } + if (rx_buff_stat_args.clear->count) { + esp_ieee802154_rx_buffer_statistic_clear(); + } + if (!rx_buff_stat_args.print->count && !rx_buff_stat_args.clear->count) { + ESP_LOGE(TAG, "no valid arguments"); + return 1; + } + return 0; +} + +static void register_rx_buffer_statistic(void) +{ + rx_buff_stat_args.print = + arg_lit0("p", "print", "print the result of rx buffer statistic"); + rx_buff_stat_args.clear = + arg_lit0("c", "clear", "clear the result of rx buffer statistic"); + rx_buff_stat_args.end = arg_end(2); + + const esp_console_cmd_t cmd = { + .command = "rxbufstat", + .help = "rx buffer statistic", + .hint = NULL, + .func = &process_rx_buffer_statistic, + .argtable = &rx_buff_stat_args + }; + ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); +} +#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC + +#if CONFIG_IEEE802154_TXRX_STATISTIC +static struct { + struct arg_lit *clear; + struct arg_lit *print; + struct arg_end *end; +} txrx_stat_args; + +static int process_txrx_statistic(int argc, char **argv) +{ + int nerrors = arg_parse(argc, argv, (void **) &txrx_stat_args); + if (nerrors != 0) { + arg_print_errors(stderr, txrx_stat_args.end, argv[0]); + return 1; + } + if (txrx_stat_args.print->count) { + esp_ieee802154_txrx_statistic_print(); + } + if (txrx_stat_args.clear->count) { + esp_ieee802154_txrx_statistic_clear(); + } + if (!txrx_stat_args.print->count && !txrx_stat_args.clear->count) { + ESP_LOGE(TAG, "no valid arguments"); + return 1; + } + return 0; +} + +static void register_txrx_statistic(void) +{ + txrx_stat_args.print = + arg_lit0("p", "print", "print the result of txrx statistic"); + txrx_stat_args.clear = + arg_lit0("c", "clear", "clear the result of txrx statistic"); + txrx_stat_args.end = arg_end(2); + + const esp_console_cmd_t cmd = { + .command = "txrxstat", + .help = "txrx statistic", + .hint = NULL, + .func = &process_txrx_statistic, + .argtable = &txrx_stat_args + }; + ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); +} +#endif // CONFIG_IEEE802154_TXRX_STATISTIC + +#if CONFIG_IEEE802154_RECORD +static struct { + struct arg_lit *print; + struct arg_end *end; +} record_args; + +static int process_record(int argc, char **argv) +{ + int nerrors = arg_parse(argc, argv, (void **) &record_args); + if (nerrors != 0) { + arg_print_errors(stderr, record_args.end, argv[0]); + return 1; + } + if (record_args.print->count) { + esp_ieee802154_record_print(); + } else { + ESP_LOGE(TAG, "no valid arguments"); + return 1; + } + return 0; +} + +static void register_record(void) +{ + record_args.print = + arg_lit0("p", "print", "print the result of the recording"); + record_args.end = arg_end(2); + + const esp_console_cmd_t cmd = { + .command = "record", + .help = "print the recorded IEEE802154 state/event/cmd etc.", + .hint = NULL, + .func = &process_record, + .argtable = &record_args + }; + ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); +} +#endif // CONFIG_IEEE802154_RECORD +#endif // CONFIG_IEEE802154_DEBUG diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.h b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.h new file mode 100644 index 0000000000..bb7157c140 --- /dev/null +++ b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.h @@ -0,0 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ + +#pragma once + +#if CONFIG_IEEE802154_DEBUG +void register_ieee802154_debug_cmd(void); +#endif diff --git a/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt b/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt index 1407c219b1..eb76f86a73 100644 --- a/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt +++ b/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt @@ -6,5 +6,6 @@ set(include "." # In order for the cases defined by `TEST_CASE` to be linked into the final elf, # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} - PRIV_REQUIRES ieee802154 console fatfs nvs_flash esp_phy cmd_ieee802154 cmd_system + PRIV_REQUIRES ieee802154 console fatfs nvs_flash esp_phy cmd_ieee802154 + cmd_ieee802154_stats cmd_system WHOLE_ARCHIVE) diff --git a/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c b/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c index 3ad3a546f6..64147755da 100644 --- a/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c +++ b/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c @@ -16,6 +16,7 @@ #include "esp_ieee802154.h" #include "esp_phy_init.h" #include "cmd_system.h" +#include "ieee802154_stats.h" #define PROMPT_STR "ieee802154" @@ -46,6 +47,9 @@ void app_main(void) esp_console_register_help_command(); register_ieee802154_cmd(); register_system_common(); +#if CONFIG_IEEE802154_DEBUG + register_ieee802154_debug_cmd(); +#endif esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl)); From cdcf2973f7c61bee0117a871dd4a403e4376f9ff Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Thu, 28 Nov 2024 20:09:07 +0800 Subject: [PATCH 2/4] feat(802.15.4): IEEE802.15.4 add some minor edits for readability --- components/ieee802154/driver/esp_ieee802154_debug.c | 3 ++- components/ieee802154/driver/esp_ieee802154_dev.c | 4 +--- components/ieee802154/esp_ieee802154.c | 4 ++-- components/ieee802154/include/esp_ieee802154.h | 2 +- components/ieee802154/private_include/esp_ieee802154_util.h | 4 ++-- .../ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c | 2 +- .../components/cmd_ieee802154_stats/ieee802154_stats.c | 2 +- 7 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/ieee802154/driver/esp_ieee802154_debug.c b/components/ieee802154/driver/esp_ieee802154_debug.c index 7dec983213..71847308b6 100644 --- a/components/ieee802154/driver/esp_ieee802154_debug.c +++ b/components/ieee802154/driver/esp_ieee802154_debug.c @@ -375,6 +375,7 @@ void ieee802154_txrx_statistic_print(void) #define IEEE802154_RX_BUFFER_GET_USED_LEVEL(a) (((a) * IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL) / (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1)) static uint16_t s_rx_buffer_used_nums = 0; static uint64_t s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1]; + void ieee802154_rx_buffer_statistic_is_free(bool is_free) { if (is_free) { @@ -394,7 +395,7 @@ void ieee802154_rx_buffer_statistic_clear(void) memset((void*)s_rx_buffer_used_water_level, 0, sizeof(uint64_t)*(IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1)); } -void ieee802154_rx_buffer_statistic_printf(void) +void ieee802154_rx_buffer_statistic_print(void) { uint64_t total_times = 0; for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1); i++) { diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index 9df0a3a95c..d4efd62779 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -88,9 +88,7 @@ static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t * { // If the RX done packet is written in the stub buffer, drop it silently. IEEE802154_RX_BUFFER_STAT_IS_FREE(false); - if (s_rx_index == CONFIG_IEEE802154_RX_BUFFER_SIZE) { - esp_rom_printf("receive buffer full, drop the current frame.\n"); - } else { + if (s_rx_index != CONFIG_IEEE802154_RX_BUFFER_SIZE) { // Otherwise, post it to the upper layer. // Ignore bit8 for the frame length, due to the max frame length is 127 based 802.15.4 spec. data[0] = data[0] & 0x7f; diff --git a/components/ieee802154/esp_ieee802154.c b/components/ieee802154/esp_ieee802154.c index 2d021891a1..0b77579c7f 100644 --- a/components/ieee802154/esp_ieee802154.c +++ b/components/ieee802154/esp_ieee802154.c @@ -421,9 +421,9 @@ void esp_ieee802154_rx_buffer_statistic_clear(void) ieee802154_rx_buffer_statistic_clear(); } -void esp_ieee802154_rx_buffer_statistic_printf(void) +void esp_ieee802154_rx_buffer_statistic_print(void) { - ieee802154_rx_buffer_statistic_printf(); + ieee802154_rx_buffer_statistic_print(); } #endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC diff --git a/components/ieee802154/include/esp_ieee802154.h b/components/ieee802154/include/esp_ieee802154.h index 90ffb2b41a..5ad7998d79 100644 --- a/components/ieee802154/include/esp_ieee802154.h +++ b/components/ieee802154/include/esp_ieee802154.h @@ -635,7 +635,7 @@ void esp_ieee802154_rx_buffer_statistic_clear(void); * @brief Clear the current IEEE802.15.4 rx buffer statistic. * */ -void esp_ieee802154_rx_buffer_statistic_printf(void); +void esp_ieee802154_rx_buffer_statistic_print(void); #endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC #if CONFIG_IEEE802154_RECORD diff --git a/components/ieee802154/private_include/esp_ieee802154_util.h b/components/ieee802154/private_include/esp_ieee802154_util.h index 843e34117c..f33fc5823c 100644 --- a/components/ieee802154/private_include/esp_ieee802154_util.h +++ b/components/ieee802154/private_include/esp_ieee802154_util.h @@ -277,12 +277,12 @@ void ieee802154_rx_buffer_statistic_clear(void); * @brief Print the current IEEE802.15.4 rx buffer statistic. * */ -void ieee802154_rx_buffer_statistic_printf(void); +void ieee802154_rx_buffer_statistic_print(void); #define IEEE802154_RX_BUFFER_STAT_IS_FREE(a) ieee802154_rx_buffer_statistic_is_free(a) #else #define IEEE802154_RX_BUFFER_STAT_IS_FREE(a) -#endif +#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC // TODO: replace etm code using common interface diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c index bef801beb4..00d62cf73c 100644 --- a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c +++ b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154/ieee802154_cmd.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c index dbda393bdc..2941be74d4 100644 --- a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c +++ b/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c @@ -56,7 +56,7 @@ static int process_rx_buffer_statistic(int argc, char **argv) return 1; } if (rx_buff_stat_args.print->count) { - esp_ieee802154_rx_buffer_statistic_printf(); + esp_ieee802154_rx_buffer_statistic_print(); } if (rx_buff_stat_args.clear->count) { esp_ieee802154_rx_buffer_statistic_clear(); From 7515df3ee2dc07bcada0b0aa6e163cb5f0e56392 Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Fri, 29 Nov 2024 15:54:53 +0800 Subject: [PATCH 3/4] feat(802.15.4): IEEE802.15.4 add documentation and refactor component structure --- .../ieee802154/driver/esp_ieee802154_debug.c | 14 ++-- .../cmd_ieee802154_debug}/CMakeLists.txt | 2 +- .../components/cmd_ieee802154_debug/README.md | 68 +++++++++++++++++++ .../cmd_ieee802154_debug/ieee802154_debug.c} | 9 +-- .../cmd_ieee802154_debug/ieee802154_debug.h} | 0 .../ieee802154_cli/main/CMakeLists.txt | 2 +- .../ieee802154_cli/main/esp_ieee802154_cli.c | 2 +- .../ieee802154_cli/main/idf_component.yml | 2 + 8 files changed, 85 insertions(+), 14 deletions(-) rename examples/ieee802154/{ieee802154_cli/components/cmd_ieee802154_stats => components/cmd_ieee802154_debug}/CMakeLists.txt (65%) create mode 100644 examples/ieee802154/components/cmd_ieee802154_debug/README.md rename examples/ieee802154/{ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c => components/cmd_ieee802154_debug/ieee802154_debug.c} (94%) rename examples/ieee802154/{ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.h => components/cmd_ieee802154_debug/ieee802154_debug.h} (100%) diff --git a/components/ieee802154/driver/esp_ieee802154_debug.c b/components/ieee802154/driver/esp_ieee802154_debug.c index 71847308b6..cd5041f910 100644 --- a/components/ieee802154/driver/esp_ieee802154_debug.c +++ b/components/ieee802154/driver/esp_ieee802154_debug.c @@ -401,15 +401,15 @@ void ieee802154_rx_buffer_statistic_print(void) for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1); i++) { total_times += s_rx_buffer_used_water_level[i]; } - ESP_LOGW(IEEE802154_TAG, "+--------------------+-------------------------+-------------------------+"); - ESP_LOGW(IEEE802154_TAG, "|%-20s|%-25s|%-25u|", "rx buff total size:", "", CONFIG_IEEE802154_RX_BUFFER_SIZE); - ESP_LOGW(IEEE802154_TAG, "|%-20s|%-25s|%-25llu|", "buffer alloc times:", "", total_times); - ESP_LOGW(IEEE802154_TAG, "+--------------------+-------------------------+-------------------------+"); + ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%25s|%-25u|", "rx buff total size:", CONFIG_IEEE802154_RX_BUFFER_SIZE); + ESP_LOGW(IEEE802154_TAG, "|%25s|%-25llu|", "buffer alloc times:", total_times); + ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+"); for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL); i++) { - ESP_LOGW(IEEE802154_TAG, "|%-20s|%4d%%%5s%4d%%%-10s|%-15llu%9.2f%%|", "", ((i) * 100 / IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL), "~", ((i + 1) * 100 / IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL), " used:", s_rx_buffer_used_water_level[i], ((float)s_rx_buffer_used_water_level[i] / (float)total_times)*100); + ESP_LOGW(IEEE802154_TAG, "|%4d%%%5s%4d%%%10s|%-15llu%9.2f%%|", ((i) * 100 / IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL), "~", ((i + 1) * 100 / IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL), " used:", s_rx_buffer_used_water_level[i], ((float)s_rx_buffer_used_water_level[i] / (float)total_times)*100); } - ESP_LOGW(IEEE802154_TAG, "|%-20s|%-25s|%-15llu%9.2f%%|", "", "full used:", s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL], ((float)s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL] / (float)total_times)*100); - ESP_LOGW(IEEE802154_TAG, "+--------------------+-------------------------+-------------------------+"); + ESP_LOGW(IEEE802154_TAG, "|%25s|%-15llu%9.2f%%|", "full used:", s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL], ((float)s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL] / (float)total_times)*100); + ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+"); } #endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/CMakeLists.txt b/examples/ieee802154/components/cmd_ieee802154_debug/CMakeLists.txt similarity index 65% rename from examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/CMakeLists.txt rename to examples/ieee802154/components/cmd_ieee802154_debug/CMakeLists.txt index c59fc3d2d7..24b8958a9e 100644 --- a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/CMakeLists.txt +++ b/examples/ieee802154/components/cmd_ieee802154_debug/CMakeLists.txt @@ -1,3 +1,3 @@ -idf_component_register(SRCS "ieee802154_stats.c" +idf_component_register(SRCS "ieee802154_debug.c" INCLUDE_DIRS "." REQUIRES ieee802154 console esp_phy) diff --git a/examples/ieee802154/components/cmd_ieee802154_debug/README.md b/examples/ieee802154/components/cmd_ieee802154_debug/README.md new file mode 100644 index 0000000000..1393266cc9 --- /dev/null +++ b/examples/ieee802154/components/cmd_ieee802154_debug/README.md @@ -0,0 +1,68 @@ +| Supported Targets | ESP32-C5 | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | -------- | + +# IEEE802.15.4 RX Buffer Statistics Component + +This component is used to consolidate the RX buffer statistics for IEEE802.15.4. The use of this component is demonstrated in the `ieee802154_cli` example, but can be similarly implemented for other stack examples (e.g. Zigbee / Thread). + +## How to use component + +In addition to the necessary configurations described in the `ieee802154_cli` example, some additional steps are required for configuring the board to enable the RX buffer statistics component. + +``` +idf.py menuconfig +``` + +This component can be enabled through the menuconfig: + +``` +Component config → IEEE 802.15.4 → IEEE802154 Enable → Enable IEEE802154 Debug → Rx buffer statistic +``` + +### Build, Flash, and Run + +Build the project and flash it to the board, then run monitor tool to view serial output: + +``` +idf.py -p PORT build flash monitor +``` + +Now you'll get an IEEE802.15.4 command line shell. + +## IEEE802.15.4 Command List + +In addition to the commands available in the `ieee802154_cli` example, enabling this component provides a new command: + +- [rxbufstat](#rxbufstat) + +### rxbufstat +#### rxbufstat -p +Print a summary table of rx buffer statistics. + +```bash +> rxbufstat -p +W (913011) ieee802154: +-------------------------+-------------------------+ +W (913011) ieee802154: | rx buff total size:|20 | +W (913021) ieee802154: | buffer alloc times:|80 | +W (913021) ieee802154: +-------------------------+-------------------------+ +W (913031) ieee802154: | 0% ~ 10% used:|80 100.00%| +W (913031) ieee802154: | 10% ~ 20% used:|0 0.00%| +W (913041) ieee802154: | 20% ~ 30% used:|0 0.00%| +W (913051) ieee802154: | 30% ~ 40% used:|0 0.00%| +W (913051) ieee802154: | 40% ~ 50% used:|0 0.00%| +W (913061) ieee802154: | 50% ~ 60% used:|0 0.00%| +W (913061) ieee802154: | 60% ~ 70% used:|0 0.00%| +W (913081) ieee802154: | 70% ~ 80% used:|0 0.00%| +W (913091) ieee802154: | 80% ~ 90% used:|0 0.00%| +W (913091) ieee802154: | 90% ~ 100% used:|0 0.00%| +W (913101) ieee802154: | full used:|0 0.00%| +W (913101) ieee802154: +-------------------------+-------------------------+ +``` + +#### rxbufstat -c +Clear the rx buffer statistics. + +```bash +> rxbufstat -c +I (7971) i154cmd: clear the rx buffer statistics +``` \ No newline at end of file diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c b/examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.c similarity index 94% rename from examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c rename to examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.c index 2941be74d4..b97a53050c 100644 --- a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.c +++ b/examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.c @@ -10,7 +10,7 @@ #include "esp_ieee802154.h" #include "esp_console.h" #include "argtable3/argtable3.h" -#include "ieee802154_stats.h" +#include "ieee802154_debug.h" #if CONFIG_IEEE802154_DEBUG static const char* TAG = "i154cmd"; @@ -60,6 +60,7 @@ static int process_rx_buffer_statistic(int argc, char **argv) } if (rx_buff_stat_args.clear->count) { esp_ieee802154_rx_buffer_statistic_clear(); + ESP_LOGI(TAG, "clear the rx buffer statistics"); } if (!rx_buff_stat_args.print->count && !rx_buff_stat_args.clear->count) { ESP_LOGE(TAG, "no valid arguments"); @@ -71,14 +72,14 @@ static int process_rx_buffer_statistic(int argc, char **argv) static void register_rx_buffer_statistic(void) { rx_buff_stat_args.print = - arg_lit0("p", "print", "print the result of rx buffer statistic"); + arg_lit0("p", "print", "print a summary table of rx buffer statistics"); rx_buff_stat_args.clear = - arg_lit0("c", "clear", "clear the result of rx buffer statistic"); + arg_lit0("c", "clear", "clear the rx buffer statistics"); rx_buff_stat_args.end = arg_end(2); const esp_console_cmd_t cmd = { .command = "rxbufstat", - .help = "rx buffer statistic", + .help = "rx buffer statistics", .hint = NULL, .func = &process_rx_buffer_statistic, .argtable = &rx_buff_stat_args diff --git a/examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.h b/examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.h similarity index 100% rename from examples/ieee802154/ieee802154_cli/components/cmd_ieee802154_stats/ieee802154_stats.h rename to examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.h diff --git a/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt b/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt index eb76f86a73..5c3a65e600 100644 --- a/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt +++ b/examples/ieee802154/ieee802154_cli/main/CMakeLists.txt @@ -7,5 +7,5 @@ set(include "." # the component can be registered as WHOLE_ARCHIVE idf_component_register(SRCS ${srcs} PRIV_REQUIRES ieee802154 console fatfs nvs_flash esp_phy cmd_ieee802154 - cmd_ieee802154_stats cmd_system + cmd_ieee802154_debug cmd_system WHOLE_ARCHIVE) diff --git a/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c b/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c index 64147755da..fb66b71689 100644 --- a/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c +++ b/examples/ieee802154/ieee802154_cli/main/esp_ieee802154_cli.c @@ -16,7 +16,7 @@ #include "esp_ieee802154.h" #include "esp_phy_init.h" #include "cmd_system.h" -#include "ieee802154_stats.h" +#include "ieee802154_debug.h" #define PROMPT_STR "ieee802154" diff --git a/examples/ieee802154/ieee802154_cli/main/idf_component.yml b/examples/ieee802154/ieee802154_cli/main/idf_component.yml index 77b231f2a7..670c948277 100644 --- a/examples/ieee802154/ieee802154_cli/main/idf_component.yml +++ b/examples/ieee802154/ieee802154_cli/main/idf_component.yml @@ -2,3 +2,5 @@ dependencies: cmd_system: path: ${IDF_PATH}/examples/system/console/advanced/components/cmd_system + cmd_ieee802154_debug: + path: ${IDF_PATH}/examples/ieee802154/components/cmd_ieee802154_debug From c711541e2be15d283c6220a4bd89862c89cd6668 Mon Sep 17 00:00:00 2001 From: Tan Yan Quan Date: Tue, 3 Dec 2024 20:00:31 +0800 Subject: [PATCH 4/4] feat(802.15.4): add some documentation for txrx statistics and debug record --- .../components/cmd_ieee802154_debug/README.md | 124 +++++++++++++++++- .../cmd_ieee802154_debug/ieee802154_debug.c | 1 + 2 files changed, 120 insertions(+), 5 deletions(-) diff --git a/examples/ieee802154/components/cmd_ieee802154_debug/README.md b/examples/ieee802154/components/cmd_ieee802154_debug/README.md index 1393266cc9..eb37d6139b 100644 --- a/examples/ieee802154/components/cmd_ieee802154_debug/README.md +++ b/examples/ieee802154/components/cmd_ieee802154_debug/README.md @@ -1,13 +1,27 @@ | Supported Targets | ESP32-C5 | ESP32-C6 | ESP32-H2 | | ----------------- | -------- | -------- | -------- | -# IEEE802.15.4 RX Buffer Statistics Component +# IEEE802.15.4 Debug Component -This component is used to consolidate the RX buffer statistics for IEEE802.15.4. The use of this component is demonstrated in the `ieee802154_cli` example, but can be similarly implemented for other stack examples (e.g. Zigbee / Thread). +This component is used to enable several debug features, including: +- Consolidate the RX buffer statistics for IEEE802.15.4 +- Consolidate the TX / RX statistics for IEEE802.15.4 +- Print the recorded events for IEEE802.15.4 + +The use of this component is demonstrated in the `ieee802154_cli` example below, but can be similarly implemented in examples (e.g. Zigbee / Thread) for other protocol stacks. ## How to use component -In addition to the necessary configurations described in the `ieee802154_cli` example, some additional steps are required for configuring the board to enable the RX buffer statistics component. +In addition to the necessary configurations described in the `ieee802154_cli` example, some additional steps are required for configuring the board to enable the IEEE802.15.4 Debug component. + +This component should be added as a dependency in `idf_component.yml`: +``` +dependencies: + cmd_ieee802154_debug: + path: ${IDF_PATH}/examples/ieee802154/components/cmd_ieee802154_debug +``` + +The `register_ieee802154_debug_cmd()` function should be called upon initialization to register the commands to be used in the cli. To enable this function, use: ``` idf.py menuconfig @@ -16,7 +30,15 @@ idf.py menuconfig This component can be enabled through the menuconfig: ``` -Component config → IEEE 802.15.4 → IEEE802154 Enable → Enable IEEE802154 Debug → Rx buffer statistic +Component config → IEEE 802.15.4 → IEEE802154 Enable → Enable IEEE802154 Debug +``` + +The commands can be independently enabled / disabled using: + +``` +Enable IEEE802154 Debug → Rx buffer statistic +Enable IEEE802154 Debug → Record the information with IEEE802154 state and event +Enable IEEE802154 Debug → Enable record tx/rx packets information for debugging ``` ### Build, Flash, and Run @@ -31,9 +53,48 @@ Now you'll get an IEEE802.15.4 command line shell. ## IEEE802.15.4 Command List -In addition to the commands available in the `ieee802154_cli` example, enabling this component provides a new command: +In addition to the commands available in the `ieee802154_cli` example, enabling this component provides the following new commands: +- [record](#record) - [rxbufstat](#rxbufstat) +- [txrxstat](#txrxstat) + +### record +#### record -p +Print the recorded IEEE802154 state/event/cmd etc. + +```bash +ieee802154> record -p +W (130811) ieee802154: Print the record event, current event index: 14 +W (130811) ieee802154: index 0: event: 0x1000, RX_SFD_DONE, state: RX, timestamp: 90951226 +... +W (130921) ieee802154: index 13: event: 0x 2, RX_DONE, state: RX, timestamp: 109182378 +W (130931) ieee802154: index 14: event: 0x 0, Multi events, state: DISABLE, timestamp: 0 +... +W (131061) ieee802154: index 29: event: 0x 0, Multi events, state: DISABLE, timestamp: 0 +W (131071) ieee802154: Print the record event done. +W (131071) ieee802154: Print the record state, current state index: 9 +W (131081) ieee802154: index 0: line: 794, state: IDLE, timestamp: 114737 +W (131091) ieee802154: index 1: line: 354, state: RX, timestamp: 90578575 +... +W (131131) ieee802154: index 7: line: 354, state: RX, timestamp: 109215261 +W (131141) ieee802154: index 8: line: 1038, state: SLEEP, timestamp: 112782354 +W (131141) ieee802154: index 9: line: , state: DISABLE, timestamp: 0 +W (131151) ieee802154: Print the record state done. +W (131161) ieee802154: Print the record cmd, current cmd index: 8 +W (131161) ieee802154: index 0: line: 352, cmd: rx, timestamp: 90578559 +... +W (131211) ieee802154: index 7: line: 204, cmd: stop, timestamp: 112782331 +W (131221) ieee802154: index 8: line: , cmd: , timestamp: 0 +W (131221) ieee802154: index 9: line: , cmd: , timestamp: 0 +W (131231) ieee802154: Print the record cmd done. +W (131241) ieee802154: Print the record abort, current abort index: 0 +W (131241) ieee802154: index 0: rx abort: 0, RSVD, timestamp: 0 +... +W (131301) ieee802154: index 9: rx abort: 0, RSVD, timestamp: 0 +W (131311) ieee802154: Print the record abort done. + +``` ### rxbufstat #### rxbufstat -p @@ -65,4 +126,57 @@ Clear the rx buffer statistics. ```bash > rxbufstat -c I (7971) i154cmd: clear the rx buffer statistics +``` + +### txrxstat +#### txrxstat -p +Print a summary table of rx buffer statistics. + +```bash +ieee802154> txrxstat -p +W (115381) ieee802154: +--------------------+-----------------------------------+--------------------------------------------------+ +W (115381) ieee802154: | |Done: 0 0.00%|Success: 0 0.00%| +W (115391) ieee802154: + + +--------------------------------------------------+ +W (115401) ieee802154: | | |tx_direct_num: 0 0.00%| +W (115411) ieee802154: + + +--------------------------------------------------+ +W (115431) ieee802154: | | |tx_deferred_num: 0 0.00%| +W (115451) ieee802154: + +-----------------------------------+--------------------------------------------------+ +W (115461) ieee802154: | | |rx_ack_coex_break: 0 0.00%| +W (115471) ieee802154: + + +--------------------------------------------------+ +W (115481) ieee802154: | | |rx_ack_timeout: 0 0.00%| +W (115491) ieee802154: + + +--------------------------------------------------+ +W (115501) ieee802154: |TX: 0 |Abort 0 0.00%|tx_coex_break: 0 0.00%| +W (115511) ieee802154: + + +--------------------------------------------------+ +W (115531) ieee802154: | | |tx_security_error: 0 0.00%| +W (115541) ieee802154: + + +--------------------------------------------------+ +W (115551) ieee802154: | | |cca_failed: 0 0.00%| +W (115561) ieee802154: + + +--------------------------------------------------+ +W (115571) ieee802154: | | |cca_busy: 0 0.00%| +W (115581) ieee802154: +--------------------+-----------------------------------+--------------------------------------------------+ +W (115591) ieee802154: | |Done: 6 |Success: 6 | +W (115611) ieee802154: + +-----------------------------------+--------------------------------------------------+ +W (115621) ieee802154: | | |tx_ack_coex_break: 0 | +W (115631) ieee802154: + + +--------------------------------------------------+ +W (115641) ieee802154: | | |sfd_timeout: 14 | +W (115651) ieee802154: + + +--------------------------------------------------+ +W (115661) ieee802154: | | |crc_error: 1 | +W (115671) ieee802154: + + +--------------------------------------------------+ +W (115691) ieee802154: |RX |Abort 17 |filter_fail: 0 | +W (115701) ieee802154: + + +--------------------------------------------------+ +W (115711) ieee802154: | | |no_rss: 0 | +W (115721) ieee802154: + + +--------------------------------------------------+ +W (115731) ieee802154: | | |rx_coex_break: 0 | +W (115741) ieee802154: + + +--------------------------------------------------+ +W (115751) ieee802154: | | |rx_restart: 2 | +W (115771) ieee802154: + + +--------------------------------------------------+ +W (115781) ieee802154: | | |ed_abort: 0 | +W (115791) ieee802154: +--------------------+-----------------------------------+--------------------------------------------------+ +``` + +#### txrxstat -c +Clear the rx buffer statistics. + +```bash +> txrxstat -c +I (7971) i154cmd: clear the txrx statistics ``` \ No newline at end of file diff --git a/examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.c b/examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.c index b97a53050c..c3664159c0 100644 --- a/examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.c +++ b/examples/ieee802154/components/cmd_ieee802154_debug/ieee802154_debug.c @@ -107,6 +107,7 @@ static int process_txrx_statistic(int argc, char **argv) } if (txrx_stat_args.clear->count) { esp_ieee802154_txrx_statistic_clear(); + ESP_LOGI(TAG, "clear the txrx statistics"); } if (!txrx_stat_args.print->count && !txrx_stat_args.clear->count) { ESP_LOGE(TAG, "no valid arguments");