esp_phy: phy track pll logic refactor

pull/11869/head
zhangwenxu 2023-06-07 20:05:29 +08:00
rodzic b8e71140ad
commit 4d6b13f395
4 zmienionych plików z 60 dodań i 1 usunięć

Wyświetl plik

@ -5,7 +5,7 @@ if(IDF_TARGET STREQUAL "esp32p4")
return()
endif()
set(srcs "src/phy_override.c" "src/lib_printf.c")
set(srcs "src/phy_override.c" "src/lib_printf.c" "src/phy_common.c")
if(CONFIG_APP_NO_BLOBS)
set(link_binary_libs 0)

Wyświetl plik

@ -258,6 +258,17 @@ esp_err_t esp_phy_apply_phy_init_data(uint8_t *init_data);
*/
char * get_phy_version_str(void);
/**
* @brief Enable phy track pll
*
*/
void phy_track_pll_init(void);
/**
* @brief Disable phy track pll
*
*/
void phy_track_pll_deinit(void);
#ifdef __cplusplus
}
#endif

Wyświetl plik

@ -0,0 +1,46 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_timer.h"
#include <stdint.h>
extern void bt_track_pll_cap(void);
static esp_timer_handle_t phy_track_pll_timer;
static volatile int64_t s_previous_timestamp;
#define PHY_TRACK_PLL_PERIOD_IN_US 1000000
static void phy_track_pll_timer_callback(void* arg)
{
#if IEEE802154_ENABLED || BT_ENABLED
bt_track_pll_cap();
#endif
s_previous_timestamp = esp_timer_get_time();
}
void phy_track_pll_init(void)
{
// Light sleep scenario: enabling and disabling PHY frequently, the timer will not get triggered.
// Using a variable to record the previously tracked time when PLL was last called.
// If the duration is larger than PHY_TRACK_PLL_PERIOD_IN_US, then track PLL.
int64_t now = esp_timer_get_time();
if (now - s_previous_timestamp > PHY_TRACK_PLL_PERIOD_IN_US) {
phy_track_pll_timer_callback((void* )0);
}
const esp_timer_create_args_t phy_track_pll_timer_args = {
.callback = &phy_track_pll_timer_callback,
.name = "phy-track-pll-timer"
};
ESP_ERROR_CHECK(esp_timer_create(&phy_track_pll_timer_args, &phy_track_pll_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(phy_track_pll_timer, PHY_TRACK_PLL_PERIOD_IN_US));
}
void phy_track_pll_deinit(void)
{
ESP_ERROR_CHECK(esp_timer_stop(phy_track_pll_timer));
ESP_ERROR_CHECK(esp_timer_delete(phy_track_pll_timer));
}

Wyświetl plik

@ -53,6 +53,7 @@ void esp_phy_enable(void)
} else {
phy_wakeup_init();
}
phy_track_pll_init();
}
s_phy_access_ref++;
@ -69,6 +70,7 @@ void esp_phy_disable(void)
}
if (s_phy_access_ref == 0) {
phy_track_pll_deinit();
phy_close_rf();
phy_xpd_tsens();
}