mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-09 00:23:00 +00:00
Merge branch 'feature/add_rx_buff_statistic_v5.3' into 'release/v5.3'
feat(802.15.4): IEEE802.15.4 add rx buffer statistic (v5.3) See merge request espressif/esp-idf!35640
This commit is contained in:
@@ -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
|
||||
|
@@ -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,48 @@ 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_print(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, "|%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, "|%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, "|%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
|
||||
|
@@ -87,6 +87,7 @@ 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.
|
||||
IEEE802154_RX_BUFFER_STAT_IS_FREE(false);
|
||||
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.
|
||||
@@ -99,6 +100,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 +120,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;
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
*/
|
||||
@@ -416,3 +416,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_print(void)
|
||||
{
|
||||
ieee802154_rx_buffer_statistic_print();
|
||||
}
|
||||
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC
|
||||
|
||||
#if CONFIG_IEEE802154_RECORD
|
||||
void esp_ieee802154_record_print(void)
|
||||
{
|
||||
ieee802154_record_print();
|
||||
}
|
||||
#endif // CONFIG_IEEE802154_RECORD
|
||||
|
@@ -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_print(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
|
||||
|
@@ -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_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 // CONFIG_IEEE802154_RX_BUFFER_STATISTIC
|
||||
|
||||
// TODO: replace etm code using common interface
|
||||
|
||||
#define IEEE802154_ETM_CHANNEL0 0
|
||||
|
Reference in New Issue
Block a user