mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(802.15.4): IEEE802.15.4 add rx buffer statistic
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user